Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: endpoint: Pass EPF device ID to the probe function

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>

authored by

Manivannan Sadhasivam and committed by
Bjorn Helgaas
081c715d ff2f19d6

+17 -9
+3 -1
drivers/pci/endpoint/functions/pci-epf-ntb.c
··· 2075 2075 /** 2076 2076 * epf_ntb_probe() - Probe NTB function driver 2077 2077 * @epf: NTB endpoint function device 2078 + * @id: NTB endpoint function device ID 2078 2079 * 2079 2080 * Probe NTB function driver when endpoint function bus detects a NTB 2080 2081 * endpoint function. 2081 2082 */ 2082 - static int epf_ntb_probe(struct pci_epf *epf) 2083 + static int epf_ntb_probe(struct pci_epf *epf, 2084 + const struct pci_epf_device_id *id) 2083 2085 { 2084 2086 struct epf_ntb *ntb; 2085 2087 struct device *dev;
+2 -1
drivers/pci/endpoint/functions/pci-epf-test.c
··· 952 952 {}, 953 953 }; 954 954 955 - static int pci_epf_test_probe(struct pci_epf *epf) 955 + static int pci_epf_test_probe(struct pci_epf *epf, 956 + const struct pci_epf_device_id *id) 956 957 { 957 958 struct pci_epf_test *epf_test; 958 959 struct device *dev = &epf->dev;
+3 -1
drivers/pci/endpoint/functions/pci-epf-vntb.c
··· 1395 1395 /** 1396 1396 * epf_ntb_probe() - Probe NTB function driver 1397 1397 * @epf: NTB endpoint function device 1398 + * @id: NTB endpoint function device ID 1398 1399 * 1399 1400 * Probe NTB function driver when endpoint function bus detects a NTB 1400 1401 * endpoint function. 1401 1402 * 1402 1403 * Returns: Zero for success, or an error code in case of failure 1403 1404 */ 1404 - static int epf_ntb_probe(struct pci_epf *epf) 1405 + static int epf_ntb_probe(struct pci_epf *epf, 1406 + const struct pci_epf_device_id *id) 1405 1407 { 1406 1408 struct epf_ntb *ntb; 1407 1409 struct device *dev;
+5 -5
drivers/pci/endpoint/pci-epf-core.c
··· 461 461 .release = pci_epf_dev_release, 462 462 }; 463 463 464 - static int 464 + static const struct pci_epf_device_id * 465 465 pci_epf_match_id(const struct pci_epf_device_id *id, const struct pci_epf *epf) 466 466 { 467 467 while (id->name[0]) { 468 468 if (strcmp(epf->name, id->name) == 0) 469 - return true; 469 + return id; 470 470 id++; 471 471 } 472 472 473 - return false; 473 + return NULL; 474 474 } 475 475 476 476 static int pci_epf_device_match(struct device *dev, struct device_driver *drv) ··· 479 479 struct pci_epf_driver *driver = to_pci_epf_driver(drv); 480 480 481 481 if (driver->id_table) 482 - return pci_epf_match_id(driver->id_table, epf); 482 + return !!pci_epf_match_id(driver->id_table, epf); 483 483 484 484 return !strcmp(epf->name, drv->name); 485 485 } ··· 494 494 495 495 epf->driver = driver; 496 496 497 - return driver->probe(epf); 497 + return driver->probe(epf, pci_epf_match_id(driver->id_table, epf)); 498 498 } 499 499 500 500 static void pci_epf_device_remove(struct device *dev)
+4 -1
include/linux/pci-epf.h
··· 89 89 * @id_table: identifies EPF devices for probing 90 90 */ 91 91 struct pci_epf_driver { 92 - int (*probe)(struct pci_epf *epf); 92 + int (*probe)(struct pci_epf *epf, 93 + const struct pci_epf_device_id *id); 93 94 void (*remove)(struct pci_epf *epf); 94 95 95 96 struct device_driver driver; ··· 132 131 * @epc: the EPC device to which this EPF device is bound 133 132 * @epf_pf: the physical EPF device to which this virtual EPF device is bound 134 133 * @driver: the EPF driver to which this EPF device is bound 134 + * @id: Pointer to the EPF device ID 135 135 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc 136 136 * @lock: mutex to protect pci_epf_ops 137 137 * @sec_epc: the secondary EPC device to which this EPF device is bound ··· 160 158 struct pci_epc *epc; 161 159 struct pci_epf *epf_pf; 162 160 struct pci_epf_driver *driver; 161 + const struct pci_epf_device_id *id; 163 162 struct list_head list; 164 163 /* mutex to protect against concurrent access of pci_epf_ops */ 165 164 struct mutex lock;