Lines Matching +full:system +full:- +full:ctl
1 // SPDX-License-Identifier: GPL-2.0
26 if (id->match_flags & TBSVC_MATCH_PROTOCOL_KEY) { in match_service_id()
27 if (strcmp(id->protocol_key, svc->key)) in match_service_id()
31 if (id->match_flags & TBSVC_MATCH_PROTOCOL_ID) { in match_service_id()
32 if (id->protocol_id != svc->prtcid) in match_service_id()
36 if (id->match_flags & TBSVC_MATCH_PROTOCOL_VERSION) { in match_service_id()
37 if (id->protocol_version != svc->prtcvers) in match_service_id()
41 if (id->match_flags & TBSVC_MATCH_PROTOCOL_VERSION) { in match_service_id()
42 if (id->protocol_revision != svc->prtcrevs) in match_service_id()
61 if (!driver->id_table) in __tb_service_match()
64 for (ids = driver->id_table; ids->match_flags != 0; ids++) { in __tb_service_match()
83 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_probe()
84 id = __tb_service_match(dev, &driver->driver); in tb_service_probe()
86 return driver->probe(svc, id); in tb_service_probe()
94 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_remove()
95 if (driver->remove) in tb_service_remove()
96 driver->remove(svc); in tb_service_remove()
107 if (!svc || !dev->driver) in tb_service_shutdown()
110 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_shutdown()
111 if (driver->shutdown) in tb_service_shutdown()
112 driver->shutdown(svc); in tb_service_shutdown()
131 uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_show()
133 return -ENOMEM; in boot_acl_show()
135 pm_runtime_get_sync(&tb->dev); in boot_acl_show()
137 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_show()
138 ret = -ERESTARTSYS; in boot_acl_show()
141 ret = tb->cm_ops->get_boot_acl(tb, uuids, tb->nboot_acl); in boot_acl_show()
143 mutex_unlock(&tb->lock); in boot_acl_show()
146 mutex_unlock(&tb->lock); in boot_acl_show()
148 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { in boot_acl_show()
150 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%pUb", in boot_acl_show()
153 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s", in boot_acl_show()
154 i < tb->nboot_acl - 1 ? "," : "\n"); in boot_acl_show()
158 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_show()
159 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_show()
175 * Make sure the value is not bigger than tb->nboot_acl * UUID in boot_acl_store()
177 * string is tb->nboot_acl * ",". in boot_acl_store()
179 if (count > (UUID_STRING_LEN + 1) * tb->nboot_acl + 1) in boot_acl_store()
180 return -EINVAL; in boot_acl_store()
181 if (count < tb->nboot_acl - 1) in boot_acl_store()
182 return -EINVAL; in boot_acl_store()
186 return -ENOMEM; in boot_acl_store()
188 acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_store()
190 ret = -ENOMEM; in boot_acl_store()
195 while ((s = strsep(&uuid_str, ",")) != NULL && i < tb->nboot_acl) { in boot_acl_store()
200 ret = -EINVAL; in boot_acl_store()
211 if (s || i < tb->nboot_acl) { in boot_acl_store()
212 ret = -EINVAL; in boot_acl_store()
216 pm_runtime_get_sync(&tb->dev); in boot_acl_store()
218 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_store()
219 ret = -ERESTARTSYS; in boot_acl_store()
222 ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); in boot_acl_store()
225 kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); in boot_acl_store()
227 mutex_unlock(&tb->lock); in boot_acl_store()
230 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_store()
231 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_store()
261 if (tb->security_level < ARRAY_SIZE(tb_security_names)) in security_show()
262 name = tb_security_names[tb->security_level]; in security_show()
282 if (tb->nboot_acl && in domain_attr_is_visible()
283 tb->cm_ops->get_boot_acl && in domain_attr_is_visible()
284 tb->cm_ops->set_boot_acl) in domain_attr_is_visible()
285 return attr->mode; in domain_attr_is_visible()
289 return attr->mode; in domain_attr_is_visible()
314 tb_ctl_free(tb->ctl); in tb_domain_release()
315 destroy_workqueue(tb->wq); in tb_domain_release()
316 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_release()
317 mutex_destroy(&tb->lock); in tb_domain_release()
327 * tb_domain_alloc() - Allocate a domain
336 * to the system.
346 * expects because bit-fields are being used. in tb_domain_alloc()
356 tb->nhi = nhi; in tb_domain_alloc()
357 mutex_init(&tb->lock); in tb_domain_alloc()
359 tb->index = ida_simple_get(&tb_domain_ida, 0, 0, GFP_KERNEL); in tb_domain_alloc()
360 if (tb->index < 0) in tb_domain_alloc()
363 tb->wq = alloc_ordered_workqueue("thunderbolt%d", 0, tb->index); in tb_domain_alloc()
364 if (!tb->wq) in tb_domain_alloc()
367 tb->dev.parent = &nhi->pdev->dev; in tb_domain_alloc()
368 tb->dev.bus = &tb_bus_type; in tb_domain_alloc()
369 tb->dev.type = &tb_domain_type; in tb_domain_alloc()
370 tb->dev.groups = domain_attr_groups; in tb_domain_alloc()
371 dev_set_name(&tb->dev, "domain%d", tb->index); in tb_domain_alloc()
372 device_initialize(&tb->dev); in tb_domain_alloc()
377 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_alloc()
389 if (!tb->cm_ops->handle_event) { in tb_domain_event_cb()
400 tb->cm_ops->handle_event(tb, type, buf, size); in tb_domain_event_cb()
407 * tb_domain_add() - Add domain to the system
410 * Starts the domain and adds it to the system. Hotplugging devices will
421 if (WARN_ON(!tb->cm_ops)) in tb_domain_add()
422 return -EINVAL; in tb_domain_add()
424 mutex_lock(&tb->lock); in tb_domain_add()
426 tb->ctl = tb_ctl_alloc(tb->nhi, tb_domain_event_cb, tb); in tb_domain_add()
427 if (!tb->ctl) { in tb_domain_add()
428 ret = -ENOMEM; in tb_domain_add()
436 tb_ctl_start(tb->ctl); in tb_domain_add()
438 if (tb->cm_ops->driver_ready) { in tb_domain_add()
439 ret = tb->cm_ops->driver_ready(tb); in tb_domain_add()
444 ret = device_add(&tb->dev); in tb_domain_add()
449 if (tb->cm_ops->start) { in tb_domain_add()
450 ret = tb->cm_ops->start(tb); in tb_domain_add()
456 mutex_unlock(&tb->lock); in tb_domain_add()
458 device_init_wakeup(&tb->dev, true); in tb_domain_add()
460 pm_runtime_no_callbacks(&tb->dev); in tb_domain_add()
461 pm_runtime_set_active(&tb->dev); in tb_domain_add()
462 pm_runtime_enable(&tb->dev); in tb_domain_add()
463 pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); in tb_domain_add()
464 pm_runtime_mark_last_busy(&tb->dev); in tb_domain_add()
465 pm_runtime_use_autosuspend(&tb->dev); in tb_domain_add()
470 device_del(&tb->dev); in tb_domain_add()
472 tb_ctl_stop(tb->ctl); in tb_domain_add()
474 mutex_unlock(&tb->lock); in tb_domain_add()
480 * tb_domain_remove() - Removes and releases a domain
483 * Stops the domain, removes it from the system and releases all
488 mutex_lock(&tb->lock); in tb_domain_remove()
489 if (tb->cm_ops->stop) in tb_domain_remove()
490 tb->cm_ops->stop(tb); in tb_domain_remove()
492 tb_ctl_stop(tb->ctl); in tb_domain_remove()
493 mutex_unlock(&tb->lock); in tb_domain_remove()
495 flush_workqueue(tb->wq); in tb_domain_remove()
496 device_unregister(&tb->dev); in tb_domain_remove()
500 * tb_domain_suspend_noirq() - Suspend a domain
514 mutex_lock(&tb->lock); in tb_domain_suspend_noirq()
515 if (tb->cm_ops->suspend_noirq) in tb_domain_suspend_noirq()
516 ret = tb->cm_ops->suspend_noirq(tb); in tb_domain_suspend_noirq()
518 tb_ctl_stop(tb->ctl); in tb_domain_suspend_noirq()
519 mutex_unlock(&tb->lock); in tb_domain_suspend_noirq()
525 * tb_domain_resume_noirq() - Resume a domain
528 * Re-starts the control channel, and resumes all devices connected to
535 mutex_lock(&tb->lock); in tb_domain_resume_noirq()
536 tb_ctl_start(tb->ctl); in tb_domain_resume_noirq()
537 if (tb->cm_ops->resume_noirq) in tb_domain_resume_noirq()
538 ret = tb->cm_ops->resume_noirq(tb); in tb_domain_resume_noirq()
539 mutex_unlock(&tb->lock); in tb_domain_resume_noirq()
546 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0; in tb_domain_suspend()
553 mutex_lock(&tb->lock); in tb_domain_freeze_noirq()
554 if (tb->cm_ops->freeze_noirq) in tb_domain_freeze_noirq()
555 ret = tb->cm_ops->freeze_noirq(tb); in tb_domain_freeze_noirq()
557 tb_ctl_stop(tb->ctl); in tb_domain_freeze_noirq()
558 mutex_unlock(&tb->lock); in tb_domain_freeze_noirq()
567 mutex_lock(&tb->lock); in tb_domain_thaw_noirq()
568 tb_ctl_start(tb->ctl); in tb_domain_thaw_noirq()
569 if (tb->cm_ops->thaw_noirq) in tb_domain_thaw_noirq()
570 ret = tb->cm_ops->thaw_noirq(tb); in tb_domain_thaw_noirq()
571 mutex_unlock(&tb->lock); in tb_domain_thaw_noirq()
578 if (tb->cm_ops->complete) in tb_domain_complete()
579 tb->cm_ops->complete(tb); in tb_domain_complete()
584 if (tb->cm_ops->runtime_suspend) { in tb_domain_runtime_suspend()
585 int ret = tb->cm_ops->runtime_suspend(tb); in tb_domain_runtime_suspend()
589 tb_ctl_stop(tb->ctl); in tb_domain_runtime_suspend()
595 tb_ctl_start(tb->ctl); in tb_domain_runtime_resume()
596 if (tb->cm_ops->runtime_resume) { in tb_domain_runtime_resume()
597 int ret = tb->cm_ops->runtime_resume(tb); in tb_domain_runtime_resume()
605 * tb_domain_approve_switch() - Approve switch
617 if (!tb->cm_ops->approve_switch) in tb_domain_approve_switch()
618 return -EPERM; in tb_domain_approve_switch()
621 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_approve_switch()
622 if (!parent_sw || !parent_sw->authorized) in tb_domain_approve_switch()
623 return -EINVAL; in tb_domain_approve_switch()
625 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch()
629 * tb_domain_approve_switch_key() - Approve switch and add key
644 if (!tb->cm_ops->approve_switch || !tb->cm_ops->add_switch_key) in tb_domain_approve_switch_key()
645 return -EPERM; in tb_domain_approve_switch_key()
648 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_approve_switch_key()
649 if (!parent_sw || !parent_sw->authorized) in tb_domain_approve_switch_key()
650 return -EINVAL; in tb_domain_approve_switch_key()
652 ret = tb->cm_ops->add_switch_key(tb, sw); in tb_domain_approve_switch_key()
656 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch_key()
660 * tb_domain_challenge_switch_key() - Challenge and approve switch
681 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) in tb_domain_challenge_switch_key()
682 return -EPERM; in tb_domain_challenge_switch_key()
685 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_challenge_switch_key()
686 if (!parent_sw || !parent_sw->authorized) in tb_domain_challenge_switch_key()
687 return -EINVAL; in tb_domain_challenge_switch_key()
690 ret = tb->cm_ops->challenge_switch_key(tb, sw, challenge, response); in tb_domain_challenge_switch_key()
698 ret = crypto_shash_setkey(tfm, sw->key, TB_SWITCH_KEY_SIZE); in tb_domain_challenge_switch_key()
705 ret = -ENOMEM; in tb_domain_challenge_switch_key()
709 shash->tfm = tfm; in tb_domain_challenge_switch_key()
718 ret = -EKEYREJECTED; in tb_domain_challenge_switch_key()
725 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_challenge_switch_key()
736 * tb_domain_disconnect_pcie_paths() - Disconnect all PCIe paths
746 if (!tb->cm_ops->disconnect_pcie_paths) in tb_domain_disconnect_pcie_paths()
747 return -EPERM; in tb_domain_disconnect_pcie_paths()
749 return tb->cm_ops->disconnect_pcie_paths(tb); in tb_domain_disconnect_pcie_paths()
753 * tb_domain_approve_xdomain_paths() - Enable DMA paths for XDomain
761 * particular returns %-ENOTSUPP if the connection manager
766 if (!tb->cm_ops->approve_xdomain_paths) in tb_domain_approve_xdomain_paths()
767 return -ENOTSUPP; in tb_domain_approve_xdomain_paths()
769 return tb->cm_ops->approve_xdomain_paths(tb, xd); in tb_domain_approve_xdomain_paths()
773 * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain
781 * particular returns %-ENOTSUPP if the connection manager
786 if (!tb->cm_ops->disconnect_xdomain_paths) in tb_domain_disconnect_xdomain_paths()
787 return -ENOTSUPP; in tb_domain_disconnect_xdomain_paths()
789 return tb->cm_ops->disconnect_xdomain_paths(tb, xd); in tb_domain_disconnect_xdomain_paths()
799 if (xd && xd->tb == tb) in disconnect_xdomain()
806 * tb_domain_disconnect_all_paths() - Disconnect all paths for the domain