qdio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 /* 100 microseconds */
  15. #define QDIO_INPUT_THRESHOLD 500 /* 500 microseconds */
  16. /*
  17. * if an asynchronous HiperSockets queue runs full, the 10 seconds timer wait
  18. * till next initiative to give transmitted skbs back to the stack is too long.
  19. * Therefore polling is started in case of multicast queue is filled more
  20. * than 50 percent.
  21. */
  22. #define QDIO_IQDIO_POLL_LVL 65 /* HS multicast queue */
  23. enum qdio_irq_states {
  24. QDIO_IRQ_STATE_INACTIVE,
  25. QDIO_IRQ_STATE_ESTABLISHED,
  26. QDIO_IRQ_STATE_ACTIVE,
  27. QDIO_IRQ_STATE_STOPPED,
  28. QDIO_IRQ_STATE_CLEANUP,
  29. QDIO_IRQ_STATE_ERR,
  30. NR_QDIO_IRQ_STATES,
  31. };
  32. /* used as intparm in do_IO */
  33. #define QDIO_DOING_ESTABLISH 1
  34. #define QDIO_DOING_ACTIVATE 2
  35. #define QDIO_DOING_CLEANUP 3
  36. #define SLSB_STATE_NOT_INIT 0x0
  37. #define SLSB_STATE_EMPTY 0x1
  38. #define SLSB_STATE_PRIMED 0x2
  39. #define SLSB_STATE_HALTED 0xe
  40. #define SLSB_STATE_ERROR 0xf
  41. #define SLSB_TYPE_INPUT 0x0
  42. #define SLSB_TYPE_OUTPUT 0x20
  43. #define SLSB_OWNER_PROG 0x80
  44. #define SLSB_OWNER_CU 0x40
  45. #define SLSB_P_INPUT_NOT_INIT \
  46. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_NOT_INIT) /* 0x80 */
  47. #define SLSB_P_INPUT_ACK \
  48. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x81 */
  49. #define SLSB_CU_INPUT_EMPTY \
  50. (SLSB_OWNER_CU | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x41 */
  51. #define SLSB_P_INPUT_PRIMED \
  52. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_PRIMED) /* 0x82 */
  53. #define SLSB_P_INPUT_HALTED \
  54. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_HALTED) /* 0x8e */
  55. #define SLSB_P_INPUT_ERROR \
  56. (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_ERROR) /* 0x8f */
  57. #define SLSB_P_OUTPUT_NOT_INIT \
  58. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_NOT_INIT) /* 0xa0 */
  59. #define SLSB_P_OUTPUT_EMPTY \
  60. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_EMPTY) /* 0xa1 */
  61. #define SLSB_CU_OUTPUT_PRIMED \
  62. (SLSB_OWNER_CU | SLSB_TYPE_OUTPUT | SLSB_STATE_PRIMED) /* 0x62 */
  63. #define SLSB_P_OUTPUT_HALTED \
  64. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_HALTED) /* 0xae */
  65. #define SLSB_P_OUTPUT_ERROR \
  66. (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_ERROR) /* 0xaf */
  67. #define SLSB_ERROR_DURING_LOOKUP 0xff
  68. /* additional CIWs returned by extended Sense-ID */
  69. #define CIW_TYPE_EQUEUE 0x3 /* establish QDIO queues */
  70. #define CIW_TYPE_AQUEUE 0x4 /* activate QDIO queues */
  71. /* flags for st qdio sch data */
  72. #define CHSC_FLAG_QDIO_CAPABILITY 0x80
  73. #define CHSC_FLAG_VALIDITY 0x40
  74. /* qdio adapter-characteristics-1 flag */
  75. #define AC1_SIGA_INPUT_NEEDED 0x40 /* process input queues */
  76. #define AC1_SIGA_OUTPUT_NEEDED 0x20 /* process output queues */
  77. #define AC1_SIGA_SYNC_NEEDED 0x10 /* ask hypervisor to sync */
  78. #define AC1_AUTOMATIC_SYNC_ON_THININT 0x08 /* set by hypervisor */
  79. #define AC1_AUTOMATIC_SYNC_ON_OUT_PCI 0x04 /* set by hypervisor */
  80. #define AC1_SC_QEBSM_AVAILABLE 0x02 /* available for subchannel */
  81. #define AC1_SC_QEBSM_ENABLED 0x01 /* enabled for subchannel */
  82. #ifdef CONFIG_64BIT
  83. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  84. int *start, int *count)
  85. {
  86. register unsigned long _ccq asm ("0") = *count;
  87. register unsigned long _token asm ("1") = token;
  88. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  89. asm volatile(
  90. " .insn rsy,0xeb000000008A,%1,0,0(%2)"
  91. : "+d" (_ccq), "+d" (_queuestart)
  92. : "d" ((unsigned long)state), "d" (_token)
  93. : "memory", "cc");
  94. *count = _ccq & 0xff;
  95. *start = _queuestart & 0xff;
  96. return (_ccq >> 32) & 0xff;
  97. }
  98. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  99. int *start, int *count, int ack)
  100. {
  101. register unsigned long _ccq asm ("0") = *count;
  102. register unsigned long _token asm ("1") = token;
  103. unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
  104. unsigned long _state = (unsigned long)ack << 63;
  105. asm volatile(
  106. " .insn rrf,0xB99c0000,%1,%2,0,0"
  107. : "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
  108. : "d" (_token)
  109. : "memory", "cc");
  110. *count = _ccq & 0xff;
  111. *start = _queuestart & 0xff;
  112. *state = _state & 0xff;
  113. return (_ccq >> 32) & 0xff;
  114. }
  115. #else
  116. static inline int do_sqbs(u64 token, unsigned char state, int queue,
  117. int *start, int *count) { return 0; }
  118. static inline int do_eqbs(u64 token, unsigned char *state, int queue,
  119. int *start, int *count, int ack) { return 0; }
  120. #endif /* CONFIG_64BIT */
  121. struct qdio_irq;
  122. struct siga_flag {
  123. u8 input:1;
  124. u8 output:1;
  125. u8 sync:1;
  126. u8 no_sync_ti:1;
  127. u8 no_sync_out_ti:1;
  128. u8 no_sync_out_pci:1;
  129. u8:2;
  130. } __attribute__ ((packed));
  131. struct chsc_ssqd_area {
  132. struct chsc_header request;
  133. u16:10;
  134. u8 ssid:2;
  135. u8 fmt:4;
  136. u16 first_sch;
  137. u16:16;
  138. u16 last_sch;
  139. u32:32;
  140. struct chsc_header response;
  141. u32:32;
  142. struct qdio_ssqd_desc qdio_ssqd;
  143. } __attribute__ ((packed));
  144. struct scssc_area {
  145. struct chsc_header request;
  146. u16 operation_code;
  147. u16:16;
  148. u32:32;
  149. u32:32;
  150. u64 summary_indicator_addr;
  151. u64 subchannel_indicator_addr;
  152. u32 ks:4;
  153. u32 kc:4;
  154. u32:21;
  155. u32 isc:3;
  156. u32 word_with_d_bit;
  157. u32:32;
  158. struct subchannel_id schid;
  159. u32 reserved[1004];
  160. struct chsc_header response;
  161. u32:32;
  162. } __attribute__ ((packed));
  163. struct qdio_dev_perf_stat {
  164. unsigned int adapter_int;
  165. unsigned int qdio_int;
  166. unsigned int pci_request_int;
  167. unsigned int tasklet_inbound;
  168. unsigned int tasklet_inbound_resched;
  169. unsigned int tasklet_inbound_resched2;
  170. unsigned int tasklet_outbound;
  171. unsigned int siga_read;
  172. unsigned int siga_write;
  173. unsigned int siga_sync;
  174. unsigned int inbound_call;
  175. unsigned int inbound_handler;
  176. unsigned int stop_polling;
  177. unsigned int inbound_queue_full;
  178. unsigned int outbound_call;
  179. unsigned int outbound_handler;
  180. unsigned int fast_requeue;
  181. unsigned int target_full;
  182. unsigned int eqbs;
  183. unsigned int eqbs_partial;
  184. unsigned int sqbs;
  185. unsigned int sqbs_partial;
  186. };
  187. struct qdio_input_q {
  188. /* input buffer acknowledgement flag */
  189. int polling;
  190. /* first ACK'ed buffer */
  191. int ack_start;
  192. /* how much sbals are acknowledged with qebsm */
  193. int ack_count;
  194. /* last time of noticing incoming data */
  195. u64 timestamp;
  196. };
  197. struct qdio_output_q {
  198. /* PCIs are enabled for the queue */
  199. int pci_out_enabled;
  200. /* IQDIO: output multiple buffers (enhanced SIGA) */
  201. int use_enh_siga;
  202. /* timer to check for more outbound work */
  203. struct timer_list timer;
  204. };
  205. struct qdio_q {
  206. struct slsb slsb;
  207. union {
  208. struct qdio_input_q in;
  209. struct qdio_output_q out;
  210. } u;
  211. /* queue number */
  212. int nr;
  213. /* bitmask of queue number */
  214. int mask;
  215. /* input or output queue */
  216. int is_input_q;
  217. /* list of thinint input queues */
  218. struct list_head entry;
  219. /* upper-layer program handler */
  220. qdio_handler_t (*handler);
  221. /*
  222. * inbound: next buffer the program should check for
  223. * outbound: next buffer to check for having been processed
  224. * by the card
  225. */
  226. int first_to_check;
  227. /* first_to_check of the last time */
  228. int last_move;
  229. /* beginning position for calling the program */
  230. int first_to_kick;
  231. /* number of buffers in use by the adapter */
  232. atomic_t nr_buf_used;
  233. struct qdio_irq *irq_ptr;
  234. struct dentry *debugfs_q;
  235. struct tasklet_struct tasklet;
  236. /* error condition during a data transfer */
  237. unsigned int qdio_error;
  238. struct sl *sl;
  239. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
  240. /*
  241. * Warning: Leave this member at the end so it won't be cleared in
  242. * qdio_fill_qs. A page is allocated under this pointer and used for
  243. * slib and sl. slib is 2048 bytes big and sl points to offset
  244. * PAGE_SIZE / 2.
  245. */
  246. struct slib *slib;
  247. } __attribute__ ((aligned(256)));
  248. struct qdio_irq {
  249. struct qib qib;
  250. u32 *dsci; /* address of device state change indicator */
  251. struct ccw_device *cdev;
  252. struct dentry *debugfs_dev;
  253. struct dentry *debugfs_perf;
  254. unsigned long int_parm;
  255. struct subchannel_id schid;
  256. unsigned long sch_token; /* QEBSM facility */
  257. enum qdio_irq_states state;
  258. struct siga_flag siga_flag; /* siga sync information from qdioac */
  259. int nr_input_qs;
  260. int nr_output_qs;
  261. struct ccw1 ccw;
  262. struct ciw equeue;
  263. struct ciw aqueue;
  264. struct qdio_ssqd_desc ssqd_desc;
  265. void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
  266. struct qdio_dev_perf_stat perf_stat;
  267. int perf_stat_enabled;
  268. /*
  269. * Warning: Leave these members together at the end so they won't be
  270. * cleared in qdio_setup_irq.
  271. */
  272. struct qdr *qdr;
  273. unsigned long chsc_page;
  274. struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
  275. struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
  276. debug_info_t *debug_area;
  277. struct mutex setup_mutex;
  278. };
  279. /* helper functions */
  280. #define queue_type(q) q->irq_ptr->qib.qfmt
  281. #define SCH_NO(q) (q->irq_ptr->schid.sch_no)
  282. #define is_thinint_irq(irq) \
  283. (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
  284. css_general_characteristics.aif_osa)
  285. #define qperf(qdev,attr) qdev->perf_stat.attr
  286. #define qperf_inc(q,attr) if (q->irq_ptr->perf_stat_enabled) \
  287. q->irq_ptr->perf_stat.attr++
  288. /* the highest iqdio queue is used for multicast */
  289. static inline int multicast_outbound(struct qdio_q *q)
  290. {
  291. return (q->irq_ptr->nr_output_qs > 1) &&
  292. (q->nr == q->irq_ptr->nr_output_qs - 1);
  293. }
  294. static inline unsigned long long get_usecs(void)
  295. {
  296. return monotonic_clock() >> 12;
  297. }
  298. #define pci_out_supported(q) \
  299. (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
  300. #define is_qebsm(q) (q->irq_ptr->sch_token != 0)
  301. #define need_siga_sync_thinint(q) (!q->irq_ptr->siga_flag.no_sync_ti)
  302. #define need_siga_sync_out_thinint(q) (!q->irq_ptr->siga_flag.no_sync_out_ti)
  303. #define need_siga_in(q) (q->irq_ptr->siga_flag.input)
  304. #define need_siga_out(q) (q->irq_ptr->siga_flag.output)
  305. #define need_siga_sync(q) (q->irq_ptr->siga_flag.sync)
  306. #define siga_syncs_out_pci(q) (q->irq_ptr->siga_flag.no_sync_out_pci)
  307. #define for_each_input_queue(irq_ptr, q, i) \
  308. for (i = 0, q = irq_ptr->input_qs[0]; \
  309. i < irq_ptr->nr_input_qs; \
  310. q = irq_ptr->input_qs[++i])
  311. #define for_each_output_queue(irq_ptr, q, i) \
  312. for (i = 0, q = irq_ptr->output_qs[0]; \
  313. i < irq_ptr->nr_output_qs; \
  314. q = irq_ptr->output_qs[++i])
  315. #define prev_buf(bufnr) \
  316. ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK)
  317. #define next_buf(bufnr) \
  318. ((bufnr + 1) & QDIO_MAX_BUFFERS_MASK)
  319. #define add_buf(bufnr, inc) \
  320. ((bufnr + inc) & QDIO_MAX_BUFFERS_MASK)
  321. #define sub_buf(bufnr, dec) \
  322. ((bufnr - dec) & QDIO_MAX_BUFFERS_MASK)
  323. /* prototypes for thin interrupt */
  324. void qdio_setup_thinint(struct qdio_irq *irq_ptr);
  325. int qdio_establish_thinint(struct qdio_irq *irq_ptr);
  326. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr);
  327. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr);
  328. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr);
  329. void tiqdio_inbound_processing(unsigned long q);
  330. int tiqdio_allocate_memory(void);
  331. void tiqdio_free_memory(void);
  332. int tiqdio_register_thinints(void);
  333. void tiqdio_unregister_thinints(void);
  334. /* prototypes for setup */
  335. void qdio_inbound_processing(unsigned long data);
  336. void qdio_outbound_processing(unsigned long data);
  337. void qdio_outbound_timer(unsigned long data);
  338. void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
  339. struct irb *irb);
  340. int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs,
  341. int nr_output_qs);
  342. void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr);
  343. int qdio_setup_get_ssqd(struct qdio_irq *irq_ptr,
  344. struct subchannel_id *schid,
  345. struct qdio_ssqd_desc *data);
  346. int qdio_setup_irq(struct qdio_initialize *init_data);
  347. void qdio_print_subchannel_info(struct qdio_irq *irq_ptr,
  348. struct ccw_device *cdev);
  349. void qdio_release_memory(struct qdio_irq *irq_ptr);
  350. int qdio_setup_create_sysfs(struct ccw_device *cdev);
  351. void qdio_setup_destroy_sysfs(struct ccw_device *cdev);
  352. int qdio_setup_init(void);
  353. void qdio_setup_exit(void);
  354. int debug_get_buf_state(struct qdio_q *q, unsigned int bufnr,
  355. unsigned char *state);
  356. #endif /* _CIO_QDIO_H */