Lines Matching full:tunnel

13 #include "tunnel.h"
49 #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ argument
51 struct tb_tunnel *__tunnel = (tunnel); \
61 #define tb_tunnel_WARN(tunnel, fmt, arg...) \ argument
62 __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
63 #define tb_tunnel_warn(tunnel, fmt, arg...) \ argument
64 __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
65 #define tb_tunnel_info(tunnel, fmt, arg...) \ argument
66 __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
67 #define tb_tunnel_dbg(tunnel, fmt, arg...) \ argument
68 __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg)
93 /* Add some credits for potential second DMA tunnel */ in tb_available_credits()
125 struct tb_tunnel *tunnel; in tb_tunnel_alloc() local
127 tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); in tb_tunnel_alloc()
128 if (!tunnel) in tb_tunnel_alloc()
131 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); in tb_tunnel_alloc()
132 if (!tunnel->paths) { in tb_tunnel_alloc()
133 tb_tunnel_free(tunnel); in tb_tunnel_alloc()
137 INIT_LIST_HEAD(&tunnel->list); in tb_tunnel_alloc()
138 tunnel->tb = tb; in tb_tunnel_alloc()
139 tunnel->npaths = npaths; in tb_tunnel_alloc()
140 tunnel->type = type; in tb_tunnel_alloc()
142 return tunnel; in tb_tunnel_alloc()
145 static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate) in tb_pci_activate() argument
149 res = tb_pci_port_enable(tunnel->src_port, activate); in tb_pci_activate()
153 if (tb_port_is_pcie_up(tunnel->dst_port)) in tb_pci_activate()
154 return tb_pci_port_enable(tunnel->dst_port, activate); in tb_pci_activate()
215 * If @down adapter is active, follows the tunnel to the PCIe upstream
216 * adapter and back. Returns the discovered tunnel or %NULL if there was
217 * no tunnel.
222 struct tb_tunnel *tunnel; in tb_tunnel_discover_pci() local
228 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_discover_pci()
229 if (!tunnel) in tb_tunnel_discover_pci()
232 tunnel->activate = tb_pci_activate; in tb_tunnel_discover_pci()
233 tunnel->src_port = down; in tb_tunnel_discover_pci()
241 &tunnel->dst_port, "PCIe Up", alloc_hopid); in tb_tunnel_discover_pci()
247 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_discover_pci()
248 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_UP])) in tb_tunnel_discover_pci()
251 path = tb_path_discover(tunnel->dst_port, -1, down, TB_PCI_HOPID, NULL, in tb_tunnel_discover_pci()
255 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_discover_pci()
256 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_DOWN])) in tb_tunnel_discover_pci()
259 /* Validate that the tunnel is complete */ in tb_tunnel_discover_pci()
260 if (!tb_port_is_pcie_up(tunnel->dst_port)) { in tb_tunnel_discover_pci()
261 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_pci()
266 if (down != tunnel->src_port) { in tb_tunnel_discover_pci()
267 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_pci()
271 if (!tb_pci_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_pci()
272 tb_tunnel_warn(tunnel, in tb_tunnel_discover_pci()
273 "tunnel is not fully activated, cleaning up\n"); in tb_tunnel_discover_pci()
277 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_pci()
278 return tunnel; in tb_tunnel_discover_pci()
281 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_pci()
283 tb_tunnel_free(tunnel); in tb_tunnel_discover_pci()
289 * tb_tunnel_alloc_pci() - allocate a pci tunnel
294 * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and
302 struct tb_tunnel *tunnel; in tb_tunnel_alloc_pci() local
305 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_alloc_pci()
306 if (!tunnel) in tb_tunnel_alloc_pci()
309 tunnel->activate = tb_pci_activate; in tb_tunnel_alloc_pci()
310 tunnel->src_port = down; in tb_tunnel_alloc_pci()
311 tunnel->dst_port = up; in tb_tunnel_alloc_pci()
317 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_alloc_pci()
325 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_alloc_pci()
329 return tunnel; in tb_tunnel_alloc_pci()
332 tb_tunnel_free(tunnel); in tb_tunnel_alloc_pci()
504 static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) in tb_dp_xchg_caps() argument
507 struct tb_port *out = tunnel->dst_port; in tb_dp_xchg_caps()
508 struct tb_port *in = tunnel->src_port; in tb_dp_xchg_caps()
549 * If the tunnel bandwidth is limited (max_bw is set) then see in tb_dp_xchg_caps()
559 max_bw = tunnel->max_down; in tb_dp_xchg_caps()
561 max_bw = tunnel->max_up; in tb_dp_xchg_caps()
570 tb_port_info(out, "not enough bandwidth for DP tunnel\n"); in tb_dp_xchg_caps()
600 static int tb_dp_activate(struct tb_tunnel *tunnel, bool active) in tb_dp_activate() argument
608 paths = tunnel->paths; in tb_dp_activate()
611 tb_dp_port_set_hops(tunnel->src_port, in tb_dp_activate()
616 tb_dp_port_set_hops(tunnel->dst_port, in tb_dp_activate()
621 tb_dp_port_hpd_clear(tunnel->src_port); in tb_dp_activate()
622 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0); in tb_dp_activate()
623 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
624 tb_dp_port_set_hops(tunnel->dst_port, 0, 0, 0); in tb_dp_activate()
627 ret = tb_dp_port_enable(tunnel->src_port, active); in tb_dp_activate()
631 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
632 return tb_dp_port_enable(tunnel->dst_port, active); in tb_dp_activate()
637 static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, in tb_dp_consumed_bandwidth() argument
640 struct tb_port *in = tunnel->src_port; in tb_dp_consumed_bandwidth()
650 * for active tunnel. in tb_dp_consumed_bandwidth()
687 if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) { in tb_dp_consumed_bandwidth()
781 * If @in adapter is active, follows the tunnel to the DP out adapter
782 * and back. Returns the discovered tunnel or %NULL if there was no
783 * tunnel.
785 * Return: DP tunnel or %NULL if no tunnel found.
790 struct tb_tunnel *tunnel; in tb_tunnel_discover_dp() local
797 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_discover_dp()
798 if (!tunnel) in tb_tunnel_discover_dp()
801 tunnel->init = tb_dp_xchg_caps; in tb_tunnel_discover_dp()
802 tunnel->activate = tb_dp_activate; in tb_tunnel_discover_dp()
803 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_discover_dp()
804 tunnel->src_port = in; in tb_tunnel_discover_dp()
807 &tunnel->dst_port, "Video", alloc_hopid); in tb_tunnel_discover_dp()
813 tunnel->paths[TB_DP_VIDEO_PATH_OUT] = path; in tb_tunnel_discover_dp()
814 if (tb_dp_init_video_path(tunnel->paths[TB_DP_VIDEO_PATH_OUT])) in tb_tunnel_discover_dp()
821 tunnel->paths[TB_DP_AUX_PATH_OUT] = path; in tb_tunnel_discover_dp()
822 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_OUT]); in tb_tunnel_discover_dp()
824 path = tb_path_discover(tunnel->dst_port, -1, in, TB_DP_AUX_RX_HOPID, in tb_tunnel_discover_dp()
828 tunnel->paths[TB_DP_AUX_PATH_IN] = path; in tb_tunnel_discover_dp()
829 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_IN]); in tb_tunnel_discover_dp()
831 /* Validate that the tunnel is complete */ in tb_tunnel_discover_dp()
832 if (!tb_port_is_dpout(tunnel->dst_port)) { in tb_tunnel_discover_dp()
837 if (!tb_dp_port_is_enabled(tunnel->dst_port)) in tb_tunnel_discover_dp()
840 if (!tb_dp_port_hpd_is_active(tunnel->dst_port)) in tb_tunnel_discover_dp()
843 if (port != tunnel->src_port) { in tb_tunnel_discover_dp()
844 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_dp()
848 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_dp()
849 return tunnel; in tb_tunnel_discover_dp()
852 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_dp()
854 tb_tunnel_free(tunnel); in tb_tunnel_discover_dp()
860 * tb_tunnel_alloc_dp() - allocate a Display Port tunnel
865 * @max_up: Maximum available upstream bandwidth for the DP tunnel (%0
867 * @max_down: Maximum available downstream bandwidth for the DP tunnel
870 * Allocates a tunnel between @in and @out that is capable of tunneling
879 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dp() local
886 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_alloc_dp()
887 if (!tunnel) in tb_tunnel_alloc_dp()
890 tunnel->init = tb_dp_xchg_caps; in tb_tunnel_alloc_dp()
891 tunnel->activate = tb_dp_activate; in tb_tunnel_alloc_dp()
892 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_alloc_dp()
893 tunnel->src_port = in; in tb_tunnel_alloc_dp()
894 tunnel->dst_port = out; in tb_tunnel_alloc_dp()
895 tunnel->max_up = max_up; in tb_tunnel_alloc_dp()
896 tunnel->max_down = max_down; in tb_tunnel_alloc_dp()
898 paths = tunnel->paths; in tb_tunnel_alloc_dp()
921 return tunnel; in tb_tunnel_alloc_dp()
924 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dp()
989 * We don't tunnel other traffic over this link so can use all in tb_dma_init_rx_path()
1052 static void tb_dma_deinit(struct tb_tunnel *tunnel) in tb_dma_deinit() argument
1056 for (i = 0; i < tunnel->npaths; i++) { in tb_dma_deinit()
1057 if (!tunnel->paths[i]) in tb_dma_deinit()
1059 tb_dma_deinit_path(tunnel->paths[i]); in tb_dma_deinit()
1064 * tb_tunnel_alloc_dma() - allocate a DMA tunnel
1082 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dma() local
1095 tunnel = tb_tunnel_alloc(tb, npaths, TB_TUNNEL_DMA); in tb_tunnel_alloc_dma()
1096 if (!tunnel) in tb_tunnel_alloc_dma()
1099 tunnel->src_port = nhi; in tb_tunnel_alloc_dma()
1100 tunnel->dst_port = dst; in tb_tunnel_alloc_dma()
1101 tunnel->deinit = tb_dma_deinit; in tb_tunnel_alloc_dma()
1110 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1112 tb_tunnel_dbg(tunnel, "not enough buffers for RX path\n"); in tb_tunnel_alloc_dma()
1122 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1124 tb_tunnel_dbg(tunnel, "not enough buffers for TX path\n"); in tb_tunnel_alloc_dma()
1129 return tunnel; in tb_tunnel_alloc_dma()
1132 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dma()
1137 * tb_tunnel_match_dma() - Match DMA tunnel
1138 * @tunnel: Tunnel to match
1146 * This function can be used to match specific DMA tunnel, if there are
1150 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path, in tb_tunnel_match_dma() argument
1159 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_match_dma()
1160 const struct tb_path *path = tunnel->paths[i]; in tb_tunnel_match_dma()
1213 static int tb_usb3_init(struct tb_tunnel *tunnel) in tb_usb3_init() argument
1215 tb_tunnel_dbg(tunnel, "allocating initial bandwidth %d/%d Mb/s\n", in tb_usb3_init()
1216 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_init()
1218 return usb4_usb3_port_allocate_bandwidth(tunnel->src_port, in tb_usb3_init()
1219 &tunnel->allocated_up, in tb_usb3_init()
1220 &tunnel->allocated_down); in tb_usb3_init()
1223 static int tb_usb3_activate(struct tb_tunnel *tunnel, bool activate) in tb_usb3_activate() argument
1227 res = tb_usb3_port_enable(tunnel->src_port, activate); in tb_usb3_activate()
1231 if (tb_port_is_usb3_up(tunnel->dst_port)) in tb_usb3_activate()
1232 return tb_usb3_port_enable(tunnel->dst_port, activate); in tb_usb3_activate()
1237 static int tb_usb3_consumed_bandwidth(struct tb_tunnel *tunnel, in tb_usb3_consumed_bandwidth() argument
1246 *consumed_up = tunnel->allocated_up * (3 + pcie_enabled) / 3; in tb_usb3_consumed_bandwidth()
1247 *consumed_down = tunnel->allocated_down * (3 + pcie_enabled) / 3; in tb_usb3_consumed_bandwidth()
1251 static int tb_usb3_release_unused_bandwidth(struct tb_tunnel *tunnel) in tb_usb3_release_unused_bandwidth() argument
1255 ret = usb4_usb3_port_release_bandwidth(tunnel->src_port, in tb_usb3_release_unused_bandwidth()
1256 &tunnel->allocated_up, in tb_usb3_release_unused_bandwidth()
1257 &tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1261 tb_tunnel_dbg(tunnel, "decreased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_release_unused_bandwidth()
1262 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1266 static void tb_usb3_reclaim_available_bandwidth(struct tb_tunnel *tunnel, in tb_usb3_reclaim_available_bandwidth() argument
1272 ret = usb4_usb3_port_actual_link_rate(tunnel->src_port); in tb_usb3_reclaim_available_bandwidth()
1274 tb_tunnel_warn(tunnel, "failed to read actual link rate\n"); in tb_usb3_reclaim_available_bandwidth()
1278 ret = usb4_usb3_port_max_link_rate(tunnel->src_port); in tb_usb3_reclaim_available_bandwidth()
1280 tb_tunnel_warn(tunnel, "failed to read maximum link rate\n"); in tb_usb3_reclaim_available_bandwidth()
1292 if (tunnel->allocated_up >= max_rate && in tb_usb3_reclaim_available_bandwidth()
1293 tunnel->allocated_down >= max_rate) in tb_usb3_reclaim_available_bandwidth()
1298 if (allocate_up < tunnel->allocated_up) in tb_usb3_reclaim_available_bandwidth()
1299 allocate_up = tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1302 if (allocate_down < tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1303 allocate_down = tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1306 if (allocate_up == tunnel->allocated_up && in tb_usb3_reclaim_available_bandwidth()
1307 allocate_down == tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1310 ret = usb4_usb3_port_allocate_bandwidth(tunnel->src_port, &allocate_up, in tb_usb3_reclaim_available_bandwidth()
1313 tb_tunnel_info(tunnel, "failed to allocate bandwidth\n"); in tb_usb3_reclaim_available_bandwidth()
1317 tunnel->allocated_up = allocate_up; in tb_usb3_reclaim_available_bandwidth()
1318 *available_up -= tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1320 tunnel->allocated_down = allocate_down; in tb_usb3_reclaim_available_bandwidth()
1321 *available_down -= tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1323 tb_tunnel_dbg(tunnel, "increased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_reclaim_available_bandwidth()
1324 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_reclaim_available_bandwidth()
1367 * If @down adapter is active, follows the tunnel to the USB3 upstream
1368 * adapter and back. Returns the discovered tunnel or %NULL if there was
1369 * no tunnel.
1374 struct tb_tunnel *tunnel; in tb_tunnel_discover_usb3() local
1380 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3); in tb_tunnel_discover_usb3()
1381 if (!tunnel) in tb_tunnel_discover_usb3()
1384 tunnel->activate = tb_usb3_activate; in tb_tunnel_discover_usb3()
1385 tunnel->src_port = down; in tb_tunnel_discover_usb3()
1393 &tunnel->dst_port, "USB3 Down", alloc_hopid); in tb_tunnel_discover_usb3()
1399 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_discover_usb3()
1400 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_DOWN]); in tb_tunnel_discover_usb3()
1402 path = tb_path_discover(tunnel->dst_port, -1, down, TB_USB3_HOPID, NULL, in tb_tunnel_discover_usb3()
1406 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_discover_usb3()
1407 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_UP]); in tb_tunnel_discover_usb3()
1409 /* Validate that the tunnel is complete */ in tb_tunnel_discover_usb3()
1410 if (!tb_port_is_usb3_up(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
1411 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_usb3()
1416 if (down != tunnel->src_port) { in tb_tunnel_discover_usb3()
1417 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_usb3()
1421 if (!tb_usb3_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
1422 tb_tunnel_warn(tunnel, in tb_tunnel_discover_usb3()
1423 "tunnel is not fully activated, cleaning up\n"); in tb_tunnel_discover_usb3()
1432 * hop tunnel. in tb_tunnel_discover_usb3()
1435 &tunnel->allocated_up, &tunnel->allocated_down); in tb_tunnel_discover_usb3()
1439 tb_tunnel_dbg(tunnel, "currently allocated bandwidth %d/%d Mb/s\n", in tb_tunnel_discover_usb3()
1440 tunnel->allocated_up, tunnel->allocated_down); in tb_tunnel_discover_usb3()
1442 tunnel->init = tb_usb3_init; in tb_tunnel_discover_usb3()
1443 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_discover_usb3()
1444 tunnel->release_unused_bandwidth = in tb_tunnel_discover_usb3()
1446 tunnel->reclaim_available_bandwidth = in tb_tunnel_discover_usb3()
1450 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_usb3()
1451 return tunnel; in tb_tunnel_discover_usb3()
1454 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_usb3()
1456 tb_tunnel_free(tunnel); in tb_tunnel_discover_usb3()
1462 * tb_tunnel_alloc_usb3() - allocate a USB3 tunnel
1466 * @max_up: Maximum available upstream bandwidth for the USB3 tunnel (%0
1468 * @max_down: Maximum available downstream bandwidth for the USB3 tunnel
1471 * Allocate an USB3 tunnel. The ports must be of type @TB_TYPE_USB3_UP and
1480 struct tb_tunnel *tunnel; in tb_tunnel_alloc_usb3() local
1486 * USB3 tunnel. in tb_tunnel_alloc_usb3()
1495 tb_port_dbg(up, "required bandwidth for USB3 tunnel %d Mb/s\n", in tb_tunnel_alloc_usb3()
1499 tb_port_warn(up, "not enough bandwidth for USB3 tunnel\n"); in tb_tunnel_alloc_usb3()
1504 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3); in tb_tunnel_alloc_usb3()
1505 if (!tunnel) in tb_tunnel_alloc_usb3()
1508 tunnel->activate = tb_usb3_activate; in tb_tunnel_alloc_usb3()
1509 tunnel->src_port = down; in tb_tunnel_alloc_usb3()
1510 tunnel->dst_port = up; in tb_tunnel_alloc_usb3()
1511 tunnel->max_up = max_up; in tb_tunnel_alloc_usb3()
1512 tunnel->max_down = max_down; in tb_tunnel_alloc_usb3()
1517 tb_tunnel_free(tunnel); in tb_tunnel_alloc_usb3()
1521 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_alloc_usb3()
1526 tb_tunnel_free(tunnel); in tb_tunnel_alloc_usb3()
1530 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_alloc_usb3()
1533 tunnel->allocated_up = max_rate; in tb_tunnel_alloc_usb3()
1534 tunnel->allocated_down = max_rate; in tb_tunnel_alloc_usb3()
1536 tunnel->init = tb_usb3_init; in tb_tunnel_alloc_usb3()
1537 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_alloc_usb3()
1538 tunnel->release_unused_bandwidth = in tb_tunnel_alloc_usb3()
1540 tunnel->reclaim_available_bandwidth = in tb_tunnel_alloc_usb3()
1544 return tunnel; in tb_tunnel_alloc_usb3()
1548 * tb_tunnel_free() - free a tunnel
1549 * @tunnel: Tunnel to be freed
1551 * Frees a tunnel. The tunnel does not need to be deactivated.
1553 void tb_tunnel_free(struct tb_tunnel *tunnel) in tb_tunnel_free() argument
1557 if (!tunnel) in tb_tunnel_free()
1560 if (tunnel->deinit) in tb_tunnel_free()
1561 tunnel->deinit(tunnel); in tb_tunnel_free()
1563 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_free()
1564 if (tunnel->paths[i]) in tb_tunnel_free()
1565 tb_path_free(tunnel->paths[i]); in tb_tunnel_free()
1568 kfree(tunnel->paths); in tb_tunnel_free()
1569 kfree(tunnel); in tb_tunnel_free()
1574 * @tunnel: Tunnel to check
1576 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel) in tb_tunnel_is_invalid() argument
1580 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_invalid()
1581 WARN_ON(!tunnel->paths[i]->activated); in tb_tunnel_is_invalid()
1582 if (tb_path_is_invalid(tunnel->paths[i])) in tb_tunnel_is_invalid()
1590 * tb_tunnel_restart() - activate a tunnel after a hardware reset
1591 * @tunnel: Tunnel to restart
1595 int tb_tunnel_restart(struct tb_tunnel *tunnel) in tb_tunnel_restart() argument
1599 tb_tunnel_dbg(tunnel, "activating\n"); in tb_tunnel_restart()
1605 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
1606 if (tunnel->paths[i]->activated) { in tb_tunnel_restart()
1607 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_restart()
1608 tunnel->paths[i]->activated = false; in tb_tunnel_restart()
1612 if (tunnel->init) { in tb_tunnel_restart()
1613 res = tunnel->init(tunnel); in tb_tunnel_restart()
1618 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
1619 res = tb_path_activate(tunnel->paths[i]); in tb_tunnel_restart()
1624 if (tunnel->activate) { in tb_tunnel_restart()
1625 res = tunnel->activate(tunnel, true); in tb_tunnel_restart()
1633 tb_tunnel_warn(tunnel, "activation failed\n"); in tb_tunnel_restart()
1634 tb_tunnel_deactivate(tunnel); in tb_tunnel_restart()
1639 * tb_tunnel_activate() - activate a tunnel
1640 * @tunnel: Tunnel to activate
1644 int tb_tunnel_activate(struct tb_tunnel *tunnel) in tb_tunnel_activate() argument
1648 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_activate()
1649 if (tunnel->paths[i]->activated) { in tb_tunnel_activate()
1650 tb_tunnel_WARN(tunnel, in tb_tunnel_activate()
1651 "trying to activate an already activated tunnel\n"); in tb_tunnel_activate()
1656 return tb_tunnel_restart(tunnel); in tb_tunnel_activate()
1660 * tb_tunnel_deactivate() - deactivate a tunnel
1661 * @tunnel: Tunnel to deactivate
1663 void tb_tunnel_deactivate(struct tb_tunnel *tunnel) in tb_tunnel_deactivate() argument
1667 tb_tunnel_dbg(tunnel, "deactivating\n"); in tb_tunnel_deactivate()
1669 if (tunnel->activate) in tb_tunnel_deactivate()
1670 tunnel->activate(tunnel, false); in tb_tunnel_deactivate()
1672 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_deactivate()
1673 if (tunnel->paths[i] && tunnel->paths[i]->activated) in tb_tunnel_deactivate()
1674 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_deactivate()
1679 * tb_tunnel_port_on_path() - Does the tunnel go through port
1680 * @tunnel: Tunnel to check
1683 * Returns true if @tunnel goes through @port (direction does not matter),
1686 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel, in tb_tunnel_port_on_path() argument
1691 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_port_on_path()
1692 if (!tunnel->paths[i]) in tb_tunnel_port_on_path()
1695 if (tb_path_port_on_path(tunnel->paths[i], port)) in tb_tunnel_port_on_path()
1702 static bool tb_tunnel_is_active(const struct tb_tunnel *tunnel) in tb_tunnel_is_active() argument
1706 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_active()
1707 if (!tunnel->paths[i]) in tb_tunnel_is_active()
1709 if (!tunnel->paths[i]->activated) in tb_tunnel_is_active()
1717 * tb_tunnel_consumed_bandwidth() - Return bandwidth consumed by the tunnel
1718 * @tunnel: Tunnel to check
1724 * Stores the amount of isochronous bandwidth @tunnel consumes in
1728 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, in tb_tunnel_consumed_bandwidth() argument
1733 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_consumed_bandwidth()
1736 if (tunnel->consumed_bandwidth) { in tb_tunnel_consumed_bandwidth()
1739 ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw); in tb_tunnel_consumed_bandwidth()
1743 tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw, in tb_tunnel_consumed_bandwidth()
1758 * @tunnel: Tunnel whose unused bandwidth to release
1760 * If tunnel supports dynamic bandwidth management (USB3 tunnels at the
1765 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel) in tb_tunnel_release_unused_bandwidth() argument
1767 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_release_unused_bandwidth()
1770 if (tunnel->release_unused_bandwidth) { in tb_tunnel_release_unused_bandwidth()
1773 ret = tunnel->release_unused_bandwidth(tunnel); in tb_tunnel_release_unused_bandwidth()
1783 * @tunnel: Tunnel reclaiming available bandwidth
1789 * reclaimed by the tunnel). If nothing was reclaimed the values are
1792 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel, in tb_tunnel_reclaim_available_bandwidth() argument
1796 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_reclaim_available_bandwidth()
1799 if (tunnel->reclaim_available_bandwidth) in tb_tunnel_reclaim_available_bandwidth()
1800 tunnel->reclaim_available_bandwidth(tunnel, available_up, in tb_tunnel_reclaim_available_bandwidth()