qdio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * linux/drivers/s390/cio/qdio.h
  3. *
  4. * Copyright 2000,2008 IBM Corp.
  5. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  6. * Jan Glauber <jang@linux.vnet.ibm.com>
  7. */
  8. #ifndef _CIO_QDIO_H
  9. #define _CIO_QDIO_H
  10. #include <asm/page.h>
  11. #include <asm/schid.h>
  12. #include <asm/debug.h>
  13. #include "chsc.h"
  14. #define QDIO_BUSY_BIT_PATIENCE 100 /* 100 microseconds */
  15. #define QDIO_BUSY_BIT_GIVE_UP 2000000 /* 2 seconds = eternity */
  16. #define QDIO_INPUT_THRESHOLD 500 /* 500 microseconds */
  17. /*
  18. * if an asynchronous HiperSockets queue runs full, the 10 seconds timer wait
  19. * till next initiative to give transmitted skbs back to the stack is too long.
  20. * Therefore polling is started in case of multicast queue is filled more
  21. * than 50 percent.
  22. */
  23. #define QDIO_IQDIO_POLL_LVL 65 /* HS multicast queue */
  24. enum qdio_irq_states {
  25. QDIO_IRQ_STATE_INACTIVE,
  26. QDIO_IRQ_STATE_ESTABLISHED,
  27. QDIO_IRQ_STATE_ACTIVE,
  28. QDIO_IRQ_STATE_STOPPED,
  29. QDIO_IRQ_STATE_CLEANUP,
  30. QDIO_IRQ_STATE_ERR,
  31. NR_QDIO_IRQ_STATES,
  32. };
  33. /* used as intparm in do_IO */
  34. #define QDIO_DOING_ESTABLISH 1
  35. #define QDIO_DOING_ACTIVATE 2
  36. #define QDIO_DOING_CLEANUP 3
  37. #define SLSB_STATE_NOT_INIT 0x0
  38. #define SLSB_STATE_EMPTY 0x1
  39. #define SLSB_STATE_PRIMED 0x2
  40. #define SLSB_STATE_HALTED 0xe
  41. #define SLSB_STATE_ERROR 0xf
  42. #define SLSB_TYPE_INPUT 0x0
  43. #define SLSB_TYPE_OUTPUT 0x20
  44. #define SLSB_OWNER_PROG 0x80
  45. #define SLSB_OWNER_CU 0x40
  46. #define SLSB_P_INPUT_NOT_INIT \
  47. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_NOT_INIT) /* 0x80 */
  48. #define SLSB_P_INPUT_ACK \
  49. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x81 */
  50. #define SLSB_CU_INPUT_EMPTY \
  51. (SLSB_OWNER_CU | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x41 */
  52. #define SLSB_P_INPUT_PRIMED \
  53. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_PRIMED) /* 0x82 */
  54. #define SLSB_P_INPUT_HALTED \
  55. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_HALTED) /* 0x8e */
  56. #define SLSB_P_INPUT_ERROR \
  57. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_ERROR) /* 0x8f */
  58. #define SLSB_P_OUTPUT_NOT_INIT \
  59. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_NOT_INIT) /* 0xa0 */
  60. #define SLSB_P_OUTPUT_EMPTY \
  61. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_EMPTY) /* 0xa1 */
  62. #define SLSB_CU_OUTPUT_PRIMED \
  63. (SLSB_OWNER_CU | SLSB_TYPE_OUTPUT | SLSB_STATE_PRIMED) /* 0x62 */
  64. #define SLSB_P_OUTPUT_HALTED \
  65. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_HALTED) /* 0xae */
  66. #define SLSB_P_OUTPUT_ERROR \
  67. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_ERROR) /* 0xaf */
  68. #define SLSB_ERROR_DURING_LOOKUP 0xff
  69. /* additional CIWs returned by extended Sense-ID */
  70. #define CIW_TYPE_EQUEUE 0x3 /* establish QDIO queues */
  71. #define CIW_TYPE_AQUEUE 0x4 /* activate QDIO queues */
  72. /* flags for st qdio sch data */
  73. #define CHSC_FLAG_QDIO_CAPABILITY 0x80
  74. #define CHSC_FLAG_VALIDITY 0x40
  75. /* qdio adapter-characteristics-1 flag */
  76. #define AC1_SIGA_INPUT_NEEDED 0x40 /* process input queues */
  77. #define AC1_SIGA_OUTPUT_NEEDED 0x20 /* process output queues */
  78. #define AC1_SIGA_SYNC_NEEDED 0x10 /* ask hypervisor to sync */
  79. #define AC1_AUTOMATIC_SYNC_ON_THININT 0x08 /* set by hypervisor */
  80. #define AC1_AUTOMATIC_SYNC_ON_OUT_PCI 0x04 /* set by hypervisor */
  81. #define AC1_SC_QEBSM_AVAILABLE 0x02 /* available for subchannel */
  82. #define AC1_SC_QEBSM_ENABLED 0x01 /* enabled for subchannel */
  83. #ifdef CONFIG_64BIT
  84. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  85. int *start, int *count)
  86. {
  87. register unsigned long _ccq asm ("0") = *count;
  88. register unsigned long _token asm ("1") = token;
  89. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  90. asm volatile(
  91. " .insn rsy,0xeb000000008A,%1,0,0(%2)"
  92. : "+d" (_ccq), "+d" (_queuestart)
  93. : "d" ((unsigned long)state), "d" (_token)
  94. : "memory", "cc");
  95. *count = _ccq & 0xff;
  96. *start = _queuestart & 0xff;
  97. return (_ccq >> 32) & 0xff;
  98. }
  99. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  100. int *start, int *count)
  101. {
  102. register unsigned long _ccq asm ("0") = *count;
  103. register unsigned long _token asm ("1") = token;
  104. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  105. unsigned long _state = 0;
  106. asm volatile(
  107. " .insn rrf,0xB99c0000,%1,%2,0,0"
  108. : "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
  109. : "d" (_token)
  110. : "memory", "cc");
  111. *count = _ccq & 0xff;
  112. *start = _queuestart & 0xff;
  113. *state = _state & 0xff;
  114. return (_ccq >> 32) & 0xff;
  115. }
  116. #else
  117. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  118. int *start, int *count) { return 0; }
  119. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  120. int *start, int *count) { return 0; }
  121. #endif /* CONFIG_64BIT */
  122. struct qdio_irq;
  123. struct siga_flag {
  124. u8 input:1;
  125. u8 output:1;
  126. u8 sync:1;
  127. u8 no_sync_ti:1;
  128. u8 no_sync_out_ti:1;
  129. u8 no_sync_out_pci:1;
  130. u8:2;
  131. } __attribute__ ((packed));
  132. struct chsc_ssqd_area {
  133. struct chsc_header request;
  134. u16:10;
  135. u8 ssid:2;
  136. u8 fmt:4;
  137. u16 first_sch;
  138. u16:16;
  139. u16 last_sch;
  140. u32:32;
  141. struct chsc_header response;
  142. u32:32;
  143. struct qdio_ssqd_desc qdio_ssqd;
  144. } __attribute__ ((packed));
  145. struct scssc_area {
  146. struct chsc_header request;
  147. u16 operation_code;
  148. u16:16;
  149. u32:32;
  150. u32:32;
  151. u64 summary_indicator_addr;
  152. u64 subchannel_indicator_addr;
  153. u32 ks:4;
  154. u32 kc:4;
  155. u32:21;
  156. u32 isc:3;
  157. u32 word_with_d_bit;
  158. u32:32;
  159. struct subchannel_id schid;
  160. u32 reserved[1004];
  161. struct chsc_header response;
  162. u32:32;
  163. } __attribute__ ((packed));
  164. struct qdio_input_q {
  165. /* input buffer acknowledgement flag */
  166. int polling;
  167. /* last time of noticing incoming data */
  168. u64 timestamp;
  169. /* lock for clearing the acknowledgement */
  170. spinlock_t lock;
  171. };
  172. struct qdio_output_q {
  173. /* failed siga-w attempts*/
  174. atomic_t busy_siga_counter;
  175. /* start time of busy condition */
  176. u64 timestamp;
  177. /* PCIs are enabled for the queue */
  178. int pci_out_enabled;
  179. /* IQDIO: output multiple buffers (enhanced SIGA) */
  180. int use_enh_siga;
  181. /* timer to check for more outbound work */
  182. struct timer_list timer;
  183. };
  184. struct qdio_q {
  185. struct slsb slsb;
  186. union {
  187. struct qdio_input_q in;
  188. struct qdio_output_q out;
  189. } u;
  190. /* queue number */
  191. int nr;
  192. /* bitmask of queue number */
  193. int mask;
  194. /* input or output queue */
  195. int is_input_q;
  196. /* list of thinint input queues */
  197. struct list_head entry;
  198. /* upper-layer program handler */
  199. qdio_handler_t (*handler);
  200. /*
  201. * inbound: next buffer the program should check for
  202. * outbound: next buffer to check for having been processed
  203. * by the card
  204. */
  205. int first_to_check;
  206. /* first_to_check of the last time */
  207. int last_move_ftc;
  208. /* beginning position for calling the program */
  209. int first_to_kick;
  210. /* number of buffers in use by the adapter */
  211. atomic_t nr_buf_used;
  212. struct qdio_irq *irq_ptr;
  213. struct tasklet_struct tasklet;
  214. /* error condition during a data transfer */
  215. unsigned int qdio_error;
  216. struct sl *sl;
  217. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
  218. /*
  219. * Warning: Leave this member at the end so it won't be cleared in
  220. * qdio_fill_qs. A page is allocated under this pointer and used for
  221. * slib and sl. slib is 2048 bytes big and sl points to offset
  222. * PAGE_SIZE / 2.
  223. */
  224. struct slib *slib;
  225. } __attribute__ ((aligned(256)));
  226. struct qdio_irq {
  227. struct qib qib;
  228. u32 *dsci; /* address of device state change indicator */
  229. struct ccw_device *cdev;
  230. unsigned long int_parm;
  231. struct subchannel_id schid;
  232. unsigned long sch_token; /* QEBSM facility */
  233. enum qdio_irq_states state;
  234. struct siga_flag siga_flag; /* siga sync information from qdioac */
  235. int nr_input_qs;
  236. int nr_output_qs;
  237. struct ccw1 ccw;
  238. struct ciw equeue;
  239. struct ciw aqueue;
  240. struct qdio_ssqd_desc ssqd_desc;
  241. void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
  242. /*
  243. * Warning: Leave these members together at the end so they won't be
  244. * cleared in qdio_setup_irq.
  245. */
  246. struct qdr *qdr;
  247. unsigned long chsc_page;
  248. struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
  249. struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
  250. debug_info_t *debug_area;
  251. struct mutex setup_mutex;
  252. };
  253. /* helper functions */
  254. #define queue_type(q) q->irq_ptr->qib.qfmt
  255. #define SCH_NO(q) (q->irq_ptr->schid.sch_no)
  256. #define is_thinint_irq(irq) \
  257. (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
  258. css_general_characteristics.aif_osa)
  259. /* the highest iqdio queue is used for multicast */
  260. static inline int multicast_outbound(struct qdio_q *q)
  261. {
  262. return (q->irq_ptr->nr_output_qs > 1) &&
  263. (q->nr == q->irq_ptr->nr_output_qs - 1);
  264. }
  265. static inline unsigned long long get_usecs(void)
  266. {
  267. return monotonic_clock() >> 12;
  268. }
  269. #define pci_out_supported(q) \
  270. (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
  271. #define is_qebsm(q) (q->irq_ptr->sch_token != 0)
  272. #define need_siga_sync_thinint(q) (!q->irq_ptr->siga_flag.no_sync_ti)
  273. #define need_siga_sync_out_thinint(q) (!q->irq_ptr->siga_flag.no_sync_out_ti)
  274. #define need_siga_in(q) (q->irq_ptr->siga_flag.input)
  275. #define need_siga_out(q) (q->irq_ptr->siga_flag.output)
  276. #define need_siga_sync(q) (q->irq_ptr->siga_flag.sync)
  277. #define siga_syncs_out_pci(q) (q->irq_ptr->siga_flag.no_sync_out_pci)
  278. #define for_each_input_queue(irq_ptr, q, i) \
  279. for (i = 0, q = irq_ptr->input_qs[0]; \
  280. i < irq_ptr->nr_input_qs; \
  281. q = irq_ptr->input_qs[++i])
  282. #define for_each_output_queue(irq_ptr, q, i) \
  283. for (i = 0, q = irq_ptr->output_qs[0]; \
  284. i < irq_ptr->nr_output_qs; \
  285. q = irq_ptr->output_qs[++i])
  286. #define prev_buf(bufnr) \
  287. ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
  288. #define next_buf(bufnr) \
  289. ((bufnr + 1) & QDIO_MAX_BUFFERS_MASK)
  290. #define add_buf(bufnr, inc) \
  291. ((bufnr + inc) & QDIO_MAX_BUFFERS_MASK)
  292. /* prototypes for thin interrupt */
  293. void qdio_sync_after_thinint(struct qdio_q *q);
  294. int get_buf_state(struct qdio_q *q, unsigned int bufnr, unsigned char *state);
  295. void qdio_check_outbound_after_thinint(struct qdio_q *q);
  296. int qdio_inbound_q_moved(struct qdio_q *q);
  297. void qdio_kick_inbound_handler(struct qdio_q *q);
  298. void qdio_stop_polling(struct qdio_q *q);
  299. int qdio_siga_sync_q(struct qdio_q *q);
  300. void qdio_setup_thinint(struct qdio_irq *irq_ptr);
  301. int qdio_establish_thinint(struct qdio_irq *irq_ptr);
  302. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
  303. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr);
  304. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr);
  305. void tiqdio_inbound_processing(unsigned long q);
  306. int tiqdio_allocate_memory(void);
  307. void tiqdio_free_memory(void);
  308. int tiqdio_register_thinints(void);
  309. void tiqdio_unregister_thinints(void);
  310. /* prototypes for setup */
  311. void qdio_inbound_processing(unsigned long data);
  312. void qdio_outbound_processing(unsigned long data);
  313. void qdio_outbound_timer(unsigned long data);
  314. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  315. struct irb *irb);
  316. int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
  317. int nr_output_qs);
  318. void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
  319. int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
  320. struct subchannel_id *schid,
  321. struct qdio_ssqd_desc *data);
  322. int qdio_setup_irq(struct qdio_initialize *init_data);
  323. void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
  324. struct ccw_device *cdev);
  325. void qdio_release_memory(struct qdio_irq *irq_ptr);
  326. int qdio_setup_init(void);
  327. void qdio_setup_exit(void);
  328. #endif /* _CIO_QDIO_H */