Skip to content

Commit

Permalink
mlxsw: core_linecards: Add line card objects and implement provisioning
Browse files Browse the repository at this point in the history
Introduce objects for line cards and an infrastructure around that.
Use devlink_linecard_create/destroy() to register the line card with
devlink core. Implement provisioning ops with a list of supported
line cards.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and davem330 committed Apr 18, 2022
1 parent 5bade5a commit b217127
Show file tree
Hide file tree
Showing 6 changed files with 1,006 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_MLXSW_CORE) += mlxsw_core.o
mlxsw_core-objs := core.o core_acl_flex_keys.o \
core_acl_flex_actions.o core_env.o
core_acl_flex_actions.o core_env.o \
core_linecards.o
mlxsw_core-$(CONFIG_MLXSW_CORE_HWMON) += core_hwmon.o
mlxsw_core-$(CONFIG_MLXSW_CORE_THERMAL) += core_thermal.o
obj-$(CONFIG_MLXSW_PCI) += mlxsw_pci.o
Expand Down
19 changes: 19 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct mlxsw_core {
struct mlxsw_res res;
struct mlxsw_hwmon *hwmon;
struct mlxsw_thermal *thermal;
struct mlxsw_linecards *linecards;
struct mlxsw_core_port *ports;
unsigned int max_ports;
atomic_t active_ports_count;
Expand All @@ -94,6 +95,17 @@ struct mlxsw_core {
/* driver_priv has to be always the last item */
};

struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core)
{
return mlxsw_core->linecards;
}

void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards)
{
mlxsw_core->linecards = linecards;
}

#define MLXSW_PORT_MAX_PORTS_DEFAULT 0x40

static u64 mlxsw_ports_occ_get(void *priv)
Expand Down Expand Up @@ -2145,6 +2157,10 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
if (err)
goto err_fw_rev_validate;

err = mlxsw_linecards_init(mlxsw_core, mlxsw_bus_info);
if (err)
goto err_linecards_init;

err = mlxsw_core_health_init(mlxsw_core);
if (err)
goto err_health_init;
Expand Down Expand Up @@ -2183,6 +2199,8 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
err_hwmon_init:
mlxsw_core_health_fini(mlxsw_core);
err_health_init:
mlxsw_linecards_fini(mlxsw_core);
err_linecards_init:
err_fw_rev_validate:
if (!reload)
mlxsw_core_params_unregister(mlxsw_core);
Expand Down Expand Up @@ -2255,6 +2273,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core,
mlxsw_thermal_fini(mlxsw_core->thermal);
mlxsw_hwmon_fini(mlxsw_core->hwmon);
mlxsw_core_health_fini(mlxsw_core);
mlxsw_linecards_fini(mlxsw_core);
if (!reload)
mlxsw_core_params_unregister(mlxsw_core);
mlxsw_emad_fini(mlxsw_core);
Expand Down
46 changes: 46 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core);

void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);

struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core);

void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecard);

bool
mlxsw_core_fw_rev_minor_subminor_validate(const struct mlxsw_fw_rev *rev,
const struct mlxsw_fw_rev *req_rev);
Expand Down Expand Up @@ -543,4 +548,45 @@ static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb)
return (struct mlxsw_skb_cb *) skb->cb;
}

struct mlxsw_linecards;

enum mlxsw_linecard_status_event_type {
MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION,
MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION,
};

struct mlxsw_linecard {
u8 slot_index;
struct mlxsw_linecards *linecards;
struct devlink_linecard *devlink_linecard;
struct mutex lock; /* Locks accesses to the linecard structure */
char name[MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN];
char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */
enum mlxsw_linecard_status_event_type status_event_type_to;
struct delayed_work status_event_to_dw;
u8 provisioned:1;
u16 hw_revision;
u16 ini_version;
};

struct mlxsw_linecard_types_info;

struct mlxsw_linecards {
struct mlxsw_core *mlxsw_core;
const struct mlxsw_bus_info *bus_info;
u8 count;
struct mlxsw_linecard_types_info *types_info;
struct mlxsw_linecard linecards[];
};

static inline struct mlxsw_linecard *
mlxsw_linecard_get(struct mlxsw_linecards *linecards, u8 slot_index)
{
return &linecards->linecards[slot_index - 1];
}

int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *bus_info);
void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core);

#endif
Loading

0 comments on commit b217127

Please sign in to comment.