Lines Matching refs:tunnel

61 #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...)                   \  argument
63 struct tb_tunnel *__tunnel = (tunnel); \
73 #define tb_tunnel_WARN(tunnel, fmt, arg...) \ argument
74 __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
75 #define tb_tunnel_warn(tunnel, fmt, arg...) \ argument
76 __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
77 #define tb_tunnel_info(tunnel, fmt, arg...) \ argument
78 __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
79 #define tb_tunnel_dbg(tunnel, fmt, arg...) \ argument
80 __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg)
137 struct tb_tunnel *tunnel; in tb_tunnel_alloc() local
139 tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); in tb_tunnel_alloc()
140 if (!tunnel) in tb_tunnel_alloc()
143 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); in tb_tunnel_alloc()
144 if (!tunnel->paths) { in tb_tunnel_alloc()
145 tb_tunnel_free(tunnel); in tb_tunnel_alloc()
149 INIT_LIST_HEAD(&tunnel->list); in tb_tunnel_alloc()
150 tunnel->tb = tb; in tb_tunnel_alloc()
151 tunnel->npaths = npaths; in tb_tunnel_alloc()
152 tunnel->type = type; in tb_tunnel_alloc()
154 return tunnel; in tb_tunnel_alloc()
157 static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable) in tb_pci_set_ext_encapsulation() argument
162 if (usb4_switch_version(tunnel->src_port->sw) < 2 || in tb_pci_set_ext_encapsulation()
163 usb4_switch_version(tunnel->dst_port->sw) < 2) in tb_pci_set_ext_encapsulation()
166 ret = usb4_pci_port_set_ext_encapsulation(tunnel->src_port, enable); in tb_pci_set_ext_encapsulation()
170 ret = usb4_pci_port_set_ext_encapsulation(tunnel->dst_port, enable); in tb_pci_set_ext_encapsulation()
174 tb_tunnel_dbg(tunnel, "extended encapsulation %s\n", in tb_pci_set_ext_encapsulation()
179 static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate) in tb_pci_activate() argument
184 res = tb_pci_set_ext_encapsulation(tunnel, activate); in tb_pci_activate()
189 res = tb_pci_port_enable(tunnel->src_port, activate); in tb_pci_activate()
193 if (tb_port_is_pcie_up(tunnel->dst_port)) { in tb_pci_activate()
194 res = tb_pci_port_enable(tunnel->dst_port, activate); in tb_pci_activate()
199 return activate ? 0 : tb_pci_set_ext_encapsulation(tunnel, activate); in tb_pci_activate()
265 struct tb_tunnel *tunnel; in tb_tunnel_discover_pci() local
271 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_discover_pci()
272 if (!tunnel) in tb_tunnel_discover_pci()
275 tunnel->activate = tb_pci_activate; in tb_tunnel_discover_pci()
276 tunnel->src_port = down; in tb_tunnel_discover_pci()
284 &tunnel->dst_port, "PCIe Up", alloc_hopid); in tb_tunnel_discover_pci()
290 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_discover_pci()
291 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_UP])) in tb_tunnel_discover_pci()
294 path = tb_path_discover(tunnel->dst_port, -1, down, TB_PCI_HOPID, NULL, in tb_tunnel_discover_pci()
298 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_discover_pci()
299 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_DOWN])) in tb_tunnel_discover_pci()
303 if (!tb_port_is_pcie_up(tunnel->dst_port)) { in tb_tunnel_discover_pci()
304 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_pci()
309 if (down != tunnel->src_port) { in tb_tunnel_discover_pci()
310 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_pci()
314 if (!tb_pci_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_pci()
315 tb_tunnel_warn(tunnel, in tb_tunnel_discover_pci()
320 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_pci()
321 return tunnel; in tb_tunnel_discover_pci()
324 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_pci()
326 tb_tunnel_free(tunnel); in tb_tunnel_discover_pci()
345 struct tb_tunnel *tunnel; in tb_tunnel_alloc_pci() local
348 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI); in tb_tunnel_alloc_pci()
349 if (!tunnel) in tb_tunnel_alloc_pci()
352 tunnel->activate = tb_pci_activate; in tb_tunnel_alloc_pci()
353 tunnel->src_port = down; in tb_tunnel_alloc_pci()
354 tunnel->dst_port = up; in tb_tunnel_alloc_pci()
360 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_alloc_pci()
368 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_alloc_pci()
372 return tunnel; in tb_tunnel_alloc_pci()
375 tb_tunnel_free(tunnel); in tb_tunnel_alloc_pci()
576 static int tb_dp_xchg_caps(struct tb_tunnel *tunnel) in tb_dp_xchg_caps() argument
579 struct tb_port *out = tunnel->dst_port; in tb_dp_xchg_caps()
580 struct tb_port *in = tunnel->src_port; in tb_dp_xchg_caps()
631 max_bw = tunnel->max_down; in tb_dp_xchg_caps()
633 max_bw = tunnel->max_up; in tb_dp_xchg_caps()
672 static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel) in tb_dp_bandwidth_alloc_mode_enable() argument
675 struct tb_port *out = tunnel->dst_port; in tb_dp_bandwidth_alloc_mode_enable()
676 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_alloc_mode_enable()
755 estimated_bw = tunnel->max_down; in tb_dp_bandwidth_alloc_mode_enable()
757 estimated_bw = tunnel->max_up; in tb_dp_bandwidth_alloc_mode_enable()
774 static int tb_dp_init(struct tb_tunnel *tunnel) in tb_dp_init() argument
776 struct tb_port *in = tunnel->src_port; in tb_dp_init()
781 ret = tb_dp_xchg_caps(tunnel); in tb_dp_init()
797 return tb_dp_bandwidth_alloc_mode_enable(tunnel); in tb_dp_init()
800 static void tb_dp_deinit(struct tb_tunnel *tunnel) in tb_dp_deinit() argument
802 struct tb_port *in = tunnel->src_port; in tb_dp_deinit()
812 static int tb_dp_activate(struct tb_tunnel *tunnel, bool active) in tb_dp_activate() argument
820 paths = tunnel->paths; in tb_dp_activate()
823 tb_dp_port_set_hops(tunnel->src_port, in tb_dp_activate()
828 tb_dp_port_set_hops(tunnel->dst_port, in tb_dp_activate()
833 tb_dp_port_hpd_clear(tunnel->src_port); in tb_dp_activate()
834 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0); in tb_dp_activate()
835 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
836 tb_dp_port_set_hops(tunnel->dst_port, 0, 0, 0); in tb_dp_activate()
839 ret = tb_dp_port_enable(tunnel->src_port, active); in tb_dp_activate()
843 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
844 return tb_dp_port_enable(tunnel->dst_port, active); in tb_dp_activate()
850 static int tb_dp_bandwidth_mode_maximum_bandwidth(struct tb_tunnel *tunnel, in tb_dp_bandwidth_mode_maximum_bandwidth() argument
853 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_mode_maximum_bandwidth()
898 static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel, in tb_dp_bandwidth_mode_consumed_bandwidth() argument
902 struct tb_port *out = tunnel->dst_port; in tb_dp_bandwidth_mode_consumed_bandwidth()
903 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_mode_consumed_bandwidth()
909 if (!tunnel->bw_mode) in tb_dp_bandwidth_mode_consumed_bandwidth()
918 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); in tb_dp_bandwidth_mode_consumed_bandwidth()
938 static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up, in tb_dp_allocated_bandwidth() argument
941 struct tb_port *out = tunnel->dst_port; in tb_dp_allocated_bandwidth()
942 struct tb_port *in = tunnel->src_port; in tb_dp_allocated_bandwidth()
948 if (usb4_dp_port_bandwidth_mode_enabled(in) && tunnel->bw_mode) { in tb_dp_allocated_bandwidth()
956 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); in tb_dp_allocated_bandwidth()
972 return tunnel->consumed_bandwidth(tunnel, allocated_up, in tb_dp_allocated_bandwidth()
976 static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, in tb_dp_alloc_bandwidth() argument
979 struct tb_port *out = tunnel->dst_port; in tb_dp_alloc_bandwidth()
980 struct tb_port *in = tunnel->src_port; in tb_dp_alloc_bandwidth()
986 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw); in tb_dp_alloc_bandwidth()
1008 tunnel->bw_mode = true; in tb_dp_alloc_bandwidth()
1015 static int tb_dp_read_dprx(struct tb_tunnel *tunnel, u32 *rate, u32 *lanes, in tb_dp_read_dprx() argument
1019 struct tb_port *in = tunnel->src_port; in tb_dp_read_dprx()
1049 static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate, in tb_dp_read_cap() argument
1052 struct tb_port *in = tunnel->src_port; in tb_dp_read_cap()
1062 tb_tunnel_WARN(tunnel, "invalid capability index %#x\n", cap); in tb_dp_read_cap()
1082 static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, in tb_dp_maximum_bandwidth() argument
1085 struct tb_port *in = tunnel->src_port; in tb_dp_maximum_bandwidth()
1091 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, NULL); in tb_dp_maximum_bandwidth()
1095 if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) { in tb_dp_maximum_bandwidth()
1106 static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, in tb_dp_consumed_bandwidth() argument
1109 struct tb_port *in = tunnel->src_port; in tb_dp_consumed_bandwidth()
1120 ret = tb_dp_bandwidth_mode_consumed_bandwidth(tunnel, consumed_up, in tb_dp_consumed_bandwidth()
1134 ret = tb_dp_read_dprx(tunnel, &rate, &lanes, 150); in tb_dp_consumed_bandwidth()
1137 ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, in tb_dp_consumed_bandwidth()
1143 ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, &rate, &lanes); in tb_dp_consumed_bandwidth()
1153 if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) { in tb_dp_consumed_bandwidth()
1241 static void tb_dp_dump(struct tb_tunnel *tunnel) in tb_dp_dump() argument
1246 in = tunnel->src_port; in tb_dp_dump()
1247 out = tunnel->dst_port; in tb_dp_dump()
1259 out = tunnel->dst_port; in tb_dp_dump()
1297 struct tb_tunnel *tunnel; in tb_tunnel_discover_dp() local
1304 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_discover_dp()
1305 if (!tunnel) in tb_tunnel_discover_dp()
1308 tunnel->init = tb_dp_init; in tb_tunnel_discover_dp()
1309 tunnel->deinit = tb_dp_deinit; in tb_tunnel_discover_dp()
1310 tunnel->activate = tb_dp_activate; in tb_tunnel_discover_dp()
1311 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; in tb_tunnel_discover_dp()
1312 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; in tb_tunnel_discover_dp()
1313 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; in tb_tunnel_discover_dp()
1314 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_discover_dp()
1315 tunnel->src_port = in; in tb_tunnel_discover_dp()
1318 &tunnel->dst_port, "Video", alloc_hopid); in tb_tunnel_discover_dp()
1324 tunnel->paths[TB_DP_VIDEO_PATH_OUT] = path; in tb_tunnel_discover_dp()
1325 if (tb_dp_init_video_path(tunnel->paths[TB_DP_VIDEO_PATH_OUT])) in tb_tunnel_discover_dp()
1332 tunnel->paths[TB_DP_AUX_PATH_OUT] = path; in tb_tunnel_discover_dp()
1333 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_OUT]); in tb_tunnel_discover_dp()
1335 path = tb_path_discover(tunnel->dst_port, -1, in, TB_DP_AUX_RX_HOPID, in tb_tunnel_discover_dp()
1339 tunnel->paths[TB_DP_AUX_PATH_IN] = path; in tb_tunnel_discover_dp()
1340 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_IN]); in tb_tunnel_discover_dp()
1343 if (!tb_port_is_dpout(tunnel->dst_port)) { in tb_tunnel_discover_dp()
1348 if (!tb_dp_port_is_enabled(tunnel->dst_port)) in tb_tunnel_discover_dp()
1351 if (!tb_dp_port_hpd_is_active(tunnel->dst_port)) in tb_tunnel_discover_dp()
1354 if (port != tunnel->src_port) { in tb_tunnel_discover_dp()
1355 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_dp()
1359 tb_dp_dump(tunnel); in tb_tunnel_discover_dp()
1361 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_dp()
1362 return tunnel; in tb_tunnel_discover_dp()
1365 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_dp()
1367 tb_tunnel_free(tunnel); in tb_tunnel_discover_dp()
1392 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dp() local
1399 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP); in tb_tunnel_alloc_dp()
1400 if (!tunnel) in tb_tunnel_alloc_dp()
1403 tunnel->init = tb_dp_init; in tb_tunnel_alloc_dp()
1404 tunnel->deinit = tb_dp_deinit; in tb_tunnel_alloc_dp()
1405 tunnel->activate = tb_dp_activate; in tb_tunnel_alloc_dp()
1406 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; in tb_tunnel_alloc_dp()
1407 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; in tb_tunnel_alloc_dp()
1408 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; in tb_tunnel_alloc_dp()
1409 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_alloc_dp()
1410 tunnel->src_port = in; in tb_tunnel_alloc_dp()
1411 tunnel->dst_port = out; in tb_tunnel_alloc_dp()
1412 tunnel->max_up = max_up; in tb_tunnel_alloc_dp()
1413 tunnel->max_down = max_down; in tb_tunnel_alloc_dp()
1415 paths = tunnel->paths; in tb_tunnel_alloc_dp()
1438 return tunnel; in tb_tunnel_alloc_dp()
1441 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dp()
1569 static void tb_dma_deinit(struct tb_tunnel *tunnel) in tb_dma_deinit() argument
1573 for (i = 0; i < tunnel->npaths; i++) { in tb_dma_deinit()
1574 if (!tunnel->paths[i]) in tb_dma_deinit()
1576 tb_dma_deinit_path(tunnel->paths[i]); in tb_dma_deinit()
1599 struct tb_tunnel *tunnel; in tb_tunnel_alloc_dma() local
1616 tunnel = tb_tunnel_alloc(tb, npaths, TB_TUNNEL_DMA); in tb_tunnel_alloc_dma()
1617 if (!tunnel) in tb_tunnel_alloc_dma()
1620 tunnel->src_port = nhi; in tb_tunnel_alloc_dma()
1621 tunnel->dst_port = dst; in tb_tunnel_alloc_dma()
1622 tunnel->deinit = tb_dma_deinit; in tb_tunnel_alloc_dma()
1631 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1633 tb_tunnel_dbg(tunnel, "not enough buffers for RX path\n"); in tb_tunnel_alloc_dma()
1643 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1645 tb_tunnel_dbg(tunnel, "not enough buffers for TX path\n"); in tb_tunnel_alloc_dma()
1650 return tunnel; in tb_tunnel_alloc_dma()
1653 tb_tunnel_free(tunnel); in tb_tunnel_alloc_dma()
1671 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path, in tb_tunnel_match_dma() argument
1680 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_match_dma()
1681 const struct tb_path *path = tunnel->paths[i]; in tb_tunnel_match_dma()
1734 static int tb_usb3_init(struct tb_tunnel *tunnel) in tb_usb3_init() argument
1736 tb_tunnel_dbg(tunnel, "allocating initial bandwidth %d/%d Mb/s\n", in tb_usb3_init()
1737 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_init()
1739 return usb4_usb3_port_allocate_bandwidth(tunnel->src_port, in tb_usb3_init()
1740 &tunnel->allocated_up, in tb_usb3_init()
1741 &tunnel->allocated_down); in tb_usb3_init()
1744 static int tb_usb3_activate(struct tb_tunnel *tunnel, bool activate) in tb_usb3_activate() argument
1748 res = tb_usb3_port_enable(tunnel->src_port, activate); in tb_usb3_activate()
1752 if (tb_port_is_usb3_up(tunnel->dst_port)) in tb_usb3_activate()
1753 return tb_usb3_port_enable(tunnel->dst_port, activate); in tb_usb3_activate()
1758 static int tb_usb3_consumed_bandwidth(struct tb_tunnel *tunnel, in tb_usb3_consumed_bandwidth() argument
1767 *consumed_up = tunnel->allocated_up * (3 + pcie_enabled) / 3; in tb_usb3_consumed_bandwidth()
1768 *consumed_down = tunnel->allocated_down * (3 + pcie_enabled) / 3; in tb_usb3_consumed_bandwidth()
1772 static int tb_usb3_release_unused_bandwidth(struct tb_tunnel *tunnel) in tb_usb3_release_unused_bandwidth() argument
1776 ret = usb4_usb3_port_release_bandwidth(tunnel->src_port, in tb_usb3_release_unused_bandwidth()
1777 &tunnel->allocated_up, in tb_usb3_release_unused_bandwidth()
1778 &tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1782 tb_tunnel_dbg(tunnel, "decreased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_release_unused_bandwidth()
1783 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1787 static void tb_usb3_reclaim_available_bandwidth(struct tb_tunnel *tunnel, in tb_usb3_reclaim_available_bandwidth() argument
1793 ret = usb4_usb3_port_actual_link_rate(tunnel->src_port); in tb_usb3_reclaim_available_bandwidth()
1795 tb_tunnel_warn(tunnel, "failed to read actual link rate\n"); in tb_usb3_reclaim_available_bandwidth()
1799 ret = tb_usb3_max_link_rate(tunnel->dst_port, tunnel->src_port); in tb_usb3_reclaim_available_bandwidth()
1801 tb_tunnel_warn(tunnel, "failed to read maximum link rate\n"); in tb_usb3_reclaim_available_bandwidth()
1813 if (tunnel->allocated_up >= max_rate && in tb_usb3_reclaim_available_bandwidth()
1814 tunnel->allocated_down >= max_rate) in tb_usb3_reclaim_available_bandwidth()
1819 if (allocate_up < tunnel->allocated_up) in tb_usb3_reclaim_available_bandwidth()
1820 allocate_up = tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1823 if (allocate_down < tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1824 allocate_down = tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1827 if (allocate_up == tunnel->allocated_up && in tb_usb3_reclaim_available_bandwidth()
1828 allocate_down == tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1831 ret = usb4_usb3_port_allocate_bandwidth(tunnel->src_port, &allocate_up, in tb_usb3_reclaim_available_bandwidth()
1834 tb_tunnel_info(tunnel, "failed to allocate bandwidth\n"); in tb_usb3_reclaim_available_bandwidth()
1838 tunnel->allocated_up = allocate_up; in tb_usb3_reclaim_available_bandwidth()
1839 *available_up -= tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1841 tunnel->allocated_down = allocate_down; in tb_usb3_reclaim_available_bandwidth()
1842 *available_down -= tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1844 tb_tunnel_dbg(tunnel, "increased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_reclaim_available_bandwidth()
1845 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_reclaim_available_bandwidth()
1895 struct tb_tunnel *tunnel; in tb_tunnel_discover_usb3() local
1901 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3); in tb_tunnel_discover_usb3()
1902 if (!tunnel) in tb_tunnel_discover_usb3()
1905 tunnel->activate = tb_usb3_activate; in tb_tunnel_discover_usb3()
1906 tunnel->src_port = down; in tb_tunnel_discover_usb3()
1914 &tunnel->dst_port, "USB3 Down", alloc_hopid); in tb_tunnel_discover_usb3()
1920 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_discover_usb3()
1921 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_DOWN]); in tb_tunnel_discover_usb3()
1923 path = tb_path_discover(tunnel->dst_port, -1, down, TB_USB3_HOPID, NULL, in tb_tunnel_discover_usb3()
1927 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_discover_usb3()
1928 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_UP]); in tb_tunnel_discover_usb3()
1931 if (!tb_port_is_usb3_up(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
1932 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_usb3()
1937 if (down != tunnel->src_port) { in tb_tunnel_discover_usb3()
1938 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n"); in tb_tunnel_discover_usb3()
1942 if (!tb_usb3_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
1943 tb_tunnel_warn(tunnel, in tb_tunnel_discover_usb3()
1956 &tunnel->allocated_up, &tunnel->allocated_down); in tb_tunnel_discover_usb3()
1960 tb_tunnel_dbg(tunnel, "currently allocated bandwidth %d/%d Mb/s\n", in tb_tunnel_discover_usb3()
1961 tunnel->allocated_up, tunnel->allocated_down); in tb_tunnel_discover_usb3()
1963 tunnel->init = tb_usb3_init; in tb_tunnel_discover_usb3()
1964 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_discover_usb3()
1965 tunnel->release_unused_bandwidth = in tb_tunnel_discover_usb3()
1967 tunnel->reclaim_available_bandwidth = in tb_tunnel_discover_usb3()
1971 tb_tunnel_dbg(tunnel, "discovered\n"); in tb_tunnel_discover_usb3()
1972 return tunnel; in tb_tunnel_discover_usb3()
1975 tb_tunnel_deactivate(tunnel); in tb_tunnel_discover_usb3()
1977 tb_tunnel_free(tunnel); in tb_tunnel_discover_usb3()
2001 struct tb_tunnel *tunnel; in tb_tunnel_alloc_usb3() local
2025 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3); in tb_tunnel_alloc_usb3()
2026 if (!tunnel) in tb_tunnel_alloc_usb3()
2029 tunnel->activate = tb_usb3_activate; in tb_tunnel_alloc_usb3()
2030 tunnel->src_port = down; in tb_tunnel_alloc_usb3()
2031 tunnel->dst_port = up; in tb_tunnel_alloc_usb3()
2032 tunnel->max_up = max_up; in tb_tunnel_alloc_usb3()
2033 tunnel->max_down = max_down; in tb_tunnel_alloc_usb3()
2038 tb_tunnel_free(tunnel); in tb_tunnel_alloc_usb3()
2042 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_alloc_usb3()
2047 tb_tunnel_free(tunnel); in tb_tunnel_alloc_usb3()
2051 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_alloc_usb3()
2054 tunnel->allocated_up = max_rate; in tb_tunnel_alloc_usb3()
2055 tunnel->allocated_down = max_rate; in tb_tunnel_alloc_usb3()
2057 tunnel->init = tb_usb3_init; in tb_tunnel_alloc_usb3()
2058 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_alloc_usb3()
2059 tunnel->release_unused_bandwidth = in tb_tunnel_alloc_usb3()
2061 tunnel->reclaim_available_bandwidth = in tb_tunnel_alloc_usb3()
2065 return tunnel; in tb_tunnel_alloc_usb3()
2074 void tb_tunnel_free(struct tb_tunnel *tunnel) in tb_tunnel_free() argument
2078 if (!tunnel) in tb_tunnel_free()
2081 if (tunnel->deinit) in tb_tunnel_free()
2082 tunnel->deinit(tunnel); in tb_tunnel_free()
2084 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_free()
2085 if (tunnel->paths[i]) in tb_tunnel_free()
2086 tb_path_free(tunnel->paths[i]); in tb_tunnel_free()
2089 kfree(tunnel->paths); in tb_tunnel_free()
2090 kfree(tunnel); in tb_tunnel_free()
2097 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel) in tb_tunnel_is_invalid() argument
2101 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_invalid()
2102 WARN_ON(!tunnel->paths[i]->activated); in tb_tunnel_is_invalid()
2103 if (tb_path_is_invalid(tunnel->paths[i])) in tb_tunnel_is_invalid()
2116 int tb_tunnel_restart(struct tb_tunnel *tunnel) in tb_tunnel_restart() argument
2120 tb_tunnel_dbg(tunnel, "activating\n"); in tb_tunnel_restart()
2126 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
2127 if (tunnel->paths[i]->activated) { in tb_tunnel_restart()
2128 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_restart()
2129 tunnel->paths[i]->activated = false; in tb_tunnel_restart()
2133 if (tunnel->init) { in tb_tunnel_restart()
2134 res = tunnel->init(tunnel); in tb_tunnel_restart()
2139 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
2140 res = tb_path_activate(tunnel->paths[i]); in tb_tunnel_restart()
2145 if (tunnel->activate) { in tb_tunnel_restart()
2146 res = tunnel->activate(tunnel, true); in tb_tunnel_restart()
2154 tb_tunnel_warn(tunnel, "activation failed\n"); in tb_tunnel_restart()
2155 tb_tunnel_deactivate(tunnel); in tb_tunnel_restart()
2165 int tb_tunnel_activate(struct tb_tunnel *tunnel) in tb_tunnel_activate() argument
2169 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_activate()
2170 if (tunnel->paths[i]->activated) { in tb_tunnel_activate()
2171 tb_tunnel_WARN(tunnel, in tb_tunnel_activate()
2177 return tb_tunnel_restart(tunnel); in tb_tunnel_activate()
2184 void tb_tunnel_deactivate(struct tb_tunnel *tunnel) in tb_tunnel_deactivate() argument
2188 tb_tunnel_dbg(tunnel, "deactivating\n"); in tb_tunnel_deactivate()
2190 if (tunnel->activate) in tb_tunnel_deactivate()
2191 tunnel->activate(tunnel, false); in tb_tunnel_deactivate()
2193 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_deactivate()
2194 if (tunnel->paths[i] && tunnel->paths[i]->activated) in tb_tunnel_deactivate()
2195 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_deactivate()
2207 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel, in tb_tunnel_port_on_path() argument
2212 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_port_on_path()
2213 if (!tunnel->paths[i]) in tb_tunnel_port_on_path()
2216 if (tb_path_port_on_path(tunnel->paths[i], port)) in tb_tunnel_port_on_path()
2223 static bool tb_tunnel_is_active(const struct tb_tunnel *tunnel) in tb_tunnel_is_active() argument
2227 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_active()
2228 if (!tunnel->paths[i]) in tb_tunnel_is_active()
2230 if (!tunnel->paths[i]->activated) in tb_tunnel_is_active()
2247 int tb_tunnel_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up, in tb_tunnel_maximum_bandwidth() argument
2250 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_maximum_bandwidth()
2253 if (tunnel->maximum_bandwidth) in tb_tunnel_maximum_bandwidth()
2254 return tunnel->maximum_bandwidth(tunnel, max_up, max_down); in tb_tunnel_maximum_bandwidth()
2268 int tb_tunnel_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up, in tb_tunnel_allocated_bandwidth() argument
2271 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_allocated_bandwidth()
2274 if (tunnel->allocated_bandwidth) in tb_tunnel_allocated_bandwidth()
2275 return tunnel->allocated_bandwidth(tunnel, allocated_up, in tb_tunnel_allocated_bandwidth()
2291 int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, in tb_tunnel_alloc_bandwidth() argument
2294 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_alloc_bandwidth()
2297 if (tunnel->alloc_bandwidth) in tb_tunnel_alloc_bandwidth()
2298 return tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down); in tb_tunnel_alloc_bandwidth()
2315 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, in tb_tunnel_consumed_bandwidth() argument
2320 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_consumed_bandwidth()
2323 if (tunnel->consumed_bandwidth) { in tb_tunnel_consumed_bandwidth()
2326 ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw); in tb_tunnel_consumed_bandwidth()
2330 tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw, in tb_tunnel_consumed_bandwidth()
2352 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel) in tb_tunnel_release_unused_bandwidth() argument
2354 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_release_unused_bandwidth()
2357 if (tunnel->release_unused_bandwidth) { in tb_tunnel_release_unused_bandwidth()
2360 ret = tunnel->release_unused_bandwidth(tunnel); in tb_tunnel_release_unused_bandwidth()
2379 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel, in tb_tunnel_reclaim_available_bandwidth() argument
2383 if (!tb_tunnel_is_active(tunnel)) in tb_tunnel_reclaim_available_bandwidth()
2386 if (tunnel->reclaim_available_bandwidth) in tb_tunnel_reclaim_available_bandwidth()
2387 tunnel->reclaim_available_bandwidth(tunnel, available_up, in tb_tunnel_reclaim_available_bandwidth()