qdio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * Copyright IBM Corp. 2000, 2008
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  4. * Jan Glauber <jang@linux.vnet.ibm.com>
  5. *
  6. */
  7. #ifndef __QDIO_H__
  8. #define __QDIO_H__
  9. #include <linux/interrupt.h>
  10. #include <asm/cio.h>
  11. #include <asm/ccwdev.h>
  12. /* only use 4 queues to save some cachelines */
  13. #define QDIO_MAX_QUEUES_PER_IRQ 4
  14. #define QDIO_MAX_BUFFERS_PER_Q 128
  15. #define QDIO_MAX_BUFFERS_MASK (QDIO_MAX_BUFFERS_PER_Q - 1)
  16. #define QDIO_MAX_ELEMENTS_PER_BUFFER 16
  17. #define QDIO_SBAL_SIZE 256
  18. #define QDIO_QETH_QFMT 0
  19. #define QDIO_ZFCP_QFMT 1
  20. #define QDIO_IQDIO_QFMT 2
  21. /**
  22. * struct qdesfmt0 - queue descriptor, format 0
  23. * @sliba: storage list information block address
  24. * @sla: storage list address
  25. * @slsba: storage list state block address
  26. * @akey: access key for DLIB
  27. * @bkey: access key for SL
  28. * @ckey: access key for SBALs
  29. * @dkey: access key for SLSB
  30. */
  31. struct qdesfmt0 {
  32. u64 sliba;
  33. u64 sla;
  34. u64 slsba;
  35. u32 : 32;
  36. u32 akey : 4;
  37. u32 bkey : 4;
  38. u32 ckey : 4;
  39. u32 dkey : 4;
  40. u32 : 16;
  41. } __attribute__ ((packed));
  42. #define QDR_AC_MULTI_BUFFER_ENABLE 0x01
  43. /**
  44. * struct qdr - queue description record (QDR)
  45. * @qfmt: queue format
  46. * @pfmt: implementation dependent parameter format
  47. * @ac: adapter characteristics
  48. * @iqdcnt: input queue descriptor count
  49. * @oqdcnt: output queue descriptor count
  50. * @iqdsz: inpout queue descriptor size
  51. * @oqdsz: output queue descriptor size
  52. * @qiba: queue information block address
  53. * @qkey: queue information block key
  54. * @qdf0: queue descriptions
  55. */
  56. struct qdr {
  57. u32 qfmt : 8;
  58. u32 pfmt : 8;
  59. u32 : 8;
  60. u32 ac : 8;
  61. u32 : 8;
  62. u32 iqdcnt : 8;
  63. u32 : 8;
  64. u32 oqdcnt : 8;
  65. u32 : 8;
  66. u32 iqdsz : 8;
  67. u32 : 8;
  68. u32 oqdsz : 8;
  69. /* private: */
  70. u32 res[9];
  71. /* public: */
  72. u64 qiba;
  73. u32 : 32;
  74. u32 qkey : 4;
  75. u32 : 28;
  76. struct qdesfmt0 qdf0[126];
  77. } __attribute__ ((packed, aligned(4096)));
  78. #define QIB_AC_OUTBOUND_PCI_SUPPORTED 0x40
  79. #define QIB_RFLAGS_ENABLE_QEBSM 0x80
  80. #define QIB_RFLAGS_ENABLE_DATA_DIV 0x02
  81. /**
  82. * struct qib - queue information block (QIB)
  83. * @qfmt: queue format
  84. * @pfmt: implementation dependent parameter format
  85. * @rflags: QEBSM
  86. * @ac: adapter characteristics
  87. * @isliba: absolute address of first input SLIB
  88. * @osliba: absolute address of first output SLIB
  89. * @ebcnam: adapter identifier in EBCDIC
  90. * @parm: implementation dependent parameters
  91. */
  92. struct qib {
  93. u32 qfmt : 8;
  94. u32 pfmt : 8;
  95. u32 rflags : 8;
  96. u32 ac : 8;
  97. u32 : 32;
  98. u64 isliba;
  99. u64 osliba;
  100. u32 : 32;
  101. u32 : 32;
  102. u8 ebcnam[8];
  103. /* private: */
  104. u8 res[88];
  105. /* public: */
  106. u8 parm[QDIO_MAX_BUFFERS_PER_Q];
  107. } __attribute__ ((packed, aligned(256)));
  108. /**
  109. * struct slibe - storage list information block element (SLIBE)
  110. * @parms: implementation dependent parameters
  111. */
  112. struct slibe {
  113. u64 parms;
  114. };
  115. /**
  116. * struct qaob - queue asynchronous operation block
  117. * @res0: reserved parameters
  118. * @res1: reserved parameter
  119. * @res2: reserved parameter
  120. * @res3: reserved parameter
  121. * @aorc: asynchronous operation return code
  122. * @flags: internal flags
  123. * @cbtbs: control block type
  124. * @sb_count: number of storage blocks
  125. * @sba: storage block element addresses
  126. * @dcount: size of storage block elements
  127. * @user0: user defineable value
  128. * @res4: reserved paramater
  129. * @user1: user defineable value
  130. * @user2: user defineable value
  131. */
  132. struct qaob {
  133. u64 res0[6];
  134. u8 res1;
  135. u8 res2;
  136. u8 res3;
  137. u8 aorc;
  138. u8 flags;
  139. u16 cbtbs;
  140. u8 sb_count;
  141. u64 sba[QDIO_MAX_ELEMENTS_PER_BUFFER];
  142. u16 dcount[QDIO_MAX_ELEMENTS_PER_BUFFER];
  143. u64 user0;
  144. u64 res4[2];
  145. u64 user1;
  146. u64 user2;
  147. } __attribute__ ((packed, aligned(256)));
  148. /**
  149. * struct slib - storage list information block (SLIB)
  150. * @nsliba: next SLIB address (if any)
  151. * @sla: SL address
  152. * @slsba: SLSB address
  153. * @slibe: SLIB elements
  154. */
  155. struct slib {
  156. u64 nsliba;
  157. u64 sla;
  158. u64 slsba;
  159. /* private: */
  160. u8 res[1000];
  161. /* public: */
  162. struct slibe slibe[QDIO_MAX_BUFFERS_PER_Q];
  163. } __attribute__ ((packed, aligned(2048)));
  164. #define SBAL_EFLAGS_LAST_ENTRY 0x40
  165. #define SBAL_EFLAGS_CONTIGUOUS 0x20
  166. #define SBAL_EFLAGS_FIRST_FRAG 0x04
  167. #define SBAL_EFLAGS_MIDDLE_FRAG 0x08
  168. #define SBAL_EFLAGS_LAST_FRAG 0x0c
  169. #define SBAL_EFLAGS_MASK 0x6f
  170. #define SBAL_SFLAGS0_PCI_REQ 0x40
  171. #define SBAL_SFLAGS0_DATA_CONTINUATION 0x20
  172. /* Awesome OpenFCP extensions */
  173. #define SBAL_SFLAGS0_TYPE_STATUS 0x00
  174. #define SBAL_SFLAGS0_TYPE_WRITE 0x08
  175. #define SBAL_SFLAGS0_TYPE_READ 0x10
  176. #define SBAL_SFLAGS0_TYPE_WRITE_READ 0x18
  177. #define SBAL_SFLAGS0_MORE_SBALS 0x04
  178. #define SBAL_SFLAGS0_COMMAND 0x02
  179. #define SBAL_SFLAGS0_LAST_SBAL 0x00
  180. #define SBAL_SFLAGS0_ONLY_SBAL SBAL_SFLAGS0_COMMAND
  181. #define SBAL_SFLAGS0_MIDDLE_SBAL SBAL_SFLAGS0_MORE_SBALS
  182. #define SBAL_SFLAGS0_FIRST_SBAL (SBAL_SFLAGS0_MORE_SBALS | SBAL_SFLAGS0_COMMAND)
  183. /**
  184. * struct qdio_buffer_element - SBAL entry
  185. * @eflags: SBAL entry flags
  186. * @scount: SBAL count
  187. * @sflags: whole SBAL flags
  188. * @length: length
  189. * @addr: address
  190. */
  191. struct qdio_buffer_element {
  192. u8 eflags;
  193. /* private: */
  194. u8 res1;
  195. /* public: */
  196. u8 scount;
  197. u8 sflags;
  198. u32 length;
  199. void *addr;
  200. } __attribute__ ((packed, aligned(16)));
  201. /**
  202. * struct qdio_buffer - storage block address list (SBAL)
  203. * @element: SBAL entries
  204. */
  205. struct qdio_buffer {
  206. struct qdio_buffer_element element[QDIO_MAX_ELEMENTS_PER_BUFFER];
  207. } __attribute__ ((packed, aligned(256)));
  208. /**
  209. * struct sl_element - storage list entry
  210. * @sbal: absolute SBAL address
  211. */
  212. struct sl_element {
  213. unsigned long sbal;
  214. } __attribute__ ((packed));
  215. /**
  216. * struct sl - storage list (SL)
  217. * @element: SL entries
  218. */
  219. struct sl {
  220. struct sl_element element[QDIO_MAX_BUFFERS_PER_Q];
  221. } __attribute__ ((packed, aligned(1024)));
  222. /**
  223. * struct slsb - storage list state block (SLSB)
  224. * @val: state per buffer
  225. */
  226. struct slsb {
  227. u8 val[QDIO_MAX_BUFFERS_PER_Q];
  228. } __attribute__ ((packed, aligned(256)));
  229. /**
  230. * struct qdio_outbuf_state - SBAL related asynchronous operation information
  231. * (for communication with upper layer programs)
  232. * (only required for use with completion queues)
  233. * @flags: flags indicating state of buffer
  234. * @aob: pointer to QAOB used for the particular SBAL
  235. * @user: pointer to upper layer program's state information related to SBAL
  236. * (stored in user1 data of QAOB)
  237. */
  238. struct qdio_outbuf_state {
  239. u8 flags;
  240. struct qaob *aob;
  241. void *user;
  242. };
  243. #define QDIO_OUTBUF_STATE_FLAG_NONE 0x00
  244. #define QDIO_OUTBUF_STATE_FLAG_PENDING 0x01
  245. #define CHSC_AC1_INITIATE_INPUTQ 0x80
  246. /* qdio adapter-characteristics-1 flag */
  247. #define AC1_SIGA_INPUT_NEEDED 0x40 /* process input queues */
  248. #define AC1_SIGA_OUTPUT_NEEDED 0x20 /* process output queues */
  249. #define AC1_SIGA_SYNC_NEEDED 0x10 /* ask hypervisor to sync */
  250. #define AC1_AUTOMATIC_SYNC_ON_THININT 0x08 /* set by hypervisor */
  251. #define AC1_AUTOMATIC_SYNC_ON_OUT_PCI 0x04 /* set by hypervisor */
  252. #define AC1_SC_QEBSM_AVAILABLE 0x02 /* available for subchannel */
  253. #define AC1_SC_QEBSM_ENABLED 0x01 /* enabled for subchannel */
  254. #define CHSC_AC2_MULTI_BUFFER_AVAILABLE 0x0080
  255. #define CHSC_AC2_MULTI_BUFFER_ENABLED 0x0040
  256. #define CHSC_AC2_DATA_DIV_AVAILABLE 0x0010
  257. #define CHSC_AC2_DATA_DIV_ENABLED 0x0002
  258. #define CHSC_AC3_FORMAT2_CQ_AVAILABLE 0x8000
  259. struct qdio_ssqd_desc {
  260. u8 flags;
  261. u8:8;
  262. u16 sch;
  263. u8 qfmt;
  264. u8 parm;
  265. u8 qdioac1;
  266. u8 sch_class;
  267. u8 pcnt;
  268. u8 icnt;
  269. u8:8;
  270. u8 ocnt;
  271. u8:8;
  272. u8 mbccnt;
  273. u16 qdioac2;
  274. u64 sch_token;
  275. u8 mro;
  276. u8 mri;
  277. u16 qdioac3;
  278. u16:16;
  279. u8:8;
  280. u8 mmwc;
  281. } __attribute__ ((packed));
  282. /* params are: ccw_device, qdio_error, queue_number,
  283. first element processed, number of elements processed, int_parm */
  284. typedef void qdio_handler_t(struct ccw_device *, unsigned int, int,
  285. int, int, unsigned long);
  286. /* qdio errors reported to the upper-layer program */
  287. #define QDIO_ERROR_ACTIVATE 0x0001
  288. #define QDIO_ERROR_GET_BUF_STATE 0x0002
  289. #define QDIO_ERROR_SET_BUF_STATE 0x0004
  290. #define QDIO_ERROR_SLSB_STATE 0x0100
  291. #define QDIO_ERROR_FATAL 0x00ff
  292. #define QDIO_ERROR_TEMPORARY 0xff00
  293. /* for qdio_cleanup */
  294. #define QDIO_FLAG_CLEANUP_USING_CLEAR 0x01
  295. #define QDIO_FLAG_CLEANUP_USING_HALT 0x02
  296. /**
  297. * struct qdio_initialize - qdio initialization data
  298. * @cdev: associated ccw device
  299. * @q_format: queue format
  300. * @adapter_name: name for the adapter
  301. * @qib_param_field_format: format for qib_parm_field
  302. * @qib_param_field: pointer to 128 bytes or NULL, if no param field
  303. * @qib_rflags: rflags to set
  304. * @input_slib_elements: pointer to no_input_qs * 128 words of data or NULL
  305. * @output_slib_elements: pointer to no_output_qs * 128 words of data or NULL
  306. * @no_input_qs: number of input queues
  307. * @no_output_qs: number of output queues
  308. * @input_handler: handler to be called for input queues
  309. * @output_handler: handler to be called for output queues
  310. * @queue_start_poll_array: polling handlers (one per input queue or NULL)
  311. * @int_parm: interruption parameter
  312. * @input_sbal_addr_array: address of no_input_qs * 128 pointers
  313. * @output_sbal_addr_array: address of no_output_qs * 128 pointers
  314. * @output_sbal_state_array: no_output_qs * 128 state info (for CQ or NULL)
  315. */
  316. struct qdio_initialize {
  317. struct ccw_device *cdev;
  318. unsigned char q_format;
  319. unsigned char qdr_ac;
  320. unsigned char adapter_name[8];
  321. unsigned int qib_param_field_format;
  322. unsigned char *qib_param_field;
  323. unsigned char qib_rflags;
  324. unsigned long *input_slib_elements;
  325. unsigned long *output_slib_elements;
  326. unsigned int no_input_qs;
  327. unsigned int no_output_qs;
  328. qdio_handler_t *input_handler;
  329. qdio_handler_t *output_handler;
  330. void (**queue_start_poll_array) (struct ccw_device *, int,
  331. unsigned long);
  332. int scan_threshold;
  333. unsigned long int_parm;
  334. void **input_sbal_addr_array;
  335. void **output_sbal_addr_array;
  336. struct qdio_outbuf_state *output_sbal_state_array;
  337. };
  338. /**
  339. * enum qdio_brinfo_entry_type - type of address entry for qdio_brinfo_desc()
  340. * @l3_ipv6_addr: entry contains IPv6 address
  341. * @l3_ipv4_addr: entry contains IPv4 address
  342. * @l2_addr_lnid: entry contains MAC address and VLAN ID
  343. */
  344. enum qdio_brinfo_entry_type {l3_ipv6_addr, l3_ipv4_addr, l2_addr_lnid};
  345. /**
  346. * struct qdio_brinfo_entry_XXX - Address entry for qdio_brinfo_desc()
  347. * @nit: Network interface token
  348. * @addr: Address of one of the three types
  349. *
  350. * The struct is passed to the callback function by qdio_brinfo_desc()
  351. */
  352. struct qdio_brinfo_entry_l3_ipv6 {
  353. u64 nit;
  354. struct { unsigned char _s6_addr[16]; } addr;
  355. } __packed;
  356. struct qdio_brinfo_entry_l3_ipv4 {
  357. u64 nit;
  358. struct { uint32_t _s_addr; } addr;
  359. } __packed;
  360. struct qdio_brinfo_entry_l2 {
  361. u64 nit;
  362. struct { u8 mac[6]; u16 lnid; } addr_lnid;
  363. } __packed;
  364. #define QDIO_STATE_INACTIVE 0x00000002 /* after qdio_cleanup */
  365. #define QDIO_STATE_ESTABLISHED 0x00000004 /* after qdio_establish */
  366. #define QDIO_STATE_ACTIVE 0x00000008 /* after qdio_activate */
  367. #define QDIO_STATE_STOPPED 0x00000010 /* after queues went down */
  368. #define QDIO_FLAG_SYNC_INPUT 0x01
  369. #define QDIO_FLAG_SYNC_OUTPUT 0x02
  370. #define QDIO_FLAG_PCI_OUT 0x10
  371. int qdio_alloc_buffers(struct qdio_buffer **buf, unsigned int count);
  372. void qdio_free_buffers(struct qdio_buffer **buf, unsigned int count);
  373. void qdio_reset_buffers(struct qdio_buffer **buf, unsigned int count);
  374. extern int qdio_allocate(struct qdio_initialize *);
  375. extern int qdio_establish(struct qdio_initialize *);
  376. extern int qdio_activate(struct ccw_device *);
  377. extern void qdio_release_aob(struct qaob *);
  378. extern int do_QDIO(struct ccw_device *, unsigned int, int, unsigned int,
  379. unsigned int);
  380. extern int qdio_start_irq(struct ccw_device *, int);
  381. extern int qdio_stop_irq(struct ccw_device *, int);
  382. extern int qdio_get_next_buffers(struct ccw_device *, int, int *, int *);
  383. extern int qdio_shutdown(struct ccw_device *, int);
  384. extern int qdio_free(struct ccw_device *);
  385. extern int qdio_get_ssqd_desc(struct ccw_device *, struct qdio_ssqd_desc *);
  386. extern int qdio_pnso_brinfo(struct subchannel_id schid,
  387. int cnc, u16 *response,
  388. void (*cb)(void *priv, enum qdio_brinfo_entry_type type,
  389. void *entry),
  390. void *priv);
  391. #endif /* __QDIO_H__ */