PCI: endpoint: Pass EPF device ID to the probe function
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Fri, 2 Jun 2023 11:47:49 +0000 (17:17 +0530)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 23 Jun 2023 20:05:03 +0000 (15:05 -0500)
Currently, the EPF probe function doesn't get the device ID argument needed
to correctly identify the device table ID of the EPF device.

When multiple entries are added to the "struct pci_epf_device_id" table,
the probe function needs to identify the correct one. This is achieved by
modifying the pci_epf_match_id() function to return the match ID pointer
and passing it to the driver's probe function.

pci_epf_device_match() function can return bool based on the return value
of pci_epf_match_id().

Link: https://lore.kernel.org/r/20230602114756.36586-3-manivannan.sadhasivam@linaro.org
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Kishon Vijay Abraham I <kishon@kernel.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
drivers/pci/endpoint/functions/pci-epf-ntb.c
drivers/pci/endpoint/functions/pci-epf-test.c
drivers/pci/endpoint/functions/pci-epf-vntb.c
drivers/pci/endpoint/pci-epf-core.c
include/linux/pci-epf.h

index 9a00448c7e610ee5aaf824475808810fe0d78f94..9aac2c6f3bb99ddd2c3515a74b59479f77f8ad4b 100644 (file)
@@ -2075,11 +2075,13 @@ static struct config_group *epf_ntb_add_cfs(struct pci_epf *epf,
 /**
  * epf_ntb_probe() - Probe NTB function driver
  * @epf: NTB endpoint function device
+ * @id: NTB endpoint function device ID
  *
  * Probe NTB function driver when endpoint function bus detects a NTB
  * endpoint function.
  */
-static int epf_ntb_probe(struct pci_epf *epf)
+static int epf_ntb_probe(struct pci_epf *epf,
+                        const struct pci_epf_device_id *id)
 {
        struct epf_ntb *ntb;
        struct device *dev;
index 623b08caa998dcbb07332f5d64195375f6833ab6..1f0d2b84296a34f081648dcc783cdb96fe8accb7 100644 (file)
@@ -952,7 +952,8 @@ static const struct pci_epf_device_id pci_epf_test_ids[] = {
        {},
 };
 
-static int pci_epf_test_probe(struct pci_epf *epf)
+static int pci_epf_test_probe(struct pci_epf *epf,
+                             const struct pci_epf_device_id *id)
 {
        struct pci_epf_test *epf_test;
        struct device *dev = &epf->dev;
index b7c7a8af99f4f02099c2f6308c075dc6fd57df63..6b433cfbe471b1fcecef0b180946d315605c8de7 100644 (file)
@@ -1395,13 +1395,15 @@ static struct pci_epf_ops epf_ntb_ops = {
 /**
  * epf_ntb_probe() - Probe NTB function driver
  * @epf: NTB endpoint function device
+ * @id: NTB endpoint function device ID
  *
  * Probe NTB function driver when endpoint function bus detects a NTB
  * endpoint function.
  *
  * Returns: Zero for success, or an error code in case of failure
  */
-static int epf_ntb_probe(struct pci_epf *epf)
+static int epf_ntb_probe(struct pci_epf *epf,
+                        const struct pci_epf_device_id *id)
 {
        struct epf_ntb *ntb;
        struct device *dev;
index 355a6f56fcead7decfef2a1503ee4b495831c690..2c32de66793778d3d99932e362339bc1764451ee 100644 (file)
@@ -461,16 +461,16 @@ static const struct device_type pci_epf_type = {
        .release        = pci_epf_dev_release,
 };
 
-static int
+static const struct pci_epf_device_id *
 pci_epf_match_id(const struct pci_epf_device_id *id, const struct pci_epf *epf)
 {
        while (id->name[0]) {
                if (strcmp(epf->name, id->name) == 0)
-                       return true;
+                       return id;
                id++;
        }
 
-       return false;
+       return NULL;
 }
 
 static int pci_epf_device_match(struct device *dev, struct device_driver *drv)
@@ -479,7 +479,7 @@ static int pci_epf_device_match(struct device *dev, struct device_driver *drv)
        struct pci_epf_driver *driver = to_pci_epf_driver(drv);
 
        if (driver->id_table)
-               return pci_epf_match_id(driver->id_table, epf);
+               return !!pci_epf_match_id(driver->id_table, epf);
 
        return !strcmp(epf->name, drv->name);
 }
@@ -494,7 +494,7 @@ static int pci_epf_device_probe(struct device *dev)
 
        epf->driver = driver;
 
-       return driver->probe(epf);
+       return driver->probe(epf, pci_epf_match_id(driver->id_table, epf));
 }
 
 static void pci_epf_device_remove(struct device *dev)
index b8441db2fa524e09e2b452e2913c1306e2a1979b..a3bad37ccae6b4bb4eeac1379f8b382e681f73e0 100644 (file)
@@ -89,7 +89,8 @@ struct pci_epc_event_ops {
  * @id_table: identifies EPF devices for probing
  */
 struct pci_epf_driver {
-       int     (*probe)(struct pci_epf *epf);
+       int     (*probe)(struct pci_epf *epf,
+                        const struct pci_epf_device_id *id);
        void    (*remove)(struct pci_epf *epf);
 
        struct device_driver    driver;
@@ -131,6 +132,7 @@ struct pci_epf_bar {
  * @epc: the EPC device to which this EPF device is bound
  * @epf_pf: the physical EPF device to which this virtual EPF device is bound
  * @driver: the EPF driver to which this EPF device is bound
+ * @id: Pointer to the EPF device ID
  * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
  * @lock: mutex to protect pci_epf_ops
  * @sec_epc: the secondary EPC device to which this EPF device is bound
@@ -158,6 +160,7 @@ struct pci_epf {
        struct pci_epc          *epc;
        struct pci_epf          *epf_pf;
        struct pci_epf_driver   *driver;
+       const struct pci_epf_device_id *id;
        struct list_head        list;
        /* mutex to protect against concurrent access of pci_epf_ops */
        struct mutex            lock;