Lines Matching +full:port +full:- +full:config
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
110 * struct tb_switch - a thunderbolt switch
112 * @config: Switch configuration
114 * @dma_port: If the switch has port supporting DMA configuration based
139 * @safe_mode: The switch is in safe-mode
169 struct tb_regs_switch_header config; member
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
234 * @config: Cached port configuration read from registers
235 * @sw: Switch the port belongs to
236 * @remote: Remote port (%NULL if not connected)
241 * @cap_usb4: Offset to the USB4 port capability (%0 if not present)
242 * @usb4: Pointer to the USB4 port structure (only if @cap_usb4 is != %0)
243 * @port: Port number on switch
245 * @bonded: true if the port is bonded (two lanes combined as one)
247 * to the other port.
248 * @link_nr: Is this primary or secondary port on the dual_link.
252 * @total_credits: Total number of buffers available for this port
255 * DMA paths through this port.
260 * non-zero.
266 struct tb_regs_port_header config; member
275 u8 port; member
292 * struct usb4_port - USB4 port device
293 * @dev: Device for the port
294 * @port: Pointer to the lane 0 adapter
295 * @can_offline: Does the port have necessary platform support to moved
297 * @offline: The port is currently in offline mode
302 struct tb_port *port; member
314 * @index: Retimer index facing the router USB4 port
317 * @port: Pointer to the lane 0 adapter
328 struct tb_port *port; member
335 * struct tb_path_hop - routing information for a tb_path
336 * @in_port: Ingress port of a switch
337 * @out_port: Egress port of a switch where the packet is routed out
340 * the path config space of @in_port.
342 * currently, %-1 to disable)
346 * @nfc_credits: Number of non-flow controlled buffers allocated for the
350 * Hop configuration is always done on the IN port of a switch.
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
359 * port.
373 * enum tb_path_port - path options mask
389 * struct tb_path - a unidirectional path between two ports
400 * @clear_fc: Clear all flow control from the path config space entries
404 * @alloc_hopid: Does this path consume port HopID
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
523 return (void *)tb->privdata; in tb_priv()
531 * tb_upstream_port() - return the upstream port of a switch
533 * Every switch has an upstream port (for the root switch it is the NHI).
535 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
536 * non root switches (on the NHI port remote is always NULL).
538 * Return: Returns the upstream port of the switch.
542 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
546 * tb_is_upstream_port() - Is the port upstream facing
547 * @port: Port to check
549 * Returns true if @port is upstream facing port. In case of dual link
552 static inline bool tb_is_upstream_port(const struct tb_port *port) in tb_is_upstream_port() argument
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()
565 u8 port; in tb_port_at() local
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
591 * @port: Port to check
593 * Returns true only when the port is primary port and has remote set.
595 static inline bool tb_port_has_remote(const struct tb_port *port) in tb_port_has_remote() argument
597 if (tb_is_upstream_port(port)) in tb_port_has_remote()
599 if (!port->remote) in tb_port_has_remote()
601 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
607 static inline bool tb_port_is_null(const struct tb_port *port) in tb_port_is_null() argument
609 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
612 static inline bool tb_port_is_nhi(const struct tb_port *port) in tb_port_is_nhi() argument
614 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
617 static inline bool tb_port_is_pcie_down(const struct tb_port *port) in tb_port_is_pcie_down() argument
619 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
622 static inline bool tb_port_is_pcie_up(const struct tb_port *port) in tb_port_is_pcie_up() argument
624 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
627 static inline bool tb_port_is_dpin(const struct tb_port *port) in tb_port_is_dpin() argument
629 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
632 static inline bool tb_port_is_dpout(const struct tb_port *port) in tb_port_is_dpout() argument
634 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
637 static inline bool tb_port_is_usb3_down(const struct tb_port *port) in tb_port_is_usb3_down() argument
639 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
642 static inline bool tb_port_is_usb3_up(const struct tb_port *port) in tb_port_is_usb3_up() argument
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()
675 static inline int tb_port_read(struct tb_port *port, void *buffer, in tb_port_read() argument
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()
689 static inline int tb_port_write(struct tb_port *port, const void *buffer, in tb_port_write() argument
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); \
726 #define tb_port_WARN(port, fmt, arg...) \ argument
727 __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
728 #define tb_port_warn(port, fmt, arg...) \ argument
729 __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
730 #define tb_port_info(port, fmt, arg...) \ argument
731 __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
732 #define tb_port_dbg(port, fmt, arg...) \ argument
733 __TB_PORT_PRINT(tb_dbg, port, fmt, ##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
831 * @p: Port used as iterator
833 * Iterates over each switch port skipping the control port (port %0).
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
872 * Only call for device routers. Returns the downstream facing port of
883 * tb_switch_depth() - Returns depth of the connected 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
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
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()
1024 bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx);
1031 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1043 return sw->clx & clx; in tb_switch_clx_is_enabled()
1051 int tb_port_state(struct tb_port *port);
1052 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
1053 int tb_port_add_nfc_credits(struct tb_port *port, int credits);
1054 int tb_port_clear_counter(struct tb_port *port, int counter);
1055 int tb_port_unlock(struct tb_port *port);
1056 int tb_port_enable(struct tb_port *port);
1057 int tb_port_disable(struct tb_port *port);
1058 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
1059 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
1060 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
1061 void tb_port_release_out_hopid(struct tb_port *port, int hopid);
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()
1080 static inline bool tb_port_use_credit_allocation(const struct tb_port *port) in tb_port_use_credit_allocation() argument
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
1087 * @src: Source port
1088 * @dst: Destination port
1089 * @p: Port used as iterator
1091 * Walks over each port on path from @src to @dst.
1098 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1099 * @src: Source port
1100 * @dst: Destination port
1101 * @p: Port used as iterator
1112 int tb_port_get_link_speed(struct tb_port *port);
1113 int tb_port_get_link_generation(struct tb_port *port);
1114 int tb_port_get_link_width(struct tb_port *port);
1115 bool tb_port_width_supported(struct tb_port *port, unsigned int width);
1116 int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
1117 int tb_port_lane_bonding_enable(struct tb_port *port);
1118 void tb_port_lane_bonding_disable(struct tb_port *port);
1119 int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width,
1121 int tb_port_update_credits(struct tb_port *port);
1126 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
1127 int tb_port_next_cap(struct tb_port *port, unsigned int offset);
1128 bool tb_port_is_enabled(struct tb_port *port);
1130 bool tb_usb3_port_is_enabled(struct tb_port *port);
1131 int tb_usb3_port_enable(struct tb_port *port, bool enable);
1133 bool tb_pci_port_is_enabled(struct tb_port *port);
1134 int tb_pci_port_enable(struct tb_port *port, bool enable);
1136 int tb_dp_port_hpd_is_active(struct tb_port *port);
1137 int tb_dp_port_hpd_clear(struct tb_port *port);
1138 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
1140 bool tb_dp_port_is_enabled(struct tb_port *port);
1141 int tb_dp_port_enable(struct tb_port *port, bool enable);
1155 const struct tb_port *port);
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)++)
1172 int tb_lc_configure_port(struct tb_port *port);
1173 void tb_lc_unconfigure_port(struct tb_port *port);
1174 int tb_lc_configure_xdomain(struct tb_port *port);
1175 void tb_lc_unconfigure_xdomain(struct tb_port *port);
1176 int tb_lc_start_lane_initialization(struct tb_port *port);
1177 bool tb_lc_is_clx_supported(struct tb_port *port);
1178 bool tb_lc_is_usb_plugged(struct tb_port *port);
1179 bool tb_lc_is_xhci_connected(struct tb_port *port);
1180 int tb_lc_xhci_connect(struct tb_port *port);
1181 void tb_lc_xhci_disconnect(struct tb_port *port);
1192 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1196 * tb_downstream_route() - get route to downstream switch
1198 * Port must not be the upstream port (otherwise a loop is created).
1200 * Return: Returns a route to the switch behind @port.
1202 static inline u64 tb_downstream_route(struct tb_port *port) in tb_downstream_route() argument
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
1228 * Returns the downstream port the XDomain is connected to.
1232 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1237 int tb_retimer_scan(struct tb_port *port, bool add);
1238 void tb_retimer_remove_all(struct tb_port *port);
1242 return dev->type == &tb_retimer_type; in tb_is_retimer()
1253 * usb4_switch_version() - Returns USB4 version of the router
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
1296 const struct tb_port *port);
1298 const struct tb_port *port);
1302 int usb4_port_unlock(struct tb_port *port);
1303 int usb4_port_hotplug_enable(struct tb_port *port);
1304 int usb4_port_configure(struct tb_port *port);
1305 void usb4_port_unconfigure(struct tb_port *port);
1306 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd);
1307 void usb4_port_unconfigure_xdomain(struct tb_port *port);
1308 int usb4_port_router_offline(struct tb_port *port);
1309 int usb4_port_router_online(struct tb_port *port);
1310 int usb4_port_enumerate_retimers(struct tb_port *port);
1311 bool usb4_port_clx_supported(struct tb_port *port);
1312 int usb4_port_margining_caps(struct tb_port *port, u32 *caps);
1314 bool usb4_port_asym_supported(struct tb_port *port);
1315 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width);
1316 int usb4_port_asym_start(struct tb_port *port);
1318 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes,
1321 int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing,
1323 int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors);
1325 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
1326 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index);
1327 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
1329 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
1331 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
1332 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
1333 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
1335 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
1338 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
1339 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
1341 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
1344 int usb4_usb3_port_max_link_rate(struct tb_port *port);
1345 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
1347 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
1349 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
1352 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id);
1353 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port);
1354 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port);
1355 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port,
1357 int usb4_dp_port_group_id(struct tb_port *port);
1358 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id);
1359 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes);
1360 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes);
1361 int usb4_dp_port_granularity(struct tb_port *port);
1362 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity);
1363 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw);
1364 int usb4_dp_port_allocated_bandwidth(struct tb_port *port);
1365 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw);
1366 int usb4_dp_port_requested_bandwidth(struct tb_port *port);
1368 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
1372 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1382 struct usb4_port *usb4_port_device_add(struct tb_port *port);
1388 return usb4->offline; in usb4_port_device_is_offline()
1404 int tb_acpi_power_on_retimers(struct tb_port *port);
1405 int tb_acpi_power_off_retimers(struct tb_port *port);
1417 static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_on_retimers() argument
1418 static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_off_retimers() argument