qdio.h 10 KB

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