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 << mkex->lb_lt_offset;
304 entry.kw_mask[kwi] |= 0xFULL << mkex->lb_lt_offset;
306 mcam_data = ((uint32_t)vlan_id << 16);
307 mcam_mask = (BIT_ULL(16) - 1) << 16;
308 otx2_mbox_memcpy(key_data + mkex->lb_xtract.key_off,
309 &mcam_data, mkex->lb_xtract.len + 1);
310 otx2_mbox_memcpy(key_mask + mkex->lb_xtract.key_off,
311 &mcam_mask, mkex->lb_xtract.len + 1);
314 /* Adds LB STAG flag to MCAM KW */
315 if (flags & QINQ_F_MATCH) {
316 entry.kw[kwi] |= NPC_LT_LB_STAG << mkex->lb_lt_offset;
317 entry.kw_mask[kwi] |= 0xFULL << mkex->lb_lt_offset;
320 /* Adds LB CTAG & LB STAG flags to MCAM KW */
321 if (flags & VTAG_F_MATCH) {
322 entry.kw[kwi] |= (NPC_LT_LB_CTAG | NPC_LT_LB_STAG)
323 << mkex->lb_lt_offset;
324 entry.kw_mask[kwi] |= (NPC_LT_LB_CTAG & NPC_LT_LB_STAG)
325 << mkex->lb_lt_offset;
328 /* Adds port MAC address to MCAM KW */
329 if (flags & MAC_ADDR_MATCH) {
331 mac_addr = dev->mac_addr;
332 for (idx = RTE_ETHER_ADDR_LEN - 1; idx >= 0; idx--)
333 mcam_data |= ((uint64_t)*mac_addr++) << (8 * idx);
335 mcam_mask = BIT_ULL(48) - 1;
336 otx2_mbox_memcpy(key_data + mkex->la_xtract.key_off,
337 &mcam_data, mkex->la_xtract.len + 1);
338 otx2_mbox_memcpy(key_mask + mkex->la_xtract.key_off,
339 &mcam_mask, mkex->la_xtract.len + 1);
342 /* VLAN_DROP: for drop action for all vlan packets when filter is on.
343 * For QinQ, enable vtag action for both outer & inner tags
345 if (flags & VLAN_DROP)
346 nix_set_rx_vlan_action(eth_dev, &entry, false, true);
347 else if (flags & QINQ_F_MATCH)
348 nix_set_rx_vlan_action(eth_dev, &entry, true, false);
350 nix_set_rx_vlan_action(eth_dev, &entry, false, false);
352 if (flags & DEF_F_ENTRY)
353 dev->vlan_info.def_rx_mcam_ent = entry;
355 return nix_vlan_mcam_alloc_and_write(eth_dev, &entry, NIX_INTF_RX,
359 /* Installs/Removes/Modifies default rx entry */
361 nix_vlan_handle_default_rx_entry(struct rte_eth_dev *eth_dev, bool strip,
362 bool filter, bool enable)
364 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
365 struct otx2_vlan_info *vlan = &dev->vlan_info;
369 /* Use default mcam entry to either drop vlan traffic when
370 * vlan filter is on or strip vtag when strip is enabled.
371 * Allocate default entry which matches port mac address
372 * and vtag(ctag/stag) flags with drop action.
374 if (!vlan->def_rx_mcam_idx) {
375 if (!eth_dev->data->promiscuous)
376 flags = MAC_ADDR_MATCH;
378 if (filter && enable)
379 flags |= VTAG_F_MATCH | VLAN_DROP;
380 else if (strip && enable)
381 flags |= VTAG_F_MATCH;
385 flags |= DEF_F_ENTRY;
387 mcam_idx = nix_vlan_mcam_config(eth_dev, 0, flags);
389 otx2_err("Failed to config vlan mcam");
393 vlan->def_rx_mcam_idx = mcam_idx;
397 /* Filter is already enabled, so packets would be dropped anyways. No
398 * processing needed for enabling strip wrt mcam entry.
401 /* Filter disable request */
402 if (vlan->filter_on && filter && !enable) {
403 vlan->def_rx_mcam_ent.action &= ~((uint64_t)0xF);
405 /* Free default rx entry only when
406 * 1. strip is not on and
407 * 2. qinq entry is allocated before default entry.
409 if (vlan->strip_on ||
410 (vlan->qinq_on && !vlan->qinq_before_def)) {
411 if (eth_dev->data->dev_conf.rxmode.mq_mode ==
413 vlan->def_rx_mcam_ent.action |=
416 vlan->def_rx_mcam_ent.action |=
417 NIX_RX_ACTIONOP_UCAST;
418 return nix_vlan_mcam_write(eth_dev,
419 vlan->def_rx_mcam_idx,
420 &vlan->def_rx_mcam_ent,
423 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
426 vlan->def_rx_mcam_idx = 0;
430 /* Filter enable request */
431 if (!vlan->filter_on && filter && enable) {
432 vlan->def_rx_mcam_ent.action &= ~((uint64_t)0xF);
433 vlan->def_rx_mcam_ent.action |= NIX_RX_ACTIONOP_DROP;
434 return nix_vlan_mcam_write(eth_dev, vlan->def_rx_mcam_idx,
435 &vlan->def_rx_mcam_ent, NIX_INTF_RX, 1);
438 /* Strip disable request */
439 if (vlan->strip_on && strip && !enable) {
440 if (!vlan->filter_on &&
441 !(vlan->qinq_on && !vlan->qinq_before_def)) {
442 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
445 vlan->def_rx_mcam_idx = 0;
452 /* Installs/Removes default tx entry */
454 nix_vlan_handle_default_tx_entry(struct rte_eth_dev *eth_dev,
455 enum rte_vlan_type type, int vtag_index,
458 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
459 struct otx2_vlan_info *vlan = &dev->vlan_info;
460 struct mcam_entry entry;
464 if (!vlan->def_tx_mcam_idx && enable) {
465 memset(&entry, 0, sizeof(struct mcam_entry));
467 /* Only pf_func is matched, swap it's bytes */
468 pf_func = (dev->pf_func & 0xff) << 8;
469 pf_func |= (dev->pf_func >> 8) & 0xff;
471 /* PF Func extracted to KW1[63:48] */
472 entry.kw[1] = (uint64_t)pf_func << 48;
473 entry.kw_mask[1] = (BIT_ULL(16) - 1) << 48;
475 nix_set_tx_vlan_action(&entry, type, vtag_index);
476 vlan->def_tx_mcam_ent = entry;
478 return nix_vlan_mcam_alloc_and_write(eth_dev, &entry,
482 if (vlan->def_tx_mcam_idx && !enable) {
483 rc = nix_vlan_mcam_free(dev, vlan->def_tx_mcam_idx);
486 vlan->def_rx_mcam_idx = 0;
492 /* Configure vlan stripping on or off */
494 nix_vlan_hw_strip(struct rte_eth_dev *eth_dev, const uint8_t enable)
496 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
497 struct otx2_mbox *mbox = dev->mbox;
498 struct nix_vtag_config *vtag_cfg;
501 rc = nix_vlan_handle_default_rx_entry(eth_dev, true, false, enable);
503 otx2_err("Failed to config default rx entry");
507 vtag_cfg = otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
508 /* cfg_type = 1 for rx vlan cfg */
509 vtag_cfg->cfg_type = VTAG_RX;
512 vtag_cfg->rx.strip_vtag = 1;
514 vtag_cfg->rx.strip_vtag = 0;
517 vtag_cfg->rx.capture_vtag = 1;
518 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
519 /* Use rx vtag type index[0] for now */
520 vtag_cfg->rx.vtag_type = 0;
522 rc = otx2_mbox_process(mbox);
526 dev->vlan_info.strip_on = enable;
530 /* Configure vlan filtering on or off for all vlans if vlan_id == 0 */
532 nix_vlan_hw_filter(struct rte_eth_dev *eth_dev, const uint8_t enable,
535 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
536 struct otx2_vlan_info *vlan = &dev->vlan_info;
537 struct vlan_entry *entry;
540 if (!vlan_id && enable) {
541 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true,
544 otx2_err("Failed to config vlan mcam");
547 dev->vlan_info.filter_on = enable;
551 /* Enable/disable existing vlan filter entries */
552 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
554 if (entry->vlan_id == vlan_id) {
555 rc = nix_vlan_mcam_enb_dis(dev,
562 rc = nix_vlan_mcam_enb_dis(dev, entry->mcam_idx,
569 if (!vlan_id && !enable) {
570 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true,
573 otx2_err("Failed to config vlan mcam");
576 dev->vlan_info.filter_on = enable;
583 /* Enable/disable vlan filtering for the given vlan_id */
585 otx2_nix_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
588 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
589 struct otx2_vlan_info *vlan = &dev->vlan_info;
590 struct vlan_entry *entry;
591 int entry_exists = 0;
596 otx2_err("Vlan Id can't be zero");
600 if (!vlan->def_rx_mcam_idx) {
601 otx2_err("Vlan Filtering is disabled, enable it first");
606 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
607 if (entry->vlan_id == vlan_id) {
608 /* Vlan entry already exists */
610 /* Mcam entry already allocated */
611 if (entry->mcam_idx) {
612 rc = nix_vlan_hw_filter(eth_dev, on,
621 entry = rte_zmalloc("otx2_nix_vlan_entry",
622 sizeof(struct vlan_entry), 0);
624 otx2_err("Failed to allocate memory");
629 /* Enables vlan_id & mac address based filtering */
630 if (eth_dev->data->promiscuous)
631 mcam_idx = nix_vlan_mcam_config(eth_dev, vlan_id,
634 mcam_idx = nix_vlan_mcam_config(eth_dev, vlan_id,
638 otx2_err("Failed to config vlan mcam");
639 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
644 entry->mcam_idx = mcam_idx;
646 entry->vlan_id = vlan_id;
647 TAILQ_INSERT_HEAD(&vlan->fltr_tbl, entry, next);
650 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
651 if (entry->vlan_id == vlan_id) {
652 rc = nix_vlan_mcam_free(dev, entry->mcam_idx);
655 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
664 /* Configure double vlan(qinq) on or off */
666 otx2_nix_config_double_vlan(struct rte_eth_dev *eth_dev,
667 const uint8_t enable)
669 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
670 struct otx2_vlan_info *vlan_info;
674 vlan_info = &dev->vlan_info;
677 if (!vlan_info->qinq_mcam_idx)
680 rc = nix_vlan_mcam_free(dev, vlan_info->qinq_mcam_idx);
684 vlan_info->qinq_mcam_idx = 0;
685 dev->vlan_info.qinq_on = 0;
686 vlan_info->qinq_before_def = 0;
690 if (eth_dev->data->promiscuous)
691 mcam_idx = nix_vlan_mcam_config(eth_dev, 0, QINQ_F_MATCH);
693 mcam_idx = nix_vlan_mcam_config(eth_dev, 0,
694 QINQ_F_MATCH | MAC_ADDR_MATCH);
698 if (!vlan_info->def_rx_mcam_idx)
699 vlan_info->qinq_before_def = 1;
701 vlan_info->qinq_mcam_idx = mcam_idx;
702 dev->vlan_info.qinq_on = 1;
707 otx2_nix_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
709 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
710 uint64_t offloads = dev->rx_offloads;
711 struct rte_eth_rxmode *rxmode;
714 rxmode = ð_dev->data->dev_conf.rxmode;
716 if (mask & ETH_VLAN_EXTEND_MASK) {
717 otx2_err("Extend offload not supported");
721 if (mask & ETH_VLAN_STRIP_MASK) {
722 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
723 offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
724 rc = nix_vlan_hw_strip(eth_dev, true);
726 offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
727 rc = nix_vlan_hw_strip(eth_dev, false);
733 if (mask & ETH_VLAN_FILTER_MASK) {
734 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
735 offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
736 rc = nix_vlan_hw_filter(eth_dev, true, 0);
738 offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
739 rc = nix_vlan_hw_filter(eth_dev, false, 0);
745 if (rxmode->offloads & DEV_RX_OFFLOAD_QINQ_STRIP) {
746 if (!dev->vlan_info.qinq_on) {
747 offloads |= DEV_RX_OFFLOAD_QINQ_STRIP;
748 rc = otx2_nix_config_double_vlan(eth_dev, true);
753 if (dev->vlan_info.qinq_on) {
754 offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP;
755 rc = otx2_nix_config_double_vlan(eth_dev, false);
761 if (offloads & (DEV_RX_OFFLOAD_VLAN_STRIP |
762 DEV_RX_OFFLOAD_QINQ_STRIP)) {
763 dev->rx_offloads |= offloads;
764 dev->rx_offload_flags |= NIX_RX_OFFLOAD_VLAN_STRIP_F;
765 otx2_eth_set_rx_function(eth_dev);
773 otx2_nix_vlan_tpid_set(struct rte_eth_dev *eth_dev,
774 enum rte_vlan_type type, uint16_t tpid)
776 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
777 struct nix_set_vlan_tpid *tpid_cfg;
778 struct otx2_mbox *mbox = dev->mbox;
781 tpid_cfg = otx2_mbox_alloc_msg_nix_set_vlan_tpid(mbox);
783 tpid_cfg->tpid = tpid;
784 if (type == ETH_VLAN_TYPE_OUTER)
785 tpid_cfg->vlan_type = NIX_VLAN_TYPE_OUTER;
787 tpid_cfg->vlan_type = NIX_VLAN_TYPE_INNER;
789 rc = otx2_mbox_process(mbox);
793 if (type == ETH_VLAN_TYPE_OUTER)
794 dev->vlan_info.outer_vlan_tpid = tpid;
796 dev->vlan_info.inner_vlan_tpid = tpid;
801 otx2_nix_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
803 struct otx2_eth_dev *otx2_dev = otx2_eth_pmd_priv(dev);
804 struct otx2_mbox *mbox = otx2_dev->mbox;
805 struct nix_vtag_config *vtag_cfg;
806 struct nix_vtag_config_rsp *rsp;
807 struct otx2_vlan_info *vlan;
808 int rc, rc1, vtag_index = 0;
811 otx2_err("vlan id can't be zero");
815 vlan = &otx2_dev->vlan_info;
817 if (on && vlan->pvid_insert_on && vlan->pvid == vlan_id) {
818 otx2_err("pvid %d is already enabled", vlan_id);
822 if (on && vlan->pvid_insert_on && vlan->pvid != vlan_id) {
823 otx2_err("another pvid is enabled, disable that first");
828 if (!on && !vlan->pvid_insert_on)
831 /* Given pvid already disabled */
832 if (!on && vlan->pvid != vlan_id)
835 vtag_cfg = otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
838 vtag_cfg->cfg_type = VTAG_TX;
839 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
841 if (vlan->outer_vlan_tpid)
842 vtag_cfg->tx.vtag0 = ((uint32_t)vlan->outer_vlan_tpid
846 ((RTE_ETHER_TYPE_VLAN << 16) | vlan_id);
847 vtag_cfg->tx.cfg_vtag0 = 1;
849 vtag_cfg->cfg_type = VTAG_TX;
850 vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
852 vtag_cfg->tx.vtag0_idx = vlan->outer_vlan_idx;
853 vtag_cfg->tx.free_vtag0 = 1;
856 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
861 vtag_index = rsp->vtag0_idx;
864 vlan->pvid_insert_on = 0;
865 vlan->outer_vlan_idx = 0;
868 rc = nix_vlan_handle_default_tx_entry(dev, ETH_VLAN_TYPE_OUTER,
871 printf("Default tx entry failed with rc %d\n", rc);
872 vtag_cfg->tx.vtag0_idx = vtag_index;
873 vtag_cfg->tx.free_vtag0 = 1;
874 vtag_cfg->tx.cfg_vtag0 = 0;
876 rc1 = otx2_mbox_process_msg(mbox, (void *)&rsp);
878 otx2_err("Vtag free failed");
884 vlan->pvid = vlan_id;
885 vlan->pvid_insert_on = 1;
886 vlan->outer_vlan_idx = vtag_index;
892 void otx2_nix_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
893 __rte_unused uint16_t queue,
896 otx2_err("Not Supported");
900 nix_vlan_rx_mkex_offset(uint64_t mask)
905 nib_count += mask & 1;
909 return nib_count * 4;
913 nix_vlan_get_mkex_info(struct otx2_eth_dev *dev)
915 struct vlan_mkex_info *mkex = &dev->vlan_info.mkex;
916 struct otx2_npc_flow_info *npc = &dev->npc_flow;
917 struct npc_xtract_info *x_info = NULL;
923 otx2_err("Missing npc mkex configuration");
927 #define NPC_KEX_CHAN_NIBBLE_ENA 0x7ULL
928 #define NPC_KEX_LB_LTYPE_NIBBLE_ENA 0x1000ULL
929 #define NPC_KEX_LB_LTYPE_NIBBLE_MASK 0xFFFULL
931 rx_keyx = npc->keyx_supp_nmask[NPC_MCAM_RX];
932 if ((rx_keyx & NPC_KEX_CHAN_NIBBLE_ENA) != NPC_KEX_CHAN_NIBBLE_ENA)
935 if ((rx_keyx & NPC_KEX_LB_LTYPE_NIBBLE_ENA) !=
936 NPC_KEX_LB_LTYPE_NIBBLE_ENA)
940 nix_vlan_rx_mkex_offset(rx_keyx & NPC_KEX_LB_LTYPE_NIBBLE_MASK);
943 x_info = &(*p)[NPC_MCAM_RX][NPC_LID_LA][NPC_LT_LA_ETHER].xtract[0];
944 memcpy(&mkex->la_xtract, x_info, sizeof(struct npc_xtract_info));
945 x_info = &(*p)[NPC_MCAM_RX][NPC_LID_LB][NPC_LT_LB_CTAG].xtract[0];
946 memcpy(&mkex->lb_xtract, x_info, sizeof(struct npc_xtract_info));
951 static void nix_vlan_reinstall_vlan_filters(struct rte_eth_dev *eth_dev)
953 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
954 struct vlan_entry *entry;
957 /* VLAN filters can't be set without setting filtern on */
958 rc = nix_vlan_handle_default_rx_entry(eth_dev, false, true, true);
960 otx2_err("Failed to reinstall vlan filters");
964 TAILQ_FOREACH(entry, &dev->vlan_info.fltr_tbl, next) {
965 rc = otx2_nix_vlan_filter_set(eth_dev, entry->vlan_id, true);
967 otx2_err("Failed to reinstall filter for vlan:%d",
973 otx2_nix_vlan_offload_init(struct rte_eth_dev *eth_dev)
975 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
978 /* Port initialized for first time or restarted */
979 if (!dev->configured) {
980 rc = nix_vlan_get_mkex_info(dev);
982 otx2_err("Failed to get vlan mkex info rc=%d", rc);
986 TAILQ_INIT(&dev->vlan_info.fltr_tbl);
988 /* Reinstall all mcam entries now if filter offload is set */
989 if (eth_dev->data->dev_conf.rxmode.offloads &
990 DEV_RX_OFFLOAD_VLAN_FILTER)
991 nix_vlan_reinstall_vlan_filters(eth_dev);
995 ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
996 rc = otx2_nix_vlan_offload_set(eth_dev, mask);
998 otx2_err("Failed to set vlan offload rc=%d", rc);
1006 otx2_nix_vlan_fini(struct rte_eth_dev *eth_dev)
1008 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
1009 struct otx2_vlan_info *vlan = &dev->vlan_info;
1010 struct vlan_entry *entry;
1013 TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) {
1014 if (!dev->configured) {
1015 TAILQ_REMOVE(&vlan->fltr_tbl, entry, next);
1018 /* MCAM entries freed by flow_fini & lf_free on
1021 entry->mcam_idx = 0;
1025 if (!dev->configured) {
1026 if (vlan->def_rx_mcam_idx) {
1027 rc = nix_vlan_mcam_free(dev, vlan->def_rx_mcam_idx);
1033 otx2_nix_config_double_vlan(eth_dev, false);
1034 vlan->def_rx_mcam_idx = 0;