mlx5 External sub function controller
Subsystems (5)
From: Saeed Mahameed <[email protected]>
Hi Dave, Jakub,
This adds the support to instantiate Sub-Functions on external hosts.
changelog:v1->v2:
- fixed unused variable warning
For more information please see tag log below.
Please pull and let me know if there is any problem.
Thanks,
Saeed.
---
The following changes since commit b2f0ca00e6b34bd57c9298a869ea133699e8ec39:
phy: nxp-c45-tja11xx: add interrupt support (2021-04-23 14:13:16 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-updates-2021-04-21
for you to fetch changes up to f1b9acd3a5e800bb68e7b8abc5b56d01faf68bbc:
net/mlx5: SF, Extend SF table for additional SF id range (2021-04-24 00:59:07 -0700)
----------------------------------------------------------------
mlx5-updates-2021-04-21
devlink external port attribute for SF (Sub-Function) port flavour
This adds the support to instantiate Sub-Functions on external hosts E.g when Eswitch manager is enabled on the ARM SmarNic SoC CPU, users are now able to spawn new Sub-Functions on the Host server CPU.
Parav Pandit Says:
==================
This series introduces and uses external attribute for the SF port to indicate that a SF port belongs to an external controller.
This is needed to generate unique phys_port_name when PF and SF numbers are overlapping between local and external controllers.
For example two controllers 0 and 1, both of these controller have a SF. having PF number 0, SF number 77. Here, phys_port_name has duplicate entry which doesn't have controller number in it.
Hence, add controller number optionally when a SF port is for an external controller. This extension is similar to existing PF and VF eswitch ports of the external controller.
When a SF is for external controller an example view of external SF port and config sequence:
On eswitch system:
$ devlink dev eswitch set pci/0033:01:00.0 mode switchdev
$ devlink port show
pci/0033:01:00.0/196607: type eth netdev enP51p1s0f0np0 flavour physical port 0 splittable false
pci/0033:01:00.0/131072: type eth netdev eth0 flavour pcipf controller 1 pfnum 0 external true splittable false
function:
hw_addr 00:00:00:00:00:00$ devlink port add pci/0033:01:00.0 flavour pcisf pfnum 0 sfnum 77 controller 1
pci/0033:01:00.0/163840: type eth netdev eth1 flavour pcisf controller 1 pfnum 0 sfnum 77 splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detachedphys_port_name construction:
$ cat /sys/class/net/eth1/phys_port_name c1pf0sf77
Patch summary:
First 3 patches prepares the eswitch to handle vports in more generic way using xarray to lookup vport from its unique vport number. Patch-1 returns maximum eswitch ports only when eswitch is enabled Patch-2 prepares eswitch to return eswitch max ports from a struct Patch-3 uses xarray for vport and representor lookup Patch-4 considers SF for an additioanl range of SF vports Patch-5 relies on SF hw table to check SF support
Patch-6 extends SF devlink port attribute for external flag Patch-7 stores the per controller SF allocation attributes Patch-8 uses SF function id for filtering events
Patch-9 uses helper for allocation and free
Patch-10 splits hw table into per controller table and generic one Patch-11 extends sf table for additional range
==================
----------------------------------------------------------------
Parav Pandit (11):
net/mlx5: E-Switch, Return eswitch max ports when eswitch is supported net/mlx5: E-Switch, Prepare to return total vports from eswitch struct net/mlx5: E-Switch, Use xarray for vport number to vport and rep mapping net/mlx5: E-Switch, Consider SF ports of host PF
net/mlx5: SF, Rely on hw table for SF devlink port allocation
devlink: Extend SF port attributes to have external attribute net/mlx5: SF, Store and use start function id
net/mlx5: SF, Consider own vhca events of SF devices net/mlx5: SF, Use helpers for allocation and free
net/mlx5: SF, Split mlx5_sf_hw_table into two parts net/mlx5: SF, Extend SF table for additional SF id range
.../mellanox/mlx5/core/esw/acl/egress_lgcy.c | 2 +- .../mellanox/mlx5/core/esw/acl/egress_ofld.c | 4 +- .../ethernet/mellanox/mlx5/core/esw/acl/helper.c | 8 +- .../ethernet/mellanox/mlx5/core/esw/acl/helper.h | 2 +- .../mellanox/mlx5/core/esw/acl/ingress_lgcy.c | 2 +- .../mellanox/mlx5/core/esw/acl/ingress_ofld.c | 4 +- .../ethernet/mellanox/mlx5/core/esw/devlink_port.c | 7 +- .../net/ethernet/mellanox/mlx5/core/esw/legacy.c | 3 +- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 276 +++++++++++++++---- drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 193 +++----------- .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 293 ++++++++++++++------- .../net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 12 +- .../net/ethernet/mellanox/mlx5/core/sf/devlink.c | 38 +-- .../net/ethernet/mellanox/mlx5/core/sf/hw_table.c | 256 +++++++++++++----- drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h | 9 +- drivers/net/ethernet/mellanox/mlx5/core/vport.c | 14 - include/linux/mlx5/eswitch.h | 11 +- include/linux/mlx5/vport.h | 8 - include/net/devlink.h | 5 +- net/core/devlink.c | 11 +- 20 files changed, 724 insertions(+), 434 deletions(-)
PATCH v2 1/11 net/mlx5: E-Switch, Return eswitch max ports when eswitch is supported
From: Parav Pandit <[email protected]>
mlx5_eswitch_get_total_vports() doesn't honor MLX5_ESWICH Kconfig flag.
When MLX5_ESWITCH is disabled, FS layer continues to initialize eswitch specific ACL namespaces.
Instead, start honoring MLX5_ESWITCH flag and perform vport specific initialization only when vport count is non zero.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 13 +++++++++++++ drivers/net/ethernet/mellanox/mlx5/core/vport.c | 14 -------------- include/linux/mlx5/eswitch.h | 11 +++++++++-- 3 files changed, 22 insertions(+), 16 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +13 -0
@@ -2205,3 +2205,16 @@ void mlx5_esw_unlock(struct mlx5_eswitch *esw) {up_write (&esw->mode_lock); } + +/** +* mlx5_eswitch_get_total_vports - Get total vports of the eswitch +* +* @dev: Pointer to core device +* +* mlx5_eswitch_get_total_vports returns total number of eswitch vports. +*/ +u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev) +{ +return MLX5_SPECIAL_VPORTS (dev) +mlx5_core_max_vfs (dev) +mlx5_sf_max_functions (dev); +} +EXPORT_SYMBOL_GPL (mlx5_eswitch_get_total_vports);
drivers/net/ethernet/mellanox/mlx5/core/vport.c +0 -14
@@ -1151,20 +1151,6 @@ u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev) }EXPORT_SYMBOL_GPL (mlx5_query_nic_system_image_guid); -/** -* mlx5_eswitch_get_total_vports - Get total vports of the eswitch -* -* @dev: Pointer to core device -* -* mlx5_eswitch_get_total_vports returns total number of vports for -* the eswitch. -*/ -u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev) -{ -return MLX5_SPECIAL_VPORTS (dev) +mlx5_core_max_vfs (dev) +mlx5_sf_max_functions (dev); -} -EXPORT_SYMBOL_GPL (mlx5_eswitch_get_total_vports); -int mlx5_vport_get_other_func_cap (struct mlx5_core_dev *dev,u16 function_id,void *out) {u16 opmod = (MLX5_CAP_GENERAL <<1 ) | (HCA_CAP_OPMOD_GET_MAX &0x01 );
include/linux/mlx5/eswitch.h +9 -2
@@ -65,8 +65,6 @@ struct mlx5_flow_handle * mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *on_esw, struct mlx5_eswitch_rep *rep, u32 sqn); -u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev); -#ifdef CONFIG_MLX5_ESWITCH enum devlink_eswitch_encap_mode mlx5_eswitch_get_encap_mode (const struct mlx5_core_dev *dev);
@@ -126,6 +124,8 @@ u32 mlx5_eswitch_get_vport_metadata_for_set(struct mlx5_eswitch *esw,#define ESW_TUN_SLOW_TABLE_GOTO_VPORT_MARK ESW_TUN_OPTS_MASKu8 mlx5_eswitch_mode (struct mlx5_core_dev *dev); +u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev); +#else /* CONFIG_MLX5_ESWITCH */ static inline u8 mlx5_eswitch_mode (struct mlx5_core_dev *dev)
@@ -162,10 +162,17 @@ mlx5_eswitch_get_vport_metadata_mask(void) {return 0 ; } + +static inline u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev) +{ +return 0 ; +} +#endif /* CONFIG_MLX5_ESWITCH */ static inline bool is_mdev_switchdev_mode (struct mlx5_core_dev *dev) {return mlx5_eswitch_mode (dev) ==MLX5_ESWITCH_OFFLOADS ; } +#endif
Signature · 1 line
2.30.2
Re: [net-next V2 01/11] net/mlx5: E-Switch, Return eswitch max ports when eswitch is supported
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Sat, 24 Apr 2021 01:01:05 -0700 you wrote:
From: Parav Pandit <[email protected]>
mlx5_eswitch_get_total_vports()doesn't honorMLX5_ESWICHKconfigflag.When
MLX5_ESWITCHis disabled, FS layer continues to initialize eswitch specific ACL namespaces.
Instead, start honoringMLX5_ESWITCHflag and perform vport specific initialization only when vport count is non zero.[...]
Here is the summary with links:
- [net-next,V2,01/11] net/mlx5: E-Switch, Return eswitch max ports when eswitch is supported
https://git.kernel.org/netdev/net-next/c/06ec5acc7747 - [net-next,V2,02/11] net/mlx5: E-Switch, Prepare to return total vports from eswitch struct https://git.kernel.org/netdev/net-next/c/9f8c7100c8f9 - [net-next,V2,03/11] net/mlx5: E-Switch, Use xarray for vport number to vport and rep mapping https://git.kernel.org/netdev/net-next/c/47dd7e609f69 - [net-next,V2,04/11] net/mlx5: E-Switch, Consider SF ports of host PF https://git.kernel.org/netdev/net-next/c/87bd418ea751 - [net-next,V2,05/11] net/mlx5: SF, Rely on hw table for SF devlink port allocation https://git.kernel.org/netdev/net-next/c/1d7979352f9f - [net-next,V2,06/11] devlink: Extend SF port attributes to have external attribute https://git.kernel.org/netdev/net-next/c/a1ab3e4554b5 - [net-next,V2,07/11] net/mlx5: SF, Store and use start function id https://git.kernel.org/netdev/net-next/c/7e6ccbc18784 - [net-next,V2,08/11] net/mlx5: SF, Consider own vhca events of SF devices https://git.kernel.org/netdev/net-next/c/326c08a02034 - [net-next,V2,09/11] net/mlx5: SF, Use helpers for allocation and free https://git.kernel.org/netdev/net-next/c/01ed9550e8b4 - [net-next,V2,10/11] net/mlx5: SF, Split mlx5_sf_hw_table into two parts https://git.kernel.org/netdev/net-next/c/a3088f87d984 - [net-next,V2,11/11] net/mlx5: SF, Extend SF table for additional SF id range https://git.kernel.org/netdev/net-next/c/f1b9acd3a5e8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
PATCH v2 2/11 net/mlx5: E-Switch, Prepare to return total vports from eswitch struct
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Total vports are already stored during eswitch initialization. Instead of calculating everytime, read directly from eswitch.
Additionally, host PF's SF vport information is available using QUERY_HCA_CAP command. It is not available through HCA_CAP of the eswitch manager PF.
Hence, this patch prepares the return total eswitch vport count from the existing eswitch struct.
This further helps to keep eswitch port counting macros and logic within eswitch.
--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 9 ++++++--- drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 8 ++++++++ include/linux/mlx5/vport.h | 8 -------- 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +6 -3
@@ -1573,8 +1573,8 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)if (!MLX5_VPORT_MANAGER (dev))return 0 ; - total_vports =mlx5_eswitch_get_total_vports (dev); - + total_vports =MLX5_SPECIAL_VPORTS (dev) +mlx5_core_max_vfs (dev) + +mlx5_sf_max_functions (dev); esw_info(dev, "Total vports %d, per vport: max uc(%d) max mc(%d)\n", total_vports,
@@ -2215,6 +2215,9 @@ void mlx5_esw_unlock(struct mlx5_eswitch *esw)*/ u16 mlx5_eswitch_get_total_vports (const struct mlx5_core_dev *dev) { -return MLX5_SPECIAL_VPORTS (dev) +mlx5_core_max_vfs (dev) +mlx5_sf_max_functions (dev); +struct mlx5_eswitch *esw; + + esw = dev->priv.eswitch; +return mlx5_esw_allowed (esw) ? esw->total_vports :0 ; }EXPORT_SYMBOL_GPL (mlx5_eswitch_get_total_vports);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +8 -0
@@ -545,6 +545,14 @@ static inline u16 mlx5_eswitch_first_host_vport_num(struct mlx5_core_dev *dev) MLX5_VPORT_PF :MLX5_VPORT_FIRST_VF ; } +#define MLX5_VPORT_PF_PLACEHOLDER (1u) +#define MLX5_VPORT_UPLINK_PLACEHOLDER (1u) +#define MLX5_VPORT_ECPF_PLACEHOLDER (mdev) (mlx5_ecpf_vport_exists(mdev)) + +#define MLX5_SPECIAL_VPORTS (mdev) (MLX5_VPORT_PF_PLACEHOLDER + \ + MLX5_VPORT_UPLINK_PLACEHOLDER + \ + MLX5_VPORT_ECPF_PLACEHOLDER(mdev)) +static inline int mlx5_esw_sf_start_idx (const struct mlx5_eswitch *esw) {/* PF and VF vports indices start from 0 to max_vfs */
include/linux/mlx5/vport.h +0 -8
@@ -36,14 +36,6 @@#include <linux/mlx5/driver.h> #include <linux/mlx5/device.h> -#define MLX5_VPORT_PF_PLACEHOLDER (1u) -#define MLX5_VPORT_UPLINK_PLACEHOLDER (1u) -#define MLX5_VPORT_ECPF_PLACEHOLDER (mdev) (mlx5_ecpf_vport_exists(mdev)) - -#define MLX5_SPECIAL_VPORTS (mdev) (MLX5_VPORT_PF_PLACEHOLDER + \ - MLX5_VPORT_UPLINK_PLACEHOLDER + \ - MLX5_VPORT_ECPF_PLACEHOLDER(mdev)) -#define MLX5_VPORT_MANAGER (mdev) \ (MLX5_CAP_GEN(mdev, vport_group_manager) && \ (MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) && \
Signature · 1 line
2.30.2
PATCH v2 3/11 net/mlx5: E-Switch, Use xarray for vport number to vport and rep mapping
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Currently vport number to vport and its representor are mapped using an array and an index.
Vport numbers of different types of functions are not contiguous. Adding new such discontiguous range using index and number mapping is increasingly complex and hard to maintain.
Hence, maintain an xarray of vport and rep whose lookup is done based on the vport number.
Each VF and SF entry is marked with a xarray mark to identify the function type. Additionally PF and VF needs special handling for legacy inline mode. They are additionally marked as host function using additional HOST_FN mark.
--- .../mellanox/mlx5/core/esw/acl/egress_lgcy.c | 2 +- .../mellanox/mlx5/core/esw/acl/egress_ofld.c | 4 +- .../mellanox/mlx5/core/esw/acl/helper.c | 8 +- .../mellanox/mlx5/core/esw/acl/helper.h | 2 +- .../mellanox/mlx5/core/esw/acl/ingress_lgcy.c | 2 +- .../mellanox/mlx5/core/esw/acl/ingress_ofld.c | 4 +- .../mellanox/mlx5/core/esw/devlink_port.c | 3 +- .../ethernet/mellanox/mlx5/core/esw/legacy.c | 3 +- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 205 +++++++++---- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 194 ++---------- .../mellanox/mlx5/core/eswitch_offloads.c | 276 ++++++++++++------ 11 files changed, 380 insertions(+), 323 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/egress_lgcy.c +1 -1
@@ -96,7 +96,7 @@ int esw_acl_egress_lgcy_setup(struct mlx5_eswitch *esw, }if (!vport->egress.acl) { - vport->egress.acl =esw_acl_table_create (esw, vport->vport, + vport->egress.acl =esw_acl_table_create (esw, vport,MLX5_FLOW_NAMESPACE_ESW_EGRESS , table_size);if (IS_ERR (vport->egress.acl)) {
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/egress_ofld.c +2 -2
@@ -148,7 +148,7 @@ static void esw_acl_egress_ofld_groups_destroy(struct mlx5_vport *vport)esw_acl_egress_vlan_grp_destroy (vport); } -static bool esw_acl_egress_needed (const struct mlx5_eswitch *esw,u16 vport_num) +static bool esw_acl_egress_needed (struct mlx5_eswitch *esw,u16 vport_num) {return mlx5_eswitch_is_vf_vport (esw, vport_num) ||mlx5_esw_is_sf_vport (esw, vport_num); }
@@ -171,7 +171,7 @@ int esw_acl_egress_ofld_setup(struct mlx5_eswitch *esw, struct mlx5_vport *vport table_size++;if (MLX5_CAP_GEN (esw->dev, prio_tag_required)) table_size++; - vport->egress.acl =esw_acl_table_create (esw, vport->vport, + vport->egress.acl =esw_acl_table_create (esw, vport,MLX5_FLOW_NAMESPACE_ESW_EGRESS , table_size);if (IS_ERR (vport->egress.acl)) { err =PTR_ERR (vport->egress.acl);
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/helper.c +4 -4
@@ -6,14 +6,14 @@#include "helper.h" struct mlx5_flow_table * -esw_acl_table_create (struct mlx5_eswitch *esw,u16 vport_num,int ns,int size) +esw_acl_table_create (struct mlx5_eswitch *esw,struct mlx5_vport *vport,int ns,int size) {struct mlx5_flow_table_attr ft_attr = {};struct mlx5_core_dev *dev = esw->dev;struct mlx5_flow_namespace *root_ns;struct mlx5_flow_table *acl;int acl_supported; -int vport_index; +u16 vport_num;int err; acl_supported = (ns == MLX5_FLOW_NAMESPACE_ESW_INGRESS) ?
@@ -23,11 +23,11 @@ esw_acl_table_create(struct mlx5_eswitch *esw, u16 vport_num, int ns, int size)if (!acl_supported)return ERR_PTR (-EOPNOTSUPP ); + vport_num = vport->vport;esw_debug (dev,"Create vport[%d] %s ACL table\n" , vport_num, ns ==MLX5_FLOW_NAMESPACE_ESW_INGRESS ?"ingress" :"egress" ); - vport_index =mlx5_eswitch_vport_num_to_index (esw, vport_num); - root_ns =mlx5_get_flow_vport_acl_namespace (dev, ns, vport_index); + root_ns =mlx5_get_flow_vport_acl_namespace (dev, ns, vport->index);if (!root_ns) {esw_warn (dev,"Failed to get E-Switch root namespace for vport (%d)\n" , vport_num);
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/helper.h +1 -1
@@ -8,7 +8,7 @@/* General acl helper functions */ struct mlx5_flow_table * -esw_acl_table_create (struct mlx5_eswitch *esw,u16 vport_num,int ns,int size); +esw_acl_table_create (struct mlx5_eswitch *esw,struct mlx5_vport *vport,int ns,int size);/* Egress acl helper functions */ void esw_acl_egress_table_destroy (struct mlx5_vport *vport);
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/ingress_lgcy.c +1 -1
@@ -177,7 +177,7 @@ int esw_acl_ingress_lgcy_setup(struct mlx5_eswitch *esw, }if (!vport->ingress.acl) { - vport->ingress.acl =esw_acl_table_create (esw, vport->vport, + vport->ingress.acl =esw_acl_table_create (esw, vport,MLX5_FLOW_NAMESPACE_ESW_INGRESS , table_size);if (IS_ERR (vport->ingress.acl)) {
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/ingress_ofld.c +2 -2
@@ -7,7 +7,7 @@#include "ofld.h" static bool -esw_acl_ingress_prio_tag_enabled (const struct mlx5_eswitch *esw, +esw_acl_ingress_prio_tag_enabled (struct mlx5_eswitch *esw,const struct mlx5_vport *vport) { return (MLX5_CAP_GEN(esw->dev, prio_tag_required) &&
@@ -255,7 +255,7 @@ int esw_acl_ingress_ofld_setup(struct mlx5_eswitch *esw,if (esw_acl_ingress_prio_tag_enabled (esw, vport)) num_ftes++; - vport->ingress.acl =esw_acl_table_create (esw, vport->vport, + vport->ingress.acl =esw_acl_table_create (esw, vport,MLX5_FLOW_NAMESPACE_ESW_INGRESS , num_ftes);if (IS_ERR (vport->ingress.acl)) {
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +1 -2
@@ -14,8 +14,7 @@ mlx5_esw_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_item_imemcpy (ppid->id, &parent_id,sizeof (parent_id)); } -static bool -mlx5_esw_devlink_port_supported (const struct mlx5_eswitch *esw,u16 vport_num) +static bool mlx5_esw_devlink_port_supported (struct mlx5_eswitch *esw,u16 vport_num) {return vport_num ==MLX5_VPORT_UPLINK || (mlx5_core_is_ecpf(esw->dev) && vport_num == MLX5_VPORT_PF) ||
drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c +2 -1
@@ -216,7 +216,8 @@ static void esw_destroy_legacy_table(struct mlx5_eswitch *esw)int esw_legacy_enable (struct mlx5_eswitch *esw) {struct mlx5_vport *vport; -int ret, i; +unsigned long i; +int ret; ret =esw_create_legacy_table (esw);if (ret)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +153 -52
318 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +32 -162
236 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +181 -95
515 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v2 4/11 net/mlx5: E-Switch, Consider SF ports of host PF
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Query SF vports count and base id of host PF from the firmware.
Account these ports in the total port calculation whenever it is non zero.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 55 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + 2 files changed, 56 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +55 -0
@@ -1566,6 +1566,48 @@ void mlx5_eswitch_disable(struct mlx5_eswitch *esw, bool clear_vf)up_write (&esw->mode_lock); } +static int mlx5_query_hca_cap_host_pf (struct mlx5_core_dev *dev,void *out) +{ +u16 opmod = (MLX5_CAP_GENERAL <<1 ) | (HCA_CAP_OPMOD_GET_MAX &0x01 ); +u8 in[MLX5_ST_SZ_BYTES (query_hca_cap_in)] = {}; + +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, opmod); +MLX5_SET (query_hca_cap_in, in, function_id,MLX5_VPORT_PF ); +MLX5_SET (query_hca_cap_in, in, other_function, true); +return mlx5_cmd_exec_inout (dev, query_hca_cap, in, out); +} + +int mlx5_esw_sf_max_hpf_functions (struct mlx5_core_dev *dev,u16 *max_sfs,u16 *sf_base_id) + +{ +int query_out_sz =MLX5_ST_SZ_BYTES (query_hca_cap_out); +void *query_ctx; +void *hca_caps; +int err; + +if (!mlx5_core_is_ecpf (dev)) { + *max_sfs =0 ; +return 0 ; + } + + query_ctx =kzalloc (query_out_sz,GFP_KERNEL ); +if (!query_ctx) +return -ENOMEM ; + + err =mlx5_query_hca_cap_host_pf (dev, query_ctx); +if (err) + goto out_free; + + hca_caps =MLX5_ADDR_OF (query_hca_cap_out, query_ctx, capability); + *max_sfs =MLX5_GET (cmd_hca_cap, hca_caps, max_num_sf); + *sf_base_id =MLX5_GET (cmd_hca_cap, hca_caps, sf_base_id); + +out_free: +kfree (query_ctx); +return err; +} +static int mlx5_esw_vport_alloc (struct mlx5_eswitch *esw,struct mlx5_core_dev *dev,int index,u16 vport_num) {
@@ -1612,6 +1654,7 @@ static void mlx5_esw_vports_cleanup(struct mlx5_eswitch *esw)static int mlx5_esw_vports_init (struct mlx5_eswitch *esw) {struct mlx5_core_dev *dev = esw->dev; +u16 max_host_pf_sfs;u16 base_sf_num;int idx =0 ;int err;
@@ -1642,6 +1685,18 @@ static int mlx5_esw_vports_init(struct mlx5_eswitch *esw)xa_set_mark (&esw->vports, base_sf_num + i,MLX5_ESW_VPT_SF ); idx++; } + + err =mlx5_esw_sf_max_hpf_functions (dev, &max_host_pf_sfs, &base_sf_num); +if (err) + goto err; +for (i =0 ; i < max_host_pf_sfs; i++) { + err =mlx5_esw_vport_alloc (esw, dev, idx, base_sf_num + i); +if (err) + goto err; +xa_set_mark (&esw->vports, base_sf_num + i,MLX5_ESW_VPT_SF ); + idx++; + } +if (mlx5_ecpf_vport_exists (dev)) { err =mlx5_esw_vport_alloc (esw, dev, idx,MLX5_VPORT_ECPF );if (err)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -668,6 +668,7 @@ void mlx5_esw_devlink_sf_port_unregister(struct mlx5_eswitch *esw, u16 vport_numint mlx5_esw_offloads_sf_vport_enable (struct mlx5_eswitch *esw,struct devlink_port *dl_port,u16 vport_num,u32 sfnum);void mlx5_esw_offloads_sf_vport_disable (struct mlx5_eswitch *esw,u16 vport_num); +int mlx5_esw_sf_max_hpf_functions (struct mlx5_core_dev *dev,u16 *max_sfs,u16 *sf_base_id);int mlx5_esw_vport_vhca_id_set (struct mlx5_eswitch *esw,u16 vport_num);void mlx5_esw_vport_vhca_id_clear (struct mlx5_eswitch *esw,u16 vport_num);
Signature · 1 line
2.30.2
PATCH v2 5/11 net/mlx5: SF, Rely on hw table for SF devlink port allocation
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Supporting SF allocation is currently checked at two places:
(a) SF devlink port allocator and
(b) SF HW table handler.
Both layers are using HCA CAP to identify it using helper routine mlx5_sf_supported() and mlx5_sf_max_functions().
Instead, rely on the HW table handler to check if SF is supported or not.
--- drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c | 9 ++------- drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c | 7 ++++++- drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h | 1 + 3 files changed, 9 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +2 -7
@@ -437,9 +437,6 @@ static int mlx5_sf_vhca_event(struct notifier_block *nb, unsigned long opcode, vstatic void mlx5_sf_table_enable (struct mlx5_sf_table *table) { -if (!mlx5_sf_max_functions (table->dev)) -return ; -init_completion (&table->disable_complete);refcount_set (&table->refcount,1 ); }
@@ -462,9 +459,6 @@ static void mlx5_sf_deactivate_all(struct mlx5_sf_table *table)static void mlx5_sf_table_disable (struct mlx5_sf_table *table) { -if (!mlx5_sf_max_functions (table->dev)) -return ; -if (!refcount_read (&table->refcount))return ;
@@ -498,7 +492,8 @@ static int mlx5_sf_esw_event(struct notifier_block *nb, unsigned long event, voistatic bool mlx5_sf_table_supported (const struct mlx5_core_dev *dev) { -return dev->priv.eswitch &&MLX5_ESWITCH_MANAGER (dev) &&mlx5_sf_supported (dev); +return dev->priv.eswitch &&MLX5_ESWITCH_MANAGER (dev) && +mlx5_sf_hw_table_supported (dev); }int mlx5_sf_table_init (struct mlx5_core_dev *dev)
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +6 -1
@@ -41,7 +41,7 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 usr_sfnum)int err;int i; -if (!table->max_local_functions) +if (!table || !table->max_local_functions)return -EOPNOTSUPP ;mutex_lock (&table->table_lock);
@@ -230,3 +230,8 @@ void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev)/* Dealloc SFs whose firmware event has been missed. */ mlx5_sf_hw_dealloc_all (table); } + +bool mlx5_sf_hw_table_supported (const struct mlx5_core_dev *dev) +{ +return !!dev->priv.sf_hw_table; +}
drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h +1 -0
@@ -17,5 +17,6 @@ u16 mlx5_sf_sw_to_hw_id(const struct mlx5_core_dev *dev, u16 sw_id);int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum);void mlx5_sf_hw_table_sf_free (struct mlx5_core_dev *dev,u16 id);void mlx5_sf_hw_table_sf_deferred_free (struct mlx5_core_dev *dev,u16 id); +bool mlx5_sf_hw_table_supported (const struct mlx5_core_dev *dev);#endif
Signature · 1 line
2.30.2
PATCH v2 6/11 devlink: Extend SF port attributes to have external attribute
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Extended SF port attributes to have optional external flag similar to PCI PF and VF port attributes.
External atttibute is required to generate unique phys_port_name when PF number and SF number are overlapping between two controllers similar to SR-IOV VFs.
When a SF is for external controller an example view of external SF port and config sequence.
On eswitch system:
$ devlink dev eswitch set pci/0033:01:00.0 mode switchdev
$ devlink port show
pci/0033:01:00.0/196607: type eth netdev enP51p1s0f0np0 flavour physical port 0 splittable false
pci/0033:01:00.0/131072: type eth netdev eth0 flavour pcipf controller 1 pfnum 0 external true splittable false
function:
hw_addr 00:00:00:00:00:00$ devlink port add pci/0033:01:00.0 flavour pcisf pfnum 0 sfnum 77 controller 1
pci/0033:01:00.0/163840: type eth netdev eth1 flavour pcisf controller 1 pfnum 0 sfnum 77 splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detachedphys_port_name construction:
$ cat /sys/class/net/eth1/phys_port_name c1pf0sf77
--- .../ethernet/mellanox/mlx5/core/esw/devlink_port.c | 2 +- include/net/devlink.h | 5 ++++- net/core/devlink.c | 11 ++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +1 -1
@@ -141,7 +141,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_pmlx5_esw_get_port_parent_id (dev, &ppid);memcpy (dl_port->attrs.switch_id.id, &ppid.id[0 ], ppid.id_len); dl_port->attrs.switch_id.id_len = ppid.id_len; -devlink_port_attrs_pci_sf_set (dl_port,0 , pfnum, sfnum); +devlink_port_attrs_pci_sf_set (dl_port,0 , pfnum, sfnum, false); devlink =priv_to_devlink (dev); dl_port_index =mlx5_esw_vport_to_devlink_port_index (dev, vport_num); err =devlink_port_register (devlink, dl_port, dl_port_index);
include/net/devlink.h +4 -1
@@ -98,11 +98,13 @@ struct devlink_port_pci_vf_attrs {* @controller: Associated controller number * @sf: Associated PCI SF for of the PCI PF for this port. * @pf: Associated PCI PF number for this port. +* @external: when set, indicates if a port is for an external controller */ struct devlink_port_pci_sf_attrs {u32 controller;u32 sf;u16 pf; +u8 external:1 ; };/**
@@ -1508,7 +1510,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controvoid devlink_port_attrs_pci_vf_set (struct devlink_port *devlink_port,u32 controller,u16 pf,u16 vf,bool external);void devlink_port_attrs_pci_sf_set (struct devlink_port *devlink_port, -u32 controller,u16 pf,u32 sf); +u32 controller,u16 pf,u32 sf, +bool external); 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,
net/core/devlink.c +10 -1
@@ -8599,9 +8599,10 @@ EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);* @controller: associated controller number for the devlink port instance * @pf: associated PF for the devlink port instance * @sf: associated SF of a PF for the devlink port instance +* @external: indicates if the port is for an external controller */ void devlink_port_attrs_pci_sf_set (struct devlink_port *devlink_port,u32 controller, -u16 pf,u32 sf) +u16 pf,u32 sf,bool external) {struct devlink_port_attrs *attrs = &devlink_port->attrs;int ret;
@@ -8615,6 +8616,7 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro attrs->pci_sf.controller = controller; attrs->pci_sf.pf = pf; attrs->pci_sf.sf = sf; + attrs->pci_sf.external = external; }EXPORT_SYMBOL_GPL (devlink_port_attrs_pci_sf_set);
@@ -8667,6 +8669,13 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, attrs->pci_vf.pf, attrs->pci_vf.vf);break ;case DEVLINK_PORT_FLAVOUR_PCI_SF : +if (attrs->pci_sf.external) { + n =snprintf (name, len,"c%u" , attrs->pci_sf.controller); +if (n >= len) +return -EINVAL ; + len -= n; + name += n; + } n =snprintf (name, len,"pf%usf%u" , attrs->pci_sf.pf, attrs->pci_sf.sf);break ;
Signature · 1 line
2.30.2
PATCH v2 7/11 net/mlx5: SF, Store and use start function id
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
SF ids in the device are in two different contiguous ranges. One for the local controller and second for the external host controller.
Prepare code to handle multiple start function id by storing it in the table.
--- drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +8 -2
@@ -19,18 +19,23 @@ struct mlx5_sf_hw_table {struct mlx5_core_dev *dev;struct mlx5_sf_hw *sfs;int max_local_functions; +u16 start_fn_id;struct mutex table_lock;/* Serializes sf deletion and vhca state change handler. */ struct notifier_block vhca_nb; };u16 mlx5_sf_sw_to_hw_id (const struct mlx5_core_dev *dev,u16 sw_id) { -return sw_id +mlx5_sf_start_function_id (dev); +struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; + +return table->start_fn_id + sw_id; }static u16 mlx5_sf_hw_to_sw_id (const struct mlx5_core_dev *dev,u16 hw_id) { -return hw_id -mlx5_sf_start_function_id (dev); +struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; + +return hw_id - table->start_fn_id; }int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum)
@@ -164,6 +169,7 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev) table->dev = dev; table->sfs = sfs; table->max_local_functions = max_functions; + table->start_fn_id =mlx5_sf_start_function_id (dev); dev->priv.sf_hw_table = table;mlx5_core_dbg (dev,"SF HW table: max sfs = %d\n" , max_functions);return 0 ;
Signature · 1 line
2.30.2
PATCH v2 8/11 net/mlx5: SF, Consider own vhca events of SF devices
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Vhca events on eswitch manager are received for all the functions on the NIC, including for SFs of external host PF controllers.
While SF device handler is only interested in SF devices events related to its own PF.
Hence, validate if the function belongs to self or not.
--- drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c +11 -1
@@ -148,9 +148,19 @@ mlx5_sf_dev_state_change_handler(struct notifier_block *nb, unsigned long event_ struct mlx5_sf_dev_table *table = container_of(nb, struct mlx5_sf_dev_table, nb);const struct mlx5_vhca_state_event *event = data;struct mlx5_sf_dev *sf_dev; +u16 max_functions;u16 sf_index; +u16 base_id; + + max_functions =mlx5_sf_max_functions (table->dev); +if (!max_functions) +return 0 ; + + base_id =MLX5_CAP_GEN (table->dev, sf_base_id); +if (event->function_id < base_id || event->function_id >= (base_id + max_functions)) +return 0 ; - sf_index = event->function_id -MLX5_CAP_GEN (table->dev, sf_base_id); + sf_index = event->function_id - base_id; sf_dev =xa_load (&table->devices, sf_index);switch (event->new_vhca_state) {case MLX5_VHCA_STATE_ALLOCATED :
Signature · 1 line
2.30.2
PATCH v2 9/11 net/mlx5: SF, Use helpers for allocation and free
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Use helper routines for SF id and SF table allocation and free so that subsequent patch can reuse it for multiple SF function id range.
--- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 97 ++++++++++++------- 1 file changed, 60 insertions(+), 37 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +60 -37
@@ -38,37 +38,46 @@ static u16 mlx5_sf_hw_to_sw_id(const struct mlx5_core_dev *dev, u16 hw_id)return hw_id - table->start_fn_id; } -int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum) +static int mlx5_sf_hw_table_id_alloc (struct mlx5_sf_hw_table *table,u32 usr_sfnum) { -struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; -int sw_id = -ENOSPC ; -u16 hw_fn_id; -int err;int i; -if (!table || !table->max_local_functions) -return -EOPNOTSUPP ; - -mutex_lock (&table->table_lock);/* Check if sf with same sfnum already exists or not. */ for (i =0 ; i < table->max_local_functions; i++) { -if (table->sfs[i].allocated && table->sfs[i].usr_sfnum == usr_sfnum) { - err = -EEXIST ; - goto exist_err; - } +if (table->sfs[i].allocated && table->sfs[i].usr_sfnum == usr_sfnum) +return -EEXIST ; } -/* Find the free entry and allocate the entry from the array */ for (i =0 ; i < table->max_local_functions; i++) {if (!table->sfs[i].allocated) { table->sfs[i].usr_sfnum = usr_sfnum; table->sfs[i].allocated = true; - sw_id = i; -break ; +return i; } } -if (sw_id == -ENOSPC ) { - err = -ENOSPC ; +return -ENOSPC ; +} + +static void mlx5_sf_hw_table_id_free (struct mlx5_sf_hw_table *table,int id) +{ + table->sfs[id].allocated = false; + table->sfs[id].pending_delete = false; +} + +int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum) +{ +struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; +u16 hw_fn_id; +int sw_id; +int err; + +if (!table) +return -EOPNOTSUPP ; + +mutex_lock (&table->table_lock); + sw_id =mlx5_sf_hw_table_id_alloc (table, usr_sfnum); +if (sw_id <0 ) { + err = sw_id; goto exist_err; }
@@ -87,21 +96,20 @@ int mlx5_sf_hw_table_sf_alloc(struct mlx5_core_dev *dev, u32 usr_sfnum) vhca_err:mlx5_cmd_dealloc_sf (dev, hw_fn_id); err: - table->sfs[i].allocated = false; +mlx5_sf_hw_table_id_free (table, sw_id); exist_err:mutex_unlock (&table->table_lock);return err; } -static void _mlx5_sf_hw_id_free (struct mlx5_core_dev *dev,u16 id) +static void _mlx5_sf_hw_table_sf_free (struct mlx5_core_dev *dev,u16 id) {struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;u16 hw_fn_id; hw_fn_id =mlx5_sf_sw_to_hw_id (dev, id);mlx5_cmd_dealloc_sf (dev, hw_fn_id); - table->sfs[id].allocated = false; - table->sfs[id].pending_delete = false; +mlx5_sf_hw_table_id_free (table, id); }void mlx5_sf_hw_table_sf_free (struct mlx5_core_dev *dev,u16 id)
@@ -109,7 +117,7 @@ void mlx5_sf_hw_table_sf_free(struct mlx5_core_dev *dev, u16 id)struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;mutex_lock (&table->table_lock); -_mlx5_sf_hw_id_free (dev, id); +_mlx5_sf_hw_table_sf_free (dev, id);mutex_unlock (&table->table_lock); }
@@ -143,40 +151,55 @@ static void mlx5_sf_hw_dealloc_all(struct mlx5_sf_hw_table *table)for (i =0 ; i < table->max_local_functions; i++) {if (table->sfs[i].allocated) -_mlx5_sf_hw_id_free (table->dev, i); +_mlx5_sf_hw_table_sf_free (table->dev, i); } } +static int mlx5_sf_hw_table_alloc (struct mlx5_sf_hw_table *table,u16 max_fn,u16 base_id) +{ +struct mlx5_sf_hw *sfs; + + sfs =kcalloc (max_fn,sizeof (*sfs),GFP_KERNEL ); +if (!sfs) +return -ENOMEM ; + + table->sfs = sfs; + table->max_local_functions = max_fn; + table->start_fn_id = base_id; +return 0 ; +} +int mlx5_sf_hw_table_init (struct mlx5_core_dev *dev) {struct mlx5_sf_hw_table *table; -struct mlx5_sf_hw *sfs; -int max_functions; +u16 base_id; +u16 max_fn; +int err;if (!mlx5_sf_supported (dev) || !mlx5_vhca_event_supported (dev))return 0 ; - max_functions =mlx5_sf_max_functions (dev); + max_fn =mlx5_sf_max_functions (dev); table =kzalloc (sizeof (*table),GFP_KERNEL );if (!table)return -ENOMEM ; - sfs =kcalloc (max_functions,sizeof (*sfs),GFP_KERNEL ); -if (!sfs) - goto table_err; -mutex_init (&table->table_lock); table->dev = dev; - table->sfs = sfs; - table->max_local_functions = max_functions; - table->start_fn_id =mlx5_sf_start_function_id (dev); dev->priv.sf_hw_table = table; -mlx5_core_dbg (dev,"SF HW table: max sfs = %d\n" , max_functions); + + base_id =mlx5_sf_start_function_id (dev); + err =mlx5_sf_hw_table_alloc (table, max_fn, base_id); +if (err) + goto table_err; + +mlx5_core_dbg (dev,"SF HW table: max sfs = %d\n" , max_fn);return 0 ; table_err: +mutex_destroy (&table->table_lock);kfree (table); -return -ENOMEM ; +return err; }void mlx5_sf_hw_table_cleanup (struct mlx5_core_dev *dev)
@@ -209,7 +232,7 @@ static int mlx5_sf_hw_vhca_event(struct notifier_block *nb, unsigned long opcode* Hence recycle the sf hardware id for reuse. */ if (sf_hw->allocated && sf_hw->pending_delete) -_mlx5_sf_hw_id_free (table->dev, sw_id); +_mlx5_sf_hw_table_sf_free (table->dev, sw_id);mutex_unlock (&table->table_lock);return 0 ; }
Signature · 1 line
2.30.2
PATCH v2 10/11 net/mlx5: SF, Split mlx5_sf_hw_table into two parts
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Device has SF ids in two different contiguous ranges. One for the local controller and second for the external controller's PF.
Each such range has its own maximum number of functions and base id. To allocate SF from either of the range, prepare code to split into range specific fields into its own structure.
--- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 87 ++++++++++++------- 1 file changed, 58 insertions(+), 29 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +58 -29
@@ -15,43 +15,55 @@ struct mlx5_sf_hw { u8 pending_delete: 1; }; -struct mlx5_sf_hw_table { -struct mlx5_core_dev *dev; +struct mlx5_sf_hwc_table {struct mlx5_sf_hw *sfs; -int max_local_functions; +int max_fn;u16 start_fn_id; +}; + +enum mlx5_sf_hwc_index { +MLX5_SF_HWC_LOCAL , +MLX5_SF_HWC_MAX , +}; + +struct mlx5_sf_hw_table { +struct mlx5_core_dev *dev;struct mutex table_lock;/* Serializes sf deletion and vhca state change handler. */ struct notifier_block vhca_nb; +struct mlx5_sf_hwc_table hwc[MLX5_SF_HWC_MAX ]; };u16 mlx5_sf_sw_to_hw_id (const struct mlx5_core_dev *dev,u16 sw_id) { -struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; +struct mlx5_sf_hwc_table *hwc = &dev->priv.sf_hw_table->hwc[MLX5_SF_HWC_LOCAL ]; -return table->start_fn_id + sw_id; +return hwc->start_fn_id + sw_id; }static u16 mlx5_sf_hw_to_sw_id (const struct mlx5_core_dev *dev,u16 hw_id) { -struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table; +struct mlx5_sf_hwc_table *hwc = &dev->priv.sf_hw_table->hwc[MLX5_SF_HWC_LOCAL ]; -return hw_id - table->start_fn_id; +return hw_id - hwc->start_fn_id; }static int mlx5_sf_hw_table_id_alloc (struct mlx5_sf_hw_table *table,u32 usr_sfnum) { +struct mlx5_sf_hwc_table *hwc;int i; + hwc = &table->hwc[MLX5_SF_HWC_LOCAL ]; +/* Check if sf with same sfnum already exists or not. */ -for (i =0 ; i < table->max_local_functions; i++) { -if (table->sfs[i].allocated && table->sfs[i].usr_sfnum == usr_sfnum) +for (i =0 ; i < hwc->max_fn; i++) { +if (hwc->sfs[i].allocated && hwc->sfs[i].usr_sfnum == usr_sfnum)return -EEXIST ; }/* Find the free entry and allocate the entry from the array */ -for (i =0 ; i < table->max_local_functions; i++) { -if (!table->sfs[i].allocated) { - table->sfs[i].usr_sfnum = usr_sfnum; - table->sfs[i].allocated = true; +for (i =0 ; i < hwc->max_fn; i++) { +if (!hwc->sfs[i].allocated) { + hwc->sfs[i].usr_sfnum = usr_sfnum; + hwc->sfs[i].allocated = true;return i; } }
@@ -60,8 +72,10 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_sf_hw_table *table, u32 usr_sfnstatic void mlx5_sf_hw_table_id_free (struct mlx5_sf_hw_table *table,int id) { - table->sfs[id].allocated = false; - table->sfs[id].pending_delete = false; +struct mlx5_sf_hwc_table *hwc = &table->hwc[MLX5_SF_HWC_LOCAL ]; + + hwc->sfs[id].allocated = false; + hwc->sfs[id].pending_delete = false; }int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum)
@@ -125,11 +139,13 @@ void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u16 id) {struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;u32 out[MLX5_ST_SZ_DW (query_vhca_state_out)] = {}; +struct mlx5_sf_hwc_table *hwc;u16 hw_fn_id;u8 state;int err; hw_fn_id =mlx5_sf_sw_to_hw_id (dev, id); + hwc = &table->hwc[MLX5_SF_HWC_LOCAL ];mutex_lock (&table->table_lock); err =mlx5_cmd_query_vhca_state (dev, hw_fn_id, out,sizeof (out));if (err)
@@ -137,25 +153,31 @@ void mlx5_sf_hw_table_sf_deferred_free(struct mlx5_core_dev *dev, u16 id) state =MLX5_GET (query_vhca_state_out, out, vhca_state_context.vhca_state);if (state ==MLX5_VHCA_STATE_ALLOCATED ) {mlx5_cmd_dealloc_sf (dev, hw_fn_id); - table->sfs[id].allocated = false; + hwc->sfs[id].allocated = false; }else { - table->sfs[id].pending_delete = true; + hwc->sfs[id].pending_delete = true; } err:mutex_unlock (&table->table_lock); } -static void mlx5_sf_hw_dealloc_all (struct mlx5_sf_hw_table *table) +static void mlx5_sf_hw_table_hwc_dealloc_all (struct mlx5_core_dev *dev, +struct mlx5_sf_hwc_table *hwc) {int i; -for (i =0 ; i < table->max_local_functions; i++) { -if (table->sfs[i].allocated) -_mlx5_sf_hw_table_sf_free (table->dev, i); +for (i =0 ; i < hwc->max_fn; i++) { +if (hwc->sfs[i].allocated) +_mlx5_sf_hw_table_sf_free (dev, i); } } -static int mlx5_sf_hw_table_alloc (struct mlx5_sf_hw_table *table,u16 max_fn,u16 base_id) +static void mlx5_sf_hw_table_dealloc_all (struct mlx5_sf_hw_table *table) +{ +mlx5_sf_hw_table_hwc_dealloc_all (table->dev, &table->hwc[MLX5_SF_HWC_LOCAL ]); +} + +static int mlx5_sf_hw_table_hwc_init (struct mlx5_sf_hwc_table *hwc,u16 max_fn,u16 base_id) {struct mlx5_sf_hw *sfs;
@@ -163,12 +185,17 @@ static int mlx5_sf_hw_table_alloc(struct mlx5_sf_hw_table *table, u16 max_fn, u1if (!sfs)return -ENOMEM ; - table->sfs = sfs; - table->max_local_functions = max_fn; - table->start_fn_id = base_id; + hwc->sfs = sfs; + hwc->max_fn = max_fn; + hwc->start_fn_id = base_id;return 0 ; } +static void mlx5_sf_hw_table_hwc_cleanup (struct mlx5_sf_hwc_table *hwc) +{ +kfree (hwc->sfs); +} +int mlx5_sf_hw_table_init (struct mlx5_core_dev *dev) {struct mlx5_sf_hw_table *table;
@@ -189,7 +216,7 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev) dev->priv.sf_hw_table = table; base_id =mlx5_sf_start_function_id (dev); - err =mlx5_sf_hw_table_alloc (table, max_fn, base_id); + err =mlx5_sf_hw_table_hwc_init (&table->hwc[MLX5_SF_HWC_LOCAL ], max_fn, base_id);if (err) goto table_err;
@@ -210,7 +237,7 @@ void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev)return ;mutex_destroy (&table->table_lock); -kfree (table->sfs); +mlx5_sf_hw_table_hwc_cleanup (&table->hwc[MLX5_SF_HWC_LOCAL ]);kfree (table); }
@@ -218,14 +245,16 @@ static int mlx5_sf_hw_vhca_event(struct notifier_block *nb, unsigned long opcode { struct mlx5_sf_hw_table *table = container_of(nb, struct mlx5_sf_hw_table, vhca_nb);const struct mlx5_vhca_state_event *event = data; +struct mlx5_sf_hwc_table *hwc;struct mlx5_sf_hw *sf_hw;u16 sw_id;if (event->new_vhca_state !=MLX5_VHCA_STATE_ALLOCATED )return 0 ; + hwc = &table->hwc[MLX5_SF_HWC_LOCAL ]; sw_id =mlx5_sf_hw_to_sw_id (table->dev, event->function_id); - sf_hw = &table->sfs[sw_id]; + sf_hw = &hwc->sfs[sw_id];mutex_lock (&table->table_lock);/* SF driver notified through firmware that SF is finally detached.
@@ -257,7 +286,7 @@ void mlx5_sf_hw_table_destroy(struct mlx5_core_dev *dev)mlx5_vhca_event_notifier_unregister (dev, &table->vhca_nb);/* Dealloc SFs whose firmware event has been missed. */ -mlx5_sf_hw_dealloc_all (table); +mlx5_sf_hw_table_dealloc_all (table); }bool mlx5_sf_hw_table_supported (const struct mlx5_core_dev *dev)
Signature · 1 line
2.30.2
PATCH v2 11/11 net/mlx5: SF, Extend SF table for additional SF id range
In reply to Saeed MahameedFrom: Parav Pandit <[email protected]>
Extended the SF table to cover additioanl SF id range of external controller.
A user optionallly provides the external controller number when user wants to create SF on the external controller.
An example on eswitch system:
$ devlink dev eswitch set pci/0033:01:00.0 mode switchdev
$ devlink port show
pci/0033:01:00.0/196607: type eth netdev enP51p1s0f0np0 flavour physical port 0 splittable false
pci/0033:01:00.0/131072: type eth netdev eth0 flavour pcipf controller 1 pfnum 0 external true splittable false
function:
hw_addr 00:00:00:00:00:00$ devlink port add pci/0033:01:00.0 flavour pcisf pfnum 0 sfnum 77 controller 1
pci/0033:01:00.0/163840: type eth netdev eth1 flavour pcisf controller 1 pfnum 0 sfnum 77 external true splittable false
function:
hw_addr 00:00:00:00:00:00 state inactive opstate detached--- .../mellanox/mlx5/core/esw/devlink_port.c | 4 +- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 6 +- .../mellanox/mlx5/core/eswitch_offloads.c | 17 ++- .../ethernet/mellanox/mlx5/core/sf/devlink.c | 29 ++-- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 129 +++++++++++++----- .../net/ethernet/mellanox/mlx5/core/sf/priv.h | 8 +- 6 files changed, 140 insertions(+), 53 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +2 -2
@@ -123,7 +123,7 @@ struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u1 }int mlx5_esw_devlink_sf_port_register (struct mlx5_eswitch *esw,struct devlink_port *dl_port, -u16 vport_num,u32 sfnum) +u16 vport_num,u32 controller,u32 sfnum) {struct mlx5_core_dev *dev = esw->dev;struct netdev_phys_item_id ppid = {};
@@ -141,7 +141,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_pmlx5_esw_get_port_parent_id (dev, &ppid);memcpy (dl_port->attrs.switch_id.id, &ppid.id[0 ], ppid.id_len); dl_port->attrs.switch_id.id_len = ppid.id_len; -devlink_port_attrs_pci_sf_set (dl_port,0 , pfnum, sfnum, false); +devlink_port_attrs_pci_sf_set (dl_port, controller, pfnum, sfnum, !!controller); devlink =priv_to_devlink (dev); dl_port_index =mlx5_esw_vport_to_devlink_port_index (dev, vport_num); err =devlink_port_register (devlink, dl_port, dl_port_index);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +4 -2
@@ -662,11 +662,11 @@ void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, u16 vpostruct devlink_port *mlx5_esw_offloads_devlink_port (struct mlx5_eswitch *esw,u16 vport_num);int mlx5_esw_devlink_sf_port_register (struct mlx5_eswitch *esw,struct devlink_port *dl_port, -u16 vport_num,u32 sfnum); +u16 vport_num,u32 controller,u32 sfnum);void mlx5_esw_devlink_sf_port_unregister (struct mlx5_eswitch *esw,u16 vport_num);int mlx5_esw_offloads_sf_vport_enable (struct mlx5_eswitch *esw,struct devlink_port *dl_port, -u16 vport_num,u32 sfnum); +u16 vport_num,u32 controller,u32 sfnum);void mlx5_esw_offloads_sf_vport_disable (struct mlx5_eswitch *esw,u16 vport_num);int mlx5_esw_sf_max_hpf_functions (struct mlx5_core_dev *dev,u16 *max_sfs,u16 *sf_base_id);
@@ -695,6 +695,8 @@ void mlx5_esw_unlock(struct mlx5_eswitch *esw);void esw_vport_change_handle_locked (struct mlx5_vport *vport); +bool mlx5_esw_offloads_controller_valid (const struct mlx5_eswitch *esw,u32 controller); +#else /* CONFIG_MLX5_ESWITCH */ /* eswitch API stubs */ static inline int mlx5_eswitch_init (struct mlx5_core_dev *dev) {return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +15 -2
@@ -2747,6 +2747,19 @@ static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)return 0 ; } +bool mlx5_esw_offloads_controller_valid (const struct mlx5_eswitch *esw,u32 controller) +{ +/* Local controller is always valid */ +if (controller ==0 ) +return true; + +if (!mlx5_core_is_ecpf_esw_manager (esw->dev)) +return false; + +/* External host number starts with zero in device */ +return (controller == esw->offloads.host_number +1 ); +} +int esw_offloads_enable (struct mlx5_eswitch *esw) {struct mapping_ctx *reg_c0_obj_pool;
@@ -3295,7 +3308,7 @@ u32 mlx5_eswitch_get_vport_metadata_for_match(struct mlx5_eswitch *esw,EXPORT_SYMBOL (mlx5_eswitch_get_vport_metadata_for_match);int mlx5_esw_offloads_sf_vport_enable (struct mlx5_eswitch *esw,struct devlink_port *dl_port, -u16 vport_num,u32 sfnum) +u16 vport_num,u32 controller,u32 sfnum) {int err;
@@ -3303,7 +3316,7 @@ int mlx5_esw_offloads_sf_vport_enable(struct mlx5_eswitch *esw, struct devlink_pif (err)return err; - err =mlx5_esw_devlink_sf_port_register (esw, dl_port, vport_num, sfnum); + err =mlx5_esw_devlink_sf_port_register (esw, dl_port, vport_num, controller, sfnum);if (err) goto devlink_err;
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c +19 -10
@@ -12,6 +12,7 @@struct mlx5_sf {struct devlink_port dl_port;unsigned int port_index; +u32 controller;u16 id;u16 hw_fn_id;u16 hw_state;
@@ -58,7 +59,8 @@ static void mlx5_sf_id_erase(struct mlx5_sf_table *table, struct mlx5_sf *sf) }static struct mlx5_sf * -mlx5_sf_alloc (struct mlx5_sf_table *table,u32 sfnum,struct netlink_ext_ack *extack) +mlx5_sf_alloc (struct mlx5_sf_table *table,struct mlx5_eswitch *esw, +u32 controller,u32 sfnum,struct netlink_ext_ack *extack) {unsigned int dl_port_index;struct mlx5_sf *sf;
@@ -66,7 +68,12 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, u32 sfnum, struct netlink_ext_ack *exint id_err;int err; - id_err =mlx5_sf_hw_table_sf_alloc (table->dev, sfnum); +if (!mlx5_esw_offloads_controller_valid (esw, controller)) { +NL_SET_ERR_MSG_MOD (extack,"Invalid controller number" ); +return ERR_PTR (-EINVAL ); + } + + id_err =mlx5_sf_hw_table_sf_alloc (table->dev, controller, sfnum);if (id_err <0 ) { err = id_err; goto id_err;
@@ -78,11 +85,12 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, u32 sfnum, struct netlink_ext_ack *ex goto alloc_err; } sf->id = id_err; - hw_fn_id =mlx5_sf_sw_to_hw_id (table->dev, sf->id); + hw_fn_id =mlx5_sf_sw_to_hw_id (table->dev, controller, sf->id); dl_port_index =mlx5_esw_vport_to_devlink_port_index (table->dev, hw_fn_id); sf->port_index = dl_port_index; sf->hw_fn_id = hw_fn_id; sf->hw_state =MLX5_VHCA_STATE_ALLOCATED ; + sf->controller = controller; err =mlx5_sf_id_insert (table, sf);if (err)
@@ -93,7 +101,7 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, u32 sfnum, struct netlink_ext_ack *ex insert_err:kfree (sf); alloc_err: -mlx5_sf_hw_table_sf_free (table->dev, id_err); +mlx5_sf_hw_table_sf_free (table->dev, controller, id_err); id_err:if (err == -EEXIST )NL_SET_ERR_MSG_MOD (extack,"SF already exist. Choose different sfnum" );
@@ -103,7 +111,7 @@ mlx5_sf_alloc(struct mlx5_sf_table *table, u32 sfnum, struct netlink_ext_ack *exstatic void mlx5_sf_free (struct mlx5_sf_table *table,struct mlx5_sf *sf) {mlx5_sf_id_erase (table, sf); -mlx5_sf_hw_table_sf_free (table->dev, sf->id); +mlx5_sf_hw_table_sf_free (table->dev, sf->controller, sf->id);kfree (sf); }
@@ -272,12 +280,12 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,struct mlx5_sf *sf;int err; - sf =mlx5_sf_alloc (table, new_attr->sfnum, extack); + sf =mlx5_sf_alloc (table, esw, new_attr->controller, new_attr->sfnum, extack);if (IS_ERR (sf))return PTR_ERR (sf); err =mlx5_esw_offloads_sf_vport_enable (esw, &sf->dl_port, sf->hw_fn_id, - new_attr->sfnum); + new_attr->controller, new_attr->sfnum);if (err) goto esw_err; *new_port_index = sf->port_index;
@@ -306,7 +314,8 @@ mlx5_sf_new_check_attr(struct mlx5_core_dev *dev, const struct devlink_port_new_ "User must provide unique sfnum. Driver does not support auto assignment");return -EOPNOTSUPP ; } -if (new_attr->controller_valid && new_attr->controller) { +if (new_attr->controller_valid && new_attr->controller && + !mlx5_core_is_ecpf_esw_manager (dev)) {NL_SET_ERR_MSG_MOD (extack,"External controller is unsupported" );return -EOPNOTSUPP ; }
@@ -352,10 +361,10 @@ static void mlx5_sf_dealloc(struct mlx5_sf_table *table, struct mlx5_sf *sf)* firmware gives confirmation that it is detached by the driver. */ mlx5_cmd_sf_disable_hca (table->dev, sf->hw_fn_id); -mlx5_sf_hw_table_sf_deferred_free (table->dev, sf->id); +mlx5_sf_hw_table_sf_deferred_free (table->dev, sf->controller, sf->id);kfree (sf); }else { -mlx5_sf_hw_table_sf_deferred_free (table->dev, sf->id); +mlx5_sf_hw_table_sf_deferred_free (table->dev, sf->controller, sf->id);kfree (sf); } }
drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +96 -33
270 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/sf/priv.h +4 -4
@@ -12,11 +12,11 @@ int mlx5_cmd_dealloc_sf(struct mlx5_core_dev *dev, u16 function_id);int mlx5_cmd_sf_enable_hca (struct mlx5_core_dev *dev,u16 func_id);int mlx5_cmd_sf_disable_hca (struct mlx5_core_dev *dev,u16 func_id); -u16 mlx5_sf_sw_to_hw_id (const struct mlx5_core_dev *dev,u16 sw_id); +u16 mlx5_sf_sw_to_hw_id (struct mlx5_core_dev *dev,u32 controller,u16 sw_id); -int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 usr_sfnum); -void mlx5_sf_hw_table_sf_free (struct mlx5_core_dev *dev,u16 id); -void mlx5_sf_hw_table_sf_deferred_free (struct mlx5_core_dev *dev,u16 id); +int mlx5_sf_hw_table_sf_alloc (struct mlx5_core_dev *dev,u32 controller,u32 usr_sfnum); +void mlx5_sf_hw_table_sf_free (struct mlx5_core_dev *dev,u32 controller,u16 id); +void mlx5_sf_hw_table_sf_deferred_free (struct mlx5_core_dev *dev,u32 controller,u16 id);bool mlx5_sf_hw_table_supported (const struct mlx5_core_dev *dev);#endif
Signature · 1 line
2.30.2