Lines Matching defs:link

148 	struct device_link *link;
163 list_for_each_entry(link, &dev->links.consumers, s_node) {
164 if (link->flags == (DL_FLAG_SYNC_STATE_ONLY | DL_FLAG_MANAGED))
167 if (link->consumer == target)
170 ret = device_is_dependent(link->consumer, target);
177 static void device_link_init_status(struct device_link *link,
186 * A consumer driver can create a link to a supplier
192 link->status = DL_STATE_CONSUMER_PROBE;
195 link->status = DL_STATE_DORMANT;
202 link->status = DL_STATE_CONSUMER_PROBE;
205 link->status = DL_STATE_ACTIVE;
208 link->status = DL_STATE_AVAILABLE;
213 link->status = DL_STATE_SUPPLIER_UNBIND;
216 link->status = DL_STATE_DORMANT;
223 struct device_link *link;
236 list_for_each_entry(link, &dev->links.consumers, s_node) {
237 if (link->flags == (DL_FLAG_SYNC_STATE_ONLY | DL_FLAG_MANAGED))
239 device_reorder_to_tail(link->consumer, NULL);
303 struct device_link *link = to_devlink(dev);
306 if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
308 else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER)
320 struct device_link *link = to_devlink(dev);
322 return sysfs_emit(buf, "%d\n", !!(link->flags & DL_FLAG_PM_RUNTIME));
329 struct device_link *link = to_devlink(dev);
332 !!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
347 struct device_link *link = container_of(work, struct device_link, rm_work);
349 /* Ensure that all references to the link object have been dropped. */
352 pm_runtime_release_supplier(link);
353 pm_request_idle(link->supplier);
355 put_device(link->consumer);
356 put_device(link->supplier);
357 kfree(link);
362 struct device_link *link = to_devlink(dev);
364 INIT_WORK(&link->rm_work, device_link_release_fn);
371 queue_work(system_long_wq, &link->rm_work);
386 struct device_link *link = to_devlink(dev);
387 struct device *sup = link->supplier;
388 struct device *con = link->consumer;
399 ret = sysfs_create_link(&link->link_dev.kobj, &sup->kobj, "supplier");
403 ret = sysfs_create_link(&link->link_dev.kobj, &con->kobj, "consumer");
408 ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
413 ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
423 sysfs_remove_link(&link->link_dev.kobj, "consumer");
425 sysfs_remove_link(&link->link_dev.kobj, "supplier");
434 struct device_link *link = to_devlink(dev);
436 struct device *sup = link->supplier;
437 struct device *con = link->consumer;
440 sysfs_remove_link(&link->link_dev.kobj, "consumer");
441 sysfs_remove_link(&link->link_dev.kobj, "supplier");
449 WARN(1, "Unable to properly free device link symlinks!\n");
493 * device_link_add - Create a link between two devices.
494 * @consumer: Consumer end of the link.
495 * @supplier: Supplier end of the link.
498 * The caller is responsible for the proper synchronization of the link creation
500 * runtime PM framework to take the link into account. Second, if the
503 * of the link. If DL_FLAG_PM_RUNTIME is not set, DL_FLAG_RPM_ACTIVE will be
507 * expected to release the link returned by it directly with the help of either
511 * management of the link over to the driver core entirely and its return value
512 * can only be used to check whether or not the link is present. In that case,
513 * the DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER device link
514 * flags can be used to indicate to the driver core when the link can be safely
516 * that the link is not going to be used (by the given caller of this function)
518 * device, so the link can be deleted at that point. If none of them is set,
519 * the link will be maintained until one of the devices pointed to by it (either
524 * managed device link is being added), the DL_FLAG_AUTOPROBE_CONSUMER flag can
531 * However, if a device link between the given @consumer and @supplier pair
532 * exists already when this function is called for them, the existing link will
533 * be returned regardless of its current type and status (the link's flags may
535 * the link as though it has just been created, so (in particular) if
536 * DL_FLAG_STATELESS was passed in @flags, the link needs to be released
539 * A side effect of the link creation is re-ordering of dpm_list and the
551 struct device_link *link;
579 * the supplier already in the graph, return NULL. If the link is a
580 * SYNC_STATE_ONLY link, we don't check for reverse dependencies
586 link = NULL;
591 * DL_FLAG_AUTOREMOVE_SUPPLIER indicates that the link will be needed
598 list_for_each_entry(link, &supplier->links.consumers, s_node) {
599 if (link->consumer != consumer)
603 if (!(link->flags & DL_FLAG_PM_RUNTIME)) {
605 link->flags |= DL_FLAG_PM_RUNTIME;
608 refcount_inc(&link->rpm_active);
612 kref_get(&link->kref);
613 if (link->flags & DL_FLAG_SYNC_STATE_ONLY &&
614 !(link->flags & DL_FLAG_STATELESS)) {
615 link->flags |= DL_FLAG_STATELESS;
618 link->flags |= DL_FLAG_STATELESS;
624 * If the life time of the link following from the new flags is
625 * longer than indicated by the flags of the existing link,
626 * update the existing link to stay around longer.
629 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) {
630 link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER;
631 link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER;
634 link->flags &= ~(DL_FLAG_AUTOREMOVE_CONSUMER |
637 if (!(link->flags & DL_FLAG_MANAGED)) {
638 kref_get(&link->kref);
639 link->flags |= DL_FLAG_MANAGED;
640 device_link_init_status(link, consumer, supplier);
642 if (link->flags & DL_FLAG_SYNC_STATE_ONLY &&
644 link->flags &= ~DL_FLAG_SYNC_STATE_ONLY;
651 link = kzalloc(sizeof(*link), GFP_KERNEL);
652 if (!link)
655 refcount_set(&link->rpm_active, 1);
658 link->supplier = supplier;
659 INIT_LIST_HEAD(&link->s_node);
661 link->consumer = consumer;
662 INIT_LIST_HEAD(&link->c_node);
663 link->flags = flags;
664 kref_init(&link->kref);
666 link->link_dev.class = &devlink_class;
667 device_set_pm_not_required(&link->link_dev);
668 dev_set_name(&link->link_dev, "%s:%s--%s:%s",
671 if (device_register(&link->link_dev)) {
672 put_device(&link->link_dev);
673 link = NULL;
679 refcount_inc(&link->rpm_active);
684 /* Determine the initial link state. */
686 link->status = DL_STATE_NONE;
688 device_link_init_status(link, consumer, supplier);
691 * Some callers expect the link creation during consumer driver probe to
694 if (link->status == DL_STATE_CONSUMER_PROBE &&
698 list_add_tail_rcu(&link->s_node, &supplier->links.consumers);
699 list_add_tail_rcu(&link->c_node, &consumer->links.suppliers);
724 if ((flags & DL_FLAG_PM_RUNTIME && flags & DL_FLAG_RPM_ACTIVE) && !link)
727 return link;
802 struct device_link *link = container_of(kref, struct device_link, kref);
804 dev_dbg(link->consumer, "Dropping the link to %s\n",
805 dev_name(link->supplier));
807 pm_runtime_drop_link(link);
809 list_del_rcu(&link->s_node);
810 list_del_rcu(&link->c_node);
811 device_unregister(&link->link_dev);
816 struct device_link *link = container_of(kref, struct device_link, kref);
818 dev_info(link->consumer, "Dropping the link to %s\n",
819 dev_name(link->supplier));
821 pm_runtime_drop_link(link);
823 list_del(&link->s_node);
824 list_del(&link->c_node);
825 device_unregister(&link->link_dev);
829 static void device_link_put_kref(struct device_link *link)
831 if (link->flags & DL_FLAG_STATELESS)
832 kref_put(&link->kref, __device_link_del);
834 WARN(1, "Unable to drop a managed device link reference\n");
838 * device_link_del - Delete a stateless link between two devices.
839 * @link: Device link to delete.
842 * PM. If the link was added multiple times, it needs to be deleted as often.
846 void device_link_del(struct device_link *link)
849 device_link_put_kref(link);
855 * device_link_remove - Delete a stateless link between two devices.
856 * @consumer: Consumer end of the link.
857 * @supplier: Supplier end of the link.
864 struct device_link *link;
871 list_for_each_entry(link, &supplier->links.consumers, s_node) {
872 if (link->consumer == consumer) {
873 device_link_put_kref(link);
884 struct device_link *link;
886 list_for_each_entry(link, &dev->links.suppliers, c_node) {
887 if (link->status != DL_STATE_CONSUMER_PROBE)
890 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) {
891 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
893 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
894 WRITE_ONCE(link->status, DL_STATE_DORMANT);
910 * mark the link as "consumer probe in progress" to make the supplier removal
917 struct device_link *link;
934 list_for_each_entry(link, &dev->links.suppliers, c_node) {
935 if (!(link->flags & DL_FLAG_MANAGED))
938 if (link->status != DL_STATE_AVAILABLE &&
939 !(link->flags & DL_FLAG_SYNC_STATE_ONLY)) {
944 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
973 struct device_link *link;
980 list_for_each_entry(link, &dev->links.consumers, s_node) {
981 if (!(link->flags & DL_FLAG_MANAGED))
983 if (link->status != DL_STATE_ACTIVE)
1082 static void device_link_drop_managed(struct device_link *link)
1084 link->flags &= ~DL_FLAG_MANAGED;
1085 WRITE_ONCE(link->status, DL_STATE_NONE);
1086 kref_put(&link->kref, __device_link_del);
1118 struct device_link *link, *ln;
1133 list_for_each_entry(link, &dev->links.consumers, s_node) {
1134 if (!(link->flags & DL_FLAG_MANAGED))
1143 if (link->status == DL_STATE_CONSUMER_PROBE ||
1144 link->status == DL_STATE_ACTIVE)
1147 WARN_ON(link->status != DL_STATE_DORMANT);
1148 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
1150 if (link->flags & DL_FLAG_AUTOPROBE_CONSUMER)
1151 driver_deferred_probe_add(link->consumer);
1159 list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) {
1162 if (!(link->flags & DL_FLAG_MANAGED))
1165 supplier = link->supplier;
1166 if (link->flags & DL_FLAG_SYNC_STATE_ONLY) {
1170 * save to drop the managed link completely.
1172 device_link_drop_managed(link);
1174 WARN_ON(link->status != DL_STATE_CONSUMER_PROBE);
1175 WRITE_ONCE(link->status, DL_STATE_ACTIVE);
1180 * DL_FLAG_SYNC_STATE_ONLY device link in case it was the last
1181 * device link that was preventing the supplier from getting a
1211 struct device_link *link, *ln;
1213 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) {
1214 if (!(link->flags & DL_FLAG_MANAGED))
1217 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) {
1218 device_link_drop_managed(link);
1222 if (link->status != DL_STATE_CONSUMER_PROBE &&
1223 link->status != DL_STATE_ACTIVE)
1226 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) {
1227 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
1229 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
1230 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1249 struct device_link *link;
1253 list_for_each_entry(link, &dev->links.consumers, s_node) {
1254 if (!(link->flags & DL_FLAG_MANAGED))
1258 * The probe has failed, so if the status of the link is
1264 if (link->status == DL_STATE_CONSUMER_PROBE ||
1265 link->status == DL_STATE_ACTIVE)
1266 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1286 struct device_link *link, *ln;
1290 list_for_each_entry_safe(link, ln, &dev->links.consumers, s_node) {
1291 if (!(link->flags & DL_FLAG_MANAGED))
1294 WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER);
1295 WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
1299 * devices that are not active, i.e. where the link state
1302 if (link->status == DL_STATE_SUPPLIER_UNBIND &&
1303 link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
1304 device_link_drop_managed(link);
1306 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1319 * Check each consumer of the device and return 'true' if its link's status
1321 * probing right now or its driver is present). Otherwise, change the link
1331 struct device_link *link;
1336 list_for_each_entry(link, &dev->links.consumers, s_node) {
1337 if (!(link->flags & DL_FLAG_MANAGED))
1340 if (link->status == DL_STATE_CONSUMER_PROBE
1341 || link->status == DL_STATE_ACTIVE) {
1345 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND);
1362 * If that's not the case, change the status of the link to "supplier unbind"
1363 * and check if the link was in the "active" state. If so, force the consumer
1365 * changed the state of the link already).
1371 struct device_link *link;
1376 list_for_each_entry(link, &dev->links.consumers, s_node) {
1379 if (!(link->flags & DL_FLAG_MANAGED) ||
1380 link->flags & DL_FLAG_SYNC_STATE_ONLY)
1383 status = link->status;
1390 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND);
1392 struct device *consumer = link->consumer;
1414 struct device_link *link, *ln;
1429 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) {
1430 WARN_ON(link->status == DL_STATE_ACTIVE);
1431 __device_link_del(&link->kref);
1434 list_for_each_entry_safe_reverse(link, ln, &dev->links.consumers, s_node) {
1435 WARN_ON(link->status != DL_STATE_DORMANT &&
1436 link->status != DL_STATE_NONE);
1437 __device_link_del(&link->kref);
1494 * suppliers they need to link to later. Then, when the fw_devlink is
1495 * resumed, all these devices will get a chance to try and link to any
1533 * able to link to newly added devices.
1541 * when a lot of devices that need to link to each other are added in a short
1552 * all the supplier devices already registered and ready to link to. It won't
2712 dev_warn(dev, "Error %d creating of_node link\n",error);
2738 /* link in the class directory pointing to the device */
2800 * the link.
2985 * link to it.
2991 * waiting consumers can link to it before the driver is bound to the