Skip to content

Commit f108c88

Browse files
committed
Merge branch 'devlink-Introduce-PCI-PF-VF-ports-and-attributes'
Parav Pandit says: ==================== devlink: Introduce PCI PF, VF ports and attributes This patchset carry forwards the work initiated in [1] and discussion futher concluded at [2]. To improve visibility of representor netdevice, its association with PF or VF, physical port, two new devlink port flavours are added as PCI PF and PCI VF ports. A sample eswitch view can be seen below, which will be futher extended to mdev subdevices of a PCI function in future. Patch-1 moves physical port's attribute to new structure Patch-2 enhances netlink response to consider port flavour Patch-3,4 extends devlink port attributes and port flavour Patch-5 extends mlx5 driver to register devlink ports for PF, VF and physical link. +---+ +---+ vf| | | | pf +-+-+ +-+-+ physical link <---------+ | | | | | | | | +-+-+ +-+-+ +-+-+ | 1 | | 2 | | 3 | +--+---+-----+---+------+---+--+ | physical vf pf | | port port port | | | | eswitch | | | +------------------------------+ [1] https://www.spinics.net/lists/netdev/msg555797.html [2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2 Changelog: v5->v6: - Fixed port flavour check order for PCI PF vs other flavours in netlink response. - Changed 'physical' to 'phys'. v4->v5: - Split first patch to two patches to handle netlink response in separate patch. - Corrected typo 'otwerwise' to 'otherwise' in patches 3 and 4. v3->v4: - Addressed comments from Jiri. - Split first patch to two patches. - Renamed phys_port to physical to be consistent with pci_pf. - Removed port_number from __devlink_port_attrs_set and moved assignment to caller function. - Used capital letter while moving old comment to new structure. - Removed helper function is_devlink_phy_port_num_supported(). v2->v3: - Made port_number and split_port_number applicable only to physical port flavours. v1->v2: - Updated new APIs and mlx5 driver to drop port_number for PF, VF attributes - Updated port_number comment for its usage - Limited putting port_number to physical ports ==================== Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents b14a260 + f60f315 commit f108c88

File tree

5 files changed

+232
-53
lines changed

5 files changed

+232
-53
lines changed

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

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <net/act_api.h>
3838
#include <net/netevent.h>
3939
#include <net/arp.h>
40+
#include <net/devlink.h>
4041

4142
#include "eswitch.h"
4243
#include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
11191120
return ret;
11201121
}
11211122

1122-
static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
1123-
char *buf, size_t len)
1124-
{
1125-
struct mlx5e_priv *priv = netdev_priv(dev);
1126-
struct mlx5e_rep_priv *rpriv = priv->ppriv;
1127-
struct mlx5_eswitch_rep *rep = rpriv->rep;
1128-
unsigned int fn;
1129-
int ret;
1130-
1131-
fn = PCI_FUNC(priv->mdev->pdev->devfn);
1132-
if (fn >= MLX5_MAX_PORTS)
1133-
return -EOPNOTSUPP;
1134-
1135-
if (rep->vport == MLX5_VPORT_UPLINK)
1136-
ret = snprintf(buf, len, "p%d", fn);
1137-
else if (rep->vport == MLX5_VPORT_PF)
1138-
ret = snprintf(buf, len, "pf%d", fn);
1139-
else
1140-
ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
1141-
1142-
if (ret >= len)
1143-
return -EOPNOTSUPP;
1144-
1145-
return 0;
1146-
}
1147-
11481123
static int
11491124
mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
11501125
struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,26 +1273,33 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
12981273
return 0;
12991274
}
13001275

1276+
static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
1277+
{
1278+
struct mlx5e_priv *priv = netdev_priv(dev);
1279+
struct mlx5e_rep_priv *rpriv = priv->ppriv;
1280+
1281+
return &rpriv->dl_port;
1282+
}
1283+
13011284
static const struct net_device_ops mlx5e_netdev_ops_rep = {
13021285
.ndo_open = mlx5e_rep_open,
13031286
.ndo_stop = mlx5e_rep_close,
13041287
.ndo_start_xmit = mlx5e_xmit,
1305-
.ndo_get_phys_port_name = mlx5e_rep_get_phys_port_name,
13061288
.ndo_setup_tc = mlx5e_rep_setup_tc,
1289+
.ndo_get_devlink_port = mlx5e_get_devlink_port,
13071290
.ndo_get_stats64 = mlx5e_rep_get_stats,
13081291
.ndo_has_offload_stats = mlx5e_rep_has_offload_stats,
13091292
.ndo_get_offload_stats = mlx5e_rep_get_offload_stats,
13101293
.ndo_change_mtu = mlx5e_rep_change_mtu,
1311-
.ndo_get_port_parent_id = mlx5e_rep_get_port_parent_id,
13121294
};
13131295

