[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230217225558.19837-10-shannon.nelson@amd.com>
Date: Fri, 17 Feb 2023 14:55:53 -0800
From: Shannon Nelson <shannon.nelson@....com>
To: <netdev@...r.kernel.org>, <davem@...emloft.net>, <kuba@...nel.org>
CC: <drivers@...sando.io>, <brett.creeley@....com>,
Shannon Nelson <shannon.nelson@....com>
Subject: [PATCH v3 net-next 09/14] pds_core: initial VF configuration
Set up the VF control and management
Signed-off-by: Shannon Nelson <shannon.nelson@....com>
---
drivers/net/ethernet/amd/pds_core/core.h | 10 ++++++-
drivers/net/ethernet/amd/pds_core/main.c | 35 ++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/amd/pds_core/core.h b/drivers/net/ethernet/amd/pds_core/core.h
index 0355a0b850eb..1885976c6486 100644
--- a/drivers/net/ethernet/amd/pds_core/core.h
+++ b/drivers/net/ethernet/amd/pds_core/core.h
@@ -30,6 +30,13 @@ struct pdsc_dev_bar {
int res_index;
};
+struct pdsc_vf {
+ u16 index;
+ __le16 vif_types[PDS_DEV_TYPE_MAX];
+
+ struct pds_auxiliary_dev *padev;
+};
+
struct pdsc_devinfo {
u8 asic_type;
u8 asic_rev;
@@ -147,6 +154,7 @@ struct pdsc {
struct dentry *dentry;
struct device *dev;
struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX];
+ struct pdsc_vf *vfs;
int num_vfs;
int hw_index;
int id;
@@ -166,6 +174,7 @@ struct pdsc {
struct pdsc_intr_info *intr_info; /* array of nintrs elements */
struct workqueue_struct *wq;
+ struct rw_semaphore vf_op_lock; /* lock for VF operations */
unsigned int devcmd_timeout;
struct mutex devcmd_lock; /* lock for dev_cmd operations */
@@ -299,5 +308,4 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data);
int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw,
struct netlink_ext_ack *extack);
-
#endif /* _PDSC_H_ */
diff --git a/drivers/net/ethernet/amd/pds_core/main.c b/drivers/net/ethernet/amd/pds_core/main.c
index 23e9bf48a05e..1376dec84756 100644
--- a/drivers/net/ethernet/amd/pds_core/main.c
+++ b/drivers/net/ethernet/amd/pds_core/main.c
@@ -165,6 +165,37 @@ void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num)
(u64)page_num << PAGE_SHIFT, PAGE_SIZE);
}
+static int pdsc_sriov_configure(struct pci_dev *pdev, int num_vfs)
+{
+ struct pdsc *pdsc = pci_get_drvdata(pdev);
+ struct device *dev = pdsc->dev;
+ int ret = 0;
+
+ if (num_vfs > 0) {
+ pdsc->vfs = kcalloc(num_vfs, sizeof(struct pdsc_vf), GFP_KERNEL);
+ if (!pdsc->vfs)
+ return -ENOMEM;
+ pdsc->num_vfs = num_vfs;
+
+ ret = pci_enable_sriov(pdev, num_vfs);
+ if (ret) {
+ dev_err(dev, "Cannot enable SRIOV: %pe\n", ERR_PTR(ret));
+ goto no_vfs;
+ }
+
+ return num_vfs;
+ }
+
+no_vfs:
+ pci_disable_sriov(pdev);
+
+ kfree(pdsc->vfs);
+ pdsc->vfs = NULL;
+ pdsc->num_vfs = 0;
+
+ return ret;
+}
+
static DEFINE_IDA(pdsc_pf_ida);
#define PDSC_WQ_NAME_LEN 24
@@ -237,6 +268,7 @@ static int pdsc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
spin_lock_init(&pdsc->adminq_lock);
mutex_lock(&pdsc->config_lock);
+ init_rwsem(&pdsc->vf_op_lock);
err = pdsc_setup(pdsc, PDSC_SETUP_INIT);
if (err)
goto err_out_unmap_bars;
@@ -300,6 +332,8 @@ static void pdsc_remove(struct pci_dev *pdev)
*/
pdsc_dl_unregister(pdsc);
+ pdsc_sriov_configure(pdev, 0);
+
/* Now we can lock it up and tear it down */
mutex_lock(&pdsc->config_lock);
set_bit(PDSC_S_STOPPING_DRIVER, &pdsc->state);
@@ -337,6 +371,7 @@ static struct pci_driver pdsc_driver = {
.id_table = pdsc_id_table,
.probe = pdsc_probe,
.remove = pdsc_remove,
+ .sriov_configure = pdsc_sriov_configure,
};
static int __init pdsc_init_module(void)
--
2.17.1
Powered by blists - more mailing lists