qdio.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. #ifdef CONFIG_64BIT
  77. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  78. int *start, int *count)
  79. {
  80. register unsigned long _ccq asm ("0") = *count;
  81. register unsigned long _token asm ("1") = token;
  82. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  83. asm volatile(
  84. " .insn rsy,0xeb000000008A,%1,0,0(%2)"
  85. : "+d" (_ccq), "+d" (_queuestart)
  86. : "d" ((unsigned long)state), "d" (_token)
  87. : "memory", "cc");
  88. *count = _ccq & 0xff;
  89. *start = _queuestart & 0xff;
  90. return (_ccq >> 32) & 0xff;
  91. }
  92. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  93. int *start, int *count, int ack)
  94. {
  95. register unsigned long _ccq asm ("0") = *count;
  96. register unsigned long _token asm ("1") = token;
  97. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  98. unsigned long _state = (unsigned long)ack << 63;
  99. asm volatile(
  100. " .insn rrf,0xB99c0000,%1,%2,0,0"
  101. : "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
  102. : "d" (_token)
  103. : "memory", "cc");
  104. *count = _ccq & 0xff;
  105. *start = _queuestart & 0xff;
  106. *state = _state & 0xff;
  107. return (_ccq >> 32) & 0xff;
  108. }
  109. #else
  110. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  111. int *start, int *count) { return 0; }
  112. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  113. int *start, int *count, int ack) { return 0; }
  114. #endif /* CONFIG_64BIT */
  115. struct qdio_irq;
  116. struct siga_flag {
  117. u8 input:1;
  118. u8 output:1;
  119. u8 sync:1;
  120. u8 sync_after_ai:1;
  121. u8 sync_out_after_pci:1;
  122. u8:3;
  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_dev_perf_stat {
  157. unsigned int adapter_int;
  158. unsigned int qdio_int;
  159. unsigned int pci_request_int;
  160. unsigned int tasklet_inbound;
  161. unsigned int tasklet_inbound_resched;
  162. unsigned int tasklet_inbound_resched2;
  163. unsigned int tasklet_outbound;
  164. unsigned int siga_read;
  165. unsigned int siga_write;
  166. unsigned int siga_sync;
  167. unsigned int inbound_call;
  168. unsigned int inbound_handler;
  169. unsigned int stop_polling;
  170. unsigned int inbound_queue_full;
  171. unsigned int outbound_call;
  172. unsigned int outbound_handler;
  173. unsigned int outbound_queue_full;
  174. unsigned int fast_requeue;
  175. unsigned int target_full;
  176. unsigned int eqbs;
  177. unsigned int eqbs_partial;
  178. unsigned int sqbs;
  179. unsigned int sqbs_partial;
  180. unsigned int int_discarded;
  181. } ____cacheline_aligned;
  182. struct qdio_queue_perf_stat {
  183. /*
  184. * Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128.
  185. * Since max. 127 SBALs are scanned reuse entry for 128 as queue full
  186. * aka 127 SBALs found.
  187. */
  188. unsigned int nr_sbals[8];
  189. unsigned int nr_sbal_error;
  190. unsigned int nr_sbal_nop;
  191. unsigned int nr_sbal_total;
  192. };
  193. enum qdio_queue_irq_states {
  194. QDIO_QUEUE_IRQS_DISABLED,
  195. };
  196. struct qdio_input_q {
  197. /* input buffer acknowledgement flag */
  198. int polling;
  199. /* first ACK'ed buffer */
  200. int ack_start;
  201. /* how much sbals are acknowledged with qebsm */
  202. int ack_count;
  203. /* last time of noticing incoming data */
  204. u64 timestamp;
  205. /* upper-layer polling flag */
  206. unsigned long queue_irq_state;
  207. /* callback to start upper-layer polling */
  208. void (*queue_start_poll) (struct ccw_device *, int, unsigned long);
  209. };
  210. struct qdio_output_q {
  211. /* PCIs are enabled for the queue */
  212. int pci_out_enabled;
  213. /* cq: use asynchronous output buffers */
  214. int use_cq;
  215. /* cq: aobs used for particual SBAL */
  216. struct qaob **aobs;
  217. /* cq: sbal state related to asynchronous operation */
  218. struct qdio_outbuf_state *sbal_state;
  219. /* timer to check for more outbound work */
  220. struct timer_list timer;
  221. /* used SBALs before tasklet schedule */
  222. int scan_threshold;
  223. };
  224. /*
  225. * Note on cache alignment: grouped slsb and write mostly data at the beginning
  226. * sbal[] is read-only and starts on a new cacheline followed by read mostly.
  227. */
  228. struct qdio_q {
  229. struct slsb slsb;
  230. union {
  231. struct qdio_input_q in;
  232. struct qdio_output_q out;
  233. } u;
  234. /*
  235. * inbound: next buffer the program should check for
  236. * outbound: next buffer to check if adapter processed it
  237. */
  238. int first_to_check;
  239. /* first_to_check of the last time */
  240. int last_move;
  241. /* beginning position for calling the program */
  242. int first_to_kick;
  243. /* number of buffers in use by the adapter */
  244. atomic_t nr_buf_used;
  245. /* error condition during a data transfer */
  246. unsigned int qdio_error;
  247. /* last scan of the queue */
  248. u64 timestamp;
  249. struct tasklet_struct tasklet;
  250. struct qdio_queue_perf_stat q_stats;
  251. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q] ____cacheline_aligned;
  252. /* queue number */
  253. int nr;
  254. /* bitmask of queue number */
  255. int mask;
  256. /* input or output queue */
  257. int is_input_q;
  258. /* list of thinint input queues */
  259. struct list_head entry;
  260. /* upper-layer program handler */
  261. qdio_handler_t (*handler);
  262. struct dentry *debugfs_q;
  263. struct qdio_irq *irq_ptr;
  264. struct sl *sl;
  265. /*
  266. * A page is allocated under this pointer and used for slib and sl.
  267. * slib is 2048 bytes big and sl points to offset PAGE_SIZE / 2.
  268. */
  269. struct slib *slib;
  270. } __attribute__ ((aligned(256)));
  271. struct qdio_irq {
  272. struct qib qib;
  273. u32 *dsci; /* address of device state change indicator */
  274. struct ccw_device *cdev;
  275. struct dentry *debugfs_dev;
  276. struct dentry *debugfs_perf;
  277. unsigned long int_parm;
  278. struct subchannel_id schid;
  279. unsigned long sch_token; /* QEBSM facility */
  280. enum qdio_irq_states state;
  281. struct siga_flag siga_flag; /* siga sync information from qdioac */
  282. int nr_input_qs;
  283. int nr_output_qs;
  284. struct ccw1 ccw;
  285. struct ciw equeue;
  286. struct ciw aqueue;
  287. struct qdio_ssqd_desc ssqd_desc;
  288. void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
  289. int perf_stat_enabled;
  290. struct qdr *qdr;
  291. unsigned long chsc_page;
  292. struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
  293. struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
  294. debug_info_t *debug_area;
  295. struct mutex setup_mutex;
  296. struct qdio_dev_perf_stat perf_stat;
  297. };
  298. /* helper functions */
  299. #define queue_type(q) q->irq_ptr->qib.qfmt
  300. #define SCH_NO(q) (q->irq_ptr->schid.sch_no)
  301. #define is_thinint_irq(irq) \
  302. (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
  303. css_general_characteristics.aif_osa)
  304. #define qperf(__qdev, __attr) ((__qdev)->perf_stat.(__attr))
  305. #define qperf_inc(__q, __attr) \
  306. ({ \
  307. struct qdio_irq *qdev = (__q)->irq_ptr; \
  308. if (qdev->perf_stat_enabled) \
  309. (qdev->perf_stat.__attr)++; \
  310. })
  311. static inline void account_sbals_error(struct qdio_q *q, int count)
  312. {
  313. q->q_stats.nr_sbal_error += count;
  314. q->q_stats.nr_sbal_total += count;
  315. }
  316. /* the highest iqdio queue is used for multicast */
  317. static inline int multicast_outbound(struct qdio_q *q)
  318. {
  319. return (q->irq_ptr->nr_output_qs > 1) &&
  320. (q->nr == q->irq_ptr->nr_output_qs - 1);
  321. }
  322. #define pci_out_supported(q) \
  323. (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
  324. #define is_qebsm(q) (q->irq_ptr->sch_token != 0)
  325. #define need_siga_in(q) (q->irq_ptr->siga_flag.input)
  326. #define need_siga_out(q) (q->irq_ptr->siga_flag.output)
  327. #define need_siga_sync(q) (unlikely(q->irq_ptr->siga_flag.sync))
  328. #define need_siga_sync_after_ai(q) \
  329. (unlikely(q->irq_ptr->siga_flag.sync_after_ai))
  330. #define need_siga_sync_out_after_pci(q) \
  331. (unlikely(q->irq_ptr->siga_flag.sync_out_after_pci))
  332. #define for_each_input_queue(irq_ptr, q, i) \
  333. for (i = 0, q = irq_ptr->input_qs[0]; \
  334. i < irq_ptr->nr_input_qs; \
  335. q = irq_ptr->input_qs[++i])
  336. #define for_each_output_queue(irq_ptr, q, i) \
  337. for (i = 0, q = irq_ptr->output_qs[0]; \
  338. i < irq_ptr->nr_output_qs; \
  339. q = irq_ptr->output_qs[++i])
  340. #define prev_buf(bufnr) \
  341. ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
  342. #define next_buf(bufnr) \
  343. ((bufnr + 1) & QDIO_MAX_BUFFERS_MASK)
  344. #define add_buf(bufnr, inc) \
  345. ((bufnr + inc) & QDIO_MAX_BUFFERS_MASK)
  346. #define sub_buf(bufnr, dec) \
  347. ((bufnr - dec) & QDIO_MAX_BUFFERS_MASK)
  348. #define queue_irqs_enabled(q) \
  349. (test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) == 0)
  350. #define queue_irqs_disabled(q) \
  351. (test_bit(QDIO_QUEUE_IRQS_DISABLED, &q->u.in.queue_irq_state) != 0)
  352. extern u64 last_ai_time;
  353. /* prototypes for thin interrupt */
  354. void qdio_setup_thinint(struct qdio_irq *irq_ptr);
  355. int qdio_establish_thinint(struct qdio_irq *irq_ptr);
  356. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
  357. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr);
  358. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr);
  359. void tiqdio_inbound_processing(unsigned long q);
  360. int tiqdio_allocate_memory(void);
  361. void tiqdio_free_memory(void);
  362. int tiqdio_register_thinints(void);
  363. void tiqdio_unregister_thinints(void);
  364. void clear_nonshared_ind(struct qdio_irq *);
  365. int test_nonshared_ind(struct qdio_irq *);
  366. /* prototypes for setup */
  367. void qdio_inbound_processing(unsigned long data);
  368. void qdio_outbound_processing(unsigned long data);
  369. void qdio_outbound_timer(unsigned long data);
  370. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  371. struct irb *irb);
  372. int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
  373. int nr_output_qs);
  374. void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
  375. int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
  376. struct subchannel_id *schid,
  377. struct qdio_ssqd_desc *data);
  378. int qdio_setup_irq(struct qdio_initialize *init_data);
  379. void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
  380. struct ccw_device *cdev);
  381. void qdio_release_memory(struct qdio_irq *irq_ptr);
  382. int qdio_setup_create_sysfs(struct ccw_device *cdev);
  383. void qdio_setup_destroy_sysfs(struct ccw_device *cdev);
  384. int qdio_setup_init(void);
  385. void qdio_setup_exit(void);
  386. int qdio_enable_async_operation(struct qdio_output_q *q);
  387. void qdio_disable_async_operation(struct qdio_output_q *q);
  388. struct qaob *qdio_allocate_aob(void);
  389. int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
  390. unsigned char *state);
  391. #endif /* _CIO_QDIO_H */