diff mbox series

[net-next,08/12] mlxsw: Add APIs to init/fini PCI port

Message ID 6189497bf72fc28c44c55195f7f7759755014dc4.1738665783.git.petrm@nvidia.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series mlxsw: Preparations for XDP support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 53 this patch: 53
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 70 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-04--15-00 (tests: 886)

Commit Message

Petr Machata Feb. 4, 2025, 11:05 a.m. UTC
From: Amit Cohen <amcohen@nvidia.com>

The previous patch added PCI ports array, to store the associated netdevice
for each local port. Add APIs which set/unset netdevice for specific local
port, these APIs will be used from mlxsw_sp_port_create() and
mlxsw_sp_port_remove(). For now, store only netdevice pointer, next patches
will extend this structure.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 13 +++++++++++++
 drivers/net/ethernet/mellanox/mlxsw/core.h |  6 ++++++
 drivers/net/ethernet/mellanox/mlxsw/pci.c  | 21 +++++++++++++++++++++
 3 files changed, 40 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index 392c0355d589..628530e01b19 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -219,6 +219,19 @@  mlxsw_core_flood_mode(struct mlxsw_core *mlxsw_core)
 }
 EXPORT_SYMBOL(mlxsw_core_flood_mode);
 
+void mlxsw_core_bus_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
+			      struct net_device *netdev)
+{
+	mlxsw_core->bus->port_init(mlxsw_core->bus_priv, local_port, netdev);
+}
+EXPORT_SYMBOL(mlxsw_core_bus_port_init);
+
+void mlxsw_core_bus_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port)
+{
+	mlxsw_core->bus->port_fini(mlxsw_core->bus_priv, local_port);
+}
+EXPORT_SYMBOL(mlxsw_core_bus_port_fini);
+
 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core)
 {
 	return mlxsw_core->driver_priv;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h
index 72eb7dbf57ce..506fe50acdec 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.h
@@ -40,6 +40,9 @@  enum mlxsw_cmd_mbox_config_profile_lag_mode
 mlxsw_core_lag_mode(struct mlxsw_core *mlxsw_core);
 enum mlxsw_cmd_mbox_config_profile_flood_mode
 mlxsw_core_flood_mode(struct mlxsw_core *mlxsw_core);
+void mlxsw_core_bus_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
+			      struct net_device *netdev);
+void mlxsw_core_bus_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port);
 
 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);
 
@@ -495,6 +498,9 @@  struct mlxsw_bus {
 	u32 (*read_frc_l)(void *bus_priv);
 	u32 (*read_utc_sec)(void *bus_priv);
 	u32 (*read_utc_nsec)(void *bus_priv);
+	void (*port_init)(void *bus_priv, u16 local_port,
+			  struct net_device *netdev);
+	void (*port_fini)(void *bus_priv, u16 local_port);
 	enum mlxsw_cmd_mbox_config_profile_lag_mode (*lag_mode)(void *bus_priv);
 	enum mlxsw_cmd_mbox_config_profile_flood_mode (*flood_mode)(void *priv);
 	u8 features;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index 563b9c0578f8..bd6c772a3384 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -2434,6 +2434,25 @@  mlxsw_pci_flood_mode(void *bus_priv)
 	return mlxsw_pci->flood_mode;
 }
 
+static void mlxsw_pci_port_init(void *bus_priv, u16 local_port,
+				struct net_device *netdev)
+{
+	struct mlxsw_pci *mlxsw_pci = bus_priv;
+	struct mlxsw_pci_port *pci_port;
+
+	pci_port = &mlxsw_pci->pci_ports[local_port];
+	pci_port->netdev = netdev;
+}
+
+static void mlxsw_pci_port_fini(void *bus_priv, u16 local_port)
+{
+	struct mlxsw_pci *mlxsw_pci = bus_priv;
+	struct mlxsw_pci_port *pci_port;
+
+	pci_port = &mlxsw_pci->pci_ports[local_port];
+	pci_port->netdev = NULL;
+}
+
 static const struct mlxsw_bus mlxsw_pci_bus = {
 	.kind			= "pci",
 	.init			= mlxsw_pci_init,
@@ -2445,6 +2464,8 @@  static const struct mlxsw_bus mlxsw_pci_bus = {
 	.read_frc_l		= mlxsw_pci_read_frc_l,
 	.read_utc_sec		= mlxsw_pci_read_utc_sec,
 	.read_utc_nsec		= mlxsw_pci_read_utc_nsec,
+	.port_init		= mlxsw_pci_port_init,
+	.port_fini		= mlxsw_pci_port_fini,
 	.lag_mode		= mlxsw_pci_lag_mode,
 	.flood_mode		= mlxsw_pci_flood_mode,
 	.features		= MLXSW_BUS_F_TXRX | MLXSW_BUS_F_RESET,