dpcsup.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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/spinlock.h>
  35. #include <linux/slab.h>
  36. #include <linux/completion.h>
  37. #include <linux/blkdev.h>
  38. #include <asm/semaphore.h>
  39. #include "aacraid.h"
  40. /**
  41. * aac_response_normal - Handle command replies
  42. * @q: Queue to read from
  43. *
  44. * This DPC routine will be run when the adapter interrupts us to let us
  45. * know there is a response on our normal priority queue. We will pull off
  46. * all QE there are and wake up all the waiters before exiting. We will
  47. * take a spinlock out on the queue before operating on it.
  48. */
  49. unsigned int aac_response_normal(struct aac_queue * q)
  50. {
  51. struct aac_dev * dev = q->dev;
  52. struct aac_entry *entry;
  53. struct hw_fib * hwfib;
  54. struct fib * fib;
  55. int consumed = 0;
  56. unsigned long flags;
  57. spin_lock_irqsave(q->lock, flags);
  58. /*
  59. * Keep pulling response QEs off the response queue and waking
  60. * up the waiters until there are no more QEs. We then return
  61. * back to the system. If no response was requesed we just
  62. * deallocate the Fib here and continue.
  63. */
  64. while(aac_consumer_get(dev, q, &entry))
  65. {
  66. int fast;
  67. u32 index = le32_to_cpu(entry->addr);
  68. fast = index & 0x01;
  69. fib = &dev->fibs[index >> 2];
  70. hwfib = fib->hw_fib;
  71. aac_consumer_free(dev, q, HostNormRespQueue);
  72. /*
  73. * Remove this fib from the Outstanding I/O queue.
  74. * But only if it has not already been timed out.
  75. *
  76. * If the fib has been timed out already, then just
  77. * continue. The caller has already been notified that
  78. * the fib timed out.
  79. */
  80. if (!(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
  81. dev->queues->queue[AdapNormCmdQueue].numpending--;
  82. else {
  83. printk(KERN_WARNING "aacraid: FIB timeout (%x).\n", fib->flags);
  84. printk(KERN_DEBUG"aacraid: hwfib=%p fib index=%i fib=%p\n",hwfib, hwfib->header.SenderData,fib);
  85. continue;
  86. }
  87. spin_unlock_irqrestore(q->lock, flags);
  88. if (fast) {
  89. /*
  90. * Doctor the fib
  91. */
  92. *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
  93. hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
  94. }
  95. FIB_COUNTER_INCREMENT(aac_config.FibRecved);
  96. if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
  97. {
  98. __le32 *pstatus = (__le32 *)hwfib->data;
  99. if (*pstatus & cpu_to_le32(0xffff0000))
  100. *pstatus = cpu_to_le32(ST_OK);
  101. }
  102. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
  103. {
  104. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
  105. FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
  106. else
  107. FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
  108. /*
  109. * NOTE: we cannot touch the fib after this
  110. * call, because it may have been deallocated.
  111. */
  112. fib->callback(fib->callback_data, fib);
  113. } else {
  114. unsigned long flagv;
  115. spin_lock_irqsave(&fib->event_lock, flagv);
  116. if (!fib->done)
  117. fib->done = 1;
  118. up(&fib->event_wait);
  119. spin_unlock_irqrestore(&fib->event_lock, flagv);
  120. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  121. if (fib->done == 2) {
  122. aac_fib_complete(fib);
  123. aac_fib_free(fib);
  124. }
  125. }
  126. consumed++;
  127. spin_lock_irqsave(q->lock, flags);
  128. }
  129. if (consumed > aac_config.peak_fibs)
  130. aac_config.peak_fibs = consumed;
  131. if (consumed == 0)
  132. aac_config.zero_fibs++;
  133. spin_unlock_irqrestore(q->lock, flags);
  134. return 0;
  135. }
  136. /**
  137. * aac_command_normal - handle commands
  138. * @q: queue to process
  139. *
  140. * This DPC routine will be queued when the adapter interrupts us to
  141. * let us know there is a command on our normal priority queue. We will
  142. * pull off all QE there are and wake up all the waiters before exiting.
  143. * We will take a spinlock out on the queue before operating on it.
  144. */
  145. unsigned int aac_command_normal(struct aac_queue *q)
  146. {
  147. struct aac_dev * dev = q->dev;
  148. struct aac_entry *entry;
  149. unsigned long flags;
  150. spin_lock_irqsave(q->lock, flags);
  151. /*
  152. * Keep pulling response QEs off the response queue and waking
  153. * up the waiters until there are no more QEs. We then return
  154. * back to the system.
  155. */
  156. while(aac_consumer_get(dev, q, &entry))
  157. {
  158. struct fib fibctx;
  159. struct hw_fib * hw_fib;
  160. u32 index;
  161. struct fib *fib = &fibctx;
  162. index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
  163. hw_fib = &dev->aif_base_va[index];
  164. /*
  165. * Allocate a FIB at all costs. For non queued stuff
  166. * we can just use the stack so we are happy. We need
  167. * a fib object in order to manage the linked lists
  168. */
  169. if (dev->aif_thread)
  170. if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
  171. fib = &fibctx;
  172. memset(fib, 0, sizeof(struct fib));
  173. INIT_LIST_HEAD(&fib->fiblink);
  174. fib->type = FSAFS_NTC_FIB_CONTEXT;
  175. fib->size = sizeof(struct fib);
  176. fib->hw_fib = hw_fib;
  177. fib->data = hw_fib->data;
  178. fib->dev = dev;
  179. if (dev->aif_thread && fib != &fibctx) {
  180. list_add_tail(&fib->fiblink, &q->cmdq);
  181. aac_consumer_free(dev, q, HostNormCmdQueue);
  182. wake_up_interruptible(&q->cmdready);
  183. } else {
  184. aac_consumer_free(dev, q, HostNormCmdQueue);
  185. spin_unlock_irqrestore(q->lock, flags);
  186. /*
  187. * Set the status of this FIB
  188. */
  189. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  190. aac_fib_adapter_complete(fib, sizeof(u32));
  191. spin_lock_irqsave(q->lock, flags);
  192. }
  193. }
  194. spin_unlock_irqrestore(q->lock, flags);
  195. return 0;
  196. }
  197. /**
  198. * aac_intr_normal - Handle command replies
  199. * @dev: Device
  200. * @index: completion reference
  201. *
  202. * This DPC routine will be run when the adapter interrupts us to let us
  203. * know there is a response on our normal priority queue. We will pull off
  204. * all QE there are and wake up all the waiters before exiting.
  205. */
  206. unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index)
  207. {
  208. u32 index = le32_to_cpu(Index);
  209. dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, Index));
  210. if ((index & 0x00000002L)) {
  211. struct hw_fib * hw_fib;
  212. struct fib * fib;
  213. struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
  214. unsigned long flags;
  215. if (index == 0xFFFFFFFEL) /* Special Case */
  216. return 0; /* Do nothing */
  217. /*
  218. * Allocate a FIB. For non queued stuff we can just use
  219. * the stack so we are happy. We need a fib object in order to
  220. * manage the linked lists.
  221. */
  222. if ((!dev->aif_thread)
  223. || (!(fib = kmalloc(sizeof(struct fib),GFP_ATOMIC))))
  224. return 1;
  225. if (!(hw_fib = kmalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
  226. kfree (fib);
  227. return 1;
  228. }
  229. memset(hw_fib, 0, sizeof(struct hw_fib));
  230. memcpy(hw_fib, (struct hw_fib *)(((unsigned long)(dev->regs.sa)) + (index & ~0x00000002L)), sizeof(struct hw_fib));
  231. memset(fib, 0, sizeof(struct fib));
  232. INIT_LIST_HEAD(&fib->fiblink);
  233. fib->type = FSAFS_NTC_FIB_CONTEXT;
  234. fib->size = sizeof(struct fib);
  235. fib->hw_fib = hw_fib;
  236. fib->data = hw_fib->data;
  237. fib->dev = dev;
  238. spin_lock_irqsave(q->lock, flags);
  239. list_add_tail(&fib->fiblink, &q->cmdq);
  240. wake_up_interruptible(&q->cmdready);
  241. spin_unlock_irqrestore(q->lock, flags);
  242. return 1;
  243. } else {
  244. int fast = index & 0x01;
  245. struct fib * fib = &dev->fibs[index >> 2];
  246. struct hw_fib * hwfib = fib->hw_fib;
  247. /*
  248. * Remove this fib from the Outstanding I/O queue.
  249. * But only if it has not already been timed out.
  250. *
  251. * If the fib has been timed out already, then just
  252. * continue. The caller has already been notified that
  253. * the fib timed out.
  254. */
  255. if ((fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
  256. printk(KERN_WARNING "aacraid: FIB timeout (%x).\n", fib->flags);
  257. printk(KERN_DEBUG"aacraid: hwfib=%p index=%i fib=%p\n",hwfib, hwfib->header.SenderData,fib);
  258. return 0;
  259. }
  260. dev->queues->queue[AdapNormCmdQueue].numpending--;
  261. if (fast) {
  262. /*
  263. * Doctor the fib
  264. */
  265. *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
  266. hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
  267. }
  268. FIB_COUNTER_INCREMENT(aac_config.FibRecved);
  269. if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
  270. {
  271. u32 *pstatus = (u32 *)hwfib->data;
  272. if (*pstatus & cpu_to_le32(0xffff0000))
  273. *pstatus = cpu_to_le32(ST_OK);
  274. }
  275. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
  276. {
  277. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
  278. FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
  279. else
  280. FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
  281. /*
  282. * NOTE: we cannot touch the fib after this
  283. * call, because it may have been deallocated.
  284. */
  285. fib->callback(fib->callback_data, fib);
  286. } else {
  287. unsigned long flagv;
  288. dprintk((KERN_INFO "event_wait up\n"));
  289. spin_lock_irqsave(&fib->event_lock, flagv);
  290. if (!fib->done)
  291. fib->done = 1;
  292. up(&fib->event_wait);
  293. spin_unlock_irqrestore(&fib->event_lock, flagv);
  294. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  295. }
  296. return 0;
  297. }
  298. }