qdio.h 13 KB

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