13141296
static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
13151297
.ndo_open = mlx5e_open,
13161298
.ndo_stop = mlx5e_close,
13171299
.ndo_start_xmit = mlx5e_xmit,
13181300
.ndo_set_mac_address = mlx5e_uplink_rep_set_mac,
1319-
.ndo_get_phys_port_name = mlx5e_rep_get_phys_port_name,
13201301
.ndo_setup_tc = mlx5e_rep_setup_tc,
1302+
.ndo_get_devlink_port = mlx5e_get_devlink_port,
13211303
.ndo_get_stats64 = mlx5e_get_stats,
13221304
.ndo_has_offload_stats = mlx5e_rep_has_offload_stats,
13231305
.ndo_get_offload_stats = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
13301312
.ndo_get_vf_config = mlx5e_get_vf_config,
13311313
.ndo_get_vf_stats = mlx5e_get_vf_stats,
13321314
.ndo_set_vf_vlan = mlx5e_uplink_rep_set_vf_vlan,
1333-
.ndo_get_port_parent_id = mlx5e_rep_get_port_parent_id,
13341315
.ndo_set_features = mlx5e_set_features,
13351316
};
13361317

@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
17311712
.max_tc = MLX5E_MAX_NUM_TC,
17321713
};
17331714

1715+
static bool
1716+
is_devlink_port_supported(const struct mlx5_core_dev *dev,
1717+
const struct mlx5e_rep_priv *rpriv)
1718+
{
1719+
return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
1720+
rpriv->rep->vport == MLX5_VPORT_PF ||
1721+
mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
1722+
}
1723+
1724+
static int register_devlink_port(struct mlx5_core_dev *dev,
1725+
struct mlx5e_rep_priv *rpriv)
1726+
{
1727+
struct devlink *devlink = priv_to_devlink(dev);
1728+
struct mlx5_eswitch_rep *rep = rpriv->rep;
1729+
struct netdev_phys_item_id ppid = {};
1730+
int ret;
1731+
1732+
if (!is_devlink_port_supported(dev, rpriv))
1733+
return 0;
1734+
1735+
ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
1736+
if (ret)
1737+
return ret;
1738+
1739+
if (rep->vport == MLX5_VPORT_UPLINK)
1740+
devlink_port_attrs_set(&rpriv->dl_port,
1741+
DEVLINK_PORT_FLAVOUR_PHYSICAL,
1742+
PCI_FUNC(dev->pdev->devfn), false, 0,
1743+
&ppid.id[0], ppid.id_len);
1744+
else if (rep->vport == MLX5_VPORT_PF)
1745+
devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
1746+
&ppid.id[0], ppid.id_len,
1747+
dev->pdev->devfn);
1748+
else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
1749+
devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
1750+
&ppid.id[0], ppid.id_len,
1751+
dev->pdev->devfn,
1752+
rep->vport - 1);
1753+
1754+
return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
1755+
}
1756+
1757+
static void unregister_devlink_port(struct mlx5_core_dev *dev,
1758+
struct mlx5e_rep_priv *rpriv)
1759+
{
1760+
if (is_devlink_port_supported(dev, rpriv))
1761+
devlink_port_unregister(&rpriv->dl_port);
1762+
}
1763+
17341764
/* e-Switch vport representors */
17351765
static int
17361766
mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
17821812
goto err_detach_netdev;
17831813
}
17841814

1815+
err = register_devlink_port(dev, rpriv);
1816+
if (err) {
1817+
esw_warn(dev, "Failed to register devlink port %d\n",
1818+
rep->vport);
1819+
goto err_neigh_cleanup;
1820+
}
1821+
17851822
err = register_netdev(netdev);
17861823
if (err) {
17871824
pr_warn("Failed to register representor netdev for vport %d\n",
17881825
rep->vport);
1789-
goto err_neigh_cleanup;
1826+
goto err_devlink_cleanup;
17901827
}
17911828

