Commit 2a38de06 authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-line-card'

Ido Schimmel says:

====================
mlxsw: Introduce line card support for modular switch

Jiri says:

This patchset introduces support for modular switch systems and also
introduces mlxsw support for NVIDIA Mellanox SN4800 modular switch.
It contains 8 slots to accommodate line cards - replaceable PHY modules
which may contain gearboxes.
Currently supported line card:
16X 100GbE (QSFP28)
Other line cards that are going to be supported:
8X 200GbE (QSFP56)
4X 400GbE (QSFP-DD)
There may be other types of line cards added in the future.

To be consistent with the port split configuration (splitter cabels),
the line card entities are treated in the similar way. The nature of
a line card is not "a pluggable device", but "a pluggable PHY module".

A concept of "provisioning" is introduced. The user may "provision"
certain slot with a line card type. Driver then creates all instances
(devlink ports, netdevices, etc) related to this line card type. It does
not matter if the line card is plugged-in at the time. User is able to
configure netdevices, devlink ports, setup port splitters, etc. From the
perspective of the switch ASIC, all is present and can be configured.

The carrier of netdevices stays down if the line card is not plugged-in.
Once the line card is inserted and activated, the carrier of
the related netdevices is then reflecting the physical line state,
same as for an ordinary fixed port.

Once user does not want to use the line card related instances
anymore, he can "unprovision" the slot. Driver then removes the
instances.

Patches 1-4 are extending devlink driver API and UAPI in order to
register, show, dump, provision and activate the line card.
Patches 5-17 are implementing the introduced API in mlxsw.
The last patch adds a selftest for mlxsw line cards.

Example:
$ devlink port # No ports are listed
$ devlink lc
pci/0000:01:00.0:
  lc 1 state unprovisioned
    supported_types:
       16x100G
  lc 2 state unprovisioned
    supported_types:
       16x100G
  lc 3 state unprovisioned
    supported_types:
       16x100G
  lc 4 state unprovisioned
    supported_types:
       16x100G
  lc 5 state unprovisioned
    supported_types:
       16x100G
  lc 6 state unprovisioned
    supported_types:
       16x100G
  lc 7 state unprovisioned
    supported_types:
       16x100G
  lc 8 state unprovisioned
    supported_types:
       16x100G

Note that driver exposes list supported line card types. Currently
there is only one: "16x100G".

To provision the slot #8:

$ devlink lc set pci/0000:01:00.0 lc 8 type 16x100G
$ devlink lc show pci/0000:01:00.0 lc 8
pci/0000:01:00.0:
  lc 8 state active type 16x100G
    supported_types:
       16x100G
$ devlink port
pci/0000:01:00.0/0: type notset flavour cpu port 0 splittable false
pci/0000:01:00.0/53: type eth netdev enp1s0nl8p1 flavour physical lc 8 port 1 splittable true lanes 4
pci/0000:01:00.0/54: type eth netdev enp1s0nl8p2 flavour physical lc 8 port 2 splittable true lanes 4
pci/0000:01:00.0/55: type eth netdev enp1s0nl8p3 flavour physical lc 8 port 3 splittable true lanes 4
pci/0000:01:00.0/56: type eth netdev enp1s0nl8p4 flavour physical lc 8 port 4 splittable true lanes 4
pci/0000:01:00.0/57: type eth netdev enp1s0nl8p5 flavour physical lc 8 port 5 splittable true lanes 4
pci/0000:01:00.0/58: type eth netdev enp1s0nl8p6 flavour physical lc 8 port 6 splittable true lanes 4
pci/0000:01:00.0/59: type eth netdev enp1s0nl8p7 flavour physical lc 8 port 7 splittable true lanes 4
pci/0000:01:00.0/60: type eth netdev enp1s0nl8p8 flavour physical lc 8 port 8 splittable true lanes 4
pci/0000:01:00.0/61: type eth netdev enp1s0nl8p9 flavour physical lc 8 port 9 splittable true lanes 4
pci/0000:01:00.0/62: type eth netdev enp1s0nl8p10 flavour physical lc 8 port 10 splittable true lanes 4
pci/0000:01:00.0/63: type eth netdev enp1s0nl8p11 flavour physical lc 8 port 11 splittable true lanes 4
pci/0000:01:00.0/64: type eth netdev enp1s0nl8p12 flavour physical lc 8 port 12 splittable true lanes 4
pci/0000:01:00.0/125: type eth netdev enp1s0nl8p13 flavour physical lc 8 port 13 splittable true lanes 4
pci/0000:01:00.0/126: type eth netdev enp1s0nl8p14 flavour physical lc 8 port 14 splittable true lanes 4
pci/0000:01:00.0/127: type eth netdev enp1s0nl8p15 flavour physical lc 8 port 15 splittable true lanes 4
pci/0000:01:00.0/128: type eth netdev enp1s0nl8p16 flavour physical lc 8 port 16 splittable true lanes 4

To uprovision the slot #8:

