2024-02-07 09:59:21

by Andrey Melnikov

[permalink] [raw]
Subject: [PATCH] ahci: asm1064: correct count of reported ports

The ASM1064 SATA host controller always reports wrongly,
that it has 24 ports. But in reality, it only has four ports.

before:
ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst

after:
ahci 0000:04:00.0: ASM1064 has only four ports
ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst


Signed-off-by: Andrey Jr. Melnikov <[email protected]>

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index da2e74fce2d9..ec30d8330d16 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
static void ahci_pci_save_initial_config(struct pci_dev *pdev,
struct ahci_host_priv *hpriv)
{
- if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
- dev_info(&pdev->dev, "ASM1166 has only six ports\n");
- hpriv->saved_port_map = 0x3f;
+ if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
+ if (pdev->device == 0x1166) {
+ dev_info(&pdev->dev, "ASM1166 has only six ports\n");
+ hpriv->saved_port_map = 0x3f;
+ } else if (pdev->device == 0x1064) {
+ dev_info(&pdev->dev, "ASM1064 has only four ports\n");
+ hpriv->saved_port_map = 0xf;
+ }
}

if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {


2024-02-07 11:15:42

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

Hi Andrey

On 2/7/24 10:58, Andrey Jr. Melnikov wrote:
> The ASM1064 SATA host controller always reports wrongly,
> that it has 24 ports. But in reality, it only has four ports.
>
> before:
> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>
> after:
> ahci 0000:04:00.0: ASM1064 has only four ports
> ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode

This still says 24 ports, is that a copy & paste error in the commit msg ?

Regards,

Hans



> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>
>
> Signed-off-by: Andrey Jr. Melnikov <[email protected]>
>
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index da2e74fce2d9..ec30d8330d16 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> struct ahci_host_priv *hpriv)
> {
> - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> - hpriv->saved_port_map = 0x3f;
> + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> + if (pdev->device == 0x1166) {
> + dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> + hpriv->saved_port_map = 0x3f;
> + } else if (pdev->device == 0x1064) {
> + dev_info(&pdev->dev, "ASM1064 has only four ports\n");
> + hpriv->saved_port_map = 0xf;
> + }
> }
>
> if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
>


2024-02-07 11:28:46

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:

> The ASM1064 SATA host controller always reports wrongly,
> that it has 24 ports. But in reality, it only has four ports.
>
> before:
> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>
> after:
> ahci 0000:04:00.0: ASM1064 has only four ports
> ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>
>
> Signed-off-by: Andrey Jr. Melnikov <[email protected]>
>
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index da2e74fce2d9..ec30d8330d16 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> struct ahci_host_priv *hpriv)
> {
> - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> - hpriv->saved_port_map = 0x3f;
> + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> + if (pdev->device == 0x1166) {

Maybe *switch* instead?

> + dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> + hpriv->saved_port_map = 0x3f;
> + } else if (pdev->device == 0x1064) {
> + dev_info(&pdev->dev, "ASM1064 has only four ports\n");
> + hpriv->saved_port_map = 0xf;
> + }
> }
>
> if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {

MBR, Sergey

2024-02-08 07:21:33

by Andrey Melnikov

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

>
> Hi Andrey
>
> On 2/7/24 10:58, Andrey Jr. Melnikov wrote:
> > The ASM1064 SATA host controller always reports wrongly,
> > that it has 24 ports. But in reality, it only has four ports.
> >
> > before:
> > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> >
> > after:
> > ahci 0000:04:00.0: ASM1064 has only four ports
> > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
>
> This still says 24 ports, is that a copy & paste error in the commit msg ?

This is the raw value of the read-only Host Capability register, how
should it be changed here? If silicon lies about its configuration -
kerel prints what it sees from silicon.

2024-02-08 07:27:35

by Andrey Melnikov

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

> On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
>
> > The ASM1064 SATA host controller always reports wrongly,
> > that it has 24 ports. But in reality, it only has four ports.
> >
> > before:
> > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> >
> > after:
> > ahci 0000:04:00.0: ASM1064 has only four ports
> > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> >
> >
> > Signed-off-by: Andrey Jr. Melnikov <[email protected]>
> >
> > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > index da2e74fce2d9..ec30d8330d16 100644
> > --- a/drivers/ata/ahci.c
> > +++ b/drivers/ata/ahci.c
> > @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> > static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> > struct ahci_host_priv *hpriv)
> > {
> > - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> > - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > - hpriv->saved_port_map = 0x3f;
> > + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> > + if (pdev->device == 0x1166) {
>
> Maybe *switch* instead?

Ok.
Can someone explain to me - which method I should use here - override
portmap via hpriv->saved_port_map or mask it via hpriv->mask_port_map
?

> > + dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > + hpriv->saved_port_map = 0x3f;
> > + } else if (pdev->device == 0x1064) {
> > + dev_info(&pdev->dev, "ASM1064 has only four ports\n");
> > + hpriv->saved_port_map = 0xf;
> > + }
> > }
> >
> > if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {

2024-02-08 07:46:26

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

On 2/8/24 16:21, Andrey Melnikov wrote:
>>
>> Hi Andrey
>>
>> On 2/7/24 10:58, Andrey Jr. Melnikov wrote:
>>> The ASM1064 SATA host controller always reports wrongly,
>>> that it has 24 ports. But in reality, it only has four ports.
>>>
>>> before:
>>> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
>>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
>>> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>>>
>>> after:
>>> ahci 0000:04:00.0: ASM1064 has only four ports
>>> ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
>>> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
>>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
>>
>> This still says 24 ports, is that a copy & paste error in the commit msg ?
>
> This is the raw value of the read-only Host Capability register, how
> should it be changed here? If silicon lies about its configuration -
> kerel prints what it sees from silicon.

This should print the actual number of ports that you forced with the port map
change:

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 1a63200ea437..7cb3f137bc1b 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -2637,7 +2637,7 @@ void ahci_print_info(struct ata_host *host, const char *scc_s)
vers & 0xff,

((cap >> 8) & 0x1f) + 1,
- (cap & 0x1f) + 1,
+ (cap & hpriv->saved_port_map) + 1,
speed_s,
impl,
scc_s);


