qdio_thinint.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright IBM Corp. 2000, 2009
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  4. * Cornelia Huck <cornelia.huck@de.ibm.com>
  5. * Jan Glauber <jang@linux.vnet.ibm.com>
  6. */
  7. #include <linux/io.h>
  8. #include <linux/slab.h>
  9. #include <linux/kernel_stat.h>
  10. #include <linux/atomic.h>
  11. #include <asm/debug.h>
  12. #include <asm/qdio.h>
  13. #include <asm/airq.h>
  14. #include <asm/isc.h>
  15. #include "cio.h"
  16. #include "ioasm.h"
  17. #include "qdio.h"
  18. #include "qdio_debug.h"
  19. /*
  20. * Restriction: only 63 iqdio subchannels would have its own indicator,
  21. * after that, subsequent subchannels share one indicator
  22. */
  23. #define TIQDIO_NR_NONSHARED_IND 63
  24. #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
  25. #define TIQDIO_SHARED_IND 63
  26. /* device state change indicators */
  27. struct indicator_t {
  28. u32 ind; /* u32 because of compare-and-swap performance */
  29. atomic_t count; /* use count, 0 or 1 for non-shared indicators */
  30. };
  31. /* list of thin interrupt input queues */
  32. static LIST_HEAD(tiq_list);
  33. static DEFINE_MUTEX(tiq_list_lock);
  34. /* Adapter interrupt definitions */
  35. static void tiqdio_thinint_handler(struct airq_struct *airq);
  36. static struct airq_struct tiqdio_airq = {
  37. .handler = tiqdio_thinint_handler,
  38. .isc = QDIO_AIRQ_ISC,
  39. };
  40. static struct indicator_t *q_indicators;
  41. u64 last_ai_time;
  42. /* returns addr for the device state change indicator */
  43. static u32 *get_indicator(void)
  44. {
  45. int i;
  46. for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
  47. if (!atomic_read(&q_indicators[i].count)) {
  48. atomic_set(&q_indicators[i].count, 1);
  49. return &q_indicators[i].ind;
  50. }
  51. /* use the shared indicator */
  52. atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
  53. return &q_indicators[TIQDIO_SHARED_IND].ind;
  54. }
  55. static void put_indicator(u32 *addr)
  56. {
  57. int i;
  58. if (!addr)
  59. return;
  60. i = ((unsigned long)addr - (unsigned long)q_indicators) /
  61. sizeof(struct indicator_t);
  62. atomic_dec(&q_indicators[i].count);
  63. }
  64. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
  65. {
  66. mutex_lock(&tiq_list_lock);
  67. list_add_rcu(&irq_ptr->input_qs[0]->entry, &tiq_list);
  68. mutex_unlock(&tiq_list_lock);
  69. xchg(irq_ptr->dsci, 1 << 7);
  70. }
  71. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
  72. {
  73. struct qdio_q *q;
  74. q = irq_ptr->input_qs[0];
  75. /* if establish triggered an error */
  76. if (!q || !q->entry.prev || !q->entry.next)
  77. return;
  78. mutex_lock(&tiq_list_lock);
  79. list_del_rcu(&q->entry);
  80. mutex_unlock(&tiq_list_lock);
  81. synchronize_rcu();
  82. }
  83. static inline int has_multiple_inq_on_dsci(struct qdio_irq *irq_ptr)
  84. {
  85. return irq_ptr->nr_input_qs > 1;
  86. }
  87. static inline int references_shared_dsci(struct qdio_irq *irq_ptr)
  88. {
  89. return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind;
  90. }
  91. static inline int shared_ind(struct qdio_irq *irq_ptr)
  92. {
  93. return references_shared_dsci(irq_ptr) ||
  94. has_multiple_inq_on_dsci(irq_ptr);
  95. }
  96. void clear_nonshared_ind(struct qdio_irq *irq_ptr)
  97. {
  98. if (!is_thinint_irq(irq_ptr))
  99. return;
  100. if (shared_ind(irq_ptr))
  101. return;
  102. xchg(irq_ptr->dsci, 0);
  103. }
  104. int test_nonshared_ind(struct qdio_irq *irq_ptr)
  105. {
  106. if (!is_thinint_irq(irq_ptr))
  107. return 0;
  108. if (shared_ind(irq_ptr))
  109. return 0;
  110. if (*irq_ptr->dsci)
  111. return 1;
  112. else
  113. return 0;
  114. }
  115. static inline u32 clear_shared_ind(void)
  116. {
  117. if (!atomic_read(&q_indicators[TIQDIO_SHARED_IND].count))
  118. return 0;
  119. return xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0);
  120. }
  121. static inline void tiqdio_call_inq_handlers(struct qdio_irq *irq)
  122. {
  123. struct qdio_q *q;
  124. int i;
  125. if (!references_shared_dsci(irq) &&
  126. has_multiple_inq_on_dsci(irq))
  127. xchg(irq->dsci, 0);
  128. for_each_input_queue(irq, q, i) {
  129. if (q->u.in.queue_start_poll) {
  130. /* skip if polling is enabled or already in work */
  131. if (test_and_set_bit(QDIO_QUEUE_IRQS_DISABLED,
  132. &q->u.in.queue_irq_state)) {
  133. qperf_inc(q, int_discarded);
  134. continue;
  135. }
  136. /* avoid dsci clear here, done after processing */
  137. q->u.in.queue_start_poll(q->irq_ptr->cdev, q->nr,
  138. q->irq_ptr->int_parm);
  139. } else {
  140. if (!shared_ind(q->irq_ptr))
  141. xchg(q->irq_ptr->dsci, 0);
  142. /*
  143. * Call inbound processing but not directly
  144. * since that could starve other thinint queues.
  145. */
  146. tasklet_schedule(&q->tasklet);
  147. }
  148. }
  149. }
  150. /**
  151. * tiqdio_thinint_handler - thin interrupt handler for qdio
  152. * @alsi: pointer to adapter local summary indicator
  153. * @data: NULL
  154. */
  155. static void tiqdio_thinint_handler(struct airq_struct *airq)
  156. {
  157. u32 si_used = clear_shared_ind();
  158. struct qdio_q *q;
  159. last_ai_time = S390_lowcore.int_clock;
  160. inc_irq_stat(IRQIO_QAI);
  161. /* protect tiq_list entries, only changed in activate or shutdown */
  162. rcu_read_lock();
  163. /* check for work on all inbound thinint queues */
  164. list_for_each_entry_rcu(q, &tiq_list, entry) {
  165. struct qdio_irq *irq;
  166. /* only process queues from changed sets */
  167. irq = q->irq_ptr;
  168. if (unlikely(references_shared_dsci(irq))) {
  169. if (!si_used)
  170. continue;
  171. } else if (!*irq->dsci)
  172. continue;
  173. tiqdio_call_inq_handlers(irq);
  174. qperf_inc(q, adapter_int);
  175. }
  176. rcu_read_unlock();
  177. }
  178. static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
  179. {
  180. struct chsc_scssc_area *scssc = (void *)irq_ptr->chsc_page;
  181. u64 summary_indicator_addr, subchannel_indicator_addr;
  182. int rc;
  183. if (reset) {
  184. summary_indicator_addr = 0;
  185. subchannel_indicator_addr = 0;
  186. } else {
  187. summary_indicator_addr = virt_to_phys(tiqdio_airq.lsi_ptr);
  188. subchannel_indicator_addr = virt_to_phys(irq_ptr->dsci);
  189. }
  190. rc = chsc_sadc(irq_ptr->schid, scssc, summary_indicator_addr,
  191. subchannel_indicator_addr);
  192. if (rc) {
  193. DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
  194. scssc->response.code);
  195. goto out;
  196. }
  197. DBF_EVENT("setscind");
  198. DBF_HEX(&summary_indicator_addr, sizeof(summary_indicator_addr));
  199. DBF_HEX(&subchannel_indicator_addr, sizeof(subchannel_indicator_addr));
  200. out:
  201. return rc;
  202. }
  203. /* allocate non-shared indicators and shared indicator */
  204. int __init tiqdio_allocate_memory(void)
  205. {
  206. q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
  207. GFP_KERNEL);
  208. if (!q_indicators)
  209. return -ENOMEM;
  210. return 0;
  211. }
  212. void tiqdio_free_memory(void)
  213. {
  214. kfree(q_indicators);
  215. }
  216. int __init tiqdio_register_thinints(void)
  217. {
  218. int rc;
  219. rc = register_adapter_interrupt(&tiqdio_airq);
  220. if (rc) {
  221. DBF_EVENT("RTI:%x", rc);
  222. return rc;
  223. }
  224. return 0;
  225. }
  226. int qdio_establish_thinint(struct qdio_irq *irq_ptr)
  227. {
  228. if (!is_thinint_irq(irq_ptr))
  229. return 0;
  230. return set_subchannel_ind(irq_ptr, 0);
  231. }
  232. void qdio_setup_thinint(struct qdio_irq *irq_ptr)
  233. {
  234. if (!is_thinint_irq(irq_ptr))
  235. return;
  236. irq_ptr->dsci = get_indicator();
  237. DBF_HEX(&irq_ptr->dsci, sizeof(void *));
  238. }
  239. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
  240. {
  241. if (!is_thinint_irq(irq_ptr))
  242. return;
  243. /* reset adapter interrupt indicators */
  244. set_subchannel_ind(irq_ptr, 1);
  245. put_indicator(irq_ptr->dsci);
  246. }
  247. void __exit tiqdio_unregister_thinints(void)
  248. {
  249. WARN_ON(!list_empty(&tiq_list));
  250. unregister_adapter_interrupt(&tiqdio_airq);
  251. }