On Mon, 23 Jan 2023 11:17:00 +0100 Lukas Wunner <lukas@xxxxxxxxx> wrote: > Currently a DOE instance cannot be shared by multiple drivers because > each driver creates its own pci_doe_mb struct for a given DOE instance. > For the same reason a DOE instance cannot be shared between the PCI core > and a driver. > > Overcome this limitation by creating mailboxes in the PCI core on device > enumeration. Provide a pci_find_doe_mailbox() API call to allow drivers > to get a pci_doe_mb for a given (pci_dev, vendor, protocol) triple. > > On device removal, tear down mailboxes in two steps: > > In pci_stop_dev(), before the driver is unbound, stop ongoing DOE > exchanges and prevent new ones from being scheduled. This ensures that > a hot-removed device doesn't needlessly wait for a running exchange to > time out. Ah. I didn't have to go far to find answer to my earlier query! This needs to be two step - hence the split in the previous patch. > > In pci_destroy_dev(), after the driver is unbound, free the mailboxes > and their internal data structures. > > Tested-by: Ira Weiny <ira.weiny@xxxxxxxxx> > Signed-off-by: Lukas Wunner <lukas@xxxxxxxxx> Very nice. One comment on a possible future need inline. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> > +/** > + * pci_find_doe_mailbox() - Find Data Object Exchange mailbox > + * > + * @pdev: PCI device > + * @vendor: Vendor ID > + * @type: Data Object Type > + * > + * Find first DOE mailbox of a PCI device which supports the given protocol. > + * > + * RETURNS: Pointer to the DOE mailbox or NULL if none was found. > + */ > +struct pci_doe_mb *pci_find_doe_mailbox(struct pci_dev *pdev, u16 vendor, > + u8 type) This is good for now. We may want eventually to be slightly more flexible and allow for a 'find instance X of a DOE that supports Y'. Can solve that when we need it though. > +{ > + struct pci_doe_mb *doe_mb; > + unsigned long index; > + > + xa_for_each(&pdev->doe_mbs, index, doe_mb) > + if (pci_doe_supports_prot(doe_mb, vendor, type)) > + return doe_mb; > + > + return NULL; > +} > +EXPORT_SYMBOL_GPL(pci_find_doe_mailbox);