Lines Matching refs:tunnel
35 #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ argument
37 struct tb_tunnel *__tunnel = (tunnel); \
47 #define tb_tunnel_WARN(tunnel, fmt, arg...) \ argument
48 __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
49 #define tb_tunnel_warn(tunnel, fmt, arg...) \ argument
50 __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
51 #define tb_tunnel_info(tunnel, fmt, arg...) \ argument
52 __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
53 #define tb_tunnel_dbg(tunnel, fmt, arg...) \ argument
54 __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg)
59 struct tb_tunnel *tunnel; in tb_tunnel_alloc() local
61 tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); in tb_tunnel_alloc()
62 if (!tunnel) in tb_tunnel_alloc()
65 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); in tb_tunnel_alloc()
66 if (!tunnel->paths) { in tb_tunnel_alloc()
67 tb_tunnel_free(tunnel); in tb_tunnel_alloc()
71 INIT_LIST_HEAD(&tunnel->list); in tb_tunnel_alloc()
72 tunnel->tb = tb; in tb_tunnel_alloc()
73 tunnel->npaths = npaths; in tb_tunnel_alloc()
74 tunnel->type = type; in tb_tunnel_alloc()
76 return tunnel; in tb_tunnel_alloc()
79 static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate) in tb_pci_activate() argument
83 res = tb_pci_port_enable(tunnel->src_port, activate); in tb_pci_activate()
87 if (tb_port_is_pcie_up(tunnel->dst_port)) in tb_pci_activate()
88 return tb_pci_port_enable(tunnel->dst_port, activate); in tb_pci_activate()
118 struct tb_tunnel *tunnel; in tb_tunnel_discover_pci() local
124 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_discover_pci()
125 if (!tunnel) in tb_tunnel_discover_pci()
128 tunnel->activate = tb_pci_activate; in tb_tunnel_discover_pci()
129 tunnel->src_port = down; in tb_tunnel_discover_pci()
137 &tunnel->dst_port, "PCIe Up"); in tb_tunnel_discover_pci()
143 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_discover_pci()
144 tb_pci_init_path(tunnel->paths[TB_PCI_PATH_UP]); in tb_tunnel_discover_pci()
146 path = tb_path_discover(tunnel->dst_port, -1, down, TB_PCI_HOPID, NULL, in tb_tunnel_discover_pci()
150 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_discover_pci()
151 tb_pci_init_path(tunnel->paths[TB_PCI_PATH_DOWN]); in tb_tunnel_discover_pci()
154 if (!tb_port_is_pcie_up(tunnel->dst_port)) { in tb_tunnel_discover_pci()
155 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_pci()
160 if (down != tunnel->src_port) { in tb_tunnel_discover_pci()
161 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_pci()
165 if (!tb_pci_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_pci()
166 tb_tunnel_warn(tunnel, in tb_tunnel_discover_pci()
171 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_pci()
172 return tunnel; in tb_tunnel_discover_pci()
175 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_pci()
177 tb_tunnel_free(tunnel); in tb_tunnel_discover_pci()
196 struct tb_tunnel *tunnel; in tb_tunnel_alloc_pci() local
199 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_alloc_pci()
200 if (!tunnel) in tb_tunnel_alloc_pci()
203 tunnel->activate = tb_pci_activate; in tb_tunnel_alloc_pci()
204 tunnel->src_port = down; in tb_tunnel_alloc_pci()
205 tunnel->dst_port = up; in tb_tunnel_alloc_pci()
210 tb_tunnel_free(tunnel); in tb_tunnel_alloc_pci()
214 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_alloc_pci()
219 tb_tunnel_free(tunnel); in tb_tunnel_alloc_pci()
223 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_alloc_pci()
225 return tunnel; in tb_tunnel_alloc_pci()
228 static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) in tb_dp_xchg_caps() argument
230 struct tb_port *out = tunnel->dst_port; in tb_dp_xchg_caps()
231 struct tb_port *in = tunnel->src_port; in tb_dp_xchg_caps()
263 static int tb_dp_activate(struct tb_tunnel *tunnel, bool active) in tb_dp_activate() argument
271 paths = tunnel->paths; in tb_dp_activate()
274 tb_dp_port_set_hops(tunnel->src_port, in tb_dp_activate()
279 tb_dp_port_set_hops(tunnel->dst_port, in tb_dp_activate()
284 tb_dp_port_hpd_clear(tunnel->src_port); in tb_dp_activate()
285 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0); in tb_dp_activate()
286 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
287 tb_dp_port_set_hops(tunnel->dst_port, 0, 0, 0); in tb_dp_activate()
290 ret = tb_dp_port_enable(tunnel->src_port, active); in tb_dp_activate()
294 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
295 return tb_dp_port_enable(tunnel->dst_port, active); in tb_dp_activate()
351 struct tb_tunnel *tunnel; in tb_tunnel_discover_dp() local
358 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_discover_dp()
359 if (!tunnel) in tb_tunnel_discover_dp()
362 tunnel->init = tb_dp_xchg_caps; in tb_tunnel_discover_dp()
363 tunnel->activate = tb_dp_activate; in tb_tunnel_discover_dp()
364 tunnel->src_port = in; in tb_tunnel_discover_dp()
367 &tunnel->dst_port, "Video"); in tb_tunnel_discover_dp()
373 tunnel->paths[TB_DP_VIDEO_PATH_OUT] = path; in tb_tunnel_discover_dp()
374 tb_dp_init_video_path(tunnel->paths[TB_DP_VIDEO_PATH_OUT], true); in tb_tunnel_discover_dp()
379 tunnel->paths[TB_DP_AUX_PATH_OUT] = path; in tb_tunnel_discover_dp()
380 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_OUT]); in tb_tunnel_discover_dp()
382 path = tb_path_discover(tunnel->dst_port, -1, in, TB_DP_AUX_RX_HOPID, in tb_tunnel_discover_dp()
386 tunnel->paths[TB_DP_AUX_PATH_IN] = path; in tb_tunnel_discover_dp()
387 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_IN]); in tb_tunnel_discover_dp()
390 if (!tb_port_is_dpout(tunnel->dst_port)) { in tb_tunnel_discover_dp()
395 if (!tb_dp_port_is_enabled(tunnel->dst_port)) in tb_tunnel_discover_dp()
398 if (!tb_dp_port_hpd_is_active(tunnel->dst_port)) in tb_tunnel_discover_dp()
401 if (port != tunnel->src_port) { in tb_tunnel_discover_dp()
402 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_dp()
406 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_dp()
407 return tunnel; in tb_tunnel_discover_dp()
410 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_dp()
412 tb_tunnel_free(tunnel); in tb_tunnel_discover_dp()
431 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dp() local
438 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_alloc_dp()
439 if (!tunnel) in tb_tunnel_alloc_dp()
442 tunnel->init = tb_dp_xchg_caps; in tb_tunnel_alloc_dp()
443 tunnel->activate = tb_dp_activate; in tb_tunnel_alloc_dp()
444 tunnel->src_port = in; in tb_tunnel_alloc_dp()
445 tunnel->dst_port = out; in tb_tunnel_alloc_dp()
447 paths = tunnel->paths; in tb_tunnel_alloc_dp()
470 return tunnel; in tb_tunnel_alloc_dp()
473 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dp()
486 static int tb_dma_activate(struct tb_tunnel *tunnel, bool active) in tb_dma_activate() argument
488 struct tb_port *nhi = tunnel->src_port; in tb_dma_activate()
531 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dma() local
535 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_DMA); in tb_tunnel_alloc_dma()
536 if (!tunnel) in tb_tunnel_alloc_dma()
539 tunnel->activate = tb_dma_activate; in tb_tunnel_alloc_dma()
540 tunnel->src_port = nhi; in tb_tunnel_alloc_dma()
541 tunnel->dst_port = dst; in tb_tunnel_alloc_dma()
547 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dma()
552 tunnel->paths[TB_DMA_PATH_IN] = path; in tb_tunnel_alloc_dma()
556 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dma()
560 tunnel->paths[TB_DMA_PATH_OUT] = path; in tb_tunnel_alloc_dma()
562 return tunnel; in tb_tunnel_alloc_dma()
571 void tb_tunnel_free(struct tb_tunnel *tunnel) in tb_tunnel_free() argument
575 if (!tunnel) in tb_tunnel_free()
578 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_free()
579 if (tunnel->paths[i]) in tb_tunnel_free()
580 tb_path_free(tunnel->paths[i]); in tb_tunnel_free()
583 kfree(tunnel->paths); in tb_tunnel_free()
584 kfree(tunnel); in tb_tunnel_free()
591 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel) in tb_tunnel_is_invalid() argument
595 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_invalid()
596 WARN_ON(!tunnel->paths[i]->activated); in tb_tunnel_is_invalid()
597 if (tb_path_is_invalid(tunnel->paths[i])) in tb_tunnel_is_invalid()
610 int tb_tunnel_restart(struct tb_tunnel *tunnel) in tb_tunnel_restart() argument
614 tb_tunnel_dbg(tunnel, "activating\n"); in tb_tunnel_restart()
620 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
621 if (tunnel->paths[i]->activated) { in tb_tunnel_restart()
622 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_restart()
623 tunnel->paths[i]->activated = false; in tb_tunnel_restart()
627 if (tunnel->init) { in tb_tunnel_restart()
628 res = tunnel->init(tunnel); in tb_tunnel_restart()
633 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
634 res = tb_path_activate(tunnel->paths[i]); in tb_tunnel_restart()
639 if (tunnel->activate) { in tb_tunnel_restart()
640 res = tunnel->activate(tunnel, true); in tb_tunnel_restart()
648 tb_tunnel_warn(tunnel, "activation failed\n"); in tb_tunnel_restart()
649 tb_tunnel_deactivate(tunnel); in tb_tunnel_restart()
659 int tb_tunnel_activate(struct tb_tunnel *tunnel) in tb_tunnel_activate() argument
663 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_activate()
664 if (tunnel->paths[i]->activated) { in tb_tunnel_activate()
665 tb_tunnel_WARN(tunnel, in tb_tunnel_activate()
671 return tb_tunnel_restart(tunnel); in tb_tunnel_activate()
678 void tb_tunnel_deactivate(struct tb_tunnel *tunnel) in tb_tunnel_deactivate() argument
682 tb_tunnel_dbg(tunnel, "deactivating\n"); in tb_tunnel_deactivate()
684 if (tunnel->activate) in tb_tunnel_deactivate()
685 tunnel->activate(tunnel, false); in tb_tunnel_deactivate()
687 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_deactivate()
688 if (tunnel->paths[i] && tunnel->paths[i]->activated) in tb_tunnel_deactivate()
689 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_deactivate()