thunderbolt: Add support for USB4
Subsystems (3)
cover thunderbolt: Add support for USB4
Hi all,
I'm sending this as RFC because the series is still missing important features such as power management so not ready for merging. However, I think it is good to get any early feedback from the community. We are working to add support for the missing features.
USB4 is the public specification of Thunderbolt 3 protocol and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_1.zip
USB4 is about tunneling different protocols over a single cable (in the same way as Thunderbolt). The current USB4 spec supports PCIe, Display Port and USB 3.x, and also software based protocols such as networking between domains (hosts).
So far PCs have been using firmware based Connection Manager and Apple systems have been using software based one. A Connection Manager is the entity that handles creation of different tunnel types through the USB4 (and Thunderbolt) fabric. With USB4 the plan is to have software based Connection Manager everywhere but some early systems will also support firmware to allow OS downgrade for example.
Current Linux Thunderbolt driver supports both "modes" and can detect which one to use dynamically.
This series first adds support for Thunderbolt 3 devices to the software connection manager and then extends that to support USB4 compliant hosts and devices (this applies to both firmware and software based connection managers). With this series the following features are supported also for USB4 compliant devices:
- PCIe tunneling
- Display Port tunneling
- USB 3.x tunneling
- P2P networking (implemented in drivers/net/thunderbolt.c)
- Host and device NVM firmware upgrade
We also add two new sysfs attributes under each device that expose link speed and width to userspace. The rest of the userspace ABI stays the same.
I'm including Linux USB folks as well because USB4 is officially coming from USB-IF which puts us on same boat now.
While I changed the user visible Kconfig string to mention "USB4" (the Kconfig option is still CONFIG_THUNDERBOLT), I'm wondering whether we should move the whole Thunderbolt driver under drivers/usb/thunderbolt as well?
Mika Westerberg (19):
thunderbolt: Introduce tb_switch_is_icm()
thunderbolt: Log switch route string on config read/write timeout
thunderbolt: Log warning if adding switch fails
thunderbolt: Make tb_sw_write() take const parameter
thunderbolt: Add helper macros to iterate over switch ports
thunderbolt: Add support for lane bonding
thunderbolt: Add default linking between ports if not provided by DROM
thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
thunderbolt: Convert basic adapter register names to follow the USB4 spec
thunderbolt: Convert PCIe adapter register names to use USB4 names
thunderbolt: Convert DP adapter register names to follow the USB4 spec
thunderbolt: Add Display Port CM handshake for Titan Ridge devices
thunderbolt: Add Display Port adapter pairing and resource management
thunderbolt: Add bandwidth management for Display Port tunnels
thunderbolt: Make tb_find_port() available to other files
thunderbolt: Call tb_eeprom_get_drom_offset() from tb_eeprom_read_n()
thunderbolt: Add initial support for USB4
thunderbolt: Update documentation with the USB4 information
thunderbolt: Do not start firmware unless asked by the user
Rajmohan Mani (3):
thunderbolt: Make tb_switch_find_cap() available to other files
thunderbolt: Add support for Time Management Unit
thunderbolt: Add support for USB tunnels
.../ABI/testing/sysfs-bus-thunderbolt | 17 + Documentation/admin-guide/thunderbolt.rst | 27 +- drivers/thunderbolt/Kconfig | 9 +- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/cap.c | 11 +- drivers/thunderbolt/ctl.c | 8 +- drivers/thunderbolt/eeprom.c | 146 +-- drivers/thunderbolt/icm.c | 36 +- drivers/thunderbolt/lc.c | 193 +++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/path.c | 52 +- drivers/thunderbolt/switch.c | 870 +++++++++++++++--- drivers/thunderbolt/tb.c | 529 +++++++++-- drivers/thunderbolt/tb.h | 198 +++- drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 160 +++- drivers/thunderbolt/tmu.c | 380 ++++++++ drivers/thunderbolt/tunnel.c | 517 ++++++++++- drivers/thunderbolt/tunnel.h | 19 +- drivers/thunderbolt/usb4.c | 761 +++++++++++++++ drivers/thunderbolt/xdomain.c | 8 +- 22 files changed, 3578 insertions(+), 372 deletions(-) create mode 100644 drivers/thunderbolt/tmu.c create mode 100644 drivers/thunderbolt/usb4.c
Signature · 1 line
2.23.0
RFC PATCH 1/22 thunderbolt: Introduce tb_switch_is_icm()
We currently differentiate between SW CM and ICM by looking directly at the sw->config.enabled field which may be rather hard to understand for the casual reader. For this reason introduce a wrapper function with documentation that should make the intention more clear.
--- drivers/thunderbolt/lc.c | 4 ++-- drivers/thunderbolt/switch.c | 4 ++-- drivers/thunderbolt/tb.h | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
drivers/thunderbolt/lc.c +2 -2
@@ -94,7 +94,7 @@ int tb_lc_configure_link(struct tb_switch *sw)struct tb_port *up, *down;int ret; -if (!sw->config.enabled || !tb_route (sw)) +if (!tb_route (sw) ||tb_switch_is_icm (sw))return 0 ; up =tb_upstream_port (sw);
@@ -124,7 +124,7 @@ void tb_lc_unconfigure_link(struct tb_switch *sw) {struct tb_port *up, *down; -if (sw->is_unplugged || !sw->config.enabled || !tb_route (sw)) +if (sw->is_unplugged || !tb_route (sw) ||tb_switch_is_icm (sw))return ; up =tb_upstream_port (sw);
drivers/thunderbolt/switch.c +2 -2
@@ -986,7 +986,7 @@ static int tb_plug_events_active(struct tb_switch *sw, bool active)u32 data;int res; -if (!sw->config.enabled) +if (tb_switch_is_icm (sw))return 0 ; sw->config.plug_events_delay =0xff ;
@@ -1710,7 +1710,7 @@ static int tb_switch_add_dma_port(struct tb_switch *sw) }/* Root switch DMA port requires running firmware */ -if (!tb_route (sw) && sw->config.enabled) +if (!tb_route (sw) && !tb_switch_is_icm (sw))return 0 ; sw->dma_port =dma_port_alloc (sw);
drivers/thunderbolt/tb.h +14 -0
@@ -591,6 +591,20 @@ static inline bool tb_switch_is_fr(const struct tb_switch *sw) } } +/** +* tb_switch_is_icm() - Is the switch handled by ICM firmware +* @sw: Switch to check +* +* In case there is a need to differentiate whether ICM firmware or SW CM +* is handling @sw this function can be called. It is valid to call this +* after tb_switch_alloc() and tb_switch_configure() has been called +* (latter only for SW CM case). +*/ +static inline bool tb_switch_is_icm (const struct tb_switch *sw) +{ +return !sw->config.enabled; +} +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 1 line · Mika Westerberg
We currently differentiate between SW CM and ICM by looking directly at
You should spell out what "SW CM" and "ICM" means please :)
thanks,
greg k-h
Re: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Mika Westerberg
We currently differentiate between SW CM and ICM by looking directly at
You should spell out what "SW CM" and "ICM" means please :)
Indeed, sorry about that. I will spell them out in next version.
SW CM is Software Connection manager, essentiallydrivers/thunderbolt/tb.c.
ICM is the Firmware Connection manager, essentially what is done in drivers/thunderbolt/icm.c. I think the I in ICM comes from Internal.
RE: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 14 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 7:47 AM
To: Greg Kroah-Hartman
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 01/22] thunderbolt: Introducetb_switch_is_icm()[EXTERNAL EMAIL]
Quoted 1 line · Greg Kroah-Hartman
On Tue, Oct 01, 2019 at 02:38:09PM +0300, Mika Westerberg wrote:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
We currently differentiate between SW CM and ICM by looking directly at
You should spell out what "SW CM" and "ICM" means please :)
Indeed, sorry about that. I will spell them out in next version.
SW CM is Software Connection manager, essentially
drivers/thunderbolt/tb.c.
In some of the documentation I've seen non-internal connection manager referred to as ECM, which I guess is an external connection manager? To be consistent with various documentations maybe that would be better than "SW CM".
Quoted 3 lines
ICM is the Firmware Connection manager, essentially what is done in
drivers/thunderbolt/icm.c. I think the I in ICM comes from Internal.
Re: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 18 lines · On Tue, Oct 01, 2019 at 01:36:49PM +0000, [email protected] wrote:
Quoted 18 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 7:47 AM
To: Greg Kroah-Hartman
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 01/22] thunderbolt: Introducetb_switch_is_icm()[EXTERNAL EMAIL]
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Mika Westerberg
We currently differentiate between SW CM and ICM by looking directly at
You should spell out what "SW CM" and "ICM" means please :)
Quoted 8 lines
Quoted 4 lines
Indeed, sorry about that. I will spell them out in next version.
SW CM is Software Connection manager, essentially
drivers/thunderbolt/tb.c.In some of the documentation I've seen non-internal connection manager referred to as ECM, which I guess is an external connection manager? To be consistent with various documentations maybe that would be better than "SW CM".
That's the first time I hear about ECM ;-)
Here at Intel we use term "SW CM" and "FW CM" and IMHO they are better than ECM/ICM. But if people insist I can change them.
RE: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 42 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 8:48 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 01/22] thunderbolt: Introducetb_switch_is_icm()[EXTERNAL EMAIL]
Quoted 5 lines · On Tue, Oct 01, 2019 at 01:36:49PM +0000, [email protected] wrote:
Quoted 5 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 7:47 AM
To: Greg Kroah-Hartman
Cc: [email protected]; Andreas Noever; Michael Jamet; YehezkelBernat;
Quoted 1 line
Quoted 1 line
Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello,
Mario;
Quoted 10 lines
Quoted 10 lines
Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 01/22] thunderbolt: Introducetb_switch_is_icm()[EXTERNAL EMAIL]
Quoted 3 lines · Greg Kroah-Hartman
Quoted 1 line · Mika Westerberg
We currently differentiate between SW CM and ICM by looking directly at
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
You should spell out what "SW CM" and "ICM" means please :)
Indeed, sorry about that. I will spell them out in next version.
SW CM is Software Connection manager, essentially
drivers/thunderbolt/tb.c.In some of the documentation I've seen non-internal connection manager
referred to
Quoted 8 lines
Quoted 1 line
as ECM, which I guess is an external connection manager? To be consistent with
various
Quoted 1 line
documentations maybe that would be better than "SW CM".
That's the first time I hear about ECM ;-)
Here at Intel we use term "SW CM" and "FW CM" and IMHO they are better than ECM/ICM. But if people insist I can change them.
I do agree with you, SW CM and FW CM are clearer than ECM/ICM, maybe just reference both in the comments so if someone is aware of ECM/ICM from some documents they can relate the two concepts.
Re: [RFC PATCH 01/22] thunderbolt: Introduce tb_switch_is_icm()
Quoted 6 lines · On Tue, Oct 01, 2019 at 01:50:13PM +0000, [email protected] wrote:
Quoted 2 lines
Here at Intel we use term "SW CM" and "FW CM" and IMHO they are better than ECM/ICM. But if people insist I can change them.
I do agree with you, SW CM and FW CM are clearer than ECM/ICM, maybe just reference both in the comments so if someone is aware of ECM/ICM from some documents they can relate the two concepts.
Sure, I'll do that in the next version.
RFC PATCH 2/22 thunderbolt: Log switch route string on config read/write timeout
In reply to Mika WesterbergThis helps to point out which switch config read/write triggered the timeout.
--- drivers/thunderbolt/ctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thunderbolt/ctl.c +4 -4
@@ -962,8 +962,8 @@ int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,return tb_cfg_get_error (ctl, space, &res);case -ETIMEDOUT : -tb_ctl_warn (ctl,"timeout reading config space %u from %#x\n" , - space, offset); +tb_ctl_warn (ctl,"%llx: timeout reading config space %u from %#x\n" , + route, space, offset);break ;default :
@@ -988,8 +988,8 @@ int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,return tb_cfg_get_error (ctl, space, &res);case -ETIMEDOUT : -tb_ctl_warn (ctl,"timeout writing config space %u to %#x\n" , - space, offset); +tb_ctl_warn (ctl,"%llx: timeout writing config space %u to %#x\n" , + route, space, offset);break ;default :
Signature · 1 line
2.23.0
RFC PATCH 3/22 thunderbolt: Log warning if adding switch fails
In reply to Mika WesterbergIf we fail to add a switch for some reason log a warning with the error code. This is useful for debugging.
--- drivers/thunderbolt/tb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/thunderbolt/tb.c +4 -1
@@ -143,6 +143,7 @@ static void tb_scan_port(struct tb_port *port)struct tb_cm *tcm =tb_priv (port->sw->tb);struct tb_port *upstream_port;struct tb_switch *sw; +int ret;if (tb_is_upstream_port (port))return ;
@@ -203,7 +204,9 @@ static void tb_scan_port(struct tb_port *port)if (!tcm->hotplug_active)dev_set_uevent_suppress (&sw->dev, true); -if (tb_switch_add (sw)) { + ret =tb_switch_add (sw); +if (ret) { +dev_warn (&sw->dev,"failed to register switch: %d\n" , ret);tb_switch_put (sw);return ; }
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 03/22] thunderbolt: Log warning if adding switch fails
Quoted 21 lines · Mika Westerberg
If we fail to add a switch for some reason log a warning with the error code. This is useful for debugging.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/thunderbolt/tb.c +1
-0@@ -143,6 +143,7 @@ static void tb_scan_port(struct tb_port *port)struct tb_cm *tcm =tb_priv (port->sw->tb);struct tb_port *upstream_port;struct tb_switch *sw; +int ret;if (tb_is_upstream_port (port))return ;
drivers/thunderbolt/tb.c static void tb_scan_port(struct tb_port *port) · line 209
Quoted 7 lines
drivers/thunderbolt/tb.c +3
-1@@ -203,7 +204,9 @@ static void tb_scan_port(struct tb_port *port)if (!tcm->hotplug_active)dev_set_uevent_suppress (&sw->dev, true); -if (tb_switch_add (sw)) { + ret =tb_switch_add (sw); +if (ret) { +dev_warn (&sw->dev,"failed to register switch: %d\n" , ret);
Shouldn't tb_switch_add() do the error reporting instead? That way it makes it easier to call functions and not always have to print failure messages :)
thanks,
greg k-h
Re: [RFC PATCH 03/22] thunderbolt: Log warning if adding switch fails
Quoted 25 lines · Greg Kroah-Hartman
Quoted 24 lines · Mika Westerberg
If we fail to add a switch for some reason log a warning with the error code. This is useful for debugging.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/thunderbolt/tb.c +1
-0@@ -143,6 +143,7 @@ static void tb_scan_port(struct tb_port *port)struct tb_cm *tcm =tb_priv (port->sw->tb);struct tb_port *upstream_port;struct tb_switch *sw; +int ret;if (tb_is_upstream_port (port))return ;@@ -203,7 +204,9 @@ static void tb_scan_port(struct tb_port *port)if (!tcm->hotplug_active)dev_set_uevent_suppress (&sw->dev, true);
Quoted 8 lines
drivers/thunderbolt/tb.c static void tb_scan_port(struct tb_port *port) · line 209
Quoted 4 lines
drivers/thunderbolt/tb.c +3
-1-if (tb_switch_add (sw)) { + ret =tb_switch_add (sw); +if (ret) { +dev_warn (&sw->dev,"failed to register switch: %d\n" , ret);Shouldn't
tb_switch_add()do the error reporting instead? That way it makes it easier to call functions and not always have to print failure messages :)
Yes, that's better - I'll move it there.
RFC PATCH 4/22 thunderbolt: Make tb_sw_write() take const parameter
In reply to Mika WesterbergThe function does not modify the argument in any way so make it const.
--- drivers/thunderbolt/tb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.h +1 -1
@@ -399,7 +399,7 @@ static inline int tb_sw_read(struct tb_switch *sw, void *buffer, length); } -static inline int tb_sw_write (struct tb_switch *sw,void *buffer, +static inline int tb_sw_write (struct tb_switch *sw,const void *buffer,enum tb_cfg_space space,u32 offset,u32 length) {if (sw->is_unplugged)
Signature · 1 line
2.23.0
RFC PATCH 5/22 thunderbolt: Add helper macros to iterate over switch ports
In reply to Mika WesterbergThere are quite many places in the driver where we iterate over each port in the switch skipping. To make it bit more consistent provide set of helper macros that can be used to do this and convert the existing call sites to these.
No functional changes.
--- drivers/thunderbolt/icm.c | 4 ++-- drivers/thunderbolt/switch.c | 17 ++++++----------- drivers/thunderbolt/tb.c | 26 +++++++++++++------------- drivers/thunderbolt/tb.h | 35 +++++++++++++++++++++++++++++++++++ drivers/thunderbolt/xdomain.c | 2 +- 5 files changed, 57 insertions(+), 27 deletions(-)
drivers/thunderbolt/icm.c +2 -2
@@ -1898,7 +1898,7 @@ static void icm_unplug_children(struct tb_switch *sw)if (tb_route (sw)) sw->is_unplugged = true; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {struct tb_port *port = &sw->ports[i];if (port->xdomain)
@@ -1938,7 +1938,7 @@ static void icm_free_unplugged_children(struct tb_switch *sw) {unsigned int i; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {struct tb_port *port = &sw->ports[i];if (port->xdomain && port->xdomain->is_unplugged) {
drivers/thunderbolt/switch.c +6 -11
@@ -1386,7 +1386,7 @@ static void tb_switch_release(struct device *dev)dma_port_free (sw->dma_port); -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {if (!sw->ports[i].disabled) {ida_destroy (&sw->ports[i].in_hopids);ida_destroy (&sw->ports[i].out_hopids);
@@ -1850,7 +1850,7 @@ void tb_switch_remove(struct tb_switch *sw) }/* port 0 is the switch itself and never has a remote */ -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {if (tb_port_has_remote (&sw->ports[i])) {tb_switch_remove (sw->ports[i].remote->sw); sw->ports[i].remote =NULL ;
@@ -1886,7 +1886,7 @@ void tb_sw_set_unplugged(struct tb_switch *sw)return ; } sw->is_unplugged = true; -for (i =0 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {if (tb_port_has_remote (&sw->ports[i]))tb_sw_set_unplugged (sw->ports[i].remote->sw);else if (sw->ports[i].xdomain)
@@ -1944,12 +1944,9 @@ int tb_switch_resume(struct tb_switch *sw)return err;/* check for surviving downstream switches */ -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_connected_port (sw, i) {struct tb_port *port = &sw->ports[i]; -if (!tb_port_has_remote (port) && !port->xdomain) -continue ; -if (tb_wait_for_port (port, true) <=0 ) {tb_port_warn (port,"lost during suspend, disconnecting\n" );
@@ -1975,10 +1972,8 @@ void tb_switch_suspend(struct tb_switch *sw)if (err)return ; -for (i =1 ; i <= sw->config.max_port_number; i++) { -if (tb_port_has_remote (&sw->ports[i])) -tb_switch_suspend (sw->ports[i].remote->sw); - } +tb_switch_for_each_remote_port (sw, i) +tb_switch_suspend (sw->ports[i].remote->sw);tb_lc_set_sleep (sw); }
drivers/thunderbolt/tb.c +13 -13
@@ -63,7 +63,7 @@ static void tb_discover_tunnels(struct tb_switch *sw)struct tb_port *port;int i; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {struct tb_tunnel *tunnel =NULL ; port = &sw->ports[i];
@@ -95,10 +95,8 @@ static void tb_discover_tunnels(struct tb_switch *sw)list_add_tail (&tunnel->list, &tcm->tunnel_list); } -for (i =1 ; i <= sw->config.max_port_number; i++) { -if (tb_port_has_remote (&sw->ports[i])) -tb_discover_tunnels (sw->ports[i].remote->sw); - } +tb_switch_for_each_remote_port (sw, i) +tb_discover_tunnels (sw->ports[i].remote->sw); }static void tb_scan_xdomain (struct tb_port *port)
@@ -131,7 +129,8 @@ static void tb_scan_port(struct tb_port *port);static void tb_scan_switch (struct tb_switch *sw) {int i; -for (i =1 ; i <= sw->config.max_port_number; i++) + +tb_switch_for_each_port (sw, i)tb_scan_port (&sw->ports[i]); }
@@ -267,11 +266,9 @@ static void tb_free_invalid_tunnels(struct tb *tb)static void tb_free_unplugged_children (struct tb_switch *sw) {int i; -for (i =1 ; i <= sw->config.max_port_number; i++) { -struct tb_port *port = &sw->ports[i]; -if (!tb_port_has_remote (port)) -continue ; +tb_switch_for_each_remote_port (sw, i) { +struct tb_port *port = &sw->ports[i];if (port->remote->sw->is_unplugged) {tb_switch_remove (port->remote->sw);
@@ -293,9 +290,12 @@ static struct tb_port *tb_find_port(struct tb_switch *sw, enum tb_port_type type) {int i; -for (i =1 ; i <= sw->config.max_port_number; i++) + +tb_switch_for_each_port (sw, i) {if (sw->ports[i].config.type == type)return &sw->ports[i]; + } +return NULL ; }
@@ -309,7 +309,7 @@ static struct tb_port *tb_find_unused_port(struct tb_switch *sw, {int i; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {if (tb_is_upstream_port (&sw->ports[i]))continue ;if (sw->ports[i].config.type != type)
@@ -739,7 +739,7 @@ static int tb_free_unplugged_xdomains(struct tb_switch *sw) {int i, ret =0 ; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {struct tb_port *port = &sw->ports[i];if (tb_is_upstream_port (port))
drivers/thunderbolt/tb.h +35 -0
@@ -530,6 +530,41 @@ struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,struct tb_switch *tb_switch_find_by_uuid (struct tb *tb,const uuid_t *uuid);struct tb_switch *tb_switch_find_by_route (struct tb *tb,u64 route); +/** +* tb_switch_for_each_port() - Iterate over each switch port +* @sw: Switch whose ports to iterate +* @i: Port index inside @sw->ports[] array +* +* Iterates over each switch port except control port. +*/ +#define tb_switch_for_each_port (sw, i) \ + for (i = 1; i <= sw->config.max_port_number; i++) + +/** +* tb_switch_for_each_remote_port() - Iterate over each port that has remote +* @sw: Switch whose ports to iterate +* @i: Port index inside @sw->ports[] array +* +* Iterates over all ports that have another switch connected +* downstream. +*/ +#define tb_switch_for_each_remote_port (sw, i) \ + tb_switch_for_each_port(sw, i) \ + if (!tb_port_has_remote(&sw->ports[i])) {} else + +/** +* tb_switch_for_each_connected_port() - Iterate over each connected port +* @sw: Switch whose ports to iterate +* @i: Port index inside @sw->ports[] array +* +* Iterates over each connected port. This means each port that has +* either a switch or remote host (XDomain) connected. +*/ +#define tb_switch_for_each_connected_port (sw, i) \ + tb_switch_for_each_port(sw, i) \ + if (!tb_port_has_remote(&sw->ports[i]) && \ + !sw->ports[i].xdomain) {} else +static inline struct tb_switch *tb_switch_get (struct tb_switch *sw) {if (sw)
drivers/thunderbolt/xdomain.c +1 -1
@@ -1406,7 +1406,7 @@ static struct tb_xdomain *switch_find_xdomain(struct tb_switch *sw, {int i; -for (i =1 ; i <= sw->config.max_port_number; i++) { +tb_switch_for_each_port (sw, i) {struct tb_port *port = &sw->ports[i];struct tb_xdomain *xd;
Signature · 1 line
2.23.0
Re: [RFC PATCH 05/22] thunderbolt: Add helper macros to iterate over switch ports
Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg:
drivers/thunderbolt/switch.c void tb_switch_suspend(struct tb_switch *sw) · line 1976
Quoted 10 lines
drivers/thunderbolt/switch.c +2
-4@@ -1975,10 +1972,8 @@ void tb_switch_suspend(struct tb_switch *sw)if (err)return ; -for (i =1 ; i <= sw->config.max_port_number; i++) { -if (tb_port_has_remote (&sw->ports[i])) -tb_switch_suspend (sw->ports[i].remote->sw); - } +tb_switch_for_each_remote_port (sw, i) +tb_switch_suspend (sw->ports[i].remote->sw);
This macro looks a bit prone to misunderstanding.
I guess the function would be better if the test could be seen.
Regards
Oliver
Re: [RFC PATCH 05/22] thunderbolt: Add helper macros to iterate over switch ports
Quoted 5 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg:
Quoted 4 lines
drivers/thunderbolt/switch.c +0
-0@@ -1975,10 +1972,8 @@ void tb_switch_suspend(struct tb_switch *sw)if (err)return ;
Quoted 9 lines
drivers/thunderbolt/switch.c void tb_switch_suspend(struct tb_switch *sw) · line 1976
Quoted 6 lines
drivers/thunderbolt/switch.c +2
-4-for (i =1 ; i <= sw->config.max_port_number; i++) { -if (tb_port_has_remote (&sw->ports[i])) -tb_switch_suspend (sw->ports[i].remote->sw); - } +tb_switch_for_each_remote_port (sw, i) +tb_switch_suspend (sw->ports[i].remote->sw);This macro looks a bit prone to misunderstanding.
I guess the function would be better if the test could be seen.
The macro does not really save too many lines so I think I can just drop this patch for now and keep these open-coded.
Re: [RFC PATCH 05/22] thunderbolt: Add helper macros to iterate over switch ports
Quoted 16 lines · Mika Westerberg
Quoted 5 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg:
Quoted 4 lines
drivers/thunderbolt/switch.c +0
-0@@ -1975,10 +1972,8 @@ void tb_switch_suspend(struct tb_switch *sw)if (err)return ;Quoted 9 lines
drivers/thunderbolt/switch.c void tb_switch_suspend(struct tb_switch *sw) · line 1976
Quoted 6 lines
drivers/thunderbolt/switch.c +2
-4-for (i =1 ; i <= sw->config.max_port_number; i++) { -if (tb_port_has_remote (&sw->ports[i])) -tb_switch_suspend (sw->ports[i].remote->sw); - } +tb_switch_for_each_remote_port (sw, i) +tb_switch_suspend (sw->ports[i].remote->sw);This macro looks a bit prone to misunderstanding.
I guess the function would be better if the test could be seen.
Quoted 2 lines
The macro does not really save too many lines so I think I can just drop this patch for now and keep these open-coded.
Introducing a macro is fine.
However instead of using an index "i" as iterator, I'd suggest using a pointer to struct tb_port. This reduces the horizontal width of the code because you can replace the "sw->ports[i]" with just "port".
In most of the loops this also saves 1 line for an assignment:
"struct tb_port *port = &sw->ports[i];"
In fact, I've already proposed such a macro more than a year ago but it never got merged:
https://lore.kernel.org/patchwork/patch/983863/
/**
* tb_sw_for_each_port() - iterate over ports on a switch
* @switch: pointer to struct tb_switch over whose ports shall be iterated
* @port: pointer to struct tb_port which shall be used as the iterator *
* Excludes port 0, which is the switch itself and therefore irrelevant for
* most iterations.
*/
#define tb_sw_for_each_port(switch, port) \ for (port = &(switch)->ports[1]; \ port <= &(switch)->ports[(switch)->config.max_port_number]; \ port++)
Thanks,
Lukas
RFC PATCH 6/22 thunderbolt: Add support for lane bonding
In reply to Mika WesterbergLane bonding allows aggregating the two 10/20 Gb/s (depending on the generation) lanes into a single 20/40 Gb/s bonded link. This allows sharing the full bandwidth more efficiently. In order to establish lane bonding we need to check that the lane bonding is possible through LC and that both end of the link actually supports 2x widths. This also means that all the paths should be established through the primary port so update tb_path_alloc() to handle this as well.
Lane bonding is supported starting from Falcon Ridge (2nd generation) controllers.
--- .../ABI/testing/sysfs-bus-thunderbolt | 17 ++ drivers/thunderbolt/icm.c | 18 +- drivers/thunderbolt/lc.c | 28 ++ drivers/thunderbolt/path.c | 30 +- drivers/thunderbolt/switch.c | 274 ++++++++++++++++++ drivers/thunderbolt/tb.c | 21 ++ drivers/thunderbolt/tb.h | 10 + drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tunnel.c | 19 +- 10 files changed, 429 insertions(+), 10 deletions(-)
Documentation/ABI/testing/sysfs-bus-thunderbolt +17 -0
@@ -104,6 +104,23 @@ Contact: [email protected] Description: This attribute contains name of this device extracted from the device DROM. +What: /sys/bus/thunderbolt/devices/.../link_speed +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link speed + in Gb/s per lane. If there are two lanes they both are + running at the same speed. Use link_width to determine + whether the two lanes are bonded or not. + +What: /sys/bus/thunderbolt/devices/.../link_width +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link width. + It is 1 for single lane link (or two single lane links) + and 2 for bonded dual lane link. + What: /sys/bus/thunderbolt/devices/.../vendor Date: Sep 2017 KernelVersion: 4.13
drivers/thunderbolt/icm.c +13 -5
@@ -567,7 +567,8 @@ static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, size_t ep_name_size, u8 connection_id, u8 connection_key, u8 link, u8 depth, enum tb_security_level security_level, - bool authorized, bool boot) + bool authorized, bool boot, bool dual_lane, + bool speed_gen3) { const struct intel_vss *vss;struct tb_switch *sw;
@@ -592,6 +593,8 @@ static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, sw->authorized = authorized; sw->security_level = security_level; sw->boot = boot; + sw->link_speed = speed_gen3 ?20 :10 ; + sw->link_width = dual_lane ?2 :1 ;init_completion (&sw->rpm_complete); vss =parse_intel_vss (ep_name, ep_name_size);
@@ -697,11 +700,11 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) (const struct icm_fr_event_device_connected *)hdr;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw; +bool boot, dual_lane, speed_gen3;struct icm *icm =tb_priv (tb);bool authorized = false;struct tb_xdomain *xd;u8 link, depth; -bool boot;u64 route;int ret;
@@ -714,6 +717,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n",
@@ -814,7 +819,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name,sizeof (pkg->ep_name), pkg->connection_id, pkg->connection_key, link, depth, security_level, - authorized, boot); + authorized, boot, dual_lane, speed_gen3);tb_switch_put (parent_sw); }
@@ -1142,10 +1147,10 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, {const struct icm_tr_event_device_connected *pkg = (const struct icm_tr_event_device_connected *)hdr; +bool authorized, boot, dual_lane, speed_gen3;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw;struct tb_xdomain *xd; -bool authorized, boot;u64 route;icm_postpone_rescan (tb);
@@ -1163,6 +1168,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n",
@@ -1207,7 +1214,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, sw =add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name,sizeof (pkg->ep_name), pkg->connection_id,0 ,0 ,0 , - security_level, authorized, boot); + security_level, authorized, boot, dual_lane, + speed_gen3);if (!IS_ERR (sw) && force_rtd3) sw->rpm = true;
drivers/thunderbolt/lc.c +28 -0
@@ -177,3 +177,31 @@ int tb_lc_set_sleep(struct tb_switch *sw)return 0 ; } + +/** +* tb_lc_lane_bonding_possible() - Is lane bonding possible towards switch +* @sw: Switch to check +* +* Checks whether conditions for lane bonding from parent to @sw are +* possible. +*/ +bool tb_lc_lane_bonding_possible (struct tb_switch *sw) +{ +struct tb_port *up; +int cap, ret; +u32 val; + +if (sw->generation <2 ) +return false; + + up =tb_upstream_port (sw); + cap =find_port_lc_cap (up); +if (cap <0 ) +return false; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , cap +TB_LC_PORT_ATTR ,1 ); +if (ret) +return false; + +return !!(val &TB_LC_PORT_ATTR_BE ); +}
drivers/thunderbolt/path.c +26 -4
@@ -220,7 +220,8 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,* Creates path between two ports starting with given @src_hopid. Reserves * HopIDs for each port (they can be different from @src_hopid depending on * how many HopIDs each port already have reserved). If there are dual -* links on the path, prioritizes using @link_nr. +* links on the path, prioritizes using @link_nr but takes into account +* that the lanes may be bonded. * * Return: Returns a tb_path on success or NULL on failure. */
@@ -259,7 +260,9 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!in_port) goto err; -if (in_port->dual_link_port && in_port->link_nr != link_nr) +/* When lanes are bonded primary link must be used */ +if (!in_port->bonded && in_port->dual_link_port && + in_port->link_nr != link_nr) in_port = in_port->dual_link_port; ret =tb_port_alloc_in_hopid (in_port, in_hopid, in_hopid);
@@ -271,8 +274,27 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!out_port) goto err; -if (out_port->dual_link_port && out_port->link_nr != link_nr) - out_port = out_port->dual_link_port; +/* +* Pick up right port when going from non-bonded to +* bonded or from bonded to non-bonded. +*/ +if (out_port->dual_link_port) { +if (!in_port->bonded && out_port->bonded && + out_port->link_nr) { +/* +* Use primary link when going from +* non-bonded to bonded. +*/ + out_port = out_port->dual_link_port; + }else if (!out_port->bonded && + out_port->link_nr != link_nr) { +/* +* If out port is not bonded follow +* link_nr. +*/ + out_port = out_port->dual_link_port; + } + }if (i == num_hops -1 ) ret = tb_port_alloc_out_hopid(out_port, dst_hopid,
drivers/thunderbolt/switch.c +274 -0
310 lines not on this page · raw message
drivers/thunderbolt/tb.c +21 -0
@@ -219,6 +219,10 @@ static void tb_scan_port(struct tb_port *port) upstream_port->dual_link_port->remote = port->dual_link_port; } +/* Enable lane bonding if supported */ +if (tb_switch_lane_bonding_enable (sw)) +tb_sw_warn (sw,"failed to enable lane bonding\n" ); +tb_scan_switch (sw); }
@@ -271,6 +275,7 @@ static void tb_free_unplugged_children(struct tb_switch *sw)struct tb_port *port = &sw->ports[i];if (port->remote->sw->is_unplugged) { +tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;if (port->dual_link_port)
@@ -536,6 +541,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_port_dbg (port,"switch unplugged\n" );tb_sw_set_unplugged (port->remote->sw);tb_free_invalid_tunnels (tb); +tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;if (port->dual_link_port)
@@ -705,6 +711,20 @@ static int tb_suspend_noirq(struct tb *tb)return 0 ; } +static void tb_restore_children (struct tb_switch *sw) +{ +int i; + +tb_switch_for_each_remote_port (sw, i) { +struct tb_port *port = &sw->ports[i]; + +if (tb_switch_lane_bonding_enable (port->remote->sw)) +dev_warn (&sw->dev,"failed to restore lane bonding\n" ); + +tb_restore_children (port->remote->sw); + } +} +static int tb_resume_noirq (struct tb *tb) {struct tb_cm *tcm =tb_priv (tb);
@@ -718,6 +738,7 @@ static int tb_resume_noirq(struct tb *tb)tb_switch_resume (tb->root_switch);tb_free_invalid_tunnels (tb);tb_free_unplugged_children (tb->root_switch); +tb_restore_children (tb->root_switch);list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list)tb_tunnel_restart (tunnel);if (!list_empty (&tcm->tunnel_list)) {
drivers/thunderbolt/tb.h +10 -0
@@ -61,6 +61,8 @@ struct tb_switch_nvm {* @device: Device ID of the switch * @vendor_name: Name of the vendor (or %NULL if not known) * @device_name: Name of the device (or %NULL if not known) +* @link_speed: Speed of the link in Gb/s +* @link_width: Width of the link (1 or 2) * @generation: Switch Thunderbolt generation * @cap_plug_events: Offset to the plug events capability (%0 if not found) * @cap_lc: Offset to the link controller capability (%0 if not found)
@@ -97,6 +99,8 @@ struct tb_switch {u16 device;const char *vendor_name;const char *device_name; +unsigned int link_speed; +unsigned int link_width;unsigned int generation;int cap_plug_events;int cap_lc;
@@ -127,6 +131,7 @@ struct tb_switch {* @cap_adap: Offset of the adapter specific capability (%0 if not present) * @port: Port number on switch * @disabled: Disabled by eeprom +* @bonded: true if the port is bonded (two lanes combined as one) * @dual_link_port: If the switch is connected using two ports, points * to the other port. * @link_nr: Is this primary or secondary port on the dual_link.
@@ -142,6 +147,7 @@ struct tb_port {int cap_adap;u8 port;bool disabled; +bool bonded;struct tb_port *dual_link_port; u8 link_nr:1;struct ida in_hopids;
@@ -640,6 +646,9 @@ static inline bool tb_switch_is_icm(const struct tb_switch *sw)return !sw->config.enabled; } +int tb_switch_lane_bonding_enable (struct tb_switch *sw); +void tb_switch_lane_bonding_disable (struct tb_switch *sw); +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
@@ -683,6 +692,7 @@ int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);int tb_lc_configure_link (struct tb_switch *sw);void tb_lc_unconfigure_link (struct tb_switch *sw);int tb_lc_set_sleep (struct tb_switch *sw); +bool tb_lc_lane_bonding_possible (struct tb_switch *sw);static inline int tb_route_length (u64 route) {
drivers/thunderbolt/tb_msgs.h +2 -0
@@ -122,6 +122,8 @@ struct icm_pkg_header {#define ICM_FLAGS_NO_KEY BIT(1)#define ICM_FLAGS_SLEVEL_SHIFT 3#define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3) +#define ICM_FLAGS_DUAL_LANE BIT(5) +#define ICM_FLAGS_SPEED_GEN3 BIT(7)#define ICM_FLAGS_WRITE BIT(7)struct icm_pkg_driver_ready {
drivers/thunderbolt/tb_regs.h +20 -0
@@ -219,6 +219,23 @@ struct tb_regs_port_header {#define TB_PORT_LCA_SHIFT 22#define TB_PORT_LCA_MASK GENMASK(28, 22) +/* Lane adapter registers */ +#define LANE_ADP_CS_0 0x00 +#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20) +#define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20 +#define LANE_ADP_CS_1 0x01 +#define LANE_ADP_CS_1_TARGET_WIDTH_MASK GENMASK(9, 4) +#define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT 4 +#define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE 0x1 +#define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3 +#define LANE_ADP_CS_1_LB BIT(15) +#define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16) +#define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT 16 +#define LANE_ADP_CS_1_CURRENT_SPEED_GEN2 0x8 +#define LANE_ADP_CS_1_CURRENT_SPEED_GEN3 0x4 +#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20) +#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20 +/* Display Port adapter registers */ /* DWORD 0 */
@@ -280,6 +297,9 @@ struct tb_regs_hop {#define TB_LC_FUSE 0x03/* Link controller registers */ +#define TB_LC_PORT_ATTR 0x8d +#define TB_LC_PORT_ATTR_BE BIT(12) +#define TB_LC_SX_CTRL 0x96#define TB_LC_SX_CTRL_L1C BIT(16)#define TB_LC_SX_CTRL_L2C BIT(20)
drivers/thunderbolt/tunnel.c +18 -1
@@ -90,6 +90,22 @@ static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate)return 0 ; } +static int tb_initial_credits (const struct tb_switch *sw) +{ +/* If the path is complete sw is not NULL */ +if (sw) { +/* More credits for faster link */ +switch (sw->link_speed * sw->link_width) { +case 40 : +return 32 ; +case 20 : +return 24 ; + } + } + +return 16 ; +} +static void tb_pci_init_path (struct tb_path *path) { path->egress_fc_enable =TB_PATH_SOURCE |TB_PATH_INTERNAL ;
@@ -101,7 +117,8 @@ static void tb_pci_init_path(struct tb_path *path) path->drop_packages =0 ; path->nfc_credits =0 ; path->hops[0 ].initial_credits =7 ; - path->hops[1 ].initial_credits =16 ; + path->hops[1 ].initial_credits = +tb_initial_credits (path->hops[1 ].in_port->sw); }/**
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Quoted 10 lines · Mika Westerberg
Lane bonding allows aggregating the two 10/20 Gb/s (depending on the generation) lanes into a single 20/40 Gb/s bonded link. This allows sharing the full bandwidth more efficiently. In order to establish lane bonding we need to check that the lane bonding is possible through LC and that both end of the link actually supports 2x widths. This also means that all the paths should be established through the primary port so update
tb_path_alloc()to handle this as well.Lane bonding is supported starting from Falcon Ridge (2nd generation) controllers.
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
Anyway, one tiny nit below:
Quoted 48 lines
Signed-off-by Mika Westerberg <[email protected]>--- .../ABI/testing/sysfs-bus-thunderbolt | 17 ++ drivers/thunderbolt/icm.c | 18 +- drivers/thunderbolt/lc.c | 28 ++ drivers/thunderbolt/path.c | 30 +- drivers/thunderbolt/switch.c | 274 ++++++++++++++++++ drivers/thunderbolt/tb.c | 21 ++ drivers/thunderbolt/tb.h | 10 + drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tunnel.c | 19 +- 10 files changed, 429 insertions(+), 10 deletions(-)Documentation/ABI/testing/sysfs-bus-thunderbolt +17
-0@@ -104,6 +104,23 @@ Contact: [email protected] Description: This attribute contains name of this device extracted from the device DROM. +What: /sys/bus/thunderbolt/devices/.../link_speed +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link speed + in Gb/s per lane. If there are two lanes they both are + running at the same speed. Use link_width to determine + whether the two lanes are bonded or not. + +What: /sys/bus/thunderbolt/devices/.../link_width +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link width. + It is 1 for single lane link (or two single lane links) + and 2 for bonded dual lane link. + What: /sys/bus/thunderbolt/devices/.../vendor Date: Sep 2017 KernelVersion: 4.13drivers/thunderbolt/icm.c +0
-0
drivers/thunderbolt/icm.c static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, · line 571
Quoted 6 lines
drivers/thunderbolt/icm.c +2
-1@@ -567,7 +567,8 @@ static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, size_t ep_name_size, u8 connection_id, u8 connection_key, u8 link, u8 depth, enum tb_security_level security_level, - bool authorized, bool boot) + bool authorized, bool boot, bool dual_lane, + bool speed_gen3)
That's just a crazy amount of function parameters, with no way of remembering what is what, especially when you add 2 more booleans at the end.
It's your code, but ugh, that's going to be hard to maintain over time :(
Quoted 303 lines
drivers/thunderbolt/icm.c +11
-4{const struct intel_vss *vss;struct tb_switch *sw;@@ -592,6 +593,8 @@ static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, sw->authorized = authorized; sw->security_level = security_level; sw->boot = boot; + sw->link_speed = speed_gen3 ?20 :10 ; + sw->link_width = dual_lane ?2 :1 ;init_completion (&sw->rpm_complete); vss =parse_intel_vss (ep_name, ep_name_size);@@ -697,11 +700,11 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) (const struct icm_fr_event_device_connected *)hdr;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw; +bool boot, dual_lane, speed_gen3;struct icm *icm =tb_priv (tb);bool authorized = false;struct tb_xdomain *xd;u8 link, depth; -bool boot;u64 route;int ret;@@ -714,6 +717,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n",@@ -814,7 +819,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name,sizeof (pkg->ep_name), pkg->connection_id, pkg->connection_key, link, depth, security_level, - authorized, boot); + authorized, boot, dual_lane, speed_gen3);tb_switch_put (parent_sw); }@@ -1142,10 +1147,10 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, {const struct icm_tr_event_device_connected *pkg = (const struct icm_tr_event_device_connected *)hdr; +bool authorized, boot, dual_lane, speed_gen3;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw;struct tb_xdomain *xd; -bool authorized, boot;u64 route;icm_postpone_rescan (tb);@@ -1163,6 +1168,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n",@@ -1207,7 +1214,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, sw =add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name,sizeof (pkg->ep_name), pkg->connection_id,0 ,0 ,0 , - security_level, authorized, boot); + security_level, authorized, boot, dual_lane, + speed_gen3);if (!IS_ERR (sw) && force_rtd3) sw->rpm = true;drivers/thunderbolt/lc.c +28
-0@@ -177,3 +177,31 @@ int tb_lc_set_sleep(struct tb_switch *sw)return 0 ; } + +/** +* tb_lc_lane_bonding_possible() - Is lane bonding possible towards switch +* @sw: Switch to check +* +* Checks whether conditions for lane bonding from parent to @sw are +* possible. +*/ +bool tb_lc_lane_bonding_possible (struct tb_switch *sw) +{ +struct tb_port *up; +int cap, ret; +u32 val; + +if (sw->generation <2 ) +return false; + + up =tb_upstream_port (sw); + cap =find_port_lc_cap (up); +if (cap <0 ) +return false; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , cap +TB_LC_PORT_ATTR ,1 ); +if (ret) +return false; + +return !!(val &TB_LC_PORT_ATTR_BE ); +}drivers/thunderbolt/path.c +26
-4@@ -220,7 +220,8 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,* Creates path between two ports starting with given @src_hopid. Reserves * HopIDs for each port (they can be different from @src_hopid depending on * how many HopIDs each port already have reserved). If there are dual -* links on the path, prioritizes using @link_nr. +* links on the path, prioritizes using @link_nr but takes into account +* that the lanes may be bonded. * * Return: Returns a tb_path on success or NULL on failure. */ @@ -259,7 +260,9 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!in_port) goto err; -if (in_port->dual_link_port && in_port->link_nr != link_nr) +/* When lanes are bonded primary link must be used */ +if (!in_port->bonded && in_port->dual_link_port && + in_port->link_nr != link_nr) in_port = in_port->dual_link_port; ret =tb_port_alloc_in_hopid (in_port, in_hopid, in_hopid);@@ -271,8 +274,27 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!out_port) goto err; -if (out_port->dual_link_port && out_port->link_nr != link_nr) - out_port = out_port->dual_link_port; +/* +* Pick up right port when going from non-bonded to +* bonded or from bonded to non-bonded. +*/ +if (out_port->dual_link_port) { +if (!in_port->bonded && out_port->bonded && + out_port->link_nr) { +/* +* Use primary link when going from +* non-bonded to bonded. +*/ + out_port = out_port->dual_link_port; + }else if (!out_port->bonded && + out_port->link_nr != link_nr) { +/* +* If out port is not bonded follow +* link_nr. +*/ + out_port = out_port->dual_link_port; + } + }if (i == num_hops -1 ) ret = tb_port_alloc_out_hopid(out_port, dst_hopid,drivers/thunderbolt/switch.c +126
-0@@ -775,6 +775,132 @@ struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,return next; } +static int tb_port_get_link_speed (struct tb_port *port) +{ +u32 val, speed; +int ret; + +if (!port->cap_phy) +return -EINVAL ; + + ret =tb_port_read (port, &val,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_1 ,1 ); +if (ret) +return ret; + + speed = (val &LANE_ADP_CS_1_CURRENT_SPEED_MASK ) >> +LANE_ADP_CS_1_CURRENT_SPEED_SHIFT ; +return speed ==LANE_ADP_CS_1_CURRENT_SPEED_GEN3 ?20 :10 ; +} + +static int tb_port_get_link_width (struct tb_port *port) +{ +u32 val; +int ret; + +if (!port->cap_phy) +return -EINVAL ; + + ret =tb_port_read (port, &val,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_1 ,1 ); +if (ret) +return ret; + +return (val &LANE_ADP_CS_1_CURRENT_WIDTH_MASK ) >> +LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT ; +} + +static bool tb_port_is_width_supported (struct tb_port *port,int width) +{ +u32 phy, widths; +int ret; + +if (!port->cap_phy) +return false; + + ret =tb_port_read (port, &phy,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_0 ,1 ); +if (ret) +return ret; + + widths = (phy &LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK ) >> +LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT ; + +return !!(widths & width); +} + +static int tb_port_set_link_width (struct tb_port *port,unsigned int width) +{ +u32 val; +int ret; + +if (!port->cap_phy) +return -EINVAL ; + + ret =tb_port_read (port, &val,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_1 ,1 ); +if (ret) +return ret; + + val &= ~LANE_ADP_CS_1_TARGET_WIDTH_MASK ; +switch (width) { +case 1 : + val |=LANE_ADP_CS_1_TARGET_WIDTH_SINGLE << +LANE_ADP_CS_1_TARGET_WIDTH_SHIFT ; +break ; +case 2 : + val |=LANE_ADP_CS_1_TARGET_WIDTH_DUAL << +LANE_ADP_CS_1_TARGET_WIDTH_SHIFT ; +break ; +default : +return -EINVAL ; + } + + val |=LANE_ADP_CS_1_LB ; + +return tb_port_write (port, &val,TB_CFG_PORT , + port->cap_phy +LANE_ADP_CS_1 ,1 ); +} + +static int tb_port_lane_bonding_enable (struct tb_port *port) +{ +int ret; + +/* +* Enable lane bonding for both links if not already enabled by +* for example the boot firmware. +*/ + ret =tb_port_get_link_width (port); +if (ret ==1 ) { + ret =tb_port_set_link_width (port,2 ); +if (ret) +return ret; + } + + ret =tb_port_get_link_width (port->dual_link_port); +if (ret ==1 ) { + ret =tb_port_set_link_width (port->dual_link_port,2 ); +if (ret) { +tb_port_set_link_width (port,1 ); +return ret; + } + } + + port->bonded = true; + port->dual_link_port->bonded = true; + +return 0 ; +} + +static void tb_port_lane_bonding_disable (struct tb_port *port) +{ + port->dual_link_port->bonded = false; + port->bonded = false; + +tb_port_set_link_width (port->dual_link_port,1 ); +tb_port_set_link_width (port,1 ); +} +/** * tb_port_is_enabled() - Is the adapter port enabled * @port: Port to check
drivers/thunderbolt/switch.c static ssize_t key_store(struct device *dev, struct device_attribute *attr, · line 1300
Quoted 9 lines
drivers/thunderbolt/switch.c +6
-0@@ -1166,6 +1292,26 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR(key, 0600, key_show, key_store); +static ssize_t link_speed_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct tb_switch *sw =tb_to_switch (dev); + +return sprintf (buf,"%u.0 Gb/s\n" , sw->link_speed);
Why units? ".0" is implied as it always will be the case, so why not just have the units be Gb in the sysfs documentation file and then just report link_speed here with nothing else? Makes it much easier for userspace to parse as well.
Otherwise, looks sane to me, nice job.
greg k-h
Re: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Mika Westerberg
Lane bonding allows aggregating the two 10/20 Gb/s (depending on the generation) lanes into a single 20/40 Gb/s bonded link. This allows sharing the full bandwidth more efficiently. In order to establish lane bonding we need to check that the lane bonding is possible through LC and that both end of the link actually supports 2x widths. This also means that all the paths should be established through the primary port so update
tb_path_alloc()to handle this as well.
Quoted 6 lines
Quoted 2 lines
Lane bonding is supported starting from Falcon Ridge (2nd generation) controllers.
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
AFAICT only two lanes are available in USB4. This goes over USB type-C using the two lanes there.
Of course I don't know if in future there will be USB4 1.1 or something that adds more lanes so if you think there is a better way to specify these, I'm happy to implement that instead :)
Quoted 61 lines
Anyway, one tiny nit below:
Quoted 48 lines
Signed-off-by Mika Westerberg <[email protected]>--- .../ABI/testing/sysfs-bus-thunderbolt | 17 ++ drivers/thunderbolt/icm.c | 18 +- drivers/thunderbolt/lc.c | 28 ++ drivers/thunderbolt/path.c | 30 +- drivers/thunderbolt/switch.c | 274 ++++++++++++++++++ drivers/thunderbolt/tb.c | 21 ++ drivers/thunderbolt/tb.h | 10 + drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tunnel.c | 19 +- 10 files changed, 429 insertions(+), 10 deletions(-)Documentation/ABI/testing/sysfs-bus-thunderbolt +17
-0@@ -104,6 +104,23 @@ Contact: [email protected] Description: This attribute contains name of this device extracted from the device DROM. +What: /sys/bus/thunderbolt/devices/.../link_speed +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link speed + in Gb/s per lane. If there are two lanes they both are + running at the same speed. Use link_width to determine + whether the two lanes are bonded or not. + +What: /sys/bus/thunderbolt/devices/.../link_width +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the current upstream link width. + It is 1 for single lane link (or two single lane links) + and 2 for bonded dual lane link. + What: /sys/bus/thunderbolt/devices/.../vendor Date: Sep 2017 KernelVersion: 4.13drivers/thunderbolt/icm.c +0
-0drivers/thunderbolt/icm.c static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, · line 571
Quoted 6 lines
drivers/thunderbolt/icm.c +2
-1@@ -567,7 +567,8 @@ static struct tb_switch *add_switch(struct tb_switch *parent_sw, u64 route, size_t ep_name_size, u8 connection_id, u8 connection_key, u8 link, u8 depth, enum tb_security_level security_level, - bool authorized, bool boot) + bool authorized, bool boot, bool dual_lane, + bool speed_gen3)That's just a crazy amount of function parameters, with no way of remembering what is what, especially when you add 2 more booleans at the end.
Quoted 2 lines
It's your code, but ugh, that's going to be hard to maintain over time :(
Good point. I'll see if I can simplify it in the next version.
Re: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Am Dienstag, den 01.10.2019, 15:53 +0300 schrieb Mika Westerberg:
Quoted 11 lines
Quoted 4 lines
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
AFAICT only two lanes are available in USB4. This goes over USB type-C using the two lanes there.
Of course I don't know if in future there will be USB4 1.1 or something that adds more lanes so if you think there is a better way to specify these, I'm happy to implement that instead :)
If this ever can become asymmetric this interface is going to turn around and bite.
Regards
Oliver
Re: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Quoted 9 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 15:53 +0300 schrieb Mika Westerberg:
Quoted 8 lines
Quoted 4 lines
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
AFAICT only two lanes are available in USB4. This goes over USB type-C using the two lanes there.
Quoted 6 lines
Quoted 3 lines
Of course I don't know if in future there will be USB4 1.1 or something that adds more lanes so if you think there is a better way to specify these, I'm happy to implement that instead :)
If this ever can become asymmetric this interface is going to turn around and bite.
Don't think it can be asymmetric but I'm open to all ideas how to make it more flexible :-)
Re: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Am Mittwoch, den 02.10.2019, 17:30 +0300 schrieb Mika Westerberg:
Quoted 14 lines · Oliver Neukum
Quoted 13 lines
Am Dienstag, den 01.10.2019, 15:53 +0300 schrieb Mika Westerberg:
Quoted 11 lines
Quoted 4 lines
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
AFAICT only two lanes are available in USB4. This goes over USB type-C using the two lanes there.
Of course I don't know if in future there will be USB4 1.1 or something that adds more lanes so if you think there is a better way to specify these, I'm happy to implement that instead :)
Quoted 5 lines
Quoted 2 lines
If this ever can become asymmetric this interface is going to turn around and bite.
Don't think it can be asymmetric but I'm open to all ideas how to make it more flexible :-)
Split the the attributes into link_speed_rx and link_speed_tx. For link_width likewise. We had the same issue with USB.
Regards
Oliver
Re: [RFC PATCH 06/22] thunderbolt: Add support for lane bonding
Quoted 15 lines · Oliver Neukum
Am Mittwoch, den 02.10.2019, 17:30 +0300 schrieb Mika Westerberg:
Quoted 14 lines · Oliver Neukum
Quoted 13 lines
Am Dienstag, den 01.10.2019, 15:53 +0300 schrieb Mika Westerberg:
Quoted 11 lines
Quoted 4 lines
Are we only going to be allowed to "bond" two links together? Or will we be doing more than 2 in the future? If more, then we might want to think of a different way to specify these...
AFAICT only two lanes are available in USB4. This goes over USB type-C using the two lanes there.
Of course I don't know if in future there will be USB4 1.1 or something that adds more lanes so if you think there is a better way to specify these, I'm happy to implement that instead :)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If this ever can become asymmetric this interface is going to turn around and bite.
Don't think it can be asymmetric but I'm open to all ideas how to make it more flexible :-)
Split the the attributes into
link_speed_rxandlink_speed_tx. Forlink_widthlikewise. We had the same issue with USB.
OK, thanks for the suggestion.
RFC PATCH 7/22 thunderbolt: Add default linking between ports if not provided by DROM
In reply to Mika WesterbergSome cases the DROM information is not correct or is simply missing. This prevents establishing lane bonding even if it would be possible otherwise. To make this work better provide default linking between ports if DROM has not provided that information.
This works with legacy devices where ports 1 and 2, and 3 and 4 are linked together and also with USB4.
--- drivers/thunderbolt/eeprom.c | 11 ----------- drivers/thunderbolt/switch.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-)
drivers/thunderbolt/eeprom.c +0 -11
@@ -514,17 +514,6 @@ int tb_drom_read(struct tb_switch *sw)* no entries). Hardcode the configuration here. */ tb_drom_read_uid_only (sw, &sw->uid); - - sw->ports[1 ].link_nr =0 ; - sw->ports[2 ].link_nr =1 ; - sw->ports[1 ].dual_link_port = &sw->ports[2 ]; - sw->ports[2 ].dual_link_port = &sw->ports[1 ]; - - sw->ports[3 ].link_nr =0 ; - sw->ports[4 ].link_nr =1 ; - sw->ports[3 ].dual_link_port = &sw->ports[4 ]; - sw->ports[4 ].dual_link_port = &sw->ports[3 ]; -return 0 ; }
drivers/thunderbolt/switch.c +32 -0
@@ -1904,6 +1904,36 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)return -ESHUTDOWN ; } +static void tb_switch_default_link_ports (struct tb_switch *sw) +{ +int i; + +for (i =1 ; i <= sw->config.max_port_number; i +=2 ) { +struct tb_port *port = &sw->ports[i]; +struct tb_port *subordinate; + +if (!tb_port_is_null (port)) +continue ; + +/* Check for the subordinate port */ +if (i == sw->config.max_port_number || + !tb_port_is_null (&sw->ports[i +1 ])) +continue ; + +/* Link them if not already done so (by DROM) */ + subordinate = &sw->ports[i +1 ]; +if (!port->dual_link_port && !subordinate->dual_link_port) { + port->link_nr =0 ; + port->dual_link_port = subordinate; + subordinate->link_nr =1 ; + subordinate->dual_link_port = port; + +tb_sw_dbg (sw,"linked ports %d <-> %d\n" , + port->port, subordinate->port); + } + } +} +static bool tb_switch_lane_bonding_possible (struct tb_switch *sw) {const struct tb_port *up =tb_upstream_port (sw);
@@ -2071,6 +2101,8 @@ int tb_switch_add(struct tb_switch *sw)return ret; } +tb_switch_default_link_ports (sw); + ret =tb_switch_update_link_attributes (sw);if (ret)return ret;
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 07/22] thunderbolt: Add default linking between ports if not provided by DROM
Quoted 1 line · Mika Westerberg
Some cases the DROM information is not correct or is simply missing.
What is "DROM"?
Quoted 6 lines
This prevents establishing lane bonding even if it would be possible otherwise. To make this work better provide default linking between ports if DROM has not provided that information.
This works with legacy devices where ports 1 and 2, and 3 and 4 are linked together and also with USB4.
"linked together" as in "bonded"? Or something else? Names are getting confusing here :(
thanks,
greg k-h
Re: [RFC PATCH 07/22] thunderbolt: Add default linking between ports if not provided by DROM
Quoted 4 lines · Greg Kroah-Hartman
Quoted 1 line · Mika Westerberg
Some cases the DROM information is not correct or is simply missing.
What is "DROM"?
It is "Device ROM". Essentially per-device information. I will spell it out in next version.
Quoted 9 lines
Quoted 6 lines
This prevents establishing lane bonding even if it would be possible otherwise. To make this work better provide default linking between ports if DROM has not provided that information.
This works with legacy devices where ports 1 and 2, and 3 and 4 are linked together and also with USB4.
"linked together" as in "bonded"? Or something else? Names are getting confusing here :(
Here linked together means the both port in dual link so ports 1, 2 and ports 3 and 4. There are always two pairs of ports (lanes) that go out of physical connector. Here we just link them in software. I'll try to clarify this in the next version.
RFC PATCH 8/22 thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
In reply to Mika WesterbergIn order to keep PCIe hierarchies consistent across hotplugs, add hard-coded PCIe downstream port to Thunderbolt port for Alpine Ridge and Titan Ridge as well.
--- drivers/thunderbolt/tb.c | 4 +++- drivers/thunderbolt/tb.h | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)
drivers/thunderbolt/tb.c +3 -1
@@ -344,10 +344,12 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,* Hard-coded Thunderbolt port to PCIe down port mapping * per controller. */ -if (tb_switch_is_cr (sw)) +if (tb_switch_is_cr (sw) ||tb_switch_is_ar (sw)) index = !phy_port ?6 :7 ;else if (tb_switch_is_fr (sw)) index = !phy_port ?6 :8 ; +else if (tb_switch_is_tr (sw)) + index = !phy_port ?8 :9 ;else goto out;
drivers/thunderbolt/tb.h +25 -0
@@ -632,6 +632,31 @@ static inline bool tb_switch_is_fr(const struct tb_switch *sw) } } +static inline bool tb_switch_is_ar (const struct tb_switch *sw) +{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE : +return true; +default : +return false; + } +} + +static inline bool tb_switch_is_tr (const struct tb_switch *sw) +{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE : +return true; +default : +return false; + } +} +/** * tb_switch_is_icm() - Is the switch handled by ICM firmware * @sw: Switch to check
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 08/22] thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
Quoted 3 lines · Mika Westerberg
In order to keep PCIe hierarchies consistent across hotplugs, add hard-coded PCIe downstream port to Thunderbolt port for Alpine Ridge and Titan Ridge as well.
Oh, that makes me nervous, how could a hard-coded pcie port ever get set up incorrectly :)
How do we "know" that this is correct? Is there any ACPI guarantees that this "always will be so"? If not, we all know someone will mess this up...
Quoted 30 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb.c | 4 +++- drivers/thunderbolt/tb.h | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)drivers/thunderbolt/tb.c +3
-1@@ -344,10 +344,12 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,* Hard-coded Thunderbolt port to PCIe down port mapping * per controller. */ -if (tb_switch_is_cr (sw)) +if (tb_switch_is_cr (sw) ||tb_switch_is_ar (sw)) index = !phy_port ?6 :7 ;else if (tb_switch_is_fr (sw)) index = !phy_port ?6 :8 ; +else if (tb_switch_is_tr (sw)) + index = !phy_port ?8 :9 ;else goto out;drivers/thunderbolt/tb.h +0
-0
drivers/thunderbolt/tb.h static inline bool tb_switch_is_fr(const struct tb_switch *sw) · line 635
Quoted 4 lines
drivers/thunderbolt/tb.h +1
-0@@ -632,6 +632,31 @@ static inline bool tb_switch_is_fr(const struct tb_switch *sw) } } +static inline bool tb_switch_is_ar (const struct tb_switch *sw)
"ar"? Can you spell it out?
drivers/thunderbolt/tb.h static inline bool tb_switch_is_fr(const struct tb_switch *sw) · line 648
Quoted 13 lines
drivers/thunderbolt/tb.h +13
-0+{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE : +return true; +default : +return false; + } +} + +static inline bool tb_switch_is_tr (const struct tb_switch *sw)
Same for "tr" please.
thanks,
greg k-h
Re: [RFC PATCH 08/22] thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
Quoted 11 lines · Greg Kroah-Hartman
Quoted 3 lines · Mika Westerberg
In order to keep PCIe hierarchies consistent across hotplugs, add hard-coded PCIe downstream port to Thunderbolt port for Alpine Ridge and Titan Ridge as well.
Oh, that makes me nervous, how could a hard-coded pcie port ever get set up incorrectly :)
How do we "know" that this is correct? Is there any ACPI guarantees that this "always will be so"? If not, we all know someone will mess this up...
For Alpine Ridge and Titan Ridge the PCIe ports are always the same.
Basically what this is about is that you have up to two Thunderbolt ports (type-C ports). When you plug in Thunderbolt device and PCIe gets tunneled, the PCIe hierarchy always is always extended from the same PCIe downstream port.
If we don't do this then the PCIe device may be changing its address each plug/unplug. Also for older generations (that code is already in mainline) there are PCIe downstream ports that do not have enough resources for additional devices.
Quoted 32 lines
Quoted 32 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb.c | 4 +++- drivers/thunderbolt/tb.h | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)drivers/thunderbolt/tb.c +3
-1@@ -344,10 +344,12 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,* Hard-coded Thunderbolt port to PCIe down port mapping * per controller. */ -if (tb_switch_is_cr (sw)) +if (tb_switch_is_cr (sw) ||tb_switch_is_ar (sw)) index = !phy_port ?6 :7 ;else if (tb_switch_is_fr (sw)) index = !phy_port ?6 :8 ; +else if (tb_switch_is_tr (sw)) + index = !phy_port ?8 :9 ;else goto out;drivers/thunderbolt/tb.h +0
-0@@ -632,6 +632,31 @@ static inline bool tb_switch_is_fr(const struct tb_switch *sw) } }
Quoted 3 lines
drivers/thunderbolt/tb.h static inline bool tb_switch_is_fr(const struct tb_switch *sw) · line 635
Quoted 1 line
drivers/thunderbolt/tb.h +1
-0+static inline bool tb_switch_is_ar (const struct tb_switch *sw)"ar"? Can you spell it out?
You mean call this tb_switch_is_alpine_ridge()? Sure, I will then do the same for tb_switch_is_fr() and the existing ones.
Quoted 16 lines
Quoted 4 lines
drivers/thunderbolt/tb.h +3
-0+{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE :drivers/thunderbolt/tb.h static inline bool tb_switch_is_fr(const struct tb_switch *sw) · line 648
Quoted 10 lines
drivers/thunderbolt/tb.h +10
-0+case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE : +return true; +default : +return false; + } +} + +static inline bool tb_switch_is_tr (const struct tb_switch *sw)Same for "tr" please.
Sure.
RFC PATCH 9/22 thunderbolt: Convert basic adapter register names to follow the USB4 spec
In reply to Mika WesterbergNow that USB4 spec has names for these basic registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 18 +++++++++--------- drivers/thunderbolt/tb_regs.h | 15 ++++++++------- drivers/thunderbolt/tunnel.c | 10 +++++----- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/thunderbolt/switch.c +9 -9
@@ -553,17 +553,17 @@ int tb_port_add_nfc_credits(struct tb_port *port, int credits)if (credits ==0 || port->sw->is_unplugged)return 0 ; - nfc_credits = port->config.nfc_credits &TB_PORT_NFC_CREDITS_MASK ; + nfc_credits = port->config.nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ; nfc_credits += credits; -tb_port_dbg (port,"adding %d NFC credits to %lu" , - credits, port->config.nfc_credits &TB_PORT_NFC_CREDITS_MASK ); +tb_port_dbg (port,"adding %d NFC credits to %lu" , credits, + port->config.nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ); - port->config.nfc_credits &= ~TB_PORT_NFC_CREDITS_MASK ; + port->config.nfc_credits &= ~ADP_CS_4_NFC_BUFFERS_MASK ; port->config.nfc_credits |= nfc_credits;return tb_port_write (port, &port->config.nfc_credits, -TB_CFG_PORT ,4 ,1 ); +TB_CFG_PORT ,ADP_CS_4 ,1 ); }/**
@@ -578,14 +578,14 @@ int tb_port_set_initial_credits(struct tb_port *port, u32 credits)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT ,5 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT ,ADP_CS_5 ,1 );if (ret)return ret; - data &= ~TB_PORT_LCA_MASK ; - data |= (credits <<TB_PORT_LCA_SHIFT ) &TB_PORT_LCA_MASK ; + data &= ~ADP_CS_5_LCA_MASK ; + data |= (credits <<ADP_CS_5_LCA_SHIFT ) &ADP_CS_5_LCA_MASK ; -return tb_port_write (port, &data,TB_CFG_PORT ,5 ,1 ); +return tb_port_write (port, &data,TB_CFG_PORT ,ADP_CS_5 ,1 ); }/**
drivers/thunderbolt/tb_regs.h +8 -7
@@ -211,13 +211,14 @@ struct tb_regs_port_header { } __packed; -/* DWORD 4 */ -#define TB_PORT_NFC_CREDITS_MASK GENMASK(19, 0) -#define TB_PORT_MAX_CREDITS_SHIFT 20 -#define TB_PORT_MAX_CREDITS_MASK GENMASK(26, 20) -/* DWORD 5 */ -#define TB_PORT_LCA_SHIFT 22 -#define TB_PORT_LCA_MASK GENMASK(28, 22) +/* Basic adapter configuration registers */ +#define ADP_CS_4 0x04 +#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0) +#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20) +#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20 +#define ADP_CS_5 0x05 +#define ADP_CS_5_LCA_MASK GENMASK(28, 22) +#define ADP_CS_5_LCA_SHIFT 22/* Lane adapter registers */ #define LANE_ADP_CS_0 0x00
drivers/thunderbolt/tunnel.c +5 -5
@@ -341,12 +341,12 @@ static void tb_dp_init_video_path(struct tb_path *path, bool discover) path->weight =1 ;if (discover) { - path->nfc_credits = nfc_credits &TB_PORT_NFC_CREDITS_MASK ; + path->nfc_credits = nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ; }else {u32 max_credits; - max_credits = (nfc_credits &TB_PORT_MAX_CREDITS_MASK ) >> -TB_PORT_MAX_CREDITS_SHIFT ; + max_credits = (nfc_credits &ADP_CS_4_TOTAL_BUFFERS_MASK ) >> +ADP_CS_4_TOTAL_BUFFERS_SHIFT ;/* Leave some credits for AUX path */ path->nfc_credits =min (max_credits -2 ,12U ); }
@@ -495,8 +495,8 @@ static u32 tb_dma_credits(struct tb_port *nhi) {u32 max_credits; - max_credits = (nhi->config.nfc_credits &TB_PORT_MAX_CREDITS_MASK ) >> -TB_PORT_MAX_CREDITS_SHIFT ; + max_credits = (nhi->config.nfc_credits &ADP_CS_4_TOTAL_BUFFERS_MASK ) >> +ADP_CS_4_TOTAL_BUFFERS_SHIFT ;return min (max_credits,13U ); }
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 09/22] thunderbolt: Convert basic adapter register names to follow the USB4 spec
Quoted 6 lines · Mika Westerberg
Now that USB4 spec has names for these basic registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
Signed-off-by Mika Westerberg <[email protected]>
This is nice to see, can we add this to the tree now? :)
thanks,
greg k-h
Re: [RFC PATCH 09/22] thunderbolt: Convert basic adapter register names to follow the USB4 spec
Quoted 9 lines · Greg Kroah-Hartman
Quoted 6 lines · Mika Westerberg
Now that USB4 spec has names for these basic registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
Signed-off-by Mika Westerberg <[email protected]>This is nice to see, can we add this to the tree now? :)
Yes, I can re-arrange the series so that these are first so they can be merged before rest of the USB4 support.
RFC PATCH 10/22 thunderbolt: Convert PCIe adapter register names to use USB4 names
In reply to Mika WesterbergNow that USB4 spec has names for these PCIe adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 10 ++++++---- drivers/thunderbolt/tb_regs.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/thunderbolt/switch.c +6 -4
@@ -929,10 +929,11 @@ bool tb_pci_port_is_enabled(struct tb_port *port) {u32 data; -if (tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap,1 )) +if (tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_PCIE_CS_0 ,1 ))return false; -return !!(data &TB_PCI_EN ); +return !!(data &ADP_PCIE_CS_0_PE ); }/**
@@ -942,10 +943,11 @@ bool tb_pci_port_is_enabled(struct tb_port *port)*/ int tb_pci_port_enable (struct tb_port *port,bool enable) { -u32 word = enable ?TB_PCI_EN :0x0 ; +u32 word = enable ?ADP_PCIE_CS_0_PE :0x0 ;if (!port->cap_adap)return -ENXIO ; -return tb_port_write (port, &word,TB_CFG_PORT , port->cap_adap,1 ); +return tb_port_write (port, &word,TB_CFG_PORT , + port->cap_adap +ADP_PCIE_CS_0 ,1 ); }/**
drivers/thunderbolt/tb_regs.h +2 -2
@@ -258,8 +258,8 @@ struct tb_regs_port_header {#define TB_DP_REMOTE_CAP 0x5/* PCIe adapter registers */ - -#define TB_PCI_EN BIT(31) +#define ADP_PCIE_CS_0 0x00 +#define ADP_PCIE_CS_0_PE BIT(31)/* Hop register from TB_CFG_HOPS. 8 byte per entry. */ struct tb_regs_hop {
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 10/22] thunderbolt: Convert PCIe adapter register names to use USB4 names
Quoted 4 lines · Mika Westerberg
Now that USB4 spec has names for these PCIe adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
Same here, can we merge this now?
thanks,
greg k-h
RFC PATCH 11/22 thunderbolt: Convert DP adapter register names to follow the USB4 spec
In reply to Mika WesterbergNow that USB4 spec has names for these DP adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 50 ++++++++++++++++++++--------------- drivers/thunderbolt/tb_regs.h | 32 ++++++++++------------ drivers/thunderbolt/tunnel.c | 8 +++--- 3 files changed, 46 insertions(+), 44 deletions(-)
drivers/thunderbolt/switch.c +28 -22
@@ -961,11 +961,12 @@ int tb_dp_port_hpd_is_active(struct tb_port *port)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap +2 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_2 ,1 );if (ret)return ret; -return !!(data &TB_DP_HDP ); +return !!(data &ADP_DP_CS_2_HDP ); }/**
@@ -979,12 +980,14 @@ int tb_dp_port_hpd_clear(struct tb_port *port)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap +3 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_3 ,1 );if (ret)return ret; - data |=TB_DP_HPDC ; -return tb_port_write (port, &data,TB_CFG_PORT , port->cap_adap +3 ,1 ); + data |=ADP_DP_CS_3_HDPC ; +return tb_port_write (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_3 ,1 ); }/**
@@ -1002,20 +1005,23 @@ int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,u32 data[2 ];int ret; - ret =tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); + ret =tb_port_read (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data));if (ret)return ret; - data[0 ] &= ~TB_DP_VIDEO_HOPID_MASK ; - data[1 ] &= ~(TB_DP_AUX_RX_HOPID_MASK |TB_DP_AUX_TX_HOPID_MASK ); + data[0 ] &= ~ADP_DP_CS_0_VIDEO_HOPID_MASK ; + data[1 ] &= ~ADP_DP_CS_1_AUX_RX_HOPID_MASK ; + data[1 ] &= ~ADP_DP_CS_1_AUX_RX_HOPID_MASK ; - data[0 ] |= (video <<TB_DP_VIDEO_HOPID_SHIFT ) &TB_DP_VIDEO_HOPID_MASK ; - data[1 ] |= aux_tx &TB_DP_AUX_TX_HOPID_MASK ; - data[1 ] |= (aux_rx <<TB_DP_AUX_RX_HOPID_SHIFT ) &TB_DP_AUX_RX_HOPID_MASK ; + data[0 ] |= (video <<ADP_DP_CS_0_VIDEO_HOPID_SHIFT ) & +ADP_DP_CS_0_VIDEO_HOPID_MASK ; + data[1 ] |= aux_tx &ADP_DP_CS_1_AUX_TX_HOPID_MASK ; + data[1 ] |= (aux_rx <<ADP_DP_CS_1_AUX_RX_HOPID_SHIFT ) & +ADP_DP_CS_1_AUX_RX_HOPID_MASK ; -return tb_port_write (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); +return tb_port_write (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)); }/**
@@ -1026,11 +1032,11 @@ bool tb_dp_port_is_enabled(struct tb_port *port) {u32 data[2 ]; -if (tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, +if (tb_port_read (port, data,TB_CFG_PORT , port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)))return false; -return !!(data[0 ] & (TB_DP_VIDEO_EN |TB_DP_AUX_EN )); +return !!(data[0 ] & (ADP_DP_CS_0_VE |ADP_DP_CS_0_AE )); }/**
@@ -1046,18 +1052,18 @@ int tb_dp_port_enable(struct tb_port *port, bool enable)u32 data[2 ];int ret; - ret =tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); + ret =tb_port_read (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data));if (ret)return ret;if (enable) - data[0 ] |=TB_DP_VIDEO_EN |TB_DP_AUX_EN ; + data[0 ] |=ADP_DP_CS_0_VE |ADP_DP_CS_0_AE ;else - data[0 ] &= ~(TB_DP_VIDEO_EN |TB_DP_AUX_EN ); + data[0 ] &= ~(ADP_DP_CS_0_VE |ADP_DP_CS_0_AE ); -return tb_port_write (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); +return tb_port_write (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)); }/* switch utility functions */
drivers/thunderbolt/tb_regs.h +14 -18
@@ -238,24 +238,20 @@ struct tb_regs_port_header {#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20/* Display Port adapter registers */ - -/* DWORD 0 */ -#define TB_DP_VIDEO_HOPID_SHIFT 16 -#define TB_DP_VIDEO_HOPID_MASK GENMASK(26, 16) -#define TB_DP_AUX_EN BIT(30) -#define TB_DP_VIDEO_EN BIT(31) -/* DWORD 1 */ -#define TB_DP_AUX_TX_HOPID_MASK GENMASK(10, 0) -#define TB_DP_AUX_RX_HOPID_SHIFT 11 -#define TB_DP_AUX_RX_HOPID_MASK GENMASK(21, 11) -/* DWORD 2 */ -#define TB_DP_HDP BIT(6) -/* DWORD 3 */ -#define TB_DP_HPDC BIT(9) -/* DWORD 4 */ -#define TB_DP_LOCAL_CAP 0x4 -/* DWORD 5 */ -#define TB_DP_REMOTE_CAP 0x5 +#define ADP_DP_CS_0 0x00 +#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16) +#define ADP_DP_CS_0_VIDEO_HOPID_SHIFT 16 +#define ADP_DP_CS_0_AE BIT(30) +#define ADP_DP_CS_0_VE BIT(31) +#define ADP_DP_CS_1_AUX_TX_HOPID_MASK GENMASK(10, 0) +#define ADP_DP_CS_1_AUX_RX_HOPID_MASK GENMASK(21, 11) +#define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11 +#define ADP_DP_CS_2 0x02 +#define ADP_DP_CS_2_HDP BIT(6) +#define ADP_DP_CS_3 0x03 +#define ADP_DP_CS_3_HDPC BIT(9) +#define DP_LOCAL_CAP 0x04 +#define DP_REMOTE_CAP 0x05/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +4 -4
@@ -258,23 +258,23 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel)/* Read both DP_LOCAL_CAP registers */ ret =tb_port_read (in, &in_dp_cap,TB_CFG_PORT , - in->cap_adap +TB_DP_LOCAL_CAP ,1 ); + in->cap_adap +DP_LOCAL_CAP ,1 );if (ret)return ret; ret =tb_port_read (out, &out_dp_cap,TB_CFG_PORT , - out->cap_adap +TB_DP_LOCAL_CAP ,1 ); + out->cap_adap +DP_LOCAL_CAP ,1 );if (ret)return ret;/* Write IN local caps to OUT remote caps */ ret =tb_port_write (out, &in_dp_cap,TB_CFG_PORT , - out->cap_adap +TB_DP_REMOTE_CAP ,1 ); + out->cap_adap +DP_REMOTE_CAP ,1 );if (ret)return ret;return tb_port_write (in, &out_dp_cap,TB_CFG_PORT , - in->cap_adap +TB_DP_REMOTE_CAP ,1 ); + in->cap_adap +DP_REMOTE_CAP ,1 ); }static int tb_dp_activate (struct tb_tunnel *tunnel,bool active)
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 11/22] thunderbolt: Convert DP adapter register names to follow the USB4 spec
Quoted 4 lines · Mika Westerberg
Now that USB4 spec has names for these DP adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
And here :)
RFC PATCH 12/22 thunderbolt: Add Display Port CM handshake for Titan Ridge devices
In reply to Mika WesterbergTitan Ridge devices and newer need an additional connection manager handshake in order to do proper Display Port tunneling so implement it here.
--- drivers/thunderbolt/tb_regs.h | 3 +++ drivers/thunderbolt/tunnel.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
drivers/thunderbolt/tb_regs.h +3 -0
@@ -252,6 +252,9 @@ struct tb_regs_port_header {#define ADP_DP_CS_3_HDPC BIT(9)#define DP_LOCAL_CAP 0x04#define DP_REMOTE_CAP 0x05 +#define DP_STATUS_CTRL 0x06 +#define DP_STATUS_CTRL_CMHS BIT(25) +#define DP_STATUS_CTRL_UF BIT(26)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +44 -0
62 lines not on this page · raw message
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 12/22] thunderbolt: Add Display Port CM handshake for Titan Ridge devices
Quoted 39 lines · Mika Westerberg
Titan Ridge devices and newer need an additional connection manager handshake in order to do proper Display Port tunneling so implement it here.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb_regs.h | 3 +++ drivers/thunderbolt/tunnel.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)drivers/thunderbolt/tb_regs.h +3
-0@@ -252,6 +252,9 @@ struct tb_regs_port_header {#define ADP_DP_CS_3_HDPC BIT(9)#define DP_LOCAL_CAP 0x04#define DP_REMOTE_CAP 0x05 +#define DP_STATUS_CTRL 0x06 +#define DP_STATUS_CTRL_CMHS BIT(25) +#define DP_STATUS_CTRL_UF BIT(26)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00drivers/thunderbolt/tunnel.c +1
-0@@ -6,6 +6,7 @@* Copyright (C) 2019, Intel Corporation */ +#include <linux/delay.h> #include <linux/slab.h> #include <linux/list.h> @@ -242,6 +243,41 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,return tunnel; }
drivers/thunderbolt/tunnel.c struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up, · line 254
Quoted 10 lines
drivers/thunderbolt/tunnel.c +9
-0+static int tb_dp_cm_handshake (struct tb_port *in,struct tb_port *out) +{ +int timeout =10 ; +u32 val; +int ret; + +/* Both ends need to support this */ +if (!tb_switch_is_tr (in->sw) || !tb_switch_is_tr (out->sw)) +return 0 ;
So if the ends are both "Titan Ridge", matches your changelog text, but where is the "and newer" comment being checked here?
thanks,
greg k-h
Re: [RFC PATCH 12/22] thunderbolt: Add Display Port CM handshake for Titan Ridge devices
Quoted 41 lines · Greg Kroah-Hartman
Quoted 40 lines · Mika Westerberg
Titan Ridge devices and newer need an additional connection manager handshake in order to do proper Display Port tunneling so implement it here.
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/tb_regs.h | 3 +++ drivers/thunderbolt/tunnel.c | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)drivers/thunderbolt/tb_regs.h +3
-0@@ -252,6 +252,9 @@ struct tb_regs_port_header {#define ADP_DP_CS_3_HDPC BIT(9)#define DP_LOCAL_CAP 0x04#define DP_REMOTE_CAP 0x05 +#define DP_STATUS_CTRL 0x06 +#define DP_STATUS_CTRL_CMHS BIT(25) +#define DP_STATUS_CTRL_UF BIT(26)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00drivers/thunderbolt/tunnel.c +1
-0@@ -6,6 +6,7 @@* Copyright (C) 2019, Intel Corporation */ +#include <linux/delay.h> #include <linux/slab.h> #include <linux/list.h> @@ -242,6 +243,41 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,return tunnel; }
Quoted 12 lines
drivers/thunderbolt/tunnel.c struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up, · line 254
Quoted 9 lines
drivers/thunderbolt/tunnel.c +9
-0+static int tb_dp_cm_handshake (struct tb_port *in,struct tb_port *out) +{ +int timeout =10 ; +u32 val; +int ret; + +/* Both ends need to support this */ +if (!tb_switch_is_tr (in->sw) || !tb_switch_is_tr (out->sw)) +return 0 ;So if the ends are both "Titan Ridge", matches your changelog text, but where is the "and newer" comment being checked here?
By "and newer" I mean USB4 devices which are added in patch 17/22. I can update the changelog here to mention just Titan Ridge, though.
RFC PATCH 13/22 thunderbolt: Add Display Port adapter pairing and resource management
In reply to Mika WesterbergTo perform proper Display Port tunneling for Thunderbolt 3 devices we need to allocate DP resources for DP IN port before they can be used. The reason for this is that the user can also connect a monitor directly to the Type-C ports in which case the Thunderbolt controller acts as re-driver for Display Port (no tunneling takes place) taking the DP sinks away from the connection manager. This allocation is done using special sink allocation registers available through the link controller.
We can pair DP IN to DP OUT only if
* DP IN has sink allocated via link controller
* DP OUT port receives hotplug event
For DP IN adapters (only for the root switch) we first query whether there is DP resource available (it may be the previous instance of the driver for example already allocated it) and if it is we add it to the list. We then update the list when after each plug/unplug event to a DP IN/OUT adapter. Each time the list is updated we try to find additional DP IN <-> DP OUT pairs for tunnel establishment. This strategy also makes it possible to establish another tunnel in case there are 3 monitors connected and one gets unplugged releasing the DP IN adapter for the new tunnel.
--- drivers/thunderbolt/lc.c | 161 +++++++++++++++++++++++++++ drivers/thunderbolt/switch.c | 44 ++++++++ drivers/thunderbolt/tb.c | 203 ++++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 9 ++ drivers/thunderbolt/tb_regs.h | 6 + 5 files changed, 389 insertions(+), 34 deletions(-)
drivers/thunderbolt/lc.c +161 -0
@@ -205,3 +205,164 @@ bool tb_lc_lane_bonding_possible(struct tb_switch *sw)return !!(val &TB_LC_PORT_ATTR_BE ); } + +static int tb_lc_dp_sink_from_port (const struct tb_switch *sw, +struct tb_port *in) +{ +int i; + +/* The first DP IN port is sink 0 and second is sink 1 */ +tb_switch_for_each_port (sw, i) { +if (tb_port_is_dpin (&sw->ports[i])) +return in != &sw->ports[i]; + } + +return -EINVAL ; +} + +static int tb_lc_dp_sink_available (struct tb_switch *sw,int sink) +{ +u32 val, alloc; +int ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +/* +* Sink is available for CM/SW to use if the allocation valie is +* either 0 or 1. +*/ +if (!sink) { + alloc = val &TB_LC_SNK_ALLOCATION_SNK0_MASK ; +if (!alloc || alloc ==TB_LC_SNK_ALLOCATION_SNK0_CM ) +return 0 ; + }else { + alloc = (val &TB_LC_SNK_ALLOCATION_SNK1_MASK ) >> +TB_LC_SNK_ALLOCATION_SNK1_SHIFT ; +if (!alloc || alloc ==TB_LC_SNK_ALLOCATION_SNK1_CM ) +return 0 ; + } + +return -EBUSY ; +} + +/** +* tb_lc_dp_sink_query() - Is DP sink available for DP IN port +* @sw: Switch whose DP sink is queried +* @in: DP IN port to check +* +* Queries through LC SNK_ALLOCATION registers whether DP sink is available +* for the given DP IN port or not. +*/ +bool tb_lc_dp_sink_query (struct tb_switch *sw,struct tb_port *in) +{ +int sink; + +/* +* For older generations sink is always available as there is no +* allocation mechanism. +*/ +if (sw->generation <3 ) +return true; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return false; + +return !tb_lc_dp_sink_available (sw, sink); +} + +/** +* tb_lc_dp_sink_alloc() - Allocate DP sink +* @sw: Switch whose DP sink is allocated +* @in: DP IN port the DP sink is allocated for +* +* Allocate DP sink for @in via LC SNK_ALLOCATION registers. If the +* resource is available and allocation is successful returns %0. In all +* other cases returs negative errno. In particular %-EBUSY is returned if +* the resource was not available. +*/ +int tb_lc_dp_sink_alloc (struct tb_switch *sw,struct tb_port *in) +{ +int ret, sink; +u32 val; + +if (sw->generation <3 ) +return 0 ; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return sink; + + ret =tb_lc_dp_sink_available (sw, sink); +if (ret) +return ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +if (!sink) { + val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK ; + val |=TB_LC_SNK_ALLOCATION_SNK0_CM ; + }else { + val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK ; + val |=TB_LC_SNK_ALLOCATION_SNK1_CM << +TB_LC_SNK_ALLOCATION_SNK1_SHIFT ; + } + + ret =tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); + +if (ret) +return ret; + +tb_port_dbg (in,"sink %d allocated\n" , sink); +return 0 ; +} + +/** +* tb_lc_dp_sink_dealloc() - De-allocate DP sink +* @sw: Switch whose DP sink is de-allocated +* @in: DP IN port whose DP sink is de-allocated +* +* De-allocate DP sink from @in using LC SNK_ALLOCATION registers. +*/ +int tb_lc_dp_sink_dealloc (struct tb_switch *sw,struct tb_port *in) +{ +int ret, sink; +u32 val; + +if (sw->generation <3 ) +return 0 ; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return sink; + +/* Needs to be owned by CM/SW */ + ret =tb_lc_dp_sink_available (sw, sink); +if (ret) +return ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +if (!sink) + val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK ; +else + val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK ; + + ret =tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +tb_port_dbg (in,"sink %d de-allocated\n" , sink); +return 0 ; +}
drivers/thunderbolt/switch.c +44 -0
56 lines not on this page · raw message
drivers/thunderbolt/tb.c +169 -34
320 lines not on this page · raw message
drivers/thunderbolt/tb.h +9 -0
@@ -137,6 +137,7 @@ struct tb_switch {* @link_nr: Is this primary or secondary port on the dual_link. * @in_hopids: Currently allocated input HopIDs * @out_hopids: Currently allocated output HopIDs +* @list: Used to link ports to DP resources list */ struct tb_port {struct tb_regs_port_header config;
@@ -152,6 +153,7 @@ struct tb_port { u8 link_nr:1;struct ida in_hopids;struct ida out_hopids; +struct list_head list; };/**
@@ -674,6 +676,10 @@ static inline bool tb_switch_is_icm(const struct tb_switch *sw)int tb_switch_lane_bonding_enable (struct tb_switch *sw);void tb_switch_lane_bonding_disable (struct tb_switch *sw); +bool tb_switch_query_dp_resource (struct tb_switch *sw,struct tb_port *in); +int tb_switch_alloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +void tb_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
@@ -718,6 +724,9 @@ int tb_lc_configure_link(struct tb_switch *sw);void tb_lc_unconfigure_link (struct tb_switch *sw);int tb_lc_set_sleep (struct tb_switch *sw);bool tb_lc_lane_bonding_possible (struct tb_switch *sw); +bool tb_lc_dp_sink_query (struct tb_switch *sw,struct tb_port *in); +int tb_lc_dp_sink_alloc (struct tb_switch *sw,struct tb_port *in); +int tb_lc_dp_sink_dealloc (struct tb_switch *sw,struct tb_port *in);static inline int tb_route_length (u64 route) {
drivers/thunderbolt/tb_regs.h +6 -0
@@ -295,6 +295,12 @@ struct tb_regs_hop {#define TB_LC_DESC_PORT_SIZE_SHIFT 16#define TB_LC_DESC_PORT_SIZE_MASK GENMASK(27, 16)#define TB_LC_FUSE 0x03 +#define TB_LC_SNK_ALLOCATION 0x10 +#define TB_LC_SNK_ALLOCATION_SNK0_MASK GENMASK(3, 0) +#define TB_LC_SNK_ALLOCATION_SNK0_CM 0x1 +#define TB_LC_SNK_ALLOCATION_SNK1_SHIFT 4 +#define TB_LC_SNK_ALLOCATION_SNK1_MASK GENMASK(7, 4) +#define TB_LC_SNK_ALLOCATION_SNK1_CM 0x1/* Link controller registers */ #define TB_LC_PORT_ATTR 0x8d
Signature · 1 line
2.23.0
RFC PATCH 14/22 thunderbolt: Add bandwidth management for Display Port tunnels
In reply to Mika WesterbergThunderbolt 3 devices and especially Titan Ridge supports Display Port 1.4 which adds HBR3 (High Bit Rate) rates that may be up to 8.1 Gb/s over 4 lanes. This translates to effective data bandwidth of 25.92 Gb/s (as 8/10 encoding is removed by the DP adapters when going over Thunderbolt fabric). If another high rate monitor is connected we may need to reduce the bandwidth it consumes so that it fits into the total 40 Gb/s available on the Thunderbolt fabric.
--- drivers/thunderbolt/path.c | 22 +++ drivers/thunderbolt/tb.c | 52 ++++++- drivers/thunderbolt/tb.h | 2 + drivers/thunderbolt/tb_regs.h | 17 +++ drivers/thunderbolt/tunnel.c | 272 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 10 +- 6 files changed, 371 insertions(+), 4 deletions(-)
drivers/thunderbolt/path.c +22 -0
@@ -557,3 +557,25 @@ bool tb_path_is_invalid(struct tb_path *path) }return false; } + +/** +* tb_path_switch_on_path() - Does the path go through certain switch +* @path: Path to check +* @sw: Switch to check +* +* Goes over all hops on path and checks if @sw is any of them. +* Direction does not matter. +*/ +bool tb_path_switch_on_path (const struct tb_path *path, +const struct tb_switch *sw) +{ +int i; + +for (i =0 ; i < path->path_length; i++) { +if (path->hops[i].in_port->sw == sw || + path->hops[i].out_port->sw == sw) +return true; + } + +return false; +}
drivers/thunderbolt/tb.c +51 -1
69 lines not on this page · raw message
drivers/thunderbolt/tb.h +2 -0
@@ -715,6 +715,8 @@ void tb_path_free(struct tb_path *path);int tb_path_activate (struct tb_path *path);void tb_path_deactivate (struct tb_path *path);bool tb_path_is_invalid (struct tb_path *path); +bool tb_path_switch_on_path (const struct tb_path *path, +const struct tb_switch *sw);int tb_drom_read (struct tb_switch *sw);int tb_drom_read_uid_only (struct tb_switch *sw,u64 *uid);
drivers/thunderbolt/tb_regs.h +17 -0
@@ -255,6 +255,23 @@ struct tb_regs_port_header {#define DP_STATUS_CTRL 0x06#define DP_STATUS_CTRL_CMHS BIT(25)#define DP_STATUS_CTRL_UF BIT(26) +#define DP_COMMON_CAP 0x07 +/* +* DP_COMMON_CAP offsets work also for DP_LOCAL_CAP and DP_REMOTE_CAP +* with exception of DPRX done. +*/ +#define DP_COMMON_CAP_RATE_MASK GENMASK(11, 8) +#define DP_COMMON_CAP_RATE_SHIFT 8 +#define DP_COMMON_CAP_RATE_RBR 0x0 +#define DP_COMMON_CAP_RATE_HBR 0x1 +#define DP_COMMON_CAP_RATE_HBR2 0x2 +#define DP_COMMON_CAP_RATE_HBR3 0x3 +#define DP_COMMON_CAP_LANES_MASK GENMASK(14, 12) +#define DP_COMMON_CAP_LANES_SHIFT 12 +#define DP_COMMON_CAP_1_LANE 0x0 +#define DP_COMMON_CAP_2_LANES 0x1 +#define DP_COMMON_CAP_4_LANES 0x2 +#define DP_COMMON_CAP_DPRX_DONE BIT(31)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +270 -2
323 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +9 -1
@@ -27,8 +27,11 @@ enum tb_tunnel_type {* @npaths: Number of paths in @paths * @init: Optional tunnel specific initialization * @activate: Optional tunnel specific activation/deactivation +* @consumed_bandwidth: Return how much bandwidth the tunnel consumes * @list: Tunnels are linked using this field * @type: Type of the tunnel +* @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP). +* Only set if the bandwidth needs to be limited. */ struct tb_tunnel {struct tb *tb;
@@ -38,8 +41,10 @@ struct tb_tunnel {size_t npaths;int (*init)(struct tb_tunnel *tunnel);int (*activate)(struct tb_tunnel *tunnel,bool activate); +int (*consumed_bandwidth)(struct tb_tunnel *tunnel);struct list_head list;enum tb_tunnel_type type; +unsigned int max_bw; };struct tb_tunnel *tb_tunnel_discover_pci (struct tb *tb,struct tb_port *down);
@@ -47,7 +52,7 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up, struct tb_port *down);struct tb_tunnel *tb_tunnel_discover_dp (struct tb *tb,struct tb_port *in);struct tb_tunnel *tb_tunnel_alloc_dp (struct tb *tb,struct tb_port *in, -struct tb_port *out); +struct tb_port *out,int max_bw); struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, struct tb_port *dst, int transmit_ring, int transmit_path, int receive_ring,
@@ -58,6 +63,9 @@ int tb_tunnel_activate(struct tb_tunnel *tunnel);int tb_tunnel_restart (struct tb_tunnel *tunnel);void tb_tunnel_deactivate (struct tb_tunnel *tunnel);bool tb_tunnel_is_invalid (struct tb_tunnel *tunnel); +bool tb_tunnel_switch_on_path (const struct tb_tunnel *tunnel, +const struct tb_switch *sw); +int tb_tunnel_consumed_bandwidth (struct tb_tunnel *tunnel);static inline bool tb_tunnel_is_pci (const struct tb_tunnel *tunnel) {
Signature · 1 line
2.23.0
RFC PATCH 15/22 thunderbolt: Make tb_find_port() available to other files
In reply to Mika WesterbergWe will be needing this when adding initial USB4 support so make it available to other files in the driver as well. We also rename it to tb_switch_find_port() to follow conventions used in switch.c.
No functional changes.
--- drivers/thunderbolt/switch.c | 18 ++++++++++++++++++ drivers/thunderbolt/tb.c | 22 ++-------------------- drivers/thunderbolt/tb.h | 2 ++ 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/thunderbolt/switch.c +18 -0
@@ -2446,6 +2446,24 @@ struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route)return NULL ; } +/** +* tb_switch_find_port() - return the first port of @type on @sw or NULL +* @sw: Switch to find the port from +* @type: Port type to look for +*/ +struct tb_port *tb_switch_find_port (struct tb_switch *sw, +enum tb_port_type type) +{ +int i; + +tb_switch_for_each_port (sw, i) { +if (sw->ports[i].config.type == type) +return &sw->ports[i]; + } + +return NULL ; +} +void tb_switch_exit (void ) {ida_destroy (&nvm_ida);
drivers/thunderbolt/tb.c +2 -20
@@ -343,24 +343,6 @@ static void tb_free_unplugged_children(struct tb_switch *sw) } } -/** -* tb_find_port() - return the first port of @type on @sw or NULL -* @sw: Switch to find the port from -* @type: Port type to look for -*/ -static struct tb_port *tb_find_port (struct tb_switch *sw, -enum tb_port_type type) -{ -int i; - -tb_switch_for_each_port (sw, i) { -if (sw->ports[i].config.type == type) -return &sw->ports[i]; - } - -return NULL ; -} -/** * tb_find_unused_port() - return the first inactive port on @sw * @sw: Switch to find the port on
@@ -590,7 +572,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)struct tb_switch *parent_sw;struct tb_tunnel *tunnel; - up =tb_find_port (sw,TB_TYPE_PCIE_UP ); + up =tb_switch_find_port (sw,TB_TYPE_PCIE_UP );if (!up)return 0 ;
@@ -628,7 +610,7 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) sw =tb_to_switch (xd->dev.parent); dst_port =tb_port_at (xd->route, sw); - nhi_port =tb_find_port (tb->root_switch,TB_TYPE_NHI ); + nhi_port =tb_switch_find_port (tb->root_switch,TB_TYPE_NHI );mutex_lock (&tb->lock); tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, xd->transmit_ring,
drivers/thunderbolt/tb.h +2 -0
@@ -533,6 +533,8 @@ void tb_switch_suspend(struct tb_switch *sw);int tb_switch_resume (struct tb_switch *sw);int tb_switch_reset (struct tb *tb,u64 route);void tb_sw_set_unplugged (struct tb_switch *sw); +struct tb_port *tb_switch_find_port (struct tb_switch *sw, +enum tb_port_type type);struct tb_switch *tb_switch_find_by_link_depth (struct tb *tb,u8 link,u8 depth);struct tb_switch *tb_switch_find_by_uuid (struct tb *tb,const uuid_t *uuid);
Signature · 1 line
2.23.0
RFC PATCH 16/22 thunderbolt: Call tb_eeprom_get_drom_offset() from tb_eeprom_read_n()
In reply to Mika WesterbergWe are going to re-use tb_drom_read() for USB4 DROM reading as well. USB4 has separate router operations for this which does not need the drom_offset. Therefore we move call to tb_eeprom_get_drom_offset() into tb_eeprom_read_n() where it is needed.
While there change return -ENOSYS to -ENODEV because the former is only supposed to be used with system calls (invalid syscall nr).
--- drivers/thunderbolt/eeprom.c | 88 ++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 45 deletions(-)
drivers/thunderbolt/eeprom.c +43 -45
@@ -130,13 +130,52 @@ static int tb_eeprom_in(struct tb_switch *sw, u8 *val)return 0 ; } +/** +* tb_eeprom_get_drom_offset - get drom offset within eeprom +*/ +static int tb_eeprom_get_drom_offset (struct tb_switch *sw,u16 *offset) +{ +struct tb_cap_plug_events cap; +int res; + +if (!sw->cap_plug_events) { +tb_sw_warn (sw,"no TB_CAP_PLUG_EVENTS, cannot read eeprom\n" ); +return -ENODEV ; + } + res =tb_sw_read (sw, &cap,TB_CFG_SWITCH , sw->cap_plug_events, +sizeof (cap) /4 ); +if (res) +return res; + +if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) { +tb_sw_warn (sw,"no NVM\n" ); +return -ENODEV ; + } + +if (cap.drom_offset >0xffff ) { +tb_sw_warn (sw,"drom offset is larger than 0xffff: %#x\n" , + cap.drom_offset); +return -ENXIO ; + } + *offset = cap.drom_offset; +return 0 ; +} +/** * tb_eeprom_read_n - read count bytes from offset into val */ static int tb_eeprom_read_n (struct tb_switch *sw,u16 offset,u8 *val,size_t count) { +u16 drom_offset;int i, res; + + res =tb_eeprom_get_drom_offset (sw, &drom_offset); +if (res) +return res; + + offset += drom_offset; + res =tb_eeprom_active (sw, true);if (res)return res;
@@ -238,36 +277,6 @@ struct tb_drom_entry_port { } __packed; -/** -* tb_eeprom_get_drom_offset - get drom offset within eeprom -*/ -static int tb_eeprom_get_drom_offset (struct tb_switch *sw,u16 *offset) -{ -struct tb_cap_plug_events cap; -int res; -if (!sw->cap_plug_events) { -tb_sw_warn (sw,"no TB_CAP_PLUG_EVENTS, cannot read eeprom\n" ); -return -ENOSYS ; - } - res =tb_sw_read (sw, &cap,TB_CFG_SWITCH , sw->cap_plug_events, -sizeof (cap) /4 ); -if (res) -return res; - -if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) { -tb_sw_warn (sw,"no NVM\n" ); -return -ENOSYS ; - } - -if (cap.drom_offset >0xffff ) { -tb_sw_warn (sw,"drom offset is larger than 0xffff: %#x\n" , - cap.drom_offset); -return -ENXIO ; - } - *offset = cap.drom_offset; -return 0 ; -} -/** * tb_drom_read_uid_only - read uid directly from drom *
@@ -277,17 +286,11 @@ static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)int tb_drom_read_uid_only (struct tb_switch *sw,u64 *uid) {u8 data[9 ]; -u16 drom_offset;u8 crc; -int res =tb_eeprom_get_drom_offset (sw, &drom_offset); -if (res) -return res; - -if (drom_offset ==0 ) -return -ENODEV ; +int res;/* read uid */ - res =tb_eeprom_read_n (sw, drom_offset, data,9 ); + res =tb_eeprom_read_n (sw,0 , data,9 );if (res)return res;
@@ -489,7 +492,6 @@ static int tb_drom_copy_nvm(struct tb_switch *sw, u16 *size)*/ int tb_drom_read (struct tb_switch *sw) { -u16 drom_offset;u16 size;u32 crc;struct tb_drom_header *header;
@@ -517,11 +519,7 @@ int tb_drom_read(struct tb_switch *sw)return 0 ; } - res =tb_eeprom_get_drom_offset (sw, &drom_offset); -if (res) -return res; - - res =tb_eeprom_read_n (sw, drom_offset +14 , (u8 *) &size,2 ); + res =tb_eeprom_read_n (sw,14 , (u8 *) &size,2 );if (res)return res; size &=0x3ff ;
@@ -535,7 +533,7 @@ int tb_drom_read(struct tb_switch *sw) sw->drom =kzalloc (size,GFP_KERNEL );if (!sw->drom)return -ENOMEM ; - res =tb_eeprom_read_n (sw, drom_offset, sw->drom, size); + res =tb_eeprom_read_n (sw,0 , sw->drom, size);if (res) goto err;
Signature · 1 line
2.23.0
RFC PATCH 17/22 thunderbolt: Add initial support for USB4
In reply to Mika WesterbergUSB4 is a public spec based on Thunderbolt protocol. There are some differences in register layouts and flows. In addition to PCIe and DP tunneling, USB4 supports tunneling of USB 3.x. USB4 is also backward compatible with Thunderbolt 3 (and older generations but the spec only talks about 3rd generation). USB4 compliant devices can be identified by checking USB4 version field in router configuration space.
This patch adds initial support for USB4 compliant hosts and devices which enables following features provided by the existing functionality in the driver:
- PCIe tunneling
- Display Port tunneling
- Host and device NVM firmware upgrade
- P2P networking
This brings the USB4 support to the same level that we already have for Thunderbolt 1, 2 and 3 devices.
Note the spec talks about host and device "routers" but in the driver we still use term "switch" in most places. Both can be used interchangeably.
This also updates the Kconfig entry accordingly.
--- drivers/thunderbolt/Kconfig | 9 +- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/eeprom.c | 53 ++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/switch.c | 384 +++++++++++++----- drivers/thunderbolt/tb.c | 20 +- drivers/thunderbolt/tb.h | 36 ++ drivers/thunderbolt/tb_regs.h | 36 +- drivers/thunderbolt/tunnel.c | 10 +- drivers/thunderbolt/usb4.c | 722 ++++++++++++++++++++++++++++++++++ drivers/thunderbolt/xdomain.c | 6 + 12 files changed, 1162 insertions(+), 121 deletions(-) create mode 100644 drivers/thunderbolt/usb4.c
drivers/thunderbolt/Kconfig +5 -4
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only menuconfig THUNDERBOLT - tristate "Thunderbolt support" + tristate "USB4 (Thunderbolt) support" depends on PCI depends on X86 || COMPILE_TEST select APPLE_PROPERTIES if EFI_STUB && X86
@@ -9,9 +9,10 @@ menuconfig THUNDERBOLT select CRYPTO_HASH select NVMEM help - Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer. To compile this driver a module, choose M here. The module will be called thunderbolt.
drivers/thunderbolt/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-${CONFIG_THUNDERBOLT} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o
drivers/thunderbolt/eeprom.c +48 -5
75 lines not on this page · raw message
drivers/thunderbolt/nhi.c +3 -0
@@ -1271,6 +1271,9 @@ static struct pci_device_id nhi_ids[] = { { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICL_NHI1), .driver_data = (kernel_ulong_t)&icl_nhi_ops }, +/* Any USB4 compliant host */ + { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) }, + { 0,} };
drivers/thunderbolt/nhi.h +2 -0
@@ -74,4 +74,6 @@ extern const struct tb_nhi_ops icl_nhi_ops;#define PCI_DEVICE_ID_INTEL_ICL_NHI1 0x8a0d#define PCI_DEVICE_ID_INTEL_ICL_NHI0 0x8a17 +#define PCI_CLASS_SERIAL_USB_USB4 0x0c0340 +#endif
drivers/thunderbolt/switch.c +282 -102
611 lines not on this page · raw message
drivers/thunderbolt/tb.c +14 -6
@@ -370,12 +370,15 @@ static struct tb_port *tb_find_unused_port(struct tb_switch *sw,static struct tb_port *tb_find_pcie_down (struct tb_switch *sw,const struct tb_port *port) { +struct tb_port *down =NULL ; +/* * To keep plugging devices consistently in the same PCIe -* hierarchy, do mapping here for root switch downstream PCIe -* ports. +* hierarchy, do mapping here for switch downstream PCIe ports. */ -if (!tb_route (sw)) { +if (tb_switch_is_usb4 (sw)) { + down =usb4_switch_map_pcie_down (sw, port); + }else if (!tb_route (sw)) {int phy_port =tb_phy_port_from_link (port->port);int index;
@@ -395,12 +398,17 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,/* Validate the hard-coding */ if (WARN_ON (index > sw->config.max_port_number)) goto out; -if (WARN_ON (!tb_port_is_pcie_down (&sw->ports[index]))) + + down = &sw->ports[index]; + } + +if (down) { +if (WARN_ON (!tb_port_is_pcie_down (down))) goto out; -if (WARN_ON (tb_pci_port_is_enabled (&sw->ports[index]))) +if (WARN_ON (tb_pci_port_is_enabled (down))) goto out; -return &sw->ports[index]; +return down; } out:
drivers/thunderbolt/tb.h +36 -0
@@ -44,6 +44,7 @@ struct tb_switch_nvm {#define TB_SWITCH_KEY_SIZE 32#define TB_SWITCH_MAX_DEPTH 6 +#define USB4_SWITCH_MAX_DEPTH 5/** * struct tb_switch - a thunderbolt switch
@@ -129,6 +130,7 @@ struct tb_switch {* @xdomain: Remote host (%NULL if not connected) * @cap_phy: Offset, zero if not found * @cap_adap: Offset of the adapter specific capability (%0 if not present) +* @cap_usb4: Offset to the USB4 port capability (%0 if not present) * @port: Port number on switch * @disabled: Disabled by eeprom * @bonded: true if the port is bonded (two lanes combined as one)
@@ -146,6 +148,7 @@ struct tb_port {struct tb_xdomain *xdomain;int cap_phy;int cap_adap; +int cap_usb4;u8 port;bool disabled;bool bonded;
@@ -661,6 +664,17 @@ static inline bool tb_switch_is_tr(const struct tb_switch *sw) } } +/** +* tb_switch_is_usb4() - Is the switch USB4 compliant +* @sw: Switch to check +* +* Returns true if the @sw is USB4 compliant router, false otherwise. +*/ +static inline bool tb_switch_is_usb4 (const struct tb_switch *sw) +{ +return sw->config.thunderbolt_version ==USB4_VERSION_1_0 ; +} +/** * tb_switch_is_icm() - Is the switch handled by ICM firmware * @sw: Switch to check
@@ -686,6 +700,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);int tb_port_clear_counter (struct tb_port *port,int counter); +int tb_port_unlock (struct tb_port *port);int tb_port_alloc_in_hopid (struct tb_port *port,int hopid,int max_hopid);void tb_port_release_in_hopid (struct tb_port *port,int hopid);int tb_port_alloc_out_hopid (struct tb_port *port,int hopid,int max_hopid);
@@ -760,4 +775,25 @@ void tb_xdomain_remove(struct tb_xdomain *xd);struct tb_xdomain *tb_xdomain_find_by_link_depth (struct tb *tb,u8 link,u8 depth); +int usb4_switch_setup (struct tb_switch *sw); +int usb4_switch_read_uid (struct tb_switch *sw,u64 *uid); +int usb4_switch_drom_read (struct tb_switch *sw,unsigned int address,void *buf, +size_t size); +int usb4_switch_configure_link (struct tb_switch *sw); +void usb4_switch_unconfigure_link (struct tb_switch *sw); +bool usb4_switch_lane_bonding_possible (struct tb_switch *sw); +int usb4_switch_set_sleep (struct tb_switch *sw); +int usb4_switch_nvm_sector_size (struct tb_switch *sw); +int usb4_switch_nvm_read (struct tb_switch *sw,unsigned int address,void *buf, +size_t size); +int usb4_switch_nvm_write (struct tb_switch *sw,unsigned int address, +const void *buf,size_t size); +int usb4_switch_nvm_authenticate (struct tb_switch *sw); +bool usb4_switch_query_dp_resource (struct tb_switch *sw,struct tb_port *in); +int usb4_switch_alloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +int usb4_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +struct tb_port *usb4_switch_map_pcie_down (struct tb_switch *sw, +const struct tb_port *port); + +int usb4_port_unlock (struct tb_port *port);#endif
drivers/thunderbolt/tb_regs.h +35 -1
@@ -41,6 +41,7 @@ enum tb_port_cap {TB_PORT_CAP_TIME1 =0x03 ,TB_PORT_CAP_ADAP =0x04 ,TB_PORT_CAP_VSE =0x05 , + TB_PORT_CAP_USB4 = 0x06, }; enum tb_port_state {
@@ -164,10 +165,36 @@ struct tb_regs_switch_header {* milliseconds. Writing 0x00 is interpreted * as 255ms. */ - u32 __unknown4:16; + u32 cmuv:8; + u32 __unknown4:8; u32 thunderbolt_version:8; } __packed; +/* USB4 version 1.0 */ +#define USB4_VERSION_1_0 0x20 + +#define ROUTER_CS_1 0x01 +#define ROUTER_CS_4 0x04 +#define ROUTER_CS_5 0x05 +#define ROUTER_CS_5_SLP BIT(0) +#define ROUTER_CS_5_C3S BIT(23) +#define ROUTER_CS_5_PTO BIT(24) +#define ROUTER_CS_5_HCO BIT(26) +#define ROUTER_CS_5_CV BIT(31) +#define ROUTER_CS_6 0x06 +#define ROUTER_CS_6_SLPR BIT(0) +#define ROUTER_CS_6_TNS BIT(1) +#define ROUTER_CS_6_HCI BIT(18) +#define ROUTER_CS_6_CR BIT(25) +#define ROUTER_CS_7 0x07 +#define ROUTER_CS_9 0x09 +#define ROUTER_CS_25 0x19 +#define ROUTER_CS_26 0x1a +#define ROUTER_CS_26_STATUS_MASK GENMASK(29, 24) +#define ROUTER_CS_26_STATUS_SHIFT 24 +#define ROUTER_CS_26_ONS BIT(30) +#define ROUTER_CS_26_OV BIT(31) +enum tb_port_type {TB_TYPE_INACTIVE =0x000000 ,TB_TYPE_PORT =0x000001 ,
@@ -216,6 +243,7 @@ struct tb_regs_port_header {#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0)#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20)#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20 +#define ADP_CS_4_LCK BIT(31)#define ADP_CS_5 0x05#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22
@@ -237,6 +265,12 @@ struct tb_regs_port_header {#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20)#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20 +/* USB4 port registers */ +#define PORT_CS_18 0x12 +#define PORT_CS_18_BE BIT(8) +#define PORT_CS_19 0x13 +#define PORT_CS_19_PC BIT(3) +/* Display Port adapter registers */ #define ADP_DP_CS_0 0x00#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16)
drivers/thunderbolt/tunnel.c +8 -2
@@ -243,6 +243,12 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,return tunnel; } +static bool tb_dp_is_usb4 (const struct tb_switch *sw) +{ +/* Titan Ridge DP adapters need the same treatment as USB4 */ +return tb_switch_is_usb4 (sw) ||tb_switch_is_tr (sw); +} +static int tb_dp_cm_handshake (struct tb_port *in,struct tb_port *out) {int timeout =10 ;
@@ -250,7 +256,7 @@ static int tb_dp_cm_handshake(struct tb_port *in, struct tb_port *out)int ret;/* Both ends need to support this */ -if (!tb_switch_is_tr (in->sw) || !tb_switch_is_tr (out->sw)) +if (!tb_dp_is_usb4 (in->sw) || !tb_dp_is_usb4 (out->sw))return 0 ; ret = tb_port_read(out, &val, TB_CFG_PORT,
@@ -520,7 +526,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel)u32 val, rate =0 , lanes =0 ;int ret; -if (tb_switch_is_tr (sw)) { +if (tb_dp_is_usb4 (sw)) {int timeout =10 ;/*
drivers/thunderbolt/usb4.c new file +722 -0
722 lines not on this page · raw message
drivers/thunderbolt/xdomain.c +6 -0
@@ -1220,7 +1220,13 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent, u64 route, const uuid_t *local_uuid, const uuid_t *remote_uuid) { + struct tb_switch *parent_sw = tb_to_switch(parent);struct tb_xdomain *xd; +struct tb_port *down; + +/* Make sure the downstream domain is accessible */ + down =tb_port_at (route, parent_sw); +tb_port_unlock (down); xd =kzalloc (sizeof (*xd),GFP_KERNEL );if (!xd)
Signature · 1 line
2.23.0
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 56 lines · Mika Westerberg
USB4 is a public spec based on Thunderbolt protocol. There are some differences in register layouts and flows. In addition to PCIe and DP tunneling, USB4 supports tunneling of USB 3.x. USB4 is also backward compatible with Thunderbolt 3 (and older generations but the spec only talks about 3rd generation). USB4 compliant devices can be identified by checking USB4 version field in router configuration space.
This patch adds initial support for USB4 compliant hosts and devices which enables following features provided by the existing functionality in the driver:
- PCIe tunneling
- Display Port tunneling
- Host and device NVM firmware upgrade
- P2P networkingThis brings the USB4 support to the same level that we already have for Thunderbolt 1, 2 and 3 devices.
Note the spec talks about host and device "routers" but in the driver we still use term "switch" in most places. Both can be used interchangeably.
This also updates the
Kconfigentry accordingly.Co-developed-by Rajmohan Mani <[email protected]>Signed-off-by Rajmohan Mani <[email protected]>Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/Kconfig | 9 +- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/eeprom.c | 53 ++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/switch.c | 384 +++++++++++++----- drivers/thunderbolt/tb.c | 20 +- drivers/thunderbolt/tb.h | 36 ++ drivers/thunderbolt/tb_regs.h | 36 +- drivers/thunderbolt/tunnel.c | 10 +- drivers/thunderbolt/usb4.c | 722 ++++++++++++++++++++++++++++++++++ drivers/thunderbolt/xdomain.c | 6 + 12 files changed, 1162 insertions(+), 121 deletions(-) create mode 100644 drivers/thunderbolt/usb4.cdrivers/thunderbolt/Kconfig +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only menuconfig THUNDERBOLT - tristate "Thunderbolt support" + tristate "USB4 (Thunderbolt) support" depends on PCI depends on X86 || COMPILE_TEST select APPLE_PROPERTIES if EFI_STUB && X86
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 10 lines
drivers/thunderbolt/Kconfig +4
-3@@ -9,9 +9,10 @@ menuconfig THUNDERBOLT select CRYPTO_HASH select NVMEM help - Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.
Wait, did "old" thunderbolt just get re-branded as USB4?
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Shouldn't there just be a new USB4 option that only enables/builds the USB4 stuff if selected? Why would I want all of this additional code on my old system if it's not going to do anything at all?
Or am I confused?
thanks,
greg k-h
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the Kconfig option tries to have both names there:
tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the Kconfig option is still CONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
Quoted 3 lines
Shouldn't there just be a new USB4 option that only enables/builds the USB4 stuff if selected? Why would I want all of this additional code on my old system if it's not going to do anything at all?
USB4 devices are backward compatible with Thunderbolt 3 so you should be able to plug in USB4 device to your old Thunderbolt 3 laptop for example. It goes the other way as well. Some things are optional but for example USB4 hubs must support also Thunderbolt 3.
Does that clarify?
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the Kconfig option as well, otherwise no one will "know" that this changed, so they will not be prompted for it.
Quoted 9 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
Quoted 8 lines
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
CONFIG_USB4 instead?
Quoted 10 lines
Quoted 3 lines
Shouldn't there just be a new USB4 option that only enables/builds the USB4 stuff if selected? Why would I want all of this additional code on my old system if it's not going to do anything at all?
USB4 devices are backward compatible with Thunderbolt 3 so you should be able to plug in USB4 device to your old Thunderbolt 3 laptop for example. It goes the other way as well. Some things are optional but for example USB4 hubs must support also Thunderbolt 3.
Does that clarify?
Yes, it does, looks like marketing just renamed an old functioning system into a "brand new one!" :)
thanks,
greg k-h
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 50 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, October 1, 2019 9:54 AM
To: Mika Westerberg
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 14 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
Quoted 5 lines
Quoted 3 lines
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
CONFIG_USB4instead?
How about CONFIG_USB4_PCIE?
I think that will help align that certain aspects of USB4 can be built optionally.
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Shouldn't there just be a new USB4 option that only enables/builds the USB4 stuff if selected? Why would I want all of this additional code on my old system if it's not going to do anything at all?
USB4 devices are backward compatible with Thunderbolt 3 so you should be able to plug in USB4 device to your old Thunderbolt 3 laptop for example. It goes the other way as well. Some things are optional but for example USB4 hubs must support also Thunderbolt 3.
If PCIe tunnels are an optional feature in USB4, how can it be mandatory to support Thunderbolt 3?
Quoted 8 lines
Quoted 1 line
Does that clarify?
Yes, it does, looks like marketing just renamed an old functioning system into a "brand new one!" :)
thanks,
greg k-h
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 54 lines · On Tue, Oct 01, 2019 at 02:59:06PM +0000, [email protected] wrote:
Quoted 54 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, October 1, 2019 9:54 AM
To: Mika Westerberg
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 17 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
Quoted 5 lines
Quoted 1 line
CONFIG_USB4instead?How about
CONFIG_USB4_PCIE?I think that will help align that certain aspects of USB4 can be built optionally.
But this is not about PCIe - it is just one type of a tunnel that is optional with USB4.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Shouldn't there just be a new USB4 option that only enables/builds the USB4 stuff if selected? Why would I want all of this additional code on my old system if it's not going to do anything at all?
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
USB4 devices are backward compatible with Thunderbolt 3 so you should be able to plug in USB4 device to your old Thunderbolt 3 laptop for example. It goes the other way as well. Some things are optional but for example USB4 hubs must support also Thunderbolt 3.
If PCIe tunnels are an optional feature in USB4, how can it be mandatory to support Thunderbolt 3?
It is mandatory for USB4 hubs. For peripheral devices and hosts Thunderbolt 3 support is optional. So for example you could have USB4 host that does not enter Thunderbolt 3 alternate mode at all so it only supports USB4 devices.
Greg KH
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to [email protected]Quoted 54 lines · On Tue, Oct 01, 2019 at 02:59:06PM +0000, [email protected] wrote:
Quoted 54 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, October 1, 2019 9:54 AM
To: Mika Westerberg
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 17 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
Quoted 5 lines
Quoted 1 line
CONFIG_USB4instead?How about
CONFIG_USB4_PCIE?I think that will help align that certain aspects of USB4 can be built optionally.
What aspects? We don't have that here at all.
I guess the parts of USB4 that are not just this "hook up the PCIe lane" that need to still be developed?
thanks,
greg k-h
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 57 lines · Greg KH
Quoted 56 lines · On Tue, Oct 01, 2019 at 02:59:06PM +0000, [email protected] wrote:
Quoted 55 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, October 1, 2019 9:54 AM
To: Mika Westerberg
Cc: [email protected]; Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 9 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
Quoted 8 lines
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
CONFIG_USB4instead?
Quoted 8 lines
Quoted 3 lines
How about
CONFIG_USB4_PCIE?I think that will help align that certain aspects of USB4 can be built optionally.
What aspects? We don't have that here at all.
I guess the parts of USB4 that are not just this "hook up the PCIe lane" that need to still be developed?
Actually PCIe tunneling is already there in the driver. USB4 has one bit that is needed to be set before PCIe tunneling can happen (we do that in patch 17/22) but other than that the existing PCIe tunneling code in the driver works as is.
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to Greg Kroah-HartmanQuoted 36 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 14 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
Quoted 5 lines
Quoted 3 lines
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
CONFIG_USB4instead?
OK, but does that break existing .configs? I mean if you have already CONFIG_THUNDERBOLT in your .config/defconfig does it now just get dropped silently?
For example firewire has CONFIG_FIREWIRE even though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/Thunderbolt?
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 41 lines · Mika Westerberg
Quoted 40 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 17 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
Quoted 5 lines
Quoted 1 line
CONFIG_USB4instead?OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?
Yup. And then you get asked about CONFIG_USB4
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/Thunderbolt?
It comes down to the what do you want to do for the next 20+ years, explain to people that "to get USB4 support, enable CONFIG_THUNDERBOLT"?
:)
thanks,
greg k-h
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 42 lines · Greg Kroah-Hartman
Quoted 41 lines · Mika Westerberg
Quoted 40 lines · Greg Kroah-Hartman
Quoted 11 lines · Mika Westerberg
Quoted 9 lines · Greg Kroah-Hartman
drivers/thunderbolt/Kconfig menuconfig THUNDERBOLT · line 15
Quoted 7 lines
drivers/thunderbolt/Kconfig +4
-3- Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4 (Thunderbolt) driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple + hardware or on PCs with Intel Falcon Ridge or newer.Wait, did "old" thunderbolt just get re-branded as USB4?
Quoted 6 lines
Not but the driver started supporting USB4 as well :)
USB4 is pretty much public spec of Thunderbolt 3 but with some differences in register layouts (this is because Thunderbolt uses some vendor specific capabilities which are now moved to more "standard" places).
Ok, then we need to rename the
Kconfigoption as well, otherwise no one will "know" that this changed, so they will not be prompted for it.Quoted 17 lines
Quoted 2 lines
Because if I have an "old" laptop that needs Thunderbolt support, how am I going to know it is now called USB4 instead?
Well the
Kconfigoption tries to have both names there:tristate "USB4 (Thunderbolt) support"
and then
USB4 (Thunderbolt) driver. USB4 is the public spec based on Thunderbolt 3 protocol. This driver is required if you want to hotplug Thunderbolt and USB4 compliant devices on Apple hardware or on PCs with Intel Falcon Ridge or newer.
and the
Kconfigoption is stillCONFIG_THUNDERBOLT. I know this is confusing but I don't have better ideas how we can advertise both. I borrowed this "format" from firewire.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
CONFIG_USB4instead?OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?Yup. And then you get asked about
CONFIG_USB4
I see.
Quoted 6 lines
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/Thunderbolt?It comes down to the what do you want to do for the next 20+ years, explain to people that "to get USB4 support, enable
CONFIG_THUNDERBOLT"?
That's a very good point indeed :)
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to Mika WesterbergAm Dienstag, den 01.10.2019, 18:07 +0300 schrieb Mika Westerberg:
Hi,
Quoted 3 lines
OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?
People will have to look at this new stuff anyway.
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/Thunderbolt
USB and Thunderbolt used to be distinct protocols. Whereas Firewire was just a colloquial name for IEEE1394. Please be wordy here. "Unified support for USB4 and Thunderbolt4"
Regards
Oliver
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 10 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 18:07 +0300 schrieb Mika Westerberg:
Hi,
Quoted 3 lines
OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?People will have to look at this new stuff anyway.
Quoted 7 lines
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/ThunderboltUSB and Thunderbolt used to be distinct protocols. Whereas Firewire was just a colloquial name for IEEE1394. Please be wordy here. "Unified support for USB4 and Thunderbolt4"
OK.
I've been thinking this bit more and since Thunderbolt will stick around as well (it basically implements all the optional USB4 features and more) so would it make sense to have the Kconfig option be CONFIG_THUNDERBOLT_USB4 (or CONFIG_USB4_THUNDERBOLT)? That should cover both.
Comments?
Also does anyone have any thoughts about keeping the driver under drivers/thunderbolt vs. moving it under usb like drivers/usb/thunderbolt? I'm thinking if anyone not familiar with this tries to enable support for USB4 so the first place he/she probably looks is under "USB support" menuconfig entry.
Greg Kroah-Hartman
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 19 lines · Mika Westerberg
Quoted 10 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 18:07 +0300 schrieb Mika Westerberg:
Hi,
Quoted 3 lines
OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?People will have to look at this new stuff anyway.
Quoted 7 lines
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/ThunderboltUSB and Thunderbolt used to be distinct protocols. Whereas Firewire was just a colloquial name for IEEE1394. Please be wordy here. "Unified support for USB4 and Thunderbolt4"
Quoted 7 lines
OK.
I've been thinking this bit more and since Thunderbolt will stick around as well (it basically implements all the optional USB4 features and more) so would it make sense to have the
Kconfigoption beCONFIG_THUNDERBOLT_USB4(orCONFIG_USB4_THUNDERBOLT)? That should cover both.
I would stick with CONFIG_USB4 but put both in the Kconfig text. Again, it will be easier to handle this over time.
Quoted 7 lines
Comments?
Also does anyone have any thoughts about keeping the driver under
drivers/thunderboltvs. moving it under usb likedrivers/usb/thunderbolt? I'm thinking if anyone not familiar with this tries to enable support for USB4 so the first place he/she probably looks is under "USB support" menuconfig entry.
You are not sharing/needing any of the drivers/usb/ code just yet, right? I imagine that will happen "soon" and when it does, then sure, moving stuff is fine with me.
thanks,
greg k-h
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 22 lines · Greg Kroah-Hartman
Quoted 21 lines · Mika Westerberg
Quoted 10 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 18:07 +0300 schrieb Mika Westerberg:
Hi,
Quoted 3 lines
OK, but does that break existing .configs? I mean if you have already
CONFIG_THUNDERBOLTin your .config/defconfig does it now just get dropped silently?People will have to look at this new stuff anyway.
Quoted 7 lines
Quoted 3 lines
For example firewire has
CONFIG_FIREWIREeven though the "standard" name is IEEE 1394. I was thinking maybe we can do the same for USB4/ThunderboltUSB and Thunderbolt used to be distinct protocols. Whereas Firewire was just a colloquial name for IEEE1394. Please be wordy here. "Unified support for USB4 and Thunderbolt4"
OK.
Quoted 8 lines
Quoted 5 lines
I've been thinking this bit more and since Thunderbolt will stick around as well (it basically implements all the optional USB4 features and more) so would it make sense to have the
Kconfigoption beCONFIG_THUNDERBOLT_USB4(orCONFIG_USB4_THUNDERBOLT)? That should cover both.I would stick with
CONFIG_USB4but put both in theKconfigtext. Again, it will be easier to handle this over time.
OK, thanks Greg!
Quoted 10 lines
Quoted 7 lines
Comments?
Also does anyone have any thoughts about keeping the driver under
drivers/thunderboltvs. moving it under usb likedrivers/usb/thunderbolt? I'm thinking if anyone not familiar with this tries to enable support for USB4 so the first place he/she probably looks is under "USB support" menuconfig entry.You are not sharing/needing any of the
drivers/usb/code just yet, right?
Yes, that's correct.
Quoted 2 lines
I imagine that will happen "soon" and when it does, then sure, moving stuff is fine with me.
OK thanks!
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to Mika WesterbergQuoted 11 lines
drivers/thunderbolt/switch.c +4
-1@@ -322,9 +398,21 @@ static int tb_switch_nvm_add(struct tb_switch *sw)u32 val;int ret; -if (!sw->dma_port) +if (!nvm_readable (sw))return 0 ; +/* +* The NVM format of non-Intel hardware is not known so +* currently restrict NVM upgrade for Intel hardware. We may
drivers/thunderbolt/switch.c static int tb_switch_nvm_add(struct tb_switch *sw) · line 416
Quoted 10 lines
drivers/thunderbolt/switch.c +9
-0+* relax this in the future when we learn other NVM formats. +*/ +if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL ) { +dev_info (&sw->dev, +"NVM format of vendor %#x is not known, disabling NVM upgrade\n", + sw->config.vendor_id); +return 0 ; + } +
Don't you actually have an attribute you can use here for this exact purpose that you could be setting rather than returning immediately?sw->no_nvm_upgrade
Then potentially you can at least let users "dump out" the nvm on !Intel but don't let it be written until ready to relax further.
Quoted 3 lines
drivers/thunderbolt/switch.c +0
-0nvm =kzalloc (sizeof (*nvm),GFP_KERNEL );if (!nvm)return
-ENOMEM;
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 27 lines
-----Original Message-----
From: Limonciello, Mario
Sent: Tuesday, October 1, 2019 12:05 PM
To: 'Mika Westerberg'; [email protected]
Cc: Andreas Noever; Michael Jamet; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Anthony Wong; linux- [email protected]
Subject: RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4Quoted 18 lines
drivers/thunderbolt/switch.c +10
-1@@ -322,9 +398,21 @@ static int tb_switch_nvm_add(struct tb_switch *sw)u32 val;int ret; -if (!sw->dma_port) +if (!nvm_readable (sw))return 0 ; +/* +* The NVM format of non-Intel hardware is not known so +* currently restrict NVM upgrade for Intel hardware. We may +* relax this in the future when we learn other NVM formats. +*/ +if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL ) { +dev_info (&sw->dev, +"NVM format of vendor %#x is not known, disabling NVM upgrade\n", + sw->config.vendor_id);
Quoted 9 lines
drivers/thunderbolt/switch.c static int tb_switch_nvm_add(struct tb_switch *sw) · line 415
Quoted 3 lines
drivers/thunderbolt/switch.c +3
-0+return 0 ; + } +Don't you actually have an attribute you can use here for this exact purpose that you
could be setting rather than returning immediately?sw->no_nvm_upgrade
One more thought; would you consider exporting to sysfs sw->config.vendor_id? Maybe an attribute that is switch_vendor?
Userland fwupd also does validation on the NVM and will need to follow this. The same check will go into fwupd to match the vendor and lack of nvm_non_active0 to mark the device as not updatable. When the checks in the kernel get relaxed, some NVM parsing will have to make it over to fwupd too to relax the check at that point.
Quoted 7 lines
Then potentially you can at least let users "dump out" the nvm on !Intel but don't let
it be written until ready to relax further.Quoted 3 lines
drivers/thunderbolt/switch.c +0
-0nvm =kzalloc (sizeof (*nvm),GFP_KERNEL );if (!nvm)return
-ENOMEM;
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 7 lines · On Tue, Oct 01, 2019 at 06:14:23PM +0000, [email protected] wrote:
One more thought; would you consider exporting to sysfs
sw->config.vendor_id? Maybe an attribute that isswitch_vendor?Userland fwupd also does validation on the NVM and will need to follow this. The same check will go into fwupd to match the vendor and lack of
nvm_non_active0to mark the device as not updatable. When the checks in the kernel get relaxed, some NVM parsing will have to make it over to fwupd too to relax the check at that point.
The original idea was that the kernel does the basic validation and userspace then does more complex checks. Currently you can compare the two NVM images (active one and the new) and find that information there. I think fwupd is doing just that already. Is that not enough?
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 23 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, October 2, 2019 3:39 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 6 lines · On Tue, Oct 01, 2019 at 06:14:23PM +0000, [email protected] wrote:
One more thought; would you consider exporting to sysfs sw- config.vendor_id?
Maybe an attribute that isswitch_vendor?Userland fwupd also does validation on the NVM and will need to follow this. The same check will go into fwupd to match the vendor and lack of
nvm_non_active0Quoted 1 line
to mark the device as not updatable. When the checks in the kernel get
Quoted 8 lines
relaxed,
Quoted 1 line
some NVM parsing will have to make it over to fwupd too to relax the check at
that point.
The original idea was that the kernel does the basic validation and userspace then does more complex checks. Currently you can compare the two NVM images (active one and the new) and find that information there. I think fwupd is doing just that already. Is that not enough?
I guess for fwupd we can do this without the extra attribute:
1) If no NVM files or nvm_version: means unsupported vendor -show that messaging somewhere. This means kernel doesn't know the vendor.
2) If NVM file and nvm_version: means kernel knows it
*fwupd checks the vendor offset for intel.
-> intel: good, proceed
->something else: fwupd needs to learn the format for the new vendor, show messaging
There is the unlikely case that kernel knows new vendor format and vendor NVM happened to have same value as Intel vendor ID in same location of Intel NVM but another meaning. Hopefully that doesn't happen :)
Yehezkel Bernat
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 38 lines · On Wed, Oct 2, 2019 at 6:09 PM <[email protected]> wrote:
Quoted 24 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, October 2, 2019 3:39 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 6 lines · On Tue, Oct 01, 2019 at 06:14:23PM +0000, [email protected] wrote:
One more thought; would you consider exporting to sysfs sw- config.vendor_id?
Maybe an attribute that isswitch_vendor?Userland fwupd also does validation on the NVM and will need to follow this. The same check will go into fwupd to match the vendor and lack of
nvm_non_active0Quoted 1 line
to mark the device as not updatable. When the checks in the kernel get
Quoted 8 lines
relaxed,
Quoted 1 line
some NVM parsing will have to make it over to fwupd too to relax the check at
that point.
The original idea was that the kernel does the basic validation and userspace then does more complex checks. Currently you can compare the two NVM images (active one and the new) and find that information there. I think fwupd is doing just that already. Is that not enough?
I guess for fwupd we can do this without the extra attribute:
1) If no NVM files or
nvm_version: means unsupported vendor -show that messaging somewhere. This means kernel doesn't know the vendor.
Quoted 8 lines
2) If NVM file and
nvm_version: means kernel knows it
*fwupd checks the vendor offset for intel.
-> intel: good, proceed
->something else: fwupd needs to learn the format for the new vendor, show messagingThere is the unlikely case that kernel knows new vendor format and vendor NVM happened to have same value as Intel vendor ID in same location of Intel NVM but another meaning. Hopefully that doesn't happen :)
It's not even "same location - another meaning", the vendor ID comes from the DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation in a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 69 lines
-----Original Message-----
From: Yehezkel Bernat <[email protected]>
Sent: Wednesday, October 2, 2019 10:37 AM
To: Limonciello, Mario
Cc: Mika Westerberg; [email protected]; Andreas Noever; Michael Jamet; Rajmohan Mani; [email protected]; Lukas Wunner; [email protected]; [email protected]; Anthony Wong; LKML
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 7 lines · On Wed, Oct 2, 2019 at 6:09 PM <[email protected]> wrote:
Quoted 7 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, October 2, 2019 3:39 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected];Quoted 9 lines
Quoted 9 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
On Tue, Oct 01, 2019 at 06:14:23PM +0000, [email protected]
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
One more thought; would you consider exporting to sysfs sw- config.vendor_id?
Maybe an attribute that isswitch_vendor?Userland fwupd also does validation on the NVM and will need to follow
this.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
The same check will go into fwupd to match the vendor and lack of
nvm_non_active0Quoted 1 line
to mark the device as not updatable. When the checks in the kernel get
relaxed,
Quoted 1 line
some NVM parsing will have to make it over to fwupd too to relax the check
at
Quoted 10 lines
Quoted 6 lines
that point.
The original idea was that the kernel does the basic validation and userspace then does more complex checks. Currently you can compare the two NVM images (active one and the new) and find that information there. I think fwupd is doing just that already. Is that not enough?
I guess for fwupd we can do this without the extra attribute:
1) If no NVM files or
nvm_version: means unsupported vendor -show thatmessaging somewhere.
Quoted 6 lines
This means kernel doesn't know the vendor.
2) If NVM file and
nvm_version: means kernel knows it
*fwupd checks the vendor offset for intel.
-> intel: good, proceed
->something else: fwupd needs to learn the format for the new vendor, showmessaging
Quoted 2 lines
There is the unlikely case that kernel knows new vendor format and vendor
NVM happened to have
Quoted 1 line
same value as Intel vendor ID in same location of Intel NVM but another
meaning.
Quoted 1 line
Hopefully that doesn't happen :)
Quoted 7 lines
It's not even "same location - another meaning", the vendor ID comes from the DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation in a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
And now I remember why the back of my mind was having this thought of wanting sysfs attribute in the first place. The multiple jumps means that a lot more of the NVM has to be dumped to get that data, which slows down fwupd startup significantly. However the kernel has this information handy already from thunderbolt init and can easily export an attribute which can then come from udev with no startup penalty.
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 11 lines · On Wed, Oct 02, 2019 at 04:00:55PM +0000, [email protected] wrote:
Quoted 7 lines
It's not even "same location - another meaning", the vendor ID comes from the DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation in a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
And now I remember why the back of my mind was having this thought of wanting sysfs attribute in the first place. The multiple jumps means that a lot more of the NVM has to be dumped to get that data, which slows down fwupd startup significantly.
IIRC currently fwupd does two reads of total 128 bytes from the active NVM. Is that really slowing down fwupd startup significantly?
Quoted 2 lines
However the kernel has this information handy already from thunderbolt init and can easily export an attribute which can then come from udev with no startup penalty.
Indeed kernel has this information but I'm bit hesitant to add new attributes if that same information is already available to the userspace rather easily. IMHO we can always add this to the driver later as we learn new NVM formats that require more parsing from fwupd side slowing it down considerably.
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 26 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Thursday, October 3, 2019 3:00 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 1 line · On Wed, Oct 02, 2019 at 04:00:55PM +0000, [email protected] wrote:
Quoted 1 line
It's not even "same location - another meaning", the vendor ID comes from
the
Quoted 4 lines
Quoted 4 lines
DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation
in
Quoted 4 lines
Quoted 2 lines
a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
And now I remember why the back of my mind was having this thought of
Quoted 8 lines
wanting
Quoted 1 line
sysfs attribute in the first place. The multiple jumps means that a lot more of
the
Quoted 1 line
NVM has to be dumped to get that data, which slows down fwupd startup
significantly.
IIRC currently fwupd does two reads of total 128 bytes from the active NVM. Is that really slowing down fwupd startup significantly?
Yeah, I timed it with fwupd. Here's the averages:
Without doing the reads to jump to this it's 0:00.06 seconds to probe a tree of Host controller and dock plugged in.
With doing the reads and just host controller:
0:04.40 seconds
With doing the reads and host controller and dock plugged in:
0:10.73 seconds
Quoted 11 lines
Quoted 2 lines
However the kernel has this information handy already from thunderbolt init
and can
Quoted 1 line
easily export an attribute which can then come from udev with no startup
penalty.
Indeed kernel has this information but I'm bit hesitant to add new attributes if that same information is already available to the userspace rather easily. IMHO we can always add this to the driver later as we learn new NVM formats that require more parsing from fwupd side slowing it down considerably.
I guess we can wait until new NVM formats come and cross the bridge at that point. If we encounter a new NVM format that kernel recognizes but old fwupd doesn't it will reject it anyway (just the error won't be super clear why).
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 37 lines · On Thu, Oct 03, 2019 at 02:41:11PM +0000, [email protected] wrote:
Quoted 26 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Thursday, October 3, 2019 3:00 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 1 line · On Wed, Oct 02, 2019 at 04:00:55PM +0000, [email protected] wrote:
Quoted 1 line
It's not even "same location - another meaning", the vendor ID comes from
the
Quoted 4 lines
Quoted 4 lines
DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation
in
Quoted 4 lines
Quoted 2 lines
a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
And now I remember why the back of my mind was having this thought of
Quoted 8 lines
wanting
Quoted 1 line
sysfs attribute in the first place. The multiple jumps means that a lot more of
the
Quoted 1 line
NVM has to be dumped to get that data, which slows down fwupd startup
significantly.
IIRC currently fwupd does two reads of total 128 bytes from the active NVM. Is that really slowing down fwupd startup significantly?
Yeah, I timed it with fwupd. Here's the averages:
Quoted 8 lines
Without doing the reads to jump to this it's 0:00.06 seconds to probe a tree of Host controller and dock plugged in.
With doing the reads and just host controller:
0:04.40 secondsWith doing the reads and host controller and dock plugged in:
0:10.73 seconds
OK, it clearly takes time to read them. I wonder if this includes powering up the controller?
Also if you can get the hw_vendor_id and hw_product_id from the kernel does that mean you don't need to do the two reads or you still need those?
Yehezkel Bernat
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 48 lines · Mika Westerberg
Quoted 37 lines · On Thu, Oct 03, 2019 at 02:41:11PM +0000, [email protected] wrote:
Quoted 26 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Thursday, October 3, 2019 3:00 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 1 line · On Wed, Oct 02, 2019 at 04:00:55PM +0000, [email protected] wrote:
Quoted 1 line
It's not even "same location - another meaning", the vendor ID comes from
the
Quoted 4 lines
Quoted 4 lines
DROM section, so it takes a few internal jumps inside the NVM to find the location. One of the "pointers" or section headers will be broken for sure.
And after this, we need to find the NVM in LVFS and it has to pass validation
in
Quoted 4 lines
Quoted 2 lines
a few other locations. The chances are so low that I'd think it isn't worth worrying about it.
And now I remember why the back of my mind was having this thought of
Quoted 8 lines
wanting
Quoted 1 line
sysfs attribute in the first place. The multiple jumps means that a lot more of
the
Quoted 1 line
NVM has to be dumped to get that data, which slows down fwupd startup
significantly.
IIRC currently fwupd does two reads of total 128 bytes from the active NVM. Is that really slowing down fwupd startup significantly?
Yeah, I timed it with fwupd. Here's the averages:
Quoted 8 lines
Without doing the reads to jump to this it's 0:00.06 seconds to probe a tree of Host controller and dock plugged in.
With doing the reads and just host controller:
0:04.40 secondsWith doing the reads and host controller and dock plugged in:
0:10.73 seconds
Quoted 6 lines
OK, it clearly takes time to read them. I wonder if this includes powering up the controller?
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?
Are those the chip vendor or the OEM, in case they are different?
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 5 lines · Yehezkel Bernat
Quoted 3 lines
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?Are those the chip vendor or the OEM, in case they are different?
Those are the actual USB4 hardware maker values, directly from ROUTER_CS_0 (p. 287 in the USB4 spec). This almost certainly differ from the OEM values from DROM we currently expose.
Quoted 2 lines
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
So the bottom line is that if the kernel thinks the router supports NVM upgrade it exposes the nvm_active/nvm_non_active files etc. I think fwupd uses this information to display user whether the device can be upgraded or not (for example ICL cannot as the NVM is part of BIOS).
Exposing hw_vendor_id and hw_product_id may speed up fwupd because it does not need to go over the active NVM to figure out whether the new image is for the correct controller.
Yehezkel Bernat
maintainerRe: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 11 lines · Mika Westerberg
Quoted 5 lines · Yehezkel Bernat
Quoted 3 lines
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?Are those the chip vendor or the OEM, in case they are different?
Those are the actual USB4 hardware maker values, directly from
ROUTER_CS_0(p. 287 in the USB4 spec). This almost certainly differ from the OEM values from DROM we currently expose.
Makes sense to me. Userspace can learn the relevant IDs that their NVM format is known.
Quoted 8 lines
Quoted 3 lines
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
So the bottom line is that if the kernel thinks the router supports NVM upgrade it exposes the nvm_active/nvm_non_active files etc. I think fwupd uses this information to display user whether the device can be upgraded or not (for example ICL cannot as the NVM is part of BIOS).
Yes, fwupd already takes this into account, but the question here is how to handle cases that NVM is available but the format isn't known to userspace (yet).
Quoted 4 lines
Exposing
hw_vendor_idandhw_product_idmay speed up fwupd because it does not need to go over the active NVM to figure out whether the new image is for the correct controller.
It's not about finding the relevant image for upgrade (which must be searched for by looking in the DROM vendor/product values), but about the question if the NVM format is known to userspace and skip the parsing work if it's anyway going to fail.
So yes, I think exposing vendor ID (and maybe also product ID) can improve the situation.
Thanks!
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 23 lines
Quoted 11 lines · Mika Westerberg
Quoted 5 lines · Yehezkel Bernat
Quoted 3 lines
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?Are those the chip vendor or the OEM, in case they are different?
Those are the actual USB4 hardware maker values, directly from
ROUTER_CS_0(p. 287 in the USB4 spec). This almost certainly differ from the OEM values from DROM we currently expose.Makes sense to me. Userspace can learn the relevant IDs that their NVM format is
known.Quoted 4 lines
Quoted 3 lines
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
Quoted 8 lines
Quoted 4 lines
So the bottom line is that if the kernel thinks the router supports NVM upgrade it exposes the nvm_active/nvm_non_active files etc. I think fwupd uses this information to display user whether the device can be upgraded or not (for example ICL cannot as the NVM is part of BIOS).
Yes, fwupd already takes this into account, but the question here is how to handle cases that NVM is available but the format isn't known to userspace (yet).
Exactly.
Quoted 6 lines
Quoted 5 lines
Exposing
hw_vendor_idandhw_product_idmay speed up fwupd because it does not need to go over the active NVM to figure out whether the new image is for the correct controller.
Quoted 8 lines
It's not about finding the relevant image for upgrade (which must be searched for by looking in the DROM vendor/product values), but about the question if the NVM format is known to userspace and skip the parsing work if it's anyway going to fail.
So yes, I think exposing vendor ID (and maybe also product ID) can improve the situation.
Currently at probe time everything comes from udev except for the bit indicating running in "native" mode or not. Just enough chunks of the NVM are read to determine that (IE no reading up through DROM or jumping around).
If Christian's patch to export generation is accepted I think that we could move that check to only read -native if generation < 3.
And if you export the hw_vendor_id and hw_product_id fields then that means USB4 devices would require no reading from NVM at "probe" since we don't have to read a -native bit.
We would still of course read and analyze the NVM when it comes time to flash a new device though.
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
+Christian
Quoted 53 lines · On Fri, Oct 04, 2019 at 02:05:46PM +0000, [email protected] wrote:
Quoted 23 lines
Quoted 11 lines · Mika Westerberg
Quoted 5 lines · Yehezkel Bernat
Quoted 3 lines
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?Are those the chip vendor or the OEM, in case they are different?
Those are the actual USB4 hardware maker values, directly from
ROUTER_CS_0(p. 287 in the USB4 spec). This almost certainly differ from the OEM values from DROM we currently expose.Makes sense to me. Userspace can learn the relevant IDs that their NVM format is
known.Quoted 4 lines
Quoted 3 lines
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
Quoted 8 lines
Quoted 4 lines
So the bottom line is that if the kernel thinks the router supports NVM upgrade it exposes the nvm_active/nvm_non_active files etc. I think fwupd uses this information to display user whether the device can be upgraded or not (for example ICL cannot as the NVM is part of BIOS).
Yes, fwupd already takes this into account, but the question here is how to handle cases that NVM is available but the format isn't known to userspace (yet).
Exactly.
Quoted 6 lines
Quoted 5 lines
Exposing
hw_vendor_idandhw_product_idmay speed up fwupd because it does not need to go over the active NVM to figure out whether the new image is for the correct controller.Quoted 8 lines
It's not about finding the relevant image for upgrade (which must be searched for by looking in the DROM vendor/product values), but about the question if the NVM format is known to userspace and skip the parsing work if it's anyway going to fail.
So yes, I think exposing vendor ID (and maybe also product ID) can improve the situation.
Currently at probe time everything comes from udev except for the bit indicating running in "native" mode or not. Just enough chunks of the NVM are read to determine that (IE no reading up through DROM or jumping around).
Quoted 5 lines
If Christian's patch to export generation is accepted I think that we could move that check to only read -native if generation < 3.
And if you export the
hw_vendor_idandhw_product_idfields then that means USB4 devices would require no reading from NVM at "probe" since we don't have to read a -native bit.
Right. So I'm thinking instead of sw->generation what if we expose three new attributes:
hw_vendor_id - Hardware Vendor ID read from ROUTER_CS_0. hw_product_id - Hardware Product ID read from ROUTER_CS_0. hw_version - Hardware USB4 version read from ROUTER_CS_4.
This should allow userspace to determine what exactly the device is and which version it is. For example USB4 routers the hw_version is 0x20.
@Christian, would this work for bolt as well?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 3 lines · Christian Kellner
Should work. What would the value be for Thunderbolt 3 (and before)? I guess '0' if I am looking at the right thing (bits 31:24 in
ROUTER_CS_4)?
Yes, it would be 0x10 and below that depending on the generation.
Quoted 4 lines
Is there any harm of also having the 'generation' exposed as well? I like the simplicity of the mapping from that value to Thunderbolt/USB4 standard version (e.g. I would show that in 'boltctl list'); '
hw_version' will need a bit more "interpreting".
If generation is the only thing you need, we can export that now and forget hw_version :)
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 8 lines · Mika Westerberg
Quoted 5 lines
Is there any harm of also having the 'generation' exposed as well? I like the simplicity of the mapping from that value to Thunderbolt/USB4 standard version (e.g. I would show that in 'boltctl
list'); 'hw_version' will need a bit more "interpreting".If generation is the only thing you need, we can export that now and forget
hw_version:)
Sounds good to me, that is should indeed be good enough for bolt.
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to [email protected]Quoted 61 lines
-----Original Message-----
From: Limonciello, Mario
Sent: Friday, October 4, 2019 9:06 AM
To: 'Yehezkel Bernat'; Mika Westerberg
Cc: [email protected]; Andreas Noever; Michael Jamet; Rajmohan Mani; [email protected]; Lukas Wunner; [email protected]; [email protected]; Anthony Wong; LKML
Subject: RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4Quoted 9 lines
Quoted 6 lines · Mika Westerberg
Quoted 4 lines · Yehezkel Bernat
Quoted 3 lines
Also if you can get the
hw_vendor_idandhw_product_idfrom the kernel does that mean you don't need to do the two reads or you still need those?Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Are those the chip vendor or the OEM, in case they are different?
Those are the actual USB4 hardware maker values, directly from
ROUTER_CS_0(p. 287 in the USB4 spec). This almost certainly differ from the OEM values from DROM we currently expose.Makes sense to me. Userspace can learn the relevant IDs that their NVM
format
Quoted 7 lines
is
known.Quoted 4 lines
Quoted 3 lines
Thinking about it again, I'd guess it shouldn't matter much, if the chip is from Intel, the FW supports NVM upgrade, isn't it?
Quoted 8 lines
Quoted 4 lines
So the bottom line is that if the kernel thinks the router supports NVM upgrade it exposes the nvm_active/nvm_non_active files etc. I think fwupd uses this information to display user whether the device can be upgraded or not (for example ICL cannot as the NVM is part of BIOS).
Yes, fwupd already takes this into account, but the question here is how to handle cases that NVM is available but the format isn't known to userspace (yet).
Exactly.
Quoted 8 lines
Quoted 5 lines
Exposing
hw_vendor_idandhw_product_idmay speed up fwupd because it does not need to go over the active NVM to figure out whether the new image is for the correct controller.It's not about finding the relevant image for upgrade (which must be searched for by looking in the DROM vendor/product values), but about the question if
the
Quoted 1 line
NVM format is known to userspace and skip the parsing work if it's anyway
going
Quoted 5 lines
to fail.
So yes, I think exposing vendor ID (and maybe also product ID) can improve the situation.
Quoted 9 lines
Currently at probe time everything comes from udev except for the bit indicating running in "native" mode or not. Just enough chunks of the NVM are read to determine
that (IE no reading up through DROM or jumping around).If Christian's patch to export generation is accepted I think that we could move that check
to only read -native if generation < 3.
Sorry for the typo; generation < 4.
Quoted 8 lines
And if you export the
hw_vendor_idandhw_product_idfields then that means USB4 devices
would require no reading from NVM at "probe" since we don't have to read a - native bit.We would still of course read and analyze the NVM when it comes time to flash a new device
though.
Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
In reply to [email protected]Quoted 26 lines · On Tue, Oct 01, 2019 at 05:05:09PM +0000, [email protected] wrote:
Quoted 11 lines
drivers/thunderbolt/switch.c +4
-1@@ -322,9 +398,21 @@ static int tb_switch_nvm_add(struct tb_switch *sw)u32 val;int ret; -if (!sw->dma_port) +if (!nvm_readable (sw))return 0 ; +/* +* The NVM format of non-Intel hardware is not known so +* currently restrict NVM upgrade for Intel hardware. We may drivers/thunderbolt/switch.c static int tb_switch_nvm_add(struct tb_switch *sw) · line 416
Quoted 10 lines
drivers/thunderbolt/switch.c +9
-0+* relax this in the future when we learn other NVM formats. +*/ +if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL ) { +dev_info (&sw->dev, +"NVM format of vendor %#x is not known, disabling NVM upgrade\n", + sw->config.vendor_id); +return 0 ; + } +Don't you actually have an attribute you can use here for this exact purpose that you could be setting rather than returning immediately?
sw->no_nvm_upgrade
Quoted 2 lines
Then potentially you can at least let users "dump out" the nvm on !Intel but don't let it be written until ready to relax further.
Problem is that we currently read NVM version and size from a known location in the NVM. If we don't know the format we can't do that so that would mean we need to expose active NVM with some size and hide nvm_version. I would rather have this support included in the kernel driver and expose standard set of attributes but no strong feelings from one way or another.
RE: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4
Quoted 45 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, October 2, 2019 3:35 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 17/22] thunderbolt: Add initial support for USB4[EXTERNAL EMAIL]
Quoted 8 lines · On Tue, Oct 01, 2019 at 05:05:09PM +0000, [email protected] wrote:
Quoted 8 lines
drivers/thunderbolt/switch.c +1
-1@@ -322,9 +398,21 @@ static int tb_switch_nvm_add(struct tb_switch *sw)u32 val;int ret; -if (!sw->dma_port) +if (!nvm_readable (sw))return 0 ;Quoted 8 lines
drivers/thunderbolt/switch.c static int tb_switch_nvm_add(struct tb_switch *sw)
Quoted 8 lines
drivers/thunderbolt/switch.c +8
-0+/* +* The NVM format of non-Intel hardware is not known so +* currently restrict NVM upgrade for Intel hardware. We may +* relax this in the future when we learn other NVM formats. +*/ +if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL ) { + dev_info(&sw->dev, + "NVM format of vendor %#x is not known, disablingNVM
Quoted 7 lines
drivers/thunderbolt/switch.c static int tb_switch_nvm_add(struct tb_switch *sw) · line 415
Quoted 5 lines
drivers/thunderbolt/switch.c +4
-0upgrade\n", + sw->config.vendor_id); +return 0 ; + } +Don't you actually have an attribute you can use here for this exact purpose
that you
Quoted 4 lines
could be setting rather than returning immediately?
sw->no_nvm_upgradeThen potentially you can at least let users "dump out" the nvm on !Intel but
don't let
Quoted 8 lines
Quoted 1 line
it be written until ready to relax further.
Problem is that we currently read NVM version and size from a known location in the NVM. If we don't know the format we can't do that so that would mean we need to expose active NVM with some size and hide
nvm_version. I would rather have this support included in the kernel driver and expose standard set of attributes but no strong feelings from one way or another.
I agree with you; this is a safer and smarter approach to wait until details of format for other vendors is known and export attributes only when it is. This will also encourage other vendors to open up their format if the only way to access NVM is to document the headers.
RFC PATCH 18/22 thunderbolt: Make tb_switch_find_cap() available to other files
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
We need to find switch capabilities in order to implement TMU support so make it available to other files as well.
--- drivers/thunderbolt/cap.c | 11 ++++++++++- drivers/thunderbolt/tb.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/thunderbolt/cap.c +10 -1
@@ -113,7 +113,16 @@ int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap)return ret; } -static int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap) +/** +* tb_switch_find_cap() - Find switch capability +* @sw Switch to find the capability for +* @cap: Capability to look +* +* Returns offset to start of capability or %-ENOENT if no such +* capability was found. Negative errno is returned if there was an +* error. +*/ +int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap) {int offset = sw->config.first_cap_offset;
drivers/thunderbolt/tb.h +1 -0
@@ -709,6 +709,7 @@ struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, struct tb_port *prev);int tb_switch_find_vse_cap (struct tb_switch *sw,enum tb_switch_vse_cap vsec); +int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap);int tb_port_find_cap (struct tb_port *port,enum tb_port_cap cap);bool tb_port_is_enabled (struct tb_port *port);
Signature · 1 line
2.23.0
RFC PATCH 19/22 thunderbolt: Add support for Time Management Unit
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
Time Management Unit (TMU) is included in each USB4 router. It is used to synchronize time across the USB4 fabric. By default when USB4 router is plugged to the domain, its TMU is turned off. This differs from Thunderbolt (1, 2 and 3) devices whose TMU is by default configured to bi-directional HiFi mode. Since time synchronization is needed for proper Display Port tunneling this means we need to configure the TMU on USB4 compliant devices.
The USB4 spec allows some flexibility on how the TMU can be configured. This makes it possible to enable link power management states (CLx) in certain topologies, where for example DP tunneling is not used. TMU can also be re-configured dynamicaly depending on types of tunnels created over the USB4 fabric.
In this patch we simply configure the TMU to be in bi-directional HiFi mode. This way we can tunnel any kind of traffic without need to perform complex steps to re-configure the domain dynamically. We can add more fine-grained TMU configuration later on when we start enabling CLx states.
--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/switch.c | 4 + drivers/thunderbolt/tb.c | 29 +++ drivers/thunderbolt/tb.h | 47 +++++ drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tmu.c | 380 ++++++++++++++++++++++++++++++++++ 6 files changed, 481 insertions(+), 1 deletion(-) create mode 100644 drivers/thunderbolt/tmu.c
drivers/thunderbolt/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-${CONFIG_THUNDERBOLT} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
drivers/thunderbolt/switch.c +4 -0
@@ -2278,6 +2278,10 @@ int tb_switch_add(struct tb_switch *sw) ret =tb_switch_update_link_attributes (sw);if (ret)return ret; + + ret =tb_switch_tmu_init (sw); +if (ret) +return ret; } ret =device_add (&sw->dev);
drivers/thunderbolt/tb.c +29 -0
@@ -161,6 +161,25 @@ static void tb_scan_xdomain(struct tb_port *port) } } +static int tb_enable_tmu (struct tb_switch *sw) +{ +int ret; + +/* If it is already enabled in correct mode, don't touch it */ +if (tb_switch_tmu_is_enabled (sw)) +return 0 ; + + ret =tb_switch_tmu_disable (sw); +if (ret) +return ret; + + ret =tb_switch_tmu_post_time (sw); +if (ret) +return ret; + +return tb_switch_tmu_enable (sw); +} +static void tb_scan_port (struct tb_port *port);/**
@@ -263,6 +282,9 @@ static void tb_scan_port(struct tb_port *port)if (tb_switch_lane_bonding_enable (sw))tb_sw_warn (sw,"failed to enable lane bonding\n" ); +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to enable TMU\n" ); +tb_scan_switch (sw); }
@@ -713,6 +735,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_sw_set_unplugged (port->remote->sw);tb_free_invalid_tunnels (tb);tb_remove_dp_resources (port->remote->sw); +tb_switch_tmu_disable (port->remote->sw);tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;
@@ -860,6 +883,9 @@ static int tb_start(struct tb *tb)return ret; } +/* Enable TMU if it is off */ +if (!tb_switch_tmu_is_enabled (tb->root_switch)) +tb_switch_tmu_enable (tb->root_switch);/* Full scan to discover devices added before the driver was loaded. */ tb_scan_switch (tb->root_switch);/* Find out tunnels created by the boot firmware */
@@ -891,6 +917,9 @@ static void tb_restore_children(struct tb_switch *sw) {int i; +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to restore TMU configuration\n" ); +tb_switch_for_each_remote_port (sw, i) {struct tb_port *port = &sw->ports[i];
drivers/thunderbolt/tb.h +47 -0
83 lines not on this page · raw message
drivers/thunderbolt/tb_regs.h +20 -0
@@ -26,6 +26,7 @@#define TB_MAX_CONFIG_RW_LENGTH 60enum tb_switch_cap { +TB_SWITCH_CAP_TMU =0x03 ,TB_SWITCH_CAP_VSE =0x05 , };
@@ -195,6 +196,21 @@ struct tb_regs_switch_header {#define ROUTER_CS_26_ONS BIT(30)#define ROUTER_CS_26_OV BIT(31) +/* Router TMU configuration */ +#define TMU_RTR_CS_0 0x00 +#define TMU_RTR_CS_0_TD BIT(27) +#define TMU_RTR_CS_0_UCAP BIT(30) +#define TMU_RTR_CS_1 0x01 +#define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16) +#define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16 +#define TMU_RTR_CS_2 0x02 +#define TMU_RTR_CS_3 0x03 +#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16 +#define TMU_RTR_CS_22 0x16 +#define TMU_RTR_CS_24 0x18 +enum tb_port_type {TB_TYPE_INACTIVE =0x000000 ,TB_TYPE_PORT =0x000001 ,
@@ -248,6 +264,10 @@ struct tb_regs_port_header {#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22 +/* TMU adapter registers */ +#define TMU_ADP_CS_3 0x03 +#define TMU_ADP_CS_3_UDM BIT(29) +/* Lane adapter registers */ #define LANE_ADP_CS_0 0x00#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)
drivers/thunderbolt/tmu.c new file +380 -0
380 lines not on this page · raw message
Signature · 1 line
2.23.0
RE: [RFC PATCH 19/22] thunderbolt: Add support for Time Management Unit
Hi Mika,
Quoted 125 lines
-----Original Message-----
From: Mika Westerberg [mailto:[email protected]]
Sent: Tuesday, October 01, 2019 4:38 AM
To: [email protected]
Cc: Andreas Noever <[email protected]>; Jamet, Michael <[email protected]>; Mika Westerberg <[email protected]>; Yehezkel Bernat <[email protected]>; Mani, Rajmohan <[email protected]>; Nicholas Johnson <[email protected]>; Lukas Wunner <[email protected]>; Greg Kroah-Hartman <[email protected]>; Alan Stern <[email protected]>; [email protected]; Anthony Wong <[email protected]>; [email protected]
Subject: [RFC PATCH 19/22] thunderbolt: Add support for Time Management UnitFrom: Rajmohan Mani <[email protected]>
Time Management Unit (TMU) is included in each USB4 router. It is used to synchronize time across the USB4 fabric. By default when USB4 router is plugged to the domain, its TMU is turned off. This differs from Thunderbolt (1, 2 and 3) devices whose TMU is by default configured to bi-directional HiFi mode. Since time synchronization is needed for proper Display Port tunneling this means we need to configure the TMU on
USB4 compliant devices.The USB4 spec allows some flexibility on how the TMU can be configured. This makes it possible to enable link power management states (CLx) in certain topologies, where for example DP tunneling is not used. TMU can also be re- configured dynamicaly depending on types of tunnels created over the USB4 fabric.
In this patch we simply configure the TMU to be in bi-directional HiFi mode. This way we can tunnel any kind of traffic without need to perform complex steps to re-configure the domain dynamically. We can add more fine-grained TMU configuration later on when we start enabling CLx states.
Signed-off-by Rajmohan Mani <[email protected]>Co-developed-by Mika Westerberg <[email protected]>Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/switch.c | 4 + drivers/thunderbolt/tb.c | 29 +++ drivers/thunderbolt/tb.h | 47 +++++ drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tmu.c | 380 ++++++++++++++++++++++++++++++++++ 6 files changed, 481 insertions(+), 1 deletion(-) create mode 100644
drivers/thunderbolt/tmu.cdrivers/thunderbolt/Makefile index renamed from drivers/thunderbolt/Makefile +0
-0
c0b2fd73dfbd..2014bc840b06100644drivers/thunderbolt/Makefile +0
-0@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-${CONFIG_THUNDERBOLT} :=thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o
drivers/thunderbolt/Makefile +2
-0+thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o +tmu.o usb4.odrivers/thunderbolt/switch.c index renamed from drivers/thunderbolt/switch.c +0
-0
2ccd1004920e..58e3f54ddbb9100644drivers/thunderbolt/switch.c +4
-0@@ -2278,6 +2278,10 @@ int tb_switch_add(struct tb_switch *sw) ret =tb_switch_update_link_attributes (sw);if (ret)return ret; + + ret =tb_switch_tmu_init (sw); +if (ret) +return ret; } ret =device_add (&sw->dev);drivers/thunderbolt/tb.c index renamed from drivers/thunderbolt/tb.c +0
-0
24e37e47dc48..f2868c125637100644drivers/thunderbolt/tb.c +22
-0@@ -161,6 +161,25 @@ static void tb_scan_xdomain(struct tb_port *port) } } +static int tb_enable_tmu (struct tb_switch *sw) { +int ret; + +/* If it is already enabled in correct mode, don't touch it */ +if (tb_switch_tmu_is_enabled (sw)) +return 0 ; + + ret =tb_switch_tmu_disable (sw); +if (ret) +return ret; + + ret =tb_switch_tmu_post_time (sw); +if (ret) +return ret; + +return tb_switch_tmu_enable (sw); +} +static void tb_scan_port (struct tb_port *port);/** @@ -263,6 +282,9 @@ static void tb_scan_port(struct tb_port *port)if (tb_switch_lane_bonding_enable (sw))tb_sw_warn (sw,"failed to enable lane bonding\n" ); +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to enable TMU\n" ); +tb_scan_switch (sw); }@@ -713,6 +735,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_sw_set_unplugged (port->remote->sw);tb_free_invalid_tunnels (tb);tb_remove_dp_resources (port->remote->sw); +tb_switch_tmu_disable (port->remote->sw);tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw);drivers/thunderbolt/tb.c +0
-0port->remote =NULL ;
drivers/thunderbolt/tb.c static int tb_start(struct tb *tb) · line 887
Quoted 5 lines
drivers/thunderbolt/tb.c +2
-0@@ -860,6 +883,9 @@ static int tb_start(struct tb *tb)return ret; } +/* Enable TMU if it is off */ +if (!tb_switch_tmu_is_enabled (tb->root_switch))
To be consistent with the implementation of tb_switch_tmu_disable(), should we move the above check inside tb_switch_tmu_enable()?
Quoted 541 lines
drivers/thunderbolt/tb.c +1
-0+tb_switch_tmu_enable (tb->root_switch);/* Full scan to discover devices added before the driver was loaded. */ tb_scan_switch (tb->root_switch); /* Find out tunnels created by the boot firmware */ @@ -891,6 +917,9@@ static void
tb_restore_children(struct tb_switch *sw){drivers/thunderbolt/tb.c +3
-0int i; +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to restore TMU configuration\n" ); +tb_switch_for_each_remote_port (sw, i) {struct tb_port *port = &sw->ports[i];drivers/thunderbolt/tb.h index renamed from drivers/thunderbolt/tb.h +0
-0
1488382066fd..087fd6d6ef9a100644drivers/thunderbolt/tb.h +7
-0@@ -46,6 +46,38 @@ struct tb_switch_nvm {#define TB_SWITCH_MAX_DEPTH 6#define USB4_SWITCH_MAX_DEPTH 5 +/** +* enum tb_switch_tmu_rate - TMU refresh rate +* @TB_SWITCH_TMU_RATE_OFF: %0 (Disable Time Sync handshake) +* @TB_SWITCH_TMU_RATE_HIFI: %16 us time interval between successive +* transmission of the Delay Request TSNOS +* (Time Sync Notification Ordered Set) on a Link +* @TB_SWITCH_TMU_RATE_NORMAL: %1 ms time interval between successive
+ * transmission of the Delay Request TSNOS on
+ * a Link
+ */drivers/thunderbolt/tb.h +23
-0+enum tb_switch_tmu_rate { +TB_SWITCH_TMU_RATE_OFF =0 , +TB_SWITCH_TMU_RATE_HIFI =16 , +TB_SWITCH_TMU_RATE_NORMAL =1000 , +}; + +/** +* struct tb_switch_tmu - Structure holding switch TMU configuration +* @cap: Offset to the TMU capability (%0 if not found) +* @has_ucap: Does the switch support uni-directional mode +* @rate: TMU refresh rate related to upstream switch. In case of root +* switch this holds the domain rate. +* @unidirectional: Is the TMU in uni-directional or bi-directional mode +* related to upstream switch. Don't case for root switch. +*/ +struct tb_switch_tmu { +int cap; +bool has_ucap; +enum tb_switch_tmu_rate rate; +bool unidirectional; +}; +/** * struct tb_switch - a thunderbolt switch * @dev: Device for the switch @@ -55,6 +87,7 @@ struct tb_switch_nvm {* mailbox this will hold the pointer to that (%NULL * otherwise). If set it also means the switch has * upgradeable NVM. +* @tmu: The switch TMU configuration * @tb: Pointer to the domain the switch belongs to * @uid: Unique ID of the switch * @uuid: UUID of the switch (or %NULL if not supported) @@ -93,6 +126,7 @@ struct
tb_switch{drivers/thunderbolt/tb.h +15
-0struct tb_regs_switch_header config;struct tb_port *ports;struct tb_dma_port *dma_port; +struct tb_switch_tmu tmu;struct tb *tb;u64 uid;uuid_t *uuid;@@ -129,6 +163,7 @@ struct tb_switch {* @remote: Remote port (%NULL if not connected) * @xdomain: Remote host (%NULL if not connected) * @cap_phy: Offset, zero if not found +* @cap_tmu: Offset of the adapter specific TMU capability (%0 if not +present) * @cap_adap: Offset of the adapter specific capability (%0 if not present) * @cap_usb4: Offset to the USB4 port capability (%0 if not present) * @port: Port number on switch @@ -147,6 +182,7 @@ struct tb_port {struct tb_port *remote;struct tb_xdomain *xdomain;int cap_phy; +int cap_tmu;int cap_adap;int cap_usb4;u8 port;@@ -696,6 +732,17 @@ bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in); int tb_switch_alloc_dp_resource(struct tb_switch *sw,struct tb_port *in);void tb_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +int tb_switch_tmu_init (struct tb_switch *sw);int +tb_switch_tmu_post_time (struct tb_switch *sw);int +tb_switch_tmu_disable (struct tb_switch *sw);int +tb_switch_tmu_enable (struct tb_switch *sw); + +static inline bool tb_switch_tmu_is_enabled (const struct tb_switch *sw) +{ +return sw->tmu.rate ==TB_SWITCH_TMU_RATE_HIFI && + !sw->tmu.unidirectional; +} +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int
tb_port_add_nfc_credits(struct tb_port *port, int credits); inttb_port_set_initial_credits(struct tb_port *port, u32 credits); diff --gita/drivers/thunderbolt/tb_regs.hb/drivers/thunderbolt/tb_regs.hindex47f73f992412..ec1a5d1f7c94100644drivers/thunderbolt/tb_regs.h +16
-0@@ -26,6 +26,7 @@#define TB_MAX_CONFIG_RW_LENGTH 60enum tb_switch_cap { +TB_SWITCH_CAP_TMU =0x03 ,TB_SWITCH_CAP_VSE =0x05 , };@@ -195,6 +196,21 @@ struct tb_regs_switch_header {#define ROUTER_CS_26_ONS BIT(30)#define ROUTER_CS_26_OV BIT(31) +/* Router TMU configuration */ +#define TMU_RTR_CS_0 0x00 +#define TMU_RTR_CS_0_TD BIT(27) +#define TMU_RTR_CS_0_UCAP BIT(30) +#define TMU_RTR_CS_1 0x01 +#define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16) +#define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16 +#define TMU_RTR_CS_2 0x02 +#define TMU_RTR_CS_3 0x03 +#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16 +#define TMU_RTR_CS_22 0x16 +#define TMU_RTR_CS_24 0x18 +enum
tb_port_type{drivers/thunderbolt/tb_regs.h +4
-0TB_TYPE_INACTIVE =0x000000 , TB_TYPE_PORT = 0x000001,@@ -248,6 +264,10 @@ struct tb_regs_port_header {#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22 +/* TMU adapter registers */ +#define TMU_ADP_CS_3 0x03 +#define TMU_ADP_CS_3_UDM BIT(29) +/* Lane adapter registers */ #define LANE_ADP_CS_0 0x00#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)drivers/thunderbolt/tmu.c new file renamed from drivers/thunderbolt/tmu.c +0
-0mode 100644 index 000000000000..d6314f6b20c7
drivers/thunderbolt/tmu.c new file +87
-0@@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Thunderbolt Time Management Unit (TMU) support +* +* Copyright (C) 2019, Intel Corporation +* Authors: Mika Westerberg <[email protected]> +* Rajmohan Mani <[email protected]> +*/ + +#include <linux/delay.h> + +#include "tb.h" + +static const char *tb_switch_tmu_mode_name (const struct tb_switch *sw) +{ +bool root_switch = !tb_route (sw); + +switch (sw->tmu.rate) { +case TB_SWITCH_TMU_RATE_OFF : +return "off" ; + +case TB_SWITCH_TMU_RATE_HIFI : +/* Root switch does not have upstream directionality */ +if (root_switch) +return "HiFi" ; +if (sw->tmu.unidirectional) +return "uni-directional, HiFi" ; +return "bi-directional, HiFi" ; + +case TB_SWITCH_TMU_RATE_NORMAL : +if (root_switch) +return "normal" ; +return "uni-directional, normal" ; + +default : +return "unknown" ; + } +} + +static bool tb_switch_tmu_ucap_supported (struct tb_switch *sw) { +int ret; +u32 val; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_0 ,1 ); +if (ret) +return false; + +return !!(val &TMU_RTR_CS_0_UCAP ); +} + +static int tb_switch_tmu_rate_read (struct tb_switch *sw) { +int ret; +u32 val; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_3 ,1 ); +if (ret) +return ret; + + val >>=TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT ; +return val; +} + +static int tb_switch_tmu_rate_write (struct tb_switch *sw,int rate) { +int ret; +u32 val; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_3 ,1 ); +if (ret) +return ret; + + val &= ~TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK ; + val |= rate <<TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT ; + +return tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_3 ,1 ); +} + +static int tb_port_tmu_write (struct tb_port *port,u8 offset,u32 mask, +u32 value) +{ +u32 data; +int ret; + + ret = tb_port_read(port, &data, TB_CFG_PORT, port->cap_tmu +offset, 1);
drivers/thunderbolt/tmu.c new file +20
-0+if (ret) +return ret; + + data &= ~mask; + data |= value; + +return tb_port_write (port, &data,TB_CFG_PORT , + port->cap_tmu + offset,1 ); +} + +static int tb_port_tmu_set_unidirectional (struct tb_port *port, +bool unidirectional) +{ +u32 val; + +if (!port->sw->tmu.has_ucap) +return 0 ; + + val = unidirectional ?TMU_ADP_CS_3_UDM :0 ; + return tb_port_tmu_write(port, TMU_ADP_CS_3,
TMU_ADP_CS_3_UDM, val); }drivers/thunderbolt/tmu.c new file +84
-0+ +static inline int tb_port_tmu_unidirectional_disable (struct tb_port +*port) { +return tb_port_tmu_set_unidirectional (port, false); } + +static bool tb_port_tmu_is_unidirectional (struct tb_port *port) { +int ret; +u32 val; + + ret =tb_port_read (port, &val,TB_CFG_PORT , + port->cap_tmu +TMU_ADP_CS_3 ,1 ); +if (ret) +return false; + +return val &TMU_ADP_CS_3_UDM ; +} + +static int tb_switch_tmu_set_time_disruption (struct tb_switch *sw,bool +set) { +int ret; +u32 val; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_0 ,1 ); +if (ret) +return ret; + +if (set) + val |=TMU_RTR_CS_0_TD ; +else + val &= ~TMU_RTR_CS_0_TD ; + +return tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->tmu.cap +TMU_RTR_CS_0 ,1 ); +} + +/** +* tb_switch_tmu_init() - Initialize switch TMU structures +* @sw: Switch to initialized +* +* This function must be called before other TMU related functions to +* makes the internal structures are filled in correctly. Does not +* change any hardware configuration. +*/ +int tb_switch_tmu_init (struct tb_switch *sw) { +int ret, i; + +if (tb_switch_is_icm (sw)) +return 0 ; + + ret =tb_switch_find_cap (sw,TB_SWITCH_CAP_TMU ); +if (ret >0 ) + sw->tmu.cap = ret; + +tb_switch_for_each_port (sw, i) { +struct tb_port *port = &sw->ports[i]; +int cap; + + cap =tb_port_find_cap (port,TB_PORT_CAP_TIME1 ); +if (cap >0 ) + port->cap_tmu = cap; + } + + ret =tb_switch_tmu_rate_read (sw); +if (ret <0 ) +return ret; + + sw->tmu.rate = ret; + + sw->tmu.has_ucap =tb_switch_tmu_ucap_supported (sw); +if (sw->tmu.has_ucap) { +tb_sw_dbg (sw,"TMU: supports uni-directional mode\n" ); + +if (tb_route (sw)) { +struct tb_port *up =tb_upstream_port (sw); + + sw->tmu.unidirectional = +tb_port_tmu_is_unidirectional (up); + } + }else { + sw->tmu.unidirectional = false; + } + + tb_sw_dbg(sw, "TMU: current mode: %s\n",
tb_switch_tmu_mode_name(sw));drivers/thunderbolt/tmu.c new file +69
-0+return 0 ; +} + +/** +* tb_switch_tmu_post_time() - Update switch local time +* @sw: Switch whose time to update +* +* Updates switch local time using time posting procedure. +*/ +int tb_switch_tmu_post_time (struct tb_switch *sw) { +unsigned int post_local_time_offset, post_time_offset; +struct tb_switch *root_switch = sw->tb->root_switch; +u64 hi, mid, lo, local_time, post_time; +int i, ret, retries =100 ; +u32 gm_local_time[3 ]; + +if (!tb_route (sw)) +return 0 ; + +if (!tb_switch_is_usb4 (sw)) +return 0 ; + +/* Need to be able to read the grand master time */ +if (!root_switch->tmu.cap) +return 0 ; + + ret =tb_sw_read (root_switch, gm_local_time,TB_CFG_SWITCH , + root_switch->tmu.cap +TMU_RTR_CS_1 , +ARRAY_SIZE (gm_local_time)); +if (ret) +return ret; + +for (i =0 ; i <ARRAY_SIZE (gm_local_time); i++) +tb_sw_dbg (root_switch,"local_time[%d]=0x%08x\n" , i, + gm_local_time[i]); + +/* Convert to nanoseconds (drop fractional part) */ + hi = gm_local_time[2 ] &TMU_RTR_CS_3_LOCAL_TIME_NS_MASK ; + mid = gm_local_time[1 ]; + lo = (gm_local_time[0 ] &TMU_RTR_CS_1_LOCAL_TIME_NS_MASK ) >> +TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT ; + local_time = hi <<48 | mid <<16 | lo; + +/* Tell the switch that time sync is disrupted for a while */ + ret =tb_switch_tmu_set_time_disruption (sw, true); +if (ret) +return ret; + + post_local_time_offset = sw->tmu.cap +TMU_RTR_CS_22 ; + post_time_offset = sw->tmu.cap +TMU_RTR_CS_24 ; + +/* +* Write the Grandmaster time to the Post Local Time registers +* of the new switch. +*/ + ret =tb_sw_write (sw, &local_time,TB_CFG_SWITCH , + post_local_time_offset,2 ); +if (ret) + goto out; + +/* +* Have the new switch update its local time (by writing 1 to +* the post_time registers) and wait for the completion of the +* same (post_time register becomes 0). This means the time has +* been converged properly. +*/ + post_time =1 ; + + ret = tb_sw_write(sw, &post_time, TB_CFG_SWITCH, post_time_offset,2);
drivers/thunderbolt/tmu.c new file +93
-0+if (ret) + goto out; + +do { +usleep_range (5 ,10 ); + ret =tb_sw_read (sw, &post_time,TB_CFG_SWITCH , + post_time_offset,2 ); +if (ret) + goto out; + }while (--retries && post_time); + +if (!retries) { + ret = -ETIMEDOUT ; + goto out; + } + +tb_sw_dbg (sw,"TMU: updated local time to %#llx\n" , local_time); + +out: +tb_switch_tmu_set_time_disruption (sw, false); +return ret; +} + +/** +* tb_switch_tmu_disable() - Disable TMU of a switch +* @sw: Switch whose TMU to disable +* +* Turns off TMU of @sw if it is enabled. If not enabled does nothing. +*/ +int tb_switch_tmu_disable (struct tb_switch *sw) { +int ret; + +if (!tb_switch_is_usb4 (sw)) +return 0 ; + +/* Already disabled? */ +if (sw->tmu.rate ==TB_SWITCH_TMU_RATE_OFF ) +return 0 ; + +if (sw->tmu.unidirectional) { +struct tb_switch *parent =tb_switch_parent (sw); +struct tb_port *up, *down; + + up =tb_upstream_port (sw); + down =tb_port_at (tb_route (sw), parent); + +/* The switch may be unplugged so ignore any errors */ +tb_port_tmu_unidirectional_disable (up); + ret =tb_port_tmu_unidirectional_disable (down); +if (ret) +return ret; + } + +tb_switch_tmu_rate_write (sw,TB_SWITCH_TMU_RATE_OFF ); + + sw->tmu.unidirectional = false; + sw->tmu.rate =TB_SWITCH_TMU_RATE_OFF ; + +tb_sw_dbg (sw,"TMU: disabled\n" ); +return 0 ; +} + +/** +* tb_switch_tmu_enable() - Enable TMU on a switch +* @sw: Switch whose TMU to enable +* +* Enables TMU of a switch to be in bi-directional, HiFi mode. In this +mode +* all tunneling should work. +*/ +int tb_switch_tmu_enable (struct tb_switch *sw) { +int ret; + +if (!tb_switch_is_usb4 (sw)) +return 0 ; + + ret =tb_switch_tmu_set_time_disruption (sw, true); +if (ret) +return ret; + +/* Change mode to bi-directional */ +if (tb_route (sw) && sw->tmu.unidirectional) { +struct tb_switch *parent =tb_switch_parent (sw); +struct tb_port *up, *down; + + up =tb_upstream_port (sw); + down =tb_port_at (tb_route (sw), parent); + + ret =tb_port_tmu_unidirectional_disable (down); +if (ret) +return ret; + + ret = tb_switch_tmu_rate_write(sw,
TB_SWITCH_TMU_RATE_HIFI);drivers/thunderbolt/tmu.c new file +8
-0+if (ret) +return ret; + + ret =tb_port_tmu_unidirectional_disable (up); +if (ret) +return ret; + }else { + ret = tb_switch_tmu_rate_write(sw,
TB_SWITCH_TMU_RATE_HIFI);drivers/thunderbolt/tmu.c new file +7
-0+if (ret) +return ret; + } + + sw->tmu.unidirectional = false; + sw->tmu.rate =TB_SWITCH_TMU_RATE_HIFI ; + tb_sw_dbg(sw, "TMU: mode set to: %s\n",
tb_switch_tmu_mode_name(sw));drivers/thunderbolt/tmu.c new file +2
-1+ +return tb_switch_tmu_set_time_disruption (sw, false); } --2.23.0
Re: [RFC PATCH 19/22] thunderbolt: Add support for Time Management Unit
Quoted 5 lines · Rajmohan
drivers/thunderbolt/tb.c static int tb_start(struct tb *tb) · line 887
Quoted 2 lines
drivers/thunderbolt/tb.c +2
-0+/* Enable TMU if it is off */ +if (!tb_switch_tmu_is_enabled (tb->root_switch))To be consistent with the implementation of
tb_switch_tmu_disable(), should we move the above check insidetb_switch_tmu_enable()?
Yes, I think it makes sense.
RFC PATCH 20/22 thunderbolt: Add support for USB tunnels
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
USB4 added a capability to tunnel USB 3.x protocol over the USB4 fabric. USB4 device routers may include integrated SuperSpeed HUB or a function or both. USB tunneling follows PCIe so that the tunnel is created between the parent and the child router from USB downstream adapter port to USB upstream adapter port over a single USB4 link.
This adds support for USB tunneling and also capability to discover existing USB tunnels (for example created by connection manager in boot firmware).
--- drivers/thunderbolt/switch.c | 35 ++++++++ drivers/thunderbolt/tb.c | 153 ++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 15 ++++ drivers/thunderbolt/tb_regs.h | 9 +- drivers/thunderbolt/tunnel.c | 158 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 9 ++ drivers/thunderbolt/usb4.c | 41 ++++++++- 7 files changed, 393 insertions(+), 27 deletions(-)
drivers/thunderbolt/switch.c +35 -0
@@ -1025,11 +1025,46 @@ bool tb_port_is_enabled(struct tb_port *port)case TB_TYPE_DP_HDMI_OUT :return tb_dp_port_is_enabled (port); +case TB_TYPE_USB_UP : +case TB_TYPE_USB_DOWN : +return tb_usb_port_is_enabled (port); +default :return false; } } +/** +* tb_usb_port_is_enabled() - Is the USB adapter port enabled +* @port: USB port to check +*/ +bool tb_usb_port_is_enabled (struct tb_port *port) +{ +u32 data; + +if (tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_USB3_CS_0 ,1 )) +return false; + +return !!(data &ADP_USB3_CS_0_PE ); +} + +/** +* tb_usb_port_enable() - Enable USB adapter port +* @port: USB port to enable +* @enable: Enable/disable the USB adapter +*/ +int tb_usb_port_enable (struct tb_port *port,bool enable) +{ +u32 word = enable ? (ADP_USB3_CS_0_PE |ADP_USB3_CS_0_V ) + :ADP_USB3_CS_0_V ; + +if (!port->cap_adap) +return -ENXIO ; +return tb_port_write (port, &word,TB_CFG_PORT , + port->cap_adap +ADP_USB3_CS_0 ,1 ); +} +/** * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled * @port: PCIe port to check
drivers/thunderbolt/tb.c +129 -24
183 lines not on this page · raw message
drivers/thunderbolt/tb.h +15 -0
@@ -432,6 +432,16 @@ static inline bool tb_port_is_dpout(const struct tb_port *port)return port && port->config.type ==TB_TYPE_DP_HDMI_OUT ; } +static inline bool tb_port_is_usb_down (const struct tb_port *port) +{ +return port && port->config.type ==TB_TYPE_USB_DOWN ; +} + +static inline bool tb_port_is_usb_up (const struct tb_port *port) +{ +return port && port->config.type ==TB_TYPE_USB_UP ; +} +static inline int tb_sw_read (struct tb_switch *sw,void *buffer,enum tb_cfg_space space,u32 offset,u32 length) {
@@ -760,6 +770,9 @@ int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);int tb_port_find_cap (struct tb_port *port,enum tb_port_cap cap);bool tb_port_is_enabled (struct tb_port *port); +bool tb_usb_port_is_enabled (struct tb_port *port); +int tb_usb_port_enable (struct tb_port *port,bool enable); +bool tb_pci_port_is_enabled (struct tb_port *port);int tb_pci_port_enable (struct tb_port *port,bool enable);
@@ -842,6 +855,8 @@ int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);int usb4_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in);struct tb_port *usb4_switch_map_pcie_down (struct tb_switch *sw,const struct tb_port *port); +struct tb_port *usb4_switch_map_usb_down (struct tb_switch *sw, +const struct tb_port *port);int usb4_port_unlock (struct tb_port *port);#endif
drivers/thunderbolt/tb_regs.h +8 -1
@@ -180,6 +180,7 @@ struct tb_regs_switch_header {#define ROUTER_CS_5_SLP BIT(0)#define ROUTER_CS_5_C3S BIT(23)#define ROUTER_CS_5_PTO BIT(24) +#define ROUTER_CS_5_UTO BIT(25)#define ROUTER_CS_5_HCO BIT(26)#define ROUTER_CS_5_CV BIT(31)#define ROUTER_CS_6 0x06
@@ -221,7 +222,8 @@ enum tb_port_type {TB_TYPE_DP_HDMI_OUT =0x0e0102 ,TB_TYPE_PCIE_DOWN =0x100101 ,TB_TYPE_PCIE_UP =0x100102 , - /* TB_TYPE_USB = 0x200000, lower order bits are not known */ +TB_TYPE_USB_DOWN =0x200101 , + TB_TYPE_USB_UP = 0x200102, };/* Present on every port in TB_CF_PORT at address zero. */
@@ -331,6 +333,11 @@ struct tb_regs_port_header {#define ADP_PCIE_CS_0 0x00#define ADP_PCIE_CS_0_PE BIT(31) +/* USB adapter registers */ +#define ADP_USB3_CS_0 0x00 +#define ADP_USB3_CS_0_V BIT(30) +#define ADP_USB3_CS_0_PE BIT(31) +/* Hop register from TB_CFG_HOPS. 8 byte per entry. */ struct tb_regs_hop {/* DWORD 0 */
drivers/thunderbolt/tunnel.c +157 -1
176 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +9 -0
@@ -15,6 +15,7 @@ enum tb_tunnel_type {TB_TUNNEL_PCI ,TB_TUNNEL_DP ,TB_TUNNEL_DMA , + TB_TUNNEL_USB, };/**
@@ -57,6 +58,9 @@ struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, struct tb_port *dst, int transmit_ring, int transmit_path, int receive_ring, int receive_path); +struct tb_tunnel *tb_tunnel_discover_usb (struct tb *tb,struct tb_port *down); +struct tb_tunnel *tb_tunnel_alloc_usb (struct tb *tb,struct tb_port *up, +struct tb_port *down);void tb_tunnel_free (struct tb_tunnel *tunnel);int tb_tunnel_activate (struct tb_tunnel *tunnel);
@@ -82,5 +86,10 @@ static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel) return tunnel->type == TB_TUNNEL_DMA; } +static inline bool tb_tunnel_is_usb (const struct tb_tunnel *tunnel) +{ +return tunnel->type ==TB_TUNNEL_USB ; +} +#endif
drivers/thunderbolt/usb4.c +40 -1
56 lines not on this page · raw message
Signature · 1 line
2.23.0
Re: [RFC PATCH 20/22] thunderbolt: Add support for USB tunnels
Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg:
Quoted 37 lines
From: Rajmohan Mani <[email protected]>
USB4 added a capability to tunnel USB 3.x protocol over the USB4 fabric. USB4 device routers may include integrated SuperSpeed HUB or a function or both. USB tunneling follows PCIe so that the tunnel is created between the parent and the child router from USB downstream adapter port to USB upstream adapter port over a single USB4 link.
This adds support for USB tunneling and also capability to discover existing USB tunnels (for example created by connection manager in boot firmware).
Signed-off-by Rajmohan Mani <[email protected]>Co-developed-by Mika Westerberg <[email protected]>Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/switch.c | 35 ++++++++ drivers/thunderbolt/tb.c | 153 ++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 15 ++++ drivers/thunderbolt/tb_regs.h | 9 +- drivers/thunderbolt/tunnel.c | 158 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 9 ++ drivers/thunderbolt/usb4.c | 41 ++++++++- 7 files changed, 393 insertions(+), 27 deletions(-)drivers/thunderbolt/switch.c +4
-0@@ -1025,11 +1025,46 @@ bool tb_port_is_enabled(struct tb_port *port)case TB_TYPE_DP_HDMI_OUT :return tb_dp_port_is_enabled (port); +case TB_TYPE_USB_UP : +case TB_TYPE_USB_DOWN : +return tb_usb_port_is_enabled (port); +
drivers/thunderbolt/switch.c bool tb_port_is_enabled(struct tb_port *port) · line 1041
Quoted 10 lines
drivers/thunderbolt/switch.c +5
-0default :return false; } } +/** +* tb_usb_port_is_enabled() - Is the USB adapter port enabled +* @port: USB port to check +*/ +bool tb_usb_port_is_enabled (struct tb_port *port)
Should these functions be called tb_usb3_port... ? This looks like all USB would need this.
drivers/thunderbolt/switch.c bool tb_port_is_enabled(struct tb_port *port) · line 1042
Quoted 2 lines
drivers/thunderbolt/switch.c +1
-1-static const char *const tb_tunnel_names[] = {"PCI" ,"DP" ,"DMA" }; +static const char *const tb_tunnel_names[] = {"PCI" ,"DP" ,"DMA" ,"USB" };
USB3 ?
Regards
Oliver
Re: [RFC PATCH 20/22] thunderbolt: Add support for USB tunnels
Quoted 43 lines · Oliver Neukum
Am Dienstag, den 01.10.2019, 14:38 +0300 schrieb Mika Westerberg:
Quoted 42 lines
From: Rajmohan Mani <[email protected]>
USB4 added a capability to tunnel USB 3.x protocol over the USB4 fabric. USB4 device routers may include integrated SuperSpeed HUB or a function or both. USB tunneling follows PCIe so that the tunnel is created between the parent and the child router from USB downstream adapter port to USB upstream adapter port over a single USB4 link.
This adds support for USB tunneling and also capability to discover existing USB tunnels (for example created by connection manager in boot firmware).
Signed-off-by Rajmohan Mani <[email protected]>Co-developed-by Mika Westerberg <[email protected]>Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/switch.c | 35 ++++++++ drivers/thunderbolt/tb.c | 153 ++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 15 ++++ drivers/thunderbolt/tb_regs.h | 9 +- drivers/thunderbolt/tunnel.c | 158 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 9 ++ drivers/thunderbolt/usb4.c | 41 ++++++++- 7 files changed, 393 insertions(+), 27 deletions(-)drivers/thunderbolt/switch.c +4
-0@@ -1025,11 +1025,46 @@ bool tb_port_is_enabled(struct tb_port *port)case TB_TYPE_DP_HDMI_OUT :return tb_dp_port_is_enabled (port); +case TB_TYPE_USB_UP : +case TB_TYPE_USB_DOWN : +return tb_usb_port_is_enabled (port); +default :return false; } }
Quoted 8 lines
drivers/thunderbolt/switch.c bool tb_port_is_enabled(struct tb_port *port) · line 1041
Quoted 5 lines
drivers/thunderbolt/switch.c +5
-0+/** +* tb_usb_port_is_enabled() - Is the USB adapter port enabled +* @port: USB port to check +*/ +bool tb_usb_port_is_enabled (struct tb_port *port)Should these functions be called
tb_usb3_port... ? This looks like all USB would need this.
Yes, I agree it follows the spec better that way.
Quoted 4 lines
drivers/thunderbolt/switch.c bool tb_port_is_enabled(struct tb_port *port) · line 1042
Quoted 2 lines
drivers/thunderbolt/switch.c +1
-1-static const char *const tb_tunnel_names[] = {"PCI" ,"DP" ,"DMA" }; +static const char *const tb_tunnel_names[] = {"PCI" ,"DP" ,"DMA" ,"USB" };USB3 ?
Sure.
RFC PATCH 21/22 thunderbolt: Update documentation with the USB4 information
In reply to Mika WesterbergUpdate user's and administrator's guide to mention USB4, how it relates to Thunderbolt (it is public spec of Thunderbolt 3) and and how it is supported in Linux.
--- Documentation/admin-guide/thunderbolt.rst | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
Documentation/admin-guide/thunderbolt.rst +22 -5
@@ -1,6 +1,25 @@ -============= - Thunderbolt -============= +====================== + Thunderbolt and USB4 +====================== +USB4 is the public spec of Thunderbolt 3 with some differences at the +register level among other things. There are two different +implementations available: firmware connection manager and software +connection manager. Typically PCs come with a firmware connection +manager for Thunderbolt 3 and early USB4 capable systems. Apple systems +on the other hand use software connection manager and the future USB4 +compliant PCs follow the suit. + +The Linux Thunderbolt driver supports both and can detect at runtime +which connection manager implementation is to be used. To be on the safe +side the software connection manager in Linux also advertises security +level ``user`` which means PCIe tunneling is disabled by default. The +documentation below applies to both implementations with the exception +that the software connection manager only supports ``user`` security +level and is expected to be accompanied with an IOMMU based DMA +protection. + +Security levels and how to use them +----------------------------------- The interface presented here is not meant for end users. Instead there should be a userspace tool that handles all the low-level details, keeps a database of the authorized devices and prompts users for new connections.
@@ -18,8 +37,6 @@ This will authorize all devices automatically when they appear. However, keep in mind that this bypasses the security levels and makes the system vulnerable to DMA attacks. -Security levels and how to use them ------------------------------------ Starting with Intel Falcon Ridge Thunderbolt controller there are 4 security levels available. Intel Titan Ridge added one more security level (usbonly). The reason for these is the fact that the connected devices can
Signature · 1 line
2.23.0
RE: [RFC PATCH 21/22] thunderbolt: Update documentation with the USB4 information
Quoted 33 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:38 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 21/22] thunderbolt: Update documentation with the USB4 information[EXTERNAL EMAIL]
Update user's and administrator's guide to mention USB4, how it relates to Thunderbolt (it is public spec of Thunderbolt 3) and and how it is supported in Linux.
Signed-off-by Mika Westerberg <[email protected]>--- Documentation/admin-guide/thunderbolt.rst | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)Documentation/admin- renamed from Documentation/admin-guide/thunderbolt.rst +0
-0
guide/thunderbolt.rst
index898ad78f3cc7..4cbed319133d100644Documentation/admin-guide/thunderbolt.rst +0
-3@@ -1,6 +1,25 @@ -============= - Thunderbolt -=============
Documentation/admin-guide/thunderbolt.rst line 10
Quoted 10 lines
Documentation/admin-guide/thunderbolt.rst +10
-0+====================== + Thunderbolt and USB4 +====================== +USB4 is the public spec of Thunderbolt 3 with some differences at the +register level among other things. There are two different +implementations available: firmware connection manager and software +connection manager. Typically PCs come with a firmware connection +manager for Thunderbolt 3 and early USB4 capable systems. Apple systems +on the other hand use software connection manager and the future USB4 +compliant PCs follow the suit.
Future isn't going to age very well. Perhaps refer instead to "later" USB4 compliant PCs.
Also, we should be seeing this stuff pop-up outside of PCs. So maybe better to just call out "devices".
Quoted 27 lines
Documentation/admin-guide/thunderbolt.rst +12
-2+ +The Linux Thunderbolt driver supports both and can detect at runtime +which connection manager implementation is to be used. To be on the safe +side the software connection manager in Linux also advertises security +level ``user`` which means PCIe tunneling is disabled by default. The +documentation below applies to both implementations with the exception +that the software connection manager only supports ``user`` security +level and is expected to be accompanied with an IOMMU based DMA +protection. + +Security levels and how to use them +----------------------------------- The interface presented here is not meant for end users. Instead there should be a userspace tool that handles all the low-level details, keeps a database of the authorized devices and prompts users for new connections.@@ -18,8 +37,6 @@ This will authorize all devices automatically when they appear. However, keep in mind that this bypasses the security levels and makes the system vulnerable to DMA attacks. -Security levels and how to use them ------------------------------------ Starting with Intel Falcon Ridge Thunderbolt controller there are 4 security levels available. Intel Titan Ridge added one more security level(usbonly). The reason for these is the fact that the connected devices can
--
2.23.0
Re: [RFC PATCH 21/22] thunderbolt: Update documentation with the USB4 information
Quoted 38 lines · On Tue, Oct 01, 2019 at 02:17:01PM +0000, [email protected] wrote:
Quoted 38 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:38 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 21/22] thunderbolt: Update documentation with the USB4 information[EXTERNAL EMAIL]
Update user's and administrator's guide to mention USB4, how it relates to Thunderbolt (it is public spec of Thunderbolt 3) and and how it is supported in Linux.
Signed-off-by Mika Westerberg <[email protected]>--- Documentation/admin-guide/thunderbolt.rst | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)Documentation/admin- renamed from Documentation/admin-guide/thunderbolt.rst +0
-0
guide/thunderbolt.rst
index898ad78f3cc7..4cbed319133d100644Documentation/admin-guide/thunderbolt.rst +5
-3@@ -1,6 +1,25 @@ -============= - Thunderbolt -============= +====================== + Thunderbolt and USB4 +====================== +USB4 is the public spec of Thunderbolt 3 with some differences at the +register level among other things. There are two different
Quoted 8 lines
Documentation/admin-guide/thunderbolt.rst line 10
Quoted 5 lines
Documentation/admin-guide/thunderbolt.rst +5
-0+implementations available: firmware connection manager and software +connection manager. Typically PCs come with a firmware connection +manager for Thunderbolt 3 and early USB4 capable systems. Apple systems +on the other hand use software connection manager and the future USB4 +compliant PCs follow the suit.Future isn't going to age very well. Perhaps refer instead to "later" USB4 compliant PCs.
Yup.
Quoted 2 lines
Also, we should be seeing this stuff pop-up outside of PCs. So maybe better to just call out "devices".
Indeed, I'll update this accordingly.
RFC PATCH 22/22 thunderbolt: Do not start firmware unless asked by the user
In reply to Mika WesterbergSince now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Make it possible for user to switch between the two by adding a module pararameter (start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.
--- drivers/thunderbolt/icm.c | 14 +++++++++++--- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-)
drivers/thunderbolt/icm.c +11 -3
@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h>
@@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4 +static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC (start_icm,"start ICM firmware if it is not running (default: false)" ); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
@@ -1353,13 +1358,16 @@ static bool icm_ar_is_supported(struct tb *tb) {struct pci_dev *upstream_port;struct icm *icm =tb_priv (tb); +u32 val;/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first. +* However, only start it if explicitly asked by the user. */ -if (!x86_apple_machine) -return true; + val =ioread32 (tb->nhi->iobase +REG_FW_STS ); +if (!(val ®_FW_STS_ICM_EN ) && !start_icm) +return false;/* * Find the upstream PCIe port in case we need to do reset
@@ -2224,7 +2232,7 @@ struct tb *icm_probe(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_ICL_NHI0 :case PCI_DEVICE_ID_INTEL_ICL_NHI1 : - icm->is_supported = icm_ar_is_supported; + icm->is_supported = icm_fr_is_supported; icm->driver_ready = icm_icl_driver_ready; icm->set_uuid = icm_icl_set_uuid; icm->device_connected = icm_icl_device_connected;
drivers/thunderbolt/tb.c +0 -4
@@ -9,7 +9,6 @@#include <linux/slab.h> #include <linux/errno.h> #include <linux/delay.h> -#include <linux/platform_data/x86/apple.h> #include "tb.h" #include "tb_regs.h"
@@ -1117,9 +1116,6 @@ struct tb *tb_probe(struct tb_nhi *nhi)struct tb_cm *tcm;struct tb *tb; -if (!x86_apple_machine) -return NULL ; - tb =tb_domain_alloc (nhi,sizeof (*tcm));if (!tb)return NULL ;
Signature · 1 line
2.23.0
RE: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user
Quoted 18 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:39 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user[EXTERNAL EMAIL]
Since now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Quoted 4 lines
Make it possible for user to switch between the two by adding a module pararameter (
start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.
If the host system firmware didn't start the ICM, does that mean SW connection manager would just take over even on systems with discrete AR/TR controllers?
Quoted 32 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/icm.c | 14 +++++++++++--- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-)drivers/thunderbolt/icm.c +5
-0@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h> @@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4 +static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC(start_icm, "start ICM firmware if it is not running (default: false)"); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1365
Quoted 8 lines
drivers/thunderbolt/icm.c +1
-0@@ -1353,13 +1358,16 @@ static bool icm_ar_is_supported(struct tb *tb) {struct pci_dev *upstream_port;struct icm *icm =tb_priv (tb); +u32 val;/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first.
This comment doesn't really seem as relevant anymore. The meaning of it has nothing to do with Apple anymore.
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1370
Quoted 7 lines
drivers/thunderbolt/icm.c +4
-2+* However, only start it if explicitly asked by the user. */ -if (!x86_apple_machine) -return true; + val =ioread32 (tb->nhi->iobase +REG_FW_STS ); +if (!(val ®_FW_STS_ICM_EN ) && !start_icm) +return false;
This code is already in icm_firmware_start. Maybe split it to a small function So you can just have the more readable
If (!icm_firmware_running(tb) && !start_icm))
Quoted 36 lines
drivers/thunderbolt/icm.c +1
-1/* * Find the upstream PCIe port in case we need to do reset @@ -2224,7 +2232,7 @@ struct tb *icm_probe(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_ICL_NHI0 :case PCI_DEVICE_ID_INTEL_ICL_NHI1 : - icm->is_supported = icm_ar_is_supported; + icm->is_supported = icm_fr_is_supported; icm->driver_ready = icm_icl_driver_ready; icm->set_uuid = icm_icl_set_uuid; icm->device_connected = icm_icl_device_connected;drivers/thunderbolt/tb.c +0
-5@@ -9,7 +9,6 @@#include <linux/slab.h> #include <linux/errno.h> #include <linux/delay.h> -#include <linux/platform_data/x86/apple.h> #include "tb.h" #include "tb_regs.h" @@ -1117,9 +1116,6 @@ struct tb *tb_probe(struct tb_nhi *nhi)struct tb_cm *tcm;struct tb *tb; -if (!x86_apple_machine) -return NULL ; - tb =tb_domain_alloc (nhi,sizeof (*tcm));if (!tb)return NULL ; --2.23.0
Re: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user
Quoted 18 lines · On Tue, Oct 01, 2019 at 02:43:15PM +0000, [email protected] wrote:
Quoted 18 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:39 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat; Rajmohan Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user[EXTERNAL EMAIL]
Since now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Quoted 7 lines
Quoted 4 lines
Make it possible for user to switch between the two by adding a module pararameter (
start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.If the host system firmware didn't start the ICM, does that mean SW connection manager would just take over even on systems with discrete AR/TR controllers?
Yes. This is pretty much the case with Apple systems now.
Quoted 37 lines
Quoted 37 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/icm.c | 14 +++++++++++--- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-)drivers/thunderbolt/icm.c +5
-0@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h> @@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4 +static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC(start_icm, "start ICM firmware if it is not running (default: false)"); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
drivers/thunderbolt/icm.c +1
-0@@ -1353,13 +1358,16 @@ static bool icm_ar_is_supported(struct tb *tb) {struct pci_dev *upstream_port;struct icm *icm =tb_priv (tb); +u32 val;
Quoted 6 lines
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1365
Quoted 3 lines
drivers/thunderbolt/icm.c +0
-0/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first. This comment doesn't really seem as relevant anymore. The meaning of it has nothing to do with Apple anymore.
Actually it is still relevant. For USB4 the intent is to have FW/SW CM switch in ACPI spec instead. But that is still under discussion.
Quoted 11 lines
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1370
Quoted 7 lines
drivers/thunderbolt/icm.c +4
-2+* However, only start it if explicitly asked by the user. */ -if (!x86_apple_machine) -return true; + val =ioread32 (tb->nhi->iobase +REG_FW_STS ); +if (!(val ®_FW_STS_ICM_EN ) && !start_icm) +return false;This code is already in
icm_firmware_start. Maybe split it to a small function So you can just have the more readable
Quoted 1 line
If (!icm_firmware_running(tb) && !start_icm))
Good point. I'll do that.
RE: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user
Quoted 41 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 9:59 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user[EXTERNAL EMAIL]
Quoted 5 lines · On Tue, Oct 01, 2019 at 02:43:15PM +0000, [email protected] wrote:
Quoted 5 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:39 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat;Rajmohan
Quoted 3 lines
Quoted 3 lines
Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked bythe
Quoted 15 lines
Quoted 14 lines
user
[EXTERNAL EMAIL]
Since now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Make it possible for user to switch between the two by adding a module pararameter (
start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.
Quoted 4 lines
Quoted 2 lines
If the host system firmware didn't start the ICM, does that mean SW connection manager would just take over even on systems with discrete AR/TR controllers?
Yes. This is pretty much the case with Apple systems now.
Potentially if system firmware started ICM can we accomplish the same thing by resetting AR/TR that normally use ICM and then SW CM would take over?
Or is the ICM started up automatically when the controller is power cycled based on something in the NVM?
I'm trying to find a way that I can usefully exercise some of this stuff on pre-USB4 controllers like AR/TR/ICL-TBT.
Quoted 46 lines
Quoted 24 lines
Quoted 24 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/icm.c | 14 +++++++++++--- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-)drivers/thunderbolt/icm.c +1
-0@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h> @@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4Quoted 3 lines
drivers/thunderbolt/icm.c
Quoted 3 lines
drivers/thunderbolt/icm.c +3
-0+static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC(start_icm, "start ICM firmware if it is not running(default:
Quoted 11 lines
Quoted 11 lines
drivers/thunderbolt/icm.c +1
-0false)"); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
drivers/thunderbolt/icm.c +1
-0@@ -1353,13 +1358,16 @@ static bool icm_ar_is_supported(struct tb *tb) {struct pci_dev *upstream_port;struct icm *icm =tb_priv (tb); +u32 val;Quoted 6 lines
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1365
Quoted 3 lines
drivers/thunderbolt/icm.c +0
-0/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first. This comment doesn't really seem as relevant anymore. The meaning of it has nothing to do with Apple anymore.
Quoted 2 lines
Actually it is still relevant. For USB4 the intent is to have FW/SW CM switch in ACPI spec instead. But that is still under discussion.
Like read a hint from an ACPI table that indicates which one driver should use?
The idea being early USB4 systems would test and ship with this bit set to FW CM and later USB4 systems can have it set to SW CM?
I like that idea, but I think that you almost want the module parameter to indicate which CM you want to "use" instead so you would override what was set in ACPI either way, but default to auto.
cm=auto
TBT3 and less: follow NVM behavior
USB4: follow ACPI table, either use FW or SW CM.
cm=icm
Start up ICM, or error out if you can't.
cm=sw
Stop ICM if it's running, and initialize using kernel CM.
That would certainly allow running this across some more configurations really easily then.
Quoted 15 lines
Quoted 12 lines
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1370
Quoted 8 lines
drivers/thunderbolt/icm.c +4
-2+* However, only start it if explicitly asked by the user. */ -if (!x86_apple_machine) -return true; + val =ioread32 (tb->nhi->iobase +REG_FW_STS ); +if (!(val ®_FW_STS_ICM_EN ) && !start_icm) +return false;This code is already in
icm_firmware_start. Maybe split it to a small function So you can just have the more readableQuoted 1 line
If (!icm_firmware_running(tb) && !start_icm))
Good point. I'll do that.
Re: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user
Quoted 44 lines · On Tue, Oct 01, 2019 at 04:53:54PM +0000, [email protected] wrote:
Quoted 44 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 9:59 AM
To: Limonciello, Mario
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked by the user[EXTERNAL EMAIL]
Quoted 5 lines · On Tue, Oct 01, 2019 at 02:43:15PM +0000, [email protected] wrote:
Quoted 5 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Tuesday, October 1, 2019 6:39 AM
To: [email protected]
Cc: Andreas Noever; Michael Jamet; Mika Westerberg; Yehezkel Bernat;Rajmohan
Quoted 3 lines
Quoted 3 lines
Mani; Nicholas Johnson; Lukas Wunner; Greg Kroah-Hartman; Alan Stern; Limonciello, Mario; Anthony Wong; [email protected]
Subject: [RFC PATCH 22/22] thunderbolt: Do not start firmware unless asked bythe
Quoted 17 lines
Quoted 10 lines
user
[EXTERNAL EMAIL]
Since now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Quoted 4 lines
Make it possible for user to switch between the two by adding a module pararameter (
start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.If the host system firmware didn't start the ICM, does that mean SW connection manager would just take over even on systems with discrete AR/TR controllers?
Quoted 7 lines
Quoted 1 line
Yes. This is pretty much the case with Apple systems now.
Potentially if system firmware started ICM can we accomplish the same thing by resetting AR/TR that normally use ICM and then SW CM would take over?
Or is the ICM started up automatically when the controller is power cycled based on something in the NVM?
It is something in the NVM :)
Quoted 2 lines
I'm trying to find a way that I can usefully exercise some of this stuff on pre-USB4 controllers like AR/TR/ICL-TBT.
Only way I can think of is to find yourself a Mac ;-)
Quoted 44 lines
Quoted 44 lines
Quoted 22 lines
Quoted 22 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/thunderbolt/icm.c | 14 +++++++++++--- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-)drivers/thunderbolt/icm.c +1
-0@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h> @@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4Quoted 3 lines
drivers/thunderbolt/icm.c
Quoted 3 lines
drivers/thunderbolt/icm.c +3
-0+static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC(start_icm, "start ICM firmware if it is not running(default:
Quoted 17 lines
Quoted 6 lines
drivers/thunderbolt/icm.c +1
-0false)"); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
drivers/thunderbolt/icm.c static bool icm_ar_is_supported(struct tb *tb) · line 1365
Quoted 8 lines
drivers/thunderbolt/icm.c +1
-0@@ -1353,13 +1358,16 @@ static bool icm_ar_is_supported(struct tb *tb) {struct pci_dev *upstream_port;struct icm *icm =tb_priv (tb); +u32 val;/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first. This comment doesn't really seem as relevant anymore. The meaning of it has nothing to do with Apple anymore.
Quoted 4 lines
Quoted 2 lines
Actually it is still relevant. For USB4 the intent is to have FW/SW CM switch in ACPI spec instead. But that is still under discussion.
Like read a hint from an ACPI table that indicates which one driver should use?
Yes.
I think it will be extension to _OSC but as it is still under discussion so subject to change.
Quoted 2 lines
The idea being early USB4 systems would test and ship with this bit set to FW CM and later USB4 systems can have it set to SW CM?
Correct.
Quoted 8 lines
I like that idea, but I think that you almost want the module parameter to indicate which CM you want to "use" instead so you would override what was set in ACPI either way, but default to auto.
cm=auto
TBT3 and less: follow NVM behavior
USB4: follow ACPI table, either use FW or SW CM.
Quoted 7 lines
cm=icm
Start up ICM, or error out if you can't.cm=sw
Stop ICM if it's running, and initialize using kernel CM.That would certainly allow running this across some more configurations really easily then.
The point with start_icm is to act as "chicken bit" in case SW CM (Linux driver) does not work properly. Nothing else. User can then switch back to FW CM on their Apple system and get more "working" system hopefully reporting this to us so we can try to figure out what's wrong with the driver :)
I don't think it is good idea to have a module parameter to control anything else that is supposed to be set in the BIOS/boot firmware.
Greg Kroah-Hartman
maintainerQuoted 42 lines · Mika Westerberg
Hi all,
I'm sending this as RFC because the series is still missing important features such as power management so not ready for merging. However, I think it is good to get any early feedback from the community. We are working to add support for the missing features.
USB4 is the public specification of Thunderbolt 3 protocol and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_1.zip
USB4 is about tunneling different protocols over a single cable (in the same way as Thunderbolt). The current USB4 spec supports PCIe, Display Port and USB 3.x, and also software based protocols such as networking between domains (hosts).
So far PCs have been using firmware based Connection Manager and Apple systems have been using software based one. A Connection Manager is the entity that handles creation of different tunnel types through the USB4 (and Thunderbolt) fabric. With USB4 the plan is to have software based Connection Manager everywhere but some early systems will also support firmware to allow OS downgrade for example.
Current Linux Thunderbolt driver supports both "modes" and can detect which one to use dynamically.
This series first adds support for Thunderbolt 3 devices to the software connection manager and then extends that to support USB4 compliant hosts and devices (this applies to both firmware and software based connection managers). With this series the following features are supported also for USB4 compliant devices:
- PCIe tunneling
- Display Port tunneling
- USB 3.x tunneling
- P2P networking (implemented indrivers/net/thunderbolt.c)
- Host and device NVM firmware upgradeWe also add two new sysfs attributes under each device that expose link speed and width to userspace. The rest of the userspace ABI stays the same.
Quoted 7 lines
I'm including Linux USB folks as well because USB4 is officially coming from USB-IF which puts us on same boat now.
While I changed the user visible
Kconfigstring to mention "USB4" (theKconfigoption is stillCONFIG_THUNDERBOLT), I'm wondering whether we should move the whole Thunderbolt driver underdrivers/usb/thunderboltas well?
Looks "interesting", nice work!
I stopped at patch "Add initial support for USB4" as I don't think we want to add USB4 code to a system that we know does not have it, right?
Everything up to then is just "normal" thunderbolt, and with the exception of a few minor comments, all look fine to me.
I didn't actually read the USB4 patch just yet, as I figured we needed to argue about that some more :)
thanks,
greg k-h
Quoted 46 lines · Greg Kroah-Hartman
Quoted 45 lines · Mika Westerberg
Hi all,
I'm sending this as RFC because the series is still missing important features such as power management so not ready for merging. However, I think it is good to get any early feedback from the community. We are working to add support for the missing features.
USB4 is the public specification of Thunderbolt 3 protocol and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_1.zip
USB4 is about tunneling different protocols over a single cable (in the same way as Thunderbolt). The current USB4 spec supports PCIe, Display Port and USB 3.x, and also software based protocols such as networking between domains (hosts).
So far PCs have been using firmware based Connection Manager and Apple systems have been using software based one. A Connection Manager is the entity that handles creation of different tunnel types through the USB4 (and Thunderbolt) fabric. With USB4 the plan is to have software based Connection Manager everywhere but some early systems will also support firmware to allow OS downgrade for example.
Current Linux Thunderbolt driver supports both "modes" and can detect which one to use dynamically.
This series first adds support for Thunderbolt 3 devices to the software connection manager and then extends that to support USB4 compliant hosts and devices (this applies to both firmware and software based connection managers). With this series the following features are supported also for USB4 compliant devices:
- PCIe tunneling
- Display Port tunneling
- USB 3.x tunneling
- P2P networking (implemented indrivers/net/thunderbolt.c)
- Host and device NVM firmware upgradeWe also add two new sysfs attributes under each device that expose link speed and width to userspace. The rest of the userspace ABI stays the same.
I'm including Linux USB folks as well because USB4 is officially coming from USB-IF which puts us on same boat now.
Quoted 6 lines
Quoted 4 lines
While I changed the user visible
Kconfigstring to mention "USB4" (theKconfigoption is stillCONFIG_THUNDERBOLT), I'm wondering whether we should move the whole Thunderbolt driver underdrivers/usb/thunderboltas well?Looks "interesting", nice work!
Thanks!
Quoted 2 lines
I stopped at patch "Add initial support for USB4" as I don't think we want to add USB4 code to a system that we know does not have it, right?
You can connect a USB4 device to Thunderbolt 3 system. USB4 hubs specifically are required to support this by the spec. Of course then it is in Thunderbolt 3 alternate mode (not in USB4 native mode) but the USB4 register set is still there. So for example we still need to configure TMU (Time Management Unit) and access the DROM via router operations and so on.
Do you mean we don't want that?
Quoted 5 lines
Everything up to then is just "normal" thunderbolt, and with the exception of a few minor comments, all look fine to me.
I didn't actually read the USB4 patch just yet, as I figured we needed to argue about that some more :)
Heh, sure and thanks for the feedback so far :)