Skip to content

Commit

Permalink
Merge tag 'thunderbolt-for-v5.19-rc1' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/westeri/thunderbolt into usb-next

Mika writes:

thunderbolt: Changes for v5.19 merge window

This includes following Thunderbolt/USB4 changes for the v5.19 merge
window:

  * Improvements for Thunderbolt 1 DisplayPort tunneling
  * Link USB4 ports to their USB Type-C connectors
  * Lane bonding support for host-to-host (XDomain) connections
  * Buffer allocation improvement for devices with no DisplayPort
    adapters
  * Few cleanups and minor fixes.

All these have been in linux-next with no reported issues except that
there is a minor merge conflict with the kunit-next tree because one of
the commits touches the driver KUnit tests.

* tag 'thunderbolt-for-v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: Add KUnit test for devices with no DisplayPort adapters
  thunderbolt: Fix buffer allocation of devices with no DisplayPort adapters
  thunderbolt: Add support for XDomain lane bonding
  thunderbolt: Ignore port locked error in tb_port_wait_for_link_width()
  thunderbolt: Split setting link width and lane bonding into own functions
  thunderbolt: Move tb_port_state() prototype to correct place
  thunderbolt: Add debug logging when lane is enabled/disabled
  thunderbolt: Link USB4 ports to their USB Type-C connectors
  misc/mei: Add NULL check to component match callback functions
  thunderbolt: Use different lane for second DisplayPort tunnel
  thunderbolt: Dump path config space entries during discovery
  thunderbolt: Use decimal number with port numbers
  thunderbolt: Fix typo in comment
  thunderbolt: Replace usage of found with dedicated list iterator variable
  • Loading branch information
Greg Kroah-Hartman committed May 19, 2022
2 parents 74f55a6 + c7c99a0 commit 376d6b0
Show file tree
Hide file tree
Showing 17 changed files with 883 additions and 134 deletions.
10 changes: 10 additions & 0 deletions Documentation/ABI/testing/sysfs-bus-thunderbolt
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ Contact: thunderbolt-software@lists.01.org
Description: This contains XDomain service specific settings as
bitmask. Format: %x

What: /sys/bus/thunderbolt/devices/usb4_portX/connector
Date: April 2022
Contact: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Description:
Symlink to the USB Type-C connector. This link is only
created when USB Type-C Connector Class is enabled,
and only if the system firmware is capable of
describing the connection between a port and its
connector.

