public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: Clear hops before overwriting
@ 2014-08-26 15:42 Andreas Noever
  2014-08-26 15:54 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Noever @ 2014-08-26 15:42 UTC (permalink / raw)
  To: linux-kernel, Greg KH; +Cc: Andreas Noever

Zero hops in tb_path_activate before writing a new path.

This fixes the following scenario:
 - Boot with a coldplugged device
 - Unplug device
 - Plug device back in
 - PCI hotplug fails

The hotplug operation fails because our new path matches the (now
defunct) path which was setup by the firmware for the coldplugged
device. By writing zeros before writing our path configuration we can
force thunderbolt to retrain the path.

Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
---
 drivers/thunderbolt/path.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c
index 8fcf8a7..9562cd0 100644
--- a/drivers/thunderbolt/path.c
+++ b/drivers/thunderbolt/path.c
@@ -150,7 +150,26 @@ int tb_path_activate(struct tb_path *path)
 
 	/* Activate hops. */
 	for (i = path->path_length - 1; i >= 0; i--) {
-		struct tb_regs_hop hop;
+		struct tb_regs_hop hop = { 0 };
+
+		/*
+		 * We do (currently) not tear down paths setup by the firmeware.
+		 * If a firmware device is unplugged and plugged in again then
+		 * it can happen that we reuse some of the hops from the (now
+		 * defunct) firmeware path. This causes the hotplug operation to
+		 * fail (the pci device does not show up). Clearing the hop
+		 * before overwriting it fixes the problem.
+		 *
+		 * Should be removed once we discover and tear down firmeware
+		 * paths.
+		 */
+		res = tb_port_write(path->hops[i].in_port, &hop, TB_CFG_HOPS,
+				    2 * path->hops[i].in_hop_index, 2);
+		if (res) {
+			__tb_path_deactivate_hops(path, i);
+			__tb_path_deallocate_nfc(path, 0);
+			goto err;
+		}
 
 		/* dword 0 */
 		hop.next_hop = path->hops[i].next_hop_index;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] thunderbolt: Clear hops before overwriting
  2014-08-26 15:42 [PATCH] thunderbolt: Clear hops before overwriting Andreas Noever
@ 2014-08-26 15:54 ` Greg KH
  2014-08-26 16:02   ` Andreas Noever
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2014-08-26 15:54 UTC (permalink / raw)
  To: Andreas Noever; +Cc: linux-kernel

On Tue, Aug 26, 2014 at 05:42:21PM +0200, Andreas Noever wrote:
> Zero hops in tb_path_activate before writing a new path.
> 
> This fixes the following scenario:
>  - Boot with a coldplugged device
>  - Unplug device
>  - Plug device back in
>  - PCI hotplug fails
> 
> The hotplug operation fails because our new path matches the (now
> defunct) path which was setup by the firmware for the coldplugged
> device. By writing zeros before writing our path configuration we can
> force thunderbolt to retrain the path.
> 
> Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
> ---
>  drivers/thunderbolt/path.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)

Should this get in for 3.17-final or can it wait for 3.18?  I'm thinking
3.17, but want to make sure.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] thunderbolt: Clear hops before overwriting
  2014-08-26 15:54 ` Greg KH
@ 2014-08-26 16:02   ` Andreas Noever
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Noever @ 2014-08-26 16:02 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel@vger.kernel.org

On Tue, Aug 26, 2014 at 5:54 PM, Greg KH <greg@kroah.com> wrote:
> On Tue, Aug 26, 2014 at 05:42:21PM +0200, Andreas Noever wrote:
>> Zero hops in tb_path_activate before writing a new path.
>>
>> This fixes the following scenario:
>>  - Boot with a coldplugged device
>>  - Unplug device
>>  - Plug device back in
>>  - PCI hotplug fails
>>
>> The hotplug operation fails because our new path matches the (now
>> defunct) path which was setup by the firmware for the coldplugged
>> device. By writing zeros before writing our path configuration we can
>> force thunderbolt to retrain the path.
>>
>> Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
>> ---
>>  drivers/thunderbolt/path.c | 21 ++++++++++++++++++++-
>>  1 file changed, 20 insertions(+), 1 deletion(-)
>
> Should this get in for 3.17-final or can it wait for 3.18?  I'm thinking
> 3.17, but want to make sure.

I would prefer 3.17.

> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-26 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-26 15:42 [PATCH] thunderbolt: Clear hops before overwriting Andreas Noever
2014-08-26 15:54 ` Greg KH
2014-08-26 16:02   ` Andreas Noever

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox