Lines Matching +full:peer +full:- +full:hub
1 // SPDX-License-Identifier: GPL-2.0
16 #include "hub.h"
27 return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no"); in early_stop_show()
37 return -EINVAL; in early_stop_store()
40 port_dev->early_stop = 1; in early_stop_store()
42 port_dev->early_stop = 0; in early_stop_store()
52 struct usb_device *hdev = to_usb_device(dev->parent->parent); in disable_show()
53 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in disable_show() local
54 struct usb_interface *intf = to_usb_interface(dev->parent); in disable_show()
55 int port1 = port_dev->portnum; in disable_show()
61 if (!hub) in disable_show()
62 return -ENODEV; in disable_show()
63 hub_get(hub); in disable_show()
72 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); in disable_show()
74 rc = -ENODEV; in disable_show()
78 if (hub->disconnected) { in disable_show()
79 rc = -ENODEV; in disable_show()
83 usb_hub_port_status(hub, port1, &portstatus, &unused); in disable_show()
84 disabled = !usb_port_is_power_on(hub, portstatus); in disable_show()
92 hub_put(hub); in disable_show()
104 struct usb_device *hdev = to_usb_device(dev->parent->parent); in disable_store()
105 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in disable_store() local
106 struct usb_interface *intf = to_usb_interface(dev->parent); in disable_store()
107 int port1 = port_dev->portnum; in disable_store()
112 if (!hub) in disable_store()
113 return -ENODEV; in disable_store()
118 hub_get(hub); in disable_store()
127 kn = sysfs_break_active_protection(&dev->kobj, &attr->attr); in disable_store()
129 rc = -ENODEV; in disable_store()
133 if (hub->disconnected) { in disable_store()
134 rc = -ENODEV; in disable_store()
138 if (disabled && port_dev->child) in disable_store()
139 usb_disconnect(&port_dev->child); in disable_store()
141 rc = usb_hub_set_port_power(hdev, hub, port1, !disabled); in disable_store()
145 if (!port_dev->is_superspeed) in disable_store()
158 hub_put(hub); in disable_store()
169 return sprintf(buf, "0x%08x\n", port_dev->location); in location_show()
179 switch (port_dev->connect_type) { in connect_type_show()
202 enum usb_device_state state = READ_ONCE(port_dev->state); in state_show()
213 return sprintf(buf, "%u\n", port_dev->over_current_count); in over_current_count_show()
222 return sprintf(buf, "%08x\n", port_dev->quirks); in quirks_show()
232 return -EINVAL; in quirks_store()
234 port_dev->quirks = value; in quirks_store()
245 if (port_dev->usb3_lpm_u1_permit) { in usb3_lpm_permit_show()
246 if (port_dev->usb3_lpm_u2_permit) in usb3_lpm_permit_show()
251 if (port_dev->usb3_lpm_u2_permit) in usb3_lpm_permit_show()
265 struct usb_device *udev = port_dev->child; in usb3_lpm_permit_store()
269 port_dev->usb3_lpm_u1_permit = 1; in usb3_lpm_permit_store()
270 port_dev->usb3_lpm_u2_permit = 1; in usb3_lpm_permit_store()
273 port_dev->usb3_lpm_u1_permit = 1; in usb3_lpm_permit_store()
274 port_dev->usb3_lpm_u2_permit = 0; in usb3_lpm_permit_store()
277 port_dev->usb3_lpm_u1_permit = 0; in usb3_lpm_permit_store()
278 port_dev->usb3_lpm_u2_permit = 1; in usb3_lpm_permit_store()
281 port_dev->usb3_lpm_u1_permit = 0; in usb3_lpm_permit_store()
282 port_dev->usb3_lpm_u2_permit = 0; in usb3_lpm_permit_store()
284 return -EINVAL; in usb3_lpm_permit_store()
290 hcd = bus_to_hcd(udev->bus); in usb3_lpm_permit_store()
292 return -EINVAL; in usb3_lpm_permit_store()
294 mutex_lock(hcd->bandwidth_mutex); in usb3_lpm_permit_store()
297 mutex_unlock(hcd->bandwidth_mutex); in usb3_lpm_permit_store()
344 kfree(port_dev->req); in usb_port_device_release()
352 struct usb_device *hdev = to_usb_device(dev->parent->parent); in usb_port_runtime_resume()
353 struct usb_interface *intf = to_usb_interface(dev->parent); in usb_port_runtime_resume()
354 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_port_runtime_resume() local
355 struct usb_device *udev = port_dev->child; in usb_port_runtime_resume()
356 struct usb_port *peer = port_dev->peer; in usb_port_runtime_resume() local
357 int port1 = port_dev->portnum; in usb_port_runtime_resume()
360 if (!hub) in usb_port_runtime_resume()
361 return -EINVAL; in usb_port_runtime_resume()
362 if (hub->in_reset) { in usb_port_runtime_resume()
363 set_bit(port1, hub->power_bits); in usb_port_runtime_resume()
368 * Power on our usb3 peer before this usb2 port to prevent a usb3 in usb_port_runtime_resume()
371 if (!port_dev->is_superspeed && peer) in usb_port_runtime_resume()
372 pm_runtime_get_sync(&peer->dev); in usb_port_runtime_resume()
378 retval = usb_hub_set_port_power(hdev, hub, port1, true); in usb_port_runtime_resume()
379 msleep(hub_power_on_good_delay(hub)); in usb_port_runtime_resume()
390 if (hub_port_debounce_be_connected(hub, port1) < 0) { in usb_port_runtime_resume()
391 dev_dbg(&port_dev->dev, "reconnect timeout\n"); in usb_port_runtime_resume()
393 set_bit(port1, hub->warm_reset_bits); in usb_port_runtime_resume()
397 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_runtime_resume()
398 pm_runtime_get_noresume(&port_dev->dev); in usb_port_runtime_resume()
399 pm_request_resume(&udev->dev); in usb_port_runtime_resume()
411 struct usb_device *hdev = to_usb_device(dev->parent->parent); in usb_port_runtime_suspend()
412 struct usb_interface *intf = to_usb_interface(dev->parent); in usb_port_runtime_suspend()
413 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_port_runtime_suspend() local
414 struct usb_port *peer = port_dev->peer; in usb_port_runtime_suspend() local
415 int port1 = port_dev->portnum; in usb_port_runtime_suspend()
418 if (!hub) in usb_port_runtime_suspend()
419 return -EINVAL; in usb_port_runtime_suspend()
420 if (hub->in_reset) in usb_port_runtime_suspend()
421 return -EBUSY; in usb_port_runtime_suspend()
423 if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) in usb_port_runtime_suspend()
425 return -EAGAIN; in usb_port_runtime_suspend()
428 return -EBUSY; in usb_port_runtime_suspend()
434 retval = usb_hub_set_port_power(hdev, hub, port1, false); in usb_port_runtime_suspend()
436 if (!port_dev->is_superspeed) in usb_port_runtime_suspend()
441 * Our peer usb3 port may now be able to suspend, so in usb_port_runtime_suspend()
445 if (!port_dev->is_superspeed && peer) in usb_port_runtime_suspend()
446 pm_runtime_put(&peer->dev); in usb_port_runtime_suspend()
456 if (port_dev->child) { in usb_port_shutdown()
457 usb_disable_usb2_hardware_lpm(port_dev->child); in usb_port_shutdown()
458 usb_unlocked_disable_lpm(port_dev->child); in usb_port_shutdown()
486 if (left->peer == right && right->peer == left) in link_peers()
489 if (left->peer || right->peer) { in link_peers()
490 struct usb_port *lpeer = left->peer; in link_peers()
491 struct usb_port *rpeer = right->peer; in link_peers()
494 if (left->location && left->location == right->location) in link_peers()
499 pr_debug("usb: failed to peer %s and %s by %s (%s:%s) (%s:%s)\n", in link_peers()
500 dev_name(&left->dev), dev_name(&right->dev), method, in link_peers()
501 dev_name(&left->dev), in link_peers()
502 lpeer ? dev_name(&lpeer->dev) : "none", in link_peers()
503 dev_name(&right->dev), in link_peers()
504 rpeer ? dev_name(&rpeer->dev) : "none"); in link_peers()
505 return -EBUSY; in link_peers()
508 rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer"); in link_peers()
511 rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer"); in link_peers()
513 sysfs_remove_link(&left->dev.kobj, "peer"); in link_peers()
519 * setting ->peer with usb_port_runtime_suspend(). Otherwise we in link_peers()
522 if (left->is_superspeed) { in link_peers()
524 WARN_ON(right->is_superspeed); in link_peers()
528 WARN_ON(!right->is_superspeed); in link_peers()
531 pm_runtime_get_sync(&hs_port->dev); in link_peers()
533 left->peer = right; in link_peers()
534 right->peer = left; in link_peers()
540 * device degrading to its powered-off HiSpeed connection. in link_peers()
544 pm_runtime_get_sync(&ss_port->dev); in link_peers()
545 pm_runtime_put(&hs_port->dev); in link_peers()
556 dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev)); in link_peers_report()
558 dev_dbg(&left->dev, "failed to peer to %s (%d)\n", in link_peers_report()
559 dev_name(&right->dev), rc); in link_peers_report()
569 WARN(right->peer != left || left->peer != right, in unlink_peers()
571 dev_name(&left->dev), dev_name(&right->dev)); in unlink_peers()
576 * when ->peer is !NULL. in unlink_peers()
578 if (left->is_superspeed) { in unlink_peers()
586 pm_runtime_get_sync(&hs_port->dev); in unlink_peers()
588 sysfs_remove_link(&left->dev.kobj, "peer"); in unlink_peers()
589 right->peer = NULL; in unlink_peers()
590 sysfs_remove_link(&right->dev.kobj, "peer"); in unlink_peers()
591 left->peer = NULL; in unlink_peers()
594 pm_runtime_put(&ss_port->dev); in unlink_peers()
597 pm_runtime_put(&hs_port->dev); in unlink_peers()
601 * For each usb hub device in the system check to see if it is in the
602 * peer domain of the given port_dev, and if it is check to see if it
609 struct usb_port *port_dev = p, *peer; in match_location() local
611 struct usb_device *hdev = to_usb_device(port_dev->dev.parent->parent); in match_location()
613 if (!peer_hub || port_dev->connect_type == USB_PORT_NOT_USED) in match_location()
616 hcd = bus_to_hcd(hdev->bus); in match_location()
617 peer_hcd = bus_to_hcd(peer_hdev->bus); in match_location()
618 /* peer_hcd is provisional until we verify it against the known peer */ in match_location()
619 if (peer_hcd != hcd->shared_hcd) in match_location()
622 for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) { in match_location()
623 peer = peer_hub->ports[port1 - 1]; in match_location()
624 if (peer && peer->connect_type != USB_PORT_NOT_USED && in match_location()
625 peer->location == port_dev->location) { in match_location()
626 link_peers_report(port_dev, peer); in match_location()
635 * Find the peer port either via explicit platform firmware "location"
636 * data, the peer hcd for root hubs, or the upstream peer relationship
639 static void find_and_link_peer(struct usb_hub *hub, int port1) in find_and_link_peer() argument
641 struct usb_port *port_dev = hub->ports[port1 - 1], *peer; in find_and_link_peer() local
642 struct usb_device *hdev = hub->hdev; in find_and_link_peer()
647 * If location data is available then we can only peer this port in find_and_link_peer()
648 * by a location match, not the default peer (lest we create a in find_and_link_peer()
652 if (port_dev->location) { in find_and_link_peer()
653 /* we link the peer in match_location() if found */ in find_and_link_peer()
656 } else if (!hdev->parent) { in find_and_link_peer()
657 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in find_and_link_peer()
658 struct usb_hcd *peer_hcd = hcd->shared_hcd; in find_and_link_peer()
663 peer_hdev = peer_hcd->self.root_hub; in find_and_link_peer()
666 struct usb_device *parent = hdev->parent; in find_and_link_peer()
672 upstream = parent_hub->ports[hdev->portnum - 1]; in find_and_link_peer()
673 if (!upstream || !upstream->peer) in find_and_link_peer()
676 peer_hdev = upstream->peer->child; in find_and_link_peer()
680 if (!peer_hub || port1 > peer_hdev->maxchild) in find_and_link_peer()
684 * we found a valid default peer, last check is to make sure it in find_and_link_peer()
687 peer = peer_hub->ports[port1 - 1]; in find_and_link_peer()
688 if (peer && peer->location == 0) in find_and_link_peer()
689 link_peers_report(port_dev, peer); in find_and_link_peer()
697 ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector"); in connector_bind()
701 ret = sysfs_create_link(&connector->kobj, &dev->kobj, dev_name(dev)); in connector_bind()
703 sysfs_remove_link(&dev->kobj, "connector"); in connector_bind()
707 port_dev->connector = data; in connector_bind()
711 * Type-C connector know about it immediately. in connector_bind()
713 if (port_dev->child) in connector_bind()
714 typec_attach(port_dev->connector, &port_dev->child->dev); in connector_bind()
723 sysfs_remove_link(&connector->kobj, dev_name(dev)); in connector_unbind()
724 sysfs_remove_link(&dev->kobj, "connector"); in connector_unbind()
725 port_dev->connector = NULL; in connector_unbind()
733 int usb_hub_create_port_device(struct usb_hub *hub, int port1) in usb_hub_create_port_device() argument
736 struct usb_device *hdev = hub->hdev; in usb_hub_create_port_device()
741 return -ENOMEM; in usb_hub_create_port_device()
743 port_dev->req = kzalloc(sizeof(*(port_dev->req)), GFP_KERNEL); in usb_hub_create_port_device()
744 if (!port_dev->req) { in usb_hub_create_port_device()
746 return -ENOMEM; in usb_hub_create_port_device()
749 port_dev->connect_type = usb_of_get_connect_type(hdev, port1); in usb_hub_create_port_device()
750 hub->ports[port1 - 1] = port_dev; in usb_hub_create_port_device()
751 port_dev->portnum = port1; in usb_hub_create_port_device()
752 set_bit(port1, hub->power_bits); in usb_hub_create_port_device()
753 port_dev->dev.parent = hub->intfdev; in usb_hub_create_port_device()
755 port_dev->is_superspeed = 1; in usb_hub_create_port_device()
756 port_dev->usb3_lpm_u1_permit = 1; in usb_hub_create_port_device()
757 port_dev->usb3_lpm_u2_permit = 1; in usb_hub_create_port_device()
758 port_dev->dev.groups = port_dev_usb3_group; in usb_hub_create_port_device()
760 port_dev->dev.groups = port_dev_group; in usb_hub_create_port_device()
761 port_dev->dev.type = &usb_port_device_type; in usb_hub_create_port_device()
762 port_dev->dev.driver = &usb_port_driver; in usb_hub_create_port_device()
763 dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev), in usb_hub_create_port_device()
765 mutex_init(&port_dev->status_lock); in usb_hub_create_port_device()
766 retval = device_register(&port_dev->dev); in usb_hub_create_port_device()
768 put_device(&port_dev->dev); in usb_hub_create_port_device()
772 port_dev->state_kn = sysfs_get_dirent(port_dev->dev.kobj.sd, "state"); in usb_hub_create_port_device()
773 if (!port_dev->state_kn) { in usb_hub_create_port_device()
774 dev_err(&port_dev->dev, "failed to sysfs_get_dirent 'state'\n"); in usb_hub_create_port_device()
775 retval = -ENODEV; in usb_hub_create_port_device()
779 /* Set default policy of port-poweroff disabled. */ in usb_hub_create_port_device()
780 retval = dev_pm_qos_add_request(&port_dev->dev, port_dev->req, in usb_hub_create_port_device()
786 retval = component_add(&port_dev->dev, &connector_ops); in usb_hub_create_port_device()
788 dev_warn(&port_dev->dev, "failed to add component\n"); in usb_hub_create_port_device()
792 find_and_link_peer(hub, port1); in usb_hub_create_port_device()
797 * and the hub has been fully registered (hdev->maxchild set). in usb_hub_create_port_device()
799 pm_runtime_set_active(&port_dev->dev); in usb_hub_create_port_device()
800 pm_runtime_get_noresume(&port_dev->dev); in usb_hub_create_port_device()
801 pm_runtime_enable(&port_dev->dev); in usb_hub_create_port_device()
802 device_enable_async_suspend(&port_dev->dev); in usb_hub_create_port_device()
805 * Keep hidden the ability to enable port-poweroff if the hub in usb_hub_create_port_device()
808 if (!hub_is_port_power_switchable(hub)) in usb_hub_create_port_device()
812 retval = dev_pm_qos_expose_flags(&port_dev->dev, in usb_hub_create_port_device()
815 dev_warn(&port_dev->dev, "failed to expose pm_qos_no_poweroff\n"); in usb_hub_create_port_device()
820 retval = dev_pm_qos_remove_request(port_dev->req); in usb_hub_create_port_device()
822 kfree(port_dev->req); in usb_hub_create_port_device()
823 port_dev->req = NULL; in usb_hub_create_port_device()
828 sysfs_put(port_dev->state_kn); in usb_hub_create_port_device()
830 device_unregister(&port_dev->dev); in usb_hub_create_port_device()
835 void usb_hub_remove_port_device(struct usb_hub *hub, int port1) in usb_hub_remove_port_device() argument
837 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_hub_remove_port_device()
838 struct usb_port *peer; in usb_hub_remove_port_device() local
840 peer = port_dev->peer; in usb_hub_remove_port_device()
841 if (peer) in usb_hub_remove_port_device()
842 unlink_peers(port_dev, peer); in usb_hub_remove_port_device()
843 component_del(&port_dev->dev, &connector_ops); in usb_hub_remove_port_device()
844 sysfs_put(port_dev->state_kn); in usb_hub_remove_port_device()
845 device_unregister(&port_dev->dev); in usb_hub_remove_port_device()