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>
24 /* Intel specific NVM offsets */
30 * struct tb_nvm - Structure holding NVM information
36 * @non_active: Non-active portion NVMem device
65 * enum tb_switch_tmu_rate - TMU refresh rate
81 * struct tb_switch_tmu - Structure holding switch TMU configuration
83 * @has_ucap: Does the switch support uni-directional mode
86 * @unidirectional: Is the TMU in uni-directional or bi-directional mode
97 * struct tb_switch - a thunderbolt switch
101 * @dma_port: If the switch has port supporting DMA configuration based
123 * @safe_mode: The switch is in safe-mode
181 * struct tb_port - a thunderbolt port, part of a tb_switch
182 * @config: Cached port configuration read from registers
183 * @sw: Switch the port belongs to
184 * @remote: Remote port (%NULL if not connected)
187 * @cap_tmu: Offset of the adapter specific TMU capability (%0 if not present)
188 * @cap_adap: Offset of the adapter specific capability (%0 if not present)
189 * @cap_usb4: Offset to the USB4 port capability (%0 if not present)
190 * @port: Port number on switch
192 * @bonded: true if the port is bonded (two lanes combined as one)
194 * to the other port.
195 * @link_nr: Is this primary or secondary port on the dual_link.
209 u8 port; member
223 * @index: Retimer index facing the router USB4 port
226 * @port: Pointer to the lane 0 adapter
236 struct tb_port *port; member
242 * struct tb_path_hop - routing information for a tb_path
243 * @in_port: Ingress port of a switch
244 * @out_port: Egress port of a switch where the packet is routed out
249 * currently, %-1 to disable)
254 * Hop configuration is always done on the IN port of a switch.
257 * next hop to take (on out_port->remote) is determined by
258 * next_hop_index. When routing packet to another switch (out->remote is
263 * port.
275 * enum tb_path_port - path options mask
291 * struct tb_path - a unidirectional path between two ports
330 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
346 * struct tb_cm_ops - Connection manager specific operations vector
351 * @suspend_noirq: Connection manager specific suspend_noirq
352 * @resume_noirq: Connection manager specific resume_noirq
353 * @suspend: Connection manager specific suspend
354 * @freeze_noirq: Connection manager specific freeze_noirq
355 * @thaw_noirq: Connection manager specific thaw_noirq
356 * @complete: Connection manager specific complete
357 * @runtime_suspend: Connection manager specific runtime_suspend
358 * @runtime_resume: Connection manager specific runtime_resume
400 return (void *)tb->privdata; in tb_priv()
408 * tb_upstream_port() - return the upstream port of a switch
410 * Every switch has an upstream port (for the root switch it is the NHI).
412 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
413 * non root switches (on the NHI port remote is always NULL).
415 * Return: Returns the upstream port of the switch.
419 return &sw->ports[sw->config.upstream_port_number]; in tb_upstream_port()
423 * tb_is_upstream_port() - Is the port upstream facing
424 * @port: Port to check
426 * Returns true if @port is upstream facing port. In case of dual link
429 static inline bool tb_is_upstream_port(const struct tb_port *port) in tb_is_upstream_port() argument
431 const struct tb_port *upstream_port = tb_upstream_port(port->sw); in tb_is_upstream_port()
432 return port == upstream_port || port->dual_link_port == upstream_port; in tb_is_upstream_port()
437 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo; in tb_route()
442 u8 port; in tb_port_at() local
444 port = route >> (sw->config.depth * 8); in tb_port_at()
445 if (WARN_ON(port > sw->config.max_port_number)) in tb_port_at()
447 return &sw->ports[port]; in tb_port_at()
451 * tb_port_has_remote() - Does the port have switch connected downstream
452 * @port: Port to check
454 * Returns true only when the port is primary port and has remote set.
456 static inline bool tb_port_has_remote(const struct tb_port *port) in tb_port_has_remote() argument
458 if (tb_is_upstream_port(port)) in tb_port_has_remote()
460 if (!port->remote) in tb_port_has_remote()
462 if (port->dual_link_port && port->link_nr) in tb_port_has_remote()
468 static inline bool tb_port_is_null(const struct tb_port *port) in tb_port_is_null() argument
470 return port && port->port && port->config.type == TB_TYPE_PORT; in tb_port_is_null()
473 static inline bool tb_port_is_nhi(const struct tb_port *port) in tb_port_is_nhi() argument
475 return port && port->config.type == TB_TYPE_NHI; in tb_port_is_nhi()
478 static inline bool tb_port_is_pcie_down(const struct tb_port *port) in tb_port_is_pcie_down() argument
480 return port && port->config.type == TB_TYPE_PCIE_DOWN; in tb_port_is_pcie_down()
483 static inline bool tb_port_is_pcie_up(const struct tb_port *port) in tb_port_is_pcie_up() argument
485 return port && port->config.type == TB_TYPE_PCIE_UP; in tb_port_is_pcie_up()
488 static inline bool tb_port_is_dpin(const struct tb_port *port) in tb_port_is_dpin() argument
490 return port && port->config.type == TB_TYPE_DP_HDMI_IN; in tb_port_is_dpin()
493 static inline bool tb_port_is_dpout(const struct tb_port *port) in tb_port_is_dpout() argument
495 return port && port->config.type == TB_TYPE_DP_HDMI_OUT; in tb_port_is_dpout()
498 static inline bool tb_port_is_usb3_down(const struct tb_port *port) in tb_port_is_usb3_down() argument
500 return port && port->config.type == TB_TYPE_USB3_DOWN; in tb_port_is_usb3_down()
503 static inline bool tb_port_is_usb3_up(const struct tb_port *port) in tb_port_is_usb3_up() argument
505 return port && port->config.type == TB_TYPE_USB3_UP; in tb_port_is_usb3_up()
511 if (sw->is_unplugged) in tb_sw_read()
512 return -ENODEV; in tb_sw_read()
513 return tb_cfg_read(sw->tb->ctl, in tb_sw_read()
525 if (sw->is_unplugged) in tb_sw_write()
526 return -ENODEV; in tb_sw_write()
527 return tb_cfg_write(sw->tb->ctl, in tb_sw_write()
536 static inline int tb_port_read(struct tb_port *port, void *buffer, in tb_port_read() argument
539 if (port->sw->is_unplugged) in tb_port_read()
540 return -ENODEV; in tb_port_read()
541 return tb_cfg_read(port->sw->tb->ctl, in tb_port_read()
543 tb_route(port->sw), in tb_port_read()
544 port->port, in tb_port_read()
550 static inline int tb_port_write(struct tb_port *port, const void *buffer, in tb_port_write() argument
553 if (port->sw->is_unplugged) in tb_port_write()
554 return -ENODEV; in tb_port_write()
555 return tb_cfg_write(port->sw->tb->ctl, in tb_port_write()
557 tb_route(port->sw), in tb_port_write()
558 port->port, in tb_port_write()
564 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
565 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
566 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
567 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
568 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
573 level(__sw->tb, "%llx: " fmt, \
584 level(__port->sw->tb, "%llx:%x: " fmt, \
585 tb_route(__port->sw), __port->port, ## arg); \
587 #define tb_port_WARN(port, fmt, arg...) \ argument
588 __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
589 #define tb_port_warn(port, fmt, arg...) \ argument
590 __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
591 #define tb_port_info(port, fmt, arg...) \ argument
592 __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
593 #define tb_port_dbg(port, fmt, arg...) \ argument
594 __TB_PORT_PRINT(tb_dbg, port, fmt, ##arg)
630 get_device(&tb->dev); in tb_domain_get()
636 put_device(&tb->dev); in tb_domain_put()
667 * tb_switch_for_each_port() - Iterate over each switch port
669 * @p: Port used as iterator
671 * Iterates over each switch port skipping the control port (port %0).
674 for ((p) = &(sw)->ports[1]; \
675 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
680 get_device(&sw->dev); in tb_switch_get()
686 put_device(&sw->dev); in tb_switch_put()
691 return dev->type == &tb_switch_type; in tb_is_switch()
703 return tb_to_switch(sw->dev.parent); in tb_switch_parent()
708 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_light_ridge()
709 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE; in tb_switch_is_light_ridge()
714 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL && in tb_switch_is_eagle_ridge()
715 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE; in tb_switch_is_eagle_ridge()
720 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_cactus_ridge()
721 switch (sw->config.device_id) { in tb_switch_is_cactus_ridge()
732 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_falcon_ridge()
733 switch (sw->config.device_id) { in tb_switch_is_falcon_ridge()
744 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_alpine_ridge()
745 switch (sw->config.device_id) { in tb_switch_is_alpine_ridge()
758 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_titan_ridge()
759 switch (sw->config.device_id) { in tb_switch_is_titan_ridge()
771 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_ice_lake()
772 switch (sw->config.device_id) { in tb_switch_is_ice_lake()
783 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_is_tiger_lake()
784 switch (sw->config.device_id) { in tb_switch_is_tiger_lake()
796 * tb_switch_is_usb4() - Is the switch USB4 compliant
803 return sw->config.thunderbolt_version == USB4_VERSION_1_0; in tb_switch_is_usb4()
807 * tb_switch_is_icm() - Is the switch handled by ICM firmware
817 return !sw->config.enabled; in tb_switch_is_icm()
836 return sw->tmu.rate == TB_SWITCH_TMU_RATE_HIFI && in tb_switch_tmu_is_enabled()
837 !sw->tmu.unidirectional; in tb_switch_tmu_is_enabled()
840 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
841 int tb_port_add_nfc_credits(struct tb_port *port, int credits);
842 int tb_port_set_initial_credits(struct tb_port *port, u32 credits);
843 int tb_port_clear_counter(struct tb_port *port, int counter);
844 int tb_port_unlock(struct tb_port *port);
845 int tb_port_enable(struct tb_port *port);
846 int tb_port_disable(struct tb_port *port);
847 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
848 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
849 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
850 void tb_port_release_out_hopid(struct tb_port *port, int hopid);
855 * tb_for_each_port_on_path() - Iterate over each port on path
856 * @src: Source port
857 * @dst: Destination port
858 * @p: Port used as iterator
860 * Walks over each port on path from @src to @dst.
866 int tb_port_get_link_speed(struct tb_port *port);
871 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
872 int tb_port_next_cap(struct tb_port *port, unsigned int offset);
873 bool tb_port_is_enabled(struct tb_port *port);
875 bool tb_usb3_port_is_enabled(struct tb_port *port);
876 int tb_usb3_port_enable(struct tb_port *port, bool enable);
878 bool tb_pci_port_is_enabled(struct tb_port *port);
879 int tb_pci_port_enable(struct tb_port *port, bool enable);
881 int tb_dp_port_hpd_is_active(struct tb_port *port);
882 int tb_dp_port_hpd_clear(struct tb_port *port);
883 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
885 bool tb_dp_port_is_enabled(struct tb_port *port);
886 int tb_dp_port_enable(struct tb_port *port, bool enable);
899 const struct tb_port *port);
905 int tb_lc_configure_port(struct tb_port *port);
906 void tb_lc_unconfigure_port(struct tb_port *port);
907 int tb_lc_configure_xdomain(struct tb_port *port);
908 void tb_lc_unconfigure_xdomain(struct tb_port *port);
919 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT; in tb_route_length()
923 * tb_downstream_route() - get route to downstream switch
925 * Port must not be the upstream port (otherwise a loop is created).
927 * Return: Returns a route to the switch behind @port.
929 static inline u64 tb_downstream_route(struct tb_port *port) in tb_downstream_route() argument
931 return tb_route(port->sw) in tb_downstream_route()
932 | ((u64) port->port << (port->sw->config.depth * 8)); in tb_downstream_route()
945 int tb_retimer_scan(struct tb_port *port);
946 void tb_retimer_remove_all(struct tb_port *port);
950 return dev->type == &tb_retimer_type; in tb_is_retimer()
977 const struct tb_port *port);
979 const struct tb_port *port);
981 int usb4_port_unlock(struct tb_port *port);
982 int usb4_port_hotplug_enable(struct tb_port *port);
983 int usb4_port_configure(struct tb_port *port);
984 void usb4_port_unconfigure(struct tb_port *port);
985 int usb4_port_configure_xdomain(struct tb_port *port);
986 void usb4_port_unconfigure_xdomain(struct tb_port *port);
987 int usb4_port_enumerate_retimers(struct tb_port *port);
989 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
991 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
993 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
994 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
995 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
998 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
999 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
1001 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
1004 int usb4_usb3_port_max_link_rate(struct tb_port *port);
1005 int usb4_usb3_port_actual_link_rate(struct tb_port *port);
1006 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
1008 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
1010 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,