mbox series

[0/4] Add support for AMD USB4 and bug fixes

Message ID 1627909100-83338-1-git-send-email-Sanju.Mehta@amd.com
Headers show
Series Add support for AMD USB4 and bug fixes | expand

Message

Sanjay R Mehta Aug. 2, 2021, 12:58 p.m. UTC
From: Sanjay R Mehta <sanju.mehta@amd.com>

This series adds support for AMD USB4 host router and
some general USB4 bug fixes.

Sanjay R Mehta (4):
  PCI: Add AMD USB4 host router device IDs
  thunderbolt: Handle INTR when Disable ISR auto clear bit set
  thunderbolt: Fix adapter init handling during switch add
  thunderbolt: Fix port linking by checking all adapters

 drivers/thunderbolt/nhi.c    | 30 +++++++++++++++++++++++++++++-
 drivers/thunderbolt/switch.c |  5 +++--
 include/linux/pci_ids.h      |  2 ++
 include/linux/thunderbolt.h  |  1 +
 4 files changed, 35 insertions(+), 3 deletions(-)

Comments

Mika Westerberg Aug. 2, 2021, 3:12 p.m. UTC | #1
On Mon, Aug 02, 2021 at 07:58:17AM -0500, Sanjay R Mehta wrote:
> From: Sanjay R Mehta <sanju.mehta@amd.com>
> 
> This patch enables support for AMD USB4 host router.
> 
> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>
> ---
>  drivers/thunderbolt/nhi.c | 4 ++++
>  include/linux/pci_ids.h   | 2 ++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
> index fa44332..d7d9c4b 100644
> --- a/drivers/thunderbolt/nhi.c
> +++ b/drivers/thunderbolt/nhi.c
> @@ -1338,6 +1338,10 @@ static struct pci_device_id nhi_ids[] = {
>  	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL_NHI1),
>  	  .driver_data = (kernel_ulong_t)&icl_nhi_ops },
>  
> +	/* AMD USB4 host */
> +	{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA0) },
> +	{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA1) },
> +
>  	/* Any USB4 compliant host */
>  	{ PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
>  
> diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
> index 4bac183..6d50019 100644
> --- a/include/linux/pci_ids.h
> +++ b/include/linux/pci_ids.h
> @@ -604,6 +604,8 @@
>  #define PCI_DEVICE_ID_AMD_HUDSON2_SMBUS		0x780b
>  #define PCI_DEVICE_ID_AMD_HUDSON2_IDE		0x780c
>  #define PCI_DEVICE_ID_AMD_KERNCZ_SMBUS  0x790b
> +#define PCI_DEVICE_ID_AMD_USB4_HIA0	0x162e
> +#define PCI_DEVICE_ID_AMD_USB4_HIA1	0x162f

No need to add them here (and you actually should not since these IDs
are not shared between multiple drivers, see the top level comment in
this header).

I suggest adding these to drivers/thunderbolt/nhi.h instead.

>  
>  #define PCI_VENDOR_ID_TRIDENT		0x1023
>  #define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX	0x2000
> -- 
> 2.7.4
Mika Westerberg Aug. 2, 2021, 3:26 p.m. UTC | #2
On Mon, Aug 02, 2021 at 07:58:19AM -0500, Sanjay R Mehta wrote:
> From: Sanjay R Mehta <sanju.mehta@amd.com>
> 
> Adapter0 (Port0) is the control adapter on the AMD USB4 host router.
> As per USB4 spec in "Section 1.8", Control Adapters do not
> have an Adapter Configuration Space".
> 
> The read requests on Adapter0 time's out and driver initialization fails.
> 
> Hence Disabling the Adapter in case of read-request timeout and continuing
> the driver init.
> 
> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>
> ---
>  drivers/thunderbolt/switch.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
> index 83b1ef3..effbfe4 100644
> --- a/drivers/thunderbolt/switch.c
> +++ b/drivers/thunderbolt/switch.c
> @@ -2747,8 +2747,9 @@ int tb_switch_add(struct tb_switch *sw)
>  			}
>  			ret = tb_init_port(&sw->ports[i]);
>  			if (ret) {
> +				sw->ports[i].disabled = true;
>  				dev_err(&sw->dev, "failed to initialize port %d\n", i);
> -				return ret;
> +				continue;

Instead of this, would it work if we start the loop at 1? In case of the
control adapter (0) tb_port_init() does not do anything useful anyway
and it actually would simplify that function too if we get rid of the
special casing.

>  			}
>  		}
>  
> -- 
> 2.7.4
Sanjay R Mehta Aug. 2, 2021, 6:53 p.m. UTC | #3
On 8/2/2021 8:56 PM, Mika Westerberg wrote:
> [CAUTION: External Email]
> 
> On Mon, Aug 02, 2021 at 07:58:19AM -0500, Sanjay R Mehta wrote:
>> From: Sanjay R Mehta <sanju.mehta@amd.com>
>>
>> Adapter0 (Port0) is the control adapter on the AMD USB4 host router.
>> As per USB4 spec in "Section 1.8", Control Adapters do not
>> have an Adapter Configuration Space".
>>
>> The read requests on Adapter0 time's out and driver initialization fails.
>>
>> Hence Disabling the Adapter in case of read-request timeout and continuing
>> the driver init.
>>
>> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
>> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>
>> ---
>>  drivers/thunderbolt/switch.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
>> index 83b1ef3..effbfe4 100644
>> --- a/drivers/thunderbolt/switch.c
>> +++ b/drivers/thunderbolt/switch.c
>> @@ -2747,8 +2747,9 @@ int tb_switch_add(struct tb_switch *sw)
>>                       }
>>                       ret = tb_init_port(&sw->ports[i]);
>>                       if (ret) {
>> +                             sw->ports[i].disabled = true;
>>                               dev_err(&sw->dev, "failed to initialize port %d\n", i);
>> -                             return ret;
>> +                             continue;
> 
> Instead of this, would it work if we start the loop at 1? In case of the
> control adapter (0) tb_port_init() does not do anything useful anyway
> and it actually would simplify that function too if we get rid of the
> special casing.
> 
Hi Mika,

If we start loop from 1, it will work for host router
but this will skip port (0) on device router which may be valid port.

Yes, as you said, for host router adapter (0) we can skip tb_port_init().

Will send the changes accordingly.

Thanks,
Sanjay

>>                       }
>>               }
>>
>> --
>> 2.7.4
Mika Westerberg Aug. 3, 2021, 9:05 a.m. UTC | #4
Hi,

