bfad_intr.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include "bfad_drv.h"
  18. #include "bfad_trcmod.h"
  19. BFA_TRC_FILE(LDRV, INTR);
  20. /**
  21. * bfa_isr BFA driver interrupt functions
  22. */
  23. irqreturn_t bfad_intx(int irq, void *dev_id);
  24. static int msix_disable;
  25. module_param(msix_disable, int, S_IRUGO | S_IWUSR);
  26. /**
  27. * Line based interrupt handler.
  28. */
  29. irqreturn_t
  30. bfad_intx(int irq, void *dev_id)
  31. {
  32. struct bfad_s *bfad = dev_id;
  33. struct list_head doneq;
  34. unsigned long flags;
  35. bfa_boolean_t rc;
  36. spin_lock_irqsave(&bfad->bfad_lock, flags);
  37. rc = bfa_intx(&bfad->bfa);
  38. if (!rc) {
  39. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  40. return IRQ_NONE;
  41. }
  42. bfa_comp_deq(&bfad->bfa, &doneq);
  43. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  44. if (!list_empty(&doneq)) {
  45. bfa_comp_process(&bfad->bfa, &doneq);
  46. spin_lock_irqsave(&bfad->bfad_lock, flags);
  47. bfa_comp_free(&bfad->bfa, &doneq);
  48. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  49. bfa_trc_fp(bfad, irq);
  50. }
  51. return IRQ_HANDLED;
  52. }
  53. static irqreturn_t
  54. bfad_msix(int irq, void *dev_id)
  55. {
  56. struct bfad_msix_s *vec = dev_id;
  57. struct bfad_s *bfad = vec->bfad;
  58. struct list_head doneq;
  59. unsigned long flags;
  60. spin_lock_irqsave(&bfad->bfad_lock, flags);
  61. bfa_msix(&bfad->bfa, vec->msix.entry);
  62. bfa_comp_deq(&bfad->bfa, &doneq);
  63. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  64. if (!list_empty(&doneq)) {
  65. bfa_comp_process(&bfad->bfa, &doneq);
  66. spin_lock_irqsave(&bfad->bfad_lock, flags);
  67. bfa_comp_free(&bfad->bfa, &doneq);
  68. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  69. }
  70. return IRQ_HANDLED;
  71. }
  72. /**
  73. * Initialize the MSIX entry table.
  74. */
  75. static void
  76. bfad_init_msix_entry(struct bfad_s *bfad, struct msix_entry *msix_entries,
  77. int mask, int max_bit)
  78. {
  79. int i;
  80. int match = 0x00000001;
  81. for (i = 0, bfad->nvec = 0; i < MAX_MSIX_ENTRY; i++) {
  82. if (mask & match) {
  83. bfad->msix_tab[bfad->nvec].msix.entry = i;
  84. bfad->msix_tab[bfad->nvec].bfad = bfad;
  85. msix_entries[bfad->nvec].entry = i;
  86. bfad->nvec++;
  87. }
  88. match <<= 1;
  89. }
  90. }
  91. int
  92. bfad_install_msix_handler(struct bfad_s *bfad)
  93. {
  94. int i, error = 0;
  95. for (i = 0; i < bfad->nvec; i++) {
  96. error = request_irq(bfad->msix_tab[i].msix.vector,
  97. (irq_handler_t) bfad_msix, 0,
  98. BFAD_DRIVER_NAME, &bfad->msix_tab[i]);
  99. bfa_trc(bfad, i);
  100. bfa_trc(bfad, bfad->msix_tab[i].msix.vector);
  101. if (error) {
  102. int j;
  103. for (j = 0; j < i; j++)
  104. free_irq(bfad->msix_tab[j].msix.vector,
  105. &bfad->msix_tab[j]);
  106. return 1;
  107. }
  108. }
  109. return 0;
  110. }
  111. /**
  112. * Setup MSIX based interrupt.
  113. */
  114. int
  115. bfad_setup_intr(struct bfad_s *bfad)
  116. {
  117. int error = 0;
  118. u32 mask = 0, i, num_bit = 0, max_bit = 0;
  119. struct msix_entry msix_entries[MAX_MSIX_ENTRY];
  120. /* Call BFA to get the msix map for this PCI function. */
  121. bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
  122. /* Set up the msix entry table */
  123. bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
  124. if (!msix_disable) {
  125. error = pci_enable_msix(bfad->pcidev, msix_entries, bfad->nvec);
  126. if (error) {
  127. /*
  128. * Only error number of vector is available.
  129. * We don't have a mechanism to map multiple
  130. * interrupts into one vector, so even if we
  131. * can try to request less vectors, we don't
  132. * know how to associate interrupt events to
  133. * vectors. Linux doesn't dupicate vectors
  134. * in the MSIX table for this case.
  135. */
  136. printk(KERN_WARNING "bfad%d: "
  137. "pci_enable_msix failed (%d),"
  138. " use line based.\n", bfad->inst_no, error);
  139. goto line_based;
  140. }
  141. /* Save the vectors */
  142. for (i = 0; i < bfad->nvec; i++) {
  143. bfa_trc(bfad, msix_entries[i].vector);
  144. bfad->msix_tab[i].msix.vector = msix_entries[i].vector;
  145. }
  146. bfa_msix_init(&bfad->bfa, bfad->nvec);
  147. bfad->bfad_flags |= BFAD_MSIX_ON;
  148. return error;
  149. }
  150. line_based:
  151. error = 0;
  152. if (request_irq
  153. (bfad->pcidev->irq, (irq_handler_t) bfad_intx, BFAD_IRQ_FLAGS,
  154. BFAD_DRIVER_NAME, bfad) != 0) {
  155. /* Enable interrupt handler failed */
  156. return 1;
  157. }
  158. return error;
  159. }
  160. void
  161. bfad_remove_intr(struct bfad_s *bfad)
  162. {
  163. int i;
  164. if (bfad->bfad_flags & BFAD_MSIX_ON) {
  165. for (i = 0; i < bfad->nvec; i++)
  166. free_irq(bfad->msix_tab[i].msix.vector,
  167. &bfad->msix_tab[i]);
  168. pci_disable_msix(bfad->pcidev);
  169. bfad->bfad_flags &= ~BFAD_MSIX_ON;
  170. } else {
  171. free_irq(bfad->pcidev->irq, bfad);
  172. }
  173. }