dpcsup.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. atomic_dec(&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. fib->flags |= FIB_CONTEXT_FLAG_FASTRESP;
  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->flags &= FIB_CONTEXT_FLAG_FASTRESP;
  116. fib->callback(fib->callback_data, fib);
  117. } else {
  118. unsigned long flagv;
  119. spin_lock_irqsave(&fib->event_lock, flagv);
  120. if (!fib->done) {
  121. fib->done = 1;
  122. up(&fib->event_wait);
  123. }
  124. spin_unlock_irqrestore(&fib->event_lock, flagv);
  125. spin_lock_irqsave(&dev->manage_lock, mflags);
  126. dev->management_fib_count--;
  127. spin_unlock_irqrestore(&dev->manage_lock, mflags);
  128. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  129. if (fib->done == 2) {
  130. spin_lock_irqsave(&fib->event_lock, flagv);
  131. fib->done = 0;
  132. spin_unlock_irqrestore(&fib->event_lock, flagv);
  133. aac_fib_complete(fib);
  134. aac_fib_free(fib);
  135. }
  136. }
  137. consumed++;
  138. spin_lock_irqsave(q->lock, flags);
  139. }
  140. if (consumed > aac_config.peak_fibs)
  141. aac_config.peak_fibs = consumed;
  142. if (consumed == 0)
  143. aac_config.zero_fibs++;
  144. spin_unlock_irqrestore(q->lock, flags);
  145. return 0;
  146. }
  147. /**
  148. * aac_command_normal - handle commands
  149. * @q: queue to process
  150. *
  151. * This DPC routine will be queued when the adapter interrupts us to
  152. * let us know there is a command on our normal priority queue. We will
  153. * pull off all QE there are and wake up all the waiters before exiting.
  154. * We will take a spinlock out on the queue before operating on it.
  155. */
  156. unsigned int aac_command_normal(struct aac_queue *q)
  157. {
  158. struct aac_dev * dev = q->dev;
  159. struct aac_entry *entry;
  160. unsigned long flags;
  161. spin_lock_irqsave(q->lock, flags);
  162. /*
  163. * Keep pulling response QEs off the response queue and waking
  164. * up the waiters until there are no more QEs. We then return
  165. * back to the system.
  166. */
  167. while(aac_consumer_get(dev, q, &entry))
  168. {
  169. struct fib fibctx;
  170. struct hw_fib * hw_fib;
  171. u32 index;
  172. struct fib *fib = &fibctx;
  173. index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
  174. hw_fib = &dev->aif_base_va[index];
  175. /*
  176. * Allocate a FIB at all costs. For non queued stuff
  177. * we can just use the stack so we are happy. We need
  178. * a fib object in order to manage the linked lists
  179. */
  180. if (dev->aif_thread)
  181. if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
  182. fib = &fibctx;
  183. memset(fib, 0, sizeof(struct fib));
  184. INIT_LIST_HEAD(&fib->fiblink);
  185. fib->type = FSAFS_NTC_FIB_CONTEXT;
  186. fib->size = sizeof(struct fib);
  187. fib->hw_fib_va = hw_fib;
  188. fib->data = hw_fib->data;
  189. fib->dev = dev;
  190. if (dev->aif_thread && fib != &fibctx) {
  191. list_add_tail(&fib->fiblink, &q->cmdq);
  192. aac_consumer_free(dev, q, HostNormCmdQueue);
  193. wake_up_interruptible(&q->cmdready);
  194. } else {
  195. aac_consumer_free(dev, q, HostNormCmdQueue);
  196. spin_unlock_irqrestore(q->lock, flags);
  197. /*
  198. * Set the status of this FIB
  199. */
  200. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  201. aac_fib_adapter_complete(fib, sizeof(u32));
  202. spin_lock_irqsave(q->lock, flags);
  203. }
  204. }
  205. spin_unlock_irqrestore(q->lock, flags);
  206. return 0;
  207. }
  208. /*
  209. *
  210. * aac_aif_callback
  211. * @context: the context set in the fib - here it is scsi cmd
  212. * @fibptr: pointer to the fib
  213. *
  214. * Handles the AIFs - new method (SRC)
  215. *
  216. */
  217. static void aac_aif_callback(void *context, struct fib * fibptr)
  218. {
  219. struct fib *fibctx;
  220. struct aac_dev *dev;
  221. struct aac_aifcmd *cmd;
  222. int status;
  223. fibctx = (struct fib *)context;
  224. BUG_ON(fibptr == NULL);
  225. dev = fibptr->dev;
  226. if (fibptr->hw_fib_va->header.XferState &
  227. cpu_to_le32(NoMoreAifDataAvailable)) {
  228. aac_fib_complete(fibptr);
  229. aac_fib_free(fibptr);
  230. return;
  231. }
  232. aac_intr_normal(dev, 0, 1, 0, fibptr->hw_fib_va);
  233. aac_fib_init(fibctx);
  234. cmd = (struct aac_aifcmd *) fib_data(fibctx);
  235. cmd->command = cpu_to_le32(AifReqEvent);
  236. status = aac_fib_send(AifRequest,
  237. fibctx,
  238. sizeof(struct hw_fib)-sizeof(struct aac_fibhdr),
  239. FsaNormal,
  240. 0, 1,
  241. (fib_callback)aac_aif_callback, fibctx);
  242. }
  243. /**
  244. * aac_intr_normal - Handle command replies
  245. * @dev: Device
  246. * @index: completion reference
  247. *
  248. * This DPC routine will be run when the adapter interrupts us to let us
  249. * know there is a response on our normal priority queue. We will pull off
  250. * all QE there are and wake up all the waiters before exiting.
  251. */
  252. unsigned int aac_intr_normal(struct aac_dev *dev, u32 index,
  253. int isAif, int isFastResponse, struct hw_fib *aif_fib)
  254. {
  255. unsigned long mflags;
  256. dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, index));
  257. if (isAif == 1) { /* AIF - common */
  258. struct hw_fib * hw_fib;
  259. struct fib * fib;
  260. struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
  261. unsigned long flags;
  262. /*
  263. * Allocate a FIB. For non queued stuff we can just use
  264. * the stack so we are happy. We need a fib object in order to
  265. * manage the linked lists.
  266. */
  267. if ((!dev->aif_thread)
  268. || (!(fib = kzalloc(sizeof(struct fib),GFP_ATOMIC))))
  269. return 1;
  270. if (!(hw_fib = kzalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
  271. kfree (fib);
  272. return 1;
  273. }
  274. if (aif_fib != NULL) {
  275. memcpy(hw_fib, aif_fib, sizeof(struct hw_fib));
  276. } else {
  277. memcpy(hw_fib,
  278. (struct hw_fib *)(((uintptr_t)(dev->regs.sa)) +
  279. index), sizeof(struct hw_fib));
  280. }
  281. INIT_LIST_HEAD(&fib->fiblink);
  282. fib->type = FSAFS_NTC_FIB_CONTEXT;
  283. fib->size = sizeof(struct fib);
  284. fib->hw_fib_va = hw_fib;
  285. fib->data = hw_fib->data;
  286. fib->dev = dev;
  287. spin_lock_irqsave(q->lock, flags);
  288. list_add_tail(&fib->fiblink, &q->cmdq);
  289. wake_up_interruptible(&q->cmdready);
  290. spin_unlock_irqrestore(q->lock, flags);
  291. return 1;
  292. } else if (isAif == 2) { /* AIF - new (SRC) */
  293. struct fib *fibctx;
  294. struct aac_aifcmd *cmd;
  295. fibctx = aac_fib_alloc(dev);
  296. if (!fibctx)
  297. return 1;
  298. aac_fib_init(fibctx);
  299. cmd = (struct aac_aifcmd *) fib_data(fibctx);
  300. cmd->command = cpu_to_le32(AifReqEvent);
  301. return aac_fib_send(AifRequest,
  302. fibctx,
  303. sizeof(struct hw_fib)-sizeof(struct aac_fibhdr),
  304. FsaNormal,
  305. 0, 1,
  306. (fib_callback)aac_aif_callback, fibctx);
  307. } else {
  308. struct fib *fib = &dev->fibs[index];
  309. struct hw_fib * hwfib = fib->hw_fib_va;
  310. /*
  311. * Remove this fib from the Outstanding I/O queue.
  312. * But only if it has not already been timed out.
  313. *
  314. * If the fib has been timed out already, then just
  315. * continue. The caller has already been notified that
  316. * the fib timed out.
  317. */
  318. atomic_dec(&dev->queues->queue[AdapNormCmdQueue].numpending);
  319. if (unlikely(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
  320. aac_fib_complete(fib);
  321. aac_fib_free(fib);
  322. return 0;
  323. }
  324. if (isFastResponse) {
  325. /*
  326. * Doctor the fib
  327. */
  328. *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
  329. hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
  330. fib->flags |= FIB_CONTEXT_FLAG_FASTRESP;
  331. }
  332. FIB_COUNTER_INCREMENT(aac_config.FibRecved);
  333. if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
  334. {
  335. __le32 *pstatus = (__le32 *)hwfib->data;
  336. if (*pstatus & cpu_to_le32(0xffff0000))
  337. *pstatus = cpu_to_le32(ST_OK);
  338. }
  339. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
  340. {
  341. if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
  342. FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
  343. else
  344. FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
  345. /*
  346. * NOTE: we cannot touch the fib after this
  347. * call, because it may have been deallocated.
  348. */
  349. if (likely(fib->callback && fib->callback_data)) {
  350. fib->flags &= FIB_CONTEXT_FLAG_FASTRESP;
  351. fib->callback(fib->callback_data, fib);
  352. } else {
  353. aac_fib_complete(fib);
  354. aac_fib_free(fib);
  355. }
  356. } else {
  357. unsigned long flagv;
  358. dprintk((KERN_INFO "event_wait up\n"));
  359. spin_lock_irqsave(&fib->event_lock, flagv);
  360. if (!fib->done) {
  361. fib->done = 1;
  362. up(&fib->event_wait);
  363. }
  364. spin_unlock_irqrestore(&fib->event_lock, flagv);
  365. spin_lock_irqsave(&dev->manage_lock, mflags);
  366. dev->management_fib_count--;
  367. spin_unlock_irqrestore(&dev->manage_lock, mflags);
  368. FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
  369. if (fib->done == 2) {
  370. spin_lock_irqsave(&fib->event_lock, flagv);
  371. fib->done = 0;
  372. spin_unlock_irqrestore(&fib->event_lock, flagv);
  373. aac_fib_complete(fib);
  374. aac_fib_free(fib);
  375. }
  376. }
  377. return 0;
  378. }
  379. }