[PATCH v6 part1 7/8] usb: sysfs link peer ports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The usb topology after this change will have symlinks between usb3 ports
and their usb2 peers, for example:

usb2/2-1/2-1:1.0/2-1-port1/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port1
usb2/2-1/2-1:1.0/2-1-port2/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port2
usb2/2-1/2-1:1.0/2-1-port3/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port3
usb2/2-1/2-1:1.0/2-1-port4/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port4
usb2/2-0:1.0/usb2-port1/peer    => ../../../usb3/3-0:1.0/usb3-port1
usb2/2-0:1.0/usb2-port2/peer    => ../../../usb3/3-0:1.0/usb3-port2
usb2/2-0:1.0/usb2-port3/peer    => ../../../usb3/3-0:1.0/usb3-port3
usb2/2-0:1.0/usb2-port4/peer    => ../../../usb3/3-0:1.0/usb3-port4

usb3/3-1/3-1:1.0/usb3-1-port1/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port1
usb3/3-1/3-1:1.0/usb3-1-port2/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port2
usb3/3-1/3-1:1.0/usb3-1-port3/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port3
usb3/3-1/3-1:1.0/usb3-1-port4/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port4
usb3/3-0:1.0/usb3-port1/peer       => ../../../usb2/2-0:1.0/usb2-port1
usb3/3-0:1.0/usb3-port2/peer       => ../../../usb2/2-0:1.0/usb2-port2
usb3/3-0:1.0/usb3-port3/peer       => ../../../usb2/2-0:1.0/usb2-port3
usb3/3-0:1.0/usb3-port4/peer       => ../../../usb2/2-0:1.0/usb2-port4

Introduce link_peers_report() to notify on all link_peers() failure
cases.

Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
---
 drivers/usb/core/port.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 313f20fdfbf2..783a3bc6c4c9 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -219,10 +219,12 @@ static struct usb_port *find_default_peer(struct usb_hub *hub, int port1)
 	return peer;
 }
 
-static void link_peers(struct usb_port *left, struct usb_port *right)
+static int link_peers(struct usb_port *left, struct usb_port *right)
 {
+	int rc;
+
 	if (left->peer == right && right->peer == left)
-		return;
+		return 0;
 
 	if (left->peer || right->peer) {
 		struct usb_port *lpeer = left->peer;
@@ -232,11 +234,36 @@ static void link_peers(struct usb_port *left, struct usb_port *right)
 			dev_name(&left->dev), dev_name(&right->dev),
 			dev_name(&left->dev), lpeer,
 			dev_name(&right->dev), rpeer);
-		return;
+		return -EBUSY;
+	}
+
+	rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer");
+	if (rc)
+		return rc;
+	rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer");
+	if (rc) {
+		sysfs_remove_link(&left->dev.kobj, "peer");
+		return rc;
 	}
 
 	left->peer = right;
 	right->peer = left;
+
+	return 0;
+}
+
+static void link_peers_report(struct usb_port *left, struct usb_port *right)
+{
+	int rc;
+
+	rc = link_peers(left, right);
+	if (rc == 0) {
+		dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev));
+	} else {
+		dev_warn(&left->dev, "failed to peer to %s (%d)\n",
+				dev_name(&right->dev), rc);
+		pr_warn_once("usb: port power management may be unreliable\n");
+	}
 }
 
 static void unlink_peers(struct usb_port *left, struct usb_port *right)
@@ -245,7 +272,9 @@ static void unlink_peers(struct usb_port *left, struct usb_port *right)
 			"%s and %s are not peers?\n",
 			dev_name(&left->dev), dev_name(&right->dev));
 
+	sysfs_remove_link(&left->dev.kobj, "peer");
 	right->peer = NULL;
+	sysfs_remove_link(&right->dev.kobj, "peer");
 	left->peer = NULL;
 }
 
@@ -329,7 +358,7 @@ void usb_set_hub_port_location(struct usb_device *hdev, int port1,
 	if (!peer)
 		return;
 
-	link_peers(port_dev, peer);
+	link_peers_report(port_dev, peer);
 }
 
 int usb_hub_create_port_device(struct usb_hub *hub, int port1)
@@ -360,7 +389,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 		struct usb_port *peer = find_default_peer(hub, port1);
 
 		if (peer)
-			link_peers(port_dev, peer);
+			link_peers_report(port_dev, peer);
 	}
 	mutex_unlock(&usb_port_peer_mutex);
 	if (retval)

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux