Switch support
Subsystems (4)
Ratheesh Kannoth
maintainerv2 cover Switch support
Marvell CN10K switch hardware is capable of accelerating L2, L3, and flow. The switch hardware runs an application that creates a logical port for each representor device when representors are enabled through devlink.
This patch series implements communication from Host OS to switch HW and vice versa.
|--------------------------------|
| HOST OS |
| |
| eth0(rep-eth0) eth1(rep-eth1) |
| | | |
| | | |
---------------------------------|
| |
| |
---------------------------------|
| lport0 lport1 |
| |
| switch |
| |
---------------------------------|When representors are created, corresponding "logical ports" are created in switchdev. The switch hardware allocates a NIX PF and configures its send queues. These send queues should be able to transmit packets to any channel, as send queues as from same NIX PF. Switch is capable of forwarding packets between these logical ports.
Notifier callbacks are registered to receive system events such as FDB add/delete and FIB add/delete. Flow add/delete operations are handled through the .ndo_setup_tc() interface. These events are captured and processed by the NIC driver and forwarded to the switch device through the AF driver. All message exchanges use the mailbox interface.
Bridge acceleration:
FDB add/delete notifications are processed, and learned SMAC information is sent to the switch hardware. The switch inserts a hardware rule to accelerate packets destined to the MAC address.
Flow acceleration:
NFT and OVS applications call .ndo_setup_tc() to push rules to hardware for acceleration. This interface is used to forward rules to the switch hardware through the mailbox interface.
Ratheesh Kannoth (10):
octeontx2-af: switch: Add AF to switch mbox and skeleton files Mbox message for AF to switch
octeontx2-af: switch: Add switch dev to AF mboxes Switch to AF driver mbox messages
octeontx2-pf: switch: Add pf files hierarchy
PF skeleton files for bridge, fib and flow
octeontx2-af: switch: Representor for switch port Switch ID is copied and sent to switch when Representors are enabled thru devlink. Upon receipt of the message, switch queries AF driver to get info on rep interfaces.
octeontx2-af: switch: Enable Switch hw port for all channels Switch ports should be configured to TX packets on any channel.
octeontx2-pf: switch: Register for notifier chains. Notifier callback for various system events.
octeontx2: switch: L2 offload support
Bridge (L2) offload support
octeontx2: switch: L3 offload support
FIB (L3) offload support.
octeontx2: switch: Flow offload support
Flow (5/7 tuple) offload support.
octeontx2: switch: trace support
Trace logs for flow and action
.../net/ethernet/marvell/octeontx2/Kconfig | 12 + .../ethernet/marvell/octeontx2/af/Makefile | 2 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 219 ++++++ .../net/ethernet/marvell/octeontx2/af/rvu.c | 111 +++- .../net/ethernet/marvell/octeontx2/af/rvu.h | 6 + .../ethernet/marvell/octeontx2/af/rvu_nix.c | 54 +- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 77 ++- .../marvell/octeontx2/af/rvu_npc_fs.c | 13 +- .../ethernet/marvell/octeontx2/af/rvu_rep.c | 3 +- .../marvell/octeontx2/af/switch/rvu_sw.c | 47 ++ .../marvell/octeontx2/af/switch/rvu_sw.h | 14 + .../marvell/octeontx2/af/switch/rvu_sw_fl.c | 294 ++++++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.h | 13 + .../marvell/octeontx2/af/switch/rvu_sw_l2.c | 284 ++++++++ .../marvell/octeontx2/af/switch/rvu_sw_l2.h | 13 + .../marvell/octeontx2/af/switch/rvu_sw_l3.c | 215 ++++++ .../marvell/octeontx2/af/switch/rvu_sw_l3.h | 11 + .../ethernet/marvell/octeontx2/nic/Makefile | 8 +- .../ethernet/marvell/octeontx2/nic/otx2_tc.c | 17 +- .../marvell/octeontx2/nic/otx2_txrx.h | 2 + .../ethernet/marvell/octeontx2/nic/otx2_vf.c | 8 + .../net/ethernet/marvell/octeontx2/nic/rep.c | 10 + .../marvell/octeontx2/nic/switch/sw_fdb.c | 143 ++++ .../marvell/octeontx2/nic/switch/sw_fdb.h | 18 + .../marvell/octeontx2/nic/switch/sw_fib.c | 133 ++++ .../marvell/octeontx2/nic/switch/sw_fib.h | 16 + .../marvell/octeontx2/nic/switch/sw_fl.c | 544 +++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fl.h | 15 + .../marvell/octeontx2/nic/switch/sw_nb.c | 629 ++++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_nb.h | 31 + .../marvell/octeontx2/nic/switch/sw_trace.c | 11 + .../marvell/octeontx2/nic/switch/sw_trace.h | 82 +++ 32 files changed, 3040 insertions(+), 15 deletions(-) create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.h
--
ChangeLog:
v1 -> v2: Fixed build errors
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 1/10 octeontx2-af: switch: Add AF to switch mbox and skeleton files
The Marvell switch hardware runs on a Linux OS. This OS receives various messages, which are parsed to create flow rules that can be installed on HW. The switch is capable of accelerating both L2 and L3 flows.
This commit adds various mailbox messages used by the Linux OS (on arm64) to send events to the switch hardware.
fdb messages: Linux bridge FDB messages fib messages: Linux routing table messages status messages: Packet status updates sent to Host
Linux to keep flows active
for connection-tracked flows.
--- .../ethernet/marvell/octeontx2/af/Makefile | 2 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 95 +++++++++++++++++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.c | 21 ++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.h | 11 +++ .../marvell/octeontx2/af/switch/rvu_sw_l2.c | 14 +++ .../marvell/octeontx2/af/switch/rvu_sw_l2.h | 11 +++ .../marvell/octeontx2/af/switch/rvu_sw_l3.c | 14 +++ .../marvell/octeontx2/af/switch/rvu_sw_l3.h | 11 +++ 8 files changed, 179 insertions(+) create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.h
drivers/net/ethernet/marvell/octeontx2/af/Makefile +2 -0
@@ -4,6 +4,7 @@ # ccflags-y += -I$(src) +ccflags-y += -I$(src) -I$(src)/switch/ obj-$(CONFIG_OCTEONTX2_MBOX) += rvu_mbox.o obj-$(CONFIG_OCTEONTX2_AF) += rvu_af.o
@@ -12,5 +13,6 @@ rvu_af-y := cgx.o rvu.o rvu_cgx.o rvu_npa.o rvu_nix.o \ rvu_reg.o rvu_npc.o rvu_debugfs.o ptp.o rvu_npc_fs.o \ rvu_cpt.o rvu_devlink.o rpm.o rvu_cn10k.o rvu_switch.o \ rvu_sdp.o rvu_npc_hash.o mcs.o mcs_rvu_if.o mcs_cnf10kb.o \ + switch/rvu_sw_l2.o switch/rvu_sw_l3.o switch/rvu_sw_fl.o\ rvu_rep.o cn20k/mbox_init.o cn20k/nix.o cn20k/debugfs.o \ cn20k/npa.o
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +95 -0
107 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "rvu.h" + +int rvu_mbox_handler_fl_get_stats (struct rvu *rvu, +struct fl_get_stats_req *req, +struct fl_get_stats_rsp *rsp) +{ +return 0 ; +} + +int rvu_mbox_handler_fl_notify (struct rvu *rvu, +struct fl_notify_req *req, +struct msg_rsp *rsp) +{ +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#ifndef RVU_SW_FL_H +#define RVU_SW_FL_H + +#endif
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "rvu.h" + +int rvu_mbox_handler_fdb_notify (struct rvu *rvu, +struct fdb_notify_req *req, +struct msg_rsp *rsp) +{ +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#ifndef RVU_SW_L2_H +#define RVU_SW_L2_H + +#endif
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "rvu.h" + +int rvu_mbox_handler_fib_notify (struct rvu *rvu, +struct fib_notify_req *req, +struct msg_rsp *rsp) +{ +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#ifndef RVU_SW_L3_H +#define RVU_SW_L3_H + +#endif
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 01/10] octeontx2-af: switch: Add AF to switch mbox and skeleton files
Quoted 37 lines · Ratheesh Kannoth
The Marvell switch hardware runs on a Linux OS. This OS receives various messages, which are parsed to create flow rules that can be installed on HW. The switch is capable of accelerating both L2 and L3 flows.
This commit adds various mailbox messages used by the Linux OS (on arm64) to send events to the switch hardware.
fdb messages: Linux bridge FDB messages fib messages: Linux routing table messages status messages: Packet status updates sent to HostLinux to keep flows active
for connection-tracked flows.Signed-off-by Ratheesh Kannoth<[email protected]>--- .../ethernet/marvell/octeontx2/af/Makefile | 2 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 95 +++++++++++++++++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.c | 21 ++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.h | 11 +++ .../marvell/octeontx2/af/switch/rvu_sw_l2.c | 14 +++ .../marvell/octeontx2/af/switch/rvu_sw_l2.h | 11 +++ .../marvell/octeontx2/af/switch/rvu_sw_l3.c | 14 +++ .../marvell/octeontx2/af/switch/rvu_sw_l3.h | 11 +++ 8 files changed, 179 insertions(+)create mode 100644
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.ccreate mode 100644drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.hcreate mode 100644drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.ccreate mode 100644drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.hcreate mode 100644drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.ccreate mode 100644drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.hdrivers/net/ethernet/marvell/octeontx2/af/Makefile +0
-0
drivers/net/ethernet/marvell/octeontx2/af/Makefile line 6
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/af/Makefile +0
-0@@ -4,6 +4,7 @@ # ccflags-y += -I$(src)
redundant include path
drivers/net/ethernet/marvell/octeontx2/af/Makefile line 9
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/af/Makefile +1
-0+ccflags-y += -I$(src) -I$(src)/switch/ obj-$(CONFIG_OCTEONTX2_MBOX) += rvu_mbox.o obj-$(CONFIG_OCTEONTX2_AF) += rvu_af.o
Thanks,
Alok
Ratheesh Kannoth
maintainerRe: [PATCH net-next v2 01/10] octeontx2-af: switch: Add AF to switch mbox and skeleton files
Quoted 13 lines · ALOK TIWARI
drivers/net/ethernet/marvell/octeontx2/af/Makefile line 5
Quoted 4 lines · Ratheesh Kannoth
+++ b/drivers/net/ethernet/marvell/octeontx2/af/Makefile
drivers/net/ethernet/marvell/octeontx2/af/Makefile +0
-0@@ -4,6 +4,7 @@ # ccflags-y += -I$(src)redundant include path
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/af/Makefile +1
-0+ccflags-y += -I$(src) -I$(src)/switch/ obj-$(CONFIG_OCTEONTX2_MBOX) += rvu_mbox.o obj-$(CONFIG_OCTEONTX2_AF) += rvu_af.o
ACK.
Ratheesh Kannoth
maintainerPATCH v2 2/10 octeontx2-af: switch: Add switch dev to AF mboxes
In reply to Ratheesh KannothThe Marvell switch hardware runs on a Linux OS. Switch needs various information from AF driver. These mboxes are defined to query those from AF driver.
--- .../ethernet/marvell/octeontx2/af/Makefile | 2 +- .../net/ethernet/marvell/octeontx2/af/mbox.h | 119 ++++++++++++++++++ .../net/ethernet/marvell/octeontx2/af/rvu.c | 110 +++++++++++++++- .../net/ethernet/marvell/octeontx2/af/rvu.h | 1 + .../ethernet/marvell/octeontx2/af/rvu_nix.c | 4 +- .../ethernet/marvell/octeontx2/af/rvu_npc.c | 77 +++++++++++- .../marvell/octeontx2/af/rvu_npc_fs.c | 11 ++ .../marvell/octeontx2/af/switch/rvu_sw.c | 15 +++ .../marvell/octeontx2/af/switch/rvu_sw.h | 11 ++ 9 files changed, 344 insertions(+), 6 deletions(-) create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.h
drivers/net/ethernet/marvell/octeontx2/af/Makefile +1 -1
@@ -13,6 +13,6 @@ rvu_af-y := cgx.o rvu.o rvu_cgx.o rvu_npa.o rvu_nix.o \ rvu_reg.o rvu_npc.o rvu_debugfs.o ptp.o rvu_npc_fs.o \ rvu_cpt.o rvu_devlink.o rpm.o rvu_cn10k.o rvu_switch.o \ rvu_sdp.o rvu_npc_hash.o mcs.o mcs_rvu_if.o mcs_cnf10kb.o \ - switch/rvu_sw_l2.o switch/rvu_sw_l3.o switch/rvu_sw_fl.o\ + switch/rvu_sw.o switch/rvu_sw_l2.o switch/rvu_sw_l3.o switch/rvu_sw_fl.o \ rvu_rep.o cn20k/mbox_init.o cn20k/nix.o cn20k/debugfs.o \ cn20k/npa.o
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +119 -0
155 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +109 -1
122 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +1 -0
@@ -1147,6 +1147,7 @@ void rvu_program_channels(struct rvu *rvu);/* CN10K NIX */ void rvu_nix_block_cn10k_init (struct rvu *rvu,struct nix_hw *nix_hw); +int nix_get_tx_link (struct rvu *rvu,u16 pcifunc);/* CN10K RVU - LMT*/ void rvu_reset_lmt_map_tbl (struct rvu *rvu,u16 pcifunc);
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +1 -3
@@ -31,7 +31,6 @@ static int nix_free_all_bandprof(struct rvu *rvu, u16 pcifunc);static void nix_clear_ratelimit_aggr (struct rvu *rvu,struct nix_hw *nix_hw,u32 leaf_prof);static const char *nix_get_ctx_name (int ctype); -static int nix_get_tx_link (struct rvu *rvu,u16 pcifunc);enum mc_tbl_sz {MC_TBL_SZ_256 ,
@@ -2055,7 +2054,7 @@ static void nix_clear_tx_xoff(struct rvu *rvu, int blkaddr,rvu_write64 (rvu, blkaddr, reg,0x0 ); } -static int nix_get_tx_link (struct rvu *rvu,u16 pcifunc) +int nix_get_tx_link (struct rvu *rvu,u16 pcifunc) {struct rvu_hwinfo *hw = rvu->hw;int pf =rvu_get_pf (rvu->pdev, pcifunc);
@@ -5283,7 +5282,6 @@ int rvu_mbox_handler_nix_lf_stop_rx(struct rvu *rvu, struct msg_req *req,/* Disable the interface if it is in any multicast list */ nix_mcast_update_mce_entry (rvu, pcifunc,0 ); - pfvf =rvu_get_pfvf (rvu, pcifunc);clear_bit (NIXLF_INITIALIZED , &pfvf->flags);
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +76 -1
95 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +11 -0
@@ -1549,6 +1549,17 @@ static int npc_delete_flow(struct rvu *rvu, struct rvu_npc_mcam_rule *rule,return rvu_mbox_handler_npc_mcam_dis_entry (rvu, &dis_req, &dis_rsp); } +int rvu_mbox_handler_npc_mcam_get_features (struct rvu *rvu, +struct msg_req *req, +struct npc_mcam_get_features_rsp *rsp) +{ +struct npc_mcam *mcam = &rvu->hw->mcam; + + rsp->rx_features = mcam->rx_features; + rsp->tx_features = mcam->tx_features; +return 0 ; +} +int rvu_mbox_handler_npc_delete_flow (struct rvu *rvu,struct npc_delete_flow_req *req,struct npc_delete_flow_rsp *rsp)
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#include "rvu.h" + +int rvu_mbox_handler_swdev2af_notify (struct rvu *rvu, +struct swdev2af_notify_req *req, +struct msg_rsp *rsp) +{ +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#ifndef RVU_SWITCH_H +#define RVU_SWITCH_H + +#endif
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 3/10 octeontx2-pf: switch: Add pf files hierarchy
In reply to Ratheesh KannothPF driver skeleton files. Follow up patches add meat to these files.
sw_nb* : Implements various notifier callbacks for linux events sw_fdb* : L2 offload
sw_fib* : L3 offload
sw_fl* : Flow based offload (ovs, nft etc)
--- drivers/net/ethernet/marvell/octeontx2/Kconfig | 12 ++++++++++++ .../net/ethernet/marvell/octeontx2/nic/Makefile | 8 +++++++- .../marvell/octeontx2/nic/switch/sw_fdb.c | 16 ++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fdb.h | 13 +++++++++++++ .../marvell/octeontx2/nic/switch/sw_fib.c | 16 ++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fib.h | 13 +++++++++++++ .../marvell/octeontx2/nic/switch/sw_fl.c | 16 ++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fl.h | 13 +++++++++++++ .../marvell/octeontx2/nic/switch/sw_nb.c | 17 +++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_nb.h | 13 +++++++++++++ 10 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.h create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h
drivers/net/ethernet/marvell/octeontx2/Kconfig +12 -0
@@ -28,6 +28,18 @@ config NDC_DIS_DYNAMIC_CACHING , NPA stack pages etc in NDC. Also locks down NIX SQ/CQ/RQ/RSS and NPA Aura/Pool contexts. +config OCTEONTX_SWITCH + tristate "Marvell OcteonTX2 switch driver" + select OCTEONTX2_MBOX + select NET_DEVLINK + default n + select PAGE_POOL + depends on (64BIT && COMPILE_TEST) || ARM64 + help + This driver supports Marvell's OcteonTX2 switch driver. + Marvell SW HW can offload L2, L3 offload. ARM core interacts + with Marvell SW HW thru mbox. + config OCTEONTX2_PF tristate "Marvell OcteonTX2 NIC Physical Function driver" select OCTEONTX2_MBOX
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +7 -1
@@ -9,7 +9,13 @@ obj-$(CONFIG_RVU_ESWITCH) += rvu_rep.o rvu_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o \ otx2_flows.o otx2_tc.o cn10k.o cn20k.o otx2_dmac_flt.o \ - otx2_devlink.o qos_sq.o qos.o otx2_xsk.o + otx2_devlink.o qos_sq.o qos.o otx2_xsk.o \ + switch/sw_fdb.o switch/sw_fl.o + +ifdef CONFIG_OCTEONTX_SWITCH +rvu_nicpf-y += switch/sw_nb.o switch/sw_fib.o +endif + rvu_nicvf-y := otx2_vf.o rvu_rep-y := rep.o
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "sw_fdb.h" + +int sw_fdb_init (void ) +{ +return 0 ; +} + +void sw_fdb_deinit (void ) +{ +}
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#ifndef SW_FDB_H_ +#define SW_FDB_H_ + +void sw_fdb_deinit (void ); +int sw_fdb_init (void ); + +#endif // SW_FDB_H
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "sw_fib.h" + +int sw_fib_init (void ) +{ +return 0 ; +} + +void sw_fib_deinit (void ) +{ +}
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#ifndef SW_FIB_H_ +#define SW_FIB_H_ + +void sw_fib_deinit (void ); +int sw_fib_init (void ); + +#endif // SW_FIB_H
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "sw_fl.h" + +int sw_fl_init (void ) +{ +return 0 ; +} + +void sw_fl_deinit (void ) +{ +}
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#ifndef SW_FL_H_ +#define SW_FL_H_ + +void sw_fl_deinit (void ); +int sw_fl_init (void ); + +#endif // SW_FL_H
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#include "sw_nb.h" + +int sw_nb_unregister (void ) +{ +return 0 ; +} + +int sw_nb_register (void ) +{ +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell switch driver +* +* Copyright (C) 2026 Marvell. +* +*/ +#ifndef SW_NB_H_ +#define SW_NB_H_ + +int sw_nb_register (void ); +int sw_nb_unregister (void ); + +#endif // SW_NB_H__
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 03/10] octeontx2-pf: switch: Add pf files hierarchy
Quoted 5 lines · Ratheesh Kannoth
+++
b/drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.hdrivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h new file +3
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell switch driver +*
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h line 13
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h new file +10
-0+* Copyright (C) 2026 Marvell. +* +*/ +#ifndef SW_NB_H_ +#define SW_NB_H_ + +int sw_nb_register (void ); +int sw_nb_unregister (void ); + +#endif // SW_NB_H__
SW_NB_H__ -> SW_NB_H_
Thanks,
Alok
Ratheesh Kannoth
maintainerRe: [PATCH net-next v2 03/10] octeontx2-pf: switch: Add pf files hierarchy
Quoted 9 lines · ALOK TIWARI
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h line 13
Quoted 4 lines · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h new file +4
-0+int sw_nb_register (void ); +int sw_nb_unregister (void ); + +#endif // SW_NB_H__
SW_NB_H__->SW_NB_H_
ACK
Ratheesh Kannoth
maintainerPATCH v2 4/10 octeontx2-af: switch: Representor for switch port
In reply to Ratheesh KannothRepresentor support is already available in AF driver. When Representors are enabled through devlink, switch id and various information are collected from AF driver and sent to switchdev thru mbox message. This message enables switchdev HW.
--- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 1 + drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 5 +++++ .../net/ethernet/marvell/octeontx2/af/rvu_rep.c | 3 ++- .../ethernet/marvell/octeontx2/af/switch/rvu_sw.c | 14 ++++++++++++++ .../ethernet/marvell/octeontx2/af/switch/rvu_sw.h | 3 +++ drivers/net/ethernet/marvell/octeontx2/nic/rep.c | 4 ++++ 6 files changed, 29 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +1 -0
@@ -1721,6 +1721,7 @@ struct get_rep_cnt_rsp {struct esw_cfg_req {struct mbox_msghdr hdr;u8 ena; +unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ];u64 rsvd; };
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +5 -0
@@ -567,6 +567,10 @@ struct rvu_switch {u16 *entry2pcifunc;u16 mode;u16 start_entry; +unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN ]; +#define RVU_SWITCH_FLAG_FW_READY BIT_ULL(0) +u64 flags; +u16 pcifunc; };struct rep_evtq_ent {
@@ -1185,4 +1189,5 @@ int rvu_rep_pf_init(struct rvu *rvu);int rvu_rep_install_mcam_rules (struct rvu *rvu);void rvu_rep_update_rules (struct rvu *rvu,u16 pcifunc,bool ena);int rvu_rep_notify_pfvf_state (struct rvu *rvu,u16 pcifunc,bool enable); +u16 rvu_rep_get_vlan_id (struct rvu *rvu,u16 pcifunc);#endif /* RVU_H */
drivers/net/ethernet/marvell/octeontx2/af/rvu_rep.c +2 -1
@@ -181,7 +181,7 @@ int rvu_mbox_handler_nix_lf_stats(struct rvu *rvu,return 0 ; } -static u16 rvu_rep_get_vlan_id (struct rvu *rvu,u16 pcifunc) +u16 rvu_rep_get_vlan_id (struct rvu *rvu,u16 pcifunc) {int id;
@@ -428,6 +428,7 @@ int rvu_mbox_handler_esw_cfg(struct rvu *rvu, struct esw_cfg_req *req,return 0 ; rvu->rep_mode = req->ena; +memcpy (rvu->rswitch.switch_id, req->switch_id,MAX_PHYS_ITEM_ID_LEN );if (!rvu->rep_mode)rvu_npc_free_mcam_entries (rvu, req->hdr.pcifunc,-1 );
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c +14 -0
@@ -6,6 +6,20 @@*/ #include "rvu.h" +#include "rvu_sw.h" + +u32 rvu_sw_port_id (struct rvu *rvu,u16 pcifunc) +{ +u16 port_id; +u16 rep_id; + + rep_id =rvu_rep_get_vlan_id (rvu, pcifunc); + + port_id =FIELD_PREP (GENMASK_ULL (31 ,16 ), rep_id) | +FIELD_PREP (GENMASK_ULL (15 ,0 ), pcifunc); + +return port_id; +} int rvu_mbox_handler_swdev2af_notify(struct rvu *rvu, struct swdev2af_notify_req *req,
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.h +3 -0
@@ -8,4 +8,7 @@#ifndef RVU_SWITCH_H #define RVU_SWITCH_H +/* RVU Switch */ +u32 rvu_sw_port_id (struct rvu *rvu,u16 pcifunc); +#endif
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +4 -0
@@ -399,8 +399,11 @@ static void rvu_rep_get_stats64(struct net_device *dev,static int rvu_eswitch_config (struct otx2_nic *priv,u8 ena) { +struct devlink_port_attrs attrs = {};struct esw_cfg_req *req; +rvu_rep_devlink_set_switch_id (priv, &attrs.switch_id); +mutex_lock (&priv->mbox.lock); req =otx2_mbox_alloc_msg_esw_cfg (&priv->mbox);if (!req) {
@@ -408,6 +411,7 @@ static int rvu_eswitch_config(struct otx2_nic *priv, u8 ena)return -ENOMEM ; } req->ena = ena; +memcpy (req->switch_id, attrs.switch_id.id, attrs.switch_id.id_len);otx2_sync_mbox_msg (&priv->mbox);mutex_unlock (&priv->mbox.lock);return 0 ;
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 5/10 octeontx2-af: switch: Enable Switch hw port for all channels
In reply to Ratheesh KannothSwitch HW should be able to fwd packets to any link based on flow rules. Set txlink enable for all channels.
--- .../net/ethernet/marvell/octeontx2/af/mbox.h | 4 ++ .../ethernet/marvell/octeontx2/af/rvu_nix.c | 50 ++++++++++++++++--- .../marvell/octeontx2/af/rvu_npc_fs.c | 2 +- .../marvell/octeontx2/nic/otx2_txrx.h | 2 + 4 files changed, 51 insertions(+), 7 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +4 -0
@@ -1122,6 +1122,8 @@ struct nix_txsch_alloc_req {/* Scheduler queue count request at each level */ u16 schq_contig[NIX_TXSCH_LVL_CNT ];/* No of contiguous queues */ u16 schq[NIX_TXSCH_LVL_CNT ];/* No of non-contiguous queues */ +#define NIX_TXSCH_ALLOC_FLAG_PAN BIT_ULL(0) +u64 flags; };struct nix_txsch_alloc_rsp {
@@ -1140,6 +1142,7 @@ struct nix_txsch_alloc_rsp {struct nix_txsch_free_req {struct mbox_msghdr hdr;#define TXSCHQ_FREE_ALL BIT_ULL(0) +#define TXSCHQ_FREE_PAN_TL1 BIT_ULL(1)u16 flags;/* Scheduler queue level to be freed */ u16 schq_lvl;
@@ -1958,6 +1961,7 @@ struct npc_install_flow_req {u16 entry;u16 channel;u16 chan_mask; +u8 set_chanmask;u8 intf;u8 set_cntr;/* If counter is available set counter for this entry ? */ u8 default_rule;
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +44 -6
91 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +1 -1
@@ -1469,7 +1469,7 @@ int rvu_mbox_handler_npc_install_flow(struct rvu *rvu, }/* ignore chan_mask in case pf func is not AF, revisit later */ -if (!is_pffunc_af (req->hdr.pcifunc)) +if (!req->set_chanmask && !is_pffunc_af (req->hdr.pcifunc)) req->chan_mask =0xFFF ; err =npc_check_unsupported_flows (rvu, req->features, req->intf);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h +2 -0
@@ -78,6 +78,8 @@ struct otx2_rcv_queue {struct sg_list {u16 num_segs;u16 flags; +u16 cq_idx; +u16 len;u64 skb;u64 size[OTX2_MAX_FRAGS_IN_SQE ];u64 dma_addr[OTX2_MAX_FRAGS_IN_SQE ];
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 6/10 octeontx2-pf: switch: Register for notifier chains.
In reply to Ratheesh KannothSwitchdev flow table needs information on 5tuple information to mangle/to find egress ports etc. PF driver registers for fdb/fib/netdev notifier chains to listen to events. These events are parsed and sent to switchdev HW through mbox events.
--- .../net/ethernet/marvell/octeontx2/nic/rep.c | 7 + .../marvell/octeontx2/nic/switch/sw_nb.c | 622 +++++++++++++++++- .../marvell/octeontx2/nic/switch/sw_nb.h | 22 +- 3 files changed, 647 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +7 -0
@@ -15,6 +15,7 @@#include "cn10k.h" #include "otx2_reg.h" #include "rep.h" +#include "switch/sw_nb.h" #define DRV_NAME "rvu_rep"#define DRV_STRING "Marvell RVU Representor Driver"
@@ -399,6 +400,7 @@ static void rvu_rep_get_stats64(struct net_device *dev,static int rvu_eswitch_config (struct otx2_nic *priv,u8 ena) { +struct net_device *netdev = priv->netdev;struct devlink_port_attrs attrs = {};struct esw_cfg_req *req;
@@ -414,6 +416,11 @@ static int rvu_eswitch_config(struct otx2_nic *priv, u8 ena)memcpy (req->switch_id, attrs.switch_id.id, attrs.switch_id.id_len);otx2_sync_mbox_msg (&priv->mbox);mutex_unlock (&priv->mbox.lock); + +#if IS_ENABLED (CONFIG_OCTEONTX_SWITCH ) + ena ?sw_nb_register (netdev) :sw_nb_unregister (netdev); +#endif +return 0 ; }
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c +620 -2
634 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.h +20 -2
@@ -7,7 +7,25 @@#ifndef SW_NB_H_ #define SW_NB_H_ -int sw_nb_register (void ); -int sw_nb_unregister (void ); +enum { +OTX2_DEV_UP =1 , +OTX2_DEV_DOWN , +OTX2_DEV_CHANGE , +OTX2_NEIGH_UPDATE , +OTX2_FIB_ENTRY_REPLACE , +OTX2_FIB_ENTRY_ADD , +OTX2_FIB_ENTRY_DEL , +OTX2_FIB_ENTRY_APPEND , +OTX2_CMD_MAX , +}; +int sw_nb_register (struct net_device *netdev); +int sw_nb_unregister (struct net_device *netdev); +bool sw_nb_is_valid_dev (struct net_device *netdev); + +int otx2_mbox_up_handler_af2pf_fdb_refresh (struct otx2_nic *pf, +struct af2pf_fdb_refresh_req *req, +struct msg_rsp *rsp); + +const char *sw_nb_get_cmd2str (int cmd);#endif // SW_NB_H__
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 7/10 octeontx2: switch: L2 offload support
In reply to Ratheesh KannothLinux bridge fdb events are parsed to decide on DMAC to fwd packets. Switchdev HW flow table is filled with this information. Once populated, all packet with DMAC will be accelerated.
--- .../net/ethernet/marvell/octeontx2/af/rvu.c | 1 + .../marvell/octeontx2/af/switch/rvu_sw.c | 18 +- .../marvell/octeontx2/af/switch/rvu_sw_l2.c | 270 ++++++++++++++++++ .../marvell/octeontx2/af/switch/rvu_sw_l2.h | 2 + .../ethernet/marvell/octeontx2/nic/otx2_vf.c | 17 ++ .../marvell/octeontx2/nic/switch/sw_fdb.c | 127 ++++++++ .../marvell/octeontx2/nic/switch/sw_fdb.h | 5 + .../marvell/octeontx2/nic/switch/sw_nb.c | 5 +- 8 files changed, 441 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +1 -0
@@ -2460,6 +2460,7 @@ static void __rvu_mbox_up_handler(struct rvu_work *mwork, int type)switch (msg->id) {case MBOX_MSG_CGX_LINK_EVENT : +case MBOX_MSG_AF2PF_FDB_REFRESH :break ;default :if (msg->rc)
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c +16 -2
@@ -7,6 +7,8 @@#include "rvu.h" #include "rvu_sw.h" +#include "rvu_sw_l2.h" +#include "rvu_sw_fl.h" u32 rvu_sw_port_id (struct rvu *rvu,u16 pcifunc) {
@@ -16,7 +18,7 @@ u32 rvu_sw_port_id(struct rvu *rvu, u16 pcifunc) rep_id =rvu_rep_get_vlan_id (rvu, pcifunc); port_id =FIELD_PREP (GENMASK_ULL (31 ,16 ), rep_id) | -FIELD_PREP (GENMASK_ULL (15 ,0 ), pcifunc); +FIELD_PREP (GENMASK_ULL (15 ,0 ), pcifunc);return port_id; }
@@ -25,5 +27,17 @@ int rvu_mbox_handler_swdev2af_notify(struct rvu *rvu,struct swdev2af_notify_req *req, struct msg_rsp *rsp) { -return 0 ; + int rc = 0; + +switch (req->msg_type) { +case SWDEV2AF_MSG_TYPE_FW_STATUS : + rc =rvu_sw_l2_init_offl_wq (rvu, req->pcifunc, req->fw_up); +break ; + +case SWDEV2AF_MSG_TYPE_REFRESH_FDB : + rc =rvu_sw_l2_fdb_list_entry_add (rvu, req->pcifunc, req->mac); +break ; + } + +return rc; }
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +270 -0
281 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.h +2 -0
@@ -8,4 +8,6 @@#ifndef RVU_SW_L2_H #define RVU_SW_L2_H +int rvu_sw_l2_init_offl_wq (struct rvu *rvu,u16 pcifunc,bool fw_up); +int rvu_sw_l2_fdb_list_entry_add (struct rvu *rvu,u16 pcifunc,u8 *mac);#endif
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +17 -0
@@ -15,6 +15,7 @@#include "otx2_ptp.h" #include "cn10k.h" #include "cn10k_ipsec.h" +#include "switch/sw_nb.h" #define DRV_NAME "rvu_nicvf"#define DRV_STRING "Marvell RVU NIC Virtual Function Driver"
@@ -141,6 +142,22 @@ static int otx2vf_process_mbox_msg_up(struct otx2_nic *vf, err =otx2_mbox_up_handler_cgx_link_event ( vf, (struct cgx_link_info_msg *)req, rsp);return err; + +case MBOX_MSG_AF2PF_FDB_REFRESH : + rsp = (struct msg_rsp *)otx2_mbox_alloc_msg (&vf->mbox.mbox_up,0 , +sizeof (struct msg_rsp )); +if (!rsp) +return -ENOMEM ; + + rsp->hdr.id =MBOX_MSG_AF2PF_FDB_REFRESH ; + rsp->hdr.sig =OTX2_MBOX_RSP_SIG ; + rsp->hdr.pcifunc = req->pcifunc; + rsp->hdr.rc =0 ; + err =otx2_mbox_up_handler_af2pf_fdb_refresh (vf, + (struct af2pf_fdb_refresh_req *)req, + rsp); +return err; +default :otx2_reply_invalid_msg (&vf->mbox.mbox_up,0 ,0 , req->id);return -ENODEV ;
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.c +127 -0
140 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fdb.h +5 -0
@@ -7,7 +7,12 @@#ifndef SW_FDB_H_ #define SW_FDB_H_ +int sw_fdb_add_to_list (struct net_device *dev,u8 *mac,bool add_fdb);void sw_fdb_deinit (void );int sw_fdb_init (void ); +int otx2_mbox_up_handler_af2pf_fdb_refresh (struct otx2_nic *pf, +struct af2pf_fdb_refresh_req *req, +struct msg_rsp *rsp); +#endif // SW_FDB_H
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c +3 -2
@@ -21,6 +21,7 @@#include "sw_fdb.h" #include "sw_fib.h" #include "sw_fl.h" +#include "sw_nb.h" static const char *sw_nb_cmd2str[OTX2_CMD_MAX ] = { [OTX2_DEV_UP ] ="OTX2_DEV_UP" ,
@@ -59,7 +60,6 @@ static int sw_nb_check_slaves(struct net_device *dev, struct netdev_nested_priv *priv) {int *cnt; -if (!priv->flags)return 0 ;
@@ -115,11 +115,13 @@ static int sw_nb_fdb_event(struct notifier_block *unused,case SWITCHDEV_FDB_ADD_TO_DEVICE :if (fdb_info->is_local)break ; +sw_fdb_add_to_list (dev, (u8 *)fdb_info->addr, true);break ;case SWITCHDEV_FDB_DEL_TO_DEVICE :if (fdb_info->is_local)break ; +sw_fdb_add_to_list (dev, (u8 *)fdb_info->addr, false);break ;default :
@@ -313,7 +315,6 @@ static int sw_nb_fib_event(struct notifier_block *nb, entries =kcalloc (hcnt,sizeof (*entries),GFP_ATOMIC );if (!entries)return NOTIFY_DONE ; - iter = entries;for (i =0 ; i < hcnt; i++, iter++) {
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 07/10] octeontx2: switch: L2 offload support
Quoted 45 lines · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +45
-0+ +static void rvu_sw_l2_offl_rule_wq_handler (struct work_struct *work) +{ +struct rvu_sw_l2_work *offl_work; +struct l2_entry *l2_entry; +int budget =16 ; +bool add_fdb; + + offl_work = container_of(work, struct rvu_sw_l2_work, work); + +while (budget--) { +mutex_lock (&l2_offl_list_lock); + l2_entry = list_first_entry_or_null(&l2_offl_lh, struct l2_entry, list); +if (!l2_entry) { +mutex_unlock (&l2_offl_list_lock); +return ; + } + +list_del_init (&l2_entry->list); +mutex_unlock (&l2_offl_list_lock); + + add_fdb = !!(l2_entry->flags &FDB_ADD ); + +if (add_fdb) +rvu_sw_l2_offl_cancel_add_if_del_reqs_exist (l2_entry->mac); + +rvu_sw_l2_offl_rule_push (offl_work->rvu, l2_entry); +kfree (l2_entry); + } + +if (!list_empty (&l2_offl_lh)) +queue_work (rvu_sw_l2_offl_wq, &l2_offl_work.work); +} + +int rvu_sw_l2_init_offl_wq (struct rvu *rvu,u16 pcifunc,bool fw_up) +{ +struct rvu_switch *rswitch; + + rswitch = &rvu->rswitch; + +if (fw_up) { + rswitch->flags |=RVU_SWITCH_FLAG_FW_READY ; + rswitch->pcifunc = pcifunc; + + l2_offl_work.rvu = rvu;
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c line 226
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +10
-0+INIT_WORK (&l2_offl_work.work, rvu_sw_l2_offl_rule_wq_handler); + rvu_sw_l2_offl_wq =alloc_workqueue ("swdev_rvu_sw_l2_offl_wq" ,0 ,0 ); +if (!rvu_sw_l2_offl_wq) { +dev_err (rvu->dev,"L2 offl workqueue allocation failed\n" ); +return -ENOMEM ; + } + + fdb_refresh_work.rvu = rvu; +INIT_WORK (&fdb_refresh_work.work, rvu_sw_l2_fdb_refresh_wq_handler); + fdb_refresh_wq =alloc_workqueue ("swdev_fdb_refresg_wq" ,0 ,0 );
consider, "swdev_fdb_refresg_wq" -> "swdev_fdb_refresh_wq"
Review
Quoted 1 line
(quoted diff) +1
-0+ if (!rvu_sw_l2_offl_wq) {
Checks rvu_sw_l2_offl_wq instead of fdb_refresh_wq
Review
Quoted 1 line
(quoted diff) +1
-0+ dev_err(rvu->dev, "L2 offl workqueue allocation failed\n");
offl -> fbd
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c line 239
Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +11
-0+return -ENOMEM ; + } + +return 0 ; + } + + rswitch->flags &= ~RVU_SWITCH_FLAG_FW_READY ; + rswitch->pcifunc =-1 ; +flush_work (&l2_offl_work.work); +return 0 ; +}
Thanks,
Alok
Ratheesh Kannoth
maintainerRe: [PATCH net-next v2 07/10] octeontx2: switch: L2 offload support
Quoted 6 lines · ALOK TIWARI
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c line 226
Quoted 1 line · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +1
-0+ fdb_refresh_wq =alloc_workqueue ("swdev_fdb_refresg_wq" ,0 ,0 );consider, "
swdev_fdb_refresg_wq" -> "swdev_fdb_refresh_wq"
ACK.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ if (!rvu_sw_l2_offl_wq) {Checks
rvu_sw_l2_offl_wqinstead offdb_refresh_wqReview
Quoted 1 line
(quoted diff) +1
-0+ dev_err(rvu->dev, "L2 offl workqueue allocation failed\n");offl -> fbd
ACK.
Quoted 16 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c line 239
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l2.c +11
-0+return -ENOMEM ; + } + +return 0 ; + } + + rswitch->flags &= ~RVU_SWITCH_FLAG_FW_READY ; + rswitch->pcifunc =-1 ; +flush_work (&l2_offl_work.work); +return 0 ; +}Thanks,
Alok
Ratheesh Kannoth
maintainerPATCH v2 8/10 octeontx2: switch: L3 offload support
In reply to Ratheesh KannothLinux route events are parsed to decide on destination DIP/MASK to fwd packets. Switchdev HW flow table is filled with this information. Once populated, all packet with DIP/MASK will be accelerated.
--- .../marvell/octeontx2/af/switch/rvu_sw.c | 2 +- .../marvell/octeontx2/af/switch/rvu_sw_l3.c | 202 ++++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fib.c | 119 +++++++++++ .../marvell/octeontx2/nic/switch/sw_fib.h | 3 + .../marvell/octeontx2/nic/switch/sw_nb.c | 20 ++ 5 files changed, 345 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c +1 -1
@@ -6,9 +6,9 @@*/ #include "rvu.h" -#include "rvu_sw.h" #include "rvu_sw_l2.h" #include "rvu_sw_fl.h" +#include "rvu_sw.h" u32 rvu_sw_port_id (struct rvu *rvu,u16 pcifunc) {
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_l3.c +202 -0
213 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.c +119 -0
132 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fib.h +3 -0
@@ -7,6 +7,9 @@#ifndef SW_FIB_H_ #define SW_FIB_H_ +int sw_fib_add_to_list (struct net_device *dev, +struct fib_entry *entry,int cnt); +void sw_fib_deinit (void );int sw_fib_init (void );
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c +20 -0
@@ -307,6 +307,12 @@ static int sw_nb_fib_event(struct notifier_block *nb,return NOTIFY_DONE ; } +if (sw_fib_add_to_list (pf_dev, entries, cnt)) { +kfree (entries); +kfree (haddr); +return NOTIFY_DONE ; + } +if (!hcnt) {kfree (haddr);return NOTIFY_DONE ;
@@ -336,6 +342,7 @@ static int sw_nb_fib_event(struct notifier_block *nb, iter->cmd, iter->dst, iter->dst_len, iter->gw, dev->name); } +sw_fib_add_to_list (pf_dev, entries, hcnt);kfree (haddr);return NOTIFY_DONE ; }
@@ -390,6 +397,9 @@ static int sw_nb_net_event(struct notifier_block *nb, pf =netdev_priv (pf_dev); entry->port_id = pf->pcifunc; +if (sw_fib_add_to_list (pf_dev, entry,1 )) +kfree (entry); +break ; }
@@ -469,6 +479,11 @@ static int sw_nb_inetaddr_event(struct notifier_block *nb,break ; } +if (sw_fib_add_to_list (pf_dev, entry,1 )) { +kfree (entry); +return NOTIFY_DONE ; + } +netdev_dbg (dev,"%s:%d pushing inetaddr event from HOST interface address %#x, %pM, %s\n" , __func__, __LINE__, entry->dst, entry->mac, dev->name);
@@ -536,6 +551,11 @@ static int sw_nb_netdev_event(struct notifier_block *unused,break ; } +if (sw_fib_add_to_list (pf_dev, entry,1 )) { +kfree (entry); +return NOTIFY_DONE ; + } +netdev_dbg (dev,"%s:%d pushing netdev event from HOST interface address %#x, %pM, dev=%s\n" , __func__, __LINE__, entry->dst, entry->mac, dev->name);
Signature · 1 line
2.43.0
Ratheesh Kannoth
maintainerPATCH v2 9/10 octeontx2: switch: Flow offload support
In reply to Ratheesh KannothOVS/NFT pushed HW acceleration rules to pf driver thru .ndo_tc(). Switchdev HW flow table is filled with this information. Once populated, flow will be accelerated.
--- .../marvell/octeontx2/af/switch/rvu_sw.c | 4 + .../marvell/octeontx2/af/switch/rvu_sw_fl.c | 278 ++++++++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.h | 2 + .../ethernet/marvell/octeontx2/nic/otx2_tc.c | 17 +- .../marvell/octeontx2/nic/switch/sw_fl.c | 520 ++++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fl.h | 2 + .../marvell/octeontx2/nic/switch/sw_nb.c | 1 - 7 files changed, 822 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c +4 -0
@@ -37,6 +37,10 @@ int rvu_mbox_handler_swdev2af_notify(struct rvu *rvu,case SWDEV2AF_MSG_TYPE_REFRESH_FDB : rc =rvu_sw_l2_fdb_list_entry_add (rvu, req->pcifunc, req->mac);break ; + +case SWDEV2AF_MSG_TYPE_REFRESH_FL : + rc =rvu_sw_fl_stats_sync2db (rvu, req->fl, req->cnt); +break ; }return rc;
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +278 -0
295 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.h +2 -0
@@ -8,4 +8,6 @@#ifndef RVU_SW_FL_H #define RVU_SW_FL_H +int rvu_sw_fl_stats_sync2db (struct rvu *rvu,struct fl_info *fl,int cnt); +#endif
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +16 -1
@@ -20,6 +20,7 @@#include "cn10k.h" #include "otx2_common.h" #include "qos.h" +#include "switch/sw_fl.h" #define CN10K_MAX_BURST_MANTISSA 0x7FFFULL#define CN10K_MAX_BURST_SIZE 8453888ULL
@@ -1238,7 +1239,6 @@ static int otx2_tc_del_flow(struct otx2_nic *nic,mutex_unlock (&nic->mbox.lock); } - free_mcam_flow:otx2_del_mcam_flow_entry (nic, flow_node->entry,NULL );otx2_tc_update_mcam_table (nic, flow_cfg, flow_node, false);
@@ -1595,11 +1595,26 @@ static int otx2_setup_tc_block(struct net_device *netdev,int otx2_setup_tc (struct net_device *netdev,enum tc_setup_type type,void *type_data) { +struct otx2_nic *nic =netdev_priv (netdev); +switch (type) {case TC_SETUP_BLOCK : +if (netif_is_ovs_port (netdev)) { +return flow_block_cb_setup_simple (type_data, + &otx2_block_cb_list, + sw_fl_setup_ft_block_ingress_cb, + nic, nic, true); + } +return otx2_setup_tc_block (netdev, type_data);case TC_SETUP_QDISC_HTB :return otx2_setup_tc_htb (netdev, type_data); + +case TC_SETUP_FT : +return flow_block_cb_setup_simple (type_data, + &otx2_block_cb_list, + sw_fl_setup_ft_block_ingress_cb, + nic, nic, true);default :return -EOPNOTSUPP ; }
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +520 -0
533 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.h +2 -0
@@ -9,5 +9,7 @@void sw_fl_deinit (void );int sw_fl_init (void ); +int sw_fl_setup_ft_block_ingress_cb (enum tc_setup_type type, +void *type_data,void *cb_priv);#endif // SW_FL_H
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c +0 -1
@@ -21,7 +21,6 @@#include "sw_fdb.h" #include "sw_fib.h" #include "sw_fl.h" -#include "sw_nb.h" static const char *sw_nb_cmd2str[OTX2_CMD_MAX ] = { [OTX2_DEV_UP ] ="OTX2_DEV_UP" ,
Signature · 1 line
2.43.0
Re: [PATCH net-next v2 09/10] octeontx2: switch: Flow offload support
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 211
Quoted 9 lines · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +9
-0+ err =sw_fl_get_route (&res, dst); +if (err) { +pr_err ("%s:%d Failed to find route to dst %pI4\n" , + __func__, __LINE__, &dst); + goto done; + } + +if (res.fi->fib_type !=RTN_UNICAST ) { + pr_err("%s:%d Not unicast route to dst %pi4\n",
%pi4 -> %pI4
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 223
Quoted 12 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +12
-0+ __func__, __LINE__, &dst); + err = -EFAULT ; + goto done; + } + + fib_nhc =fib_info_nhc (res.fi,0 ); +if (!fib_nhc) { + err = -EINVAL ; +pr_err ("%s:%d Could not get fib_nhc for %pI4\n" , + __func__, __LINE__, &dst); + goto done; + }
Thanks,
Alok
Ratheesh Kannoth
maintainerRe: [PATCH net-next v2 09/10] octeontx2: switch: Flow offload support
Quoted 14 lines · ALOK TIWARI
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 211
Quoted 9 lines · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +9
-0+ err =sw_fl_get_route (&res, dst); +if (err) { +pr_err ("%s:%d Failed to find route to dst %pI4\n" , + __func__, __LINE__, &dst); + goto done; + } + +if (res.fi->fib_type !=RTN_UNICAST ) { + pr_err("%s:%d Not unicast route to dst %pi4\n",%pi4 -> %pI4
ACK
Quoted 17 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 223
Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +12
-0+ __func__, __LINE__, &dst); + err = -EFAULT ; + goto done; + } + + fib_nhc =fib_info_nhc (res.fi,0 ); +if (!fib_nhc) { + err = -EINVAL ; +pr_err ("%s:%d Could not get fib_nhc for %pI4\n" , + __func__, __LINE__, &dst); + goto done; + }Thanks,
Alok
Re: [PATCH net-next v2 09/10] octeontx2: switch: Flow offload support
In reply to Ratheesh KannothQuoted 120 lines · Ratheesh Kannoth
OVS/NFT pushed HW acceleration rules to pf driver thru .ndo_tc(). Switchdev HW flow table is filled with this information. Once populated, flow will be accelerated.
Signed-off-by Ratheesh Kannoth <[email protected]>--- .../marvell/octeontx2/af/switch/rvu_sw.c | 4 + .../marvell/octeontx2/af/switch/rvu_sw_fl.c | 278 ++++++++++ .../marvell/octeontx2/af/switch/rvu_sw_fl.h | 2 + .../ethernet/marvell/octeontx2/nic/otx2_tc.c | 17 +- .../marvell/octeontx2/nic/switch/sw_fl.c | 520 ++++++++++++++++++ .../marvell/octeontx2/nic/switch/sw_fl.h | 2 + .../marvell/octeontx2/nic/switch/sw_nb.c | 1 - 7 files changed, 822 insertions(+), 2 deletions(-)drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw.c +4
-0@@ -37,6 +37,10 @@ int rvu_mbox_handler_swdev2af_notify(struct rvu *rvu,case SWDEV2AF_MSG_TYPE_REFRESH_FDB : rc =rvu_sw_l2_fdb_list_entry_add (rvu, req->pcifunc, req->mac);break ; + +case SWDEV2AF_MSG_TYPE_REFRESH_FL : + rc =rvu_sw_fl_stats_sync2db (rvu, req->fl, req->cnt); +break ; }return rc;drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +80
-0@@ -4,12 +4,260 @@* Copyright (C) 2026 Marvell. * */ + +#include <linux/bitfield.h> #include "rvu.h" +#include "rvu_sw.h" +#include "rvu_sw_fl.h" + +#define M (_name, _id, _fn_name, _req_type, _rsp_type) \ +static struct _req_type __maybe_unused \ +*otx2_mbox_alloc_msg_ ## _fn_name(struct rvu *rvu, int devid) \ +{ \ + struct _req_type *req; \ + \ + req = (struct _req_type *)otx2_mbox_alloc_msg_rsp( \ + &rvu->afpf_wq_info.mbox_up, devid, sizeof(struct _req_type), \ + sizeof(struct _rsp_type)); \ + if (!req) \ + return NULL; \ + req->hdr.sig = OTX2_MBOX_REQ_SIG; \ + req->hdr.id = _id; \ + return req; \ +} + +MBOX_UP_AF2SWDEV_MESSAGES +#undef M + +static struct workqueue_struct *sw_fl_offl_wq; + +struct fl_entry { +struct list_head list; +struct rvu *rvu; +u32 port_id; +unsigned long cookie; +struct fl_tuple tuple; +u64 flags; +u64 features; +}; + +static DEFINE_MUTEX (fl_offl_llock); +static LIST_HEAD (fl_offl_lh); +static bool fl_offl_work_running; + +static struct workqueue_struct *sw_fl_offl_wq; +static void sw_fl_offl_work_handler (struct work_struct *work); +static DECLARE_DELAYED_WORK(fl_offl_work, sw_fl_offl_work_handler); + +struct sw_fl_stats_node { +struct list_head list; +unsigned long cookie; +u16 mcam_idx[2 ]; +u64 opkts, npkts; +bool uni_di; +}; + +static LIST_HEAD (sw_fl_stats_lh); +static DEFINE_MUTEX (sw_fl_stats_lock); + +static int +rvu_sw_fl_stats_sync2db_one_entry (unsigned long cookie,u8 disabled, +u16 mcam_idx[2 ],bool uni_di,u64 pkts) +{ +struct sw_fl_stats_node *snode, *tmp; + +mutex_lock (&sw_fl_stats_lock); +list_for_each_entry_safe (snode, tmp, &sw_fl_stats_lh, list) { +if (snode->cookie != cookie) +continue ; + +if (disabled) { +list_del_init (&snode->list); +mutex_unlock (&sw_fl_stats_lock); +kfree (snode); +return 0 ; + } + +if (snode->uni_di != uni_di) { + snode->uni_di = uni_di; + snode->mcam_idx[1 ] = mcam_idx[1 ]; + } + +if (snode->opkts == pkts) { +mutex_unlock (&sw_fl_stats_lock);
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 97
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +10
-0+return 0 ; + } + + snode->npkts = pkts; +mutex_unlock (&sw_fl_stats_lock); +return 0 ; + } +mutex_unlock (&sw_fl_stats_lock); + + snode =kcalloc (1 ,sizeof (*snode),GFP_KERNEL );
Why not kzalloc() instead of kcalloc with size 1?
Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +13
-0+if (!snode) +return -ENOMEM ; + + snode->cookie = cookie; + snode->mcam_idx[0 ] = mcam_idx[0 ]; +if (!uni_di) + snode->mcam_idx[1 ] = mcam_idx[1 ]; + + snode->npkts = pkts; + snode->uni_di = uni_di; +INIT_LIST_HEAD (&snode->list); + +mutex_lock (&sw_fl_stats_lock);
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 120
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +10
-0+list_add_tail (&snode->list, &sw_fl_stats_lh); +mutex_unlock (&sw_fl_stats_lock); + +return 0 ; +} + +int rvu_sw_fl_stats_sync2db (struct rvu *rvu,struct fl_info *fl,int cnt) +{ +struct npc_mcam_get_mul_stats_req *req =NULL ; +struct npc_mcam_get_mul_stats_rsp *rsp =NULL ;
there is no need to initialize these two variables
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 122
Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +2
-0+int tot =0 ; +u16 i2idx_map[256 ];
follow RCT order
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 129
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+int rc =0 ; +u64 pkts; +int idx; + + cnt =min (cnt,64 ); + +for (int i =0 ; i < cnt; i++) {
I think you can move the declaration of i at the beginning of the function. it is repeated in the for loops below as well
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 137
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +8
-0+ tot++; +if (fl[i].uni_di) +continue ; + + tot++; + } + + req =kcalloc (1 ,sizeof (*req),GFP_KERNEL );
I think you can use kzalloc kere
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 139
Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +2
-0+if (!req) { + rc = -ENOMEM ;
You can return directly here
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 146
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+ goto fail; + } + + rsp =kcalloc (1 ,sizeof (*rsp),GFP_KERNEL ); +if (!rsp) { + rc = -ENOMEM ; + goto fail;
better do individual cleanup by adding a label and use goto free_req
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+ } + + req->cnt = tot; + idx =0 ; +for (int i =0 ; i < tot; idx++) { + i2idx_map[i] = idx; + req->entry[i++] = fl[idx].mcam_idx[0 ];
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 163
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +10
-0+if (fl[idx].uni_di) +continue ; + + i2idx_map[i] = idx; + req->entry[i++] = fl[idx].mcam_idx[1 ]; + } + +if (rvu_mbox_handler_npc_mcam_mul_stats (rvu, req, rsp)) { +dev_err (rvu->dev,"Error to get multiple stats\n" ); + rc = -EFAULT ;
You can add a new label and use goto free_resp
Quoted 118 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +106
-0+ goto fail; + } + +for (int i =0 ; i < tot;) { + idx = i2idx_map[i]; + pkts = rsp->stat[i++]; + +if (!fl[idx].uni_di) + pkts += rsp->stat[i++]; + + rc |=rvu_sw_fl_stats_sync2db_one_entry (fl[idx].cookie, fl[idx].dis, + fl[idx].mcam_idx, + fl[idx].uni_di, pkts); + } + +fail: +kfree (req); +kfree (rsp); +return rc; +} + +static void sw_fl_offl_dump (struct fl_entry *fl_entry) +{ +struct fl_tuple *tuple = &fl_entry->tuple; + +pr_debug ("%pI4 to %pI4\n" , &tuple->ip4src, &tuple->ip4dst); +} + +static int rvu_sw_fl_offl_rule_push (struct fl_entry *fl_entry) +{ +struct af2swdev_notify_req *req; +struct rvu *rvu; +int swdev_pf; + + rvu = fl_entry->rvu; + swdev_pf =rvu_get_pf (rvu->pdev, rvu->rswitch.pcifunc); + +mutex_lock (&rvu->mbox_lock); + req =otx2_mbox_alloc_msg_af2swdev_notify (rvu, swdev_pf); +if (!req) { +mutex_unlock (&rvu->mbox_lock); +return -ENOMEM ; + } + + req->tuple = fl_entry->tuple; + req->flags = fl_entry->flags; + req->cookie = fl_entry->cookie; + req->features = fl_entry->features; + +sw_fl_offl_dump (fl_entry); + +otx2_mbox_wait_for_zero (&rvu->afpf_wq_info.mbox_up, swdev_pf); +otx2_mbox_msg_send_up (&rvu->afpf_wq_info.mbox_up, swdev_pf); + +mutex_unlock (&rvu->mbox_lock); +return 0 ; +} + +static void sw_fl_offl_work_handler (struct work_struct *work) +{ +struct fl_entry *fl_entry; + +mutex_lock (&fl_offl_llock); + fl_entry = list_first_entry_or_null(&fl_offl_lh, struct fl_entry, list); +if (!fl_entry) { +mutex_unlock (&fl_offl_llock); +return ; + } + +list_del_init (&fl_entry->list); +mutex_unlock (&fl_offl_llock); + +rvu_sw_fl_offl_rule_push (fl_entry); +kfree (fl_entry); + +mutex_lock (&fl_offl_llock); +if (!list_empty (&fl_offl_lh)) +queue_delayed_work (sw_fl_offl_wq, &fl_offl_work,msecs_to_jiffies (10 )); +mutex_unlock (&fl_offl_llock); +}int rvu_mbox_handler_fl_get_stats (struct rvu *rvu,struct fl_get_stats_req *req,struct fl_get_stats_rsp *rsp) { +struct sw_fl_stats_node *snode, *tmp; + +mutex_lock (&sw_fl_stats_lock); +list_for_each_entry_safe (snode, tmp, &sw_fl_stats_lh, list) { +if (snode->cookie != req->cookie) +continue ; + + rsp->pkts_diff = snode->npkts - snode->opkts; + snode->opkts = snode->npkts; +break ; + } +mutex_unlock (&sw_fl_stats_lock);return 0 ; }@@ -17,5 +265,35 @@ int rvu_mbox_handler_fl_notify(struct rvu *rvu,struct fl_notify_req *req, struct msg_rsp *rsp) { + struct fl_entry *fl_entry; + +if (!(rvu->rswitch.flags &RVU_SWITCH_FLAG_FW_READY )) +return 0 ; + + fl_entry =kcalloc (1 ,sizeof (*fl_entry),GFP_KERNEL ); +if (!fl_entry) +return -ENOMEM ; + + fl_entry->port_id =rvu_sw_port_id (rvu, req->hdr.pcifunc); + fl_entry->rvu = rvu; +INIT_LIST_HEAD (&fl_entry->list); + fl_entry->tuple = req->tuple; + fl_entry->cookie = req->cookie;
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c int rvu_mbox_handler_fl_notify(struct rvu *rvu, · line 291
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +10
-0+ fl_entry->flags = req->flags; + fl_entry->features = req->features; + +mutex_lock (&fl_offl_llock); +list_add_tail (&fl_entry->list, &fl_offl_lh); +mutex_unlock (&fl_offl_llock); + +if (!fl_offl_work_running) { + sw_fl_offl_wq =alloc_workqueue ("sw_af_fl_wq" ,0 ,0 ); +if (!sw_fl_offl_wq)
free fl_entry here? also, do you want to move list_add_tail() after this if() condition?
Quoted 43 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +6
-0+return -ENOMEM ; + + fl_offl_work_running = true; + } +queue_delayed_work (sw_fl_offl_wq, &fl_offl_work,msecs_to_jiffies (10 )); +return 0 ; }drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.h +2
-0@@ -8,4 +8,6 @@#ifndef RVU_SW_FL_H #define RVU_SW_FL_H +int rvu_sw_fl_stats_sync2db (struct rvu *rvu,struct fl_info *fl,int cnt); +#endif drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +1
-1@@ -20,6 +20,7 @@#include "cn10k.h" #include "otx2_common.h" #include "qos.h" +#include "switch/sw_fl.h" #define CN10K_MAX_BURST_MANTISSA 0x7FFFULL#define CN10K_MAX_BURST_SIZE 8453888ULL@@ -1238,7 +1239,6 @@ static int otx2_tc_del_flow(struct otx2_nic *nic,mutex_unlock (&nic->mbox.lock); } - free_mcam_flow:otx2_del_mcam_flow_entry (nic, flow_node->entry,NULL );otx2_tc_update_mcam_table (nic, flow_cfg, flow_node, false);@@ -1595,11 +1595,26 @@ static int otx2_setup_tc_block(struct net_device *netdev,int otx2_setup_tc (struct net_device *netdev,enum tc_setup_type type,void *type_data) {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1607
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +8
-0+struct otx2_nic *nic =netdev_priv (netdev); +switch (type) {case TC_SETUP_BLOCK : +if (netif_is_ovs_port (netdev)) { +return flow_block_cb_setup_simple (type_data, + &otx2_block_cb_list, + sw_fl_setup_ft_block_ingress_cb, + nic, nic, true); + }
braces are not required here
Quoted 134 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +7
-0+return otx2_setup_tc_block (netdev, type_data);case TC_SETUP_QDISC_HTB :return otx2_setup_tc_htb (netdev, type_data); + +case TC_SETUP_FT : +return flow_block_cb_setup_simple (type_data, + &otx2_block_cb_list, + sw_fl_setup_ft_block_ingress_cb, + nic, nic, true);default :return -EOPNOTSUPP ; }drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +111
-0@@ -4,13 +4,533 @@* Copyright (C) 2026 Marvell. * */ +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <net/switchdev.h> +#include <net/netevent.h> +#include <net/arp.h> +#include <net/nexthop.h> +#include <net/netfilter/nf_flow_table.h> + +#include "../otx2_reg.h" +#include "../otx2_common.h" +#include "../otx2_struct.h" +#include "../cn10k.h" +#include "sw_nb.h" #include "sw_fl.h" +#if !IS_ENABLED (CONFIG_OCTEONTX_SWITCH ) +int sw_fl_setup_ft_block_ingress_cb (enum tc_setup_type type, +void *type_data,void *cb_priv) +{ +return -EOPNOTSUPP ; +} + +#else + +static DEFINE_SPINLOCK (sw_fl_lock); +static LIST_HEAD (sw_fl_lh); + +struct sw_fl_list_entry { +struct list_head list; +u64 flags; +unsigned long cookie; +struct otx2_nic *pf; +struct fl_tuple tuple; +}; + +static struct workqueue_struct *sw_fl_wq; +static struct work_struct sw_fl_work; + +static int sw_fl_msg_send (struct otx2_nic *pf, +struct fl_tuple *tuple, +u64 flags, +unsigned long cookie) +{ +struct fl_notify_req *req; +int rc; + +mutex_lock (&pf->mbox.lock); + req =otx2_mbox_alloc_msg_fl_notify (&pf->mbox); +if (!req) { + rc = -ENOMEM ; + goto out; + } + + req->tuple = *tuple; + req->flags = flags; + req->cookie = cookie; + + rc =otx2_sync_mbox_msg (&pf->mbox); +out: +mutex_unlock (&pf->mbox.lock); +return rc; +} + +static void sw_fl_wq_handler (struct work_struct *work) +{ +struct sw_fl_list_entry *entry; +LIST_HEAD (tlist); + +spin_lock (&sw_fl_lock); +list_splice_init (&sw_fl_lh, &tlist); +spin_unlock (&sw_fl_lock); + +while ((entry = +list_first_entry_or_null (&tlist, + struct sw_fl_list_entry, + list)) !=NULL ) { +list_del_init (&entry->list); +sw_fl_msg_send (entry->pf, &entry->tuple, + entry->flags, entry->cookie); +kfree (entry); + } + +spin_lock (&sw_fl_lock); +if (!list_empty (&sw_fl_lh)) +queue_work (sw_fl_wq, &sw_fl_work); +spin_unlock (&sw_fl_lock); +} + +static int +sw_fl_add_to_list (struct otx2_nic *pf,struct fl_tuple *tuple, +unsigned long cookie,bool add_fl) +{ +struct sw_fl_list_entry *entry; + + entry =kcalloc (1 ,sizeof (*entry),GFP_ATOMIC ); +if (!entry) +return -ENOMEM ; + + entry->pf = pf; + entry->flags = add_fl ?FL_ADD :FL_DEL ; +if (add_fl) + entry->tuple = *tuple; + entry->cookie = cookie; + entry->tuple.uni_di =netif_is_ovs_port (pf->netdev); + +spin_lock (&sw_fl_lock); +list_add_tail (&entry->list, &sw_fl_lh); +queue_work (sw_fl_wq, &sw_fl_work); +spin_unlock (&sw_fl_lock); + +return 0 ; +}
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 129
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +10
-0+ +static int sw_fl_parse_actions (struct otx2_nic *nic, +struct flow_action *flow_action, +struct flow_cls_offload *f, +struct fl_tuple *tuple,u64 *op) +{ +struct flow_action_entry *act; +struct otx2_nic *out_nic; +int err; +int used =0 ;
RCT order here
Quoted 308 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +308
-0+int i; + +if (!flow_action_has_entries (flow_action)) +return -EINVAL ; + +flow_action_for_each (i, act, flow_action) { +WARN_ON (used >=MANGLE_ARR_SZ ); + +switch (act->id) { +case FLOW_ACTION_REDIRECT : + tuple->in_pf = nic->pcifunc; + out_nic =netdev_priv (act->dev); + tuple->xmit_pf = out_nic->pcifunc; + *op |=BIT_ULL (FLOW_ACTION_REDIRECT ); +break ; + +case FLOW_ACTION_CT : + err =nf_flow_table_offload_add_cb (act->ct.flow_table, + sw_fl_setup_ft_block_ingress_cb, + nic); +if (err != -EEXIST && err) { +pr_err ("%s:%d Error to offload flow, err=%d\n" , + __func__, __LINE__, err); +break ; + } + + *op |=BIT_ULL (FLOW_ACTION_CT ); +break ; + +case FLOW_ACTION_MANGLE : + tuple->mangle[used].type = act->mangle.htype; + tuple->mangle[used].val = act->mangle.val; + tuple->mangle[used].mask = act->mangle.mask; + tuple->mangle[used].offset = act->mangle.offset; + tuple->mangle_map[act->mangle.htype] |=BIT (used); + used++; +break ; + +default : +break ; + } + } + + tuple->mangle_cnt = used; + +if (!*op) { +pr_debug ("%s:%d Op is not valid\n" , __func__, __LINE__); +return -EOPNOTSUPP ; + } + +return 0 ; +} + +static int sw_fl_get_route (struct fib_result *res,__be32 addr) +{ +struct flowi4 fl4; + +memset (&fl4,0 ,sizeof (fl4)); + fl4.daddr = addr; +return fib_lookup (&init_net, &fl4, res,0 ); +} + +static int sw_fl_get_pcifunc (__be32 dst,u16 *pcifunc,struct fl_tuple *ftuple,bool is_in_dev) +{ +struct fib_nh_common *fib_nhc; +struct net_device *dev, *br; +struct otx2_nic *nic; +struct fib_result res; +struct list_head *lh; +int err; + +rcu_read_lock (); + + err =sw_fl_get_route (&res, dst); +if (err) { +pr_err ("%s:%d Failed to find route to dst %pI4\n" , + __func__, __LINE__, &dst); + goto done; + } + +if (res.fi->fib_type !=RTN_UNICAST ) { +pr_err ("%s:%d Not unicast route to dst %pi4\n" , + __func__, __LINE__, &dst); + err = -EFAULT ; + goto done; + } + + fib_nhc =fib_info_nhc (res.fi,0 ); +if (!fib_nhc) { + err = -EINVAL ; +pr_err ("%s:%d Could not get fib_nhc for %pI4\n" , + __func__, __LINE__, &dst); + goto done; + } + +if (unlikely (netif_is_bridge_master (fib_nhc->nhc_dev))) { + br = fib_nhc->nhc_dev; + +if (is_in_dev) + ftuple->is_indev_br =1 ; +else + ftuple->is_xdev_br =1 ; + + lh = &br->adj_list.lower; +if (list_empty (lh)) { +pr_err ("%s:%d Unable to find any slave device\n" , + __func__, __LINE__); + err = -EINVAL ; + goto done; + } + dev =netdev_next_lower_dev_rcu (br, &lh); + + }else { + dev = fib_nhc->nhc_dev; + } + +if (!sw_nb_is_valid_dev (dev)) { +pr_err ("%s:%d flow acceleration support is only for cavium devices\n" , + __func__, __LINE__); + err = -EOPNOTSUPP ; + goto done; + } + + nic =netdev_priv (dev); + *pcifunc = nic->pcifunc; + +done: +rcu_read_unlock (); +return err; +} + +static int sw_fl_parse_flow (struct otx2_nic *nic,struct flow_cls_offload *f, +struct fl_tuple *tuple,u64 *features) +{ +struct flow_rule *rule; +u8 ip_proto =0 ; + + *features =0 ; + + rule =flow_cls_offload_flow_rule (f); + +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_BASIC )) { +struct flow_match_basic match; + +flow_rule_match_basic (rule, &match); + +/* All EtherTypes can be matched, no hw limitation */ + +if (match.mask->n_proto) { + tuple->eth_type = match.key->n_proto; + tuple->m_eth_type = match.mask->n_proto; + *features |=BIT_ULL (NPC_ETYPE ); + } + +if (match.mask->ip_proto && + (match.key->ip_proto !=IPPROTO_TCP && + match.key->ip_proto !=IPPROTO_UDP )) { +netdev_dbg (nic->netdev, +"ip_proto=%u not supported\n" , + match.key->ip_proto); + } + +if (match.mask->ip_proto) + ip_proto = match.key->ip_proto; + +if (ip_proto ==IPPROTO_UDP ) { + *features |=BIT_ULL (NPC_IPPROTO_UDP ); + }else if (ip_proto ==IPPROTO_TCP ) { + *features |=BIT_ULL (NPC_IPPROTO_TCP ); + }else { +netdev_dbg (nic->netdev, +"ip_proto=%u not supported\n" , + match.key->ip_proto); + } + + tuple->proto = ip_proto; + } + +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ETH_ADDRS )) { +struct flow_match_eth_addrs match; + +flow_rule_match_eth_addrs (rule, &match); + +if (!is_zero_ether_addr (match.key->dst) && +is_unicast_ether_addr (match.key->dst)) { +ether_addr_copy (tuple->dmac, + match.key->dst); + +ether_addr_copy (tuple->m_dmac, + match.mask->dst); + + *features |=BIT_ULL (NPC_DMAC ); + } + +if (!is_zero_ether_addr (match.key->src) && +is_unicast_ether_addr (match.key->src)) { +ether_addr_copy (tuple->smac, + match.key->src); +ether_addr_copy (tuple->m_smac, + match.mask->src); + *features |=BIT_ULL (NPC_SMAC ); + } + } + +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_IPV4_ADDRS )) { +struct flow_match_ipv4_addrs match; + +flow_rule_match_ipv4_addrs (rule, &match); + +if (match.key->dst) { + tuple->ip4dst = match.key->dst; + tuple->m_ip4dst = match.mask->dst; + *features |=BIT_ULL (NPC_DIP_IPV4 ); + } + +if (match.key->src) { + tuple->ip4src = match.key->src; + tuple->m_ip4src = match.mask->src; + *features |=BIT_ULL (NPC_SIP_IPV4 ); + } + } + +if (!(*features &BIT_ULL (NPC_DMAC ))) { +if (!tuple->ip4src || !tuple->ip4dst) { +pr_err ("%s:%d Invalid src=%pI4 and dst=%pI4 addresses\n" , + __func__, __LINE__, &tuple->ip4src, &tuple->ip4dst); +return -EINVAL ; + } + +if ((tuple->ip4src & tuple->m_ip4src) == (tuple->ip4dst & tuple->m_ip4dst)) { +pr_err ("%s:%d Masked values are same; Invalid src=%pI4 and dst=%pI4 addresses\n" , + __func__, __LINE__, &tuple->ip4src, &tuple->ip4dst); +return -EINVAL ; + } + } + +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_PORTS )) { +struct flow_match_ports match; + +flow_rule_match_ports (rule, &match); + +if (ip_proto ==IPPROTO_UDP ) { +if (match.key->dst) + *features |=BIT_ULL (NPC_DPORT_UDP ); + +if (match.key->src) + *features |=BIT_ULL (NPC_SPORT_UDP ); + }else if (ip_proto ==IPPROTO_TCP ) { +if (match.key->dst) + *features |=BIT_ULL (NPC_DPORT_TCP ); + +if (match.key->src) + *features |=BIT_ULL (NPC_SPORT_TCP ); + } + +if (match.mask->src) { + tuple->sport = match.key->src; + tuple->m_sport = match.mask->src; + } + +if (match.mask->dst) { + tuple->dport = match.key->dst; + tuple->m_dport = match.mask->dst; + } + } + +if (!(*features & (BIT_ULL (NPC_DMAC ) | +BIT_ULL (NPC_SMAC ) | +BIT_ULL (NPC_DIP_IPV4 ) | +BIT_ULL (NPC_SIP_IPV4 ) | +BIT_ULL (NPC_DPORT_UDP ) | +BIT_ULL (NPC_SPORT_UDP ) | +BIT_ULL (NPC_DPORT_TCP ) | +BIT_ULL (NPC_SPORT_TCP )))) { +return -EINVAL ; + } + + tuple->features = *features; + +return 0 ; +} + +static int sw_fl_add (struct otx2_nic *nic,struct flow_cls_offload *f) +{ +struct fl_tuple tuple = {0 }; +struct flow_rule *rule; +u64 features =0 ; +u64 op =0 ; +int rc; + + rule =flow_cls_offload_flow_rule (f); + + rc =sw_fl_parse_actions (nic, &rule->action, f, &tuple, &op); +if (rc) +return rc; + +if (op &BIT_ULL (FLOW_ACTION_CT )) +return 0 ; + + rc =sw_fl_parse_flow (nic, f, &tuple, &features); +if (rc) +return -EFAULT ; + +if (!netif_is_ovs_port (nic->netdev)) { + rc =sw_fl_get_pcifunc (tuple.ip4src, &tuple.in_pf, &tuple, true); +if (rc) +return rc; +
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 447
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +10
-0+ rc =sw_fl_get_pcifunc (tuple.ip4dst, &tuple.xmit_pf, &tuple, false); +if (rc) +return rc; + } + +sw_fl_add_to_list (nic, &tuple, f->cookie, true); +return 0 ; +} + +static int sw_fl_del (struct otx2_nic *nic,struct flow_cls_offload *f)
function prototype can be changed to void?
Quoted 114 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +81
-0+{ +sw_fl_add_to_list (nic,NULL , f->cookie, false); +return 0 ; +} + +static int sw_fl_stats (struct otx2_nic *nic,struct flow_cls_offload *f) +{ +struct fl_get_stats_req *req; +struct fl_get_stats_rsp *rsp; +u64 pkts_diff; +int rc =0 ; + +mutex_lock (&nic->mbox.lock); + + req =otx2_mbox_alloc_msg_fl_get_stats (&nic->mbox); +if (!req) { +pr_err ("%s:%d Error happened while mcam alloc req\n" , __func__, __LINE__); + rc = -ENOMEM ; + goto fail; + } + req->cookie = f->cookie; + + rc =otx2_sync_mbox_msg (&nic->mbox); +if (rc) + goto fail; + + rsp = (struct fl_get_stats_rsp *)otx2_mbox_get_rsp + (&nic->mbox.mbox,0 , &req->hdr); +if (IS_ERR (rsp)) { + rc =PTR_ERR (rsp); + goto fail; + } + + pkts_diff = rsp->pkts_diff; +mutex_unlock (&nic->mbox.lock); + +if (pkts_diff) { +flow_stats_update (&f->stats,0x0 , pkts_diff, +0x0 , jiffies, +FLOW_ACTION_HW_STATS_IMMEDIATE ); + } +return 0 ; +fail: +mutex_unlock (&nic->mbox.lock); +return rc; +} + +static bool init_done; + +int sw_fl_setup_ft_block_ingress_cb (enum tc_setup_type type, +void *type_data,void *cb_priv) +{ +struct flow_cls_offload *cls = type_data; +struct otx2_nic *nic = cb_priv; + +if (!init_done) +return 0 ; + +switch (cls->command) { +case FLOW_CLS_REPLACE : +return sw_fl_add (nic, cls); +case FLOW_CLS_DESTROY : +return sw_fl_del (nic, cls); +case FLOW_CLS_STATS : +return sw_fl_stats (nic, cls); +default : +break ; + } + +return -EOPNOTSUPP ; +} +int sw_fl_init (void ) { +INIT_WORK (&sw_fl_work, sw_fl_wq_handler); + sw_fl_wq =alloc_workqueue ("sw_fl_wq" ,0 ,0 ); +if (!sw_fl_wq) +return -ENOMEM ; + + init_done = true;return 0 ; }void sw_fl_deinit (void ) { +cancel_work_sync (&sw_fl_work); +destroy_workqueue (sw_fl_wq); } +#endif drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.h +2
-0@@ -9,5 +9,7 @@void sw_fl_deinit (void );int sw_fl_init (void ); +int sw_fl_setup_ft_block_ingress_cb (enum tc_setup_type type, +void *type_data,void *cb_priv);#endif // SW_FL_H drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_nb.c +0
-2@@ -21,7 +21,6 @@#include "sw_fdb.h" #include "sw_fib.h" #include "sw_fl.h" -#include "sw_nb.h" static const char *sw_nb_cmd2str[OTX2_CMD_MAX ] = { [OTX2_DEV_UP ] ="OTX2_DEV_UP" , --
Quoted 3 lines
2.43.0
--
Regards,
Kalesh AP
Ratheesh Kannoth
maintainerRe: [PATCH net-next v2 09/10] octeontx2: switch: Flow offload support
Quoted 8 lines · Kalesh Anakkur Purayil
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 97
Quoted 6 lines · Ratheesh Kannoth
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +5
-0+return 0 ; + } +mutex_unlock (&sw_fl_stats_lock); + + snode =kcalloc (1 ,sizeof (*snode),GFP_KERNEL );Why not
kzalloc()instead of kcalloc with size 1?
All fields are assigned with values. why to initialize to zero ?
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 120
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +9
-0+if (!snode) + +return 0 ; +} + +int rvu_sw_fl_stats_sync2db (struct rvu *rvu,struct fl_info *fl,int cnt) +{ +struct npc_mcam_get_mul_stats_req *req =NULL ; +struct npc_mcam_get_mul_stats_rsp *rsp =NULL ;there is no need to initialize these two variables
This is initialized so that (after fail lablel) free() does not act on garbage value.
Quoted 3 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 122
Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +2
-0+int tot =0 ; +u16 i2idx_map[256 ];follow RCT order
ACK.
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 129
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+int rc =0 ; +u64 pkts; +int idx; + + cnt =min (cnt,64 ); + +for (int i =0 ; i < cnt; i++) {I think you can move the declaration of i at the beginning of the function. it is repeated in the for loops below as well
I think, better to keep the scope local. Does kernel coding guidlines mandate it ?
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 137
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +8
-0+ tot++; +if (fl[i].uni_di) +continue ; + + tot++; + } + + req =kcalloc (1 ,sizeof (*req),GFP_KERNEL );I think you can use kzalloc kere
ACK.
Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!req) { + rc = -ENOMEM;You can return directly here
ACK.
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 146
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+ goto fail; + } + + rsp =kcalloc (1 ,sizeof (*rsp),GFP_KERNEL ); +if (!rsp) { + rc = -ENOMEM ; + goto fail;better do individual cleanup by adding a label and use goto
free_req
free: lablel is enough , right ?
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +10
-0+ } + + req->cnt = tot; + idx =0 ; +for (int i =0 ; i < tot; idx++) { + i2idx_map[i] = idx; + req->entry[i++] = fl[idx].mcam_idx[0 ]; +if (fl[idx].uni_di) +continue ; +
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c line 163
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +7
-0+ i2idx_map[i] = idx; + req->entry[i++] = fl[idx].mcam_idx[1 ]; + } + +if (rvu_mbox_handler_npc_mcam_mul_stats (rvu, req, rsp)) { +dev_err (rvu->dev,"Error to get multiple stats\n" ); + rc = -EFAULT ;You can add a new label and use goto
free_resp
same comment as above.
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +13
-0+ goto fail; + } + + +fail: +kfree (req); +kfree (rsp); +return rc; +} + + fl_entry->features = req->features; + +mutex_lock (&fl_offl_llock);
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c int rvu_mbox_handler_fl_notify(struct rvu *rvu, · line 291
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/af/switch/rvu_sw_fl.c +6
-0+list_add_tail (&fl_entry->list, &fl_offl_lh); +mutex_unlock (&fl_offl_llock); + +if (!fl_offl_work_running) { + sw_fl_offl_wq =alloc_workqueue ("sw_af_fl_wq" ,0 ,0 ); +if (!sw_fl_offl_wq)free
fl_entryhere? also, do you want to movelist_add_tail()after thisif()condition?
ACK.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4
-0+return -ENOMEM ; + void *type_data) { +struct otx2_nic *nic =netdev_priv (netdev); +switch (type) {
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1607
Quoted 7 lines
case
TC_SETUP_BLOCK:drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +6
-0+if (netif_is_ovs_port (netdev)) { +return flow_block_cb_setup_simple (type_data, + &otx2_block_cb_list, + sw_fl_setup_ft_block_ingress_cb, + nic, nic, true); + }braces are not required here
ACK.
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +5
-0+return otx2_setup_tc_block (netdev, type_data); +} + +static int sw_fl_parse_actions(struct otx2_nic *nic, + struct flow_action *flow_action,
Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 129
Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +7
-0+struct flow_cls_offload *f, + struct fl_tuple *tuple, u64 *op) +{ + struct flow_action_entry *act; +struct otx2_nic *out_nic; +int err; +int used =0 ;RCT order here
ACK.
Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c line 447
Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +9
-0+int i; +return rc; + } + +sw_fl_add_to_list (nic, &tuple, f->cookie, true); +return 0 ; +} + +static int sw_fl_del (struct otx2_nic *nic,struct flow_cls_offload *f)function prototype can be changed to void?
ACK.
Quoted 1 line
Quoted 1 line
+{
Ratheesh Kannoth
maintainerPATCH v2 10/10 octeontx2: switch: trace support
In reply to Ratheesh KannothTraces are added to flow parsing to ease debugging.
--- .../ethernet/marvell/octeontx2/nic/Makefile | 2 +- .../marvell/octeontx2/nic/switch/sw_fl.c | 18 +++- .../marvell/octeontx2/nic/switch/sw_trace.c | 11 +++ .../marvell/octeontx2/nic/switch/sw_trace.h | 82 +++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.c create mode 100644 drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.h
drivers/net/ethernet/marvell/octeontx2/nic/Makefile +1 -1
@@ -13,7 +13,7 @@ rvu_nicpf-y := otx2_pf.o otx2_common.o otx2_txrx.o otx2_ethtool.o \ switch/sw_fdb.o switch/sw_fl.o ifdef CONFIG_OCTEONTX_SWITCH -rvu_nicpf-y += switch/sw_nb.o switch/sw_fib.o +rvu_nicpf-y += switch/sw_nb.o switch/sw_fib.o switch/sw_trace.o endif rvu_nicvf-y := otx2_vf.o
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_fl.c +15 -3
@@ -18,6 +18,7 @@#include "../otx2_struct.h" #include "../cn10k.h" #include "sw_nb.h" +#include "sw_trace.h" #include "sw_fl.h" #if !IS_ENABLED (CONFIG_OCTEONTX_SWITCH )
@@ -137,6 +138,7 @@ static int sw_fl_parse_actions(struct otx2_nic *nic,switch (act->id) {case FLOW_ACTION_REDIRECT : +trace_sw_act_dump (__func__, __LINE__, act->id); tuple->in_pf = nic->pcifunc; out_nic =netdev_priv (act->dev); tuple->xmit_pf = out_nic->pcifunc;
@@ -144,6 +146,7 @@ static int sw_fl_parse_actions(struct otx2_nic *nic,break ;case FLOW_ACTION_CT : +trace_sw_act_dump (__func__, __LINE__, act->id); err =nf_flow_table_offload_add_cb (act->ct.flow_table, sw_fl_setup_ft_block_ingress_cb, nic);
@@ -157,6 +160,7 @@ static int sw_fl_parse_actions(struct otx2_nic *nic,break ;case FLOW_ACTION_MANGLE : +trace_sw_act_dump (__func__, __LINE__, act->id); tuple->mangle[used].type = act->mangle.htype; tuple->mangle[used].val = act->mangle.val; tuple->mangle[used].mask = act->mangle.mask;
@@ -166,6 +170,7 @@ static int sw_fl_parse_actions(struct otx2_nic *nic,break ;default : +trace_sw_act_dump (__func__, __LINE__, act->id);break ; } }
@@ -427,19 +432,26 @@ static int sw_fl_add(struct otx2_nic *nic, struct flow_cls_offload *f)return 0 ; rc =sw_fl_parse_flow (nic, f, &tuple, &features); -if (rc) +if (rc) { +trace_sw_fl_dump (__func__, __LINE__, &tuple);return -EFAULT ; + }if (!netif_is_ovs_port (nic->netdev)) { rc =sw_fl_get_pcifunc (tuple.ip4src, &tuple.in_pf, &tuple, true); -if (rc) +if (rc) { +trace_sw_fl_dump (__func__, __LINE__, &tuple);return rc; + } rc =sw_fl_get_pcifunc (tuple.ip4dst, &tuple.xmit_pf, &tuple, false); -if (rc) +if (rc) { +trace_sw_fl_dump (__func__, __LINE__, &tuple);return rc; + } } +trace_sw_fl_dump (__func__, __LINE__, &tuple);sw_fl_add_to_list (nic, &tuple, f->cookie, true);return 0 ; }
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.c new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Marvell RVU Admin Function driver +* +* Copyright (C) 2026 Marvell. +* +*/ + +#define CREATE_TRACE_POINTS +#include "sw_trace.h" +EXPORT_TRACEPOINT_SYMBOL (sw_fl_dump); +EXPORT_TRACEPOINT_SYMBOL (sw_act_dump);
drivers/net/ethernet/marvell/octeontx2/nic/switch/sw_trace.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.43.0