ism.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef S390_ISM_H
  3. #define S390_ISM_H
  4. #include <linux/spinlock.h>
  5. #include <linux/types.h>
  6. #include <linux/pci.h>
  7. #include <linux/dibs.h>
  8. #include <asm/pci_insn.h>
  9. #define UTIL_STR_LEN 16
  10. #define ISM_ERROR 0xFFFF
  11. #define ISM_NR_DMBS 1920
  12. /*
  13. * Do not use the first word of the DMB bits to ensure 8 byte aligned access.
  14. */
  15. #define ISM_DMB_WORD_OFFSET 1
  16. #define ISM_DMB_BIT_OFFSET (ISM_DMB_WORD_OFFSET * 32)
  17. #define ISM_REG_SBA 0x1
  18. #define ISM_REG_IEQ 0x2
  19. #define ISM_READ_GID 0x3
  20. #define ISM_ADD_VLAN_ID 0x4
  21. #define ISM_DEL_VLAN_ID 0x5
  22. #define ISM_SET_VLAN 0x6
  23. #define ISM_RESET_VLAN 0x7
  24. #define ISM_QUERY_INFO 0x8
  25. #define ISM_QUERY_RGID 0x9
  26. #define ISM_REG_DMB 0xA
  27. #define ISM_UNREG_DMB 0xB
  28. #define ISM_SIGNAL_IEQ 0xE
  29. #define ISM_UNREG_SBA 0x11
  30. #define ISM_UNREG_IEQ 0x12
  31. enum ism_event_type {
  32. ISM_EVENT_BUF = 0x00,
  33. ISM_EVENT_DEV = 0x01,
  34. ISM_EVENT_SWR = 0x02
  35. };
  36. enum ism_event_code {
  37. ISM_BUF_DMB_UNREGISTERED = 0x04,
  38. ISM_BUF_USING_ISM_DEV_DISABLED = 0x08,
  39. ISM_BUF_OWNING_ISM_DEV_IN_ERR_STATE = 0x02,
  40. ISM_BUF_USING_ISM_DEV_IN_ERR_STATE = 0x03,
  41. ISM_BUF_VLAN_MISMATCH_WITH_OWNER = 0x05,
  42. ISM_BUF_VLAN_MISMATCH_WITH_USER = 0x06,
  43. ISM_DEV_GID_DISABLED = 0x07,
  44. ISM_DEV_GID_ERR_STATE = 0x01
  45. };
  46. struct ism_req_hdr {
  47. u32 cmd;
  48. u16 : 16;
  49. u16 len;
  50. };
  51. struct ism_resp_hdr {
  52. u32 cmd;
  53. u16 ret;
  54. u16 len;
  55. };
  56. union ism_reg_sba {
  57. struct {
  58. struct ism_req_hdr hdr;
  59. u64 sba;
  60. } request;
  61. struct {
  62. struct ism_resp_hdr hdr;
  63. } response;
  64. } __aligned(16);
  65. union ism_reg_ieq {
  66. struct {
  67. struct ism_req_hdr hdr;
  68. u64 ieq;
  69. u64 len;
  70. } request;
  71. struct {
  72. struct ism_resp_hdr hdr;
  73. } response;
  74. } __aligned(16);
  75. /* ISM-vPCI devices provide 64 Bit GIDs
  76. * Map them to ISM UUID GIDs like this:
  77. * _________________________________________
  78. * | 64 Bit ISM-vPCI GID | 00000000_00000000 |
  79. * -----------------------------------------
  80. * This will be interpreted as a UIID variant, that is reserved
  81. * for NCS backward compatibility. So it will not collide with
  82. * proper UUIDs.
  83. */
  84. union ism_read_gid {
  85. struct {
  86. struct ism_req_hdr hdr;
  87. } request;
  88. struct {
  89. struct ism_resp_hdr hdr;
  90. u64 gid;
  91. } response;
  92. } __aligned(16);
  93. union ism_qi {
  94. struct {
  95. struct ism_req_hdr hdr;
  96. } request;
  97. struct {
  98. struct ism_resp_hdr hdr;
  99. u32 version;
  100. u32 max_len;
  101. u64 ism_state;
  102. u64 my_gid;
  103. u64 sba;
  104. u64 ieq;
  105. u32 ieq_len;
  106. u32 : 32;
  107. u32 dmbs_owned;
  108. u32 dmbs_used;
  109. u32 vlan_required;
  110. u32 vlan_nr_ids;
  111. u16 vlan_id[64];
  112. } response;
  113. } __aligned(64);
  114. union ism_query_rgid {
  115. struct {
  116. struct ism_req_hdr hdr;
  117. u64 rgid;
  118. u32 vlan_valid;
  119. u32 vlan_id;
  120. } request;
  121. struct {
  122. struct ism_resp_hdr hdr;
  123. } response;
  124. } __aligned(16);
  125. union ism_reg_dmb {
  126. struct {
  127. struct ism_req_hdr hdr;
  128. u64 dmb;
  129. u32 dmb_len;
  130. u32 sba_idx;
  131. u32 vlan_valid;
  132. u32 vlan_id;
  133. u64 rgid;
  134. } request;
  135. struct {
  136. struct ism_resp_hdr hdr;
  137. u64 dmb_tok;
  138. } response;
  139. } __aligned(32);
  140. union ism_sig_ieq {
  141. struct {
  142. struct ism_req_hdr hdr;
  143. u64 rgid;
  144. u32 trigger_irq;
  145. u32 event_code;
  146. u64 info;
  147. } request;
  148. struct {
  149. struct ism_resp_hdr hdr;
  150. } response;
  151. } __aligned(32);
  152. union ism_unreg_dmb {
  153. struct {
  154. struct ism_req_hdr hdr;
  155. u64 dmb_tok;
  156. } request;
  157. struct {
  158. struct ism_resp_hdr hdr;
  159. } response;
  160. } __aligned(16);
  161. union ism_cmd_simple {
  162. struct {
  163. struct ism_req_hdr hdr;
  164. } request;
  165. struct {
  166. struct ism_resp_hdr hdr;
  167. } response;
  168. } __aligned(8);
  169. union ism_set_vlan_id {
  170. struct {
  171. struct ism_req_hdr hdr;
  172. u64 vlan_id;
  173. } request;
  174. struct {
  175. struct ism_resp_hdr hdr;
  176. } response;
  177. } __aligned(16);
  178. struct ism_eq_header {
  179. u64 idx;
  180. u64 ieq_len;
  181. u64 entry_len;
  182. u64 : 64;
  183. };
  184. struct ism_event {
  185. u32 type;
  186. u32 code;
  187. u64 tok;
  188. u64 time;
  189. u64 info;
  190. };
  191. struct ism_eq {
  192. struct ism_eq_header header;
  193. struct ism_event entry[15];
  194. };
  195. struct ism_sba {
  196. u32 s : 1; /* summary bit */
  197. u32 e : 1; /* event bit */
  198. u32 : 30;
  199. u32 dmb_bits[ISM_NR_DMBS / 32];
  200. u32 reserved[3];
  201. u16 dmbe_mask[ISM_NR_DMBS];
  202. };
  203. struct ism_dev {
  204. spinlock_t cmd_lock; /* serializes cmds */
  205. struct dibs_dev *dibs;
  206. struct pci_dev *pdev;
  207. struct ism_sba *sba;
  208. dma_addr_t sba_dma_addr;
  209. DECLARE_BITMAP(sba_bitmap, ISM_NR_DMBS);
  210. struct ism_eq *ieq;
  211. dma_addr_t ieq_dma_addr;
  212. int ieq_idx;
  213. };
  214. #define ISM_CREATE_REQ(dmb, idx, sf, offset) \
  215. ((dmb) | (idx) << 24 | (sf) << 23 | (offset))
  216. static inline void __ism_read_cmd(struct ism_dev *ism, void *data,
  217. unsigned long offset, unsigned long len)
  218. {
  219. struct zpci_dev *zdev = to_zpci(ism->pdev);
  220. u64 req = ZPCI_CREATE_REQ(zdev->fh, 2, 8);
  221. while (len > 0) {
  222. __zpci_load(data, req, offset);
  223. offset += 8;
  224. data += 8;
  225. len -= 8;
  226. }
  227. }
  228. static inline void __ism_write_cmd(struct ism_dev *ism, void *data,
  229. unsigned long offset, unsigned long len)
  230. {
  231. struct zpci_dev *zdev = to_zpci(ism->pdev);
  232. u64 req = ZPCI_CREATE_REQ(zdev->fh, 2, len);
  233. if (len)
  234. __zpci_store_block(data, req, offset);
  235. }
  236. static inline int __ism_move(struct ism_dev *ism, u64 dmb_req, void *data,
  237. unsigned int size)
  238. {
  239. struct zpci_dev *zdev = to_zpci(ism->pdev);
  240. u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, size);
  241. return __zpci_store_block(data, req, dmb_req);
  242. }
  243. #endif /* S390_ISM_H */