Hi,
Linux FireWire subsystem includes a driver (firewire-ohci) for 1394 OHCI
controller. The code of driver is mostly written at the time when device
managed resource (devres) was not widely used. Nowadays the usage of
devres is standard when writing drivers. The series is an adoption of
devres for firewire-ohci.
I note that MSI-related operation is left as is. The hardware vendors
forms their products of extension card with 1394 OHCI controller
connected to PCIe bus by several ways. If chip of 1394 OHCI controller has
PCIe interface (e.g. VIA VT6315, LSI FW643), it is just connected to PCIe
bus. If the chip has PCI interface only, it is connected to PCIe bus via
PCI/PCIe bridge chip (e.g. VIA VT6307 + asmedia ASM1083). There is some
chip of 1394 OHCI controller integrated with the bus bridge (e.g. TI
XIO2213, XIO2221). The MSI-related operation should cover the above
forms as well as module option, while it is still unclear that the
operation from pci device driver to the bus bridge.
Takashi Sakamoto (9):
firewire: ohci: use devres for memory object of ohci structure
firewire: ohci: use devres for PCI-related resources
firewire: ohci: use devres for MMIO region mapping
firewire: ohci: use devres for misc DMA buffer
firewire: ohci: use devres for requested IRQ
firewire: ohci: use devres for list of isochronous contexts
firewire: ohci: use devres for IT, IR, AT/receive, and AT/request
contexts
firewire: ohci: use devres for content of configuration ROM
firewire: ohci: release buffer for AR req/resp contexts when managed
resource is released
drivers/firewire/ohci.c | 174 +++++++++++++++-------------------------
1 file changed, 63 insertions(+), 111 deletions(-)
--
2.39.2
The 1394 OHCI driver allocates the list of isochronous contexts as much
as the hardware supports.
This commit utilizes managed device resource to maintain the lifetime of
list.
Signed-off-by: Takashi Sakamoto <[email protected]>
---
drivers/firewire/ohci.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index cb6b43e3f67e..086505bd1729 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -3666,7 +3666,11 @@ static int pci_probe(struct pci_dev *dev,
ohci->ir_context_mask = ohci->ir_context_support;
ohci->n_ir = hweight32(ohci->ir_context_mask);
size = sizeof(struct iso_context) * ohci->n_ir;
- ohci->ir_context_list = kzalloc(size, GFP_KERNEL);
+ ohci->ir_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL);
+ if (!ohci->ir_context_list) {
+ err = -ENOMEM;
+ goto fail_atresp_ctx;
+ }
reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
ohci->it_context_support = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
@@ -3679,11 +3683,10 @@ static int pci_probe(struct pci_dev *dev,
ohci->it_context_mask = ohci->it_context_support;
ohci->n_it = hweight32(ohci->it_context_mask);
size = sizeof(struct iso_context) * ohci->n_it;
- ohci->it_context_list = kzalloc(size, GFP_KERNEL);
-
- if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
+ ohci->it_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL);
+ if (!ohci->it_context_list) {
err = -ENOMEM;
- goto fail_contexts;
+ goto fail_atresp_ctx;
}
ohci->self_id = ohci->misc_buffer + PAGE_SIZE/2;
@@ -3721,9 +3724,7 @@ static int pci_probe(struct pci_dev *dev,
fail_msi:
pci_disable_msi(dev);
- fail_contexts:
- kfree(ohci->ir_context_list);
- kfree(ohci->it_context_list);
+ fail_atresp_ctx:
context_release(&ohci->at_response_ctx);
fail_atreq_ctx:
context_release(&ohci->at_request_ctx);
@@ -3767,8 +3768,6 @@ static void pci_remove(struct pci_dev *dev)
ar_context_release(&ohci->ar_response_ctx);
context_release(&ohci->at_request_ctx);
context_release(&ohci->at_response_ctx);
- kfree(ohci->it_context_list);
- kfree(ohci->ir_context_list);
pci_disable_msi(dev);
dev_notice(&dev->dev, "removing fw-ohci device\n");
--
2.39.2
The PCI framework supports managed device resource to maintain the
lifetime of PCI specific resources.
This commit allows 1394 OHCI driver to utilize it.
Signed-off-by: Takashi Sakamoto <[email protected]>
---
drivers/firewire/ohci.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 2b02cebcb0ae..f3d0882a876c 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -3588,7 +3588,7 @@ static int pci_probe(struct pci_dev *dev,
pmac_ohci_on(dev);
devres_add(&dev->dev, ohci);
- err = pci_enable_device(dev);
+ err = pcim_enable_device(dev);
if (err) {
dev_err(&dev->dev, "failed to enable OHCI hardware\n");
return err;
@@ -3605,14 +3605,13 @@ static int pci_probe(struct pci_dev *dev,
if (!(pci_resource_flags(dev, 0) & IORESOURCE_MEM) ||
pci_resource_len(dev, 0) < OHCI1394_REGISTER_SIZE) {
ohci_err(ohci, "invalid MMIO resource\n");
- err = -ENXIO;
- goto fail_disable;
+ return -ENXIO;
}
err = pci_request_region(dev, 0, ohci_driver_name);
if (err) {
ohci_err(ohci, "MMIO resource unavailable\n");
- goto fail_disable;
+ return err;
}
ohci->registers = pci_iomap(dev, 0, OHCI1394_REGISTER_SIZE);
@@ -3752,8 +3751,6 @@ static int pci_probe(struct pci_dev *dev,
pci_iounmap(dev, ohci->registers);
fail_iomem:
pci_release_region(dev, 0);
- fail_disable:
- pci_disable_device(dev);
return err;
}
@@ -3798,7 +3795,6 @@ static void pci_remove(struct pci_dev *dev)
pci_disable_msi(dev);
pci_iounmap(dev, ohci->registers);
pci_release_region(dev, 0);
- pci_disable_device(dev);
dev_notice(&dev->dev, "removing fw-ohci device\n");
}
--
2.39.2
The managed device resource (devres) framework is convenient to maintain
lifetime of allocated memory object for device.
This commit utilizes the framework for the object of ohci structure. The
extra operation for power management is required in Apple PowerMac based
machines, thus release callback is assigned to the object to call the
operation.
Signed-off-by: Takashi Sakamoto <[email protected]>
---
drivers/firewire/ohci.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 06386c3b7f03..2b02cebcb0ae 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -3557,6 +3557,15 @@ static inline void pmac_ohci_on(struct pci_dev *dev) {}
static inline void pmac_ohci_off(struct pci_dev *dev) {}
#endif /* CONFIG_PPC_PMAC */
+static void release_ohci(struct device *dev, void *data)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+
+ pmac_ohci_off(pdev);
+
+ dev_notice(dev, "removed fw-ohci device\n");
+}
+
static int pci_probe(struct pci_dev *dev,
const struct pci_device_id *ent)
{
@@ -3571,25 +3580,22 @@ static int pci_probe(struct pci_dev *dev,
return -ENOSYS;
}
- ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
- if (ohci == NULL) {
- err = -ENOMEM;
- goto fail;
- }
-
+ ohci = devres_alloc(release_ohci, sizeof(*ohci), GFP_KERNEL);
+ if (ohci == NULL)
+ return -ENOMEM;
fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev);
-
+ pci_set_drvdata(dev, ohci);
pmac_ohci_on(dev);
+ devres_add(&dev->dev, ohci);
err = pci_enable_device(dev);
if (err) {
dev_err(&dev->dev, "failed to enable OHCI hardware\n");
- goto fail_free;
+ return err;
}
pci_set_master(dev);
pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0);
- pci_set_drvdata(dev, ohci);
spin_lock_init(&ohci->lock);
mutex_init(&ohci->phy_reg_mutex);
@@ -3748,10 +3754,7 @@ static int pci_probe(struct pci_dev *dev,
pci_release_region(dev, 0);
fail_disable:
pci_disable_device(dev);
- fail_free:
- kfree(ohci);
- pmac_ohci_off(dev);
- fail:
+
return err;
}
@@ -3796,10 +3799,8 @@ static void pci_remove(struct pci_dev *dev)
pci_iounmap(dev, ohci->registers);
pci_release_region(dev, 0);
pci_disable_device(dev);
- kfree(ohci);
- pmac_ohci_off(dev);
- dev_notice(&dev->dev, "removed fw-ohci device\n");
+ dev_notice(&dev->dev, "removing fw-ohci device\n");
}
#ifdef CONFIG_PM
--
2.39.2
On Sun, Jun 04, 2023 at 02:44:42PM +0900, Takashi Sakamoto wrote:
> Hi,
>
> Linux FireWire subsystem includes a driver (firewire-ohci) for 1394 OHCI
> controller. The code of driver is mostly written at the time when device
> managed resource (devres) was not widely used. Nowadays the usage of
> devres is standard when writing drivers. The series is an adoption of
> devres for firewire-ohci.
>
> I note that MSI-related operation is left as is. The hardware vendors
> forms their products of extension card with 1394 OHCI controller
> connected to PCIe bus by several ways. If chip of 1394 OHCI controller has
> PCIe interface (e.g. VIA VT6315, LSI FW643), it is just connected to PCIe
> bus. If the chip has PCI interface only, it is connected to PCIe bus via
> PCI/PCIe bridge chip (e.g. VIA VT6307 + asmedia ASM1083). There is some
> chip of 1394 OHCI controller integrated with the bus bridge (e.g. TI
> XIO2213, XIO2221). The MSI-related operation should cover the above
> forms as well as module option, while it is still unclear that the
> operation from pci device driver to the bus bridge.
>
> Takashi Sakamoto (9):
> firewire: ohci: use devres for memory object of ohci structure
> firewire: ohci: use devres for PCI-related resources
> firewire: ohci: use devres for MMIO region mapping
> firewire: ohci: use devres for misc DMA buffer
> firewire: ohci: use devres for requested IRQ
> firewire: ohci: use devres for list of isochronous contexts
> firewire: ohci: use devres for IT, IR, AT/receive, and AT/request
> contexts
> firewire: ohci: use devres for content of configuration ROM
> firewire: ohci: release buffer for AR req/resp contexts when managed
> resource is released
>
> drivers/firewire/ohci.c | 174 +++++++++++++++-------------------------
> 1 file changed, 63 insertions(+), 111 deletions(-)
Applied to for-next branch.
Regards
Takashi Sakamoto