Skip to content

Commit b599a5b

Browse files
committed
Merge branch 'devlink-show-controller-number'
Parav Pandit says: ==================== devlink show controller number Currently a devlink instance that supports an eswitch handles eswitch ports of two type of controllers. (1) controller discovered on same system where eswitch resides. This is the case where PCI PF/VF of a controller and devlink eswitch instance both are located on a single system. (2) controller located on external system. This is the case where a controller is plugged in one system and its devlink eswitch ports are located in a different system. In this case devlink instance of the eswitch only have access to ports of the controller. However, there is no way to describe that a eswitch devlink port belongs to which controller (mainly which external host controller). This problem is more prevalent when port attribute such as PF and VF numbers are overlapping between multiple controllers of same eswitch. Due to this, for a specific switch_id, unique phys_port_name cannot be constructed for such devlink ports. This short series overcomes this limitation by defining two new attributes. (a) external: Indicates if port belongs to external controller (b) controller number: Indicates a controller number of the port Based on this a unique phys_port_name is prepared using controller number. phys_port_name construction using unique controller number is only applicable to external controller ports. This ensures that for non smartnic usecases where there is no external controller, phys_port_name stays same as before. Patch summary: Patch-1 Added mlx5 driver to read controller number Patch-2 Adds the missing comment for the port attributes Patch-3 Move structure comments away from structure fields Patch-4 external attribute added for PCI port flavours Patch-5 Add controller number Patch-6 Use controller number to build phys_port_name --- Changelog: v2->v3: - Updated diagram to get rid of controller 'A' and 'B' - Kept ports of single controller together in diagram - Updated diagram for pf1's VF and SF and its ports v1->v2: - Added text diagram of multiple controllers - Updated example for a VF - Addressed comments from Jiri and Jakub - Moved controller number attribute to PCI port flavours This enables to better, hirerchical view with controller and its PF, VF numbers - Split 'external' and 'controller number' attributes as two different attributes - Merged mlx5_core driver to avoid compiliation break ==================== Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 6b5472d + 66b1708 commit b599a5b

File tree

6 files changed

+99
-19
lines changed

6 files changed

+99
-19
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,16 +1210,22 @@ is_devlink_port_supported(const struct mlx5_core_dev *dev,
12101210
static int register_devlink_port(struct mlx5_core_dev *dev,
12111211
struct mlx5e_rep_priv *rpriv)
12121212
{
1213+
struct mlx5_esw_offload *offloads = &dev->priv.eswitch->offloads;
12131214
struct devlink *devlink = priv_to_devlink(dev);
12141215
struct mlx5_eswitch_rep *rep = rpriv->rep;
12151216
struct devlink_port_attrs attrs = {};
12161217
struct netdev_phys_item_id ppid = {};
12171218
unsigned int dl_port_index = 0;
1219+
u32 controller_num = 0;
1220+
bool external;
12181221
u16 pfnum;
12191222

12201223
if (!is_devlink_port_supported(dev, rpriv))
12211224
return 0;
12221225

1226+
external = mlx5_core_is_ecpf_esw_manager(dev);
1227+
if (external)
1228+
controller_num = offloads->host_number + 1;
12231229
mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
12241230
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, rep->vport);
12251231
pfnum = PCI_FUNC(dev->pdev->devfn);
@@ -1232,12 +1238,13 @@ static int register_devlink_port(struct mlx5_core_dev *dev,
12321238
} else if (rep->vport == MLX5_VPORT_PF) {
12331239
memcpy(rpriv->dl_port.attrs.switch_id.id, &ppid.id[0], ppid.id_len);
12341240
rpriv->dl_port.attrs.switch_id.id_len = ppid.id_len;
1235-
devlink_port_attrs_pci_pf_set(&rpriv->dl_port, pfnum);
1241+
devlink_port_attrs_pci_pf_set(&rpriv->dl_port, controller_num,
1242+
pfnum, external);
12361243
} else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport)) {
12371244
memcpy(rpriv->dl_port.attrs.switch_id.id, &ppid.id[0], ppid.id_len);
12381245
rpriv->dl_port.attrs.switch_id.id_len = ppid.id_len;
1239-
devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
1240-
pfnum, rep->vport - 1);
1246+
devlink_port_attrs_pci_vf_set(&rpriv->dl_port, controller_num,
1247+
pfnum, rep->vport - 1, external);
12411248
}
12421249
return devlink_port_register(devlink, &rpriv->dl_port, dl_port_index);
12431250
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct mlx5_esw_offload {
217217
atomic64_t num_flows;
218218
enum devlink_eswitch_encap_mode encap;
219219
struct ida vport_metadata_ida;
220+
unsigned int host_number; /* ECPF supports one external host */
220221
};
221222

