diff mbox series

[RFC,6/8] usb: xhci: Fix port minor revision

Message ID 4627ca7e922019cd9a37073db90e4e9cd585c97e.1612237179.git.Thinh.Nguyen@synopsys.com
State Superseded
Headers show
Series usb: Check for genXxY on host | expand

Commit Message

Thinh Nguyen Feb. 2, 2021, 3:42 a.m. UTC
Some hosts incorrectly use sub-minor version for minor version (i.e.
0x02 instead of 0x20 for bcdUSB 0x320 and 0x01 for bcdUSB 0x310).
Currently the xHCI driver works around this by just checking for minor
revision > 0x01 for USB 3.1 everywhere. With the addition of USB 3.2,
checking this gets a bit cumbersome. Since there is no USB release with
bcdUSB 0x301 to 0x309, we can assume that sub-minor version 01 to 09 is
incorrect. Let's try to fix this and use the minor revision that matches
with the USB/xHCI spec to help with the version checking within the
driver.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
 drivers/usb/host/xhci-mem.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Thinh Nguyen Feb. 3, 2021, 1:16 a.m. UTC | #1
Sergei Shtylyov wrote:
> Hello!

>

> On 02.02.2021 6:42, Thinh Nguyen wrote:

>

>> Some hosts incorrectly use sub-minor version for minor version (i.e.

>> 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01 for bcdUSB 0x310).

>> Currently the xHCI driver works around this by just checking for minor

>> revision > 0x01 for USB 3.1 everywhere. With the addition of USB 3.2,

>> checking this gets a bit cumbersome. Since there is no USB release with

>> bcdUSB 0x301 to 0x309, we can assume that sub-minor version 01 to 09 is

>> incorrect. Let's try to fix this and use the minor revision that matches

>> with the USB/xHCI spec to help with the version checking within the

>> driver.

>>

>> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

>> ---

>>   drivers/usb/host/xhci-mem.c | 9 +++++++++

>>   1 file changed, 9 insertions(+)

>>

>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c

>> index f2c4ee7c4786..34105b477c62 100644

>> --- a/drivers/usb/host/xhci-mem.c

>> +++ b/drivers/usb/host/xhci-mem.c

>> @@ -2129,6 +2129,15 @@ static void xhci_add_in_port(struct xhci_hcd

>> *xhci, unsigned int num_ports,

>>         if (major_revision == 0x03) {

>>           rhub = &xhci->usb3_rhub;

>> +        /*

>> +         * Some hosts incorrectly use sub-minor version for minor

>> +         * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01

>> +         * for bcdUSB 0x310). Since there is no USB release with sub

>> +         * minor version 0x301 to 0x309, we can assume that they are

>> +         * incorrect and fix it here.

>> +         */

>> +        if (!(minor_revision & 0xf0) && (minor_revision & 0x0f))

>> +            minor_revision = minor_revision << 4;

>

>    Why not:

>

>             minor_revision <<= 4;

>

> [...]

>

> MBR, Sergei


Sure, we can do that.

Thanks,
Thinh
David Laight Feb. 4, 2021, 10:16 a.m. UTC | #2
From: Thinh Nguyen

> Sent: 03 February 2021 01:16

> 

> Sergei Shtylyov wrote:

> > Hello!

> >

> > On 02.02.2021 6:42, Thinh Nguyen wrote:

> >

> >> Some hosts incorrectly use sub-minor version for minor version (i.e.

> >> 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01 for bcdUSB 0x310).

> >> Currently the xHCI driver works around this by just checking for minor

> >> revision > 0x01 for USB 3.1 everywhere. With the addition of USB 3.2,

> >> checking this gets a bit cumbersome. Since there is no USB release with

> >> bcdUSB 0x301 to 0x309, we can assume that sub-minor version 01 to 09 is

> >> incorrect. Let's try to fix this and use the minor revision that matches

> >> with the USB/xHCI spec to help with the version checking within the

> >> driver.

> >>

> >> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

> >> ---

> >>   drivers/usb/host/xhci-mem.c | 9 +++++++++

> >>   1 file changed, 9 insertions(+)

> >>

> >> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c

> >> index f2c4ee7c4786..34105b477c62 100644

> >> --- a/drivers/usb/host/xhci-mem.c

> >> +++ b/drivers/usb/host/xhci-mem.c

> >> @@ -2129,6 +2129,15 @@ static void xhci_add_in_port(struct xhci_hcd

> >> *xhci, unsigned int num_ports,

> >>         if (major_revision == 0x03) {

> >>           rhub = &xhci->usb3_rhub;

> >> +        /*

> >> +         * Some hosts incorrectly use sub-minor version for minor

> >> +         * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01

> >> +         * for bcdUSB 0x310). Since there is no USB release with sub

> >> +         * minor version 0x301 to 0x309, we can assume that they are

> >> +         * incorrect and fix it here.

> >> +         */

> >> +        if (!(minor_revision & 0xf0) && (minor_revision & 0x0f))

> >> +            minor_revision = minor_revision << 4;

> >

> >    Why not:

> >

> >             minor_revision <<= 4;

> >

> > [...]

> >

> > MBR, Sergei

> 

> Sure, we can do that.


Isn't it just:
		if (minor_revision < 0x10)
			minor_revision <<= 4;

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Thinh Nguyen Feb. 5, 2021, 1:31 a.m. UTC | #3
David Laight wrote:
> From: Thinh Nguyen

>> Sent: 03 February 2021 01:16

>>

>> Sergei Shtylyov wrote:

>>> Hello!

>>>

>>> On 02.02.2021 6:42, Thinh Nguyen wrote:

>>>

>>>> Some hosts incorrectly use sub-minor version for minor version (i.e.

>>>> 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01 for bcdUSB 0x310).

>>>> Currently the xHCI driver works around this by just checking for minor

>>>> revision > 0x01 for USB 3.1 everywhere. With the addition of USB 3.2,

>>>> checking this gets a bit cumbersome. Since there is no USB release with

>>>> bcdUSB 0x301 to 0x309, we can assume that sub-minor version 01 to 09 is

>>>> incorrect. Let's try to fix this and use the minor revision that matches

>>>> with the USB/xHCI spec to help with the version checking within the

>>>> driver.

>>>>

>>>> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

>>>> ---

>>>>   drivers/usb/host/xhci-mem.c | 9 +++++++++

>>>>   1 file changed, 9 insertions(+)

>>>>

>>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c

>>>> index f2c4ee7c4786..34105b477c62 100644

>>>> --- a/drivers/usb/host/xhci-mem.c

>>>> +++ b/drivers/usb/host/xhci-mem.c

>>>> @@ -2129,6 +2129,15 @@ static void xhci_add_in_port(struct xhci_hcd

>>>> *xhci, unsigned int num_ports,

>>>>         if (major_revision == 0x03) {

>>>>           rhub = &xhci->usb3_rhub;

>>>> +        /*

>>>> +         * Some hosts incorrectly use sub-minor version for minor

>>>> +         * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01

>>>> +         * for bcdUSB 0x310). Since there is no USB release with sub

>>>> +         * minor version 0x301 to 0x309, we can assume that they are

>>>> +         * incorrect and fix it here.

>>>> +         */

>>>> +        if (!(minor_revision & 0xf0) && (minor_revision & 0x0f))

>>>> +            minor_revision = minor_revision << 4;

>>>    Why not:

>>>

>>>             minor_revision <<= 4;

>>>

>>> [...]

>>>

>>> MBR, Sergei

>> Sure, we can do that.

> Isn't it just:

> 		if (minor_revision < 0x10)

> 			minor_revision <<= 4;

>

> 	David

>

>


Ah.... Not sure what I was thinking when I made that roundabout check.
Thanks for pointing it out.

Thinh
Thinh Nguyen Feb. 5, 2021, 3:30 a.m. UTC | #4
Thinh Nguyen wrote:
> David Laight wrote:

>> From: Thinh Nguyen

>>> Sent: 03 February 2021 01:16

>>>

>>> Sergei Shtylyov wrote:

>>>> Hello!

>>>>

>>>> On 02.02.2021 6:42, Thinh Nguyen wrote:

>>>>

>>>>> Some hosts incorrectly use sub-minor version for minor version (i.e.

>>>>> 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01 for bcdUSB 0x310).

>>>>> Currently the xHCI driver works around this by just checking for minor

>>>>> revision > 0x01 for USB 3.1 everywhere. With the addition of USB 3.2,

>>>>> checking this gets a bit cumbersome. Since there is no USB release with

>>>>> bcdUSB 0x301 to 0x309, we can assume that sub-minor version 01 to 09 is

>>>>> incorrect. Let's try to fix this and use the minor revision that matches

>>>>> with the USB/xHCI spec to help with the version checking within the

>>>>> driver.

>>>>>

>>>>> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

>>>>> ---

>>>>>   drivers/usb/host/xhci-mem.c | 9 +++++++++

>>>>>   1 file changed, 9 insertions(+)

>>>>>

>>>>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c

>>>>> index f2c4ee7c4786..34105b477c62 100644

>>>>> --- a/drivers/usb/host/xhci-mem.c

>>>>> +++ b/drivers/usb/host/xhci-mem.c

>>>>> @@ -2129,6 +2129,15 @@ static void xhci_add_in_port(struct xhci_hcd

>>>>> *xhci, unsigned int num_ports,

>>>>>         if (major_revision == 0x03) {

>>>>>           rhub = &xhci->usb3_rhub;

>>>>> +        /*

>>>>> +         * Some hosts incorrectly use sub-minor version for minor

>>>>> +         * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01

>>>>> +         * for bcdUSB 0x310). Since there is no USB release with sub

>>>>> +         * minor version 0x301 to 0x309, we can assume that they are

>>>>> +         * incorrect and fix it here.

>>>>> +         */

>>>>> +        if (!(minor_revision & 0xf0) && (minor_revision & 0x0f))

>>>>> +            minor_revision = minor_revision << 4;

>>>>    Why not:

>>>>

>>>>             minor_revision <<= 4;

>>>>

>>>> [...]

>>>>

>>>> MBR, Sergei

>>> Sure, we can do that.

>> Isn't it just:

>> 		if (minor_revision < 0x10)

>> 			minor_revision <<= 4;

>>

>> 	David

>>

>>

> Ah.... Not sure what I was thinking when I made that roundabout check.

> Thanks for pointing it out.


Btw, the intention is this:
if (minor_revision >  0x00 && minor_revision < 0x10) ...

It's much clearer this way. I'll make the change after more feedbacks on
other patches.

BR,
Thinh
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index f2c4ee7c4786..34105b477c62 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2129,6 +2129,15 @@  static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 
 	if (major_revision == 0x03) {
 		rhub = &xhci->usb3_rhub;
+		/*
+		 * Some hosts incorrectly use sub-minor version for minor
+		 * version (i.e. 0x02 instead of 0x20 for bcdUSB 0x320 and 0x01
+		 * for bcdUSB 0x310). Since there is no USB release with sub
+		 * minor version 0x301 to 0x309, we can assume that they are
+		 * incorrect and fix it here.
+		 */
+		if (!(minor_revision & 0xf0) && (minor_revision & 0x0f))
+			minor_revision = minor_revision << 4;
 	} else if (major_revision <= 0x02) {
 		rhub = &xhci->usb2_rhub;
 	} else {