Lines Matching +full:switch +full:- +full:mode
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
13 #include <linux/nvmem-provider.h>
27 /* Need to keep power on while USB4 port is in redrive mode */
31 * struct tb_nvm - Structure holding NVM information
38 * @non_active: Non-active portion NVMem device
79 * enum tb_switch_tmu_mode - TMU mode
81 * @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
82 * @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
83 * @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
84 * @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
97 * struct tb_switch_tmu - Structure holding router TMU configuration
99 * @has_ucap: Does the switch support uni-directional mode
100 * @mode: TMU mode related to the upstream router. Reflects the HW
102 * @mode_request: TMU mode requested to set. Related to upstream router.
108 enum tb_switch_tmu_mode mode; member
113 * struct tb_switch - a thunderbolt switch
114 * @dev: Device for the switch
115 * @config: Switch configuration
116 * @ports: Ports in this switch
117 * @dma_port: If the switch has port supporting DMA configuration based
119 * otherwise). If set it also means the switch has
121 * @tmu: The switch TMU configuration
122 * @tb: Pointer to the domain the switch belongs to
123 * @uid: Unique ID of the switch
124 * @uuid: UUID of the switch (or %NULL if not supported)
125 * @vendor: Vendor ID of the switch
126 * @device: Device ID of the switch
133 * @generation: Switch Thunderbolt generation
138 * @is_unplugged: The switch is going away
139 * @drom: DROM of the switch (%NULL if not found)
140 * @nvm: Pointer to the NVM if the switch has one (%NULL otherwise)
141 * @no_nvm_upgrade: Prevent NVM upgrade of this switch
142 * @safe_mode: The switch is in safe-mode
143 * @boot: Whether the switch was already authorized on boot or not
144 * @rpm: The switch supports runtime PM
145 * @authorized: Whether the switch is authorized by user or policy
146 * @security_level: Switch supported security level
152 * @link: Root switch link this switch is connected (ICM only)
153 * @depth: Depth in the chain this switch is connected (ICM only)
156 * @quirks: Quirks used for this Thunderbolt switch
166 * When the switch is being added or removed to the domain (other
223 * struct tb_bandwidth_group - Bandwidth management group
225 * @index: Index of the group (aka Group_ID). Valid values %1-%7
247 * struct tb_port - a thunderbolt port, part of a tb_switch
249 * @sw: Switch the port belongs to
257 * @port: Port number on switch
260 * @dual_link_port: If the switch is connected using two ports, points
274 * non-zero.
275 * @redrive: For DP IN, if true the adapter is in redrive mode.
308 * struct usb4_port - USB4 port device
312 * it into offline mode and back
313 * @offline: The port is currently in offline mode
327 * struct tb_retimer - Thunderbolt retimer
355 * struct tb_path_hop - routing information for a tb_path
356 * @in_port: Ingress port of a switch
357 * @out_port: Egress port of a switch where the packet is routed out
358 * (must be on the same switch as @in_port)
362 * currently, %-1 to disable)
366 * @nfc_credits: Number of non-flow controlled buffers allocated for the
370 * Hop configuration is always done on the IN port of a switch.
371 * in_port and out_port have to be on the same switch. Packets arriving on
373 * next hop to take (on out_port->remote) is determined by
374 * next_hop_index. When routing packet to another switch (out->remote is
393 * enum tb_path_port - path options mask
409 * struct tb_path - a unidirectional path between two ports
448 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
470 * struct tb_cm_ops - Connection manager specific operations vector
476 * it is unregistered. Called without @tb->lock taken. Optional.
485 * @runtime_suspend_switch: Runtime suspend a switch
486 * @runtime_resume_switch: Runtime resume a switch
490 * @disapprove_switch: Disapprove switch (disconnect PCIe tunnel)
491 * @approve_switch: Approve switch
492 * @add_switch_key: Add key to switch
493 * @challenge_switch_key: Challenge switch using key
499 * performed. If this returns %-EOPNOTSUPP then the
546 return (void *)tb->privdata; in tb_priv()
554 * tb_upstream_port() - return the upstream port of a switch
557 * Every switch has an upstream port (for the root switch it is the NHI).
559 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
566 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
570 * tb_is_upstream_port() - Is the port upstream facing
578 const struct tb_port *upstream_port = tb_upstream_port(port->sw); in tb_is_upstream_port()
579 return port == upstream_port || port->dual_link_port == upstream_port; in tb_is_upstream_port()
584 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
591 port = route >> (sw->config.depth * 8); in tb_port_at()
592 if (WARN_ON(port > sw->config.max_port_number)) in tb_port_at()
594 return &sw->ports[port]; in tb_port_at()
599 switch (width) { in tb_width_name()
614 * tb_port_has_remote() - Does the port have switch connected downstream
623 if (!port->remote) in tb_port_has_remote()
625 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
633 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
638 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
643 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
648 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
653 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
658 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
663 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
668 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
674 if (sw->is_unplugged) in tb_sw_read()
675 return -ENODEV; in tb_sw_read()
676 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
688 if (sw->is_unplugged) in tb_sw_write()
689 return -ENODEV; in tb_sw_write()
690 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
702 if (port->sw->is_unplugged) in tb_port_read()
703 return -ENODEV; in tb_port_read()
704 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
706 tb_route(port->sw), in tb_port_read()
707 port->port, in tb_port_read()
716 if (port->sw->is_unplugged) in tb_port_write()
717 return -ENODEV; in tb_port_write()
718 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
720 tb_route(port->sw), in tb_port_write()
721 port->port, in tb_port_write()
727 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
728 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
729 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
730 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
731 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
736 level(__sw->tb, "%llx: " fmt, \
747 level(__port->sw->tb, "%llx:%u: " fmt, \
748 tb_route(__port->sw), __port->port, ## arg); \
799 get_device(&tb->dev); in tb_domain_get()
805 put_device(&tb->dev); in tb_domain_put()
809 * tb_domain_event() - Notify userspace about an event in domain
818 kobject_uevent_env(&tb->dev.kobj, KOBJ_CHANGE, envp); in tb_domain_event()
866 * tb_switch_for_each_port() - Iterate over each switch port
867 * @sw: Switch whose ports to iterate
870 * Iterates over each switch port skipping the control port (port %0).
873 for ((p) = &(sw)->ports[1]; \
874 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
879 get_device(&sw->dev); in tb_switch_get()
885 put_device(&sw->dev); in tb_switch_put()
890 return dev->type == &tb_switch_type; in tb_is_switch()
902 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
906 * tb_switch_downstream_port() - Return downstream facing port of parent router
921 * tb_switch_depth() - Returns depth of the connected router
928 return sw->config.depth; in tb_switch_depth()
933 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
934 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
939 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
940 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
945 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
946 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
957 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
958 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
969 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
970 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
984 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
985 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
997 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
998 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
1010 * tb_switch_is_icm() - Is the switch handled by ICM firmware
1011 * @sw: Switch to check
1018 * Return: %true if switch is handled by ICM, %false if handled by
1023 return !sw->config.enabled; in tb_switch_is_icm()
1038 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
1041 * tb_switch_tmu_is_configured() - Is given TMU mode configured
1042 * @sw: Router whose mode to check
1043 * @mode: Mode to check
1045 * Checks if given router TMU mode is configured to @mode. Note the
1046 * router TMU might not be enabled to this mode.
1048 * Return: %true if TMU mode is equal to @mode, %false otherwise.
1051 enum tb_switch_tmu_mode mode) in tb_switch_tmu_is_configured() argument
1053 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
1057 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
1058 * @sw: Router whose TMU mode to check
1065 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
1066 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1076 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1089 return sw->clx & clx; in tb_switch_clx_is_enabled()
1112 * tb_port_path_direction_downstream() - Checks if path is directed downstream
1123 return src->sw->config.depth < dst->sw->config.depth; in tb_port_path_direction_downstream()
1128 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1132 * tb_for_each_port_on_path() - Iterate over each port on path
1144 * tb_for_each_upstream_port_on_path() - Iterate over each upstream port on path
1205 * tb_path_for_each_hop() - Iterate over each hop on path
1212 for ((hop) = &(path)->hops[0]; \
1213 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1240 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1244 * tb_downstream_route() - get route to downstream switch
1249 * Return: Route to the switch behind @port.
1253 return tb_route(port->sw) in tb_downstream_route()
1254 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1270 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1274 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1281 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1291 return dev->type == &tb_retimer_type; in tb_is_retimer()
1302 * usb4_switch_version() - Returns USB4 version of the router
1306 * on). Can be called to pre-USB4 router too and in that case returns %0.
1310 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1314 * tb_switch_is_usb4() - Is the switch USB4 compliant
1315 * @sw: Switch to check
1369 * enum usb4_sb_target - Sideband transaction target
1386 * enum usb4_margin_sw_error_counter - Software margining error counter operation
1407 * struct usb4_port_margining_params - USB4 margining parameters
1484 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1501 return usb4->offline; in usb4_port_device_is_offline()