From: Jiri Pirko <jiri@resnulli.us>
To: Ido Schimmel <idosch@idosch.org>
Cc: netdev@vger.kernel.org, davem@davemloft.net, jiri@mellanox.com,
shalomt@mellanox.com, mlxsw@mellanox.com,
Ido Schimmel <idosch@mellanox.com>
Subject: Re: [PATCH net-next 1/2] mlxsw: spectrum: Register CPU port with devlink
Date: Fri, 13 Sep 2019 10:02:23 +0200 [thread overview]
Message-ID: <20190913080223.GB2330@nanopsycho> (raw)
In-Reply-To: <20190912130740.22061-2-idosch@idosch.org>
Thu, Sep 12, 2019 at 03:07:39PM CEST, idosch@idosch.org wrote:
>From: Shalom Toledo <shalomt@mellanox.com>
>
>Register CPU port with devlink.
>
>Signed-off-by: Shalom Toledo <shalomt@mellanox.com>
>Signed-off-by: Ido Schimmel <idosch@mellanox.com>
>---
> drivers/net/ethernet/mellanox/mlxsw/core.c | 33 +++++++++++++
> drivers/net/ethernet/mellanox/mlxsw/core.h | 5 ++
> .../net/ethernet/mellanox/mlxsw/spectrum.c | 47 +++++++++++++++++++
> 3 files changed, 85 insertions(+)
>
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
>index 963a2b4b61b1..94f83d2be17e 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
>+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
>@@ -1892,6 +1892,39 @@ void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
> }
> EXPORT_SYMBOL(mlxsw_core_port_fini);
>
>+int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
>+ void *port_driver_priv,
>+ const unsigned char *switch_id,
>+ unsigned char switch_id_len)
>+{
>+ struct devlink *devlink = priv_to_devlink(mlxsw_core);
>+ struct mlxsw_core_port *mlxsw_core_port =
>+ &mlxsw_core->ports[MLXSW_PORT_CPU_PORT];
>+ struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port;
>+ int err;
>+
>+ mlxsw_core_port->local_port = MLXSW_PORT_CPU_PORT;
>+ mlxsw_core_port->port_driver_priv = port_driver_priv;
>+ devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_CPU,
>+ 0, false, 0, switch_id, switch_id_len);
>+ err = devlink_port_register(devlink, devlink_port, MLXSW_PORT_CPU_PORT);
>+ if (err)
>+ memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
>+ return err;
This duplicates almost 100% of code of mlxsw_core_port_init. Please do a
common function what can be used by both.
>+}
>+EXPORT_SYMBOL(mlxsw_core_cpu_port_init);
>+
>+void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core)
>+{
>+ struct mlxsw_core_port *mlxsw_core_port =
>+ &mlxsw_core->ports[MLXSW_PORT_CPU_PORT];
>+ struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port;
>+
>+ devlink_port_unregister(devlink_port);
>+ memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
>+}
>+EXPORT_SYMBOL(mlxsw_core_cpu_port_fini);
>+
> void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u8 local_port,
> void *port_driver_priv, struct net_device *dev)
> {
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h
>index b65a17d49e43..5d7d2ab6d155 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/core.h
>+++ b/drivers/net/ethernet/mellanox/mlxsw/core.h
>@@ -177,6 +177,11 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
> const unsigned char *switch_id,
> unsigned char switch_id_len);
> void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port);
>+int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
>+ void *port_driver_priv,
>+ const unsigned char *switch_id,
>+ unsigned char switch_id_len);
>+void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core);
> void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u8 local_port,
> void *port_driver_priv, struct net_device *dev);
> void mlxsw_core_port_ib_set(struct mlxsw_core *mlxsw_core, u8 local_port,
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>index 91e4792bb7e7..1fc73a9ad84d 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>@@ -3872,6 +3872,46 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
> mlxsw_core_port_fini(mlxsw_sp->core, local_port);
> }
>
>+static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
>+{
>+ struct mlxsw_sp_port *mlxsw_sp_port;
>+ int err;
>+
>+ mlxsw_sp_port = kzalloc(sizeof(*mlxsw_sp_port), GFP_KERNEL);
>+ if (!mlxsw_sp_port)
>+ return -ENOMEM;
>+
>+ mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
>+ mlxsw_sp_port->local_port = MLXSW_PORT_CPU_PORT;
>+
>+ mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = mlxsw_sp_port;
Assign this at the end of the function and avoid NULL assignment on
error path.
>+
>+ err = mlxsw_core_cpu_port_init(mlxsw_sp->core,
>+ mlxsw_sp_port,
>+ mlxsw_sp->base_mac,
>+ sizeof(mlxsw_sp->base_mac));
>+ if (err) {
>+ dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize core CPU port\n");
>+ goto err_core_cpu_port_init;
>+ }
>+
>+ return err;
>+
>+err_core_cpu_port_init:
>+ mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = NULL;
>+ kfree(mlxsw_sp_port);
>+ return err;
>+}
>+
>+static void mlxsw_sp_cpu_port_remove(struct mlxsw_sp *mlxsw_sp)
>+{
>+ struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[0];
s/0/MLXSW_PORT_CPU_PORT/
>+
>+ mlxsw_core_cpu_port_fini(mlxsw_sp->core);
>+ mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = NULL;
>+ kfree(mlxsw_sp_port);
>+}
>+
> static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u8 local_port)
> {
> return mlxsw_sp->ports[local_port] != NULL;
>@@ -3884,6 +3924,7 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
> for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
> if (mlxsw_sp_port_created(mlxsw_sp, i))
> mlxsw_sp_port_remove(mlxsw_sp, i);
>+ mlxsw_sp_cpu_port_remove(mlxsw_sp);
> kfree(mlxsw_sp->port_to_module);
> kfree(mlxsw_sp->ports);
> }
>@@ -3908,6 +3949,10 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
> goto err_port_to_module_alloc;
> }
>
>+ err = mlxsw_sp_cpu_port_create(mlxsw_sp);
>+ if (err)
>+ goto err_cpu_port_create;
>+
> for (i = 1; i < max_ports; i++) {
> /* Mark as invalid */
> mlxsw_sp->port_to_module[i] = -1;
>@@ -3931,6 +3976,8 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
> for (i--; i >= 1; i--)
> if (mlxsw_sp_port_created(mlxsw_sp, i))
> mlxsw_sp_port_remove(mlxsw_sp, i);
>+ mlxsw_sp_cpu_port_remove(mlxsw_sp);
>+err_cpu_port_create:
> kfree(mlxsw_sp->port_to_module);
> err_port_to_module_alloc:
> kfree(mlxsw_sp->ports);
>--
>2.21.0
>
next prev parent reply other threads:[~2019-09-13 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 13:07 [PATCH net-next 0/2] mlxsw: spectrum_buffers: Add the ability to query the CPU port's shared buffer Ido Schimmel
2019-09-12 13:07 ` [PATCH net-next 1/2] mlxsw: spectrum: Register CPU port with devlink Ido Schimmel
2019-09-13 8:02 ` Jiri Pirko [this message]
2019-09-13 9:06 ` Shalom Toledo
2019-09-12 13:07 ` [PATCH net-next 2/2] mlxsw: spectrum_buffers: Add the ability to query the CPU port's shared buffer Ido Schimmel
2019-09-13 8:17 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190913080223.GB2330@nanopsycho \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=idosch@idosch.org \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=shalomt@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).