tb_regs.h 5.0 KB

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