2019-11-18 00:22:33

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH v2 1/4] skd: 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/skd_main.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index 51569c199a6c..f25f6ef6b4c7 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -3134,18 +3134,14 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);

static char *skd_pci_info(struct skd_device *skdev, char *str)
{
- int pcie_reg;
-
strcpy(str, "PCIe (");
- pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);

- if (pcie_reg) {
+ if (pci_is_pcie(skdev->pdev)) {

char lwstr[6];
uint16_t pcie_lstat, lspeed, lwidth;

- pcie_reg += 0x12;
- pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat);
+ pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
lspeed = pcie_lstat & (0xF);
lwidth = (pcie_lstat & 0x3F0) >> 4;

--
2.20.1


2019-11-18 01:47:19

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] skd: Prefer pcie_capability_read_word()

On 2019/11/18 9:21, Frederick Lawler wrote:
> 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/skd_main.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
> index 51569c199a6c..f25f6ef6b4c7 100644
> --- a/drivers/block/skd_main.c
> +++ b/drivers/block/skd_main.c
> @@ -3134,18 +3134,14 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
>
> static char *skd_pci_info(struct skd_device *skdev, char *str)
> {
> - int pcie_reg;
> -
> strcpy(str, "PCIe (");
> - pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
>
> - if (pcie_reg) {
> + if (pci_is_pcie(skdev->pdev)) {

Maybe return early here ? The reason is that if pci_is_pcie() is false,
then the string "PCIe (" is not terminated with a closing parenthesis.
So something like:

if (!pci_is_pcie(skdev->pdev)) {
strcat(str, ")");
return str;
}

May be better. Note that the "return str" is also rather pointless since
it is not used by the caller of skd_pci_info().

>
> char lwstr[6];
> uint16_t pcie_lstat, lspeed, lwidth;
>
> - pcie_reg += 0x12;
> - pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat);
> + pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
> lspeed = pcie_lstat & (0xF);
> lwidth = (pcie_lstat & 0x3F0) >> 4;
>
>


--
Damien Le Moal
Western Digital Research

2019-11-19 01:24:44

by Frederick Lawler

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] skd: Prefer pcie_capability_read_word()

Damien Le Moal wrote on 11/17/19 7:45 PM:
> On 2019/11/18 9:21, Frederick Lawler wrote:
>> 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/skd_main.c | 8 ++------
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
>> index 51569c199a6c..f25f6ef6b4c7 100644
>> --- a/drivers/block/skd_main.c
>> +++ b/drivers/block/skd_main.c
>> @@ -3134,18 +3134,14 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
>>
>> static char *skd_pci_info(struct skd_device *skdev, char *str)
>> {
>> - int pcie_reg;
>> -
>> strcpy(str, "PCIe (");
>> - pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
>>
>> - if (pcie_reg) {
>> + if (pci_is_pcie(skdev->pdev)) {
>
> Maybe return early here ? The reason is that if pci_is_pcie() is false,
> then the string "PCIe (" is not terminated with a closing parenthesis.
> So something like:
>
> if (!pci_is_pcie(skdev->pdev)) {
> strcat(str, ")");
> return str;
> }
>
> May be better. Note that the "return str" is also rather pointless since
> it is not used by the caller of skd_pci_info().
>

I agree, but it might be better to include a note that this is not a
PCIe device. Reading "PCIe ()" seems weird to me.

>>
>> char lwstr[6];
>> uint16_t pcie_lstat, lspeed, lwidth;
>>
>> - pcie_reg += 0x12;
>> - pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat);
>> + pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
>> lspeed = pcie_lstat & (0xF);
>> lwidth = (pcie_lstat & 0x3F0) >> 4;
>>
>>
>
>

Thanks,
Frederick Lawler

2019-11-19 02:46:22

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] skd: Prefer pcie_capability_read_word()

On 2019/11/19 10:20, Frederick Lawler wrote:
> Damien Le Moal wrote on 11/17/19 7:45 PM:
>> On 2019/11/18 9:21, Frederick Lawler wrote:
>>> 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/skd_main.c | 8 ++------
>>> 1 file changed, 2 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
>>> index 51569c199a6c..f25f6ef6b4c7 100644
>>> --- a/drivers/block/skd_main.c
>>> +++ b/drivers/block/skd_main.c
>>> @@ -3134,18 +3134,14 @@ MODULE_DEVICE_TABLE(pci, skd_pci_tbl);
>>>
>>> static char *skd_pci_info(struct skd_device *skdev, char *str)
>>> {
>>> - int pcie_reg;
>>> -
>>> strcpy(str, "PCIe (");
>>> - pcie_reg = pci_find_capability(skdev->pdev, PCI_CAP_ID_EXP);
>>>
>>> - if (pcie_reg) {
>>> + if (pci_is_pcie(skdev->pdev)) {
>>
>> Maybe return early here ? The reason is that if pci_is_pcie() is false,
>> then the string "PCIe (" is not terminated with a closing parenthesis.
>> So something like:
>>
>> if (!pci_is_pcie(skdev->pdev)) {
>> strcat(str, ")");
>> return str;
>> }
>>
>> May be better. Note that the "return str" is also rather pointless since
>> it is not used by the caller of skd_pci_info().
>>
>
> I agree, but it might be better to include a note that this is not a
> PCIe device. Reading "PCIe ()" seems weird to me.

Yes indeed. But since this device is PCIe only, if
pci_is_pcie(skdev->pdev) == false, we should probably fail the driver
initialization.

>
>>>
>>> char lwstr[6];
>>> uint16_t pcie_lstat, lspeed, lwidth;
>>>
>>> - pcie_reg += 0x12;
>>> - pci_read_config_word(skdev->pdev, pcie_reg, &pcie_lstat);
>>> + pcie_capability_read_word(skdev->pdev, 0x12, &pcie_lstat);
>>> lspeed = pcie_lstat & (0xF);
>>> lwidth = (pcie_lstat & 0x3F0) >> 4;
>>>
>>>
>>
>>
>
> Thanks,
> Frederick Lawler
>
>


--
Damien Le Moal
Western Digital Research