| 1 |
|
| 2 | |
| 3 | * Thunderbolt driver - bus logic (NHI independent)
|
| 4 | *
|
| 5 | * Copyright (c) 2014 Andreas Noever <[email protected]>
|
| 6 | * Copyright (C) 2018, Intel Corporation
|
| 7 |
|
| 8 |
|
| 9 | #ifndef TB_H_
|
| 10 | #define TB_H_
|
| 11 |
|
| 12 | #include <linux/debugfs.h>
|
| 13 | #include <linux/nvmem-provider.h>
|
| 14 | #include <linux/pci.h>
|
| 15 | #include <linux/thunderbolt.h>
|
| 16 | #include <linux/uuid.h>
|
| 17 | #include <linux/bitfield.h>
|
| 18 |
|
| 19 | #include "tb_regs.h"
|
| 20 | #include "ctl.h"
|
| 21 | #include "dma_port.h"
|
| 22 |
|
| 23 |
|
| 24 | #define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0)
|
| 25 |
|
| 26 | #define QUIRK_NO_CLX BIT(1)
|
| 27 |
|
| 28 | #define QUIRK_KEEP_POWER_IN_DP_REDRIVE BIT(2)
|
| 29 |
|
| 30 | |
| 31 | * struct tb_nvm - Structure holding NVM information
|
| 32 | * @dev: Owner of the NVM
|
| 33 | * @major: Major version number of the active NVM portion
|
| 34 | * @minor: Minor version number of the active NVM portion
|
| 35 | * @id: Identifier used with both NVM portions
|
| 36 | * @active: Active portion NVMem device
|
| 37 | * @active_size: Size in bytes of the active NVM
|
| 38 | * @non_active: Non-active portion NVMem device
|
| 39 | * @buf: Buffer where the NVM image is stored before it is written to
|
| 40 | * the actual NVM flash device
|
| 41 | * @buf_data_start: Where the actual image starts after skipping
|
| 42 | * possible headers
|
| 43 | * @buf_data_size: Number of bytes actually consumed by the new NVM
|
| 44 | * image
|
| 45 | * @authenticating: The device is authenticating the new NVM
|
| 46 | * @flushed: The image has been flushed to the storage area
|
| 47 | * @vops: Router vendor specific NVM operations (optional)
|
| 48 | *
|
| 49 | * The user of this structure needs to handle serialization of possible
|
| 50 | * concurrent access.
|
| 51 |
|
| 52 | struct tb_nvm {
|
| 53 | struct device *dev;
|
| 54 | u32 major;
|
| 55 | u32 minor;
|
| 56 | int id;
|
| 57 | struct nvmem_device *active;
|
| 58 | size_t active_size;
|
| 59 | struct nvmem_device *non_active;
|
| 60 | void *buf;
|
| 61 | void *buf_data_start;
|
| 62 | size_t buf_data_size;
|
| 63 | bool authenticating;
|
| 64 | bool flushed;
|
| 65 | const struct tb_nvm_vendor_ops *vops;
|
| 66 | };
|
| 67 |
|
| 68 | enum tb_nvm_write_ops {
|
| 69 | WRITE_AND_AUTHENTICATE = 1,
|
| 70 | WRITE_ONLY = 2,
|
| 71 | AUTHENTICATE_ONLY = 3,
|
| 72 | };
|
| 73 |
|
| 74 | #define TB_SWITCH_KEY_SIZE 32
|
| 75 | #define TB_SWITCH_MAX_DEPTH 6
|
| 76 | #define USB4_SWITCH_MAX_DEPTH 5
|
| 77 |
|
| 78 | |
| 79 | * enum tb_switch_tmu_mode - TMU mode
|
| 80 | * @TB_SWITCH_TMU_MODE_OFF: TMU is off
|
| 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
|
| 85 | *
|
| 86 | * Ordering is based on TMU accuracy level (highest last).
|
| 87 |
|
| 88 | enum tb_switch_tmu_mode {
|
| 89 | TB_SWITCH_TMU_MODE_OFF,
|
| 90 | TB_SWITCH_TMU_MODE_LOWRES,
|
| 91 | TB_SWITCH_TMU_MODE_HIFI_UNI,
|
| 92 | TB_SWITCH_TMU_MODE_HIFI_BI,
|
| 93 | TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI,
|
| 94 | };
|
| 95 |
|
| 96 | |
| 97 | * struct tb_switch_tmu - Structure holding router TMU configuration
|
| 98 | * @cap: Offset to the TMU capability (%0 if not found)
|
| 99 | * @has_ucap: Does the switch support uni-directional mode
|
| 100 | * @mode: TMU mode related to the upstream router. Reflects the HW
|
| 101 | * setting. Don't care for host router.
|
| 102 | * @mode_request: TMU mode requested to set. Related to upstream router.
|
| 103 | * Don't care for host router.
|
| 104 |
|
| 105 | struct tb_switch_tmu {
|
| 106 | int cap;
|
| 107 | bool has_ucap;
|
| 108 | enum tb_switch_tmu_mode mode;
|
| 109 | enum tb_switch_tmu_mode mode_request;
|
| 110 | };
|
| 111 |
|
| 112 | |
| 113 | * struct tb_switch - a thunderbolt switch
|
| 114 | * @dev: Device for the switch
|
| 115 | * @config: Switch configuration
|
| 116 | * @ports: Ports in this switch
|
| 117 | * @dma_port: If the switch has port supporting DMA configuration based
|
| 118 | * mailbox this will hold the pointer to that (%NULL
|
| 119 | * otherwise). If set it also means the switch has
|
| 120 | * upgradeable NVM.
|
| 121 | * @tmu: The switch TMU configuration
|
| 122 | * @tb: Pointer to the domain the switch belongs to
|
| 123 | * @uid: Unique ID of the switch
|
| 124 | * @uuid: UUID of the switch (or %NULL if not supported)
|
| 125 | * @vendor: Vendor ID of the switch
|
| 126 | * @device: Device ID of the switch
|
| 127 | * @vendor_name: Name of the vendor (or %NULL if not known)
|
| 128 | * @device_name: Name of the device (or %NULL if not known)
|
| 129 | * @link_speed: Speed of the link in Gb/s
|
| 130 | * @link_width: Width of the upstream facing link
|
| 131 | * @preferred_link_width: Router preferred link width (only set for Gen 4 links)
|
| 132 | * @link_usb4: Upstream link is USB4
|
| 133 | * @generation: Switch Thunderbolt generation
|
| 134 | * @cap_plug_events: Offset to the plug events capability (%0 if not found)
|
| 135 | * @cap_vsec_tmu: Offset to the TMU vendor specific capability (%0 if not found)
|
| 136 | * @cap_lc: Offset to the link controller capability (%0 if not found)
|
| 137 | * @cap_lp: Offset to the low power (CLx for TBT) capability (%0 if not found)
|
| 138 | * @is_unplugged: The switch is going away
|
| 139 | * @drom: DROM of the switch (%NULL if not found)
|
| 140 | * @nvm: Pointer to the NVM if the switch has one (%NULL otherwise)
|
| 141 | * @no_nvm_upgrade: Prevent NVM upgrade of this switch
|
| 142 | * @safe_mode: The switch is in safe-mode
|
| 143 | * @boot: Whether the switch was already authorized on boot or not
|
| 144 | * @rpm: The switch supports runtime PM
|
| 145 | * @authorized: Whether the switch is authorized by user or policy
|
| 146 | * @security_level: Switch supported security level
|
| 147 | * @debugfs_dir: Pointer to the debugfs structure
|
| 148 | * @key: Contains the key used to challenge the device or %NULL if not
|
| 149 | * supported. Size of the key is %TB_SWITCH_KEY_SIZE.
|
| 150 | * @connection_id: Connection ID used with ICM messaging
|
| 151 | * @connection_key: Connection key used with ICM messaging
|
| 152 | * @link: Root switch link this switch is connected (ICM only)
|
| 153 | * @depth: Depth in the chain this switch is connected (ICM only)
|
| 154 | * @rpm_complete: Completion used to wait for runtime resume to
|
| 155 | * complete (ICM only)
|
| 156 | * @quirks: Quirks used for this Thunderbolt switch
|
| 157 | * @credit_allocation: Are the below buffer allocation parameters valid
|
| 158 | * @max_usb3_credits: Router preferred number of buffers for USB 3.x
|
| 159 | * @min_dp_aux_credits: Router preferred minimum number of buffers for DP AUX
|
| 160 | * @min_dp_main_credits: Router preferred minimum number of buffers for DP MAIN
|
| 161 | * @max_pcie_credits: Router preferred number of buffers for PCIe
|
| 162 | * @max_dma_credits: Router preferred number of buffers for DMA/P2P
|
| 163 | * @clx: CLx states on the upstream link of the router
|
| 164 | * @drom_blob: DROM debugfs blob wrapper
|
| 165 | *
|
| 166 | * When the switch is being added or removed to the domain (other
|
| 167 | * switches) you need to have domain lock held.
|
| 168 | *
|
| 169 | * In USB4 terminology this structure represents a router.
|
| 170 |
|
| 171 | struct tb_switch {
|
| 172 | struct device dev;
|
| 173 | struct tb_regs_switch_header config;
|
| 174 | struct tb_port *ports;
|
| 175 | struct tb_dma_port *dma_port;
|
| 176 | struct tb_switch_tmu tmu;
|
| 177 | struct tb *tb;
|
| 178 | u64 uid;
|
| 179 | uuid_t *uuid;
|
| 180 | u16 vendor;
|
| 181 | u16 device;
|
| 182 | const char *vendor_name;
|
| 183 | const char *device_name;
|
| 184 | unsigned int link_speed;
|
| 185 | enum tb_link_width link_width;
|
| 186 | enum tb_link_width preferred_link_width;
|
| 187 | bool link_usb4;
|
| 188 | unsigned int generation;
|
| 189 | int cap_plug_events;
|
| 190 | int cap_vsec_tmu;
|
| 191 | int cap_lc;
|
| 192 | int cap_lp;
|
| 193 | bool is_unplugged;
|
| 194 | u8 *drom;
|
| 195 | struct tb_nvm *nvm;
|
| 196 | bool no_nvm_upgrade;
|
| 197 | bool safe_mode;
|
| 198 | bool boot;
|
| 199 | bool rpm;
|
| 200 | unsigned int authorized;
|
| 201 | enum tb_security_level security_level;
|
| 202 | struct dentry *debugfs_dir;
|
| 203 | u8 *key;
|
| 204 | u8 connection_id;
|
| 205 | u8 connection_key;
|
| 206 | u8 link;
|
| 207 | u8 depth;
|
| 208 | struct completion rpm_complete;
|
| 209 | unsigned long quirks;
|
| 210 | bool credit_allocation;
|
| 211 | unsigned int max_usb3_credits;
|
| 212 | unsigned int min_dp_aux_credits;
|
| 213 | unsigned int min_dp_main_credits;
|
| 214 | unsigned int max_pcie_credits;
|
| 215 | unsigned int max_dma_credits;
|
| 216 | unsigned int clx;
|
| 217 | #ifdef CONFIG_DEBUG_FS
|
| 218 | struct debugfs_blob_wrapper drom_blob;
|
| 219 | #endif
|
| 220 | };
|
| 221 |
|
| 222 | |
| 223 | * struct tb_bandwidth_group - Bandwidth management group
|
| 224 | * @tb: Pointer to the domain the group belongs to
|
| 225 | * @index: Index of the group (aka Group_ID). Valid values %1-%7
|
| 226 | * @ports: DP IN adapters belonging to this group are linked here
|
| 227 | * @reserved: Bandwidth released by one tunnel in the group, available
|
| 228 | * to others. This is reported as part of estimated_bw for
|
| 229 | * the group.
|
| 230 | * @release_work: Worker to release the @reserved if it is not used by
|
| 231 | * any of the tunnels.
|
| 232 | *
|
| 233 | * Any tunnel that requires isochronous bandwidth (that's DP for now) is
|
| 234 | * attached to a bandwidth group. All tunnels going through the same
|
| 235 | * USB4 links share the same group and can dynamically distribute the
|
| 236 | * bandwidth within the group.
|
| 237 |
|
| 238 | struct tb_bandwidth_group {
|
| 239 | struct tb *tb;
|
| 240 | int index;
|
| 241 | struct list_head ports;
|
| 242 | int reserved;
|
| 243 | struct delayed_work release_work;
|
| 244 | };
|
| 245 |
|
| 246 | |
| 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)
|
| 251 | * @xdomain: Remote host (%NULL if not connected)
|
| 252 | * @cap_phy: Offset, zero if not found
|
| 253 | * @cap_tmu: Offset of the adapter specific TMU capability (%0 if not present)
|
| 254 | * @cap_adap: Offset of the adapter specific capability (%0 if not present)
|
| 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
|
| 258 | * @disabled: Disabled by eeprom or enabled but not implemented
|
| 259 | * @bonded: true if the port is bonded (two lanes combined as one)
|
| 260 | * @dual_link_port: If the switch is connected using two ports, points
|
| 261 | * to the other port.
|
| 262 | * @link_nr: Is this primary or secondary port on the dual_link.
|
| 263 | * @in_hopids: Currently allocated input HopIDs
|
| 264 | * @out_hopids: Currently allocated output HopIDs
|
| 265 | * @list: Used to link ports to DP resources list
|
| 266 | * @total_credits: Total number of buffers available for this port
|
| 267 | * @ctl_credits: Buffers reserved for control path
|
| 268 | * @dma_credits: Number of credits allocated for DMA tunneling for all
|
| 269 | * DMA paths through this port.
|
| 270 | * @group: Bandwidth allocation group the adapter is assigned to. Only
|
| 271 | * used for DP IN adapters for now.
|
| 272 | * @group_list: The adapter is linked to the group's list of ports through this
|
| 273 | * @max_bw: Maximum possible bandwidth through this adapter if set to
|
| 274 | * non-zero.
|
| 275 | * @redrive: For DP IN, if true the adapter is in redrive mode.
|
| 276 | *
|
| 277 | * In USB4 terminology this structure represents an adapter (protocol or
|
| 278 | * lane adapter).
|
| 279 |
|
| 280 | struct tb_port {
|
| 281 | struct tb_regs_port_header config;
|
| 282 | struct tb_switch *sw;
|
| 283 | struct tb_port *remote;
|
| 284 | struct tb_xdomain *xdomain;
|
| 285 | int cap_phy;
|
| 286 | int cap_tmu;
|
| 287 | int cap_adap;
|
| 288 | int cap_usb4;
|
| 289 | struct usb4_port *usb4;
|
| 290 | u8 port;
|
| 291 | bool disabled;
|
| 292 | bool bonded;
|
| 293 | struct tb_port *dual_link_port;
|
| 294 | u8 link_nr:1;
|
| 295 | struct ida in_hopids;
|
| 296 | struct ida out_hopids;
|
| 297 | struct list_head list;
|
| 298 | unsigned int total_credits;
|
| 299 | unsigned int ctl_credits;
|
| 300 | unsigned int dma_credits;
|
| 301 | struct tb_bandwidth_group *group;
|
| 302 | struct list_head group_list;
|
| 303 | unsigned int max_bw;
|
| 304 | bool redrive;
|
| 305 | };
|
| 306 |
|
| 307 | |
| 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 move
|
| 312 | * it into offline mode and back
|
| 313 | * @offline: The port is currently in offline mode
|
| 314 | * @margining: Pointer to margining structure if enabled
|
| 315 |
|
| 316 | struct usb4_port {
|
| 317 | struct device dev;
|
| 318 | struct tb_port *port;
|
| 319 | bool can_offline;
|
| 320 | bool offline;
|
| 321 | #ifdef CONFIG_USB4_DEBUGFS_MARGINING
|
| 322 | struct tb_margining *margining;
|
| 323 | #endif
|
| 324 | };
|
| 325 |
|
| 326 | |
| 327 | * struct tb_retimer - Thunderbolt retimer
|
| 328 | * @dev: Device for the retimer
|
| 329 | * @tb: Pointer to the domain the retimer belongs to
|
| 330 | * @index: Retimer index facing the router USB4 port
|
| 331 | * @vendor: Vendor ID of the retimer
|
| 332 | * @device: Device ID of the retimer
|
| 333 | * @port: Pointer to the lane 0 adapter
|
| 334 | * @nvm: Pointer to the NVM if the retimer has one (%NULL otherwise)
|
| 335 | * @no_nvm_upgrade: Prevent NVM upgrade of this retimer
|
| 336 | * @auth_status: Status of last NVM authentication
|
| 337 | * @margining: Pointer to margining structure if enabled
|
| 338 |
|
| 339 | struct tb_retimer {
|
| 340 | struct device dev;
|
| 341 | struct tb *tb;
|
| 342 | u8 index;
|
| 343 | u32 vendor;
|
| 344 | u32 device;
|
| 345 | struct tb_port *port;
|
| 346 | struct tb_nvm *nvm;
|
| 347 | bool no_nvm_upgrade;
|
| 348 | u32 auth_status;
|
| 349 | #ifdef CONFIG_USB4_DEBUGFS_MARGINING
|
| 350 | struct tb_margining *margining;
|
| 351 | #endif
|
| 352 | };
|
| 353 |
|
| 354 | |
| 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
|
| 358 | * (must be on the same switch as @in_port)
|
| 359 | * @in_hop_index: HopID where the path configuration entry is placed in
|
| 360 | * the path config space of @in_port.
|
| 361 | * @in_counter_index: Used counter index (not used in the driver
|
| 362 | * currently, %-1 to disable)
|
| 363 | * @next_hop_index: HopID of the packet when it is routed out from @out_port
|
| 364 | * @initial_credits: Number of initial flow control credits allocated for
|
| 365 | * the path
|
| 366 | * @nfc_credits: Number of non-flow controlled buffers allocated for the
|
| 367 | * @in_port.
|
| 368 | * @pm_support: Set path PM packet support bit to 1 (for USB4 v2 routers)
|
| 369 | *
|
| 370 | * Hop configuration is always done on the IN port of a switch.
|
| 371 | * in_port and out_port have to be on the same switch. Packets arriving on
|
| 372 | * in_port with "hop" = in_hop_index will get routed to through out_port. The
|
| 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
|
| 375 | * set) the @next_hop_index must match the @in_hop_index of that next
|
| 376 | * hop to make routing possible.
|
| 377 | *
|
| 378 | * in_counter_index is the index of a counter (in TB_CFG_COUNTERS) on the in
|
| 379 | * port.
|
| 380 |
|
| 381 | struct tb_path_hop {
|
| 382 | struct tb_port *in_port;
|
| 383 | struct tb_port *out_port;
|
| 384 | int in_hop_index;
|
| 385 | int in_counter_index;
|
| 386 | int next_hop_index;
|
| 387 | unsigned int initial_credits;
|
| 388 | unsigned int nfc_credits;
|
| 389 | bool pm_support;
|
| 390 | };
|
| 391 |
|
| 392 | |
| 393 | * enum tb_path_port - path options mask
|
| 394 | * @TB_PATH_NONE: Do not activate on any hop on path
|
| 395 | * @TB_PATH_SOURCE: Activate on the first hop (out of src)
|
| 396 | * @TB_PATH_INTERNAL: Activate on the intermediate hops (not the first/last)
|
| 397 | * @TB_PATH_DESTINATION: Activate on the last hop (into dst)
|
| 398 | * @TB_PATH_ALL: Activate on all hops on the path
|
| 399 |
|
| 400 | enum tb_path_port {
|
| 401 | TB_PATH_NONE = 0,
|
| 402 | TB_PATH_SOURCE = 1,
|
| 403 | TB_PATH_INTERNAL = 2,
|
| 404 | TB_PATH_DESTINATION = 4,
|
| 405 | TB_PATH_ALL = 7,
|
| 406 | };
|
| 407 |
|
| 408 | |
| 409 | * struct tb_path - a unidirectional path between two ports
|
| 410 | * @tb: Pointer to the domain structure
|
| 411 | * @name: Name of the path (used for debugging)
|
| 412 | * @ingress_shared_buffer: Shared buffering used for ingress ports on the path
|
| 413 | * @egress_shared_buffer: Shared buffering used for egress ports on the path
|
| 414 | * @ingress_fc_enable: Flow control for ingress ports on the path
|
| 415 | * @egress_fc_enable: Flow control for egress ports on the path
|
| 416 | * @priority: Priority group if the path
|
| 417 | * @weight: Weight of the path inside the priority group
|
| 418 | * @drop_packages: Drop packages from queue tail or head
|
| 419 | * @activated: Is the path active
|
| 420 | * @clear_fc: Clear all flow control from the path config space entries
|
| 421 | * when deactivating this path
|
| 422 | * @path_length: How many hops the path uses
|
| 423 | * @alloc_hopid: Does this path consume port HopID
|
| 424 | * @hops: Path hops
|
| 425 | *
|
| 426 | * A path consists of a number of hops (see &struct tb_path_hop). To
|
| 427 | * establish a PCIe tunnel two paths have to be created between the two
|
| 428 | * PCIe ports.
|
| 429 |
|
| 430 | struct tb_path {
|
| 431 | struct tb *tb;
|
| 432 | const char *name;
|
| 433 | enum tb_path_port ingress_shared_buffer;
|
| 434 | enum tb_path_port egress_shared_buffer;
|
| 435 | enum tb_path_port ingress_fc_enable;
|
| 436 | enum tb_path_port egress_fc_enable;
|
| 437 |
|
| 438 | unsigned int priority:3;
|
| 439 | int weight:4;
|
| 440 | bool drop_packages;
|
| 441 | bool activated;
|
| 442 | bool clear_fc;
|
| 443 | int path_length;
|
| 444 | bool alloc_hopid;
|
| 445 |
|
| 446 | struct tb_path_hop hops[] __counted_by(path_length);
|
| 447 | };
|
| 448 |
|
| 449 |
|
| 450 | #define TB_PATH_MIN_HOPID 8
|
| 451 | |
| 452 | * Support paths from the farthest (depth 6) router to the host and back
|
| 453 | * to the same level (not necessarily to the same router).
|
| 454 |
|
| 455 | #define TB_PATH_MAX_HOPS (7 * 2)
|
| 456 |
|
| 457 |
|
| 458 | #define TB_WAKE_ON_CONNECT BIT(0)
|
| 459 | #define TB_WAKE_ON_DISCONNECT BIT(1)
|
| 460 | #define TB_WAKE_ON_USB4 BIT(2)
|
| 461 | #define TB_WAKE_ON_USB3 BIT(3)
|
| 462 | #define TB_WAKE_ON_PCIE BIT(4)
|
| 463 | #define TB_WAKE_ON_DP BIT(5)
|
| 464 |
|
| 465 |
|
| 466 | #define TB_CL0S BIT(0)
|
| 467 | #define TB_CL1 BIT(1)
|
| 468 | #define TB_CL2 BIT(2)
|
| 469 |
|
| 470 | |
| 471 | * struct tb_cm_ops - Connection manager specific operations vector
|
| 472 | * @driver_ready: Called right after control channel is started. Used by
|
| 473 | * ICM to send driver ready message to the firmware.
|
| 474 | * @start: Starts the domain
|
| 475 | * @stop: Stops the domain
|
| 476 | * @deinit: Perform any cleanup after the domain is stopped but before
|
| 477 | * it is unregistered. Called without @tb->lock taken. Optional.
|
| 478 | * @suspend_noirq: Connection manager specific suspend_noirq
|
| 479 | * @resume_noirq: Connection manager specific resume_noirq
|
| 480 | * @suspend: Connection manager specific suspend
|
| 481 | * @freeze_noirq: Connection manager specific freeze_noirq
|
| 482 | * @thaw_noirq: Connection manager specific thaw_noirq
|
| 483 | * @complete: Connection manager specific complete
|
| 484 | * @runtime_suspend: Connection manager specific runtime_suspend
|
| 485 | * @runtime_resume: Connection manager specific runtime_resume
|
| 486 | * @runtime_suspend_switch: Runtime suspend a switch
|
| 487 | * @runtime_resume_switch: Runtime resume a switch
|
| 488 | * @handle_event: Handle thunderbolt event
|
| 489 | * @get_boot_acl: Get boot ACL list
|
| 490 | * @set_boot_acl: Set boot ACL list
|
| 491 | * @disapprove_switch: Disapprove switch (disconnect PCIe tunnel)
|
| 492 | * @approve_switch: Approve switch
|
| 493 | * @add_switch_key: Add key to switch
|
| 494 | * @challenge_switch_key: Challenge switch using key
|
| 495 | * @disconnect_pcie_paths: Disconnects PCIe paths before NVM update
|
| 496 | * @approve_xdomain_paths: Approve (establish) XDomain DMA paths
|
| 497 | * @disconnect_xdomain_paths: Disconnect XDomain DMA paths
|
| 498 | * @usb4_switch_op: Optional proxy for USB4 router operations. If set
|
| 499 | * this will be called whenever USB4 router operation is
|
| 500 | * performed. If this returns %-EOPNOTSUPP then the
|
| 501 | * native USB4 router operation is called.
|
| 502 | * @usb4_switch_nvm_authenticate_status: Optional callback that the CM
|
| 503 | * implementation can use to return
|
| 504 | * status of USB4 NVM_AUTH router
|
| 505 | * operation.
|
| 506 |
|
| 507 | struct tb_cm_ops {
|
| 508 | int (*driver_ready)(struct tb *tb);
|
| 509 | int (*start)(struct tb *tb, bool reset);
|
| 510 | void (*stop)(struct tb *tb);
|
| 511 | void (*deinit)(struct tb *tb);
|
| 512 | int (*suspend_noirq)(struct tb *tb);
|
| 513 | int (*resume_noirq)(struct tb *tb);
|
| 514 | int (*suspend)(struct tb *tb);
|
| 515 | int (*freeze_noirq)(struct tb *tb);
|
| 516 | int (*thaw_noirq)(struct tb *tb);
|
| 517 | void (*complete)(struct tb *tb);
|
| 518 | int (*runtime_suspend)(struct tb *tb);
|
| 519 | int (*runtime_resume)(struct tb *tb);
|
| 520 | int (*runtime_suspend_switch)(struct tb_switch *sw);
|
| 521 | int (*runtime_resume_switch)(struct tb_switch *sw);
|
| 522 | void (*handle_event)(struct tb *tb, enum tb_cfg_pkg_type,
|
| 523 | const void *buf, size_t size);
|
| 524 | int (*get_boot_acl)(struct tb *tb, uuid_t *uuids, size_t nuuids);
|
| 525 | int (*set_boot_acl)(struct tb *tb, const uuid_t *uuids, size_t nuuids);
|
| 526 | int (*disapprove_switch)(struct tb *tb, struct tb_switch *sw);
|
| 527 | int (*approve_switch)(struct tb *tb, struct tb_switch *sw);
|
| 528 | int (*add_switch_key)(struct tb *tb, struct tb_switch *sw);
|
| 529 | int (*challenge_switch_key)(struct tb *tb, struct tb_switch *sw,
|
| 530 | const u8 *challenge, u8 *response);
|
| 531 | int (*disconnect_pcie_paths)(struct tb *tb);
|
| 532 | int (*approve_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
|
| 533 | int transmit_path, int transmit_ring,
|
| 534 | int receive_path, int receive_ring);
|
| 535 | int (*disconnect_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
|
| 536 | int transmit_path, int transmit_ring,
|
| 537 | int receive_path, int receive_ring);
|
| 538 | int (*usb4_switch_op)(struct tb_switch *sw, u16 opcode, u32 *metadata,
|
| 539 | u8 *status, const void *tx_data, size_t tx_data_len,
|
| 540 | void *rx_data, size_t rx_data_len);
|
| 541 | int (*usb4_switch_nvm_authenticate_status)(struct tb_switch *sw,
|
| 542 | u32 *status);
|
| 543 | };
|
| 544 |
|
| 545 | static inline void *tb_priv(struct tb *tb)
|
| 546 | {
|
| 547 | return (void *)tb->privdata;
|
| 548 | }
|
| 549 |
|
| 550 | #define TB_AUTOSUSPEND_DELAY 15000
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 | |
| 555 | * tb_upstream_port() - return the upstream port of a switch
|
| 556 | * @sw: Router
|
| 557 | *
|
| 558 | * Every switch has an upstream port (for the root switch it is the NHI).
|
| 559 | *
|
| 560 | * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
|
| 561 | * non root switches (on the NHI port remote is always NULL).
|
| 562 | *
|
| 563 | * Return: Pointer to &struct tb_port.
|
| 564 |
|
| 565 | static inline struct tb_port *tb_upstream_port(struct tb_switch *sw)
|
| 566 | {
|
| 567 | return &sw->ports[sw->config.upstream_port_number];
|
| 568 | }
|
| 569 |
|
| 570 | |
| 571 | * tb_is_upstream_port() - Is the port upstream facing
|
| 572 | * @port: Port to check
|
| 573 | *
|
| 574 | * Return: %true if @port is upstream facing port. In case of dual link
|
| 575 | * ports, both return %true.
|
| 576 |
|
| 577 | static inline bool tb_is_upstream_port(const struct tb_port *port)
|
| 578 | {
|
| 579 | const struct tb_port *upstream_port = tb_upstream_port(port->sw);
|
| 580 | return port == upstream_port || port->dual_link_port == upstream_port;
|
| 581 | }
|
| 582 |
|
| 583 | static inline u64 tb_route(const struct tb_switch *sw)
|
| 584 | {
|
| 585 | return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo;
|
| 586 | }
|
| 587 |
|
| 588 | static inline struct tb_port *tb_port_at(u64 route, struct tb_switch *sw)
|
| 589 | {
|
| 590 | u8 port;
|
| 591 |
|
| 592 | port = route >> (sw->config.depth * 8);
|
| 593 | if (WARN_ON(port > sw->config.max_port_number))
|
| 594 | return NULL;
|
| 595 | return &sw->ports[port];
|
| 596 | }
|
| 597 |
|
| 598 | static inline const char *tb_width_name(enum tb_link_width width)
|
| 599 | {
|
| 600 | switch (width) {
|
| 601 | case TB_LINK_WIDTH_SINGLE:
|
| 602 | return "symmetric, single lane";
|
| 603 | case TB_LINK_WIDTH_DUAL:
|
| 604 | return "symmetric, dual lanes";
|
| 605 | case TB_LINK_WIDTH_ASYM_TX:
|
| 606 | return "asymmetric, 3 transmitters, 1 receiver";
|
| 607 | case TB_LINK_WIDTH_ASYM_RX:
|
| 608 | return "asymmetric, 3 receivers, 1 transmitter";
|
| 609 | default:
|
| 610 | return "unknown";
|
| 611 | }
|
| 612 | }
|
| 613 |
|
| 614 | |
| 615 | * tb_port_has_remote() - Does the port have switch connected downstream
|
| 616 | * @port: Port to check
|
| 617 | *
|
| 618 | * Return: %true only when the port is primary port and has remote set.
|
| 619 |
|
| 620 | static inline bool tb_port_has_remote(const struct tb_port *port)
|
| 621 | {
|
| 622 | if (tb_is_upstream_port(port))
|
| 623 | return false;
|
| 624 | if (!port->remote)
|
| 625 | return false;
|
| 626 | if (port->dual_link_port && port->link_nr)
|
| 627 | return false;
|
| 628 |
|
| 629 | return true;
|
| 630 | }
|
| 631 |
|
| 632 | static inline bool tb_port_is_null(const struct tb_port *port)
|
| 633 | {
|
| 634 | return port && port->port && port->config.type == TB_TYPE_PORT;
|
| 635 | }
|
| 636 |
|
| 637 | static inline bool tb_port_is_nhi(const struct tb_port *port)
|
| 638 | {
|
| 639 | return port && port->config.type == TB_TYPE_NHI;
|
| 640 | }
|
| 641 |
|
| 642 | static inline bool tb_port_is_pcie_down(const struct tb_port *port)
|
| 643 | {
|
| 644 | return port && port->config.type == TB_TYPE_PCIE_DOWN;
|
| 645 | }
|
| 646 |
|
| 647 | static inline bool tb_port_is_pcie_up(const struct tb_port *port)
|
| 648 | {
|
| 649 | return port && port->config.type == TB_TYPE_PCIE_UP;
|
| 650 | }
|
| 651 |
|
| 652 | static inline bool tb_port_is_dpin(const struct tb_port *port)
|
| 653 | {
|
| 654 | return port && port->config.type == TB_TYPE_DP_HDMI_IN;
|
| 655 | }
|
| 656 |
|
| 657 | static inline bool tb_port_is_dpout(const struct tb_port *port)
|
| 658 | {
|
| 659 | return port && port->config.type == TB_TYPE_DP_HDMI_OUT;
|
| 660 | }
|
| 661 |
|
| 662 | static inline bool tb_port_is_usb3_down(const struct tb_port *port)
|
| 663 | {
|
| 664 | return port && port->config.type == TB_TYPE_USB3_DOWN;
|
| 665 | }
|
| 666 |
|
| 667 | static inline bool tb_port_is_usb3_up(const struct tb_port *port)
|
| 668 | {
|
| 669 | return port && port->config.type == TB_TYPE_USB3_UP;
|
| 670 | }
|
| 671 |
|
| 672 | static inline int tb_sw_read(struct tb_switch *sw, void *buffer,
|
| 673 | enum tb_cfg_space space, u32 offset, u32 length)
|
| 674 | {
|
| 675 | if (sw->is_unplugged)
|
| 676 | return -ENODEV;
|
| 677 | return tb_cfg_read(sw->tb->ctl,
|
| 678 | buffer,
|
| 679 | tb_route(sw),
|
| 680 | 0,
|
| 681 | space,
|
| 682 | offset,
|
| 683 | length);
|
| 684 | }
|
| 685 |
|
| 686 | static inline int tb_sw_write(struct tb_switch *sw, const void *buffer,
|
| 687 | enum tb_cfg_space space, u32 offset, u32 length)
|
| 688 | {
|
| 689 | if (sw->is_unplugged)
|
| 690 | return -ENODEV;
|
| 691 | return tb_cfg_write(sw->tb->ctl,
|
| 692 | buffer,
|
| 693 | tb_route(sw),
|
| 694 | 0,
|
| 695 | space,
|
| 696 | offset,
|
| 697 | length);
|
| 698 | }
|
| 699 |
|
| 700 | static inline int tb_port_read(struct tb_port *port, void *buffer,
|
| 701 | enum tb_cfg_space space, u32 offset, u32 length)
|
| 702 | {
|
| 703 | if (port->sw->is_unplugged)
|
| 704 | return -ENODEV;
|
| 705 | return tb_cfg_read(port->sw->tb->ctl,
|
| 706 | buffer,
|
| 707 | tb_route(port->sw),
|
| 708 | port->port,
|
| 709 | space,
|
| 710 | offset,
|
| 711 | length);
|
| 712 | }
|
| 713 |
|
| 714 | static inline int tb_port_write(struct tb_port *port, const void *buffer,
|
| 715 | enum tb_cfg_space space, u32 offset, u32 length)
|
| 716 | {
|
| 717 | if (port->sw->is_unplugged)
|
| 718 | return -ENODEV;
|
| 719 | return tb_cfg_write(port->sw->tb->ctl,
|
| 720 | buffer,
|
| 721 | tb_route(port->sw),
|
| 722 | port->port,
|
| 723 | space,
|
| 724 | offset,
|
| 725 | length);
|
| 726 | }
|
| 727 |
|
| 728 | #define tb_err(tb, fmt, arg...) dev_err((tb)->nhi->dev, fmt, ## arg)
|
| 729 | #define tb_WARN(tb, fmt, arg...) dev_WARN((tb)->nhi->dev, fmt, ## arg)
|
| 730 | #define tb_warn(tb, fmt, arg...) dev_warn((tb)->nhi->dev, fmt, ## arg)
|
| 731 | #define tb_info(tb, fmt, arg...) dev_info((tb)->nhi->dev, fmt, ## arg)
|
| 732 | #define tb_dbg(tb, fmt, arg...) dev_dbg((tb)->nhi->dev, fmt, ## arg)
|
| 733 |
|
| 734 | #define __TB_SW_PRINT(level, sw, fmt, arg...) \
|
| 735 | do { \
|
| 736 | const struct tb_switch *__sw = (sw); \
|
| 737 | level(__sw->tb, "%llx: " fmt, \
|
| 738 | tb_route(__sw), ## arg); \
|
| 739 | } while (0)
|
| 740 | #define tb_sw_WARN(sw, fmt, arg...) __TB_SW_PRINT(tb_WARN, sw, fmt, ##arg)
|
| 741 | #define tb_sw_warn(sw, fmt, arg...) __TB_SW_PRINT(tb_warn, sw, fmt, ##arg)
|
| 742 | #define tb_sw_info(sw, fmt, arg...) __TB_SW_PRINT(tb_info, sw, fmt, ##arg)
|
| 743 | #define tb_sw_dbg(sw, fmt, arg...) __TB_SW_PRINT(tb_dbg, sw, fmt, ##arg)
|
| 744 |
|
| 745 | #define __TB_PORT_PRINT(level, _port, fmt, arg...) \
|
| 746 | do { \
|
| 747 | const struct tb_port *__port = (_port); \
|
| 748 | level(__port->sw->tb, "%llx:%u: " fmt, \
|
| 749 | tb_route(__port->sw), __port->port, ## arg); \
|
| 750 | } while (0)
|
| 751 | #define tb_port_WARN(port, fmt, arg...) \
|
| 752 | __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
|
| 753 | #define tb_port_warn(port, fmt, arg...) \
|
| 754 | __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
|
| 755 | #define tb_port_info(port, fmt, arg...) \
|
| 756 | __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
|
| 757 | #define tb_port_dbg(port, fmt, arg...) \
|
| 758 | __TB_PORT_PRINT(tb_dbg, port, fmt, ##arg)
|
| 759 |
|
| 760 | struct tb *icm_probe(struct tb_nhi *nhi);
|
| 761 | struct tb *tb_probe(struct tb_nhi *nhi);
|
| 762 |
|
| 763 | extern const struct device_type tb_domain_type;
|
| 764 | extern const struct device_type tb_retimer_type;
|
| 765 | extern const struct device_type tb_switch_type;
|
| 766 | extern const struct device_type usb4_port_device_type;
|
| 767 |
|
| 768 | int tb_domain_init(void);
|
| 769 | void tb_domain_exit(void);
|
| 770 | int tb_xdomain_init(void);
|
| 771 | void tb_xdomain_exit(void);
|
| 772 |
|
| 773 | struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize);
|
| 774 | int tb_domain_add(struct tb *tb, bool reset);
|
| 775 | void tb_domain_remove(struct tb *tb);
|
| 776 | int tb_domain_suspend_noirq(struct tb *tb);
|
| 777 | int tb_domain_resume_noirq(struct tb *tb);
|
| 778 | int tb_domain_suspend(struct tb *tb);
|
| 779 | int tb_domain_freeze_noirq(struct tb *tb);
|
| 780 | int tb_domain_thaw_noirq(struct tb *tb);
|
| 781 | void tb_domain_complete(struct tb *tb);
|
| 782 | int tb_domain_runtime_suspend(struct tb *tb);
|
| 783 | int tb_domain_runtime_resume(struct tb *tb);
|
| 784 | int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw);
|
| 785 | int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);
|
| 786 | int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw);
|
| 787 | int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw);
|
| 788 | int tb_domain_disconnect_pcie_paths(struct tb *tb);
|
| 789 | int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
|
| 790 | int transmit_path, int transmit_ring,
|
| 791 | int receive_path, int receive_ring);
|
| 792 | int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
|
| 793 | int transmit_path, int transmit_ring,
|
| 794 | int receive_path, int receive_ring);
|
| 795 | int tb_domain_disconnect_all_paths(struct tb *tb);
|
| 796 | int tb_domain_unregister_unplugged_xdomains(struct tb *tb);
|
| 797 |
|
| 798 | static inline struct tb *tb_domain_get(struct tb *tb)
|
| 799 | {
|
| 800 | if (tb)
|
| 801 | get_device(&tb->dev);
|
| 802 | return tb;
|
| 803 | }
|
| 804 |
|
| 805 | static inline void tb_domain_put(struct tb *tb)
|
| 806 | {
|
| 807 | put_device(&tb->dev);
|
| 808 | }
|
| 809 |
|
| 810 | |
| 811 | * tb_domain_event() - Notify userspace about an event in domain
|
| 812 | * @tb: Domain where event occurred
|
| 813 | * @envp: Array of uevent environment strings (can be %NULL)
|
| 814 | *
|
| 815 | * This function provides a way to notify userspace about any events
|
| 816 | * that take place in the domain.
|
| 817 |
|
| 818 | static inline void tb_domain_event(struct tb *tb, char *envp[])
|
| 819 | {
|
| 820 | kobject_uevent_env(&tb->dev.kobj, KOBJ_CHANGE, envp);
|
| 821 | }
|
| 822 |
|
| 823 | struct tb_nvm *tb_nvm_alloc(struct device *dev);
|
| 824 | int tb_nvm_read_version(struct tb_nvm *nvm);
|
| 825 | int tb_nvm_validate(struct tb_nvm *nvm);
|
| 826 | int tb_nvm_write_headers(struct tb_nvm *nvm);
|
| 827 | int tb_nvm_add_active(struct tb_nvm *nvm, nvmem_reg_read_t reg_read);
|
| 828 | int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val,
|
| 829 | size_t bytes);
|
| 830 | int tb_nvm_add_non_active(struct tb_nvm *nvm, nvmem_reg_write_t reg_write);
|
| 831 | void tb_nvm_free(struct tb_nvm *nvm);
|
| 832 | void tb_nvm_exit(void);
|
| 833 |
|
| 834 | typedef int (*read_block_fn)(void *, unsigned int, void *, size_t);
|
| 835 | typedef int (*write_block_fn)(void *, unsigned int, const void *, size_t);
|
| 836 |
|
| 837 | int tb_nvm_read_data(unsigned int address, void *buf, size_t size,
|
| 838 | unsigned int retries, read_block_fn read_block,
|
| 839 | void *read_block_data);
|
| 840 | int tb_nvm_write_data(unsigned int address, const void *buf, size_t size,
|
| 841 | unsigned int retries, write_block_fn write_next_block,
|
| 842 | void *write_block_data);
|
| 843 |
|
| 844 | int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
|
| 845 | size_t size);
|
| 846 | struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
|
| 847 | u64 route);
|
| 848 | struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb,
|
| 849 | struct device *parent, u64 route);
|
| 850 | int tb_switch_configure(struct tb_switch *sw);
|
| 851 | int tb_switch_configuration_valid(struct tb_switch *sw);
|
| 852 | int tb_switch_add(struct tb_switch *sw);
|
| 853 | void tb_switch_remove(struct tb_switch *sw);
|
| 854 | void tb_switch_suspend(struct tb_switch *sw, bool runtime);
|
| 855 | int tb_switch_resume(struct tb_switch *sw, bool runtime);
|
| 856 | int tb_switch_reset(struct tb_switch *sw);
|
| 857 | int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit,
|
| 858 | u32 value, int timeout_msec);
|
| 859 | void tb_sw_set_unplugged(struct tb_switch *sw);
|
| 860 | struct tb_port *tb_switch_find_port(struct tb_switch *sw,
|
| 861 | enum tb_port_type type);
|
| 862 | struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,
|
| 863 | u8 depth);
|
| 864 | struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid);
|
| 865 | struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route);
|
| 866 |
|
| 867 | |
| 868 | * tb_switch_for_each_port() - Iterate over each switch port
|
| 869 | * @sw: Switch whose ports to iterate
|
| 870 | * @p: Port used as iterator
|
| 871 | *
|
| 872 | * Iterates over each switch port skipping the control port (port %0).
|
| 873 |
|
| 874 | #define tb_switch_for_each_port(sw, p) \
|
| 875 | for ((p) = &(sw)->ports[1]; \
|
| 876 | (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
|
| 877 |
|
| 878 | static inline struct tb_switch *tb_switch_get(struct tb_switch *sw)
|
| 879 | {
|
| 880 | if (sw)
|
| 881 | get_device(&sw->dev);
|
| 882 | return sw;
|
| 883 | }
|
| 884 |
|
| 885 | static inline void tb_switch_put(struct tb_switch *sw)
|
| 886 | {
|
| 887 | put_device(&sw->dev);
|
| 888 | }
|
| 889 |
|
| 890 | static inline bool tb_is_switch(const struct device *dev)
|
| 891 | {
|
| 892 | return dev->type == &tb_switch_type;
|
| 893 | }
|
| 894 |
|
| 895 | static inline struct tb_switch *tb_to_switch(const struct device *dev)
|
| 896 | {
|
| 897 | if (tb_is_switch(dev))
|
| 898 | return container_of(dev, struct tb_switch, dev);
|
| 899 | return NULL;
|
| 900 | }
|
| 901 |
|
| 902 | static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw)
|
| 903 | {
|
| 904 | return tb_to_switch(sw->dev.parent);
|
| 905 | }
|
| 906 |
|
| 907 | |
| 908 | * tb_switch_downstream_port() - Return downstream facing port of parent router
|
| 909 | * @sw: Device router pointer
|
| 910 | *
|
| 911 | * Call only for device routers.
|
| 912 | *
|
| 913 | * Return: Pointer to &struct tb_port or %NULL in case of failure.
|
| 914 |
|
| 915 | static inline struct tb_port *tb_switch_downstream_port(struct tb_switch *sw)
|
| 916 | {
|
| 917 | if (WARN_ON(!tb_route(sw)))
|
| 918 | return NULL;
|
| 919 | return tb_port_at(tb_route(sw), tb_switch_parent(sw));
|
| 920 | }
|
| 921 |
|
| 922 | |
| 923 | * tb_switch_depth() - Returns depth of the connected router
|
| 924 | * @sw: Router
|
| 925 | *
|
| 926 | * Return: Router depth level as a number.
|
| 927 |
|
| 928 | static inline int tb_switch_depth(const struct tb_switch *sw)
|
| 929 | {
|
| 930 | return sw->config.depth;
|
| 931 | }
|
| 932 |
|
| 933 | static inline bool tb_switch_is_light_ridge(const struct tb_switch *sw)
|
| 934 | {
|
| 935 | return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
|
| 936 | sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE;
|
| 937 | }
|
| 938 |
|
| 939 | static inline bool tb_switch_is_eagle_ridge(const struct tb_switch *sw)
|
| 940 | {
|
| 941 | return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
|
| 942 | sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE;
|
| 943 | }
|
| 944 |
|
| 945 | static inline bool tb_switch_is_cactus_ridge(const struct tb_switch *sw)
|
| 946 | {
|
| 947 | if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
|
| 948 | switch (sw->config.device_id) {
|
| 949 | case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C:
|
| 950 | case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C:
|
| 951 | return true;
|
| 952 | }
|
| 953 | }
|
| 954 | return false;
|
| 955 | }
|
| 956 |
|
| 957 | static inline bool tb_switch_is_falcon_ridge(const struct tb_switch *sw)
|
| 958 | {
|
| 959 | if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
|
| 960 | switch (sw->config.device_id) {
|
| 961 | case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE:
|
| 962 | case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE:
|
| 963 | return true;
|
| 964 | }
|
| 965 | }
|
| 966 | return false;
|
| 967 | }
|
| 968 |
|
| 969 | static inline bool tb_switch_is_alpine_ridge(const struct tb_switch *sw)
|
| 970 | {
|
| 971 | if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
|
| 972 | switch (sw->config.device_id) {
|
| 973 | case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE:
|
| 974 | case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE:
|
| 975 | case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE:
|
| 976 | case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE:
|
| 977 | case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE:
|
| 978 | return true;
|
| 979 | }
|
| 980 | }
|
| 981 | return false;
|
| 982 | }
|
| 983 |
|
| 984 | static inline bool tb_switch_is_titan_ridge(const struct tb_switch *sw)
|
| 985 | {
|
| 986 | if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
|
| 987 | switch (sw->config.device_id) {
|
| 988 | case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE:
|
| 989 | case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE:
|
| 990 | case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE:
|
| 991 | return true;
|
| 992 | }
|
| 993 | }
|
| 994 | return false;
|
| 995 | }
|
| 996 |
|
| 997 | static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
|
| 998 | {
|
| 999 | if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
|
| 1000 | switch (sw->config.device_id) {
|
| 1001 | case PCI_DEVICE_ID_INTEL_TGL_NHI0:
|
| 1002 | case PCI_DEVICE_ID_INTEL_TGL_NHI1:
|
| 1003 | case PCI_DEVICE_ID_INTEL_TGL_H_NHI0:
|
| 1004 | case PCI_DEVICE_ID_INTEL_TGL_H_NHI1:
|
| 1005 | return true;
|
| 1006 | }
|
| 1007 | }
|
| 1008 | return false;
|
| 1009 | }
|
| 1010 |
|
| 1011 | |
| 1012 | * tb_switch_is_icm() - Is the switch handled by ICM firmware
|
| 1013 | * @sw: Switch to check
|
| 1014 | *
|
| 1015 | * In case there is a need to differentiate whether ICM firmware or SW CM
|
| 1016 | * is handling @sw this function can be called. It is valid to call this
|
| 1017 | * after tb_switch_alloc() and tb_switch_configure() has been called
|
| 1018 | * (latter only for SW CM case).
|
| 1019 | *
|
| 1020 | * Return: %true if switch is handled by ICM, %false if handled by
|
| 1021 | * software CM.
|
| 1022 |
|
| 1023 | static inline bool tb_switch_is_icm(const struct tb_switch *sw)
|
| 1024 | {
|
| 1025 | return !sw->config.enabled;
|
| 1026 | }
|
| 1027 |
|
| 1028 | int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width);
|
| 1029 | int tb_switch_configure_link(struct tb_switch *sw);
|
| 1030 | void tb_switch_unconfigure_link(struct tb_switch *sw);
|
| 1031 |
|
| 1032 | bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1033 | int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1034 | void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1035 |
|
| 1036 | int tb_switch_tmu_init(struct tb_switch *sw);
|
| 1037 | int tb_switch_tmu_post_time(struct tb_switch *sw);
|
| 1038 | int tb_switch_tmu_disable(struct tb_switch *sw);
|
| 1039 | int tb_switch_tmu_enable(struct tb_switch *sw);
|
| 1040 | int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
|
| 1041 |
|
| 1042 | |
| 1043 | * tb_switch_tmu_is_configured() - Is given TMU mode configured
|
| 1044 | * @sw: Router whose mode to check
|
| 1045 | * @mode: Mode to check
|
| 1046 | *
|
| 1047 | * Checks if given router TMU mode is configured to @mode. Note the
|
| 1048 | * router TMU might not be enabled to this mode.
|
| 1049 | *
|
| 1050 | * Return: %true if TMU mode is equal to @mode, %false otherwise.
|
| 1051 |
|
| 1052 | static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw,
|
| 1053 | enum tb_switch_tmu_mode mode)
|
| 1054 | {
|
| 1055 | return sw->tmu.mode_request == mode;
|
| 1056 | }
|
| 1057 |
|
| 1058 | |
| 1059 | * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
|
| 1060 | * @sw: Router whose TMU mode to check
|
| 1061 | *
|
| 1062 | * Return: %true if hardware TMU configuration matches the requested
|
| 1063 | * configuration (and is not %TB_SWITCH_TMU_MODE_OFF), %false otherwise.
|
| 1064 |
|
| 1065 | static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw)
|
| 1066 | {
|
| 1067 | return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF &&
|
| 1068 | sw->tmu.mode == sw->tmu.mode_request;
|
| 1069 | }
|
| 1070 |
|
| 1071 | bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx);
|
| 1072 |
|
| 1073 | int tb_switch_clx_init(struct tb_switch *sw);
|
| 1074 | int tb_switch_clx_enable(struct tb_switch *sw, unsigned int clx);
|
| 1075 | int tb_switch_clx_disable(struct tb_switch *sw);
|
| 1076 |
|
| 1077 | |
| 1078 | * tb_switch_clx_is_enabled() - Checks if the CLx is enabled
|
| 1079 | * @sw: Router to check for the CLx
|
| 1080 | * @clx: The CLx states to check for
|
| 1081 | *
|
| 1082 | * Checks if the specified CLx is enabled on the router upstream link.
|
| 1083 | *
|
| 1084 | * Not applicable for a host router.
|
| 1085 | *
|
| 1086 | * Return: %true if any of the given states is enabled, %false otherwise.
|
| 1087 |
|
| 1088 | static inline bool tb_switch_clx_is_enabled(const struct tb_switch *sw,
|
| 1089 | unsigned int clx)
|
| 1090 | {
|
| 1091 | return sw->clx & clx;
|
| 1092 | }
|
| 1093 |
|
| 1094 | int tb_switch_pcie_l1_enable(struct tb_switch *sw);
|
| 1095 |
|
| 1096 | int tb_switch_xhci_connect(struct tb_switch *sw);
|
| 1097 | void tb_switch_xhci_disconnect(struct tb_switch *sw);
|
| 1098 |
|
| 1099 | int tb_port_state(struct tb_port *port);
|
| 1100 | int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
|
| 1101 | int tb_port_add_nfc_credits(struct tb_port *port, int credits);
|
| 1102 | int tb_port_clear_counter(struct tb_port *port, int counter);
|
| 1103 | int tb_port_unlock(struct tb_port *port);
|
| 1104 | int tb_port_enable(struct tb_port *port);
|
| 1105 | int tb_port_disable(struct tb_port *port);
|
| 1106 | int tb_port_reset(struct tb_port *port);
|
| 1107 | int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
|
| 1108 | void tb_port_release_in_hopid(struct tb_port *port, int hopid);
|
| 1109 | int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
|
| 1110 | void tb_port_release_out_hopid(struct tb_port *port, int hopid);
|
| 1111 | struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,
|
| 1112 | struct tb_port *prev);
|
| 1113 |
|
| 1114 | |
| 1115 | * tb_port_path_direction_downstream() - Checks if path is directed downstream
|
| 1116 | * @src: Source adapter
|
| 1117 | * @dst: Destination adapter
|
| 1118 | *
|
| 1119 | * Return: %true only if the specified path from source adapter (@src)
|
| 1120 | * to destination adapter (@dst) is directed downstream.
|
| 1121 |
|
| 1122 | static inline bool
|
| 1123 | tb_port_path_direction_downstream(const struct tb_port *src,
|
| 1124 | const struct tb_port *dst)
|
| 1125 | {
|
| 1126 | return src->sw->config.depth < dst->sw->config.depth;
|
| 1127 | }
|
| 1128 |
|
| 1129 | static inline bool tb_port_use_credit_allocation(const struct tb_port *port)
|
| 1130 | {
|
| 1131 | return tb_port_is_null(port) && port->sw->credit_allocation;
|
| 1132 | }
|
| 1133 |
|
| 1134 | |
| 1135 | * tb_for_each_port_on_path() - Iterate over each port on path
|
| 1136 | * @src: Source port
|
| 1137 | * @dst: Destination port
|
| 1138 | * @p: Port used as iterator
|
| 1139 | *
|
| 1140 | * Walks over each port on path from @src to @dst.
|
| 1141 |
|
| 1142 | #define tb_for_each_port_on_path(src, dst, p) \
|
| 1143 | for ((p) = tb_next_port_on_path((src), (dst), NULL); (p); \
|
| 1144 | (p) = tb_next_port_on_path((src), (dst), (p)))
|
| 1145 |
|
| 1146 | |
| 1147 | * tb_for_each_upstream_port_on_path() - Iterate over each upstream port on path
|
| 1148 | * @src: Source port
|
| 1149 | * @dst: Destination port
|
| 1150 | * @p: Port used as iterator
|
| 1151 | *
|
| 1152 | * Walks over each upstream lane adapter on path from @src to @dst.
|
| 1153 |
|
| 1154 | #define tb_for_each_upstream_port_on_path(src, dst, p) \
|
| 1155 | for ((p) = tb_next_port_on_path((src), (dst), NULL); (p); \
|
| 1156 | (p) = tb_next_port_on_path((src), (dst), (p))) \
|
| 1157 | if (!tb_port_is_null((p)) || !tb_is_upstream_port((p))) {\
|
| 1158 | continue; \
|
| 1159 | } else
|
| 1160 |
|
| 1161 | int tb_port_get_link_speed(struct tb_port *port);
|
| 1162 | int tb_port_get_link_generation(struct tb_port *port);
|
| 1163 | int tb_port_get_link_width(struct tb_port *port);
|
| 1164 | bool tb_port_width_supported(struct tb_port *port, unsigned int width);
|
| 1165 | int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
|
| 1166 | int tb_port_lane_bonding_enable(struct tb_port *port);
|
| 1167 | void tb_port_lane_bonding_disable(struct tb_port *port);
|
| 1168 | int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width,
|
| 1169 | int timeout_msec);
|
| 1170 | int tb_port_update_credits(struct tb_port *port);
|
| 1171 |
|
| 1172 | int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
|
| 1173 | int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);
|
| 1174 | int tb_switch_next_cap(struct tb_switch *sw, unsigned int offset);
|
| 1175 | int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
|
| 1176 | int tb_port_next_cap(struct tb_port *port, unsigned int offset);
|
| 1177 | bool tb_port_is_enabled(struct tb_port *port);
|
| 1178 |
|
| 1179 | bool tb_usb3_port_is_enabled(struct tb_port *port);
|
| 1180 | int tb_usb3_port_enable(struct tb_port *port, bool enable);
|
| 1181 |
|
| 1182 | bool tb_pci_port_is_enabled(struct tb_port *port);
|
| 1183 | int tb_pci_port_enable(struct tb_port *port, bool enable);
|
| 1184 |
|
| 1185 | int tb_dp_port_hpd_is_active(struct tb_port *port);
|
| 1186 | int tb_dp_port_hpd_clear(struct tb_port *port);
|
| 1187 | int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
|
| 1188 | unsigned int aux_tx, unsigned int aux_rx);
|
| 1189 | bool tb_dp_port_is_enabled(struct tb_port *port);
|
| 1190 | int tb_dp_port_enable(struct tb_port *port, bool enable);
|
| 1191 |
|
| 1192 | struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,
|
| 1193 | struct tb_port *dst, int dst_hopid,
|
| 1194 | struct tb_port **last, const char *name,
|
| 1195 | bool alloc_hopid);
|
| 1196 | struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
|
| 1197 | struct tb_port *dst, int dst_hopid, int link_nr,
|
| 1198 | const char *name);
|
| 1199 | void tb_path_free(struct tb_path *path);
|
| 1200 | int tb_path_activate(struct tb_path *path);
|
| 1201 | void tb_path_deactivate(struct tb_path *path);
|
| 1202 | int tb_path_deactivate_hop(struct tb_port *port, int hop_index);
|
| 1203 | bool tb_path_is_invalid(struct tb_path *path);
|
| 1204 | bool tb_path_port_on_path(const struct tb_path *path,
|
| 1205 | const struct tb_port *port);
|
| 1206 |
|
| 1207 | |
| 1208 | * tb_path_for_each_hop() - Iterate over each hop on path
|
| 1209 | * @path: Path whose hops to iterate
|
| 1210 | * @hop: Hop used as iterator
|
| 1211 | *
|
| 1212 | * Iterates over each hop on path.
|
| 1213 |
|
| 1214 | #define tb_path_for_each_hop(path, hop) \
|
| 1215 | for ((hop) = &(path)->hops[0]; \
|
| 1216 | (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
|
| 1217 |
|
| 1218 | int tb_drom_read(struct tb_switch *sw);
|
| 1219 | int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid);
|
| 1220 |
|
| 1221 | int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);
|
| 1222 | int tb_lc_reset_port(struct tb_port *port);
|
| 1223 | int tb_lc_configure_port(struct tb_port *port);
|
| 1224 | void tb_lc_unconfigure_port(struct tb_port *port);
|
| 1225 | int tb_lc_configure_xdomain(struct tb_port *port);
|
| 1226 | void tb_lc_unconfigure_xdomain(struct tb_port *port);
|
| 1227 | int tb_lc_start_lane_initialization(struct tb_port *port);
|
| 1228 | bool tb_lc_is_clx_supported(struct tb_port *port);
|
| 1229 | bool tb_lc_is_usb_plugged(struct tb_port *port);
|
| 1230 | bool tb_lc_is_xhci_connected(struct tb_port *port);
|
| 1231 | int tb_lc_xhci_connect(struct tb_port *port);
|
| 1232 | void tb_lc_xhci_disconnect(struct tb_port *port);
|
| 1233 | int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags);
|
| 1234 | int tb_lc_set_sleep(struct tb_switch *sw);
|
| 1235 | bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
|
| 1236 | bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in);
|
| 1237 | int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in);
|
| 1238 | int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in);
|
| 1239 | int tb_lc_force_power(struct tb_switch *sw);
|
| 1240 |
|
| 1241 | static inline int tb_route_length(u64 route)
|
| 1242 | {
|
| 1243 | return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT;
|
| 1244 | }
|
| 1245 |
|
| 1246 | |
| 1247 | * tb_downstream_route() - get route to downstream switch
|
| 1248 | * @port: Port to check
|
| 1249 | *
|
| 1250 | * Port must not be the upstream port (otherwise a loop is created).
|
| 1251 | *
|
| 1252 | * Return: Route to the switch behind @port.
|
| 1253 |
|
| 1254 | static inline u64 tb_downstream_route(struct tb_port *port)
|
| 1255 | {
|
| 1256 | return tb_route(port->sw)
|
| 1257 | | ((u64) port->port << (port->sw->config.depth * 8));
|
| 1258 | }
|
| 1259 |
|
| 1260 | bool tb_is_xdomain_enabled(void);
|
| 1261 | bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type,
|
| 1262 | const void *buf, size_t size);
|
| 1263 | struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
|
| 1264 | u64 route, const uuid_t *local_uuid,
|
| 1265 | const uuid_t *remote_uuid);
|
| 1266 | void tb_xdomain_add(struct tb_xdomain *xd);
|
| 1267 | void tb_xdomain_remove(struct tb_xdomain *xd);
|
| 1268 | void tb_xdomain_unregister(struct tb_xdomain *xd);
|
| 1269 | struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link,
|
| 1270 | u8 depth);
|
| 1271 |
|
| 1272 | static inline struct tb_switch *tb_xdomain_parent(struct tb_xdomain *xd)
|
| 1273 | {
|
| 1274 | return tb_to_switch(xd->dev.parent);
|
| 1275 | }
|
| 1276 |
|
| 1277 | |
| 1278 | * tb_xdomain_downstream_port() - Return downstream facing port of parent router
|
| 1279 | * @xd: Xdomain pointer
|
| 1280 | *
|
| 1281 | * Return: Pointer to &struct tb_port or %NULL in case of failure.
|
| 1282 |
|
| 1283 | static inline struct tb_port *tb_xdomain_downstream_port(struct tb_xdomain *xd)
|
| 1284 | {
|
| 1285 | return tb_port_at(xd->route, tb_xdomain_parent(xd));
|
| 1286 | }
|
| 1287 |
|
| 1288 | int tb_retimer_nvm_read(struct tb_retimer *rt, unsigned int address, void *buf,
|
| 1289 | size_t size);
|
| 1290 | int tb_retimer_scan(struct tb_port *port, bool add);
|
| 1291 | void tb_retimer_remove_all(struct tb_port *port);
|
| 1292 |
|
| 1293 | static inline bool tb_is_retimer(const struct device *dev)
|
| 1294 | {
|
| 1295 | return dev->type == &tb_retimer_type;
|
| 1296 | }
|
| 1297 |
|
| 1298 | static inline struct tb_retimer *tb_to_retimer(struct device *dev)
|
| 1299 | {
|
| 1300 | if (tb_is_retimer(dev))
|
| 1301 | return container_of(dev, struct tb_retimer, dev);
|
| 1302 | return NULL;
|
| 1303 | }
|
| 1304 |
|
| 1305 | |
| 1306 | * usb4_switch_version() - Returns USB4 version of the router
|
| 1307 | * @sw: Router to check
|
| 1308 | *
|
| 1309 | * Return: Major version of USB4 router (%1 for v1, %2 for v2 and so
|
| 1310 | * on). Can be called to pre-USB4 router too and in that case returns %0.
|
| 1311 |
|
| 1312 | static inline unsigned int usb4_switch_version(const struct tb_switch *sw)
|
| 1313 | {
|
| 1314 | return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version);
|
| 1315 | }
|
| 1316 |
|
| 1317 | |
| 1318 | * tb_switch_is_usb4() - Is the switch USB4 compliant
|
| 1319 | * @sw: Switch to check
|
| 1320 | *
|
| 1321 | * Return: %true if the @sw is USB4 compliant router, %false otherwise.
|
| 1322 |
|
| 1323 | static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
|
| 1324 | {
|
| 1325 | return usb4_switch_version(sw) > 0;
|
| 1326 | }
|
| 1327 |
|
| 1328 | void usb4_switch_check_wakes(struct tb_switch *sw);
|
| 1329 | int usb4_switch_setup(struct tb_switch *sw);
|
| 1330 | int usb4_switch_configuration_valid(struct tb_switch *sw);
|
| 1331 | int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
|
| 1332 | int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
|
| 1333 | size_t size);
|
| 1334 | bool usb4_switch_lane_bonding_possible(struct tb_switch *sw);
|
| 1335 | int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime);
|
| 1336 | int usb4_switch_set_sleep(struct tb_switch *sw);
|
| 1337 | int usb4_switch_nvm_sector_size(struct tb_switch *sw);
|
| 1338 | int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
|
| 1339 | size_t size);
|
| 1340 | int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address);
|
| 1341 | int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address,
|
| 1342 | const void *buf, size_t size);
|
| 1343 | int usb4_switch_nvm_authenticate(struct tb_switch *sw);
|
| 1344 | int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status);
|
| 1345 | int usb4_switch_credits_init(struct tb_switch *sw);
|
| 1346 | bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1347 | int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1348 | int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
|
| 1349 | struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw,
|
| 1350 | const struct tb_port *port);
|
| 1351 | struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw,
|
| 1352 | const struct tb_port *port);
|
| 1353 | int usb4_switch_add_ports(struct tb_switch *sw);
|
| 1354 | void usb4_switch_remove_ports(struct tb_switch *sw);
|
| 1355 |
|
| 1356 | int usb4_port_unlock(struct tb_port *port);
|
| 1357 | int usb4_port_hotplug_enable(struct tb_port *port);
|
| 1358 | int usb4_port_reset(struct tb_port *port);
|
| 1359 | int usb4_port_configure(struct tb_port *port);
|
| 1360 | void usb4_port_unconfigure(struct tb_port *port);
|
| 1361 | int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd);
|
| 1362 | void usb4_port_unconfigure_xdomain(struct tb_port *port);
|
| 1363 | int usb4_port_router_offline(struct tb_port *port);
|
| 1364 | int usb4_port_router_online(struct tb_port *port);
|
| 1365 | int usb4_port_enumerate_retimers(struct tb_port *port);
|
| 1366 | bool usb4_port_clx_supported(struct tb_port *port);
|
| 1367 |
|
| 1368 | bool usb4_port_asym_supported(struct tb_port *port);
|
| 1369 | int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width);
|
| 1370 | int usb4_port_asym_start(struct tb_port *port);
|
| 1371 |
|
| 1372 | |
| 1373 | * enum usb4_sb_target - Sideband transaction target
|
| 1374 | * @USB4_SB_TARGET_ROUTER: Target is the router itself
|
| 1375 | * @USB4_SB_TARGET_PARTNER: Target is partner
|
| 1376 | * @USB4_SB_TARGET_RETIMER: Target is retimer
|
| 1377 |
|
| 1378 | enum usb4_sb_target {
|
| 1379 | USB4_SB_TARGET_ROUTER,
|
| 1380 | USB4_SB_TARGET_PARTNER,
|
| 1381 | USB4_SB_TARGET_RETIMER,
|
| 1382 | };
|
| 1383 |
|
| 1384 | int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index,
|
| 1385 | u8 reg, void *buf, u8 size);
|
| 1386 | int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
|
| 1387 | u8 index, u8 reg, const void *buf, u8 size);
|
| 1388 |
|
| 1389 | |
| 1390 | * enum usb4_margin_sw_error_counter - Software margining error counter operation
|
| 1391 | * @USB4_MARGIN_SW_ERROR_COUNTER_NOP: No change in counter setup
|
| 1392 | * @USB4_MARGIN_SW_ERROR_COUNTER_CLEAR: Set the error counter to 0, enable counter
|
| 1393 | * @USB4_MARGIN_SW_ERROR_COUNTER_START: Start counter, count from last value
|
| 1394 | * @USB4_MARGIN_SW_ERROR_COUNTER_STOP: Stop counter, do not clear value
|
| 1395 |
|
| 1396 | enum usb4_margin_sw_error_counter {
|
| 1397 | USB4_MARGIN_SW_ERROR_COUNTER_NOP,
|
| 1398 | USB4_MARGIN_SW_ERROR_COUNTER_CLEAR,
|
| 1399 | USB4_MARGIN_SW_ERROR_COUNTER_START,
|
| 1400 | USB4_MARGIN_SW_ERROR_COUNTER_STOP,
|
| 1401 | };
|
| 1402 |
|
| 1403 | enum usb4_margining_lane {
|
| 1404 | USB4_MARGINING_LANE_RX0 = 0,
|
| 1405 | USB4_MARGINING_LANE_RX1 = 1,
|
| 1406 | USB4_MARGINING_LANE_RX2 = 2,
|
| 1407 | USB4_MARGINING_LANE_ALL = 7,
|
| 1408 | };
|
| 1409 |
|
| 1410 | |
| 1411 | * struct usb4_port_margining_params - USB4 margining parameters
|
| 1412 | * @error_counter: Error counter operation for software margining
|
| 1413 | * @ber_level: Current BER level contour value
|
| 1414 | * @lanes: Lanes to enable for the margining operation
|
| 1415 | * @voltage_time_offset: Offset for voltage / time for software margining
|
| 1416 | * @optional_voltage_offset_range: Enable optional extended voltage range
|
| 1417 | * @right_high: %false if left/low margin test is performed, %true if right/high
|
| 1418 | * @upper_eye: %true if margin test is done on upper eye, %false if done on
|
| 1419 | * lower eye
|
| 1420 | * @time: %true if time margining is used instead of voltage
|
| 1421 |
|
| 1422 | struct usb4_port_margining_params {
|
| 1423 | enum usb4_margin_sw_error_counter error_counter;
|
| 1424 | u32 ber_level;
|
| 1425 | enum usb4_margining_lane lanes;
|
| 1426 | u32 voltage_time_offset;
|
| 1427 | bool optional_voltage_offset_range;
|
| 1428 | bool right_high;
|
| 1429 | bool upper_eye;
|
| 1430 | bool time;
|
| 1431 | };
|
| 1432 |
|
| 1433 | int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target,
|
| 1434 | u8 index, u32 *caps, size_t ncaps);
|
| 1435 | int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target,
|
| 1436 | u8 index, const struct usb4_port_margining_params *params,
|
| 1437 | u32 *results, size_t nresults);
|
| 1438 | int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target,
|
| 1439 | u8 index, const struct usb4_port_margining_params *params,
|
| 1440 | u32 *results);
|
| 1441 | int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target,
|
| 1442 | u8 index, u32 *errors);
|
| 1443 |
|
| 1444 | int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
|
| 1445 | int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index);
|
| 1446 | int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
|
| 1447 | int usb4_port_retimer_is_cable(struct tb_port *port, u8 index);
|
| 1448 | int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
|
| 1449 | int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
|
| 1450 | unsigned int address);
|
| 1451 | int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
|
| 1452 | unsigned int address, const void *buf,
|
| 1453 | size_t size);
|
| 1454 | int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
|
| 1455 | int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
|
| 1456 | u32 *status);
|
| 1457 | int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
|
| 1458 | unsigned int address, void *buf, size_t size);
|
| 1459 |
|
| 1460 | int usb4_usb3_port_max_link_rate(struct tb_port *port);
|
| 1461 | int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
|
| 1462 | int *downstream_bw);
|
| 1463 | int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
|
| 1464 | int *downstream_bw);
|
| 1465 | int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
|
| 1466 | int *downstream_bw);
|
| 1467 |
|
| 1468 | int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id);
|
| 1469 | bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port);
|
| 1470 | bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port);
|
| 1471 | int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port,
|
| 1472 | bool supported);
|
| 1473 | int usb4_dp_port_group_id(struct tb_port *port);
|
| 1474 | int usb4_dp_port_set_group_id(struct tb_port *port, int group_id);
|
| 1475 | int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes);
|
| 1476 | int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes);
|
| 1477 | int usb4_dp_port_granularity(struct tb_port *port);
|
| 1478 | int usb4_dp_port_set_granularity(struct tb_port *port, int granularity);
|
| 1479 | int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw);
|
| 1480 | int usb4_dp_port_allocated_bandwidth(struct tb_port *port);
|
| 1481 | int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw);
|
| 1482 | int usb4_dp_port_requested_bandwidth(struct tb_port *port);
|
| 1483 |
|
| 1484 | int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
|
| 1485 | int usb4_pci_port_ltssm_state(struct tb_port *port);
|
| 1486 |
|
| 1487 | static inline bool tb_is_usb4_port_device(const struct device *dev)
|
| 1488 | {
|
| 1489 | return dev->type == &usb4_port_device_type;
|
| 1490 | }
|
| 1491 |
|
| 1492 | static inline struct usb4_port *tb_to_usb4_port_device(struct device *dev)
|
| 1493 | {
|
| 1494 | if (tb_is_usb4_port_device(dev))
|
| 1495 | return container_of(dev, struct usb4_port, dev);
|
| 1496 | return NULL;
|
| 1497 | }
|
| 1498 |
|
| 1499 | struct usb4_port *usb4_port_device_add(struct tb_port *port);
|
| 1500 | void usb4_port_device_remove(struct usb4_port *usb4);
|
| 1501 | int usb4_port_device_resume(struct usb4_port *usb4);
|
| 1502 | int usb4_port_index(const struct tb_switch *sw, const struct tb_port *port);
|
| 1503 |
|
| 1504 | static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4)
|
| 1505 | {
|
| 1506 | return usb4->offline;
|
| 1507 | }
|
| 1508 |
|
| 1509 | void tb_check_quirks(struct tb_switch *sw);
|
| 1510 |
|
| 1511 | #ifdef CONFIG_ACPI
|
| 1512 | bool tb_acpi_add_links(struct tb_nhi *nhi);
|
| 1513 |
|
| 1514 | bool tb_acpi_is_native(void);
|
| 1515 | bool tb_acpi_may_tunnel_usb3(void);
|
| 1516 | bool tb_acpi_may_tunnel_dp(void);
|
| 1517 | bool tb_acpi_may_tunnel_pcie(void);
|
| 1518 | bool tb_acpi_is_xdomain_allowed(void);
|
| 1519 |
|
| 1520 | int tb_acpi_init(void);
|
| 1521 | void tb_acpi_exit(void);
|
| 1522 | int tb_acpi_power_on_retimers(struct tb_port *port);
|
| 1523 | int tb_acpi_power_off_retimers(struct tb_port *port);
|
| 1524 | #else
|
| 1525 | static inline bool tb_acpi_add_links(struct tb_nhi *nhi) { return false; }
|
| 1526 |
|
| 1527 | static inline bool tb_acpi_is_native(void) { return true; }
|
| 1528 | static inline bool tb_acpi_may_tunnel_usb3(void) { return true; }
|
| 1529 | static inline bool tb_acpi_may_tunnel_dp(void) { return true; }
|
| 1530 | static inline bool tb_acpi_may_tunnel_pcie(void) { return true; }
|
| 1531 | static inline bool tb_acpi_is_xdomain_allowed(void) { return true; }
|
| 1532 |
|
| 1533 | static inline int tb_acpi_init(void) { return 0; }
|
| 1534 | static inline void tb_acpi_exit(void) { }
|
| 1535 | static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; }
|
| 1536 | static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; }
|
| 1537 | #endif
|
| 1538 |
|
| 1539 | #ifdef CONFIG_DEBUG_FS
|
| 1540 | void tb_debugfs_init(void);
|
| 1541 | void tb_debugfs_exit(void);
|
| 1542 | void tb_switch_debugfs_init(struct tb_switch *sw);
|
| 1543 | void tb_switch_debugfs_remove(struct tb_switch *sw);
|
| 1544 | void tb_xdomain_debugfs_init(struct tb_xdomain *xd);
|
| 1545 | void tb_xdomain_debugfs_remove(struct tb_xdomain *xd);
|
| 1546 | void tb_service_debugfs_init(struct tb_service *svc);
|
| 1547 | void tb_service_debugfs_remove(struct tb_service *svc);
|
| 1548 | void tb_retimer_debugfs_init(struct tb_retimer *rt);
|
| 1549 | void tb_retimer_debugfs_remove(struct tb_retimer *rt);
|
| 1550 | #else
|
| 1551 | static inline void tb_debugfs_init(void) { }
|
| 1552 | static inline void tb_debugfs_exit(void) { }
|
| 1553 | static inline void tb_switch_debugfs_init(struct tb_switch *sw) { }
|
| 1554 | static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { }
|
| 1555 | static inline void tb_xdomain_debugfs_init(struct tb_xdomain *xd) { }
|
| 1556 | static inline void tb_xdomain_debugfs_remove(struct tb_xdomain *xd) { }
|
| 1557 | static inline void tb_service_debugfs_init(struct tb_service *svc) { }
|
| 1558 | static inline void tb_service_debugfs_remove(struct tb_service *svc) { }
|
| 1559 | static inline void tb_retimer_debugfs_init(struct tb_retimer *rt) { }
|
| 1560 | static inline void tb_retimer_debugfs_remove(struct tb_retimer *rt) { }
|
| 1561 | #endif
|
| 1562 |
|
| 1563 | #if IS_REACHABLE(CONFIG_CONFIGFS_FS)
|
| 1564 | int tb_configfs_init(void);
|
| 1565 | void tb_configfs_exit(void);
|
| 1566 | #else
|
| 1567 | static inline int tb_configfs_init(void) { return 0; }
|
| 1568 | static inline void tb_configfs_exit(void) { }
|
| 1569 | #endif
|
| 1570 |
|
| 1571 | #endif
|