1829+
if (is_devlink_port_supported(dev, rpriv))
1830+
devlink_port_type_eth_set(&rpriv->dl_port, netdev);
17921831
return 0;
17931832

1833+
err_devlink_cleanup:
1834+
unregister_devlink_port(dev, rpriv);
1835+
17941836
err_neigh_cleanup:
17951837
mlx5e_rep_neigh_cleanup(rpriv);
17961838

@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
18131855
struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
18141856
struct net_device *netdev = rpriv->netdev;
18151857
struct mlx5e_priv *priv = netdev_priv(netdev);
1858+
struct mlx5_core_dev *dev = priv->mdev;
18161859
void *ppriv = priv->ppriv;
18171860

1861+
if (is_devlink_port_supported(dev, rpriv))
1862+
devlink_port_type_clear(&rpriv->dl_port);
18181863
unregister_netdev(netdev);
1864+
unregister_devlink_port(dev, rpriv);
18191865
mlx5e_rep_neigh_cleanup(rpriv);
18201866
mlx5e_detach_netdev(priv);
18211867
if (rep->vport == MLX5_VPORT_UPLINK)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
8686
struct mlx5_flow_handle *vport_rx_rule;
8787
struct list_head vport_sqs_list;
8888
struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
89+
struct devlink_port dl_port;
8990
};
9091

9192
static inline

include/net/devlink.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,34 @@ struct devlink {
3838
char priv[0] __aligned(NETDEV_ALIGN);
3939
};
4040

41+
struct devlink_port_phys_attrs {
42+
u32 port_number; /* Same value as "split group".
43+
* A physical port which is visible to the user
44+
* for a given port flavour.
45+
*/
46+
u32 split_subport_number;
47+
};
48+
49+
struct devlink_port_pci_pf_attrs {
50+
u16 pf; /* Associated PCI PF for this port. */
51+
};
52+
53+
struct devlink_port_pci_vf_attrs {
54+
u16 pf; /* Associated PCI PF for this port. */
55+
u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
56+
};
57+
4158
struct devlink_port_attrs {
4259
u8 set:1,
4360
split:1,
4461
switch_port:1;
4562
enum devlink_port_flavour flavour;
46-
u32 port_number; /* same value as "split group" */
47-
u32 split_subport_number;
4863
struct netdev_phys_item_id switch_id;
64+
union {
65+
struct devlink_port_phys_attrs phys;
66+
struct devlink_port_pci_pf_attrs pci_pf;
67+
struct devlink_port_pci_vf_attrs pci_vf;
68+
};
4969
};
5070

5171
struct devlink_port {
@@ -590,6 +610,13 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
590610
u32 split_subport_number,
591611
const unsigned char *switch_id,
592612
unsigned char switch_id_len);
613+
void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
614+
const unsigned char *switch_id,
615+
unsigned char switch_id_len, u16 pf);
616+
void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
617+
const unsigned char *switch_id,
618+
unsigned char switch_id_len,
619+
u16 pf, u16 vf);
593620
int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
594621
u32 size, u16 ingress_pools_count,
595622
u16 egress_pools_count, u16 ingress_tc_count,

include/uapi/linux/devlink.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ enum devlink_port_flavour {
169169
DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
170170
* interconnect port.
171171
*/
172+
DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
173+
* the PCI PF. It is an internal
174+
* port that faces the PCI PF.
175+
*/
176+
DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
177+
* for the PCI VF. It is an internal
178+
* port that faces the PCI VF.
179+
*/
172180
};
173181

174182
enum devlink_param_cmode {
@@ -337,6 +345,9 @@ enum devlink_attr {
337345
DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE, /* u64 */
338346
DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL, /* u64 */
339347

348+
DEVLINK_ATTR_PORT_PCI_PF_NUMBER, /* u16 */
349+
DEVLINK_ATTR_PORT_PCI_VF_NUMBER, /* u16 */
350+
340351
/* add new attributes above here, update the policy in devlink.c */
341352

342353
__DEVLINK_ATTR_MAX,

0 commit comments

Comments
 (0)