Lines Matching refs:tb
125 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_show() local
130 uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_show()
134 pm_runtime_get_sync(&tb->dev); in boot_acl_show()
136 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_show()
140 ret = tb->cm_ops->get_boot_acl(tb, uuids, tb->nboot_acl); in boot_acl_show()
142 mutex_unlock(&tb->lock); in boot_acl_show()
145 mutex_unlock(&tb->lock); in boot_acl_show()
147 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { in boot_acl_show()
153 i < tb->nboot_acl - 1 ? "," : "\n"); in boot_acl_show()
157 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_show()
158 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_show()
167 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_store() local
178 if (count > (UUID_STRING_LEN + 1) * tb->nboot_acl + 1) in boot_acl_store()
180 if (count < tb->nboot_acl - 1) in boot_acl_store()
187 acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_store()
194 while ((s = strsep(&uuid_str, ",")) != NULL && i < tb->nboot_acl) { in boot_acl_store()
210 if (s || i < tb->nboot_acl) { in boot_acl_store()
215 pm_runtime_get_sync(&tb->dev); in boot_acl_store()
217 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_store()
221 ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); in boot_acl_store()
224 kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); in boot_acl_store()
226 mutex_unlock(&tb->lock); in boot_acl_store()
229 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_store()
230 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_store()
244 const struct tb *tb = container_of(dev, struct tb, dev); in deauthorization_show() local
248 if (tb->security_level == TB_SECURITY_USER || in deauthorization_show()
249 tb->security_level == TB_SECURITY_SECURE) in deauthorization_show()
250 deauthorization = !!tb->cm_ops->disapprove_switch; in deauthorization_show()
273 struct tb *tb = container_of(dev, struct tb, dev); in security_show() local
276 if (tb->security_level < ARRAY_SIZE(tb_security_names)) in security_show()
277 name = tb_security_names[tb->security_level]; in security_show()
295 struct tb *tb = container_of(dev, struct tb, dev); in domain_attr_is_visible() local
298 if (tb->nboot_acl && in domain_attr_is_visible()
299 tb->cm_ops->get_boot_acl && in domain_attr_is_visible()
300 tb->cm_ops->set_boot_acl) in domain_attr_is_visible()
328 struct tb *tb = container_of(dev, struct tb, dev); in tb_domain_release() local
330 tb_ctl_free(tb->ctl); in tb_domain_release()
331 destroy_workqueue(tb->wq); in tb_domain_release()
332 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_release()
333 mutex_destroy(&tb->lock); in tb_domain_release()
334 kfree(tb); in tb_domain_release()
345 struct tb *tb = data; in tb_domain_event_cb() local
347 if (!tb->cm_ops->handle_event) { in tb_domain_event_cb()
348 tb_warn(tb, "domain does not have event handler\n"); in tb_domain_event_cb()
356 return tb_xdomain_handle_request(tb, type, buf, size); in tb_domain_event_cb()
360 tb->cm_ops->handle_event(tb, type, buf, size); in tb_domain_event_cb()
381 struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize) in tb_domain_alloc()
383 struct tb *tb; in tb_domain_alloc() local
393 tb = kzalloc(sizeof(*tb) + privsize, GFP_KERNEL); in tb_domain_alloc()
394 if (!tb) in tb_domain_alloc()
397 tb->nhi = nhi; in tb_domain_alloc()
398 mutex_init(&tb->lock); in tb_domain_alloc()
400 tb->index = ida_simple_get(&tb_domain_ida, 0, 0, GFP_KERNEL); in tb_domain_alloc()
401 if (tb->index < 0) in tb_domain_alloc()
404 tb->wq = alloc_ordered_workqueue("thunderbolt%d", 0, tb->index); in tb_domain_alloc()
405 if (!tb->wq) in tb_domain_alloc()
408 tb->ctl = tb_ctl_alloc(nhi, timeout_msec, tb_domain_event_cb, tb); in tb_domain_alloc()
409 if (!tb->ctl) in tb_domain_alloc()
412 tb->dev.parent = &nhi->pdev->dev; in tb_domain_alloc()
413 tb->dev.bus = &tb_bus_type; in tb_domain_alloc()
414 tb->dev.type = &tb_domain_type; in tb_domain_alloc()
415 tb->dev.groups = domain_attr_groups; in tb_domain_alloc()
416 dev_set_name(&tb->dev, "domain%d", tb->index); in tb_domain_alloc()
417 device_initialize(&tb->dev); in tb_domain_alloc()
419 return tb; in tb_domain_alloc()
422 destroy_workqueue(tb->wq); in tb_domain_alloc()
424 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_alloc()
426 kfree(tb); in tb_domain_alloc()
442 int tb_domain_add(struct tb *tb) in tb_domain_add() argument
446 if (WARN_ON(!tb->cm_ops)) in tb_domain_add()
449 mutex_lock(&tb->lock); in tb_domain_add()
454 tb_ctl_start(tb->ctl); in tb_domain_add()
456 if (tb->cm_ops->driver_ready) { in tb_domain_add()
457 ret = tb->cm_ops->driver_ready(tb); in tb_domain_add()
462 tb_dbg(tb, "security level set to %s\n", in tb_domain_add()
463 tb_security_names[tb->security_level]); in tb_domain_add()
465 ret = device_add(&tb->dev); in tb_domain_add()
470 if (tb->cm_ops->start) { in tb_domain_add()
471 ret = tb->cm_ops->start(tb); in tb_domain_add()
477 mutex_unlock(&tb->lock); in tb_domain_add()
479 device_init_wakeup(&tb->dev, true); in tb_domain_add()
481 pm_runtime_no_callbacks(&tb->dev); in tb_domain_add()
482 pm_runtime_set_active(&tb->dev); in tb_domain_add()
483 pm_runtime_enable(&tb->dev); in tb_domain_add()
484 pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); in tb_domain_add()
485 pm_runtime_mark_last_busy(&tb->dev); in tb_domain_add()
486 pm_runtime_use_autosuspend(&tb->dev); in tb_domain_add()
491 device_del(&tb->dev); in tb_domain_add()
493 tb_ctl_stop(tb->ctl); in tb_domain_add()
494 mutex_unlock(&tb->lock); in tb_domain_add()
506 void tb_domain_remove(struct tb *tb) in tb_domain_remove() argument
508 mutex_lock(&tb->lock); in tb_domain_remove()
509 if (tb->cm_ops->stop) in tb_domain_remove()
510 tb->cm_ops->stop(tb); in tb_domain_remove()
512 tb_ctl_stop(tb->ctl); in tb_domain_remove()
513 mutex_unlock(&tb->lock); in tb_domain_remove()
515 flush_workqueue(tb->wq); in tb_domain_remove()
516 device_unregister(&tb->dev); in tb_domain_remove()
525 int tb_domain_suspend_noirq(struct tb *tb) in tb_domain_suspend_noirq() argument
534 mutex_lock(&tb->lock); in tb_domain_suspend_noirq()
535 if (tb->cm_ops->suspend_noirq) in tb_domain_suspend_noirq()
536 ret = tb->cm_ops->suspend_noirq(tb); in tb_domain_suspend_noirq()
538 tb_ctl_stop(tb->ctl); in tb_domain_suspend_noirq()
539 mutex_unlock(&tb->lock); in tb_domain_suspend_noirq()
551 int tb_domain_resume_noirq(struct tb *tb) in tb_domain_resume_noirq() argument
555 mutex_lock(&tb->lock); in tb_domain_resume_noirq()
556 tb_ctl_start(tb->ctl); in tb_domain_resume_noirq()
557 if (tb->cm_ops->resume_noirq) in tb_domain_resume_noirq()
558 ret = tb->cm_ops->resume_noirq(tb); in tb_domain_resume_noirq()
559 mutex_unlock(&tb->lock); in tb_domain_resume_noirq()
564 int tb_domain_suspend(struct tb *tb) in tb_domain_suspend() argument
566 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0; in tb_domain_suspend()
569 int tb_domain_freeze_noirq(struct tb *tb) in tb_domain_freeze_noirq() argument
573 mutex_lock(&tb->lock); in tb_domain_freeze_noirq()
574 if (tb->cm_ops->freeze_noirq) in tb_domain_freeze_noirq()
575 ret = tb->cm_ops->freeze_noirq(tb); in tb_domain_freeze_noirq()
577 tb_ctl_stop(tb->ctl); in tb_domain_freeze_noirq()
578 mutex_unlock(&tb->lock); in tb_domain_freeze_noirq()
583 int tb_domain_thaw_noirq(struct tb *tb) in tb_domain_thaw_noirq() argument
587 mutex_lock(&tb->lock); in tb_domain_thaw_noirq()
588 tb_ctl_start(tb->ctl); in tb_domain_thaw_noirq()
589 if (tb->cm_ops->thaw_noirq) in tb_domain_thaw_noirq()
590 ret = tb->cm_ops->thaw_noirq(tb); in tb_domain_thaw_noirq()
591 mutex_unlock(&tb->lock); in tb_domain_thaw_noirq()
596 void tb_domain_complete(struct tb *tb) in tb_domain_complete() argument
598 if (tb->cm_ops->complete) in tb_domain_complete()
599 tb->cm_ops->complete(tb); in tb_domain_complete()
602 int tb_domain_runtime_suspend(struct tb *tb) in tb_domain_runtime_suspend() argument
604 if (tb->cm_ops->runtime_suspend) { in tb_domain_runtime_suspend()
605 int ret = tb->cm_ops->runtime_suspend(tb); in tb_domain_runtime_suspend()
609 tb_ctl_stop(tb->ctl); in tb_domain_runtime_suspend()
613 int tb_domain_runtime_resume(struct tb *tb) in tb_domain_runtime_resume() argument
615 tb_ctl_start(tb->ctl); in tb_domain_runtime_resume()
616 if (tb->cm_ops->runtime_resume) { in tb_domain_runtime_resume()
617 int ret = tb->cm_ops->runtime_resume(tb); in tb_domain_runtime_resume()
633 int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw) in tb_domain_disapprove_switch() argument
635 if (!tb->cm_ops->disapprove_switch) in tb_domain_disapprove_switch()
638 return tb->cm_ops->disapprove_switch(tb, sw); in tb_domain_disapprove_switch()
650 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch() argument
654 if (!tb->cm_ops->approve_switch) in tb_domain_approve_switch()
662 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch()
676 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch_key() argument
681 if (!tb->cm_ops->approve_switch || !tb->cm_ops->add_switch_key) in tb_domain_approve_switch_key()
689 ret = tb->cm_ops->add_switch_key(tb, sw); in tb_domain_approve_switch_key()
693 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch_key()
708 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_challenge_switch_key() argument
718 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) in tb_domain_challenge_switch_key()
727 ret = tb->cm_ops->challenge_switch_key(tb, sw, challenge, response); in tb_domain_challenge_switch_key()
762 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_challenge_switch_key()
781 int tb_domain_disconnect_pcie_paths(struct tb *tb) in tb_domain_disconnect_pcie_paths() argument
783 if (!tb->cm_ops->disconnect_pcie_paths) in tb_domain_disconnect_pcie_paths()
786 return tb->cm_ops->disconnect_pcie_paths(tb); in tb_domain_disconnect_pcie_paths()
805 int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_domain_approve_xdomain_paths() argument
809 if (!tb->cm_ops->approve_xdomain_paths) in tb_domain_approve_xdomain_paths()
812 return tb->cm_ops->approve_xdomain_paths(tb, xd, transmit_path, in tb_domain_approve_xdomain_paths()
832 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_domain_disconnect_xdomain_paths() argument
836 if (!tb->cm_ops->disconnect_xdomain_paths) in tb_domain_disconnect_xdomain_paths()
839 return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, in tb_domain_disconnect_xdomain_paths()
846 struct tb *tb = data; in disconnect_xdomain() local
850 if (xd && xd->tb == tb) in disconnect_xdomain()
866 int tb_domain_disconnect_all_paths(struct tb *tb) in tb_domain_disconnect_all_paths() argument
870 ret = tb_domain_disconnect_pcie_paths(tb); in tb_domain_disconnect_all_paths()
874 return bus_for_each_dev(&tb_bus_type, NULL, tb, disconnect_xdomain); in tb_domain_disconnect_all_paths()