Introduce Thunderbolt/USB4 <-> USB Type-C port mapping
Subsystems (3)
cover Introduce Thunderbolt/USB4 <-> USB Type-C port mapping
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
Alan Borzeszkowski (3):
thunderbolt: Expose usb4_port_index() to other modules
thunderbolt: Add Thunderbolt/USB4 <-> USB3 match function
usb: typec: Connect Type-C port with associated USB4 port
drivers/thunderbolt/tb.h | 1 + drivers/thunderbolt/usb4.c | 14 +++++++-- drivers/thunderbolt/usb4_port.c | 56 ++++++++++++++++++++++++++++----- drivers/usb/typec/port-mapper.c | 23 ++++++++++++-- include/linux/thunderbolt.h | 18 +++++++++++ 5 files changed, 99 insertions(+), 13 deletions(-)
base-commit: 306a14d03f47fa152c7e47be544d8d582d387a20
Signature · 1 line
2.43.0
PATCH 1/3 thunderbolt: Expose usb4_port_index() to other modules
Make usb4_port_index() available to other files in the driver, rename and add function documentation.
--- drivers/thunderbolt/tb.h | 1 + drivers/thunderbolt/usb4.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/thunderbolt/tb.h +1 -0
@@ -1481,6 +1481,7 @@ static inline struct usb4_port *tb_to_usb4_port_device(struct device *dev)struct usb4_port *usb4_port_device_add (struct tb_port *port);void usb4_port_device_remove (struct usb4_port *usb4);int usb4_port_device_resume (struct usb4_port *usb4); +int usb4_port_index (const struct tb_switch *sw,const struct tb_port *port);static inline bool usb4_port_device_is_offline (const struct usb4_port *usb4) {
drivers/thunderbolt/usb4.c +11 -3
@@ -935,7 +935,15 @@ int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in)return status ? -EIO :0 ; } -static int usb4_port_idx (const struct tb_switch *sw,const struct tb_port *port) +/** +* usb4_port_index() - Finds matching USB4 port index +* @sw: USB4 router +* @port: USB4 protocol or lane adapter +* +* Finds matching USB4 port index (starting from %0) that given @port goes +* through. +*/ +int usb4_port_index (const struct tb_switch *sw,const struct tb_port *port) {struct tb_port *p;int usb4_idx =0 ;
@@ -969,7 +977,7 @@ static int usb4_port_idx(const struct tb_switch *sw, const struct tb_port *port)struct tb_port *usb4_switch_map_pcie_down (struct tb_switch *sw,const struct tb_port *port) { -int usb4_idx =usb4_port_idx (sw, port); +int usb4_idx =usb4_port_index (sw, port);struct tb_port *p;int pcie_idx =0 ;
@@ -1000,7 +1008,7 @@ struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw,struct tb_port *usb4_switch_map_usb3_down (struct tb_switch *sw,const struct tb_port *port) { -int usb4_idx =usb4_port_idx (sw, port); +int usb4_idx =usb4_port_index (sw, port);struct tb_port *p;int usb_idx =0 ;
Signature · 1 line
2.43.0
PATCH 2/3 thunderbolt: Add Thunderbolt/USB4 <-> USB3 match function
In reply to Alan BorzeszkowskiThis function checks whether given USB4 port device matches with USB3.x port device, using ACPI _DSD property.
It is designed to be used by component framework to match USB4 ports with Type-C ports they are connected to.
Also, added USB4 config stub in case mapping function is not reachable.
--- drivers/thunderbolt/usb4_port.c | 56 ++++++++++++++++++++++++++++----- include/linux/thunderbolt.h | 18 +++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-)
drivers/thunderbolt/usb4_port.c +48 -8
@@ -105,6 +105,49 @@ static void usb4_port_online(struct usb4_port *usb4)tb_acpi_power_off_retimers (port); } +/** +* usb4_usb3_port_match() - Matches USB4 port device with USB 3.x port device +* @usb4_port_dev: USB4 port device +* @usb3_port_fwnode: USB 3.x port firmware node +* +* Checks if USB 3.x port @usb3_port_fwnode is tunneled through USB4 port @usb4_port_dev. +* Returns true if match is found, false otherwise. +* +* Function is designed to be used with component framework (component_match_add). +*/ +bool usb4_usb3_port_match (struct device *usb4_port_dev, +const struct fwnode_handle *usb3_port_fwnode) +{ + struct fwnode_handle *nhi_fwnode __free(fwnode_handle) = NULL; +struct usb4_port *usb4; +struct tb_switch *sw; +struct tb_nhi *nhi; +u8 usb4_port_num; +struct tb *tb; + + usb4 =tb_to_usb4_port_device (usb4_port_dev); +if (!usb4) +return false; + + sw = usb4->port->sw; + tb = sw->tb; + nhi = tb->nhi; + + nhi_fwnode =fwnode_find_reference (usb3_port_fwnode,"usb4-host-interface" ,0 ); +if (IS_ERR (nhi_fwnode)) +return false; + +/* Check if USB3 fwnode references same NHI where USB4 port resides */ +if (!device_match_fwnode (&nhi->pdev->dev, nhi_fwnode)) +return false; + +if (fwnode_property_read_u8 (usb3_port_fwnode,"usb4-port-number" , &usb4_port_num)) +return false; + +return usb4_port_index (sw, usb4->port) == usb4_port_num; +} +EXPORT_SYMBOL_GPL (usb4_usb3_port_match); +static ssize_t offline_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -276,12 +319,10 @@ struct usb4_port *usb4_port_device_add(struct tb_port *port)return ERR_PTR (ret); } -if (dev_fwnode (&usb4->dev)) { - ret =component_add (&usb4->dev, &connector_ops); -if (ret) { -dev_err (&usb4->dev,"failed to add component\n" ); -device_unregister (&usb4->dev); - } + ret =component_add (&usb4->dev, &connector_ops); +if (ret) { +dev_err (&usb4->dev,"failed to add component\n" ); +device_unregister (&usb4->dev); }if (!tb_is_upstream_port (port))
@@ -306,8 +347,7 @@ struct usb4_port *usb4_port_device_add(struct tb_port *port)*/ void usb4_port_device_remove (struct usb4_port *usb4) { -if (dev_fwnode (&usb4->dev)) -component_del (&usb4->dev, &connector_ops); +component_del (&usb4->dev, &connector_ops);device_unregister (&usb4->dev); }
include/linux/thunderbolt.h +18 -0
@@ -11,6 +11,13 @@#ifndef THUNDERBOLT_H_ #define THUNDERBOLT_H_ +#include <linux/types.h> + +struct fwnode_handle ; +struct device ; + +#if IS_REACHABLE (CONFIG_USB4 ) +#include <linux/device.h> #include <linux/idr.h> #include <linux/list.h>
@@ -674,4 +681,15 @@ static inline struct device *tb_ring_dma_device(struct tb_ring *ring)return &ring->nhi->pdev->dev; } +bool usb4_usb3_port_match (struct device *usb4_port_dev, +const struct fwnode_handle *usb3_port_fwnode); + +#else /* CONFIG_USB4 */ +static inline bool usb4_usb3_port_match (struct device *usb4_port_dev, +const struct fwnode_handle *usb3_port_fwnode) +{ +return false; +} +#endif /* CONFIG_USB4 */ +#endif /* THUNDERBOLT_H_ */
Signature · 1 line
2.43.0
PATCH 3/3 usb: typec: Connect Type-C port with associated USB4 port
In reply to Alan BorzeszkowskiIf USB3.x device references USB4 host interface, USB4 port can be connected with appropriate Type-C port. By using component framework, and in turn by creating symlinks, userspace can benefit from having Thunderbolt/USB4 connection to Type-C ports.
Note: This change introduces dependency on Thunderbolt driver as it's required to properly map USB4 port to Type-C port.
--- drivers/usb/typec/port-mapper.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/usb/typec/port-mapper.c +21 -2
@@ -8,6 +8,7 @@#include <linux/acpi.h> #include <linux/component.h> +#include <linux/thunderbolt.h> #include <linux/usb.h> #include "class.h"
@@ -36,6 +37,11 @@ struct each_port_arg {struct component_match *match; }; +static int usb4_port_compare (struct device *dev,void *fwnode) +{ +return usb4_usb3_port_match (dev, fwnode); +} +static int typec_port_compare (struct device *dev,void *fwnode) {return device_match_fwnode (dev, fwnode);
@@ -51,9 +57,22 @@ static int typec_port_match(struct device *dev, void *data)if (con_adev == adev)return 0 ; -if (con_adev->pld_crc == adev->pld_crc) +if (con_adev->pld_crc == adev->pld_crc) { +struct fwnode_handle *adev_fwnode =acpi_fwnode_handle (adev); +component_match_add (&arg->port->dev, &arg->match, typec_port_compare, -acpi_fwnode_handle (adev)); + adev_fwnode); + +/* +* If dev is USB 3.x port, it may have reference to the +* USB4 host interface in which case we can also link the +* Type-C port with the USB4 port. +*/ +if (fwnode_property_present (adev_fwnode,"usb4-host-interface" )) +component_match_add (&arg->port->dev, &arg->match, + usb4_port_compare, adev_fwnode); + } +return 0 ; }
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 7 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
"mapping" in what way? sysfs links? If so, care to add Documentation/ABI/ updates?
thanks,
greg k-h
Heikki Krogerus
maintainerHi Greg,
Quoted 11 lines · Greg KH
Quoted 7 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
"mapping" in what way? sysfs links? If so, care to add
Documentation/ABI/updates?
It is already there:
https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-bus-thunderbolt-devices-usb4-portx-connector
The link is already created on Cromebooks like Alan explained, because there each USB4/TBT port has a device node in the ACPI tables with the appropriate _PLD (Physical Location of Device), but on systems targeted primarily for Windows, that is not the case. There ports do not have device nodes, so we can't make the link based on _PLD.
This series makes that same link by taking advantage of the "usb4-host-interface" _DSD device property [1] that we always have on those Windows platforms. That same device property that we also use in drivers/usb/code/usb-acpi.c, and probable some other places too.
[1] https://www.usb.org/sites/default/files/D1T2-2%20-%20USB4%20on%20Windows.pdf
thanks,
Signature · 1 line
heikki
Greg KH
maintainerQuoted 24 lines · Heikki Krogerus
Hi Greg,
Quoted 11 lines · Greg KH
Quoted 7 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
"mapping" in what way? sysfs links? If so, care to add
Documentation/ABI/updates?It is already there:
https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-bus-thunderbolt-devices-usb4-portx-connectorThe link is already created on Cromebooks like Alan explained, because there each USB4/TBT port has a device node in the ACPI tables with the appropriate
_PLD(Physical Location of Device), but on systems targeted primarily for Windows, that is not the case. There ports do not have device nodes, so we can't make the link based on_PLD.
Quoted 6 lines
This series makes that same link by taking advantage of the "usb4-host-interface"
_DSDdevice property [1] that we always have on those Windows platforms. That same device property that we also use indrivers/usb/code/usb-acpi.c, and probable some other places too.[1] https://www.usb.org/sites/default/files/D1T2-2%20-%20USB4%20on%20Windows.pdf
Thanks for the information, sorry I had missed that it was already there.
greg k-h
Greg KH
maintainerQuoted 21 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
Alan Borzeszkowski (3):
thunderbolt: Exposeusb4_port_index()to other modules
thunderbolt: Add Thunderbolt/USB4 <-> USB3 match function
usb: typec: Connect Type-C port with associated USB4 portdrivers/thunderbolt/tb.h | 1 + drivers/thunderbolt/usb4.c | 14 +++++++-- drivers/thunderbolt/usb4_port.c | 56 ++++++++++++++++++++++++++++----- drivers/usb/typec/port-mapper.c | 23 ++++++++++++-- include/linux/thunderbolt.h | 18 +++++++++++ 5 files changed, 99 insertions(+), 13 deletions(-)
Quoted 5 lines
base-commit:
306a14d03f47fa152c7e47be544d8d582d387a20Signature · 1 line
2.43.0
I'm guessing that these will come through the thunderbolt tree to me?
Quoted 22 lines · Greg KH
Quoted 21 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
Alan Borzeszkowski (3):
thunderbolt: Exposeusb4_port_index()to other modules
thunderbolt: Add Thunderbolt/USB4 <-> USB3 match function
usb: typec: Connect Type-C port with associated USB4 portdrivers/thunderbolt/tb.h | 1 + drivers/thunderbolt/usb4.c | 14 +++++++-- drivers/thunderbolt/usb4_port.c | 56 ++++++++++++++++++++++++++++----- drivers/usb/typec/port-mapper.c | 23 ++++++++++++-- include/linux/thunderbolt.h | 18 +++++++++++ 5 files changed, 99 insertions(+), 13 deletions(-)
Quoted 7 lines
Quoted 5 lines
base-commit:
306a14d03f47fa152c7e47be544d8d582d387a20Signature · 1 line
2.43.0I'm guessing that these will come through the thunderbolt tree to me?
Yes, I will pick them up and send to you with the rest of the v6.16 stuff.
Quoted 8 lines · Alan Borzeszkowski
Hello everyone,
This patch series introduces the creation of symlinks between Thunderbolt/USB4 ports and their corresponding USB Type-C ports. The primary goal is to provide users with clear visibility into which USB4 port is connected via a specific Type-C port. This provides the same functionality that is already present in Chromebooks.
Quoted 4 lines
Alan Borzeszkowski (3):
thunderbolt: Exposeusb4_port_index()to other modules
thunderbolt: Add Thunderbolt/USB4 <-> USB3 match function
usb: typec: Connect Type-C port with associated USB4 port
All applied to thunderbolt.git/next, thanks!