1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell RVU Ethernet driver
4 * Copyright (C) 2020 Marvell.
9 #include <linux/sort.h>
11 #include "otx2_common.h"
13 #define OTX2_DEFAULT_ACTION 0x1
15 static int otx2_mcam_entry_init(struct otx2_nic *pfvf);
18 struct ethtool_rx_flow_spec flow_spec;
19 struct list_head list;
24 #define DMAC_FILTER_RULE BIT(0)
25 #define PFC_FLOWCTRL_RULE BIT(1)
35 static void otx2_clear_ntuple_flow_info(struct otx2_nic *pfvf, struct otx2_flow_config *flow_cfg)
37 devm_kfree(pfvf->dev, flow_cfg->flow_ent);
38 flow_cfg->flow_ent = NULL;
39 flow_cfg->max_flows = 0;
42 static int otx2_free_ntuple_mcam_entries(struct otx2_nic *pfvf)
44 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
45 struct npc_mcam_free_entry_req *req;
48 if (!flow_cfg->max_flows)
51 mutex_lock(&pfvf->mbox.lock);
52 for (ent = 0; ent < flow_cfg->max_flows; ent++) {
53 req = otx2_mbox_alloc_msg_npc_mcam_free_entry(&pfvf->mbox);
57 req->entry = flow_cfg->flow_ent[ent];
59 /* Send message to AF to free MCAM entries */
60 err = otx2_sync_mbox_msg(&pfvf->mbox);
64 mutex_unlock(&pfvf->mbox.lock);
65 otx2_clear_ntuple_flow_info(pfvf, flow_cfg);
69 static int mcam_entry_cmp(const void *a, const void *b)
71 return *(u16 *)a - *(u16 *)b;
74 int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 count)
76 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
77 struct npc_mcam_alloc_entry_req *req;
78 struct npc_mcam_alloc_entry_rsp *rsp;
79 int ent, allocated = 0;
81 /* Free current ones and allocate new ones with requested count */
82 otx2_free_ntuple_mcam_entries(pfvf);
87 flow_cfg->flow_ent = devm_kmalloc_array(pfvf->dev, count,
88 sizeof(u16), GFP_KERNEL);
89 if (!flow_cfg->flow_ent) {
90 netdev_err(pfvf->netdev,
91 "%s: Unable to allocate memory for flow entries\n",
96 mutex_lock(&pfvf->mbox.lock);
98 /* In a single request a max of NPC_MAX_NONCONTIG_ENTRIES MCAM entries
99 * can only be allocated.
101 while (allocated < count) {
102 req = otx2_mbox_alloc_msg_npc_mcam_alloc_entry(&pfvf->mbox);
107 req->count = (count - allocated) > NPC_MAX_NONCONTIG_ENTRIES ?
108 NPC_MAX_NONCONTIG_ENTRIES : count - allocated;
110 /* Allocate higher priority entries for PFs, so that VF's entries
111 * will be on top of PF.
113 if (!is_otx2_vf(pfvf->pcifunc)) {
114 req->priority = NPC_MCAM_HIGHER_PRIO;
115 req->ref_entry = flow_cfg->def_ent[0];
118 /* Send message to AF */
119 if (otx2_sync_mbox_msg(&pfvf->mbox))
122 rsp = (struct npc_mcam_alloc_entry_rsp *)otx2_mbox_get_rsp
123 (&pfvf->mbox.mbox, 0, &req->hdr);
125 for (ent = 0; ent < rsp->count; ent++)
126 flow_cfg->flow_ent[ent + allocated] = rsp->entry_list[ent];
128 allocated += rsp->count;
130 /* If this request is not fulfilled, no need to send
133 if (rsp->count != req->count)
137 /* Multiple MCAM entry alloc requests could result in non-sequential
138 * MCAM entries in the flow_ent[] array. Sort them in an ascending order,
139 * otherwise user installed ntuple filter index and MCAM entry index will
143 sort(&flow_cfg->flow_ent[0], allocated,
144 sizeof(flow_cfg->flow_ent[0]), mcam_entry_cmp, NULL);
147 mutex_unlock(&pfvf->mbox.lock);
149 flow_cfg->max_flows = allocated;
152 pfvf->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
153 pfvf->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
156 if (allocated != count)
157 netdev_info(pfvf->netdev,
158 "Unable to allocate %d MCAM entries, got only %d\n",
162 EXPORT_SYMBOL(otx2_alloc_mcam_entries);
164 static int otx2_mcam_entry_init(struct otx2_nic *pfvf)
166 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
167 struct npc_get_field_status_req *freq;
168 struct npc_get_field_status_rsp *frsp;
169 struct npc_mcam_alloc_entry_req *req;
170 struct npc_mcam_alloc_entry_rsp *rsp;
171 int vf_vlan_max_flows;
174 vf_vlan_max_flows = pfvf->total_vfs * OTX2_PER_VF_VLAN_FLOWS;
175 count = OTX2_MAX_UNICAST_FLOWS +
176 OTX2_MAX_VLAN_FLOWS + vf_vlan_max_flows;
178 flow_cfg->def_ent = devm_kmalloc_array(pfvf->dev, count,
179 sizeof(u16), GFP_KERNEL);
180 if (!flow_cfg->def_ent)
183 mutex_lock(&pfvf->mbox.lock);
185 req = otx2_mbox_alloc_msg_npc_mcam_alloc_entry(&pfvf->mbox);
187 mutex_unlock(&pfvf->mbox.lock);
194 /* Send message to AF */
195 if (otx2_sync_mbox_msg(&pfvf->mbox)) {
196 mutex_unlock(&pfvf->mbox.lock);
200 rsp = (struct npc_mcam_alloc_entry_rsp *)otx2_mbox_get_rsp
201 (&pfvf->mbox.mbox, 0, &req->hdr);
203 if (rsp->count != req->count) {
204 netdev_info(pfvf->netdev,
205 "Unable to allocate MCAM entries for ucast, vlan and vf_vlan\n");
206 mutex_unlock(&pfvf->mbox.lock);
207 devm_kfree(pfvf->dev, flow_cfg->def_ent);
211 for (ent = 0; ent < rsp->count; ent++)
212 flow_cfg->def_ent[ent] = rsp->entry_list[ent];
214 flow_cfg->vf_vlan_offset = 0;
215 flow_cfg->unicast_offset = vf_vlan_max_flows;
216 flow_cfg->rx_vlan_offset = flow_cfg->unicast_offset +
217 OTX2_MAX_UNICAST_FLOWS;
218 pfvf->flags |= OTX2_FLAG_UCAST_FLTR_SUPPORT;
220 /* Check if NPC_DMAC field is supported
221 * by the mkex profile before setting VLAN support flag.
223 freq = otx2_mbox_alloc_msg_npc_get_field_status(&pfvf->mbox);
225 mutex_unlock(&pfvf->mbox.lock);
229 freq->field = NPC_DMAC;
230 if (otx2_sync_mbox_msg(&pfvf->mbox)) {
231 mutex_unlock(&pfvf->mbox.lock);
235 frsp = (struct npc_get_field_status_rsp *)otx2_mbox_get_rsp
236 (&pfvf->mbox.mbox, 0, &freq->hdr);
239 pfvf->flags |= OTX2_FLAG_RX_VLAN_SUPPORT;
240 pfvf->flags |= OTX2_FLAG_VF_VLAN_SUPPORT;
243 pfvf->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
244 mutex_unlock(&pfvf->mbox.lock);
246 /* Allocate entries for Ntuple filters */
247 count = otx2_alloc_mcam_entries(pfvf, OTX2_DEFAULT_FLOWCOUNT);
249 otx2_clear_ntuple_flow_info(pfvf, flow_cfg);
253 pfvf->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
258 /* TODO : revisit on size */
259 #define OTX2_DMAC_FLTR_BITMAP_SZ (4 * 2048 + 32)
261 int otx2vf_mcam_flow_init(struct otx2_nic *pfvf)
263 struct otx2_flow_config *flow_cfg;
265 pfvf->flow_cfg = devm_kzalloc(pfvf->dev,
266 sizeof(struct otx2_flow_config),
271 pfvf->flow_cfg->dmacflt_bmap = devm_kcalloc(pfvf->dev,
272 BITS_TO_LONGS(OTX2_DMAC_FLTR_BITMAP_SZ),
273 sizeof(long), GFP_KERNEL);
274 if (!pfvf->flow_cfg->dmacflt_bmap)
277 flow_cfg = pfvf->flow_cfg;
278 INIT_LIST_HEAD(&flow_cfg->flow_list);
279 INIT_LIST_HEAD(&flow_cfg->flow_list_tc);
280 flow_cfg->max_flows = 0;
284 EXPORT_SYMBOL(otx2vf_mcam_flow_init);
286 int otx2_mcam_flow_init(struct otx2_nic *pf)
290 pf->flow_cfg = devm_kzalloc(pf->dev, sizeof(struct otx2_flow_config),
295 pf->flow_cfg->dmacflt_bmap = devm_kcalloc(pf->dev,
296 BITS_TO_LONGS(OTX2_DMAC_FLTR_BITMAP_SZ),
297 sizeof(long), GFP_KERNEL);
298 if (!pf->flow_cfg->dmacflt_bmap)
301 INIT_LIST_HEAD(&pf->flow_cfg->flow_list);
302 INIT_LIST_HEAD(&pf->flow_cfg->flow_list_tc);
304 /* Allocate bare minimum number of MCAM entries needed for
305 * unicast and ntuple filters.
307 err = otx2_mcam_entry_init(pf);
311 /* Check if MCAM entries are allocate or not */
312 if (!(pf->flags & OTX2_FLAG_UCAST_FLTR_SUPPORT))
315 pf->mac_table = devm_kzalloc(pf->dev, sizeof(struct otx2_mac_table)
316 * OTX2_MAX_UNICAST_FLOWS, GFP_KERNEL);
320 otx2_dmacflt_get_max_cnt(pf);
322 /* DMAC filters are not allocated */
323 if (!pf->flow_cfg->dmacflt_max_flows)
326 pf->flow_cfg->bmap_to_dmacindex =
327 devm_kzalloc(pf->dev, sizeof(u32) *
328 pf->flow_cfg->dmacflt_max_flows,
331 if (!pf->flow_cfg->bmap_to_dmacindex)
334 pf->flags |= OTX2_FLAG_DMACFLTR_SUPPORT;
339 void otx2_mcam_flow_del(struct otx2_nic *pf)
341 otx2_destroy_mcam_flows(pf);
343 EXPORT_SYMBOL(otx2_mcam_flow_del);
345 /* On success adds mcam entry
346 * On failure enable promisous mode
348 static int otx2_do_add_macfilter(struct otx2_nic *pf, const u8 *mac)
350 struct otx2_flow_config *flow_cfg = pf->flow_cfg;
351 struct npc_install_flow_req *req;
354 if (!(pf->flags & OTX2_FLAG_UCAST_FLTR_SUPPORT))
357 /* dont have free mcam entries or uc list is greater than alloted */
358 if (netdev_uc_count(pf->netdev) > OTX2_MAX_UNICAST_FLOWS)
361 mutex_lock(&pf->mbox.lock);
362 req = otx2_mbox_alloc_msg_npc_install_flow(&pf->mbox);
364 mutex_unlock(&pf->mbox.lock);
368 /* unicast offset starts with 32 0..31 for ntuple */
369 for (i = 0; i < OTX2_MAX_UNICAST_FLOWS; i++) {
370 if (pf->mac_table[i].inuse)
372 ether_addr_copy(pf->mac_table[i].addr, mac);
373 pf->mac_table[i].inuse = true;
374 pf->mac_table[i].mcam_entry =
375 flow_cfg->def_ent[i + flow_cfg->unicast_offset];
376 req->entry = pf->mac_table[i].mcam_entry;
380 ether_addr_copy(req->packet.dmac, mac);
381 eth_broadcast_addr((u8 *)&req->mask.dmac);
382 req->features = BIT_ULL(NPC_DMAC);
383 req->channel = pf->hw.rx_chan_base;
384 req->intf = NIX_INTF_RX;
385 req->op = NIX_RX_ACTION_DEFAULT;
388 err = otx2_sync_mbox_msg(&pf->mbox);
389 mutex_unlock(&pf->mbox.lock);
394 int otx2_add_macfilter(struct net_device *netdev, const u8 *mac)
396 struct otx2_nic *pf = netdev_priv(netdev);
398 if (!bitmap_empty(pf->flow_cfg->dmacflt_bmap,
399 pf->flow_cfg->dmacflt_max_flows))
401 "Add %pM to CGX/RPM DMAC filters list as well\n",
404 return otx2_do_add_macfilter(pf, mac);
407 static bool otx2_get_mcamentry_for_mac(struct otx2_nic *pf, const u8 *mac,
412 for (i = 0; i < OTX2_MAX_UNICAST_FLOWS; i++) {
413 if (!pf->mac_table[i].inuse)
416 if (ether_addr_equal(pf->mac_table[i].addr, mac)) {
417 *mcam_entry = pf->mac_table[i].mcam_entry;
418 pf->mac_table[i].inuse = false;
425 int otx2_del_macfilter(struct net_device *netdev, const u8 *mac)
427 struct otx2_nic *pf = netdev_priv(netdev);
428 struct npc_delete_flow_req *req;
431 /* check does mcam entry exists for given mac */
432 if (!otx2_get_mcamentry_for_mac(pf, mac, &mcam_entry))
435 mutex_lock(&pf->mbox.lock);
436 req = otx2_mbox_alloc_msg_npc_delete_flow(&pf->mbox);
438 mutex_unlock(&pf->mbox.lock);
441 req->entry = mcam_entry;
442 /* Send message to AF */
443 err = otx2_sync_mbox_msg(&pf->mbox);
444 mutex_unlock(&pf->mbox.lock);
449 static struct otx2_flow *otx2_find_flow(struct otx2_nic *pfvf, u32 location)
451 struct otx2_flow *iter;
453 list_for_each_entry(iter, &pfvf->flow_cfg->flow_list, list) {
454 if (iter->location == location)
461 static void otx2_add_flow_to_list(struct otx2_nic *pfvf, struct otx2_flow *flow)
463 struct list_head *head = &pfvf->flow_cfg->flow_list;
464 struct otx2_flow *iter;
466 list_for_each_entry(iter, &pfvf->flow_cfg->flow_list, list) {
467 if (iter->location > flow->location)
472 list_add(&flow->list, head);
475 int otx2_get_maxflows(struct otx2_flow_config *flow_cfg)
480 if (flow_cfg->nr_flows == flow_cfg->max_flows ||
481 !bitmap_empty(flow_cfg->dmacflt_bmap,
482 flow_cfg->dmacflt_max_flows))
483 return flow_cfg->max_flows + flow_cfg->dmacflt_max_flows;
485 return flow_cfg->max_flows;
487 EXPORT_SYMBOL(otx2_get_maxflows);
489 int otx2_get_flow(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc,
492 struct otx2_flow *iter;
494 if (location >= otx2_get_maxflows(pfvf->flow_cfg))
497 list_for_each_entry(iter, &pfvf->flow_cfg->flow_list, list) {
498 if (iter->location == location) {
499 nfc->fs = iter->flow_spec;
500 nfc->rss_context = iter->rss_ctx_id;
508 int otx2_get_all_flows(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc,
511 u32 rule_cnt = nfc->rule_cnt;
516 nfc->data = otx2_get_maxflows(pfvf->flow_cfg);
517 while ((!err || err == -ENOENT) && idx < rule_cnt) {
518 err = otx2_get_flow(pfvf, nfc, location);
520 rule_locs[idx++] = location;
523 nfc->rule_cnt = rule_cnt;
528 static int otx2_prepare_ipv4_flow(struct ethtool_rx_flow_spec *fsp,
529 struct npc_install_flow_req *req,
532 struct ethtool_usrip4_spec *ipv4_usr_mask = &fsp->m_u.usr_ip4_spec;
533 struct ethtool_usrip4_spec *ipv4_usr_hdr = &fsp->h_u.usr_ip4_spec;
534 struct ethtool_tcpip4_spec *ipv4_l4_mask = &fsp->m_u.tcp_ip4_spec;
535 struct ethtool_tcpip4_spec *ipv4_l4_hdr = &fsp->h_u.tcp_ip4_spec;
536 struct ethtool_ah_espip4_spec *ah_esp_hdr = &fsp->h_u.ah_ip4_spec;
537 struct ethtool_ah_espip4_spec *ah_esp_mask = &fsp->m_u.ah_ip4_spec;
538 struct flow_msg *pmask = &req->mask;
539 struct flow_msg *pkt = &req->packet;
543 if (ipv4_usr_mask->ip4src) {
544 memcpy(&pkt->ip4src, &ipv4_usr_hdr->ip4src,
545 sizeof(pkt->ip4src));
546 memcpy(&pmask->ip4src, &ipv4_usr_mask->ip4src,
547 sizeof(pmask->ip4src));
548 req->features |= BIT_ULL(NPC_SIP_IPV4);
550 if (ipv4_usr_mask->ip4dst) {
551 memcpy(&pkt->ip4dst, &ipv4_usr_hdr->ip4dst,
552 sizeof(pkt->ip4dst));
553 memcpy(&pmask->ip4dst, &ipv4_usr_mask->ip4dst,
554 sizeof(pmask->ip4dst));
555 req->features |= BIT_ULL(NPC_DIP_IPV4);
557 if (ipv4_usr_mask->tos) {
558 pkt->tos = ipv4_usr_hdr->tos;
559 pmask->tos = ipv4_usr_mask->tos;
560 req->features |= BIT_ULL(NPC_TOS);
562 if (ipv4_usr_mask->proto) {
563 switch (ipv4_usr_hdr->proto) {
565 req->features |= BIT_ULL(NPC_IPPROTO_ICMP);
568 req->features |= BIT_ULL(NPC_IPPROTO_TCP);
571 req->features |= BIT_ULL(NPC_IPPROTO_UDP);
574 req->features |= BIT_ULL(NPC_IPPROTO_SCTP);
577 req->features |= BIT_ULL(NPC_IPPROTO_AH);
580 req->features |= BIT_ULL(NPC_IPPROTO_ESP);
586 pkt->etype = cpu_to_be16(ETH_P_IP);
587 pmask->etype = cpu_to_be16(0xFFFF);
588 req->features |= BIT_ULL(NPC_ETYPE);
593 pkt->etype = cpu_to_be16(ETH_P_IP);
594 pmask->etype = cpu_to_be16(0xFFFF);
595 req->features |= BIT_ULL(NPC_ETYPE);
596 if (ipv4_l4_mask->ip4src) {
597 memcpy(&pkt->ip4src, &ipv4_l4_hdr->ip4src,
598 sizeof(pkt->ip4src));
599 memcpy(&pmask->ip4src, &ipv4_l4_mask->ip4src,
600 sizeof(pmask->ip4src));
601 req->features |= BIT_ULL(NPC_SIP_IPV4);
603 if (ipv4_l4_mask->ip4dst) {
604 memcpy(&pkt->ip4dst, &ipv4_l4_hdr->ip4dst,
605 sizeof(pkt->ip4dst));
606 memcpy(&pmask->ip4dst, &ipv4_l4_mask->ip4dst,
607 sizeof(pmask->ip4dst));
608 req->features |= BIT_ULL(NPC_DIP_IPV4);
610 if (ipv4_l4_mask->tos) {
611 pkt->tos = ipv4_l4_hdr->tos;
612 pmask->tos = ipv4_l4_mask->tos;
613 req->features |= BIT_ULL(NPC_TOS);
615 if (ipv4_l4_mask->psrc) {
616 memcpy(&pkt->sport, &ipv4_l4_hdr->psrc,
618 memcpy(&pmask->sport, &ipv4_l4_mask->psrc,
619 sizeof(pmask->sport));
620 if (flow_type == UDP_V4_FLOW)
621 req->features |= BIT_ULL(NPC_SPORT_UDP);
622 else if (flow_type == TCP_V4_FLOW)
623 req->features |= BIT_ULL(NPC_SPORT_TCP);
625 req->features |= BIT_ULL(NPC_SPORT_SCTP);
627 if (ipv4_l4_mask->pdst) {
628 memcpy(&pkt->dport, &ipv4_l4_hdr->pdst,
630 memcpy(&pmask->dport, &ipv4_l4_mask->pdst,
631 sizeof(pmask->dport));
632 if (flow_type == UDP_V4_FLOW)
633 req->features |= BIT_ULL(NPC_DPORT_UDP);
634 else if (flow_type == TCP_V4_FLOW)
635 req->features |= BIT_ULL(NPC_DPORT_TCP);
637 req->features |= BIT_ULL(NPC_DPORT_SCTP);
639 if (flow_type == UDP_V4_FLOW)
640 req->features |= BIT_ULL(NPC_IPPROTO_UDP);
641 else if (flow_type == TCP_V4_FLOW)
642 req->features |= BIT_ULL(NPC_IPPROTO_TCP);
644 req->features |= BIT_ULL(NPC_IPPROTO_SCTP);
648 pkt->etype = cpu_to_be16(ETH_P_IP);
649 pmask->etype = cpu_to_be16(0xFFFF);
650 req->features |= BIT_ULL(NPC_ETYPE);
651 if (ah_esp_mask->ip4src) {
652 memcpy(&pkt->ip4src, &ah_esp_hdr->ip4src,
653 sizeof(pkt->ip4src));
654 memcpy(&pmask->ip4src, &ah_esp_mask->ip4src,
655 sizeof(pmask->ip4src));
656 req->features |= BIT_ULL(NPC_SIP_IPV4);
658 if (ah_esp_mask->ip4dst) {
659 memcpy(&pkt->ip4dst, &ah_esp_hdr->ip4dst,
660 sizeof(pkt->ip4dst));
661 memcpy(&pmask->ip4dst, &ah_esp_mask->ip4dst,
662 sizeof(pmask->ip4dst));
663 req->features |= BIT_ULL(NPC_DIP_IPV4);
665 if (ah_esp_mask->tos) {
666 pkt->tos = ah_esp_hdr->tos;
667 pmask->tos = ah_esp_mask->tos;
668 req->features |= BIT_ULL(NPC_TOS);
671 /* NPC profile doesn't extract AH/ESP header fields */
672 if (ah_esp_mask->spi & ah_esp_hdr->spi)
675 if (flow_type == AH_V4_FLOW)
676 req->features |= BIT_ULL(NPC_IPPROTO_AH);
678 req->features |= BIT_ULL(NPC_IPPROTO_ESP);
687 static int otx2_prepare_ipv6_flow(struct ethtool_rx_flow_spec *fsp,
688 struct npc_install_flow_req *req,
691 struct ethtool_usrip6_spec *ipv6_usr_mask = &fsp->m_u.usr_ip6_spec;
692 struct ethtool_usrip6_spec *ipv6_usr_hdr = &fsp->h_u.usr_ip6_spec;
693 struct ethtool_tcpip6_spec *ipv6_l4_mask = &fsp->m_u.tcp_ip6_spec;
694 struct ethtool_tcpip6_spec *ipv6_l4_hdr = &fsp->h_u.tcp_ip6_spec;
695 struct ethtool_ah_espip6_spec *ah_esp_hdr = &fsp->h_u.ah_ip6_spec;
696 struct ethtool_ah_espip6_spec *ah_esp_mask = &fsp->m_u.ah_ip6_spec;
697 struct flow_msg *pmask = &req->mask;
698 struct flow_msg *pkt = &req->packet;
702 if (!ipv6_addr_any((struct in6_addr *)ipv6_usr_mask->ip6src)) {
703 memcpy(&pkt->ip6src, &ipv6_usr_hdr->ip6src,
704 sizeof(pkt->ip6src));
705 memcpy(&pmask->ip6src, &ipv6_usr_mask->ip6src,
706 sizeof(pmask->ip6src));
707 req->features |= BIT_ULL(NPC_SIP_IPV6);
709 if (!ipv6_addr_any((struct in6_addr *)ipv6_usr_mask->ip6dst)) {
710 memcpy(&pkt->ip6dst, &ipv6_usr_hdr->ip6dst,
711 sizeof(pkt->ip6dst));
712 memcpy(&pmask->ip6dst, &ipv6_usr_mask->ip6dst,
713 sizeof(pmask->ip6dst));
714 req->features |= BIT_ULL(NPC_DIP_IPV6);
716 if (ipv6_usr_hdr->l4_proto == IPPROTO_FRAGMENT) {
717 pkt->next_header = ipv6_usr_hdr->l4_proto;
718 pmask->next_header = ipv6_usr_mask->l4_proto;
719 req->features |= BIT_ULL(NPC_IPFRAG_IPV6);
721 pkt->etype = cpu_to_be16(ETH_P_IPV6);
722 pmask->etype = cpu_to_be16(0xFFFF);
723 req->features |= BIT_ULL(NPC_ETYPE);
728 pkt->etype = cpu_to_be16(ETH_P_IPV6);
729 pmask->etype = cpu_to_be16(0xFFFF);
730 req->features |= BIT_ULL(NPC_ETYPE);
731 if (!ipv6_addr_any((struct in6_addr *)ipv6_l4_mask->ip6src)) {
732 memcpy(&pkt->ip6src, &ipv6_l4_hdr->ip6src,
733 sizeof(pkt->ip6src));
734 memcpy(&pmask->ip6src, &ipv6_l4_mask->ip6src,
735 sizeof(pmask->ip6src));
736 req->features |= BIT_ULL(NPC_SIP_IPV6);
738 if (!ipv6_addr_any((struct in6_addr *)ipv6_l4_mask->ip6dst)) {
739 memcpy(&pkt->ip6dst, &ipv6_l4_hdr->ip6dst,
740 sizeof(pkt->ip6dst));
741 memcpy(&pmask->ip6dst, &ipv6_l4_mask->ip6dst,
742 sizeof(pmask->ip6dst));
743 req->features |= BIT_ULL(NPC_DIP_IPV6);
745 if (ipv6_l4_mask->psrc) {
746 memcpy(&pkt->sport, &ipv6_l4_hdr->psrc,
748 memcpy(&pmask->sport, &ipv6_l4_mask->psrc,
749 sizeof(pmask->sport));
750 if (flow_type == UDP_V6_FLOW)
751 req->features |= BIT_ULL(NPC_SPORT_UDP);
752 else if (flow_type == TCP_V6_FLOW)
753 req->features |= BIT_ULL(NPC_SPORT_TCP);
755 req->features |= BIT_ULL(NPC_SPORT_SCTP);
757 if (ipv6_l4_mask->pdst) {
758 memcpy(&pkt->dport, &ipv6_l4_hdr->pdst,
760 memcpy(&pmask->dport, &ipv6_l4_mask->pdst,
761 sizeof(pmask->dport));
762 if (flow_type == UDP_V6_FLOW)
763 req->features |= BIT_ULL(NPC_DPORT_UDP);
764 else if (flow_type == TCP_V6_FLOW)
765 req->features |= BIT_ULL(NPC_DPORT_TCP);
767 req->features |= BIT_ULL(NPC_DPORT_SCTP);
769 if (flow_type == UDP_V6_FLOW)
770 req->features |= BIT_ULL(NPC_IPPROTO_UDP);
771 else if (flow_type == TCP_V6_FLOW)
772 req->features |= BIT_ULL(NPC_IPPROTO_TCP);
774 req->features |= BIT_ULL(NPC_IPPROTO_SCTP);
778 pkt->etype = cpu_to_be16(ETH_P_IPV6);
779 pmask->etype = cpu_to_be16(0xFFFF);
780 req->features |= BIT_ULL(NPC_ETYPE);
781 if (!ipv6_addr_any((struct in6_addr *)ah_esp_hdr->ip6src)) {
782 memcpy(&pkt->ip6src, &ah_esp_hdr->ip6src,
783 sizeof(pkt->ip6src));
784 memcpy(&pmask->ip6src, &ah_esp_mask->ip6src,
785 sizeof(pmask->ip6src));
786 req->features |= BIT_ULL(NPC_SIP_IPV6);
788 if (!ipv6_addr_any((struct in6_addr *)ah_esp_hdr->ip6dst)) {
789 memcpy(&pkt->ip6dst, &ah_esp_hdr->ip6dst,
790 sizeof(pkt->ip6dst));
791 memcpy(&pmask->ip6dst, &ah_esp_mask->ip6dst,
792 sizeof(pmask->ip6dst));
793 req->features |= BIT_ULL(NPC_DIP_IPV6);
796 /* NPC profile doesn't extract AH/ESP header fields */
797 if ((ah_esp_mask->spi & ah_esp_hdr->spi) ||
798 (ah_esp_mask->tclass & ah_esp_hdr->tclass))
801 if (flow_type == AH_V6_FLOW)
802 req->features |= BIT_ULL(NPC_IPPROTO_AH);
804 req->features |= BIT_ULL(NPC_IPPROTO_ESP);
813 static int otx2_prepare_flow_request(struct ethtool_rx_flow_spec *fsp,
814 struct npc_install_flow_req *req)
816 struct ethhdr *eth_mask = &fsp->m_u.ether_spec;
817 struct ethhdr *eth_hdr = &fsp->h_u.ether_spec;
818 struct flow_msg *pmask = &req->mask;
819 struct flow_msg *pkt = &req->packet;
823 flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS);
825 /* bits not set in mask are don't care */
827 if (!is_zero_ether_addr(eth_mask->h_source)) {
828 ether_addr_copy(pkt->smac, eth_hdr->h_source);
829 ether_addr_copy(pmask->smac, eth_mask->h_source);
830 req->features |= BIT_ULL(NPC_SMAC);
832 if (!is_zero_ether_addr(eth_mask->h_dest)) {
833 ether_addr_copy(pkt->dmac, eth_hdr->h_dest);
834 ether_addr_copy(pmask->dmac, eth_mask->h_dest);
835 req->features |= BIT_ULL(NPC_DMAC);
837 if (eth_hdr->h_proto) {
838 memcpy(&pkt->etype, ð_hdr->h_proto,
840 memcpy(&pmask->etype, ð_mask->h_proto,
841 sizeof(pmask->etype));
842 req->features |= BIT_ULL(NPC_ETYPE);
851 ret = otx2_prepare_ipv4_flow(fsp, req, flow_type);
861 ret = otx2_prepare_ipv6_flow(fsp, req, flow_type);
868 if (fsp->flow_type & FLOW_EXT) {
871 if (fsp->m_ext.vlan_etype) {
872 /* Partial masks not supported */
873 if (be16_to_cpu(fsp->m_ext.vlan_etype) != 0xFFFF)
876 vlan_etype = be16_to_cpu(fsp->h_ext.vlan_etype);
878 /* Drop rule with vlan_etype == 802.1Q
879 * and vlan_id == 0 is not supported
881 if (vlan_etype == ETH_P_8021Q && !fsp->m_ext.vlan_tci &&
882 fsp->ring_cookie == RX_CLS_FLOW_DISC)
885 /* Only ETH_P_8021Q and ETH_P_802AD types supported */
886 if (vlan_etype != ETH_P_8021Q &&
887 vlan_etype != ETH_P_8021AD)
890 memcpy(&pkt->vlan_etype, &fsp->h_ext.vlan_etype,
891 sizeof(pkt->vlan_etype));
892 memcpy(&pmask->vlan_etype, &fsp->m_ext.vlan_etype,
893 sizeof(pmask->vlan_etype));
895 if (vlan_etype == ETH_P_8021Q)
896 req->features |= BIT_ULL(NPC_VLAN_ETYPE_CTAG);
898 req->features |= BIT_ULL(NPC_VLAN_ETYPE_STAG);
901 if (fsp->m_ext.vlan_tci) {
902 memcpy(&pkt->vlan_tci, &fsp->h_ext.vlan_tci,
903 sizeof(pkt->vlan_tci));
904 memcpy(&pmask->vlan_tci, &fsp->m_ext.vlan_tci,
905 sizeof(pmask->vlan_tci));
906 req->features |= BIT_ULL(NPC_OUTER_VID);
909 if (fsp->m_ext.data[1]) {
910 if (flow_type == IP_USER_FLOW) {
911 if (be32_to_cpu(fsp->h_ext.data[1]) != IPV4_FLAG_MORE)
914 pkt->ip_flag = be32_to_cpu(fsp->h_ext.data[1]);
915 pmask->ip_flag = be32_to_cpu(fsp->m_ext.data[1]);
916 req->features |= BIT_ULL(NPC_IPFRAG_IPV4);
917 } else if (fsp->h_ext.data[1] ==
918 cpu_to_be32(OTX2_DEFAULT_ACTION)) {
919 /* Not Drop/Direct to queue but use action
922 req->op = NIX_RX_ACTION_DEFAULT;
927 if (fsp->flow_type & FLOW_MAC_EXT &&
928 !is_zero_ether_addr(fsp->m_ext.h_dest)) {
929 ether_addr_copy(pkt->dmac, fsp->h_ext.h_dest);
930 ether_addr_copy(pmask->dmac, fsp->m_ext.h_dest);
931 req->features |= BIT_ULL(NPC_DMAC);
940 static int otx2_is_flow_rule_dmacfilter(struct otx2_nic *pfvf,
941 struct ethtool_rx_flow_spec *fsp)
943 struct ethhdr *eth_mask = &fsp->m_u.ether_spec;
944 struct ethhdr *eth_hdr = &fsp->h_u.ether_spec;
945 u64 ring_cookie = fsp->ring_cookie;
948 if (!(pfvf->flags & OTX2_FLAG_DMACFLTR_SUPPORT))
951 flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS);
953 /* CGX/RPM block dmac filtering configured for white listing
954 * check for action other than DROP
956 if (flow_type == ETHER_FLOW && ring_cookie != RX_CLS_FLOW_DISC &&
957 !ethtool_get_flow_spec_ring_vf(ring_cookie)) {
958 if (is_zero_ether_addr(eth_mask->h_dest) &&
959 is_valid_ether_addr(eth_hdr->h_dest))
966 static int otx2_add_flow_msg(struct otx2_nic *pfvf, struct otx2_flow *flow)
968 u64 ring_cookie = flow->flow_spec.ring_cookie;
970 int vlan_prio, qidx, pfc_rule = 0;
972 struct npc_install_flow_req *req;
975 mutex_lock(&pfvf->mbox.lock);
976 req = otx2_mbox_alloc_msg_npc_install_flow(&pfvf->mbox);
978 mutex_unlock(&pfvf->mbox.lock);
982 err = otx2_prepare_flow_request(&flow->flow_spec, req);
984 /* free the allocated msg above */
985 otx2_mbox_reset(&pfvf->mbox.mbox, 0);
986 mutex_unlock(&pfvf->mbox.lock);
990 req->entry = flow->entry;
991 req->intf = NIX_INTF_RX;
993 req->channel = pfvf->hw.rx_chan_base;
994 if (ring_cookie == RX_CLS_FLOW_DISC) {
995 req->op = NIX_RX_ACTIONOP_DROP;
997 /* change to unicast only if action of default entry is not
1000 if (flow->flow_spec.flow_type & FLOW_RSS) {
1001 req->op = NIX_RX_ACTIONOP_RSS;
1002 req->index = flow->rss_ctx_id;
1003 req->flow_key_alg = pfvf->hw.flowkey_alg_idx;
1005 req->op = NIX_RX_ACTIONOP_UCAST;
1006 req->index = ethtool_get_flow_spec_ring(ring_cookie);
1008 vf = ethtool_get_flow_spec_ring_vf(ring_cookie);
1009 if (vf > pci_num_vf(pfvf->pdev)) {
1010 mutex_unlock(&pfvf->mbox.lock);
1015 /* Identify PFC rule if PFC enabled and ntuple rule is vlan */
1016 if (!vf && (req->features & BIT_ULL(NPC_OUTER_VID)) &&
1017 pfvf->pfc_en && req->op != NIX_RX_ACTIONOP_RSS) {
1018 vlan_prio = ntohs(req->packet.vlan_tci) &
1019 ntohs(req->mask.vlan_tci);
1021 /* Get the priority */
1023 flow->rule_type |= PFC_FLOWCTRL_RULE;
1024 /* Check if PFC enabled for this priority */
1025 if (pfvf->pfc_en & BIT(vlan_prio)) {
1033 /* ethtool ring_cookie has (VF + 1) for VF */
1040 /* Send message to AF */
1041 err = otx2_sync_mbox_msg(&pfvf->mbox);
1044 if (!err && pfc_rule)
1045 otx2_update_bpid_in_rqctx(pfvf, vlan_prio, qidx, true);
1048 mutex_unlock(&pfvf->mbox.lock);
1052 static int otx2_add_flow_with_pfmac(struct otx2_nic *pfvf,
1053 struct otx2_flow *flow)
1055 struct otx2_flow *pf_mac;
1056 struct ethhdr *eth_hdr;
1058 pf_mac = kzalloc(sizeof(*pf_mac), GFP_KERNEL);
1063 pf_mac->rule_type |= DMAC_FILTER_RULE;
1064 pf_mac->location = pfvf->flow_cfg->max_flows;
1065 memcpy(&pf_mac->flow_spec, &flow->flow_spec,
1066 sizeof(struct ethtool_rx_flow_spec));
1067 pf_mac->flow_spec.location = pf_mac->location;
1069 /* Copy PF mac address */
1070 eth_hdr = &pf_mac->flow_spec.h_u.ether_spec;
1071 ether_addr_copy(eth_hdr->h_dest, pfvf->netdev->dev_addr);
1073 /* Install DMAC filter with PF mac address */
1074 otx2_dmacflt_add(pfvf, eth_hdr->h_dest, 0);
1076 otx2_add_flow_to_list(pfvf, pf_mac);
1077 pfvf->flow_cfg->nr_flows++;
1078 set_bit(0, pfvf->flow_cfg->dmacflt_bmap);
1083 int otx2_add_flow(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc)
1085 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1086 struct ethtool_rx_flow_spec *fsp = &nfc->fs;
1087 struct otx2_flow *flow;
1088 struct ethhdr *eth_hdr;
1094 if (!flow_cfg->max_flows) {
1095 netdev_err(pfvf->netdev,
1096 "Ntuple rule count is 0, allocate and retry\n");
1100 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
1101 if (!(pfvf->flags & OTX2_FLAG_NTUPLE_SUPPORT))
1104 /* Number of queues on a VF can be greater or less than
1105 * the PF's queue. Hence no need to check for the
1106 * queue count. Hence no need to check queue count if PF
1107 * is installing for its VF. Below is the expected vf_num value
1108 * based on the ethtool commands.
1111 * 1. ethtool -U <netdev> ... action -1 ==> vf_num:255
1112 * 2. ethtool -U <netdev> ... action <queue_num> ==> vf_num:0
1113 * 3. ethtool -U <netdev> ... vf <vf_idx> queue <queue_num> ==>
1116 vf_num = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
1117 if (!is_otx2_vf(pfvf->pcifunc) && !vf_num &&
1118 ring >= pfvf->hw.rx_queues && fsp->ring_cookie != RX_CLS_FLOW_DISC)
1121 if (fsp->location >= otx2_get_maxflows(flow_cfg))
1124 flow = otx2_find_flow(pfvf, fsp->location);
1126 flow = kzalloc(sizeof(*flow), GFP_KERNEL);
1129 flow->location = fsp->location;
1130 flow->entry = flow_cfg->flow_ent[flow->location];
1134 flow->flow_spec = *fsp;
1136 if (fsp->flow_type & FLOW_RSS)
1137 flow->rss_ctx_id = nfc->rss_context;
1139 if (otx2_is_flow_rule_dmacfilter(pfvf, &flow->flow_spec)) {
1140 eth_hdr = &flow->flow_spec.h_u.ether_spec;
1142 /* Sync dmac filter table with updated fields */
1143 if (flow->rule_type & DMAC_FILTER_RULE)
1144 return otx2_dmacflt_update(pfvf, eth_hdr->h_dest,
1147 if (bitmap_full(flow_cfg->dmacflt_bmap,
1148 flow_cfg->dmacflt_max_flows)) {
1149 netdev_warn(pfvf->netdev,
1150 "Can't insert the rule %d as max allowed dmac filters are %d\n",
1152 flow_cfg->dmacflt_max_flows,
1153 flow_cfg->dmacflt_max_flows);
1160 /* Install PF mac address to DMAC filter list */
1161 if (!test_bit(0, flow_cfg->dmacflt_bmap))
1162 otx2_add_flow_with_pfmac(pfvf, flow);
1164 flow->rule_type |= DMAC_FILTER_RULE;
1165 flow->entry = find_first_zero_bit(flow_cfg->dmacflt_bmap,
1166 flow_cfg->dmacflt_max_flows);
1167 fsp->location = flow_cfg->max_flows + flow->entry;
1168 flow->flow_spec.location = fsp->location;
1169 flow->location = fsp->location;
1171 set_bit(flow->entry, flow_cfg->dmacflt_bmap);
1172 otx2_dmacflt_add(pfvf, eth_hdr->h_dest, flow->entry);
1175 if (flow->location >= pfvf->flow_cfg->max_flows) {
1176 netdev_warn(pfvf->netdev,
1177 "Can't insert non dmac ntuple rule at %d, allowed range %d-0\n",
1179 flow_cfg->max_flows - 1);
1182 err = otx2_add_flow_msg(pfvf, flow);
1187 if (err == MBOX_MSG_INVALID)
1194 /* add the new flow installed to list */
1196 otx2_add_flow_to_list(pfvf, flow);
1197 flow_cfg->nr_flows++;
1201 netdev_info(pfvf->netdev,
1202 "Make sure that VF's queue number is within its queue limit\n");
1206 static int otx2_remove_flow_msg(struct otx2_nic *pfvf, u16 entry, bool all)
1208 struct npc_delete_flow_req *req;
1211 mutex_lock(&pfvf->mbox.lock);
1212 req = otx2_mbox_alloc_msg_npc_delete_flow(&pfvf->mbox);
1214 mutex_unlock(&pfvf->mbox.lock);
1222 /* Send message to AF */
1223 err = otx2_sync_mbox_msg(&pfvf->mbox);
1224 mutex_unlock(&pfvf->mbox.lock);
1228 static void otx2_update_rem_pfmac(struct otx2_nic *pfvf, int req)
1230 struct otx2_flow *iter;
1231 struct ethhdr *eth_hdr;
1234 list_for_each_entry(iter, &pfvf->flow_cfg->flow_list, list) {
1235 if ((iter->rule_type & DMAC_FILTER_RULE) && iter->entry == 0) {
1236 eth_hdr = &iter->flow_spec.h_u.ether_spec;
1237 if (req == DMAC_ADDR_DEL) {
1238 otx2_dmacflt_remove(pfvf, eth_hdr->h_dest,
1240 clear_bit(0, pfvf->flow_cfg->dmacflt_bmap);
1243 ether_addr_copy(eth_hdr->h_dest,
1244 pfvf->netdev->dev_addr);
1246 otx2_dmacflt_update(pfvf, eth_hdr->h_dest, 0);
1253 list_del(&iter->list);
1255 pfvf->flow_cfg->nr_flows--;
1259 int otx2_remove_flow(struct otx2_nic *pfvf, u32 location)
1261 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1262 struct otx2_flow *flow;
1265 if (location >= otx2_get_maxflows(flow_cfg))
1268 flow = otx2_find_flow(pfvf, location);
1272 if (flow->rule_type & DMAC_FILTER_RULE) {
1273 struct ethhdr *eth_hdr = &flow->flow_spec.h_u.ether_spec;
1275 /* user not allowed to remove dmac filter with interface mac */
1276 if (ether_addr_equal(pfvf->netdev->dev_addr, eth_hdr->h_dest))
1279 err = otx2_dmacflt_remove(pfvf, eth_hdr->h_dest,
1281 clear_bit(flow->entry, flow_cfg->dmacflt_bmap);
1282 /* If all dmac filters are removed delete macfilter with
1283 * interface mac address and configure CGX/RPM block in
1286 if (bitmap_weight(flow_cfg->dmacflt_bmap,
1287 flow_cfg->dmacflt_max_flows) == 1)
1288 otx2_update_rem_pfmac(pfvf, DMAC_ADDR_DEL);
1291 if (flow->rule_type & PFC_FLOWCTRL_RULE)
1292 otx2_update_bpid_in_rqctx(pfvf, 0,
1293 flow->flow_spec.ring_cookie,
1297 err = otx2_remove_flow_msg(pfvf, flow->entry, false);
1303 list_del(&flow->list);
1305 flow_cfg->nr_flows--;
1310 void otx2_rss_ctx_flow_del(struct otx2_nic *pfvf, int ctx_id)
1312 struct otx2_flow *flow, *tmp;
1315 list_for_each_entry_safe(flow, tmp, &pfvf->flow_cfg->flow_list, list) {
1316 if (flow->rss_ctx_id != ctx_id)
1318 err = otx2_remove_flow(pfvf, flow->location);
1320 netdev_warn(pfvf->netdev,
1321 "Can't delete the rule %d associated with this rss group err:%d",
1322 flow->location, err);
1326 int otx2_destroy_ntuple_flows(struct otx2_nic *pfvf)
1328 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1329 struct npc_delete_flow_req *req;
1330 struct otx2_flow *iter, *tmp;
1333 if (!(pfvf->flags & OTX2_FLAG_NTUPLE_SUPPORT))
1336 if (!flow_cfg->max_flows)
1339 mutex_lock(&pfvf->mbox.lock);
1340 req = otx2_mbox_alloc_msg_npc_delete_flow(&pfvf->mbox);
1342 mutex_unlock(&pfvf->mbox.lock);
1346 req->start = flow_cfg->flow_ent[0];
1347 req->end = flow_cfg->flow_ent[flow_cfg->max_flows - 1];
1348 err = otx2_sync_mbox_msg(&pfvf->mbox);
1349 mutex_unlock(&pfvf->mbox.lock);
1351 list_for_each_entry_safe(iter, tmp, &flow_cfg->flow_list, list) {
1352 list_del(&iter->list);
1354 flow_cfg->nr_flows--;
1359 int otx2_destroy_mcam_flows(struct otx2_nic *pfvf)
1361 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1362 struct npc_mcam_free_entry_req *req;
1363 struct otx2_flow *iter, *tmp;
1366 if (!(pfvf->flags & OTX2_FLAG_MCAM_ENTRIES_ALLOC))
1369 /* remove all flows */
1370 err = otx2_remove_flow_msg(pfvf, 0, true);
1374 list_for_each_entry_safe(iter, tmp, &flow_cfg->flow_list, list) {
1375 list_del(&iter->list);
1377 flow_cfg->nr_flows--;
1380 mutex_lock(&pfvf->mbox.lock);
1381 req = otx2_mbox_alloc_msg_npc_mcam_free_entry(&pfvf->mbox);
1383 mutex_unlock(&pfvf->mbox.lock);
1388 /* Send message to AF to free MCAM entries */
1389 err = otx2_sync_mbox_msg(&pfvf->mbox);
1391 mutex_unlock(&pfvf->mbox.lock);
1395 pfvf->flags &= ~OTX2_FLAG_MCAM_ENTRIES_ALLOC;
1396 mutex_unlock(&pfvf->mbox.lock);
1401 int otx2_install_rxvlan_offload_flow(struct otx2_nic *pfvf)
1403 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1404 struct npc_install_flow_req *req;
1407 mutex_lock(&pfvf->mbox.lock);
1408 req = otx2_mbox_alloc_msg_npc_install_flow(&pfvf->mbox);
1410 mutex_unlock(&pfvf->mbox.lock);
1414 req->entry = flow_cfg->def_ent[flow_cfg->rx_vlan_offset];
1415 req->intf = NIX_INTF_RX;
1416 ether_addr_copy(req->packet.dmac, pfvf->netdev->dev_addr);
1417 eth_broadcast_addr((u8 *)&req->mask.dmac);
1418 req->channel = pfvf->hw.rx_chan_base;
1419 req->op = NIX_RX_ACTION_DEFAULT;
1420 req->features = BIT_ULL(NPC_OUTER_VID) | BIT_ULL(NPC_DMAC);
1421 req->vtag0_valid = true;
1422 req->vtag0_type = NIX_AF_LFX_RX_VTAG_TYPE0;
1424 /* Send message to AF */
1425 err = otx2_sync_mbox_msg(&pfvf->mbox);
1426 mutex_unlock(&pfvf->mbox.lock);
1430 static int otx2_delete_rxvlan_offload_flow(struct otx2_nic *pfvf)
1432 struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
1433 struct npc_delete_flow_req *req;
1436 mutex_lock(&pfvf->mbox.lock);
1437 req = otx2_mbox_alloc_msg_npc_delete_flow(&pfvf->mbox);
1439 mutex_unlock(&pfvf->mbox.lock);
1443 req->entry = flow_cfg->def_ent[flow_cfg->rx_vlan_offset];
1444 /* Send message to AF */
1445 err = otx2_sync_mbox_msg(&pfvf->mbox);
1446 mutex_unlock(&pfvf->mbox.lock);
1450 int otx2_enable_rxvlan(struct otx2_nic *pf, bool enable)
1452 struct nix_vtag_config *req;
1453 struct mbox_msghdr *rsp_hdr;
1456 /* Dont have enough mcam entries */
1457 if (!(pf->flags & OTX2_FLAG_RX_VLAN_SUPPORT))
1461 err = otx2_install_rxvlan_offload_flow(pf);
1465 err = otx2_delete_rxvlan_offload_flow(pf);
1470 mutex_lock(&pf->mbox.lock);
1471 req = otx2_mbox_alloc_msg_nix_vtag_cfg(&pf->mbox);
1473 mutex_unlock(&pf->mbox.lock);
1477 /* config strip, capture and size */
1478 req->vtag_size = VTAGSIZE_T4;
1479 req->cfg_type = 1; /* rx vlan cfg */
1480 req->rx.vtag_type = NIX_AF_LFX_RX_VTAG_TYPE0;
1481 req->rx.strip_vtag = enable;
1482 req->rx.capture_vtag = enable;
1484 err = otx2_sync_mbox_msg(&pf->mbox);
1486 mutex_unlock(&pf->mbox.lock);
1490 rsp_hdr = otx2_mbox_get_rsp(&pf->mbox.mbox, 0, &req->hdr);
1491 if (IS_ERR(rsp_hdr)) {
1492 mutex_unlock(&pf->mbox.lock);
1493 return PTR_ERR(rsp_hdr);
1496 mutex_unlock(&pf->mbox.lock);
1500 void otx2_dmacflt_reinstall_flows(struct otx2_nic *pf)
1502 struct otx2_flow *iter;
1503 struct ethhdr *eth_hdr;
1505 list_for_each_entry(iter, &pf->flow_cfg->flow_list, list) {
1506 if (iter->rule_type & DMAC_FILTER_RULE) {
1507 eth_hdr = &iter->flow_spec.h_u.ether_spec;
1508 otx2_dmacflt_add(pf, eth_hdr->h_dest,
1514 void otx2_dmacflt_update_pfmac_flow(struct otx2_nic *pfvf)
1516 otx2_update_rem_pfmac(pfvf, DMAC_ADDR_UPDATE);