Lines Matching +full:sw +full:- +full:enable +full:- +full:bit
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
13 #include <linux/nvmem-provider.h>
24 #define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0)
26 #define QUIRK_NO_CLX BIT(1)
28 #define QUIRK_KEEP_POWER_IN_DP_REDRIVE BIT(2)
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
113 * struct tb_switch - a thunderbolt switch
142 * @safe_mode: The switch is in safe-mode
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
274 * non-zero.
282 struct tb_switch *sw; member
308 * struct usb4_port - USB4 port device
355 * struct tb_path_hop - routing information for a tb_path
362 * currently, %-1 to disable)
366 * @nfc_credits: Number of non-flow controlled buffers allocated for the
368 * @pm_support: Set path PM packet support bit to 1 (for USB4 v2 routers)
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 */
457 #define TB_WAKE_ON_CONNECT BIT(0)
458 #define TB_WAKE_ON_DISCONNECT BIT(1)
459 #define TB_WAKE_ON_USB4 BIT(2)
460 #define TB_WAKE_ON_USB3 BIT(3)
461 #define TB_WAKE_ON_PCIE BIT(4)
462 #define TB_WAKE_ON_DP BIT(5)
465 #define TB_CL0S BIT(0)
466 #define TB_CL1 BIT(1)
467 #define TB_CL2 BIT(2)
470 * struct tb_cm_ops - Connection manager specific operations vector
476 * it is unregistered. Called without @tb->lock taken. Optional.
499 * performed. If this returns %-EOPNOTSUPP then the
519 int (*runtime_suspend_switch)(struct tb_switch *sw);
520 int (*runtime_resume_switch)(struct tb_switch *sw);
525 int (*disapprove_switch)(struct tb *tb, struct tb_switch *sw);
526 int (*approve_switch)(struct tb *tb, struct tb_switch *sw);
527 int (*add_switch_key)(struct tb *tb, struct tb_switch *sw);
528 int (*challenge_switch_key)(struct tb *tb, struct tb_switch *sw,
537 int (*usb4_switch_op)(struct tb_switch *sw, u16 opcode, u32 *metadata,
540 int (*usb4_switch_nvm_authenticate_status)(struct tb_switch *sw,
546 return (void *)tb->privdata; in tb_priv()
554 * tb_upstream_port() - return the upstream port of a switch
558 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
563 static inline struct tb_port *tb_upstream_port(struct tb_switch *sw) in tb_upstream_port() argument
565 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
569 * tb_is_upstream_port() - Is the port upstream facing
577 const struct tb_port *upstream_port = tb_upstream_port(port->sw); in tb_is_upstream_port()
578 return port == upstream_port || port->dual_link_port == upstream_port; in tb_is_upstream_port()
581 static inline u64 tb_route(const struct tb_switch *sw) in tb_route() argument
583 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
586 static inline struct tb_port *tb_port_at(u64 route, struct tb_switch *sw) in tb_port_at() argument
590 port = route >> (sw->config.depth * 8); in tb_port_at()
591 if (WARN_ON(port > sw->config.max_port_number)) in tb_port_at()
593 return &sw->ports[port]; in tb_port_at()
613 * tb_port_has_remote() - Does the port have switch connected downstream
622 if (!port->remote) in tb_port_has_remote()
624 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
632 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
637 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
642 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
647 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
652 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
657 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
662 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
667 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
670 static inline int tb_sw_read(struct tb_switch *sw, void *buffer, in tb_sw_read() argument
673 if (sw->is_unplugged) in tb_sw_read()
674 return -ENODEV; in tb_sw_read()
675 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
677 tb_route(sw), in tb_sw_read()
684 static inline int tb_sw_write(struct tb_switch *sw, const void *buffer, in tb_sw_write() argument
687 if (sw->is_unplugged) in tb_sw_write()
688 return -ENODEV; in tb_sw_write()
689 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
691 tb_route(sw), in tb_sw_write()
701 if (port->sw->is_unplugged) in tb_port_read()
702 return -ENODEV; in tb_port_read()
703 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
705 tb_route(port->sw), in tb_port_read()
706 port->port, in tb_port_read()
715 if (port->sw->is_unplugged) in tb_port_write()
716 return -ENODEV; in tb_port_write()
717 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
719 tb_route(port->sw), in tb_port_write()
720 port->port, in tb_port_write()
726 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
727 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
728 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
729 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
730 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
732 #define __TB_SW_PRINT(level, sw, fmt, arg...) \ argument
734 const struct tb_switch *__sw = (sw); \
735 level(__sw->tb, "%llx: " fmt, \
738 #define tb_sw_WARN(sw, fmt, arg...) __TB_SW_PRINT(tb_WARN, sw, fmt, ##arg) argument
739 #define tb_sw_warn(sw, fmt, arg...) __TB_SW_PRINT(tb_warn, sw, fmt, ##arg) argument
740 #define tb_sw_info(sw, fmt, arg...) __TB_SW_PRINT(tb_info, sw, fmt, ##arg) argument
741 #define tb_sw_dbg(sw, fmt, arg...) __TB_SW_PRINT(tb_dbg, sw, fmt, ##arg) argument
746 level(__port->sw->tb, "%llx:%u: " fmt, \
747 tb_route(__port->sw), __port->port, ## arg); \
782 int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw);
783 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);
784 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw);
785 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw);
798 get_device(&tb->dev); in tb_domain_get()
804 put_device(&tb->dev); in tb_domain_put()
808 * tb_domain_event() - Notify userspace about an event in domain
817 kobject_uevent_env(&tb->dev.kobj, KOBJ_CHANGE, envp); in tb_domain_event()
841 int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
847 int tb_switch_configure(struct tb_switch *sw);
848 int tb_switch_configuration_valid(struct tb_switch *sw);
849 int tb_switch_add(struct tb_switch *sw);
850 void tb_switch_remove(struct tb_switch *sw);
851 void tb_switch_suspend(struct tb_switch *sw, bool runtime);
852 int tb_switch_resume(struct tb_switch *sw, bool runtime);
853 int tb_switch_reset(struct tb_switch *sw);
854 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit,
856 void tb_sw_set_unplugged(struct tb_switch *sw);
857 struct tb_port *tb_switch_find_port(struct tb_switch *sw,
865 * tb_switch_for_each_port() - Iterate over each switch port
866 * @sw: Switch whose ports to iterate
871 #define tb_switch_for_each_port(sw, p) \ argument
872 for ((p) = &(sw)->ports[1]; \
873 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
875 static inline struct tb_switch *tb_switch_get(struct tb_switch *sw) in tb_switch_get() argument
877 if (sw) in tb_switch_get()
878 get_device(&sw->dev); in tb_switch_get()
879 return sw; in tb_switch_get()
882 static inline void tb_switch_put(struct tb_switch *sw) in tb_switch_put() argument
884 put_device(&sw->dev); in tb_switch_put()
889 return dev->type == &tb_switch_type; in tb_is_switch()
899 static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw) in tb_switch_parent() argument
901 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
905 * tb_switch_downstream_port() - Return downstream facing port of parent router
906 * @sw: Device router pointer
911 static inline struct tb_port *tb_switch_downstream_port(struct tb_switch *sw) in tb_switch_downstream_port() argument
913 if (WARN_ON(!tb_route(sw))) in tb_switch_downstream_port()
915 return tb_port_at(tb_route(sw), tb_switch_parent(sw)); in tb_switch_downstream_port()
919 * tb_switch_depth() - Returns depth of the connected router
920 * @sw: Router
922 static inline int tb_switch_depth(const struct tb_switch *sw) in tb_switch_depth() argument
924 return sw->config.depth; in tb_switch_depth()
927 static inline bool tb_switch_is_light_ridge(const struct tb_switch *sw) in tb_switch_is_light_ridge() argument
929 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
930 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
933 static inline bool tb_switch_is_eagle_ridge(const struct tb_switch *sw) in tb_switch_is_eagle_ridge() argument
935 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
936 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
939 static inline bool tb_switch_is_cactus_ridge(const struct tb_switch *sw) in tb_switch_is_cactus_ridge() argument
941 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
942 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
951 static inline bool tb_switch_is_falcon_ridge(const struct tb_switch *sw) in tb_switch_is_falcon_ridge() argument
953 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
954 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
963 static inline bool tb_switch_is_alpine_ridge(const struct tb_switch *sw) in tb_switch_is_alpine_ridge() argument
965 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
966 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
978 static inline bool tb_switch_is_titan_ridge(const struct tb_switch *sw) in tb_switch_is_titan_ridge() argument
980 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
981 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
991 static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw) in tb_switch_is_tiger_lake() argument
993 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
994 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
1006 * tb_switch_is_icm() - Is the switch handled by ICM firmware
1007 * @sw: Switch to check
1009 * In case there is a need to differentiate whether ICM firmware or SW CM
1010 * is handling @sw this function can be called. It is valid to call this
1012 * (latter only for SW CM case).
1014 static inline bool tb_switch_is_icm(const struct tb_switch *sw) in tb_switch_is_icm() argument
1016 return !sw->config.enabled; in tb_switch_is_icm()
1019 int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width);
1020 int tb_switch_configure_link(struct tb_switch *sw);
1021 void tb_switch_unconfigure_link(struct tb_switch *sw);
1023 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
1024 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1025 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1027 int tb_switch_tmu_init(struct tb_switch *sw);
1028 int tb_switch_tmu_post_time(struct tb_switch *sw);
1029 int tb_switch_tmu_disable(struct tb_switch *sw);
1030 int tb_switch_tmu_enable(struct tb_switch *sw);
1031 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
1034 * tb_switch_tmu_is_configured() - Is given TMU mode configured
1035 * @sw: Router whose mode to check
1041 static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw, in tb_switch_tmu_is_configured() argument
1044 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
1048 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
1049 * @sw: Router whose TMU mode to check
1054 static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw) in tb_switch_tmu_is_enabled() argument
1056 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
1057 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1062 int tb_switch_clx_init(struct tb_switch *sw);
1063 int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx);
1064 int tb_switch_clx_disable(struct tb_switch *sw);
1067 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1068 * @sw: Router to check for the CLx
1076 static inline bool tb_switch_clx_is_enabled(const struct tb_switch *sw, in tb_switch_clx_is_enabled() argument
1079 return sw->clx & clx; in tb_switch_clx_is_enabled()
1082 int tb_switch_pcie_l1_enable(struct tb_switch *sw);
1084 int tb_switch_xhci_connect(struct tb_switch *sw);
1085 void tb_switch_xhci_disconnect(struct tb_switch *sw);
1102 * tb_port_path_direction_downstream() - Checks if path directed downstream
1113 return src->sw->config.depth < dst->sw->config.depth; in tb_port_path_direction_downstream()
1118 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1122 * tb_for_each_port_on_path() - Iterate over each port on path
1134 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1159 int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
1160 int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);
1161 int tb_switch_next_cap(struct tb_switch *sw, unsigned int offset);
1167 int tb_usb3_port_enable(struct tb_port *port, bool enable);
1170 int tb_pci_port_enable(struct tb_port *port, bool enable);
1177 int tb_dp_port_enable(struct tb_port *port, bool enable);
1195 * tb_path_for_each_hop() - Iterate over each hop on path
1202 for ((hop) = &(path)->hops[0]; \
1203 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1205 int tb_drom_read(struct tb_switch *sw);
1206 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid);
1208 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);
1220 int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags);
1221 int tb_lc_set_sleep(struct tb_switch *sw);
1222 bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
1223 bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in);
1224 int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in);
1225 int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in);
1226 int tb_lc_force_power(struct tb_switch *sw);
1230 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1234 * tb_downstream_route() - get route to downstream switch
1242 return tb_route(port->sw) in tb_downstream_route()
1243 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1259 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1263 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1270 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1280 return dev->type == &tb_retimer_type; in tb_is_retimer()
1291 * usb4_switch_version() - Returns USB4 version of the router
1292 * @sw: Router to check
1295 * on). Can be called to pre-USB4 router too and in that case returns %0.
1297 static inline unsigned int usb4_switch_version(const struct tb_switch *sw) in usb4_switch_version() argument
1299 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1303 * tb_switch_is_usb4() - Is the switch USB4 compliant
1304 * @sw: Switch to check
1306 * Returns true if the @sw is USB4 compliant router, false otherwise.
1308 static inline bool tb_switch_is_usb4(const struct tb_switch *sw) in tb_switch_is_usb4() argument
1310 return usb4_switch_version(sw) > 0; in tb_switch_is_usb4()
1313 void usb4_switch_check_wakes(struct tb_switch *sw);
1314 int usb4_switch_setup(struct tb_switch *sw);
1315 int usb4_switch_configuration_valid(struct tb_switch *sw);
1316 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
1317 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
1319 bool usb4_switch_lane_bonding_possible(struct tb_switch *sw);
1320 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime);
1321 int usb4_switch_set_sleep(struct tb_switch *sw);
1322 int usb4_switch_nvm_sector_size(struct tb_switch *sw);
1323 int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
1325 int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address);
1326 int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address,
1328 int usb4_switch_nvm_authenticate(struct tb_switch *sw);
1329 int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status);
1330 int usb4_switch_credits_init(struct tb_switch *sw);
1331 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
1332 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1333 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1334 struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw,
1336 struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw,
1338 int usb4_switch_add_ports(struct tb_switch *sw);
1339 void usb4_switch_remove_ports(struct tb_switch *sw);
1358 * enum tb_sb_target - Sideband transaction target
1375 * enum usb4_margin_sw_error_counter - Software margining error counter operation
1377 * @USB4_MARGIN_SW_ERROR_COUNTER_CLEAR: Set the error counter to 0, enable counter
1396 * struct usb4_port_margining_params - USB4 margining parameters
1399 * @lanes: Lanes to enable for the margining operation
1401 * @optional_voltage_offset_range: Enable optional extended voltage range
1467 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
1471 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1484 int usb4_port_index(const struct tb_switch *sw, const struct tb_port *port);
1488 return usb4->offline; in usb4_port_device_is_offline()
1491 void tb_check_quirks(struct tb_switch *sw);
1524 void tb_switch_debugfs_init(struct tb_switch *sw);
1525 void tb_switch_debugfs_remove(struct tb_switch *sw);
1535 static inline void tb_switch_debugfs_init(struct tb_switch *sw) { } in tb_switch_debugfs_init() argument
1536 static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { } in tb_switch_debugfs_remove() argument