On Fri, 2014-02-21 at 16:09 -0800, Dan Williams wrote: > 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/port1/peer => ../../../../usb3/3-1/3-1:1.0/port1 > usb2/2-1/2-1:1.0/port2/peer => ../../../../usb3/3-1/3-1:1.0/port2 > usb2/2-1/2-1:1.0/port3/peer => ../../../../usb3/3-1/3-1:1.0/port3 > usb2/2-1/2-1:1.0/port4/peer => ../../../../usb3/3-1/3-1:1.0/port4 > usb2/2-0:1.0/port1/peer => ../../../usb3/3-0:1.0/port1 > usb2/2-0:1.0/port2/peer => ../../../usb3/3-0:1.0/port2 > usb2/2-0:1.0/port3/peer => ../../../usb3/3-0:1.0/port3 > usb2/2-0:1.0/port4/peer => ../../../usb3/3-0:1.0/port4 > > usb3/3-1/3-1:1.0/port1/peer => ../../../../usb2/2-1/2-1:1.0/port1 > usb3/3-1/3-1:1.0/port2/peer => ../../../../usb2/2-1/2-1:1.0/port2 > usb3/3-1/3-1:1.0/port3/peer => ../../../../usb2/2-1/2-1:1.0/port3 > usb3/3-1/3-1:1.0/port4/peer => ../../../../usb2/2-1/2-1:1.0/port4 > usb3/3-0:1.0/port1/peer => ../../../usb2/2-0:1.0/port1 > usb3/3-0:1.0/port2/peer => ../../../usb2/2-0:1.0/port2 > usb3/3-0:1.0/port3/peer => ../../../usb2/2-0:1.0/port3 > usb3/3-0:1.0/port4/peer => ../../../usb2/2-0:1.0/port4 > > Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> > --- > drivers/usb/core/port.c | 45 +++++++++++++++++++++++++++++++++++++++------ > 1 files changed, 39 insertions(+), 6 deletions(-) > > diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c > index 0b8ae73b0466..86e78bbd2e4e 100644 > --- a/drivers/usb/core/port.c > +++ b/drivers/usb/core/port.c > @@ -196,10 +196,11 @@ 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) > { > struct device *rdev; > struct device *ldev; > + int rc; > > if (left->peer) { > right = left->peer; > @@ -209,7 +210,7 @@ static void link_peers(struct usb_port *left, struct usb_port *right) > WARN_ONCE(1, "%s port%d already peered with %s %d\n", > dev_name(ldev), left->portnum, dev_name(rdev), > right->portnum); > - return; > + return -EBUSY; > } else if (right->peer) { > left = right->peer; > ldev = left->dev.parent->parent; > @@ -218,13 +219,43 @@ static void link_peers(struct usb_port *left, struct usb_port *right) > WARN_ONCE(1, "%s port%d already peered with %s %d\n", > dev_name(rdev), right->portnum, dev_name(ldev), > left->portnum); > - 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; > } > > get_device(&right->dev); > left->peer = right; > get_device(&left->dev); > right->peer = left; > + > + return 0; > +} > + > +static void link_peers_report(struct usb_port *left, struct usb_port *right) > +{ > + struct device *rdev = right->dev.parent->parent; > + struct device *ldev = left->dev.parent->parent; > + int rc; > + > + rc = link_peers(left, right); > + if (rc == 0) { > + pr_debug("usb: link %s port%d to %s port%d\n", > + dev_name(ldev), left->portnum, > + dev_name(rdev), right->portnum); > + } else { > + pr_warn("usb: failed to link %s port%d to %s port%d (%d)\n", > + dev_name(ldev), left->portnum, > + dev_name(rdev), right->portnum, rc); > + pr_warn_once("usb: port power management may be unreliable\n"); > + } > } Fix this up to use dev_name(&port_dev->dev) now that the name is no longer ambiguous. 8<------------ Subject: usb: sysfs link peer ports From: Dan Williams <dan.j.williams@xxxxxxxxx> 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/port1/peer => ../../../../usb3/3-1/3-1:1.0/port1 usb2/2-1/2-1:1.0/port2/peer => ../../../../usb3/3-1/3-1:1.0/port2 usb2/2-1/2-1:1.0/port3/peer => ../../../../usb3/3-1/3-1:1.0/port3 usb2/2-1/2-1:1.0/port4/peer => ../../../../usb3/3-1/3-1:1.0/port4 usb2/2-0:1.0/port1/peer => ../../../usb3/3-0:1.0/port1 usb2/2-0:1.0/port2/peer => ../../../usb3/3-0:1.0/port2 usb2/2-0:1.0/port3/peer => ../../../usb3/3-0:1.0/port3 usb2/2-0:1.0/port4/peer => ../../../usb3/3-0:1.0/port4 usb3/3-1/3-1:1.0/port1/peer => ../../../../usb2/2-1/2-1:1.0/port1 usb3/3-1/3-1:1.0/port2/peer => ../../../../usb2/2-1/2-1:1.0/port2 usb3/3-1/3-1:1.0/port3/peer => ../../../../usb2/2-1/2-1:1.0/port3 usb3/3-1/3-1:1.0/port4/peer => ../../../../usb2/2-1/2-1:1.0/port4 usb3/3-0:1.0/port1/peer => ../../../usb2/2-0:1.0/port1 usb3/3-0:1.0/port2/peer => ../../../usb2/2-0:1.0/port2 usb3/3-0:1.0/port3/peer => ../../../usb2/2-0:1.0/port3 usb3/3-0:1.0/port4/peer => ../../../usb2/2-0:1.0/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 | 41 +++++++++++++++++++++++++++++++++++------ 1 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 684941361287..2a560cd64758 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -196,10 +196,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; @@ -211,13 +213,38 @@ static void link_peers(struct usb_port *left, struct usb_port *right) lpeer ? dev_name(&lpeer->dev) : "[none]", dev_name(&right->dev), rpeer ? dev_name(&rpeer->dev) : "[none]"); - 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; } get_device(&right->dev); left->peer = right; get_device(&left->dev); 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) @@ -226,8 +253,10 @@ 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"); put_device(&left->dev); right->peer = NULL; + sysfs_remove_link(&right->dev.kobj, "peer"); put_device(&right->dev); left->peer = NULL; } @@ -296,7 +325,7 @@ static struct usb_port *do_default_link(struct usb_port *port_dev, void *p) * set */ if (peer && !port_dev->peer) - link_peers(port_dev, peer); + link_peers_report(port_dev, peer); return NULL; } @@ -362,7 +391,7 @@ void usb_set_hub_port_location(struct usb_device *hdev, int port1, enum_peer = 1; } - link_peers(port_dev, peer); + link_peers_report(port_dev, peer); /* * If a peer relationship was invalidated then we need to @@ -405,7 +434,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(&peer_lock); -- 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