On Tue, Aug 03, 2021 at 12:23:44AM +0530, Sanjay R Mehta wrote:
> 

> 

> On 8/2/2021 8:56 PM, Mika Westerberg wrote:

> > [CAUTION: External Email]

> > 

> > On Mon, Aug 02, 2021 at 07:58:19AM -0500, Sanjay R Mehta wrote:

> >> From: Sanjay R Mehta <sanju.mehta@amd.com>

> >>

> >> Adapter0 (Port0) is the control adapter on the AMD USB4 host router.

> >> As per USB4 spec in "Section 1.8", Control Adapters do not

> >> have an Adapter Configuration Space".

> >>

> >> The read requests on Adapter0 time's out and driver initialization fails.

> >>

> >> Hence Disabling the Adapter in case of read-request timeout and continuing

> >> the driver init.

> >>

> >> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

> >> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>

> >> ---

> >>  drivers/thunderbolt/switch.c | 3 ++-

> >>  1 file changed, 2 insertions(+), 1 deletion(-)

> >>

> >> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c

> >> index 83b1ef3..effbfe4 100644

> >> --- a/drivers/thunderbolt/switch.c

> >> +++ b/drivers/thunderbolt/switch.c

> >> @@ -2747,8 +2747,9 @@ int tb_switch_add(struct tb_switch *sw)

> >>                       }

> >>                       ret = tb_init_port(&sw->ports[i]);

> >>                       if (ret) {

> >> +                             sw->ports[i].disabled = true;

> >>                               dev_err(&sw->dev, "failed to initialize port %d\n", i);

> >> -                             return ret;

> >> +                             continue;

> > 

> > Instead of this, would it work if we start the loop at 1? In case of the

> > control adapter (0) tb_port_init() does not do anything useful anyway

> > and it actually would simplify that function too if we get rid of the

> > special casing.

> > 

> Hi Mika,

> 

> If we start loop from 1, it will work for host router

> but this will skip port (0) on device router which may be valid port.


For device router adapter 0 is also contror adapter so I think we can
just skip it here unconditionally.
Mika Westerberg Aug. 3, 2021, 9:45 a.m. UTC | #5
Hi,

I have one more comment, see below.

On Mon, Aug 02, 2021 at 11:39:32PM +0530, Sanjay R Mehta wrote:
> 

> 

> On 8/2/2021 8:42 PM, Mika Westerberg wrote:

> > [CAUTION: External Email]

> > 

> > On Mon, Aug 02, 2021 at 07:58:17AM -0500, Sanjay R Mehta wrote:

> >> From: Sanjay R Mehta <sanju.mehta@amd.com>

> >>

> >> This patch enables support for AMD USB4 host router.

> >>

> >> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

> >> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>

> >> ---

> >>  drivers/thunderbolt/nhi.c | 4 ++++

> >>  include/linux/pci_ids.h   | 2 ++

> >>  2 files changed, 6 insertions(+)

> >>

> >> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c

> >> index fa44332..d7d9c4b 100644

> >> --- a/drivers/thunderbolt/nhi.c

> >> +++ b/drivers/thunderbolt/nhi.c

> >> @@ -1338,6 +1338,10 @@ static struct pci_device_id nhi_ids[] = {

> >>       { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL_NHI1),

> >>         .driver_data = (kernel_ulong_t)&icl_nhi_ops },

> >>

> >> +     /* AMD USB4 host */

> >> +     { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA0) },

