tb_regs.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Thunderbolt Cactus Ridge driver - Port/Switch config area registers
  4. *
  5. * Every thunderbolt device consists (logically) of a switch with multiple
  6. * ports. Every port contains up to four config regions (HOPS, PORT, SWITCH,
  7. * COUNTERS) which are used to configure the device.
  8. *
  9. * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
  10. */
  11. #ifndef _TB_REGS
  12. #define _TB_REGS
  13. #include <linux/types.h>
  14. #define TB_ROUTE_SHIFT 8 /* number of bits in a port entry of a route */
  15. /*
  16. * TODO: should be 63? But we do not know how to receive frames larger than 256
  17. * bytes at the frame level. (header + checksum = 16, 60*4 = 240)
  18. */
  19. #define TB_MAX_CONFIG_RW_LENGTH 60
  20. enum tb_switch_cap {
  21. TB_SWITCH_CAP_VSE = 0x05,
  22. };
  23. enum tb_switch_vse_cap {
  24. TB_VSE_CAP_PLUG_EVENTS = 0x01, /* also EEPROM */
  25. TB_VSE_CAP_TIME2 = 0x03,
  26. TB_VSE_CAP_IECS = 0x04,
  27. TB_VSE_CAP_LINK_CONTROLLER = 0x06, /* also IECS */
  28. };
  29. enum tb_port_cap {
  30. TB_PORT_CAP_PHY = 0x01,
  31. TB_PORT_CAP_TIME1 = 0x03,
  32. TB_PORT_CAP_ADAP = 0x04,
  33. TB_PORT_CAP_VSE = 0x05,
  34. };
  35. enum tb_port_state {
  36. TB_PORT_DISABLED = 0, /* tb_cap_phy.disable == 1 */
  37. TB_PORT_CONNECTING = 1, /* retry */
  38. TB_PORT_UP = 2,
  39. TB_PORT_UNPLUGGED = 7,
  40. };
  41. /* capability headers */
  42. struct tb_cap_basic {
  43. u8 next;
  44. /* enum tb_cap cap:8; prevent "narrower than values of its type" */
  45. u8 cap; /* if cap == 0x05 then we have a extended capability */
  46. } __packed;
  47. /**
  48. * struct tb_cap_extended_short - Switch extended short capability
  49. * @next: Pointer to the next capability. If @next and @length are zero
  50. * then we have a long cap.
  51. * @cap: Base capability ID (see &enum tb_switch_cap)
  52. * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
  53. * @length: Length of this capability
  54. */
  55. struct tb_cap_extended_short {
  56. u8 next;
  57. u8 cap;
  58. u8 vsec_id;
  59. u8 length;
  60. } __packed;
  61. /**
  62. * struct tb_cap_extended_long - Switch extended long capability
  63. * @zero1: This field should be zero
  64. * @cap: Base capability ID (see &enum tb_switch_cap)
  65. * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
  66. * @zero2: This field should be zero
  67. * @next: Pointer to the next capability
  68. * @length: Length of this capability
  69. */
  70. struct tb_cap_extended_long {
  71. u8 zero1;
  72. u8 cap;
  73. u8 vsec_id;
  74. u8 zero2;
  75. u16 next;
  76. u16 length;
  77. } __packed;
  78. /* capabilities */
  79. struct tb_cap_link_controller {
  80. struct tb_cap_extended_long cap_header;
  81. u32 count:4; /* number of link controllers */
  82. u32 unknown1:4;
  83. u32 base_offset:8; /*
  84. * offset (into this capability) of the configuration
  85. * area of the first link controller
  86. */
  87. u32 length:12; /* link controller configuration area length */
  88. u32 unknown2:4; /* TODO check that length is correct */
  89. } __packed;
  90. struct tb_cap_phy {
  91. struct tb_cap_basic cap_header;
  92. u32 unknown1:16;
  93. u32 unknown2:14;
  94. bool disable:1;
  95. u32 unknown3:11;
  96. enum tb_port_state state:4;
  97. u32 unknown4:2;
  98. } __packed;
  99. struct tb_eeprom_ctl {
  100. bool clock:1; /* send pulse to transfer one bit */
  101. bool access_low:1; /* set to 0 before access */
  102. bool data_out:1; /* to eeprom */
  103. bool data_in:1; /* from eeprom */
  104. bool access_high:1; /* set to 1 before access */
  105. bool not_present:1; /* should be 0 */
  106. bool unknown1:1;
  107. bool present:1; /* should be 1 */
  108. u32 unknown2:24;
  109. } __packed;
  110. struct tb_cap_plug_events {
  111. struct tb_cap_extended_short cap_header;
  112. u32 __unknown1:2;
  113. u32 plug_events:5;
  114. u32 __unknown2:25;
  115. u32 __unknown3;
  116. u32 __unknown4;
  117. struct tb_eeprom_ctl eeprom_ctl;
  118. u32 __unknown5[7];
  119. u32 drom_offset; /* 32 bit register, but eeprom addresses are 16 bit */
  120. } __packed;
  121. /* device headers */
  122. /* Present on port 0 in TB_CFG_SWITCH at address zero. */
  123. struct tb_regs_switch_header {
  124. /* DWORD 0 */
  125. u16 vendor_id;
  126. u16 device_id;
  127. /* DWORD 1 */
  128. u32 first_cap_offset:8;
  129. u32 upstream_port_number:6;
  130. u32 max_port_number:6;
  131. u32 depth:3;
  132. u32 __unknown1:1;
  133. u32 revision:8;
  134. /* DWORD 2 */
  135. u32 route_lo;
  136. /* DWORD 3 */
  137. u32 route_hi:31;
  138. bool enabled:1;
  139. /* DWORD 4 */
  140. u32 plug_events_delay:8; /*
  141. * RW, pause between plug events in
  142. * milliseconds. Writing 0x00 is interpreted
  143. * as 255ms.
  144. */
  145. u32 __unknown4:16;
  146. u32 thunderbolt_version:8;
  147. } __packed;
  148. enum tb_port_type {
  149. TB_TYPE_INACTIVE = 0x000000,
  150. TB_TYPE_PORT = 0x000001,
  151. TB_TYPE_NHI = 0x000002,
  152. /* TB_TYPE_ETHERNET = 0x020000, lower order bits are not known */
  153. /* TB_TYPE_SATA = 0x080000, lower order bits are not known */
  154. TB_TYPE_DP_HDMI_IN = 0x0e0101,
  155. TB_TYPE_DP_HDMI_OUT = 0x0e0102,
  156. TB_TYPE_PCIE_DOWN = 0x100101,
  157. TB_TYPE_PCIE_UP = 0x100102,
  158. /* TB_TYPE_USB = 0x200000, lower order bits are not known */
  159. };
  160. /* Present on every port in TB_CF_PORT at address zero. */
  161. struct tb_regs_port_header {
  162. /* DWORD 0 */
  163. u16 vendor_id;
  164. u16 device_id;
  165. /* DWORD 1 */
  166. u32 first_cap_offset:8;
  167. u32 max_counters:11;
  168. u32 __unknown1:5;
  169. u32 revision:8;
  170. /* DWORD 2 */
  171. enum tb_port_type type:24;
  172. u32 thunderbolt_version:8;
  173. /* DWORD 3 */
  174. u32 __unknown2:20;
  175. u32 port_number:6;
  176. u32 __unknown3:6;
  177. /* DWORD 4 */
  178. u32 nfc_credits;
  179. /* DWORD 5 */
  180. u32 max_in_hop_id:11;
  181. u32 max_out_hop_id:11;
  182. u32 __unknown4:10;
  183. /* DWORD 6 */
  184. u32 __unknown5;
  185. /* DWORD 7 */
  186. u32 __unknown6;
  187. } __packed;
  188. /* Hop register from TB_CFG_HOPS. 8 byte per entry. */
  189. struct tb_regs_hop {
  190. /* DWORD 0 */
  191. u32 next_hop:11; /*
  192. * hop to take after sending the packet through
  193. * out_port (on the incoming port of the next switch)
  194. */
  195. u32 out_port:6; /* next port of the path (on the same switch) */
  196. u32 initial_credits:8;
  197. u32 unknown1:6; /* set to zero */
  198. bool enable:1;
  199. /* DWORD 1 */
  200. u32 weight:4;
  201. u32 unknown2:4; /* set to zero */
  202. u32 priority:3;
  203. bool drop_packages:1;
  204. u32 counter:11; /* index into TB_CFG_COUNTERS on this port */
  205. bool counter_enable:1;
  206. bool ingress_fc:1;
  207. bool egress_fc:1;
  208. bool ingress_shared_buffer:1;
  209. bool egress_shared_buffer:1;
  210. u32 unknown3:4; /* set to zero */
  211. } __packed;
  212. #endif