pci_insn.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #ifndef _ASM_S390_PCI_INSN_H
  2. #define _ASM_S390_PCI_INSN_H
  3. #include <linux/delay.h>
  4. #define ZPCI_INSN_BUSY_DELAY 1 /* 1 microsecond */
  5. /* Load/Store status codes */
  6. #define ZPCI_PCI_ST_FUNC_NOT_ENABLED 4
  7. #define ZPCI_PCI_ST_FUNC_IN_ERR 8
  8. #define ZPCI_PCI_ST_BLOCKED 12
  9. #define ZPCI_PCI_ST_INSUF_RES 16
  10. #define ZPCI_PCI_ST_INVAL_AS 20
  11. #define ZPCI_PCI_ST_FUNC_ALREADY_ENABLED 24
  12. #define ZPCI_PCI_ST_DMA_AS_NOT_ENABLED 28
  13. #define ZPCI_PCI_ST_2ND_OP_IN_INV_AS 36
  14. #define ZPCI_PCI_ST_FUNC_NOT_AVAIL 40
  15. #define ZPCI_PCI_ST_ALREADY_IN_RQ_STATE 44
  16. /* Load/Store return codes */
  17. #define ZPCI_PCI_LS_OK 0
  18. #define ZPCI_PCI_LS_ERR 1
  19. #define ZPCI_PCI_LS_BUSY 2
  20. #define ZPCI_PCI_LS_INVAL_HANDLE 3
  21. /* Load/Store address space identifiers */
  22. #define ZPCI_PCIAS_MEMIO_0 0
  23. #define ZPCI_PCIAS_MEMIO_1 1
  24. #define ZPCI_PCIAS_MEMIO_2 2
  25. #define ZPCI_PCIAS_MEMIO_3 3
  26. #define ZPCI_PCIAS_MEMIO_4 4
  27. #define ZPCI_PCIAS_MEMIO_5 5
  28. #define ZPCI_PCIAS_CFGSPC 15
  29. /* Modify PCI Function Controls */
  30. #define ZPCI_MOD_FC_REG_INT 2
  31. #define ZPCI_MOD_FC_DEREG_INT 3
  32. #define ZPCI_MOD_FC_REG_IOAT 4
  33. #define ZPCI_MOD_FC_DEREG_IOAT 5
  34. #define ZPCI_MOD_FC_REREG_IOAT 6
  35. #define ZPCI_MOD_FC_RESET_ERROR 7
  36. #define ZPCI_MOD_FC_RESET_BLOCK 9
  37. #define ZPCI_MOD_FC_SET_MEASURE 10
  38. /* FIB function controls */
  39. #define ZPCI_FIB_FC_ENABLED 0x80
  40. #define ZPCI_FIB_FC_ERROR 0x40
  41. #define ZPCI_FIB_FC_LS_BLOCKED 0x20
  42. #define ZPCI_FIB_FC_DMAAS_REG 0x10
  43. /* FIB function controls */
  44. #define ZPCI_FIB_FC_ENABLED 0x80
  45. #define ZPCI_FIB_FC_ERROR 0x40
  46. #define ZPCI_FIB_FC_LS_BLOCKED 0x20
  47. #define ZPCI_FIB_FC_DMAAS_REG 0x10
  48. /* Function Information Block */
  49. struct zpci_fib {
  50. u32 fmt : 8; /* format */
  51. u32 : 24;
  52. u32 reserved1;
  53. u8 fc; /* function controls */
  54. u8 reserved2;
  55. u16 reserved3;
  56. u32 reserved4;
  57. u64 pba; /* PCI base address */
  58. u64 pal; /* PCI address limit */
  59. u64 iota; /* I/O Translation Anchor */
  60. u32 : 1;
  61. u32 isc : 3; /* Interrupt subclass */
  62. u32 noi : 12; /* Number of interrupts */
  63. u32 : 2;
  64. u32 aibvo : 6; /* Adapter interrupt bit vector offset */
  65. u32 sum : 1; /* Adapter int summary bit enabled */
  66. u32 : 1;
  67. u32 aisbo : 6; /* Adapter int summary bit offset */
  68. u32 reserved5;
  69. u64 aibv; /* Adapter int bit vector address */
  70. u64 aisb; /* Adapter int summary bit address */
  71. u64 fmb_addr; /* Function measurement block address and key */
  72. u64 reserved6;
  73. u64 reserved7;
  74. } __packed;
  75. /* Modify PCI Function Controls */
  76. static inline u8 __mpcifc(u64 req, struct zpci_fib *fib, u8 *status)
  77. {
  78. u8 cc;
  79. asm volatile (
  80. " .insn rxy,0xe300000000d0,%[req],%[fib]\n"
  81. " ipm %[cc]\n"
  82. " srl %[cc],28\n"
  83. : [cc] "=d" (cc), [req] "+d" (req), [fib] "+Q" (*fib)
  84. : : "cc");
  85. *status = req >> 24 & 0xff;
  86. return cc;
  87. }
  88. static inline int mpcifc_instr(u64 req, struct zpci_fib *fib)
  89. {
  90. u8 cc, status;
  91. do {
  92. cc = __mpcifc(req, fib, &status);
  93. if (cc == 2)
  94. msleep(ZPCI_INSN_BUSY_DELAY);
  95. } while (cc == 2);
  96. if (cc)
  97. printk_once(KERN_ERR "%s: error cc: %d status: %d\n",
  98. __func__, cc, status);
  99. return (cc) ? -EIO : 0;
  100. }
  101. /* Refresh PCI Translations */
  102. static inline u8 __rpcit(u64 fn, u64 addr, u64 range, u8 *status)
  103. {
  104. register u64 __addr asm("2") = addr;
  105. register u64 __range asm("3") = range;
  106. u8 cc;
  107. asm volatile (
  108. " .insn rre,0xb9d30000,%[fn],%[addr]\n"
  109. " ipm %[cc]\n"
  110. " srl %[cc],28\n"
  111. : [cc] "=d" (cc), [fn] "+d" (fn)
  112. : [addr] "d" (__addr), "d" (__range)
  113. : "cc");
  114. *status = fn >> 24 & 0xff;
  115. return cc;
  116. }
  117. static inline int rpcit_instr(u64 fn, u64 addr, u64 range)
  118. {
  119. u8 cc, status;
  120. do {
  121. cc = __rpcit(fn, addr, range, &status);
  122. if (cc == 2)
  123. udelay(ZPCI_INSN_BUSY_DELAY);
  124. } while (cc == 2);
  125. if (cc)
  126. printk_once(KERN_ERR "%s: error cc: %d status: %d dma_addr: %Lx size: %Lx\n",
  127. __func__, cc, status, addr, range);
  128. return (cc) ? -EIO : 0;
  129. }
  130. /* Store PCI function controls */
  131. static inline u8 __stpcifc(u32 handle, u8 space, struct zpci_fib *fib, u8 *status)
  132. {
  133. u64 fn = (u64) handle << 32 | space << 16;
  134. u8 cc;
  135. asm volatile (
  136. " .insn rxy,0xe300000000d4,%[fn],%[fib]\n"
  137. " ipm %[cc]\n"
  138. " srl %[cc],28\n"
  139. : [cc] "=d" (cc), [fn] "+d" (fn), [fib] "=m" (*fib)
  140. : : "cc");
  141. *status = fn >> 24 & 0xff;
  142. return cc;
  143. }
  144. /* Set Interruption Controls */
  145. static inline void sic_instr(u16 ctl, char *unused, u8 isc)
  146. {
  147. asm volatile (
  148. " .insn rsy,0xeb00000000d1,%[ctl],%[isc],%[u]\n"
  149. : : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));
  150. }
  151. /* PCI Load */
  152. static inline u8 __pcilg(u64 *data, u64 req, u64 offset, u8 *status)
  153. {
  154. register u64 __req asm("2") = req;
  155. register u64 __offset asm("3") = offset;
  156. u64 __data;
  157. u8 cc;
  158. asm volatile (
  159. " .insn rre,0xb9d20000,%[data],%[req]\n"
  160. " ipm %[cc]\n"
  161. " srl %[cc],28\n"
  162. : [cc] "=d" (cc), [data] "=d" (__data), [req] "+d" (__req)
  163. : "d" (__offset)
  164. : "cc");
  165. *status = __req >> 24 & 0xff;
  166. *data = __data;
  167. return cc;
  168. }
  169. static inline int pcilg_instr(u64 *data, u64 req, u64 offset)
  170. {
  171. u8 cc, status;
  172. do {
  173. cc = __pcilg(data, req, offset, &status);
  174. if (cc == 2)
  175. udelay(ZPCI_INSN_BUSY_DELAY);
  176. } while (cc == 2);
  177. if (cc) {
  178. printk_once(KERN_ERR "%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
  179. __func__, cc, status, req, offset);
  180. /* TODO: on IO errors set data to 0xff...
  181. * here or in users of pcilg (le conversion)?
  182. */
  183. }
  184. return (cc) ? -EIO : 0;
  185. }
  186. /* PCI Store */
  187. static inline u8 __pcistg(u64 data, u64 req, u64 offset, u8 *status)
  188. {
  189. register u64 __req asm("2") = req;
  190. register u64 __offset asm("3") = offset;
  191. u8 cc;
  192. asm volatile (
  193. " .insn rre,0xb9d00000,%[data],%[req]\n"
  194. " ipm %[cc]\n"
  195. " srl %[cc],28\n"
  196. : [cc] "=d" (cc), [req] "+d" (__req)
  197. : "d" (__offset), [data] "d" (data)
  198. : "cc");
  199. *status = __req >> 24 & 0xff;
  200. return cc;
  201. }
  202. static inline int pcistg_instr(u64 data, u64 req, u64 offset)
  203. {
  204. u8 cc, status;
  205. do {
  206. cc = __pcistg(data, req, offset, &status);
  207. if (cc == 2)
  208. udelay(ZPCI_INSN_BUSY_DELAY);
  209. } while (cc == 2);
  210. if (cc)
  211. printk_once(KERN_ERR "%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
  212. __func__, cc, status, req, offset);
  213. return (cc) ? -EIO : 0;
  214. }
  215. /* PCI Store Block */
  216. static inline u8 __pcistb(const u64 *data, u64 req, u64 offset, u8 *status)
  217. {
  218. u8 cc;
  219. asm volatile (
  220. " .insn rsy,0xeb00000000d0,%[req],%[offset],%[data]\n"
  221. " ipm %[cc]\n"
  222. " srl %[cc],28\n"
  223. : [cc] "=d" (cc), [req] "+d" (req)
  224. : [offset] "d" (offset), [data] "Q" (*data)
  225. : "cc");
  226. *status = req >> 24 & 0xff;
  227. return cc;
  228. }
  229. static inline int pcistb_instr(const u64 *data, u64 req, u64 offset)
  230. {
  231. u8 cc, status;
  232. do {
  233. cc = __pcistb(data, req, offset, &status);
  234. if (cc == 2)
  235. udelay(ZPCI_INSN_BUSY_DELAY);
  236. } while (cc == 2);
  237. if (cc)
  238. printk_once(KERN_ERR "%s: error cc: %d status: %d req: %Lx offset: %Lx\n",
  239. __func__, cc, status, req, offset);
  240. return (cc) ? -EIO : 0;
  241. }
  242. #endif