Skip to contentSkip to conversation

Add support for AMD USB4 and bug fixes

PATCH In review Sanjay R Mehta 3 participants 16 messages Aug 2, 2021 – Aug 3, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add support for AMD USB4 and bug fixes

From: Sanjay R Mehta <[email protected]>

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(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 PCI: Add AMD USB4 host router device IDs

From: Sanjay R Mehta <[email protected]>

This patch enables support for AMD USB4 host router.

---
 drivers/thunderbolt/nhi.c | 4 ++++
 include/linux/pci_ids.h   | 2 ++
 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +4 -0
index fa44332..d7d9c4b 100644
@@ -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) },
 
include/linux/pci_ids.h +2 -0
index 4bac183..6d50019 100644
@@ -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
 
 #define PCI_VENDOR_ID_TRIDENT		0x1023
 #define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX	0x2000
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/4] PCI: Add AMD USB4 host router device IDs

Quoted 31 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

This patch enables support for AMD USB4 host router.

---
 drivers/thunderbolt/nhi.c | 4 ++++
 include/linux/pci_ids.h   | 2 ++
 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +4 -0
index fa44332..d7d9c4b 100644
@@ -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) },
 
include/linux/pci_ids.h +0 -0
index 4bac183..6d50019 100644

include/linux/pci_ids.h line 608

Quoted 5 lines
include/linux/pci_ids.h +2 -0
@@ -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.

Quoted 5 lines
include/linux/pci_ids.h +0 -0
 #define PCI_VENDOR_ID_TRIDENT		0x1023
 #define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX	0x2000
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH 1/4] PCI: Add AMD USB4 host router device IDs

Quoted 44 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 31 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

This patch enables support for AMD USB4 host router.

---
 drivers/thunderbolt/nhi.c | 4 ++++
 include/linux/pci_ids.h   | 2 ++
 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +4 -0
index fa44332..d7d9c4b 100644
@@ -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) },
 
include/linux/pci_ids.h +0 -0
index 4bac183..6d50019 100644

include/linux/pci_ids.h line 608

Quoted 5 lines
include/linux/pci_ids.h +2 -0
@@ -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).

Quoted 2 lines

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

Thanks Mika. Agree and will add it in drivers/thunderbolt/nhi.h .

Quoted 5 lines
Quoted 5 lines
include/linux/pci_ids.h +0 -1
 #define PCI_VENDOR_ID_TRIDENT                0x1023
 #define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX      0x2000
--

2.7.4

#4 lore raw

Re: [PATCH 1/4] PCI: Add AMD USB4 host router device IDs

Hi,

I have one more comment, see below.

Quoted 25 lines · Sanjay R Mehta
Quoted 22 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 19 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

This patch enables support for AMD USB4 host router.

---
 drivers/thunderbolt/nhi.c | 4 ++++
 include/linux/pci_ids.h   | 2 ++
 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +0 -0
index fa44332..d7d9c4b 100644
@@ -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 },
 
Quoted 4 lines
Quoted 4 lines

drivers/thunderbolt/nhi.c static struct pci_device_id nhi_ids[] = { · line 1344

Quoted 4 lines
drivers/thunderbolt/nhi.c +4 -0
+     /* 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.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/thunderbolt/nhi.c +0 -0
      /* Any USB4 compliant host */
      { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
#5 lore raw

Re: [PATCH 1/4] PCI: Add AMD USB4 host router device IDs

Quoted 41 lines · Mika Westerberg

[CAUTION: External Email]

Hi,

I have one more comment, see below.

Quoted 25 lines · Sanjay R Mehta
Quoted 22 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 19 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

This patch enables support for AMD USB4 host router.

---
 drivers/thunderbolt/nhi.c | 4 ++++
 include/linux/pci_ids.h   | 2 ++
 2 files changed, 6 insertions(+)
drivers/thunderbolt/nhi.c +0 -0
index fa44332..d7d9c4b 100644
@@ -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 },
 
Quoted 4 lines
Quoted 4 lines

drivers/thunderbolt/nhi.c static struct pci_device_id nhi_ids[] = { · line 1344

Quoted 4 lines
drivers/thunderbolt/nhi.c +4 -0
+     /* 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.

Quoted 1 line

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

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

Thanks,
Sanjay

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/thunderbolt/nhi.c +0 -0
      /* Any USB4 compliant host */
      { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) },
#6 lore raw

PATCH 2/4 thunderbolt: Handle INTR when Disable ISR auto clear bit set

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

when the "Disable ISR Auto-Clear" bit is set, the Tx/Rx ring interrupt status is not cleared. Hence handling it by setting the "Interrupt status clear" register to clear the corresponding Tx/Rx ring interrupt.

---
 drivers/thunderbolt/nhi.c   | 26 +++++++++++++++++++++++++-
 include/linux/thunderbolt.h |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/thunderbolt/nhi.c +25 -1
index d7d9c4b..63bbabf 100644
@@ -74,7 +74,11 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)
 		if (!(misc & REG_DMA_MISC_INT_AUTO_CLEAR)) {
 			misc |= REG_DMA_MISC_INT_AUTO_CLEAR;
 			iowrite32(misc, ring->nhi->iobase + REG_DMA_MISC);
-		}
+			misc = ioread32(ring->nhi->iobase + REG_DMA_MISC);
+			if (misc & REG_DMA_MISC_INT_AUTO_CLEAR)
+				ring->nhi->is_intr_autoclr = true;
+		} else
+			ring->nhi->is_intr_autoclr = true;
 
 		ivr_base = ring->nhi->iobase + REG_INT_VEC_ALLOC_BASE;
 		step = index / REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
@@ -377,11 +381,31 @@ void tb_ring_poll_complete(struct tb_ring *ring)
 }
 EXPORT_SYMBOL_GPL(tb_ring_poll_complete);
 
+static void check_and_clear_intr_status(struct tb_ring *ring, int int_pos)
+{
+	u32 value;
+
+	if (!ring->nhi->is_intr_autoclr) {
+		value = ioread32(ring->nhi->iobase
+					 + REG_RING_NOTIFY_BASE
+					 + 4 * (int_pos / 32));
+		iowrite32(value, ring->nhi->iobase
+			  + (REG_RING_NOTIFY_BASE + 8)
+			  + 4 * (int_pos / 32));
+	}
+}
+
 static irqreturn_t ring_msix(int irq, void *data)
 {
 	struct tb_ring *ring = data;
 
 	spin_lock(&ring->nhi->lock);
+
+	if (ring->is_tx)
+		check_and_clear_intr_status(ring, 0);
+	else
+		check_and_clear_intr_status(ring, ring->nhi->hop_count);
+
 	spin_lock(&ring->lock);
 	__ring_interrupt(ring);
 	spin_unlock(&ring->lock);
include/linux/thunderbolt.h +1 -0
index e7c96c3..bbe7c7e 100644
@@ -478,6 +478,7 @@ struct tb_nhi {
 	struct tb_ring **rx_rings;
 	struct ida msix_ida;
 	bool going_away;
+	bool is_intr_autoclr;
 	struct work_struct interrupt_work;
 	u32 hop_count;
 };
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH 2/4] thunderbolt: Handle INTR when Disable ISR auto clear bit set

Hi,

Quoted 6 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

when the "Disable ISR Auto-Clear" bit is set, the Tx/Rx ring interrupt status is not cleared. Hence handling it by setting the "Interrupt status clear" register to clear the corresponding Tx/Rx ring interrupt.

I think REG_DMA_MISC_INT_AUTO_CLEAR which is bit 2 in that register is actually Intel specific and not the same as in the USB4 spec bit 17. I guess the AMD controller works fine as is if this bit (2) is not set? If that's the case we can simply limit this behavior for Intel controllers.

Quoted 71 lines
---
 drivers/thunderbolt/nhi.c   | 26 +++++++++++++++++++++++++-
 include/linux/thunderbolt.h |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/thunderbolt/nhi.c +25 -1
index d7d9c4b..63bbabf 100644
@@ -74,7 +74,11 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)
 		if (!(misc & REG_DMA_MISC_INT_AUTO_CLEAR)) {
 			misc |= REG_DMA_MISC_INT_AUTO_CLEAR;
 			iowrite32(misc, ring->nhi->iobase + REG_DMA_MISC);
-		}
+			misc = ioread32(ring->nhi->iobase + REG_DMA_MISC);
+			if (misc & REG_DMA_MISC_INT_AUTO_CLEAR)
+				ring->nhi->is_intr_autoclr = true;
+		} else
+			ring->nhi->is_intr_autoclr = true;
 
 		ivr_base = ring->nhi->iobase + REG_INT_VEC_ALLOC_BASE;
 		step = index / REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
@@ -377,11 +381,31 @@ void tb_ring_poll_complete(struct tb_ring *ring)
 }
 EXPORT_SYMBOL_GPL(tb_ring_poll_complete);
 
