2019-11-18 00:22:34

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH v2 0/4] skd/mtip32xx: Prefer pcie_capability_read_word()

Hi,

These changes are in reference to Bjorn's suggestions here:
https://lore.kernel.org/lkml/CAErSpo6BmWDxi3Vckm03=fZHEUosTgkMUjqCvYRA186jv8XbFw@mail.gmail.com/
https://lore.kernel.org/lkml/CAErSpo5TZC3iM09SB1td+F7b-+aiu9EHwPYa1ayiU-i1tseV5w@mail.gmail.com/

And the patches are rebased ontop of 54ecb8f7028c ("Linux 5.4-rc1")

Changes since v1:
* Replace magic numbers constants

This is a long time coming, apologies for dragging my feet on getting
these trivial patches out.

Frederick Lawler (4):
skd: Prefer pcie_capability_read_word()
skd: Replace magic numbers with PCI constants
mtip32xx: Prefer pcie_capability_read_word()
mtip32xx: Replace magic numbers with PCI constants

drivers/block/mtip32xx/mtip32xx.c | 28 ++++++++++++----------------
drivers/block/skd_main.c | 14 ++++++--------
2 files changed, 18 insertions(+), 24 deletions(-)

--
2.20.1


2019-11-18 00:22:39

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH v2 2/4] skd: Replace magic numbers with PCI constants

Readability was improved by replacing pci_read_config_word() with
pcie_capability_read_word(). Take that a step further by replacing magic
numbers with PCI reg constants.

No functional change intended.

Signed-off-by: Frederick Lawler <[email protected]>
---
v2
- Added this patch
---
drivers/block/skd_main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index f25f6ef6b4c7..7f8243573ad9 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -3141,9 +3141,11 @@ static char *skd_pci_info(struct skd_device *skdev, char *str)
char lwstr[6];
uint16_t pcie_lstat, lspeed, lwidth;

- pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
- lspeed = pcie_lstat & (0xF);
- lwidth = (pcie_lstat & 0x3F0) >> 4;
+ pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA,
+ &pcie_lstat);
+ lspeed = pcie_lstat & PCI_EXP_LNKSTA_CLS;
+ lwidth = (pcie_lstat & PCI_EXP_LNKSTA_NLW) >>
+ PCI_EXP_LNKSTA_NLW_SHIFT;

if (lspeed == 1)
strcat(str, "2.5GT/s ");
--
2.20.1

2019-11-18 00:23:12

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH v2 4/4] mtip32xx: Replace magic numbers with PCI constants

Readability was improved by replacing pci_read_config_word() with
pcie_capability_read_word(). Take that a step further by replacing magic
numbers with PCI reg constants.

No functional change intended.

Signed-off-by: Frederick Lawler <[email protected]>
---
v2:
- Added this patch
---
drivers/block/mtip32xx/mtip32xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 35703dc98e25..225c6ae62385 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -3942,8 +3942,8 @@ static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
return;

pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &pcie_dev_ctrl);
- if (pcie_dev_ctrl & (1 << 11) ||
- pcie_dev_ctrl & (1 << 4)) {
+ if (pcie_dev_ctrl & PCI_EXP_DEVCTL_NOSNOOP_EN ||
+ pcie_dev_ctrl & PCI_EXP_DEVCTL_RELAX_EN) {
dev_info(&dd->pdev->dev,
"Disabling ERO/No-Snoop on bridge device %04x:%04x\n",
pdev->vendor, pdev->device);
--
2.20.1

2019-11-18 00:25:29

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH v2 3/4] mtip32xx: Prefer pcie_capability_read_word()

Commit 8c0d3a02c130 ("PCI: Add accessors for PCI Express Capability")
added accessors for the PCI Express Capability so that drivers didn't
need to be aware of differences between v1 and v2 of the PCI
Express Capability.

Replace pci_read_config_word() and pci_write_config_word() calls with
pcie_capability_read_word() and pcie_capability_write_word().

Signed-off-by: Frederick Lawler <[email protected]>
---
drivers/block/mtip32xx/mtip32xx.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 964f78cfffa0..35703dc98e25 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -3938,22 +3938,18 @@ static void mtip_disable_link_opts(struct driver_data *dd, struct pci_dev *pdev)
int pos;
unsigned short pcie_dev_ctrl;

- pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
- if (pos) {
- pci_read_config_word(pdev,
- pos + PCI_EXP_DEVCTL,
- &pcie_dev_ctrl);
- if (pcie_dev_ctrl & (1 << 11) ||
- pcie_dev_ctrl & (1 << 4)) {
- dev_info(&dd->pdev->dev,
- "Disabling ERO/No-Snoop on bridge device %04x:%04x\n",
- pdev->vendor, pdev->device);
- pcie_dev_ctrl &= ~(PCI_EXP_DEVCTL_NOSNOOP_EN |
- PCI_EXP_DEVCTL_RELAX_EN);
- pci_write_config_word(pdev,
- pos + PCI_EXP_DEVCTL,
- pcie_dev_ctrl);
- }
+ if (!pci_is_pcie(pdev))
+ return;
+
+ pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &pcie_dev_ctrl);
+ if (pcie_dev_ctrl & (1 << 11) ||
+ pcie_dev_ctrl & (1 << 4)) {
+ dev_info(&dd->pdev->dev,
+ "Disabling ERO/No-Snoop on bridge device %04x:%04x\n",
+ pdev->vendor, pdev->device);
+ pcie_dev_ctrl &= ~(PCI_EXP_DEVCTL_NOSNOOP_EN |
+ PCI_EXP_DEVCTL_RELAX_EN);
+ pcie_capability_write_word(pdev, PCI_EXP_DEVCTL, pcie_dev_ctrl);
}
}

