Lines Matching refs:tb
52 sw = tb_switch_alloc(port->sw->tb, tb_downstream_route(port)); in tb_scan_port()
63 static void tb_free_invalid_tunnels(struct tb *tb) in tb_free_invalid_tunnels() argument
67 list_for_each_entry_safe(tunnel, n, &tb->tunnel_list, list) in tb_free_invalid_tunnels()
143 static void tb_activate_pcie_devices(struct tb *tb) in tb_activate_pcie_devices() argument
153 for (i = 1; i <= tb->root_switch->config.max_port_number; i++) { in tb_activate_pcie_devices()
154 if (tb_is_upstream_port(&tb->root_switch->ports[i])) in tb_activate_pcie_devices()
156 if (tb->root_switch->ports[i].config.type != TB_TYPE_PORT) in tb_activate_pcie_devices()
158 if (!tb->root_switch->ports[i].remote) in tb_activate_pcie_devices()
160 sw = tb->root_switch->ports[i].remote->sw; in tb_activate_pcie_devices()
179 down_port = tb_find_unused_down_port(tb->root_switch); in tb_activate_pcie_devices()
185 tunnel = tb_pci_alloc(tb, up_port, down_port); in tb_activate_pcie_devices()
205 struct tb *tb; member
219 struct tb *tb = ev->tb; in tb_handle_hotplug() local
222 mutex_lock(&tb->lock); in tb_handle_hotplug()
223 if (!tb->hotplug_active) in tb_handle_hotplug()
226 sw = get_switch_at_route(tb->root_switch, ev->route); in tb_handle_hotplug()
228 tb_warn(tb, in tb_handle_hotplug()
234 tb_warn(tb, in tb_handle_hotplug()
241 tb_warn(tb, in tb_handle_hotplug()
250 tb_free_invalid_tunnels(tb); in tb_handle_hotplug()
271 tb_activate_pcie_devices(tb); in tb_handle_hotplug()
275 mutex_unlock(&tb->lock); in tb_handle_hotplug()
287 struct tb *tb = data; in tb_schedule_hotplug_handler() local
292 ev->tb = tb; in tb_schedule_hotplug_handler()
296 queue_work(tb->wq, &ev->work); in tb_schedule_hotplug_handler()
306 void thunderbolt_shutdown_and_free(struct tb *tb) in thunderbolt_shutdown_and_free() argument
311 mutex_lock(&tb->lock); in thunderbolt_shutdown_and_free()
314 list_for_each_entry_safe(tunnel, n, &tb->tunnel_list, list) { in thunderbolt_shutdown_and_free()
319 if (tb->root_switch) in thunderbolt_shutdown_and_free()
320 tb_switch_free(tb->root_switch); in thunderbolt_shutdown_and_free()
321 tb->root_switch = NULL; in thunderbolt_shutdown_and_free()
323 if (tb->ctl) { in thunderbolt_shutdown_and_free()
324 tb_ctl_stop(tb->ctl); in thunderbolt_shutdown_and_free()
325 tb_ctl_free(tb->ctl); in thunderbolt_shutdown_and_free()
327 tb->ctl = NULL; in thunderbolt_shutdown_and_free()
328 tb->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in thunderbolt_shutdown_and_free()
331 mutex_unlock(&tb->lock); in thunderbolt_shutdown_and_free()
332 if (tb->wq) { in thunderbolt_shutdown_and_free()
333 flush_workqueue(tb->wq); in thunderbolt_shutdown_and_free()
334 destroy_workqueue(tb->wq); in thunderbolt_shutdown_and_free()
335 tb->wq = NULL; in thunderbolt_shutdown_and_free()
337 mutex_destroy(&tb->lock); in thunderbolt_shutdown_and_free()
338 kfree(tb); in thunderbolt_shutdown_and_free()
349 struct tb *thunderbolt_alloc_and_start(struct tb_nhi *nhi) in thunderbolt_alloc_and_start()
351 struct tb *tb; in thunderbolt_alloc_and_start() local
357 tb = kzalloc(sizeof(*tb), GFP_KERNEL); in thunderbolt_alloc_and_start()
358 if (!tb) in thunderbolt_alloc_and_start()
361 tb->nhi = nhi; in thunderbolt_alloc_and_start()
362 mutex_init(&tb->lock); in thunderbolt_alloc_and_start()
363 mutex_lock(&tb->lock); in thunderbolt_alloc_and_start()
364 INIT_LIST_HEAD(&tb->tunnel_list); in thunderbolt_alloc_and_start()
366 tb->wq = alloc_ordered_workqueue("thunderbolt", 0); in thunderbolt_alloc_and_start()
367 if (!tb->wq) in thunderbolt_alloc_and_start()
370 tb->ctl = tb_ctl_alloc(tb->nhi, tb_schedule_hotplug_handler, tb); in thunderbolt_alloc_and_start()
371 if (!tb->ctl) in thunderbolt_alloc_and_start()
377 tb_ctl_start(tb->ctl); in thunderbolt_alloc_and_start()
379 tb->root_switch = tb_switch_alloc(tb, 0); in thunderbolt_alloc_and_start()
380 if (!tb->root_switch) in thunderbolt_alloc_and_start()
384 tb_scan_switch(tb->root_switch); in thunderbolt_alloc_and_start()
385 tb_activate_pcie_devices(tb); in thunderbolt_alloc_and_start()
388 tb->hotplug_active = true; in thunderbolt_alloc_and_start()
389 mutex_unlock(&tb->lock); in thunderbolt_alloc_and_start()
390 return tb; in thunderbolt_alloc_and_start()
393 mutex_unlock(&tb->lock); in thunderbolt_alloc_and_start()
394 thunderbolt_shutdown_and_free(tb); in thunderbolt_alloc_and_start()
398 void thunderbolt_suspend(struct tb *tb) in thunderbolt_suspend() argument
400 tb_info(tb, "suspending...\n"); in thunderbolt_suspend()
401 mutex_lock(&tb->lock); in thunderbolt_suspend()
402 tb_switch_suspend(tb->root_switch); in thunderbolt_suspend()
403 tb_ctl_stop(tb->ctl); in thunderbolt_suspend()
404 tb->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in thunderbolt_suspend()
405 mutex_unlock(&tb->lock); in thunderbolt_suspend()
406 tb_info(tb, "suspend finished\n"); in thunderbolt_suspend()
409 void thunderbolt_resume(struct tb *tb) in thunderbolt_resume() argument
412 tb_info(tb, "resuming...\n"); in thunderbolt_resume()
413 mutex_lock(&tb->lock); in thunderbolt_resume()
414 tb_ctl_start(tb->ctl); in thunderbolt_resume()
417 tb_switch_reset(tb, 0); in thunderbolt_resume()
419 tb_switch_resume(tb->root_switch); in thunderbolt_resume()
420 tb_free_invalid_tunnels(tb); in thunderbolt_resume()
421 tb_free_unplugged_children(tb->root_switch); in thunderbolt_resume()
422 list_for_each_entry_safe(tunnel, n, &tb->tunnel_list, list) in thunderbolt_resume()
424 if (!list_empty(&tb->tunnel_list)) { in thunderbolt_resume()
429 tb_info(tb, "tunnels restarted, sleeping for 100ms\n"); in thunderbolt_resume()
433 tb->hotplug_active = true; in thunderbolt_resume()
434 mutex_unlock(&tb->lock); in thunderbolt_resume()
435 tb_info(tb, "resume finished\n"); in thunderbolt_resume()