Added some bug fixes for USB4
Subsystems (2)
v3 cover Added some bug fixes for USB4
From: Sanjay R Mehta <[email protected]>
This series adds some general USB4 bug fixes as per USB4 Spec.
v2:
- Added quirk to handle any vendor specific quirks.
v1:
- removed PCI-IDs as AMD USB4 controller exposes USB4 class ID.
- removed clearing of interrupt using interrupt status clear register.
- skip port Adapter(0) initialisation for both host router & device router.
Sanjay R Mehta (4):
thunderbolt: Add quirk to support vendor specific implementation
thunderbolt: Handle ring interrupt by reading intr status
thunderbolt: Skip port init for control adapter(0)
thunderbolt: Fix port linking by checking all adapters
drivers/thunderbolt/nhi.c | 32 ++++++++++++++++++++++++++++---- drivers/thunderbolt/switch.c | 4 ++-- include/linux/thunderbolt.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/4 thunderbolt: Add quirk to support vendor specific implementation
From: Sanjay R Mehta <[email protected]>
Introduce nhi_check_quirks() routine to handle any vendor specific quirks to manage a hardware specific implementation.
On Intel system, the USB4 controller requires the REG_DMA_MISC_INT_AUTO_CLEAR to be set. Hence handle it accordingly as per the USB4 specification via a quirk.
--- drivers/thunderbolt/nhi.c | 18 ++++++++++++++---- include/linux/thunderbolt.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/thunderbolt/nhi.c +14 -4
@@ -43,6 +43,12 @@ static int ring_interrupt_index(struct tb_ring *ring)return bit; } +static void nhi_check_quirks (struct tb_nhi *nhi) +{ +if (nhi->pdev->vendor ==PCI_VENDOR_ID_INTEL ) + nhi->quirks |=REG_DMA_MISC_INT_AUTO_CLEAR ; +} +/* * ring_interrupt_active() - activate/deactivate interrupts for a single ring *
@@ -70,10 +76,12 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)* Ask the hardware to clear interrupt status bits automatically * since we already know which interrupt was triggered. */ - misc =ioread32 (ring->nhi->iobase +REG_DMA_MISC ); -if (!(misc ®_DMA_MISC_INT_AUTO_CLEAR )) { - misc |=REG_DMA_MISC_INT_AUTO_CLEAR ; -iowrite32 (misc, ring->nhi->iobase +REG_DMA_MISC ); +if (ring->nhi->quirks ®_DMA_MISC_INT_AUTO_CLEAR ) { + misc =ioread32 (ring->nhi->iobase +REG_DMA_MISC ); +if (!(misc ®_DMA_MISC_INT_AUTO_CLEAR )) { + misc |=REG_DMA_MISC_INT_AUTO_CLEAR ; +iowrite32 (misc, ring->nhi->iobase +REG_DMA_MISC ); + } } ivr_base = ring->nhi->iobase +REG_INT_VEC_ALLOC_BASE ;
@@ -1190,6 +1198,8 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (!nhi->tx_rings || !nhi->rx_rings)return -ENOMEM ; +nhi_check_quirks (nhi); + res =nhi_init_msi (nhi);if (res) {dev_err (&pdev->dev,"cannot enable MSI, aborting\n" );
include/linux/thunderbolt.h +1 -0
@@ -480,6 +480,7 @@ struct tb_nhi {bool going_away;struct work_struct interrupt_work;u32 hop_count; +u32 quirks; };/**
Signature · 1 line
2.7.4
PATCH v3 2/4 thunderbolt: Handle ring interrupt by reading intr status
In reply to Sanjay R MehtaFrom: Sanjay R Mehta <[email protected]>
As per USB4 specification by default "Disable ISR Auto-Clear" bit is set to zero and the Tx/Rx ring interrupt status needs to be cleared.
Hence handle it by reading the "Interrupt status" register in the ISR.
--- drivers/thunderbolt/nhi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/thunderbolt/nhi.c +14 -0
@@ -385,11 +385,25 @@ 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) +{ +if (!(ring->nhi->quirks ®_DMA_MISC_INT_AUTO_CLEAR )) { +if (ring->is_tx) +ioread32 (ring->nhi->iobase + +REG_RING_NOTIFY_BASE ); +else +ioread32 (ring->nhi->iobase + +REG_RING_NOTIFY_BASE + +4 * (ring->nhi->hop_count /32 )); + } +} +static irqreturn_t ring_msix (int irq,void *data) {struct tb_ring *ring = data;spin_lock (&ring->nhi->lock); +check_and_clear_intr_status (ring);spin_lock (&ring->lock);__ring_interrupt (ring);spin_unlock (&ring->lock);
Signature · 1 line
2.7.4
PATCH v3 3/4 thunderbolt: Skip port init for control adapter(0)
In reply to Sanjay R MehtaFrom: Sanjay R Mehta <[email protected]>
Adapter (0) is control adapter and as per USB4 spec in "Section 1.8", "Control Adapters do not have an Adapter Configuration Space".
Hence skip port initialization for adapter (0).
--- drivers/thunderbolt/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/switch.c +1 -1
@@ -2740,7 +2740,7 @@ int tb_switch_add(struct tb_switch *sw)return ret; } -for (i =0 ; i <= sw->config.max_port_number; i++) { +for (i =1 ; i <= sw->config.max_port_number; i++) {if (sw->ports[i].disabled) {tb_port_dbg (&sw->ports[i],"disabled by eeprom\n" );continue ;
Signature · 1 line
2.7.4
PATCH v3 4/4 thunderbolt: Fix port linking by checking all adapters
In reply to Sanjay R MehtaFrom: 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.
--- drivers/thunderbolt/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/switch.c +1 -1
@@ -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
Hi,
Quoted 11 lines · Sanjay R Mehta
From: Sanjay R Mehta <[email protected]>
This series adds some general USB4 bug fixes as per USB4 Spec.
v2:
- Added quirk to handle any vendor specific quirks.
v1:
- removed PCI-IDs as AMD USB4 controller exposes USB4 class ID.
- removed clearing of interrupt using interrupt status clear register.
- skip port Adapter(0) initialisation for both host router & device router.
Quoted 5 lines
Sanjay R Mehta (4):
thunderbolt: Add quirk to support vendor specific implementation
thunderbolt: Handle ring interrupt by reading intr status
thunderbolt: Skip port init for control adapter(0)
thunderbolt: Fix port linking by checking all adapters
I did some minor tweaks and removed the "Fixes" lines since these are actually not fixes per se more like improvements :) Then applied all to thunderbolt.git/next. Please check that they still work on AMD hardware and make sense in general.
Thanks!
Quoted 22 lines · Mika Westerberg
[CAUTION: External Email]
Hi,
Quoted 11 lines · Sanjay R Mehta
From: Sanjay R Mehta <[email protected]>
This series adds some general USB4 bug fixes as per USB4 Spec.
v2:
- Added quirk to handle any vendor specific quirks.
v1:
- removed PCI-IDs as AMD USB4 controller exposes USB4 class ID.
- removed clearing of interrupt using interrupt status clear register.
- skip port Adapter(0) initialisation for both host router & device router.Quoted 5 lines
Sanjay R Mehta (4):
thunderbolt: Add quirk to support vendor specific implementation
thunderbolt: Handle ring interrupt by reading intr status
thunderbolt: Skip port init for control adapter(0)
thunderbolt: Fix port linking by checking all adapters
Quoted 5 lines
I did some minor tweaks and removed the "Fixes" lines since these are actually not fixes per se more like improvements :) Then applied all to thunderbolt.git/next. Please check that they still work on AMD hardware and make sense in general.
Thanks a lot Mika :). This should work for AMD.
Quoted 2 lines
Thanks!