1
2
3
4#include "ice_switch.h"
5
6#define ICE_ETH_DA_OFFSET 0
7#define ICE_ETH_ETHTYPE_OFFSET 12
8#define ICE_ETH_VLAN_TCI_OFFSET 14
9#define ICE_MAX_VLAN_ID 0xFFF
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#define DUMMY_ETH_HDR_LEN 16
27static const u8 dummy_eth_header[DUMMY_ETH_HDR_LEN] = { 0x2, 0, 0, 0, 0, 0,
28 0x2, 0, 0, 0, 0, 0,
29 0x81, 0, 0, 0};
30
31#define ICE_SW_RULE_RX_TX_ETH_HDR_SIZE \
32 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr) + \
33 (DUMMY_ETH_HDR_LEN * \
34 sizeof(((struct ice_sw_rule_lkup_rx_tx *)0)->hdr[0])))
35#define ICE_SW_RULE_RX_TX_NO_HDR_SIZE \
36 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lkup_tx_rx.hdr))
37#define ICE_SW_RULE_LG_ACT_SIZE(n) \
38 (offsetof(struct ice_aqc_sw_rules_elem, pdata.lg_act.act) + \
39 ((n) * sizeof(((struct ice_sw_rule_lg_act *)0)->act[0])))
40#define ICE_SW_RULE_VSI_LIST_SIZE(n) \
41 (offsetof(struct ice_aqc_sw_rules_elem, pdata.vsi_list.vsi) + \
42 ((n) * sizeof(((struct ice_sw_rule_vsi_list *)0)->vsi[0])))
43
44
45
46
47
48
49
50
51enum ice_status ice_init_def_sw_recp(struct ice_hw *hw)
52{
53 struct ice_sw_recipe *recps;
54 u8 i;
55
56 recps = devm_kcalloc(ice_hw_to_dev(hw), ICE_MAX_NUM_RECIPES,
57 sizeof(*recps), GFP_KERNEL);
58 if (!recps)
59 return ICE_ERR_NO_MEMORY;
60
61 for (i = 0; i < ICE_SW_LKUP_LAST; i++) {
62 recps[i].root_rid = i;
63 INIT_LIST_HEAD(&recps[i].filt_rules);
64 INIT_LIST_HEAD(&recps[i].filt_replay_rules);
65 mutex_init(&recps[i].filt_rule_lock);
66 }
67
68 hw->switch_info->recp_list = recps;
69
70 return 0;
71}
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98static enum ice_status
99ice_aq_get_sw_cfg(struct ice_hw *hw, struct ice_aqc_get_sw_cfg_resp_elem *buf,
100 u16 buf_size, u16 *req_desc, u16 *num_elems,
101 struct ice_sq_cd *cd)
102{
103 struct ice_aqc_get_sw_cfg *cmd;
104 struct ice_aq_desc desc;
105 enum ice_status status;
106
107 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_sw_cfg);
108 cmd = &desc.params.get_sw_conf;
109 cmd->element = cpu_to_le16(*req_desc);
110
111 status = ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);
112 if (!status) {
113 *req_desc = le16_to_cpu(cmd->element);
114 *num_elems = le16_to_cpu(cmd->num_elems);
115 }
116
117 return status;
118}
119
120
121
122
123
124
125
126
127
128static enum ice_status
129ice_aq_add_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
130 struct ice_sq_cd *cd)
131{
132 struct ice_aqc_add_update_free_vsi_resp *res;
133 struct ice_aqc_add_get_update_free_vsi *cmd;
134 struct ice_aq_desc desc;
135 enum ice_status status;
136
137 cmd = &desc.params.vsi_cmd;
138 res = &desc.params.add_update_free_vsi_res;
139
140 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_add_vsi);
141
142 if (!vsi_ctx->alloc_from_pool)
143 cmd->vsi_num = cpu_to_le16(vsi_ctx->vsi_num |
144 ICE_AQ_VSI_IS_VALID);
145 cmd->vf_id = vsi_ctx->vf_num;
146
147 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
148
149 desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
150
151 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
152 sizeof(vsi_ctx->info), cd);
153
154 if (!status) {
155 vsi_ctx->vsi_num = le16_to_cpu(res->vsi_num) & ICE_AQ_VSI_NUM_M;
156 vsi_ctx->vsis_allocd = le16_to_cpu(res->vsi_used);
157 vsi_ctx->vsis_unallocated = le16_to_cpu(res->vsi_free);
158 }
159
160 return status;
161}
162
163
164
165
166
167
168
169
170
171
172static enum ice_status
173ice_aq_free_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
174 bool keep_vsi_alloc, struct ice_sq_cd *cd)
175{
176 struct ice_aqc_add_update_free_vsi_resp *resp;
177 struct ice_aqc_add_get_update_free_vsi *cmd;
178 struct ice_aq_desc desc;
179 enum ice_status status;
180
181 cmd = &desc.params.vsi_cmd;
182 resp = &desc.params.add_update_free_vsi_res;
183
184 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_free_vsi);
185
186 cmd->vsi_num = cpu_to_le16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
187 if (keep_vsi_alloc)
188 cmd->cmd_flags = cpu_to_le16(ICE_AQ_VSI_KEEP_ALLOC);
189
190 status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
191 if (!status) {
192 vsi_ctx->vsis_allocd = le16_to_cpu(resp->vsi_used);
193 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
194 }
195
196 return status;
197}
198
199
200
201
202
203
204
205
206
207static enum ice_status
208ice_aq_update_vsi(struct ice_hw *hw, struct ice_vsi_ctx *vsi_ctx,
209 struct ice_sq_cd *cd)
210{
211 struct ice_aqc_add_update_free_vsi_resp *resp;
212 struct ice_aqc_add_get_update_free_vsi *cmd;
213 struct ice_aq_desc desc;
214 enum ice_status status;
215
216 cmd = &desc.params.vsi_cmd;
217 resp = &desc.params.add_update_free_vsi_res;
218
219 ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_update_vsi);
220
221 cmd->vsi_num = cpu_to_le16(vsi_ctx->vsi_num | ICE_AQ_VSI_IS_VALID);
222
223 desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
224
225 status = ice_aq_send_cmd(hw, &desc, &vsi_ctx->info,
226 sizeof(vsi_ctx->info), cd);
227
228 if (!status) {
229 vsi_ctx->vsis_allocd = le16_to_cpu(resp->vsi_used);
230 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
231 }
232
233 return status;
234}
235
236
237
238
239
240
241
242
243bool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle)
244{
245 return vsi_handle < ICE_MAX_VSI && hw->vsi_ctx[vsi_handle];
246}
247
248
249
250
251
252
253
254
255
256u16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle)
257{
258 return hw->vsi_ctx[vsi_handle]->vsi_num;
259}
260
261
262
263
264
265
266
267
268struct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
269{
270 return (vsi_handle >= ICE_MAX_VSI) ? NULL : hw->vsi_ctx[vsi_handle];
271}
272
273
274
275
276
277
278
279
280
281static void
282ice_save_vsi_ctx(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi)
283{
284 hw->vsi_ctx[vsi_handle] = vsi;
285}
286
287
288
289
290
291
292static void ice_clear_vsi_q_ctx(struct ice_hw *hw, u16 vsi_handle)
293{
294 struct ice_vsi_ctx *vsi;
295 u8 i;
296
297 vsi = ice_get_vsi_ctx(hw, vsi_handle);
298 if (!vsi)
299 return;
300 ice_for_each_traffic_class(i) {
301 if (vsi->lan_q_ctx[i]) {
302 devm_kfree(ice_hw_to_dev(hw), vsi->lan_q_ctx[i]);
303 vsi->lan_q_ctx[i] = NULL;
304 }
305 }
306}
307
308
309
310
311
312
313
314
315static void ice_clear_vsi_ctx(struct ice_hw *hw, u16 vsi_handle)
316{
317 struct ice_vsi_ctx *vsi;
318
319 vsi = ice_get_vsi_ctx(hw, vsi_handle);
320 if (vsi) {
321 ice_clear_vsi_q_ctx(hw, vsi_handle);
322 devm_kfree(ice_hw_to_dev(hw), vsi);
323 hw->vsi_ctx[vsi_handle] = NULL;
324 }
325}
326
327
328
329
330
331void ice_clear_all_vsi_ctx(struct ice_hw *hw)
332{
333 u16 i;
334
335 for (i = 0; i < ICE_MAX_VSI; i++)
336 ice_clear_vsi_ctx(hw, i);
337}
338
339
340
341
342
343
344
345
346
347
348
349
350enum ice_status
351ice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
352 struct ice_sq_cd *cd)
353{
354 struct ice_vsi_ctx *tmp_vsi_ctx;
355 enum ice_status status;
356
357 if (vsi_handle >= ICE_MAX_VSI)
358 return ICE_ERR_PARAM;
359 status = ice_aq_add_vsi(hw, vsi_ctx, cd);
360 if (status)
361 return status;
362 tmp_vsi_ctx = ice_get_vsi_ctx(hw, vsi_handle);
363 if (!tmp_vsi_ctx) {
364
365 tmp_vsi_ctx = devm_kzalloc(ice_hw_to_dev(hw),
366 sizeof(*tmp_vsi_ctx), GFP_KERNEL);
367 if (!tmp_vsi_ctx) {
368 ice_aq_free_vsi(hw, vsi_ctx, false, cd);
369 return ICE_ERR_NO_MEMORY;
370 }
371 *tmp_vsi_ctx = *vsi_ctx;
372 ice_save_vsi_ctx(hw, vsi_handle, tmp_vsi_ctx);
373 } else {
374
375 tmp_vsi_ctx->vsi_num = vsi_ctx->vsi_num;
376 }
377
378 return 0;
379}
380
381
382
383
384
385
386
387
388
389
390
391enum ice_status
392ice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
393 bool keep_vsi_alloc, struct ice_sq_cd *cd)
394{
395 enum ice_status status;
396
397 if (!ice_is_vsi_valid(hw, vsi_handle))
398 return ICE_ERR_PARAM;
399 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
400 status = ice_aq_free_vsi(hw, vsi_ctx, keep_vsi_alloc, cd);
401 if (!status)
402 ice_clear_vsi_ctx(hw, vsi_handle);
403 return status;
404}
405
406
407
408
409
410
411
412
413
414
415enum ice_status
416ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx,
417 struct ice_sq_cd *cd)
418{
419 if (!ice_is_vsi_valid(hw, vsi_handle))
420 return ICE_ERR_PARAM;
421 vsi_ctx->vsi_num = ice_get_hw_vsi_num(hw, vsi_handle);
422 return ice_aq_update_vsi(hw, vsi_ctx, cd);
423}
424
425
426
427
428
429
430
431
432
433
434static enum ice_status
435ice_aq_alloc_free_vsi_list(struct ice_hw *hw, u16 *vsi_list_id,
436 enum ice_sw_lkup_type lkup_type,
437 enum ice_adminq_opc opc)
438{
439 struct ice_aqc_alloc_free_res_elem *sw_buf;
440 struct ice_aqc_res_elem *vsi_ele;
441 enum ice_status status;
442 u16 buf_len;
443
444 buf_len = struct_size(sw_buf, elem, 1);
445 sw_buf = devm_kzalloc(ice_hw_to_dev(hw), buf_len, GFP_KERNEL);
446 if (!sw_buf)
447 return ICE_ERR_NO_MEMORY;
448 sw_buf->num_elems = cpu_to_le16(1);
449
450 if (lkup_type == ICE_SW_LKUP_MAC ||
451 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
452 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
453 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
454 lkup_type == ICE_SW_LKUP_PROMISC ||
455 lkup_type == ICE_SW_LKUP_PROMISC_VLAN) {
456 sw_buf->res_type = cpu_to_le16(ICE_AQC_RES_TYPE_VSI_LIST_REP);
457 } else if (lkup_type == ICE_SW_LKUP_VLAN) {
458 sw_buf->res_type =
459 cpu_to_le16(ICE_AQC_RES_TYPE_VSI_LIST_PRUNE);
460 } else {
461 status = ICE_ERR_PARAM;
462 goto ice_aq_alloc_free_vsi_list_exit;
463 }
464
465 if (opc == ice_aqc_opc_free_res)
466 sw_buf->elem[0].e.sw_resp = cpu_to_le16(*vsi_list_id);
467
468 status = ice_aq_alloc_free_res(hw, 1, sw_buf, buf_len, opc, NULL);
469 if (status)
470 goto ice_aq_alloc_free_vsi_list_exit;
471
472 if (opc == ice_aqc_opc_alloc_res) {
473 vsi_ele = &sw_buf->elem[0];
474 *vsi_list_id = le16_to_cpu(vsi_ele->e.sw_resp);
475 }
476
477ice_aq_alloc_free_vsi_list_exit:
478 devm_kfree(ice_hw_to_dev(hw), sw_buf);
479 return status;
480}
481
482
483
484
485
486
487
488
489
490
491
492
493static enum ice_status
494ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz,
495 u8 num_rules, enum ice_adminq_opc opc, struct ice_sq_cd *cd)
496{
497 struct ice_aq_desc desc;
498 enum ice_status status;
499
500 if (opc != ice_aqc_opc_add_sw_rules &&
501 opc != ice_aqc_opc_update_sw_rules &&
502 opc != ice_aqc_opc_remove_sw_rules)
503 return ICE_ERR_PARAM;
504
505 ice_fill_dflt_direct_cmd_desc(&desc, opc);
506
507 desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD);
508 desc.params.sw_rules.num_rules_fltr_entry_index =
509 cpu_to_le16(num_rules);
510 status = ice_aq_send_cmd(hw, &desc, rule_list, rule_list_sz, cd);
511 if (opc != ice_aqc_opc_add_sw_rules &&
512 hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT)
513 status = ICE_ERR_DOES_NOT_EXIST;
514
515 return status;
516}
517
518
519
520
521
522
523
524
525
526static void
527ice_init_port_info(struct ice_port_info *pi, u16 vsi_port_num, u8 type,
528 u16 swid, u16 pf_vf_num, bool is_vf)
529{
530 switch (type) {
531 case ICE_AQC_GET_SW_CONF_RESP_PHYS_PORT:
532 pi->lport = (u8)(vsi_port_num & ICE_LPORT_MASK);
533 pi->sw_id = swid;
534 pi->pf_vf_num = pf_vf_num;
535 pi->is_vf = is_vf;
536 pi->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
537 pi->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
538 break;
539 default:
540 ice_debug(pi->hw, ICE_DBG_SW,
541 "incorrect VSI/port type received\n");
542 break;
543 }
544}
545
546
547
548
549enum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw)
550{
551 struct ice_aqc_get_sw_cfg_resp_elem *rbuf;
552 enum ice_status status;
553 u16 req_desc = 0;
554 u16 num_elems;
555 u16 i;
556
557 rbuf = devm_kzalloc(ice_hw_to_dev(hw), ICE_SW_CFG_MAX_BUF_LEN,
558 GFP_KERNEL);
559
560 if (!rbuf)
561 return ICE_ERR_NO_MEMORY;
562
563
564
565
566
567
568 do {
569 struct ice_aqc_get_sw_cfg_resp_elem *ele;
570
571 status = ice_aq_get_sw_cfg(hw, rbuf, ICE_SW_CFG_MAX_BUF_LEN,
572 &req_desc, &num_elems, NULL);
573
574 if (status)
575 break;
576
577 for (i = 0, ele = rbuf; i < num_elems; i++, ele++) {
578 u16 pf_vf_num, swid, vsi_port_num;
579 bool is_vf = false;
580 u8 res_type;
581
582 vsi_port_num = le16_to_cpu(ele->vsi_port_num) &
583 ICE_AQC_GET_SW_CONF_RESP_VSI_PORT_NUM_M;
584
585 pf_vf_num = le16_to_cpu(ele->pf_vf_num) &
586 ICE_AQC_GET_SW_CONF_RESP_FUNC_NUM_M;
587
588 swid = le16_to_cpu(ele->swid);
589
590 if (le16_to_cpu(ele->pf_vf_num) &
591 ICE_AQC_GET_SW_CONF_RESP_IS_VF)
592 is_vf = true;
593
594 res_type = (u8)(le16_to_cpu(ele->vsi_port_num) >>
595 ICE_AQC_GET_SW_CONF_RESP_TYPE_S);
596
597 if (res_type == ICE_AQC_GET_SW_CONF_RESP_VSI) {
598
599 continue;
600 }
601
602 ice_init_port_info(hw->port_info, vsi_port_num,
603 res_type, swid, pf_vf_num, is_vf);
604 }
605 } while (req_desc && !status);
606
607 devm_kfree(ice_hw_to_dev(hw), (void *)rbuf);
608 return status;
609}
610
611
612
613
614
615
616
617
618
619
620static void ice_fill_sw_info(struct ice_hw *hw, struct ice_fltr_info *fi)
621{
622 fi->lb_en = false;
623 fi->lan_en = false;
624 if ((fi->flag & ICE_FLTR_TX) &&
625 (fi->fltr_act == ICE_FWD_TO_VSI ||
626 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
627 fi->fltr_act == ICE_FWD_TO_Q ||
628 fi->fltr_act == ICE_FWD_TO_QGRP)) {
629
630
631
632 if (fi->lkup_type != ICE_SW_LKUP_VLAN)
633 fi->lb_en = true;
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651 if (hw->evb_veb) {
652 if (fi->lkup_type == ICE_SW_LKUP_ETHERTYPE ||
653 fi->lkup_type == ICE_SW_LKUP_PROMISC ||
654 fi->lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
655 fi->lkup_type == ICE_SW_LKUP_PROMISC_VLAN ||
656 fi->lkup_type == ICE_SW_LKUP_DFLT ||
657 fi->lkup_type == ICE_SW_LKUP_VLAN ||
658 (fi->lkup_type == ICE_SW_LKUP_MAC &&
659 !is_unicast_ether_addr(fi->l_data.mac.mac_addr)) ||
660 (fi->lkup_type == ICE_SW_LKUP_MAC_VLAN &&
661 !is_unicast_ether_addr(fi->l_data.mac.mac_addr)))
662 fi->lan_en = true;
663 } else {
664 fi->lan_en = true;
665 }
666 }
667}
668
669
670
671
672
673
674
675
676static void
677ice_fill_sw_rule(struct ice_hw *hw, struct ice_fltr_info *f_info,
678 struct ice_aqc_sw_rules_elem *s_rule, enum ice_adminq_opc opc)
679{
680 u16 vlan_id = ICE_MAX_VLAN_ID + 1;
681 void *daddr = NULL;
682 u16 eth_hdr_sz;
683 u8 *eth_hdr;
684 u32 act = 0;
685 __be16 *off;
686 u8 q_rgn;
687
688 if (opc == ice_aqc_opc_remove_sw_rules) {
689 s_rule->pdata.lkup_tx_rx.act = 0;
690 s_rule->pdata.lkup_tx_rx.index =
691 cpu_to_le16(f_info->fltr_rule_id);
692 s_rule->pdata.lkup_tx_rx.hdr_len = 0;
693 return;
694 }
695
696 eth_hdr_sz = sizeof(dummy_eth_header);
697 eth_hdr = s_rule->pdata.lkup_tx_rx.hdr;
698
699
700 memcpy(eth_hdr, dummy_eth_header, eth_hdr_sz);
701 ice_fill_sw_info(hw, f_info);
702
703 switch (f_info->fltr_act) {
704 case ICE_FWD_TO_VSI:
705 act |= (f_info->fwd_id.hw_vsi_id << ICE_SINGLE_ACT_VSI_ID_S) &
706 ICE_SINGLE_ACT_VSI_ID_M;
707 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
708 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
709 ICE_SINGLE_ACT_VALID_BIT;
710 break;
711 case ICE_FWD_TO_VSI_LIST:
712 act |= ICE_SINGLE_ACT_VSI_LIST;
713 act |= (f_info->fwd_id.vsi_list_id <<
714 ICE_SINGLE_ACT_VSI_LIST_ID_S) &
715 ICE_SINGLE_ACT_VSI_LIST_ID_M;
716 if (f_info->lkup_type != ICE_SW_LKUP_VLAN)
717 act |= ICE_SINGLE_ACT_VSI_FORWARDING |
718 ICE_SINGLE_ACT_VALID_BIT;
719 break;
720 case ICE_FWD_TO_Q:
721 act |= ICE_SINGLE_ACT_TO_Q;
722 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
723 ICE_SINGLE_ACT_Q_INDEX_M;
724 break;
725 case ICE_DROP_PACKET:
726 act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
727 ICE_SINGLE_ACT_VALID_BIT;
728 break;
729 case ICE_FWD_TO_QGRP:
730 q_rgn = f_info->qgrp_size > 0 ?
731 (u8)ilog2(f_info->qgrp_size) : 0;
732 act |= ICE_SINGLE_ACT_TO_Q;
733 act |= (f_info->fwd_id.q_id << ICE_SINGLE_ACT_Q_INDEX_S) &
734 ICE_SINGLE_ACT_Q_INDEX_M;
735 act |= (q_rgn << ICE_SINGLE_ACT_Q_REGION_S) &
736 ICE_SINGLE_ACT_Q_REGION_M;
737 break;
738 default:
739 return;
740 }
741
742 if (f_info->lb_en)
743 act |= ICE_SINGLE_ACT_LB_ENABLE;
744 if (f_info->lan_en)
745 act |= ICE_SINGLE_ACT_LAN_ENABLE;
746
747 switch (f_info->lkup_type) {
748 case ICE_SW_LKUP_MAC:
749 daddr = f_info->l_data.mac.mac_addr;
750 break;
751 case ICE_SW_LKUP_VLAN:
752 vlan_id = f_info->l_data.vlan.vlan_id;
753 if (f_info->fltr_act == ICE_FWD_TO_VSI ||
754 f_info->fltr_act == ICE_FWD_TO_VSI_LIST) {
755 act |= ICE_SINGLE_ACT_PRUNE;
756 act |= ICE_SINGLE_ACT_EGRESS | ICE_SINGLE_ACT_INGRESS;
757 }
758 break;
759 case ICE_SW_LKUP_ETHERTYPE_MAC:
760 daddr = f_info->l_data.ethertype_mac.mac_addr;
761 fallthrough;
762 case ICE_SW_LKUP_ETHERTYPE:
763 off = (__force __be16 *)(eth_hdr + ICE_ETH_ETHTYPE_OFFSET);
764 *off = cpu_to_be16(f_info->l_data.ethertype_mac.ethertype);
765 break;
766 case ICE_SW_LKUP_MAC_VLAN:
767 daddr = f_info->l_data.mac_vlan.mac_addr;
768 vlan_id = f_info->l_data.mac_vlan.vlan_id;
769 break;
770 case ICE_SW_LKUP_PROMISC_VLAN:
771 vlan_id = f_info->l_data.mac_vlan.vlan_id;
772 fallthrough;
773 case ICE_SW_LKUP_PROMISC:
774 daddr = f_info->l_data.mac_vlan.mac_addr;
775 break;
776 default:
777 break;
778 }
779
780 s_rule->type = (f_info->flag & ICE_FLTR_RX) ?
781 cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_RX) :
782 cpu_to_le16(ICE_AQC_SW_RULES_T_LKUP_TX);
783
784
785 s_rule->pdata.lkup_tx_rx.recipe_id = cpu_to_le16(f_info->lkup_type);
786 s_rule->pdata.lkup_tx_rx.src = cpu_to_le16(f_info->src);
787 s_rule->pdata.lkup_tx_rx.act = cpu_to_le32(act);
788
789 if (daddr)
790 ether_addr_copy(eth_hdr + ICE_ETH_DA_OFFSET, daddr);
791
792 if (!(vlan_id > ICE_MAX_VLAN_ID)) {
793 off = (__force __be16 *)(eth_hdr + ICE_ETH_VLAN_TCI_OFFSET);
794 *off = cpu_to_be16(vlan_id);
795 }
796
797
798 if (opc != ice_aqc_opc_update_sw_rules)
799 s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(eth_hdr_sz);
800}
801
802
803
804
805
806
807
808
809
810
811
812static enum ice_status
813ice_add_marker_act(struct ice_hw *hw, struct ice_fltr_mgmt_list_entry *m_ent,
814 u16 sw_marker, u16 l_id)
815{
816 struct ice_aqc_sw_rules_elem *lg_act, *rx_tx;
817
818
819
820
821
822 const u16 num_lg_acts = 3;
823 enum ice_status status;
824 u16 lg_act_size;
825 u16 rules_size;
826 u32 act;
827 u16 id;
828
829 if (m_ent->fltr_info.lkup_type != ICE_SW_LKUP_MAC)
830 return ICE_ERR_PARAM;
831
832
833
834
835
836
837 lg_act_size = (u16)ICE_SW_RULE_LG_ACT_SIZE(num_lg_acts);
838 rules_size = lg_act_size + ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
839 lg_act = devm_kzalloc(ice_hw_to_dev(hw), rules_size, GFP_KERNEL);
840 if (!lg_act)
841 return ICE_ERR_NO_MEMORY;
842
843 rx_tx = (struct ice_aqc_sw_rules_elem *)((u8 *)lg_act + lg_act_size);
844
845
846 lg_act->type = cpu_to_le16(ICE_AQC_SW_RULES_T_LG_ACT);
847 lg_act->pdata.lg_act.index = cpu_to_le16(l_id);
848 lg_act->pdata.lg_act.size = cpu_to_le16(num_lg_acts);
849
850
851
852
853 id = (m_ent->vsi_count > 1) ? m_ent->fltr_info.fwd_id.vsi_list_id :
854 m_ent->fltr_info.fwd_id.hw_vsi_id;
855
856 act = ICE_LG_ACT_VSI_FORWARDING | ICE_LG_ACT_VALID_BIT;
857 act |= (id << ICE_LG_ACT_VSI_LIST_ID_S) & ICE_LG_ACT_VSI_LIST_ID_M;
858 if (m_ent->vsi_count > 1)
859 act |= ICE_LG_ACT_VSI_LIST;
860 lg_act->pdata.lg_act.act[0] = cpu_to_le32(act);
861
862
863 act = ICE_LG_ACT_GENERIC;
864
865 act |= (1 << ICE_LG_ACT_GENERIC_VALUE_S) & ICE_LG_ACT_GENERIC_VALUE_M;
866 lg_act->pdata.lg_act.act[1] = cpu_to_le32(act);
867
868 act = (ICE_LG_ACT_GENERIC_OFF_RX_DESC_PROF_IDX <<
869 ICE_LG_ACT_GENERIC_OFFSET_S) & ICE_LG_ACT_GENERIC_OFFSET_M;
870
871
872 act |= ICE_LG_ACT_GENERIC;
873 act |= (sw_marker << ICE_LG_ACT_GENERIC_VALUE_S) &
874 ICE_LG_ACT_GENERIC_VALUE_M;
875
876 lg_act->pdata.lg_act.act[2] = cpu_to_le32(act);
877
878
879 ice_fill_sw_rule(hw, &m_ent->fltr_info, rx_tx,
880 ice_aqc_opc_update_sw_rules);
881
882
883 rx_tx->pdata.lkup_tx_rx.act =
884 cpu_to_le32(ICE_SINGLE_ACT_PTR |
885 ((l_id << ICE_SINGLE_ACT_PTR_VAL_S) &
886 ICE_SINGLE_ACT_PTR_VAL_M));
887
888
889
890
891
892 rx_tx->pdata.lkup_tx_rx.index =
893 cpu_to_le16(m_ent->fltr_info.fltr_rule_id);
894
895 status = ice_aq_sw_rules(hw, lg_act, rules_size, 2,
896 ice_aqc_opc_update_sw_rules, NULL);
897 if (!status) {
898 m_ent->lg_act_idx = l_id;
899 m_ent->sw_marker_id = sw_marker;
900 }
901
902 devm_kfree(ice_hw_to_dev(hw), lg_act);
903 return status;
904}
905
906
907
908
909
910
911
912
913
914
915
916static struct ice_vsi_list_map_info *
917ice_create_vsi_list_map(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
918 u16 vsi_list_id)
919{
920 struct ice_switch_info *sw = hw->switch_info;
921 struct ice_vsi_list_map_info *v_map;
922 int i;
923
924 v_map = devm_kcalloc(ice_hw_to_dev(hw), 1, sizeof(*v_map), GFP_KERNEL);
925 if (!v_map)
926 return NULL;
927
928 v_map->vsi_list_id = vsi_list_id;
929 v_map->ref_cnt = 1;
930 for (i = 0; i < num_vsi; i++)
931 set_bit(vsi_handle_arr[i], v_map->vsi_map);
932
933 list_add(&v_map->list_entry, &sw->vsi_list_map_head);
934 return v_map;
935}
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950static enum ice_status
951ice_update_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
952 u16 vsi_list_id, bool remove, enum ice_adminq_opc opc,
953 enum ice_sw_lkup_type lkup_type)
954{
955 struct ice_aqc_sw_rules_elem *s_rule;
956 enum ice_status status;
957 u16 s_rule_size;
958 u16 rule_type;
959 int i;
960
961 if (!num_vsi)
962 return ICE_ERR_PARAM;
963
964 if (lkup_type == ICE_SW_LKUP_MAC ||
965 lkup_type == ICE_SW_LKUP_MAC_VLAN ||
966 lkup_type == ICE_SW_LKUP_ETHERTYPE ||
967 lkup_type == ICE_SW_LKUP_ETHERTYPE_MAC ||
968 lkup_type == ICE_SW_LKUP_PROMISC ||
969 lkup_type == ICE_SW_LKUP_PROMISC_VLAN)
970 rule_type = remove ? ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR :
971 ICE_AQC_SW_RULES_T_VSI_LIST_SET;
972 else if (lkup_type == ICE_SW_LKUP_VLAN)
973 rule_type = remove ? ICE_AQC_SW_RULES_T_PRUNE_LIST_CLEAR :
974 ICE_AQC_SW_RULES_T_PRUNE_LIST_SET;
975 else
976 return ICE_ERR_PARAM;
977
978 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(num_vsi);
979 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
980 if (!s_rule)
981 return ICE_ERR_NO_MEMORY;
982 for (i = 0; i < num_vsi; i++) {
983 if (!ice_is_vsi_valid(hw, vsi_handle_arr[i])) {
984 status = ICE_ERR_PARAM;
985 goto exit;
986 }
987
988 s_rule->pdata.vsi_list.vsi[i] =
989 cpu_to_le16(ice_get_hw_vsi_num(hw, vsi_handle_arr[i]));
990 }
991
992 s_rule->type = cpu_to_le16(rule_type);
993 s_rule->pdata.vsi_list.number_vsi = cpu_to_le16(num_vsi);
994 s_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);
995
996 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opc, NULL);
997
998exit:
999 devm_kfree(ice_hw_to_dev(hw), s_rule);
1000 return status;
1001}
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011static enum ice_status
1012ice_create_vsi_list_rule(struct ice_hw *hw, u16 *vsi_handle_arr, u16 num_vsi,
1013 u16 *vsi_list_id, enum ice_sw_lkup_type lkup_type)
1014{
1015 enum ice_status status;
1016
1017 status = ice_aq_alloc_free_vsi_list(hw, vsi_list_id, lkup_type,
1018 ice_aqc_opc_alloc_res);
1019 if (status)
1020 return status;
1021
1022
1023 return ice_update_vsi_list_rule(hw, vsi_handle_arr, num_vsi,
1024 *vsi_list_id, false,
1025 ice_aqc_opc_add_sw_rules, lkup_type);
1026}
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037static enum ice_status
1038ice_create_pkt_fwd_rule(struct ice_hw *hw,
1039 struct ice_fltr_list_entry *f_entry)
1040{
1041 struct ice_fltr_mgmt_list_entry *fm_entry;
1042 struct ice_aqc_sw_rules_elem *s_rule;
1043 enum ice_sw_lkup_type l_type;
1044 struct ice_sw_recipe *recp;
1045 enum ice_status status;
1046
1047 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
1048 ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, GFP_KERNEL);
1049 if (!s_rule)
1050 return ICE_ERR_NO_MEMORY;
1051 fm_entry = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*fm_entry),
1052 GFP_KERNEL);
1053 if (!fm_entry) {
1054 status = ICE_ERR_NO_MEMORY;
1055 goto ice_create_pkt_fwd_rule_exit;
1056 }
1057
1058 fm_entry->fltr_info = f_entry->fltr_info;
1059
1060
1061 fm_entry->vsi_count = 1;
1062 fm_entry->lg_act_idx = ICE_INVAL_LG_ACT_INDEX;
1063 fm_entry->sw_marker_id = ICE_INVAL_SW_MARKER_ID;
1064 fm_entry->counter_index = ICE_INVAL_COUNTER_ID;
1065
1066 ice_fill_sw_rule(hw, &fm_entry->fltr_info, s_rule,
1067 ice_aqc_opc_add_sw_rules);
1068
1069 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1070 ice_aqc_opc_add_sw_rules, NULL);
1071 if (status) {
1072 devm_kfree(ice_hw_to_dev(hw), fm_entry);
1073 goto ice_create_pkt_fwd_rule_exit;
1074 }
1075
1076 f_entry->fltr_info.fltr_rule_id =
1077 le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
1078 fm_entry->fltr_info.fltr_rule_id =
1079 le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
1080
1081
1082
1083
1084 l_type = fm_entry->fltr_info.lkup_type;
1085 recp = &hw->switch_info->recp_list[l_type];
1086 list_add(&fm_entry->list_entry, &recp->filt_rules);
1087
1088ice_create_pkt_fwd_rule_exit:
1089 devm_kfree(ice_hw_to_dev(hw), s_rule);
1090 return status;
1091}
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101static enum ice_status
1102ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)
1103{
1104 struct ice_aqc_sw_rules_elem *s_rule;
1105 enum ice_status status;
1106
1107 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
1108 ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, GFP_KERNEL);
1109 if (!s_rule)
1110 return ICE_ERR_NO_MEMORY;
1111
1112 ice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);
1113
1114 s_rule->pdata.lkup_tx_rx.index = cpu_to_le16(f_info->fltr_rule_id);
1115
1116
1117 status = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,
1118 ice_aqc_opc_update_sw_rules, NULL);
1119
1120 devm_kfree(ice_hw_to_dev(hw), s_rule);
1121 return status;
1122}
1123
1124
1125
1126
1127
1128
1129
1130enum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw)
1131{
1132 struct ice_switch_info *sw = hw->switch_info;
1133 struct ice_fltr_mgmt_list_entry *fm_entry;
1134 enum ice_status status = 0;
1135 struct list_head *rule_head;
1136 struct mutex *rule_lock;
1137
1138 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1139 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1140
1141 mutex_lock(rule_lock);
1142 list_for_each_entry(fm_entry, rule_head, list_entry) {
1143 struct ice_fltr_info *fi = &fm_entry->fltr_info;
1144 u8 *addr = fi->l_data.mac.mac_addr;
1145
1146
1147
1148
1149 if ((fi->flag & ICE_FLTR_TX) && is_unicast_ether_addr(addr) &&
1150 (fi->fltr_act == ICE_FWD_TO_VSI ||
1151 fi->fltr_act == ICE_FWD_TO_VSI_LIST ||
1152 fi->fltr_act == ICE_FWD_TO_Q ||
1153 fi->fltr_act == ICE_FWD_TO_QGRP)) {
1154 status = ice_update_pkt_fwd_rule(hw, fi);
1155 if (status)
1156 break;
1157 }
1158 }
1159
1160 mutex_unlock(rule_lock);
1161
1162 return status;
1163}
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186static enum ice_status
1187ice_add_update_vsi_list(struct ice_hw *hw,
1188 struct ice_fltr_mgmt_list_entry *m_entry,
1189 struct ice_fltr_info *cur_fltr,
1190 struct ice_fltr_info *new_fltr)
1191{
1192 enum ice_status status = 0;
1193 u16 vsi_list_id = 0;
1194
1195 if ((cur_fltr->fltr_act == ICE_FWD_TO_Q ||
1196 cur_fltr->fltr_act == ICE_FWD_TO_QGRP))
1197 return ICE_ERR_NOT_IMPL;
1198
1199 if ((new_fltr->fltr_act == ICE_FWD_TO_Q ||
1200 new_fltr->fltr_act == ICE_FWD_TO_QGRP) &&
1201 (cur_fltr->fltr_act == ICE_FWD_TO_VSI ||
1202 cur_fltr->fltr_act == ICE_FWD_TO_VSI_LIST))
1203 return ICE_ERR_NOT_IMPL;
1204
1205 if (m_entry->vsi_count < 2 && !m_entry->vsi_list_info) {
1206
1207
1208
1209
1210 struct ice_fltr_info tmp_fltr;
1211 u16 vsi_handle_arr[2];
1212
1213
1214 if (cur_fltr->fwd_id.hw_vsi_id == new_fltr->fwd_id.hw_vsi_id)
1215 return ICE_ERR_ALREADY_EXISTS;
1216
1217 vsi_handle_arr[0] = cur_fltr->vsi_handle;
1218 vsi_handle_arr[1] = new_fltr->vsi_handle;
1219 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1220 &vsi_list_id,
1221 new_fltr->lkup_type);
1222 if (status)
1223 return status;
1224
1225 tmp_fltr = *new_fltr;
1226 tmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;
1227 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1228 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1229
1230
1231
1232 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1233 if (status)
1234 return status;
1235
1236 cur_fltr->fwd_id.vsi_list_id = vsi_list_id;
1237 cur_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1238 m_entry->vsi_list_info =
1239 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1240 vsi_list_id);
1241
1242
1243
1244
1245 if (m_entry->sw_marker_id != ICE_INVAL_SW_MARKER_ID)
1246 status =
1247 ice_add_marker_act(hw, m_entry,
1248 m_entry->sw_marker_id,
1249 m_entry->lg_act_idx);
1250 } else {
1251 u16 vsi_handle = new_fltr->vsi_handle;
1252 enum ice_adminq_opc opcode;
1253
1254 if (!m_entry->vsi_list_info)
1255 return ICE_ERR_CFG;
1256
1257
1258 if (test_bit(vsi_handle, m_entry->vsi_list_info->vsi_map))
1259 return 0;
1260
1261
1262
1263
1264 vsi_list_id = cur_fltr->fwd_id.vsi_list_id;
1265 opcode = ice_aqc_opc_update_sw_rules;
1266
1267 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1,
1268 vsi_list_id, false, opcode,
1269 new_fltr->lkup_type);
1270
1271 if (!status)
1272 set_bit(vsi_handle, m_entry->vsi_list_info->vsi_map);
1273 }
1274 if (!status)
1275 m_entry->vsi_count++;
1276 return status;
1277}
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288static struct ice_fltr_mgmt_list_entry *
1289ice_find_rule_entry(struct ice_hw *hw, u8 recp_id, struct ice_fltr_info *f_info)
1290{
1291 struct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;
1292 struct ice_switch_info *sw = hw->switch_info;
1293 struct list_head *list_head;
1294
1295 list_head = &sw->recp_list[recp_id].filt_rules;
1296 list_for_each_entry(list_itr, list_head, list_entry) {
1297 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
1298 sizeof(f_info->l_data)) &&
1299 f_info->flag == list_itr->fltr_info.flag) {
1300 ret = list_itr;
1301 break;
1302 }
1303 }
1304 return ret;
1305}
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318static struct ice_vsi_list_map_info *
1319ice_find_vsi_list_entry(struct ice_hw *hw, u8 recp_id, u16 vsi_handle,
1320 u16 *vsi_list_id)
1321{
1322 struct ice_vsi_list_map_info *map_info = NULL;
1323 struct ice_switch_info *sw = hw->switch_info;
1324 struct ice_fltr_mgmt_list_entry *list_itr;
1325 struct list_head *list_head;
1326
1327 list_head = &sw->recp_list[recp_id].filt_rules;
1328 list_for_each_entry(list_itr, list_head, list_entry) {
1329 if (list_itr->vsi_count == 1 && list_itr->vsi_list_info) {
1330 map_info = list_itr->vsi_list_info;
1331 if (test_bit(vsi_handle, map_info->vsi_map)) {
1332 *vsi_list_id = map_info->vsi_list_id;
1333 return map_info;
1334 }
1335 }
1336 }
1337 return NULL;
1338}
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348static enum ice_status
1349ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,
1350 struct ice_fltr_list_entry *f_entry)
1351{
1352 struct ice_switch_info *sw = hw->switch_info;
1353 struct ice_fltr_info *new_fltr, *cur_fltr;
1354 struct ice_fltr_mgmt_list_entry *m_entry;
1355 struct mutex *rule_lock;
1356 enum ice_status status = 0;
1357
1358 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1359 return ICE_ERR_PARAM;
1360 f_entry->fltr_info.fwd_id.hw_vsi_id =
1361 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1362
1363 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1364
1365 mutex_lock(rule_lock);
1366 new_fltr = &f_entry->fltr_info;
1367 if (new_fltr->flag & ICE_FLTR_RX)
1368 new_fltr->src = hw->port_info->lport;
1369 else if (new_fltr->flag & ICE_FLTR_TX)
1370 new_fltr->src = f_entry->fltr_info.fwd_id.hw_vsi_id;
1371
1372 m_entry = ice_find_rule_entry(hw, recp_id, new_fltr);
1373 if (!m_entry) {
1374 mutex_unlock(rule_lock);
1375 return ice_create_pkt_fwd_rule(hw, f_entry);
1376 }
1377
1378 cur_fltr = &m_entry->fltr_info;
1379 status = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);
1380 mutex_unlock(rule_lock);
1381
1382 return status;
1383}
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394static enum ice_status
1395ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,
1396 enum ice_sw_lkup_type lkup_type)
1397{
1398 struct ice_aqc_sw_rules_elem *s_rule;
1399 enum ice_status status;
1400 u16 s_rule_size;
1401
1402 s_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);
1403 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
1404 if (!s_rule)
1405 return ICE_ERR_NO_MEMORY;
1406
1407 s_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);
1408 s_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);
1409
1410
1411
1412
1413 status = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,
1414 ice_aqc_opc_free_res);
1415
1416 devm_kfree(ice_hw_to_dev(hw), s_rule);
1417 return status;
1418}
1419
1420
1421
1422
1423
1424
1425
1426
1427static enum ice_status
1428ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_handle,
1429 struct ice_fltr_mgmt_list_entry *fm_list)
1430{
1431 enum ice_sw_lkup_type lkup_type;
1432 enum ice_status status = 0;
1433 u16 vsi_list_id;
1434
1435 if (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||
1436 fm_list->vsi_count == 0)
1437 return ICE_ERR_PARAM;
1438
1439
1440 if (!test_bit(vsi_handle, fm_list->vsi_list_info->vsi_map))
1441 return ICE_ERR_DOES_NOT_EXIST;
1442
1443 lkup_type = fm_list->fltr_info.lkup_type;
1444 vsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;
1445 status = ice_update_vsi_list_rule(hw, &vsi_handle, 1, vsi_list_id, true,
1446 ice_aqc_opc_update_sw_rules,
1447 lkup_type);
1448 if (status)
1449 return status;
1450
1451 fm_list->vsi_count--;
1452 clear_bit(vsi_handle, fm_list->vsi_list_info->vsi_map);
1453
1454 if (fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) {
1455 struct ice_fltr_info tmp_fltr_info = fm_list->fltr_info;
1456 struct ice_vsi_list_map_info *vsi_list_info =
1457 fm_list->vsi_list_info;
1458 u16 rem_vsi_handle;
1459
1460 rem_vsi_handle = find_first_bit(vsi_list_info->vsi_map,
1461 ICE_MAX_VSI);
1462 if (!ice_is_vsi_valid(hw, rem_vsi_handle))
1463 return ICE_ERR_OUT_OF_RANGE;
1464
1465
1466 status = ice_update_vsi_list_rule(hw, &rem_vsi_handle, 1,
1467 vsi_list_id, true,
1468 ice_aqc_opc_update_sw_rules,
1469 lkup_type);
1470 if (status)
1471 return status;
1472
1473 tmp_fltr_info.fltr_act = ICE_FWD_TO_VSI;
1474 tmp_fltr_info.fwd_id.hw_vsi_id =
1475 ice_get_hw_vsi_num(hw, rem_vsi_handle);
1476 tmp_fltr_info.vsi_handle = rem_vsi_handle;
1477 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr_info);
1478 if (status) {
1479 ice_debug(hw, ICE_DBG_SW,
1480 "Failed to update pkt fwd rule to FWD_TO_VSI on HW VSI %d, error %d\n",
1481 tmp_fltr_info.fwd_id.hw_vsi_id, status);
1482 return status;
1483 }
1484
1485 fm_list->fltr_info = tmp_fltr_info;
1486 }
1487
1488 if ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||
1489 (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {
1490 struct ice_vsi_list_map_info *vsi_list_info =
1491 fm_list->vsi_list_info;
1492
1493
1494 status = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);
1495 if (status) {
1496 ice_debug(hw, ICE_DBG_SW,
1497 "Failed to remove VSI list %d, error %d\n",
1498 vsi_list_id, status);
1499 return status;
1500 }
1501
1502 list_del(&vsi_list_info->list_entry);
1503 devm_kfree(ice_hw_to_dev(hw), vsi_list_info);
1504 fm_list->vsi_list_info = NULL;
1505 }
1506
1507 return status;
1508}
1509
1510
1511
1512
1513
1514
1515
1516static enum ice_status
1517ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id,
1518 struct ice_fltr_list_entry *f_entry)
1519{
1520 struct ice_switch_info *sw = hw->switch_info;
1521 struct ice_fltr_mgmt_list_entry *list_elem;
1522 struct mutex *rule_lock;
1523 enum ice_status status = 0;
1524 bool remove_rule = false;
1525 u16 vsi_handle;
1526
1527 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1528 return ICE_ERR_PARAM;
1529 f_entry->fltr_info.fwd_id.hw_vsi_id =
1530 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1531
1532 rule_lock = &sw->recp_list[recp_id].filt_rule_lock;
1533 mutex_lock(rule_lock);
1534 list_elem = ice_find_rule_entry(hw, recp_id, &f_entry->fltr_info);
1535 if (!list_elem) {
1536 status = ICE_ERR_DOES_NOT_EXIST;
1537 goto exit;
1538 }
1539
1540 if (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {
1541 remove_rule = true;
1542 } else if (!list_elem->vsi_list_info) {
1543 status = ICE_ERR_DOES_NOT_EXIST;
1544 goto exit;
1545 } else if (list_elem->vsi_list_info->ref_cnt > 1) {
1546
1547
1548
1549
1550
1551 list_elem->vsi_list_info->ref_cnt--;
1552 remove_rule = true;
1553 } else {
1554
1555
1556
1557
1558
1559 vsi_handle = f_entry->fltr_info.vsi_handle;
1560 status = ice_rem_update_vsi_list(hw, vsi_handle, list_elem);
1561 if (status)
1562 goto exit;
1563
1564 if (list_elem->vsi_count == 0)
1565 remove_rule = true;
1566 }
1567
1568 if (remove_rule) {
1569
1570 struct ice_aqc_sw_rules_elem *s_rule;
1571
1572 s_rule = devm_kzalloc(ice_hw_to_dev(hw),
1573 ICE_SW_RULE_RX_TX_NO_HDR_SIZE,
1574 GFP_KERNEL);
1575 if (!s_rule) {
1576 status = ICE_ERR_NO_MEMORY;
1577 goto exit;
1578 }
1579
1580 ice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,
1581 ice_aqc_opc_remove_sw_rules);
1582
1583 status = ice_aq_sw_rules(hw, s_rule,
1584 ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,
1585 ice_aqc_opc_remove_sw_rules, NULL);
1586
1587
1588 devm_kfree(ice_hw_to_dev(hw), s_rule);
1589
1590 if (status)
1591 goto exit;
1592
1593 list_del(&list_elem->list_entry);
1594 devm_kfree(ice_hw_to_dev(hw), list_elem);
1595 }
1596exit:
1597 mutex_unlock(rule_lock);
1598 return status;
1599}
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612enum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_list)
1613{
1614 struct ice_aqc_sw_rules_elem *s_rule, *r_iter;
1615 struct ice_fltr_list_entry *m_list_itr;
1616 struct list_head *rule_head;
1617 u16 total_elem_left, s_rule_size;
1618 struct ice_switch_info *sw;
1619 struct mutex *rule_lock;
1620 enum ice_status status = 0;
1621 u16 num_unicast = 0;
1622 u8 elem_sent;
1623
1624 if (!m_list || !hw)
1625 return ICE_ERR_PARAM;
1626
1627 s_rule = NULL;
1628 sw = hw->switch_info;
1629 rule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
1630 list_for_each_entry(m_list_itr, m_list, list_entry) {
1631 u8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];
1632 u16 vsi_handle;
1633 u16 hw_vsi_id;
1634
1635 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
1636 vsi_handle = m_list_itr->fltr_info.vsi_handle;
1637 if (!ice_is_vsi_valid(hw, vsi_handle))
1638 return ICE_ERR_PARAM;
1639 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
1640 m_list_itr->fltr_info.fwd_id.hw_vsi_id = hw_vsi_id;
1641
1642 if (m_list_itr->fltr_info.src_id != ICE_SRC_ID_VSI)
1643 return ICE_ERR_PARAM;
1644 m_list_itr->fltr_info.src = hw_vsi_id;
1645 if (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||
1646 is_zero_ether_addr(add))
1647 return ICE_ERR_PARAM;
1648 if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
1649
1650 mutex_lock(rule_lock);
1651 if (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,
1652 &m_list_itr->fltr_info)) {
1653 mutex_unlock(rule_lock);
1654 return ICE_ERR_ALREADY_EXISTS;
1655 }
1656 mutex_unlock(rule_lock);
1657 num_unicast++;
1658 } else if (is_multicast_ether_addr(add) ||
1659 (is_unicast_ether_addr(add) && hw->ucast_shared)) {
1660 m_list_itr->status =
1661 ice_add_rule_internal(hw, ICE_SW_LKUP_MAC,
1662 m_list_itr);
1663 if (m_list_itr->status)
1664 return m_list_itr->status;
1665 }
1666 }
1667
1668 mutex_lock(rule_lock);
1669
1670 if (!num_unicast) {
1671 status = 0;
1672 goto ice_add_mac_exit;
1673 }
1674
1675 rule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;
1676
1677
1678 s_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;
1679 s_rule = devm_kcalloc(ice_hw_to_dev(hw), num_unicast, s_rule_size,
1680 GFP_KERNEL);
1681 if (!s_rule) {
1682 status = ICE_ERR_NO_MEMORY;
1683 goto ice_add_mac_exit;
1684 }
1685
1686 r_iter = s_rule;
1687 list_for_each_entry(m_list_itr, m_list, list_entry) {
1688 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
1689 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
1690
1691 if (is_unicast_ether_addr(mac_addr)) {
1692 ice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,
1693 ice_aqc_opc_add_sw_rules);
1694 r_iter = (struct ice_aqc_sw_rules_elem *)
1695 ((u8 *)r_iter + s_rule_size);
1696 }
1697 }
1698
1699
1700 r_iter = s_rule;
1701
1702 for (total_elem_left = num_unicast; total_elem_left > 0;
1703 total_elem_left -= elem_sent) {
1704 struct ice_aqc_sw_rules_elem *entry = r_iter;
1705
1706 elem_sent = min_t(u8, total_elem_left,
1707 (ICE_AQ_MAX_BUF_LEN / s_rule_size));
1708 status = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,
1709 elem_sent, ice_aqc_opc_add_sw_rules,
1710 NULL);
1711 if (status)
1712 goto ice_add_mac_exit;
1713 r_iter = (struct ice_aqc_sw_rules_elem *)
1714 ((u8 *)r_iter + (elem_sent * s_rule_size));
1715 }
1716
1717
1718 r_iter = s_rule;
1719 list_for_each_entry(m_list_itr, m_list, list_entry) {
1720 struct ice_fltr_info *f_info = &m_list_itr->fltr_info;
1721 u8 *mac_addr = &f_info->l_data.mac.mac_addr[0];
1722 struct ice_fltr_mgmt_list_entry *fm_entry;
1723
1724 if (is_unicast_ether_addr(mac_addr)) {
1725 f_info->fltr_rule_id =
1726 le16_to_cpu(r_iter->pdata.lkup_tx_rx.index);
1727 f_info->fltr_act = ICE_FWD_TO_VSI;
1728
1729 fm_entry = devm_kzalloc(ice_hw_to_dev(hw),
1730 sizeof(*fm_entry), GFP_KERNEL);
1731 if (!fm_entry) {
1732 status = ICE_ERR_NO_MEMORY;
1733 goto ice_add_mac_exit;
1734 }
1735 fm_entry->fltr_info = *f_info;
1736 fm_entry->vsi_count = 1;
1737
1738
1739
1740
1741 list_add(&fm_entry->list_entry, rule_head);
1742 r_iter = (struct ice_aqc_sw_rules_elem *)
1743 ((u8 *)r_iter + s_rule_size);
1744 }
1745 }
1746
1747ice_add_mac_exit:
1748 mutex_unlock(rule_lock);
1749 if (s_rule)
1750 devm_kfree(ice_hw_to_dev(hw), s_rule);
1751 return status;
1752}
1753
1754
1755
1756
1757
1758
1759static enum ice_status
1760ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)
1761{
1762 struct ice_switch_info *sw = hw->switch_info;
1763 struct ice_fltr_mgmt_list_entry *v_list_itr;
1764 struct ice_fltr_info *new_fltr, *cur_fltr;
1765 enum ice_sw_lkup_type lkup_type;
1766 u16 vsi_list_id = 0, vsi_handle;
1767 struct mutex *rule_lock;
1768 enum ice_status status = 0;
1769
1770 if (!ice_is_vsi_valid(hw, f_entry->fltr_info.vsi_handle))
1771 return ICE_ERR_PARAM;
1772
1773 f_entry->fltr_info.fwd_id.hw_vsi_id =
1774 ice_get_hw_vsi_num(hw, f_entry->fltr_info.vsi_handle);
1775 new_fltr = &f_entry->fltr_info;
1776
1777
1778 if (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)
1779 return ICE_ERR_PARAM;
1780
1781 if (new_fltr->src_id != ICE_SRC_ID_VSI)
1782 return ICE_ERR_PARAM;
1783
1784 new_fltr->src = new_fltr->fwd_id.hw_vsi_id;
1785 lkup_type = new_fltr->lkup_type;
1786 vsi_handle = new_fltr->vsi_handle;
1787 rule_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
1788 mutex_lock(rule_lock);
1789 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN, new_fltr);
1790 if (!v_list_itr) {
1791 struct ice_vsi_list_map_info *map_info = NULL;
1792
1793 if (new_fltr->fltr_act == ICE_FWD_TO_VSI) {
1794
1795
1796
1797
1798
1799 map_info = ice_find_vsi_list_entry(hw, ICE_SW_LKUP_VLAN,
1800 vsi_handle,
1801 &vsi_list_id);
1802 if (!map_info) {
1803 status = ice_create_vsi_list_rule(hw,
1804 &vsi_handle,
1805 1,
1806 &vsi_list_id,
1807 lkup_type);
1808 if (status)
1809 goto exit;
1810 }
1811
1812 new_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;
1813 new_fltr->fwd_id.vsi_list_id = vsi_list_id;
1814 }
1815
1816 status = ice_create_pkt_fwd_rule(hw, f_entry);
1817 if (!status) {
1818 v_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN,
1819 new_fltr);
1820 if (!v_list_itr) {
1821 status = ICE_ERR_DOES_NOT_EXIST;
1822 goto exit;
1823 }
1824
1825 if (map_info) {
1826 v_list_itr->vsi_list_info = map_info;
1827 map_info->ref_cnt++;
1828 } else {
1829 v_list_itr->vsi_list_info =
1830 ice_create_vsi_list_map(hw, &vsi_handle,
1831 1, vsi_list_id);
1832 }
1833 }
1834 } else if (v_list_itr->vsi_list_info->ref_cnt == 1) {
1835
1836
1837
1838 cur_fltr = &v_list_itr->fltr_info;
1839 status = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr,
1840 new_fltr);
1841 } else {
1842
1843
1844
1845
1846
1847 struct ice_fltr_info tmp_fltr;
1848 u16 vsi_handle_arr[2];
1849 u16 cur_handle;
1850
1851
1852
1853
1854 if (v_list_itr->vsi_count > 1 &&
1855 v_list_itr->vsi_list_info->ref_cnt > 1) {
1856 ice_debug(hw, ICE_DBG_SW,
1857 "Invalid configuration: Optimization to reuse VSI list with more than one VSI is not being done yet\n");
1858 status = ICE_ERR_CFG;
1859 goto exit;
1860 }
1861
1862 cur_handle =
1863 find_first_bit(v_list_itr->vsi_list_info->vsi_map,
1864 ICE_MAX_VSI);
1865
1866
1867 if (cur_handle == vsi_handle) {
1868 status = ICE_ERR_ALREADY_EXISTS;
1869 goto exit;
1870 }
1871
1872 vsi_handle_arr[0] = cur_handle;
1873 vsi_handle_arr[1] = vsi_handle;
1874 status = ice_create_vsi_list_rule(hw, &vsi_handle_arr[0], 2,
1875 &vsi_list_id, lkup_type);
1876 if (status)
1877 goto exit;
1878
1879 tmp_fltr = v_list_itr->fltr_info;
1880 tmp_fltr.fltr_rule_id = v_list_itr->fltr_info.fltr_rule_id;
1881 tmp_fltr.fwd_id.vsi_list_id = vsi_list_id;
1882 tmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;
1883
1884
1885
1886 status = ice_update_pkt_fwd_rule(hw, &tmp_fltr);
1887 if (status)
1888 goto exit;
1889
1890
1891
1892
1893 v_list_itr->vsi_list_info->ref_cnt--;
1894
1895
1896 v_list_itr->fltr_info.fwd_id.vsi_list_id = vsi_list_id;
1897 v_list_itr->vsi_list_info =
1898 ice_create_vsi_list_map(hw, &vsi_handle_arr[0], 2,
1899 vsi_list_id);
1900 v_list_itr->vsi_count++;
1901 }
1902
1903exit:
1904 mutex_unlock(rule_lock);
1905 return status;
1906}
1907
1908
1909
1910
1911
1912
1913enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *v_list)
1914{
1915 struct ice_fltr_list_entry *v_list_itr;
1916
1917 if (!v_list || !hw)
1918 return ICE_ERR_PARAM;
1919
1920 list_for_each_entry(v_list_itr, v_list, list_entry) {
1921 if (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)
1922 return ICE_ERR_PARAM;
1923 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1924 v_list_itr->status = ice_add_vlan_internal(hw, v_list_itr);
1925 if (v_list_itr->status)
1926 return v_list_itr->status;
1927 }
1928 return 0;
1929}
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940enum ice_status
1941ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list)
1942{
1943 struct ice_fltr_list_entry *em_list_itr;
1944
1945 if (!em_list || !hw)
1946 return ICE_ERR_PARAM;
1947
1948 list_for_each_entry(em_list_itr, em_list, list_entry) {
1949 enum ice_sw_lkup_type l_type =
1950 em_list_itr->fltr_info.lkup_type;
1951
1952 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
1953 l_type != ICE_SW_LKUP_ETHERTYPE)
1954 return ICE_ERR_PARAM;
1955
1956 em_list_itr->status = ice_add_rule_internal(hw, l_type,
1957 em_list_itr);
1958 if (em_list_itr->status)
1959 return em_list_itr->status;
1960 }
1961 return 0;
1962}
1963
1964
1965
1966
1967
1968
1969enum ice_status
1970ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list)
1971{
1972 struct ice_fltr_list_entry *em_list_itr, *tmp;
1973
1974 if (!em_list || !hw)
1975 return ICE_ERR_PARAM;
1976
1977 list_for_each_entry_safe(em_list_itr, tmp, em_list, list_entry) {
1978 enum ice_sw_lkup_type l_type =
1979 em_list_itr->fltr_info.lkup_type;
1980
1981 if (l_type != ICE_SW_LKUP_ETHERTYPE_MAC &&
1982 l_type != ICE_SW_LKUP_ETHERTYPE)
1983 return ICE_ERR_PARAM;
1984
1985 em_list_itr->status = ice_remove_rule_internal(hw, l_type,
1986 em_list_itr);
1987 if (em_list_itr->status)
1988 return em_list_itr->status;
1989 }
1990 return 0;
1991}
1992
1993
1994
1995
1996
1997
1998static void
1999ice_rem_sw_rule_info(struct ice_hw *hw, struct list_head *rule_head)
2000{
2001 if (!list_empty(rule_head)) {
2002 struct ice_fltr_mgmt_list_entry *entry;
2003 struct ice_fltr_mgmt_list_entry *tmp;
2004
2005 list_for_each_entry_safe(entry, tmp, rule_head, list_entry) {
2006 list_del(&entry->list_entry);
2007 devm_kfree(ice_hw_to_dev(hw), entry);
2008 }
2009 }
2010}
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022enum ice_status
2023ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction)
2024{
2025 struct ice_aqc_sw_rules_elem *s_rule;
2026 struct ice_fltr_info f_info;
2027 enum ice_adminq_opc opcode;
2028 enum ice_status status;
2029 u16 s_rule_size;
2030 u16 hw_vsi_id;
2031
2032 if (!ice_is_vsi_valid(hw, vsi_handle))
2033 return ICE_ERR_PARAM;
2034 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2035
2036 s_rule_size = set ? ICE_SW_RULE_RX_TX_ETH_HDR_SIZE :
2037 ICE_SW_RULE_RX_TX_NO_HDR_SIZE;
2038
2039 s_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);
2040 if (!s_rule)
2041 return ICE_ERR_NO_MEMORY;
2042
2043 memset(&f_info, 0, sizeof(f_info));
2044
2045 f_info.lkup_type = ICE_SW_LKUP_DFLT;
2046 f_info.flag = direction;
2047 f_info.fltr_act = ICE_FWD_TO_VSI;
2048 f_info.fwd_id.hw_vsi_id = hw_vsi_id;
2049
2050 if (f_info.flag & ICE_FLTR_RX) {
2051 f_info.src = hw->port_info->lport;
2052 f_info.src_id = ICE_SRC_ID_LPORT;
2053 if (!set)
2054 f_info.fltr_rule_id =
2055 hw->port_info->dflt_rx_vsi_rule_id;
2056 } else if (f_info.flag & ICE_FLTR_TX) {
2057 f_info.src_id = ICE_SRC_ID_VSI;
2058 f_info.src = hw_vsi_id;
2059 if (!set)
2060 f_info.fltr_rule_id =
2061 hw->port_info->dflt_tx_vsi_rule_id;
2062 }
2063
2064 if (set)
2065 opcode = ice_aqc_opc_add_sw_rules;
2066 else
2067 opcode = ice_aqc_opc_remove_sw_rules;
2068
2069 ice_fill_sw_rule(hw, &f_info, s_rule, opcode);
2070
2071 status = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1, opcode, NULL);
2072 if (status || !(f_info.flag & ICE_FLTR_TX_RX))
2073 goto out;
2074 if (set) {
2075 u16 index = le16_to_cpu(s_rule->pdata.lkup_tx_rx.index);
2076
2077 if (f_info.flag & ICE_FLTR_TX) {
2078 hw->port_info->dflt_tx_vsi_num = hw_vsi_id;
2079 hw->port_info->dflt_tx_vsi_rule_id = index;
2080 } else if (f_info.flag & ICE_FLTR_RX) {
2081 hw->port_info->dflt_rx_vsi_num = hw_vsi_id;
2082 hw->port_info->dflt_rx_vsi_rule_id = index;
2083 }
2084 } else {
2085 if (f_info.flag & ICE_FLTR_TX) {
2086 hw->port_info->dflt_tx_vsi_num = ICE_DFLT_VSI_INVAL;
2087 hw->port_info->dflt_tx_vsi_rule_id = ICE_INVAL_ACT;
2088 } else if (f_info.flag & ICE_FLTR_RX) {
2089 hw->port_info->dflt_rx_vsi_num = ICE_DFLT_VSI_INVAL;
2090 hw->port_info->dflt_rx_vsi_rule_id = ICE_INVAL_ACT;
2091 }
2092 }
2093
2094out:
2095 devm_kfree(ice_hw_to_dev(hw), s_rule);
2096 return status;
2097}
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111static struct ice_fltr_mgmt_list_entry *
2112ice_find_ucast_rule_entry(struct ice_hw *hw, u8 recp_id,
2113 struct ice_fltr_info *f_info)
2114{
2115 struct ice_switch_info *sw = hw->switch_info;
2116 struct ice_fltr_mgmt_list_entry *list_itr;
2117 struct list_head *list_head;
2118
2119 list_head = &sw->recp_list[recp_id].filt_rules;
2120 list_for_each_entry(list_itr, list_head, list_entry) {
2121 if (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,
2122 sizeof(f_info->l_data)) &&
2123 f_info->fwd_id.hw_vsi_id ==
2124 list_itr->fltr_info.fwd_id.hw_vsi_id &&
2125 f_info->flag == list_itr->fltr_info.flag)
2126 return list_itr;
2127 }
2128 return NULL;
2129}
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144enum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_list)
2145{
2146 struct ice_fltr_list_entry *list_itr, *tmp;
2147 struct mutex *rule_lock;
2148
2149 if (!m_list)
2150 return ICE_ERR_PARAM;
2151
2152 rule_lock = &hw->switch_info->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;
2153 list_for_each_entry_safe(list_itr, tmp, m_list, list_entry) {
2154 enum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;
2155 u8 *add = &list_itr->fltr_info.l_data.mac.mac_addr[0];
2156 u16 vsi_handle;
2157
2158 if (l_type != ICE_SW_LKUP_MAC)
2159 return ICE_ERR_PARAM;
2160
2161 vsi_handle = list_itr->fltr_info.vsi_handle;
2162 if (!ice_is_vsi_valid(hw, vsi_handle))
2163 return ICE_ERR_PARAM;
2164
2165 list_itr->fltr_info.fwd_id.hw_vsi_id =
2166 ice_get_hw_vsi_num(hw, vsi_handle);
2167 if (is_unicast_ether_addr(add) && !hw->ucast_shared) {
2168
2169
2170
2171
2172 mutex_lock(rule_lock);
2173 if (!ice_find_ucast_rule_entry(hw, ICE_SW_LKUP_MAC,
2174 &list_itr->fltr_info)) {
2175 mutex_unlock(rule_lock);
2176 return ICE_ERR_DOES_NOT_EXIST;
2177 }
2178 mutex_unlock(rule_lock);
2179 }
2180 list_itr->status = ice_remove_rule_internal(hw,
2181 ICE_SW_LKUP_MAC,
2182 list_itr);
2183 if (list_itr->status)
2184 return list_itr->status;
2185 }
2186 return 0;
2187}
2188
2189
2190
2191
2192
2193
2194enum ice_status
2195ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list)
2196{
2197 struct ice_fltr_list_entry *v_list_itr, *tmp;
2198
2199 if (!v_list || !hw)
2200 return ICE_ERR_PARAM;
2201
2202 list_for_each_entry_safe(v_list_itr, tmp, v_list, list_entry) {
2203 enum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;
2204
2205 if (l_type != ICE_SW_LKUP_VLAN)
2206 return ICE_ERR_PARAM;
2207 v_list_itr->status = ice_remove_rule_internal(hw,
2208 ICE_SW_LKUP_VLAN,
2209 v_list_itr);
2210 if (v_list_itr->status)
2211 return v_list_itr->status;
2212 }
2213 return 0;
2214}
2215
2216
2217
2218
2219
2220
2221static bool
2222ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_handle)
2223{
2224 return ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&
2225 fm_entry->fltr_info.vsi_handle == vsi_handle) ||
2226 (fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&
2227 (test_bit(vsi_handle, fm_entry->vsi_list_info->vsi_map))));
2228}
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243static enum ice_status
2244ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2245 struct list_head *vsi_list_head,
2246 struct ice_fltr_info *fi)
2247{
2248 struct ice_fltr_list_entry *tmp;
2249
2250
2251
2252
2253 tmp = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*tmp), GFP_KERNEL);
2254 if (!tmp)
2255 return ICE_ERR_NO_MEMORY;
2256
2257 tmp->fltr_info = *fi;
2258
2259
2260
2261
2262
2263
2264 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2265 tmp->fltr_info.vsi_handle = vsi_handle;
2266 tmp->fltr_info.fwd_id.hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2267
2268 list_add(&tmp->list_entry, vsi_list_head);
2269
2270 return 0;
2271}
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286static enum ice_status
2287ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_handle,
2288 struct list_head *lkup_list_head,
2289 struct list_head *vsi_list_head)
2290{
2291 struct ice_fltr_mgmt_list_entry *fm_entry;
2292 enum ice_status status = 0;
2293
2294
2295 if (!ice_is_vsi_valid(hw, vsi_handle))
2296 return ICE_ERR_PARAM;
2297
2298 list_for_each_entry(fm_entry, lkup_list_head, list_entry) {
2299 struct ice_fltr_info *fi;
2300
2301 fi = &fm_entry->fltr_info;
2302 if (!fi || !ice_vsi_uses_fltr(fm_entry, vsi_handle))
2303 continue;
2304
2305 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2306 vsi_list_head, fi);
2307 if (status)
2308 return status;
2309 }
2310 return status;
2311}
2312
2313
2314
2315
2316
2317
2318
2319
2320static u8 ice_determine_promisc_mask(struct ice_fltr_info *fi)
2321{
2322 u16 vid = fi->l_data.mac_vlan.vlan_id;
2323 u8 *macaddr = fi->l_data.mac.mac_addr;
2324 bool is_tx_fltr = false;
2325 u8 promisc_mask = 0;
2326
2327 if (fi->flag == ICE_FLTR_TX)
2328 is_tx_fltr = true;
2329
2330 if (is_broadcast_ether_addr(macaddr))
2331 promisc_mask |= is_tx_fltr ?
2332 ICE_PROMISC_BCAST_TX : ICE_PROMISC_BCAST_RX;
2333 else if (is_multicast_ether_addr(macaddr))
2334 promisc_mask |= is_tx_fltr ?
2335 ICE_PROMISC_MCAST_TX : ICE_PROMISC_MCAST_RX;
2336 else if (is_unicast_ether_addr(macaddr))
2337 promisc_mask |= is_tx_fltr ?
2338 ICE_PROMISC_UCAST_TX : ICE_PROMISC_UCAST_RX;
2339 if (vid)
2340 promisc_mask |= is_tx_fltr ?
2341 ICE_PROMISC_VLAN_TX : ICE_PROMISC_VLAN_RX;
2342
2343 return promisc_mask;
2344}
2345
2346
2347
2348
2349
2350
2351
2352static enum ice_status
2353ice_remove_promisc(struct ice_hw *hw, u8 recp_id,
2354 struct list_head *v_list)
2355{
2356 struct ice_fltr_list_entry *v_list_itr, *tmp;
2357
2358 list_for_each_entry_safe(v_list_itr, tmp, v_list, list_entry) {
2359 v_list_itr->status =
2360 ice_remove_rule_internal(hw, recp_id, v_list_itr);
2361 if (v_list_itr->status)
2362 return v_list_itr->status;
2363 }
2364 return 0;
2365}
2366
2367
2368
2369
2370
2371
2372
2373
2374enum ice_status
2375ice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2376 u16 vid)
2377{
2378 struct ice_switch_info *sw = hw->switch_info;
2379 struct ice_fltr_list_entry *fm_entry, *tmp;
2380 struct list_head remove_list_head;
2381 struct ice_fltr_mgmt_list_entry *itr;
2382 struct list_head *rule_head;
2383 struct mutex *rule_lock;
2384 enum ice_status status = 0;
2385 u8 recipe_id;
2386
2387 if (!ice_is_vsi_valid(hw, vsi_handle))
2388 return ICE_ERR_PARAM;
2389
2390 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX))
2391 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2392 else
2393 recipe_id = ICE_SW_LKUP_PROMISC;
2394
2395 rule_head = &sw->recp_list[recipe_id].filt_rules;
2396 rule_lock = &sw->recp_list[recipe_id].filt_rule_lock;
2397
2398 INIT_LIST_HEAD(&remove_list_head);
2399
2400 mutex_lock(rule_lock);
2401 list_for_each_entry(itr, rule_head, list_entry) {
2402 struct ice_fltr_info *fltr_info;
2403 u8 fltr_promisc_mask = 0;
2404
2405 if (!ice_vsi_uses_fltr(itr, vsi_handle))
2406 continue;
2407 fltr_info = &itr->fltr_info;
2408
2409 if (recipe_id == ICE_SW_LKUP_PROMISC_VLAN &&
2410 vid != fltr_info->l_data.mac_vlan.vlan_id)
2411 continue;
2412
2413 fltr_promisc_mask |= ice_determine_promisc_mask(fltr_info);
2414
2415
2416 if (fltr_promisc_mask & ~promisc_mask)
2417 continue;
2418
2419 status = ice_add_entry_to_vsi_fltr_list(hw, vsi_handle,
2420 &remove_list_head,
2421 fltr_info);
2422 if (status) {
2423 mutex_unlock(rule_lock);
2424 goto free_fltr_list;
2425 }
2426 }
2427 mutex_unlock(rule_lock);
2428
2429 status = ice_remove_promisc(hw, recipe_id, &remove_list_head);
2430
2431free_fltr_list:
2432 list_for_each_entry_safe(fm_entry, tmp, &remove_list_head, list_entry) {
2433 list_del(&fm_entry->list_entry);
2434 devm_kfree(ice_hw_to_dev(hw), fm_entry);
2435 }
2436
2437 return status;
2438}
2439
2440
2441
2442
2443
2444
2445
2446
2447enum ice_status
2448ice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, u16 vid)
2449{
2450 enum { UCAST_FLTR = 1, MCAST_FLTR, BCAST_FLTR };
2451 struct ice_fltr_list_entry f_list_entry;
2452 struct ice_fltr_info new_fltr;
2453 enum ice_status status = 0;
2454 bool is_tx_fltr;
2455 u16 hw_vsi_id;
2456 int pkt_type;
2457 u8 recipe_id;
2458
2459 if (!ice_is_vsi_valid(hw, vsi_handle))
2460 return ICE_ERR_PARAM;
2461 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2462
2463 memset(&new_fltr, 0, sizeof(new_fltr));
2464
2465 if (promisc_mask & (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX)) {
2466 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC_VLAN;
2467 new_fltr.l_data.mac_vlan.vlan_id = vid;
2468 recipe_id = ICE_SW_LKUP_PROMISC_VLAN;
2469 } else {
2470 new_fltr.lkup_type = ICE_SW_LKUP_PROMISC;
2471 recipe_id = ICE_SW_LKUP_PROMISC;
2472 }
2473
2474
2475
2476
2477
2478
2479 while (promisc_mask) {
2480 u8 *mac_addr;
2481
2482 pkt_type = 0;
2483 is_tx_fltr = false;
2484
2485 if (promisc_mask & ICE_PROMISC_UCAST_RX) {
2486 promisc_mask &= ~ICE_PROMISC_UCAST_RX;
2487 pkt_type = UCAST_FLTR;
2488 } else if (promisc_mask & ICE_PROMISC_UCAST_TX) {
2489 promisc_mask &= ~ICE_PROMISC_UCAST_TX;
2490 pkt_type = UCAST_FLTR;
2491 is_tx_fltr = true;
2492 } else if (promisc_mask & ICE_PROMISC_MCAST_RX) {
2493 promisc_mask &= ~ICE_PROMISC_MCAST_RX;
2494 pkt_type = MCAST_FLTR;
2495 } else if (promisc_mask & ICE_PROMISC_MCAST_TX) {
2496 promisc_mask &= ~ICE_PROMISC_MCAST_TX;
2497 pkt_type = MCAST_FLTR;
2498 is_tx_fltr = true;
2499 } else if (promisc_mask & ICE_PROMISC_BCAST_RX) {
2500 promisc_mask &= ~ICE_PROMISC_BCAST_RX;
2501 pkt_type = BCAST_FLTR;
2502 } else if (promisc_mask & ICE_PROMISC_BCAST_TX) {
2503 promisc_mask &= ~ICE_PROMISC_BCAST_TX;
2504 pkt_type = BCAST_FLTR;
2505 is_tx_fltr = true;
2506 }
2507
2508
2509 if (promisc_mask & ICE_PROMISC_VLAN_RX) {
2510 promisc_mask &= ~ICE_PROMISC_VLAN_RX;
2511 } else if (promisc_mask & ICE_PROMISC_VLAN_TX) {
2512 promisc_mask &= ~ICE_PROMISC_VLAN_TX;
2513 is_tx_fltr = true;
2514 }
2515
2516
2517 mac_addr = new_fltr.l_data.mac.mac_addr;
2518 if (pkt_type == BCAST_FLTR) {
2519 eth_broadcast_addr(mac_addr);
2520 } else if (pkt_type == MCAST_FLTR ||
2521 pkt_type == UCAST_FLTR) {
2522
2523 ether_addr_copy(mac_addr, dummy_eth_header);
2524 if (pkt_type == MCAST_FLTR)
2525 mac_addr[0] |= 0x1;
2526 }
2527
2528
2529 new_fltr.flag = 0;
2530 if (is_tx_fltr) {
2531 new_fltr.flag |= ICE_FLTR_TX;
2532 new_fltr.src = hw_vsi_id;
2533 } else {
2534 new_fltr.flag |= ICE_FLTR_RX;
2535 new_fltr.src = hw->port_info->lport;
2536 }
2537
2538 new_fltr.fltr_act = ICE_FWD_TO_VSI;
2539 new_fltr.vsi_handle = vsi_handle;
2540 new_fltr.fwd_id.hw_vsi_id = hw_vsi_id;
2541 f_list_entry.fltr_info = new_fltr;
2542
2543 status = ice_add_rule_internal(hw, recipe_id, &f_list_entry);
2544 if (status)
2545 goto set_promisc_exit;
2546 }
2547
2548set_promisc_exit:
2549 return status;
2550}
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561enum ice_status
2562ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
2563 bool rm_vlan_promisc)
2564{
2565 struct ice_switch_info *sw = hw->switch_info;
2566 struct ice_fltr_list_entry *list_itr, *tmp;
2567 struct list_head vsi_list_head;
2568 struct list_head *vlan_head;
2569 struct mutex *vlan_lock;
2570 enum ice_status status;
2571 u16 vlan_id;
2572
2573 INIT_LIST_HEAD(&vsi_list_head);
2574 vlan_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;
2575 vlan_head = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rules;
2576 mutex_lock(vlan_lock);
2577 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, vlan_head,
2578 &vsi_list_head);
2579 mutex_unlock(vlan_lock);
2580 if (status)
2581 goto free_fltr_list;
2582
2583 list_for_each_entry(list_itr, &vsi_list_head, list_entry) {
2584 vlan_id = list_itr->fltr_info.l_data.vlan.vlan_id;
2585 if (rm_vlan_promisc)
2586 status = ice_clear_vsi_promisc(hw, vsi_handle,
2587 promisc_mask, vlan_id);
2588 else
2589 status = ice_set_vsi_promisc(hw, vsi_handle,
2590 promisc_mask, vlan_id);
2591 if (status)
2592 break;
2593 }
2594
2595free_fltr_list:
2596 list_for_each_entry_safe(list_itr, tmp, &vsi_list_head, list_entry) {
2597 list_del(&list_itr->list_entry);
2598 devm_kfree(ice_hw_to_dev(hw), list_itr);
2599 }
2600 return status;
2601}
2602
2603
2604
2605
2606
2607
2608
2609static void
2610ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_handle,
2611 enum ice_sw_lkup_type lkup)
2612{
2613 struct ice_switch_info *sw = hw->switch_info;
2614 struct ice_fltr_list_entry *fm_entry;
2615 struct list_head remove_list_head;
2616 struct list_head *rule_head;
2617 struct ice_fltr_list_entry *tmp;
2618 struct mutex *rule_lock;
2619 enum ice_status status;
2620
2621 INIT_LIST_HEAD(&remove_list_head);
2622 rule_lock = &sw->recp_list[lkup].filt_rule_lock;
2623 rule_head = &sw->recp_list[lkup].filt_rules;
2624 mutex_lock(rule_lock);
2625 status = ice_add_to_vsi_fltr_list(hw, vsi_handle, rule_head,
2626 &remove_list_head);
2627 mutex_unlock(rule_lock);
2628 if (status)
2629 return;
2630
2631 switch (lkup) {
2632 case ICE_SW_LKUP_MAC:
2633 ice_remove_mac(hw, &remove_list_head);
2634 break;
2635 case ICE_SW_LKUP_VLAN:
2636 ice_remove_vlan(hw, &remove_list_head);
2637 break;
2638 case ICE_SW_LKUP_PROMISC:
2639 case ICE_SW_LKUP_PROMISC_VLAN:
2640 ice_remove_promisc(hw, lkup, &remove_list_head);
2641 break;
2642 case ICE_SW_LKUP_MAC_VLAN:
2643 case ICE_SW_LKUP_ETHERTYPE:
2644 case ICE_SW_LKUP_ETHERTYPE_MAC:
2645 case ICE_SW_LKUP_DFLT:
2646 case ICE_SW_LKUP_LAST:
2647 default:
2648 ice_debug(hw, ICE_DBG_SW, "Unsupported lookup type %d\n", lkup);
2649 break;
2650 }
2651
2652 list_for_each_entry_safe(fm_entry, tmp, &remove_list_head, list_entry) {
2653 list_del(&fm_entry->list_entry);
2654 devm_kfree(ice_hw_to_dev(hw), fm_entry);
2655 }
2656}
2657
2658
2659
2660
2661
2662
2663void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle)
2664{
2665 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC);
2666 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_MAC_VLAN);
2667 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC);
2668 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_VLAN);
2669 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_DFLT);
2670 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE);
2671 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_ETHERTYPE_MAC);
2672 ice_remove_vsi_lkup_fltr(hw, vsi_handle, ICE_SW_LKUP_PROMISC_VLAN);
2673}
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683enum ice_status
2684ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
2685 u16 *counter_id)
2686{
2687 struct ice_aqc_alloc_free_res_elem *buf;
2688 enum ice_status status;
2689 u16 buf_len;
2690
2691
2692 buf_len = struct_size(buf, elem, 1);
2693 buf = kzalloc(buf_len, GFP_KERNEL);
2694 if (!buf)
2695 return ICE_ERR_NO_MEMORY;
2696
2697 buf->num_elems = cpu_to_le16(num_items);
2698 buf->res_type = cpu_to_le16(((type << ICE_AQC_RES_TYPE_S) &
2699 ICE_AQC_RES_TYPE_M) | alloc_shared);
2700
2701 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
2702 ice_aqc_opc_alloc_res, NULL);
2703 if (status)
2704 goto exit;
2705
2706 *counter_id = le16_to_cpu(buf->elem[0].e.sw_resp);
2707
2708exit:
2709 kfree(buf);
2710 return status;
2711}
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721enum ice_status
2722ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
2723 u16 counter_id)
2724{
2725 struct ice_aqc_alloc_free_res_elem *buf;
2726 enum ice_status status;
2727 u16 buf_len;
2728
2729
2730 buf_len = struct_size(buf, elem, 1);
2731 buf = kzalloc(buf_len, GFP_KERNEL);
2732 if (!buf)
2733 return ICE_ERR_NO_MEMORY;
2734
2735 buf->num_elems = cpu_to_le16(num_items);
2736 buf->res_type = cpu_to_le16(((type << ICE_AQC_RES_TYPE_S) &
2737 ICE_AQC_RES_TYPE_M) | alloc_shared);
2738 buf->elem[0].e.sw_resp = cpu_to_le16(counter_id);
2739
2740 status = ice_aq_alloc_free_res(hw, 1, buf, buf_len,
2741 ice_aqc_opc_free_res, NULL);
2742 if (status)
2743 ice_debug(hw, ICE_DBG_SW,
2744 "counter resource could not be freed\n");
2745
2746 kfree(buf);
2747 return status;
2748}
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760static enum ice_status
2761ice_replay_vsi_fltr(struct ice_hw *hw, u16 vsi_handle, u8 recp_id,
2762 struct list_head *list_head)
2763{
2764 struct ice_fltr_mgmt_list_entry *itr;
2765 enum ice_status status = 0;
2766 u16 hw_vsi_id;
2767
2768 if (list_empty(list_head))
2769 return status;
2770 hw_vsi_id = ice_get_hw_vsi_num(hw, vsi_handle);
2771
2772 list_for_each_entry(itr, list_head, list_entry) {
2773 struct ice_fltr_list_entry f_entry;
2774
2775 f_entry.fltr_info = itr->fltr_info;
2776 if (itr->vsi_count < 2 && recp_id != ICE_SW_LKUP_VLAN &&
2777 itr->fltr_info.vsi_handle == vsi_handle) {
2778
2779 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
2780 f_entry.fltr_info.src = hw_vsi_id;
2781 status = ice_add_rule_internal(hw, recp_id, &f_entry);
2782 if (status)
2783 goto end;
2784 continue;
2785 }
2786 if (!itr->vsi_list_info ||
2787 !test_bit(vsi_handle, itr->vsi_list_info->vsi_map))
2788 continue;
2789
2790 clear_bit(vsi_handle, itr->vsi_list_info->vsi_map);
2791 f_entry.fltr_info.vsi_handle = vsi_handle;
2792 f_entry.fltr_info.fltr_act = ICE_FWD_TO_VSI;
2793
2794 if (f_entry.fltr_info.src_id == ICE_SRC_ID_VSI)
2795 f_entry.fltr_info.src = hw_vsi_id;
2796 if (recp_id == ICE_SW_LKUP_VLAN)
2797 status = ice_add_vlan_internal(hw, &f_entry);
2798 else
2799 status = ice_add_rule_internal(hw, recp_id, &f_entry);
2800 if (status)
2801 goto end;
2802 }
2803end:
2804 return status;
2805}
2806
2807
2808
2809
2810
2811
2812
2813
2814enum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle)
2815{
2816 struct ice_switch_info *sw = hw->switch_info;
2817 enum ice_status status = 0;
2818 u8 i;
2819
2820 for (i = 0; i < ICE_SW_LKUP_LAST; i++) {
2821 struct list_head *head;
2822
2823 head = &sw->recp_list[i].filt_replay_rules;
2824 status = ice_replay_vsi_fltr(hw, vsi_handle, i, head);
2825 if (status)
2826 return status;
2827 }
2828 return status;
2829}
2830
2831
2832
2833
2834
2835
2836
2837void ice_rm_all_sw_replay_rule_info(struct ice_hw *hw)
2838{
2839 struct ice_switch_info *sw = hw->switch_info;
2840 u8 i;
2841
2842 if (!sw)
2843 return;
2844
2845 for (i = 0; i < ICE_SW_LKUP_LAST; i++) {
2846 if (!list_empty(&sw->recp_list[i].filt_replay_rules)) {
2847 struct list_head *l_head;
2848
2849 l_head = &sw->recp_list[i].filt_replay_rules;
2850 ice_rem_sw_rule_info(hw, l_head);
2851 }
2852 }
2853}
2854