From: Jiri Pirko <jiri@resnulli.us>
To: alejandro.lucero-palau@amd.com
Cc: netdev@vger.kernel.org, linux-net-drivers@amd.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, habetsm@gmail.com, ecree.xilinx@gmail.com
Subject: Re: [PATCH net-next 4/7] sfc: add devlink port support for ef100
Date: Thu, 19 Jan 2023 13:33:16 +0100 [thread overview]
Message-ID: <Y8k4jFnloCfylMUV@nanopsycho> (raw)
In-Reply-To: <20230119113140.20208-5-alejandro.lucero-palau@amd.com>
Thu, Jan 19, 2023 at 12:31:37PM CET, alejandro.lucero-palau@amd.com wrote:
>From: Alejandro Lucero <alejandro.lucero-palau@amd.com>
>
>Using the data when enumerating mports, create devlink ports just before
>netdevs are registered and removing those devlink ports after netdev has
>been unregister.
>
>Signed-off-by: Alejandro Lucero <alejandro.lucero-palau@amd.com>
>---
> drivers/net/ethernet/sfc/ef100_netdev.c | 14 ++-
> drivers/net/ethernet/sfc/ef100_rep.c | 23 +++++
> drivers/net/ethernet/sfc/ef100_rep.h | 6 ++
> drivers/net/ethernet/sfc/efx_devlink.c | 114 ++++++++++++++++++++++++
> drivers/net/ethernet/sfc/efx_devlink.h | 7 ++
> drivers/net/ethernet/sfc/net_driver.h | 1 +
> 6 files changed, 161 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c
>index ddcc325ed570..4a5d028f757e 100644
>--- a/drivers/net/ethernet/sfc/ef100_netdev.c
>+++ b/drivers/net/ethernet/sfc/ef100_netdev.c
>@@ -24,6 +24,7 @@
> #include "rx_common.h"
> #include "ef100_sriov.h"
> #include "tc_bindings.h"
>+#include "efx_devlink.h"
>
> static void ef100_update_name(struct efx_nic *efx)
> {
>@@ -280,6 +281,9 @@ static int ef100_register_netdev(struct efx_nic *efx)
> net_dev->max_mtu = EFX_MAX_MTU;
> net_dev->ethtool_ops = &ef100_ethtool_ops;
>
>+ if (!efx->type->is_vf)
>+ ef100_pf_set_devlink_port(efx);
Again, why no port for VF while you are at it?
>+
> rtnl_lock();
>
> rc = dev_alloc_name(net_dev, net_dev->name);
>@@ -302,6 +306,7 @@ static int ef100_register_netdev(struct efx_nic *efx)
>
> fail_locked:
> rtnl_unlock();
>+ ef100_pf_unset_devlink_port(efx);
> netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
> return rc;
> }
>@@ -312,6 +317,7 @@ static void ef100_unregister_netdev(struct efx_nic *efx)
> efx_fini_mcdi_logging(efx);
> efx->state = STATE_PROBED;
> unregister_netdev(efx->net_dev);
>+ ef100_pf_unset_devlink_port(efx);
> }
> }
>
>@@ -405,16 +411,16 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data)
> /* Don't fail init if RSS setup doesn't work. */
> efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels);
>
>- rc = ef100_register_netdev(efx);
>- if (rc)
>- goto fail;
>-
> if (!efx->type->is_vf) {
> rc = ef100_probe_netdev_pf(efx);
> if (rc)
> goto fail;
> }
>
>+ rc = ef100_register_netdev(efx);
>+ if (rc)
>+ goto fail;
>+
> efx->netdev_notifier.notifier_call = ef100_netdev_event;
> rc = register_netdevice_notifier(&efx->netdev_notifier);
> if (rc) {
>diff --git a/drivers/net/ethernet/sfc/ef100_rep.c b/drivers/net/ethernet/sfc/ef100_rep.c
>index 9cd1a3ac67e0..ff0c8da61919 100644
>--- a/drivers/net/ethernet/sfc/ef100_rep.c
>+++ b/drivers/net/ethernet/sfc/ef100_rep.c
>@@ -16,6 +16,7 @@
> #include "mae.h"
> #include "rx_common.h"
> #include "tc_bindings.h"
>+#include "efx_devlink.h"
>
> #define EFX_EF100_REP_DRIVER "efx_ef100_rep"
>
>@@ -297,6 +298,7 @@ int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i)
> i, rc);
> goto fail1;
> }
>+ ef100_rep_set_devlink_port(efv);
> rc = register_netdev(efv->net_dev);
> if (rc) {
> pci_err(efx->pci_dev,
>@@ -304,10 +306,12 @@ int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i)
> i, rc);
> goto fail2;
> }
>+
> pci_dbg(efx->pci_dev, "Representor for VF %d is %s\n", i,
> efv->net_dev->name);
> return 0;
> fail2:
>+ ef100_rep_unset_devlink_port(efv);
> efx_ef100_deconfigure_rep(efv);
> fail1:
> efx_ef100_rep_destroy_netdev(efv);
>@@ -323,6 +327,7 @@ void efx_ef100_vfrep_destroy(struct efx_nic *efx, struct efx_rep *efv)
> return;
> netif_dbg(efx, drv, rep_dev, "Removing VF representor\n");
> unregister_netdev(rep_dev);
>+ ef100_rep_unset_devlink_port(efv);
> efx_ef100_deconfigure_rep(efv);
> efx_ef100_rep_destroy_netdev(efv);
> }
>@@ -339,6 +344,24 @@ void efx_ef100_fini_vfreps(struct efx_nic *efx)
> efx_ef100_vfrep_destroy(efx, efv);
> }
>
>+bool ef100_mport_is_pcie_vnic(struct mae_mport_desc *mport_desc)
>+{
>+ return mport_desc->mport_type == MAE_MPORT_DESC_MPORT_TYPE_VNIC &&
>+ mport_desc->vnic_client_type == MAE_MPORT_DESC_VNIC_CLIENT_TYPE_FUNCTION;
>+}
>+
>+bool ef100_mport_on_local_intf(struct efx_nic *efx,
>+ struct mae_mport_desc *mport_desc)
>+{
>+ bool pcie_func;
>+ struct ef100_nic_data *nic_data = efx->nic_data;
Reverse christmas tree ordering please:
***************
*********
****
>+
>+ pcie_func = ef100_mport_is_pcie_vnic(mport_desc);
>+
>+ return nic_data->have_local_intf && pcie_func &&
>+ mport_desc->interface_idx == nic_data->local_mae_intf;
>+}
>+
> void efx_ef100_init_reps(struct efx_nic *efx)
> {
> struct ef100_nic_data *nic_data = efx->nic_data;
>diff --git a/drivers/net/ethernet/sfc/ef100_rep.h b/drivers/net/ethernet/sfc/ef100_rep.h
>index 328ac0cbb532..9cca41614982 100644
>--- a/drivers/net/ethernet/sfc/ef100_rep.h
>+++ b/drivers/net/ethernet/sfc/ef100_rep.h
>@@ -22,6 +22,8 @@ struct efx_rep_sw_stats {
> atomic64_t rx_dropped, tx_errors;
> };
>
>+struct devlink_port;
>+
> /**
> * struct efx_rep - Private data for an Efx representor
> *
>@@ -54,6 +56,7 @@ struct efx_rep {
> spinlock_t rx_lock;
> struct napi_struct napi;
> struct efx_rep_sw_stats stats;
>+ struct devlink_port *dl_port;
> };
>
> int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i);
>@@ -69,4 +72,7 @@ struct efx_rep *efx_ef100_find_rep_by_mport(struct efx_nic *efx, u16 mport);
> extern const struct net_device_ops efx_ef100_rep_netdev_ops;
> void efx_ef100_init_reps(struct efx_nic *efx);
> void efx_ef100_fini_reps(struct efx_nic *efx);
>+struct mae_mport_desc;
>+bool ef100_mport_on_local_intf(struct efx_nic *efx,
>+ struct mae_mport_desc *mport_desc);
> #endif /* EF100_REP_H */
>diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c
>index c506f8f35d25..bb19d3ad7ffd 100644
>--- a/drivers/net/ethernet/sfc/efx_devlink.c
>+++ b/drivers/net/ethernet/sfc/efx_devlink.c
>@@ -16,6 +16,8 @@
> #include "mcdi.h"
> #include "mcdi_functions.h"
> #include "mcdi_pcol.h"
>+#include "mae.h"
>+#include "ef100_rep.h"
>
> /* Custom devlink-info version object names for details that do not map to the
> * generic standardized names.
>@@ -381,6 +383,52 @@ struct efx_devlink {
> struct efx_nic *efx;
> };
>
>+static void efx_devlink_del_port(struct devlink_port *dl_port)
>+{
>+ if (!dl_port)
>+ return;
>+ devlink_port_unregister(dl_port);
>+ kfree(dl_port);
>+}
>+
>+static int efx_devlink_add_port(struct efx_nic *efx,
>+ struct mae_mport_desc *mport,
>+ struct devlink_port *dl_port)
>+{
>+ struct devlink_port_attrs attrs = {};
>+ bool external = false;
>+ int err;
>+
>+ if (!ef100_mport_on_local_intf(efx, mport))
>+ external = true;
>+
>+ switch (mport->mport_type) {
>+ case MAE_MPORT_DESC_MPORT_TYPE_NET_PORT:
>+ attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
>+ attrs.phys.port_number = mport->port_idx;
>+ devlink_port_attrs_set(dl_port, &attrs);
>+ break;
>+ case MAE_MPORT_DESC_MPORT_TYPE_VNIC:
>+ if (mport->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL) {
No need for {}'s in this if-else
>+ devlink_port_attrs_pci_vf_set(dl_port, 0, mport->pf_idx,
>+ mport->vf_idx,
>+ external);
>+ } else {
>+ devlink_port_attrs_pci_pf_set(dl_port, 0, mport->pf_idx,
>+ external);
>+ }
>+ break;
>+ default:
>+ /* MAE_MPORT_DESC_MPORT_ALIAS and UNDEFINED */
>+ return 0;
>+ }
>+
>+ dl_port->index = mport->mport_id;
>+ err = devlink_port_register(efx->devlink, dl_port, mport->mport_id);
Just return.
>+
>+ return err;
>+}
>+
> static int efx_devlink_info_get(struct devlink *devlink,
> struct devlink_info_req *req,
> struct netlink_ext_ack *extack)
>@@ -396,6 +444,72 @@ static const struct devlink_ops sfc_devlink_ops = {
> .info_get = efx_devlink_info_get,
> };
>
>+static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx)
>+{
>+ struct mae_mport_desc *mport;
>+ struct devlink_port *dl_port;
>+ u32 id;
>+
>+ if (efx_mae_lookup_mport(efx, idx, &id)) {
>+ /* This should not happen. */
>+ if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
>+ pci_warn(efx->pci_dev, "No mport ID found for PF.\n");
>+ else
>+ pci_warn(efx->pci_dev, "No mport ID found for VF %u.\n",
>+ idx);
>+ return NULL;
>+ }
>+
>+ mport = efx_mae_get_mport(efx, id);
>+ if (!mport) {
>+ /* This should not happen. */
>+ if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
>+ pci_warn(efx->pci_dev, "No mport found for PF.\n");
>+ else
>+ pci_warn(efx->pci_dev, "No mport found for VF %u.\n",
>+ idx);
>+ return NULL;
>+ }
>+
>+ dl_port = kzalloc(sizeof(*dl_port), GFP_KERNEL);
>+ if (!dl_port)
>+ return NULL;
>+
>+ if (efx_devlink_add_port(efx, mport, dl_port)) {
>+ if (idx == MAE_MPORT_DESC_VF_IDX_NULL)
>+ pci_warn(efx->pci_dev,
>+ "devlink port creation for PF failed.\n");
>+ else
>+ pci_warn(efx->pci_dev,
>+ "devlink_port creationg for VF %u failed.\n",
>+ idx);
>+ kfree(dl_port);
>+ return NULL;
>+ }
>+
>+ return dl_port;
>+}
>+
>+void ef100_rep_set_devlink_port(struct efx_rep *efv)
>+{
>+ efv->dl_port = ef100_set_devlink_port(efv->parent, efv->idx);
>+}
>+
>+void ef100_pf_set_devlink_port(struct efx_nic *efx)
>+{
>+ efx->dl_port = ef100_set_devlink_port(efx, MAE_MPORT_DESC_VF_IDX_NULL);
>+}
>+
>+void ef100_rep_unset_devlink_port(struct efx_rep *efv)
>+{
>+ efx_devlink_del_port(efv->dl_port);
>+}
>+
>+void ef100_pf_unset_devlink_port(struct efx_nic *efx)
>+{
>+ efx_devlink_del_port(efx->dl_port);
>+}
>+
> void efx_fini_devlink(struct efx_nic *efx)
> {
> if (efx->devlink) {
>diff --git a/drivers/net/ethernet/sfc/efx_devlink.h b/drivers/net/ethernet/sfc/efx_devlink.h
>index 997f878aea93..a834c393a9ad 100644
>--- a/drivers/net/ethernet/sfc/efx_devlink.h
>+++ b/drivers/net/ethernet/sfc/efx_devlink.h
>@@ -17,4 +17,11 @@
> int efx_probe_devlink(struct efx_nic *efx);
> void efx_fini_devlink(struct efx_nic *efx);
>
>+struct mae_mport_desc;
>+struct efx_rep;
>+
>+void ef100_pf_set_devlink_port(struct efx_nic *efx);
>+void ef100_rep_set_devlink_port(struct efx_rep *efv);
>+void ef100_pf_unset_devlink_port(struct efx_nic *efx);
>+void ef100_rep_unset_devlink_port(struct efx_rep *efv);
> #endif /* _EFX_DEVLINK_H */
>diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h
>index bc9efbfb3d6b..20f43695d082 100644
>--- a/drivers/net/ethernet/sfc/net_driver.h
>+++ b/drivers/net/ethernet/sfc/net_driver.h
>@@ -1185,6 +1185,7 @@ struct efx_nic {
> struct efx_tc_state *tc;
>
> struct devlink *devlink;
>+ struct devlink_port *dl_port;
> unsigned int mem_bar;
> u32 reg_base;
>
>--
>2.17.1
>
next prev parent reply other threads:[~2023-01-19 12:38 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 11:31 [PATCH net-next 0/7] sfc: devlink support for ef100 alejandro.lucero-palau
2023-01-19 11:31 ` [PATCH net-next 1/7] sfc: add " alejandro.lucero-palau
2023-01-19 12:14 ` Jiri Pirko
2023-01-19 14:51 ` Lucero Palau, Alejandro
2023-01-19 16:29 ` Lucero Palau, Alejandro
2023-01-20 11:02 ` Jiri Pirko
2023-01-20 11:00 ` Jiri Pirko
2023-01-19 15:50 ` kernel test robot
2023-01-19 17:16 ` Jakub Kicinski
2023-01-19 17:52 ` Lucero Palau, Alejandro
2023-01-19 18:44 ` Jakub Kicinski
2023-01-19 19:08 ` Lucero Palau, Alejandro
2023-01-19 23:40 ` Jacob Keller
2023-01-20 14:11 ` Lucero Palau, Alejandro
2023-01-24 6:13 ` Edward Cree
2023-01-24 7:31 ` Lucero Palau, Alejandro
2023-01-24 11:05 ` Lucero Palau, Alejandro
2023-01-24 22:12 ` Jacob Keller
2023-01-20 13:59 ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 2/7] sfc: enumerate mports in ef100 alejandro.lucero-palau
2023-01-19 23:48 ` Jacob Keller
2023-01-20 14:13 ` Lucero Palau, Alejandro
2023-01-20 12:47 ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 3/7] sfc: add mport lookup based on driver's mport data alejandro.lucero-palau
2023-01-19 23:57 ` Jacob Keller
2023-01-20 9:34 ` Lucero Palau, Alejandro
2023-01-20 18:36 ` Keller, Jacob E
2023-01-19 11:31 ` [PATCH net-next 4/7] sfc: add devlink port support for ef100 alejandro.lucero-palau
2023-01-19 12:33 ` Jiri Pirko [this message]
2023-01-19 15:03 ` Lucero Palau, Alejandro
2023-01-19 13:37 ` kernel test robot
2023-01-20 21:21 ` kernel test robot
2023-01-19 11:31 ` [PATCH net-next 5/7] sfc: obtain device mac address based on firmware handle " alejandro.lucero-palau
2023-01-19 19:47 ` kernel test robot
2023-01-20 0:03 ` Jacob Keller
2023-01-19 11:31 ` [PATCH net-next 6/7] sfc: add support for port_function_hw_addr_get devlink in ef100 alejandro.lucero-palau
2023-01-19 12:25 ` Jiri Pirko
2023-01-19 14:59 ` Lucero Palau, Alejandro
2023-01-20 11:05 ` Jiri Pirko
2023-01-22 16:41 ` Lucero Palau, Alejandro
2023-01-19 12:37 ` Jiri Pirko
2023-01-19 15:09 ` Lucero Palau, Alejandro
2023-01-20 11:08 ` Jiri Pirko
2023-01-20 12:48 ` Lucero Palau, Alejandro
2023-01-22 16:36 ` Lucero Palau, Alejandro
2023-01-23 8:38 ` Jiri Pirko
2023-01-23 9:45 ` Lucero Palau, Alejandro
2023-01-23 10:18 ` Jiri Pirko
2023-01-19 11:31 ` [PATCH net-next 7/7] sfc: add support for devlink port_function_hw_addr_set " alejandro.lucero-palau
2023-01-19 12:27 ` Jiri Pirko
2023-01-19 15:10 ` Lucero Palau, Alejandro
2023-01-20 8:55 ` [PATCH net-next 0/7] sfc: devlink support for ef100 Martin Habets
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=Y8k4jFnloCfylMUV@nanopsycho \
--to=jiri@resnulli.us \
--cc=alejandro.lucero-palau@amd.com \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=habetsm@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-net-drivers@amd.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.