commsup.c 36 KB

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