dpcsup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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-2010 Adaptec, Inc.
  9. * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Module Name:
  26. * dpcsup.c
  27. *
  28. * Abstract: All DPC processing routines for the cyclone board occur here.
  29. *
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/init.h>
  34. #include <linux/types.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/slab.h>
  37. #include <linux/completion.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/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, mflags;
  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->flags = 0;
  115. fib->callback(fib->callback_data, fib);
  116. } else {
  117. unsigned long flagv;
  118. spin_lock_irqsave(&fib->event_lock, flagv);
  119. if (!fib->done) {
  120. fib->done = 1;
  121. up(&fib->event_wait);
  122. }
  123. spin_unlock_irqrestore(&fib->event_lock, flagv);
  124. spin_lock_irqsave(&dev->manage_lock, mflags);
  125. dev->management_fib_count--;
  126. spin_unlock_irqrestore(&dev->manage_lock, mflags);
  127. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  128. if (fib->done == 2) {
  129. spin_lock_irqsave(&fib->event_lock, flagv);
  130. fib->done = 0;
  131. spin_unlock_irqrestore(&fib->event_lock, flagv);
  132. aac_fib_complete(fib);
  133. aac_fib_free(fib);
  134. }
  135. }
  136. consumed++;
  137. spin_lock_irqsave(q->lock, flags);
  138. }
  139. if (consumed > aac_config.peak_fibs)
  140. aac_config.peak_fibs = consumed;
  141. if (consumed == 0)
  142. aac_config.zero_fibs++;
  143. spin_unlock_irqrestore(q->lock, flags);
  144. return 0;
  145. }
  146. /**
  147. * aac_command_normal - handle commands
  148. * @q: queue to process
  149. *
  150. * This DPC routine will be queued when the adapter interrupts us to
  151. * let us know there is a command on our normal priority queue. We will
  152. * pull off all QE there are and wake up all the waiters before exiting.
  153. * We will take a spinlock out on the queue before operating on it.
  154. */
  155. unsigned int aac_command_normal(struct aac_queue *q)
  156. {
  157. struct aac_dev * dev = q->dev;
  158. struct aac_entry *entry;
  159. unsigned long flags;
  160. spin_lock_irqsave(q->lock, flags);
  161. /*
  162. * Keep pulling response QEs off the response queue and waking
  163. * up the waiters until there are no more QEs. We then return
  164. * back to the system.
  165. */
  166. while(aac_consumer_get(dev, q, &entry))
  167. {
  168. struct fib fibctx;
  169. struct hw_fib * hw_fib;
  170. u32 index;
  171. struct fib *fib = &fibctx;
  172. index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
  173. hw_fib = &dev->aif_base_va[index];
  174. /*
  175. * Allocate a FIB at all costs. For non queued stuff
  176. * we can just use the stack so we are happy. We need
  177. * a fib object in order to manage the linked lists
  178. */
  179. if (dev->aif_thread)
  180. if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
  181. fib = &fibctx;
  182. memset(fib, 0, sizeof(struct fib));
  183. INIT_LIST_HEAD(&fib->fiblink);
  184. fib->type = FSAFS_NTC_FIB_CONTEXT;
  185. fib->size = sizeof(struct fib);
  186. fib->hw_fib_va = hw_fib;
  187. fib->data = hw_fib->data;
  188. fib->dev = dev;
  189. if (dev->aif_thread && fib != &fibctx) {
  190. list_add_tail(&fib->fiblink, &q->cmdq);
  191. aac_consumer_free(dev, q, HostNormCmdQueue);
  192. wake_up_interruptible(&q->cmdready);
  193. } else {
  194. aac_consumer_free(dev, q, HostNormCmdQueue);
  195. spin_unlock_irqrestore(q->lock, flags);
  196. /*
  197. * Set the status of this FIB
  198. */
  199. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  200. aac_fib_adapter_complete(fib, sizeof(u32));
  201. spin_lock_irqsave(q->lock, flags);
  202. }
  203. }
  204. spin_unlock_irqrestore(q->lock, flags);
  205. return 0;
  206. }
  207. /*
  208. *
  209. * aac_aif_callback
  210. * @context: the context set in the fib - here it is scsi cmd
  211. * @fibptr: pointer to the fib
  212. *
  213. * Handles the AIFs - new method (SRC)
  214. *
  215. */
  216. static void aac_aif_callback(void *context, struct fib * fibptr)
  217. {
  218. struct fib *fibctx;
  219. struct aac_dev *dev;
  220. struct aac_aifcmd *cmd;
  221. int status;
  222. fibctx = (struct fib *)context;
  223. BUG_ON(fibptr == NULL);
  224. dev = fibptr->dev;
  225. if (fibptr->hw_fib_va->header.XferState &
  226. cpu_to_le32(NoMoreAifDataAvailable)) {
  227. aac_fib_complete(fibptr);
  228. aac_fib_free(fibptr);
  229. return;
  230. }
  231. aac_intr_normal(dev, 0, 1, 0, fibptr->hw_fib_va);
  232. aac_fib_init(fibctx);
  233. cmd = (struct aac_aifcmd *) fib_data(fibctx);
  234. cmd->command = cpu_to_le32(AifReqEvent);
  235. status = aac_fib_send(AifRequest,
  236. fibctx,
  237. sizeof(struct hw_fib)-sizeof(struct aac_fibhdr),
  238. FsaNormal,
  239. 0, 1,
  240. (fib_callback)aac_aif_callback, fibctx);
  241. }
  242. /**
  243. * aac_intr_normal - Handle command replies
  244. * @dev: Device
  245. * @index: completion reference
  246. *
  247. * This DPC routine will be run when the adapter interrupts us to let us
  248. * know there is a response on our normal priority queue. We will pull off
  249. * all QE there are and wake up all the waiters before exiting.
  250. */
  251. unsigned int aac_intr_normal(struct aac_dev *dev, u32 index,
  252. int isAif, int isFastResponse, struct hw_fib *aif_fib)
  253. {
  254. unsigned long mflags;
  255. dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, index));
  256. if (isAif == 1) { /* AIF - common */
  257. struct hw_fib * hw_fib;
  258. struct fib * fib;
  259. struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
  260. unsigned long flags;
  261. /*
  262. * Allocate a FIB. For non queued stuff we can just use
  263. * the stack so we are happy. We need a fib object in order to
  264. * manage the linked lists.
  265. */
  266. if ((!dev->aif_thread)
  267. || (!(fib = kzalloc(sizeof(struct fib),GFP_ATOMIC))))
  268. return 1;
  269. if (!(hw_fib = kzalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
  270. kfree (fib);
  271. return 1;
  272. }
  273. if (aif_fib != NULL) {
  274. memcpy(hw_fib, aif_fib, sizeof(struct hw_fib));
  275. } else {
  276. memcpy(hw_fib,
  277. (struct hw_fib *)(((uintptr_t)(dev->regs.sa)) +
  278. index), sizeof(struct hw_fib));
  279. }
  280. INIT_LIST_HEAD(&fib->fiblink);
  281. fib->type = FSAFS_NTC_FIB_CONTEXT;
  282. fib->size = sizeof(struct fib);
  283. fib->hw_fib_va = hw_fib;
  284. fib->data = hw_fib->data;
  285. fib->dev = dev;
  286. spin_lock_irqsave(q->lock, flags);
  287. list_add_tail(&fib->fiblink, &q->cmdq);
  288. wake_up_interruptible(&q->cmdready);
  289. spin_unlock_irqrestore(q->lock, flags);
  290. return 1;
  291. } else if (isAif == 2) { /* AIF - new (SRC) */
  292. struct fib *fibctx;
  293. struct aac_aifcmd *cmd;
  294. fibctx = aac_fib_alloc(dev);
  295. if (!fibctx)
  296. return 1;
  297. aac_fib_init(fibctx);
  298. cmd = (struct aac_aifcmd *) fib_data(fibctx);
  299. cmd->command = cpu_to_le32(AifReqEvent);
  300. return aac_fib_send(AifRequest,
  301. fibctx,
  302. sizeof(struct hw_fib)-sizeof(struct aac_fibhdr),
  303. FsaNormal,
  304. 0, 1,
  305. (fib_callback)aac_aif_callback, fibctx);
  306. } else {
  307. struct fib *fib = &dev->fibs[index];
  308. struct hw_fib * hwfib = fib->hw_fib_va;
  309. /*
  310. * Remove this fib from the Outstanding I/O queue.
  311. * But only if it has not already been timed out.
  312. *
  313. * If the fib has been timed out already, then just
  314. * continue. The caller has already been notified that
  315. * the fib timed out.
  316. */
  317. dev->queues->queue[AdapNormCmdQueue].numpending--;
  318. if (unlikely(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
  319. aac_fib_complete(fib);
  320. aac_fib_free(fib);
  321. return 0;
  322. }
  323. if (isFastResponse) {
  324. /*
  325. * Doctor the fib
  326. */
  327. *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
  328. hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
  329. }
  330. FIB_COUNTER_INCREMENT(aac_config.FibRecved);
  331. if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
  332. {
  333. __le32 *pstatus = (__le32 *)hwfib->data;
  334. if (*pstatus & cpu_to_le32(0xffff0000))
  335. *pstatus = cpu_to_le32(ST_OK);
  336. }
  337. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
  338. {
  339. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
  340. FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
  341. else
  342. FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
  343. /*
  344. * NOTE: we cannot touch the fib after this
  345. * call, because it may have been deallocated.
  346. */
  347. fib->flags = 0;
  348. fib->callback(fib->callback_data, fib);
  349. } else {
  350. unsigned long flagv;
  351. dprintk((KERN_INFO "event_wait up\n"));
  352. spin_lock_irqsave(&fib->event_lock, flagv);
  353. if (!fib->done) {
  354. fib->done = 1;
  355. up(&fib->event_wait);
  356. }
  357. spin_unlock_irqrestore(&fib->event_lock, flagv);
  358. spin_lock_irqsave(&dev->manage_lock, mflags);
  359. dev->management_fib_count--;
  360. spin_unlock_irqrestore(&dev->manage_lock, mflags);
  361. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  362. if (fib->done == 2) {
  363. spin_lock_irqsave(&fib->event_lock, flagv);
  364. fib->done = 0;
  365. spin_unlock_irqrestore(&fib->event_lock, flagv);
  366. aac_fib_complete(fib);
  367. aac_fib_free(fib);
  368. }
  369. }
  370. return 0;
  371. }
  372. }