Lines Matching +full:port +full:- +full:config

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
113 * struct tb_switch - a thunderbolt switch
115 * @config: Switch configuration
117 * @dma_port: If the switch has port supporting DMA configuration based
142 * @safe_mode: The switch is in safe-mode
173 struct tb_regs_switch_header config; member
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
248 * @config: Cached port configuration read from registers
249 * @sw: Switch the port belongs to
250 * @remote: Remote port (%NULL if not connected)
255 * @cap_usb4: Offset to the USB4 port capability (%0 if not present)
256 * @usb4: Pointer to the USB4 port structure (only if @cap_usb4 is != %0)
257 * @port: Port number on switch
259 * @bonded: true if the port is bonded (two lanes combined as one)
261 * to the other port.
262 * @link_nr: Is this primary or secondary port on the dual_link.
266 * @total_credits: Total number of buffers available for this port
269 * DMA paths through this port.
274 * non-zero.
281 struct tb_regs_port_header config; member
290 u8 port; member
308 * struct usb4_port - USB4 port device
309 * @dev: Device for the port
310 * @port: Pointer to the lane 0 adapter
311 * @can_offline: Does the port have necessary platform support to moved
313 * @offline: The port is currently in offline mode
318 struct tb_port *port; member
330 * @index: Retimer index facing the router USB4 port
333 * @port: Pointer to the lane 0 adapter
345 struct tb_port *port; member
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
360 * the path config space of @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.
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
379 * port.
393 * enum tb_path_port - path options mask
409 * struct tb_path - a unidirectional path between two ports
420 * @clear_fc: Clear all flow control from the path config space entries
424 * @alloc_hopid: Does this path consume port HopID
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.
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
556 * Every switch has an upstream port (for the root switch it is the NHI).
558 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
559 * non root switches (on the NHI port remote is always NULL).
561 * Return: Returns the upstream port of the switch.
565 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
569 * tb_is_upstream_port() - Is the port upstream facing
570 * @port: Port to check
572 * Returns true if @port is upstream facing port. In case of dual link
575 static inline bool tb_is_upstream_port(const struct tb_port *port) in tb_is_upstream_port() argument
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()
583 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
588 u8 port; in tb_port_at() local
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
614 * @port: Port to check
616 * Returns true only when the port is primary port and has remote set.
618 static inline bool tb_port_has_remote(const struct tb_port *port) in tb_port_has_remote() argument
620 if (tb_is_upstream_port(port)) in tb_port_has_remote()
622 if (!port->remote) in tb_port_has_remote()
624 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
630 static inline bool tb_port_is_null(const struct tb_port *port) in tb_port_is_null() argument
632 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
635 static inline bool tb_port_is_nhi(const struct tb_port *port) in tb_port_is_nhi() argument
637 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
640 static inline bool tb_port_is_pcie_down(const struct tb_port *port) in tb_port_is_pcie_down() argument
642 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
645 static inline bool tb_port_is_pcie_up(const struct tb_port *port) in tb_port_is_pcie_up() argument
647 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
650 static inline bool tb_port_is_dpin(const struct tb_port *port) in tb_port_is_dpin() argument
652 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
655 static inline bool tb_port_is_dpout(const struct tb_port *port) in tb_port_is_dpout() argument
657 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
660 static inline bool tb_port_is_usb3_down(const struct tb_port *port) in tb_port_is_usb3_down() argument
662 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
665 static inline bool tb_port_is_usb3_up(const struct tb_port *port) in tb_port_is_usb3_up() argument
667 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
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()
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()
698 static inline int tb_port_read(struct tb_port *port, void *buffer, in tb_port_read() argument
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()
712 static inline int tb_port_write(struct tb_port *port, const void *buffer, in tb_port_write() argument
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)
735 level(__sw->tb, "%llx: " fmt, \
746 level(__port->sw->tb, "%llx:%u: " fmt, \
747 tb_route(__port->sw), __port->port, ## arg); \
749 #define tb_port_WARN(port, fmt, arg...) \ argument
750 __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
751 #define tb_port_warn(port, fmt, arg...) \ argument
752 __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
753 #define tb_port_info(port, fmt, arg...) \ argument
754 __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
755 #define tb_port_dbg(port, fmt, arg...) \ argument
756 __TB_PORT_PRINT(tb_dbg, port, fmt, ##arg)
798 get_device(&tb->dev); in tb_domain_get()
804 put_device(&tb->dev); in tb_domain_put()
852 * tb_switch_for_each_port() - Iterate over each switch port
854 * @p: Port used as iterator
856 * Iterates over each switch port skipping the control port (port %0).
859 for ((p) = &(sw)->ports[1]; \
860 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
865 get_device(&sw->dev); in tb_switch_get()
871 put_device(&sw->dev); in tb_switch_put()
876 return dev->type == &tb_switch_type; in tb_is_switch()
888 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
892 * tb_switch_downstream_port() - Return downstream facing port of parent router
895 * Only call for device routers. Returns the downstream facing port of
906 * tb_switch_depth() - Returns depth of the connected router
911 return sw->config.depth; in tb_switch_depth()
916 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
917 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
922 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
923 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
928 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
929 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
940 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
941 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
952 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
953 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
967 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
968 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
980 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
981 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
993 * tb_switch_is_icm() - Is the switch handled by ICM firmware
1003 return !sw->config.enabled; in tb_switch_is_icm()
1021 * tb_switch_tmu_is_configured() - Is given TMU mode configured
1031 return sw->tmu.mode_request == mode; in tb_switch_tmu_is_configured()
1035 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
1043 return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF && in tb_switch_tmu_is_enabled()
1044 sw->tmu.mode == sw->tmu.mode_request; in tb_switch_tmu_is_enabled()
1047 bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx);
1054 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1066 return sw->clx & clx; in tb_switch_clx_is_enabled()
1074 int tb_port_state(struct tb_port *port);
1075 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
1076 int tb_port_add_nfc_credits(struct tb_port *port, int credits);
1077 int tb_port_clear_counter(struct tb_port *port, int counter);
1078 int tb_port_unlock(struct tb_port *port);
1079 int tb_port_enable(struct tb_port *port);
1080 int tb_port_disable(struct tb_port *port);
1081 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
1082 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
1083 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
1084 void tb_port_release_out_hopid(struct tb_port *port, int hopid);
1089 * tb_port_path_direction_downstream() - Checks if path directed downstream
1100 return src->sw->config.depth < dst->sw->config.depth; in tb_port_path_direction_downstream()
1103 static inline bool tb_port_use_credit_allocation(const struct tb_port *port) in tb_port_use_credit_allocation() argument
1105 return tb_port_is_null(port) && port->sw->credit_allocation; in tb_port_use_credit_allocation()
1109 * tb_for_each_port_on_path() - Iterate over each port on path
1110 * @src: Source port
1111 * @dst: Destination port
1112 * @p: Port used as iterator
1114 * Walks over each port on path from @src to @dst.
1121 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1122 * @src: Source port
1123 * @dst: Destination port
1124 * @p: Port used as iterator
1135 int tb_port_get_link_speed(struct tb_port *port);
1136 int tb_port_get_link_generation(struct tb_port *port);
1137 int tb_port_get_link_width(struct tb_port *port);
1138 bool tb_port_width_supported(struct tb_port *port, unsigned int width);
1139 int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
1140 int tb_port_lane_bonding_enable(struct tb_port *port);
1141 void tb_port_lane_bonding_disable(struct tb_port *port);
1142 int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width,
1144 int tb_port_update_credits(struct tb_port *port);
1149 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
1150 int tb_port_next_cap(struct tb_port *port, unsigned int offset);
1151 bool tb_port_is_enabled(struct tb_port *port);
1153 bool tb_usb3_port_is_enabled(struct tb_port *port);
1154 int tb_usb3_port_enable(struct tb_port *port, bool enable);
1156 bool tb_pci_port_is_enabled(struct tb_port *port);
1157 int tb_pci_port_enable(struct tb_port *port, bool enable);
1159 int tb_dp_port_hpd_is_active(struct tb_port *port);
1160 int tb_dp_port_hpd_clear(struct tb_port *port);
1161 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
1163 bool tb_dp_port_is_enabled(struct tb_port *port);
1164 int tb_dp_port_enable(struct tb_port *port, bool enable);
1176 int tb_path_deactivate_hop(struct tb_port *port, int hop_index);
1179 const struct tb_port *port);
1182 * tb_path_for_each_hop() - Iterate over each hop on path
1189 for ((hop) = &(path)->hops[0]; \
1190 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1196 int tb_lc_reset_port(struct tb_port *port);
1197 int tb_lc_configure_port(struct tb_port *port);
1198 void tb_lc_unconfigure_port(struct tb_port *port);
1199 int tb_lc_configure_xdomain(struct tb_port *port);
1200 void tb_lc_unconfigure_xdomain(struct tb_port *port);
1201 int tb_lc_start_lane_initialization(struct tb_port *port);
1202 bool tb_lc_is_clx_supported(struct tb_port *port);
1203 bool tb_lc_is_usb_plugged(struct tb_port *port);
1204 bool tb_lc_is_xhci_connected(struct tb_port *port);
1205 int tb_lc_xhci_connect(struct tb_port *port);
1206 void tb_lc_xhci_disconnect(struct tb_port *port);
1217 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1221 * tb_downstream_route() - get route to downstream switch
1223 * Port must not be the upstream port (otherwise a loop is created).
1225 * Return: Returns a route to the switch behind @port.
1227 static inline u64 tb_downstream_route(struct tb_port *port) in tb_downstream_route() argument
1229 return tb_route(port->sw) in tb_downstream_route()
1230 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
1246 return tb_to_switch(xd->dev.parent); in tb_xdomain_parent()
1250 * tb_xdomain_downstream_port() - Return downstream facing port of parent router
1253 * Returns the downstream port the XDomain is connected to.
1257 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1262 int tb_retimer_scan(struct tb_port *port, bool add);
1263 void tb_retimer_remove_all(struct tb_port *port);
1267 return dev->type == &tb_retimer_type; in tb_is_retimer()
1278 * usb4_switch_version() - Returns USB4 version of the router
1282 * on). Can be called to pre-USB4 router too and in that case returns %0.
1286 return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); in usb4_switch_version()
1290 * tb_switch_is_usb4() - Is the switch USB4 compliant
1322 const struct tb_port *port);
1324 const struct tb_port *port);
1328 int usb4_port_unlock(struct tb_port *port);
1329 int usb4_port_hotplug_enable(struct tb_port *port);
1330 int usb4_port_reset(struct tb_port *port);
1331 int usb4_port_configure(struct tb_port *port);
1332 void usb4_port_unconfigure(struct tb_port *port);
1333 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd);
1334 void usb4_port_unconfigure_xdomain(struct tb_port *port);
1335 int usb4_port_router_offline(struct tb_port *port);
1336 int usb4_port_router_online(struct tb_port *port);
1337 int usb4_port_enumerate_retimers(struct tb_port *port);
1338 bool usb4_port_clx_supported(struct tb_port *port);
1340 bool usb4_port_asym_supported(struct tb_port *port);
1341 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width);
1342 int usb4_port_asym_start(struct tb_port *port);
1345 * enum tb_sb_target - Sideband transaction target
1356 int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index,
1358 int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
1362 * enum usb4_margin_sw_error_counter - Software margining error counter operation
1383 * struct usb4_port_margining_params - USB4 margining parameters
1403 int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target,
1405 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target,
1408 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target,
1411 int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target,
1414 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
1415 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index);
1416 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
1417 int usb4_port_retimer_is_cable(struct tb_port *port, u8 index);
1418 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
1419 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
1421 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
1424 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
1425 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
1427 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
1430 int usb4_usb3_port_max_link_rate(struct tb_port *port);
1431 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
1433 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
1435 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
1438 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id);
1439 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port);
1440 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port);
1441 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port,
1443 int usb4_dp_port_group_id(struct tb_port *port);
1444 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id);
1445 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes);
1446 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes);
1447 int usb4_dp_port_granularity(struct tb_port *port);
1448 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity);
1449 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw);
1450 int usb4_dp_port_allocated_bandwidth(struct tb_port *port);
1451 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw);
1452 int usb4_dp_port_requested_bandwidth(struct tb_port *port);
1454 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
1458 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1468 struct usb4_port *usb4_port_device_add(struct tb_port *port);
1474 return usb4->offline; in usb4_port_device_is_offline()
1490 int tb_acpi_power_on_retimers(struct tb_port *port);
1491 int tb_acpi_power_off_retimers(struct tb_port *port);
1503 static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_on_retimers() argument
1504 static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_off_retimers() argument