$ devlink lc set pci/0000:01:00.0 lc 8 notype
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 843f7740 e1fad951
.. SPDX-License-Identifier: GPL-2.0
=================
Devlink Line card
=================
Background
==========
The ``devlink-linecard`` mechanism is targeted for manipulation of
line cards that serve as a detachable PHY modules for modular switch
system. Following operations are provided:
* Get a list of supported line card types.
* Provision of a slot with specific line card type.
* Get and monitor of line card state and its change.
Line card according to the type may contain one or more gearboxes
to mux the lanes with certain speed to multiple ports with lanes
of different speed. Line card ensures N:M mapping between
the switch ASIC modules and physical front panel ports.
Overview
========
Each line card devlink object is created by device driver,
according to the physical line card slots available on the device.
Similar to splitter cable, where the device might have no way
of detection of the splitter cable geometry, the device
might not have a way to detect line card type. For that devices,
concept of provisioning is introduced. It allows the user to:
* Provision a line card slot with certain line card type
- Device driver would instruct the ASIC to prepare all
resources accordingly. The device driver would
create all instances, namely devlink port and netdevices
that reside on the line card, according to the line card type
* Manipulate of line card entities even without line card
being physically connected or powered-up
* Setup splitter cable on line card ports
- As on the ordinary ports, user may provision a splitter
cable of a certain type, without the need to
be physically connected to the port
* Configure devlink ports and netdevices
Netdevice carrier is decided as follows:
* Line card is not inserted or powered-down
- The carrier is always down
* Line card is inserted and powered up
- The carrier is decided as for ordinary port netdevice
Line card state
===============
The ``devlink-linecard`` mechanism supports the following line card states:
* ``unprovisioned``: Line card is not provisioned on the slot.
* ``unprovisioning``: Line card slot is currently being unprovisioned.
* ``provisioning``: Line card slot is currently in a process of being provisioned
with a line card type.
* ``provisioning_failed``: Provisioning was not successful.
* ``provisioned``: Line card slot is provisioned with a type.
* ``active``: Line card is powered-up and active.
The following diagram provides a general overview of ``devlink-linecard``
state transitions::
+-------------------------+
| |
+----------------------------------> unprovisioned |
| | |
| +--------|-------^--------+
| | |
| | |
| +--------v-------|--------+
| | |
| | provisioning |
| | |
| +------------|------------+
| |
| +-----------------------------+
| | |
| +------------v------------+ +------------v------------+ +-------------------------+
| | | | ----> |
+----- provisioning_failed | | provisioned | | active |
| | | | <---- |
| +------------^------------+ +------------|------------+ +-------------------------+
| | |
| | |
| | +------------v------------+
| | | |
| | | unprovisioning |
| | | |
| | +------------|------------+
| | |
| +-----------------------------+
| |
+-----------------------------------------------+
Example usage
=============
.. code:: shell
$ devlink lc show [ DEV [ lc LC_INDEX ] ]
$ devlink lc set DEV lc LC_INDEX [ { type LC_TYPE | notype } ]
# Show current line card configuration and status for all slots:
$ devlink lc
# Set slot 8 to be provisioned with type "16x100G":
$ devlink lc set pci/0000:01:00.0 lc 8 type 16x100G
# Set slot 8 to be unprovisioned:
$ devlink lc set pci/0000:01:00.0 lc 8 notype
......@@ -39,6 +39,7 @@ general.
devlink-resource
devlink-reload
devlink-trap
devlink-linecard
Driver-specific documentation
-----------------------------
......
# 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
......
......@@ -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)
......@@ -82,6 +83,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;
......@@ -94,6 +96,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)
......@@ -2145,6 +2158,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;
......@@ -2183,6 +2200,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);
......@@ -2255,6 +2274,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);
......@@ -2956,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,
......@@ -2979,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));
......@@ -2996,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,
......@@ -3005,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);
......@@ -3036,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;
......@@ -3112,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;
......@@ -3124,6 +3163,15 @@ bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port)
}
EXPORT_SYMBOL(mlxsw_core_port_is_xm);
void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core,
bool (*selector)(void *priv, u16 local_port),
void *priv)
{
if (WARN_ON_ONCE(!mlxsw_core->driver->ports_remove_selected))
return;
mlxsw_core->driver->ports_remove_selected(mlxsw_core, selector, priv);
}
struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core)
{
return mlxsw_core->env;
......
......@@ -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);
......@@ -231,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);
......@@ -252,7 +258,14 @@ 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,
u16 local_port),
void *priv);
struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core);
int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
......@@ -326,6 +339,10 @@ struct mlxsw_driver {
unsigned int count, struct netlink_ext_ack *extack);
int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u16 local_port,
struct netlink_ext_ack *extack);
void (*ports_remove_selected)(struct mlxsw_core *mlxsw_core,
bool (*selector)(void *priv,
u16 local_port),
void *priv);
int (*sb_pool_get)(struct mlxsw_core *mlxsw_core,
unsigned int sb_index, u16 pool_index,
struct devlink_sb_pool_info *pool_info);
......@@ -543,4 +560,47 @@ 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,
ready:1,
active: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
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2022 NVIDIA Corporation and Mellanox Technologies. All rights reserved */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/workqueue.h>
#include <linux/gfp.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/vmalloc.h>
#include "core.h"
struct mlxsw_linecard_ini_file {
__le16 size;
union {
u8 data[0];
struct {
__be16 hw_revision;
__be16 ini_version;
u8 __dontcare[3];
u8 type;
u8 name[20];
} format;
};
};
struct mlxsw_linecard_types_info {
struct mlxsw_linecard_ini_file **ini_files;
unsigned int count;
size_t data_size;
char *data;
};
#define MLXSW_LINECARD_STATUS_EVENT_TO (10 * MSEC_PER_SEC)
static void
mlxsw_linecard_status_event_to_schedule(struct mlxsw_linecard *linecard,
enum mlxsw_linecard_status_event_type status_event_type)
{
cancel_delayed_work_sync(&linecard->status_event_to_dw);
linecard->status_event_type_to = status_event_type;
mlxsw_core_schedule_dw(&linecard->status_event_to_dw,
msecs_to_jiffies(MLXSW_LINECARD_STATUS_EVENT_TO));
}
static void
mlxsw_linecard_status_event_done(struct mlxsw_linecard *linecard,
enum mlxsw_linecard_status_event_type status_event_type)
{
if (linecard->status_event_type_to == status_event_type)
cancel_delayed_work_sync(&linecard->status_event_to_dw);
}
static const char *
mlxsw_linecard_types_lookup(struct mlxsw_linecards *linecards, u8 card_type)
{
struct mlxsw_linecard_types_info *types_info;
struct mlxsw_linecard_ini_file *ini_file;
int i;
types_info = linecards->types_info;
if (!types_info)
return NULL;
for (i = 0; i < types_info->count; i++) {
ini_file = linecards->types_info->ini_files[i];
if (ini_file->format.type == card_type)
return ini_file->format.name;
}
return NULL;
}
static const char *mlxsw_linecard_type_name(struct mlxsw_linecard *linecard)
{
struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core;
char mddq_pl[MLXSW_REG_MDDQ_LEN];
int err;
mlxsw_reg_mddq_slot_name_pack(mddq_pl, linecard->slot_index);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mddq), mddq_pl);
if (err)
return ERR_PTR(err);
mlxsw_reg_mddq_slot_name_unpack(mddq_pl, linecard->name);
return linecard->name;
}
static void mlxsw_linecard_provision_fail(struct mlxsw_linecard *linecard)
{
linecard->provisioned = false;
linecard->ready = false;
linecard->active = false;
devlink_linecard_provision_fail(linecard->devlink_linecard);
}
static int
mlxsw_linecard_provision_set(struct mlxsw_linecard *linecard, u8 card_type,
u16 hw_revision, u16 ini_version)
{
struct mlxsw_linecards *linecards = linecard->linecards;
const char *type;
type = mlxsw_linecard_types_lookup(linecards, card_type);
mlxsw_linecard_status_event_done(linecard,
MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION);
if (!type) {
/* It is possible for a line card to be provisioned before
* driver initialization. Due to a missing INI bundle file
* or an outdated one, the queried card's type might not
* be recognized by the driver. In this case, try to query
* the card's name from the device.
*/
type = mlxsw_linecard_type_name(linecard);
if (IS_ERR(type)) {
mlxsw_linecard_provision_fail(linecard);
return PTR_ERR(type);
}
}
linecard->provisioned = true;
linecard->hw_revision = hw_revision;
linecard->ini_version = ini_version;
devlink_linecard_provision_set(linecard->devlink_linecard, type);
return 0;
}
static void mlxsw_linecard_provision_clear(struct mlxsw_linecard *linecard)
{
mlxsw_linecard_status_event_done(linecard,
MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION);
linecard->provisioned = false;
devlink_linecard_provision_clear(linecard->devlink_linecard);
}
static int mlxsw_linecard_ready_set(struct mlxsw_linecard *linecard)
{
struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core;
char mddc_pl[MLXSW_REG_MDDC_LEN];
int err;
mlxsw_reg_mddc_pack(mddc_pl, linecard->slot_index, false, true);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddc), mddc_pl);
if (err)
return err;
linecard->ready = true;
return 0;
}
static int mlxsw_linecard_ready_clear(struct mlxsw_linecard *linecard)
{
struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core;
char mddc_pl[MLXSW_REG_MDDC_LEN];
int err;
mlxsw_reg_mddc_pack(mddc_pl, linecard->slot_index, false, false);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddc), mddc_pl);
if (err)
return err;
linecard->ready = false;
return 0;
}
static void mlxsw_linecard_active_set(struct mlxsw_linecard *linecard)
{
linecard->active = true;
devlink_linecard_activate(linecard->devlink_linecard);
}
static void mlxsw_linecard_active_clear(struct mlxsw_linecard *linecard)
{
linecard->active = false;
devlink_linecard_deactivate(linecard->devlink_linecard);
}
static int mlxsw_linecard_status_process(struct mlxsw_linecards *linecards,
struct mlxsw_linecard *linecard,
const char *mddq_pl)
{
enum mlxsw_reg_mddq_slot_info_ready ready;
bool provisioned, sr_valid, active;
u16 ini_version, hw_revision;
u8 slot_index, card_type;
int err = 0;
mlxsw_reg_mddq_slot_info_unpack(mddq_pl, &slot_index, &provisioned,
&sr_valid, &ready, &active,
&hw_revision, &ini_version,
&card_type);
if (linecard) {
if (WARN_ON(slot_index != linecard->slot_index))
return -EINVAL;
} else {
if (WARN_ON(slot_index > linecards->count))
return -EINVAL;
linecard = mlxsw_linecard_get(linecards, slot_index);
}
mutex_lock(&linecard->lock);
if (provisioned && linecard->provisioned != provisioned) {
err = mlxsw_linecard_provision_set(linecard, card_type,
hw_revision, ini_version);
if (err)
goto out;
}
if (ready == MLXSW_REG_MDDQ_SLOT_INFO_READY_READY && !linecard->ready) {
err = mlxsw_linecard_ready_set(linecard);
if (err)
goto out;
}
if (active && linecard->active != active)
mlxsw_linecard_active_set(linecard);
if (!active && linecard->active != active)
mlxsw_linecard_active_clear(linecard);
if (ready != MLXSW_REG_MDDQ_SLOT_INFO_READY_READY &&
linecard->ready) {
err = mlxsw_linecard_ready_clear(linecard);
if (err)
goto out;
}
if (!provisioned && linecard->provisioned != provisioned)
mlxsw_linecard_provision_clear(linecard);
out:
mutex_unlock(&linecard->lock);
return err;
}
static int mlxsw_linecard_status_get_and_process(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards,
struct mlxsw_linecard *linecard)
{
char mddq_pl[MLXSW_REG_MDDQ_LEN];
int err;
mlxsw_reg_mddq_slot_info_pack(mddq_pl, linecard->slot_index, false);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mddq), mddq_pl);
if (err)
return err;
return mlxsw_linecard_status_process(linecards, linecard, mddq_pl);
}
static const char * const mlxsw_linecard_status_event_type_name[] = {
[MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION] = "provision",
[MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION] = "unprovision",
};
static void mlxsw_linecard_status_event_to_work(struct work_struct *work)
{
struct mlxsw_linecard *linecard =
container_of(work, struct mlxsw_linecard,
status_event_to_dw.work);
mutex_lock(&linecard->lock);
dev_err(linecard->linecards->bus_info->dev, "linecard %u: Timeout reached waiting on %s status event",
linecard->slot_index,
mlxsw_linecard_status_event_type_name[linecard->status_event_type_to]);
mlxsw_linecard_provision_fail(linecard);
mutex_unlock(&linecard->lock);
}
static int __mlxsw_linecard_fix_fsm_state(struct mlxsw_linecard *linecard)
{
dev_info(linecard->linecards->bus_info->dev, "linecard %u: Clearing FSM state error",
linecard->slot_index);
mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index,
MLXSW_REG_MBCT_OP_CLEAR_ERRORS, false);
return mlxsw_reg_write(linecard->linecards->mlxsw_core,
MLXSW_REG(mbct), linecard->mbct_pl);
}
static int mlxsw_linecard_fix_fsm_state(struct mlxsw_linecard *linecard,
enum mlxsw_reg_mbct_fsm_state fsm_state)
{
if (fsm_state != MLXSW_REG_MBCT_FSM_STATE_ERROR)
return 0;
return __mlxsw_linecard_fix_fsm_state(linecard);
}
static int
mlxsw_linecard_query_ini_status(struct mlxsw_linecard *linecard,
enum mlxsw_reg_mbct_status *status,
enum mlxsw_reg_mbct_fsm_state *fsm_state,
struct netlink_ext_ack *extack)
{
int err;
mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index,
MLXSW_REG_MBCT_OP_QUERY_STATUS, false);
err = mlxsw_reg_query(linecard->linecards->mlxsw_core, MLXSW_REG(mbct),
linecard->mbct_pl);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to query linecard INI status");
return err;
}
mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, status, fsm_state);
return err;
}
static int
mlxsw_linecard_ini_transfer(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecard *linecard,
const struct mlxsw_linecard_ini_file *ini_file,
struct netlink_ext_ack *extack)
{
enum mlxsw_reg_mbct_fsm_state fsm_state;
enum mlxsw_reg_mbct_status status;
size_t size_left;
const u8 *data;
int err;
size_left = le16_to_cpu(ini_file->size);
data = ini_file->data;
while (size_left) {
size_t data_size = MLXSW_REG_MBCT_DATA_LEN;
bool is_last = false;
if (size_left <= MLXSW_REG_MBCT_DATA_LEN) {
data_size = size_left;
is_last = true;
}
mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index,
MLXSW_REG_MBCT_OP_DATA_TRANSFER, false);
mlxsw_reg_mbct_dt_pack(linecard->mbct_pl, data_size,
is_last, data);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct),
linecard->mbct_pl);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI data transfer");
return err;
}
mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL,
&status, &fsm_state);
if ((!is_last && status != MLXSW_REG_MBCT_STATUS_PART_DATA) ||
(is_last && status != MLXSW_REG_MBCT_STATUS_LAST_DATA)) {
NL_SET_ERR_MSG_MOD(extack, "Failed to transfer linecard INI data");
mlxsw_linecard_fix_fsm_state(linecard, fsm_state);
return -EINVAL;
}
size_left -= data_size;
data += data_size;
}
return 0;
}
static int
mlxsw_linecard_ini_erase(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecard *linecard,
struct netlink_ext_ack *extack)
{
enum mlxsw_reg_mbct_fsm_state fsm_state;
enum mlxsw_reg_mbct_status status;
int err;
mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index,
MLXSW_REG_MBCT_OP_ERASE_INI_IMAGE, false);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct),
linecard->mbct_pl);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI erase");
return err;
}
mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, &status, &fsm_state);
switch (status) {
case MLXSW_REG_MBCT_STATUS_ERASE_COMPLETE:
break;
default:
/* Should not happen */
fallthrough;
case MLXSW_REG_MBCT_STATUS_ERASE_FAILED:
NL_SET_ERR_MSG_MOD(extack, "Failed to erase linecard INI");
goto fix_fsm_err_out;
case MLXSW_REG_MBCT_STATUS_ERROR_INI_IN_USE:
NL_SET_ERR_MSG_MOD(extack, "Failed to erase linecard INI while being used");
goto fix_fsm_err_out;
}
return 0;
fix_fsm_err_out:
mlxsw_linecard_fix_fsm_state(linecard, fsm_state);
return -EINVAL;
}
static void mlxsw_linecard_bct_process(struct mlxsw_core *mlxsw_core,
const char *mbct_pl)
{
struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core);
enum mlxsw_reg_mbct_fsm_state fsm_state;
enum mlxsw_reg_mbct_status status;
struct mlxsw_linecard *linecard;
u8 slot_index;
mlxsw_reg_mbct_unpack(mbct_pl, &slot_index, &status, &fsm_state);
if (WARN_ON(slot_index > linecards->count))
return;
linecard = mlxsw_linecard_get(linecards, slot_index);
mutex_lock(&linecard->lock);
if (status == MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED) {
dev_err(linecards->bus_info->dev, "linecard %u: Failed to activate INI",
linecard->slot_index);
goto fix_fsm_out;
}
mutex_unlock(&linecard->lock);
return;
fix_fsm_out:
mlxsw_linecard_fix_fsm_state(linecard, fsm_state);
mlxsw_linecard_provision_fail(linecard);
mutex_unlock(&linecard->lock);
}
static int
mlxsw_linecard_ini_activate(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecard *linecard,
struct netlink_ext_ack *extack)
{
enum mlxsw_reg_mbct_fsm_state fsm_state;
enum mlxsw_reg_mbct_status status;
int err;
mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index,
MLXSW_REG_MBCT_OP_ACTIVATE, true);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct), linecard->mbct_pl);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI activation");
return err;
}
mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, &status, &fsm_state);
if (status == MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED) {
NL_SET_ERR_MSG_MOD(extack, "Failed to activate linecard INI");
goto fix_fsm_err_out;
}
return 0;
fix_fsm_err_out:
mlxsw_linecard_fix_fsm_state(linecard, fsm_state);
return -EINVAL;
}
#define MLXSW_LINECARD_INI_WAIT_RETRIES 10
#define MLXSW_LINECARD_INI_WAIT_MS 500
static int
mlxsw_linecard_ini_in_use_wait(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecard *linecard,
struct netlink_ext_ack *extack)
{
enum mlxsw_reg_mbct_fsm_state fsm_state;
enum mlxsw_reg_mbct_status status;
unsigned int ini_wait_retries = 0;
int err;
query_ini_status:
err = mlxsw_linecard_query_ini_status(linecard, &status,
&fsm_state, extack);
if (err)
return err;
switch (fsm_state) {
case MLXSW_REG_MBCT_FSM_STATE_INI_IN_USE:
if (ini_wait_retries++ > MLXSW_LINECARD_INI_WAIT_RETRIES) {
NL_SET_ERR_MSG_MOD(extack, "Failed to wait for linecard INI to be unused");
return -EINVAL;
}
mdelay(MLXSW_LINECARD_INI_WAIT_MS);
goto query_ini_status;
default:
break;
}
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,
struct netlink_ext_ack *extack)
{
const struct mlxsw_linecard_ini_file *ini_file = type_priv;
struct mlxsw_linecard *linecard = priv;
struct mlxsw_core *mlxsw_core;
int err;
mutex_lock(&linecard->lock);
mlxsw_core = linecard->linecards->mlxsw_core;
err = mlxsw_linecard_ini_erase(mlxsw_core, linecard, extack);
if (err)
goto err_out;
err = mlxsw_linecard_ini_transfer(mlxsw_core, linecard,
ini_file, extack);
if (err)
goto err_out;
mlxsw_linecard_status_event_to_schedule(linecard,
MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION);
err = mlxsw_linecard_ini_activate(mlxsw_core, linecard, extack);
if (err)
goto err_out;
goto out;
err_out:
mlxsw_linecard_provision_fail(linecard);
out:
mutex_unlock(&linecard->lock);
return err;
}
static int mlxsw_linecard_unprovision(struct devlink_linecard *devlink_linecard,
void *priv,
struct netlink_ext_ack *extack)
{
struct mlxsw_linecard *linecard = priv;
struct mlxsw_core *mlxsw_core;
int err;
mutex_lock(&linecard->lock);
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;
mlxsw_linecard_status_event_to_schedule(linecard,
MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION);
err = mlxsw_linecard_ini_erase(mlxsw_core, linecard, extack);
if (err)
goto err_out;
goto out;
err_out:
mlxsw_linecard_provision_fail(linecard);
out:
mutex_unlock(&linecard->lock);
return err;
}
static bool mlxsw_linecard_same_provision(struct devlink_linecard *devlink_linecard,
void *priv, const char *type,
const void *type_priv)
{
const struct mlxsw_linecard_ini_file *ini_file = type_priv;
struct mlxsw_linecard *linecard = priv;
bool ret;
mutex_lock(&linecard->lock);
ret = linecard->hw_revision == be16_to_cpu(ini_file->format.hw_revision) &&
linecard->ini_version == be16_to_cpu(ini_file->format.ini_version);
mutex_unlock(&linecard->lock);
return ret;
}
static unsigned int
mlxsw_linecard_types_count(struct devlink_linecard *devlink_linecard,
void *priv)
{
struct mlxsw_linecard *linecard = priv;
return linecard->linecards->types_info ?
linecard->linecards->types_info->count : 0;
}
static void mlxsw_linecard_types_get(struct devlink_linecard *devlink_linecard,
void *priv, unsigned int index,
const char **type, const void **type_priv)
{
struct mlxsw_linecard_types_info *types_info;
struct mlxsw_linecard_ini_file *ini_file;
struct mlxsw_linecard *linecard = priv;
types_info = linecard->linecards->types_info;
if (WARN_ON_ONCE(!types_info))
return;
ini_file = types_info->ini_files[index];
*type = ini_file->format.name;
*type_priv = ini_file;
}
static const struct devlink_linecard_ops mlxsw_linecard_ops = {
.provision = mlxsw_linecard_provision,
.unprovision = mlxsw_linecard_unprovision,
.same_provision = mlxsw_linecard_same_provision,
.types_count = mlxsw_linecard_types_count,
.types_get = mlxsw_linecard_types_get,
};
struct mlxsw_linecard_status_event {
struct mlxsw_core *mlxsw_core;
char mddq_pl[MLXSW_REG_MDDQ_LEN];
struct work_struct work;
};
static void mlxsw_linecard_status_event_work(struct work_struct *work)
{
struct mlxsw_linecard_status_event *event;
struct mlxsw_linecards *linecards;
struct mlxsw_core *mlxsw_core;
event = container_of(work, struct mlxsw_linecard_status_event, work);
mlxsw_core = event->mlxsw_core;
linecards = mlxsw_core_linecards(mlxsw_core);
mlxsw_linecard_status_process(linecards, NULL, event->mddq_pl);
kfree(event);
}
static void
mlxsw_linecard_status_listener_func(const struct mlxsw_reg_info *reg,
char *mddq_pl, void *priv)
{
struct mlxsw_linecard_status_event *event;
struct mlxsw_core *mlxsw_core = priv;
event = kmalloc(sizeof(*event), GFP_ATOMIC);
if (!event)
return;
event->mlxsw_core = mlxsw_core;
memcpy(event->mddq_pl, mddq_pl, sizeof(event->mddq_pl));
INIT_WORK(&event->work, mlxsw_linecard_status_event_work);
mlxsw_core_schedule_work(&event->work);
}
struct mlxsw_linecard_bct_event {
struct mlxsw_core *mlxsw_core;
char mbct_pl[MLXSW_REG_MBCT_LEN];
struct work_struct work;
};
static void mlxsw_linecard_bct_event_work(struct work_struct *work)
{
struct mlxsw_linecard_bct_event *event;
struct mlxsw_core *mlxsw_core;
event = container_of(work, struct mlxsw_linecard_bct_event, work);
mlxsw_core = event->mlxsw_core;
mlxsw_linecard_bct_process(mlxsw_core, event->mbct_pl);
kfree(event);
}
static void
mlxsw_linecard_bct_listener_func(const struct mlxsw_reg_info *reg,
char *mbct_pl, void *priv)
{
struct mlxsw_linecard_bct_event *event;
struct mlxsw_core *mlxsw_core = priv;
event = kmalloc(sizeof(*event), GFP_ATOMIC);
if (!event)
return;
event->mlxsw_core = mlxsw_core;
memcpy(event->mbct_pl, mbct_pl, sizeof(event->mbct_pl));
INIT_WORK(&event->work, mlxsw_linecard_bct_event_work);
mlxsw_core_schedule_work(&event->work);
}
static const struct mlxsw_listener mlxsw_linecard_listener[] = {
MLXSW_CORE_EVENTL(mlxsw_linecard_status_listener_func, DSDSC),
MLXSW_CORE_EVENTL(mlxsw_linecard_bct_listener_func, BCTOE),
};
static int mlxsw_linecard_event_delivery_set(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecard *linecard,
bool enable)
{
char mddq_pl[MLXSW_REG_MDDQ_LEN];
mlxsw_reg_mddq_slot_info_pack(mddq_pl, linecard->slot_index, enable);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddq), mddq_pl);
}
static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards,
u8 slot_index)
{
struct devlink_linecard *devlink_linecard;
struct mlxsw_linecard *linecard;
int err;
linecard = mlxsw_linecard_get(linecards, slot_index);
linecard->slot_index = slot_index;
linecard->linecards = linecards;
mutex_init(&linecard->lock);
devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core),
slot_index, &mlxsw_linecard_ops,
linecard);
if (IS_ERR(devlink_linecard)) {
err = PTR_ERR(devlink_linecard);
goto err_devlink_linecard_create;
}
linecard->devlink_linecard = devlink_linecard;
INIT_DELAYED_WORK(&linecard->status_event_to_dw,
&mlxsw_linecard_status_event_to_work);
err = mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, true);
if (err)
goto err_event_delivery_set;
err = mlxsw_linecard_status_get_and_process(mlxsw_core, linecards,
linecard);
if (err)
goto err_status_get_and_process;
return 0;
err_status_get_and_process:
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
err_event_delivery_set:
devlink_linecard_destroy(linecard->devlink_linecard);
err_devlink_linecard_create:
mutex_destroy(&linecard->lock);
return err;
}
static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards,
u8 slot_index)
{
struct mlxsw_linecard *linecard;
linecard = mlxsw_linecard_get(linecards, slot_index);
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
cancel_delayed_work_sync(&linecard->status_event_to_dw);
/* Make sure all scheduled events are processed */
mlxsw_core_flush_owq();
if (linecard->active)
mlxsw_linecard_active_clear(linecard);
devlink_linecard_destroy(linecard->devlink_linecard);
mutex_destroy(&linecard->lock);
}
/* LINECARDS INI BUNDLE FILE
* +----------------------------------+
* | MAGIC ("NVLCINI+") |
* +----------------------------------+ +--------------------+
* | INI 0 +---> | __le16 size |
* +----------------------------------+ | __be16 hw_revision |
* | INI 1 | | __be16 ini_version |
* +----------------------------------+ | u8 __dontcare[3] |
* | ... | | u8 type |
* +----------------------------------+ | u8 name[20] |
* | INI N | | ... |
* +----------------------------------+ +--------------------+
*/
#define MLXSW_LINECARDS_INI_BUNDLE_MAGIC "NVLCINI+"
static int
mlxsw_linecard_types_file_validate(struct mlxsw_linecards *linecards,
struct mlxsw_linecard_types_info *types_info)
{
size_t magic_size = strlen(MLXSW_LINECARDS_INI_BUNDLE_MAGIC);
struct mlxsw_linecard_ini_file *ini_file;
size_t size = types_info->data_size;
const u8 *data = types_info->data;
unsigned int count = 0;
u16 ini_file_size;
if (size < magic_size) {
dev_warn(linecards->bus_info->dev, "Invalid linecards INIs file size, smaller than magic size\n");
return -EINVAL;
}
if (memcmp(data, MLXSW_LINECARDS_INI_BUNDLE_MAGIC, magic_size)) {
dev_warn(linecards->bus_info->dev, "Invalid linecards INIs file magic pattern\n");
return -EINVAL;
}
data += magic_size;
size -= magic_size;
while (size > 0) {
if (size < sizeof(*ini_file)) {
dev_warn(linecards->bus_info->dev, "Linecards INIs file contains INI which is smaller than bare minimum\n");
return -EINVAL;
}
ini_file = (struct mlxsw_linecard_ini_file *) data;
ini_file_size = le16_to_cpu(ini_file->size);
if (ini_file_size + sizeof(__le16) > size) {
dev_warn(linecards->bus_info->dev, "Linecards INIs file appears to be truncated\n");
return -EINVAL;
}
if (ini_file_size % 4) {
dev_warn(linecards->bus_info->dev, "Linecards INIs file contains INI with invalid size\n");
return -EINVAL;
}
data += ini_file_size + sizeof(__le16);
size -= ini_file_size + sizeof(__le16);
count++;
}
if (!count) {
dev_warn(linecards->bus_info->dev, "Linecards INIs file does not contain any INI\n");
return -EINVAL;
}
types_info->count = count;
return 0;
}
static void
mlxsw_linecard_types_file_parse(struct mlxsw_linecard_types_info *types_info)
{
size_t magic_size = strlen(MLXSW_LINECARDS_INI_BUNDLE_MAGIC);
size_t size = types_info->data_size - magic_size;
const u8 *data = types_info->data + magic_size;
struct mlxsw_linecard_ini_file *ini_file;
unsigned int count = 0;
u16 ini_file_size;
int i;
while (size) {
ini_file = (struct mlxsw_linecard_ini_file *) data;
ini_file_size = le16_to_cpu(ini_file->size);
for (i = 0; i < ini_file_size / 4; i++) {
u32 *val = &((u32 *) ini_file->data)[i];
*val = swab32(*val);
}
types_info->ini_files[count] = ini_file;
data += ini_file_size + sizeof(__le16);
size -= ini_file_size + sizeof(__le16);
count++;
}
}
#define MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT \
"mellanox/lc_ini_bundle_%u_%u.bin"
#define MLXSW_LINECARDS_INI_BUNDLE_FILENAME_LEN \
(sizeof(MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT) + 4)
static int mlxsw_linecard_types_init(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards)
{
const struct mlxsw_fw_rev *rev = &linecards->bus_info->fw_rev;
char filename[MLXSW_LINECARDS_INI_BUNDLE_FILENAME_LEN];
struct mlxsw_linecard_types_info *types_info;
const struct firmware *firmware;
int err;
err = snprintf(filename, sizeof(filename),
MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT,
rev->minor, rev->subminor);
WARN_ON(err >= sizeof(filename));
err = request_firmware_direct(&firmware, filename,
linecards->bus_info->dev);
if (err) {
dev_warn(linecards->bus_info->dev, "Could not request linecards INI file \"%s\", provisioning will not be possible\n",
filename);
return 0;
}
types_info = kzalloc(sizeof(*types_info), GFP_KERNEL);
if (!types_info) {
release_firmware(firmware);
return -ENOMEM;
}
linecards->types_info = types_info;
types_info->data_size = firmware->size;
types_info->data = vmalloc(types_info->data_size);
if (!types_info->data) {
err = -ENOMEM;
release_firmware(firmware);
goto err_data_alloc;
}
memcpy(types_info->data, firmware->data, types_info->data_size);
release_firmware(firmware);
err = mlxsw_linecard_types_file_validate(linecards, types_info);
if (err) {
err = 0;
goto err_type_file_file_validate;
}
types_info->ini_files = kmalloc_array(types_info->count,
sizeof(struct mlxsw_linecard_ini_file),
GFP_KERNEL);
if (!types_info->ini_files) {
err = -ENOMEM;
goto err_ini_files_alloc;
}
mlxsw_linecard_types_file_parse(types_info);
return 0;
err_ini_files_alloc:
err_type_file_file_validate:
vfree(types_info->data);
err_data_alloc:
kfree(types_info);
return err;
}
static void mlxsw_linecard_types_fini(struct mlxsw_linecards *linecards)
{
struct mlxsw_linecard_types_info *types_info = linecards->types_info;
if (!types_info)
return;
kfree(types_info->ini_files);
vfree(types_info->data);
kfree(types_info);
}
int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *bus_info)
{
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
struct mlxsw_linecards *linecards;
u8 slot_count;
int err;
int i;
mlxsw_reg_mgpir_pack(mgpir_pl, 0);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL,
NULL, &slot_count);
if (!slot_count)
return 0;
linecards = vzalloc(struct_size(linecards, linecards, slot_count));
if (!linecards)
return -ENOMEM;
linecards->count = slot_count;
linecards->mlxsw_core = mlxsw_core;
linecards->bus_info = bus_info;
err = mlxsw_linecard_types_init(mlxsw_core, linecards);
if (err)
goto err_types_init;
err = mlxsw_core_traps_register(mlxsw_core, mlxsw_linecard_listener,
ARRAY_SIZE(mlxsw_linecard_listener),
mlxsw_core);
if (err)
goto err_traps_register;
mlxsw_core_linecards_set(mlxsw_core, linecards);
for (i = 0; i < linecards->count; i++) {
err = mlxsw_linecard_init(mlxsw_core, linecards, i + 1);
if (err)
goto err_linecard_init;
}
return 0;
err_linecard_init:
for (i--; i >= 0; i--)
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
ARRAY_SIZE(mlxsw_linecard_listener),
mlxsw_core);
err_traps_register:
mlxsw_linecard_types_fini(linecards);
err_types_init:
vfree(linecards);
return err;
}
void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core);
int i;
if (!linecards)
return;
for (i = 0; i < linecards->count; i++)
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
ARRAY_SIZE(mlxsw_linecard_listener),
mlxsw_core);
mlxsw_linecard_types_fini(linecards);
vfree(linecards);
}
......@@ -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));
......@@ -328,6 +328,7 @@ static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module)
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
{
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
struct devlink *devlink = priv_to_devlink(mlxsw_m->core);
u8 last_module = max_ports;
int i;
int err;
......@@ -356,6 +357,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
}
/* Create port objects for each valid entry */
devl_lock(devlink);
for (i = 0; i < mlxsw_m->max_ports; i++) {
if (mlxsw_m->module_to_port[i] > 0 &&
!mlxsw_core_port_is_xm(mlxsw_m->core, i)) {
......@@ -366,6 +368,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
goto err_module_to_port_create;
}
}
devl_unlock(devlink);
return 0;
......@@ -375,6 +378,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
mlxsw_m_port_remove(mlxsw_m,
mlxsw_m->module_to_port[i]);
}
devl_unlock(devlink);
i = max_ports;
err_module_to_port_map:
for (i--; i > 0; i--)
......@@ -387,8 +391,10 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
{
struct devlink *devlink = priv_to_devlink(mlxsw_m->core);
int i;
devl_lock(devlink);
for (i = 0; i < mlxsw_m->max_ports; i++) {
if (mlxsw_m->module_to_port[i] > 0) {
mlxsw_m_port_remove(mlxsw_m,
......@@ -396,6 +402,7 @@ static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
mlxsw_m_port_module_unmap(mlxsw_m, i);
}
}
devl_unlock(devlink);
kfree(mlxsw_m->module_to_port);
kfree(mlxsw_m->ports);
......@@ -424,7 +431,6 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
struct netlink_ext_ack *extack)
{
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
int err;
mlxsw_m->core = mlxsw_core;
......@@ -440,9 +446,7 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
return err;
}
devl_lock(devlink);
err = mlxsw_m_ports_create(mlxsw_m);
devl_unlock(devlink);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n");
return err;
......@@ -454,11 +458,8 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
devl_lock(devlink);
mlxsw_m_ports_remove(mlxsw_m);
devl_unlock(devlink);
}
static const struct mlxsw_config_profile mlxsw_m_config_profile;
......
......@@ -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
......@@ -5875,6 +5884,69 @@ static inline void mlxsw_reg_pmtdb_pack(char *payload, u8 slot_index, u8 module,
mlxsw_reg_pmtdb_num_ports_set(payload, num_ports);
}
/* PMECR - Ports Mapping Event Configuration Register
* --------------------------------------------------
* The PMECR register is used to enable/disable event triggering
* in case of local port mapping change.
*/
#define MLXSW_REG_PMECR_ID 0x501B
#define MLXSW_REG_PMECR_LEN 0x20
MLXSW_REG_DEFINE(pmecr, MLXSW_REG_PMECR_ID, MLXSW_REG_PMECR_LEN);
/* reg_pmecr_local_port
* Local port number.
* Access: Index
*/
MLXSW_ITEM32_LP(reg, pmecr, 0x00, 16, 0x00, 12);
/* reg_pmecr_ee
* Event update enable. If this bit is set, event generation will be updated
* based on the e field. Only relevant on Set operations.
* Access: WO
*/
MLXSW_ITEM32(reg, pmecr, ee, 0x04, 30, 1);
/* reg_pmecr_eswi
* Software ignore enable bit. If this bit is set, the value of swi is used.
* If this bit is clear, the value of swi is ignored.
* Only relevant on Set operations.
* Access: WO
*/
MLXSW_ITEM32(reg, pmecr, eswi, 0x04, 24, 1);
/* reg_pmecr_swi
* Software ignore. If this bit is set, the device shouldn't generate events
* in case of PMLP SET operation but only upon self local port mapping change
* (if applicable according to e configuration). This is supplementary
* configuration on top of e value.
* Access: RW
*/
MLXSW_ITEM32(reg, pmecr, swi, 0x04, 8, 1);
enum mlxsw_reg_pmecr_e {
MLXSW_REG_PMECR_E_DO_NOT_GENERATE_EVENT,
MLXSW_REG_PMECR_E_GENERATE_EVENT,
MLXSW_REG_PMECR_E_GENERATE_SINGLE_EVENT,
};
/* reg_pmecr_e
* Event generation on local port mapping change.
* Access: RW
*/
MLXSW_ITEM32(reg, pmecr, e, 0x04, 0, 2);
static inline void mlxsw_reg_pmecr_pack(char *payload, u16 local_port,
enum mlxsw_reg_pmecr_e e)
{
MLXSW_REG_ZERO(pmecr, payload);
mlxsw_reg_pmecr_local_port_set(payload, local_port);
mlxsw_reg_pmecr_e_set(payload, e);
mlxsw_reg_pmecr_ee_set(payload, true);
mlxsw_reg_pmecr_swi_set(payload, true);
mlxsw_reg_pmecr_eswi_set(payload, true);
}
/* PMPE - Port Module Plug/Unplug Event Register
* ---------------------------------------------
* This register reports any operational status change of a module.
......@@ -11429,6 +11501,306 @@ mlxsw_reg_mgpir_unpack(char *payload, u8 *num_of_devices,
*num_of_slots = mlxsw_reg_mgpir_num_of_slots_get(payload);
}
/* MBCT - Management Binary Code Transfer Register
* -----------------------------------------------
* This register allows to transfer binary codes from the host to
* the management FW by transferring it by chunks of maximum 1KB.
*/
#define MLXSW_REG_MBCT_ID 0x9120
#define MLXSW_REG_MBCT_LEN 0x420
MLXSW_REG_DEFINE(mbct, MLXSW_REG_MBCT_ID, MLXSW_REG_MBCT_LEN);
/* reg_mbct_slot_index
* Slot index. 0 is reserved.
* Access: Index
*/
MLXSW_ITEM32(reg, mbct, slot_index, 0x00, 0, 4);
/* reg_mbct_data_size
* Actual data field size in bytes for the current data transfer.
* Access: WO
*/
MLXSW_ITEM32(reg, mbct, data_size, 0x04, 0, 11);
enum mlxsw_reg_mbct_op {
MLXSW_REG_MBCT_OP_ERASE_INI_IMAGE = 1,
MLXSW_REG_MBCT_OP_DATA_TRANSFER, /* Download */
MLXSW_REG_MBCT_OP_ACTIVATE,
MLXSW_REG_MBCT_OP_CLEAR_ERRORS = 6,
MLXSW_REG_MBCT_OP_QUERY_STATUS,
};
/* reg_mbct_op
* Access: WO
*/
MLXSW_ITEM32(reg, mbct, op, 0x08, 28, 4);
/* reg_mbct_last
* Indicates that the current data field is the last chunk of the INI.
* Access: WO
*/
MLXSW_ITEM32(reg, mbct, last, 0x08, 26, 1);
/* reg_mbct_oee
* Opcode Event Enable. When set a BCTOE event will be sent once the opcode
* was executed and the fsm_state has changed.
* Access: WO
*/
MLXSW_ITEM32(reg, mbct, oee, 0x08, 25, 1);
enum mlxsw_reg_mbct_status {
/* Partial data transfer completed successfully and ready for next
* data transfer.
*/
MLXSW_REG_MBCT_STATUS_PART_DATA = 2,
MLXSW_REG_MBCT_STATUS_LAST_DATA,
MLXSW_REG_MBCT_STATUS_ERASE_COMPLETE,
/* Error - trying to erase INI while it being used. */
MLXSW_REG_MBCT_STATUS_ERROR_INI_IN_USE,
/* Last data transfer completed, applying magic pattern. */
MLXSW_REG_MBCT_STATUS_ERASE_FAILED = 7,
MLXSW_REG_MBCT_STATUS_INI_ERROR,
MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED,
MLXSW_REG_MBCT_STATUS_ILLEGAL_OPERATION = 11,
};
/* reg_mbct_status
* Status.
* Access: RO
*/
MLXSW_ITEM32(reg, mbct, status, 0x0C, 24, 5);
enum mlxsw_reg_mbct_fsm_state {
MLXSW_REG_MBCT_FSM_STATE_INI_IN_USE = 5,
MLXSW_REG_MBCT_FSM_STATE_ERROR,
};
/* reg_mbct_fsm_state
* FSM state.
* Access: RO
*/
MLXSW_ITEM32(reg, mbct, fsm_state, 0x0C, 16, 4);
#define MLXSW_REG_MBCT_DATA_LEN 1024
/* reg_mbct_data
* Up to 1KB of data.
* Access: WO
*/
MLXSW_ITEM_BUF(reg, mbct, data, 0x20, MLXSW_REG_MBCT_DATA_LEN);
static inline void mlxsw_reg_mbct_pack(char *payload, u8 slot_index,
enum mlxsw_reg_mbct_op op, bool oee)
{
MLXSW_REG_ZERO(mbct, payload);
mlxsw_reg_mbct_slot_index_set(payload, slot_index);
mlxsw_reg_mbct_op_set(payload, op);
mlxsw_reg_mbct_oee_set(payload, oee);
}
static inline void mlxsw_reg_mbct_dt_pack(char *payload,
u16 data_size, bool last,
const char *data)
{
if (WARN_ON(data_size > MLXSW_REG_MBCT_DATA_LEN))
return;
mlxsw_reg_mbct_data_size_set(payload, data_size);
mlxsw_reg_mbct_last_set(payload, last);
mlxsw_reg_mbct_data_memcpy_to(payload, data);
}
static inline void
mlxsw_reg_mbct_unpack(const char *payload, u8 *p_slot_index,
enum mlxsw_reg_mbct_status *p_status,
enum mlxsw_reg_mbct_fsm_state *p_fsm_state)
{
if (p_slot_index)
*p_slot_index = mlxsw_reg_mbct_slot_index_get(payload);
*p_status = mlxsw_reg_mbct_status_get(payload);
if (p_fsm_state)
*p_fsm_state = mlxsw_reg_mbct_fsm_state_get(payload);
}
/* MDDQ - Management DownStream Device Query Register
* --------------------------------------------------
* This register allows to query the DownStream device properties. The desired
* information is chosen upon the query_type field and is delivered by 32B
* of data blocks.
*/
#define MLXSW_REG_MDDQ_ID 0x9161
#define MLXSW_REG_MDDQ_LEN 0x30
MLXSW_REG_DEFINE(mddq, MLXSW_REG_MDDQ_ID, MLXSW_REG_MDDQ_LEN);
/* reg_mddq_sie
* Slot info event enable.
* When set to '1', each change in the slot_info.provisioned / sr_valid /
* active / ready will generate a DSDSC event.
* Access: RW
*/
MLXSW_ITEM32(reg, mddq, sie, 0x00, 31, 1);
enum mlxsw_reg_mddq_query_type {
MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO = 1,
MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME = 3,
};
/* reg_mddq_query_type
* Access: Index
*/
MLXSW_ITEM32(reg, mddq, query_type, 0x00, 16, 8);
/* reg_mddq_slot_index
* Slot index. 0 is reserved.
* Access: Index
*/
MLXSW_ITEM32(reg, mddq, slot_index, 0x00, 0, 4);
/* reg_mddq_slot_info_provisioned
* If set, the INI file is applied and the card is provisioned.
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_provisioned, 0x10, 31, 1);
/* reg_mddq_slot_info_sr_valid
* If set, Shift Register is valid (after being provisioned) and data
* can be sent from the switch ASIC to the line-card CPLD over Shift-Register.
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_sr_valid, 0x10, 30, 1);
enum mlxsw_reg_mddq_slot_info_ready {
MLXSW_REG_MDDQ_SLOT_INFO_READY_NOT_READY,
MLXSW_REG_MDDQ_SLOT_INFO_READY_READY,
MLXSW_REG_MDDQ_SLOT_INFO_READY_ERROR,
};
/* reg_mddq_slot_info_lc_ready
* If set, the LC is powered on, matching the INI version and a new FW
* version can be burnt (if necessary).
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_lc_ready, 0x10, 28, 2);
/* reg_mddq_slot_info_active
* If set, the FW has completed the MDDC.device_enable command.
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_active, 0x10, 27, 1);
/* reg_mddq_slot_info_hw_revision
* Major user-configured version number of the current INI file.
* Valid only when active or ready are '1'.
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_hw_revision, 0x14, 16, 16);
/* reg_mddq_slot_info_ini_file_version
* User-configured version number of the current INI file.
* Valid only when active or lc_ready are '1'.
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_ini_file_version, 0x14, 0, 16);
/* reg_mddq_slot_info_card_type
* Access: RO
*/
MLXSW_ITEM32(reg, mddq, slot_info_card_type, 0x18, 0, 8);
static inline void
__mlxsw_reg_mddq_pack(char *payload, u8 slot_index,
enum mlxsw_reg_mddq_query_type query_type)
{
MLXSW_REG_ZERO(mddq, payload);
mlxsw_reg_mddq_slot_index_set(payload, slot_index);
mlxsw_reg_mddq_query_type_set(payload, query_type);
}
static inline void
mlxsw_reg_mddq_slot_info_pack(char *payload, u8 slot_index, bool sie)
{
__mlxsw_reg_mddq_pack(payload, slot_index,
MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO);
mlxsw_reg_mddq_sie_set(payload, sie);
}
static inline void
mlxsw_reg_mddq_slot_info_unpack(const char *payload, u8 *p_slot_index,
bool *p_provisioned, bool *p_sr_valid,
enum mlxsw_reg_mddq_slot_info_ready *p_lc_ready,
bool *p_active, u16 *p_hw_revision,
u16 *p_ini_file_version,
u8 *p_card_type)
{
*p_slot_index = mlxsw_reg_mddq_slot_index_get(payload);
*p_provisioned = mlxsw_reg_mddq_slot_info_provisioned_get(payload);
*p_sr_valid = mlxsw_reg_mddq_slot_info_sr_valid_get(payload);
*p_lc_ready = mlxsw_reg_mddq_slot_info_lc_ready_get(payload);
*p_active = mlxsw_reg_mddq_slot_info_active_get(payload);
*p_hw_revision = mlxsw_reg_mddq_slot_info_hw_revision_get(payload);
*p_ini_file_version = mlxsw_reg_mddq_slot_info_ini_file_version_get(payload);
*p_card_type = mlxsw_reg_mddq_slot_info_card_type_get(payload);
}
#define MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN 20
/* reg_mddq_slot_ascii_name
* Slot's ASCII name.
* Access: RO
*/
MLXSW_ITEM_BUF(reg, mddq, slot_ascii_name, 0x10,
MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN);
static inline void
mlxsw_reg_mddq_slot_name_pack(char *payload, u8 slot_index)
{
__mlxsw_reg_mddq_pack(payload, slot_index,
MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME);
}
static inline void
mlxsw_reg_mddq_slot_name_unpack(const char *payload, char *slot_ascii_name)
{
mlxsw_reg_mddq_slot_ascii_name_memcpy_from(payload, slot_ascii_name);
}
/* MDDC - Management DownStream Device Control Register
* ----------------------------------------------------
* This register allows to control downstream devices and line cards.
*/
#define MLXSW_REG_MDDC_ID 0x9163
#define MLXSW_REG_MDDC_LEN 0x30
MLXSW_REG_DEFINE(mddc, MLXSW_REG_MDDC_ID, MLXSW_REG_MDDC_LEN);
/* reg_mddc_slot_index
* Slot index. 0 is reserved.
* Access: Index
*/
MLXSW_ITEM32(reg, mddc, slot_index, 0x00, 0, 4);
/* reg_mddc_rst
* Reset request.
* Access: OP
*/
MLXSW_ITEM32(reg, mddc, rst, 0x04, 29, 1);
/* reg_mddc_device_enable
* When set, FW is the manager and allowed to program the downstream device.
* Access: RW
*/
MLXSW_ITEM32(reg, mddc, device_enable, 0x04, 28, 1);
static inline void mlxsw_reg_mddc_pack(char *payload, u8 slot_index, bool rst,
bool device_enable)
{
MLXSW_REG_ZERO(mddc, payload);
mlxsw_reg_mddc_slot_index_set(payload, slot_index);
mlxsw_reg_mddc_rst_set(payload, rst);
mlxsw_reg_mddc_device_enable_set(payload, device_enable);
}
/* MFDE - Monitoring FW Debug Register
* -----------------------------------
*/
......@@ -12678,6 +13050,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
MLXSW_REG(pmaos),
MLXSW_REG(pplr),
MLXSW_REG(pmtdb),
MLXSW_REG(pmecr),
MLXSW_REG(pmpe),
MLXSW_REG(pddr),
MLXSW_REG(pmmp),
......@@ -12747,6 +13120,9 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
MLXSW_REG(mtptpt),
MLXSW_REG(mfgd),
MLXSW_REG(mgpir),
MLXSW_REG(mbct),
MLXSW_REG(mddq),
MLXSW_REG(mddc),
MLXSW_REG(mfde),
MLXSW_REG(tngcr),
MLXSW_REG(tnumt),
......
......@@ -89,6 +89,11 @@ static const struct mlxsw_fw_rev mlxsw_sp3_fw_rev = {
"." __stringify(MLXSW_SP_FWREV_MINOR) \
"." __stringify(MLXSW_SP_FWREV_SUBMINOR) ".mfa2"
#define MLXSW_SP_LINECARDS_INI_BUNDLE_FILENAME \
"mellanox/lc_ini_bundle_" \
__stringify(MLXSW_SP_FWREV_MINOR) "_" \
__stringify(MLXSW_SP_FWREV_SUBMINOR) ".bin"
static const char mlxsw_sp1_driver_name[] = "mlxsw_spectrum";
static const char mlxsw_sp2_driver_name[] = "mlxsw_spectrum2";
static const char mlxsw_sp3_driver_name[] = "mlxsw_spectrum3";
......@@ -481,23 +486,22 @@ mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port)
}
static int
mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port,
mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp,
u16 local_port, char *pmlp_pl,
struct mlxsw_sp_port_mapping *port_mapping)
{
char pmlp_pl[MLXSW_REG_PMLP_LEN];
bool separate_rxtx;
u8 first_lane;
u8 slot_index;
u8 module;
u8 width;
int err;
int i;
mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
if (err)
return err;
module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
slot_index = mlxsw_reg_pmlp_slot_index_get(pmlp_pl, 0);
width = mlxsw_reg_pmlp_width_get(pmlp_pl);
separate_rxtx = mlxsw_reg_pmlp_rxtx_get(pmlp_pl);
first_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
if (width && !is_power_of_2(width)) {
dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: width value is not power of 2\n",
......@@ -511,6 +515,11 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port,
local_port);
return -EINVAL;
}
if (mlxsw_reg_pmlp_slot_index_get(pmlp_pl, i) != slot_index) {
dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: contains multiple slot indexes\n",
local_port);
return -EINVAL;
}
if (separate_rxtx &&
mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) !=
mlxsw_reg_pmlp_rx_lane_get(pmlp_pl, i)) {
......@@ -518,7 +527,7 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port,
local_port);
return -EINVAL;
}
if (mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) != i) {
if (mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) != i + first_lane) {
dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: TX and RX lane numbers are not sequential\n",
local_port);
return -EINVAL;
......@@ -526,12 +535,28 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port,
}
port_mapping->module = module;
port_mapping->slot_index = slot_index;
port_mapping->width = width;
port_mapping->module_width = width;
port_mapping->lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
return 0;
}
static int
mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port,
struct mlxsw_sp_port_mapping *port_mapping)
{
char pmlp_pl[MLXSW_REG_PMLP_LEN];
int err;
mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
if (err)
return err;
return mlxsw_sp_port_module_info_parse(mlxsw_sp, local_port,
pmlp_pl, port_mapping);
}
static int
mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
const struct mlxsw_sp_port_mapping *port_mapping)
......@@ -539,11 +564,14 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
char pmlp_pl[MLXSW_REG_PMLP_LEN];
int i, err;
mlxsw_env_module_port_map(mlxsw_sp->core, 0, port_mapping->module);
mlxsw_env_module_port_map(mlxsw_sp->core, port_mapping->slot_index,
port_mapping->module);
mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
mlxsw_reg_pmlp_width_set(pmlp_pl, port_mapping->width);
for (i = 0; i < port_mapping->width; i++) {
mlxsw_reg_pmlp_slot_index_set(pmlp_pl, i,
port_mapping->slot_index);
mlxsw_reg_pmlp_module_set(pmlp_pl, i, port_mapping->module);
mlxsw_reg_pmlp_tx_lane_set(pmlp_pl, i, port_mapping->lane + i); /* Rx & Tx */
}
......@@ -554,7 +582,8 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
return 0;
err_pmlp_write:
mlxsw_env_module_port_unmap(mlxsw_sp->core, 0, port_mapping->module);
mlxsw_env_module_port_unmap(mlxsw_sp->core, port_mapping->slot_index,
port_mapping->module);
return err;
}
......@@ -575,7 +604,8 @@ static int mlxsw_sp_port_open(struct net_device *dev)
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
int err;
err = mlxsw_env_module_port_up(mlxsw_sp->core, 0,
err = mlxsw_env_module_port_up(mlxsw_sp->core,
mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module);
if (err)
return err;
......@@ -586,7 +616,8 @@ static int mlxsw_sp_port_open(struct net_device *dev)
return 0;
err_port_admin_status_set:
mlxsw_env_module_port_down(mlxsw_sp->core, 0,
mlxsw_env_module_port_down(mlxsw_sp->core,
mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module);
return err;
}
......@@ -598,7 +629,8 @@ static int mlxsw_sp_port_stop(struct net_device *dev)
netif_stop_queue(dev);
mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
mlxsw_env_module_port_down(mlxsw_sp->core, 0,
mlxsw_env_module_port_down(mlxsw_sp->core,
mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module);
return 0;
}
......@@ -1445,12 +1477,13 @@ static int mlxsw_sp_port_tc_mc_mode_set(struct mlxsw_sp_port *mlxsw_sp_port,
static int mlxsw_sp_port_overheat_init_val_set(struct mlxsw_sp_port *mlxsw_sp_port)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
u64 overheat_counter;
int err;
err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, 0, module,
&overheat_counter);
err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, slot_index,
module, &overheat_counter);
if (err)
return err;
......@@ -1525,7 +1558,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
}
splittable = lanes > 1 && !split;
err = mlxsw_core_port_init(mlxsw_sp->core, local_port,
err = mlxsw_core_port_init(mlxsw_sp->core, local_port, slot_index,
port_number, split, split_port_subnumber,
splittable, lanes, mlxsw_sp->base_mac,
sizeof(mlxsw_sp->base_mac));
......@@ -1775,7 +1808,8 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
MLXSW_PORT_SWID_DISABLED_PORT);
err_port_swid_set:
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0,
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port,
port_mapping->slot_index,
port_mapping->module);
return err;
}
......@@ -1783,6 +1817,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
{
struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
......@@ -1805,7 +1840,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
mlxsw_core_port_fini(mlxsw_sp->core, local_port);
mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
MLXSW_PORT_SWID_DISABLED_PORT);
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0, module);
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, slot_index, module);
}
static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
......@@ -1859,21 +1894,148 @@ static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u16 local_port)
return mlxsw_sp->ports[local_port] != NULL;
}
static int mlxsw_sp_port_mapping_event_set(struct mlxsw_sp *mlxsw_sp,
u16 local_port, bool enable)
{
char pmecr_pl[MLXSW_REG_PMECR_LEN];
mlxsw_reg_pmecr_pack(pmecr_pl, local_port,
enable ? MLXSW_REG_PMECR_E_GENERATE_EVENT :
MLXSW_REG_PMECR_E_DO_NOT_GENERATE_EVENT);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmecr), pmecr_pl);
}
struct mlxsw_sp_port_mapping_event {
struct list_head list;
char pmlp_pl[MLXSW_REG_PMLP_LEN];
};
static void mlxsw_sp_port_mapping_events_work(struct work_struct *work)
{
struct mlxsw_sp_port_mapping_event *event, *next_event;
struct mlxsw_sp_port_mapping_events *events;
struct mlxsw_sp_port_mapping port_mapping;
struct mlxsw_sp *mlxsw_sp;
struct devlink *devlink;
LIST_HEAD(event_queue);
u16 local_port;
int err;
events = container_of(work, struct mlxsw_sp_port_mapping_events, work);
mlxsw_sp = container_of(events, struct mlxsw_sp, port_mapping_events);
devlink = priv_to_devlink(mlxsw_sp->core);
spin_lock_bh(&events->queue_lock);
list_splice_init(&events->queue, &event_queue);
spin_unlock_bh(&events->queue_lock);
list_for_each_entry_safe(event, next_event, &event_queue, list) {
local_port = mlxsw_reg_pmlp_local_port_get(event->pmlp_pl);
err = mlxsw_sp_port_module_info_parse(mlxsw_sp, local_port,
event->pmlp_pl, &port_mapping);
if (err)
goto out;
if (WARN_ON_ONCE(!port_mapping.width))
goto out;
devl_lock(devlink);
if (!mlxsw_sp_port_created(mlxsw_sp, local_port))
mlxsw_sp_port_create(mlxsw_sp, local_port,
false, &port_mapping);
else
WARN_ON_ONCE(1);
devl_unlock(devlink);
mlxsw_sp->port_mapping[local_port] = port_mapping;
out:
kfree(event);
}
}
static void
mlxsw_sp_port_mapping_listener_func(const struct mlxsw_reg_info *reg,
char *pmlp_pl, void *priv)
{
struct mlxsw_sp_port_mapping_events *events;
struct mlxsw_sp_port_mapping_event *event;
struct mlxsw_sp *mlxsw_sp = priv;
u16 local_port;
local_port = mlxsw_reg_pmlp_local_port_get(pmlp_pl);
if (WARN_ON_ONCE(!mlxsw_sp_local_port_is_valid(mlxsw_sp, local_port)))
return;
events = &mlxsw_sp->port_mapping_events;
event = kmalloc(sizeof(*event), GFP_ATOMIC);
if (!event)
return;
memcpy(event->pmlp_pl, pmlp_pl, sizeof(event->pmlp_pl));
spin_lock(&events->queue_lock);
list_add_tail(&event->list, &events->queue);
spin_unlock(&events->queue_lock);
mlxsw_core_schedule_work(&events->work);
}
static void
__mlxsw_sp_port_mapping_events_cancel(struct mlxsw_sp *mlxsw_sp)
{
struct mlxsw_sp_port_mapping_event *event, *next_event;
struct mlxsw_sp_port_mapping_events *events;
events = &mlxsw_sp->port_mapping_events;
/* Caller needs to make sure that no new event is going to appear. */
cancel_work_sync(&events->work);
list_for_each_entry_safe(event, next_event, &events->queue, list) {
list_del(&event->list);
kfree(event);
}
}
static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
{
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
int i;
for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
for (i = 1; i < max_ports; i++)
mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, false);
/* Make sure all scheduled events are processed */
__mlxsw_sp_port_mapping_events_cancel(mlxsw_sp);
devl_lock(devlink);
for (i = 1; i < max_ports; i++)
if (mlxsw_sp_port_created(mlxsw_sp, i))
mlxsw_sp_port_remove(mlxsw_sp, i);
mlxsw_sp_cpu_port_remove(mlxsw_sp);
devl_unlock(devlink);
kfree(mlxsw_sp->ports);
mlxsw_sp->ports = NULL;
}
static void
mlxsw_sp_ports_remove_selected(struct mlxsw_core *mlxsw_core,
bool (*selector)(void *priv, u16 local_port),
void *priv)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_core);
int i;
for (i = 1; i < max_ports; i++)
if (mlxsw_sp_port_created(mlxsw_sp, i) && selector(priv, i))
mlxsw_sp_port_remove(mlxsw_sp, i);
}
static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
{
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
struct mlxsw_sp_port_mapping_events *events;
struct mlxsw_sp_port_mapping *port_mapping;
size_t alloc_size;
int i;
......@@ -1884,26 +2046,46 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
if (!mlxsw_sp->ports)
return -ENOMEM;
events = &mlxsw_sp->port_mapping_events;
INIT_LIST_HEAD(&events->queue);
spin_lock_init(&events->queue_lock);
INIT_WORK(&events->work, mlxsw_sp_port_mapping_events_work);
for (i = 1; i < max_ports; i++) {
err = mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, true);
if (err)
goto err_event_enable;
}
devl_lock(devlink);
err = mlxsw_sp_cpu_port_create(mlxsw_sp);
if (err)
goto err_cpu_port_create;
for (i = 1; i < max_ports; i++) {
port_mapping = mlxsw_sp->port_mapping[i];
if (!port_mapping)
port_mapping = &mlxsw_sp->port_mapping[i];
if (!port_mapping->width)
continue;
err = mlxsw_sp_port_create(mlxsw_sp, i, false, port_mapping);
if (err)
goto err_port_create;
}
devl_unlock(devlink);
return 0;
err_port_create:
for (i--; i >= 1; i--)
if (mlxsw_sp_port_created(mlxsw_sp, i))
mlxsw_sp_port_remove(mlxsw_sp, i);
i = max_ports;
mlxsw_sp_cpu_port_remove(mlxsw_sp);
err_cpu_port_create:
devl_unlock(devlink);
err_event_enable:
for (i--; i >= 1; i--)
mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, false);
/* Make sure all scheduled events are processed */
__mlxsw_sp_port_mapping_events_cancel(mlxsw_sp);
kfree(mlxsw_sp->ports);
mlxsw_sp->ports = NULL;
return err;
......@@ -1912,12 +2094,12 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
static int mlxsw_sp_port_module_info_init(struct mlxsw_sp *mlxsw_sp)
{
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
struct mlxsw_sp_port_mapping port_mapping;
struct mlxsw_sp_port_mapping *port_mapping;
int i;
int err;
mlxsw_sp->port_mapping = kcalloc(max_ports,
sizeof(struct mlxsw_sp_port_mapping *),
sizeof(struct mlxsw_sp_port_mapping),
GFP_KERNEL);
if (!mlxsw_sp->port_mapping)
return -ENOMEM;
......@@ -1926,36 +2108,20 @@ static int mlxsw_sp_port_module_info_init(struct mlxsw_sp *mlxsw_sp)
if (mlxsw_core_port_is_xm(mlxsw_sp->core, i))
continue;
err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &port_mapping);
port_mapping = &mlxsw_sp->port_mapping[i];
err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, port_mapping);
if (err)
goto err_port_module_info_get;
if (!port_mapping.width)
continue;
mlxsw_sp->port_mapping[i] = kmemdup(&port_mapping,
sizeof(port_mapping),
GFP_KERNEL);
if (!mlxsw_sp->port_mapping[i]) {
err = -ENOMEM;
goto err_port_module_info_dup;
}
}
return 0;
err_port_module_info_get:
err_port_module_info_dup:
for (i--; i >= 1; i--)
kfree(mlxsw_sp->port_mapping[i]);
kfree(mlxsw_sp->port_mapping);
return err;
}
static void mlxsw_sp_port_module_info_fini(struct mlxsw_sp *mlxsw_sp)
{
int i;
for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
kfree(mlxsw_sp->port_mapping[i]);
kfree(mlxsw_sp->port_mapping);
}
......@@ -2005,8 +2171,8 @@ static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp,
for (i = 0; i < count; i++) {
u16 local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i);
port_mapping = mlxsw_sp->port_mapping[local_port];
if (!port_mapping || !mlxsw_sp_local_port_valid(local_port))
port_mapping = &mlxsw_sp->port_mapping[local_port];
if (!port_mapping->width || !mlxsw_sp_local_port_valid(local_port))
continue;
mlxsw_sp_port_create(mlxsw_sp, local_port,
false, port_mapping);
......@@ -2046,7 +2212,8 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
return -EINVAL;
}
mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module,
mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module,
mlxsw_sp_port->mapping.module_width / count,
count);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl);
......@@ -2081,6 +2248,7 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port,
err_port_split_create:
mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl);
return err;
}
......@@ -2110,7 +2278,8 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port,
count = mlxsw_sp_port->mapping.module_width /
mlxsw_sp_port->mapping.width;
mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module,
mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module,
mlxsw_sp_port->mapping.module_width / count,
count);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl);
......@@ -2301,6 +2470,11 @@ static const struct mlxsw_listener mlxsw_sp1_listener[] = {
MLXSW_EVENTL(mlxsw_sp1_ptp_ing_fifo_event_func, PTP_ING_FIFO, SP_PTP0),
};
static const struct mlxsw_listener mlxsw_sp2_listener[] = {
/* Events */
MLXSW_SP_EVENTL(mlxsw_sp_port_mapping_listener_func, PMLPE),
};
static int mlxsw_sp_cpu_policers_set(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
......@@ -2819,7 +2993,6 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
struct netlink_ext_ack *extack)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
int err;
mlxsw_sp->core = mlxsw_core;
......@@ -2980,9 +3153,7 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
goto err_sample_trigger_init;
}
devl_lock(devlink);
err = mlxsw_sp_ports_create(mlxsw_sp);
devl_unlock(devlink);
if (err) {
dev_err(mlxsw_sp->bus_info->dev, "Failed to create ports\n");
goto err_ports_create;
......@@ -3095,6 +3266,8 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops;
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
mlxsw_sp->listeners = mlxsw_sp2_listener;
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
......@@ -3125,6 +3298,8 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops;
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
mlxsw_sp->listeners = mlxsw_sp2_listener;
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
......@@ -3155,6 +3330,8 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops;
mlxsw_sp->router_ops = &mlxsw_sp2_router_ops;
mlxsw_sp->listeners = mlxsw_sp2_listener;
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener);
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP4;
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
......@@ -3163,12 +3340,8 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core,
static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct devlink *devlink = priv_to_devlink(mlxsw_core);
devl_lock(devlink);
mlxsw_sp_ports_remove(mlxsw_sp);
devl_unlock(devlink);
rhashtable_destroy(&mlxsw_sp->sample_trigger_ht);
mlxsw_sp_port_module_info_fini(mlxsw_sp);
mlxsw_sp_dpipe_fini(mlxsw_sp);
......@@ -3646,6 +3819,7 @@ static struct mlxsw_driver mlxsw_sp2_driver = {
.fini = mlxsw_sp_fini,
.port_split = mlxsw_sp_port_split,
.port_unsplit = mlxsw_sp_port_unsplit,
.ports_remove_selected = mlxsw_sp_ports_remove_selected,
.sb_pool_get = mlxsw_sp_sb_pool_get,
.sb_pool_set = mlxsw_sp_sb_pool_set,
.sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
......@@ -3683,6 +3857,7 @@ static struct mlxsw_driver mlxsw_sp3_driver = {
.fini = mlxsw_sp_fini,
.port_split = mlxsw_sp_port_split,
.port_unsplit = mlxsw_sp_port_unsplit,
.ports_remove_selected = mlxsw_sp_ports_remove_selected,
.sb_pool_get = mlxsw_sp_sb_pool_get,
.sb_pool_set = mlxsw_sp_sb_pool_set,
.sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
......@@ -3718,6 +3893,7 @@ static struct mlxsw_driver mlxsw_sp4_driver = {
.fini = mlxsw_sp_fini,
.port_split = mlxsw_sp_port_split,
.port_unsplit = mlxsw_sp_port_unsplit,
.ports_remove_selected = mlxsw_sp_ports_remove_selected,
.sb_pool_get = mlxsw_sp_sb_pool_get,
.sb_pool_set = mlxsw_sp_sb_pool_set,
.sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
......@@ -5025,3 +5201,4 @@ MODULE_DEVICE_TABLE(pci, mlxsw_sp4_pci_id_table);
MODULE_FIRMWARE(MLXSW_SP1_FW_FILENAME);
MODULE_FIRMWARE(MLXSW_SP2_FW_FILENAME);
MODULE_FIRMWARE(MLXSW_SP3_FW_FILENAME);
MODULE_FIRMWARE(MLXSW_SP_LINECARDS_INI_BUNDLE_FILENAME);
......@@ -145,11 +145,18 @@ struct mlxsw_sp_mall_entry;
struct mlxsw_sp_port_mapping {
u8 module;
u8 slot_index;
u8 width; /* Number of lanes used by the port */
u8 module_width; /* Number of lanes in the module (static) */
u8 lane;
};
struct mlxsw_sp_port_mapping_events {
struct list_head queue;
spinlock_t queue_lock; /* protects queue */
struct work_struct work;
};
struct mlxsw_sp_parsing {
refcount_t parsing_depth_ref;
u16 parsing_depth;
......@@ -164,7 +171,8 @@ struct mlxsw_sp {
unsigned char base_mac[ETH_ALEN];
const unsigned char *mac_mask;
struct mlxsw_sp_upper *lags;
struct mlxsw_sp_port_mapping **port_mapping;
struct mlxsw_sp_port_mapping *port_mapping;
struct mlxsw_sp_port_mapping_events port_mapping_events;
struct rhashtable sample_trigger_ht;
struct mlxsw_sp_sb *sb;
struct mlxsw_sp_bridge *bridge;
......
......@@ -568,14 +568,14 @@ struct mlxsw_sp_port_stats {
static u64
mlxsw_sp_port_get_transceiver_overheat_stats(struct mlxsw_sp_port *mlxsw_sp_port)
{
struct mlxsw_sp_port_mapping port_mapping = mlxsw_sp_port->mapping;
struct mlxsw_core *mlxsw_core = mlxsw_sp_port->mlxsw_sp->core;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
u64 stats;
int err;
err = mlxsw_env_module_overheat_counter_get(mlxsw_core, 0,
port_mapping.module,
&stats);
err = mlxsw_env_module_overheat_counter_get(mlxsw_core, slot_index,
module, &stats);
if (err)
return mlxsw_sp_port->module_overheat_initial_val;
......@@ -1035,7 +1035,8 @@ static int mlxsw_sp_get_module_info(struct net_device *netdev,
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
return mlxsw_env_get_module_info(netdev, mlxsw_sp->core, 0,
return mlxsw_env_get_module_info(netdev, mlxsw_sp->core,
mlxsw_sp_port->mapping.slot_index,
mlxsw_sp_port->mapping.module,
modinfo);
}
......@@ -1045,10 +1046,11 @@ static int mlxsw_sp_get_module_eeprom(struct net_device *netdev,
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module, ee,
data);
return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, slot_index,
module, ee, data);
}
static int
......@@ -1058,10 +1060,11 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev,
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, 0, module,
page, extack);
return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, slot_index,
module, page, extack);
}
static int
......@@ -1202,9 +1205,11 @@ static int mlxsw_sp_reset(struct net_device *dev, u32 *flags)
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_reset_module(dev, mlxsw_sp->core, 0, module, flags);
return mlxsw_env_reset_module(dev, mlxsw_sp->core, slot_index,
module, flags);
}
static int
......@@ -1214,10 +1219,11 @@ mlxsw_sp_get_module_power_mode(struct net_device *dev,
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_get_module_power_mode(mlxsw_sp->core, 0, module,
params, extack);
return mlxsw_env_get_module_power_mode(mlxsw_sp->core, slot_index,
module, params, extack);
}
static int
......@@ -1227,10 +1233,11 @@ mlxsw_sp_set_module_power_mode(struct net_device *dev,
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 slot_index = mlxsw_sp_port->mapping.slot_index;
u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_set_module_power_mode(mlxsw_sp->core, 0, module,
params->policy, extack);
return mlxsw_env_set_module_power_mode(mlxsw_sp->core, slot_index,
module, params->policy, extack);
}
const struct ethtool_ops mlxsw_sp_port_ethtool_ops = {
......
......@@ -133,6 +133,12 @@ enum mlxsw_event_trap_id {
MLXSW_TRAP_ID_PTP_ING_FIFO = 0x2D,
/* PTP Egress FIFO has a new entry */
MLXSW_TRAP_ID_PTP_EGR_FIFO = 0x2E,
/* Downstream Device Status Change */
MLXSW_TRAP_ID_DSDSC = 0x321,
/* Binary Code Transfer Operation Executed Event */
MLXSW_TRAP_ID_BCTOE = 0x322,
/* Port mapping change */
MLXSW_TRAP_ID_PMLPE = 0x32E,
};
#endif /* _MLXSW_TRAP_H */
......@@ -22,6 +22,7 @@
#include <linux/firmware.h>
struct devlink;
struct devlink_linecard;
struct devlink_port_phys_attrs {
u32 port_number; /* Same value as "split group".
......@@ -135,6 +136,7 @@ struct devlink_port {
struct mutex reporters_lock; /* Protects reporter_list */
struct devlink_rate *devlink_rate;
struct devlink_linecard *linecard;
};
struct devlink_port_new_attrs {
......@@ -148,6 +150,40 @@ struct devlink_port_new_attrs {
sfnum_valid:1;
};
/**
* struct devlink_linecard_ops - Linecard operations
* @provision: callback to provision the linecard slot with certain
* type of linecard. As a result of this operation,
* driver is expected to eventually (could be after
* the function call returns) call one of:
* devlink_linecard_provision_set()
* devlink_linecard_provision_fail()
* @unprovision: callback to unprovision the linecard slot. As a result
* of this operation, driver is expected to eventually
* (could be after the function call returns) call
* devlink_linecard_provision_clear()
* devlink_linecard_provision_fail()
* @same_provision: callback to ask the driver if linecard is already
* provisioned in the same way user asks this linecard to be
* provisioned.
* @types_count: callback to get number of supported types
* @types_get: callback to get next type in list
*/
struct devlink_linecard_ops {
int (*provision)(struct devlink_linecard *linecard, void *priv,
const char *type, const void *type_priv,
struct netlink_ext_ack *extack);
int (*unprovision)(struct devlink_linecard *linecard, void *priv,
struct netlink_ext_ack *extack);
bool (*same_provision)(struct devlink_linecard *linecard, void *priv,
const char *type, const void *type_priv);
unsigned int (*types_count)(struct devlink_linecard *linecard,
void *priv);
void (*types_get)(struct devlink_linecard *linecard,
void *priv, unsigned int index, const char **type,
const void **type_priv);
};
struct devlink_sb_pool_info {
enum devlink_sb_pool_type pool_type;
u32 size;
......@@ -1536,6 +1572,18 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
int devlink_rate_leaf_create(struct devlink_port *port, void *priv);
void devlink_rate_leaf_destroy(struct devlink_port *devlink_port);
void devlink_rate_nodes_destroy(struct devlink *devlink);
void devlink_port_linecard_set(struct devlink_port *devlink_port,
struct devlink_linecard *linecard);
struct devlink_linecard *
devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
const struct devlink_linecard_ops *ops, void *priv);
void devlink_linecard_destroy(struct devlink_linecard *linecard);
void devlink_linecard_provision_set(struct devlink_linecard *linecard,
const char *type);
void devlink_linecard_provision_clear(struct devlink_linecard *linecard);
void devlink_linecard_provision_fail(struct devlink_linecard *linecard);
void devlink_linecard_activate(struct devlink_linecard *linecard);
void devlink_linecard_deactivate(struct devlink_linecard *linecard);
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
u32 size, u16 ingress_pools_count,
u16 egress_pools_count, u16 ingress_tc_count,
......
......@@ -131,6 +131,11 @@ enum devlink_command {
DEVLINK_CMD_RATE_NEW,
DEVLINK_CMD_RATE_DEL,
DEVLINK_CMD_LINECARD_GET, /* can dump */
DEVLINK_CMD_LINECARD_SET,
DEVLINK_CMD_LINECARD_NEW,
DEVLINK_CMD_LINECARD_DEL,
/* add new commands above here */
__DEVLINK_CMD_MAX,
DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
......@@ -338,6 +343,19 @@ enum devlink_reload_limit {
#define DEVLINK_RELOAD_LIMITS_VALID_MASK (_BITUL(__DEVLINK_RELOAD_LIMIT_MAX) - 1)
enum devlink_linecard_state {
DEVLINK_LINECARD_STATE_UNSPEC,
DEVLINK_LINECARD_STATE_UNPROVISIONED,
DEVLINK_LINECARD_STATE_UNPROVISIONING,
DEVLINK_LINECARD_STATE_PROVISIONING,
DEVLINK_LINECARD_STATE_PROVISIONING_FAILED,
DEVLINK_LINECARD_STATE_PROVISIONED,
DEVLINK_LINECARD_STATE_ACTIVE,
__DEVLINK_LINECARD_STATE_MAX,
DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1
};
enum devlink_attr {
/* don't change the order or add anything between, this is ABI! */
DEVLINK_ATTR_UNSPEC,
......@@ -553,6 +571,11 @@ enum devlink_attr {
DEVLINK_ATTR_REGION_MAX_SNAPSHOTS, /* u32 */
DEVLINK_ATTR_LINECARD_INDEX, /* u32 */
DEVLINK_ATTR_LINECARD_STATE, /* u8 */
DEVLINK_ATTR_LINECARD_TYPE, /* string */
DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* nested */
/* add new attributes above here, update the policy in devlink.c */
__DEVLINK_ATTR_MAX,
......
......@@ -54,6 +54,8 @@ struct devlink {
struct list_head trap_list;
struct list_head trap_group_list;
struct list_head trap_policer_list;
struct list_head linecard_list;
struct mutex linecards_lock; /* protects linecard_list */
const struct devlink_ops *ops;
u64 features;
struct xarray snapshot_ids;
......@@ -70,6 +72,23 @@ struct devlink {
char priv[] __aligned(NETDEV_ALIGN);
};
struct devlink_linecard_ops;
struct devlink_linecard_type;
struct devlink_linecard {
struct list_head list;
struct devlink *devlink;
unsigned int index;
refcount_t refcount;
const struct devlink_linecard_ops *ops;
void *priv;
enum devlink_linecard_state state;
struct mutex state_lock; /* Protects state */
const char *type;
struct devlink_linecard_type *types;
unsigned int types_count;
};
/**
* struct devlink_resource - devlink resource
* @name: name of the resource
......@@ -397,6 +416,58 @@ devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info)
return ERR_PTR(-EINVAL);
}
static struct devlink_linecard *
devlink_linecard_get_by_index(struct devlink *devlink,
unsigned int linecard_index)
{
struct devlink_linecard *devlink_linecard;
list_for_each_entry(devlink_linecard, &devlink->linecard_list, list) {
if (devlink_linecard->index == linecard_index)
return devlink_linecard;
}
return NULL;
}
static bool devlink_linecard_index_exists(struct devlink *devlink,
unsigned int linecard_index)
{
return devlink_linecard_get_by_index(devlink, linecard_index);
}
static struct devlink_linecard *
devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs)
{
if (attrs[DEVLINK_ATTR_LINECARD_INDEX]) {
u32 linecard_index = nla_get_u32(attrs[DEVLINK_ATTR_LINECARD_INDEX]);
struct devlink_linecard *linecard;
mutex_lock(&devlink->linecards_lock);
linecard = devlink_linecard_get_by_index(devlink, linecard_index);
if (linecard)
refcount_inc(&linecard->refcount);
mutex_unlock(&devlink->linecards_lock);
if (!linecard)
return ERR_PTR(-ENODEV);
return linecard;
}
return ERR_PTR(-EINVAL);
}
static struct devlink_linecard *
devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)
{
return devlink_linecard_get_from_attrs(devlink, info->attrs);
}
static void devlink_linecard_put(struct devlink_linecard *linecard)
{
if (refcount_dec_and_test(&linecard->refcount)) {
mutex_destroy(&linecard->state_lock);
kfree(linecard);
}
}
struct devlink_sb {
struct list_head list;
unsigned int index;
......@@ -617,16 +688,18 @@ devlink_region_snapshot_get_by_id(struct devlink_region *region, u32 id)
#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1)
#define DEVLINK_NL_FLAG_NEED_RATE BIT(2)
#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3)
#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4)
/* The per devlink instance lock is taken by default in the pre-doit
* operation, yet several commands do not require this. The global
* devlink lock is taken and protects from disruption by user-calls.
*/
#define DEVLINK_NL_FLAG_NO_LOCK BIT(4)
#define DEVLINK_NL_FLAG_NO_LOCK BIT(5)
static int devlink_nl_pre_doit(const struct genl_ops *ops,
struct sk_buff *skb, struct genl_info *info)
{
struct devlink_linecard *linecard;
struct devlink_port *devlink_port;
struct devlink *devlink;
int err;
......@@ -669,6 +742,13 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
goto unlock;
}
info->user_ptr[1] = rate_node;
} else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) {
linecard = devlink_linecard_get_from_info(devlink, info);
if (IS_ERR(linecard)) {
err = PTR_ERR(linecard);
goto unlock;
}
info->user_ptr[1] = linecard;
}
return 0;
......@@ -683,9 +763,14 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
static void devlink_nl_post_doit(const struct genl_ops *ops,
struct sk_buff *skb, struct genl_info *info)
{
struct devlink_linecard *linecard;
struct devlink *devlink;
devlink = info->user_ptr[0];
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) {
linecard = info->user_ptr[1];
devlink_linecard_put(linecard);
}
if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK)
mutex_unlock(&devlink->lock);
devlink_put(devlink);
......@@ -1158,6 +1243,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
goto nla_put_failure;
if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
goto nla_put_failure;
if (devlink_port->linecard &&
nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
devlink_port->linecard->index))
goto nla_put_failure;
genlmsg_end(msg, hdr);
return 0;
......@@ -1964,6 +2053,322 @@ static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb,
return err;
}
struct devlink_linecard_type {
const char *type;
const void *priv;
};
static int devlink_nl_linecard_fill(struct sk_buff *msg,
struct devlink *devlink,
struct devlink_linecard *linecard,
enum devlink_command cmd, u32 portid,
u32 seq, int flags,
struct netlink_ext_ack *extack)
{
struct devlink_linecard_type *linecard_type;
struct nlattr *attr;
void *hdr;
int i;
hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
if (!hdr)
return -EMSGSIZE;
if (devlink_nl_put_handle(msg, devlink))
goto nla_put_failure;
if (nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, linecard->index))
goto nla_put_failure;
if (nla_put_u8(msg, DEVLINK_ATTR_LINECARD_STATE, linecard->state))
goto nla_put_failure;
if (linecard->type &&
nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, linecard->type))
goto nla_put_failure;
if (linecard->types_count) {
attr = nla_nest_start(msg,
DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES);
if (!attr)
goto nla_put_failure;
for (i = 0; i < linecard->types_count; i++) {
linecard_type = &linecard->types[i];
if (nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE,
linecard_type->type)) {
nla_nest_cancel(msg, attr);
goto nla_put_failure;
}
}
nla_nest_end(msg, attr);
}
genlmsg_end(msg, hdr);
return 0;
nla_put_failure:
genlmsg_cancel(msg, hdr);
return -EMSGSIZE;
}
static void devlink_linecard_notify(struct devlink_linecard *linecard,
enum devlink_command cmd)
{
struct devlink *devlink = linecard->devlink;
struct sk_buff *msg;
int err;
WARN_ON(cmd != DEVLINK_CMD_LINECARD_NEW &&
cmd != DEVLINK_CMD_LINECARD_DEL);
if (!xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED))
return;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return;
err = devlink_nl_linecard_fill(msg, devlink, linecard, cmd, 0, 0, 0,
NULL);
if (err) {
nlmsg_free(msg);
return;
}
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink),
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
}
static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb,
struct genl_info *info)
{
struct devlink_linecard *linecard = info->user_ptr[1];
struct devlink *devlink = linecard->devlink;
struct sk_buff *msg;
int err;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
mutex_lock(&linecard->state_lock);
err = devlink_nl_linecard_fill(msg, devlink, linecard,
DEVLINK_CMD_LINECARD_NEW,
info->snd_portid, info->snd_seq, 0,
info->extack);
mutex_unlock(&linecard->state_lock);
if (err) {
nlmsg_free(msg);
return err;
}
return genlmsg_reply(msg, info);
}
static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
struct netlink_callback *cb)
{
struct devlink_linecard *linecard;
struct devlink *devlink;
int start = cb->args[0];
unsigned long index;
int idx = 0;
int err;
mutex_lock(&devlink_mutex);
xa_for_each_marked(&devlinks, index, devlink, DEVLINK_REGISTERED) {
if (!devlink_try_get(devlink))
continue;
if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
goto retry;
mutex_lock(&devlink->linecards_lock);
list_for_each_entry(linecard, &devlink->linecard_list, list) {
if (idx < start) {
idx++;
continue;
}
mutex_lock(&linecard->state_lock);
err = devlink_nl_linecard_fill(msg, devlink, linecard,
DEVLINK_CMD_LINECARD_NEW,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
NLM_F_MULTI,
cb->extack);
mutex_unlock(&linecard->state_lock);
if (err) {
mutex_unlock(&devlink->linecards_lock);
devlink_put(devlink);
goto out;
}
idx++;
}
mutex_unlock(&devlink->linecards_lock);
retry:
devlink_put(devlink);
}
out:
mutex_unlock(&devlink_mutex);
cb->args[0] = idx;
return msg->len;
}
static struct devlink_linecard_type *
devlink_linecard_type_lookup(struct devlink_linecard *linecard,
const char *type)
{
struct devlink_linecard_type *linecard_type;
int i;
for (i = 0; i < linecard->types_count; i++) {
linecard_type = &linecard->types[i];
if (!strcmp(type, linecard_type->type))
return linecard_type;
}
return NULL;
}
static int devlink_linecard_type_set(struct devlink_linecard *linecard,
const char *type,
struct netlink_ext_ack *extack)
{
const struct devlink_linecard_ops *ops = linecard->ops;
struct devlink_linecard_type *linecard_type;
int err;
mutex_lock(&linecard->state_lock);
if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) {
NL_SET_ERR_MSG_MOD(extack, "Line card is currently being provisioned");
err = -EBUSY;
goto out;
}
if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) {
NL_SET_ERR_MSG_MOD(extack, "Line card is currently being unprovisioned");
err = -EBUSY;
goto out;
}
linecard_type = devlink_linecard_type_lookup(linecard, type);
if (!linecard_type) {
NL_SET_ERR_MSG_MOD(extack, "Unsupported line card type provided");
err = -EINVAL;
goto out;
}
if (linecard->state != DEVLINK_LINECARD_STATE_UNPROVISIONED &&
linecard->state != DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) {
NL_SET_ERR_MSG_MOD(extack, "Line card already provisioned");
err = -EBUSY;
/* Check if the line card is provisioned in the same
* way the user asks. In case it is, make the operation
* to return success.
*/
if (ops->same_provision &&
ops->same_provision(linecard, linecard->priv,
linecard_type->type,
linecard_type->priv))
err = 0;
goto out;
}
linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING;
linecard->type = linecard_type->type;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
err = ops->provision(linecard, linecard->priv, linecard_type->type,
linecard_type->priv, extack);
if (err) {
/* Provisioning failed. Assume the linecard is unprovisioned
* for future operations.
*/
mutex_lock(&linecard->state_lock);
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
linecard->type = NULL;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
return err;
out:
mutex_unlock(&linecard->state_lock);
return err;
}
static int devlink_linecard_type_unset(struct devlink_linecard *linecard,
struct netlink_ext_ack *extack)
{
int err;
mutex_lock(&linecard->state_lock);
if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) {
NL_SET_ERR_MSG_MOD(extack, "Line card is currently being provisioned");
err = -EBUSY;
goto out;
}
if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) {
NL_SET_ERR_MSG_MOD(extack, "Line card is currently being unprovisioned");
err = -EBUSY;
goto out;
}
if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) {
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
linecard->type = NULL;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
err = 0;
goto out;
}
if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONED) {
NL_SET_ERR_MSG_MOD(extack, "Line card is not provisioned");
err = 0;
goto out;
}
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONING;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
err = linecard->ops->unprovision(linecard, linecard->priv,
extack);
if (err) {
/* Unprovisioning failed. Assume the linecard is unprovisioned
* for future operations.
*/
mutex_lock(&linecard->state_lock);
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
linecard->type = NULL;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
return err;
out:
mutex_unlock(&linecard->state_lock);
return err;
}
static int devlink_nl_cmd_linecard_set_doit(struct sk_buff *skb,
struct genl_info *info)
{
struct devlink_linecard *linecard = info->user_ptr[1];
struct netlink_ext_ack *extack = info->extack;
int err;
if (info->attrs[DEVLINK_ATTR_LINECARD_TYPE]) {
const char *type;
type = nla_data(info->attrs[DEVLINK_ATTR_LINECARD_TYPE]);
if (strcmp(type, "")) {
err = devlink_linecard_type_set(linecard, type, extack);
if (err)
return err;
} else {
err = devlink_linecard_type_unset(linecard, extack);
if (err)
return err;
}
}
return 0;
}
static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink,
struct devlink_sb *devlink_sb,
enum devlink_command cmd, u32 portid,
......@@ -8589,6 +8994,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 },
[DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING },
[DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING },
[DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 },
[DEVLINK_ATTR_LINECARD_TYPE] = { .type = NLA_NUL_STRING },
};
static const struct genl_small_ops devlink_nl_ops[] = {
......@@ -8664,6 +9071,19 @@ static const struct genl_small_ops devlink_nl_ops[] = {
.flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
},
{
.cmd = DEVLINK_CMD_LINECARD_GET,
.doit = devlink_nl_cmd_linecard_get_doit,
.dumpit = devlink_nl_cmd_linecard_get_dumpit,
.internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
/* can be retrieved by unprivileged users */
},
{
.cmd = DEVLINK_CMD_LINECARD_SET,
.doit = devlink_nl_cmd_linecard_set_doit,
.flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
},
{
.cmd = DEVLINK_CMD_SB_GET,
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
......@@ -9043,6 +9463,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
write_pnet(&devlink->_net, net);
INIT_LIST_HEAD(&devlink->port_list);
INIT_LIST_HEAD(&devlink->rate_list);
INIT_LIST_HEAD(&devlink->linecard_list);
INIT_LIST_HEAD(&devlink->sb_list);
INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list);
INIT_LIST_HEAD(&devlink->resource_list);
......@@ -9054,6 +9475,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
INIT_LIST_HEAD(&devlink->trap_policer_list);
mutex_init(&devlink->lock);
mutex_init(&devlink->reporters_lock);
mutex_init(&devlink->linecards_lock);
refcount_set(&devlink->refcount, 1);
init_completion(&devlink->comp);
......@@ -9080,10 +9502,14 @@ static void devlink_notify_register(struct devlink *devlink)
struct devlink_param_item *param_item;
struct devlink_trap_item *trap_item;
struct devlink_port *devlink_port;
struct devlink_linecard *linecard;
struct devlink_rate *rate_node;
struct devlink_region *region;
devlink_notify(devlink, DEVLINK_CMD_NEW);
list_for_each_entry(linecard, &devlink->linecard_list, list)
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
list_for_each_entry(devlink_port, &devlink->port_list, list)
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
......@@ -9191,6 +9617,7 @@ void devlink_free(struct devlink *devlink)
{
ASSERT_DEVLINK_NOT_REGISTERED(devlink);
mutex_destroy(&devlink->linecards_lock);
mutex_destroy(&devlink->reporters_lock);
mutex_destroy(&devlink->lock);
WARN_ON(!list_empty(&devlink->trap_policer_list));
......@@ -9203,6 +9630,7 @@ void devlink_free(struct devlink *devlink)
WARN_ON(!list_empty(&devlink->dpipe_table_list));
WARN_ON(!list_empty(&devlink->sb_list));
WARN_ON(!list_empty(&devlink->rate_list));
WARN_ON(!list_empty(&devlink->linecard_list));
WARN_ON(!list_empty(&devlink->port_list));
xa_destroy(&devlink->snapshot_ids);
......@@ -9681,6 +10109,21 @@ void devlink_rate_nodes_destroy(struct devlink *devlink)
}
EXPORT_SYMBOL_GPL(devlink_rate_nodes_destroy);
/**
* devlink_port_linecard_set - Link port with a linecard
*
* @devlink_port: devlink port
* @linecard: devlink linecard
*/
void devlink_port_linecard_set(struct devlink_port *devlink_port,
struct devlink_linecard *linecard)
{
if (WARN_ON(devlink_port->devlink))
return;
devlink_port->linecard = linecard;
}
EXPORT_SYMBOL_GPL(devlink_port_linecard_set);
static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
char *name, size_t len)
{
......@@ -9692,7 +10135,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
switch (attrs->flavour) {
case DEVLINK_PORT_FLAVOUR_PHYSICAL:
n = snprintf(name, len, "p%u", attrs->phys.port_number);
if (devlink_port->linecard)
n = snprintf(name, len, "l%u",
devlink_port->linecard->index);
if (n < len)
n += snprintf(name + n, len - n, "p%u",
attrs->phys.port_number);
if (n < len && attrs->split)
n += snprintf(name + n, len - n, "s%u",
attrs->phys.split_subport_number);
......@@ -9747,6 +10195,207 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
return 0;
}
static int devlink_linecard_types_init(struct devlink_linecard *linecard)
{
struct devlink_linecard_type *linecard_type;
unsigned int count;
int i;
count = linecard->ops->types_count(linecard, linecard->priv);
linecard->types = kmalloc_array(count, sizeof(*linecard_type),
GFP_KERNEL);
if (!linecard->types)
return -ENOMEM;
linecard->types_count = count;
for (i = 0; i < count; i++) {
linecard_type = &linecard->types[i];
linecard->ops->types_get(linecard, linecard->priv, i,
&linecard_type->type,
&linecard_type->priv);
}
return 0;
}
static void devlink_linecard_types_fini(struct devlink_linecard *linecard)
{
kfree(linecard->types);
}
/**
* devlink_linecard_create - Create devlink linecard
*
* @devlink: devlink
* @linecard_index: driver-specific numerical identifier of the linecard
* @ops: linecards ops
* @priv: user priv pointer
*
* Create devlink linecard instance with provided linecard index.
* Caller can use any indexing, even hw-related one.
*
* Return: Line card structure or an ERR_PTR() encoded error code.
*/
struct devlink_linecard *
devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
const struct devlink_linecard_ops *ops, void *priv)
{
struct devlink_linecard *linecard;
int err;
if (WARN_ON(!ops || !ops->provision || !ops->unprovision ||
!ops->types_count || !ops->types_get))
return ERR_PTR(-EINVAL);
mutex_lock(&devlink->linecards_lock);
if (devlink_linecard_index_exists(devlink, linecard_index)) {
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(-EEXIST);
}
linecard = kzalloc(sizeof(*linecard), GFP_KERNEL);
if (!linecard) {
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(-ENOMEM);
}
linecard->devlink = devlink;
linecard->index = linecard_index;
linecard->ops = ops;
linecard->priv = priv;
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
mutex_init(&linecard->state_lock);
err = devlink_linecard_types_init(linecard);
if (err) {
mutex_destroy(&linecard->state_lock);
kfree(linecard);
mutex_unlock(&devlink->linecards_lock);
return ERR_PTR(err);
}
list_add_tail(&linecard->list, &devlink->linecard_list);
refcount_set(&linecard->refcount, 1);
mutex_unlock(&devlink->linecards_lock);
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
return linecard;
}
EXPORT_SYMBOL_GPL(devlink_linecard_create);
/**
* devlink_linecard_destroy - Destroy devlink linecard
*
* @linecard: devlink linecard
*/
void devlink_linecard_destroy(struct devlink_linecard *linecard)
{
struct devlink *devlink = linecard->devlink;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL);
mutex_lock(&devlink->linecards_lock);
list_del(&linecard->list);
devlink_linecard_types_fini(linecard);
mutex_unlock(&devlink->linecards_lock);
devlink_linecard_put(linecard);
}
EXPORT_SYMBOL_GPL(devlink_linecard_destroy);
/**
* devlink_linecard_provision_set - Set provisioning on linecard
*
* @linecard: devlink linecard
* @type: linecard type
*
* This is either called directly from the provision() op call or
* as a result of the provision() op call asynchronously.
*/
void devlink_linecard_provision_set(struct devlink_linecard *linecard,
const char *type)
{
mutex_lock(&linecard->state_lock);
WARN_ON(linecard->type && strcmp(linecard->type, type));
linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED;
linecard->type = type;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
EXPORT_SYMBOL_GPL(devlink_linecard_provision_set);
/**
* devlink_linecard_provision_clear - Clear provisioning on linecard
*
* @linecard: devlink linecard
*
* This is either called directly from the unprovision() op call or
* as a result of the unprovision() op call asynchronously.
*/
void devlink_linecard_provision_clear(struct devlink_linecard *linecard)
{
mutex_lock(&linecard->state_lock);
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
linecard->type = NULL;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear);
/**
* devlink_linecard_provision_fail - Fail provisioning on linecard
*
* @linecard: devlink linecard
*
* This is either called directly from the provision() op call or
* as a result of the provision() op call asynchronously.
*/
void devlink_linecard_provision_fail(struct devlink_linecard *linecard)
{
mutex_lock(&linecard->state_lock);
linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
EXPORT_SYMBOL_GPL(devlink_linecard_provision_fail);
/**
* devlink_linecard_activate - Set linecard active
*
* @linecard: devlink linecard
*/
void devlink_linecard_activate(struct devlink_linecard *linecard)
{
mutex_lock(&linecard->state_lock);
WARN_ON(linecard->state != DEVLINK_LINECARD_STATE_PROVISIONED);
linecard->state = DEVLINK_LINECARD_STATE_ACTIVE;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock);
}
EXPORT_SYMBOL_GPL(devlink_linecard_activate);
/**
* devlink_linecard_deactivate - Set linecard inactive
*
* @linecard: devlink linecard
*/
void devlink_linecard_deactivate(struct devlink_linecard *linecard)
{
mutex_lock(&linecard->state_lock);
switch (linecard->state) {
case DEVLINK_LINECARD_STATE_ACTIVE:
linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
break;
case DEVLINK_LINECARD_STATE_UNPROVISIONING:
/* Line card is being deactivated as part
* of unprovisioning flow.
*/
break;
default:
WARN_ON(1);
break;
}
mutex_unlock(&linecard->state_lock);
}
EXPORT_SYMBOL_GPL(devlink_linecard_deactivate);
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
u32 size, u16 ingress_pools_count,
u16 egress_pools_count, u16 ingress_tc_count,
......
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# In addition to the common variables, user might use:
# LC_SLOT - If not set, all probed line cards are going to be tested,
# with an exception of the "activation_16x100G_test".
# It set, only the selected line card is going to be used
# for tests, including "activation_16x100G_test".
lib_dir=$(dirname $0)/../../../net/forwarding
ALL_TESTS="
unprovision_test
provision_test
activation_16x100G_test
"
NUM_NETIFS=0
source $lib_dir/lib.sh
source $lib_dir/devlink_lib.sh
until_lc_state_is()
{
local state=$1; shift
local current=$("$@")
echo "$current"
[ "$current" == "$state" ]
}
until_lc_state_is_not()
{
! until_lc_state_is "$@"
}
lc_state_get()
{
local lc=$1
devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state"
}
lc_wait_until_state_changes()
{
local lc=$1
local state=$2
local timeout=$3 # ms
busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc"
}
lc_wait_until_state_becomes()
{
local lc=$1
local state=$2
local timeout=$3 # ms
busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc"
}
until_lc_port_count_is()
{
local port_count=$1; shift
local current=$("$@")
echo "$current"
[ $current == $port_count ]
}
lc_port_count_get()
{
local lc=$1
devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l
}
lc_wait_until_port_count_is()
{
local lc=$1
local port_count=$2
local timeout=$3 # ms
busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc"
}
PROV_UNPROV_TIMEOUT=8000 # ms
POST_PROV_ACT_TIMEOUT=2000 # ms
PROV_PORTS_INSTANTIATION_TIMEOUT=15000 # ms
unprovision_one()
{
local lc=$1
local state
state=$(lc_state_get $lc)
check_err $? "Failed to get state of linecard $lc"
if [[ "$state" == "unprovisioned" ]]; then
return
fi
log_info "Unprovisioning linecard $lc"
devlink lc set $DEVLINK_DEV lc $lc notype
check_err $? "Failed to trigger linecard $lc unprovisioning"
state=$(lc_wait_until_state_changes $lc "unprovisioning" \
$PROV_UNPROV_TIMEOUT)
check_err $? "Failed to unprovision linecard $lc (timeout)"
[ "$state" == "unprovisioned" ]
check_err $? "Failed to unprovision linecard $lc (state=$state)"
}
provision_one()
{
local lc=$1
local type=$2
local state
log_info "Provisioning linecard $lc"
devlink lc set $DEVLINK_DEV lc $lc type $type
check_err $? "Failed trigger linecard $lc provisioning"
state=$(lc_wait_until_state_changes $lc "provisioning" \
$PROV_UNPROV_TIMEOUT)
check_err $? "Failed to provision linecard $lc (timeout)"
[ "$state" == "provisioned" ] || [ "$state" == "active" ]
check_err $? "Failed to provision linecard $lc (state=$state)"
provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type")
[ "$provisioned_type" == "$type" ]
check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")"
# Wait for possible activation to make sure the state
# won't change after return from this function.
state=$(lc_wait_until_state_becomes $lc "active" \
$POST_PROV_ACT_TIMEOUT)
}
unprovision_test()
{
RET=0
local lc
lc=$LC_SLOT
unprovision_one $lc
log_test "Unprovision"
}
LC_16X100G_TYPE="16x100G"
LC_16X100G_PORT_COUNT=16
supported_types_check()
{
local lc=$1
local supported_types_count
local type_index
local lc_16x100_found=false
supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
jq -e -r ".[][][].supported_types | length")
[ $supported_types_count != 0 ]
check_err $? "No supported types found for linecard $lc"
for (( type_index=0; type_index<$supported_types_count; type_index++ ))
do
type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \
jq -e -r ".[][][].supported_types[$type_index]")
if [[ "$type" == "$LC_16X100G_TYPE" ]]; then
lc_16x100_found=true
break
fi
done
[ $lc_16x100_found = true ]
check_err $? "16X100G not found between supported types of linecard $lc"
}
ports_check()
{
local lc=$1
local expected_port_count=$2
local port_count
port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \
$PROV_PORTS_INSTANTIATION_TIMEOUT)
[ $port_count != 0 ]
check_err $? "No port associated with linecard $lc"
[ $port_count == $expected_port_count ]
check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)"
}
provision_test()
{
RET=0
local lc
local type
local state
lc=$LC_SLOT
supported_types_check $lc
state=$(lc_state_get $lc)
check_err $? "Failed to get state of linecard $lc"
if [[ "$state" != "unprovisioned" ]]; then
unprovision_one $lc
fi
provision_one $lc $LC_16X100G_TYPE
ports_check $lc $LC_16X100G_PORT_COUNT
log_test "Provision"
}
ACTIVATION_TIMEOUT=20000 # ms
interface_check()
{
ip link set $h1 up
ip link set $h2 up
ifaces_upped=true
setup_wait
}
activation_16x100G_test()
{
RET=0
local lc
local type
local state
lc=$LC_SLOT
type=$LC_16X100G_TYPE
unprovision_one $lc
provision_one $lc $type
state=$(lc_wait_until_state_becomes $lc "active" \
$ACTIVATION_TIMEOUT)
check_err $? "Failed to get linecard $lc activated (timeout)"
interface_check
log_test "Activation 16x100G"
}
setup_prepare()
{
local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length")
if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then
echo "SKIP: No linecard support found"
exit $ksft_skip
fi
if [ -z "$LC_SLOT" ]; then
echo "SKIP: \"LC_SLOT\" variable not provided"
exit $ksft_skip
fi
# Interfaces are not present during the script start,
# that's why we define NUM_NETIFS here so dummy
# implicit veth pairs are not created.
NUM_NETIFS=2
h1=${NETIFS[p1]}
h2=${NETIFS[p2]}
ifaces_upped=false
}
cleanup()
{
if [ "$ifaces_upped" = true ] ; then
ip link set $h1 down
ip link set $h2 down
fi
}
trap cleanup EXIT
setup_prepare
tests_run
exit $EXIT_STATUS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment