Skip to content

Commit bdccf29

Browse files
westerigregkh
authored andcommitted
thunderbolt: Do not touch the hardware if the NHI is gone on resume
On PCs the NHI host controller is only present when there is a device connected. When the last device is disconnected the host controller will dissappear shortly (within 10s). Now if that happens when we are suspended we should not try to touch the hardware anymore, so add a flag for this and check it before we re-enable rings. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com> Reviewed-by: Michael Jamet <michael.jamet@intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Andreas Noever <andreas.noever@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3e13676 commit bdccf29

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

drivers/thunderbolt/nhi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ void ring_start(struct tb_ring *ring)
403403
{
404404
mutex_lock(&ring->nhi->lock);
405405
mutex_lock(&ring->lock);
406+
if (ring->nhi->going_away)
407+
goto err;
406408
if (ring->running) {
407409
dev_WARN(&ring->nhi->pdev->dev, "ring already started\n");
408410
goto err;
@@ -449,6 +451,8 @@ void ring_stop(struct tb_ring *ring)
449451
mutex_lock(&ring->lock);
450452
dev_info(&ring->nhi->pdev->dev, "stopping %s %d\n",
451453
RING_TYPE(ring), ring->hop);
454+
if (ring->nhi->going_away)
455+
goto err;
452456
if (!ring->running) {
453457
dev_WARN(&ring->nhi->pdev->dev, "%s %d already stopped\n",
454458
RING_TYPE(ring), ring->hop);
@@ -653,6 +657,14 @@ static int nhi_resume_noirq(struct device *dev)
653657
struct pci_dev *pdev = to_pci_dev(dev);
654658
struct tb *tb = pci_get_drvdata(pdev);
655659

660+
/*
661+
* Check that the device is still there. It may be that the user
662+
* unplugged last device which causes the host controller to go
663+
* away on PCs.
664+
*/
665+
if (!pci_device_is_present(pdev))
666+
tb->nhi->going_away = true;
667+
656668
return tb_domain_resume_noirq(tb);
657669
}
658670

drivers/thunderbolt/nhi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @tx_rings: All Tx rings available on this host controller
2121
* @rx_rings: All Rx rings available on this host controller
2222
* @msix_ida: Used to allocate MSI-X vectors for rings
23+
* @going_away: The host controller device is about to disappear so when
24+
* this flag is set, avoid touching the hardware anymore.
2325
* @interrupt_work: Work scheduled to handle ring interrupt when no
2426
* MSI-X is used.
2527
* @hop_count: Number of rings (end point hops) supported by NHI.
@@ -31,6 +33,7 @@ struct tb_nhi {
3133
struct tb_ring **tx_rings;
3234
struct tb_ring **rx_rings;
3335
struct ida msix_ida;
36+
bool going_away;
3437
struct work_struct interrupt_work;
3538
u32 hop_count;
3639
};

0 commit comments

Comments
 (0)