bfad_intr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. static int msix_disable_cb;
  24. static int msix_disable_ct;
  25. module_param(msix_disable_cb, int, S_IRUGO | S_IWUSR);
  26. MODULE_PARM_DESC(msix_disable_cb, "Disable MSIX for Brocade-415/425/815/825"
  27. " cards, default=0, Range[false:0|true:1]");
  28. module_param(msix_disable_ct, int, S_IRUGO | S_IWUSR);
  29. MODULE_PARM_DESC(msix_disable_ct, "Disable MSIX for Brocade-1010/1020/804"
  30. " cards, default=0, Range[false:0|true:1]");
  31. /**
  32. * Line based interrupt handler.
  33. */
  34. static irqreturn_t
  35. bfad_intx(int irq, void *dev_id)
  36. {
  37. struct bfad_s *bfad = dev_id;
  38. struct list_head doneq;
  39. unsigned long flags;
  40. bfa_boolean_t rc;
  41. spin_lock_irqsave(&bfad->bfad_lock, flags);
  42. rc = bfa_intx(&bfad->bfa);
  43. if (!rc) {
  44. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  45. return IRQ_NONE;
  46. }
  47. bfa_comp_deq(&bfad->bfa, &doneq);
  48. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  49. if (!list_empty(&doneq)) {
  50. bfa_comp_process(&bfad->bfa, &doneq);
  51. spin_lock_irqsave(&bfad->bfad_lock, flags);
  52. bfa_comp_free(&bfad->bfa, &doneq);
  53. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  54. bfa_trc_fp(bfad, irq);
  55. }
  56. return IRQ_HANDLED;
  57. }
  58. static irqreturn_t
  59. bfad_msix(int irq, void *dev_id)
  60. {
  61. struct bfad_msix_s *vec = dev_id;
  62. struct bfad_s *bfad = vec->bfad;
  63. struct list_head doneq;
  64. unsigned long flags;
  65. spin_lock_irqsave(&bfad->bfad_lock, flags);
  66. bfa_msix(&bfad->bfa, vec->msix.entry);
  67. bfa_comp_deq(&bfad->bfa, &doneq);
  68. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  69. if (!list_empty(&doneq)) {
  70. bfa_comp_process(&bfad->bfa, &doneq);
  71. spin_lock_irqsave(&bfad->bfad_lock, flags);
  72. bfa_comp_free(&bfad->bfa, &doneq);
  73. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  74. }
  75. return IRQ_HANDLED;
  76. }
  77. /**
  78. * Initialize the MSIX entry table.
  79. */
  80. static void
  81. bfad_init_msix_entry(struct bfad_s *bfad, struct msix_entry *msix_entries,
  82. int mask, int max_bit)
  83. {
  84. int i;
  85. int match = 0x00000001;
  86. for (i = 0, bfad->nvec = 0; i < MAX_MSIX_ENTRY; i++) {
  87. if (mask & match) {
  88. bfad->msix_tab[bfad->nvec].msix.entry = i;
  89. bfad->msix_tab[bfad->nvec].bfad = bfad;
  90. msix_entries[bfad->nvec].entry = i;
  91. bfad->nvec++;
  92. }
  93. match <<= 1;
  94. }
  95. }
  96. int
  97. bfad_install_msix_handler(struct bfad_s *bfad)
  98. {
  99. int i, error = 0;
  100. for (i = 0; i < bfad->nvec; i++) {
  101. error = request_irq(bfad->msix_tab[i].msix.vector,
  102. (irq_handler_t) bfad_msix, 0,
  103. BFAD_DRIVER_NAME, &bfad->msix_tab[i]);
  104. bfa_trc(bfad, i);
  105. bfa_trc(bfad, bfad->msix_tab[i].msix.vector);
  106. if (error) {
  107. int j;
  108. for (j = 0; j < i; j++)
  109. free_irq(bfad->msix_tab[j].msix.vector,
  110. &bfad->msix_tab[j]);
  111. return 1;
  112. }
  113. }
  114. return 0;
  115. }
  116. /**
  117. * Setup MSIX based interrupt.
  118. */
  119. int
  120. bfad_setup_intr(struct bfad_s *bfad)
  121. {
  122. int error = 0;
  123. u32 mask = 0, i, num_bit = 0, max_bit = 0;
  124. struct msix_entry msix_entries[MAX_MSIX_ENTRY];
  125. struct pci_dev *pdev = bfad->pcidev;
  126. /* Call BFA to get the msix map for this PCI function. */
  127. bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
  128. /* Set up the msix entry table */
  129. bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
  130. if ((bfa_asic_id_ct(pdev->device) && !msix_disable_ct) ||
  131. (!bfa_asic_id_ct(pdev->device) && !msix_disable_cb)) {
  132. error = pci_enable_msix(bfad->pcidev, msix_entries, bfad->nvec);
  133. if (error) {
  134. /*
  135. * Only error number of vector is available.
  136. * We don't have a mechanism to map multiple
  137. * interrupts into one vector, so even if we
  138. * can try to request less vectors, we don't
  139. * know how to associate interrupt events to
  140. * vectors. Linux doesn't dupicate vectors
  141. * in the MSIX table for this case.
  142. */
  143. printk(KERN_WARNING "bfad%d: "
  144. "pci_enable_msix failed (%d),"
  145. " use line based.\n", bfad->inst_no, error);
  146. goto line_based;
  147. }
  148. /* Save the vectors */
  149. for (i = 0; i < bfad->nvec; i++) {
  150. bfa_trc(bfad, msix_entries[i].vector);
  151. bfad->msix_tab[i].msix.vector = msix_entries[i].vector;
  152. }
  153. bfa_msix_init(&bfad->bfa, bfad->nvec);
  154. bfad->bfad_flags |= BFAD_MSIX_ON;
  155. return error;
  156. }
  157. line_based:
  158. error = 0;
  159. if (request_irq
  160. (bfad->pcidev->irq, (irq_handler_t) bfad_intx, BFAD_IRQ_FLAGS,
  161. BFAD_DRIVER_NAME, bfad) != 0) {
  162. /* Enable interrupt handler failed */
  163. return 1;
  164. }
  165. return error;
  166. }
  167. void
  168. bfad_remove_intr(struct bfad_s *bfad)
  169. {
  170. int i;
  171. if (bfad->bfad_flags & BFAD_MSIX_ON) {
  172. for (i = 0; i < bfad->nvec; i++)
  173. free_irq(bfad->msix_tab[i].msix.vector,
  174. &bfad->msix_tab[i]);
  175. pci_disable_msix(bfad->pcidev);
  176. bfad->bfad_flags &= ~BFAD_MSIX_ON;
  177. } else {
  178. free_irq(bfad->pcidev->irq, bfad);
  179. }
  180. }