2023-03-23 08:50:45

by Cai Huoqing

[permalink] [raw]
Subject: [PATCH] accel/habanalabs: Remove redundant pci_clear_master

Remove pci_clear_master to simplify the code,
the bus-mastering is also cleared in do_pci_disable_device,
like this:
./drivers/pci/pci.c:2197
static void do_pci_disable_device(struct pci_dev *dev)
{
u16 pci_command;

pci_read_config_word(dev, PCI_COMMAND, &pci_command);
if (pci_command & PCI_COMMAND_MASTER) {
pci_command &= ~PCI_COMMAND_MASTER;
pci_write_config_word(dev, PCI_COMMAND, pci_command);
}

pcibios_disable_device(dev);
}.
And dev->is_busmaster is set to 0 in pci_disable_device.

Signed-off-by: Cai Huoqing <[email protected]>
---
drivers/accel/habanalabs/common/device.c | 1 -
drivers/accel/habanalabs/common/pci/pci.c | 2 --
2 files changed, 3 deletions(-)

diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c
index 713005998cbc..2fb1e2ec3a83 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -1271,7 +1271,6 @@ int hl_device_resume(struct hl_device *hdev)
return 0;

disable_device:
- pci_clear_master(hdev->pdev);
pci_disable_device(hdev->pdev);

return rc;
diff --git a/drivers/accel/habanalabs/common/pci/pci.c b/drivers/accel/habanalabs/common/pci/pci.c
index d1f4c695baf2..191e0e3cf3a5 100644
--- a/drivers/accel/habanalabs/common/pci/pci.c
+++ b/drivers/accel/habanalabs/common/pci/pci.c
@@ -420,7 +420,6 @@ int hl_pci_init(struct hl_device *hdev)
unmap_pci_bars:
hl_pci_bars_unmap(hdev);
disable_device:
- pci_clear_master(pdev);
pci_disable_device(pdev);

return rc;
@@ -436,6 +435,5 @@ void hl_pci_fini(struct hl_device *hdev)
{
hl_pci_bars_unmap(hdev);

- pci_clear_master(hdev->pdev);
pci_disable_device(hdev->pdev);
}
--
2.34.1


2023-03-23 10:41:05

by Stanislaw Gruszka

[permalink] [raw]
Subject: Re: [PATCH] accel/habanalabs: Remove redundant pci_clear_master

On Thu, Mar 23, 2023 at 04:35:49PM +0800, Cai Huoqing wrote:
> Remove pci_clear_master to simplify the code,
> the bus-mastering is also cleared in do_pci_disable_device,
> like this:
> ./drivers/pci/pci.c:2197
> static void do_pci_disable_device(struct pci_dev *dev)
> {
> u16 pci_command;
>
> pci_read_config_word(dev, PCI_COMMAND, &pci_command);
> if (pci_command & PCI_COMMAND_MASTER) {
> pci_command &= ~PCI_COMMAND_MASTER;
> pci_write_config_word(dev, PCI_COMMAND, pci_command);
> }
>
> pcibios_disable_device(dev);
> }.
> And dev->is_busmaster is set to 0 in pci_disable_device.
>
> Signed-off-by: Cai Huoqing <[email protected]>
LGTM

Reviewed-by: Stanislaw Gruszka <[email protected]>

2023-03-23 10:43:12

by Oded Gabbay

[permalink] [raw]
Subject: Re: [PATCH] accel/habanalabs: Remove redundant pci_clear_master

On Thu, Mar 23, 2023 at 12:29 PM Stanislaw Gruszka
<[email protected]> wrote:
>
> On Thu, Mar 23, 2023 at 04:35:49PM +0800, Cai Huoqing wrote:
> > Remove pci_clear_master to simplify the code,
> > the bus-mastering is also cleared in do_pci_disable_device,
> > like this:
> > ./drivers/pci/pci.c:2197
> > static void do_pci_disable_device(struct pci_dev *dev)
> > {
> > u16 pci_command;
> >
> > pci_read_config_word(dev, PCI_COMMAND, &pci_command);
> > if (pci_command & PCI_COMMAND_MASTER) {
> > pci_command &= ~PCI_COMMAND_MASTER;
> > pci_write_config_word(dev, PCI_COMMAND, pci_command);
> > }
> >
> > pcibios_disable_device(dev);
> > }.
> > And dev->is_busmaster is set to 0 in pci_disable_device.
> >
> > Signed-off-by: Cai Huoqing <[email protected]>
> LGTM
>
> Reviewed-by: Stanislaw Gruszka <[email protected]>
>
Applied to -next
Thanks,
Oded