Lines Matching +full:dma +full:- +full:router
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
12 #include <linux/nvmem-provider.h>
28 * struct tb_nvm - Structure holding NVM information
35 * @non_active: Non-active portion NVMem device
44 * @vops: Router vendor specific NVM operations (optional)
76 * enum tb_switch_tmu_mode - TMU mode
78 * @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
79 * @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
80 * @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
81 * @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
94 * struct tb_switch_tmu - Structure holding router TMU configuration
96 * @has_ucap: Does the switch support uni-directional mode
97 * @mode: TMU mode related to the upstream router. Reflects the HW
98 * setting. Don't care for host router.
99 * @mode_request: TMU mode requested to set. Related to upstream router.
100 * Don't care for host router.
110 * struct tb_switch - a thunderbolt switch
114 * @dma_port: If the switch has port supporting DMA configuration based
128 * @preferred_link_width: Router preferred link width (only set for Gen 4 links)
139 * @safe_mode: The switch is in safe-mode
155 * @max_usb3_credits: Router preferred number of buffers for USB 3.x
156 * @min_dp_aux_credits: Router preferred minimum number of buffers for DP AUX
157 * @min_dp_main_credits: Router preferred minimum number of buffers for DP MAIN
158 * @max_pcie_credits: Router preferred number of buffers for PCIe
159 * @max_dma_credits: Router preferred number of buffers for DMA/P2P
160 * @clx: CLx states on the upstream link of the router
165 * In USB4 terminology this structure represents a router.
216 * struct tb_bandwidth_group - Bandwidth management group
218 * @index: Index of the group (aka Group_ID). Valid values %1-%7
233 * struct tb_port - a thunderbolt port, part of a tb_switch
254 * @dma_credits: Number of credits allocated for DMA tunneling for all
255 * DMA paths through this port.
260 * non-zero.
292 * struct usb4_port - USB4 port device
314 * @index: Retimer index facing the router USB4 port
335 * struct tb_path_hop - routing information for a tb_path
342 * currently, %-1 to disable)
346 * @nfc_credits: Number of non-flow controlled buffers allocated for the
353 * next hop to take (on out_port->remote) is determined by
354 * next_hop_index. When routing packet to another switch (out->remote is
373 * enum tb_path_port - path options mask
389 * struct tb_path - a unidirectional path between two ports
428 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
431 * Support paths from the farthest (depth 6) router to the host and back
432 * to the same level (not necessarily to the same router).
450 * struct tb_cm_ops - Connection manager specific operations vector
473 * @approve_xdomain_paths: Approve (establish) XDomain DMA paths
474 * @disconnect_xdomain_paths: Disconnect XDomain DMA paths
475 * @usb4_switch_op: Optional proxy for USB4 router operations. If set
476 * this will be called whenever USB4 router operation is
477 * performed. If this returns %-EOPNOTSUPP then the
478 * native USB4 router operation is called.
482 * router operation.
523 return (void *)tb->privdata; in tb_priv()
531 * tb_upstream_port() - return the upstream port of a switch
535 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
542 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
546 * tb_is_upstream_port() - Is the port upstream facing
554 const struct tb_port *upstream_port = tb_upstream_port(port->sw); in tb_is_upstream_port()
555 return port == upstream_port || port->dual_link_port == upstream_port; in tb_is_upstream_port()
560 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
567 port = route >> (sw->config.depth * 8); in tb_port_at()
568 if (WARN_ON(port > sw->config.max_port_number)) in tb_port_at()
570 return &sw->ports[port]; in tb_port_at()
590 * tb_port_has_remote() - Does the port have switch connected downstream
599 if (!port->remote) in tb_port_has_remote()
601 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
609 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
614 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
619 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
624 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
629 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
634 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
639 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
644 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
650 if (sw->is_unplugged) in tb_sw_read()
651 return -ENODEV; in tb_sw_read()
652 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
664 if (sw->is_unplugged) in tb_sw_write()
665 return -ENODEV; in tb_sw_write()
666 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
678 if (port->sw->is_unplugged) in tb_port_read()
679 return -ENODEV; in tb_port_read()
680 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
682 tb_route(port->sw), in tb_port_read()
683 port->port, in tb_port_read()
692 if (port->sw->is_unplugged) in tb_port_write()
693 return -ENODEV; in tb_port_write()
694 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
696 tb_route(port->sw), in tb_port_write()
697 port->port, in tb_port_write()
703 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
704 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
705 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
706 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
707 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
712 level(__sw->tb, "%llx: " fmt, \
723 level(__port->sw->tb, "%llx:%u: " fmt, \
724 tb_route(__port->sw), __port->port, ## arg); \
775 get_device(&tb->dev); in tb_domain_get()
781 put_device(&tb->dev); in tb_domain_put()
829 * tb_switch_for_each_port() - Iterate over each switch port
836 for ((p) = &(sw)->ports[1]; \
837 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
842 get_device(&sw->dev); in tb_switch_get()
848 put_device(&sw->dev); in tb_switch_put()
853 return dev->type == &tb_switch_type; in tb_is_switch()
865 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
869 * tb_switch_downstream_port() - Return downstream facing port of parent router
870 * @sw: Device router pointer
873 * the parent router.
883 * tb_switch_depth() - Returns depth of the connected router
884 * @sw: Router
888 return sw->config.depth; in tb_switch_depth()
893 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
894 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
899 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
900 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
905 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
906 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
917 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
918 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
929 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
930 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
944 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
945 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
957 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
958 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
970 * tb_switch_is_icm() - Is the switch handled by ICM firmware
980 return !sw->config.enabled; in tb_switch_is_icm()
998 * tb_switch_tmu_is_configured() - Is given TMU mode configured
999 * @sw: Router whose mode to check
1002 * Checks if given router TMU mode is configured to @mode. Note the
1003 * router TMU might not be enabled to this mode.
1008 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
1012 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
1013 * @sw: Router whose TMU mode to check
1020 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
1021 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1031 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1032 * @sw: Router to check for the CLx
1035 * Checks if the specified CLx is enabled on the router upstream link.
1038 * Not applicable for a host router.
1043 return sw->clx & clx; in tb_switch_clx_is_enabled()
1066 * tb_port_path_direction_downstream() - Checks if path directed downstream
1077 return src->sw->config.depth < dst->sw->config.depth; in tb_port_path_direction_downstream()
1082 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1086 * tb_for_each_port_on_path() - Iterate over each port on path
1098 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1158 * tb_path_for_each_hop() - Iterate over each hop on path
1165 for ((hop) = &(path)->hops[0]; \
1166 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1192 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1196 * tb_downstream_route() - get route to downstream switch
1204 return tb_route(port->sw) in tb_downstream_route()
1205 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1221 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1225 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1232 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1242 return dev->type == &tb_retimer_type; in tb_is_retimer()
1253 * usb4_switch_version() - Returns USB4 version of the router
1254 * @sw: Router to check
1256 * Returns major version of USB4 router (%1 for v1, %2 for v2 and so
1257 * on). Can be called to pre-USB4 router too and in that case returns %0.
1261 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1265 * tb_switch_is_usb4() - Is the switch USB4 compliant
1268 * Returns true if the @sw is USB4 compliant router, false otherwise.
1372 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1388 return usb4->offline; in usb4_port_device_is_offline()