1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_malloc.h>
8 #include "otx2_ethdev.h"
12 #define VLAN_ID_MATCH 0x1
13 #define VTAG_F_MATCH 0x2
14 #define MAC_ADDR_MATCH 0x4
15 #define QINQ_F_MATCH 0x8
16 #define VLAN_DROP 0x10
17 #define DEF_F_ENTRY 0x20
25 nix_vlan_mcam_enb_dis(struct otx2_eth_dev *dev,
26 uint32_t entry, const int enable)
28 struct npc_mcam_ena_dis_entry_req *req;
29 struct otx2_mbox *mbox = dev->mbox;
33 req = otx2_mbox_alloc_msg_npc_mcam_ena_entry(mbox);
35 req = otx2_mbox_alloc_msg_npc_mcam_dis_entry(mbox);
39 rc = otx2_mbox_process_msg(mbox, NULL);
44 nix_set_rx_vlan_action(struct rte_eth_dev *eth_dev,
45 struct mcam_entry *entry, bool qinq, bool drop)
47 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
48 int pcifunc = otx2_pfvf_func(dev->pf, dev->vf);
49 uint64_t action = 0, vtag_action = 0;
51 action = NIX_RX_ACTIONOP_UCAST;
53 if (eth_dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
54 action = NIX_RX_ACTIONOP_RSS;
55 action |= (uint64_t)(dev->rss_info.alg_idx) << 56;
58 action |= (uint64_t)pcifunc << 4;
59 entry->action = action;
62 entry->action &= ~((uint64_t)0xF);
63 entry->action |= NIX_RX_ACTIONOP_DROP;
68 /* VTAG0 fields denote CTAG in single vlan case */
69 vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
70 vtag_action |= (NPC_LID_LB << 8);
71 vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
73 /* VTAG0 & VTAG1 fields denote CTAG & STAG respectively */
74 vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
75 vtag_action |= (NPC_LID_LB << 8);
76 vtag_action |= NIX_RX_VTAGACTION_VTAG1_RELPTR;
77 vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 47);
78 vtag_action |= ((uint64_t)(NPC_LID_LB) << 40);
79 vtag_action |= (NIX_RX_VTAGACTION_VTAG0_RELPTR << 32);
82 entry->vtag_action = vtag_action;
86 nix_set_tx_vlan_action(struct mcam_entry *entry, enum rte_vlan_type type,
91 struct nix_tx_vtag_action_s act;
96 action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
99 * Take offset from LA since in case of untagged packet,
102 if (type == ETH_VLAN_TYPE_OUTER) {
103 vtag_action.act.vtag0_def = vtag_index;
104 vtag_action.act.vtag0_lid = NPC_LID_LA;
105 vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
106 vtag_action.act.vtag0_relptr = NIX_TX_VTAGACTION_VTAG0_RELPTR;
108 vtag_action.act.vtag1_def = vtag_index;
109 vtag_action.act.vtag1_lid = NPC_LID_LA;
110 vtag_action.act.vtag1_op = NIX_TX_VTAGOP_INSERT;
111 vtag_action.act.vtag1_relptr = NIX_TX_VTAGACTION_VTAG1_RELPTR;
114 entry->action = action;
115 entry->vtag_action = vtag_action.reg;
119 nix_vlan_mcam_free(struct otx2_eth_dev *dev, uint32_t entry)
121 struct npc_mcam_free_entry_req *req;
122 struct otx2_mbox *mbox = dev->mbox;
125 req = otx2_mbox_alloc_msg_npc_mcam_free_entry(mbox);
128 rc = otx2_mbox_process_msg(mbox, NULL);
133 nix_vlan_mcam_write(struct rte_eth_dev *eth_dev, uint16_t ent_idx,
134 struct mcam_entry *entry, uint8_t intf, uint8_t ena)
136 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
137 struct npc_mcam_write_entry_req *req;
138 struct otx2_mbox *mbox = dev->mbox;
142 req = otx2_mbox_alloc_msg_npc_mcam_write_entry(mbox);
144 req->entry = ent_idx;
146 req->enable_entry = ena;
147 memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
149 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
154 nix_vlan_mcam_alloc_and_write(struct rte_eth_dev *eth_dev,
155 struct mcam_entry *entry,
156 uint8_t intf, bool drop)
158 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
159 struct npc_mcam_alloc_and_write_entry_req *req;
160 struct npc_mcam_alloc_and_write_entry_rsp *rsp;
161 struct otx2_mbox *mbox = dev->mbox;
164 req = otx2_mbox_alloc_msg_npc_mcam_alloc_and_write_entry(mbox);
166 if (intf == NPC_MCAM_RX) {
167 if (!drop && dev->vlan_info.def_rx_mcam_idx) {
168 req->priority = NPC_MCAM_HIGHER_PRIO;
169 req->ref_entry = dev->vlan_info.def_rx_mcam_idx;
170 } else if (drop && dev->vlan_info.qinq_mcam_idx) {
171 req->priority = NPC_MCAM_LOWER_PRIO;
172 req->ref_entry = dev->vlan_info.qinq_mcam_idx;
174 req->priority = NPC_MCAM_ANY_PRIO;
178 req->priority = NPC_MCAM_ANY_PRIO;
183 req->enable_entry = 1;
184 memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
186 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
194 nix_vlan_update_mac(struct rte_eth_dev *eth_dev, int mcam_index,
197 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
198 struct vlan_mkex_info *mkex = &dev->vlan_info.mkex;
199 volatile uint8_t *key_data, *key_mask;
200 struct npc_mcam_read_entry_req *req;
201 struct npc_mcam_read_entry_rsp *rsp;
202 struct otx2_mbox *mbox = dev->mbox;
203 uint64_t mcam_data, mcam_mask;
204 struct mcam_entry entry;
205 uint8_t intf, mcam_ena;
206 int idx, rc = -EINVAL;
209 memset(&entry, 0, sizeof(struct mcam_entry));
211 /* Read entry first */
212 req = otx2_mbox_alloc_msg_npc_mcam_read_entry(mbox);
214 req->entry = mcam_index;
216 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
218 otx2_err("Failed to read entry %d", mcam_index);
222 entry = rsp->entry_data;
224 mcam_ena = rsp->enable;
226 /* Update mcam address */
227 key_data = (volatile uint8_t *)entry.kw;
228 key_mask = (volatile uint8_t *)entry.kw_mask;
232 otx2_mbox_memcpy(key_mask + mkex->la_xtract.key_off,
233 &mcam_mask, mkex->la_xtract.len + 1);
237 mac_addr = dev->mac_addr;
238 for (idx = RTE_ETHER_ADDR_LEN - 1; idx >= 0; idx--)
239 mcam_data |= ((uint64_t)*mac_addr++) << (8 * idx);
241 mcam_mask = BIT_ULL(48) - 1;
243 otx2_mbox_memcpy(key_data + mkex->la_xtract.key_off,
244 &mcam_data, mkex->la_xtract.len + 1);
245 otx2_mbox_memcpy(key_mask + mkex->la_xtract.key_off,
246 &mcam_mask, mkex->la_xtract.len + 1);
249 /* Write back the mcam entry */
250 rc = nix_vlan_mcam_write(eth_dev, mcam_index,
251 &entry, intf, mcam_ena);
253 otx2_err("Failed to write entry %d", mcam_index);
259 otx2_nix_vlan_update_promisc(struct rte_eth_dev *eth_dev, int enable)
261 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
262 struct otx2_vlan_info *vlan = &dev->vlan_info;
263 struct vlan_entry *entry;
265 /* Already in required mode */
266 if (enable == vlan->promisc_on)
269 /* Update default rx entry */
270 if (vlan->def_rx_mcam_idx)
271 nix_vlan_update_mac(eth_dev, vlan->def_rx_mcam_idx, enable);
273 /* Update all other rx filter entries */
274 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next)
275 nix_vlan_update_mac(eth_dev, entry->mcam_idx, enable);
277 vlan->promisc_on = enable;
280 /* Configure mcam entry with required MCAM search rules */
282 nix_vlan_mcam_config(struct rte_eth_dev *eth_dev,
283 uint16_t vlan_id, uint16_t flags)
285 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
286 struct vlan_mkex_info *mkex = &dev->vlan_info.mkex;
287 volatile uint8_t *key_data, *key_mask;
288 uint64_t mcam_data, mcam_mask;
289 struct mcam_entry entry;
293 memset(&entry, 0, sizeof(struct mcam_entry));
294 key_data = (volatile uint8_t *)entry.kw;
295 key_mask = (volatile uint8_t *)entry.kw_mask;
297 /* Channel base extracted to KW0[11:0] */
298 entry.kw[kwi] = dev->rx_chan_base;
299 entry.kw_mask[kwi] = BIT_ULL(12) - 1;
301 /* Adds vlan_id & LB CTAG flag to MCAM KW */
302 if (flags & VLAN_ID_MATCH) {
303 entry.kw[kwi] |= (NPC_LT_LB_CTAG | NPC_LT_LB_STAG_QINQ)
304 << mkex->lb_lt_offset;
305 entry.kw_mask[kwi] |=
306 (0xF & ~(NPC_LT_LB_CTAG ^ NPC_LT_LB_STAG_QINQ))
307 << mkex->lb_lt_offset;
309 mcam_data = ((uint32_t)vlan_id << 16);
310 mcam_mask = (BIT_ULL(16) - 1) << 16;
311 otx2_mbox_memcpy(key_data + mkex->lb_xtract.key_off,
312 &mcam_data, mkex->lb_xtract.len + 1);
313 otx2_mbox_memcpy(key_mask + mkex->lb_xtract.key_off,
314 &mcam_mask, mkex->lb_xtract.len + 1);
317 /* Adds LB STAG flag to MCAM KW */
318 if (flags & QINQ_F_MATCH) {
319 entry.kw[kwi] |= NPC_LT_LB_STAG_QINQ << mkex->lb_lt_offset;
320 entry.kw_mask[kwi] |= 0xFULL << mkex->lb_lt_offset;
323 /* Adds LB CTAG & LB STAG flags to MCAM KW */
324 if (flags & VTAG_F_MATCH) {
325 entry.kw[kwi] |= (NPC_LT_LB_CTAG | NPC_LT_LB_STAG_QINQ)
326 << mkex->lb_lt_offset;
327 entry.kw_mask[kwi] |=
328 (0xF & ~(NPC_LT_LB_CTAG ^ NPC_LT_LB_STAG_QINQ))
329 << mkex->lb_lt_offset;
332 /* Adds port MAC address to MCAM KW */
333 if (flags & MAC_ADDR_MATCH) {
335 mac_addr = dev->mac_addr;
336 for (idx = RTE_ETHER_ADDR_LEN - 1; idx >= 0; idx--)
337 mcam_data |= ((uint64_t)*mac_addr++) << (8 * idx);
339 mcam_mask = BIT_ULL(48) - 1;
340 otx2_mbox_memcpy(key_data + mkex->la_xtract.key_off,
341 &mcam_data, mkex->la_xtract.len + 1);
342 otx2_mbox_memcpy(key_mask + mkex->la_xtract.key_off,
343 &mcam_mask, mkex->la_xtract.len + 1);
346 /* VLAN_DROP: for drop action for all vlan packets when filter is on.
347 * For QinQ, enable vtag action for both outer & inner tags
349 if (flags & VLAN_DROP)
350 nix_set_rx_vlan_action(eth_dev, &entry, false, true);
351 else if (flags & QINQ_F_MATCH)
352 nix_set_rx_vlan_action(eth_dev, &entry, true, false);
354 nix_set_rx_vlan_action(eth_dev, &entry, false, false);
356 if (flags & DEF_F_ENTRY)
357 dev->vlan_info.def_rx_mcam_ent = entry;
359 return nix_vlan_mcam_alloc_and_write(eth_dev, &entry, NIX_INTF_RX,
363 /* Installs/Removes/Modifies default rx entry */
365 nix_vlan_handle_default_rx_entry(struct rte_eth_dev *eth_dev, bool strip,
366 bool filter, bool enable)
368 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
369 struct otx2_vlan_info *vlan = &dev->vlan_info;
373 /* Use default mcam entry to either drop vlan traffic when
374 * vlan filter is on or strip vtag when strip is enabled.
375 * Allocate default entry which matches port mac address
376 * and vtag(ctag/stag) flags with drop action.
378 if (!vlan->def_rx_mcam_idx) {
379 if (!eth_dev->data->promiscuous)
380 flags = MAC_ADDR_MATCH;
382 if (filter && enable)
383 flags |= VTAG_F_MATCH | VLAN_DROP;
384 else if (strip && enable)
385 flags |= VTAG_F_MATCH;
389 flags |= DEF_F_ENTRY;
391 mcam_idx = nix_vlan_mcam_config(eth_dev, 0, flags);
393 otx2_err("Failed to config vlan mcam");
397 vlan->def_rx_mcam_idx = mcam_idx;
401 /* Filter is already enabled, so packets would be dropped anyways. No
402 * processing needed for enabling strip wrt mcam entry.
405 /* Filter disable request */
406 if (vlan->filter_on && filter && !enable) {
407 vlan->def_rx_mcam_ent.action &= ~((uint64_t)0xF);
409 /* Free default rx entry only when
410 * 1. strip is not on and
411 * 2. qinq entry is allocated before default entry.
413 if (vlan->strip_on ||
414 (vlan->qinq_on && !vlan->qinq_before_def)) {
415 if (eth_dev->data->dev_conf.rxmode.mq_mode ==
417 vlan->def_rx_mcam_ent.action |=
420 vlan->def_rx_mcam_ent.action |=
421 NIX_RX_ACTIONOP_UCAST;
422 return nix_vlan_mcam_write(eth_dev,
423 vlan->def_rx_mcam_idx,
424 &vlan->def_rx_mcam_ent,
427 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
430 vlan->def_rx_mcam_idx = 0;
434 /* Filter enable request */
435 if (!vlan->filter_on && filter && enable) {
436 vlan->def_rx_mcam_ent.action &= ~((uint64_t)0xF);
437 vlan->def_rx_mcam_ent.action |= NIX_RX_ACTIONOP_DROP;
438 return nix_vlan_mcam_write(eth_dev, vlan->def_rx_mcam_idx,
439 &vlan->def_rx_mcam_ent, NIX_INTF_RX, 1);
442 /* Strip disable request */
443 if (vlan->strip_on && strip && !enable) {
444 if (!vlan->filter_on &&
445 !(vlan->qinq_on && !vlan->qinq_before_def)) {
446 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
449 vlan->def_rx_mcam_idx = 0;
456 /* Installs/Removes default tx entry */
458 nix_vlan_handle_default_tx_entry(struct rte_eth_dev *eth_dev,
459 enum rte_vlan_type type, int vtag_index,
462 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
463 struct otx2_vlan_info *vlan = &dev->vlan_info;
464 struct mcam_entry entry;
468 if (!vlan->def_tx_mcam_idx && enable) {
469 memset(&entry, 0, sizeof(struct mcam_entry));
471 /* Only pf_func is matched, swap it's bytes */
472 pf_func = (dev->pf_func & 0xff) << 8;
473 pf_func |= (dev->pf_func >> 8) & 0xff;
475 /* PF Func extracted to KW1[47:32] */
476 entry.kw[0] = (uint64_t)pf_func << 32;
477 entry.kw_mask[0] = (BIT_ULL(16) - 1) << 32;
479 nix_set_tx_vlan_action(&entry, type, vtag_index);
480 vlan->def_tx_mcam_ent = entry;
482 return nix_vlan_mcam_alloc_and_write(eth_dev, &entry,
486 if (vlan->def_tx_mcam_idx && !enable) {
487 rc = nix_vlan_mcam_free(dev, vlan->def_tx_mcam_idx);
490 vlan->def_rx_mcam_idx = 0;
496 /* Configure vlan stripping on or off */
498 nix_vlan_hw_strip(struct rte_eth_dev *eth_dev, const uint8_t enable)
500 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
501 struct otx2_mbox *mbox = dev->mbox;
502 struct nix_vtag_config *vtag_cfg;
505 rc = nix_vlan_handle_default_rx_entry(eth_dev, true, false, enable);
507 otx2_err("Failed to config default rx entry");
511 vtag_cfg = otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
512 /* cfg_type = 1 for rx vlan cfg */
513 vtag_cfg->cfg_type = VTAG_RX;
516 vtag_cfg->rx.strip_vtag = 1;
518 vtag_cfg->rx.strip_vtag = 0;
521 vtag_cfg->rx.capture_vtag = 1;
522 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
523 /* Use rx vtag type index[0] for now */
524 vtag_cfg->rx.vtag_type = 0;
526 rc = otx2_mbox_process(mbox);
530 dev->vlan_info.strip_on = enable;
534 /* Configure vlan filtering on or off for all vlans if vlan_id == 0 */
536 nix_vlan_hw_filter(struct rte_eth_dev *eth_dev, const uint8_t enable,
539 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
540 struct otx2_vlan_info *vlan = &dev->vlan_info;
541 struct vlan_entry *entry;
544 if (!vlan_id && enable) {
545 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true,
548 otx2_err("Failed to config vlan mcam");
551 dev->vlan_info.filter_on = enable;
555 /* Enable/disable existing vlan filter entries */
556 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
558 if (entry->vlan_id == vlan_id) {
559 rc = nix_vlan_mcam_enb_dis(dev,
566 rc = nix_vlan_mcam_enb_dis(dev, entry->mcam_idx,
573 if (!vlan_id && !enable) {
574 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true,
577 otx2_err("Failed to config vlan mcam");
580 dev->vlan_info.filter_on = enable;
587 /* Enable/disable vlan filtering for the given vlan_id */
589 otx2_nix_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
592 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
593 struct otx2_vlan_info *vlan = &dev->vlan_info;
594 struct vlan_entry *entry;
595 int entry_exists = 0;
600 otx2_err("Vlan Id can't be zero");
604 if (!vlan->def_rx_mcam_idx) {
605 otx2_err("Vlan Filtering is disabled, enable it first");
610 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
611 if (entry->vlan_id == vlan_id) {
612 /* Vlan entry already exists */
614 /* Mcam entry already allocated */
615 if (entry->mcam_idx) {
616 rc = nix_vlan_hw_filter(eth_dev, on,
625 entry = rte_zmalloc("otx2_nix_vlan_entry",
626 sizeof(struct vlan_entry), 0);
628 otx2_err("Failed to allocate memory");
633 /* Enables vlan_id & mac address based filtering */
634 if (eth_dev->data->promiscuous)
635 mcam_idx = nix_vlan_mcam_config(eth_dev, vlan_id,
638 mcam_idx = nix_vlan_mcam_config(eth_dev, vlan_id,
642 otx2_err("Failed to config vlan mcam");
643 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
648 entry->mcam_idx = mcam_idx;
650 entry->vlan_id = vlan_id;
651 TAILQ_INSERT_HEAD(&vlan->fltr_tbl, entry, next);
654 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
655 if (entry->vlan_id == vlan_id) {
656 rc = nix_vlan_mcam_free(dev, entry->mcam_idx);
659 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
668 /* Configure double vlan(qinq) on or off */
670 otx2_nix_config_double_vlan(struct rte_eth_dev *eth_dev,
671 const uint8_t enable)
673 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
674 struct otx2_vlan_info *vlan_info;
678 vlan_info = &dev->vlan_info;
681 if (!vlan_info->qinq_mcam_idx)
684 rc = nix_vlan_mcam_free(dev, vlan_info->qinq_mcam_idx);
688 vlan_info->qinq_mcam_idx = 0;
689 dev->vlan_info.qinq_on = 0;
690 vlan_info->qinq_before_def = 0;
694 if (eth_dev->data->promiscuous)
695 mcam_idx = nix_vlan_mcam_config(eth_dev, 0, QINQ_F_MATCH);
697 mcam_idx = nix_vlan_mcam_config(eth_dev, 0,
698 QINQ_F_MATCH | MAC_ADDR_MATCH);
702 if (!vlan_info->def_rx_mcam_idx)
703 vlan_info->qinq_before_def = 1;
705 vlan_info->qinq_mcam_idx = mcam_idx;
706 dev->vlan_info.qinq_on = 1;
711 otx2_nix_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
713 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
714 uint64_t offloads = dev->rx_offloads;
715 struct rte_eth_rxmode *rxmode;
718 rxmode = ð_dev->data->dev_conf.rxmode;
720 if (mask & ETH_VLAN_EXTEND_MASK) {
721 otx2_err("Extend offload not supported");
725 if (mask & ETH_VLAN_STRIP_MASK) {
726 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
727 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
728 rc = nix_vlan_hw_strip(eth_dev, true);
730 offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
731 rc = nix_vlan_hw_strip(eth_dev, false);
737 if (mask & ETH_VLAN_FILTER_MASK) {
738 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
739 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
740 rc = nix_vlan_hw_filter(eth_dev, true, 0);
742 offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
743 rc = nix_vlan_hw_filter(eth_dev, false, 0);
749 if (rxmode->offloads & DEV_RX_OFFLOAD_QINQ_STRIP) {
750 if (!dev->vlan_info.qinq_on) {
751 offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
752 rc = otx2_nix_config_double_vlan(eth_dev, true);
757 if (dev->vlan_info.qinq_on) {
758 offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
759 rc = otx2_nix_config_double_vlan(eth_dev, false);
765 if (offloads & (DEV_RX_OFFLOAD_VLAN_STRIP |
766 DEV_RX_OFFLOAD_QINQ_STRIP)) {
767 dev->rx_offloads |= offloads;
768 dev->rx_offload_flags |= NIX_RX_OFFLOAD_VLAN_STRIP_F;
769 otx2_eth_set_rx_function(eth_dev);
777 otx2_nix_vlan_tpid_set(struct rte_eth_dev *eth_dev,
778 enum rte_vlan_type type, uint16_t tpid)
780 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
781 struct nix_set_vlan_tpid *tpid_cfg;
782 struct otx2_mbox *mbox = dev->mbox;
785 tpid_cfg = otx2_mbox_alloc_msg_nix_set_vlan_tpid(mbox);
787 tpid_cfg->tpid = tpid;
788 if (type == ETH_VLAN_TYPE_OUTER)
789 tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
791 tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
793 rc = otx2_mbox_process(mbox);
797 if (type == ETH_VLAN_TYPE_OUTER)
798 dev->vlan_info.outer_vlan_tpid = tpid;
800 dev->vlan_info.inner_vlan_tpid = tpid;
805 otx2_nix_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
807 struct otx2_eth_dev *otx2_dev = otx2_eth_pmd_priv(dev);
808 struct otx2_mbox *mbox = otx2_dev->mbox;
809 struct nix_vtag_config *vtag_cfg;
810 struct nix_vtag_config_rsp *rsp;
811 struct otx2_vlan_info *vlan;
812 int rc, rc1, vtag_index = 0;
815 otx2_err("vlan id can't be zero");
819 vlan = &otx2_dev->vlan_info;
821 if (on && vlan->pvid_insert_on && vlan->pvid == vlan_id) {
822 otx2_err("pvid %d is already enabled", vlan_id);
826 if (on && vlan->pvid_insert_on && vlan->pvid != vlan_id) {
827 otx2_err("another pvid is enabled, disable that first");
832 if (!on && !vlan->pvid_insert_on)
835 /* Given pvid already disabled */
836 if (!on && vlan->pvid != vlan_id)
839 vtag_cfg = otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
842 vtag_cfg->cfg_type = VTAG_TX;
843 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
845 if (vlan->outer_vlan_tpid)
846 vtag_cfg->tx.vtag0 = ((uint32_t)vlan->outer_vlan_tpid
850 ((RTE_ETHER_TYPE_VLAN << 16) | vlan_id);
851 vtag_cfg->tx.cfg_vtag0 = 1;
853 vtag_cfg->cfg_type = VTAG_TX;
854 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
856 vtag_cfg->tx.vtag0_idx = vlan->outer_vlan_idx;
857 vtag_cfg->tx.free_vtag0 = 1;
860 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
865 vtag_index = rsp->vtag0_idx;
868 vlan->pvid_insert_on = 0;
869 vlan->outer_vlan_idx = 0;
872 rc = nix_vlan_handle_default_tx_entry(dev, ETH_VLAN_TYPE_OUTER,
875 printf("Default tx entry failed with rc %d\n", rc);
876 vtag_cfg->tx.vtag0_idx = vtag_index;
877 vtag_cfg->tx.free_vtag0 = 1;
878 vtag_cfg->tx.cfg_vtag0 = 0;
880 rc1 = otx2_mbox_process_msg(mbox, (void *)&rsp);
882 otx2_err("Vtag free failed");
888 vlan->pvid = vlan_id;
889 vlan->pvid_insert_on = 1;
890 vlan->outer_vlan_idx = vtag_index;
896 void otx2_nix_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
897 __rte_unused uint16_t queue,
900 otx2_err("Not Supported");
904 nix_vlan_rx_mkex_offset(uint64_t mask)
909 nib_count += mask & 1;
913 return nib_count * 4;
917 nix_vlan_get_mkex_info(struct otx2_eth_dev *dev)
919 struct vlan_mkex_info *mkex = &dev->vlan_info.mkex;
920 struct otx2_npc_flow_info *npc = &dev->npc_flow;
921 struct npc_xtract_info *x_info = NULL;
927 otx2_err("Missing npc mkex configuration");
931 #define NPC_KEX_CHAN_NIBBLE_ENA 0x7ULL
932 #define NPC_KEX_LB_LTYPE_NIBBLE_ENA 0x1000ULL
933 #define NPC_KEX_LB_LTYPE_NIBBLE_MASK 0xFFFULL
935 rx_keyx = npc->keyx_supp_nmask[NPC_MCAM_RX];
936 if ((rx_keyx & NPC_KEX_CHAN_NIBBLE_ENA) != NPC_KEX_CHAN_NIBBLE_ENA)
939 if ((rx_keyx & NPC_KEX_LB_LTYPE_NIBBLE_ENA) !=
940 NPC_KEX_LB_LTYPE_NIBBLE_ENA)
944 nix_vlan_rx_mkex_offset(rx_keyx & NPC_KEX_LB_LTYPE_NIBBLE_MASK);
947 x_info = &(*p)[NPC_MCAM_RX][NPC_LID_LA][NPC_LT_LA_ETHER].xtract[0];
948 memcpy(&mkex->la_xtract, x_info, sizeof(struct npc_xtract_info));
949 x_info = &(*p)[NPC_MCAM_RX][NPC_LID_LB][NPC_LT_LB_CTAG].xtract[0];
950 memcpy(&mkex->lb_xtract, x_info, sizeof(struct npc_xtract_info));
955 static void nix_vlan_reinstall_vlan_filters(struct rte_eth_dev *eth_dev)
957 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
958 struct vlan_entry *entry;
961 /* VLAN filters can't be set without setting filtern on */
962 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true, true);
964 otx2_err("Failed to reinstall vlan filters");
968 TAILQ_FOREACH(entry, &dev->vlan_info.fltr_tbl, next) {
969 rc = otx2_nix_vlan_filter_set(eth_dev, entry->vlan_id, true);
971 otx2_err("Failed to reinstall filter for vlan:%d",
977 otx2_nix_vlan_offload_init(struct rte_eth_dev *eth_dev)
979 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
982 /* Port initialized for first time or restarted */
983 if (!dev->configured) {
984 rc = nix_vlan_get_mkex_info(dev);
986 otx2_err("Failed to get vlan mkex info rc=%d", rc);
990 TAILQ_INIT(&dev->vlan_info.fltr_tbl);
992 /* Reinstall all mcam entries now if filter offload is set */
993 if (eth_dev->data->dev_conf.rxmode.offloads &
994 DEV_RX_OFFLOAD_VLAN_FILTER)
995 nix_vlan_reinstall_vlan_filters(eth_dev);
999 ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
1000 rc = otx2_nix_vlan_offload_set(eth_dev, mask);
1002 otx2_err("Failed to set vlan offload rc=%d", rc);
1010 otx2_nix_vlan_fini(struct rte_eth_dev *eth_dev)
1012 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1013 struct otx2_vlan_info *vlan = &dev->vlan_info;
1014 struct vlan_entry *entry;
1017 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
1018 if (!dev->configured) {
1019 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
1022 /* MCAM entries freed by flow_fini & lf_free on
1025 entry->mcam_idx = 0;
1029 if (!dev->configured) {
1030 if (vlan->def_rx_mcam_idx) {
1031 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
1037 otx2_nix_config_double_vlan(eth_dev, false);
1038 vlan->def_rx_mcam_idx = 0;