Lines Matching refs:tb
127 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_show() local
132 uuids = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_show()
136 pm_runtime_get_sync(&tb->dev); in boot_acl_show()
138 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_show()
142 ret = tb->cm_ops->get_boot_acl(tb, uuids, tb->nboot_acl); in boot_acl_show()
144 mutex_unlock(&tb->lock); in boot_acl_show()
147 mutex_unlock(&tb->lock); in boot_acl_show()
149 for (ret = 0, i = 0; i < tb->nboot_acl; i++) { in boot_acl_show()
155 i < tb->nboot_acl - 1 ? "," : "\n"); in boot_acl_show()
159 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_show()
160 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_show()
169 struct tb *tb = container_of(dev, struct tb, dev); in boot_acl_store() local
180 if (count > (UUID_STRING_LEN + 1) * tb->nboot_acl + 1) in boot_acl_store()
182 if (count < tb->nboot_acl - 1) in boot_acl_store()
189 acl = kcalloc(tb->nboot_acl, sizeof(uuid_t), GFP_KERNEL); in boot_acl_store()
196 while ((s = strsep(&uuid_str, ",")) != NULL && i < tb->nboot_acl) { in boot_acl_store()
212 if (s || i < tb->nboot_acl) { in boot_acl_store()
217 pm_runtime_get_sync(&tb->dev); in boot_acl_store()
219 if (mutex_lock_interruptible(&tb->lock)) { in boot_acl_store()
223 ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); in boot_acl_store()
226 kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); in boot_acl_store()
228 mutex_unlock(&tb->lock); in boot_acl_store()
231 pm_runtime_mark_last_busy(&tb->dev); in boot_acl_store()
232 pm_runtime_put_autosuspend(&tb->dev); in boot_acl_store()
245 struct tb *tb = container_of(dev, struct tb, dev); in security_show() local
248 if (tb->security_level < ARRAY_SIZE(tb_security_names)) in security_show()
249 name = tb_security_names[tb->security_level]; in security_show()
265 struct tb *tb = container_of(dev, struct tb, dev); in domain_attr_is_visible() local
268 if (tb->nboot_acl && in domain_attr_is_visible()
269 tb->cm_ops->get_boot_acl && in domain_attr_is_visible()
270 tb->cm_ops->set_boot_acl) in domain_attr_is_visible()
298 struct tb *tb = container_of(dev, struct tb, dev); in tb_domain_release() local
300 tb_ctl_free(tb->ctl); in tb_domain_release()
301 destroy_workqueue(tb->wq); in tb_domain_release()
302 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_release()
303 mutex_destroy(&tb->lock); in tb_domain_release()
304 kfree(tb); in tb_domain_release()
326 struct tb *tb_domain_alloc(struct tb_nhi *nhi, size_t privsize) in tb_domain_alloc()
328 struct tb *tb; in tb_domain_alloc() local
338 tb = kzalloc(sizeof(*tb) + privsize, GFP_KERNEL); in tb_domain_alloc()
339 if (!tb) in tb_domain_alloc()
342 tb->nhi = nhi; in tb_domain_alloc()
343 mutex_init(&tb->lock); in tb_domain_alloc()
345 tb->index = ida_simple_get(&tb_domain_ida, 0, 0, GFP_KERNEL); in tb_domain_alloc()
346 if (tb->index < 0) in tb_domain_alloc()
349 tb->wq = alloc_ordered_workqueue("thunderbolt%d", 0, tb->index); in tb_domain_alloc()
350 if (!tb->wq) in tb_domain_alloc()
353 tb->dev.parent = &nhi->pdev->dev; in tb_domain_alloc()
354 tb->dev.bus = &tb_bus_type; in tb_domain_alloc()
355 tb->dev.type = &tb_domain_type; in tb_domain_alloc()
356 tb->dev.groups = domain_attr_groups; in tb_domain_alloc()
357 dev_set_name(&tb->dev, "domain%d", tb->index); in tb_domain_alloc()
358 device_initialize(&tb->dev); in tb_domain_alloc()
360 return tb; in tb_domain_alloc()
363 ida_simple_remove(&tb_domain_ida, tb->index); in tb_domain_alloc()
365 kfree(tb); in tb_domain_alloc()
373 struct tb *tb = data; in tb_domain_event_cb() local
375 if (!tb->cm_ops->handle_event) { in tb_domain_event_cb()
376 tb_warn(tb, "domain does not have event handler\n"); in tb_domain_event_cb()
383 return tb_xdomain_handle_request(tb, type, buf, size); in tb_domain_event_cb()
386 tb->cm_ops->handle_event(tb, type, buf, size); in tb_domain_event_cb()
403 int tb_domain_add(struct tb *tb) in tb_domain_add() argument
407 if (WARN_ON(!tb->cm_ops)) in tb_domain_add()
410 mutex_lock(&tb->lock); in tb_domain_add()
412 tb->ctl = tb_ctl_alloc(tb->nhi, tb_domain_event_cb, tb); in tb_domain_add()
413 if (!tb->ctl) { in tb_domain_add()
422 tb_ctl_start(tb->ctl); in tb_domain_add()
424 if (tb->cm_ops->driver_ready) { in tb_domain_add()
425 ret = tb->cm_ops->driver_ready(tb); in tb_domain_add()
430 ret = device_add(&tb->dev); in tb_domain_add()
435 if (tb->cm_ops->start) { in tb_domain_add()
436 ret = tb->cm_ops->start(tb); in tb_domain_add()
442 mutex_unlock(&tb->lock); in tb_domain_add()
444 pm_runtime_no_callbacks(&tb->dev); in tb_domain_add()
445 pm_runtime_set_active(&tb->dev); in tb_domain_add()
446 pm_runtime_enable(&tb->dev); in tb_domain_add()
447 pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); in tb_domain_add()
448 pm_runtime_mark_last_busy(&tb->dev); in tb_domain_add()
449 pm_runtime_use_autosuspend(&tb->dev); in tb_domain_add()
454 device_del(&tb->dev); in tb_domain_add()
456 tb_ctl_stop(tb->ctl); in tb_domain_add()
458 mutex_unlock(&tb->lock); in tb_domain_add()
470 void tb_domain_remove(struct tb *tb) in tb_domain_remove() argument
472 mutex_lock(&tb->lock); in tb_domain_remove()
473 if (tb->cm_ops->stop) in tb_domain_remove()
474 tb->cm_ops->stop(tb); in tb_domain_remove()
476 tb_ctl_stop(tb->ctl); in tb_domain_remove()
477 mutex_unlock(&tb->lock); in tb_domain_remove()
479 flush_workqueue(tb->wq); in tb_domain_remove()
480 device_unregister(&tb->dev); in tb_domain_remove()
489 int tb_domain_suspend_noirq(struct tb *tb) in tb_domain_suspend_noirq() argument
498 mutex_lock(&tb->lock); in tb_domain_suspend_noirq()
499 if (tb->cm_ops->suspend_noirq) in tb_domain_suspend_noirq()
500 ret = tb->cm_ops->suspend_noirq(tb); in tb_domain_suspend_noirq()
502 tb_ctl_stop(tb->ctl); in tb_domain_suspend_noirq()
503 mutex_unlock(&tb->lock); in tb_domain_suspend_noirq()
515 int tb_domain_resume_noirq(struct tb *tb) in tb_domain_resume_noirq() argument
519 mutex_lock(&tb->lock); in tb_domain_resume_noirq()
520 tb_ctl_start(tb->ctl); in tb_domain_resume_noirq()
521 if (tb->cm_ops->resume_noirq) in tb_domain_resume_noirq()
522 ret = tb->cm_ops->resume_noirq(tb); in tb_domain_resume_noirq()
523 mutex_unlock(&tb->lock); in tb_domain_resume_noirq()
528 int tb_domain_suspend(struct tb *tb) in tb_domain_suspend() argument
530 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0; in tb_domain_suspend()
533 void tb_domain_complete(struct tb *tb) in tb_domain_complete() argument
535 if (tb->cm_ops->complete) in tb_domain_complete()
536 tb->cm_ops->complete(tb); in tb_domain_complete()
539 int tb_domain_runtime_suspend(struct tb *tb) in tb_domain_runtime_suspend() argument
541 if (tb->cm_ops->runtime_suspend) { in tb_domain_runtime_suspend()
542 int ret = tb->cm_ops->runtime_suspend(tb); in tb_domain_runtime_suspend()
546 tb_ctl_stop(tb->ctl); in tb_domain_runtime_suspend()
550 int tb_domain_runtime_resume(struct tb *tb) in tb_domain_runtime_resume() argument
552 tb_ctl_start(tb->ctl); in tb_domain_runtime_resume()
553 if (tb->cm_ops->runtime_resume) { in tb_domain_runtime_resume()
554 int ret = tb->cm_ops->runtime_resume(tb); in tb_domain_runtime_resume()
570 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch() argument
574 if (!tb->cm_ops->approve_switch) in tb_domain_approve_switch()
582 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch()
596 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_approve_switch_key() argument
601 if (!tb->cm_ops->approve_switch || !tb->cm_ops->add_switch_key) in tb_domain_approve_switch_key()
609 ret = tb->cm_ops->add_switch_key(tb, sw); in tb_domain_approve_switch_key()
613 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_approve_switch_key()
628 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw) in tb_domain_challenge_switch_key() argument
638 if (!tb->cm_ops->approve_switch || !tb->cm_ops->challenge_switch_key) in tb_domain_challenge_switch_key()
647 ret = tb->cm_ops->challenge_switch_key(tb, sw, challenge, response); in tb_domain_challenge_switch_key()
683 return tb->cm_ops->approve_switch(tb, sw); in tb_domain_challenge_switch_key()
702 int tb_domain_disconnect_pcie_paths(struct tb *tb) in tb_domain_disconnect_pcie_paths() argument
704 if (!tb->cm_ops->disconnect_pcie_paths) in tb_domain_disconnect_pcie_paths()
707 return tb->cm_ops->disconnect_pcie_paths(tb); in tb_domain_disconnect_pcie_paths()
722 int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in tb_domain_approve_xdomain_paths() argument
724 if (!tb->cm_ops->approve_xdomain_paths) in tb_domain_approve_xdomain_paths()
727 return tb->cm_ops->approve_xdomain_paths(tb, xd); in tb_domain_approve_xdomain_paths()
742 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in tb_domain_disconnect_xdomain_paths() argument
744 if (!tb->cm_ops->disconnect_xdomain_paths) in tb_domain_disconnect_xdomain_paths()
747 return tb->cm_ops->disconnect_xdomain_paths(tb, xd); in tb_domain_disconnect_xdomain_paths()
753 struct tb *tb = data; in disconnect_xdomain() local
757 if (xd && xd->tb == tb) in disconnect_xdomain()
773 int tb_domain_disconnect_all_paths(struct tb *tb) in tb_domain_disconnect_all_paths() argument
777 ret = tb_domain_disconnect_pcie_paths(tb); in tb_domain_disconnect_all_paths()
781 return bus_for_each_dev(&tb_bus_type, NULL, tb, disconnect_xdomain); in tb_domain_disconnect_all_paths()