bfad_intr.c 5.0 KB

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