--
2.20.1

2019-11-18 01:47:59

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] skd: Replace magic numbers with PCI constants

On 2019/11/18 9:21, Frederick Lawler wrote:
> Readability was improved by replacing pci_read_config_word() with
> pcie_capability_read_word(). Take that a step further by replacing magic
> numbers with PCI reg constants.
>
> No functional change intended.
>
> Signed-off-by: Frederick Lawler <[email protected]>
> ---
> v2
> - Added this patch
> ---
> drivers/block/skd_main.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
> index f25f6ef6b4c7..7f8243573ad9 100644
> --- a/drivers/block/skd_main.c
> +++ b/drivers/block/skd_main.c
> @@ -3141,9 +3141,11 @@ static char *skd_pci_info(struct skd_device *skdev, char *str)
> char lwstr[6];
> uint16_t pcie_lstat, lspeed, lwidth;
>
> - pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
> - lspeed = pcie_lstat & (0xF);
> - lwidth = (pcie_lstat & 0x3F0) >> 4;
> + pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA,
> + &pcie_lstat);
> + lspeed = pcie_lstat & PCI_EXP_LNKSTA_CLS;
> + lwidth = (pcie_lstat & PCI_EXP_LNKSTA_NLW) >>
> + PCI_EXP_LNKSTA_NLW_SHIFT;
>
> if (lspeed == 1)
> strcat(str, "2.5GT/s ");
>

Looks OK to me. But since this is changing again one line that is added
by patch 1/4, why not make patch 1 and this patch changes a single patch ?

--
Damien Le Moal
Western Digital Research

2019-11-19 01:25:00

by Frederick Lawler

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] skd: Replace magic numbers with PCI constants

Hi,

Damien Le Moal wrote on 11/17/19 7:45 PM:
> On 2019/11/18 9:21, Frederick Lawler wrote:
>> Readability was improved by replacing pci_read_config_word() with
>> pcie_capability_read_word(). Take that a step further by replacing magic
>> numbers with PCI reg constants.
>>
>> No functional change intended.
>>
>> Signed-off-by: Frederick Lawler <[email protected]>
>> ---
>> v2
>> - Added this patch
>> ---
>> drivers/block/skd_main.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
>> index f25f6ef6b4c7..7f8243573ad9 100644
>> --- a/drivers/block/skd_main.c
>> +++ b/drivers/block/skd_main.c
>> @@ -3141,9 +3141,11 @@ static char *skd_pci_info(struct skd_device *skdev, char *str)
>> char lwstr[6];
>> uint16_t pcie_lstat, lspeed, lwidth;
>>
>> - pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
>> - lspeed = pcie_lstat & (0xF);
>> - lwidth = (pcie_lstat & 0x3F0) >> 4;
>> + pcie_capability_read_word(skdev->pdev, PCI_EXP_LNKSTA,
>> + &pcie_lstat);
>> + lspeed = pcie_lstat & PCI_EXP_LNKSTA_CLS;
>> + lwidth = (pcie_lstat & PCI_EXP_LNKSTA_NLW) >>
>> + PCI_EXP_LNKSTA_NLW_SHIFT;
>>
>> if (lspeed == 1)
>> strcat(str, "2.5GT/s ");
>>
>
> Looks OK to me. But since this is changing again one line that is added
> by patch 1/4, why not make patch 1 and this patch changes a single patch ?
>

Works for me.

Thanks,
Frederick Lawler