qdio.h 13 KB

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