Lines Matching +full:port +full:- +full:specific

1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
12 #include <linux/nvmem-provider.h>
26 /* Need to keep power on while USB4 port is in redrive mode */
30 * struct tb_nvm - Structure holding NVM information
37 * @non_active: Non-active portion NVMem device
46 * @vops: Router vendor specific NVM operations (optional)
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
116 * @dma_port: If the switch has port supporting DMA configuration based
133 * @cap_vsec_tmu: Offset to the TMU vendor specific capability (%0 if not found)
140 * @safe_mode: The switch is in safe-mode
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)
239 * @cap_tmu: Offset of the adapter specific TMU capability (%0 if not present)
240 * @cap_adap: Offset of the adapter specific capability (%0 if not present)
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.
276 u8 port; member
294 * struct usb4_port - USB4 port device
295 * @dev: Device for the port
296 * @port: Pointer to the lane 0 adapter
297 * @can_offline: Does the port have necessary platform support to moved
299 * @offline: The port is currently in offline mode
304 struct tb_port *port; member
316 * @index: Retimer index facing the router USB4 port
319 * @port: Pointer to the lane 0 adapter
330 struct tb_port *port; member
337 * struct tb_path_hop - routing information for a tb_path
338 * @in_port: Ingress port of a switch
339 * @out_port: Egress port of a switch where the packet is routed out
344 * currently, %-1 to disable)
348 * @nfc_credits: Number of non-flow controlled buffers allocated for the
351 * Hop configuration is always done on the IN port of a switch.
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
360 * port.
373 * enum tb_path_port - path options mask
389 * struct tb_path - a unidirectional path between two ports
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
455 * @suspend_noirq: Connection manager specific suspend_noirq
456 * @resume_noirq: Connection manager specific resume_noirq
457 * @suspend: Connection manager specific suspend
458 * @freeze_noirq: Connection manager specific freeze_noirq
459 * @thaw_noirq: Connection manager specific thaw_noirq
460 * @complete: Connection manager specific complete
461 * @runtime_suspend: Connection manager specific runtime_suspend
462 * @runtime_resume: Connection manager specific runtime_resume
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()
574 * tb_port_has_remote() - Does the port have switch connected downstream
575 * @port: Port to check
577 * Returns true only when the port is primary port and has remote set.
579 static inline bool tb_port_has_remote(const struct tb_port *port) in tb_port_has_remote() argument
581 if (tb_is_upstream_port(port)) in tb_port_has_remote()
583 if (!port->remote) in tb_port_has_remote()
585 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
591 static inline bool tb_port_is_null(const struct tb_port *port) in tb_port_is_null() argument
593 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
596 static inline bool tb_port_is_nhi(const struct tb_port *port) in tb_port_is_nhi() argument
598 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
601 static inline bool tb_port_is_pcie_down(const struct tb_port *port) in tb_port_is_pcie_down() argument
603 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
606 static inline bool tb_port_is_pcie_up(const struct tb_port *port) in tb_port_is_pcie_up() argument
608 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
611 static inline bool tb_port_is_dpin(const struct tb_port *port) in tb_port_is_dpin() argument
613 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
616 static inline bool tb_port_is_dpout(const struct tb_port *port) in tb_port_is_dpout() argument
618 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
621 static inline bool tb_port_is_usb3_down(const struct tb_port *port) in tb_port_is_usb3_down() argument
623 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
626 static inline bool tb_port_is_usb3_up(const struct tb_port *port) in tb_port_is_usb3_up() argument
628 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
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()
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()
659 static inline int tb_port_read(struct tb_port *port, void *buffer, in tb_port_read() argument
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()
673 static inline int tb_port_write(struct tb_port *port, const void *buffer, in tb_port_write() argument
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)
696 level(__sw->tb, "%llx: " fmt, \
707 level(__port->sw->tb, "%llx:%u: " fmt, \
708 tb_route(__port->sw), __port->port, ## arg); \
710 #define tb_port_WARN(port, fmt, arg...) \ argument
711 __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
712 #define tb_port_warn(port, fmt, arg...) \ argument
713 __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
714 #define tb_port_info(port, fmt, arg...) \ argument
715 __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
716 #define tb_port_dbg(port, fmt, arg...) \ argument
717 __TB_PORT_PRINT(tb_dbg, port, fmt, ##arg)
759 get_device(&tb->dev); in tb_domain_get()
765 put_device(&tb->dev); in tb_domain_put()
813 * tb_switch_for_each_port() - Iterate over each switch port
815 * @p: Port used as iterator
817 * Iterates over each switch port skipping the control port (port %0).
820 for ((p) = &(sw)->ports[1]; \
821 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
826 get_device(&sw->dev); in tb_switch_get()
832 put_device(&sw->dev); in tb_switch_put()
837 return dev->type == &tb_switch_type; in tb_is_switch()
849 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
853 * tb_switch_downstream_port() - Return downstream facing port of parent router
856 * Only call for device routers. Returns the downstream facing port of
867 * tb_switch_depth() - Returns depth of the connected router
872 return sw->config.depth; in tb_switch_depth()
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()
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()
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()
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()
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()
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()
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
964 return !sw->config.enabled; in tb_switch_is_icm()
982 * tb_switch_tmu_is_configured() - Is given TMU mode configured
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
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()
1008 bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx);
1016 * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
1028 return sw->clx & clx; in tb_switch_clx_is_enabled()
1036 int tb_port_state(struct tb_port *port);
1037 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
1038 int tb_port_add_nfc_credits(struct tb_port *port, int credits);
1039 int tb_port_clear_counter(struct tb_port *port, int counter);
1040 int tb_port_unlock(struct tb_port *port);
1041 int tb_port_enable(struct tb_port *port);
1042 int tb_port_disable(struct tb_port *port);
1043 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
1044 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
1045 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
1046 void tb_port_release_out_hopid(struct tb_port *port, int hopid);
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()
1065 static inline bool tb_port_use_credit_allocation(const struct tb_port *port) in tb_port_use_credit_allocation() argument
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
1072 * @src: Source port
1073 * @dst: Destination port
1074 * @p: Port used as iterator
1076 * Walks over each port on path from @src to @dst.
1083 * tb_for_each_upstream_port_on_path() - Iterate over each upstreamm port on path
1084 * @src: Source port
1085 * @dst: Destination port
1086 * @p: Port used as iterator
1097 int tb_port_get_link_speed(struct tb_port *port);
1098 int tb_port_get_link_generation(struct tb_port *port);
1099 int tb_port_get_link_width(struct tb_port *port);
1100 bool tb_port_width_supported(struct tb_port *port, unsigned int width);
1101 int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
1102 int tb_port_lane_bonding_enable(struct tb_port *port);
1103 void tb_port_lane_bonding_disable(struct tb_port *port);
1104 int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width,
1106 int tb_port_update_credits(struct tb_port *port);
1111 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
1112 int tb_port_next_cap(struct tb_port *port, unsigned int offset);
1113 bool tb_port_is_enabled(struct tb_port *port);
1115 bool tb_usb3_port_is_enabled(struct tb_port *port);
1116 int tb_usb3_port_enable(struct tb_port *port, bool enable);
1118 bool tb_pci_port_is_enabled(struct tb_port *port);
1119 int tb_pci_port_enable(struct tb_port *port, bool enable);
1121 int tb_dp_port_hpd_is_active(struct tb_port *port);
1122 int tb_dp_port_hpd_clear(struct tb_port *port);
1123 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
1125 bool tb_dp_port_is_enabled(struct tb_port *port);
1126 int tb_dp_port_enable(struct tb_port *port, bool enable);
1138 int tb_path_deactivate_hop(struct tb_port *port, int hop_index);
1141 const struct tb_port *port);
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)++)
1158 int tb_lc_reset_port(struct tb_port *port);
1159 int tb_lc_configure_port(struct tb_port *port);
1160 void tb_lc_unconfigure_port(struct tb_port *port);
1161 int tb_lc_configure_xdomain(struct tb_port *port);
1162 void tb_lc_unconfigure_xdomain(struct tb_port *port);
1163 int tb_lc_start_lane_initialization(struct tb_port *port);
1164 bool tb_lc_is_clx_supported(struct tb_port *port);
1165 bool tb_lc_is_usb_plugged(struct tb_port *port);
1166 bool tb_lc_is_xhci_connected(struct tb_port *port);
1167 int tb_lc_xhci_connect(struct tb_port *port);
1168 void tb_lc_xhci_disconnect(struct tb_port *port);
1179 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
1183 * tb_downstream_route() - get route to downstream switch
1185 * Port must not be the upstream port (otherwise a loop is created).
1187 * Return: Returns a route to the switch behind @port.
1189 static inline u64 tb_downstream_route(struct tb_port *port) in tb_downstream_route() argument
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
1215 * Returns the downstream port the XDomain is connected to.
1219 return tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_downstream_port()
1224 int tb_retimer_scan(struct tb_port *port, bool add);
1225 void tb_retimer_remove_all(struct tb_port *port);
1229 return dev->type == &tb_retimer_type; in tb_is_retimer()
1240 * usb4_switch_version() - Returns USB4 version of the router
1244 * on). Can be called to pre-USB4 router too and in that case returns %0.
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
1284 const struct tb_port *port);
1286 const struct tb_port *port);
1290 int usb4_port_unlock(struct tb_port *port);
1291 int usb4_port_hotplug_enable(struct tb_port *port);
1292 int usb4_port_reset(struct tb_port *port);
1293 int usb4_port_configure(struct tb_port *port);
1294 void usb4_port_unconfigure(struct tb_port *port);
1295 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd);
1296 void usb4_port_unconfigure_xdomain(struct tb_port *port);
1297 int usb4_port_router_offline(struct tb_port *port);
1298 int usb4_port_router_online(struct tb_port *port);
1299 int usb4_port_enumerate_retimers(struct tb_port *port);
1300 bool usb4_port_clx_supported(struct tb_port *port);
1301 int usb4_port_margining_caps(struct tb_port *port, u32 *caps);
1303 bool usb4_port_asym_supported(struct tb_port *port);
1304 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width);
1305 int usb4_port_asym_start(struct tb_port *port);
1307 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes,
1310 int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing,
1312 int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors);
1314 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
1315 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index);
1316 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
1318 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
1320 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
1321 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
1322 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
1324 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
1327 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
1328 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
1330 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
1333 int usb4_usb3_port_max_link_rate(struct tb_port *port);
1334 int usb4_usb3_port_actual_link_rate(struct tb_port *port);
1335 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
1337 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
1339 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
1342 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id);
1343 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port);
1344 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port);
1345 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port,
1347 int usb4_dp_port_group_id(struct tb_port *port);
1348 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id);
1349 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes);
1350 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes);
1351 int usb4_dp_port_granularity(struct tb_port *port);
1352 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity);
1353 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw);
1354 int usb4_dp_port_allocated_bandwidth(struct tb_port *port);
1355 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw);
1356 int usb4_dp_port_requested_bandwidth(struct tb_port *port);
1358 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
1362 return dev->type == &usb4_port_device_type; in tb_is_usb4_port_device()
1372 struct usb4_port *usb4_port_device_add(struct tb_port *port);
1378 return usb4->offline; in usb4_port_device_is_offline()
1394 int tb_acpi_power_on_retimers(struct tb_port *port);
1395 int tb_acpi_power_off_retimers(struct tb_port *port);
1407 static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_on_retimers() argument
1408 static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; } in tb_acpi_power_off_retimers() argument