Commit 6445eef0 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller
Browse files

mlxsw: spectrum: Add port to linecard mapping



For each port get slot_index using PMLP register. For ports residing
on a linecard, identify it with the linecard by setting mapping
using devlink_port_linecard_set() helper. Use linecard slot index for
PMTDB register queries.

Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 45bf3b72
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ struct mlxsw_core_port {
	struct devlink_port devlink_port;
	void *port_driver_priv;
	u16 local_port;
	struct mlxsw_linecard *linecard;
};

void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port)
@@ -2975,7 +2976,7 @@ EXPORT_SYMBOL(mlxsw_core_res_get);

static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
				  enum devlink_port_flavour flavour,
				  u32 port_number, bool split,
				  u8 slot_index, u32 port_number, bool split,
				  u32 split_port_subnumber,
				  bool splittable, u32 lanes,
				  const unsigned char *switch_id,
@@ -2998,6 +2999,15 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
	attrs.switch_id.id_len = switch_id_len;
	mlxsw_core_port->local_port = local_port;
	devlink_port_attrs_set(devlink_port, &attrs);
	if (slot_index) {
		struct mlxsw_linecard *linecard;

		linecard = mlxsw_linecard_get(mlxsw_core->linecards,
					      slot_index);
		mlxsw_core_port->linecard = linecard;
		devlink_port_linecard_set(devlink_port,
					  linecard->devlink_linecard);
	}
	err = devl_port_register(devlink, devlink_port, local_port);
	if (err)
		memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
@@ -3015,7 +3025,7 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port
}

int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
			 u32 port_number, bool split,
			 u8 slot_index, u32 port_number, bool split,
			 u32 split_port_subnumber,
			 bool splittable, u32 lanes,
			 const unsigned char *switch_id,
@@ -3024,7 +3034,7 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
	int err;

	err = __mlxsw_core_port_init(mlxsw_core, local_port,
				     DEVLINK_PORT_FLAVOUR_PHYSICAL,
				     DEVLINK_PORT_FLAVOUR_PHYSICAL, slot_index,
				     port_number, split, split_port_subnumber,
				     splittable, lanes,
				     switch_id, switch_id_len);
@@ -3055,7 +3065,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,

	err = __mlxsw_core_port_init(mlxsw_core, MLXSW_PORT_CPU_PORT,
				     DEVLINK_PORT_FLAVOUR_CPU,
				     0, false, 0, false, 0,
				     0, 0, false, 0, false, 0,
				     switch_id, switch_id_len);
	if (err)
		return err;
@@ -3131,6 +3141,16 @@ mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
}
EXPORT_SYMBOL(mlxsw_core_port_devlink_port_get);

struct mlxsw_linecard *
mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
			     u16 local_port)
{
	struct mlxsw_core_port *mlxsw_core_port =
					&mlxsw_core->ports[local_port];

	return mlxsw_core_port->linecard;
}

bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port)
{
	const struct mlxsw_bus_info *bus_info = mlxsw_core->bus_info;
+5 −1
Original line number Diff line number Diff line
@@ -236,7 +236,8 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,

void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
			 u32 port_number, bool split, u32 split_port_subnumber,
			 u8 slot_index, u32 port_number, bool split,
			 u32 split_port_subnumber,
			 bool splittable, u32 lanes,
			 const unsigned char *switch_id,
			 unsigned char switch_id_len);
@@ -257,6 +258,9 @@ enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
struct devlink_port *
mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
				 u16 local_port);
struct mlxsw_linecard *
mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
			     u16 local_port);
bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port);
void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core,
				      bool (*selector)(void *priv,
+13 −0
Original line number Diff line number Diff line
@@ -481,6 +481,15 @@ mlxsw_linecard_ini_in_use_wait(struct mlxsw_core *mlxsw_core,
	return 0;
}

static bool mlxsw_linecard_port_selector(void *priv, u16 local_port)
{
	struct mlxsw_linecard *linecard = priv;
	struct mlxsw_core *mlxsw_core;

	mlxsw_core = linecard->linecards->mlxsw_core;
	return linecard == mlxsw_core_port_linecard_get(mlxsw_core, local_port);
}

static int mlxsw_linecard_provision(struct devlink_linecard *devlink_linecard,
				    void *priv, const char *type,
				    const void *type_priv,
@@ -531,6 +540,10 @@ static int mlxsw_linecard_unprovision(struct devlink_linecard *devlink_linecard,

	mlxsw_core = linecard->linecards->mlxsw_core;

	mlxsw_core_ports_remove_selected(mlxsw_core,
					 mlxsw_linecard_port_selector,
					 linecard);

	err = mlxsw_linecard_ini_in_use_wait(mlxsw_core, linecard, extack);
	if (err)
		goto err_out;
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module)
	struct net_device *dev;
	int err;

	err = mlxsw_core_port_init(mlxsw_m->core, local_port,
	err = mlxsw_core_port_init(mlxsw_m->core, local_port, 0,
				   module + 1, false, 0, false,
				   0, mlxsw_m->base_mac,
				   sizeof(mlxsw_m->base_mac));
+9 −0
Original line number Diff line number Diff line
@@ -4325,6 +4325,15 @@ MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
 */
MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0x00, false);

/* reg_pmlp_slot_index
 * Module number.
 * Slot_index
 * Slot_index = 0 represent the onboard (motherboard).
 * In case of non-modular system only slot_index = 0 is available.
 * Access: RW
 */
MLXSW_ITEM32_INDEXED(reg, pmlp, slot_index, 0x04, 8, 4, 0x04, 0x00, false);

/* reg_pmlp_tx_lane
 * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
 * Access: RW
Loading