Lines Matching +full:sw +full:- +full:reset +full:- +full:number
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
12 #include <linux/nvmem-provider.h>
30 * struct tb_nvm - Structure holding NVM information
32 * @major: Major version number of the active NVM portion
33 * @minor: Minor version number of the active NVM portion
37 * @non_active: Non-active portion NVMem device
42 * @buf_data_size: Number of bytes actually consumed by the new NVM
78 * enum tb_switch_tmu_mode - TMU mode
80 * @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
81 * @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
82 * @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
83 * @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
96 * struct tb_switch_tmu - Structure holding router TMU configuration
98 * @has_ucap: Does the switch support uni-directional mode
112 * struct tb_switch - a thunderbolt switch
140 * @safe_mode: The switch is in safe-mode
156 * @max_usb3_credits: Router preferred number of buffers for USB 3.x
157 * @min_dp_aux_credits: Router preferred minimum number of buffers for DP AUX
158 * @min_dp_main_credits: Router preferred minimum number of buffers for DP MAIN
159 * @max_pcie_credits: Router preferred number of buffers for PCIe
160 * @max_dma_credits: Router preferred number of buffers for DMA/P2P
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
235 * @sw: Switch the port belongs to
243 * @port: Port number on switch
252 * @total_credits: Total number of buffers available for this port
254 * @dma_credits: Number of credits allocated for DMA tunneling for all
260 * non-zero.
268 struct tb_switch *sw; member
294 * struct usb4_port - USB4 port device
337 * struct tb_path_hop - routing information for a tb_path
344 * currently, %-1 to disable)
346 * @initial_credits: Number of initial flow control credits allocated for
348 * @nfc_credits: Number of non-flow controlled buffers allocated for the
354 * next hop to take (on out_port->remote) is determined by
355 * 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
406 * A path consists of a number of hops (see &struct tb_path_hop). To
428 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
450 * struct tb_cm_ops - Connection manager specific operations vector
477 * performed. If this returns %-EOPNOTSUPP then the
486 int (*start)(struct tb *tb, bool reset);
496 int (*runtime_suspend_switch)(struct tb_switch *sw);
497 int (*runtime_resume_switch)(struct tb_switch *sw);
502 int (*disapprove_switch)(struct tb *tb, struct tb_switch *sw);
503 int (*approve_switch)(struct tb *tb, struct tb_switch *sw);
504 int (*add_switch_key)(struct tb *tb, struct tb_switch *sw);
505 int (*challenge_switch_key)(struct tb *tb, struct tb_switch *sw,
514 int (*usb4_switch_op)(struct tb_switch *sw, u16 opcode, u32 *metadata,
517 int (*usb4_switch_nvm_authenticate_status)(struct tb_switch *sw,
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
540 static inline struct tb_port *tb_upstream_port(struct tb_switch *sw) in tb_upstream_port() argument
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()
558 static inline u64 tb_route(const struct tb_switch *sw) in tb_route() argument
560 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
563 static inline struct tb_port *tb_port_at(u64 route, struct tb_switch *sw) in tb_port_at() argument
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()
574 * tb_port_has_remote() - Does the port have switch connected downstream
583 if (!port->remote) in tb_port_has_remote()
585 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
593 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
598 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
603 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
608 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
613 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
618 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
623 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
628 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
631 static inline int tb_sw_read(struct tb_switch *sw, void *buffer, in tb_sw_read() argument
634 if (sw->is_unplugged) in tb_sw_read()
635 return -ENODEV; in tb_sw_read()
636 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
638 tb_route(sw), in tb_sw_read()
645 static inline int tb_sw_write(struct tb_switch *sw, const void *buffer, in tb_sw_write() argument
648 if (sw->is_unplugged) in tb_sw_write()
649 return -ENODEV; in tb_sw_write()
650 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
652 tb_route(sw), in tb_sw_write()
662 if (port->sw->is_unplugged) in tb_port_read()
663 return -ENODEV; in tb_port_read()
664 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
666 tb_route(port->sw), in tb_port_read()
667 port->port, in tb_port_read()
676 if (port->sw->is_unplugged) in tb_port_write()
677 return -ENODEV; in tb_port_write()
678 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
680 tb_route(port->sw), in tb_port_write()
681 port->port, in tb_port_write()
687 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
688 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
689 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
690 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
691 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
693 #define __TB_SW_PRINT(level, sw, fmt, arg...) \ argument
695 const struct tb_switch *__sw = (sw); \
696 level(__sw->tb, "%llx: " fmt, \
699 #define tb_sw_WARN(sw, fmt, arg...) __TB_SW_PRINT(tb_WARN, sw, fmt, ##arg) argument
700 #define tb_sw_warn(sw, fmt, arg...) __TB_SW_PRINT(tb_warn, sw, fmt, ##arg) argument
701 #define tb_sw_info(sw, fmt, arg...) __TB_SW_PRINT(tb_info, sw, fmt, ##arg) argument
702 #define tb_sw_dbg(sw, fmt, arg...) __TB_SW_PRINT(tb_dbg, sw, fmt, ##arg) argument
707 level(__port->sw->tb, "%llx:%u: " fmt, \
708 tb_route(__port->sw), __port->port, ## arg); \
733 int tb_domain_add(struct tb *tb, bool reset);
743 int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw);
744 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);
745 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw);
746 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw);
759 get_device(&tb->dev); in tb_domain_get()
765 put_device(&tb->dev); in tb_domain_put()
789 int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
795 int tb_switch_configure(struct tb_switch *sw);
796 int tb_switch_configuration_valid(struct tb_switch *sw);
797 int tb_switch_add(struct tb_switch *sw);
798 void tb_switch_remove(struct tb_switch *sw);
799 void tb_switch_suspend(struct tb_switch *sw, bool runtime);
800 int tb_switch_resume(struct tb_switch *sw, bool runtime);
801 int tb_switch_reset(struct tb_switch *sw);
802 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit,
804 void tb_sw_set_unplugged(struct tb_switch *sw);
805 struct tb_port *tb_switch_find_port(struct tb_switch *sw,
813 * tb_switch_for_each_port() - Iterate over each switch port
814 * @sw: Switch whose ports to iterate
819 #define tb_switch_for_each_port(sw, p) \ argument
820 for ((p) = &(sw)->ports[1]; \
821 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
823 static inline struct tb_switch *tb_switch_get(struct tb_switch *sw) in tb_switch_get() argument
825 if (sw) in tb_switch_get()
826 get_device(&sw->dev); in tb_switch_get()
827 return sw; in tb_switch_get()
830 static inline void tb_switch_put(struct tb_switch *sw) in tb_switch_put() argument
832 put_device(&sw->dev); in tb_switch_put()
837 return dev->type == &tb_switch_type; in tb_is_switch()
847 static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw) in tb_switch_parent() argument
849 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
853 * tb_switch_downstream_port() - Return downstream facing port of parent router
854 * @sw: Device router pointer
859 static inline struct tb_port *tb_switch_downstream_port(struct tb_switch *sw) in tb_switch_downstream_port() argument
861 if (WARN_ON(!tb_route(sw))) in tb_switch_downstream_port()
863 return tb_port_at(tb_route(sw), tb_switch_parent(sw)); in tb_switch_downstream_port()
867 * tb_switch_depth() - Returns depth of the connected router
868 * @sw: Router
870 static inline int tb_switch_depth(const struct tb_switch *sw) in tb_switch_depth() argument
872 return sw->config.depth; in tb_switch_depth()
875 static inline bool tb_switch_is_light_ridge(const struct tb_switch *sw) in tb_switch_is_light_ridge() argument
877 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
878 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
881 static inline bool tb_switch_is_eagle_ridge(const struct tb_switch *sw) in tb_switch_is_eagle_ridge() argument
883 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
884 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
887 static inline bool tb_switch_is_cactus_ridge(const struct tb_switch *sw) in tb_switch_is_cactus_ridge() argument
889 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
890 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
899 static inline bool tb_switch_is_falcon_ridge(const struct tb_switch *sw) in tb_switch_is_falcon_ridge() argument
901 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
902 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
911 static inline bool tb_switch_is_alpine_ridge(const struct tb_switch *sw) in tb_switch_is_alpine_ridge() argument
913 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
914 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
926 static inline bool tb_switch_is_titan_ridge(const struct tb_switch *sw) in tb_switch_is_titan_ridge() argument
928 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
929 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
939 static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw) in tb_switch_is_tiger_lake() argument
941 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
942 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
954 * tb_switch_is_icm() - Is the switch handled by ICM firmware
955 * @sw: Switch to check
957 * In case there is a need to differentiate whether ICM firmware or SW CM
958 * is handling @sw this function can be called. It is valid to call this
960 * (latter only for SW CM case).
962 static inline bool tb_switch_is_icm(const struct tb_switch *sw) in tb_switch_is_icm() argument
964 return !sw->config.enabled; in tb_switch_is_icm()
967 int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width);
968 int tb_switch_configure_link(struct tb_switch *sw);
969 void tb_switch_unconfigure_link(struct tb_switch *sw);
971 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
972 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
973 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
975 int tb_switch_tmu_init(struct tb_switch *sw);
976 int tb_switch_tmu_post_time(struct tb_switch *sw);
977 int tb_switch_tmu_disable(struct tb_switch *sw);
978 int tb_switch_tmu_enable(struct tb_switch *sw);
979 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
982 * tb_switch_tmu_is_configured() - Is given TMU mode configured
983 * @sw: Router whose mode to check
989 static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw, in tb_switch_tmu_is_configured() argument
992 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
996 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
997 * @sw: Router whose TMU mode to check
1002 static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw) in tb_switch_tmu_is_enabled() argument
1004 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
1005 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1010 int tb_switch_clx_init(struct tb_switch *sw);
1011 bool tb_switch_clx_is_supported(const struct tb_switch *sw);
1012 int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx);
1013 int tb_switch_clx_disable(struct tb_switch *sw);
1016 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1017 * @sw: Router to check for the CLx
1025 static inline bool tb_switch_clx_is_enabled(const struct tb_switch *sw, in tb_switch_clx_is_enabled() argument
1028 return sw->clx & clx; in tb_switch_clx_is_enabled()
1031 int tb_switch_pcie_l1_enable(struct tb_switch *sw);
1033 int tb_switch_xhci_connect(struct tb_switch *sw);
1034 void tb_switch_xhci_disconnect(struct tb_switch *sw);
1051 * tb_port_path_direction_downstream() - Checks if path directed downstream
1062 return src->sw->config.depth < dst->sw->config.depth; in tb_port_path_direction_downstream()
1067 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1071 * tb_for_each_port_on_path() - Iterate over each port on path
1083 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1108 int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
1109 int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);
1110 int tb_switch_next_cap(struct tb_switch *sw, unsigned int offset);
1144 * tb_path_for_each_hop() - Iterate over each hop on path
1151 for ((hop) = &(path)->hops[0]; \
1152 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1154 int tb_drom_read(struct tb_switch *sw);
1155 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid);
1157 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);
1169 int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags);
1170 int tb_lc_set_sleep(struct tb_switch *sw);
1171 bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
1172 bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in);
1173 int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in);
1174 int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in);
1175 int tb_lc_force_power(struct tb_switch *sw);
1179 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1183 * tb_downstream_route() - get route to downstream switch
1191 return tb_route(port->sw) in tb_downstream_route()
1192 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1208 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1212 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1219 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1229 return dev->type == &tb_retimer_type; in tb_is_retimer()
1240 * usb4_switch_version() - Returns USB4 version of the router
1241 * @sw: Router to check
1244 * on). Can be called to pre-USB4 router too and in that case returns %0.
1246 static inline unsigned int usb4_switch_version(const struct tb_switch *sw) in usb4_switch_version() argument
1248 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1252 * tb_switch_is_usb4() - Is the switch USB4 compliant
1253 * @sw: Switch to check
1255 * Returns true if the @sw is USB4 compliant router, false otherwise.
1257 static inline bool tb_switch_is_usb4(const struct tb_switch *sw) in tb_switch_is_usb4() argument
1259 return usb4_switch_version(sw) > 0; in tb_switch_is_usb4()
1262 void usb4_switch_check_wakes(struct tb_switch *sw);
1263 int usb4_switch_setup(struct tb_switch *sw);
1264 int usb4_switch_configuration_valid(struct tb_switch *sw);
1265 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
1266 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
1268 bool usb4_switch_lane_bonding_possible(struct tb_switch *sw);
1269 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags);
1270 int usb4_switch_set_sleep(struct tb_switch *sw);
1271 int usb4_switch_nvm_sector_size(struct tb_switch *sw);
1272 int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
1274 int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address);
1275 int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address,
1277 int usb4_switch_nvm_authenticate(struct tb_switch *sw);
1278 int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status);
1279 int usb4_switch_credits_init(struct tb_switch *sw);
1280 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
1281 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1282 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1283 struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw,
1285 struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw,
1287 int usb4_switch_add_ports(struct tb_switch *sw);
1288 void usb4_switch_remove_ports(struct tb_switch *sw);
1362 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1378 return usb4->offline; in usb4_port_device_is_offline()
1381 void tb_check_quirks(struct tb_switch *sw);
1414 void tb_switch_debugfs_init(struct tb_switch *sw);
1415 void tb_switch_debugfs_remove(struct tb_switch *sw);
1423 static inline void tb_switch_debugfs_init(struct tb_switch *sw) { } in tb_switch_debugfs_init() argument
1424 static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { } in tb_switch_debugfs_remove() argument