etr.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright IBM Corp. 2006
  3. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  4. */
  5. #ifndef __S390_ETR_H
  6. #define __S390_ETR_H
  7. /* ETR attachment control register */
  8. struct etr_eacr {
  9. unsigned int e0 : 1; /* port 0 stepping control */
  10. unsigned int e1 : 1; /* port 1 stepping control */
  11. unsigned int _pad0 : 5; /* must be 00100 */
  12. unsigned int dp : 1; /* data port control */
  13. unsigned int p0 : 1; /* port 0 change recognition control */
  14. unsigned int p1 : 1; /* port 1 change recognition control */
  15. unsigned int _pad1 : 3; /* must be 000 */
  16. unsigned int ea : 1; /* ETR alert control */
  17. unsigned int es : 1; /* ETR sync check control */
  18. unsigned int sl : 1; /* switch to local control */
  19. } __attribute__ ((packed));
  20. /* Port state returned by steai */
  21. enum etr_psc {
  22. etr_psc_operational = 0,
  23. etr_psc_semi_operational = 1,
  24. etr_psc_protocol_error = 4,
  25. etr_psc_no_symbols = 8,
  26. etr_psc_no_signal = 12,
  27. etr_psc_pps_mode = 13
  28. };
  29. /* Logical port state returned by stetr */
  30. enum etr_lpsc {
  31. etr_lpsc_operational_step = 0,
  32. etr_lpsc_operational_alt = 1,
  33. etr_lpsc_semi_operational = 2,
  34. etr_lpsc_protocol_error = 4,
  35. etr_lpsc_no_symbol_sync = 8,
  36. etr_lpsc_no_signal = 12,
  37. etr_lpsc_pps_mode = 13
  38. };
  39. /* ETR status words */
  40. struct etr_esw {
  41. struct etr_eacr eacr; /* attachment control register */
  42. unsigned int y : 1; /* stepping mode */
  43. unsigned int _pad0 : 5; /* must be 00000 */
  44. unsigned int p : 1; /* stepping port number */
  45. unsigned int q : 1; /* data port number */
  46. unsigned int psc0 : 4; /* port 0 state code */
  47. unsigned int psc1 : 4; /* port 1 state code */
  48. } __attribute__ ((packed));
  49. /* Second level data register status word */
  50. struct etr_slsw {
  51. unsigned int vv1 : 1; /* copy of validity bit data frame 1 */
  52. unsigned int vv2 : 1; /* copy of validity bit data frame 2 */
  53. unsigned int vv3 : 1; /* copy of validity bit data frame 3 */
  54. unsigned int vv4 : 1; /* copy of validity bit data frame 4 */
  55. unsigned int _pad0 : 19; /* must by all zeroes */
  56. unsigned int n : 1; /* EAF port number */
  57. unsigned int v1 : 1; /* validity bit ETR data frame 1 */
  58. unsigned int v2 : 1; /* validity bit ETR data frame 2 */
  59. unsigned int v3 : 1; /* validity bit ETR data frame 3 */
  60. unsigned int v4 : 1; /* validity bit ETR data frame 4 */
  61. unsigned int _pad1 : 4; /* must be 0000 */
  62. } __attribute__ ((packed));
  63. /* ETR data frames */
  64. struct etr_edf1 {
  65. unsigned int u : 1; /* untuned bit */
  66. unsigned int _pad0 : 1; /* must be 0 */
  67. unsigned int r : 1; /* service request bit */
  68. unsigned int _pad1 : 4; /* must be 0000 */
  69. unsigned int a : 1; /* time adjustment bit */
  70. unsigned int net_id : 8; /* ETR network id */
  71. unsigned int etr_id : 8; /* id of ETR which sends data frames */
  72. unsigned int etr_pn : 8; /* port number of ETR output port */
  73. } __attribute__ ((packed));
  74. struct etr_edf2 {
  75. unsigned int etv : 32; /* Upper 32 bits of TOD. */
  76. } __attribute__ ((packed));
  77. struct etr_edf3 {
  78. unsigned int rc : 8; /* failure reason code */
  79. unsigned int _pad0 : 3; /* must be 000 */
  80. unsigned int c : 1; /* ETR coupled bit */
  81. unsigned int tc : 4; /* ETR type code */
  82. unsigned int blto : 8; /* biased local time offset */
  83. /* (blto - 128) * 15 = minutes */
  84. unsigned int buo : 8; /* biased utc offset */
  85. /* (buo - 128) = leap seconds */
  86. } __attribute__ ((packed));
  87. struct etr_edf4 {
  88. unsigned int ed : 8; /* ETS device dependent data */
  89. unsigned int _pad0 : 1; /* must be 0 */
  90. unsigned int buc : 5; /* biased ut1 correction */
  91. /* (buc - 16) * 0.1 seconds */
  92. unsigned int em : 6; /* ETS error magnitude */
  93. unsigned int dc : 6; /* ETS drift code */
  94. unsigned int sc : 6; /* ETS steering code */
  95. } __attribute__ ((packed));
  96. /*
  97. * ETR attachment information block, two formats
  98. * format 1 has 4 reserved words with a size of 64 bytes
  99. * format 2 has 16 reserved words with a size of 96 bytes
  100. */
  101. struct etr_aib {
  102. struct etr_esw esw;
  103. struct etr_slsw slsw;
  104. unsigned long long tsp;
  105. struct etr_edf1 edf1;
  106. struct etr_edf2 edf2;
  107. struct etr_edf3 edf3;
  108. struct etr_edf4 edf4;
  109. unsigned int reserved[16];
  110. } __attribute__ ((packed,aligned(8)));
  111. /* ETR interruption parameter */
  112. struct etr_irq_parm {
  113. unsigned int _pad0 : 8;
  114. unsigned int pc0 : 1; /* port 0 state change */
  115. unsigned int pc1 : 1; /* port 1 state change */
  116. unsigned int _pad1 : 3;
  117. unsigned int eai : 1; /* ETR alert indication */
  118. unsigned int _pad2 : 18;
  119. } __attribute__ ((packed));
  120. /* Query TOD offset result */
  121. struct etr_ptff_qto {
  122. unsigned long long physical_clock;
  123. unsigned long long tod_offset;
  124. unsigned long long logical_tod_offset;
  125. unsigned long long tod_epoch_difference;
  126. } __attribute__ ((packed));
  127. /* Inline assembly helper functions */
  128. static inline int etr_setr(struct etr_eacr *ctrl)
  129. {
  130. int rc = -ENOSYS;
  131. asm volatile(
  132. " .insn s,0xb2160000,%1\n"
  133. "0: la %0,0\n"
  134. "1:\n"
  135. EX_TABLE(0b,1b)
  136. : "+d" (rc) : "Q" (*ctrl));
  137. return rc;
  138. }
  139. /* Stores a format 1 aib with 64 bytes */
  140. static inline int etr_stetr(struct etr_aib *aib)
  141. {
  142. int rc = -ENOSYS;
  143. asm volatile(
  144. " .insn s,0xb2170000,%1\n"
  145. "0: la %0,0\n"
  146. "1:\n"
  147. EX_TABLE(0b,1b)
  148. : "+d" (rc) : "Q" (*aib));
  149. return rc;
  150. }
  151. /* Stores a format 2 aib with 96 bytes for specified port */
  152. static inline int etr_steai(struct etr_aib *aib, unsigned int func)
  153. {
  154. register unsigned int reg0 asm("0") = func;
  155. int rc = -ENOSYS;
  156. asm volatile(
  157. " .insn s,0xb2b30000,%1\n"
  158. "0: la %0,0\n"
  159. "1:\n"
  160. EX_TABLE(0b,1b)
  161. : "+d" (rc) : "Q" (*aib), "d" (reg0));
  162. return rc;
  163. }
  164. /* Function codes for the steai instruction. */
  165. #define ETR_STEAI_STEPPING_PORT 0x10
  166. #define ETR_STEAI_ALTERNATE_PORT 0x11
  167. #define ETR_STEAI_PORT_0 0x12
  168. #define ETR_STEAI_PORT_1 0x13
  169. static inline int etr_ptff(void *ptff_block, unsigned int func)
  170. {
  171. register unsigned int reg0 asm("0") = func;
  172. register unsigned long reg1 asm("1") = (unsigned long) ptff_block;
  173. int rc = -ENOSYS;
  174. asm volatile(
  175. " .word 0x0104\n"
  176. " ipm %0\n"
  177. " srl %0,28\n"
  178. : "=d" (rc), "=m" (ptff_block)
  179. : "d" (reg0), "d" (reg1), "m" (ptff_block) : "cc");
  180. return rc;
  181. }
  182. /* Function codes for the ptff instruction. */
  183. #define ETR_PTFF_QAF 0x00 /* query available functions */
  184. #define ETR_PTFF_QTO 0x01 /* query tod offset */
  185. #define ETR_PTFF_QSI 0x02 /* query steering information */
  186. #define ETR_PTFF_ATO 0x40 /* adjust tod offset */
  187. #define ETR_PTFF_STO 0x41 /* set tod offset */
  188. #define ETR_PTFF_SFS 0x42 /* set fine steering rate */
  189. #define ETR_PTFF_SGS 0x43 /* set gross steering rate */
  190. /* Functions needed by the machine check handler */
  191. void etr_switch_to_local(void);
  192. void etr_sync_check(void);
  193. /* STP interruption parameter */
  194. struct stp_irq_parm {
  195. unsigned int _pad0 : 14;
  196. unsigned int tsc : 1; /* Timing status change */
  197. unsigned int lac : 1; /* Link availability change */
  198. unsigned int tcpc : 1; /* Time control parameter change */
  199. unsigned int _pad2 : 15;
  200. } __attribute__ ((packed));
  201. #define STP_OP_SYNC 1
  202. #define STP_OP_CTRL 3
  203. struct stp_sstpi {
  204. unsigned int rsvd0;
  205. unsigned int rsvd1 : 8;
  206. unsigned int stratum : 8;
  207. unsigned int vbits : 16;
  208. unsigned int leaps : 16;
  209. unsigned int tmd : 4;
  210. unsigned int ctn : 4;
  211. unsigned int rsvd2 : 3;
  212. unsigned int c : 1;
  213. unsigned int tst : 4;
  214. unsigned int tzo : 16;
  215. unsigned int dsto : 16;
  216. unsigned int ctrl : 16;
  217. unsigned int rsvd3 : 16;
  218. unsigned int tto;
  219. unsigned int rsvd4;
  220. unsigned int ctnid[3];
  221. unsigned int rsvd5;
  222. unsigned int todoff[4];
  223. unsigned int rsvd6[48];
  224. } __attribute__ ((packed));
  225. /* Functions needed by the machine check handler */
  226. void stp_sync_check(void);
  227. void stp_island_check(void);
  228. #endif /* __S390_ETR_H */