[PATCH net-next 06/12] mlxsw: pci: Store maximum number of ports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Amit Cohen <amcohen@xxxxxxxxxx>

A next patch will store mapping between local port to netdevice in PCI
driver. The motivation is to allow quick access to XDP program.
When a packet is received, the Rx local port is known, to run XDP program
we need to map Rx local port to netdevice, as XDP program is set per
netdevice.

As preparation, store the maximum number of ports as part of mlxsw_pci
structure, this value is queried from firmware.

Signed-off-by: Amit Cohen <amcohen@xxxxxxxxxx>
Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxx>
Signed-off-by: Petr Machata <petrm@xxxxxxxxxx>
---
 drivers/net/ethernet/mellanox/mlxsw/pci.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index 5796d836a7ee..8af4050d5fc6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -137,6 +137,7 @@ struct mlxsw_pci {
 	bool skip_reset;
 	struct net_device *napi_dev_tx;
 	struct net_device *napi_dev_rx;
+	unsigned int max_ports;
 };
 
 static int mlxsw_pci_napi_devs_init(struct mlxsw_pci *mlxsw_pci)
@@ -171,6 +172,20 @@ static void mlxsw_pci_napi_devs_fini(struct mlxsw_pci *mlxsw_pci)
 	free_netdev(mlxsw_pci->napi_dev_tx);
 }
 
+static int mlxsw_pci_max_ports_set(struct mlxsw_pci *mlxsw_pci)
+{
+	struct mlxsw_core *mlxsw_core = mlxsw_pci->core;
+	unsigned int max_ports;
+
+	if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_SYSTEM_PORT))
+		return -EINVAL;
+
+	/* Switch ports are numbered from 1 to queried value */
+	max_ports = MLXSW_CORE_RES_GET(mlxsw_core, MAX_SYSTEM_PORT) + 1;
+	mlxsw_pci->max_ports = max_ports;
+	return 0;
+}
+
 static char *__mlxsw_pci_queue_elem_get(struct mlxsw_pci_queue *q,
 					size_t elem_size, int elem_index)
 {
@@ -2069,6 +2084,10 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
 	if (err)
 		goto err_napi_devs_init;
 
+	err = mlxsw_pci_max_ports_set(mlxsw_pci);
+	if (err)
+		goto err_max_ports_set;
+
 	err = mlxsw_pci_aqs_init(mlxsw_pci, mbox);
 	if (err)
 		goto err_aqs_init;
@@ -2086,6 +2105,7 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
 err_request_eq_irq:
 	mlxsw_pci_aqs_fini(mlxsw_pci);
 err_aqs_init:
+err_max_ports_set:
 	mlxsw_pci_napi_devs_fini(mlxsw_pci);
 err_napi_devs_init:
 err_requery_resources:
-- 
2.47.0





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux