qdio_thinint.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * linux/drivers/s390/cio/thinint_qdio.c
  3. *
  4. * Copyright 2000,2009 IBM Corp.
  5. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
  6. * Cornelia Huck <cornelia.huck@de.ibm.com>
  7. * Jan Glauber <jang@linux.vnet.ibm.com>
  8. */
  9. #include <linux/io.h>
  10. #include <linux/slab.h>
  11. #include <linux/kernel_stat.h>
  12. #include <linux/atomic.h>
  13. #include <asm/debug.h>
  14. #include <asm/qdio.h>
  15. #include <asm/airq.h>
  16. #include <asm/isc.h>
  17. #include "cio.h"
  18. #include "ioasm.h"
  19. #include "qdio.h"
  20. #include "qdio_debug.h"
  21. /*
  22. * Restriction: only 63 iqdio subchannels would have its own indicator,
  23. * after that, subsequent subchannels share one indicator
  24. */
  25. #define TIQDIO_NR_NONSHARED_IND 63
  26. #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1)
  27. #define TIQDIO_SHARED_IND 63
  28. /* device state change indicators */
  29. struct indicator_t {
  30. u32 ind; /* u32 because of compare-and-swap performance */
  31. atomic_t count; /* use count, 0 or 1 for non-shared indicators */
  32. };
  33. /* list of thin interrupt input queues */
  34. static LIST_HEAD(tiq_list);
  35. static DEFINE_MUTEX(tiq_list_lock);
  36. /* adapter local summary indicator */
  37. static u8 *tiqdio_alsi;
  38. static struct indicator_t *q_indicators;
  39. u64 last_ai_time;
  40. /* returns addr for the device state change indicator */
  41. static u32 *get_indicator(void)
  42. {
  43. int i;
  44. for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++)
  45. if (!atomic_read(&q_indicators[i].count)) {
  46. atomic_set(&q_indicators[i].count, 1);
  47. return &q_indicators[i].ind;
  48. }
  49. /* use the shared indicator */
  50. atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count);
  51. return &q_indicators[TIQDIO_SHARED_IND].ind;
  52. }
  53. static void put_indicator(u32 *addr)
  54. {
  55. int i;
  56. if (!addr)
  57. return;
  58. i = ((unsigned long)addr - (unsigned long)q_indicators) /
  59. sizeof(struct indicator_t);
  60. atomic_dec(&q_indicators[i].count);
  61. }
  62. void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
  63. {
  64. mutex_lock(&tiq_list_lock);
  65. BUG_ON(irq_ptr->nr_input_qs < 1);
  66. list_add_rcu(&irq_ptr->input_qs[0]->entry, &tiq_list);
  67. mutex_unlock(&tiq_list_lock);
  68. xchg(irq_ptr->dsci, 1 << 7);
  69. }
  70. void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
  71. {
  72. struct qdio_q *q;
  73. BUG_ON(irq_ptr->nr_input_qs < 1);
  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. for_each_input_queue(irq, q, i) {
  126. if (!references_shared_dsci(irq) &&
  127. has_multiple_inq_on_dsci(irq))
  128. xchg(q->irq_ptr->dsci, 0);
  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(void *alsi, void *data)
  156. {
  157. u32 si_used = clear_shared_ind();
  158. struct qdio_q *q;
  159. last_ai_time = S390_lowcore.int_clock;
  160. kstat_cpu(smp_processor_id()).irqs[IOINT_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 scssc_area *scssc_area;
  181. int rc;
  182. scssc_area = (struct scssc_area *)irq_ptr->chsc_page;
  183. memset(scssc_area, 0, PAGE_SIZE);
  184. if (reset) {
  185. scssc_area->summary_indicator_addr = 0;
  186. scssc_area->subchannel_indicator_addr = 0;
  187. } else {
  188. scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi);
  189. scssc_area->subchannel_indicator_addr =
  190. virt_to_phys(irq_ptr->dsci);
  191. }
  192. scssc_area->request = (struct chsc_header) {
  193. .length = 0x0fe0,
  194. .code = 0x0021,
  195. };
  196. scssc_area->operation_code = 0;
  197. scssc_area->ks = PAGE_DEFAULT_KEY >> 4;
  198. scssc_area->kc = PAGE_DEFAULT_KEY >> 4;
  199. scssc_area->isc = QDIO_AIRQ_ISC;
  200. scssc_area->schid = irq_ptr->schid;
  201. /* enable the time delay disablement facility */
  202. if (css_general_characteristics.aif_tdd)
  203. scssc_area->word_with_d_bit = 0x10000000;
  204. rc = chsc(scssc_area);
  205. if (rc)
  206. return -EIO;
  207. rc = chsc_error_from_response(scssc_area->response.code);
  208. if (rc) {
  209. DBF_ERROR("%4x SSI r:%4x", irq_ptr->schid.sch_no,
  210. scssc_area->response.code);
  211. DBF_ERROR_HEX(&scssc_area->response, sizeof(void *));
  212. return rc;
  213. }
  214. DBF_EVENT("setscind");
  215. DBF_HEX(&scssc_area->summary_indicator_addr, sizeof(unsigned long));
  216. DBF_HEX(&scssc_area->subchannel_indicator_addr, sizeof(unsigned long));
  217. return 0;
  218. }
  219. /* allocate non-shared indicators and shared indicator */
  220. int __init tiqdio_allocate_memory(void)
  221. {
  222. q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS,
  223. GFP_KERNEL);
  224. if (!q_indicators)
  225. return -ENOMEM;
  226. return 0;
  227. }
  228. void tiqdio_free_memory(void)
  229. {
  230. kfree(q_indicators);
  231. }
  232. int __init tiqdio_register_thinints(void)
  233. {
  234. isc_register(QDIO_AIRQ_ISC);
  235. tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler,
  236. NULL, QDIO_AIRQ_ISC);
  237. if (IS_ERR(tiqdio_alsi)) {
  238. DBF_EVENT("RTI:%lx", PTR_ERR(tiqdio_alsi));
  239. tiqdio_alsi = NULL;
  240. isc_unregister(QDIO_AIRQ_ISC);
  241. return -ENOMEM;
  242. }
  243. return 0;
  244. }
  245. int qdio_establish_thinint(struct qdio_irq *irq_ptr)
  246. {
  247. if (!is_thinint_irq(irq_ptr))
  248. return 0;
  249. return set_subchannel_ind(irq_ptr, 0);
  250. }
  251. void qdio_setup_thinint(struct qdio_irq *irq_ptr)
  252. {
  253. if (!is_thinint_irq(irq_ptr))
  254. return;
  255. irq_ptr->dsci = get_indicator();
  256. DBF_HEX(&irq_ptr->dsci, sizeof(void *));
  257. }
  258. void qdio_shutdown_thinint(struct qdio_irq *irq_ptr)
  259. {
  260. if (!is_thinint_irq(irq_ptr))
  261. return;
  262. /* reset adapter interrupt indicators */
  263. set_subchannel_ind(irq_ptr, 1);
  264. put_indicator(irq_ptr->dsci);
  265. }
  266. void __exit tiqdio_unregister_thinints(void)
  267. {
  268. WARN_ON(!list_empty(&tiq_list));
  269. if (tiqdio_alsi) {
  270. s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC);
  271. isc_unregister(QDIO_AIRQ_ISC);
  272. }
  273. }