tb.h 54 KB

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