Lines Matching +full:system +full:- +full:ctl
1 // SPDX-License-Identifier: GPL-2.0
24 if (id->match_flags & TBSVC_MATCH_PROTOCOL_KEY) { in match_service_id()
25 if (strcmp(id->protocol_key, svc->key)) in match_service_id()
29 if (id->match_flags & TBSVC_MATCH_PROTOCOL_ID) { in match_service_id()
30 if (id->protocol_id != svc->prtcid) in match_service_id()
34 if (id->match_flags & TBSVC_MATCH_PROTOCOL_VERSION) { in match_service_id()
35 if (id->protocol_version != svc->prtcvers) in match_service_id()
39 if (id->match_flags & TBSVC_MATCH_PROTOCOL_VERSION) { in match_service_id()
40 if (id->protocol_revision != svc->prtcrevs) in match_service_id()
59 if (!driver->id_table) in __tb_service_match()
62 for (ids = driver->id_table; ids->match_flags != 0; ids++) { in __tb_service_match()
81 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_probe()
82 id = __tb_service_match(dev, &driver->driver); in tb_service_probe()
84 return driver->probe(svc, id); in tb_service_probe()
92 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_remove()
93 if (driver->remove) in tb_service_remove()
94 driver->remove(svc); in tb_service_remove()
103 if (!svc || !dev->driver) in tb_service_shutdown()
106 driver = container_of(dev->driver, struct tb_service_driver, driver); in tb_service_shutdown()
107 if (driver->shutdown) in tb_service_shutdown()
108 driver->shutdown(svc); in tb_service_shutdown()
128 uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_show()
130 return -ENOMEM; in boot_acl_show()
132 pm_runtime_get_sync(&tb->dev); in boot_acl_show()
134 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_show()
135 ret = -ERESTARTSYS; in boot_acl_show()
138 ret = tb->cm_ops->get_boot_acl(tb, uuids, tb->nboot_acl); in boot_acl_show()
140 mutex_unlock(&tb->lock); in boot_acl_show()
143 mutex_unlock(&tb->lock); in boot_acl_show()
145 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { in boot_acl_show()
149 ret += sysfs_emit_at(buf, ret, "%s", i < tb->nboot_acl - 1 ? "," : "\n"); in boot_acl_show()
153 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_show()
154 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_show()
170 * Make sure the value is not bigger than tb->nboot_acl * UUID in boot_acl_store()
172 * string is tb->nboot_acl * ",". in boot_acl_store()
174 if (count > (UUID_STRING_LEN + 1) * tb->nboot_acl + 1) in boot_acl_store()
175 return -EINVAL; in boot_acl_store()
176 if (count < tb->nboot_acl - 1) in boot_acl_store()
177 return -EINVAL; in boot_acl_store()
181 return -ENOMEM; in boot_acl_store()
183 acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_store()
185 ret = -ENOMEM; in boot_acl_store()
190 while ((s = strsep(&uuid_str, ",")) != NULL && i < tb->nboot_acl) { in boot_acl_store()
195 ret = -EINVAL; in boot_acl_store()
206 if (s || i < tb->nboot_acl) { in boot_acl_store()
207 ret = -EINVAL; in boot_acl_store()
211 pm_runtime_get_sync(&tb->dev); in boot_acl_store()
213 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_store()
214 ret = -ERESTARTSYS; in boot_acl_store()
217 ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); in boot_acl_store()
220 kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); in boot_acl_store()
222 mutex_unlock(&tb->lock); in boot_acl_store()
225 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_store()
226 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_store()
244 if (tb->security_level == TB_SECURITY_USER || in deauthorization_show()
245 tb->security_level == TB_SECURITY_SECURE) in deauthorization_show()
246 deauthorization = !!tb->cm_ops->disapprove_switch; in deauthorization_show()
258 return sysfs_emit(buf, "%d\n", tb->nhi->iommu_dma_protection); in iommu_dma_protection_show()
268 if (tb->security_level < ARRAY_SIZE(tb_security_names)) in security_show()
269 name = tb_security_names[tb->security_level]; in security_show()
290 if (tb->nboot_acl && in domain_attr_is_visible()
291 tb->cm_ops->get_boot_acl && in domain_attr_is_visible()
292 tb->cm_ops->set_boot_acl) in domain_attr_is_visible()
293 return attr->mode; in domain_attr_is_visible()
297 return attr->mode; in domain_attr_is_visible()
322 tb_ctl_free(tb->ctl); in tb_domain_release()
323 destroy_workqueue(tb->wq); in tb_domain_release()
324 ida_free(&tb_domain_ida, tb->index); in tb_domain_release()
325 mutex_destroy(&tb->lock); in tb_domain_release()
339 if (!tb->cm_ops->handle_event) { in tb_domain_event_cb()
352 tb->cm_ops->handle_event(tb, type, buf, size); in tb_domain_event_cb()
359 * tb_domain_alloc() - Allocate a domain
361 * @timeout_msec: Control channel timeout for non-raw messages
369 * to the system.
379 * expects because bit-fields are being used. in tb_domain_alloc()
389 tb->nhi = nhi; in tb_domain_alloc()
390 mutex_init(&tb->lock); in tb_domain_alloc()
392 tb->index = ida_alloc(&tb_domain_ida, GFP_KERNEL); in tb_domain_alloc()
393 if (tb->index < 0) in tb_domain_alloc()
396 tb->wq = alloc_ordered_workqueue("thunderbolt%d", 0, tb->index); in tb_domain_alloc()
397 if (!tb->wq) in tb_domain_alloc()
400 tb->ctl = tb_ctl_alloc(nhi, tb->index, timeout_msec, tb_domain_event_cb, tb); in tb_domain_alloc()
401 if (!tb->ctl) in tb_domain_alloc()
404 tb->dev.parent = &nhi->pdev->dev; in tb_domain_alloc()
405 tb->dev.bus = &tb_bus_type; in tb_domain_alloc()
406 tb->dev.type = &tb_domain_type; in tb_domain_alloc()
407 tb->dev.groups = domain_attr_groups; in tb_domain_alloc()
408 dev_set_name(&tb->dev, "domain%d", tb->index); in tb_domain_alloc()
409 device_initialize(&tb->dev); in tb_domain_alloc()
414 destroy_workqueue(tb->wq); in tb_domain_alloc()
416 ida_free(&tb_domain_ida, tb->index); in tb_domain_alloc()
424 * tb_domain_add() - Add domain to the system
428 * Starts the domain and adds it to the system. Hotplugging devices will
439 if (WARN_ON(!tb->cm_ops)) in tb_domain_add()
440 return -EINVAL; in tb_domain_add()
442 mutex_lock(&tb->lock); in tb_domain_add()
447 tb_ctl_start(tb->ctl); in tb_domain_add()
449 if (tb->cm_ops->driver_ready) { in tb_domain_add()
450 ret = tb->cm_ops->driver_ready(tb); in tb_domain_add()
456 tb_security_names[tb->security_level]); in tb_domain_add()
458 ret = device_add(&tb->dev); in tb_domain_add()
463 if (tb->cm_ops->start) { in tb_domain_add()
464 ret = tb->cm_ops->start(tb, reset); in tb_domain_add()
470 mutex_unlock(&tb->lock); in tb_domain_add()
472 device_init_wakeup(&tb->dev, true); in tb_domain_add()
474 pm_runtime_no_callbacks(&tb->dev); in tb_domain_add()
475 pm_runtime_set_active(&tb->dev); in tb_domain_add()
476 pm_runtime_enable(&tb->dev); in tb_domain_add()
477 pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); in tb_domain_add()
478 pm_runtime_mark_last_busy(&tb->dev); in tb_domain_add()
479 pm_runtime_use_autosuspend(&tb->dev); in tb_domain_add()
484 device_del(&tb->dev); in tb_domain_add()
486 tb_ctl_stop(tb->ctl); in tb_domain_add()
487 mutex_unlock(&tb->lock); in tb_domain_add()
493 * tb_domain_remove() - Removes and releases a domain
496 * Stops the domain, removes it from the system and releases all
501 mutex_lock(&tb->lock); in tb_domain_remove()
502 if (tb->cm_ops->stop) in tb_domain_remove()
503 tb->cm_ops->stop(tb); in tb_domain_remove()
505 tb_ctl_stop(tb->ctl); in tb_domain_remove()
506 mutex_unlock(&tb->lock); in tb_domain_remove()
508 flush_workqueue(tb->wq); in tb_domain_remove()
510 if (tb->cm_ops->deinit) in tb_domain_remove()
511 tb->cm_ops->deinit(tb); in tb_domain_remove()
513 device_unregister(&tb->dev); in tb_domain_remove()
517 * tb_domain_suspend_noirq() - Suspend a domain
531 mutex_lock(&tb->lock); in tb_domain_suspend_noirq()
532 if (tb->cm_ops->suspend_noirq) in tb_domain_suspend_noirq()
533 ret = tb->cm_ops->suspend_noirq(tb); in tb_domain_suspend_noirq()
535 tb_ctl_stop(tb->ctl); in tb_domain_suspend_noirq()
536 mutex_unlock(&tb->lock); in tb_domain_suspend_noirq()
542 * tb_domain_resume_noirq() - Resume a domain
545 * Re-starts the control channel, and resumes all devices connected to
552 mutex_lock(&tb->lock); in tb_domain_resume_noirq()
553 tb_ctl_start(tb->ctl); in tb_domain_resume_noirq()
554 if (tb->cm_ops->resume_noirq) in tb_domain_resume_noirq()
555 ret = tb->cm_ops->resume_noirq(tb); in tb_domain_resume_noirq()
556 mutex_unlock(&tb->lock); in tb_domain_resume_noirq()
563 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0; in tb_domain_suspend()
570 mutex_lock(&tb->lock); in tb_domain_freeze_noirq()
571 if (tb->cm_ops->freeze_noirq) in tb_domain_freeze_noirq()
572 ret = tb->cm_ops->freeze_noirq(tb); in tb_domain_freeze_noirq()
574 tb_ctl_stop(tb->ctl); in tb_domain_freeze_noirq()
575 mutex_unlock(&tb->lock); in tb_domain_freeze_noirq()
584 mutex_lock(&tb->lock); in tb_domain_thaw_noirq()
585 tb_ctl_start(tb->ctl); in tb_domain_thaw_noirq()
586 if (tb->cm_ops->thaw_noirq) in tb_domain_thaw_noirq()
587 ret = tb->cm_ops->thaw_noirq(tb); in tb_domain_thaw_noirq()
588 mutex_unlock(&tb->lock); in tb_domain_thaw_noirq()
595 if (tb->cm_ops->complete) in tb_domain_complete()
596 tb->cm_ops->complete(tb); in tb_domain_complete()
601 if (tb->cm_ops->runtime_suspend) { in tb_domain_runtime_suspend()
602 int ret = tb->cm_ops->runtime_suspend(tb); in tb_domain_runtime_suspend()
606 tb_ctl_stop(tb->ctl); in tb_domain_runtime_suspend()
612 tb_ctl_start(tb->ctl); in tb_domain_runtime_resume()
613 if (tb->cm_ops->runtime_resume) { in tb_domain_runtime_resume()
614 int ret = tb->cm_ops->runtime_resume(tb); in tb_domain_runtime_resume()
622 * tb_domain_disapprove_switch() - Disapprove switch
632 if (!tb->cm_ops->disapprove_switch) in tb_domain_disapprove_switch()
633 return -EPERM; in tb_domain_disapprove_switch()
635 return tb->cm_ops->disapprove_switch(tb, sw); in tb_domain_disapprove_switch()
639 * tb_domain_approve_switch() - Approve switch
651 if (!tb->cm_ops->approve_switch) in tb_domain_approve_switch()
652 return -EPERM; in tb_domain_approve_switch()
655 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_approve_switch()
656 if (!parent_sw || !parent_sw->authorized) in tb_domain_approve_switch()
657 return -EINVAL; in tb_domain_approve_switch()
659 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch()
663 * tb_domain_approve_switch_key() - Approve switch and add key
678 if (!tb->cm_ops->approve_switch || !tb->cm_ops->add_switch_key) in tb_domain_approve_switch_key()
679 return -EPERM; in tb_domain_approve_switch_key()
682 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_approve_switch_key()
683 if (!parent_sw || !parent_sw->authorized) in tb_domain_approve_switch_key()
684 return -EINVAL; in tb_domain_approve_switch_key()
686 ret = tb->cm_ops->add_switch_key(tb, sw); in tb_domain_approve_switch_key()
690 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch_key()
694 * tb_domain_challenge_switch_key() - Challenge and approve switch
715 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) in tb_domain_challenge_switch_key()
716 return -EPERM; in tb_domain_challenge_switch_key()
719 parent_sw = tb_to_switch(sw->dev.parent); in tb_domain_challenge_switch_key()
720 if (!parent_sw || !parent_sw->authorized) in tb_domain_challenge_switch_key()
721 return -EINVAL; in tb_domain_challenge_switch_key()
724 ret = tb->cm_ops->challenge_switch_key(tb, sw, challenge, response); in tb_domain_challenge_switch_key()
732 ret = crypto_shash_setkey(tfm, sw->key, TB_SWITCH_KEY_SIZE); in tb_domain_challenge_switch_key()
739 ret = -ENOMEM; in tb_domain_challenge_switch_key()
743 shash->tfm = tfm; in tb_domain_challenge_switch_key()
752 ret = -EKEYREJECTED; in tb_domain_challenge_switch_key()
759 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_challenge_switch_key()
770 * tb_domain_disconnect_pcie_paths() - Disconnect all PCIe paths
780 if (!tb->cm_ops->disconnect_pcie_paths) in tb_domain_disconnect_pcie_paths()
781 return -EPERM; in tb_domain_disconnect_pcie_paths()
783 return tb->cm_ops->disconnect_pcie_paths(tb); in tb_domain_disconnect_pcie_paths()
787 * tb_domain_approve_xdomain_paths() - Enable DMA paths for XDomain
799 * particular returns %-ENOTSUPP if the connection manager
806 if (!tb->cm_ops->approve_xdomain_paths) in tb_domain_approve_xdomain_paths()
807 return -ENOTSUPP; in tb_domain_approve_xdomain_paths()
809 return tb->cm_ops->approve_xdomain_paths(tb, xd, transmit_path, in tb_domain_approve_xdomain_paths()
814 * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain
826 * particular returns %-ENOTSUPP if the connection manager
833 if (!tb->cm_ops->disconnect_xdomain_paths) in tb_domain_disconnect_xdomain_paths()
834 return -ENOTSUPP; in tb_domain_disconnect_xdomain_paths()
836 return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, in tb_domain_disconnect_xdomain_paths()
847 if (xd && xd->tb == tb) in disconnect_xdomain()
854 * tb_domain_disconnect_all_paths() - Disconnect all paths for the domain