Lines Matching +full:activate +full:- +full:to +full:- +full:activate

1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt driver - Tunneling support
54 * Number of credits we try to allocate for each DMA path if not limited
66 * according to USB4 v2 Connection Manager guide. This ends up reserving
87 return port->total_credits - port->ctl_credits; in tb_usable_credits()
91 * tb_available_credits() - Available credits for PCIe and DMA
92 * @port: Lane adapter to check
93 * @max_dp_streams: If non-%NULL stores maximum number of simultaneous DP
99 const struct tb_switch *sw = port->sw; in tb_available_credits()
103 usb3 = tb_acpi_may_tunnel_usb3() ? sw->max_usb3_credits : 0; in tb_available_credits()
104 pcie = tb_acpi_may_tunnel_pcie() ? sw->max_pcie_credits : 0; in tb_available_credits()
107 spare = min_not_zero(sw->max_dma_credits, dma_credits); in tb_available_credits()
120 if (sw->min_dp_aux_credits + sw->min_dp_main_credits) in tb_available_credits()
121 ndp = (credits - (usb3 + pcie + spare)) / in tb_available_credits()
122 (sw->min_dp_aux_credits + sw->min_dp_main_credits); in tb_available_credits()
128 credits -= ndp * (sw->min_dp_aux_credits + sw->min_dp_main_credits); in tb_available_credits()
129 credits -= usb3; in tb_available_credits()
139 struct tb_port *out_port = hop->out_port; in tb_init_pm_support()
140 struct tb_port *in_port = hop->in_port; in tb_init_pm_support()
143 usb4_switch_version(in_port->sw) >= 2) in tb_init_pm_support()
144 hop->pm_support = true; in tb_init_pm_support()
156 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); in tb_tunnel_alloc()
157 if (!tunnel->paths) { in tb_tunnel_alloc()
162 INIT_LIST_HEAD(&tunnel->list); in tb_tunnel_alloc()
163 tunnel->tb = tb; in tb_tunnel_alloc()
164 tunnel->npaths = npaths; in tb_tunnel_alloc()
165 tunnel->type = type; in tb_tunnel_alloc()
172 struct tb_port *port = tb_upstream_port(tunnel->dst_port->sw); in tb_pci_set_ext_encapsulation()
176 if ((usb4_switch_version(tunnel->src_port->sw) < 2) || in tb_pci_set_ext_encapsulation()
177 (usb4_switch_version(tunnel->dst_port->sw) < 2)) in tb_pci_set_ext_encapsulation()
183 ret = usb4_pci_port_set_ext_encapsulation(tunnel->src_port, enable); in tb_pci_set_ext_encapsulation()
191 ret = usb4_pci_port_set_ext_encapsulation(tunnel->dst_port, enable); in tb_pci_set_ext_encapsulation()
195 if (ret != -ENODEV) in tb_pci_set_ext_encapsulation()
204 static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate) in tb_pci_activate() argument
208 if (activate) { in tb_pci_activate()
209 res = tb_pci_set_ext_encapsulation(tunnel, activate); in tb_pci_activate()
214 if (activate) in tb_pci_activate()
215 res = tb_pci_port_enable(tunnel->dst_port, activate); in tb_pci_activate()
217 res = tb_pci_port_enable(tunnel->src_port, activate); in tb_pci_activate()
222 if (activate) { in tb_pci_activate()
223 res = tb_pci_port_enable(tunnel->src_port, activate); in tb_pci_activate()
228 tb_pci_port_enable(tunnel->dst_port, activate); in tb_pci_activate()
231 return activate ? 0 : tb_pci_set_ext_encapsulation(tunnel, activate); in tb_pci_activate()
236 struct tb_port *port = hop->in_port; in tb_pci_init_credits()
237 struct tb_switch *sw = port->sw; in tb_pci_init_credits()
244 credits = min(sw->max_pcie_credits, available); in tb_pci_init_credits()
247 return -ENOSPC; in tb_pci_init_credits()
252 credits = port->bonded ? 32 : 16; in tb_pci_init_credits()
257 hop->initial_credits = credits; in tb_pci_init_credits()
265 path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL; in tb_pci_init_path()
266 path->egress_shared_buffer = TB_PATH_NONE; in tb_pci_init_path()
267 path->ingress_fc_enable = TB_PATH_ALL; in tb_pci_init_path()
268 path->ingress_shared_buffer = TB_PATH_NONE; in tb_pci_init_path()
269 path->priority = TB_PCI_PRIORITY; in tb_pci_init_path()
270 path->weight = TB_PCI_WEIGHT; in tb_pci_init_path()
271 path->drop_packages = 0; in tb_pci_init_path()
285 * tb_tunnel_discover_pci() - Discover existing PCIe tunnels
286 * @tb: Pointer to the domain structure
290 * If @down adapter is active, follows the tunnel to the PCIe upstream
307 tunnel->activate = tb_pci_activate; in tb_tunnel_discover_pci()
308 tunnel->src_port = down; in tb_tunnel_discover_pci()
315 path = tb_path_discover(down, TB_PCI_HOPID, NULL, -1, in tb_tunnel_discover_pci()
316 &tunnel->dst_port, "PCIe Up", alloc_hopid); in tb_tunnel_discover_pci()
322 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_discover_pci()
323 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_UP])) in tb_tunnel_discover_pci()
326 path = tb_path_discover(tunnel->dst_port, -1, down, TB_PCI_HOPID, NULL, in tb_tunnel_discover_pci()
330 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_discover_pci()
331 if (tb_pci_init_path(tunnel->paths[TB_PCI_PATH_DOWN])) in tb_tunnel_discover_pci()
335 if (!tb_port_is_pcie_up(tunnel->dst_port)) { in tb_tunnel_discover_pci()
336 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_pci()
341 if (down != tunnel->src_port) { in tb_tunnel_discover_pci()
346 if (!tb_pci_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_pci()
364 * tb_tunnel_alloc_pci() - allocate a pci tunnel
365 * @tb: Pointer to the domain structure
384 tunnel->activate = tb_pci_activate; in tb_tunnel_alloc_pci()
385 tunnel->src_port = down; in tb_tunnel_alloc_pci()
386 tunnel->dst_port = up; in tb_tunnel_alloc_pci()
392 tunnel->paths[TB_PCI_PATH_DOWN] = path; in tb_tunnel_alloc_pci()
400 tunnel->paths[TB_PCI_PATH_UP] = path; in tb_tunnel_alloc_pci()
412 * tb_tunnel_reserved_pci() - Amount of bandwidth to reserve for PCIe
414 * @reserved_up: Upstream bandwidth in Mb/s to reserve
415 * @reserved_down: Downstream bandwidth in Mb/s to reserve
417 * Can be called to any connected lane 0 adapter to find out how much
418 * bandwidth needs to be left in reserve for possible PCIe bulk traffic.
419 * Returns true if there is something to be reserved and writes the
420 * amount to @reserved_down/@reserved_up. Otherwise returns false and
426 if (WARN_ON_ONCE(!port->remote)) in tb_tunnel_reserved_pci()
437 if (!tb_switch_find_port(port->sw, TB_TYPE_PCIE_UP)) in tb_tunnel_reserved_pci()
439 if (!tb_switch_find_port(port->remote->sw, TB_TYPE_PCIE_DOWN)) in tb_tunnel_reserved_pci()
442 if (!tb_switch_find_port(port->sw, TB_TYPE_PCIE_DOWN)) in tb_tunnel_reserved_pci()
444 if (!tb_switch_find_port(port->remote->sw, TB_TYPE_PCIE_UP)) in tb_tunnel_reserved_pci()
469 /* Both ends need to support this */ in tb_dp_cm_handshake()
470 if (!tb_dp_is_usb4(in->sw) || !tb_dp_is_usb4(out->sw)) in tb_dp_cm_handshake()
474 out->cap_adap + DP_STATUS_CTRL, 1); in tb_dp_cm_handshake()
481 out->cap_adap + DP_STATUS_CTRL, 1); in tb_dp_cm_handshake()
487 out->cap_adap + DP_STATUS_CTRL, 1); in tb_dp_cm_handshake()
495 return -ETIMEDOUT; in tb_dp_cm_handshake()
547 WARN(1, "invalid rate %u passed, defaulting to 1620 MB/s\n", rate); in tb_dp_cap_set_rate()
586 WARN(1, "invalid number of lanes %u passed, defaulting to 1\n", in tb_dp_cap_set_lanes()
650 return -ENOSR; in tb_dp_reduce_bandwidth()
656 struct tb_port *out = tunnel->dst_port; in tb_dp_xchg_caps()
657 struct tb_port *in = tunnel->src_port; in tb_dp_xchg_caps()
661 * Copy DP_LOCAL_CAP register to DP_REMOTE_CAP register for in tb_dp_xchg_caps()
664 if (in->sw->generation < 2 || out->sw->generation < 2) in tb_dp_xchg_caps()
677 in->cap_adap + DP_LOCAL_CAP, 1); in tb_dp_xchg_caps()
682 out->cap_adap + DP_LOCAL_CAP, 1); in tb_dp_xchg_caps()
686 /* Write IN local caps to OUT remote caps */ in tb_dp_xchg_caps()
688 out->cap_adap + DP_REMOTE_CAP, 1); in tb_dp_xchg_caps()
700 * if we need to reduce bandwidth to fit there. in tb_dp_xchg_caps()
710 max_bw = tunnel->max_down; in tb_dp_xchg_caps()
712 max_bw = tunnel->max_up; in tb_dp_xchg_caps()
727 "bandwidth reduced to %u Mb/s x%u = %u Mb/s\n", in tb_dp_xchg_caps()
731 * Set new rate and number of lanes before writing it to in tb_dp_xchg_caps()
743 if (tb_route(out->sw) && tb_switch_is_titan_ridge(out->sw)) { in tb_dp_xchg_caps()
749 in->cap_adap + DP_REMOTE_CAP, 1); in tb_dp_xchg_caps()
755 struct tb_port *out = tunnel->dst_port; in tb_dp_bandwidth_alloc_mode_enable()
756 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_alloc_mode_enable()
768 ret = usb4_dp_port_set_group_id(in, in->group->index); in tb_dp_bandwidth_alloc_mode_enable()
773 * Get the non-reduced rate and lanes based on the lowest in tb_dp_bandwidth_alloc_mode_enable()
777 in->cap_adap + DP_LOCAL_CAP, 1); in tb_dp_bandwidth_alloc_mode_enable()
782 out->cap_adap + DP_LOCAL_CAP, 1); in tb_dp_bandwidth_alloc_mode_enable()
795 tb_tunnel_dbg(tunnel, "non-reduced bandwidth %u Mb/s x%u = %u Mb/s\n", in tb_dp_bandwidth_alloc_mode_enable()
822 * Returns -EINVAL if granularity above is outside of the in tb_dp_bandwidth_alloc_mode_enable()
832 * estimation was set to. in tb_dp_bandwidth_alloc_mode_enable()
835 estimated_bw = tunnel->max_down; in tb_dp_bandwidth_alloc_mode_enable()
837 estimated_bw = tunnel->max_up; in tb_dp_bandwidth_alloc_mode_enable()
856 struct tb_port *in = tunnel->src_port; in tb_dp_init()
857 struct tb_switch *sw = in->sw; in tb_dp_init()
858 struct tb *tb = in->sw->tb; in tb_dp_init()
873 ret = usb4_dp_port_set_cm_id(in, tb->index); in tb_dp_init()
882 struct tb_port *in = tunnel->src_port; in tb_dp_deinit()
900 paths = tunnel->paths; in tb_dp_activate()
901 last = paths[TB_DP_VIDEO_PATH_OUT]->path_length - 1; in tb_dp_activate()
903 tb_dp_port_set_hops(tunnel->src_port, in tb_dp_activate()
904 paths[TB_DP_VIDEO_PATH_OUT]->hops[0].in_hop_index, in tb_dp_activate()
905 paths[TB_DP_AUX_PATH_OUT]->hops[0].in_hop_index, in tb_dp_activate()
906 paths[TB_DP_AUX_PATH_IN]->hops[last].next_hop_index); in tb_dp_activate()
908 tb_dp_port_set_hops(tunnel->dst_port, in tb_dp_activate()
909 paths[TB_DP_VIDEO_PATH_OUT]->hops[last].next_hop_index, in tb_dp_activate()
910 paths[TB_DP_AUX_PATH_IN]->hops[0].in_hop_index, in tb_dp_activate()
911 paths[TB_DP_AUX_PATH_OUT]->hops[last].next_hop_index); in tb_dp_activate()
913 tb_dp_port_hpd_clear(tunnel->src_port); in tb_dp_activate()
914 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0); in tb_dp_activate()
915 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
916 tb_dp_port_set_hops(tunnel->dst_port, 0, 0, 0); in tb_dp_activate()
919 ret = tb_dp_port_enable(tunnel->src_port, active); in tb_dp_activate()
923 if (tb_port_is_dpout(tunnel->dst_port)) in tb_dp_activate()
924 return tb_dp_port_enable(tunnel->dst_port, active); in tb_dp_activate()
930 * tb_dp_bandwidth_mode_maximum_bandwidth() - Maximum possible bandwidth
931 * @tunnel: DP tunnel to check
932 * @max_bw_rounded: Maximum bandwidth in Mb/s rounded up to the next granularity
939 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_mode_maximum_bandwidth()
944 * DP IN adapter DP_LOCAL_CAP gets updated to the lowest AUX in tb_dp_bandwidth_mode_maximum_bandwidth()
945 * read parameter values so this so we can use this to determine in tb_dp_bandwidth_mode_maximum_bandwidth()
951 in->cap_adap + DP_LOCAL_CAP, 1); in tb_dp_bandwidth_mode_maximum_bandwidth()
974 struct tb_port *in = tunnel->src_port; in tb_dp_bandwidth_mode_consumed_bandwidth()
978 return -EOPNOTSUPP; in tb_dp_bandwidth_mode_consumed_bandwidth()
980 if (!tunnel->bw_mode) in tb_dp_bandwidth_mode_consumed_bandwidth()
981 return -EOPNOTSUPP; in tb_dp_bandwidth_mode_consumed_bandwidth()
1009 struct tb_port *in = tunnel->src_port; in tb_dp_allocated_bandwidth()
1015 if (usb4_dp_port_bandwidth_mode_enabled(in) && tunnel->bw_mode) { in tb_dp_allocated_bandwidth()
1040 return tunnel->consumed_bandwidth(tunnel, allocated_up, in tb_dp_allocated_bandwidth()
1047 struct tb_port *in = tunnel->src_port; in tb_dp_alloc_bandwidth()
1051 return -EOPNOTSUPP; in tb_dp_alloc_bandwidth()
1073 /* Now we can use BW mode registers to figure out the bandwidth */ in tb_dp_alloc_bandwidth()
1074 /* TODO: need to handle discovery too */ in tb_dp_alloc_bandwidth()
1075 tunnel->bw_mode = true; in tb_dp_alloc_bandwidth()
1082 struct tb_port *in = tunnel->src_port; in tb_dp_wait_dprx()
1093 in->cap_adap + DP_COMMON_CAP, 1); in tb_dp_wait_dprx()
1105 return -ETIMEDOUT; in tb_dp_wait_dprx()
1112 struct tb_port *in = tunnel->src_port; in tb_dp_read_cap()
1124 return -EINVAL; in tb_dp_read_cap()
1131 ret = tb_port_read(in, &val, TB_CFG_PORT, in->cap_adap + cap, 1); in tb_dp_read_cap()
1145 if (!usb4_dp_port_bandwidth_mode_enabled(tunnel->src_port)) in tb_dp_maximum_bandwidth()
1146 return -EOPNOTSUPP; in tb_dp_maximum_bandwidth()
1166 const struct tb_switch *sw = tunnel->src_port->sw; in tb_dp_consumed_bandwidth()
1179 if (ret != -EOPNOTSUPP) in tb_dp_consumed_bandwidth()
1187 * reduced one). According to VESA spec, the DPRX in tb_dp_consumed_bandwidth()
1197 } else if (sw->generation >= 2) { in tb_dp_consumed_bandwidth()
1221 struct tb_port *port = hop->in_port; in tb_dp_init_aux_credits()
1222 struct tb_switch *sw = port->sw; in tb_dp_init_aux_credits()
1225 hop->initial_credits = sw->min_dp_aux_credits; in tb_dp_init_aux_credits()
1227 hop->initial_credits = 1; in tb_dp_init_aux_credits()
1234 path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL; in tb_dp_init_aux_path()
1235 path->egress_shared_buffer = TB_PATH_NONE; in tb_dp_init_aux_path()
1236 path->ingress_fc_enable = TB_PATH_ALL; in tb_dp_init_aux_path()
1237 path->ingress_shared_buffer = TB_PATH_NONE; in tb_dp_init_aux_path()
1238 path->priority = TB_DP_AUX_PRIORITY; in tb_dp_init_aux_path()
1239 path->weight = TB_DP_AUX_WEIGHT; in tb_dp_init_aux_path()
1250 struct tb_port *port = hop->in_port; in tb_dp_init_video_credits()
1251 struct tb_switch *sw = port->sw; in tb_dp_init_video_credits()
1261 * tunneling we can use that to figure out how many DP in tb_dp_init_video_credits()
1264 nfc_credits = port->config.nfc_credits & in tb_dp_init_video_credits()
1266 if (nfc_credits / sw->min_dp_main_credits > max_dp_streams) in tb_dp_init_video_credits()
1267 return -ENOSPC; in tb_dp_init_video_credits()
1269 hop->nfc_credits = sw->min_dp_main_credits; in tb_dp_init_video_credits()
1271 hop->nfc_credits = min(port->total_credits - 2, 12U); in tb_dp_init_video_credits()
1281 path->egress_fc_enable = TB_PATH_NONE; in tb_dp_init_video_path()
1282 path->egress_shared_buffer = TB_PATH_NONE; in tb_dp_init_video_path()
1283 path->ingress_fc_enable = TB_PATH_NONE; in tb_dp_init_video_path()
1284 path->ingress_shared_buffer = TB_PATH_NONE; in tb_dp_init_video_path()
1285 path->priority = TB_DP_VIDEO_PRIORITY; in tb_dp_init_video_path()
1286 path->weight = TB_DP_VIDEO_WEIGHT; in tb_dp_init_video_path()
1306 in = tunnel->src_port; in tb_dp_dump()
1307 out = tunnel->dst_port; in tb_dp_dump()
1310 in->cap_adap + DP_LOCAL_CAP, 1)) in tb_dp_dump()
1321 out->cap_adap + DP_LOCAL_CAP, 1)) in tb_dp_dump()
1332 in->cap_adap + DP_REMOTE_CAP, 1)) in tb_dp_dump()
1343 * tb_tunnel_discover_dp() - Discover existing Display Port tunnels
1344 * @tb: Pointer to the domain structure
1348 * If @in adapter is active, follows the tunnel to the DP out adapter
1368 tunnel->init = tb_dp_init; in tb_tunnel_discover_dp()
1369 tunnel->deinit = tb_dp_deinit; in tb_tunnel_discover_dp()
1370 tunnel->activate = tb_dp_activate; in tb_tunnel_discover_dp()
1371 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; in tb_tunnel_discover_dp()
1372 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; in tb_tunnel_discover_dp()
1373 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; in tb_tunnel_discover_dp()
1374 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_discover_dp()
1375 tunnel->src_port = in; in tb_tunnel_discover_dp()
1377 path = tb_path_discover(in, TB_DP_VIDEO_HOPID, NULL, -1, in tb_tunnel_discover_dp()
1378 &tunnel->dst_port, "Video", alloc_hopid); in tb_tunnel_discover_dp()
1384 tunnel->paths[TB_DP_VIDEO_PATH_OUT] = path; in tb_tunnel_discover_dp()
1385 if (tb_dp_init_video_path(tunnel->paths[TB_DP_VIDEO_PATH_OUT], false)) in tb_tunnel_discover_dp()
1388 path = tb_path_discover(in, TB_DP_AUX_TX_HOPID, NULL, -1, NULL, "AUX TX", in tb_tunnel_discover_dp()
1392 tunnel->paths[TB_DP_AUX_PATH_OUT] = path; in tb_tunnel_discover_dp()
1393 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_OUT], false); in tb_tunnel_discover_dp()
1395 path = tb_path_discover(tunnel->dst_port, -1, in, TB_DP_AUX_RX_HOPID, in tb_tunnel_discover_dp()
1399 tunnel->paths[TB_DP_AUX_PATH_IN] = path; in tb_tunnel_discover_dp()
1400 tb_dp_init_aux_path(tunnel->paths[TB_DP_AUX_PATH_IN], false); in tb_tunnel_discover_dp()
1403 if (!tb_port_is_dpout(tunnel->dst_port)) { in tb_tunnel_discover_dp()
1408 if (!tb_dp_port_is_enabled(tunnel->dst_port)) in tb_tunnel_discover_dp()
1411 if (!tb_dp_port_hpd_is_active(tunnel->dst_port)) in tb_tunnel_discover_dp()
1414 if (port != tunnel->src_port) { in tb_tunnel_discover_dp()
1433 * tb_tunnel_alloc_dp() - allocate a Display Port tunnel
1434 * @tb: Pointer to the domain structure
1457 if (WARN_ON(!in->cap_adap || !out->cap_adap)) in tb_tunnel_alloc_dp()
1464 tunnel->init = tb_dp_init; in tb_tunnel_alloc_dp()
1465 tunnel->deinit = tb_dp_deinit; in tb_tunnel_alloc_dp()
1466 tunnel->activate = tb_dp_activate; in tb_tunnel_alloc_dp()
1467 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; in tb_tunnel_alloc_dp()
1468 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; in tb_tunnel_alloc_dp()
1469 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; in tb_tunnel_alloc_dp()
1470 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth; in tb_tunnel_alloc_dp()
1471 tunnel->src_port = in; in tb_tunnel_alloc_dp()
1472 tunnel->dst_port = out; in tb_tunnel_alloc_dp()
1473 tunnel->max_up = max_up; in tb_tunnel_alloc_dp()
1474 tunnel->max_down = max_down; in tb_tunnel_alloc_dp()
1476 paths = tunnel->paths; in tb_tunnel_alloc_dp()
1477 pm_support = usb4_switch_version(in->sw) >= 2; in tb_tunnel_alloc_dp()
1509 const struct tb_switch *sw = port->sw; in tb_dma_available_credits()
1514 credits -= sw->max_pcie_credits; in tb_dma_available_credits()
1515 credits -= port->dma_credits; in tb_dma_available_credits()
1522 struct tb_port *port = hop->in_port; in tb_dma_reserve_credits()
1528 * Need to have at least TB_MIN_DMA_CREDITS, otherwise in tb_dma_reserve_credits()
1532 return -ENOSPC; in tb_dma_reserve_credits()
1535 credits--; in tb_dma_reserve_credits()
1540 port->dma_credits += credits; in tb_dma_reserve_credits()
1543 credits = port->bonded ? 14 : 6; in tb_dma_reserve_credits()
1545 credits = min(port->total_credits, credits); in tb_dma_reserve_credits()
1548 hop->initial_credits = credits; in tb_dma_reserve_credits()
1552 /* Path from lane adapter to NHI */
1558 path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL; in tb_dma_init_rx_path()
1559 path->ingress_fc_enable = TB_PATH_ALL; in tb_dma_init_rx_path()
1560 path->egress_shared_buffer = TB_PATH_NONE; in tb_dma_init_rx_path()
1561 path->ingress_shared_buffer = TB_PATH_NONE; in tb_dma_init_rx_path()
1562 path->priority = TB_DMA_PRIORITY; in tb_dma_init_rx_path()
1563 path->weight = TB_DMA_WEIGHT; in tb_dma_init_rx_path()
1564 path->clear_fc = true; in tb_dma_init_rx_path()
1567 * First lane adapter is the one connected to the remote host. in tb_dma_init_rx_path()
1571 hop = &path->hops[0]; in tb_dma_init_rx_path()
1572 tmp = min(tb_usable_credits(hop->in_port), credits); in tb_dma_init_rx_path()
1573 hop->initial_credits = tmp; in tb_dma_init_rx_path()
1574 hop->in_port->dma_credits += tmp; in tb_dma_init_rx_path()
1576 for (i = 1; i < path->path_length; i++) { in tb_dma_init_rx_path()
1579 ret = tb_dma_reserve_credits(&path->hops[i], credits); in tb_dma_init_rx_path()
1587 /* Path from NHI to lane adapter */
1592 path->egress_fc_enable = TB_PATH_ALL; in tb_dma_init_tx_path()
1593 path->ingress_fc_enable = TB_PATH_ALL; in tb_dma_init_tx_path()
1594 path->egress_shared_buffer = TB_PATH_NONE; in tb_dma_init_tx_path()
1595 path->ingress_shared_buffer = TB_PATH_NONE; in tb_dma_init_tx_path()
1596 path->priority = TB_DMA_PRIORITY; in tb_dma_init_tx_path()
1597 path->weight = TB_DMA_WEIGHT; in tb_dma_init_tx_path()
1598 path->clear_fc = true; in tb_dma_init_tx_path()
1613 struct tb_port *port = hop->in_port; in tb_dma_release_credits()
1616 port->dma_credits -= hop->initial_credits; in tb_dma_release_credits()
1619 hop->initial_credits); in tb_dma_release_credits()
1635 for (i = 0; i < tunnel->npaths; i++) { in tb_dma_deinit()
1636 if (!tunnel->paths[i]) in tb_dma_deinit()
1638 tb_dma_deinit_path(tunnel->paths[i]); in tb_dma_deinit()
1643 * tb_tunnel_alloc_dma() - allocate a DMA tunnel
1644 * @tb: Pointer to the domain structure
1646 * @dst: Destination null port which the other domain is connected to
1648 * @transmit_ring: NHI ring number used to send packets towards the
1649 * other domain. Set to %-1 if TX path is not needed.
1651 * @receive_ring: NHI ring number used to receive packets from the
1652 * other domain. Set to %-1 if RX path is not needed.
1682 tunnel->src_port = nhi; in tb_tunnel_alloc_dma()
1683 tunnel->dst_port = dst; in tb_tunnel_alloc_dma()
1684 tunnel->deinit = tb_dma_deinit; in tb_tunnel_alloc_dma()
1686 credits = min_not_zero(dma_credits, nhi->sw->max_dma_credits); in tb_tunnel_alloc_dma()
1693 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1705 tunnel->paths[i++] = path; in tb_tunnel_alloc_dma()
1720 * tb_tunnel_match_dma() - Match DMA tunnel
1721 * @tunnel: Tunnel to match
1722 * @transmit_path: HopID used for transmitting packets. Pass %-1 to ignore.
1723 * @transmit_ring: NHI ring number used to send packets towards the
1724 * other domain. Pass %-1 to ignore.
1725 * @receive_path: HopID used for receiving packets. Pass %-1 to ignore.
1726 * @receive_ring: NHI ring number used to receive packets from the
1727 * other domain. Pass %-1 to ignore.
1729 * This function can be used to match specific DMA tunnel, if there are
1742 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_match_dma()
1743 const struct tb_path *path = tunnel->paths[i]; in tb_tunnel_match_dma()
1748 if (tb_port_is_nhi(path->hops[0].in_port)) in tb_tunnel_match_dma()
1750 else if (tb_port_is_nhi(path->hops[path->path_length - 1].out_port)) in tb_tunnel_match_dma()
1758 (tx_path->hops[0].in_hop_index != transmit_ring)) in tb_tunnel_match_dma()
1761 (tx_path->hops[tx_path->path_length - 1].next_hop_index != transmit_path)) in tb_tunnel_match_dma()
1769 (rx_path->hops[0].in_hop_index != receive_path)) in tb_tunnel_match_dma()
1772 (rx_path->hops[rx_path->path_length - 1].next_hop_index != receive_ring)) in tb_tunnel_match_dma()
1799 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_init()
1801 return usb4_usb3_port_allocate_bandwidth(tunnel->src_port, in tb_usb3_init()
1802 &tunnel->allocated_up, in tb_usb3_init()
1803 &tunnel->allocated_down); in tb_usb3_init()
1806 static int tb_usb3_activate(struct tb_tunnel *tunnel, bool activate) in tb_usb3_activate() argument
1810 res = tb_usb3_port_enable(tunnel->src_port, activate); in tb_usb3_activate()
1814 if (tb_port_is_usb3_up(tunnel->dst_port)) in tb_usb3_activate()
1815 return tb_usb3_port_enable(tunnel->dst_port, activate); in tb_usb3_activate()
1823 struct tb_port *port = tb_upstream_port(tunnel->dst_port->sw); in tb_usb3_consumed_bandwidth()
1830 *consumed_up = tunnel->allocated_up * in tb_usb3_consumed_bandwidth()
1832 *consumed_down = tunnel->allocated_down * in tb_usb3_consumed_bandwidth()
1847 ret = usb4_usb3_port_release_bandwidth(tunnel->src_port, in tb_usb3_release_unused_bandwidth()
1848 &tunnel->allocated_up, in tb_usb3_release_unused_bandwidth()
1849 &tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1853 tb_tunnel_dbg(tunnel, "decreased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_release_unused_bandwidth()
1854 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_release_unused_bandwidth()
1864 ret = tb_usb3_max_link_rate(tunnel->dst_port, tunnel->src_port); in tb_usb3_reclaim_available_bandwidth()
1866 tb_tunnel_warn(tunnel, "failed to read maximum link rate\n"); in tb_usb3_reclaim_available_bandwidth()
1876 /* No need to reclaim if already at maximum */ in tb_usb3_reclaim_available_bandwidth()
1877 if (tunnel->allocated_up >= max_rate && in tb_usb3_reclaim_available_bandwidth()
1878 tunnel->allocated_down >= max_rate) in tb_usb3_reclaim_available_bandwidth()
1883 if (allocate_up < tunnel->allocated_up) in tb_usb3_reclaim_available_bandwidth()
1884 allocate_up = tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1887 if (allocate_down < tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1888 allocate_down = tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1890 /* If no changes no need to do more */ in tb_usb3_reclaim_available_bandwidth()
1891 if (allocate_up == tunnel->allocated_up && in tb_usb3_reclaim_available_bandwidth()
1892 allocate_down == tunnel->allocated_down) in tb_usb3_reclaim_available_bandwidth()
1895 ret = usb4_usb3_port_allocate_bandwidth(tunnel->src_port, &allocate_up, in tb_usb3_reclaim_available_bandwidth()
1898 tb_tunnel_info(tunnel, "failed to allocate bandwidth\n"); in tb_usb3_reclaim_available_bandwidth()
1902 tunnel->allocated_up = allocate_up; in tb_usb3_reclaim_available_bandwidth()
1903 *available_up -= tunnel->allocated_up; in tb_usb3_reclaim_available_bandwidth()
1905 tunnel->allocated_down = allocate_down; in tb_usb3_reclaim_available_bandwidth()
1906 *available_down -= tunnel->allocated_down; in tb_usb3_reclaim_available_bandwidth()
1908 tb_tunnel_dbg(tunnel, "increased bandwidth allocation to %d/%d Mb/s\n", in tb_usb3_reclaim_available_bandwidth()
1909 tunnel->allocated_up, tunnel->allocated_down); in tb_usb3_reclaim_available_bandwidth()
1914 struct tb_port *port = hop->in_port; in tb_usb3_init_credits()
1915 struct tb_switch *sw = port->sw; in tb_usb3_init_credits()
1919 credits = sw->max_usb3_credits; in tb_usb3_init_credits()
1922 credits = port->bonded ? 32 : 16; in tb_usb3_init_credits()
1927 hop->initial_credits = credits; in tb_usb3_init_credits()
1934 path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL; in tb_usb3_init_path()
1935 path->egress_shared_buffer = TB_PATH_NONE; in tb_usb3_init_path()
1936 path->ingress_fc_enable = TB_PATH_ALL; in tb_usb3_init_path()
1937 path->ingress_shared_buffer = TB_PATH_NONE; in tb_usb3_init_path()
1938 path->priority = TB_USB3_PRIORITY; in tb_usb3_init_path()
1939 path->weight = TB_USB3_WEIGHT; in tb_usb3_init_path()
1940 path->drop_packages = 0; in tb_usb3_init_path()
1947 * tb_tunnel_discover_usb3() - Discover existing USB3 tunnels
1948 * @tb: Pointer to the domain structure
1952 * If @down adapter is active, follows the tunnel to the USB3 upstream
1969 tunnel->activate = tb_usb3_activate; in tb_tunnel_discover_usb3()
1970 tunnel->src_port = down; in tb_tunnel_discover_usb3()
1977 path = tb_path_discover(down, TB_USB3_HOPID, NULL, -1, in tb_tunnel_discover_usb3()
1978 &tunnel->dst_port, "USB3 Down", alloc_hopid); in tb_tunnel_discover_usb3()
1984 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_discover_usb3()
1985 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_DOWN]); in tb_tunnel_discover_usb3()
1987 path = tb_path_discover(tunnel->dst_port, -1, down, TB_USB3_HOPID, NULL, in tb_tunnel_discover_usb3()
1991 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_discover_usb3()
1992 tb_usb3_init_path(tunnel->paths[TB_USB3_PATH_UP]); in tb_tunnel_discover_usb3()
1995 if (!tb_port_is_usb3_up(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
1996 tb_port_warn(tunnel->dst_port, in tb_tunnel_discover_usb3()
2001 if (down != tunnel->src_port) { in tb_tunnel_discover_usb3()
2006 if (!tb_usb3_port_is_enabled(tunnel->dst_port)) { in tb_tunnel_discover_usb3()
2012 if (!tb_route(down->sw)) { in tb_tunnel_discover_usb3()
2020 &tunnel->allocated_up, &tunnel->allocated_down); in tb_tunnel_discover_usb3()
2025 tunnel->allocated_up, tunnel->allocated_down); in tb_tunnel_discover_usb3()
2027 tunnel->init = tb_usb3_init; in tb_tunnel_discover_usb3()
2028 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_discover_usb3()
2029 tunnel->release_unused_bandwidth = in tb_tunnel_discover_usb3()
2031 tunnel->reclaim_available_bandwidth = in tb_tunnel_discover_usb3()
2047 * tb_tunnel_alloc_usb3() - allocate a USB3 tunnel
2048 * @tb: Pointer to the domain structure
2069 if (!tb_route(down->sw) && (max_up > 0 || max_down > 0)) { in tb_tunnel_alloc_usb3()
2088 tunnel->activate = tb_usb3_activate; in tb_tunnel_alloc_usb3()
2089 tunnel->src_port = down; in tb_tunnel_alloc_usb3()
2090 tunnel->dst_port = up; in tb_tunnel_alloc_usb3()
2091 tunnel->max_up = max_up; in tb_tunnel_alloc_usb3()
2092 tunnel->max_down = max_down; in tb_tunnel_alloc_usb3()
2101 tunnel->paths[TB_USB3_PATH_DOWN] = path; in tb_tunnel_alloc_usb3()
2110 tunnel->paths[TB_USB3_PATH_UP] = path; in tb_tunnel_alloc_usb3()
2112 if (!tb_route(down->sw)) { in tb_tunnel_alloc_usb3()
2113 tunnel->allocated_up = min(max_rate, max_up); in tb_tunnel_alloc_usb3()
2114 tunnel->allocated_down = min(max_rate, max_down); in tb_tunnel_alloc_usb3()
2116 tunnel->init = tb_usb3_init; in tb_tunnel_alloc_usb3()
2117 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; in tb_tunnel_alloc_usb3()
2118 tunnel->release_unused_bandwidth = in tb_tunnel_alloc_usb3()
2120 tunnel->reclaim_available_bandwidth = in tb_tunnel_alloc_usb3()
2128 * tb_tunnel_free() - free a tunnel
2129 * @tunnel: Tunnel to be freed
2131 * Frees a tunnel. The tunnel does not need to be deactivated.
2140 if (tunnel->deinit) in tb_tunnel_free()
2141 tunnel->deinit(tunnel); in tb_tunnel_free()
2143 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_free()
2144 if (tunnel->paths[i]) in tb_tunnel_free()
2145 tb_path_free(tunnel->paths[i]); in tb_tunnel_free()
2148 kfree(tunnel->paths); in tb_tunnel_free()
2153 * tb_tunnel_is_invalid - check whether an activated path is still valid
2154 * @tunnel: Tunnel to check
2160 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_invalid()
2161 WARN_ON(!tunnel->paths[i]->activated); in tb_tunnel_is_invalid()
2162 if (tb_path_is_invalid(tunnel->paths[i])) in tb_tunnel_is_invalid()
2170 * tb_tunnel_restart() - activate a tunnel after a hardware reset
2171 * @tunnel: Tunnel to restart
2185 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
2186 if (tunnel->paths[i]->activated) { in tb_tunnel_restart()
2187 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_restart()
2188 tunnel->paths[i]->activated = false; in tb_tunnel_restart()
2192 if (tunnel->init) { in tb_tunnel_restart()
2193 res = tunnel->init(tunnel); in tb_tunnel_restart()
2198 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_restart()
2199 res = tb_path_activate(tunnel->paths[i]); in tb_tunnel_restart()
2204 if (tunnel->activate) { in tb_tunnel_restart()
2205 res = tunnel->activate(tunnel, true); in tb_tunnel_restart()
2219 * tb_tunnel_activate() - activate a tunnel
2220 * @tunnel: Tunnel to activate
2228 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_activate()
2229 if (tunnel->paths[i]->activated) { in tb_tunnel_activate()
2231 "trying to activate an already activated tunnel\n"); in tb_tunnel_activate()
2232 return -EINVAL; in tb_tunnel_activate()
2240 * tb_tunnel_deactivate() - deactivate a tunnel
2241 * @tunnel: Tunnel to deactivate
2249 if (tunnel->activate) in tb_tunnel_deactivate()
2250 tunnel->activate(tunnel, false); in tb_tunnel_deactivate()
2252 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_deactivate()
2253 if (tunnel->paths[i] && tunnel->paths[i]->activated) in tb_tunnel_deactivate()
2254 tb_path_deactivate(tunnel->paths[i]); in tb_tunnel_deactivate()
2259 * tb_tunnel_port_on_path() - Does the tunnel go through port
2260 * @tunnel: Tunnel to check
2261 * @port: Port to check
2271 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_port_on_path()
2272 if (!tunnel->paths[i]) in tb_tunnel_port_on_path()
2275 if (tb_path_port_on_path(tunnel->paths[i], port)) in tb_tunnel_port_on_path()
2286 for (i = 0; i < tunnel->npaths; i++) { in tb_tunnel_is_active()
2287 if (!tunnel->paths[i]) in tb_tunnel_is_active()
2289 if (!tunnel->paths[i]->activated) in tb_tunnel_is_active()
2297 * tb_tunnel_maximum_bandwidth() - Return maximum possible bandwidth
2298 * @tunnel: Tunnel to check
2304 * returns %-EOPNOTSUPP.
2310 return -EINVAL; in tb_tunnel_maximum_bandwidth()
2312 if (tunnel->maximum_bandwidth) in tb_tunnel_maximum_bandwidth()
2313 return tunnel->maximum_bandwidth(tunnel, max_up, max_down); in tb_tunnel_maximum_bandwidth()
2314 return -EOPNOTSUPP; in tb_tunnel_maximum_bandwidth()
2318 * tb_tunnel_allocated_bandwidth() - Return bandwidth allocated for the tunnel
2319 * @tunnel: Tunnel to check
2331 return -EINVAL; in tb_tunnel_allocated_bandwidth()
2333 if (tunnel->allocated_bandwidth) in tb_tunnel_allocated_bandwidth()
2334 return tunnel->allocated_bandwidth(tunnel, allocated_up, in tb_tunnel_allocated_bandwidth()
2336 return -EOPNOTSUPP; in tb_tunnel_allocated_bandwidth()
2340 * tb_tunnel_alloc_bandwidth() - Change tunnel bandwidth allocation
2341 * @tunnel: Tunnel whose bandwidth allocation to change
2345 * Tries to change tunnel bandwidth allocation. If succeeds returns %0
2346 * and updates @alloc_up and @alloc_down to that was actually allocated
2354 return -EINVAL; in tb_tunnel_alloc_bandwidth()
2356 if (tunnel->alloc_bandwidth) in tb_tunnel_alloc_bandwidth()
2357 return tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down); in tb_tunnel_alloc_bandwidth()
2359 return -EOPNOTSUPP; in tb_tunnel_alloc_bandwidth()
2363 * tb_tunnel_consumed_bandwidth() - Return bandwidth consumed by the tunnel
2364 * @tunnel: Tunnel to check
2365 * @consumed_up: Consumed bandwidth in Mb/s from @dst_port to @src_port.
2367 * @consumed_down: Consumed bandwidth in Mb/s from @src_port to @dst_port.
2382 if (tunnel->consumed_bandwidth) { in tb_tunnel_consumed_bandwidth()
2385 ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw); in tb_tunnel_consumed_bandwidth()
2403 * tb_tunnel_release_unused_bandwidth() - Release unused bandwidth
2404 * @tunnel: Tunnel whose unused bandwidth to release
2407 * moment) this function makes it to release all the unused bandwidth.
2416 if (tunnel->release_unused_bandwidth) { in tb_tunnel_release_unused_bandwidth()
2419 ret = tunnel->release_unused_bandwidth(tunnel); in tb_tunnel_release_unused_bandwidth()
2428 * tb_tunnel_reclaim_available_bandwidth() - Reclaim available bandwidth
2434 * the variables accordingly (e.g decreases both according to what was
2445 if (tunnel->reclaim_available_bandwidth) in tb_tunnel_reclaim_available_bandwidth()
2446 tunnel->reclaim_available_bandwidth(tunnel, available_up, in tb_tunnel_reclaim_available_bandwidth()
2452 return tb_tunnel_names[tunnel->type]; in tb_tunnel_type_name()