222223
/* E-Switch MC FDB table hash node */

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,24 @@ int mlx5_esw_funcs_changed_handler(struct notifier_block *nb, unsigned long type
21102110
return NOTIFY_OK;
21112111
}
21122112

2113+
static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)
2114+
{
2115+
const u32 *query_host_out;
2116+
2117+
if (!mlx5_core_is_ecpf_esw_manager(esw->dev))
2118+
return 0;
2119+
2120+
query_host_out = mlx5_esw_query_functions(esw->dev);
2121+
if (IS_ERR(query_host_out))
2122+
return PTR_ERR(query_host_out);
2123+
2124+
/* Mark non local controller with non zero controller number. */
2125+
esw->offloads.host_number = MLX5_GET(query_esw_functions_out, query_host_out,
2126+
host_params_context.host_number);
2127+
kvfree(query_host_out);
2128+
return 0;
2129+
}
2130+
21132131
int esw_offloads_enable(struct mlx5_eswitch *esw)
21142132
{
21152133
struct mlx5_vport *vport;
@@ -2124,6 +2142,10 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)
21242142
mutex_init(&esw->offloads.termtbl_mutex);
21252143
mlx5_rdma_enable_roce(esw->dev);
21262144

2145+
err = mlx5_esw_host_number_init(esw);
2146+
if (err)
2147+
goto err_vport_metadata;
2148+
21272149
err = esw_set_passing_vport_metadata(esw, true);
21282150
if (err)
21292151
goto err_vport_metadata;

include/net/devlink.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,30 @@ struct devlink_port_phys_attrs {
5757
u32 split_subport_number; /* If the port is split, this is the number of subport. */
5858
};
5959

60+
/**
61+
* struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
62+
* @controller: Associated controller number
63+
* @pf: Associated PCI PF number for this port.
64+
* @external: when set, indicates if a port is for an external controller
65+
*/
6066
struct devlink_port_pci_pf_attrs {
61-
u16 pf; /* Associated PCI PF for this port. */
67+
u32 controller;
68+
u16 pf;
69+
u8 external:1;
6270
};
6371

72+
/**
73+
* struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
74+
* @controller: Associated controller number
75+
* @pf: Associated PCI PF number for this port.
76+
* @vf: Associated PCI VF for of the PCI PF for this port.
77+
* @external: when set, indicates if a port is for an external controller
78+
*/
6479
struct devlink_port_pci_vf_attrs {
65-
u16 pf; /* Associated PCI PF for this port. */
66-
u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
80+
u32 controller;
81+
u16 pf;
82+
u16 vf;
83+
u8 external:1;
6784
};
6885

6986
/**
@@ -73,6 +90,9 @@ struct devlink_port_pci_vf_attrs {
7390
* @splittable: indicates if the port can be split.
7491
* @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
7592
* @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
93+
* @phys: physical port attributes
94+
* @pci_pf: PCI PF port attributes
95+
* @pci_vf: PCI VF port attributes
7696
*/
7797
struct devlink_port_attrs {
7898
u8 split:1,
@@ -1203,9 +1223,10 @@ void devlink_port_type_ib_set(struct devlink_port *devlink_port,
12031223
void devlink_port_type_clear(struct devlink_port *devlink_port);
12041224
void devlink_port_attrs_set(struct devlink_port *devlink_port,
12051225
struct devlink_port_attrs *devlink_port_attrs);
1206-
void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf);
1207-
void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
1208-
u16 pf, u16 vf);
1226+
void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1227+
u16 pf, bool external);
1228+
void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
1229+
u16 pf, u16 vf, bool external);
12091230
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
12101231
u32 size, u16 ingress_pools_count,
12111232
u16 egress_pools_count, u16 ingress_tc_count,

