dpcsup.c 9.4 KB

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