What: /sys/bus/thunderbolt/devices/usb4_portX/link
Date: Sep 2021
KernelVersion: v5.14
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/mei/hdcp/mei_hdcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ static int mei_hdcp_component_match(struct device *dev, int subcomponent,
{
struct device *base = data;

if (strcmp(dev->driver->name, "i915") ||
if (!dev->driver || strcmp(dev->driver->name, "i915") ||
subcomponent != I915_COMPONENT_HDCP)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/mei/pxp/mei_pxp.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int mei_pxp_component_match(struct device *dev, int subcomponent,
{
struct device *base = data;

if (strcmp(dev->driver->name, "i915") ||
if (!dev->driver || strcmp(dev->driver->name, "i915") ||
subcomponent != I915_COMPONENT_PXP)
return 0;

Expand Down
15 changes: 7 additions & 8 deletions drivers/thunderbolt/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,20 @@ static bool tb_cfg_request_is_active(struct tb_cfg_request *req)
static struct tb_cfg_request *
tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)
{
struct tb_cfg_request *req;
bool found = false;
struct tb_cfg_request *req = NULL, *iter;

mutex_lock(&pkg->ctl->request_queue_lock);
list_for_each_entry(req, &pkg->ctl->request_queue, list) {
tb_cfg_request_get(req);
if (req->match(req, pkg)) {
found = true;
list_for_each_entry(iter, &pkg->ctl->request_queue, list) {
tb_cfg_request_get(iter);
if (iter->match(iter, pkg)) {
req = iter;
break;
}
tb_cfg_request_put(req);
tb_cfg_request_put(iter);
}
mutex_unlock(&pkg->ctl->request_queue_lock);

return found ? req : NULL;
return req;
}

/* utility functions */
Expand Down
2 changes: 1 addition & 1 deletion drivers/thunderbolt/nhi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)

nhi->pdev = pdev;
nhi->ops = (const struct tb_nhi_ops *)id->driver_data;
/* cannot fail - table is allocated bin pcim_iomap_regions */
/* cannot fail - table is allocated in pcim_iomap_regions */
nhi->iobase = pcim_iomap_table(pdev)[0];
nhi->hop_count = ioread32(nhi->iobase + REG_HOP_COUNT) & 0x3ff;
dev_dbg(&pdev->dev, "total paths: %d\n", nhi->hop_count);
Expand Down
6 changes: 6 additions & 0 deletions drivers/thunderbolt/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,
return NULL;
}

tb_dbg(path->tb, "discovering %s path starting from %llx:%u\n",
path->name, tb_route(src->sw), src->port);

p = src;
h = src_hopid;

Expand Down Expand Up @@ -198,10 +201,13 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,
path->hops[i].out_port = out_port;
path->hops[i].next_hop_index = next_hop;

tb_dump_hop(&path->hops[i], &hop);

h = next_hop;
p = out_port->remote;
}

tb_dbg(path->tb, "path discovery complete\n");
return path;

err:
Expand Down
109 changes: 90 additions & 19 deletions drivers/thunderbolt/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,14 @@ static int __tb_port_enable(struct tb_port *port, bool enable)
else
phy |= LANE_ADP_CS_1_LD;

return tb_port_write(port, &phy, TB_CFG_PORT,
port->cap_phy + LANE_ADP_CS_1, 1);

ret = tb_port_write(port, &phy, TB_CFG_PORT,
port->cap_phy + LANE_ADP_CS_1, 1);
if (ret)
return ret;

tb_port_dbg(port, "lane %sabled\n", enable ? "en" : "dis");
return 0;
}

/**
Expand Down Expand Up @@ -993,7 +999,17 @@ static bool tb_port_is_width_supported(struct tb_port *port, int width)
return !!(widths & width);
}

static int tb_port_set_link_width(struct tb_port *port, unsigned int width)
/**
* tb_port_set_link_width() - Set target link width of the lane adapter
* @port: Lane adapter
* @width: Target link width (%1 or %2)
*
* Sets the target link width of the lane adapter to @width. Does not
* enable/disable lane bonding. For that call tb_port_set_lane_bonding().
*
* Return: %0 in case of success and negative errno in case of error
*/
int tb_port_set_link_width(struct tb_port *port, unsigned int width)
{
u32 val;
int ret;
Expand All @@ -1020,12 +1036,58 @@ static int tb_port_set_link_width(struct tb_port *port, unsigned int width)
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);
}

/**
* tb_port_set_lane_bonding() - Enable/disable lane bonding
* @port: Lane adapter
* @bonding: enable/disable bonding
*
* Enables or disables lane bonding. This should be called after target
* link width has been set (tb_port_set_link_width()). Note in most
* cases one should use tb_port_lane_bonding_enable() instead to enable
* lane bonding.
*
* As a side effect sets @port->bonding accordingly (and does the same
* for lane 1 too).
*
* Return: %0 in case of success and negative errno in case of error
*/
int tb_port_set_lane_bonding(struct tb_port *port, bool bonding)
{
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;

if (bonding)
val |= LANE_ADP_CS_1_LB;
else
val &= ~LANE_ADP_CS_1_LB;

ret = tb_port_write(port, &val, TB_CFG_PORT,
port->cap_phy + LANE_ADP_CS_1, 1);
if (ret)
return ret;

/*
* When lane 0 bonding is set it will affect lane 1 too so
* update both.
*/
port->bonded = bonding;
port->dual_link_port->bonded = bonding;

return 0;
}

/**
* tb_port_lane_bonding_enable() - Enable bonding on port
* @port: port to enable
Expand All @@ -1050,22 +1112,27 @@ int tb_port_lane_bonding_enable(struct tb_port *port)
if (ret == 1) {
ret = tb_port_set_link_width(port, 2);
if (ret)
return ret;
goto err_lane0;
}

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;
}
if (ret)
goto err_lane0;
}

port->bonded = true;
port->dual_link_port->bonded = true;
ret = tb_port_set_lane_bonding(port, true);
if (ret)
goto err_lane1;

return 0;

err_lane1:
tb_port_set_link_width(port->dual_link_port, 1);
err_lane0:
tb_port_set_link_width(port, 1);
return ret;
}

/**
Expand All @@ -1074,13 +1141,10 @@ int tb_port_lane_bonding_enable(struct tb_port *port)
*
* Disable bonding by setting the link width of the port and the
* other port in case of dual link port.
*
*/
void tb_port_lane_bonding_disable(struct tb_port *port)
{
port->dual_link_port->bonded = false;
port->bonded = false;

tb_port_set_lane_bonding(port, false);
tb_port_set_link_width(port->dual_link_port, 1);
tb_port_set_link_width(port, 1);
}
Expand All @@ -1104,10 +1168,17 @@ int tb_port_wait_for_link_width(struct tb_port *port, int width,

do {
ret = tb_port_get_link_width(port);
if (ret < 0)
return ret;
else if (ret == width)
if (ret < 0) {
/*
* Sometimes we get port locked error when
* polling the lanes so we can ignore it and
* retry.
*/
if (ret != -EACCES)
return ret;
} else if (ret == width) {
return 0;
}

usleep_range(1000, 2000);
} while (ktime_before(ktime_get(), timeout));
Expand Down
25 changes: 17 additions & 8 deletions drivers/thunderbolt/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ static void tb_discover_tunnels(struct tb *tb)

static int tb_port_configure_xdomain(struct tb_port *port)
{
/*
* XDomain paths currently only support single lane so we must
* disable the other lane according to USB4 spec.
*/
tb_port_disable(port->dual_link_port);

if (tb_switch_is_usb4(port->sw))
return usb4_port_configure_xdomain(port);
return tb_lc_configure_xdomain(port);
Expand Down Expand Up @@ -867,7 +861,7 @@ static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in)

static void tb_tunnel_dp(struct tb *tb)
{
int available_up, available_down, ret;
int available_up, available_down, ret, link_nr;
struct tb_cm *tcm = tb_priv(tb);
struct tb_port *port, *in, *out;
struct tb_tunnel *tunnel;
Expand Down Expand Up @@ -912,6 +906,20 @@ static void tb_tunnel_dp(struct tb *tb)
return;
}

/*
* This is only applicable to links that are not bonded (so
* when Thunderbolt 1 hardware is involved somewhere in the
* topology). For these try to share the DP bandwidth between
* the two lanes.
*/
link_nr = 1;
list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
if (tb_tunnel_is_dp(tunnel)) {
link_nr = 0;
break;
}
}

/*
* DP stream needs the domain to be active so runtime resume
* both ends of the tunnel.
Expand Down Expand Up @@ -943,7 +951,8 @@ static void tb_tunnel_dp(struct tb *tb)
tb_dbg(tb, "available bandwidth for new DP tunnel %u/%u Mb/s\n",
available_up, available_down);

tunnel = tb_tunnel_alloc_dp(tb, in, out, available_up, available_down);
tunnel = tb_tunnel_alloc_dp(tb, in, out, link_nr, available_up,
available_down);
if (!tunnel) {
tb_port_dbg(out, "could not allocate DP tunnel\n");
goto err_reclaim;
Expand Down
6 changes: 4 additions & 2 deletions drivers/thunderbolt/tb.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ static inline int tb_port_write(struct tb_port *port, const void *buffer,
#define __TB_PORT_PRINT(level, _port, fmt, arg...) \
do { \
const struct tb_port *__port = (_port); \
level(__port->sw->tb, "%llx:%x: " fmt, \
level(__port->sw->tb, "%llx:%u: " fmt, \
tb_route(__port->sw), __port->port, ## arg); \
} while (0)
#define tb_port_WARN(port, fmt, arg...) \
Expand Down Expand Up @@ -991,6 +991,7 @@ int tb_switch_pcie_l1_enable(struct tb_switch *sw);
int tb_switch_xhci_connect(struct tb_switch *sw);
void tb_switch_xhci_disconnect(struct tb_switch *sw);

int tb_port_state(struct tb_port *port);
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_clear_counter(struct tb_port *port, int counter);
Expand Down Expand Up @@ -1023,7 +1024,8 @@ static inline bool tb_port_use_credit_allocation(const struct tb_port *port)

int tb_port_get_link_speed(struct tb_port *port);
int tb_port_get_link_width(struct tb_port *port);
int tb_port_state(struct tb_port *port);
int tb_port_set_link_width(struct tb_port *port, unsigned int width);
int tb_port_set_lane_bonding(struct tb_port *port, bool bonding);
int tb_port_lane_bonding_enable(struct tb_port *port);
void tb_port_lane_bonding_disable(struct tb_port *port);
int tb_port_wait_for_link_width(struct tb_port *port, int width,
Expand Down
39 changes: 39 additions & 0 deletions drivers/thunderbolt/tb_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ enum tb_xdp_type {
PROPERTIES_CHANGED_RESPONSE,
ERROR_RESPONSE,
UUID_REQUEST = 12,
LINK_STATE_STATUS_REQUEST = 15,
LINK_STATE_STATUS_RESPONSE,
LINK_STATE_CHANGE_REQUEST,
LINK_STATE_CHANGE_RESPONSE,
};

struct tb_xdp_header {
Expand All @@ -540,6 +544,41 @@ struct tb_xdp_error_response {
u32 error;
};

struct tb_xdp_link_state_status {
struct tb_xdp_header hdr;
};

struct tb_xdp_link_state_status_response {
union {
struct tb_xdp_error_response err;
struct {
struct tb_xdp_header hdr;
u32 status;
u8 slw;
u8 tlw;
u8 sls;
u8 tls;
};
};
};

struct tb_xdp_link_state_change {
struct tb_xdp_header hdr;
u8 tlw;
u8 tls;
u16 reserved;
};

struct tb_xdp_link_state_change_response {
union {
struct tb_xdp_error_response err;
struct {
struct tb_xdp_header hdr;
u32 status;
};
};
};

struct tb_xdp_uuid {
struct tb_xdp_header hdr;
};
Expand Down
Loading

0 comments on commit 376d6b0

Please sign in to comment.