+static void check_and_clear_intr_status(struct tb_ring *ring, int int_pos)
+{
+	u32 value;
+
+	if (!ring->nhi->is_intr_autoclr) {
+		value = ioread32(ring->nhi->iobase
+					 + REG_RING_NOTIFY_BASE
+					 + 4 * (int_pos / 32));
+		iowrite32(value, ring->nhi->iobase
+			  + (REG_RING_NOTIFY_BASE + 8)
+			  + 4 * (int_pos / 32));
+	}
+}
+
 static irqreturn_t ring_msix(int irq, void *data)
 {
 	struct tb_ring *ring = data;
 
 	spin_lock(&ring->nhi->lock);
+
+	if (ring->is_tx)
+		check_and_clear_intr_status(ring, 0);
+	else
+		check_and_clear_intr_status(ring, ring->nhi->hop_count);
+
 	spin_lock(&ring->lock);
 	__ring_interrupt(ring);
 	spin_unlock(&ring->lock);
include/linux/thunderbolt.h +1 -0
index e7c96c3..bbe7c7e 100644
@@ -478,6 +478,7 @@ struct tb_nhi {
 	struct tb_ring **rx_rings;
 	struct ida msix_ida;
 	bool going_away;
+	bool is_intr_autoclr;
 	struct work_struct interrupt_work;
 	u32 hop_count;
 };
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH 2/4] thunderbolt: Handle INTR when Disable ISR auto clear bit set

Quoted 12 lines · Mika Westerberg

[CAUTION: External Email]

Hi,

Quoted 6 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

when the "Disable ISR Auto-Clear" bit is set, the Tx/Rx ring interrupt status is not cleared. Hence handling it by setting the "Interrupt status clear" register to clear the corresponding Tx/Rx ring interrupt.

Quoted 5 lines

I think REG_DMA_MISC_INT_AUTO_CLEAR which is bit 2 in that register is actually Intel specific and not the same as in the USB4 spec bit 17. I guess the AMD controller works fine as is if this bit (2) is not set? If that's the case we can simply limit this behavior for Intel controllers.

Yes, you are right Mika. With bit 17 it's working for us and we didn't wanted to break Intel's functionality , hence we added this change which works for both :).

Yes, as you suggested, we can limit this to Intel controllers.

Will send the changes accordingly.

Thanks,
Sanjay

Quoted 71 lines
Quoted 71 lines
---
 drivers/thunderbolt/nhi.c   | 26 +++++++++++++++++++++++++-
 include/linux/thunderbolt.h |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/thunderbolt/nhi.c +25 -1
index d7d9c4b..63bbabf 100644
@@ -74,7 +74,11 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)
              if (!(misc & REG_DMA_MISC_INT_AUTO_CLEAR)) {
                      misc |= REG_DMA_MISC_INT_AUTO_CLEAR;
                      iowrite32(misc, ring->nhi->iobase + REG_DMA_MISC);
-             }
+                     misc = ioread32(ring->nhi->iobase + REG_DMA_MISC);
+                     if (misc & REG_DMA_MISC_INT_AUTO_CLEAR)
+                             ring->nhi->is_intr_autoclr = true;
+             } else
+                     ring->nhi->is_intr_autoclr = true;
 
              ivr_base = ring->nhi->iobase + REG_INT_VEC_ALLOC_BASE;
              step = index / REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
@@ -377,11 +381,31 @@ void tb_ring_poll_complete(struct tb_ring *ring)
 }
 EXPORT_SYMBOL_GPL(tb_ring_poll_complete);
 
+static void check_and_clear_intr_status(struct tb_ring *ring, int int_pos)
+{
+     u32 value;
+
+     if (!ring->nhi->is_intr_autoclr) {
+             value = ioread32(ring->nhi->iobase
+                                      + REG_RING_NOTIFY_BASE
+                                      + 4 * (int_pos / 32));
+             iowrite32(value, ring->nhi->iobase
+                       + (REG_RING_NOTIFY_BASE + 8)
+                       + 4 * (int_pos / 32));
+     }
+}
+
 static irqreturn_t ring_msix(int irq, void *data)
 {
      struct tb_ring *ring = data;
 
      spin_lock(&ring->nhi->lock);
+
+     if (ring->is_tx)
+             check_and_clear_intr_status(ring, 0);
+     else
+             check_and_clear_intr_status(ring, ring->nhi->hop_count);
+
      spin_lock(&ring->lock);
      __ring_interrupt(ring);
      spin_unlock(&ring->lock);
include/linux/thunderbolt.h +1 -1
index e7c96c3..bbe7c7e 100644
@@ -478,6 +478,7 @@ struct tb_nhi {
      struct tb_ring **rx_rings;
      struct ida msix_ida;
      bool going_away;
+     bool is_intr_autoclr;
      struct work_struct interrupt_work;
      u32 hop_count;
 };
--

2.7.4

#9 lore raw

PATCH 3/4 thunderbolt: Fix adapter init handling during switch add

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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.

---
 drivers/thunderbolt/switch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +2 -1
index 83b1ef3..effbfe4 100644
@@ -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;
 			}
 		}
 
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH 3/4] thunderbolt: Fix adapter init handling during switch add