include/uapi/linux/devlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ enum devlink_attr {
458458
DEVLINK_ATTR_PORT_LANES, /* u32 */
459459
DEVLINK_ATTR_PORT_SPLITTABLE, /* u8 */
460460

461+
DEVLINK_ATTR_PORT_EXTERNAL, /* u8 */
462+
DEVLINK_ATTR_PORT_CONTROLLER_NUMBER, /* u32 */
461463
/* add new attributes above here, update the policy in devlink.c */
462464

463465
__DEVLINK_ATTR_MAX,

net/core/devlink.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,20 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
523523
return -EMSGSIZE;
524524
switch (devlink_port->attrs.flavour) {
525525
case DEVLINK_PORT_FLAVOUR_PCI_PF:
526-
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
527-
attrs->pci_pf.pf))
526+
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_CONTROLLER_NUMBER,
527+
attrs->pci_pf.controller) ||
528+
nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, attrs->pci_pf.pf))
529+
return -EMSGSIZE;
530+
if (nla_put_u8(msg, DEVLINK_ATTR_PORT_EXTERNAL, attrs->pci_pf.external))
528531
return -EMSGSIZE;
529532
break;
530533
case DEVLINK_PORT_FLAVOUR_PCI_VF:
531-
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
532-
attrs->pci_vf.pf) ||
533-
nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
534-
attrs->pci_vf.vf))
534+
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_CONTROLLER_NUMBER,
535+
attrs->pci_vf.controller) ||
536+
nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, attrs->pci_vf.pf) ||
537+
nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER, attrs->pci_vf.vf))
538+
return -EMSGSIZE;
539+
if (nla_put_u8(msg, DEVLINK_ATTR_PORT_EXTERNAL, attrs->pci_vf.external))
535540
return -EMSGSIZE;
536541
break;
537542
case DEVLINK_PORT_FLAVOUR_PHYSICAL:
@@ -7715,9 +7720,12 @@ EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
77157720
* devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
77167721
*
77177722
* @devlink_port: devlink port
7723+
* @controller: associated controller number for the devlink port instance
77187724
* @pf: associated PF for the devlink port instance
7725+
* @external: indicates if the port is for an external controller
77197726
*/
7720-
void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf)
7727+
void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
7728+
u16 pf, bool external)
77217729
{
77227730
struct devlink_port_attrs *attrs = &devlink_port->attrs;
77237731
int ret;
@@ -7726,20 +7734,23 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf)
77267734
DEVLINK_PORT_FLAVOUR_PCI_PF);
77277735
if (ret)
77287736
return;
7729-
7737+
attrs->pci_pf.controller = controller;
77307738
attrs->pci_pf.pf = pf;
7739+
attrs->pci_pf.external = external;
77317740
}
77327741
EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
77337742

77347743
/**
77357744
* devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
77367745
*
77377746
* @devlink_port: devlink port
7747+
* @controller: associated controller number for the devlink port instance
77387748
* @pf: associated PF for the devlink port instance
77397749
* @vf: associated VF of a PF for the devlink port instance
7750+
* @external: indicates if the port is for an external controller
77407751
*/
7741-
void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
7742-
u16 pf, u16 vf)
7752+
void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
7753+
u16 pf, u16 vf, bool external)
77437754
{
77447755
struct devlink_port_attrs *attrs = &devlink_port->attrs;
77457756
int ret;
@@ -7748,8 +7759,10 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
77487759
DEVLINK_PORT_FLAVOUR_PCI_VF);
77497760
if (ret)
77507761
return;
7762+
attrs->pci_vf.controller = controller;
77517763
attrs->pci_vf.pf = pf;
77527764
attrs->pci_vf.vf = vf;
7765+
attrs->pci_vf.external = external;
77537766
}
77547767
EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
77557768

@@ -7780,9 +7793,23 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
77807793
WARN_ON(1);
77817794
return -EINVAL;
77827795
case DEVLINK_PORT_FLAVOUR_PCI_PF:
7796+
if (attrs->pci_pf.external) {
7797+
n = snprintf(name, len, "c%u", attrs->pci_pf.controller);
7798+
if (n >= len)
7799+
return -EINVAL;
7800+
len -= n;
7801+
name += n;
7802+
}
77837803
n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
77847804
break;
77857805
case DEVLINK_PORT_FLAVOUR_PCI_VF:
7806+
if (attrs->pci_vf.external) {
7807+
n = snprintf(name, len, "c%u", attrs->pci_vf.controller);
7808+
if (n >= len)
7809+
return -EINVAL;
7810+
len -= n;
7811+
name += n;
7812+
}
77867813
n = snprintf(name, len, "pf%uvf%u",
77877814
attrs->pci_vf.pf, attrs->pci_vf.vf);
77887815
break;

0 commit comments

Comments
 (0)