commsup.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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 = 0; /* Filled in later if needed */
  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. struct aac_dev * dev = fibptr->dev;
  349. struct hw_fib * hw_fib = fibptr->hw_fib;
  350. struct aac_queue * q;
  351. unsigned long flags = 0;
  352. unsigned long qflags;
  353. if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
  354. return -EBUSY;
  355. /*
  356. * There are 5 cases with the wait and reponse requested flags.
  357. * The only invalid cases are if the caller requests to wait and
  358. * does not request a response and if the caller does not want a
  359. * response and the Fib is not allocated from pool. If a response
  360. * is not requesed the Fib will just be deallocaed by the DPC
  361. * routine when the response comes back from the adapter. No
  362. * further processing will be done besides deleting the Fib. We
  363. * will have a debug mode where the adapter can notify the host
  364. * it had a problem and the host can log that fact.
  365. */
  366. if (wait && !reply) {
  367. return -EINVAL;
  368. } else if (!wait && reply) {
  369. hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected);
  370. FIB_COUNTER_INCREMENT(aac_config.AsyncSent);
  371. } else if (!wait && !reply) {
  372. hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected);
  373. FIB_COUNTER_INCREMENT(aac_config.NoResponseSent);
  374. } else if (wait && reply) {
  375. hw_fib->header.XferState |= cpu_to_le32(ResponseExpected);
  376. FIB_COUNTER_INCREMENT(aac_config.NormalSent);
  377. }
  378. /*
  379. * Map the fib into 32bits by using the fib number
  380. */
  381. hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
  382. hw_fib->header.SenderData = (u32)(fibptr - dev->fibs);
  383. /*
  384. * Set FIB state to indicate where it came from and if we want a
  385. * response from the adapter. Also load the command from the
  386. * caller.
  387. *
  388. * Map the hw fib pointer as a 32bit value
  389. */
  390. hw_fib->header.Command = cpu_to_le16(command);
  391. hw_fib->header.XferState |= cpu_to_le32(SentFromHost);
  392. fibptr->hw_fib->header.Flags = 0; /* 0 the flags field - internal only*/
  393. /*
  394. * Set the size of the Fib we want to send to the adapter
  395. */
  396. hw_fib->header.Size = cpu_to_le16(sizeof(struct aac_fibhdr) + size);
  397. if (le16_to_cpu(hw_fib->header.Size) > le16_to_cpu(hw_fib->header.SenderSize)) {
  398. return -EMSGSIZE;
  399. }
  400. /*
  401. * Get a queue entry connect the FIB to it and send an notify
  402. * the adapter a command is ready.
  403. */
  404. hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
  405. /*
  406. * Fill in the Callback and CallbackContext if we are not
  407. * going to wait.
  408. */
  409. if (!wait) {
  410. fibptr->callback = callback;
  411. fibptr->callback_data = callback_data;
  412. }
  413. fibptr->done = 0;
  414. fibptr->flags = 0;
  415. FIB_COUNTER_INCREMENT(aac_config.FibsSent);
  416. dprintk((KERN_DEBUG "Fib contents:.\n"));
  417. dprintk((KERN_DEBUG " Command = %d.\n", le32_to_cpu(hw_fib->header.Command)));
  418. dprintk((KERN_DEBUG " SubCommand = %d.\n", le32_to_cpu(((struct aac_query_mount *)fib_data(fibptr))->command)));
  419. dprintk((KERN_DEBUG " XferState = %x.\n", le32_to_cpu(hw_fib->header.XferState)));
  420. dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib));
  421. dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
  422. dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr));
  423. q = &dev->queues->queue[AdapNormCmdQueue];
  424. if(wait)
  425. spin_lock_irqsave(&fibptr->event_lock, flags);
  426. spin_lock_irqsave(q->lock, qflags);
  427. if (dev->new_comm_interface) {
  428. unsigned long count = 10000000L; /* 50 seconds */
  429. list_add_tail(&fibptr->queue, &q->pendingq);
  430. q->numpending++;
  431. spin_unlock_irqrestore(q->lock, qflags);
  432. while (aac_adapter_send(fibptr) != 0) {
  433. if (--count == 0) {
  434. if (wait)
  435. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  436. spin_lock_irqsave(q->lock, qflags);
  437. q->numpending--;
  438. list_del(&fibptr->queue);
  439. spin_unlock_irqrestore(q->lock, qflags);
  440. return -ETIMEDOUT;
  441. }
  442. udelay(5);
  443. }
  444. } else {
  445. u32 index;
  446. unsigned long nointr = 0;
  447. aac_queue_get( dev, &index, AdapNormCmdQueue, hw_fib, 1, fibptr, &nointr);
  448. list_add_tail(&fibptr->queue, &q->pendingq);
  449. q->numpending++;
  450. *(q->headers.producer) = cpu_to_le32(index + 1);
  451. spin_unlock_irqrestore(q->lock, qflags);
  452. dprintk((KERN_DEBUG "fib_send: inserting a queue entry at index %d.\n",index));
  453. if (!(nointr & aac_config.irq_mod))
  454. aac_adapter_notify(dev, AdapNormCmdQueue);
  455. }
  456. /*
  457. * If the caller wanted us to wait for response wait now.
  458. */
  459. if (wait) {
  460. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  461. /* Only set for first known interruptable command */
  462. if (wait < 0) {
  463. /*
  464. * *VERY* Dangerous to time out a command, the
  465. * assumption is made that we have no hope of
  466. * functioning because an interrupt routing or other
  467. * hardware failure has occurred.
  468. */
  469. unsigned long count = 36000000L; /* 3 minutes */
  470. while (down_trylock(&fibptr->event_wait)) {
  471. if (--count == 0) {
  472. spin_lock_irqsave(q->lock, qflags);
  473. q->numpending--;
  474. list_del(&fibptr->queue);
  475. spin_unlock_irqrestore(q->lock, qflags);
  476. if (wait == -1) {
  477. printk(KERN_ERR "aacraid: fib_send: first asynchronous command timed out.\n"
  478. "Usually a result of a PCI interrupt routing problem;\n"
  479. "update mother board BIOS or consider utilizing one of\n"
  480. "the SAFE mode kernel options (acpi, apic etc)\n");
  481. }
  482. return -ETIMEDOUT;
  483. }
  484. udelay(5);
  485. }
  486. } else
  487. down(&fibptr->event_wait);
  488. if(fibptr->done == 0)
  489. BUG();
  490. if((fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT)){
  491. return -ETIMEDOUT;
  492. } else {
  493. return 0;
  494. }
  495. }
  496. /*
  497. * If the user does not want a response than return success otherwise
  498. * return pending
  499. */
  500. if (reply)
  501. return -EINPROGRESS;
  502. else
  503. return 0;
  504. }
  505. /**
  506. * aac_consumer_get - get the top of the queue
  507. * @dev: Adapter
  508. * @q: Queue
  509. * @entry: Return entry
  510. *
  511. * Will return a pointer to the entry on the top of the queue requested that
  512. * we are a consumer of, and return the address of the queue entry. It does
  513. * not change the state of the queue.
  514. */
  515. int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry)
  516. {
  517. u32 index;
  518. int status;
  519. if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) {
  520. status = 0;
  521. } else {
  522. /*
  523. * The consumer index must be wrapped if we have reached
  524. * the end of the queue, else we just use the entry
  525. * pointed to by the header index
  526. */
  527. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  528. index = 0;
  529. else
  530. index = le32_to_cpu(*q->headers.consumer);
  531. *entry = q->base + index;
  532. status = 1;
  533. }
  534. return(status);
  535. }
  536. /**
  537. * aac_consumer_free - free consumer entry
  538. * @dev: Adapter
  539. * @q: Queue
  540. * @qid: Queue ident
  541. *
  542. * Frees up the current top of the queue we are a consumer of. If the
  543. * queue was full notify the producer that the queue is no longer full.
  544. */
  545. void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid)
  546. {
  547. int wasfull = 0;
  548. u32 notify;
  549. if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer))
  550. wasfull = 1;
  551. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  552. *q->headers.consumer = cpu_to_le32(1);
  553. else
  554. *q->headers.consumer = cpu_to_le32(le32_to_cpu(*q->headers.consumer)+1);
  555. if (wasfull) {
  556. switch (qid) {
  557. case HostNormCmdQueue:
  558. notify = HostNormCmdNotFull;
  559. break;
  560. case HostNormRespQueue:
  561. notify = HostNormRespNotFull;
  562. break;
  563. default:
  564. BUG();
  565. return;
  566. }
  567. aac_adapter_notify(dev, notify);
  568. }
  569. }
  570. /**
  571. * fib_adapter_complete - complete adapter issued fib
  572. * @fibptr: fib to complete
  573. * @size: size of fib
  574. *
  575. * Will do all necessary work to complete a FIB that was sent from
  576. * the adapter.
  577. */
  578. int fib_adapter_complete(struct fib * fibptr, unsigned short size)
  579. {
  580. struct hw_fib * hw_fib = fibptr->hw_fib;
  581. struct aac_dev * dev = fibptr->dev;
  582. struct aac_queue * q;
  583. unsigned long nointr = 0;
  584. unsigned long qflags;
  585. if (hw_fib->header.XferState == 0) {
  586. if (dev->new_comm_interface)
  587. kfree (hw_fib);
  588. return 0;
  589. }
  590. /*
  591. * If we plan to do anything check the structure type first.
  592. */
  593. if ( hw_fib->header.StructType != FIB_MAGIC ) {
  594. if (dev->new_comm_interface)
  595. kfree (hw_fib);
  596. return -EINVAL;
  597. }
  598. /*
  599. * This block handles the case where the adapter had sent us a
  600. * command and we have finished processing the command. We
  601. * call completeFib when we are done processing the command
  602. * and want to send a response back to the adapter. This will
  603. * send the completed cdb to the adapter.
  604. */
  605. if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
  606. if (dev->new_comm_interface) {
  607. kfree (hw_fib);
  608. } else {
  609. u32 index;
  610. hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
  611. if (size) {
  612. size += sizeof(struct aac_fibhdr);
  613. if (size > le16_to_cpu(hw_fib->header.SenderSize))
  614. return -EMSGSIZE;
  615. hw_fib->header.Size = cpu_to_le16(size);
  616. }
  617. q = &dev->queues->queue[AdapNormRespQueue];
  618. spin_lock_irqsave(q->lock, qflags);
  619. aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr);
  620. *(q->headers.producer) = cpu_to_le32(index + 1);
  621. spin_unlock_irqrestore(q->lock, qflags);
  622. if (!(nointr & (int)aac_config.irq_mod))
  623. aac_adapter_notify(dev, AdapNormRespQueue);
  624. }
  625. }
  626. else
  627. {
  628. printk(KERN_WARNING "fib_adapter_complete: Unknown xferstate detected.\n");
  629. BUG();
  630. }
  631. return 0;
  632. }
  633. /**
  634. * fib_complete - fib completion handler
  635. * @fib: FIB to complete
  636. *
  637. * Will do all necessary work to complete a FIB.
  638. */
  639. int fib_complete(struct fib * fibptr)
  640. {
  641. struct hw_fib * hw_fib = fibptr->hw_fib;
  642. /*
  643. * Check for a fib which has already been completed
  644. */
  645. if (hw_fib->header.XferState == 0)
  646. return 0;
  647. /*
  648. * If we plan to do anything check the structure type first.
  649. */
  650. if (hw_fib->header.StructType != FIB_MAGIC)
  651. return -EINVAL;
  652. /*
  653. * This block completes a cdb which orginated on the host and we
  654. * just need to deallocate the cdb or reinit it. At this point the
  655. * command is complete that we had sent to the adapter and this
  656. * cdb could be reused.
  657. */
  658. if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) &&
  659. (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed)))
  660. {
  661. fib_dealloc(fibptr);
  662. }
  663. else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost))
  664. {
  665. /*
  666. * This handles the case when the host has aborted the I/O
  667. * to the adapter because the adapter is not responding
  668. */
  669. fib_dealloc(fibptr);
  670. } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) {
  671. fib_dealloc(fibptr);
  672. } else {
  673. BUG();
  674. }
  675. return 0;
  676. }
  677. /**
  678. * aac_printf - handle printf from firmware
  679. * @dev: Adapter
  680. * @val: Message info
  681. *
  682. * Print a message passed to us by the controller firmware on the
  683. * Adaptec board
  684. */
  685. void aac_printf(struct aac_dev *dev, u32 val)
  686. {
  687. char *cp = dev->printfbuf;
  688. if (dev->printf_enabled)
  689. {
  690. int length = val & 0xffff;
  691. int level = (val >> 16) & 0xffff;
  692. /*
  693. * The size of the printfbuf is set in port.c
  694. * There is no variable or define for it
  695. */
  696. if (length > 255)
  697. length = 255;
  698. if (cp[length] != 0)
  699. cp[length] = 0;
  700. if (level == LOG_AAC_HIGH_ERROR)
  701. printk(KERN_WARNING "aacraid:%s", cp);
  702. else
  703. printk(KERN_INFO "aacraid:%s", cp);
  704. }
  705. memset(cp, 0, 256);
  706. }
  707. /**
  708. * aac_handle_aif - Handle a message from the firmware
  709. * @dev: Which adapter this fib is from
  710. * @fibptr: Pointer to fibptr from adapter
  711. *
  712. * This routine handles a driver notify fib from the adapter and
  713. * dispatches it to the appropriate routine for handling.
  714. */
  715. static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
  716. {
  717. struct hw_fib * hw_fib = fibptr->hw_fib;
  718. struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
  719. int busy;
  720. u32 container;
  721. struct scsi_device *device;
  722. enum {
  723. NOTHING,
  724. DELETE,
  725. ADD,
  726. CHANGE
  727. } device_config_needed;
  728. /* Sniff for container changes */
  729. if (!dev)
  730. return;
  731. container = (u32)-1;
  732. /*
  733. * We have set this up to try and minimize the number of
  734. * re-configures that take place. As a result of this when
  735. * certain AIF's come in we will set a flag waiting for another
  736. * type of AIF before setting the re-config flag.
  737. */
  738. switch (le32_to_cpu(aifcmd->command)) {
  739. case AifCmdDriverNotify:
  740. switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
  741. /*
  742. * Morph or Expand complete
  743. */
  744. case AifDenMorphComplete:
  745. case AifDenVolumeExtendComplete:
  746. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  747. if (container >= dev->maximum_num_containers)
  748. break;
  749. /*
  750. * Find the scsi_device associated with the SCSI
  751. * address. Make sure we have the right array, and if
  752. * so set the flag to initiate a new re-config once we
  753. * see an AifEnConfigChange AIF come through.
  754. */
  755. if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) {
  756. device = scsi_device_lookup(dev->scsi_host_ptr,
  757. CONTAINER_TO_CHANNEL(container),
  758. CONTAINER_TO_ID(container),
  759. CONTAINER_TO_LUN(container));
  760. if (device) {
  761. dev->fsa_dev[container].config_needed = CHANGE;
  762. dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
  763. scsi_device_put(device);
  764. }
  765. }
  766. }
  767. /*
  768. * If we are waiting on something and this happens to be
  769. * that thing then set the re-configure flag.
  770. */
  771. if (container != (u32)-1) {
  772. if (container >= dev->maximum_num_containers)
  773. break;
  774. if (dev->fsa_dev[container].config_waiting_on ==
  775. le32_to_cpu(*(u32 *)aifcmd->data))
  776. dev->fsa_dev[container].config_waiting_on = 0;
  777. } else for (container = 0;
  778. container < dev->maximum_num_containers; ++container) {
  779. if (dev->fsa_dev[container].config_waiting_on ==
  780. le32_to_cpu(*(u32 *)aifcmd->data))
  781. dev->fsa_dev[container].config_waiting_on = 0;
  782. }
  783. break;
  784. case AifCmdEventNotify:
  785. switch (le32_to_cpu(((u32 *)aifcmd->data)[0])) {
  786. /*
  787. * Add an Array.
  788. */
  789. case AifEnAddContainer:
  790. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  791. if (container >= dev->maximum_num_containers)
  792. break;
  793. dev->fsa_dev[container].config_needed = ADD;
  794. dev->fsa_dev[container].config_waiting_on =
  795. AifEnConfigChange;
  796. break;
  797. /*
  798. * Delete an Array.
  799. */
  800. case AifEnDeleteContainer:
  801. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  802. if (container >= dev->maximum_num_containers)
  803. break;
  804. dev->fsa_dev[container].config_needed = DELETE;
  805. dev->fsa_dev[container].config_waiting_on =
  806. AifEnConfigChange;
  807. break;
  808. /*
  809. * Container change detected. If we currently are not
  810. * waiting on something else, setup to wait on a Config Change.
  811. */
  812. case AifEnContainerChange:
  813. container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
  814. if (container >= dev->maximum_num_containers)
  815. break;
  816. if (dev->fsa_dev[container].config_waiting_on)
  817. break;
  818. dev->fsa_dev[container].config_needed = CHANGE;
  819. dev->fsa_dev[container].config_waiting_on =
  820. AifEnConfigChange;
  821. break;
  822. case AifEnConfigChange:
  823. break;
  824. }
  825. /*
  826. * If we are waiting on something and this happens to be
  827. * that thing then set the re-configure flag.
  828. */
  829. if (container != (u32)-1) {
  830. if (container >= dev->maximum_num_containers)
  831. break;
  832. if (dev->fsa_dev[container].config_waiting_on ==
  833. le32_to_cpu(*(u32 *)aifcmd->data))
  834. dev->fsa_dev[container].config_waiting_on = 0;
  835. } else for (container = 0;
  836. container < dev->maximum_num_containers; ++container) {
  837. if (dev->fsa_dev[container].config_waiting_on ==
  838. le32_to_cpu(*(u32 *)aifcmd->data))
  839. dev->fsa_dev[container].config_waiting_on = 0;
  840. }
  841. break;
  842. case AifCmdJobProgress:
  843. /*
  844. * These are job progress AIF's. When a Clear is being
  845. * done on a container it is initially created then hidden from
  846. * the OS. When the clear completes we don't get a config
  847. * change so we monitor the job status complete on a clear then
  848. * wait for a container change.
  849. */
  850. if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
  851. && ((((u32 *)aifcmd->data)[6] == ((u32 *)aifcmd->data)[5])
  852. || (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess)))) {
  853. for (container = 0;
  854. container < dev->maximum_num_containers;
  855. ++container) {
  856. /*
  857. * Stomp on all config sequencing for all
  858. * containers?
  859. */
  860. dev->fsa_dev[container].config_waiting_on =
  861. AifEnContainerChange;
  862. dev->fsa_dev[container].config_needed = ADD;
  863. }
  864. }
  865. if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
  866. && (((u32 *)aifcmd->data)[6] == 0)
  867. && (((u32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning))) {
  868. for (container = 0;
  869. container < dev->maximum_num_containers;
  870. ++container) {
  871. /*
  872. * Stomp on all config sequencing for all
  873. * containers?
  874. */
  875. dev->fsa_dev[container].config_waiting_on =
  876. AifEnContainerChange;
  877. dev->fsa_dev[container].config_needed = DELETE;
  878. }
  879. }
  880. break;
  881. }
  882. device_config_needed = NOTHING;
  883. for (container = 0; container < dev->maximum_num_containers;
  884. ++container) {
  885. if ((dev->fsa_dev[container].config_waiting_on == 0)
  886. && (dev->fsa_dev[container].config_needed != NOTHING)) {
  887. device_config_needed =
  888. dev->fsa_dev[container].config_needed;
  889. dev->fsa_dev[container].config_needed = NOTHING;
  890. break;
  891. }
  892. }
  893. if (device_config_needed == NOTHING)
  894. return;
  895. /*
  896. * If we decided that a re-configuration needs to be done,
  897. * schedule it here on the way out the door, please close the door
  898. * behind you.
  899. */
  900. busy = 0;
  901. /*
  902. * Find the scsi_device associated with the SCSI address,
  903. * and mark it as changed, invalidating the cache. This deals
  904. * with changes to existing device IDs.
  905. */
  906. if (!dev || !dev->scsi_host_ptr)
  907. return;
  908. /*
  909. * force reload of disk info via probe_container
  910. */
  911. if ((device_config_needed == CHANGE)
  912. && (dev->fsa_dev[container].valid == 1))
  913. dev->fsa_dev[container].valid = 2;
  914. if ((device_config_needed == CHANGE) ||
  915. (device_config_needed == ADD))
  916. probe_container(dev, container);
  917. device = scsi_device_lookup(dev->scsi_host_ptr,
  918. CONTAINER_TO_CHANNEL(container),
  919. CONTAINER_TO_ID(container),
  920. CONTAINER_TO_LUN(container));
  921. if (device) {
  922. switch (device_config_needed) {
  923. case DELETE:
  924. scsi_remove_device(device);
  925. break;
  926. case CHANGE:
  927. if (!dev->fsa_dev[container].valid) {
  928. scsi_remove_device(device);
  929. break;
  930. }
  931. scsi_rescan_device(&device->sdev_gendev);
  932. default:
  933. break;
  934. }
  935. scsi_device_put(device);
  936. }
  937. if (device_config_needed == ADD) {
  938. scsi_add_device(dev->scsi_host_ptr,
  939. CONTAINER_TO_CHANNEL(container),
  940. CONTAINER_TO_ID(container),
  941. CONTAINER_TO_LUN(container));
  942. }
  943. }
  944. /**
  945. * aac_command_thread - command processing thread
  946. * @dev: Adapter to monitor
  947. *
  948. * Waits on the commandready event in it's queue. When the event gets set
  949. * it will pull FIBs off it's queue. It will continue to pull FIBs off
  950. * until the queue is empty. When the queue is empty it will wait for
  951. * more FIBs.
  952. */
  953. int aac_command_thread(struct aac_dev * dev)
  954. {
  955. struct hw_fib *hw_fib, *hw_newfib;
  956. struct fib *fib, *newfib;
  957. struct aac_fib_context *fibctx;
  958. unsigned long flags;
  959. DECLARE_WAITQUEUE(wait, current);
  960. /*
  961. * We can only have one thread per adapter for AIF's.
  962. */
  963. if (dev->aif_thread)
  964. return -EINVAL;
  965. /*
  966. * Set up the name that will appear in 'ps'
  967. * stored in task_struct.comm[16].
  968. */
  969. daemonize("aacraid");
  970. allow_signal(SIGKILL);
  971. /*
  972. * Let the DPC know it has a place to send the AIF's to.
  973. */
  974. dev->aif_thread = 1;
  975. add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  976. set_current_state(TASK_INTERRUPTIBLE);
  977. dprintk ((KERN_INFO "aac_command_thread start\n"));
  978. while(1)
  979. {
  980. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  981. while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
  982. struct list_head *entry;
  983. struct aac_aifcmd * aifcmd;
  984. set_current_state(TASK_RUNNING);
  985. entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
  986. list_del(entry);
  987. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  988. fib = list_entry(entry, struct fib, fiblink);
  989. /*
  990. * We will process the FIB here or pass it to a
  991. * worker thread that is TBD. We Really can't
  992. * do anything at this point since we don't have
  993. * anything defined for this thread to do.
  994. */
  995. hw_fib = fib->hw_fib;
  996. memset(fib, 0, sizeof(struct fib));
  997. fib->type = FSAFS_NTC_FIB_CONTEXT;
  998. fib->size = sizeof( struct fib );
  999. fib->hw_fib = hw_fib;
  1000. fib->data = hw_fib->data;
  1001. fib->dev = dev;
  1002. /*
  1003. * We only handle AifRequest fibs from the adapter.
  1004. */
  1005. aifcmd = (struct aac_aifcmd *) hw_fib->data;
  1006. if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
  1007. /* Handle Driver Notify Events */
  1008. aac_handle_aif(dev, fib);
  1009. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  1010. fib_adapter_complete(fib, (u16)sizeof(u32));
  1011. } else {
  1012. struct list_head *entry;
  1013. /* The u32 here is important and intended. We are using
  1014. 32bit wrapping time to fit the adapter field */
  1015. u32 time_now, time_last;
  1016. unsigned long flagv;
  1017. unsigned num;
  1018. struct hw_fib ** hw_fib_pool, ** hw_fib_p;
  1019. struct fib ** fib_pool, ** fib_p;
  1020. /* Sniff events */
  1021. if ((aifcmd->command ==
  1022. cpu_to_le32(AifCmdEventNotify)) ||
  1023. (aifcmd->command ==
  1024. cpu_to_le32(AifCmdJobProgress))) {
  1025. aac_handle_aif(dev, fib);
  1026. }
  1027. time_now = jiffies/HZ;
  1028. /*
  1029. * Warning: no sleep allowed while
  1030. * holding spinlock. We take the estimate
  1031. * and pre-allocate a set of fibs outside the
  1032. * lock.
  1033. */
  1034. num = le32_to_cpu(dev->init->AdapterFibsSize)
  1035. / sizeof(struct hw_fib); /* some extra */
  1036. spin_lock_irqsave(&dev->fib_lock, flagv);
  1037. entry = dev->fib_list.next;
  1038. while (entry != &dev->fib_list) {
  1039. entry = entry->next;
  1040. ++num;
  1041. }
  1042. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1043. hw_fib_pool = NULL;
  1044. fib_pool = NULL;
  1045. if (num
  1046. && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
  1047. && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
  1048. hw_fib_p = hw_fib_pool;
  1049. fib_p = fib_pool;
  1050. while (hw_fib_p < &hw_fib_pool[num]) {
  1051. if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
  1052. --hw_fib_p;
  1053. break;
  1054. }
  1055. if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
  1056. kfree(*(--hw_fib_p));
  1057. break;
  1058. }
  1059. }
  1060. if ((num = hw_fib_p - hw_fib_pool) == 0) {
  1061. kfree(fib_pool);
  1062. fib_pool = NULL;
  1063. kfree(hw_fib_pool);
  1064. hw_fib_pool = NULL;
  1065. }
  1066. } else {
  1067. kfree(hw_fib_pool);
  1068. hw_fib_pool = NULL;
  1069. }
  1070. spin_lock_irqsave(&dev->fib_lock, flagv);
  1071. entry = dev->fib_list.next;
  1072. /*
  1073. * For each Context that is on the
  1074. * fibctxList, make a copy of the
  1075. * fib, and then set the event to wake up the
  1076. * thread that is waiting for it.
  1077. */
  1078. hw_fib_p = hw_fib_pool;
  1079. fib_p = fib_pool;
  1080. while (entry != &dev->fib_list) {
  1081. /*
  1082. * Extract the fibctx
  1083. */
  1084. fibctx = list_entry(entry, struct aac_fib_context, next);
  1085. /*
  1086. * Check if the queue is getting
  1087. * backlogged
  1088. */
  1089. if (fibctx->count > 20)
  1090. {
  1091. /*
  1092. * It's *not* jiffies folks,
  1093. * but jiffies / HZ so do not
  1094. * panic ...
  1095. */
  1096. time_last = fibctx->jiffies;
  1097. /*
  1098. * Has it been > 2 minutes
  1099. * since the last read off
  1100. * the queue?
  1101. */
  1102. if ((time_now - time_last) > 120) {
  1103. entry = entry->next;
  1104. aac_close_fib_context(dev, fibctx);
  1105. continue;
  1106. }
  1107. }
  1108. /*
  1109. * Warning: no sleep allowed while
  1110. * holding spinlock
  1111. */
  1112. if (hw_fib_p < &hw_fib_pool[num]) {
  1113. hw_newfib = *hw_fib_p;
  1114. *(hw_fib_p++) = NULL;
  1115. newfib = *fib_p;
  1116. *(fib_p++) = NULL;
  1117. /*
  1118. * Make the copy of the FIB
  1119. */
  1120. memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
  1121. memcpy(newfib, fib, sizeof(struct fib));
  1122. newfib->hw_fib = hw_newfib;
  1123. /*
  1124. * Put the FIB onto the
  1125. * fibctx's fibs
  1126. */
  1127. list_add_tail(&newfib->fiblink, &fibctx->fib_list);
  1128. fibctx->count++;
  1129. /*
  1130. * Set the event to wake up the
  1131. * thread that is waiting.
  1132. */
  1133. up(&fibctx->wait_sem);
  1134. } else {
  1135. printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
  1136. }
  1137. entry = entry->next;
  1138. }
  1139. /*
  1140. * Set the status of this FIB
  1141. */
  1142. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  1143. fib_adapter_complete(fib, sizeof(u32));
  1144. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1145. /* Free up the remaining resources */
  1146. hw_fib_p = hw_fib_pool;
  1147. fib_p = fib_pool;
  1148. while (hw_fib_p < &hw_fib_pool[num]) {
  1149. kfree(*hw_fib_p);
  1150. kfree(*fib_p);
  1151. ++fib_p;
  1152. ++hw_fib_p;
  1153. }
  1154. kfree(hw_fib_pool);
  1155. kfree(fib_pool);
  1156. }
  1157. kfree(fib);
  1158. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1159. }
  1160. /*
  1161. * There are no more AIF's
  1162. */
  1163. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1164. schedule();
  1165. if(signal_pending(current))
  1166. break;
  1167. set_current_state(TASK_INTERRUPTIBLE);
  1168. }
  1169. if (dev->queues)
  1170. remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  1171. dev->aif_thread = 0;
  1172. complete_and_exit(&dev->aif_completion, 0);
  1173. return 0;
  1174. }