Lines Matching refs:tunnel

15 #include "tunnel.h"
61 #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \
63 struct tb_tunnel *__tunnel = (tunnel); \
73 #define tb_tunnel_WARN(tunnel, fmt, arg...) \
74 __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
75 #define tb_tunnel_warn(tunnel, fmt, arg...) \
76 __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
77 #define tb_tunnel_info(tunnel, fmt, arg...) \
78 __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
79 #define tb_tunnel_dbg(tunnel, fmt, arg...) \
80 __TB_TUNNEL_PRINT(tb_dbg, tunnel, fmt, ##arg)
105 /* Add some credits for potential second DMA tunnel */
137 struct tb_tunnel *tunnel;
139 tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL);
140 if (!tunnel)
143 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL);
144 if (!tunnel->paths) {
145 tb_tunnel_free(tunnel);
149 INIT_LIST_HEAD(&tunnel->list);
150 tunnel->tb = tb;
151 tunnel->npaths = npaths;
152 tunnel->type = type;
154 return tunnel;
157 static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable)
162 if (usb4_switch_version(tunnel->src_port->sw) < 2 ||
163 usb4_switch_version(tunnel->dst_port->sw) < 2)
166 ret = usb4_pci_port_set_ext_encapsulation(tunnel->src_port, enable);
170 ret = usb4_pci_port_set_ext_encapsulation(tunnel->dst_port, enable);
174 tb_tunnel_dbg(tunnel, "extended encapsulation %s\n",
179 static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate)
184 res = tb_pci_set_ext_encapsulation(tunnel, activate);
189 res = tb_pci_port_enable(tunnel->src_port, activate);
193 if (tb_port_is_pcie_up(tunnel->dst_port)) {
194 res = tb_pci_port_enable(tunnel->dst_port, activate);
199 return activate ? 0 : tb_pci_set_ext_encapsulation(tunnel, activate);
258 * If @down adapter is active, follows the tunnel to the PCIe upstream
259 * adapter and back. Returns the discovered tunnel or %NULL if there was
260 * no tunnel.
265 struct tb_tunnel *tunnel;
271 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI);
272 if (!tunnel)
275 tunnel->activate = tb_pci_activate;
276 tunnel->src_port = down;
284 &tunnel->dst_port, "PCIe Up", alloc_hopid);
290 tunnel->paths[TB_PCI_PATH_UP] = path;
291 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_UP]))
294 path = tb_path_discover(tunnel->dst_port, -1, down, TB_PCI_HOPID, NULL,
298 tunnel->paths[TB_PCI_PATH_DOWN] = path;
299 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_DOWN]))
302 /* Validate that the tunnel is complete */
303 if (!tb_port_is_pcie_up(tunnel->dst_port)) {
304 tb_port_warn(tunnel->dst_port,
309 if (down != tunnel->src_port) {
310 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n");
314 if (!tb_pci_port_is_enabled(tunnel->dst_port)) {
315 tb_tunnel_warn(tunnel,
316 "tunnel is not fully activated, cleaning up\n");
320 tb_tunnel_dbg(tunnel, "discovered\n");
321 return tunnel;
324 tb_tunnel_deactivate(tunnel);
326 tb_tunnel_free(tunnel);
332 * tb_tunnel_alloc_pci() - allocate a pci tunnel
337 * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and
345 struct tb_tunnel *tunnel;
348 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_PCI);
349 if (!tunnel)
352 tunnel->activate = tb_pci_activate;
353 tunnel->src_port = down;
354 tunnel->dst_port = up;
360 tunnel->paths[TB_PCI_PATH_DOWN] = path;
368 tunnel->paths[TB_PCI_PATH_UP] = path;
372 return tunnel;
375 tb_tunnel_free(tunnel);
576 static int tb_dp_xchg_caps(struct tb_tunnel *tunnel)
579 struct tb_port *out = tunnel->dst_port;
580 struct tb_port *in = tunnel->src_port;
621 * If the tunnel bandwidth is limited (max_bw is set) then see
631 max_bw = tunnel->max_down;
633 max_bw = tunnel->max_up;
642 tb_port_info(out, "not enough bandwidth for DP tunnel\n");
672 static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel)
675 struct tb_port *out = tunnel->dst_port;
676 struct tb_port *in = tunnel->src_port;
755 estimated_bw = tunnel->max_down;
757 estimated_bw = tunnel->max_up;
774 static int tb_dp_init(struct tb_tunnel *tunnel)
776 struct tb_port *in = tunnel->src_port;
781 ret = tb_dp_xchg_caps(tunnel);
797 return tb_dp_bandwidth_alloc_mode_enable(tunnel);
800 static void tb_dp_deinit(struct tb_tunnel *tunnel)
802 struct tb_port *in = tunnel->src_port;
812 static int tb_dp_activate(struct tb_tunnel *tunnel, bool active)
820 paths = tunnel->paths;
823 tb_dp_port_set_hops(tunnel->src_port,
828 tb_dp_port_set_hops(tunnel->dst_port,
833 tb_dp_port_hpd_clear(tunnel->src_port);
834 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0);
835 if (tb_port_is_dpout(tunnel->dst_port))
836 tb_dp_port_set_hops(tunnel->dst_port, 0, 0, 0);
839 ret = tb_dp_port_enable(tunnel->src_port, active);
843 if (tb_port_is_dpout(tunnel->dst_port))
844 return tb_dp_port_enable(tunnel->dst_port, active);
850 static int tb_dp_bandwidth_mode_maximum_bandwidth(struct tb_tunnel *tunnel,
853 struct tb_port *in = tunnel->src_port;
898 static int tb_dp_bandwidth_mode_consumed_bandwidth(struct tb_tunnel *tunnel,
902 struct tb_port *out = tunnel->dst_port;
903 struct tb_port *in = tunnel->src_port;
909 if (!tunnel->bw_mode)
918 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw);
938 static int tb_dp_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up,
941 struct tb_port *out = tunnel->dst_port;
942 struct tb_port *in = tunnel->src_port;
948 if (usb4_dp_port_bandwidth_mode_enabled(in) && tunnel->bw_mode) {
956 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw);
972 return tunnel->consumed_bandwidth(tunnel, allocated_up,
976 static int tb_dp_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
979 struct tb_port *out = tunnel->dst_port;
980 struct tb_port *in = tunnel->src_port;
986 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, &max_bw);
1008 tunnel->bw_mode = true;
1015 static int tb_dp_read_dprx(struct tb_tunnel *tunnel, u32 *rate, u32 *lanes,
1019 struct tb_port *in = tunnel->src_port;
1023 * active tunnel.
1048 /* Read cap from tunnel DP IN */
1049 static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate,
1052 struct tb_port *in = tunnel->src_port;
1062 tb_tunnel_WARN(tunnel, "invalid capability index %#x\n", cap);
1082 static int tb_dp_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
1085 struct tb_port *in = tunnel->src_port;
1091 ret = tb_dp_bandwidth_mode_maximum_bandwidth(tunnel, NULL);
1095 if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) {
1106 static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
1109 struct tb_port *in = tunnel->src_port;
1120 ret = tb_dp_bandwidth_mode_consumed_bandwidth(tunnel, consumed_up,
1134 ret = tb_dp_read_dprx(tunnel, &rate, &lanes, 150);
1137 ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP,
1143 ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, &rate, &lanes);
1153 if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) {
1241 static void tb_dp_dump(struct tb_tunnel *tunnel)
1246 in = tunnel->src_port;
1247 out = tunnel->dst_port;
1259 out = tunnel->dst_port;
1288 * If @in adapter is active, follows the tunnel to the DP out adapter
1289 * and back. Returns the discovered tunnel or %NULL if there was no
1290 * tunnel.
1292 * Return: DP tunnel or %NULL if no tunnel found.
1297 struct tb_tunnel *tunnel;
1304 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP);
1305 if (!tunnel)
1308 tunnel->init = tb_dp_init;
1309 tunnel->deinit = tb_dp_deinit;
1310 tunnel->activate = tb_dp_activate;
1311 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth;
1312 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth;
1313 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth;
1314 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth;
1315 tunnel->src_port = in;
1318 &tunnel->dst_port, "Video", alloc_hopid);
1324 tunnel->paths[TB_DP_VIDEO_PATH_OUT] = path;
1325 if (tb_dp_init_video_path(tunnel->paths[TB_DP_VIDEO_PATH_OUT]))
1332 tunnel->paths[TB_DP_AUX_PATH_OUT] = path;
1333 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_OUT]);
1335 path = tb_path_discover(tunnel->dst_port, -1, in, TB_DP_AUX_RX_HOPID,
1339 tunnel->paths[TB_DP_AUX_PATH_IN] = path;
1340 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_IN]);
1342 /* Validate that the tunnel is complete */
1343 if (!tb_port_is_dpout(tunnel->dst_port)) {
1348 if (!tb_dp_port_is_enabled(tunnel->dst_port))
1351 if (!tb_dp_port_hpd_is_active(tunnel->dst_port))
1354 if (port != tunnel->src_port) {
1355 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n");
1359 tb_dp_dump(tunnel);
1361 tb_tunnel_dbg(tunnel, "discovered\n");
1362 return tunnel;
1365 tb_tunnel_deactivate(tunnel);
1367 tb_tunnel_free(tunnel);
1373 * tb_tunnel_alloc_dp() - allocate a Display Port tunnel
1378 * @max_up: Maximum available upstream bandwidth for the DP tunnel (%0
1380 * @max_down: Maximum available downstream bandwidth for the DP tunnel
1383 * Allocates a tunnel between @in and @out that is capable of tunneling
1392 struct tb_tunnel *tunnel;
1399 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP);
1400 if (!tunnel)
1403 tunnel->init = tb_dp_init;
1404 tunnel->deinit = tb_dp_deinit;
1405 tunnel->activate = tb_dp_activate;
1406 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth;
1407 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth;
1408 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth;
1409 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth;
1410 tunnel->src_port = in;
1411 tunnel->dst_port = out;
1412 tunnel->max_up = max_up;
1413 tunnel->max_down = max_down;
1415 paths = tunnel->paths;
1438 return tunnel;
1441 tb_tunnel_free(tunnel);
1506 * We don't tunnel other traffic over this link so can use all
1569 static void tb_dma_deinit(struct tb_tunnel *tunnel)
1573 for (i = 0; i < tunnel->npaths; i++) {
1574 if (!tunnel->paths[i])
1576 tb_dma_deinit_path(tunnel->paths[i]);
1581 * tb_tunnel_alloc_dma() - allocate a DMA tunnel
1599 struct tb_tunnel *tunnel;
1616 tunnel = tb_tunnel_alloc(tb, npaths, TB_TUNNEL_DMA);
1617 if (!tunnel)
1620 tunnel->src_port = nhi;
1621 tunnel->dst_port = dst;
1622 tunnel->deinit = tb_dma_deinit;
1631 tunnel->paths[i++] = path;
1633 tb_tunnel_dbg(tunnel, "not enough buffers for RX path\n");
1643 tunnel->paths[i++] = path;
1645 tb_tunnel_dbg(tunnel, "not enough buffers for TX path\n");
1650 return tunnel;
1653 tb_tunnel_free(tunnel);
1658 * tb_tunnel_match_dma() - Match DMA tunnel
1659 * @tunnel: Tunnel to match
1667 * This function can be used to match specific DMA tunnel, if there are
1671 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
1680 for (i = 0; i < tunnel->npaths; i++) {
1681 const struct tb_path *path = tunnel->paths[i];
1734 static int tb_usb3_init(struct tb_tunnel *tunnel)
1736 tb_tunnel_dbg(tunnel, "allocating initial bandwidth %d/%d Mb/s\n",
1737 tunnel->allocated_up, tunnel->allocated_down);
1739 return usb4_usb3_port_allocate_bandwidth(tunnel->src_port,
1740 &tunnel->allocated_up,
1741 &tunnel->allocated_down);
1744 static int tb_usb3_activate(struct tb_tunnel *tunnel, bool activate)
1748 res = tb_usb3_port_enable(tunnel->src_port, activate);
1752 if (tb_port_is_usb3_up(tunnel->dst_port))
1753 return tb_usb3_port_enable(tunnel->dst_port, activate);
1758 static int tb_usb3_consumed_bandwidth(struct tb_tunnel *tunnel,
1767 *consumed_up = tunnel->allocated_up * (3 + pcie_enabled) / 3;
1768 *consumed_down = tunnel->allocated_down * (3 + pcie_enabled) / 3;
1772 static int tb_usb3_release_unused_bandwidth(struct tb_tunnel *tunnel)
1776 ret = usb4_usb3_port_release_bandwidth(tunnel->src_port,
1777 &tunnel->allocated_up,
1778 &tunnel->allocated_down);
1782 tb_tunnel_dbg(tunnel, "decreased bandwidth allocation to %d/%d Mb/s\n",
1783 tunnel->allocated_up, tunnel->allocated_down);
1787 static void tb_usb3_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
1793 ret = usb4_usb3_port_actual_link_rate(tunnel->src_port);
1795 tb_tunnel_warn(tunnel, "failed to read actual link rate\n");
1799 ret = tb_usb3_max_link_rate(tunnel->dst_port, tunnel->src_port);
1801 tb_tunnel_warn(tunnel, "failed to read maximum link rate\n");
1813 if (tunnel->allocated_up >= max_rate &&
1814 tunnel->allocated_down >= max_rate)
1819 if (allocate_up < tunnel->allocated_up)
1820 allocate_up = tunnel->allocated_up;
1823 if (allocate_down < tunnel->allocated_down)
1824 allocate_down = tunnel->allocated_down;
1827 if (allocate_up == tunnel->allocated_up &&
1828 allocate_down == tunnel->allocated_down)
1831 ret = usb4_usb3_port_allocate_bandwidth(tunnel->src_port, &allocate_up,
1834 tb_tunnel_info(tunnel, "failed to allocate bandwidth\n");
1838 tunnel->allocated_up = allocate_up;
1839 *available_up -= tunnel->allocated_up;
1841 tunnel->allocated_down = allocate_down;
1842 *available_down -= tunnel->allocated_down;
1844 tb_tunnel_dbg(tunnel, "increased bandwidth allocation to %d/%d Mb/s\n",
1845 tunnel->allocated_up, tunnel->allocated_down);
1888 * If @down adapter is active, follows the tunnel to the USB3 upstream
1889 * adapter and back. Returns the discovered tunnel or %NULL if there was
1890 * no tunnel.
1895 struct tb_tunnel *tunnel;
1901 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3);
1902 if (!tunnel)
1905 tunnel->activate = tb_usb3_activate;
1906 tunnel->src_port = down;
1914 &tunnel->dst_port, "USB3 Down", alloc_hopid);
1920 tunnel->paths[TB_USB3_PATH_DOWN] = path;
1921 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_DOWN]);
1923 path = tb_path_discover(tunnel->dst_port, -1, down, TB_USB3_HOPID, NULL,
1927 tunnel->paths[TB_USB3_PATH_UP] = path;
1928 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_UP]);
1930 /* Validate that the tunnel is complete */
1931 if (!tb_port_is_usb3_up(tunnel->dst_port)) {
1932 tb_port_warn(tunnel->dst_port,
1937 if (down != tunnel->src_port) {
1938 tb_tunnel_warn(tunnel, "path is not complete, cleaning up\n");
1942 if (!tb_usb3_port_is_enabled(tunnel->dst_port)) {
1943 tb_tunnel_warn(tunnel,
1944 "tunnel is not fully activated, cleaning up\n");
1953 * hop tunnel.
1956 &tunnel->allocated_up, &tunnel->allocated_down);
1960 tb_tunnel_dbg(tunnel, "currently allocated bandwidth %d/%d Mb/s\n",
1961 tunnel->allocated_up, tunnel->allocated_down);
1963 tunnel->init = tb_usb3_init;
1964 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth;
1965 tunnel->release_unused_bandwidth =
1967 tunnel->reclaim_available_bandwidth =
1971 tb_tunnel_dbg(tunnel, "discovered\n");
1972 return tunnel;
1975 tb_tunnel_deactivate(tunnel);
1977 tb_tunnel_free(tunnel);
1983 * tb_tunnel_alloc_usb3() - allocate a USB3 tunnel
1987 * @max_up: Maximum available upstream bandwidth for the USB3 tunnel (%0
1989 * @max_down: Maximum available downstream bandwidth for the USB3 tunnel
1992 * Allocate an USB3 tunnel. The ports must be of type @TB_TYPE_USB3_UP and
2001 struct tb_tunnel *tunnel;
2007 * USB3 tunnel.
2016 tb_port_dbg(up, "required bandwidth for USB3 tunnel %d Mb/s\n",
2020 tb_port_warn(up, "not enough bandwidth for USB3 tunnel\n");
2025 tunnel = tb_tunnel_alloc(tb, 2, TB_TUNNEL_USB3);
2026 if (!tunnel)
2029 tunnel->activate = tb_usb3_activate;
2030 tunnel->src_port = down;
2031 tunnel->dst_port = up;
2032 tunnel->max_up = max_up;
2033 tunnel->max_down = max_down;
2038 tb_tunnel_free(tunnel);
2042 tunnel->paths[TB_USB3_PATH_DOWN] = path;
2047 tb_tunnel_free(tunnel);
2051 tunnel->paths[TB_USB3_PATH_UP] = path;
2054 tunnel->allocated_up = max_rate;
2055 tunnel->allocated_down = max_rate;
2057 tunnel->init = tb_usb3_init;
2058 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth;
2059 tunnel->release_unused_bandwidth =
2061 tunnel->reclaim_available_bandwidth =
2065 return tunnel;
2069 * tb_tunnel_free() - free a tunnel
2070 * @tunnel: Tunnel to be freed
2072 * Frees a tunnel. The tunnel does not need to be deactivated.
2074 void tb_tunnel_free(struct tb_tunnel *tunnel)
2078 if (!tunnel)
2081 if (tunnel->deinit)
2082 tunnel->deinit(tunnel);
2084 for (i = 0; i < tunnel->npaths; i++) {
2085 if (tunnel->paths[i])
2086 tb_path_free(tunnel->paths[i]);
2089 kfree(tunnel->paths);
2090 kfree(tunnel);
2095 * @tunnel: Tunnel to check
2097 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel)
2101 for (i = 0; i < tunnel->npaths; i++) {
2102 WARN_ON(!tunnel->paths[i]->activated);
2103 if (tb_path_is_invalid(tunnel->paths[i]))
2111 * tb_tunnel_restart() - activate a tunnel after a hardware reset
2112 * @tunnel: Tunnel to restart
2116 int tb_tunnel_restart(struct tb_tunnel *tunnel)
2120 tb_tunnel_dbg(tunnel, "activating\n");
2126 for (i = 0; i < tunnel->npaths; i++) {
2127 if (tunnel->paths[i]->activated) {
2128 tb_path_deactivate(tunnel->paths[i]);
2129 tunnel->paths[i]->activated = false;
2133 if (tunnel->init) {
2134 res = tunnel->init(tunnel);
2139 for (i = 0; i < tunnel->npaths; i++) {
2140 res = tb_path_activate(tunnel->paths[i]);
2145 if (tunnel->activate) {
2146 res = tunnel->activate(tunnel, true);
2154 tb_tunnel_warn(tunnel, "activation failed\n");
2155 tb_tunnel_deactivate(tunnel);
2160 * tb_tunnel_activate() - activate a tunnel
2161 * @tunnel: Tunnel to activate
2165 int tb_tunnel_activate(struct tb_tunnel *tunnel)
2169 for (i = 0; i < tunnel->npaths; i++) {
2170 if (tunnel->paths[i]->activated) {
2171 tb_tunnel_WARN(tunnel,
2172 "trying to activate an already activated tunnel\n");
2177 return tb_tunnel_restart(tunnel);
2181 * tb_tunnel_deactivate() - deactivate a tunnel
2182 * @tunnel: Tunnel to deactivate
2184 void tb_tunnel_deactivate(struct tb_tunnel *tunnel)
2188 tb_tunnel_dbg(tunnel, "deactivating\n");
2190 if (tunnel->activate)
2191 tunnel->activate(tunnel, false);
2193 for (i = 0; i < tunnel->npaths; i++) {
2194 if (tunnel->paths[i] && tunnel->paths[i]->activated)
2195 tb_path_deactivate(tunnel->paths[i]);
2200 * tb_tunnel_port_on_path() - Does the tunnel go through port
2201 * @tunnel: Tunnel to check
2204 * Returns true if @tunnel goes through @port (direction does not matter),
2207 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
2212 for (i = 0; i < tunnel->npaths; i++) {
2213 if (!tunnel->paths[i])
2216 if (tb_path_port_on_path(tunnel->paths[i], port))
2223 static bool tb_tunnel_is_active(const struct tb_tunnel *tunnel)
2227 for (i = 0; i < tunnel->npaths; i++) {
2228 if (!tunnel->paths[i])
2230 if (!tunnel->paths[i]->activated)
2239 * @tunnel: Tunnel to check
2243 * Returns maximum possible bandwidth this tunnel can go if not limited
2244 * by other bandwidth clients. If the tunnel does not support this
2247 int tb_tunnel_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
2250 if (!tb_tunnel_is_active(tunnel))
2253 if (tunnel->maximum_bandwidth)
2254 return tunnel->maximum_bandwidth(tunnel, max_up, max_down);
2259 * tb_tunnel_allocated_bandwidth() - Return bandwidth allocated for the tunnel
2260 * @tunnel: Tunnel to check
2265 * Returns the bandwidth allocated for the tunnel. This may be higher
2266 * than what the tunnel actually consumes.
2268 int tb_tunnel_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up,
2271 if (!tb_tunnel_is_active(tunnel))
2274 if (tunnel->allocated_bandwidth)
2275 return tunnel->allocated_bandwidth(tunnel, allocated_up,
2281 * tb_tunnel_alloc_bandwidth() - Change tunnel bandwidth allocation
2282 * @tunnel: Tunnel whose bandwidth allocation to change
2286 * Tries to change tunnel bandwidth allocation. If succeeds returns %0
2291 int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
2294 if (!tb_tunnel_is_active(tunnel))
2297 if (tunnel->alloc_bandwidth)
2298 return tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down);
2304 * tb_tunnel_consumed_bandwidth() - Return bandwidth consumed by the tunnel
2305 * @tunnel: Tunnel to check
2311 * Stores the amount of isochronous bandwidth @tunnel consumes in
2315 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
2320 if (!tb_tunnel_is_active(tunnel))
2323 if (tunnel->consumed_bandwidth) {
2326 ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw);
2330 tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw,
2345 * @tunnel: Tunnel whose unused bandwidth to release
2347 * If tunnel supports dynamic bandwidth management (USB3 tunnels at the
2352 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel)
2354 if (!tb_tunnel_is_active(tunnel))
2357 if (tunnel->release_unused_bandwidth) {
2360 ret = tunnel->release_unused_bandwidth(tunnel);
2370 * @tunnel: Tunnel reclaiming available bandwidth
2376 * reclaimed by the tunnel). If nothing was reclaimed the values are
2379 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
2383 if (!tb_tunnel_is_active(tunnel))
2386 if (tunnel->reclaim_available_bandwidth)
2387 tunnel->reclaim_available_bandwidth(tunnel, available_up,