commsup.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  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-2007 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 <linux/delay.h>
  41. #include <linux/kthread.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/semaphore.h>
  44. #include <scsi/scsi.h>
  45. #include <scsi/scsi_host.h>
  46. #include <scsi/scsi_device.h>
  47. #include <scsi/scsi_cmnd.h>
  48. #include "aacraid.h"
  49. /**
  50. * fib_map_alloc - allocate the fib objects
  51. * @dev: Adapter to allocate for
  52. *
  53. * Allocate and map the shared PCI space for the FIB blocks used to
  54. * talk to the Adaptec firmware.
  55. */
  56. static int fib_map_alloc(struct aac_dev *dev)
  57. {
  58. dprintk((KERN_INFO
  59. "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
  60. dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue,
  61. AAC_NUM_MGT_FIB, &dev->hw_fib_pa));
  62. if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, dev->max_fib_size
  63. * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
  64. &dev->hw_fib_pa))==NULL)
  65. return -ENOMEM;
  66. return 0;
  67. }
  68. /**
  69. * aac_fib_map_free - free the fib objects
  70. * @dev: Adapter to free
  71. *
  72. * Free the PCI mappings and the memory allocated for FIB blocks
  73. * on this adapter.
  74. */
  75. void aac_fib_map_free(struct aac_dev *dev)
  76. {
  77. pci_free_consistent(dev->pdev,
  78. dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),
  79. dev->hw_fib_va, dev->hw_fib_pa);
  80. dev->hw_fib_va = NULL;
  81. dev->hw_fib_pa = 0;
  82. }
  83. /**
  84. * aac_fib_setup - setup the fibs
  85. * @dev: Adapter to set up
  86. *
  87. * Allocate the PCI space for the fibs, map it and then intialise the
  88. * fib area, the unmapped fib data and also the free list
  89. */
  90. int aac_fib_setup(struct aac_dev * dev)
  91. {
  92. struct fib *fibptr;
  93. struct hw_fib *hw_fib;
  94. dma_addr_t hw_fib_pa;
  95. int i;
  96. while (((i = fib_map_alloc(dev)) == -ENOMEM)
  97. && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {
  98. dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1);
  99. dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB;
  100. }
  101. if (i<0)
  102. return -ENOMEM;
  103. hw_fib = dev->hw_fib_va;
  104. hw_fib_pa = dev->hw_fib_pa;
  105. memset(hw_fib, 0, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
  106. /*
  107. * Initialise the fibs
  108. */
  109. for (i = 0, fibptr = &dev->fibs[i];
  110. i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
  111. i++, fibptr++)
  112. {
  113. fibptr->dev = dev;
  114. fibptr->hw_fib_va = hw_fib;
  115. fibptr->data = (void *) fibptr->hw_fib_va->data;
  116. fibptr->next = fibptr+1; /* Forward chain the fibs */
  117. init_MUTEX_LOCKED(&fibptr->event_wait);
  118. spin_lock_init(&fibptr->event_lock);
  119. hw_fib->header.XferState = cpu_to_le32(0xffffffff);
  120. hw_fib->header.SenderSize = cpu_to_le16(dev->max_fib_size);
  121. fibptr->hw_fib_pa = hw_fib_pa;
  122. hw_fib = (struct hw_fib *)((unsigned char *)hw_fib + dev->max_fib_size);
  123. hw_fib_pa = hw_fib_pa + dev->max_fib_size;
  124. }
  125. /*
  126. * Add the fib chain to the free list
  127. */
  128. dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;
  129. /*
  130. * Enable this to debug out of queue space
  131. */
  132. dev->free_fib = &dev->fibs[0];
  133. return 0;
  134. }
  135. /**
  136. * aac_fib_alloc - allocate a fib
  137. * @dev: Adapter to allocate the fib for
  138. *
  139. * Allocate a fib from the adapter fib pool. If the pool is empty we
  140. * return NULL.
  141. */
  142. struct fib *aac_fib_alloc(struct aac_dev *dev)
  143. {
  144. struct fib * fibptr;
  145. unsigned long flags;
  146. spin_lock_irqsave(&dev->fib_lock, flags);
  147. fibptr = dev->free_fib;
  148. if(!fibptr){
  149. spin_unlock_irqrestore(&dev->fib_lock, flags);
  150. return fibptr;
  151. }
  152. dev->free_fib = fibptr->next;
  153. spin_unlock_irqrestore(&dev->fib_lock, flags);
  154. /*
  155. * Set the proper node type code and node byte size
  156. */
  157. fibptr->type = FSAFS_NTC_FIB_CONTEXT;
  158. fibptr->size = sizeof(struct fib);
  159. /*
  160. * Null out fields that depend on being zero at the start of
  161. * each I/O
  162. */
  163. fibptr->hw_fib_va->header.XferState = 0;
  164. fibptr->flags = 0;
  165. fibptr->callback = NULL;
  166. fibptr->callback_data = NULL;
  167. return fibptr;
  168. }
  169. /**
  170. * aac_fib_free - free a fib
  171. * @fibptr: fib to free up
  172. *
  173. * Frees up a fib and places it on the appropriate queue
  174. */
  175. void aac_fib_free(struct fib *fibptr)
  176. {
  177. unsigned long flags;
  178. spin_lock_irqsave(&fibptr->dev->fib_lock, flags);
  179. if (unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
  180. aac_config.fib_timeouts++;
  181. if (fibptr->hw_fib_va->header.XferState != 0) {
  182. printk(KERN_WARNING "aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
  183. (void*)fibptr,
  184. le32_to_cpu(fibptr->hw_fib_va->header.XferState));
  185. }
  186. fibptr->next = fibptr->dev->free_fib;
  187. fibptr->dev->free_fib = fibptr;
  188. spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags);
  189. }
  190. /**
  191. * aac_fib_init - initialise a fib
  192. * @fibptr: The fib to initialize
  193. *
  194. * Set up the generic fib fields ready for use
  195. */
  196. void aac_fib_init(struct fib *fibptr)
  197. {
  198. struct hw_fib *hw_fib = fibptr->hw_fib_va;
  199. hw_fib->header.StructType = FIB_MAGIC;
  200. hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);
  201. hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);
  202. hw_fib->header.SenderFibAddress = 0; /* Filled in later if needed */
  203. hw_fib->header.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);
  204. hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);
  205. }
  206. /**
  207. * fib_deallocate - deallocate a fib
  208. * @fibptr: fib to deallocate
  209. *
  210. * Will deallocate and return to the free pool the FIB pointed to by the
  211. * caller.
  212. */
  213. static void fib_dealloc(struct fib * fibptr)
  214. {
  215. struct hw_fib *hw_fib = fibptr->hw_fib_va;
  216. BUG_ON(hw_fib->header.StructType != FIB_MAGIC);
  217. hw_fib->header.XferState = 0;
  218. }
  219. /*
  220. * Commuication primitives define and support the queuing method we use to
  221. * support host to adapter commuication. All queue accesses happen through
  222. * these routines and are the only routines which have a knowledge of the
  223. * how these queues are implemented.
  224. */
  225. /**
  226. * aac_get_entry - get a queue entry
  227. * @dev: Adapter
  228. * @qid: Queue Number
  229. * @entry: Entry return
  230. * @index: Index return
  231. * @nonotify: notification control
  232. *
  233. * With a priority the routine returns a queue entry if the queue has free entries. If the queue
  234. * is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is
  235. * returned.
  236. */
  237. static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
  238. {
  239. struct aac_queue * q;
  240. unsigned long idx;
  241. /*
  242. * All of the queues wrap when they reach the end, so we check
  243. * to see if they have reached the end and if they have we just
  244. * set the index back to zero. This is a wrap. You could or off
  245. * the high bits in all updates but this is a bit faster I think.
  246. */
  247. q = &dev->queues->queue[qid];
  248. idx = *index = le32_to_cpu(*(q->headers.producer));
  249. /* Interrupt Moderation, only interrupt for first two entries */
  250. if (idx != le32_to_cpu(*(q->headers.consumer))) {
  251. if (--idx == 0) {
  252. if (qid == AdapNormCmdQueue)
  253. idx = ADAP_NORM_CMD_ENTRIES;
  254. else
  255. idx = ADAP_NORM_RESP_ENTRIES;
  256. }
  257. if (idx != le32_to_cpu(*(q->headers.consumer)))
  258. *nonotify = 1;
  259. }
  260. if (qid == AdapNormCmdQueue) {
  261. if (*index >= ADAP_NORM_CMD_ENTRIES)
  262. *index = 0; /* Wrap to front of the Producer Queue. */
  263. } else {
  264. if (*index >= ADAP_NORM_RESP_ENTRIES)
  265. *index = 0; /* Wrap to front of the Producer Queue. */
  266. }
  267. /* Queue is full */
  268. if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) {
  269. printk(KERN_WARNING "Queue %d full, %u outstanding.\n",
  270. qid, q->numpending);
  271. return 0;
  272. } else {
  273. *entry = q->base + *index;
  274. return 1;
  275. }
  276. }
  277. /**
  278. * aac_queue_get - get the next free QE
  279. * @dev: Adapter
  280. * @index: Returned index
  281. * @priority: Priority of fib
  282. * @fib: Fib to associate with the queue entry
  283. * @wait: Wait if queue full
  284. * @fibptr: Driver fib object to go with fib
  285. * @nonotify: Don't notify the adapter
  286. *
  287. * Gets the next free QE off the requested priorty adapter command
  288. * queue and associates the Fib with the QE. The QE represented by
  289. * index is ready to insert on the queue when this routine returns
  290. * success.
  291. */
  292. 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)
  293. {
  294. struct aac_entry * entry = NULL;
  295. int map = 0;
  296. if (qid == AdapNormCmdQueue) {
  297. /* if no entries wait for some if caller wants to */
  298. while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
  299. printk(KERN_ERR "GetEntries failed\n");
  300. }
  301. /*
  302. * Setup queue entry with a command, status and fib mapped
  303. */
  304. entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
  305. map = 1;
  306. } else {
  307. while (!aac_get_entry(dev, qid, &entry, index, nonotify)) {
  308. /* if no entries wait for some if caller wants to */
  309. }
  310. /*
  311. * Setup queue entry with command, status and fib mapped
  312. */
  313. entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));
  314. entry->addr = hw_fib->header.SenderFibAddress;
  315. /* Restore adapters pointer to the FIB */
  316. hw_fib->header.ReceiverFibAddress = hw_fib->header.SenderFibAddress; /* Let the adapter now where to find its data */
  317. map = 0;
  318. }
  319. /*
  320. * If MapFib is true than we need to map the Fib and put pointers
  321. * in the queue entry.
  322. */
  323. if (map)
  324. entry->addr = cpu_to_le32(fibptr->hw_fib_pa);
  325. return 0;
  326. }
  327. /*
  328. * Define the highest level of host to adapter communication routines.
  329. * These routines will support host to adapter FS commuication. These
  330. * routines have no knowledge of the commuication method used. This level
  331. * sends and receives FIBs. This level has no knowledge of how these FIBs
  332. * get passed back and forth.
  333. */
  334. /**
  335. * aac_fib_send - send a fib to the adapter
  336. * @command: Command to send
  337. * @fibptr: The fib
  338. * @size: Size of fib data area
  339. * @priority: Priority of Fib
  340. * @wait: Async/sync select
  341. * @reply: True if a reply is wanted
  342. * @callback: Called with reply
  343. * @callback_data: Passed to callback
  344. *
  345. * Sends the requested FIB to the adapter and optionally will wait for a
  346. * response FIB. If the caller does not wish to wait for a response than
  347. * an event to wait on must be supplied. This event will be set when a
  348. * response FIB is received from the adapter.
  349. */
  350. int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
  351. int priority, int wait, int reply, fib_callback callback,
  352. void *callback_data)
  353. {
  354. struct aac_dev * dev = fibptr->dev;
  355. struct hw_fib * hw_fib = fibptr->hw_fib_va;
  356. unsigned long flags = 0;
  357. unsigned long qflags;
  358. if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))
  359. return -EBUSY;
  360. /*
  361. * There are 5 cases with the wait and reponse requested flags.
  362. * The only invalid cases are if the caller requests to wait and
  363. * does not request a response and if the caller does not want a
  364. * response and the Fib is not allocated from pool. If a response
  365. * is not requesed the Fib will just be deallocaed by the DPC
  366. * routine when the response comes back from the adapter. No
  367. * further processing will be done besides deleting the Fib. We
  368. * will have a debug mode where the adapter can notify the host
  369. * it had a problem and the host can log that fact.
  370. */
  371. fibptr->flags = 0;
  372. if (wait && !reply) {
  373. return -EINVAL;
  374. } else if (!wait && reply) {
  375. hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected);
  376. FIB_COUNTER_INCREMENT(aac_config.AsyncSent);
  377. } else if (!wait && !reply) {
  378. hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected);
  379. FIB_COUNTER_INCREMENT(aac_config.NoResponseSent);
  380. } else if (wait && reply) {
  381. hw_fib->header.XferState |= cpu_to_le32(ResponseExpected);
  382. FIB_COUNTER_INCREMENT(aac_config.NormalSent);
  383. }
  384. /*
  385. * Map the fib into 32bits by using the fib number
  386. */
  387. hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);
  388. hw_fib->header.SenderData = (u32)(fibptr - dev->fibs);
  389. /*
  390. * Set FIB state to indicate where it came from and if we want a
  391. * response from the adapter. Also load the command from the
  392. * caller.
  393. *
  394. * Map the hw fib pointer as a 32bit value
  395. */
  396. hw_fib->header.Command = cpu_to_le16(command);
  397. hw_fib->header.XferState |= cpu_to_le32(SentFromHost);
  398. fibptr->hw_fib_va->header.Flags = 0; /* 0 the flags field - internal only*/
  399. /*
  400. * Set the size of the Fib we want to send to the adapter
  401. */
  402. hw_fib->header.Size = cpu_to_le16(sizeof(struct aac_fibhdr) + size);
  403. if (le16_to_cpu(hw_fib->header.Size) > le16_to_cpu(hw_fib->header.SenderSize)) {
  404. return -EMSGSIZE;
  405. }
  406. /*
  407. * Get a queue entry connect the FIB to it and send an notify
  408. * the adapter a command is ready.
  409. */
  410. hw_fib->header.XferState |= cpu_to_le32(NormalPriority);
  411. /*
  412. * Fill in the Callback and CallbackContext if we are not
  413. * going to wait.
  414. */
  415. if (!wait) {
  416. fibptr->callback = callback;
  417. fibptr->callback_data = callback_data;
  418. fibptr->flags = FIB_CONTEXT_FLAG;
  419. }
  420. fibptr->done = 0;
  421. FIB_COUNTER_INCREMENT(aac_config.FibsSent);
  422. dprintk((KERN_DEBUG "Fib contents:.\n"));
  423. dprintk((KERN_DEBUG " Command = %d.\n", le32_to_cpu(hw_fib->header.Command)));
  424. dprintk((KERN_DEBUG " SubCommand = %d.\n", le32_to_cpu(((struct aac_query_mount *)fib_data(fibptr))->command)));
  425. dprintk((KERN_DEBUG " XferState = %x.\n", le32_to_cpu(hw_fib->header.XferState)));
  426. dprintk((KERN_DEBUG " hw_fib va being sent=%p\n",fibptr->hw_fib_va));
  427. dprintk((KERN_DEBUG " hw_fib pa being sent=%lx\n",(ulong)fibptr->hw_fib_pa));
  428. dprintk((KERN_DEBUG " fib being sent=%p\n",fibptr));
  429. if (!dev->queues)
  430. return -EBUSY;
  431. if(wait)
  432. spin_lock_irqsave(&fibptr->event_lock, flags);
  433. aac_adapter_deliver(fibptr);
  434. /*
  435. * If the caller wanted us to wait for response wait now.
  436. */
  437. if (wait) {
  438. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  439. /* Only set for first known interruptable command */
  440. if (wait < 0) {
  441. /*
  442. * *VERY* Dangerous to time out a command, the
  443. * assumption is made that we have no hope of
  444. * functioning because an interrupt routing or other
  445. * hardware failure has occurred.
  446. */
  447. unsigned long count = 36000000L; /* 3 minutes */
  448. while (down_trylock(&fibptr->event_wait)) {
  449. int blink;
  450. if (--count == 0) {
  451. struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue];
  452. spin_lock_irqsave(q->lock, qflags);
  453. q->numpending--;
  454. spin_unlock_irqrestore(q->lock, qflags);
  455. if (wait == -1) {
  456. printk(KERN_ERR "aacraid: aac_fib_send: first asynchronous command timed out.\n"
  457. "Usually a result of a PCI interrupt routing problem;\n"
  458. "update mother board BIOS or consider utilizing one of\n"
  459. "the SAFE mode kernel options (acpi, apic etc)\n");
  460. }
  461. return -ETIMEDOUT;
  462. }
  463. if ((blink = aac_adapter_check_health(dev)) > 0) {
  464. if (wait == -1) {
  465. printk(KERN_ERR "aacraid: aac_fib_send: adapter blinkLED 0x%x.\n"
  466. "Usually a result of a serious unrecoverable hardware problem\n",
  467. blink);
  468. }
  469. return -EFAULT;
  470. }
  471. udelay(5);
  472. }
  473. } else if (down_interruptible(&fibptr->event_wait) == 0) {
  474. fibptr->done = 2;
  475. up(&fibptr->event_wait);
  476. }
  477. spin_lock_irqsave(&fibptr->event_lock, flags);
  478. if ((fibptr->done == 0) || (fibptr->done == 2)) {
  479. fibptr->done = 2; /* Tell interrupt we aborted */
  480. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  481. return -EINTR;
  482. }
  483. spin_unlock_irqrestore(&fibptr->event_lock, flags);
  484. BUG_ON(fibptr->done == 0);
  485. if(unlikely(fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT))
  486. return -ETIMEDOUT;
  487. return 0;
  488. }
  489. /*
  490. * If the user does not want a response than return success otherwise
  491. * return pending
  492. */
  493. if (reply)
  494. return -EINPROGRESS;
  495. else
  496. return 0;
  497. }
  498. /**
  499. * aac_consumer_get - get the top of the queue
  500. * @dev: Adapter
  501. * @q: Queue
  502. * @entry: Return entry
  503. *
  504. * Will return a pointer to the entry on the top of the queue requested that
  505. * we are a consumer of, and return the address of the queue entry. It does
  506. * not change the state of the queue.
  507. */
  508. int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry)
  509. {
  510. u32 index;
  511. int status;
  512. if (le32_to_cpu(*q->headers.producer) == le32_to_cpu(*q->headers.consumer)) {
  513. status = 0;
  514. } else {
  515. /*
  516. * The consumer index must be wrapped if we have reached
  517. * the end of the queue, else we just use the entry
  518. * pointed to by the header index
  519. */
  520. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  521. index = 0;
  522. else
  523. index = le32_to_cpu(*q->headers.consumer);
  524. *entry = q->base + index;
  525. status = 1;
  526. }
  527. return(status);
  528. }
  529. /**
  530. * aac_consumer_free - free consumer entry
  531. * @dev: Adapter
  532. * @q: Queue
  533. * @qid: Queue ident
  534. *
  535. * Frees up the current top of the queue we are a consumer of. If the
  536. * queue was full notify the producer that the queue is no longer full.
  537. */
  538. void aac_consumer_free(struct aac_dev * dev, struct aac_queue *q, u32 qid)
  539. {
  540. int wasfull = 0;
  541. u32 notify;
  542. if ((le32_to_cpu(*q->headers.producer)+1) == le32_to_cpu(*q->headers.consumer))
  543. wasfull = 1;
  544. if (le32_to_cpu(*q->headers.consumer) >= q->entries)
  545. *q->headers.consumer = cpu_to_le32(1);
  546. else
  547. le32_add_cpu(q->headers.consumer, 1);
  548. if (wasfull) {
  549. switch (qid) {
  550. case HostNormCmdQueue:
  551. notify = HostNormCmdNotFull;
  552. break;
  553. case HostNormRespQueue:
  554. notify = HostNormRespNotFull;
  555. break;
  556. default:
  557. BUG();
  558. return;
  559. }
  560. aac_adapter_notify(dev, notify);
  561. }
  562. }
  563. /**
  564. * aac_fib_adapter_complete - complete adapter issued fib
  565. * @fibptr: fib to complete
  566. * @size: size of fib
  567. *
  568. * Will do all necessary work to complete a FIB that was sent from
  569. * the adapter.
  570. */
  571. int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
  572. {
  573. struct hw_fib * hw_fib = fibptr->hw_fib_va;
  574. struct aac_dev * dev = fibptr->dev;
  575. struct aac_queue * q;
  576. unsigned long nointr = 0;
  577. unsigned long qflags;
  578. if (hw_fib->header.XferState == 0) {
  579. if (dev->comm_interface == AAC_COMM_MESSAGE)
  580. kfree (hw_fib);
  581. return 0;
  582. }
  583. /*
  584. * If we plan to do anything check the structure type first.
  585. */
  586. if (hw_fib->header.StructType != FIB_MAGIC) {
  587. if (dev->comm_interface == AAC_COMM_MESSAGE)
  588. kfree (hw_fib);
  589. return -EINVAL;
  590. }
  591. /*
  592. * This block handles the case where the adapter had sent us a
  593. * command and we have finished processing the command. We
  594. * call completeFib when we are done processing the command
  595. * and want to send a response back to the adapter. This will
  596. * send the completed cdb to the adapter.
  597. */
  598. if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
  599. if (dev->comm_interface == AAC_COMM_MESSAGE) {
  600. kfree (hw_fib);
  601. } else {
  602. u32 index;
  603. hw_fib->header.XferState |= cpu_to_le32(HostProcessed);
  604. if (size) {
  605. size += sizeof(struct aac_fibhdr);
  606. if (size > le16_to_cpu(hw_fib->header.SenderSize))
  607. return -EMSGSIZE;
  608. hw_fib->header.Size = cpu_to_le16(size);
  609. }
  610. q = &dev->queues->queue[AdapNormRespQueue];
  611. spin_lock_irqsave(q->lock, qflags);
  612. aac_queue_get(dev, &index, AdapNormRespQueue, hw_fib, 1, NULL, &nointr);
  613. *(q->headers.producer) = cpu_to_le32(index + 1);
  614. spin_unlock_irqrestore(q->lock, qflags);
  615. if (!(nointr & (int)aac_config.irq_mod))
  616. aac_adapter_notify(dev, AdapNormRespQueue);
  617. }
  618. } else {
  619. printk(KERN_WARNING "aac_fib_adapter_complete: "
  620. "Unknown xferstate detected.\n");
  621. BUG();
  622. }
  623. return 0;
  624. }
  625. /**
  626. * aac_fib_complete - fib completion handler
  627. * @fib: FIB to complete
  628. *
  629. * Will do all necessary work to complete a FIB.
  630. */
  631. int aac_fib_complete(struct fib *fibptr)
  632. {
  633. struct hw_fib * hw_fib = fibptr->hw_fib_va;
  634. /*
  635. * Check for a fib which has already been completed
  636. */
  637. if (hw_fib->header.XferState == 0)
  638. return 0;
  639. /*
  640. * If we plan to do anything check the structure type first.
  641. */
  642. if (hw_fib->header.StructType != FIB_MAGIC)
  643. return -EINVAL;
  644. /*
  645. * This block completes a cdb which orginated on the host and we
  646. * just need to deallocate the cdb or reinit it. At this point the
  647. * command is complete that we had sent to the adapter and this
  648. * cdb could be reused.
  649. */
  650. if((hw_fib->header.XferState & cpu_to_le32(SentFromHost)) &&
  651. (hw_fib->header.XferState & cpu_to_le32(AdapterProcessed)))
  652. {
  653. fib_dealloc(fibptr);
  654. }
  655. else if(hw_fib->header.XferState & cpu_to_le32(SentFromHost))
  656. {
  657. /*
  658. * This handles the case when the host has aborted the I/O
  659. * to the adapter because the adapter is not responding
  660. */
  661. fib_dealloc(fibptr);
  662. } else if(hw_fib->header.XferState & cpu_to_le32(HostOwned)) {
  663. fib_dealloc(fibptr);
  664. } else {
  665. BUG();
  666. }
  667. return 0;
  668. }
  669. /**
  670. * aac_printf - handle printf from firmware
  671. * @dev: Adapter
  672. * @val: Message info
  673. *
  674. * Print a message passed to us by the controller firmware on the
  675. * Adaptec board
  676. */
  677. void aac_printf(struct aac_dev *dev, u32 val)
  678. {
  679. char *cp = dev->printfbuf;
  680. if (dev->printf_enabled)
  681. {
  682. int length = val & 0xffff;
  683. int level = (val >> 16) & 0xffff;
  684. /*
  685. * The size of the printfbuf is set in port.c
  686. * There is no variable or define for it
  687. */
  688. if (length > 255)
  689. length = 255;
  690. if (cp[length] != 0)
  691. cp[length] = 0;
  692. if (level == LOG_AAC_HIGH_ERROR)
  693. printk(KERN_WARNING "%s:%s", dev->name, cp);
  694. else
  695. printk(KERN_INFO "%s:%s", dev->name, cp);
  696. }
  697. memset(cp, 0, 256);
  698. }
  699. /**
  700. * aac_handle_aif - Handle a message from the firmware
  701. * @dev: Which adapter this fib is from
  702. * @fibptr: Pointer to fibptr from adapter
  703. *
  704. * This routine handles a driver notify fib from the adapter and
  705. * dispatches it to the appropriate routine for handling.
  706. */
  707. #define AIF_SNIFF_TIMEOUT (30*HZ)
  708. static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
  709. {
  710. struct hw_fib * hw_fib = fibptr->hw_fib_va;
  711. struct aac_aifcmd * aifcmd = (struct aac_aifcmd *)hw_fib->data;
  712. u32 channel, id, lun, container;
  713. struct scsi_device *device;
  714. enum {
  715. NOTHING,
  716. DELETE,
  717. ADD,
  718. CHANGE
  719. } device_config_needed = NOTHING;
  720. /* Sniff for container changes */
  721. if (!dev || !dev->fsa_dev)
  722. return;
  723. container = channel = id = lun = (u32)-1;
  724. /*
  725. * We have set this up to try and minimize the number of
  726. * re-configures that take place. As a result of this when
  727. * certain AIF's come in we will set a flag waiting for another
  728. * type of AIF before setting the re-config flag.
  729. */
  730. switch (le32_to_cpu(aifcmd->command)) {
  731. case AifCmdDriverNotify:
  732. switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
  733. /*
  734. * Morph or Expand complete
  735. */
  736. case AifDenMorphComplete:
  737. case AifDenVolumeExtendComplete:
  738. container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
  739. if (container >= dev->maximum_num_containers)
  740. break;
  741. /*
  742. * Find the scsi_device associated with the SCSI
  743. * address. Make sure we have the right array, and if
  744. * so set the flag to initiate a new re-config once we
  745. * see an AifEnConfigChange AIF come through.
  746. */
  747. if ((dev != NULL) && (dev->scsi_host_ptr != NULL)) {
  748. device = scsi_device_lookup(dev->scsi_host_ptr,
  749. CONTAINER_TO_CHANNEL(container),
  750. CONTAINER_TO_ID(container),
  751. CONTAINER_TO_LUN(container));
  752. if (device) {
  753. dev->fsa_dev[container].config_needed = CHANGE;
  754. dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
  755. dev->fsa_dev[container].config_waiting_stamp = jiffies;
  756. scsi_device_put(device);
  757. }
  758. }
  759. }
  760. /*
  761. * If we are waiting on something and this happens to be
  762. * that thing then set the re-configure flag.
  763. */
  764. if (container != (u32)-1) {
  765. if (container >= dev->maximum_num_containers)
  766. break;
  767. if ((dev->fsa_dev[container].config_waiting_on ==
  768. le32_to_cpu(*(__le32 *)aifcmd->data)) &&
  769. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
  770. dev->fsa_dev[container].config_waiting_on = 0;
  771. } else for (container = 0;
  772. container < dev->maximum_num_containers; ++container) {
  773. if ((dev->fsa_dev[container].config_waiting_on ==
  774. le32_to_cpu(*(__le32 *)aifcmd->data)) &&
  775. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
  776. dev->fsa_dev[container].config_waiting_on = 0;
  777. }
  778. break;
  779. case AifCmdEventNotify:
  780. switch (le32_to_cpu(((__le32 *)aifcmd->data)[0])) {
  781. case AifEnBatteryEvent:
  782. dev->cache_protected =
  783. (((__le32 *)aifcmd->data)[1] == cpu_to_le32(3));
  784. break;
  785. /*
  786. * Add an Array.
  787. */
  788. case AifEnAddContainer:
  789. container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
  790. if (container >= dev->maximum_num_containers)
  791. break;
  792. dev->fsa_dev[container].config_needed = ADD;
  793. dev->fsa_dev[container].config_waiting_on =
  794. AifEnConfigChange;
  795. dev->fsa_dev[container].config_waiting_stamp = jiffies;
  796. break;
  797. /*
  798. * Delete an Array.
  799. */
  800. case AifEnDeleteContainer:
  801. container = le32_to_cpu(((__le32 *)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. dev->fsa_dev[container].config_waiting_stamp = jiffies;
  808. break;
  809. /*
  810. * Container change detected. If we currently are not
  811. * waiting on something else, setup to wait on a Config Change.
  812. */
  813. case AifEnContainerChange:
  814. container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
  815. if (container >= dev->maximum_num_containers)
  816. break;
  817. if (dev->fsa_dev[container].config_waiting_on &&
  818. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
  819. break;
  820. dev->fsa_dev[container].config_needed = CHANGE;
  821. dev->fsa_dev[container].config_waiting_on =
  822. AifEnConfigChange;
  823. dev->fsa_dev[container].config_waiting_stamp = jiffies;
  824. break;
  825. case AifEnConfigChange:
  826. break;
  827. case AifEnAddJBOD:
  828. case AifEnDeleteJBOD:
  829. container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
  830. if ((container >> 28))
  831. break;
  832. channel = (container >> 24) & 0xF;
  833. if (channel >= dev->maximum_num_channels)
  834. break;
  835. id = container & 0xFFFF;
  836. if (id >= dev->maximum_num_physicals)
  837. break;
  838. lun = (container >> 16) & 0xFF;
  839. channel = aac_phys_to_logical(channel);
  840. device_config_needed =
  841. (((__le32 *)aifcmd->data)[0] ==
  842. cpu_to_le32(AifEnAddJBOD)) ? ADD : DELETE;
  843. break;
  844. case AifEnEnclosureManagement:
  845. /*
  846. * If in JBOD mode, automatic exposure of new
  847. * physical target to be suppressed until configured.
  848. */
  849. if (dev->jbod)
  850. break;
  851. switch (le32_to_cpu(((__le32 *)aifcmd->data)[3])) {
  852. case EM_DRIVE_INSERTION:
  853. case EM_DRIVE_REMOVAL:
  854. container = le32_to_cpu(
  855. ((__le32 *)aifcmd->data)[2]);
  856. if ((container >> 28))
  857. break;
  858. channel = (container >> 24) & 0xF;
  859. if (channel >= dev->maximum_num_channels)
  860. break;
  861. id = container & 0xFFFF;
  862. lun = (container >> 16) & 0xFF;
  863. if (id >= dev->maximum_num_physicals) {
  864. /* legacy dev_t ? */
  865. if ((0x2000 <= id) || lun || channel ||
  866. ((channel = (id >> 7) & 0x3F) >=
  867. dev->maximum_num_channels))
  868. break;
  869. lun = (id >> 4) & 7;
  870. id &= 0xF;
  871. }
  872. channel = aac_phys_to_logical(channel);
  873. device_config_needed =
  874. (((__le32 *)aifcmd->data)[3]
  875. == cpu_to_le32(EM_DRIVE_INSERTION)) ?
  876. ADD : DELETE;
  877. break;
  878. }
  879. break;
  880. }
  881. /*
  882. * If we are waiting on something and this happens to be
  883. * that thing then set the re-configure flag.
  884. */
  885. if (container != (u32)-1) {
  886. if (container >= dev->maximum_num_containers)
  887. break;
  888. if ((dev->fsa_dev[container].config_waiting_on ==
  889. le32_to_cpu(*(__le32 *)aifcmd->data)) &&
  890. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
  891. dev->fsa_dev[container].config_waiting_on = 0;
  892. } else for (container = 0;
  893. container < dev->maximum_num_containers; ++container) {
  894. if ((dev->fsa_dev[container].config_waiting_on ==
  895. le32_to_cpu(*(__le32 *)aifcmd->data)) &&
  896. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
  897. dev->fsa_dev[container].config_waiting_on = 0;
  898. }
  899. break;
  900. case AifCmdJobProgress:
  901. /*
  902. * These are job progress AIF's. When a Clear is being
  903. * done on a container it is initially created then hidden from
  904. * the OS. When the clear completes we don't get a config
  905. * change so we monitor the job status complete on a clear then
  906. * wait for a container change.
  907. */
  908. if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
  909. (((__le32 *)aifcmd->data)[6] == ((__le32 *)aifcmd->data)[5] ||
  910. ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsSuccess))) {
  911. for (container = 0;
  912. container < dev->maximum_num_containers;
  913. ++container) {
  914. /*
  915. * Stomp on all config sequencing for all
  916. * containers?
  917. */
  918. dev->fsa_dev[container].config_waiting_on =
  919. AifEnContainerChange;
  920. dev->fsa_dev[container].config_needed = ADD;
  921. dev->fsa_dev[container].config_waiting_stamp =
  922. jiffies;
  923. }
  924. }
  925. if (((__le32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero) &&
  926. ((__le32 *)aifcmd->data)[6] == 0 &&
  927. ((__le32 *)aifcmd->data)[4] == cpu_to_le32(AifJobStsRunning)) {
  928. for (container = 0;
  929. container < dev->maximum_num_containers;
  930. ++container) {
  931. /*
  932. * Stomp on all config sequencing for all
  933. * containers?
  934. */
  935. dev->fsa_dev[container].config_waiting_on =
  936. AifEnContainerChange;
  937. dev->fsa_dev[container].config_needed = DELETE;
  938. dev->fsa_dev[container].config_waiting_stamp =
  939. jiffies;
  940. }
  941. }
  942. break;
  943. }
  944. if (device_config_needed == NOTHING)
  945. for (container = 0; container < dev->maximum_num_containers;
  946. ++container) {
  947. if ((dev->fsa_dev[container].config_waiting_on == 0) &&
  948. (dev->fsa_dev[container].config_needed != NOTHING) &&
  949. time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
  950. device_config_needed =
  951. dev->fsa_dev[container].config_needed;
  952. dev->fsa_dev[container].config_needed = NOTHING;
  953. channel = CONTAINER_TO_CHANNEL(container);
  954. id = CONTAINER_TO_ID(container);
  955. lun = CONTAINER_TO_LUN(container);
  956. break;
  957. }
  958. }
  959. if (device_config_needed == NOTHING)
  960. return;
  961. /*
  962. * If we decided that a re-configuration needs to be done,
  963. * schedule it here on the way out the door, please close the door
  964. * behind you.
  965. */
  966. /*
  967. * Find the scsi_device associated with the SCSI address,
  968. * and mark it as changed, invalidating the cache. This deals
  969. * with changes to existing device IDs.
  970. */
  971. if (!dev || !dev->scsi_host_ptr)
  972. return;
  973. /*
  974. * force reload of disk info via aac_probe_container
  975. */
  976. if ((channel == CONTAINER_CHANNEL) &&
  977. (device_config_needed != NOTHING)) {
  978. if (dev->fsa_dev[container].valid == 1)
  979. dev->fsa_dev[container].valid = 2;
  980. aac_probe_container(dev, container);
  981. }
  982. device = scsi_device_lookup(dev->scsi_host_ptr, channel, id, lun);
  983. if (device) {
  984. switch (device_config_needed) {
  985. case DELETE:
  986. if (scsi_device_online(device)) {
  987. scsi_device_set_state(device, SDEV_OFFLINE);
  988. sdev_printk(KERN_INFO, device,
  989. "Device offlined - %s\n",
  990. (channel == CONTAINER_CHANNEL) ?
  991. "array deleted" :
  992. "enclosure services event");
  993. }
  994. break;
  995. case ADD:
  996. if (!scsi_device_online(device)) {
  997. sdev_printk(KERN_INFO, device,
  998. "Device online - %s\n",
  999. (channel == CONTAINER_CHANNEL) ?
  1000. "array created" :
  1001. "enclosure services event");
  1002. scsi_device_set_state(device, SDEV_RUNNING);
  1003. }
  1004. /* FALLTHRU */
  1005. case CHANGE:
  1006. if ((channel == CONTAINER_CHANNEL)
  1007. && (!dev->fsa_dev[container].valid)) {
  1008. if (!scsi_device_online(device))
  1009. break;
  1010. scsi_device_set_state(device, SDEV_OFFLINE);
  1011. sdev_printk(KERN_INFO, device,
  1012. "Device offlined - %s\n",
  1013. "array failed");
  1014. break;
  1015. }
  1016. scsi_rescan_device(&device->sdev_gendev);
  1017. default:
  1018. break;
  1019. }
  1020. scsi_device_put(device);
  1021. device_config_needed = NOTHING;
  1022. }
  1023. if (device_config_needed == ADD)
  1024. scsi_add_device(dev->scsi_host_ptr, channel, id, lun);
  1025. }
  1026. static int _aac_reset_adapter(struct aac_dev *aac, int forced)
  1027. {
  1028. int index, quirks;
  1029. int retval;
  1030. struct Scsi_Host *host;
  1031. struct scsi_device *dev;
  1032. struct scsi_cmnd *command;
  1033. struct scsi_cmnd *command_list;
  1034. int jafo = 0;
  1035. /*
  1036. * Assumptions:
  1037. * - host is locked, unless called by the aacraid thread.
  1038. * (a matter of convenience, due to legacy issues surrounding
  1039. * eh_host_adapter_reset).
  1040. * - in_reset is asserted, so no new i/o is getting to the
  1041. * card.
  1042. * - The card is dead, or will be very shortly ;-/ so no new
  1043. * commands are completing in the interrupt service.
  1044. */
  1045. host = aac->scsi_host_ptr;
  1046. scsi_block_requests(host);
  1047. aac_adapter_disable_int(aac);
  1048. if (aac->thread->pid != current->pid) {
  1049. spin_unlock_irq(host->host_lock);
  1050. kthread_stop(aac->thread);
  1051. jafo = 1;
  1052. }
  1053. /*
  1054. * If a positive health, means in a known DEAD PANIC
  1055. * state and the adapter could be reset to `try again'.
  1056. */
  1057. retval = aac_adapter_restart(aac, forced ? 0 : aac_adapter_check_health(aac));
  1058. if (retval)
  1059. goto out;
  1060. /*
  1061. * Loop through the fibs, close the synchronous FIBS
  1062. */
  1063. for (retval = 1, index = 0; index < (aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); index++) {
  1064. struct fib *fib = &aac->fibs[index];
  1065. if (!(fib->hw_fib_va->header.XferState & cpu_to_le32(NoResponseExpected | Async)) &&
  1066. (fib->hw_fib_va->header.XferState & cpu_to_le32(ResponseExpected))) {
  1067. unsigned long flagv;
  1068. spin_lock_irqsave(&fib->event_lock, flagv);
  1069. up(&fib->event_wait);
  1070. spin_unlock_irqrestore(&fib->event_lock, flagv);
  1071. schedule();
  1072. retval = 0;
  1073. }
  1074. }
  1075. /* Give some extra time for ioctls to complete. */
  1076. if (retval == 0)
  1077. ssleep(2);
  1078. index = aac->cardtype;
  1079. /*
  1080. * Re-initialize the adapter, first free resources, then carefully
  1081. * apply the initialization sequence to come back again. Only risk
  1082. * is a change in Firmware dropping cache, it is assumed the caller
  1083. * will ensure that i/o is queisced and the card is flushed in that
  1084. * case.
  1085. */
  1086. aac_fib_map_free(aac);
  1087. pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
  1088. aac->comm_addr = NULL;
  1089. aac->comm_phys = 0;
  1090. kfree(aac->queues);
  1091. aac->queues = NULL;
  1092. free_irq(aac->pdev->irq, aac);
  1093. kfree(aac->fsa_dev);
  1094. aac->fsa_dev = NULL;
  1095. quirks = aac_get_driver_ident(index)->quirks;
  1096. if (quirks & AAC_QUIRK_31BIT) {
  1097. if (((retval = pci_set_dma_mask(aac->pdev, DMA_31BIT_MASK))) ||
  1098. ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_31BIT_MASK))))
  1099. goto out;
  1100. } else {
  1101. if (((retval = pci_set_dma_mask(aac->pdev, DMA_32BIT_MASK))) ||
  1102. ((retval = pci_set_consistent_dma_mask(aac->pdev, DMA_32BIT_MASK))))
  1103. goto out;
  1104. }
  1105. if ((retval = (*(aac_get_driver_ident(index)->init))(aac)))
  1106. goto out;
  1107. if (quirks & AAC_QUIRK_31BIT)
  1108. if ((retval = pci_set_dma_mask(aac->pdev, DMA_32BIT_MASK)))
  1109. goto out;
  1110. if (jafo) {
  1111. aac->thread = kthread_run(aac_command_thread, aac, aac->name);
  1112. if (IS_ERR(aac->thread)) {
  1113. retval = PTR_ERR(aac->thread);
  1114. goto out;
  1115. }
  1116. }
  1117. (void)aac_get_adapter_info(aac);
  1118. if ((quirks & AAC_QUIRK_34SG) && (host->sg_tablesize > 34)) {
  1119. host->sg_tablesize = 34;
  1120. host->max_sectors = (host->sg_tablesize * 8) + 112;
  1121. }
  1122. if ((quirks & AAC_QUIRK_17SG) && (host->sg_tablesize > 17)) {
  1123. host->sg_tablesize = 17;
  1124. host->max_sectors = (host->sg_tablesize * 8) + 112;
  1125. }
  1126. aac_get_config_status(aac, 1);
  1127. aac_get_containers(aac);
  1128. /*
  1129. * This is where the assumption that the Adapter is quiesced
  1130. * is important.
  1131. */
  1132. command_list = NULL;
  1133. __shost_for_each_device(dev, host) {
  1134. unsigned long flags;
  1135. spin_lock_irqsave(&dev->list_lock, flags);
  1136. list_for_each_entry(command, &dev->cmd_list, list)
  1137. if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
  1138. command->SCp.buffer = (struct scatterlist *)command_list;
  1139. command_list = command;
  1140. }
  1141. spin_unlock_irqrestore(&dev->list_lock, flags);
  1142. }
  1143. while ((command = command_list)) {
  1144. command_list = (struct scsi_cmnd *)command->SCp.buffer;
  1145. command->SCp.buffer = NULL;
  1146. command->result = DID_OK << 16
  1147. | COMMAND_COMPLETE << 8
  1148. | SAM_STAT_TASK_SET_FULL;
  1149. command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
  1150. command->scsi_done(command);
  1151. }
  1152. retval = 0;
  1153. out:
  1154. aac->in_reset = 0;
  1155. scsi_unblock_requests(host);
  1156. if (jafo) {
  1157. spin_lock_irq(host->host_lock);
  1158. }
  1159. return retval;
  1160. }
  1161. int aac_reset_adapter(struct aac_dev * aac, int forced)
  1162. {
  1163. unsigned long flagv = 0;
  1164. int retval;
  1165. struct Scsi_Host * host;
  1166. if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
  1167. return -EBUSY;
  1168. if (aac->in_reset) {
  1169. spin_unlock_irqrestore(&aac->fib_lock, flagv);
  1170. return -EBUSY;
  1171. }
  1172. aac->in_reset = 1;
  1173. spin_unlock_irqrestore(&aac->fib_lock, flagv);
  1174. /*
  1175. * Wait for all commands to complete to this specific
  1176. * target (block maximum 60 seconds). Although not necessary,
  1177. * it does make us a good storage citizen.
  1178. */
  1179. host = aac->scsi_host_ptr;
  1180. scsi_block_requests(host);
  1181. if (forced < 2) for (retval = 60; retval; --retval) {
  1182. struct scsi_device * dev;
  1183. struct scsi_cmnd * command;
  1184. int active = 0;
  1185. __shost_for_each_device(dev, host) {
  1186. spin_lock_irqsave(&dev->list_lock, flagv);
  1187. list_for_each_entry(command, &dev->cmd_list, list) {
  1188. if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
  1189. active++;
  1190. break;
  1191. }
  1192. }
  1193. spin_unlock_irqrestore(&dev->list_lock, flagv);
  1194. if (active)
  1195. break;
  1196. }
  1197. /*
  1198. * We can exit If all the commands are complete
  1199. */
  1200. if (active == 0)
  1201. break;
  1202. ssleep(1);
  1203. }
  1204. /* Quiesce build, flush cache, write through mode */
  1205. if (forced < 2)
  1206. aac_send_shutdown(aac);
  1207. spin_lock_irqsave(host->host_lock, flagv);
  1208. retval = _aac_reset_adapter(aac, forced ? forced : ((aac_check_reset != 0) && (aac_check_reset != 1)));
  1209. spin_unlock_irqrestore(host->host_lock, flagv);
  1210. if ((forced < 2) && (retval == -ENODEV)) {
  1211. /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
  1212. struct fib * fibctx = aac_fib_alloc(aac);
  1213. if (fibctx) {
  1214. struct aac_pause *cmd;
  1215. int status;
  1216. aac_fib_init(fibctx);
  1217. cmd = (struct aac_pause *) fib_data(fibctx);
  1218. cmd->command = cpu_to_le32(VM_ContainerConfig);
  1219. cmd->type = cpu_to_le32(CT_PAUSE_IO);
  1220. cmd->timeout = cpu_to_le32(1);
  1221. cmd->min = cpu_to_le32(1);
  1222. cmd->noRescan = cpu_to_le32(1);
  1223. cmd->count = cpu_to_le32(0);
  1224. status = aac_fib_send(ContainerCommand,
  1225. fibctx,
  1226. sizeof(struct aac_pause),
  1227. FsaNormal,
  1228. -2 /* Timeout silently */, 1,
  1229. NULL, NULL);
  1230. if (status >= 0)
  1231. aac_fib_complete(fibctx);
  1232. aac_fib_free(fibctx);
  1233. }
  1234. }
  1235. return retval;
  1236. }
  1237. int aac_check_health(struct aac_dev * aac)
  1238. {
  1239. int BlinkLED;
  1240. unsigned long time_now, flagv = 0;
  1241. struct list_head * entry;
  1242. struct Scsi_Host * host;
  1243. /* Extending the scope of fib_lock slightly to protect aac->in_reset */
  1244. if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
  1245. return 0;
  1246. if (aac->in_reset || !(BlinkLED = aac_adapter_check_health(aac))) {
  1247. spin_unlock_irqrestore(&aac->fib_lock, flagv);
  1248. return 0; /* OK */
  1249. }
  1250. aac->in_reset = 1;
  1251. /* Fake up an AIF:
  1252. * aac_aifcmd.command = AifCmdEventNotify = 1
  1253. * aac_aifcmd.seqnum = 0xFFFFFFFF
  1254. * aac_aifcmd.data[0] = AifEnExpEvent = 23
  1255. * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3
  1256. * aac.aifcmd.data[2] = AifHighPriority = 3
  1257. * aac.aifcmd.data[3] = BlinkLED
  1258. */
  1259. time_now = jiffies/HZ;
  1260. entry = aac->fib_list.next;
  1261. /*
  1262. * For each Context that is on the
  1263. * fibctxList, make a copy of the
  1264. * fib, and then set the event to wake up the
  1265. * thread that is waiting for it.
  1266. */
  1267. while (entry != &aac->fib_list) {
  1268. /*
  1269. * Extract the fibctx
  1270. */
  1271. struct aac_fib_context *fibctx = list_entry(entry, struct aac_fib_context, next);
  1272. struct hw_fib * hw_fib;
  1273. struct fib * fib;
  1274. /*
  1275. * Check if the queue is getting
  1276. * backlogged
  1277. */
  1278. if (fibctx->count > 20) {
  1279. /*
  1280. * It's *not* jiffies folks,
  1281. * but jiffies / HZ, so do not
  1282. * panic ...
  1283. */
  1284. u32 time_last = fibctx->jiffies;
  1285. /*
  1286. * Has it been > 2 minutes
  1287. * since the last read off
  1288. * the queue?
  1289. */
  1290. if ((time_now - time_last) > aif_timeout) {
  1291. entry = entry->next;
  1292. aac_close_fib_context(aac, fibctx);
  1293. continue;
  1294. }
  1295. }
  1296. /*
  1297. * Warning: no sleep allowed while
  1298. * holding spinlock
  1299. */
  1300. hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC);
  1301. fib = kzalloc(sizeof(struct fib), GFP_ATOMIC);
  1302. if (fib && hw_fib) {
  1303. struct aac_aifcmd * aif;
  1304. fib->hw_fib_va = hw_fib;
  1305. fib->dev = aac;
  1306. aac_fib_init(fib);
  1307. fib->type = FSAFS_NTC_FIB_CONTEXT;
  1308. fib->size = sizeof (struct fib);
  1309. fib->data = hw_fib->data;
  1310. aif = (struct aac_aifcmd *)hw_fib->data;
  1311. aif->command = cpu_to_le32(AifCmdEventNotify);
  1312. aif->seqnum = cpu_to_le32(0xFFFFFFFF);
  1313. ((__le32 *)aif->data)[0] = cpu_to_le32(AifEnExpEvent);
  1314. ((__le32 *)aif->data)[1] = cpu_to_le32(AifExeFirmwarePanic);
  1315. ((__le32 *)aif->data)[2] = cpu_to_le32(AifHighPriority);
  1316. ((__le32 *)aif->data)[3] = cpu_to_le32(BlinkLED);
  1317. /*
  1318. * Put the FIB onto the
  1319. * fibctx's fibs
  1320. */
  1321. list_add_tail(&fib->fiblink, &fibctx->fib_list);
  1322. fibctx->count++;
  1323. /*
  1324. * Set the event to wake up the
  1325. * thread that will waiting.
  1326. */
  1327. up(&fibctx->wait_sem);
  1328. } else {
  1329. printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
  1330. kfree(fib);
  1331. kfree(hw_fib);
  1332. }
  1333. entry = entry->next;
  1334. }
  1335. spin_unlock_irqrestore(&aac->fib_lock, flagv);
  1336. if (BlinkLED < 0) {
  1337. printk(KERN_ERR "%s: Host adapter dead %d\n", aac->name, BlinkLED);
  1338. goto out;
  1339. }
  1340. printk(KERN_ERR "%s: Host adapter BLINK LED 0x%x\n", aac->name, BlinkLED);
  1341. if (!aac_check_reset || ((aac_check_reset == 1) &&
  1342. (aac->supplement_adapter_info.SupportedOptions2 &
  1343. AAC_OPTION_IGNORE_RESET)))
  1344. goto out;
  1345. host = aac->scsi_host_ptr;
  1346. if (aac->thread->pid != current->pid)
  1347. spin_lock_irqsave(host->host_lock, flagv);
  1348. BlinkLED = _aac_reset_adapter(aac, aac_check_reset != 1);
  1349. if (aac->thread->pid != current->pid)
  1350. spin_unlock_irqrestore(host->host_lock, flagv);
  1351. return BlinkLED;
  1352. out:
  1353. aac->in_reset = 0;
  1354. return BlinkLED;
  1355. }
  1356. /**
  1357. * aac_command_thread - command processing thread
  1358. * @dev: Adapter to monitor
  1359. *
  1360. * Waits on the commandready event in it's queue. When the event gets set
  1361. * it will pull FIBs off it's queue. It will continue to pull FIBs off
  1362. * until the queue is empty. When the queue is empty it will wait for
  1363. * more FIBs.
  1364. */
  1365. int aac_command_thread(void *data)
  1366. {
  1367. struct aac_dev *dev = data;
  1368. struct hw_fib *hw_fib, *hw_newfib;
  1369. struct fib *fib, *newfib;
  1370. struct aac_fib_context *fibctx;
  1371. unsigned long flags;
  1372. DECLARE_WAITQUEUE(wait, current);
  1373. unsigned long next_jiffies = jiffies + HZ;
  1374. unsigned long next_check_jiffies = next_jiffies;
  1375. long difference = HZ;
  1376. /*
  1377. * We can only have one thread per adapter for AIF's.
  1378. */
  1379. if (dev->aif_thread)
  1380. return -EINVAL;
  1381. /*
  1382. * Let the DPC know it has a place to send the AIF's to.
  1383. */
  1384. dev->aif_thread = 1;
  1385. add_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  1386. set_current_state(TASK_INTERRUPTIBLE);
  1387. dprintk ((KERN_INFO "aac_command_thread start\n"));
  1388. while (1) {
  1389. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1390. while(!list_empty(&(dev->queues->queue[HostNormCmdQueue].cmdq))) {
  1391. struct list_head *entry;
  1392. struct aac_aifcmd * aifcmd;
  1393. set_current_state(TASK_RUNNING);
  1394. entry = dev->queues->queue[HostNormCmdQueue].cmdq.next;
  1395. list_del(entry);
  1396. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1397. fib = list_entry(entry, struct fib, fiblink);
  1398. /*
  1399. * We will process the FIB here or pass it to a
  1400. * worker thread that is TBD. We Really can't
  1401. * do anything at this point since we don't have
  1402. * anything defined for this thread to do.
  1403. */
  1404. hw_fib = fib->hw_fib_va;
  1405. memset(fib, 0, sizeof(struct fib));
  1406. fib->type = FSAFS_NTC_FIB_CONTEXT;
  1407. fib->size = sizeof(struct fib);
  1408. fib->hw_fib_va = hw_fib;
  1409. fib->data = hw_fib->data;
  1410. fib->dev = dev;
  1411. /*
  1412. * We only handle AifRequest fibs from the adapter.
  1413. */
  1414. aifcmd = (struct aac_aifcmd *) hw_fib->data;
  1415. if (aifcmd->command == cpu_to_le32(AifCmdDriverNotify)) {
  1416. /* Handle Driver Notify Events */
  1417. aac_handle_aif(dev, fib);
  1418. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  1419. aac_fib_adapter_complete(fib, (u16)sizeof(u32));
  1420. } else {
  1421. /* The u32 here is important and intended. We are using
  1422. 32bit wrapping time to fit the adapter field */
  1423. u32 time_now, time_last;
  1424. unsigned long flagv;
  1425. unsigned num;
  1426. struct hw_fib ** hw_fib_pool, ** hw_fib_p;
  1427. struct fib ** fib_pool, ** fib_p;
  1428. /* Sniff events */
  1429. if ((aifcmd->command ==
  1430. cpu_to_le32(AifCmdEventNotify)) ||
  1431. (aifcmd->command ==
  1432. cpu_to_le32(AifCmdJobProgress))) {
  1433. aac_handle_aif(dev, fib);
  1434. }
  1435. time_now = jiffies/HZ;
  1436. /*
  1437. * Warning: no sleep allowed while
  1438. * holding spinlock. We take the estimate
  1439. * and pre-allocate a set of fibs outside the
  1440. * lock.
  1441. */
  1442. num = le32_to_cpu(dev->init->AdapterFibsSize)
  1443. / sizeof(struct hw_fib); /* some extra */
  1444. spin_lock_irqsave(&dev->fib_lock, flagv);
  1445. entry = dev->fib_list.next;
  1446. while (entry != &dev->fib_list) {
  1447. entry = entry->next;
  1448. ++num;
  1449. }
  1450. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1451. hw_fib_pool = NULL;
  1452. fib_pool = NULL;
  1453. if (num
  1454. && ((hw_fib_pool = kmalloc(sizeof(struct hw_fib *) * num, GFP_KERNEL)))
  1455. && ((fib_pool = kmalloc(sizeof(struct fib *) * num, GFP_KERNEL)))) {
  1456. hw_fib_p = hw_fib_pool;
  1457. fib_p = fib_pool;
  1458. while (hw_fib_p < &hw_fib_pool[num]) {
  1459. if (!(*(hw_fib_p++) = kmalloc(sizeof(struct hw_fib), GFP_KERNEL))) {
  1460. --hw_fib_p;
  1461. break;
  1462. }
  1463. if (!(*(fib_p++) = kmalloc(sizeof(struct fib), GFP_KERNEL))) {
  1464. kfree(*(--hw_fib_p));
  1465. break;
  1466. }
  1467. }
  1468. if ((num = hw_fib_p - hw_fib_pool) == 0) {
  1469. kfree(fib_pool);
  1470. fib_pool = NULL;
  1471. kfree(hw_fib_pool);
  1472. hw_fib_pool = NULL;
  1473. }
  1474. } else {
  1475. kfree(hw_fib_pool);
  1476. hw_fib_pool = NULL;
  1477. }
  1478. spin_lock_irqsave(&dev->fib_lock, flagv);
  1479. entry = dev->fib_list.next;
  1480. /*
  1481. * For each Context that is on the
  1482. * fibctxList, make a copy of the
  1483. * fib, and then set the event to wake up the
  1484. * thread that is waiting for it.
  1485. */
  1486. hw_fib_p = hw_fib_pool;
  1487. fib_p = fib_pool;
  1488. while (entry != &dev->fib_list) {
  1489. /*
  1490. * Extract the fibctx
  1491. */
  1492. fibctx = list_entry(entry, struct aac_fib_context, next);
  1493. /*
  1494. * Check if the queue is getting
  1495. * backlogged
  1496. */
  1497. if (fibctx->count > 20)
  1498. {
  1499. /*
  1500. * It's *not* jiffies folks,
  1501. * but jiffies / HZ so do not
  1502. * panic ...
  1503. */
  1504. time_last = fibctx->jiffies;
  1505. /*
  1506. * Has it been > 2 minutes
  1507. * since the last read off
  1508. * the queue?
  1509. */
  1510. if ((time_now - time_last) > aif_timeout) {
  1511. entry = entry->next;
  1512. aac_close_fib_context(dev, fibctx);
  1513. continue;
  1514. }
  1515. }
  1516. /*
  1517. * Warning: no sleep allowed while
  1518. * holding spinlock
  1519. */
  1520. if (hw_fib_p < &hw_fib_pool[num]) {
  1521. hw_newfib = *hw_fib_p;
  1522. *(hw_fib_p++) = NULL;
  1523. newfib = *fib_p;
  1524. *(fib_p++) = NULL;
  1525. /*
  1526. * Make the copy of the FIB
  1527. */
  1528. memcpy(hw_newfib, hw_fib, sizeof(struct hw_fib));
  1529. memcpy(newfib, fib, sizeof(struct fib));
  1530. newfib->hw_fib_va = hw_newfib;
  1531. /*
  1532. * Put the FIB onto the
  1533. * fibctx's fibs
  1534. */
  1535. list_add_tail(&newfib->fiblink, &fibctx->fib_list);
  1536. fibctx->count++;
  1537. /*
  1538. * Set the event to wake up the
  1539. * thread that is waiting.
  1540. */
  1541. up(&fibctx->wait_sem);
  1542. } else {
  1543. printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
  1544. }
  1545. entry = entry->next;
  1546. }
  1547. /*
  1548. * Set the status of this FIB
  1549. */
  1550. *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
  1551. aac_fib_adapter_complete(fib, sizeof(u32));
  1552. spin_unlock_irqrestore(&dev->fib_lock, flagv);
  1553. /* Free up the remaining resources */
  1554. hw_fib_p = hw_fib_pool;
  1555. fib_p = fib_pool;
  1556. while (hw_fib_p < &hw_fib_pool[num]) {
  1557. kfree(*hw_fib_p);
  1558. kfree(*fib_p);
  1559. ++fib_p;
  1560. ++hw_fib_p;
  1561. }
  1562. kfree(hw_fib_pool);
  1563. kfree(fib_pool);
  1564. }
  1565. kfree(fib);
  1566. spin_lock_irqsave(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1567. }
  1568. /*
  1569. * There are no more AIF's
  1570. */
  1571. spin_unlock_irqrestore(dev->queues->queue[HostNormCmdQueue].lock, flags);
  1572. /*
  1573. * Background activity
  1574. */
  1575. if ((time_before(next_check_jiffies,next_jiffies))
  1576. && ((difference = next_check_jiffies - jiffies) <= 0)) {
  1577. next_check_jiffies = next_jiffies;
  1578. if (aac_check_health(dev) == 0) {
  1579. difference = ((long)(unsigned)check_interval)
  1580. * HZ;
  1581. next_check_jiffies = jiffies + difference;
  1582. } else if (!dev->queues)
  1583. break;
  1584. }
  1585. if (!time_before(next_check_jiffies,next_jiffies)
  1586. && ((difference = next_jiffies - jiffies) <= 0)) {
  1587. struct timeval now;
  1588. int ret;
  1589. /* Don't even try to talk to adapter if its sick */
  1590. ret = aac_check_health(dev);
  1591. if (!ret && !dev->queues)
  1592. break;
  1593. next_check_jiffies = jiffies
  1594. + ((long)(unsigned)check_interval)
  1595. * HZ;
  1596. do_gettimeofday(&now);
  1597. /* Synchronize our watches */
  1598. if (((1000000 - (1000000 / HZ)) > now.tv_usec)
  1599. && (now.tv_usec > (1000000 / HZ)))
  1600. difference = (((1000000 - now.tv_usec) * HZ)
  1601. + 500000) / 1000000;
  1602. else if (ret == 0) {
  1603. struct fib *fibptr;
  1604. if ((fibptr = aac_fib_alloc(dev))) {
  1605. __le32 *info;
  1606. aac_fib_init(fibptr);
  1607. info = (__le32 *) fib_data(fibptr);
  1608. if (now.tv_usec > 500000)
  1609. ++now.tv_sec;
  1610. *info = cpu_to_le32(now.tv_sec);
  1611. (void)aac_fib_send(SendHostTime,
  1612. fibptr,
  1613. sizeof(*info),
  1614. FsaNormal,
  1615. 1, 1,
  1616. NULL,
  1617. NULL);
  1618. aac_fib_complete(fibptr);
  1619. aac_fib_free(fibptr);
  1620. }
  1621. difference = (long)(unsigned)update_interval*HZ;
  1622. } else {
  1623. /* retry shortly */
  1624. difference = 10 * HZ;
  1625. }
  1626. next_jiffies = jiffies + difference;
  1627. if (time_before(next_check_jiffies,next_jiffies))
  1628. difference = next_check_jiffies - jiffies;
  1629. }
  1630. if (difference <= 0)
  1631. difference = 1;
  1632. set_current_state(TASK_INTERRUPTIBLE);
  1633. schedule_timeout(difference);
  1634. if (kthread_should_stop())
  1635. break;
  1636. }
  1637. if (dev->queues)
  1638. remove_wait_queue(&dev->queues->queue[HostNormCmdQueue].cmdready, &wait);
  1639. dev->aif_thread = 0;
  1640. return 0;
  1641. }