Quoted 22 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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.

---
 drivers/thunderbolt/switch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +0 -0
index 83b1ef3..effbfe4 100644

drivers/thunderbolt/switch.c int tb_switch_add(struct tb_switch *sw) · line 2752

Quoted 7 lines
drivers/thunderbolt/switch.c +2 -1
@@ -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.

Quoted 5 lines
drivers/thunderbolt/switch.c +0 -0
 			}
 		}
 
Signature · 1 line
2.7.4
#11 lore raw

Re: [PATCH 3/4] thunderbolt: Fix adapter init handling during switch add

Quoted 29 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 26 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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.

---
 drivers/thunderbolt/switch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +1 -0
index 83b1ef3..effbfe4 100644
@@ -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;
Quoted 9 lines

drivers/thunderbolt/switch.c int tb_switch_add(struct tb_switch *sw) · line 2752

Quoted 3 lines
drivers/thunderbolt/switch.c +1 -1
                              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

Quoted 5 lines
Quoted 5 lines
drivers/thunderbolt/switch.c +0 -1
                      }
              }
 
--

2.7.4

#12 lore raw

Re: [PATCH 3/4] thunderbolt: Fix adapter init handling during switch add

Hi,

Quoted 41 lines · Sanjay R Mehta
Quoted 29 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 26 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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.

---
 drivers/thunderbolt/switch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +1 -0
index 83b1ef3..effbfe4 100644
@@ -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;
Quoted 9 lines

drivers/thunderbolt/switch.c int tb_switch_add(struct tb_switch *sw) · line 2752

Quoted 3 lines
drivers/thunderbolt/switch.c +1 -1
                              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.

Quoted 4 lines

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.

#13 lore raw

Re: [PATCH 3/4] thunderbolt: Fix adapter init handling during switch add

Quoted 46 lines · Mika Westerberg

[CAUTION: External Email]

Hi,

Quoted 41 lines · Sanjay R Mehta
Quoted 38 lines · Mika Westerberg

[CAUTION: External Email]

Quoted 22 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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.

---
 drivers/thunderbolt/switch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +0 -0
index 83b1ef3..effbfe4 100644

drivers/thunderbolt/switch.c int tb_switch_add(struct tb_switch *sw) · line 2752

Quoted 7 lines
drivers/thunderbolt/switch.c +2 -1
@@ -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.

Quoted 7 lines
Quoted 4 lines

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

Quoted 1 line
#14 lore raw

PATCH 4/4 thunderbolt: Fix port linking by checking all adapters

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

In tb_switch_default_link_ports(), while linking of ports, only odd-numbered ports (1,3,5..) are considered and even-numbered ports are not considered.

AMD host router has lane adapters at 2 & 3 and link ports at adapter-2 is not considered due to which lane bonding gets disabled.

Hence added a fix such that all ports are considered during linking of ports.

Fixes 0d46c08d1ed4 ("thunderbolt: Add default linking between lane adapters if not provided by DROM")
---
 drivers/thunderbolt/switch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/switch.c +1 -1
index effbfe4..8b2fe67 100644
@@ -2456,7 +2456,7 @@ static void tb_switch_default_link_ports(struct tb_switch *sw)
 {
 	int i;
 
-	for (i = 1; i <= sw->config.max_port_number; i += 2) {
+	for (i = 1; i <= sw->config.max_port_number; i++) {
 		struct tb_port *port = &sw->ports[i];
 		struct tb_port *subordinate;
 
Signature · 1 line
2.7.4
#15 lore raw
In reply to Sanjay R Mehta

Hi Sanjay,

Quoted 4 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

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

Nice to see AMD support being added! :) I have few comments on the series. I'll comment on the separate patches.

In general looks already good.

Quoted 15 lines

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(-)
Signature · 1 line
2.7.4