dpcsup.c 10.0 KB

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