> >> +     { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA1) },

> >> +


I wonder if AMD USB4 controller exposes the USB4 PCI class ID? If that's
the case and you don't need any special quirking like Intel does then we
don't need to add any PCI IDs here and allow the below line to match.

This is actually what I hope we get eventually in Intel HW too.

> >>       /* Any USB4 compliant host */

> >>       { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
Sanjay R Mehta Aug. 3, 2021, 12:26 p.m. UTC | #6
On 8/3/2021 3:15 PM, Mika Westerberg wrote:
> [CAUTION: External Email]

> 

> Hi,

> 

> I have one more comment, see below.

> 

> On Mon, Aug 02, 2021 at 11:39:32PM +0530, Sanjay R Mehta wrote:

>>

>>

>> On 8/2/2021 8:42 PM, Mika Westerberg wrote:

>>> [CAUTION: External Email]

>>>

>>> On Mon, Aug 02, 2021 at 07:58:17AM -0500, Sanjay R Mehta wrote:

>>>> From: Sanjay R Mehta <sanju.mehta@amd.com>

>>>>

>>>> This patch enables support for AMD USB4 host router.

>>>>

>>>> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

>>>> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>

>>>> ---

>>>>  drivers/thunderbolt/nhi.c | 4 ++++

>>>>  include/linux/pci_ids.h   | 2 ++

>>>>  2 files changed, 6 insertions(+)

>>>>

>>>> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c

>>>> index fa44332..d7d9c4b 100644

>>>> --- a/drivers/thunderbolt/nhi.c

>>>> +++ b/drivers/thunderbolt/nhi.c

>>>> @@ -1338,6 +1338,10 @@ static struct pci_device_id nhi_ids[] = {

>>>>       { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ADL_NHI1),

>>>>         .driver_data = (kernel_ulong_t)&icl_nhi_ops },

>>>>

>>>> +     /* AMD USB4 host */

>>>> +     { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA0) },

>>>> +     { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_USB4_HIA1) },

>>>> +

> 

> I wonder if AMD USB4 controller exposes the USB4 PCI class ID? If that's

> the case and you don't need any special quirking like Intel does then we

> don't need to add any PCI IDs here and allow the below line to match.

> 

> This is actually what I hope we get eventually in Intel HW too.


yes, make sense. Will remove this from the series.

Thanks,
Sanjay

> 

>>>>       /* Any USB4 compliant host */

>>>>       { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
Sanjay R Mehta Aug. 3, 2021, 12:29 p.m. UTC | #7
On 8/3/2021 2:35 PM, Mika Westerberg wrote:
> [CAUTION: External Email]

> 

> Hi,

> 

> On Tue, Aug 03, 2021 at 12:23:44AM +0530, Sanjay R Mehta wrote:

>>

>>

>> On 8/2/2021 8:56 PM, Mika Westerberg wrote:

>>> [CAUTION: External Email]

>>>

>>> On Mon, Aug 02, 2021 at 07:58:19AM -0500, Sanjay R Mehta wrote:

>>>> From: Sanjay R Mehta <sanju.mehta@amd.com>

>>>>

>>>> Adapter0 (Port0) is the control adapter on the AMD USB4 host router.

>>>> As per USB4 spec in "Section 1.8", Control Adapters do not

>>>> have an Adapter Configuration Space".

>>>>

>>>> The read requests on Adapter0 time's out and driver initialization fails.

>>>>

>>>> Hence Disabling the Adapter in case of read-request timeout and continuing

>>>> the driver init.

>>>>

>>>> Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

>>>> Signed-off-by: Sanjay R Mehta <sanju.mehta@amd.com>

>>>> ---

>>>>  drivers/thunderbolt/switch.c | 3 ++-

>>>>  1 file changed, 2 insertions(+), 1 deletion(-)

>>>>

>>>> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c

>>>> index 83b1ef3..effbfe4 100644

>>>> --- a/drivers/thunderbolt/switch.c

>>>> +++ b/drivers/thunderbolt/switch.c

>>>> @@ -2747,8 +2747,9 @@ int tb_switch_add(struct tb_switch *sw)

>>>>                       }

>>>>                       ret = tb_init_port(&sw->ports[i]);

>>>>                       if (ret) {

>>>> +                             sw->ports[i].disabled = true;

>>>>                               dev_err(&sw->dev, "failed to initialize port %d\n", i);

>>>> -                             return ret;

>>>> +                             continue;

>>>

>>> Instead of this, would it work if we start the loop at 1? In case of the

>>> control adapter (0) tb_port_init() does not do anything useful anyway

>>> and it actually would simplify that function too if we get rid of the

>>> special casing.

>>>

>> Hi Mika,

>>

>> If we start loop from 1, it will work for host router

>> but this will skip port (0) on device router which may be valid port.

> 

> For device router adapter 0 is also contror adapter so I think we can

> just skip it here unconditionally.


Sure Mika. Will send the updated changes.

Thanks,
Sanjay

>