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
;
1093 if (!flow_cfg
->max_flows
) {
1094 netdev_err(pfvf
->netdev
,
1095 "Ntuple rule count is 0, allocate and retry\n");
1099 ring
= ethtool_get_flow_spec_ring(fsp
->ring_cookie
);
1100 if (!(pfvf
->flags
& OTX2_FLAG_NTUPLE_SUPPORT
))
1103 if (ring
>= pfvf
->hw
.rx_queues
&& fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
)
1106 if (fsp
->location
>= otx2_get_maxflows(flow_cfg
))
1109 flow
= otx2_find_flow(pfvf
, fsp
->location
);
1111 flow
= kzalloc(sizeof(*flow
), GFP_KERNEL
);
1114 flow
->location
= fsp
->location
;
1115 flow
->entry
= flow_cfg
->flow_ent
[flow
->location
];
1119 flow
->flow_spec
= *fsp
;
1121 if (fsp
->flow_type
& FLOW_RSS
)
1122 flow
->rss_ctx_id
= nfc
->rss_context
;
1124 if (otx2_is_flow_rule_dmacfilter(pfvf
, &flow
->flow_spec
)) {
1125 eth_hdr
= &flow
->flow_spec
.h_u
.ether_spec
;
1127 /* Sync dmac filter table with updated fields */
1128 if (flow
->rule_type
& DMAC_FILTER_RULE
)
1129 return otx2_dmacflt_update(pfvf
, eth_hdr
->h_dest
,
1132 if (bitmap_full(flow_cfg
->dmacflt_bmap
,
1133 flow_cfg
->dmacflt_max_flows
)) {
1134 netdev_warn(pfvf
->netdev
,
1135 "Can't insert the rule %d as max allowed dmac filters are %d\n",
1137 flow_cfg
->dmacflt_max_flows
,
1138 flow_cfg
->dmacflt_max_flows
);
1145 /* Install PF mac address to DMAC filter list */
1146 if (!test_bit(0, flow_cfg
->dmacflt_bmap
))
1147 otx2_add_flow_with_pfmac(pfvf
, flow
);
1149 flow
->rule_type
|= DMAC_FILTER_RULE
;
1150 flow
->entry
= find_first_zero_bit(flow_cfg
->dmacflt_bmap
,
1151 flow_cfg
->dmacflt_max_flows
);
1152 fsp
->location
= flow_cfg
->max_flows
+ flow
->entry
;
1153 flow
->flow_spec
.location
= fsp
->location
;
1154 flow
->location
= fsp
->location
;
1156 set_bit(flow
->entry
, flow_cfg
->dmacflt_bmap
);
1157 otx2_dmacflt_add(pfvf
, eth_hdr
->h_dest
, flow
->entry
);
1160 if (flow
->location
>= pfvf
->flow_cfg
->max_flows
) {
1161 netdev_warn(pfvf
->netdev
,
1162 "Can't insert non dmac ntuple rule at %d, allowed range %d-0\n",
1164 flow_cfg
->max_flows
- 1);
1167 err
= otx2_add_flow_msg(pfvf
, flow
);
1172 if (err
== MBOX_MSG_INVALID
)
1179 /* add the new flow installed to list */
1181 otx2_add_flow_to_list(pfvf
, flow
);
1182 flow_cfg
->nr_flows
++;
1188 static int otx2_remove_flow_msg(struct otx2_nic
*pfvf
, u16 entry
, bool all
)
1190 struct npc_delete_flow_req
*req
;
1193 mutex_lock(&pfvf
->mbox
.lock
);
1194 req
= otx2_mbox_alloc_msg_npc_delete_flow(&pfvf
->mbox
);
1196 mutex_unlock(&pfvf
->mbox
.lock
);
1204 /* Send message to AF */
1205 err
= otx2_sync_mbox_msg(&pfvf
->mbox
);
1206 mutex_unlock(&pfvf
->mbox
.lock
);
1210 static void otx2_update_rem_pfmac(struct otx2_nic
*pfvf
, int req
)
1212 struct otx2_flow
*iter
;
1213 struct ethhdr
*eth_hdr
;
1216 list_for_each_entry(iter
, &pfvf
->flow_cfg
->flow_list
, list
) {
1217 if ((iter
->rule_type
& DMAC_FILTER_RULE
) && iter
->entry
== 0) {
1218 eth_hdr
= &iter
->flow_spec
.h_u
.ether_spec
;
1219 if (req
== DMAC_ADDR_DEL
) {
1220 otx2_dmacflt_remove(pfvf
, eth_hdr
->h_dest
,
1222 clear_bit(0, pfvf
->flow_cfg
->dmacflt_bmap
);
1225 ether_addr_copy(eth_hdr
->h_dest
,
1226 pfvf
->netdev
->dev_addr
);
1228 otx2_dmacflt_update(pfvf
, eth_hdr
->h_dest
, 0);
1235 list_del(&iter
->list
);
1237 pfvf
->flow_cfg
->nr_flows
--;
1241 int otx2_remove_flow(struct otx2_nic
*pfvf
, u32 location
)
1243 struct otx2_flow_config
*flow_cfg
= pfvf
->flow_cfg
;
1244 struct otx2_flow
*flow
;
1247 if (location
>= otx2_get_maxflows(flow_cfg
))
1250 flow
= otx2_find_flow(pfvf
, location
);
1254 if (flow
->rule_type
& DMAC_FILTER_RULE
) {
1255 struct ethhdr
*eth_hdr
= &flow
->flow_spec
.h_u
.ether_spec
;
1257 /* user not allowed to remove dmac filter with interface mac */
1258 if (ether_addr_equal(pfvf
->netdev
->dev_addr
, eth_hdr
->h_dest
))
1261 err
= otx2_dmacflt_remove(pfvf
, eth_hdr
->h_dest
,
1263 clear_bit(flow
->entry
, flow_cfg
->dmacflt_bmap
);
1264 /* If all dmac filters are removed delete macfilter with
1265 * interface mac address and configure CGX/RPM block in
1268 if (bitmap_weight(flow_cfg
->dmacflt_bmap
,
1269 flow_cfg
->dmacflt_max_flows
) == 1)
1270 otx2_update_rem_pfmac(pfvf
, DMAC_ADDR_DEL
);
1273 if (flow
->rule_type
& PFC_FLOWCTRL_RULE
)
1274 otx2_update_bpid_in_rqctx(pfvf
, 0,
1275 flow
->flow_spec
.ring_cookie
,
1279 err
= otx2_remove_flow_msg(pfvf
, flow
->entry
, false);
1285 list_del(&flow
->list
);
1287 flow_cfg
->nr_flows
--;
1292 void otx2_rss_ctx_flow_del(struct otx2_nic
*pfvf
, int ctx_id
)
1294 struct otx2_flow
*flow
, *tmp
;
1297 list_for_each_entry_safe(flow
, tmp
, &pfvf
->flow_cfg
->flow_list
, list
) {
1298 if (flow
->rss_ctx_id
!= ctx_id
)
1300 err
= otx2_remove_flow(pfvf
, flow
->location
);
1302 netdev_warn(pfvf
->netdev
,
1303 "Can't delete the rule %d associated with this rss group err:%d",
1304 flow
->location
, err
);
1308 int otx2_destroy_ntuple_flows(struct otx2_nic
*pfvf
)
1310 struct otx2_flow_config
*flow_cfg
= pfvf
->flow_cfg
;
1311 struct npc_delete_flow_req
*req
;
1312 struct otx2_flow
*iter
, *tmp
;
1315 if (!(pfvf
->flags
& OTX2_FLAG_NTUPLE_SUPPORT
))
1318 if (!flow_cfg
->max_flows
)
1321 mutex_lock(&pfvf
->mbox
.lock
);
1322 req
= otx2_mbox_alloc_msg_npc_delete_flow(&pfvf
->mbox
);
1324 mutex_unlock(&pfvf
->mbox
.lock
);
1328 req
->start
= flow_cfg
->flow_ent
[0];
1329 req
->end
= flow_cfg
->flow_ent
[flow_cfg
->max_flows
- 1];
1330 err
= otx2_sync_mbox_msg(&pfvf
->mbox
);
1331 mutex_unlock(&pfvf
->mbox
.lock
);
1333 list_for_each_entry_safe(iter
, tmp
, &flow_cfg
->flow_list
, list
) {
1334 list_del(&iter
->list
);
1336 flow_cfg
->nr_flows
--;
1341 int otx2_destroy_mcam_flows(struct otx2_nic
*pfvf
)
1343 struct otx2_flow_config
*flow_cfg
= pfvf
->flow_cfg
;
1344 struct npc_mcam_free_entry_req
*req
;
1345 struct otx2_flow
*iter
, *tmp
;
1348 if (!(pfvf
->flags
& OTX2_FLAG_MCAM_ENTRIES_ALLOC
))
1351 /* remove all flows */
1352 err
= otx2_remove_flow_msg(pfvf
, 0, true);
1356 list_for_each_entry_safe(iter
, tmp
, &flow_cfg
->flow_list
, list
) {
1357 list_del(&iter
->list
);
1359 flow_cfg
->nr_flows
--;
1362 mutex_lock(&pfvf
->mbox
.lock
);
1363 req
= otx2_mbox_alloc_msg_npc_mcam_free_entry(&pfvf
->mbox
);
1365 mutex_unlock(&pfvf
->mbox
.lock
);
1370 /* Send message to AF to free MCAM entries */
1371 err
= otx2_sync_mbox_msg(&pfvf
->mbox
);
1373 mutex_unlock(&pfvf
->mbox
.lock
);
1377 pfvf
->flags
&= ~OTX2_FLAG_MCAM_ENTRIES_ALLOC
;
1378 mutex_unlock(&pfvf
->mbox
.lock
);
1383 int otx2_install_rxvlan_offload_flow(struct otx2_nic
*pfvf
)
1385 struct otx2_flow_config
*flow_cfg
= pfvf
->flow_cfg
;
1386 struct npc_install_flow_req
*req
;
1389 mutex_lock(&pfvf
->mbox
.lock
);
1390 req
= otx2_mbox_alloc_msg_npc_install_flow(&pfvf
->mbox
);
1392 mutex_unlock(&pfvf
->mbox
.lock
);
1396 req
->entry
= flow_cfg
->def_ent
[flow_cfg
->rx_vlan_offset
];
1397 req
->intf
= NIX_INTF_RX
;
1398 ether_addr_copy(req
->packet
.dmac
, pfvf
->netdev
->dev_addr
);
1399 eth_broadcast_addr((u8
*)&req
->mask
.dmac
);
1400 req
->channel
= pfvf
->hw
.rx_chan_base
;
1401 req
->op
= NIX_RX_ACTION_DEFAULT
;
1402 req
->features
= BIT_ULL(NPC_OUTER_VID
) | BIT_ULL(NPC_DMAC
);
1403 req
->vtag0_valid
= true;
1404 req
->vtag0_type
= NIX_AF_LFX_RX_VTAG_TYPE0
;
1406 /* Send message to AF */
1407 err
= otx2_sync_mbox_msg(&pfvf
->mbox
);
1408 mutex_unlock(&pfvf
->mbox
.lock
);
1412 static int otx2_delete_rxvlan_offload_flow(struct otx2_nic
*pfvf
)
1414 struct otx2_flow_config
*flow_cfg
= pfvf
->flow_cfg
;
1415 struct npc_delete_flow_req
*req
;
1418 mutex_lock(&pfvf
->mbox
.lock
);
1419 req
= otx2_mbox_alloc_msg_npc_delete_flow(&pfvf
->mbox
);
1421 mutex_unlock(&pfvf
->mbox
.lock
);
1425 req
->entry
= flow_cfg
->def_ent
[flow_cfg
->rx_vlan_offset
];
1426 /* Send message to AF */
1427 err
= otx2_sync_mbox_msg(&pfvf
->mbox
);
1428 mutex_unlock(&pfvf
->mbox
.lock
);
1432 int otx2_enable_rxvlan(struct otx2_nic
*pf
, bool enable
)
1434 struct nix_vtag_config
*req
;
1435 struct mbox_msghdr
*rsp_hdr
;
1438 /* Dont have enough mcam entries */
1439 if (!(pf
->flags
& OTX2_FLAG_RX_VLAN_SUPPORT
))
1443 err
= otx2_install_rxvlan_offload_flow(pf
);
1447 err
= otx2_delete_rxvlan_offload_flow(pf
);
1452 mutex_lock(&pf
->mbox
.lock
);
1453 req
= otx2_mbox_alloc_msg_nix_vtag_cfg(&pf
->mbox
);
1455 mutex_unlock(&pf
->mbox
.lock
);
1459 /* config strip, capture and size */
1460 req
->vtag_size
= VTAGSIZE_T4
;
1461 req
->cfg_type
= 1; /* rx vlan cfg */
1462 req
->rx
.vtag_type
= NIX_AF_LFX_RX_VTAG_TYPE0
;
1463 req
->rx
.strip_vtag
= enable
;
1464 req
->rx
.capture_vtag
= enable
;
1466 err
= otx2_sync_mbox_msg(&pf
->mbox
);
1468 mutex_unlock(&pf
->mbox
.lock
);
1472 rsp_hdr
= otx2_mbox_get_rsp(&pf
->mbox
.mbox
, 0, &req
->hdr
);
1473 if (IS_ERR(rsp_hdr
)) {
1474 mutex_unlock(&pf
->mbox
.lock
);
1475 return PTR_ERR(rsp_hdr
);
1478 mutex_unlock(&pf
->mbox
.lock
);
1482 void otx2_dmacflt_reinstall_flows(struct otx2_nic
*pf
)
1484 struct otx2_flow
*iter
;
1485 struct ethhdr
*eth_hdr
;
1487 list_for_each_entry(iter
, &pf
->flow_cfg
->flow_list
, list
) {
1488 if (iter
->rule_type
& DMAC_FILTER_RULE
) {
1489 eth_hdr
= &iter
->flow_spec
.h_u
.ether_spec
;
1490 otx2_dmacflt_add(pf
, eth_hdr
->h_dest
,
1496 void otx2_dmacflt_update_pfmac_flow(struct otx2_nic
*pfvf
)
1498 otx2_update_rem_pfmac(pfvf
, DMAC_ADDR_UPDATE
);