qdio.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. 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_WRITEM 0x03
  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. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  81. unsigned long _ccq = *count;
  82. asm volatile(
  83. " lgr 1,%[token]\n"
  84. " .insn rsy,0xeb000000008a,%[qs],%[ccq],0(%[state])"
  85. : [ccq] "+&d" (_ccq), [qs] "+&d" (_queuestart)
  86. : [state] "a" ((unsigned long)state), [token] "d" (token)
  87. : "memory", "cc", "1");
  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. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  96. unsigned long _state = (unsigned long)ack << 63;
  97. unsigned long _ccq = *count;
  98. asm volatile(
  99. " lgr 1,%[token]\n"
  100. " .insn rrf,0xb99c0000,%[qs],%[state],%[ccq],0"
  101. : [ccq] "+&d" (_ccq), [qs] "+&d" (_queuestart),
  102. [state] "+&d" (_state)
  103. : [token] "d" (token)
  104. : "memory", "cc", "1");
  105. *count = _ccq & 0xff;
  106. *start = _queuestart & 0xff;
  107. *state = _state & 0xff;
  108. return (_ccq >> 32) & 0xff;
  109. }
  110. struct qdio_irq;
  111. struct qdio_dev_perf_stat {
  112. unsigned int adapter_int;
  113. unsigned int qdio_int;
  114. unsigned int siga_read;
  115. unsigned int siga_write;
  116. unsigned int siga_sync;
  117. unsigned int inbound_call;
  118. unsigned int stop_polling;
  119. unsigned int inbound_queue_full;
  120. unsigned int outbound_call;
  121. unsigned int outbound_queue_full;
  122. unsigned int fast_requeue;
  123. unsigned int target_full;
  124. unsigned int eqbs;
  125. unsigned int eqbs_partial;
  126. unsigned int sqbs;
  127. unsigned int sqbs_partial;
  128. unsigned int int_discarded;
  129. } ____cacheline_aligned;
  130. struct qdio_queue_perf_stat {
  131. /* Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128. */
  132. unsigned int nr_sbals[8];
  133. unsigned int nr_sbal_error;
  134. unsigned int nr_sbal_nop;
  135. unsigned int nr_sbal_total;
  136. };
  137. enum qdio_irq_poll_states {
  138. QDIO_IRQ_DISABLED,
  139. };
  140. struct qdio_input_q {
  141. /* Batch of SBALs that we processed while polling the queue: */
  142. unsigned int batch_start;
  143. unsigned int batch_count;
  144. };
  145. struct qdio_output_q {
  146. };
  147. /*
  148. * Note on cache alignment: grouped slsb and write mostly data at the beginning
  149. * sbal[] is read-only and starts on a new cacheline followed by read mostly.
  150. */
  151. struct qdio_q {
  152. struct slsb slsb;
  153. union {
  154. struct qdio_input_q in;
  155. struct qdio_output_q out;
  156. } u;
  157. /*
  158. * inbound: next buffer the program should check for
  159. * outbound: next buffer to check if adapter processed it
  160. */
  161. int first_to_check;
  162. /* number of buffers in use by the adapter */
  163. atomic_t nr_buf_used;
  164. /* last scan of the queue */
  165. u64 timestamp;
  166. struct qdio_queue_perf_stat q_stats;
  167. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q] ____cacheline_aligned;
  168. /* queue number */
  169. int nr;
  170. /* bitmask of queue number */
  171. int mask;
  172. /* input or output queue */
  173. int is_input_q;
  174. /* upper-layer program handler */
  175. qdio_handler_t (*handler);
  176. struct qdio_irq *irq_ptr;
  177. /* memory page (PAGE_SIZE) used to place slib and sl on */
  178. void *sl_page;
  179. struct sl *sl;
  180. struct slib *slib;
  181. } __attribute__ ((aligned(256)));
  182. struct qdio_irq {
  183. struct qib qib;
  184. u32 *dsci; /* address of device state change indicator */
  185. struct ccw_device *cdev;
  186. struct list_head entry; /* list of thinint devices */
  187. struct dentry *debugfs_dev;
  188. u64 last_data_irq_time;
  189. unsigned long int_parm;
  190. struct subchannel_id schid;
  191. unsigned long sch_token; /* QEBSM facility */
  192. enum qdio_irq_states state;
  193. u8 qdioac1;
  194. int nr_input_qs;
  195. int nr_output_qs;
  196. struct ccw1 *ccw;
  197. struct qdio_ssqd_desc ssqd_desc;
  198. void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
  199. qdio_handler_t (*error_handler);
  200. int perf_stat_enabled;
  201. struct qdr *qdr;
  202. unsigned long chsc_page;
  203. struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
  204. struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
  205. unsigned int max_input_qs;
  206. unsigned int max_output_qs;
  207. void (*irq_poll)(struct ccw_device *cdev, unsigned long data);
  208. unsigned long poll_state;
  209. debug_info_t *debug_area;
  210. struct mutex setup_mutex;
  211. struct qdio_dev_perf_stat perf_stat;
  212. };
  213. /* helper functions */
  214. #define queue_type(q) q->irq_ptr->qib.qfmt
  215. #define SCH_NO(q) (q->irq_ptr->schid.sch_no)
  216. #define is_thinint_irq(irq) \
  217. (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
  218. css_general_characteristics.aif_qdio)
  219. #define qperf(__qdev, __attr) ((__qdev)->perf_stat.(__attr))
  220. #define QDIO_PERF_STAT_INC(__irq, __attr) \
  221. ({ \
  222. struct qdio_irq *qdev = __irq; \
  223. if (qdev->perf_stat_enabled) \
  224. (qdev->perf_stat.__attr)++; \
  225. })
  226. #define qperf_inc(__q, __attr) QDIO_PERF_STAT_INC((__q)->irq_ptr, __attr)
  227. static inline void account_sbals_error(struct qdio_q *q, int count)
  228. {
  229. q->q_stats.nr_sbal_error += count;
  230. q->q_stats.nr_sbal_total += count;
  231. }
  232. /* the highest iqdio queue is used for multicast */
  233. static inline int multicast_outbound(struct qdio_q *q)
  234. {
  235. return (q->irq_ptr->nr_output_qs > 1) &&
  236. (q->nr == q->irq_ptr->nr_output_qs - 1);
  237. }
  238. static inline void qdio_deliver_irq(struct qdio_irq *irq)
  239. {
  240. if (!test_and_set_bit(QDIO_IRQ_DISABLED, &irq->poll_state))
  241. irq->irq_poll(irq->cdev, irq->int_parm);
  242. else
  243. QDIO_PERF_STAT_INC(irq, int_discarded);
  244. }
  245. #define pci_out_supported(irq) ((irq)->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
  246. #define is_qebsm(q) (q->irq_ptr->sch_token != 0)
  247. #define qdio_need_siga_in(irq) ((irq)->qdioac1 & AC1_SIGA_INPUT_NEEDED)
  248. #define qdio_need_siga_out(irq) ((irq)->qdioac1 & AC1_SIGA_OUTPUT_NEEDED)
  249. #define qdio_need_siga_sync(irq) (unlikely((irq)->qdioac1 & AC1_SIGA_SYNC_NEEDED))
  250. #define for_each_input_queue(irq_ptr, q, i) \
  251. for (i = 0; i < irq_ptr->nr_input_qs && \
  252. ({ q = irq_ptr->input_qs[i]; 1; }); i++)
  253. #define for_each_output_queue(irq_ptr, q, i) \
  254. for (i = 0; i < irq_ptr->nr_output_qs && \
  255. ({ q = irq_ptr->output_qs[i]; 1; }); i++)
  256. #define add_buf(bufnr, inc) QDIO_BUFNR((bufnr) + (inc))
  257. #define next_buf(bufnr) add_buf(bufnr, 1)
  258. #define sub_buf(bufnr, dec) QDIO_BUFNR((bufnr) - (dec))
  259. #define prev_buf(bufnr) sub_buf(bufnr, 1)
  260. extern u64 last_ai_time;
  261. /* prototypes for thin interrupt */
  262. int qdio_establish_thinint(struct qdio_irq *irq_ptr);
  263. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
  264. int qdio_thinint_init(void);
  265. void qdio_thinint_exit(void);
  266. int test_nonshared_ind(struct qdio_irq *);
  267. /* prototypes for setup */
  268. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  269. struct irb *irb);
  270. int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
  271. int nr_output_qs);
  272. void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
  273. int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
  274. struct subchannel_id *schid,
  275. struct qdio_ssqd_desc *data);
  276. void qdio_setup_irq(struct qdio_irq *irq_ptr, struct qdio_initialize *init_data);
  277. void qdio_shutdown_irq(struct qdio_irq *irq);
  278. void qdio_print_subchannel_info(struct qdio_irq *irq_ptr);
  279. void qdio_free_queues(struct qdio_irq *irq_ptr);
  280. int qdio_setup_init(void);
  281. void qdio_setup_exit(void);
  282. int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
  283. unsigned char *state);
  284. #endif /* _CIO_QDIO_H */