aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thunderbolt/xdomain.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thunderbolt/xdomain.c')
-rw-r--r--drivers/thunderbolt/xdomain.c148
1 files changed, 140 insertions, 8 deletions
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index c00ad817042e..9b3a299a1202 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -8,6 +8,7 @@
*/
#include <linux/device.h>
+#include <linux/delay.h>
#include <linux/kmod.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
@@ -21,6 +22,7 @@
#define XDOMAIN_UUID_RETRIES 10
#define XDOMAIN_PROPERTIES_RETRIES 60
#define XDOMAIN_PROPERTIES_CHANGED_RETRIES 10
+#define XDOMAIN_BONDING_WAIT 100 /* ms */
struct xdomain_request_work {
struct work_struct work;
@@ -587,8 +589,6 @@ static void tb_xdp_handle_request(struct work_struct *work)
break;
case PROPERTIES_CHANGED_REQUEST: {
- const struct tb_xdp_properties_changed *xchg =
- (const struct tb_xdp_properties_changed *)pkg;
struct tb_xdomain *xd;
ret = tb_xdp_properties_changed_response(ctl, route, sequence);
@@ -598,10 +598,12 @@ static void tb_xdp_handle_request(struct work_struct *work)
* the xdomain related to this connection as well in
* case there is a change in services it offers.
*/
- xd = tb_xdomain_find_by_uuid_locked(tb, &xchg->src_uuid);
+ xd = tb_xdomain_find_by_route_locked(tb, route);
if (xd) {
- queue_delayed_work(tb->wq, &xd->get_properties_work,
- msecs_to_jiffies(50));
+ if (device_is_registered(&xd->dev)) {
+ queue_delayed_work(tb->wq, &xd->get_properties_work,
+ msecs_to_jiffies(50));
+ }
tb_xdomain_put(xd);
}
@@ -777,6 +779,7 @@ static void tb_service_release(struct device *dev)
struct tb_service *svc = container_of(dev, struct tb_service, dev);
struct tb_xdomain *xd = tb_service_parent(svc);
+ tb_service_debugfs_remove(svc);
ida_simple_remove(&xd->service_ids, svc->id);
kfree(svc->key);
kfree(svc);
@@ -891,6 +894,8 @@ static void enumerate_services(struct tb_xdomain *xd)
svc->dev.parent = &xd->dev;
dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
+ tb_service_debugfs_init(svc);
+
if (device_register(&svc->dev)) {
put_device(&svc->dev);
break;
@@ -943,6 +948,43 @@ static void tb_xdomain_restore_paths(struct tb_xdomain *xd)
}
}
+static inline struct tb_switch *tb_xdomain_parent(struct tb_xdomain *xd)
+{
+ return tb_to_switch(xd->dev.parent);
+}
+
+static int tb_xdomain_update_link_attributes(struct tb_xdomain *xd)
+{
+ bool change = false;
+ struct tb_port *port;
+ int ret;
+
+ port = tb_port_at(xd->route, tb_xdomain_parent(xd));
+
+ ret = tb_port_get_link_speed(port);
+ if (ret < 0)
+ return ret;
+
+ if (xd->link_speed != ret)
+ change = true;
+
+ xd->link_speed = ret;
+
+ ret = tb_port_get_link_width(port);
+ if (ret < 0)
+ return ret;
+
+ if (xd->link_width != ret)
+ change = true;
+
+ xd->link_width = ret;
+
+ if (change)
+ kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
+
+ return 0;
+}
+
static void tb_xdomain_get_uuid(struct work_struct *work)
{
struct tb_xdomain *xd = container_of(work, typeof(*xd),
@@ -962,10 +1004,8 @@ static void tb_xdomain_get_uuid(struct work_struct *work)
return;
}
- if (uuid_equal(&uuid, xd->local_uuid)) {
+ if (uuid_equal(&uuid, xd->local_uuid))
dev_dbg(&xd->dev, "intra-domain loop detected\n");
- return;
- }
/*
* If the UUID is different, there is another domain connected
@@ -1056,6 +1096,8 @@ static void tb_xdomain_get_properties(struct work_struct *work)
xd->properties = dir;
xd->property_block_gen = gen;
+ tb_xdomain_update_link_attributes(xd);
+
tb_xdomain_restore_paths(xd);
mutex_unlock(&xd->lock);
@@ -1162,9 +1204,35 @@ static ssize_t unique_id_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(unique_id);
+static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
+
+ return sprintf(buf, "%u.0 Gb/s\n", xd->link_speed);
+}
+
+static DEVICE_ATTR(rx_speed, 0444, speed_show, NULL);
+static DEVICE_ATTR(tx_speed, 0444, speed_show, NULL);
+
+static ssize_t lanes_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
+
+ return sprintf(buf, "%u\n", xd->link_width);
+}
+
+static DEVICE_ATTR(rx_lanes, 0444, lanes_show, NULL);
+static DEVICE_ATTR(tx_lanes, 0444, lanes_show, NULL);
+
static struct attribute *xdomain_attrs[] = {
&dev_attr_device.attr,
&dev_attr_device_name.attr,
+ &dev_attr_rx_lanes.attr,
+ &dev_attr_rx_speed.attr,
+ &dev_attr_tx_lanes.attr,
+ &dev_attr_tx_speed.attr,
&dev_attr_unique_id.attr,
&dev_attr_vendor.attr,
&dev_attr_vendor_name.attr,
@@ -1382,6 +1450,70 @@ void tb_xdomain_remove(struct tb_xdomain *xd)
}
/**
+ * tb_xdomain_lane_bonding_enable() - Enable lane bonding on XDomain
+ * @xd: XDomain connection
+ *
+ * Lane bonding is disabled by default for XDomains. This function tries
+ * to enable bonding by first enabling the port and waiting for the CL0
+ * state.
+ *
+ * Return: %0 in case of success and negative errno in case of error.
+ */
+int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd)
+{
+ struct tb_port *port;
+ int ret;
+
+ port = tb_port_at(xd->route, tb_xdomain_parent(xd));
+ if (!port->dual_link_port)
+ return -ENODEV;
+
+ ret = tb_port_enable(port->dual_link_port);
+ if (ret)
+ return ret;
+
+ ret = tb_wait_for_port(port->dual_link_port, true);
+ if (ret < 0)
+ return ret;
+ if (!ret)
+ return -ENOTCONN;
+
+ ret = tb_port_lane_bonding_enable(port);
+ if (ret) {
+ tb_port_warn(port, "failed to enable lane bonding\n");
+ return ret;
+ }
+
+ tb_xdomain_update_link_attributes(xd);
+
+ dev_dbg(&xd->dev, "lane bonding enabled\n");
+ return 0;
+}
+EXPORT_SYMBOL_GPL(tb_xdomain_lane_bonding_enable);
+
+/**
+ * tb_xdomain_lane_bonding_disable() - Disable lane bonding
+ * @xd: XDomain connection
+ *
+ * Lane bonding is disabled by default for XDomains. If bonding has been
+ * enabled, this function can be used to disable it.
+ */
+void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd)
+{
+ struct tb_port *port;
+
+ port = tb_port_at(xd->route, tb_xdomain_parent(xd));
+ if (port->dual_link_port) {
+ tb_port_lane_bonding_disable(port);
+ tb_port_disable(port->dual_link_port);
+ tb_xdomain_update_link_attributes(xd);
+
+ dev_dbg(&xd->dev, "lane bonding disabled\n");
+ }
+}
+EXPORT_SYMBOL_GPL(tb_xdomain_lane_bonding_disable);
+
+/**
* tb_xdomain_enable_paths() - Enable DMA paths for XDomain connection
* @xd: XDomain connection
* @transmit_path: HopID of the transmit path the other end is using to