Lines Matching +full:peer +full:- +full:hub
1 // SPDX-License-Identifier: GPL-2.0
15 #include "hub.h"
26 return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no"); in early_stop_show()
36 return -EINVAL; in early_stop_store()
39 port_dev->early_stop = 1; in early_stop_store()
41 port_dev->early_stop = 0; in early_stop_store()
51 struct usb_device *hdev = to_usb_device(dev->parent->parent); in disable_show()
52 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in disable_show() local
53 struct usb_interface *intf = to_usb_interface(hub->intfdev); in disable_show()
54 int port1 = port_dev->portnum; in disable_show()
64 if (hub->disconnected) { in disable_show()
65 rc = -ENODEV; in disable_show()
69 usb_hub_port_status(hub, port1, &portstatus, &unused); in disable_show()
70 disabled = !usb_port_is_power_on(hub, portstatus); in disable_show()
86 struct usb_device *hdev = to_usb_device(dev->parent->parent); in disable_store()
87 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in disable_store() local
88 struct usb_interface *intf = to_usb_interface(hub->intfdev); in disable_store()
89 int port1 = port_dev->portnum; in disable_store()
102 if (hub->disconnected) { in disable_store()
103 rc = -ENODEV; in disable_store()
107 if (disabled && port_dev->child) in disable_store()
108 usb_disconnect(&port_dev->child); in disable_store()
110 rc = usb_hub_set_port_power(hdev, hub, port1, !disabled); in disable_store()
114 if (!port_dev->is_superspeed) in disable_store()
134 return sprintf(buf, "0x%08x\n", port_dev->location); in location_show()
144 switch (port_dev->connect_type) { in connect_type_show()
167 enum usb_device_state state = READ_ONCE(port_dev->state); in state_show()
178 return sprintf(buf, "%u\n", port_dev->over_current_count); in over_current_count_show()
187 return sprintf(buf, "%08x\n", port_dev->quirks); in quirks_show()
197 return -EINVAL; in quirks_store()
199 port_dev->quirks = value; in quirks_store()
210 if (port_dev->usb3_lpm_u1_permit) { in usb3_lpm_permit_show()
211 if (port_dev->usb3_lpm_u2_permit) in usb3_lpm_permit_show()
216 if (port_dev->usb3_lpm_u2_permit) in usb3_lpm_permit_show()
230 struct usb_device *udev = port_dev->child; in usb3_lpm_permit_store()
234 port_dev->usb3_lpm_u1_permit = 1; in usb3_lpm_permit_store()
235 port_dev->usb3_lpm_u2_permit = 1; in usb3_lpm_permit_store()
238 port_dev->usb3_lpm_u1_permit = 1; in usb3_lpm_permit_store()
239 port_dev->usb3_lpm_u2_permit = 0; in usb3_lpm_permit_store()
242 port_dev->usb3_lpm_u1_permit = 0; in usb3_lpm_permit_store()
243 port_dev->usb3_lpm_u2_permit = 1; in usb3_lpm_permit_store()
246 port_dev->usb3_lpm_u1_permit = 0; in usb3_lpm_permit_store()
247 port_dev->usb3_lpm_u2_permit = 0; in usb3_lpm_permit_store()
249 return -EINVAL; in usb3_lpm_permit_store()
255 hcd = bus_to_hcd(udev->bus); in usb3_lpm_permit_store()
257 return -EINVAL; in usb3_lpm_permit_store()
259 mutex_lock(hcd->bandwidth_mutex); in usb3_lpm_permit_store()
262 mutex_unlock(hcd->bandwidth_mutex); in usb3_lpm_permit_store()
309 kfree(port_dev->req); in usb_port_device_release()
317 struct usb_device *hdev = to_usb_device(dev->parent->parent); in usb_port_runtime_resume()
318 struct usb_interface *intf = to_usb_interface(dev->parent); in usb_port_runtime_resume()
319 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_port_runtime_resume() local
320 struct usb_device *udev = port_dev->child; in usb_port_runtime_resume()
321 struct usb_port *peer = port_dev->peer; in usb_port_runtime_resume() local
322 int port1 = port_dev->portnum; in usb_port_runtime_resume()
325 if (!hub) in usb_port_runtime_resume()
326 return -EINVAL; in usb_port_runtime_resume()
327 if (hub->in_reset) { in usb_port_runtime_resume()
328 set_bit(port1, hub->power_bits); in usb_port_runtime_resume()
333 * Power on our usb3 peer before this usb2 port to prevent a usb3 in usb_port_runtime_resume()
336 if (!port_dev->is_superspeed && peer) in usb_port_runtime_resume()
337 pm_runtime_get_sync(&peer->dev); in usb_port_runtime_resume()
343 retval = usb_hub_set_port_power(hdev, hub, port1, true); in usb_port_runtime_resume()
344 msleep(hub_power_on_good_delay(hub)); in usb_port_runtime_resume()
355 if (hub_port_debounce_be_connected(hub, port1) < 0) { in usb_port_runtime_resume()
356 dev_dbg(&port_dev->dev, "reconnect timeout\n"); in usb_port_runtime_resume()
358 set_bit(port1, hub->warm_reset_bits); in usb_port_runtime_resume()
362 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_runtime_resume()
363 pm_runtime_get_noresume(&port_dev->dev); in usb_port_runtime_resume()
364 pm_request_resume(&udev->dev); in usb_port_runtime_resume()
376 struct usb_device *hdev = to_usb_device(dev->parent->parent); in usb_port_runtime_suspend()
377 struct usb_interface *intf = to_usb_interface(dev->parent); in usb_port_runtime_suspend()
378 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_port_runtime_suspend() local
379 struct usb_port *peer = port_dev->peer; in usb_port_runtime_suspend() local
380 int port1 = port_dev->portnum; in usb_port_runtime_suspend()
383 if (!hub) in usb_port_runtime_suspend()
384 return -EINVAL; in usb_port_runtime_suspend()
385 if (hub->in_reset) in usb_port_runtime_suspend()
386 return -EBUSY; in usb_port_runtime_suspend()
388 if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) in usb_port_runtime_suspend()
390 return -EAGAIN; in usb_port_runtime_suspend()
393 return -EBUSY; in usb_port_runtime_suspend()
399 retval = usb_hub_set_port_power(hdev, hub, port1, false); in usb_port_runtime_suspend()
401 if (!port_dev->is_superspeed) in usb_port_runtime_suspend()
406 * Our peer usb3 port may now be able to suspend, so in usb_port_runtime_suspend()
410 if (!port_dev->is_superspeed && peer) in usb_port_runtime_suspend()
411 pm_runtime_put(&peer->dev); in usb_port_runtime_suspend()
421 if (port_dev->child) in usb_port_shutdown()
422 usb_disable_usb2_hardware_lpm(port_dev->child); in usb_port_shutdown()
449 if (left->peer == right && right->peer == left) in link_peers()
452 if (left->peer || right->peer) { in link_peers()
453 struct usb_port *lpeer = left->peer; in link_peers()
454 struct usb_port *rpeer = right->peer; in link_peers()
457 if (left->location && left->location == right->location) in link_peers()
462 pr_debug("usb: failed to peer %s and %s by %s (%s:%s) (%s:%s)\n", in link_peers()
463 dev_name(&left->dev), dev_name(&right->dev), method, in link_peers()
464 dev_name(&left->dev), in link_peers()
465 lpeer ? dev_name(&lpeer->dev) : "none", in link_peers()
466 dev_name(&right->dev), in link_peers()
467 rpeer ? dev_name(&rpeer->dev) : "none"); in link_peers()
468 return -EBUSY; in link_peers()
471 rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer"); in link_peers()
474 rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer"); in link_peers()
476 sysfs_remove_link(&left->dev.kobj, "peer"); in link_peers()
482 * setting ->peer with usb_port_runtime_suspend(). Otherwise we in link_peers()
485 if (left->is_superspeed) { in link_peers()
487 WARN_ON(right->is_superspeed); in link_peers()
491 WARN_ON(!right->is_superspeed); in link_peers()
494 pm_runtime_get_sync(&hs_port->dev); in link_peers()
496 left->peer = right; in link_peers()
497 right->peer = left; in link_peers()
503 * device degrading to its powered-off HiSpeed connection. in link_peers()
507 pm_runtime_get_sync(&ss_port->dev); in link_peers()
508 pm_runtime_put(&hs_port->dev); in link_peers()
519 dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev)); in link_peers_report()
521 dev_dbg(&left->dev, "failed to peer to %s (%d)\n", in link_peers_report()
522 dev_name(&right->dev), rc); in link_peers_report()
532 WARN(right->peer != left || left->peer != right, in unlink_peers()
534 dev_name(&left->dev), dev_name(&right->dev)); in unlink_peers()
539 * when ->peer is !NULL. in unlink_peers()
541 if (left->is_superspeed) { in unlink_peers()
549 pm_runtime_get_sync(&hs_port->dev); in unlink_peers()
551 sysfs_remove_link(&left->dev.kobj, "peer"); in unlink_peers()
552 right->peer = NULL; in unlink_peers()
553 sysfs_remove_link(&right->dev.kobj, "peer"); in unlink_peers()
554 left->peer = NULL; in unlink_peers()
557 pm_runtime_put(&ss_port->dev); in unlink_peers()
560 pm_runtime_put(&hs_port->dev); in unlink_peers()
564 * For each usb hub device in the system check to see if it is in the
565 * peer domain of the given port_dev, and if it is check to see if it
572 struct usb_port *port_dev = p, *peer; in match_location() local
574 struct usb_device *hdev = to_usb_device(port_dev->dev.parent->parent); in match_location()
576 if (!peer_hub || port_dev->connect_type == USB_PORT_NOT_USED) in match_location()
579 hcd = bus_to_hcd(hdev->bus); in match_location()
580 peer_hcd = bus_to_hcd(peer_hdev->bus); in match_location()
581 /* peer_hcd is provisional until we verify it against the known peer */ in match_location()
582 if (peer_hcd != hcd->shared_hcd) in match_location()
585 for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) { in match_location()
586 peer = peer_hub->ports[port1 - 1]; in match_location()
587 if (peer && peer->connect_type != USB_PORT_NOT_USED && in match_location()
588 peer->location == port_dev->location) { in match_location()
589 link_peers_report(port_dev, peer); in match_location()
598 * Find the peer port either via explicit platform firmware "location"
599 * data, the peer hcd for root hubs, or the upstream peer relationship
602 static void find_and_link_peer(struct usb_hub *hub, int port1) in find_and_link_peer() argument
604 struct usb_port *port_dev = hub->ports[port1 - 1], *peer; in find_and_link_peer() local
605 struct usb_device *hdev = hub->hdev; in find_and_link_peer()
610 * If location data is available then we can only peer this port in find_and_link_peer()
611 * by a location match, not the default peer (lest we create a in find_and_link_peer()
615 if (port_dev->location) { in find_and_link_peer()
616 /* we link the peer in match_location() if found */ in find_and_link_peer()
619 } else if (!hdev->parent) { in find_and_link_peer()
620 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in find_and_link_peer()
621 struct usb_hcd *peer_hcd = hcd->shared_hcd; in find_and_link_peer()
626 peer_hdev = peer_hcd->self.root_hub; in find_and_link_peer()
629 struct usb_device *parent = hdev->parent; in find_and_link_peer()
635 upstream = parent_hub->ports[hdev->portnum - 1]; in find_and_link_peer()
636 if (!upstream || !upstream->peer) in find_and_link_peer()
639 peer_hdev = upstream->peer->child; in find_and_link_peer()
643 if (!peer_hub || port1 > peer_hdev->maxchild) in find_and_link_peer()
647 * we found a valid default peer, last check is to make sure it in find_and_link_peer()
650 peer = peer_hub->ports[port1 - 1]; in find_and_link_peer()
651 if (peer && peer->location == 0) in find_and_link_peer()
652 link_peers_report(port_dev, peer); in find_and_link_peer()
660 ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector"); in connector_bind()
664 ret = sysfs_create_link(&connector->kobj, &dev->kobj, dev_name(dev)); in connector_bind()
666 sysfs_remove_link(&dev->kobj, "connector"); in connector_bind()
670 port_dev->connector = data; in connector_bind()
674 * Type-C connector know about it immediately. in connector_bind()
676 if (port_dev->child) in connector_bind()
677 typec_attach(port_dev->connector, &port_dev->child->dev); in connector_bind()
686 sysfs_remove_link(&connector->kobj, dev_name(dev)); in connector_unbind()
687 sysfs_remove_link(&dev->kobj, "connector"); in connector_unbind()
688 port_dev->connector = NULL; in connector_unbind()
696 int usb_hub_create_port_device(struct usb_hub *hub, int port1) in usb_hub_create_port_device() argument
699 struct usb_device *hdev = hub->hdev; in usb_hub_create_port_device()
704 return -ENOMEM; in usb_hub_create_port_device()
706 port_dev->req = kzalloc(sizeof(*(port_dev->req)), GFP_KERNEL); in usb_hub_create_port_device()
707 if (!port_dev->req) { in usb_hub_create_port_device()
709 return -ENOMEM; in usb_hub_create_port_device()
712 hub->ports[port1 - 1] = port_dev; in usb_hub_create_port_device()
713 port_dev->portnum = port1; in usb_hub_create_port_device()
714 set_bit(port1, hub->power_bits); in usb_hub_create_port_device()
715 port_dev->dev.parent = hub->intfdev; in usb_hub_create_port_device()
717 port_dev->is_superspeed = 1; in usb_hub_create_port_device()
718 port_dev->usb3_lpm_u1_permit = 1; in usb_hub_create_port_device()
719 port_dev->usb3_lpm_u2_permit = 1; in usb_hub_create_port_device()
720 port_dev->dev.groups = port_dev_usb3_group; in usb_hub_create_port_device()
722 port_dev->dev.groups = port_dev_group; in usb_hub_create_port_device()
723 port_dev->dev.type = &usb_port_device_type; in usb_hub_create_port_device()
724 port_dev->dev.driver = &usb_port_driver; in usb_hub_create_port_device()
725 dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev), in usb_hub_create_port_device()
727 mutex_init(&port_dev->status_lock); in usb_hub_create_port_device()
728 retval = device_register(&port_dev->dev); in usb_hub_create_port_device()
730 put_device(&port_dev->dev); in usb_hub_create_port_device()
734 port_dev->state_kn = sysfs_get_dirent(port_dev->dev.kobj.sd, "state"); in usb_hub_create_port_device()
735 if (!port_dev->state_kn) { in usb_hub_create_port_device()
736 dev_err(&port_dev->dev, "failed to sysfs_get_dirent 'state'\n"); in usb_hub_create_port_device()
737 retval = -ENODEV; in usb_hub_create_port_device()
741 /* Set default policy of port-poweroff disabled. */ in usb_hub_create_port_device()
742 retval = dev_pm_qos_add_request(&port_dev->dev, port_dev->req, in usb_hub_create_port_device()
748 retval = component_add(&port_dev->dev, &connector_ops); in usb_hub_create_port_device()
750 dev_warn(&port_dev->dev, "failed to add component\n"); in usb_hub_create_port_device()
754 find_and_link_peer(hub, port1); in usb_hub_create_port_device()
759 * and the hub has been fully registered (hdev->maxchild set). in usb_hub_create_port_device()
761 pm_runtime_set_active(&port_dev->dev); in usb_hub_create_port_device()
762 pm_runtime_get_noresume(&port_dev->dev); in usb_hub_create_port_device()
763 pm_runtime_enable(&port_dev->dev); in usb_hub_create_port_device()
764 device_enable_async_suspend(&port_dev->dev); in usb_hub_create_port_device()
767 * Keep hidden the ability to enable port-poweroff if the hub in usb_hub_create_port_device()
770 if (!hub_is_port_power_switchable(hub)) in usb_hub_create_port_device()
774 retval = dev_pm_qos_expose_flags(&port_dev->dev, in usb_hub_create_port_device()
777 dev_warn(&port_dev->dev, "failed to expose pm_qos_no_poweroff\n"); in usb_hub_create_port_device()
782 retval = dev_pm_qos_remove_request(port_dev->req); in usb_hub_create_port_device()
784 kfree(port_dev->req); in usb_hub_create_port_device()
785 port_dev->req = NULL; in usb_hub_create_port_device()
790 sysfs_put(port_dev->state_kn); in usb_hub_create_port_device()
792 device_unregister(&port_dev->dev); in usb_hub_create_port_device()
797 void usb_hub_remove_port_device(struct usb_hub *hub, int port1) in usb_hub_remove_port_device() argument
799 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_hub_remove_port_device()
800 struct usb_port *peer; in usb_hub_remove_port_device() local
802 peer = port_dev->peer; in usb_hub_remove_port_device()
803 if (peer) in usb_hub_remove_port_device()
804 unlink_peers(port_dev, peer); in usb_hub_remove_port_device()
805 component_del(&port_dev->dev, &connector_ops); in usb_hub_remove_port_device()
806 sysfs_put(port_dev->state_kn); in usb_hub_remove_port_device()
807 device_unregister(&port_dev->dev); in usb_hub_remove_port_device()