Commit 2a4d9408 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Bjorn Helgaas

PCI: Use to_pci_driver() instead of pci_dev->driver

Struct pci_driver contains a struct device_driver, so for PCI devices, it's
easy to convert a device_driver * to a pci_driver * with to_pci_driver().
The device_driver * is in struct device, so we don't need to also keep
track of the pci_driver * in struct pci_dev.

Replace pci_dev->driver with to_pci_driver().  This is a step toward
removing pci_dev->driver.

[bhelgaas: split to separate patch]
Link: https://lore.kernel.org/r/20211004125935.2300113-11-u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent d98d5333
...@@ -164,13 +164,15 @@ static ssize_t sriov_vf_total_msix_show(struct device *dev, ...@@ -164,13 +164,15 @@ static ssize_t sriov_vf_total_msix_show(struct device *dev,
char *buf) char *buf)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct pci_driver *pdrv;
u32 vf_total_msix = 0; u32 vf_total_msix = 0;
device_lock(dev); device_lock(dev);
if (!pdev->driver || !pdev->driver->sriov_get_vf_total_msix) pdrv = to_pci_driver(dev->driver);
if (!pdrv || !pdrv->sriov_get_vf_total_msix)
goto unlock; goto unlock;
vf_total_msix = pdev->driver->sriov_get_vf_total_msix(pdev); vf_total_msix = pdrv->sriov_get_vf_total_msix(pdev);
unlock: unlock:
device_unlock(dev); device_unlock(dev);
return sysfs_emit(buf, "%u\n", vf_total_msix); return sysfs_emit(buf, "%u\n", vf_total_msix);
...@@ -183,6 +185,7 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev, ...@@ -183,6 +185,7 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev,
{ {
struct pci_dev *vf_dev = to_pci_dev(dev); struct pci_dev *vf_dev = to_pci_dev(dev);
struct pci_dev *pdev = pci_physfn(vf_dev); struct pci_dev *pdev = pci_physfn(vf_dev);
struct pci_driver *pdrv;
int val, ret; int val, ret;
ret = kstrtoint(buf, 0, &val); ret = kstrtoint(buf, 0, &val);
...@@ -193,13 +196,14 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev, ...@@ -193,13 +196,14 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev,
return -EINVAL; return -EINVAL;
device_lock(&pdev->dev); device_lock(&pdev->dev);
if (!pdev->driver || !pdev->driver->sriov_set_msix_vec_count) { pdrv = to_pci_driver(dev->driver);
if (!pdrv || !pdrv->sriov_set_msix_vec_count) {
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
goto err_pdev; goto err_pdev;
} }
device_lock(&vf_dev->dev); device_lock(&vf_dev->dev);
if (vf_dev->driver) { if (to_pci_driver(vf_dev->dev.driver)) {
/* /*
* A driver is already attached to this VF and has configured * A driver is already attached to this VF and has configured
* itself based on the current MSI-X vector count. Changing * itself based on the current MSI-X vector count. Changing
...@@ -209,7 +213,7 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev, ...@@ -209,7 +213,7 @@ static ssize_t sriov_vf_msix_count_store(struct device *dev,
goto err_dev; goto err_dev;
} }
ret = pdev->driver->sriov_set_msix_vec_count(vf_dev, val); ret = pdrv->sriov_set_msix_vec_count(vf_dev, val);
err_dev: err_dev:
device_unlock(&vf_dev->dev); device_unlock(&vf_dev->dev);
...@@ -376,6 +380,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, ...@@ -376,6 +380,7 @@ static ssize_t sriov_numvfs_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct pci_driver *pdrv;
int ret; int ret;
u16 num_vfs; u16 num_vfs;
...@@ -392,14 +397,15 @@ static ssize_t sriov_numvfs_store(struct device *dev, ...@@ -392,14 +397,15 @@ static ssize_t sriov_numvfs_store(struct device *dev,
goto exit; goto exit;
/* is PF driver loaded */ /* is PF driver loaded */
if (!pdev->driver) { pdrv = to_pci_driver(dev->driver);
if (!pdrv) {
pci_info(pdev, "no driver bound to device; cannot configure SR-IOV\n"); pci_info(pdev, "no driver bound to device; cannot configure SR-IOV\n");
ret = -ENOENT; ret = -ENOENT;
goto exit; goto exit;
} }
/* is PF driver loaded w/callback */ /* is PF driver loaded w/callback */
if (!pdev->driver->sriov_configure) { if (!pdrv->sriov_configure) {
pci_info(pdev, "driver does not support SR-IOV configuration via sysfs\n"); pci_info(pdev, "driver does not support SR-IOV configuration via sysfs\n");
ret = -ENOENT; ret = -ENOENT;
goto exit; goto exit;
...@@ -407,7 +413,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, ...@@ -407,7 +413,7 @@ static ssize_t sriov_numvfs_store(struct device *dev,
if (num_vfs == 0) { if (num_vfs == 0) {
/* disable VFs */ /* disable VFs */
ret = pdev->driver->sriov_configure(pdev, 0); ret = pdrv->sriov_configure(pdev, 0);
goto exit; goto exit;
} }
...@@ -419,7 +425,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, ...@@ -419,7 +425,7 @@ static ssize_t sriov_numvfs_store(struct device *dev,
goto exit; goto exit;
} }
ret = pdev->driver->sriov_configure(pdev, num_vfs); ret = pdrv->sriov_configure(pdev, num_vfs);
if (ret < 0) if (ret < 0)
goto exit; goto exit;
......
...@@ -457,7 +457,7 @@ static int pci_device_probe(struct device *dev) ...@@ -457,7 +457,7 @@ static int pci_device_probe(struct device *dev)
static void pci_device_remove(struct device *dev) static void pci_device_remove(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = to_pci_driver(dev->driver);
if (drv->remove) { if (drv->remove) {
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
...@@ -493,7 +493,7 @@ static void pci_device_remove(struct device *dev) ...@@ -493,7 +493,7 @@ static void pci_device_remove(struct device *dev)
static void pci_device_shutdown(struct device *dev) static void pci_device_shutdown(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = to_pci_driver(dev->driver);
pm_runtime_resume(dev); pm_runtime_resume(dev);
...@@ -589,7 +589,7 @@ static int pci_pm_reenable_device(struct pci_dev *pci_dev) ...@@ -589,7 +589,7 @@ static int pci_pm_reenable_device(struct pci_dev *pci_dev)
static int pci_legacy_suspend(struct device *dev, pm_message_t state) static int pci_legacy_suspend(struct device *dev, pm_message_t state)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = to_pci_driver(dev->driver);
if (drv && drv->suspend) { if (drv && drv->suspend) {
pci_power_t prev = pci_dev->current_state; pci_power_t prev = pci_dev->current_state;
...@@ -630,7 +630,7 @@ static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) ...@@ -630,7 +630,7 @@ static int pci_legacy_suspend_late(struct device *dev, pm_message_t state)
static int pci_legacy_resume(struct device *dev) static int pci_legacy_resume(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = to_pci_driver(dev->driver);
pci_fixup_device(pci_fixup_resume, pci_dev); pci_fixup_device(pci_fixup_resume, pci_dev);
...@@ -649,7 +649,7 @@ static void pci_pm_default_suspend(struct pci_dev *pci_dev) ...@@ -649,7 +649,7 @@ static void pci_pm_default_suspend(struct pci_dev *pci_dev)
static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
{ {
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = to_pci_driver(pci_dev->dev.driver);
bool ret = drv && (drv->suspend || drv->resume); bool ret = drv && (drv->suspend || drv->resume);
/* /*
...@@ -1242,11 +1242,11 @@ static int pci_pm_runtime_suspend(struct device *dev) ...@@ -1242,11 +1242,11 @@ static int pci_pm_runtime_suspend(struct device *dev)
int error; int error;
/* /*
* If pci_dev->driver is not set (unbound), we leave the device in D0, * If the device has no driver, we leave it in D0, but it may go to
* but it may go to D3cold when the bridge above it runtime suspends. * D3cold when the bridge above it runtime suspends. Save its
* Save its config space in case that happens. * config space in case that happens.
*/ */
if (!pci_dev->driver) { if (!to_pci_driver(dev->driver)) {
pci_save_state(pci_dev); pci_save_state(pci_dev);
return 0; return 0;
} }
...@@ -1303,7 +1303,7 @@ static int pci_pm_runtime_resume(struct device *dev) ...@@ -1303,7 +1303,7 @@ static int pci_pm_runtime_resume(struct device *dev)
*/ */
pci_restore_standard_config(pci_dev); pci_restore_standard_config(pci_dev);
if (!pci_dev->driver) if (!to_pci_driver(dev->driver))
return 0; return 0;
pci_fixup_device(pci_fixup_resume_early, pci_dev); pci_fixup_device(pci_fixup_resume_early, pci_dev);
...@@ -1322,14 +1322,13 @@ static int pci_pm_runtime_resume(struct device *dev) ...@@ -1322,14 +1322,13 @@ static int pci_pm_runtime_resume(struct device *dev)
static int pci_pm_runtime_idle(struct device *dev) static int pci_pm_runtime_idle(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
/* /*
* If pci_dev->driver is not set (unbound), the device should * If the device has no driver, it should always remain in D0
* always remain in D0 regardless of the runtime PM status * regardless of the runtime PM status
*/ */
if (!pci_dev->driver) if (!to_pci_driver(dev->driver))
return 0; return 0;
if (!pm) if (!pm)
...@@ -1436,8 +1435,10 @@ static struct pci_driver pci_compat_driver = { ...@@ -1436,8 +1435,10 @@ static struct pci_driver pci_compat_driver = {
*/ */
struct pci_driver *pci_dev_driver(const struct pci_dev *dev) struct pci_driver *pci_dev_driver(const struct pci_dev *dev)
{ {
if (dev->driver) struct pci_driver *drv = to_pci_driver(dev->dev.driver);
return dev->driver;
if (drv)
return drv;
else { else {
int i; int i;
for (i = 0; i <= PCI_ROM_RESOURCE; i++) for (i = 0; i <= PCI_ROM_RESOURCE; i++)
......
...@@ -5088,13 +5088,14 @@ EXPORT_SYMBOL_GPL(pci_dev_unlock); ...@@ -5088,13 +5088,14 @@ EXPORT_SYMBOL_GPL(pci_dev_unlock);
static void pci_dev_save_and_disable(struct pci_dev *dev) static void pci_dev_save_and_disable(struct pci_dev *dev)
{ {
struct pci_driver *drv = to_pci_driver(dev->dev.driver);
const struct pci_error_handlers *err_handler = const struct pci_error_handlers *err_handler =
dev->driver ? dev->driver->err_handler : NULL; drv ? drv->err_handler : NULL;
/* /*
* dev->driver->err_handler->reset_prepare() is protected against * drv->err_handler->reset_prepare() is protected against races
* races with ->remove() by the device lock, which must be held by * with ->remove() by the device lock, which must be held by the
* the caller. * caller.
*/ */
if (err_handler && err_handler->reset_prepare) if (err_handler && err_handler->reset_prepare)
err_handler->reset_prepare(dev); err_handler->reset_prepare(dev);
...@@ -5119,15 +5120,15 @@ static void pci_dev_save_and_disable(struct pci_dev *dev) ...@@ -5119,15 +5120,15 @@ static void pci_dev_save_and_disable(struct pci_dev *dev)
static void pci_dev_restore(struct pci_dev *dev) static void pci_dev_restore(struct pci_dev *dev)
{ {
struct pci_driver *drv = to_pci_driver(dev->dev.driver);
const struct pci_error_handlers *err_handler = const struct pci_error_handlers *err_handler =
dev->driver ? dev->driver->err_handler : NULL; drv ? drv->err_handler : NULL;
pci_restore_state(dev); pci_restore_state(dev);
/* /*
* dev->driver->err_handler->reset_done() is protected against * drv->err_handler->reset_done() is protected against races with
* races with ->remove() by the device lock, which must be held by * ->remove() by the device lock, which must be held by the caller.
* the caller.
*/ */
if (err_handler && err_handler->reset_done) if (err_handler && err_handler->reset_done)
err_handler->reset_done(dev); err_handler->reset_done(dev);
......
...@@ -54,7 +54,7 @@ static int report_error_detected(struct pci_dev *dev, ...@@ -54,7 +54,7 @@ static int report_error_detected(struct pci_dev *dev,
const struct pci_error_handlers *err_handler; const struct pci_error_handlers *err_handler;
device_lock(&dev->dev); device_lock(&dev->dev);
pdrv = dev->driver; pdrv = to_pci_driver(dev->dev.driver);
if (!pci_dev_set_io_state(dev, state) || if (!pci_dev_set_io_state(dev, state) ||
!pdrv || !pdrv ||
!pdrv->err_handler || !pdrv->err_handler ||
...@@ -98,7 +98,7 @@ static int report_mmio_enabled(struct pci_dev *dev, void *data) ...@@ -98,7 +98,7 @@ static int report_mmio_enabled(struct pci_dev *dev, void *data)
const struct pci_error_handlers *err_handler; const struct pci_error_handlers *err_handler;
device_lock(&dev->dev); device_lock(&dev->dev);
pdrv = dev->driver; pdrv = to_pci_driver(dev->dev.driver);
if (!pdrv || if (!pdrv ||
!pdrv->err_handler || !pdrv->err_handler ||
!pdrv->err_handler->mmio_enabled) !pdrv->err_handler->mmio_enabled)
...@@ -119,7 +119,7 @@ static int report_slot_reset(struct pci_dev *dev, void *data) ...@@ -119,7 +119,7 @@ static int report_slot_reset(struct pci_dev *dev, void *data)
const struct pci_error_handlers *err_handler; const struct pci_error_handlers *err_handler;
device_lock(&dev->dev); device_lock(&dev->dev);
pdrv = dev->driver; pdrv = to_pci_driver(dev->dev.driver);
if (!pdrv || if (!pdrv ||
!pdrv->err_handler || !pdrv->err_handler ||
!pdrv->err_handler->slot_reset) !pdrv->err_handler->slot_reset)
...@@ -139,7 +139,7 @@ static int report_resume(struct pci_dev *dev, void *data) ...@@ -139,7 +139,7 @@ static int report_resume(struct pci_dev *dev, void *data)
const struct pci_error_handlers *err_handler; const struct pci_error_handlers *err_handler;
device_lock(&dev->dev); device_lock(&dev->dev);
pdrv = dev->driver; pdrv = to_pci_driver(dev->dev.driver);
if (!pci_dev_set_io_state(dev, pci_channel_io_normal) || if (!pci_dev_set_io_state(dev, pci_channel_io_normal) ||
!pdrv || !pdrv ||
!pdrv->err_handler || !pdrv->err_handler ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment