qdio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * Copyright IBM Corp. 2000, 2009
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  4. * Jan Glauber <jang@linux.vnet.ibm.com>
  5. */
  6. #ifndef _CIO_QDIO_H
  7. #define _CIO_QDIO_H
  8. #include <asm/page.h>
  9. #include <asm/schid.h>
  10. #include <asm/debug.h>
  11. #include "chsc.h"
  12. #define QDIO_BUSY_BIT_PATIENCE (100 << 12) /* 100 microseconds */
  13. #define QDIO_BUSY_BIT_RETRY_DELAY 10 /* 10 milliseconds */
  14. #define QDIO_BUSY_BIT_RETRIES 1000 /* = 10s retry time */
  15. #define QDIO_INPUT_THRESHOLD (500 << 12) /* 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_PENDING 0x3
  33. #define SLSB_STATE_HALTED 0xe
  34. #define SLSB_STATE_ERROR 0xf
  35. #define SLSB_TYPE_INPUT 0x0
  36. #define SLSB_TYPE_OUTPUT 0x20
  37. #define SLSB_OWNER_PROG 0x80
  38. #define SLSB_OWNER_CU 0x40
  39. #define SLSB_P_INPUT_NOT_INIT \
  40. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_NOT_INIT) /* 0x80 */
  41. #define SLSB_P_INPUT_ACK \
  42. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x81 */
  43. #define SLSB_CU_INPUT_EMPTY \
  44. (SLSB_OWNER_CU | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x41 */
  45. #define SLSB_P_INPUT_PRIMED \
  46. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_PRIMED) /* 0x82 */
  47. #define SLSB_P_INPUT_HALTED \
  48. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_HALTED) /* 0x8e */
  49. #define SLSB_P_INPUT_ERROR \
  50. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_ERROR) /* 0x8f */
  51. #define SLSB_P_OUTPUT_NOT_INIT \
  52. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_NOT_INIT) /* 0xa0 */
  53. #define SLSB_P_OUTPUT_EMPTY \
  54. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_EMPTY) /* 0xa1 */
  55. #define SLSB_P_OUTPUT_PENDING \
  56. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_PENDING) /* 0xa3 */
  57. #define SLSB_CU_OUTPUT_PRIMED \
  58. (SLSB_OWNER_CU | SLSB_TYPE_OUTPUT | SLSB_STATE_PRIMED) /* 0x62 */
  59. #define SLSB_P_OUTPUT_HALTED \
  60. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_HALTED) /* 0xae */
  61. #define SLSB_P_OUTPUT_ERROR \
  62. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_ERROR) /* 0xaf */
  63. #define SLSB_ERROR_DURING_LOOKUP 0xff
  64. /* additional CIWs returned by extended Sense-ID */
  65. #define CIW_TYPE_EQUEUE 0x3 /* establish QDIO queues */
  66. #define CIW_TYPE_AQUEUE 0x4 /* activate QDIO queues */
  67. /* flags for st qdio sch data */
  68. #define CHSC_FLAG_QDIO_CAPABILITY 0x80
  69. #define CHSC_FLAG_VALIDITY 0x40
  70. /* SIGA flags */
  71. #define QDIO_SIGA_WRITE 0x00
  72. #define QDIO_SIGA_READ 0x01
  73. #define QDIO_SIGA_SYNC 0x02
  74. #define QDIO_SIGA_WRITEQ 0x04
  75. #define QDIO_SIGA_QEBSM_FLAG 0x80
  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, int ack)
  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 = (unsigned long)ack << 63;
  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. struct qdio_irq;
  109. struct siga_flag {
  110. u8 input:1;
  111. u8 output:1;
  112. u8 sync:1;
  113. u8 sync_after_ai:1;
  114. u8 sync_out_after_pci:1;
  115. u8:3;
  116. } __attribute__ ((packed));
  117. struct qdio_dev_perf_stat {
  118. unsigned int adapter_int;
  119. unsigned int qdio_int;
  120. unsigned int pci_request_int;
  121. unsigned int tasklet_inbound;
  122. unsigned int tasklet_inbound_resched;
  123. unsigned int tasklet_inbound_resched2;
  124. unsigned int tasklet_outbound;
  125. unsigned int siga_read;
  126. unsigned int siga_write;
  127. unsigned int siga_sync;
  128. unsigned int inbound_call;
  129. unsigned int inbound_handler;
  130. unsigned int stop_polling;
  131. unsigned int inbound_queue_full;
  132. unsigned int outbound_call;
  133. unsigned int outbound_handler;
  134. unsigned int outbound_queue_full;
  135. unsigned int fast_requeue;
  136. unsigned int target_full;
  137. unsigned int eqbs;
  138. unsigned int eqbs_partial;
  139. unsigned int sqbs;
  140. unsigned int sqbs_partial;
  141. unsigned int int_discarded;
  142. } ____cacheline_aligned;
  143. struct qdio_queue_perf_stat {
  144. /*
  145. * Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128.
  146. * Since max. 127 SBALs are scanned reuse entry for 128 as queue full
  147. * aka 127 SBALs found.
  148. */
  149. unsigned int nr_sbals[8];
  150. unsigned int nr_sbal_error;
  151. unsigned int nr_sbal_nop;
  152. unsigned int nr_sbal_total;
  153. };
  154. enum qdio_queue_irq_states {
  155. QDIO_QUEUE_IRQS_DISABLED,
  156. };
  157. struct qdio_input_q {
  158. /* input buffer acknowledgement flag */
  159. int polling;
  160. /* first ACK'ed buffer */
  161. int ack_start;
  162. /* how much sbals are acknowledged with qebsm */
  163. int ack_count;
  164. /* last time of noticing incoming data */
  165. u64 timestamp;
  166. /* upper-layer polling flag */
  167. unsigned long queue_irq_state;
  168. /* callback to start upper-layer polling */
  169. void (*queue_start_poll) (struct ccw_device *, int, unsigned long);
  170. };
  171. struct qdio_output_q {
  172. /* PCIs are enabled for the queue */
  173. int pci_out_enabled;
  174. /* cq: use asynchronous output buffers */
  175. int use_cq;
  176. /* cq: aobs used for particual SBAL */
  177. struct qaob **aobs;
  178. /* cq: sbal state related to asynchronous operation */
  179. struct qdio_outbuf_state *sbal_state;
  180. /* timer to check for more outbound work */
  181. struct timer_list timer;
  182. /* used SBALs before tasklet schedule */
  183. int scan_threshold;
  184. };
  185. /*
  186. * Note on cache alignment: grouped slsb and write mostly data at the beginning
  187. * sbal[] is read-only and starts on a new cacheline followed by read mostly.
  188. */
  189. struct qdio_q {
  190. struct slsb slsb;
  191. union {
  192. struct qdio_input_q in;
  193. struct qdio_output_q out;
  194. } u;
  195. /*
  196. * inbound: next buffer the program should check for
  197. * outbound: next buffer to check if adapter processed it
  198. */
  199. int first_to_check;
  200. /* first_to_check of the last time */
  201. int last_move;
  202. /* beginning position for calling the program */
  203. int first_to_kick;
  204. /* number of buffers in use by the adapter */
  205. atomic_t nr_buf_used;
  206. /* error condition during a data transfer */
  207. unsigned int qdio_error;
  208. /* last scan of the queue */
  209. u64 timestamp;
  210. struct tasklet_struct tasklet;
  211. struct qdio_queue_perf_stat q_stats;
  212. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q] ____cacheline_aligned;
  213. /* queue number */
  214. int nr;
  215. /* bitmask of queue number */
  216. int mask;
  217. /* input or output queue */
  218. int is_input_q;
  219. /* list of thinint input queues */
  220. struct list_head entry;
  221. /* upper-layer program handler */
  222. qdio_handler_t (*handler);
  223. struct dentry *debugfs_q;
  224. struct qdio_irq *irq_ptr;
  225. struct sl *sl;
  226. /*
  227. * A page is allocated under this pointer and used for slib and sl.
  228. * slib is 2048 bytes big and sl points to offset PAGE_SIZE / 2.
  229. */
  230. struct slib *slib;
  231. } __attribute__ ((aligned(256)));
  232. struct qdio_irq {
  233. struct qib qib;
  234. u32 *dsci; /* address of device state change indicator */
  235. struct ccw_device *cdev;
  236. struct dentry *debugfs_dev;
  237. struct dentry *debugfs_perf;
  238. unsigned long int_parm;
  239. struct subchannel_id schid;
  240. unsigned long sch_token; /* QEBSM facility */
  241. enum qdio_irq_states state;
  242. struct siga_flag siga_flag; /* siga sync information from qdioac */
  243. int nr_input_qs;
  244. int nr_output_qs;
  245. struct ccw1 ccw;
  246. struct ciw equeue;
  247. struct ciw aqueue;
  248. struct qdio_ssqd_desc ssqd_desc;
  249. void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
  250. int perf_stat_enabled;
  251. struct qdr *qdr;
  252. unsigned long chsc_page;
  253. struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
  254. struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
  255. debug_info_t *debug_area;
  256. struct mutex setup_mutex;
  257. struct qdio_dev_perf_stat perf_stat;
  258. };
  259. /* helper functions */
  260. #define queue_type(q) q->irq_ptr->qib.qfmt
  261. #define SCH_NO(q) (q->irq_ptr->schid.sch_no)
  262. #define is_thinint_irq(irq) \
  263. (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
  264. css_general_characteristics.aif_osa)
  265. #define qperf(__qdev, __attr) ((__qdev)->perf_stat.(__attr))
  266. #define qperf_inc(__q, __attr) \
  267. ({ \
  268. struct qdio_irq *qdev = (__q)->irq_ptr; \
  269. if (qdev->perf_stat_enabled) \
  270. (qdev->perf_stat.__attr)++; \
  271. })
  272. static inline void account_sbals_error(struct qdio_q *q, int count)
  273. {
  274. q->q_stats.nr_sbal_error += count;
  275. q->q_stats.nr_sbal_total += count;
  276. }
  277. /* the highest iqdio queue is used for multicast */
  278. static inline int multicast_outbound(struct qdio_q *q)
  279. {
  280. return (q->irq_ptr->nr_output_qs > 1) &&
  281. (q->nr == q->irq_ptr->nr_output_qs - 1);
  282. }
  283. #define pci_out_supported(q) \
  284. (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
  285. #define is_qebsm(q) (q->irq_ptr->sch_token != 0)
  286. #define need_siga_in(q) (q->irq_ptr->siga_flag.input)
  287. #define need_siga_out(q) (q->irq_ptr->siga_flag.output)
  288. #define need_siga_sync(q) (unlikely(q->irq_ptr->siga_flag.sync))
  289. #define need_siga_sync_after_ai(q) \
  290. (unlikely(q->irq_ptr->siga_flag.sync_after_ai))
  291. #define need_siga_sync_out_after_pci(q) \
  292. (unlikely(q->irq_ptr->siga_flag.sync_out_after_pci))
  293. #define for_each_input_queue(irq_ptr, q, i) \
  294. for (i = 0; i < irq_ptr->nr_input_qs && \
  295. ({ q = irq_ptr->input_qs[i]; 1; }); i++)
  296. #define for_each_output_queue(irq_ptr, q, i) \
  297. for (i = 0; i < irq_ptr->nr_output_qs && \
  298. ({ q = irq_ptr->output_qs[i]; 1; }); i++)
  299. #define prev_buf(bufnr) \
  300. ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
  301. #define next_buf(bufnr) \
  302. ((bufnr + 1) & QDIO_MAX_BUFFERS_MASK)
  303. #define add_buf(bufnr, inc) \
  304. ((bufnr + inc) & QDIO_MAX_BUFFERS_MASK)
  305. #define sub_buf(bufnr, dec) \
  306. ((bufnr - dec) & QDIO_MAX_BUFFERS_MASK)
  307. #define queue_irqs_enabled(q) \
  308. (test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) == 0)
  309. #define queue_irqs_disabled(q) \
  310. (test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) != 0)
  311. extern u64 last_ai_time;
  312. /* prototypes for thin interrupt */
  313. void qdio_setup_thinint(struct qdio_irq *irq_ptr);
  314. int qdio_establish_thinint(struct qdio_irq *irq_ptr);
  315. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
  316. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr);
  317. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr);
  318. void tiqdio_inbound_processing(unsigned long q);
  319. int tiqdio_allocate_memory(void);
  320. void tiqdio_free_memory(void);
  321. int tiqdio_register_thinints(void);
  322. void tiqdio_unregister_thinints(void);
  323. void clear_nonshared_ind(struct qdio_irq *);
  324. int test_nonshared_ind(struct qdio_irq *);
  325. /* prototypes for setup */
  326. void qdio_inbound_processing(unsigned long data);
  327. void qdio_outbound_processing(unsigned long data);
  328. void qdio_outbound_timer(unsigned long data);
  329. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  330. struct irb *irb);
  331. int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
  332. int nr_output_qs);
  333. void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
  334. int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
  335. struct subchannel_id *schid,
  336. struct qdio_ssqd_desc *data);
  337. int qdio_setup_irq(struct qdio_initialize *init_data);
  338. void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
  339. struct ccw_device *cdev);
  340. void qdio_release_memory(struct qdio_irq *irq_ptr);
  341. int qdio_setup_create_sysfs(struct ccw_device *cdev);
  342. void qdio_setup_destroy_sysfs(struct ccw_device *cdev);
  343. int qdio_setup_init(void);
  344. void qdio_setup_exit(void);
  345. int qdio_enable_async_operation(struct qdio_output_q *q);
  346. void qdio_disable_async_operation(struct qdio_output_q *q);
  347. struct qaob *qdio_allocate_aob(void);
  348. int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
  349. unsigned char *state);
  350. #endif /* _CIO_QDIO_H */