dpcsup.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Adaptec AAC series RAID controller driver
  3. * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
  4. *
  5. * based on the old aacraid driver that is..
  6. * Adaptec aacraid device driver for Linux.
  7. *
  8. * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; see the file COPYING. If not, write to
  22. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * Module Name:
  25. * dpcsup.c
  26. *
  27. * Abstract: All DPC processing routines for the cyclone board occur here.
  28. *
  29. *
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/types.h>
  34. #include <linux/sched.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/slab.h>
  38. #include <linux/completion.h>
  39. #include <linux/blkdev.h>
  40. #include <asm/semaphore.h>
  41. #include "aacraid.h"
  42. /**
  43. * aac_response_normal - Handle command replies
  44. * @q: Queue to read from
  45. *
  46. * This DPC routine will be run when the adapter interrupts us to let us
  47. * know there is a response on our normal priority queue. We will pull off
  48. * all QE there are and wake up all the waiters before exiting. We will
  49. * take a spinlock out on the queue before operating on it.
  50. */
  51. unsigned int aac_response_normal(struct aac_queue * q)
  52. {
  53. struct aac_dev * dev = q->dev;
  54. struct aac_entry *entry;
  55. struct hw_fib * hwfib;
  56. struct fib * fib;
  57. int consumed = 0;
  58. unsigned long flags;
  59. spin_lock_irqsave(q->lock, flags);
  60. /*
  61. * Keep pulling response QEs off the response queue and waking
  62. * up the waiters until there are no more QEs. We then return
  63. * back to the system. If no response was requesed we just
  64. * deallocate the Fib here and continue.
  65. */
  66. while(aac_consumer_get(dev, q, &entry))
  67. {
  68. int fast;
  69. u32 index = le32_to_cpu(entry->addr);
  70. fast = index & 0x01;
  71. fib = &dev->fibs[index >> 1];
  72. hwfib = fib->hw_fib;
  73. aac_consumer_free(dev, q, HostNormRespQueue);
  74. /*
  75. * Remove this fib from the Outstanding I/O queue.
  76. * But only if it has not already been timed out.
  77. *
  78. * If the fib has been timed out already, then just
  79. * continue. The caller has already been notified that
  80. * the fib timed out.
  81. */
  82. if (!(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
  83. list_del(&fib->queue);
  84. dev->queues->queue[AdapNormCmdQueue].numpending--;
  85. } else {
  86. printk(KERN_WARNING "aacraid: FIB timeout (%x).\n", fib->flags);
  87. printk(KERN_DEBUG"aacraid: hwfib=%p fib index=%i fib=%p\n",hwfib, hwfib->header.SenderData,fib);
  88. continue;
  89. }
  90. spin_unlock_irqrestore(q->lock, flags);
  91. if (fast) {
  92. /*
  93. * Doctor the fib
  94. */
  95. *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
  96. hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
  97. }
  98. FIB_COUNTER_INCREMENT(aac_config.FibRecved);
  99. if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
  100. {
  101. __le32 *pstatus = (__le32 *)hwfib->data;
  102. if (*pstatus & cpu_to_le32(0xffff0000))
  103. *pstatus = cpu_to_le32(ST_OK);
  104. }
  105. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
  106. {
  107. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
  108. FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
  109. else
  110. FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
  111. /*
  112. * NOTE: we cannot touch the fib after this
  113. * call, because it may have been deallocated.
  114. */
  115. fib->callback(fib->callback_data, fib);
  116. } else {
  117. unsigned long flagv;
  118. spin_lock_irqsave(&fib->event_lock, flagv);
  119. fib->done = 1;
  120. up(&fib->event_wait);
  121. spin_unlock_irqrestore(&fib->event_lock, flagv);
  122. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  123. }
  124. consumed++;
  125. spin_lock_irqsave(q->lock, flags);
  126. }
  127. if (consumed > aac_config.peak_fibs)
  128. aac_config.peak_fibs = consumed;
  129. if (consumed == 0)
  130. aac_config.zero_fibs++;
  131. spin_unlock_irqrestore(q->lock, flags);
  132. return 0;
  133. }
  134. /**
  135. * aac_command_normal - handle commands
  136. * @q: queue to process
  137. *
  138. * This DPC routine will be queued when the adapter interrupts us to
  139. * let us know there is a command on our normal priority queue. We will
  140. * pull off all QE there are and wake up all the waiters before exiting.
  141. * We will take a spinlock out on the queue before operating on it.
  142. */
  143. unsigned int aac_command_normal(struct aac_queue *q)
  144. {
  145. struct aac_dev * dev = q->dev;
  146. struct aac_entry *entry;
  147. unsigned long flags;
  148. spin_lock_irqsave(q->lock, flags);
  149. /*
  150. * Keep pulling response QEs off the response queue and waking
  151. * up the waiters until there are no more QEs. We then return
  152. * back to the system.
  153. */
  154. while(aac_consumer_get(dev, q, &entry))
  155. {
  156. struct fib fibctx;
  157. struct hw_fib * hw_fib;
  158. u32 index;
  159. struct fib *fib = &fibctx;
  160. index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
  161. hw_fib = &dev->aif_base_va[index];
  162. /*
  163. * Allocate a FIB at all costs. For non queued stuff
  164. * we can just use the stack so we are happy. We need
  165. * a fib object in order to manage the linked lists
  166. */
  167. if (dev->aif_thread)
  168. if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
  169. fib = &fibctx;
  170. memset(fib, 0, sizeof(struct fib));
  171. INIT_LIST_HEAD(&fib->fiblink);
  172. fib->type = FSAFS_NTC_FIB_CONTEXT;
  173. fib->size = sizeof(struct fib);
  174. fib->hw_fib = hw_fib;
  175. fib->data = hw_fib->data;
  176. fib->dev = dev;
  177. if (dev->aif_thread && fib != &fibctx) {
  178. list_add_tail(&fib->fiblink, &q->cmdq);
  179. aac_consumer_free(dev, q, HostNormCmdQueue);
  180. wake_up_interruptible(&q->cmdready);
  181. } else {
  182. aac_consumer_free(dev, q, HostNormCmdQueue);
  183. spin_unlock_irqrestore(q->lock, flags);
  184. /*
  185. * Set the status of this FIB
  186. */
  187. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  188. fib_adapter_complete(fib, sizeof(u32));
  189. spin_lock_irqsave(q->lock, flags);
  190. }
  191. }
  192. spin_unlock_irqrestore(q->lock, flags);
  193. return 0;
  194. }