commsup.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. * commsup.c
  26. *
  27. * Abstract: Contain all routines that are required for FSA host/adapter
  28. * communication.
  29. *
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/types.h>
  34. #include <linux/sched.h>
  35. #include <linux/pci.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/slab.h>
  38. #include <linux/completion.h>
  39. #include <linux/blkdev.h>
  40. #include <scsi/scsi_host.h>
  41. #include <scsi/scsi_device.h>
  42. #include <asm/semaphore.h>
  43. #include <asm/delay.h>
  44. #include "aacraid.h"
  45. /**
  46. * fib_map_alloc - allocate the fib objects
  47. * @dev: Adapter to allocate for
  48. *
  49. * Allocate and map the shared PCI space for the FIB blocks used to
  50. * talk to the Adaptec firmware.
  51. */
  52. static int fib_map_alloc(struct aac_dev *dev)
  53. {
  54. dprintk((KERN_INFO
  55. "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
  56. dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue,
  57. AAC_NUM_MGT_FIB, &dev->hw_fib_pa));
  58. if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, dev->max_fib_size
  59. * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
  60. &dev->hw_fib_pa))==NULL)
  61. return -ENOMEM;
  62. return 0;
  63. }
  64. /**
  65. * fib_map_free - free the fib objects
  66. * @dev: Adapter to free
  67. *
  68. * Free the PCI mappings and the memory allocated for FIB blocks
  69. * on this adapter.
  70. */
  71. void fib_map_free(struct aac_dev *dev)
  72. {
  73. pci_free_consistent(dev->pdev, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB), dev->hw_fib_va, dev->hw_fib_pa);
  74. }
  75. /**
  76. * fib_setup - setup the fibs
  77. * @dev: Adapter to set up
  78. *
  79. * Allocate the PCI space for the fibs, map it and then intialise the
  80. * fib area, the unmapped fib data and also the free list
  81. */
  82. int fib_setup(struct aac_dev * dev)
  83. {
  84. struct fib *fibptr;
  85. struct hw_fib *hw_fib_va;
  86. dma_addr_t hw_fib_pa;
  87. int i;
  88. while (((i = fib_map_alloc(dev)) == -ENOMEM)
  89. && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {
  90. dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1);
  91. dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB;
  92. }
  93. if (i<0)
  94. return -ENOMEM;
  95. hw_fib_va = dev->hw_fib_va;
  96. hw_fib_pa = dev->hw_fib_pa;
  97. memset(hw_fib_va, 0, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
  98. /*
  99. * Initialise the fibs
  100. */
  101. for (i = 0, fibptr = &dev->fibs[i]; i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); i++, fibptr++)
  102. {
  103. fibptr->dev = dev;
  104. fibptr->hw_fib = hw_fib_va;
  105. fibptr->data = (void *) fibptr->hw_fib->data;
  106. fibptr->next = fibptr+1; /* Forward chain the fibs */
  107. init_MUTEX_LOCKED(&fibptr->event_wait);
  108. spin_lock_init(&fibptr->event_lock);
  109. hw_fib_va->header.XferState = cpu_to_le32(0xffffffff);
  110. hw_fib_va->header.SenderSize = cpu_to_le16(dev->max_fib_size);
  111. fibptr->hw_fib_pa = hw_fib_pa;
  112. hw_fib_va = (struct hw_fib *)((unsigned char *)hw_fib_va + dev->max_fib_size);
  113. hw_fib_pa = hw_fib_pa + dev->max_fib_size;
  114. }
  115. /*
  116. * Add the fib chain to the free list
  117. */
  118. dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;
  119. /*
  120. * Enable this to debug out of queue space
  121. */
  122. dev->free_fib = &dev->fibs[0];
  123. return 0;
  124. }
  125. /**
  126. * fib_alloc - allocate a fib
  127. * @dev: Adapter to allocate the fib for
  128. *
  129. * Allocate a fib from the adapter fib pool. If the pool is empty we
  130. * return NULL.
  131. */
  132. struct fib * fib_alloc(struct aac_dev *dev)
  133. {
  134. struct fib * fibptr;
  135. unsigned long flags;
  136. spin_lock_irqsave(&dev->fib_lock, flags);
  137. fibptr = dev->free_fib;
  138. if(!fibptr){
  139. spin_unlock_irqrestore(&dev->fib_lock, flags);
  140. return fibptr;
  141. }
  142. dev->free_fib = fibptr->next;
  143. spin_unlock_irqrestore(&dev->fib_lock, flags);
  144. /*
  145. * Set the proper node type code and node byte size
  146. */
  147. fibptr->type = FSAFS_NTC_FIB_CONTEXT;
  148. fibptr->size = sizeof(struct fib);
  149. /*
  150. * Null out fields that depend on being zero at the start of
  151. * each I/O
  152. */
  153. fibptr->hw_fib->header.XferState = 0;
  154. fibptr->callback = NULL;
  155. fibptr->callback_data = NULL;
  156. return fibptr;
  157. }
  158. /**
  159. * fib_free - free a fib
  160. * @fibptr: fib to free up
  161. *
  162. * Frees up a fib and places it on the appropriate queue
  163. * (either free or timed out)
  164. */
  165. void fib_free(struct fib * fibptr)
  166. {
  167. unsigned long flags;
  168. spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
  169. if (fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT) {
  170. aac_config.fib_timeouts++;
  171. fibptr->next = fibptr->dev->timeout_fib;
  172. fibptr->dev->timeout_fib = fibptr;
  173. } else {
  174. if (fibptr->hw_fib->header.XferState != 0) {
  175. printk(KERN_WARNING "fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
  176. (void*)fibptr,
  177. le32_to_cpu(fibptr->hw_fib->header.XferState));
  178. }
  179. fibptr->next = fibptr->dev->free_fib;
  180. fibptr->dev->free_fib = fibptr;
  181. }
  182. spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags);
  183. }
  184. /**
  185. * fib_init - initialise a fib
  186. * @fibptr: The fib to initialize
  187. *
  188. * Set up the generic fib fields ready for use
  189. */
  190. void fib_init(struct fib *fibptr)
  191. {
  192. struct hw_fib *hw_fib = fibptr->hw_fib;
  193. hw_fib->header.StructType = FIB_MAGIC;
  194. hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);
  195. hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
  196. hw_fib->header.SenderFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
  197. hw_fib->header.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
  198. hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);
  199. }
  200. /**
  201. * fib_deallocate - deallocate a fib
  202. * @fibptr: fib to deallocate
  203. *
  204. * Will deallocate and return to the free pool the FIB pointed to by the
  205. * caller.
  206. */
  207. static void fib_dealloc(struct fib * fibptr)
  208. {
  209. struct hw_fib *hw_fib = fibptr->hw_fib;
  210. if(hw_fib->header.StructType != FIB_MAGIC)
  211. BUG();
  212. hw_fib->header.XferState = 0;
  213. }
  214. /*
  215. * Commuication primitives define and support the queuing method we use to
  216. * support host to adapter commuication. All queue accesses happen through
  217. * these routines and are the only routines which have a knowledge of the
  218. * how these queues are implemented.
  219. */
  220. /**
  221. * aac_get_entry - get a queue entry
  222. * @dev: Adapter
  223. * @qid: Queue Number
  224. * @entry: Entry return
  225. * @index: Index return
  226. * @nonotify: notification control
  227. *
  228. * With a priority the routine returns a queue entry if the queue has free entries. If the queue
  229. * is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is
  230. * returned.
  231. */
  232. static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
  233. {
  234. struct aac_queue * q;
  235. unsigned long idx;
  236. /*
  237. * All of the queues wrap when they reach the end, so we check
  238. * to see if they have reached the end and if they have we just
  239. * set the index back to zero. This is a wrap. You could or off
  240. * the high bits in all updates but this is a bit faster I think.
  241. */
  242. q = &dev->queues->queue[qid];
  243. idx = *index = le32_to_cpu(*(q->headers.producer));
  244. /* Interrupt Moderation, only interrupt for first two entries */
  245. if (idx != le32_to_cpu(*(q->headers.consumer))) {
  246. if (--idx == 0) {
  247. if (qid == AdapNormCmdQueue)
  248. idx = ADAP_NORM_CMD_ENTRIES;
  249. else
  250. idx = ADAP_NORM_RESP_ENTRIES;
  251. }
  252. if (idx != le32_to_cpu(*(q->headers.consumer)))
  253. *nonotify = 1;
  254. }
  255. if (qid == AdapNormCmdQueue) {
  256. if (*index >= ADAP_NORM_CMD_ENTRIES)
  257. *index = 0; /* Wrap to front of the Producer Queue. */
  258. } else {
  259. if (*index >= ADAP_NORM_RESP_ENTRIES)
  260. *index = 0; /* Wrap to front of the Producer Queue. */
  261. }
  262. if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */
  263. printk(KERN_WARNING "Queue %d full, %u outstanding.\n",
  264. qid, q->numpending);
  265. return 0;
  266. } else {
  267. *entry = q->base + *index;
  268. return 1;
  269. }
  270. }
  271. /**
  272. * aac_queue_get - get the next free QE
  273. * @dev: Adapter
  274. * @index: Returned index
  275. * @priority: Priority of fib
  276. * @fib: Fib to associate with the queue entry
  277. * @wait: Wait if queue full
  278. * @fibptr: Driver fib object to go with fib
  279. * @nonotify: Don't notify the adapter
  280. *
  281. * Gets the next free QE off the requested priorty adapter command
  282. * queue and associates the Fib with the QE. The QE represented by
  283. * index is ready to insert on the queue when this routine returns
  284. * success.
  285. */
  286. static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify)
  287. {
  288. struct aac_entry * entry = NULL;
  289. int map = 0;
  290. if (qid == AdapNormCmdQueue) {
  291. /* if no entries wait for some if caller wants to */
  292. while (!aac_get_entry(dev, qid, &entry, index, nonotify))
  293. {
  294. printk(KERN_ERR "GetEntries failed\n");
  295. }
  296. /*
  297. * Setup queue entry with a command, status and fib mapped
  298. */
  299. entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
  300. map = 1;
  301. } else {
  302. while(!aac_get_entry(dev, qid, &entry, index, nonotify))
  303. {
  304. /* if no entries wait for some if caller wants to */
  305. }
  306. /*
  307. * Setup queue entry with command, status and fib mapped
  308. */
  309. entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
  310. entry->addr = hw_fib->header.SenderFibAddress;
  311. /* Restore adapters pointer to the FIB */
  312. hw_fib->header.ReceiverFibAddress = hw_fib->header.SenderFibAddress; /* Let the adapter now where to find its data */
  313. map = 0;
  314. }
  315. /*
  316. * If MapFib is true than we need to map the Fib and put pointers
  317. * in the queue entry.
  318. */
  319. if (map)
  320. entry->addr = cpu_to_le32(fibptr->hw_fib_pa);
  321. return 0;
  322. }
  323. /*
  324. * Define the highest level of host to adapter communication routines.
  325. * These routines will support host to adapter FS commuication. These
  326. * routines have no knowledge of the commuication method used. This level
  327. * sends and receives FIBs. This level has no knowledge of how these FIBs
  328. * get passed back and forth.
  329. */
  330. /**
  331. * fib_send - send a fib to the adapter
  332. * @command: Command to send
  333. * @fibptr: The fib
  334. * @size: Size of fib data area
  335. * @priority: Priority of Fib
  336. * @wait: Async/sync select
  337. * @reply: True if a reply is wanted
  338. * @callback: Called with reply
  339. * @callback_data: Passed to callback
  340. *
  341. * Sends the requested FIB to the adapter and optionally will wait for a
  342. * response FIB. If the caller does not wish to wait for a response than
  343. * an event to wait on must be supplied. This event will be set when a
  344. * response FIB is received from the adapter.
  345. */
  346. int fib_send(u16 command, struct fib * fibptr, unsigned long size, int priority, int wait, int reply, fib_callback callback, void * callback_data)
  347. {
  348. u32 index;
  349. struct aac_dev * dev = fibptr->dev;
  350. unsigned long nointr = 0;
  351. struct hw_fib * hw_fib = fibptr->hw_fib;
  352. struct aac_queue * q;
  353. unsigned long flags = 0;
  354. unsigned long qflags;
  355. if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
  356. return -EBUSY;
  357. /*
  358. * There are 5 cases with the wait and reponse requested flags.
  359. * The only invalid cases are if the caller requests to wait and
  360. * does not request a response and if the caller does not want a
  361. * response and the Fib is not allocated from pool. If a response
  362. * is not requesed the Fib will just be deallocaed by the DPC
  363. * routine when the response comes back from the adapter. No
  364. * further processing will be done besides deleting the Fib. We
  365. * will have a debug mode where the adapter can notify the host
  366. * it had a problem and the host can log that fact.
  367. */
  368. if (wait && !reply) {
  369. return -EINVAL;
  370. } else if (!wait && reply) {
  371. hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected);
  372. FIB_COUNTER_INCREMENT(aac_config.AsyncSent);
  373. } else if (!wait && !reply) {
  374. hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected);
  375. FIB_COUNTER_INCREMENT(aac_config.NoResponseSent);
  376. } else if (wait && reply) {
  377. hw_fib->header.XferState |= cpu_to_le32(ResponseExpected);
  378. FIB_COUNTER_INCREMENT(aac_config.NormalSent);
  379. }
  380. /*
  381. * Map the fib into 32bits by using the fib number
  382. */
  383. hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr-dev->fibs)) << 1);
  384. hw_fib->header.SenderData = (u32)(fibptr - dev->fibs);
  385. /*
  386. * Set FIB state to indicate where it came from and if we want a
  387. * response from the adapter. Also load the command from the
  388. * caller.
  389. *
  390. * Map the hw fib pointer as a 32bit value
  391. */
  392. hw_fib->header.Command = cpu_to_le16(command);
  393. hw_fib->header.XferState |= cpu_to_le32(SentFromHost);
  394. fibptr->hw_fib->header.Flags = 0; /* 0 the flags field - internal only*/
  395. /*
  396. * Set the size of the Fib we want to send to the adapter
  397. */
  398. hw_fib->header.Size = cpu_to_le16(sizeof(struct aac_fibhdr) + size);
  399. if (le16_to_cpu(hw_fib->header.Size) > le16_to_cpu(hw_fib->header.SenderSize)) {
  400. return -EMSGSIZE;
  401. }
  402. /*
  403. * Get a queue entry connect the FIB to it and send an notify
  404. * the adapter a command is ready.
  405. */
  406. hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
  407. /*
  408. * Fill in the Callback and CallbackContext if we are not
  409. * going to wait.
  410. */
  411. if (!wait) {
  412. fibptr->callback = callback;
  413. fibptr->callback_data = callback_data;
  414. }
  415. fibptr->done = 0;
  416. fibptr->flags = 0;
  417. FIB_COUNTER_INCREMENT(aac_config.FibsSent);
  418. dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index));
  419. dprintk((KERN_DEBUG "Fib contents:.\n"));
  420. dprintk((KERN_DEBUG " Command = %d.\n", hw_fib->header.Command));
  421. dprintk((KERN_DEBUG " XferState = %x.\n", hw_fib->header.XferState));
  422. dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib));
  423. dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
  424. dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr));
  425. q = &dev->queues->queue[AdapNormCmdQueue];
  426. if(wait)
  427. spin_lock_irqsave(&fibptr->event_lock, flags);
  428. spin_lock_irqsave(q->lock, qflags);
  429. aac_queue_get( dev, &index, AdapNormCmdQueue, hw_fib, 1, fibptr, &nointr);
  430. list_add_tail(&fibptr->queue, &q->pendingq);
  431. q->numpending++;
  432. *(q->headers.producer) = cpu_to_le32(index + 1);
  433. spin_unlock_irqrestore(q->lock, qflags);
  434. if (!(nointr & aac_config.irq_mod))
  435. aac_adapter_notify(dev, AdapNormCmdQueue);
  436. /*
  437. * If the caller wanted us to wait for response wait now.
  438. */
  439. if (wait) {
  440. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  441. /* Only set for first known interruptable command */
  442. if (wait < 0) {
  443. /*
  444. * *VERY* Dangerous to time out a command, the
  445. * assumption is made that we have no hope of
  446. * functioning because an interrupt routing or other
  447. * hardware failure has occurred.
  448. */
  449. unsigned long count = 36000000L; /* 3 minutes */
  450. unsigned long qflags;
  451. while (down_trylock(&fibptr->event_wait)) {
  452. if (--count == 0) {
  453. spin_lock_irqsave(q->lock, qflags);
  454. q->numpending--;
  455. list_del(&fibptr->queue);
  456. spin_unlock_irqrestore(q->lock, qflags);
  457. if (wait == -1) {
  458. printk(KERN_ERR "aacraid: fib_send: first asynchronous command timed out.\n"
  459. "Usually a result of a PCI interrupt routing problem;\n"
  460. "update mother board BIOS or consider utilizing one of\n"
  461. "the SAFE mode kernel options (acpi, apic etc)\n");
  462. }
  463. return -ETIMEDOUT;
  464. }
  465. udelay(5);
  466. }
  467. } else
  468. down(&fibptr->event_wait);
  469. if(fibptr->done == 0)
  470. BUG();
  471. if((fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)){
  472. return -ETIMEDOUT;
  473. } else {
  474. return 0;
  475. }
  476. }
  477. /*
  478. * If the user does not want a response than return success otherwise
  479. * return pending
  480. */
  481. if (reply)
  482. return -EINPROGRESS;
  483. else
  484. return 0;
  485. }
  486. /**
  487. * aac_consumer_get - get the top of the queue
  488. * @dev: Adapter
  489. * @q: Queue
  490. * @entry: Return entry
  491. *
  492. * Will return a pointer to the entry on the top of the queue requested that
  493. * we are a consumer of, and return the address of the queue entry. It does
  494. * not change the state of the queue.
  495. */
  496. int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry)
  497. {
  498. u32 index;
  499. int status;
  500. if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) {
  501. status = 0;
  502. } else {
  503. /*
  504. * The consumer index must be wrapped if we have reached
  505. * the end of the queue, else we just use the entry
  506. * pointed to by the header index
  507. */
  508. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  509. index = 0;
  510. else
  511. index = le32_to_cpu(*q->headers.consumer);
  512. *entry = q->base + index;
  513. status = 1;
  514. }
  515. return(status);
  516. }
  517. /**
  518. * aac_consumer_free - free consumer entry
  519. * @dev: Adapter
  520. * @q: Queue
  521. * @qid: Queue ident
  522. *
  523. * Frees up the current top of the queue we are a consumer of. If the
  524. * queue was full notify the producer that the queue is no longer full.
  525. */
  526. void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid)
  527. {
  528. int wasfull = 0;
  529. u32 notify;
  530. if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer))
  531. wasfull = 1;
  532. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  533. *q->headers.consumer = cpu_to_le32(1);
  534. else
  535. *q->headers.consumer = cpu_to_le32(le32_to_cpu(*q->headers.consumer)+1);
  536. if (wasfull) {
  537. switch (qid) {
  538. case HostNormCmdQueue:
  539. notify = HostNormCmdNotFull;
  540. break;
  541. case HostNormRespQueue:
  542. notify = HostNormRespNotFull;
  543. break;
  544. default:
  545. BUG();
  546. return;
  547. }
  548. aac_adapter_notify(dev, notify);
  549. }
  550. }
  551. /**
  552. * fib_adapter_complete - complete adapter issued fib
  553. * @fibptr: fib to complete
  554. * @size: size of fib
  555. *
  556. * Will do all necessary work to complete a FIB that was sent from
  557. * the adapter.
  558. */
  559. int fib_adapter_complete(struct fib * fibptr, unsigned short size)
  560. {
  561. struct hw_fib * hw_fib = fibptr->hw_fib;
  562. struct aac_dev * dev = fibptr->dev;
  563. struct aac_queue * q;
  564. unsigned long nointr = 0;
  565. unsigned long qflags;
  566. if (hw_fib->header.XferState == 0) {
  567. return 0;
  568. }
  569. /*
  570. * If we plan to do anything check the structure type first.
  571. */
  572. if ( hw_fib->header.StructType != FIB_MAGIC ) {
  573. return -EINVAL;
  574. }
  575. /*
  576. * This block handles the case where the adapter had sent us a
  577. * command and we have finished processing the command. We
  578. * call completeFib when we are done processing the command
  579. * and want to send a response back to the adapter. This will
  580. * send the completed cdb to the adapter.
  581. */
  582. if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
  583. u32 index;
  584. hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
  585. if (size) {
  586. size += sizeof(struct aac_fibhdr);
  587. if (size > le16_to_cpu(hw_fib->header.SenderSize))
  588. return -EMSGSIZE;
  589. hw_fib->header.Size = cpu_to_le16(size);
  590. }
  591. q = &dev->queues->queue[AdapNormRespQueue];
  592. spin_lock_irqsave(q->lock, qflags);
  593. aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr);
  594. *(q->headers.producer) = cpu_to_le32(index + 1);
  595. spin_unlock_irqrestore(q->lock, qflags);
  596. if (!(nointr & (int)aac_config.irq_mod))
  597. aac_adapter_notify(dev, AdapNormRespQueue);
  598. }
  599. else
  600. {
  601. printk(KERN_WARNING "fib_adapter_complete: Unknown xferstate detected.\n");
  602. BUG();
  603. }
  604. return 0;
  605. }
  606. /**
  607. * fib_complete - fib completion handler
  608. * @fib: FIB to complete
  609. *
  610. * Will do all necessary work to complete a FIB.
  611. */
  612. int fib_complete(struct fib * fibptr)
  613. {
  614. struct hw_fib * hw_fib = fibptr->hw_fib;
  615. /*
  616. * Check for a fib which has already been completed
  617. */
  618. if (hw_fib->header.XferState == 0)
  619. return 0;
  620. /*
  621. * If we plan to do anything check the structure type first.
  622. */
  623. if (hw_fib->header.StructType != FIB_MAGIC)
  624. return -EINVAL;
  625. /*
  626. * This block completes a cdb which orginated on the host and we
  627. * just need to deallocate the cdb or reinit it. At this point the
  628. * command is complete that we had sent to the adapter and this
  629. * cdb could be reused.
  630. */
  631. if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) &&
  632. (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed)))
  633. {
  634. fib_dealloc(fibptr);
  635. }
  636. else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost))
  637. {
  638. /*
  639. * This handles the case when the host has aborted the I/O
  640. * to the adapter because the adapter is not responding
  641. */
  642. fib_dealloc(fibptr);
  643. } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) {
  644. fib_dealloc(fibptr);
  645. } else {
  646. BUG();
  647. }
  648. return 0;
  649. }
  650. /**
  651. * aac_printf - handle printf from firmware
  652. * @dev: Adapter
  653. * @val: Message info
  654. *
  655. * Print a message passed to us by the controller firmware on the
  656. * Adaptec board
  657. */
  658. void aac_printf(struct aac_dev *dev, u32 val)
  659. {
  660. char *cp = dev->printfbuf;
  661. if (dev->printf_enabled)
  662. {
  663. int length = val & 0xffff;
  664. int level = (val >> 16) & 0xffff;
  665. /*
  666. * The size of the printfbuf is set in port.c
  667. * There is no variable or define for it
  668. */
  669. if (length > 255)
  670. length = 255;
  671. if (cp[length] != 0)
  672. cp[length] = 0;
  673. if (level == LOG_AAC_HIGH_ERROR)
  674. printk(KERN_WARNING "aacraid:%s", cp);
  675. else
  676. printk(KERN_INFO "aacraid:%s", cp);
  677. }
  678. memset(cp, 0, 256);
  679. }
  680. /**
  681. * aac_handle_aif - Handle a message from the firmware
  682. * @dev: Which adapter this fib is from
  683. * @fibptr: Pointer to fibptr from adapter
  684. *
  685. * This routine handles a driver notify fib from the adapter and
  686. * dispatches it to the appropriate routine for handling.
  687. */
  688. static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
  689. {
  690. struct hw_fib * hw_fib = fibptr->hw_fib;
  691. struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
  692. int busy;
  693. u32 container;
  694. struct scsi_device *device;
  695. enum {
  696. NOTHING,
  697. DELETE,
  698. ADD,
  699. CHANGE
  700. } device_config_needed;
  701. /* Sniff for container changes */
  702. if (!dev)
  703. return;
  704. container = (u32)-1;
  705. /*
  706. * We have set this up to try and minimize the number of
  707. * re-configures that take place. As a result of this when
  708. * certain AIF's come in we will set a flag waiting for another
  709. * type of AIF before setting the re-config flag.
  710. */
  711. switch (le32_to_cpu(aifcmd->command)) {
  712. case AifCmdDriverNotify:
  713. switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
  714. /*
  715. * Morph or Expand complete
  716. */
  717. case AifDenMorphComplete:
  718. case AifDenVolumeExtendComplete:
  719. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  720. if (container >= dev->maximum_num_containers)
  721. break;
  722. /*
  723. * Find the Scsi_Device associated with the SCSI
  724. * address. Make sure we have the right array, and if
  725. * so set the flag to initiate a new re-config once we
  726. * see an AifEnConfigChange AIF come through.
  727. */
  728. if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) {
  729. device = scsi_device_lookup(dev->scsi_host_ptr,
  730. CONTAINER_TO_CHANNEL(container),
  731. CONTAINER_TO_ID(container),
  732. CONTAINER_TO_LUN(container));
  733. if (device) {
  734. dev->fsa_dev[container].config_needed = CHANGE;
  735. dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
  736. scsi_device_put(device);
  737. }
  738. }
  739. }
  740. /*
  741. * If we are waiting on something and this happens to be
  742. * that thing then set the re-configure flag.
  743. */
  744. if (container != (u32)-1) {
  745. if (container >= dev->maximum_num_containers)
  746. break;
  747. if (dev->fsa_dev[container].config_waiting_on ==
  748. le32_to_cpu(*(u32 *)aifcmd->data))
  749. dev->fsa_dev[container].config_waiting_on = 0;
  750. } else for (container = 0;
  751. container < dev->maximum_num_containers; ++container) {
  752. if (dev->fsa_dev[container].config_waiting_on ==
  753. le32_to_cpu(*(u32 *)aifcmd->data))
  754. dev->fsa_dev[container].config_waiting_on = 0;
  755. }
  756. break;
  757. case AifCmdEventNotify:
  758. switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
  759. /*
  760. * Add an Array.
  761. */
  762. case AifEnAddContainer:
  763. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  764. if (container >= dev->maximum_num_containers)
  765. break;
  766. dev->fsa_dev[container].config_needed = ADD;
  767. dev->fsa_dev[container].config_waiting_on =
  768. AifEnConfigChange;
  769. break;
  770. /*
  771. * Delete an Array.
  772. */
  773. case AifEnDeleteContainer:
  774. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  775. if (container >= dev->maximum_num_containers)
  776. break;
  777. dev->fsa_dev[container].config_needed = DELETE;
  778. dev->fsa_dev[container].config_waiting_on =
  779. AifEnConfigChange;
  780. break;
  781. /*
  782. * Container change detected. If we currently are not
  783. * waiting on something else, setup to wait on a Config Change.
  784. */
  785. case AifEnContainerChange:
  786. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  787. if (container >= dev->maximum_num_containers)
  788. break;
  789. if (dev->fsa_dev[container].config_waiting_on)
  790. break;
  791. dev->fsa_dev[container].config_needed = CHANGE;
  792. dev->fsa_dev[container].config_waiting_on =
  793. AifEnConfigChange;
  794. break;
  795. case AifEnConfigChange:
  796. break;
  797. }
  798. /*
  799. * If we are waiting on something and this happens to be
  800. * that thing then set the re-configure flag.
  801. */
  802. if (container != (u32)-1) {
  803. if (container >= dev->maximum_num_containers)
  804. break;
  805. if (dev->fsa_dev[container].config_waiting_on ==
  806. le32_to_cpu(*(u32 *)aifcmd->data))
  807. dev->fsa_dev[container].config_waiting_on = 0;
  808. } else for (container = 0;
  809. container < dev->maximum_num_containers; ++container) {
  810. if (dev->fsa_dev[container].config_waiting_on ==
  811. le32_to_cpu(*(u32 *)aifcmd->data))
  812. dev->fsa_dev[container].config_waiting_on = 0;
  813. }
  814. break;
  815. case AifCmdJobProgress:
  816. /*
  817. * These are job progress AIF's. When a Clear is being
  818. * done on a container it is initially created then hidden from
  819. * the OS. When the clear completes we don't get a config
  820. * change so we monitor the job status complete on a clear then
  821. * wait for a container change.
  822. */
  823. if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
  824. && ((((u32 *)aifcmd->data)[6] == ((u32 *)aifcmd->data)[5])
  825. || (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess)))) {
  826. for (container = 0;
  827. container < dev->maximum_num_containers;
  828. ++container) {
  829. /*
  830. * Stomp on all config sequencing for all
  831. * containers?
  832. */
  833. dev->fsa_dev[container].config_waiting_on =
  834. AifEnContainerChange;
  835. dev->fsa_dev[container].config_needed = ADD;
  836. }
  837. }
  838. if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
  839. && (((u32 *)aifcmd->data)[6] == 0)
  840. && (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning))) {
  841. for (container = 0;
  842. container < dev->maximum_num_containers;
  843. ++container) {
  844. /*
  845. * Stomp on all config sequencing for all
  846. * containers?
  847. */
  848. dev->fsa_dev[container].config_waiting_on =
  849. AifEnContainerChange;
  850. dev->fsa_dev[container].config_needed = DELETE;
  851. }
  852. }
  853. break;
  854. }
  855. device_config_needed = NOTHING;
  856. for (container = 0; container < dev->maximum_num_containers;
  857. ++container) {
  858. if ((dev->fsa_dev[container].config_waiting_on == 0)
  859. && (dev->fsa_dev[container].config_needed != NOTHING)) {
  860. device_config_needed =
  861. dev->fsa_dev[container].config_needed;
  862. dev->fsa_dev[container].config_needed = NOTHING;
  863. break;
  864. }
  865. }
  866. if (device_config_needed == NOTHING)
  867. return;
  868. /*
  869. * If we decided that a re-configuration needs to be done,
  870. * schedule it here on the way out the door, please close the door
  871. * behind you.
  872. */
  873. busy = 0;
  874. /*
  875. * Find the Scsi_Device associated with the SCSI address,
  876. * and mark it as changed, invalidating the cache. This deals
  877. * with changes to existing device IDs.
  878. */
  879. if (!dev || !dev->scsi_host_ptr)
  880. return;
  881. /*
  882. * force reload of disk info via probe_container
  883. */
  884. if ((device_config_needed == CHANGE)
  885. && (dev->fsa_dev[container].valid == 1))
  886. dev->fsa_dev[container].valid = 2;
  887. if ((device_config_needed == CHANGE) ||
  888. (device_config_needed == ADD))
  889. probe_container(dev, container);
  890. device = scsi_device_lookup(dev->scsi_host_ptr,
  891. CONTAINER_TO_CHANNEL(container),
  892. CONTAINER_TO_ID(container),
  893. CONTAINER_TO_LUN(container));
  894. if (device) {
  895. switch (device_config_needed) {
  896. case DELETE:
  897. scsi_remove_device(device);
  898. break;
  899. case CHANGE:
  900. if (!dev->fsa_dev[container].valid) {
  901. scsi_remove_device(device);
  902. break;
  903. }
  904. scsi_rescan_device(&device->sdev_gendev);
  905. default:
  906. break;
  907. }
  908. scsi_device_put(device);
  909. }
  910. if (device_config_needed == ADD) {
  911. scsi_add_device(dev->scsi_host_ptr,
  912. CONTAINER_TO_CHANNEL(container),
  913. CONTAINER_TO_ID(container),
  914. CONTAINER_TO_LUN(container));
  915. }
  916. }
  917. /**
  918. * aac_command_thread - command processing thread
  919. * @dev: Adapter to monitor
  920. *
  921. * Waits on the commandready event in it's queue. When the event gets set
  922. * it will pull FIBs off it's queue. It will continue to pull FIBs off
  923. * until the queue is empty. When the queue is empty it will wait for
  924. * more FIBs.
  925. */
  926. int aac_command_thread(struct aac_dev * dev)
  927. {
  928. struct hw_fib *hw_fib, *hw_newfib;
  929. struct fib *fib, *newfib;
  930. struct aac_fib_context *fibctx;
  931. unsigned long flags;
  932. DECLARE_WAITQUEUE(wait, current);
  933. /*
  934. * We can only have one thread per adapter for AIF's.
  935. */
  936. if (dev->aif_thread)
  937. return -EINVAL;
  938. /*
  939. * Set up the name that will appear in 'ps'
  940. * stored in task_struct.comm[16].
  941. */
  942. daemonize("aacraid");
  943. allow_signal(SIGKILL);
  944. /*
  945. * Let the DPC know it has a place to send the AIF's to.
  946. */
  947. dev->aif_thread = 1;
  948. add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  949. set_current_state(TASK_INTERRUPTIBLE);
  950. dprintk ((KERN_INFO "aac_command_thread start\n"));
  951. while(1)
  952. {
  953. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  954. while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
  955. struct list_head *entry;
  956. struct aac_aifcmd * aifcmd;
  957. set_current_state(TASK_RUNNING);
  958. entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
  959. list_del(entry);
  960. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  961. fib = list_entry(entry, struct fib, fiblink);
  962. /*
  963. * We will process the FIB here or pass it to a
  964. * worker thread that is TBD. We Really can't
  965. * do anything at this point since we don't have
  966. * anything defined for this thread to do.
  967. */
  968. hw_fib = fib->hw_fib;
  969. memset(fib, 0, sizeof(struct fib));
  970. fib->type = FSAFS_NTC_FIB_CONTEXT;
  971. fib->size = sizeof( struct fib );
  972. fib->hw_fib = hw_fib;
  973. fib->data = hw_fib->data;
  974. fib->dev = dev;
  975. /*
  976. * We only handle AifRequest fibs from the adapter.
  977. */
  978. aifcmd = (struct aac_aifcmd *) hw_fib->data;
  979. if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
  980. /* Handle Driver Notify Events */
  981. aac_handle_aif(dev, fib);
  982. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  983. fib_adapter_complete(fib, (u16)sizeof(u32));
  984. } else {
  985. struct list_head *entry;
  986. /* The u32 here is important and intended. We are using
  987. 32bit wrapping time to fit the adapter field */
  988. u32 time_now, time_last;
  989. unsigned long flagv;
  990. unsigned num;
  991. struct hw_fib ** hw_fib_pool, ** hw_fib_p;
  992. struct fib ** fib_pool, ** fib_p;
  993. /* Sniff events */
  994. if ((aifcmd->command ==
  995. cpu_to_le32(AifCmdEventNotify)) ||
  996. (aifcmd->command ==
  997. cpu_to_le32(AifCmdJobProgress))) {
  998. aac_handle_aif(dev, fib);
  999. }
  1000. time_now = jiffies/HZ;
  1001. /*
  1002. * Warning: no sleep allowed while
  1003. * holding spinlock. We take the estimate
  1004. * and pre-allocate a set of fibs outside the
  1005. * lock.
  1006. */
  1007. num = le32_to_cpu(dev->init->AdapterFibsSize)
  1008. / sizeof(struct hw_fib); /* some extra */
  1009. spin_lock_irqsave(&dev->fib_lock, flagv);
  1010. entry = dev->fib_list.next;
  1011. while (entry != &dev->fib_list) {
  1012. entry = entry->next;
  1013. ++num;
  1014. }
  1015. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1016. hw_fib_pool = NULL;
  1017. fib_pool = NULL;
  1018. if (num
  1019. && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
  1020. && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
  1021. hw_fib_p = hw_fib_pool;
  1022. fib_p = fib_pool;
  1023. while (hw_fib_p < &hw_fib_pool[num]) {
  1024. if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
  1025. --hw_fib_p;
  1026. break;
  1027. }
  1028. if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
  1029. kfree(*(--hw_fib_p));
  1030. break;
  1031. }
  1032. }
  1033. if ((num = hw_fib_p - hw_fib_pool) == 0) {
  1034. kfree(fib_pool);
  1035. fib_pool = NULL;
  1036. kfree(hw_fib_pool);
  1037. hw_fib_pool = NULL;
  1038. }
  1039. } else if (hw_fib_pool) {
  1040. kfree(hw_fib_pool);
  1041. hw_fib_pool = NULL;
  1042. }
  1043. spin_lock_irqsave(&dev->fib_lock, flagv);
  1044. entry = dev->fib_list.next;
  1045. /*
  1046. * For each Context that is on the
  1047. * fibctxList, make a copy of the
  1048. * fib, and then set the event to wake up the
  1049. * thread that is waiting for it.
  1050. */
  1051. hw_fib_p = hw_fib_pool;
  1052. fib_p = fib_pool;
  1053. while (entry != &dev->fib_list) {
  1054. /*
  1055. * Extract the fibctx
  1056. */
  1057. fibctx = list_entry(entry, struct aac_fib_context, next);
  1058. /*
  1059. * Check if the queue is getting
  1060. * backlogged
  1061. */
  1062. if (fibctx->count > 20)
  1063. {
  1064. /*
  1065. * It's *not* jiffies folks,
  1066. * but jiffies / HZ so do not
  1067. * panic ...
  1068. */
  1069. time_last = fibctx->jiffies;
  1070. /*
  1071. * Has it been > 2 minutes
  1072. * since the last read off
  1073. * the queue?
  1074. */
  1075. if ((time_now - time_last) > 120) {
  1076. entry = entry->next;
  1077. aac_close_fib_context(dev, fibctx);
  1078. continue;
  1079. }
  1080. }
  1081. /*
  1082. * Warning: no sleep allowed while
  1083. * holding spinlock
  1084. */
  1085. if (hw_fib_p < &hw_fib_pool[num]) {
  1086. hw_newfib = *hw_fib_p;
  1087. *(hw_fib_p++) = NULL;
  1088. newfib = *fib_p;
  1089. *(fib_p++) = NULL;
  1090. /*
  1091. * Make the copy of the FIB
  1092. */
  1093. memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
  1094. memcpy(newfib, fib, sizeof(struct fib));
  1095. newfib->hw_fib = hw_newfib;
  1096. /*
  1097. * Put the FIB onto the
  1098. * fibctx's fibs
  1099. */
  1100. list_add_tail(&newfib->fiblink, &fibctx->fib_list);
  1101. fibctx->count++;
  1102. /*
  1103. * Set the event to wake up the
  1104. * thread that is waiting.
  1105. */
  1106. up(&fibctx->wait_sem);
  1107. } else {
  1108. printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
  1109. }
  1110. entry = entry->next;
  1111. }
  1112. /*
  1113. * Set the status of this FIB
  1114. */
  1115. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  1116. fib_adapter_complete(fib, sizeof(u32));
  1117. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1118. /* Free up the remaining resources */
  1119. hw_fib_p = hw_fib_pool;
  1120. fib_p = fib_pool;
  1121. while (hw_fib_p < &hw_fib_pool[num]) {
  1122. if (*hw_fib_p)
  1123. kfree(*hw_fib_p);
  1124. if (*fib_p)
  1125. kfree(*fib_p);
  1126. ++fib_p;
  1127. ++hw_fib_p;
  1128. }
  1129. if (hw_fib_pool)
  1130. kfree(hw_fib_pool);
  1131. if (fib_pool)
  1132. kfree(fib_pool);
  1133. }
  1134. kfree(fib);
  1135. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1136. }
  1137. /*
  1138. * There are no more AIF's
  1139. */
  1140. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1141. schedule();
  1142. if(signal_pending(current))
  1143. break;
  1144. set_current_state(TASK_INTERRUPTIBLE);
  1145. }
  1146. if (dev->queues)
  1147. remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  1148. dev->aif_thread = 0;
  1149. complete_and_exit(&dev->aif_completion, 0);
  1150. return 0;
  1151. }