Thunderbolt networking
Subsystems (5)
v3 cover Thunderbolt networking
Hi,
In addition of tunneling PCIe, Display Port and USB traffic, Thunderbolt allows connecting two hosts (domains) over a Thunderbolt cable. It is possible to tunnel arbitrary data packets over such connection using high-speed DMA rings available in the Thunderbolt host controller.
In order to discover Thunderbolt services the other host supports, there is a software protocol running on top of the automatically configured control channel (ring 0). This protocol is called XDomain discovery protocol and it uses XDomain properties to describe the host (domain) and the services it supports.
Once both sides have agreed what services are supported they can enable high-speed DMA rings to transfer data over the cable.
This series adds support for the XDomain protocol so that we expose each remote connection as Thunderbolt XDomain device and each service as Thunderbolt service device. On top of that we create an API that allows writing drivers for these services and finally we provide an example Thunderbolt service driver that creates virtual ethernet inferface that allows tunneling networking packets over Thunderbolt cable. The API could be used for creating other future Thunderbolt services, such as tunneling SCSI over Thunderbolt, for example.
The XDomain protocol and networking support is also available in macOS and Windows so this makes it possible to connect Linux to macOS and Windows as well.
The patches are based on previous Thunderbolt networking patch series by Amir Levy and Michael Jamet, that can be found here:
https://lwn.net/Articles/705998/
The main difference to that patch series is that we have the XDomain protocol running in the kernel now so there is no need for a separate userspace daemon.
Note this does not affect the existing functionality, so security levels and NVM firmware upgrade continue to work as before (with the small exception that now sysfs also shows the XDomain connections and services in addition to normal Thunderbolt devices). It is also possible to connect up to 5 Thunderbolt devices and then another host, and the network driver works exactly the same.
This is third version of the patch series. The previous versions can be be found here:
v2: https://lkml.org/lkml/2017/9/25/225
v1: https://lwn.net/Articles/734019/
Changes from the v2:
* Add comment regarding calculation of interrupt throttling value
* Add UUIDs as strings in comments on top of each declaration
* Add a patch removing __packed from existing ICM messages. They are all 32-bit aligned and should pack fine without the __packed.
* Move adding MAINTAINERS entries to a separate patches
* Added Michael and Yehezkel to be maintainers of the network driver
* Remove __packed from the new ICM messages. They should pack fine as well without it.
* Call register_netdev() after all other initialization is done in the network driver.
* Use build_skb() instead of copying. We allocate order 1 page here to leave room for SKB shared info required by build_skb(). However, we do not leave room for full NET_SKB_PAD because the NHI hardware does not cope well if a frame crosses 4kB boundary. According comments in __build_skb() that should still be fine.
* Added Reviewed-by tag from Andy.
Changes from the v1:
* Add include/linux/thunderbolt.h to MAINTAINERS
* Correct Linux version and date of new sysfs entries in Documentation/ABI/testing/sysfs-bus-thunderbolt
* Move network driver from drivers/thunderbolt/net.c to drivers/net/thunderbolt.c and update it to follow coding style in drivers/net/*.
* Add MAINTAINERS entry for the network driver
* Minor cleanups
In case someone wants to try this out, the last patch adds documentation how the networking driver can be used. In short, if you connect Linux to a macOS or Windows, everything is done automatically (as those systems have the networking service enabled by default). For Linux to Linux connection one host needs to load the networking driver first (so that the other side can locate the networking service and load the corresponding driver).
Amir Levy (1):
net: Add support for networking over Thunderbolt cable
Mika Westerberg (18):
byteorder: Move {cpu_to_be32,be32_to_cpu}_array() from Thunderbolt to core
thunderbolt: Remove __packed from ICM message structures
thunderbolt: Add support for XDomain properties
thunderbolt: Move enum tb_cfg_pkg_type to thunderbolt.h
thunderbolt: Move thunderbolt domain structure to thunderbolt.h
thunderbolt: Move tb_switch_phy_port_from_link() to thunderbolt.h
thunderbolt: Add support for XDomain discovery protocol
thunderbolt: Configure interrupt throttling for all interrupts
thunderbolt: Add support for frame mode
thunderbolt: Export ring handling functions to modules
thunderbolt: Move ring descriptor flags to thunderbolt.h
thunderbolt: Use spinlock in ring serialization
thunderbolt: Use spinlock in NHI serialization
thunderbolt: Add polling mode for rings
thunderbolt: Add function to retrieve DMA device for the ring
thunderbolt: Allocate ring HopID automatically if requested
MAINTAINERS: Add thunderbolt.h to the Thunderbolt driver entry
MAINTAINERS: Add entry for Thunderbolt network driver
Documentation/ABI/testing/sysfs-bus-thunderbolt | 48 + Documentation/admin-guide/thunderbolt.rst | 24 + MAINTAINERS | 9 + drivers/net/Kconfig | 12 + drivers/net/Makefile | 3 + drivers/net/thunderbolt.c | 1362 ++++++++++++++++++++ drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/ctl.c | 46 +- drivers/thunderbolt/ctl.h | 3 +- drivers/thunderbolt/domain.c | 197 ++- drivers/thunderbolt/icm.c | 218 +++- drivers/thunderbolt/nhi.c | 410 ++++-- drivers/thunderbolt/nhi.h | 141 +- drivers/thunderbolt/nhi_regs.h | 11 +- drivers/thunderbolt/property.c | 670 ++++++++++ drivers/thunderbolt/switch.c | 7 +- drivers/thunderbolt/tb.h | 88 +- drivers/thunderbolt/tb_msgs.h | 168 ++- drivers/thunderbolt/xdomain.c | 1576 +++++++++++++++++++++++ include/linux/byteorder/generic.h | 16 + include/linux/mod_devicetable.h | 26 + include/linux/thunderbolt.h | 598 +++++++++ scripts/mod/devicetable-offsets.c | 7 + scripts/mod/file2alias.c | 25 + 24 files changed, 5304 insertions(+), 363 deletions(-) create mode 100644 drivers/net/thunderbolt.c create mode 100644 drivers/thunderbolt/property.c create mode 100644 drivers/thunderbolt/xdomain.c create mode 100644 include/linux/thunderbolt.h
Signature · 1 line
2.14.2
PATCH v3 1/19 byteorder: Move {cpu_to_be32,be32_to_cpu}_array() from Thunderbolt to core
We will be using these when communicating XDomain discovery protocol over Thunderbolt link but they might be useful for other drivers as well.
Make them available through byteorder/generic.h.
--- drivers/thunderbolt/ctl.c | 14 -------------- include/linux/byteorder/generic.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-)
drivers/thunderbolt/ctl.c +0 -14
@@ -289,20 +289,6 @@ static void tb_cfg_print_error(struct tb_ctl *ctl, } } -static void cpu_to_be32_array (__be32 *dst,const u32 *src,size_t len) -{ -int i; -for (i =0 ; i < len; i++) - dst[i] =cpu_to_be32 (src[i]); -} - -static void be32_to_cpu_array (u32 *dst,__be32 *src,size_t len) -{ -int i; -for (i =0 ; i < len; i++) - dst[i] =be32_to_cpu (src[i]); -} -static __be32 tb_crc (const void *data,size_t len) {return cpu_to_be32 (~__crc32c_le (~0 , data, len));
include/linux/byteorder/generic.h +16 -0
@@ -170,4 +170,20 @@ static inline void be64_add_cpu(__be64 *var, u64 val) *var = cpu_to_be64(be64_to_cpu(*var) + val); } +static inline void cpu_to_be32_array (__be32 *dst,const u32 *src,size_t len) +{ +int i; + +for (i =0 ; i < len; i++) + dst[i] =cpu_to_be32 (src[i]); +} + +static inline void be32_to_cpu_array (u32 *dst,const __be32 *src,size_t len) +{ +int i; + +for (i =0 ; i < len; i++) + dst[i] =be32_to_cpu (src[i]); +} +#endif /* _LINUX_BYTEORDER_GENERIC_H */
Signature · 1 line
2.14.2
PATCH v3 2/19 thunderbolt: Remove __packed from ICM message structures
In reply to Mika WesterbergThese messages are all 32-byte aligned and they should be packed without the __packed attribute just fine. It also allows compiler to generate better code on some architectures.
--- drivers/thunderbolt/tb_msgs.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/thunderbolt/tb_msgs.h +14 -14
@@ -130,7 +130,7 @@ struct icm_pkg_header {u8 flags;u8 packet_id;u8 total_packets; -} __packed; +};#define ICM_FLAGS_ERROR BIT(0)#define ICM_FLAGS_NO_KEY BIT(1)
@@ -139,20 +139,20 @@ struct icm_pkg_header {struct icm_pkg_driver_ready {struct icm_pkg_header hdr; -} __packed; +};struct icm_pkg_driver_ready_response {struct icm_pkg_header hdr;u8 romver;u8 ramver;u16 security_level; -} __packed; +};/* Falcon Ridge & Alpine Ridge common messages */ struct icm_fr_pkg_get_topology {struct icm_pkg_header hdr; -} __packed; +};#define ICM_GET_TOPOLOGY_PACKETS 14
@@ -167,7 +167,7 @@ struct icm_fr_pkg_get_topology_response {u32 reserved[2 ];u32 ports[16 ];u32 port_hop_info[16 ]; -} __packed; +};#define ICM_SWITCH_USED BIT(0)#define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1)
@@ -184,7 +184,7 @@ struct icm_fr_event_device_connected {u8 connection_id;u16 link_info;u32 ep_name[55 ]; -} __packed; +};#define ICM_LINK_INFO_LINK_MASK 0x7#define ICM_LINK_INFO_DEPTH_SHIFT 4
@@ -197,13 +197,13 @@ struct icm_fr_pkg_approve_device {u8 connection_key;u8 connection_id;u16 reserved; -} __packed; +};struct icm_fr_event_device_disconnected {struct icm_pkg_header hdr;u16 reserved;u16 link_info; -} __packed; +};struct icm_fr_pkg_add_device_key {struct icm_pkg_header hdr;
@@ -212,7 +212,7 @@ struct icm_fr_pkg_add_device_key {u8 connection_id;u16 reserved;u32 key[8 ]; -} __packed; +};struct icm_fr_pkg_add_device_key_response {struct icm_pkg_header hdr;
@@ -220,7 +220,7 @@ struct icm_fr_pkg_add_device_key_response {u8 connection_key;u8 connection_id;u16 reserved; -} __packed; +};struct icm_fr_pkg_challenge_device {struct icm_pkg_header hdr;
@@ -229,7 +229,7 @@ struct icm_fr_pkg_challenge_device {u8 connection_id;u16 reserved;u32 challenge[8 ]; -} __packed; +};struct icm_fr_pkg_challenge_device_response {struct icm_pkg_header hdr;
@@ -239,7 +239,7 @@ struct icm_fr_pkg_challenge_device_response {u16 reserved;u32 challenge[8 ];u32 response[8 ]; -} __packed; +};/* Alpine Ridge only messages */
@@ -247,7 +247,7 @@ struct icm_ar_pkg_get_route {struct icm_pkg_header hdr;u16 reserved;u16 link_info; -} __packed; +};struct icm_ar_pkg_get_route_response {struct icm_pkg_header hdr;
@@ -255,6 +255,6 @@ struct icm_ar_pkg_get_route_response {u16 link_info;u32 route_hi; u32 route_lo; -} __packed; +};#endif
Signature · 1 line
2.14.2
Re: [PATCH v3 02/19] thunderbolt: Remove __packed from ICM message structures
Quoted 1 line · Mika Westerberg
These messages are all 32-byte aligned and they should be packed
Obviously 32-bit.
Other than that,
Quoted 136 lines
without
the__packedattribute just fine. It also allows compiler to generate better code on some architectures.Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Michael Jamet <[email protected]>Reviewed-by Yehezkel Bernat <[email protected]>--- drivers/thunderbolt/tb_msgs.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)drivers/thunderbolt/tb_msgs.h +14
-14@@ -130,7 +130,7 @@ struct icm_pkg_header {u8 flags;u8 packet_id;u8 total_packets; -} __packed; +};#define ICM_FLAGS_ERROR BIT(0)#define ICM_FLAGS_NO_KEY BIT(1)@@ -139,20 +139,20 @@ struct icm_pkg_header {struct icm_pkg_driver_ready {struct icm_pkg_header hdr; -} __packed; +};struct icm_pkg_driver_ready_response {struct icm_pkg_header hdr;u8 romver;u8 ramver;u16 security_level; -} __packed; +};/* Falcon Ridge & Alpine Ridge common messages */ struct icm_fr_pkg_get_topology {struct icm_pkg_header hdr; -} __packed; +};#define ICM_GET_TOPOLOGY_PACKETS 14@@ -167,7 +167,7 @@ struct icm_fr_pkg_get_topology_response {u32 reserved[2 ];u32 ports[16 ];u32 port_hop_info[16 ]; -} __packed; +};#define ICM_SWITCH_USED BIT(0)#define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1)@@ -184,7 +184,7 @@ struct icm_fr_event_device_connected {u8 connection_id;u16 link_info;u32 ep_name[55 ]; -} __packed; +};#define ICM_LINK_INFO_LINK_MASK 0x7#define ICM_LINK_INFO_DEPTH_SHIFT 4@@ -197,13 +197,13 @@ struct icm_fr_pkg_approve_device {u8 connection_key;u8 connection_id;u16 reserved; -} __packed; +};struct icm_fr_event_device_disconnected {struct icm_pkg_header hdr;u16 reserved;u16 link_info; -} __packed; +};struct icm_fr_pkg_add_device_key {struct icm_pkg_header hdr;@@ -212,7 +212,7 @@ struct icm_fr_pkg_add_device_key {u8 connection_id;u16 reserved;u32 key[8 ]; -} __packed; +};struct icm_fr_pkg_add_device_key_response {struct icm_pkg_header hdr;@@ -220,7 +220,7 @@ struct icm_fr_pkg_add_device_key_response {u8 connection_key;u8 connection_id;u16 reserved; -} __packed; +};struct icm_fr_pkg_challenge_device {struct icm_pkg_header hdr;@@ -229,7 +229,7 @@ struct icm_fr_pkg_challenge_device {u8 connection_id;u16 reserved;u32 challenge[8 ]; -} __packed; +};struct icm_fr_pkg_challenge_device_response {struct icm_pkg_header hdr;@@ -239,7 +239,7 @@ struct icm_fr_pkg_challenge_device_response {u16 reserved;u32 challenge[8 ];u32 response[8 ]; -} __packed; +};/* Alpine Ridge only messages */ @@ -247,7 +247,7 @@ struct icm_ar_pkg_get_route {struct icm_pkg_header hdr;u16 reserved;u16 link_info; -} __packed; +};struct icm_ar_pkg_get_route_response {struct icm_pkg_header hdr;@@ -255,6 +255,6 @@ struct icm_ar_pkg_get_route_response {u16 link_info;u32 route_hi; u32 route_lo; -} __packed; +};#endif
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH v3 3/19 thunderbolt: Add support for XDomain properties
In reply to Mika WesterbergThunderbolt XDomain discovery protocol uses directories which contain properties and other directories to exchange information about what capabilities the remote host supports. This also includes identification information like device ID and name.
This adds support for parsing and formatting these properties and establishes an API drivers can use in addition to the core Thunderbolt driver. This API is exposed in a new header: include/linux/thunderbolt.h.
This code is based on the work done by Amir Levy and Michael Jamet.
--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/property.c | 670 +++++++++++++++++++++++++++++++++++++++++ include/linux/thunderbolt.h | 89 ++++++ 3 files changed, 760 insertions(+), 1 deletion(-) create mode 100644 drivers/thunderbolt/property.c create mode 100644 include/linux/thunderbolt.h
drivers/thunderbolt/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-${CONFIG_THUNDERBOLT} := thunderbolt.o thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel_pci.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o
drivers/thunderbolt/property.c new file +670 -0
670 lines not on this page · raw message
include/linux/thunderbolt.h new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH v3 4/19 thunderbolt: Move enum tb_cfg_pkg_type to thunderbolt.h
In reply to Mika WesterbergThese will be needed by Thunderbolt services when sending and receiving XDomain control messages. While there change TB_CFG_PKG_PREPARE_TO_SLEEP value to be decimal in order to be consistent with other members.
--- drivers/thunderbolt/ctl.h | 1 + drivers/thunderbolt/tb_msgs.h | 17 ----------------- include/linux/thunderbolt.h | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-)
drivers/thunderbolt/ctl.h +1 -0
@@ -8,6 +8,7 @@#define _TB_CFG#include <linux/kref.h> +#include <linux/thunderbolt.h> #include "nhi.h" #include "tb_msgs.h"
drivers/thunderbolt/tb_msgs.h +0 -17
@@ -15,23 +15,6 @@#include <linux/types.h> #include <linux/uuid.h> -enum tb_cfg_pkg_type { -TB_CFG_PKG_READ =1 , -TB_CFG_PKG_WRITE =2 , -TB_CFG_PKG_ERROR =3 , -TB_CFG_PKG_NOTIFY_ACK =4 , -TB_CFG_PKG_EVENT =5 , -TB_CFG_PKG_XDOMAIN_REQ =6 , -TB_CFG_PKG_XDOMAIN_RESP =7 , -TB_CFG_PKG_OVERRIDE =8 , -TB_CFG_PKG_RESET =9 , -TB_CFG_PKG_ICM_EVENT =10 , -TB_CFG_PKG_ICM_CMD =11 , -TB_CFG_PKG_ICM_RESP =12 , -TB_CFG_PKG_PREPARE_TO_SLEEP =0xd , - -}; -enum tb_cfg_space {TB_CFG_HOPS =0 ,TB_CFG_PORT =1 ,
include/linux/thunderbolt.h +17 -0
@@ -1,6 +1,7 @@/* * Thunderbolt service API * +* Copyright (C) 2014 Andreas Noever <[email protected]> * Copyright (C) 2017, Intel Corporation * Authors: Michael Jamet <[email protected]> * Mika Westerberg <[email protected]>
@@ -16,6 +17,22 @@#include <linux/list.h> #include <linux/uuid.h> +enum tb_cfg_pkg_type { +TB_CFG_PKG_READ =1 , +TB_CFG_PKG_WRITE =2 , +TB_CFG_PKG_ERROR =3 , +TB_CFG_PKG_NOTIFY_ACK =4 , +TB_CFG_PKG_EVENT =5 , +TB_CFG_PKG_XDOMAIN_REQ =6 , +TB_CFG_PKG_XDOMAIN_RESP =7 , +TB_CFG_PKG_OVERRIDE =8 , +TB_CFG_PKG_RESET =9 , +TB_CFG_PKG_ICM_EVENT =10 , +TB_CFG_PKG_ICM_CMD =11 , +TB_CFG_PKG_ICM_RESP =12 , +TB_CFG_PKG_PREPARE_TO_SLEEP =13 , +}; +/** * struct tb_property_dir - XDomain property directory * @uuid: Directory UUID or %NULL if root directory
Signature · 1 line
2.14.2
PATCH v3 5/19 thunderbolt: Move thunderbolt domain structure to thunderbolt.h
In reply to Mika WesterbergThese are needed by Thunderbolt services so move them to thunderbolt.h to make sure they are available outside of drivers/thunderbolt.
--- drivers/thunderbolt/tb.h | 42 ------------------------------------------ include/linux/thunderbolt.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 42 deletions(-)
drivers/thunderbolt/tb.h +0 -42
@@ -39,20 +39,6 @@ struct tb_switch_nvm {bool authenticating; }; -/** -* enum tb_security_level - Thunderbolt security level -* @TB_SECURITY_NONE: No security, legacy mode -* @TB_SECURITY_USER: User approval required at minimum -* @TB_SECURITY_SECURE: One time saved key required at minimum -* @TB_SECURITY_DPONLY: Only tunnel Display port (and USB) -*/ -enum tb_security_level { -TB_SECURITY_NONE , -TB_SECURITY_USER , -TB_SECURITY_SECURE , -TB_SECURITY_DPONLY , -}; -#define TB_SWITCH_KEY_SIZE 32/* Each physical port contains 2 links on modern controllers */ #define TB_SWITCH_LINKS_PER_PHY_PORT 2
@@ -223,33 +209,6 @@ struct tb_cm_ops {int (*disconnect_pcie_paths)(struct tb *tb); }; -/** -* struct tb - main thunderbolt bus structure -* @dev: Domain device -* @lock: Big lock. Must be held when accessing any struct -* tb_switch / struct tb_port. -* @nhi: Pointer to the NHI structure -* @ctl: Control channel for this domain -* @wq: Ordered workqueue for all domain specific work -* @root_switch: Root switch of this domain -* @cm_ops: Connection manager specific operations vector -* @index: Linux assigned domain number -* @security_level: Current security level -* @privdata: Private connection manager specific data -*/ -struct tb { -struct device dev; -struct mutex lock; -struct tb_nhi *nhi; -struct tb_ctl *ctl; -struct workqueue_struct *wq; -struct tb_switch *root_switch; -const struct tb_cm_ops *cm_ops; -int index; -enum tb_security_level security_level; -unsigned long privdata[0 ]; -}; -static inline void *tb_priv (struct tb *tb) {return (void *)tb->privdata;
@@ -368,7 +327,6 @@ static inline int tb_port_write(struct tb_port *port, const void *buffer,struct tb *icm_probe (struct tb_nhi *nhi);struct tb *tb_probe (struct tb_nhi *nhi); -extern struct bus_type tb_bus_type;extern struct device_type tb_domain_type;extern struct device_type tb_switch_type;
include/linux/thunderbolt.h +45 -0
58 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH v3 6/19 thunderbolt: Move tb_switch_phy_port_from_link() to thunderbolt.h
In reply to Mika WesterbergA Thunderbolt service might need to find the physical port from a link the cable is connected to. For instance networking driver uses this information to generate MAC address according the Apple ThunderboltIP protocol.
Move this function to thunderbolt.h and rename it to tb_phy_port_from_link() to reflect the fact that it does not take switch as parameter.
--- drivers/thunderbolt/icm.c | 2 +- drivers/thunderbolt/tb.h | 7 ------- include/linux/thunderbolt.h | 7 +++++++ 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/thunderbolt/icm.c +1 -1
@@ -89,7 +89,7 @@ static inline struct tb *icm_to_tb(struct icm *icm)static inline u8 phy_port_from_route (u64 route,u8 depth) { -return tb_switch_phy_port_from_link (route >> ((depth -1 ) *8 )); +return tb_phy_port_from_link (route >> ((depth -1 ) *8 )); }static inline u8 dual_link_from_link (u8 link)
drivers/thunderbolt/tb.h +0 -7
@@ -40,8 +40,6 @@ struct tb_switch_nvm { };#define TB_SWITCH_KEY_SIZE 32 -/* Each physical port contains 2 links on modern controllers */ -#define TB_SWITCH_LINKS_PER_PHY_PORT 2/** * struct tb_switch - a thunderbolt switch
@@ -367,11 +365,6 @@ 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); -static inline unsigned int tb_switch_phy_port_from_link (unsigned int link) -{ -return (link -1 ) /TB_SWITCH_LINKS_PER_PHY_PORT ; -} -static inline void tb_switch_put (struct tb_switch *sw) {put_device (&sw->dev);
include/linux/thunderbolt.h +7 -0
@@ -78,6 +78,13 @@ struct tb {extern struct bus_type tb_bus_type; +#define TB_LINKS_PER_PHY_PORT 2 + +static inline unsigned int tb_phy_port_from_link (unsigned int link) +{ +return (link -1 ) /TB_LINKS_PER_PHY_PORT ; +} +/** * struct tb_property_dir - XDomain property directory * @uuid: Directory UUID or %NULL if root directory
Signature · 1 line
2.14.2
PATCH v3 7/19 thunderbolt: Add support for XDomain discovery protocol
In reply to Mika WesterbergWhen two hosts are connected over a Thunderbolt cable, there is a protocol they can use to communicate capabilities supported by the host. The discovery protocol uses automatically configured control channel (ring 0) and is build on top of request/response transactions using special XDomain primitives provided by the Thunderbolt base protocol.
The capabilities consists of a root directory block of basic properties used for identification of the host, and then there can be zero or more directories each describing a Thunderbolt service and its capabilities.
Once both sides have discovered what is supported the two hosts can setup high-speed DMA paths and transfer data to the other side using whatever protocol was agreed based on the properties. The software protocol used to communicate which DMA paths to enable is service specific.
This patch adds support for the XDomain discovery protocol to the Thunderbolt bus. We model each remote host connection as a Linux XDomain device. For each Thunderbolt service found supported on the XDomain device, we create Linux Thunderbolt service device which Thunderbolt service drivers can then bind to based on the protocol identification information retrieved from the property directory describing the service.
This code is based on the work done by Amir Levy and Michael Jamet.
--- Documentation/ABI/testing/sysfs-bus-thunderbolt | 48 + drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/ctl.c | 11 +- drivers/thunderbolt/ctl.h | 2 +- drivers/thunderbolt/domain.c | 197 ++- drivers/thunderbolt/icm.c | 218 +++- drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/switch.c | 7 +- drivers/thunderbolt/tb.h | 39 +- drivers/thunderbolt/tb_msgs.h | 123 ++ drivers/thunderbolt/xdomain.c | 1576 +++++++++++++++++++++++ include/linux/mod_devicetable.h | 26 + include/linux/thunderbolt.h | 242 ++++ scripts/mod/devicetable-offsets.c | 7 + scripts/mod/file2alias.c | 25 + 15 files changed, 2507 insertions(+), 18 deletions(-) create mode 100644 drivers/thunderbolt/xdomain.c
Documentation/ABI/testing/sysfs-bus-thunderbolt +48 -0
@@ -110,3 +110,51 @@ Description: When new NVM image is written to the non-active NVM is directly the status value from the DMA configuration based mailbox before the device is power cycled. Writing 0 here clears the status. + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/key +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: This contains name of the property directory the XDomain + service exposes. This entry describes the protocol in + question. Following directories are already reserved by + the Apple XDomain specification: + + network: IP/ethernet over Thunderbolt + targetdm: Target disk mode protocol over Thunderbolt + extdisp: External display mode protocol over Thunderbolt + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/modalias +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: Stores the same MODALIAS value emitted by uevent for + the XDomain service. Format: tbtsvc:kSpNvNrN + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcid +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: This contains XDomain protocol identifier the XDomain + service supports. + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcvers +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: This contains XDomain protocol version the XDomain + service supports. + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcrevs +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: This contains XDomain software version the XDomain + service supports. + +What: /sys/bus/thunderbolt/devices/<xdomain>.<service>/prtcstns +Date: Jan 2018 +KernelVersion: 4.15 +Contact: [email protected] +Description: This contains XDomain service specific settings as + bitmask. Format: %x
drivers/thunderbolt/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-${CONFIG_THUNDERBOLT} := thunderbolt.o thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel_pci.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o
drivers/thunderbolt/ctl.c +7 -4
@@ -368,10 +368,10 @@ static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len,/** * tb_ctl_handle_event() - acknowledge a plug event, invoke ctl->callback */ -static void tb_ctl_handle_event (struct tb_ctl *ctl,enum tb_cfg_pkg_type type, +static bool tb_ctl_handle_event (struct tb_ctl *ctl,enum tb_cfg_pkg_type type,struct ctl_pkg *pkg,size_t size) { - ctl->callback (ctl->callback_data, type, pkg->buffer, size); +return ctl->callback (ctl->callback_data, type, pkg->buffer, size); }static void tb_ctl_rx_submit (struct ctl_pkg *pkg)
@@ -444,6 +444,8 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,break ;case TB_CFG_PKG_EVENT : +case TB_CFG_PKG_XDOMAIN_RESP : +case TB_CFG_PKG_XDOMAIN_REQ :if (*(__be32 *)(pkg->buffer + frame->size) != crc32) {tb_ctl_err (pkg->ctl,"RX: checksum mismatch, dropping packet\n" );
@@ -451,8 +453,9 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame, }/* Fall through */ case TB_CFG_PKG_ICM_EVENT : -tb_ctl_handle_event (pkg->ctl, frame->eof, pkg, frame->size); - goto rx; +if (tb_ctl_handle_event (pkg->ctl, frame->eof, pkg, frame->size)) + goto rx; +break ;default :break ;
drivers/thunderbolt/ctl.h +1 -1
@@ -16,7 +16,7 @@/* control channel */ struct tb_ctl ; -typedef void (*event_cb )(void *data,enum tb_cfg_pkg_type type, +typedef bool (*event_cb )(void *data,enum tb_cfg_pkg_type type,const void *buf,size_t size);struct tb_ctl *tb_ctl_alloc (struct tb_nhi *nhi,event_cb cb,void *cb_data);
drivers/thunderbolt/domain.c +193 -4
235 lines not on this page · raw message
drivers/thunderbolt/icm.c +216 -2
291 lines not on this page · raw message
drivers/thunderbolt/nhi.h +2 -0
@@ -157,6 +157,8 @@ enum nhi_mailbox_cmd {NHI_MAILBOX_SAVE_DEVS =0x05 ,NHI_MAILBOX_DISCONNECT_PCIE_PATHS =0x06 ,NHI_MAILBOX_DRV_UNLOADS =0x07 , +NHI_MAILBOX_DISCONNECT_PA =0x10 , +NHI_MAILBOX_DISCONNECT_PB =0x11 , NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23, };
drivers/thunderbolt/switch.c +5 -2
@@ -171,11 +171,11 @@ static int nvm_authenticate_host(struct tb_switch *sw)/* * Root switch NVM upgrade requires that we disconnect the -* existing PCIe paths first (in case it is not in safe mode +* existing paths first (in case it is not in safe mode * already). */ if (!sw->safe_mode) { - ret =tb_domain_disconnect_pcie_paths (sw->tb); + ret =tb_domain_disconnect_all_paths (sw->tb);if (ret)return ret;/*
@@ -1363,6 +1363,9 @@ void tb_switch_remove(struct tb_switch *sw)if (sw->ports[i].remote)tb_switch_remove (sw->ports[i].remote->sw); sw->ports[i].remote =NULL ; +if (sw->ports[i].xdomain) +tb_xdomain_remove (sw->ports[i].xdomain); + sw->ports[i].xdomain =NULL ; }if (!sw->is_unplugged)
drivers/thunderbolt/tb.h +35 -4
@@ -9,6 +9,7 @@#include <linux/nvmem-provider.h> #include <linux/pci.h> +#include <linux/thunderbolt.h> #include <linux/uuid.h> #include "tb_regs.h"
@@ -109,14 +110,25 @@ struct tb_switch {/** * struct tb_port - a thunderbolt port, part of a tb_switch +* @config: Cached port configuration read from registers +* @sw: Switch the port belongs to +* @remote: Remote port (%NULL if not connected) +* @xdomain: Remote host (%NULL if not connected) +* @cap_phy: Offset, zero if not found +* @port: Port number on switch +* @disabled: Disabled by eeprom +* @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. */ struct tb_port {struct tb_regs_port_header config;struct tb_switch *sw; -struct tb_port *remote;/* remote port, NULL if not connected */ -int cap_phy;/* offset, zero if not found */ -u8 port;/* port number on switch */ -bool disabled;/* disabled by eeprom */ +struct tb_port *remote; +struct tb_xdomain *xdomain; +int cap_phy; +u8 port; +bool disabled;struct tb_port *dual_link_port;u8 link_nr:1 ; };
@@ -189,6 +201,8 @@ struct tb_path {* @add_switch_key: Add key to switch * @challenge_switch_key: Challenge switch using key * @disconnect_pcie_paths: Disconnects PCIe paths before NVM update +* @approve_xdomain_paths: Approve (establish) XDomain DMA paths +* @disconnect_xdomain_paths: Disconnect XDomain DMA paths */ struct tb_cm_ops {int (*driver_ready)(struct tb *tb);
@@ -205,6 +219,8 @@ struct tb_cm_ops {int (*challenge_switch_key)(struct tb *tb,struct tb_switch *sw,const u8 *challenge,u8 *response);int (*disconnect_pcie_paths)(struct tb *tb); +int (*approve_xdomain_paths)(struct tb *tb,struct tb_xdomain *xd); +int (*disconnect_xdomain_paths)(struct tb *tb,struct tb_xdomain *xd); };static inline void *tb_priv (struct tb *tb)
@@ -331,6 +347,8 @@ extern struct device_type tb_switch_type;int tb_domain_init (void );void tb_domain_exit (void );void tb_switch_exit (void ); +int tb_xdomain_init (void ); +void tb_xdomain_exit (void );struct tb *tb_domain_alloc (struct tb_nhi *nhi,size_t privsize);int tb_domain_add (struct tb *tb);
@@ -343,6 +361,9 @@ int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);int tb_domain_challenge_switch_key (struct tb *tb,struct tb_switch *sw);int tb_domain_disconnect_pcie_paths (struct tb *tb); +int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd); +int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd); +int tb_domain_disconnect_all_paths (struct tb *tb);static inline void tb_domain_put (struct tb *tb) {
@@ -422,4 +443,14 @@ static inline u64 tb_downstream_route(struct tb_port *port) | ((u64) port->port << (port->sw->config.depth * 8)); } +bool tb_xdomain_handle_request (struct tb *tb,enum tb_cfg_pkg_type type, +const void *buf,size_t size); +struct tb_xdomain *tb_xdomain_alloc (struct tb *tb,struct device *parent, +u64 route,const uuid_t *local_uuid, +const uuid_t *remote_uuid); +void tb_xdomain_add (struct tb_xdomain *xd); +void tb_xdomain_remove (struct tb_xdomain *xd); +struct tb_xdomain *tb_xdomain_find_by_link_depth (struct tb *tb,u8 link, +u8 depth); +#endif
drivers/thunderbolt/tb_msgs.h +123 -0
150 lines not on this page · raw message
drivers/thunderbolt/xdomain.c new file +1576 -0
1,576 lines not on this page · raw message
include/linux/mod_devicetable.h +26 -0
@@ -683,5 +683,31 @@ struct fsl_mc_device_id { const char obj_type[16]; }; +/** +* struct tb_service_id - Thunderbolt service identifiers +* @match_flags: Flags used to match the structure +* @protocol_key: Protocol key the service supports +* @protocol_id: Protocol id the service supports +* @protocol_version: Version of the protocol +* @protocol_revision: Revision of the protocol software +* @driver_data: Driver specific data +* +* Thunderbolt XDomain services are exposed as devices where each device +* carries the protocol information the service supports. Thunderbolt +* XDomain service drivers match against that information. +*/ +struct tb_service_id { +__u32 match_flags; +char protocol_key[8 +1 ]; +__u32 protocol_id; +__u32 protocol_version; +__u32 protocol_revision; +kernel_ulong_t driver_data; +}; + +#define TBSVC_MATCH_PROTOCOL_KEY 0x0001 +#define TBSVC_MATCH_PROTOCOL_ID 0x0002 +#define TBSVC_MATCH_PROTOCOL_VERSION 0x0004 +#define TBSVC_MATCH_PROTOCOL_REVISION 0x0008#endif /* LINUX_MOD_DEVICETABLE_H */
include/linux/thunderbolt.h +242 -0
258 lines not on this page · raw message
scripts/mod/devicetable-offsets.c +7 -0
@@ -206,5 +206,12 @@ int main(void)DEVID_FIELD (fsl_mc_device_id, vendor);DEVID_FIELD (fsl_mc_device_id, obj_type); +DEVID (tb_service_id); +DEVID_FIELD (tb_service_id, match_flags); +DEVID_FIELD (tb_service_id, protocol_key); +DEVID_FIELD (tb_service_id, protocol_id); +DEVID_FIELD (tb_service_id, protocol_version); +DEVID_FIELD (tb_service_id, protocol_revision); +return 0 ; }
scripts/mod/file2alias.c +25 -0
@@ -1301,6 +1301,31 @@ static int do_fsl_mc_entry(const char *filename, void *symval, }ADD_TO_DEVTABLE ("fslmc" , fsl_mc_device_id, do_fsl_mc_entry); +/* Looks like: tbsvc:kSpNvNrN */ +static int do_tbsvc_entry (const char *filename,void *symval,char *alias) +{ +DEF_FIELD (symval, tb_service_id, match_flags); +DEF_FIELD_ADDR (symval, tb_service_id, protocol_key); +DEF_FIELD (symval, tb_service_id, protocol_id); +DEF_FIELD (symval, tb_service_id, protocol_version); +DEF_FIELD (symval, tb_service_id, protocol_revision); + +strcpy (alias,"tbsvc:" ); +if (match_flags &TBSVC_MATCH_PROTOCOL_KEY ) +sprintf (alias +strlen (alias),"k%s" , *protocol_key); +else +strcat (alias +strlen (alias),"k*" ); +ADD (alias,"p" , match_flags &TBSVC_MATCH_PROTOCOL_ID , protocol_id); +ADD (alias,"v" , match_flags &TBSVC_MATCH_PROTOCOL_VERSION , + protocol_version); +ADD (alias,"r" , match_flags &TBSVC_MATCH_PROTOCOL_REVISION , + protocol_revision); + +add_wildcard (alias); +return 1 ; +} +ADD_TO_DEVTABLE ("tbsvc" , tb_service_id, do_tbsvc_entry); +/* Does namelen bytes of name exactly match the symbol? */ static bool sym_is (const char *name,unsigned namelen,const char *symbol) {
Signature · 1 line
2.14.2
PATCH v3 8/19 thunderbolt: Configure interrupt throttling for all interrupts
In reply to Mika WesterbergThis will keep the interrupt delivery rate reasonable. The value used here (128 us) is a recommendation from the hardware people.
This code is based on the work done by Amir Levy and Michael Jamet.
--- drivers/thunderbolt/nhi.c | 23 ++++++++++++++++++++--- drivers/thunderbolt/nhi_regs.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-)
drivers/thunderbolt/nhi.c +20 -3
@@ -651,6 +651,22 @@ static int nhi_suspend_noirq(struct device *dev)return tb_domain_suspend_noirq (tb); } +static void nhi_enable_int_throttling (struct tb_nhi *nhi) +{ +/* Throttling is specified in 256ns increments */ +u32 throttle =DIV_ROUND_UP (128 *NSEC_PER_USEC ,256 ); +unsigned int i; + +/* +* Configure interrupt throttling for all vectors even if we +* only use few. +*/ +for (i =0 ; i <MSIX_MAX_VECS ; i++) { +u32 reg =REG_INT_THROTTLING_RATE + i *4 ; +iowrite32 (throttle, nhi->iobase + reg); + } +} +static int nhi_resume_noirq (struct device *dev) {struct pci_dev *pdev =to_pci_dev (dev);
@@ -663,6 +679,8 @@ static int nhi_resume_noirq(struct device *dev)*/ if (!pci_device_is_present (pdev)) tb->nhi->going_away = true; +else +nhi_enable_int_throttling (tb->nhi);return tb_domain_resume_noirq (tb); }
@@ -717,6 +735,8 @@ static int nhi_init_msi(struct tb_nhi *nhi)/* In case someone left them on. */ nhi_disable_interrupts (nhi); +nhi_enable_int_throttling (nhi); +ida_init (&nhi->msix_ida);/*
@@ -796,9 +816,6 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)pci_set_master (pdev); -/* magic value - clock related? */ -iowrite32 (3906250 /10000 , nhi->iobase +0x38c00 ); - tb =icm_probe (nhi);if (!tb) tb =tb_probe (nhi);
drivers/thunderbolt/nhi_regs.h +2 -0
@@ -95,6 +95,8 @@ struct ring_desc {#define REG_RING_INTERRUPT_BASE 0x38200#define RING_INTERRUPT_REG_COUNT (nhi) ((31 + 2 * nhi->hop_count) / 32) +#define REG_INT_THROTTLING_RATE 0x38c00 +/* Interrupt Vector Allocation */ #define REG_INT_VEC_ALLOC_BASE 0x38c40#define REG_INT_VEC_ALLOC_BITS 4
Signature · 1 line
2.14.2
PATCH v3 9/19 thunderbolt: Add support for frame mode
In reply to Mika WesterbergWhen high-speed DMA paths are used to transfer arbitrary data over a Thunderbolt link, DMA rings should be in frame mode instead of raw mode. The latter is used by the control channel (ring 0). In frame mode each data frame can hold up to 4kB payload.
This patch modifies the DMA ring code to allow configuring a ring to be in frame mode by passing a new flag (RING_FLAG_FRAME) to the ring when it is allocated. In addition there might be need to enable end-to-end (E2E) workaround for the ring to prevent losing Rx frames in certain situations. We add another flag (RING_FLAG_E2E) that can be used for this purpose.
This code is based on the work done by Amir Levy and Michael Jamet.
--- drivers/thunderbolt/ctl.c | 3 +- drivers/thunderbolt/nhi.c | 76 ++++++++++++++++++++++++++---------------- drivers/thunderbolt/nhi.h | 10 +++++- drivers/thunderbolt/nhi_regs.h | 2 ++ 4 files changed, 61 insertions(+), 30 deletions(-)
drivers/thunderbolt/ctl.c +2 -1
@@ -618,7 +618,8 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data)if (!ctl->tx) goto err; - ctl->rx =ring_alloc_rx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ); + ctl->rx =ring_alloc_rx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ,0xffff , +0xffff );if (!ctl->rx) goto err;
drivers/thunderbolt/nhi.c +48 -28
132 lines not on this page · raw message
drivers/thunderbolt/nhi.h +9 -1
@@ -56,6 +56,8 @@ struct tb_nhi {* @irq: MSI-X irq number if the ring uses MSI-X. %0 otherwise. * @vector: MSI-X vector number the ring uses (only set if @irq is > 0) * @flags: Ring specific flags +* @sof_mask: Bit mask used to detect start of frame PDF +* @eof_mask: Bit mask used to detect end of frame PDF */ struct tb_ring {struct mutex lock;
@@ -74,10 +76,16 @@ struct tb_ring {int irq;u8 vector;unsigned int flags; +u16 sof_mask; +u16 eof_mask; };/* Leave ring interrupt enabled on suspend */ #define RING_FLAG_NO_SUSPEND BIT(0) +/* Configure the ring to be in frame mode */ +#define RING_FLAG_FRAME BIT(1) +/* Enable end-to-end flow control */ +#define RING_FLAG_E2E BIT(2)struct ring_frame ;typedef void (*ring_cb )(struct tb_ring *,struct ring_frame *,bool canceled);
@@ -100,7 +108,7 @@ struct ring_frame {struct tb_ring *ring_alloc_tx (struct tb_nhi *nhi,int hop,int size,unsigned int flags);struct tb_ring *ring_alloc_rx (struct tb_nhi *nhi,int hop,int size, -unsigned int flags); +unsigned int flags,u16 sof_mask,u16 eof_mask);void ring_start (struct tb_ring *ring);void ring_stop (struct tb_ring *ring);void ring_free (struct tb_ring *ring);
drivers/thunderbolt/nhi_regs.h +2 -0
@@ -77,6 +77,8 @@ struct ring_desc {* ..: unknown */ #define REG_RX_OPTIONS_BASE 0x29800 +#define REG_RX_OPTIONS_E2E_HOP_MASK GENMASK(22, 12) +#define REG_RX_OPTIONS_E2E_HOP_SHIFT 12/* * three bitfields: tx, rx, rx overflow
Signature · 1 line
2.14.2
PATCH v3 10/19 thunderbolt: Export ring handling functions to modules
In reply to Mika WesterbergThese are used by Thunderbolt services to send and receive frames over the high-speed DMA rings.
We also put the functions to tb_ namespace to make sure we do not collide with others and add missing kernel-doc comments for the exported functions.
--- drivers/thunderbolt/ctl.c | 20 +++--- drivers/thunderbolt/nhi.c | 62 +++++++++++------ drivers/thunderbolt/nhi.h | 147 +---------------------------------------- include/linux/thunderbolt.h | 158 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 176 deletions(-)
drivers/thunderbolt/ctl.c +10 -10
@@ -359,7 +359,7 @@ static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len,cpu_to_be32_array (pkg->buffer, data, len /4 ); *(__be32 *) (pkg->buffer + len) =tb_crc (pkg->buffer, len); - res =ring_tx (ctl->tx, &pkg->frame); + res =tb_ring_tx (ctl->tx, &pkg->frame);if (res)/* ring is stopped */ tb_ctl_pkg_free (pkg);return res;
@@ -376,7 +376,7 @@ static bool tb_ctl_handle_event(struct tb_ctl *ctl, enum tb_cfg_pkg_type type,static void tb_ctl_rx_submit (struct ctl_pkg *pkg) { -ring_rx (pkg->ctl->rx, &pkg->frame);/* +tb_ring_rx (pkg->ctl->rx, &pkg->frame);/* * We ignore failures during stop. * All rx packets are referenced * from ctl->rx_packets, so we do
@@ -614,11 +614,11 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data)if (!ctl->frame_pool) goto err; - ctl->tx =ring_alloc_tx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ); + ctl->tx =tb_ring_alloc_tx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND );if (!ctl->tx) goto err; - ctl->rx =ring_alloc_rx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ,0xffff , + ctl->rx =tb_ring_alloc_rx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ,0xffff ,0xffff );if (!ctl->rx) goto err;
@@ -652,9 +652,9 @@ void tb_ctl_free(struct tb_ctl *ctl)return ;if (ctl->rx) -ring_free (ctl->rx); +tb_ring_free (ctl->rx);if (ctl->tx) -ring_free (ctl->tx); +tb_ring_free (ctl->tx);/* free RX packets */ for (i =0 ; i <TB_CTL_RX_PKG_COUNT ; i++)
@@ -673,8 +673,8 @@ void tb_ctl_start(struct tb_ctl *ctl) {int i;tb_ctl_info (ctl,"control channel starting...\n" ); -ring_start (ctl->tx);/* is used to ack hotplug packets, start first */ -ring_start (ctl->rx); +tb_ring_start (ctl->tx);/* is used to ack hotplug packets, start first */ +tb_ring_start (ctl->rx);for (i =0 ; i <TB_CTL_RX_PKG_COUNT ; i++)tb_ctl_rx_submit (ctl->rx_packets[i]);
@@ -695,8 +695,8 @@ void tb_ctl_stop(struct tb_ctl *ctl) ctl->running = false;mutex_unlock (&ctl->request_queue_lock); -ring_stop (ctl->rx); -ring_stop (ctl->tx); +tb_ring_stop (ctl->rx); +tb_ring_stop (ctl->tx);if (!list_empty (&ctl->request_queue))tb_ctl_WARN (ctl,"dangling request in request_queue\n" );
drivers/thunderbolt/nhi.c +42 -20
131 lines not on this page · raw message
drivers/thunderbolt/nhi.h +1 -146
153 lines not on this page · raw message
include/linux/thunderbolt.h +158 -0
172 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH v3 11/19 thunderbolt: Move ring descriptor flags to thunderbolt.h
In reply to Mika WesterbergA Thunderbolt service driver might need to check if there was an error with the descriptor when in frame mode. We also add two Rx specific error flags RING_DESC_CRC_ERROR and RING_DESC_BUFFER_OVERRUN.
--- drivers/thunderbolt/nhi_regs.h | 7 ------- include/linux/thunderbolt.h | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-)
drivers/thunderbolt/nhi_regs.h +0 -7
@@ -17,13 +17,6 @@ enum ring_flags { RING_FLAG_ENABLE = 1 << 31, }; -enum ring_desc_flags { -RING_DESC_ISOCH =0x1 ,/* TX only? */ -RING_DESC_COMPLETED =0x2 ,/* set by NHI */ -RING_DESC_POSTED =0x4 ,/* always set this */ -RING_DESC_INTERRUPT =0x8 ,/* request an interrupt on completion */ -}; -/** * struct ring_desc - TX/RX ring entry *
include/linux/thunderbolt.h +18 -0
@@ -478,6 +478,24 @@ struct tb_ring {struct ring_frame ;typedef void (*ring_cb )(struct tb_ring *,struct ring_frame *,bool canceled); +/** +* enum ring_desc_flags - Flags for DMA ring descriptor +* %RING_DESC_ISOCH: Enable isonchronous DMA (Tx only) +* %RING_DESC_CRC_ERROR: In frame mode CRC check failed for the frame (Rx only) +* %RING_DESC_COMPLETED: Descriptor completed (set by NHI) +* %RING_DESC_POSTED: Always set this +* %RING_DESC_BUFFER_OVERRUN: RX buffer overrun +* %RING_DESC_INTERRUPT: Request an interrupt on completion +*/ +enum ring_desc_flags { +RING_DESC_ISOCH =0x1 , +RING_DESC_CRC_ERROR =0x1 , +RING_DESC_COMPLETED =0x2 , +RING_DESC_POSTED =0x4 , +RING_DESC_BUFFER_OVERRUN =0x04 , +RING_DESC_INTERRUPT =0x8 , +}; +/** * struct ring_frame - For use with ring_rx/ring_tx * @buffer_phy: DMA mapped address of the frame
Signature · 1 line
2.14.2
PATCH v3 12/19 thunderbolt: Use spinlock in ring serialization
In reply to Mika WesterbergThis makes it possible to enqueue frames also from atomic context which is needed for example, when networking packets are sent over a Thunderbolt cable.
--- drivers/thunderbolt/nhi.c | 26 ++++++++++++++------------ include/linux/thunderbolt.h | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/thunderbolt/nhi.c +14 -12
@@ -212,8 +212,10 @@ static void ring_work(struct work_struct *work)struct tb_ring *ring =container_of (work,typeof (*ring), work);struct ring_frame *frame;bool canceled = false; +unsigned long flags;LIST_HEAD (done); -mutex_lock (&ring->lock); + +spin_lock_irqsave (&ring->lock, flags);if (!ring->running) {/* Move all frames to done and mark them as canceled. */
@@ -241,7 +243,8 @@ static void ring_work(struct work_struct *work)ring_write_descriptors (ring); invoke_callback: -mutex_unlock (&ring->lock);/* allow callbacks to schedule new work */ +/* allow callbacks to schedule new work */ +spin_unlock_irqrestore (&ring->lock, flags);while (!list_empty (&done)) { frame =list_first_entry (&done,typeof (*frame), list);/*
@@ -255,15 +258,17 @@ static void ring_work(struct work_struct *work)int __tb_ring_enqueue (struct tb_ring *ring,struct ring_frame *frame) { +unsigned long flags;int ret =0 ; -mutex_lock (&ring->lock); + +spin_lock_irqsave (&ring->lock, flags);if (ring->running) {list_add_tail (&frame->list, &ring->queue);ring_write_descriptors (ring); }else { ret = -ESHUTDOWN ; } -mutex_unlock (&ring->lock); +spin_unlock_irqrestore (&ring->lock, flags);return ret; }EXPORT_SYMBOL_GPL (__tb_ring_enqueue);
@@ -338,7 +343,7 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,if (!ring) goto err; -mutex_init (&ring->lock); +spin_lock_init (&ring->lock);INIT_LIST_HEAD (&ring->queue);INIT_LIST_HEAD (&ring->in_flight);INIT_WORK (&ring->work, ring_work);
@@ -371,8 +376,6 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,return ring; err: -if (ring) -mutex_destroy (&ring->lock);kfree (ring);mutex_unlock (&nhi->lock);return NULL ;
@@ -419,7 +422,7 @@ void tb_ring_start(struct tb_ring *ring)u32 flags;mutex_lock (&ring->nhi->lock); -mutex_lock (&ring->lock); +spin_lock_irq (&ring->lock);if (ring->nhi->going_away) goto err;if (ring->running) {
@@ -466,7 +469,7 @@ void tb_ring_start(struct tb_ring *ring)ring_interrupt_active (ring, true); ring->running = true; err: -mutex_unlock (&ring->lock); +spin_unlock_irq (&ring->lock);mutex_unlock (&ring->nhi->lock); }EXPORT_SYMBOL_GPL (tb_ring_start);
@@ -487,7 +490,7 @@ EXPORT_SYMBOL_GPL(tb_ring_start);void tb_ring_stop (struct tb_ring *ring) {mutex_lock (&ring->nhi->lock); -mutex_lock (&ring->lock); +spin_lock_irq (&ring->lock);dev_info (&ring->nhi->pdev->dev,"stopping %s %d\n" ,RING_TYPE (ring), ring->hop);if (ring->nhi->going_away)
@@ -508,7 +511,7 @@ void tb_ring_stop(struct tb_ring *ring) ring->running = false; err: -mutex_unlock (&ring->lock); +spin_unlock_irq (&ring->lock);mutex_unlock (&ring->nhi->lock);/*
@@ -568,7 +571,6 @@ void tb_ring_free(struct tb_ring *ring)* to finish before freeing the ring. */ flush_work (&ring->work); -mutex_destroy (&ring->lock);kfree (ring); }EXPORT_SYMBOL_GPL (tb_ring_free);
include/linux/thunderbolt.h +1 -1
@@ -448,7 +448,7 @@ struct tb_nhi {* @eof_mask: Bit mask used to detect end of frame PDF */ struct tb_ring { -struct mutex lock; +spinlock_t lock;struct tb_nhi *nhi;int size;int hop;
Signature · 1 line
2.14.2
PATCH v3 13/19 thunderbolt: Use spinlock in NHI serialization
In reply to Mika WesterbergThis is needed because ring polling functionality can be called from atomic contexts when networking and other high-speed traffic is transferred over a Thunderbolt cable.
--- drivers/thunderbolt/nhi.c | 75 +++++++++++++++++++++++++-------------------- include/linux/thunderbolt.h | 2 +- 2 files changed, 42 insertions(+), 35 deletions(-)
drivers/thunderbolt/nhi.c +41 -34
@@ -327,21 +327,9 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,if (transmit && hop ==RING_E2E_UNUSED_HOPID )return NULL ; -mutex_lock (&nhi->lock); -if (hop >= nhi->hop_count) { -dev_WARN (&nhi->pdev->dev,"invalid hop: %d\n" , hop); - goto err; - } -if (transmit && nhi->tx_rings[hop]) { -dev_WARN (&nhi->pdev->dev,"TX hop %d already allocated\n" , hop); - goto err; - }else if (!transmit && nhi->rx_rings[hop]) { -dev_WARN (&nhi->pdev->dev,"RX hop %d already allocated\n" , hop); - goto err; - } ring =kzalloc (sizeof (*ring),GFP_KERNEL );if (!ring) - goto err; +return NULL ;spin_lock_init (&ring->lock);INIT_LIST_HEAD (&ring->queue);
@@ -359,25 +347,45 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size, ring->tail =0 ; ring->running = false; -if (ring_request_msix (ring, flags &RING_FLAG_NO_SUSPEND )) - goto err; - ring->descriptors =dma_alloc_coherent (&ring->nhi->pdev->dev, size *sizeof (*ring->descriptors), &ring->descriptors_dma,GFP_KERNEL | __GFP_ZERO);if (!ring->descriptors) - goto err; + goto err_free_ring; +if (ring_request_msix (ring, flags &RING_FLAG_NO_SUSPEND )) + goto err_free_descs; + +spin_lock_irq (&nhi->lock); +if (hop >= nhi->hop_count) { +dev_WARN (&nhi->pdev->dev,"invalid hop: %d\n" , hop); + goto err_release_msix; + } +if (transmit && nhi->tx_rings[hop]) { +dev_WARN (&nhi->pdev->dev,"TX hop %d already allocated\n" , hop); + goto err_release_msix; + }else if (!transmit && nhi->rx_rings[hop]) { +dev_WARN (&nhi->pdev->dev,"RX hop %d already allocated\n" , hop); + goto err_release_msix; + }if (transmit) nhi->tx_rings[hop] = ring;else nhi->rx_rings[hop] = ring; -mutex_unlock (&nhi->lock); +spin_unlock_irq (&nhi->lock); +return ring; -err: +err_release_msix: +spin_unlock_irq (&nhi->lock); +ring_release_msix (ring); +err_free_descs: +dma_free_coherent (&ring->nhi->pdev->dev, + ring->size *sizeof (*ring->descriptors), + ring->descriptors, ring->descriptors_dma); +err_free_ring:kfree (ring); -mutex_unlock (&nhi->lock); +return NULL ; }
@@ -421,8 +429,8 @@ void tb_ring_start(struct tb_ring *ring)u16 frame_size;u32 flags; -mutex_lock (&ring->nhi->lock); -spin_lock_irq (&ring->lock); +spin_lock_irq (&ring->nhi->lock); +spin_lock (&ring->lock);if (ring->nhi->going_away) goto err;if (ring->running) {
@@ -469,8 +477,8 @@ void tb_ring_start(struct tb_ring *ring)ring_interrupt_active (ring, true); ring->running = true; err: -spin_unlock_irq (&ring->lock); -mutex_unlock (&ring->nhi->lock); +spin_unlock (&ring->lock); +spin_unlock_irq (&ring->nhi->lock); }EXPORT_SYMBOL_GPL (tb_ring_start);
@@ -489,8 +497,8 @@ EXPORT_SYMBOL_GPL(tb_ring_start);*/ void tb_ring_stop (struct tb_ring *ring) { -mutex_lock (&ring->nhi->lock); -spin_lock_irq (&ring->lock); +spin_lock_irq (&ring->nhi->lock); +spin_lock (&ring->lock);dev_info (&ring->nhi->pdev->dev,"stopping %s %d\n" ,RING_TYPE (ring), ring->hop);if (ring->nhi->going_away)
@@ -511,8 +519,8 @@ void tb_ring_stop(struct tb_ring *ring) ring->running = false; err: -spin_unlock_irq (&ring->lock); -mutex_unlock (&ring->nhi->lock); +spin_unlock (&ring->lock); +spin_unlock_irq (&ring->nhi->lock);/* * schedule ring->work to invoke callbacks on all remaining frames.
@@ -534,7 +542,7 @@ EXPORT_SYMBOL_GPL(tb_ring_stop);*/ void tb_ring_free (struct tb_ring *ring) { -mutex_lock (&ring->nhi->lock); +spin_lock_irq (&ring->nhi->lock);/* * Dissociate the ring from the NHI. This also ensures that * nhi_interrupt_work cannot reschedule ring->work.
@@ -564,7 +572,7 @@ void tb_ring_free(struct tb_ring *ring)RING_TYPE (ring), ring->hop); -mutex_unlock (&ring->nhi->lock); +spin_unlock_irq (&ring->nhi->lock);/** * ring->work can no longer be scheduled (it is scheduled only * by nhi_interrupt_work, ring_stop and ring_msix). Wait for it
@@ -639,7 +647,7 @@ static void nhi_interrupt_work(struct work_struct *work)int type =0 ;/* current interrupt type 0: TX, 1: RX, 2: RX overflow */ struct tb_ring *ring; -mutex_lock (&nhi->lock); +spin_lock_irq (&nhi->lock);/* * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
@@ -677,7 +685,7 @@ static void nhi_interrupt_work(struct work_struct *work)/* we do not check ring->running, this is done in ring->work */ schedule_work (&ring->work); } -mutex_unlock (&nhi->lock); +spin_unlock_irq (&nhi->lock); }static irqreturn_t nhi_msi (int irq,void *data)
@@ -767,7 +775,6 @@ static void nhi_shutdown(struct tb_nhi *nhi)devm_free_irq (&nhi->pdev->dev, nhi->pdev->irq, nhi);flush_work (&nhi->interrupt_work); } -mutex_destroy (&nhi->lock);ida_destroy (&nhi->msix_ida); }
@@ -856,7 +863,7 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)return res; } -mutex_init (&nhi->lock); +spin_lock_init (&nhi->lock);pci_set_master (pdev);
include/linux/thunderbolt.h +1 -1
@@ -415,7 +415,7 @@ static inline struct tb_xdomain *tb_service_parent(struct tb_service *svc)* @hop_count: Number of rings (end point hops) supported by NHI. */ struct tb_nhi { -struct mutex lock; +spinlock_t lock;struct pci_dev *pdev;void __iomem *iobase;struct tb_ring **tx_rings;
Signature · 1 line
2.14.2
PATCH v3 14/19 thunderbolt: Add polling mode for rings
In reply to Mika WesterbergIn order to support things like networking over Thunderbolt cable, there needs to be a way to switch the ring to a mode where it can be polled with the interrupt masked. We implement such mode so that the caller can allocate a ring by passing pointer to a function that is then called when an interrupt is triggered. Completed frames can be fetched using tb_ring_poll() and the interrupt can be re-enabled when the caller is finished with polling by using tb_ring_poll_complete().
--- drivers/thunderbolt/ctl.c | 2 +- drivers/thunderbolt/nhi.c | 126 ++++++++++++++++++++++++++++++++++++++++---- include/linux/thunderbolt.h | 23 +++++--- 3 files changed, 134 insertions(+), 17 deletions(-)
drivers/thunderbolt/ctl.c +1 -1
@@ -619,7 +619,7 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data) goto err; ctl->rx =tb_ring_alloc_rx (nhi,0 ,10 ,RING_FLAG_NO_SUSPEND ,0xffff , -0xffff ); +0xffff ,NULL ,NULL );if (!ctl->rx) goto err;
drivers/thunderbolt/nhi.c +117 -9
187 lines not on this page · raw message
include/linux/thunderbolt.h +16 -7
@@ -446,6 +446,9 @@ struct tb_nhi {* @flags: Ring specific flags * @sof_mask: Bit mask used to detect start of frame PDF * @eof_mask: Bit mask used to detect end of frame PDF +* @start_poll: Called when ring interrupt is triggered to start +* polling. Passing %NULL keeps the ring in interrupt mode. +* @poll_data: Data passed to @start_poll */ struct tb_ring {spinlock_t lock;
@@ -466,6 +469,8 @@ struct tb_ring {unsigned int flags;u16 sof_mask;u16 eof_mask; +void (*start_poll)(void *data); +void *poll_data; };/* Leave ring interrupt enabled on suspend */
@@ -499,7 +504,7 @@ enum ring_desc_flags {/** * struct ring_frame - For use with ring_rx/ring_tx * @buffer_phy: DMA mapped address of the frame -* @callback: Callback called when the frame is finished +* @callback: Callback called when the frame is finished (optional) * @list: Frame is linked to a queue using this * @size: Size of the frame in bytes (%0 means %4096) * @flags: Flags for the frame (see &enum ring_desc_flags)
@@ -522,8 +527,8 @@ struct ring_frame {struct tb_ring *tb_ring_alloc_tx (struct tb_nhi *nhi,int hop,int size,unsigned int flags);struct tb_ring *tb_ring_alloc_rx (struct tb_nhi *nhi,int hop,int size, -unsigned int flags,u16 sof_mask, -u16 eof_mask); +unsigned int flags,u16 sof_mask,u16 eof_mask, +void (*start_poll)(void *),void *poll_data);void tb_ring_start (struct tb_ring *ring);void tb_ring_stop (struct tb_ring *ring);void tb_ring_free (struct tb_ring *ring);
@@ -535,8 +540,8 @@ int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame);* @ring: Ring to enqueue the frame * @frame: Frame to enqueue * -* @frame->buffer, @frame->buffer_phy and @frame->callback have to be set. The -* buffer must contain at least %TB_FRAME_SIZE bytes. +* @frame->buffer, @frame->buffer_phy have to be set. The buffer must +* contain at least %TB_FRAME_SIZE bytes. * * @frame->callback will be invoked with @frame->size, @frame->flags, * @frame->eof, @frame->sof set once the frame has been received.
@@ -557,8 +562,8 @@ static inline int tb_ring_rx(struct tb_ring *ring, struct ring_frame *frame)* @ring: Ring the enqueue the frame * @frame: Frame to enqueue * -* @frame->buffer, @frame->buffer_phy, @frame->callback, @frame->size, -* @frame->eof and @frame->sof have to be set. +* @frame->buffer, @frame->buffer_phy, @frame->size, @frame->eof and +* @frame->sof have to be set. * * @frame->callback will be invoked with once the frame has been transmitted. *
@@ -573,4 +578,8 @@ static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame) return __tb_ring_enqueue(ring, frame); } +/* Used only when the ring is in polling mode */ +struct ring_frame *tb_ring_poll (struct tb_ring *ring); +void tb_ring_poll_complete (struct tb_ring *ring); +#endif /* THUNDERBOLT_H_ */
Signature · 1 line
2.14.2
PATCH v3 15/19 thunderbolt: Add function to retrieve DMA device for the ring
In reply to Mika WesterbergThis is needed when Thunderbolt service drivers need to DMA map memory before it is passed down to the ring.
--- include/linux/thunderbolt.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/thunderbolt.h +13 -0
@@ -19,6 +19,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/mod_devicetable.h> +#include <linux/pci.h> #include <linux/uuid.h> #include <linux/workqueue.h>
@@ -582,4 +583,16 @@ static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame)struct ring_frame *tb_ring_poll (struct tb_ring *ring);void tb_ring_poll_complete (struct tb_ring *ring); +/** +* tb_ring_dma_device() - Return device used for DMA mapping +* @ring: Ring whose DMA device is retrieved +* +* Use this function when you are mapping DMA for buffers that are +* passed to the ring for sending/receiving. +*/ +static inline struct device *tb_ring_dma_device (struct tb_ring *ring) +{ +return &ring->nhi->pdev->dev; +} +#endif /* THUNDERBOLT_H_ */
Signature · 1 line
2.14.2
PATCH v3 16/19 thunderbolt: Allocate ring HopID automatically if requested
In reply to Mika WesterbergThunderbolt services should not care which HopID (ring) they use for sending and receiving packets over the high-speed DMA path, so make tb_ring_alloc_rx() and tb_ring_alloc_tx() accept negative HopID. This means that the NHI will allocate next available HopID for the caller automatically.
These HopIDs will be allocated from the range which is not reserved for the Thunderbolt protocol (8 .. hop_count - 1).
The allocated HopID can be retrieved from ring->hop field after the ring has been allocated successfully if needed.
--- drivers/thunderbolt/nhi.c | 78 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 18 deletions(-)
drivers/thunderbolt/nhi.c +60 -18
@@ -26,6 +26,8 @@* use this ring for anything else. */ #define RING_E2E_UNUSED_HOPID 2 +/* HopIDs 0-7 are reserved by the Thunderbolt protocol */ +#define RING_FIRST_USABLE_HOPID 8/* * Minimal number of vectors when we use MSI-X. Two for control channel
@@ -411,6 +413,62 @@ static void ring_release_msix(struct tb_ring *ring) ring->irq =0 ; } +static int nhi_alloc_hop (struct tb_nhi *nhi,struct tb_ring *ring) +{ +int ret =0 ; + +spin_lock_irq (&nhi->lock); + +if (ring->hop <0 ) { +unsigned int i; + +/* +* Automatically allocate HopID from the non-reserved +* range 8 .. hop_count - 1. +*/ +for (i =RING_FIRST_USABLE_HOPID ; i < nhi->hop_count; i++) { +if (ring->is_tx) { +if (!nhi->tx_rings[i]) { + ring->hop = i; +break ; + } + }else { +if (!nhi->rx_rings[i]) { + ring->hop = i; +break ; + } + } + } + } + +if (ring->hop <0 || ring->hop >= nhi->hop_count) { +dev_warn (&nhi->pdev->dev,"invalid hop: %d\n" , ring->hop); + ret = -EINVAL ; + goto err_unlock; + } +if (ring->is_tx && nhi->tx_rings[ring->hop]) { +dev_warn (&nhi->pdev->dev,"TX hop %d already allocated\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + }else if (!ring->is_tx && nhi->rx_rings[ring->hop]) { +dev_warn (&nhi->pdev->dev,"RX hop %d already allocated\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + } + +if (ring->is_tx) + nhi->tx_rings[ring->hop] = ring; +else + nhi->rx_rings[ring->hop] = ring; + +err_unlock: +spin_unlock_irq (&nhi->lock); + +return ret; +} + static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size, bool transmit, unsigned int flags, u16 sof_mask, u16 eof_mask,
@@ -456,28 +514,12 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,if (ring_request_msix (ring, flags &RING_FLAG_NO_SUSPEND )) goto err_free_descs; -spin_lock_irq (&nhi->lock); -if (hop >= nhi->hop_count) { -dev_WARN (&nhi->pdev->dev,"invalid hop: %d\n" , hop); +if (nhi_alloc_hop (nhi, ring)) goto err_release_msix; - } -if (transmit && nhi->tx_rings[hop]) { -dev_WARN (&nhi->pdev->dev,"TX hop %d already allocated\n" , hop); - goto err_release_msix; - }else if (!transmit && nhi->rx_rings[hop]) { -dev_WARN (&nhi->pdev->dev,"RX hop %d already allocated\n" , hop); - goto err_release_msix; - } -if (transmit) - nhi->tx_rings[hop] = ring; -else - nhi->rx_rings[hop] = ring; -spin_unlock_irq (&nhi->lock);return ring; err_release_msix: -spin_unlock_irq (&nhi->lock);ring_release_msix (ring); err_free_descs: dma_free_coherent(&ring->nhi->pdev->dev,
@@ -506,7 +548,7 @@ EXPORT_SYMBOL_GPL(tb_ring_alloc_tx);/** * tb_ring_alloc_rx() - Allocate DMA ring for receive * @nhi: Pointer to the NHI the ring is to be allocated -* @hop: HopID (ring) to allocate +* @hop: HopID (ring) to allocate. Pass %-1 for automatic allocation. * @size: Number of entries in the ring * @flags: Flags for the ring * @sof_mask: Mask of PDF values that start a frame
Signature · 1 line
2.14.2
PATCH v3 17/19 MAINTAINERS: Add thunderbolt.h to the Thunderbolt driver entry
In reply to Mika WesterbergThe new API header (include/linux/thunderbolt.h) is maintained by the Thunderbolt driver maintainers.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -13284,6 +13284,7 @@ M: Mika Westerberg <[email protected]> M: Yehezkel Bernat <[email protected]> S: Maintained F: drivers/thunderbolt/ +F: include/linux/thunderbolt.h THUNDERX GPIO DRIVER M: David Daney <[email protected]>
Signature · 1 line
2.14.2
PATCH v3 18/19 net: Add support for networking over Thunderbolt cable
In reply to Mika WesterbergFrom: Amir Levy <[email protected]>
ThunderboltIP is a protocol created by Apple to tunnel IP/ethernet traffic over a Thunderbolt cable. The protocol consists of configuration phase where each side sends ThunderboltIP login packets (the protocol is determined by UUID in the XDomain packet header) over the configuration channel. Once both sides get positive acknowledgment to their login packet, they configure high-speed DMA path accordingly. This DMA path is then used to transmit and receive networking traffic.
This patch creates a virtual ethernet interface the host software can use in the same way as any other networking interface. Once the interface is brought up successfully network packets get tunneled over the Thunderbolt cable to the remote host and back.
The connection is terminated by sending a ThunderboltIP logout packet over the configuration channel. We do this when the network interface is brought down by user or the driver is unloaded.
--- Documentation/admin-guide/thunderbolt.rst | 24 + drivers/net/Kconfig | 12 + drivers/net/Makefile | 3 + drivers/net/thunderbolt.c | 1362 +++++++++++++++++++++++++++++ 4 files changed, 1401 insertions(+) create mode 100644 drivers/net/thunderbolt.c
Documentation/admin-guide/thunderbolt.rst +24 -0
@@ -197,3 +197,27 @@ information is missing. To recover from this mode, one needs to flash a valid NVM image to the host host controller in the same way it is done in the previous chapter. + +Networking over Thunderbolt cable +--------------------------------- +Thunderbolt technology allows software communication across two hosts +connected by a Thunderbolt cable. + +It is possible to tunnel any kind of traffic over Thunderbolt link but +currently we only support Apple ThunderboltIP protocol. + +If the other host is running Windows or macOS only thing you need to +do is to connect Thunderbolt cable between the two hosts, the +``thunderbolt-net`` is loaded automatically. If the other host is also +Linux you should load ``thunderbolt-net`` manually on one host (it does +not matter which one):: + + # modprobe thunderbolt-net + +This triggers module load on the other host automatically. If the driver +is built-in to the kernel image, there is no need to do anything. + +The driver will create one virtual ethernet interface per Thunderbolt +port which are named like ``thunderbolt0`` and so on. From this point +you can either use standard userspace tools like ``ifconfig`` to +configure the interface or let your GUI to handle it automatically.
drivers/net/Kconfig +12 -0
@@ -483,6 +483,18 @@ config FUJITSU_ES This driver provides support for Extended Socket network device on Extended Partitioning of FUJITSU PRIMEQUEST 2000 E2 series. +config THUNDERBOLT_NET + tristate "Networking over Thunderbolt cable" + depends on THUNDERBOLT && INET + help + Select this if you want to create network between two + computers over a Thunderbolt cable. The driver supports Apple + ThunderboltIP protocol and allows communication with any host + supporting the same protocol including Windows and macOS. + + To compile this driver a module, choose M here. The module will be + called thunderbolt-net. + source "drivers/net/hyperv/Kconfig" endif # NETDEVICES
drivers/net/Makefile +3 -0
@@ -74,3 +74,6 @@ obj-$(CONFIG_HYPERV_NET) += hyperv/ obj-$(CONFIG_NTB_NETDEV) += ntb_netdev.o obj-$(CONFIG_FUJITSU_ES) += fjes/ + +thunderbolt-net-y += thunderbolt.o +obj-$(CONFIG_THUNDERBOLT_NET) += thunderbolt-net.o
drivers/net/thunderbolt.c new file +1362 -0
1,362 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH v3 19/19 MAINTAINERS: Add entry for Thunderbolt network driver
In reply to Mika WesterbergI will be maintaining the Thunderbolt network driver along with Michael and Yehezkel.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -13286,6 +13286,14 @@ S: Maintained F: drivers/thunderbolt/ F: include/linux/thunderbolt.h +THUNDERBOLT NETWORK DRIVER +M: Michael Jamet <[email protected]> +M: Mika Westerberg <[email protected]> +M: Yehezkel Bernat <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/thunderbolt.c + THUNDERX GPIO DRIVER M: David Daney <[email protected]> S: Maintained
Signature · 1 line
2.14.2
David Miller
maintainerFrom: Mika Westerberg <[email protected]>
Date: Mon, 2 Oct 2017 13:38:27 +0300
Quoted 4 lines
In addition of tunneling PCIe, Display Port and USB traffic, Thunderbolt allows connecting two hosts (domains) over a Thunderbolt cable. It is possible to tunnel arbitrary data packets over such connection using high-speed DMA rings available in the Thunderbolt host controller.
Series applied to net-next, thanks!