--
Damien Le Moal
Western Digital Research


2024-02-08 08:39:38

by Niklas Cassel

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

Hello Serge, Andrey,

On Thu, Feb 08, 2024 at 10:27:11AM +0300, Andrey Melnikov wrote:
> > On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
> >
> > > The ASM1064 SATA host controller always reports wrongly,
> > > that it has 24 ports. But in reality, it only has four ports.
> > >
> > > before:
> > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > >
> > > after:
> > > ahci 0000:04:00.0: ASM1064 has only four ports
> > > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > >
> > >
> > > Signed-off-by: Andrey Jr. Melnikov <[email protected]>
> > >
> > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > > index da2e74fce2d9..ec30d8330d16 100644
> > > --- a/drivers/ata/ahci.c
> > > +++ b/drivers/ata/ahci.c
> > > @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> > > static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> > > struct ahci_host_priv *hpriv)
> > > {
> > > - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> > > - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > > - hpriv->saved_port_map = 0x3f;
> > > + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> > > + if (pdev->device == 0x1166) {
> >
> > Maybe *switch* instead?
>
> Ok.
> Can someone explain to me - which method I should use here - override
> portmap via hpriv->saved_port_map or mask it via hpriv->mask_port_map
> ?

Serge, you seem to be the last person to touch this in
commit 88589772e80c ("ata: libahci: Discard redundant force_port_map
parameter"), where you removed force_port_map, so you are already
familiar with this code.

From my quick look, it looks like mask_port_map is used to disable one or
more ports from the port_map.

But do you know if there is a reason why platforms that need to do that
can't just change saved_port map directly?


Kind regards,
Niklas

2024-02-08 12:04:58

by Andrey Melnikov

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

Hello.

> Hello Serge, Andrey,
>
> On Thu, Feb 08, 2024 at 10:27:11AM +0300, Andrey Melnikov wrote:
> > > On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
> > >
> > > > The ASM1064 SATA host controller always reports wrongly,
> > > > that it has 24 ports. But in reality, it only has four ports.
> > > >
> > > > before:
> > > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > > >
> > > > after:
> > > > ahci 0000:04:00.0: ASM1064 has only four ports
> > > > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> > > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > > >
> > > >
> > > > Signed-off-by: Andrey Jr. Melnikov <[email protected]>
> > > >
> > > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > > > index da2e74fce2d9..ec30d8330d16 100644
> > > > --- a/drivers/ata/ahci.c
> > > > +++ b/drivers/ata/ahci.c
> > > > @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> > > > static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> > > > struct ahci_host_priv *hpriv)
> > > > {
> > > > - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> > > > - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > > > - hpriv->saved_port_map = 0x3f;
> > > > + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> > > > + if (pdev->device == 0x1166) {
> > >
> > > Maybe *switch* instead?
> >
> > Ok.
> > Can someone explain to me - which method I should use here - override
> > portmap via hpriv->saved_port_map or mask it via hpriv->mask_port_map
> > ?
>
> Serge, you seem to be the last person to touch this in
> commit 88589772e80c ("ata: libahci: Discard redundant force_port_map
> parameter"), where you removed force_port_map, so you are already
> familiar with this code.
>
> From my quick look, it looks like mask_port_map is used to disable one or
> more ports from the port_map.
>
> But do you know if there is a reason why platforms that need to do that
> can't just change saved_port map directly?

Well, after deep dive into git history - initially, overriding
port_map introduced by commits
d799e083a80b220f3681d7790f11e77d1704022b (jmb361 workaround) and
cd70c26617f4686355263be4533ce8030242740e (marvel 6145 support), both
override port mapping, but in different ways - first set to 1, second
- apply masks. Logically - port_map = 1 and port_map &= 1 - are the
same.
Later, in commit 394d6e535f15c6f2d3c7fe2e228ee595acf0648c this two
hacks moved around, and setting port_map splitted into two ways - set
it directly via force_port_map (jmb361 workaround) and apply mask via
mask_port_map (marvel 6145 hack).
And now, we have two knobs which do the same! After that, commit
566d1827df2ef0cbe921d3d6946ac3007b1a6938 add checking AHCI version
(yet another SATA glitches workaround, user report [1] shows 8 port
and bitmask 0xff - 32 ports) and this break updating saved_port_map
for AHCI >= 1.3. Later, commit
2fd0f46cb1b82587c7ae4a616d69057fb9bd0af7 fix saving port_map again,
and now overriding port_map completely splitted. saved_port_map is
really saved (and written back to HOST_PORTS_IMPL register on
saved_port map()) for all AHCI versions, mask_port_map is applied and
not updated saved_port_map.

1. https://lists.openwall.net/linux-kernel/2016/01/13/171

2024-02-13 17:43:22

by Niklas Cassel

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

On Thu, Feb 08, 2024 at 10:27:11AM +0300, Andrey Melnikov wrote:
> > On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
> >
> > > The ASM1064 SATA host controller always reports wrongly,
> > > that it has 24 ports. But in reality, it only has four ports.
> > >
> > > before:
> > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > >
> > > after:
> > > ahci 0000:04:00.0: ASM1064 has only four ports
> > > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > >
> > >
> > > Signed-off-by: Andrey Jr. Melnikov <[email protected]>
> > >
> > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > > index da2e74fce2d9..ec30d8330d16 100644
> > > --- a/drivers/ata/ahci.c
> > > +++ b/drivers/ata/ahci.c
> > > @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> > > static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> > > struct ahci_host_priv *hpriv)
> > > {
> > > - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> > > - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > > - hpriv->saved_port_map = 0x3f;
> > > + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> > > + if (pdev->device == 0x1166) {
> >
> > Maybe *switch* instead?
>
> Ok.

Hello Andrey,

do you intend to send out a v2 that uses a switch instead?

And perhaps take Damien's patch as patch 1/2
(with Suggested-by: Damien ... of course),
so that the before/after print in your commit message shows
the override value.


Kind regards,
Niklas

2024-02-13 18:06:11

by Niklas Cassel

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

On Tue, Feb 13, 2024 at 06:19:10PM +0100, Niklas Cassel wrote:
> On Thu, Feb 08, 2024 at 10:27:11AM +0300, Andrey Melnikov wrote:
> > > On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
> > >
> > > > The ASM1064 SATA host controller always reports wrongly,
> > > > that it has 24 ports. But in reality, it only has four ports.
> > > >
> > > > before:
> > > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
> > > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > > >
> > > > after:
> > > > ahci 0000:04:00.0: ASM1064 has only four ports
> > > > ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
> > > > ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
> > > > ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
> > > > ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
> > > >
> > > >
> > > > Signed-off-by: Andrey Jr. Melnikov <[email protected]>
> > > >
> > > > diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> > > > index da2e74fce2d9..ec30d8330d16 100644
> > > > --- a/drivers/ata/ahci.c
> > > > +++ b/drivers/ata/ahci.c
> > > > @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
> > > > static void ahci_pci_save_initial_config(struct pci_dev *pdev,
> > > > struct ahci_host_priv *hpriv)
> > > > {
> > > > - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
> > > > - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
> > > > - hpriv->saved_port_map = 0x3f;
> > > > + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
> > > > + if (pdev->device == 0x1166) {
> > >
> > > Maybe *switch* instead?
> >
> > Ok.
>
> Hello Andrey,
>
> do you intend to send out a v2 that uses a switch instead?
>
> And perhaps take Damien's patch as patch 1/2
> (with Suggested-by: Damien ... of course),
> so that the before/after print in your commit message shows
> the override value.

On second thought, just go ahead and respin your patch using a switch,
as I don't think Damien's patch is fully correct.

He suggested to use hpriv->saved_port_map.

However, that will show the wrong result for platforms using
hpriv->mask_port_map.

As when hpriv->mask_port_map is used, saved_port_map is not set:
https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L536-L548

However, the local variable "port_map" is updated for both
saved_port_map and mask_port_map cases.

And then at the end:
hpriv->port_map = port_map;
https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L597

So I think we should print hpriv->port_map,
and not hpriv->saved_port_map.



However.. hpriv->port_map is already printed:
https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L2617
in the "0x%x impl" print.

So
> before:
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode

> after:
> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode

Actually prints the number of *implemented* ports.


I have to admit that this is a bit confusing.

Personally I would have preferred if we simply printed
"%u ports", hpriv->port_map,

and simply dropped the "0x%x impl" part of the print,
but I'm a bit worried that someone parses this print from user space,
but I guess we must be allowed to improve prints if they are confusing.

Damien, what do you think?


Kind regards,
Niklas

2024-02-14 00:34:06

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH] ahci: asm1064: correct count of reported ports

On 2/14/24 03:05, Niklas Cassel wrote:
> On Tue, Feb 13, 2024 at 06:19:10PM +0100, Niklas Cassel wrote:
>> On Thu, Feb 08, 2024 at 10:27:11AM +0300, Andrey Melnikov wrote:
>>>> On 2/7/24 12:58 PM, Andrey Jr. Melnikov wrote:
>>>>
>>>>> The ASM1064 SATA host controller always reports wrongly,
>>>>> that it has 24 ports. But in reality, it only has four ports.
>>>>>
>>>>> before:
>>>>> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
>>>>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
>>>>> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>>>>>
>>>>> after:
>>>>> ahci 0000:04:00.0: ASM1064 has only four ports
>>>>> ahci 0000:04:00.0: forcing port_map 0xffff0f -> 0xf
>>>>> ahci 0000:04:00.0: SSS flag set, parallel bus scan disabled
>>>>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
>>>>> ahci 0000:04:00.0: flags: 64bit ncq sntf stag pm led only pio sxs deso sadm sds apst
>>>>>
>>>>>
>>>>> Signed-off-by: Andrey Jr. Melnikov <[email protected]>
>>>>>
>>>>> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
>>>>> index da2e74fce2d9..ec30d8330d16 100644
>>>>> --- a/drivers/ata/ahci.c
>>>>> +++ b/drivers/ata/ahci.c
>>>>> @@ -671,9 +671,14 @@ MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
>>>>> static void ahci_pci_save_initial_config(struct pci_dev *pdev,
>>>>> struct ahci_host_priv *hpriv)
>>>>> {
>>>>> - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == 0x1166) {
>>>>> - dev_info(&pdev->dev, "ASM1166 has only six ports\n");
>>>>> - hpriv->saved_port_map = 0x3f;
>>>>> + if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA) {
>>>>> + if (pdev->device == 0x1166) {
>>>>
>>>> Maybe *switch* instead?
>>>
>>> Ok.
>>
>> Hello Andrey,
>>
>> do you intend to send out a v2 that uses a switch instead?
>>
>> And perhaps take Damien's patch as patch 1/2
>> (with Suggested-by: Damien ... of course),
>> so that the before/after print in your commit message shows
>> the override value.
>
> On second thought, just go ahead and respin your patch using a switch,
> as I don't think Damien's patch is fully correct.
>
> He suggested to use hpriv->saved_port_map.
>
> However, that will show the wrong result for platforms using
> hpriv->mask_port_map.
>
> As when hpriv->mask_port_map is used, saved_port_map is not set:
> https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L536-L548
>
> However, the local variable "port_map" is updated for both
> saved_port_map and mask_port_map cases.
>
> And then at the end:
> hpriv->port_map = port_map;
> https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L597
>
> So I think we should print hpriv->port_map,
> and not hpriv->saved_port_map.

Indeed, good catch...

> However.. hpriv->port_map is already printed:
> https://github.com/torvalds/linux/blob/v6.8-rc4/drivers/ata/libahci.c#L2617
> in the "0x%x impl" print.
>
> So
>> before:
>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xffff0f impl SATA mode
>
>> after:
>> ahci 0000:04:00.0: AHCI 0001.0301 32 slots 24 ports 6 Gbps 0xf impl SATA mode
>
> Actually prints the number of *implemented* ports.
>
>
> I have to admit that this is a bit confusing.
>
> Personally I would have preferred if we simply printed
> "%u ports", hpriv->port_map,
>
> and simply dropped the "0x%x impl" part of the print,
> but I'm a bit worried that someone parses this print from user space,
> but I guess we must be allowed to improve prints if they are confusing.
>
> Damien, what do you think?

..but port_map is a mask, not a count of ports. So this would still be wrong.
I think we simply need a small helper that look something like:

int ahci_nr_ports(struct ata_host *host)
{
struct ahci_host_priv *hpriv = host->private_data;
int i, n = 0;

for_each_set_bit(i, &hpriv->port_map, AHCI_MAX_PORTS)
n++;

return n;
}

and print that instead together with the mask.

--
Damien Le Moal
Western Digital Research