qdio.h 12 KB

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