Lines Matching +full:switch +full:- +full:mode
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
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
99 * @mode_request: TMU mode requested to set. Related to upstream router.
105 enum tb_switch_tmu_mode mode; member
110 * struct tb_switch - a thunderbolt switch
111 * @dev: Device for the switch
112 * @config: Switch configuration
113 * @ports: Ports in this switch
114 * @dma_port: If the switch has port supporting DMA configuration based
116 * otherwise). If set it also means the switch has
118 * @tmu: The switch TMU configuration
119 * @tb: Pointer to the domain the switch belongs to
120 * @uid: Unique ID of the switch
121 * @uuid: UUID of the switch (or %NULL if not supported)
122 * @vendor: Vendor ID of the switch
123 * @device: Device ID of the switch
129 * @generation: Switch Thunderbolt generation
134 * @is_unplugged: The switch is going away
135 * @drom: DROM of the switch (%NULL if not found)
136 * @nvm: Pointer to the NVM if the switch has one (%NULL otherwise)
137 * @no_nvm_upgrade: Prevent NVM upgrade of this switch
138 * @safe_mode: The switch is in safe-mode
139 * @boot: Whether the switch was already authorized on boot or not
140 * @rpm: The switch supports runtime PM
141 * @authorized: Whether the switch is authorized by user or policy
142 * @security_level: Switch supported security level
148 * @link: Root switch link this switch is connected (ICM only)
149 * @depth: Depth in the chain this switch is connected (ICM only)
152 * @quirks: Quirks used for this Thunderbolt switch
161 * When the switch is being added or removed to the domain (other
219 * struct tb_bandwidth_group - Bandwidth management group
221 * @index: Index of the group (aka Group_ID). Valid values %1-%7
236 * struct tb_port - a thunderbolt port, part of a tb_switch
238 * @sw: Switch the port belongs to
246 * @port: Port number on switch
249 * @dual_link_port: If the switch is connected using two ports, points
263 * non-zero.
295 * struct usb4_port - USB4 port device
299 * it into offline mode and back
300 * @offline: The port is currently in offline mode
338 * struct tb_path_hop - routing information for a tb_path
339 * @in_port: Ingress port of a switch
340 * @out_port: Egress port of a switch where the packet is routed out
341 * (must be on the same switch than @in_port)
345 * currently, %-1 to disable)
349 * @nfc_credits: Number of non-flow controlled buffers allocated for the
352 * Hop configuration is always done on the IN port of a switch.
353 * in_port and out_port have to be on the same switch. Packets arriving on
355 * next hop to take (on out_port->remote) is determined by
356 * next_hop_index. When routing packet to another switch (out->remote is
374 * enum tb_path_port - path options mask
390 * struct tb_path - a unidirectional path between two ports
429 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
451 * struct tb_cm_ops - Connection manager specific operations vector
464 * @runtime_suspend_switch: Runtime suspend a switch
465 * @runtime_resume_switch: Runtime resume a switch
469 * @disapprove_switch: Disapprove switch (disconnect PCIe tunnel)
470 * @approve_switch: Approve switch
471 * @add_switch_key: Add key to switch
472 * @challenge_switch_key: Challenge switch using key
478 * performed. If this returns %-EOPNOTSUPP then the
524 return (void *)tb->privdata; in tb_priv()
532 * tb_upstream_port() - return the upstream port of a switch
534 * Every switch has an upstream port (for the root switch it is the NHI).
536 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
539 * Return: Returns the upstream port of the switch.
543 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
547 * tb_is_upstream_port() - Is the port upstream facing
555 const struct tb_port *upstream_port = tb_upstream_port(port->sw); in tb_is_upstream_port()
556 return port == upstream_port || port->dual_link_port == upstream_port; in tb_is_upstream_port()
561 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
568 port = route >> (sw->config.depth * 8); in tb_port_at()
569 if (WARN_ON(port > sw->config.max_port_number)) in tb_port_at()
571 return &sw->ports[port]; in tb_port_at()
575 * tb_port_has_remote() - Does the port have switch connected downstream
584 if (!port->remote) in tb_port_has_remote()
586 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
594 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
599 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
604 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
609 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
614 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
619 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
624 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
629 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
635 if (sw->is_unplugged) in tb_sw_read()
636 return -ENODEV; in tb_sw_read()
637 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
649 if (sw->is_unplugged) in tb_sw_write()
650 return -ENODEV; in tb_sw_write()
651 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
663 if (port->sw->is_unplugged) in tb_port_read()
664 return -ENODEV; in tb_port_read()
665 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
667 tb_route(port->sw), in tb_port_read()
668 port->port, in tb_port_read()
677 if (port->sw->is_unplugged) in tb_port_write()
678 return -ENODEV; in tb_port_write()
679 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
681 tb_route(port->sw), in tb_port_write()
682 port->port, in tb_port_write()
688 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
689 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
690 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
691 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
692 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
697 level(__sw->tb, "%llx: " fmt, \
708 level(__port->sw->tb, "%llx:%u: " fmt, \
709 tb_route(__port->sw), __port->port, ## arg); \
760 get_device(&tb->dev); in tb_domain_get()
766 put_device(&tb->dev); in tb_domain_put()
814 * tb_switch_for_each_port() - Iterate over each switch port
815 * @sw: Switch whose ports to iterate
818 * Iterates over each switch port skipping the control port (port %0).
821 for ((p) = &(sw)->ports[1]; \
822 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
827 get_device(&sw->dev); in tb_switch_get()
833 put_device(&sw->dev); in tb_switch_put()
838 return dev->type == &tb_switch_type; in tb_is_switch()
850 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
854 * tb_switch_downstream_port() - Return downstream facing port of parent router
869 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
870 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
875 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
876 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
881 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
882 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
893 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
894 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
905 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
906 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
920 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
921 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
933 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
934 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
946 * tb_switch_is_icm() - Is the switch handled by ICM firmware
947 * @sw: Switch to check
956 return !sw->config.enabled; in tb_switch_is_icm()
972 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
975 * tb_switch_tmu_is_configured() - Is given TMU mode configured
976 * @sw: Router whose mode to check
977 * @mode: Mode to check
979 * Checks if given router TMU mode is configured to @mode. Note the
980 * router TMU might not be enabled to this mode.
983 enum tb_switch_tmu_mode mode) in tb_switch_tmu_is_configured() argument
985 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
989 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
990 * @sw: Router whose TMU mode to check
997 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
998 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1009 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1021 return sw->clx & clx; in tb_switch_clx_is_enabled()
1045 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1049 * tb_for_each_port_on_path() - Iterate over each port on path
1104 * tb_path_for_each_hop() - Iterate over each hop on path
1111 for ((hop) = &(path)->hops[0]; \
1112 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1138 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1142 * tb_downstream_route() - get route to downstream switch
1146 * Return: Returns a route to the switch behind @port.
1150 return tb_route(port->sw) in tb_downstream_route()
1151 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1167 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1171 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1178 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1188 return dev->type == &tb_retimer_type; in tb_is_retimer()
1199 * usb4_switch_version() - Returns USB4 version of the router
1203 * on). Can be called to pre-USB4 router too and in that case returns %0.
1207 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1211 * tb_switch_is_usb4() - Is the switch USB4 compliant
1212 * @sw: Switch to check
1314 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1330 return usb4->offline; in usb4_port_device_is_offline()