aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/mlx5/mlx5_core
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2020-03-18 22:43:39 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2020-03-18 22:43:39 +0000
commit90959e7e37823272cac53cec28c8e68a5789e44c (patch)
tree709cfab44c41ccf4cf394191360c88652439f974 /sys/dev/mlx5/mlx5_core
parent18a70fa5746d536fe119677513d60b8907e0fbf4 (diff)
Notes
Diffstat (limited to 'sys/dev/mlx5/mlx5_core')
-rw-r--r--sys/dev/mlx5/mlx5_core/eswitch.h2
-rw-r--r--sys/dev/mlx5/mlx5_core/mlx5_eswitch.c3
-rw-r--r--sys/dev/mlx5/mlx5_core/mlx5_main.c17
3 files changed, 18 insertions, 4 deletions
diff --git a/sys/dev/mlx5/mlx5_core/eswitch.h b/sys/dev/mlx5/mlx5_core/eswitch.h
index bc5673f020e79..027004b157d55 100644
--- a/sys/dev/mlx5/mlx5_core/eswitch.h
+++ b/sys/dev/mlx5/mlx5_core/eswitch.h
@@ -152,7 +152,7 @@ struct mlx5_esw_vport_info {
};
/* E-Switch API */
-int mlx5_eswitch_init(struct mlx5_core_dev *dev);
+int mlx5_eswitch_init(struct mlx5_core_dev *dev, int total_vports);
void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe);
int mlx5_eswitch_enable_sriov(struct mlx5_eswitch *esw, int nvfs);
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c b/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c
index 907e2621beba9..ccf05b0384350 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c
@@ -1081,10 +1081,9 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw)
esw_enable_vport(esw, 0, UC_ADDR_CHANGE);
}
-int mlx5_eswitch_init(struct mlx5_core_dev *dev)
+int mlx5_eswitch_init(struct mlx5_core_dev *dev, int total_vports)
{
int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table);
- int total_vports = 1;
struct mlx5_eswitch *esw;
int vport_num;
int err;
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_main.c b/sys/dev/mlx5/mlx5_core/mlx5_main.c
index d0fa1be9b74b0..0e560e16ab5e0 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_main.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_main.c
@@ -1317,6 +1317,7 @@ static int init_one(struct pci_dev *pdev,
device_t bsddev = pdev->dev.bsddev;
#ifdef PCI_IOV
nvlist_t *pf_schema, *vf_schema;
+ int num_vfs, sriov_pos;
#endif
int i,err;
struct sysctl_oid *pme_sysctl_node;
@@ -1603,7 +1604,14 @@ static int init_one(struct pci_dev *pdev,
#ifdef PCI_IOV
if (MLX5_CAP_GEN(dev, vport_group_manager)) {
- err = mlx5_eswitch_init(dev);
+ if (pci_find_extcap(bsddev, PCIZ_SRIOV, &sriov_pos) == 0) {
+ num_vfs = pci_read_config(bsddev, sriov_pos +
+ PCIR_SRIOV_TOTAL_VFS, 2);
+ } else {
+ mlx5_core_err(dev, "cannot find SR-IOV PCIe cap\n");
+ num_vfs = 0;
+ }
+ err = mlx5_eswitch_init(dev, 1 + num_vfs);
if (err == 0) {
pf_schema = pci_iov_schema_alloc_node();
vf_schema = pci_iov_schema_alloc_node();
@@ -1780,6 +1788,10 @@ mlx5_iov_init(device_t dev, uint16_t num_vfs, const nvlist_t *pf_config)
core_dev = pci_get_drvdata(pdev);
priv = &core_dev->priv;
+ if (priv->eswitch == NULL)
+ return (ENXIO);
+ if (priv->eswitch->total_vports < num_vfs + 1)
+ num_vfs = priv->eswitch->total_vports - 1;
err = mlx5_eswitch_enable_sriov(priv->eswitch, num_vfs);
return (-err);
}
@@ -1812,6 +1824,9 @@ mlx5_iov_add_vf(device_t dev, uint16_t vfnum, const nvlist_t *vf_config)
core_dev = pci_get_drvdata(pdev);
priv = &core_dev->priv;
+ if (vfnum + 1 >= priv->eswitch->total_vports)
+ return (ENXIO);
+
if (nvlist_exists_binary(vf_config, iov_mac_addr_name)) {
mac = nvlist_get_binary(vf_config, iov_mac_addr_name,
&mac_size);