rx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Adaptec AAC series RAID controller driver
  3. * (c) Copyright 2001 Red Hat Inc.
  4. *
  5. * based on the old aacraid driver that is..
  6. * Adaptec aacraid device driver for Linux.
  7. *
  8. * Copyright (c) 2000-2010 Adaptec, Inc.
  9. * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Module Name:
  26. * rx.c
  27. *
  28. * Abstract: Hardware miniport for Drawbridge specific hardware functions.
  29. *
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/init.h>
  33. #include <linux/types.h>
  34. #include <linux/pci.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/blkdev.h>
  37. #include <linux/delay.h>
  38. #include <linux/completion.h>
  39. #include <linux/time.h>
  40. #include <linux/interrupt.h>
  41. #include <scsi/scsi_host.h>
  42. #include "aacraid.h"
  43. static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id)
  44. {
  45. struct aac_dev *dev = dev_id;
  46. unsigned long bellbits;
  47. u8 intstat = rx_readb(dev, MUnit.OISR);
  48. /*
  49. * Read mask and invert because drawbridge is reversed.
  50. * This allows us to only service interrupts that have
  51. * been enabled.
  52. * Check to see if this is our interrupt. If it isn't just return
  53. */
  54. if (likely(intstat & ~(dev->OIMR))) {
  55. bellbits = rx_readl(dev, OutboundDoorbellReg);
  56. if (unlikely(bellbits & DoorBellPrintfReady)) {
  57. aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
  58. rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
  59. rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
  60. }
  61. else if (unlikely(bellbits & DoorBellAdapterNormCmdReady)) {
  62. rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
  63. aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
  64. }
  65. else if (likely(bellbits & DoorBellAdapterNormRespReady)) {
  66. rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
  67. aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
  68. }
  69. else if (unlikely(bellbits & DoorBellAdapterNormCmdNotFull)) {
  70. rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  71. }
  72. else if (unlikely(bellbits & DoorBellAdapterNormRespNotFull)) {
  73. rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  74. rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
  75. }
  76. return IRQ_HANDLED;
  77. }
  78. return IRQ_NONE;
  79. }
  80. static irqreturn_t aac_rx_intr_message(int irq, void *dev_id)
  81. {
  82. int isAif, isFastResponse, isSpecial;
  83. struct aac_dev *dev = dev_id;
  84. u32 Index = rx_readl(dev, MUnit.OutboundQueue);
  85. if (unlikely(Index == 0xFFFFFFFFL))
  86. Index = rx_readl(dev, MUnit.OutboundQueue);
  87. if (likely(Index != 0xFFFFFFFFL)) {
  88. do {
  89. isAif = isFastResponse = isSpecial = 0;
  90. if (Index & 0x00000002L) {
  91. isAif = 1;
  92. if (Index == 0xFFFFFFFEL)
  93. isSpecial = 1;
  94. Index &= ~0x00000002L;
  95. } else {
  96. if (Index & 0x00000001L)
  97. isFastResponse = 1;
  98. Index >>= 2;
  99. }
  100. if (!isSpecial) {
  101. if (unlikely(aac_intr_normal(dev,
  102. Index, isAif,
  103. isFastResponse, NULL))) {
  104. rx_writel(dev,
  105. MUnit.OutboundQueue,
  106. Index);
  107. rx_writel(dev,
  108. MUnit.ODR,
  109. DoorBellAdapterNormRespReady);
  110. }
  111. }
  112. Index = rx_readl(dev, MUnit.OutboundQueue);
  113. } while (Index != 0xFFFFFFFFL);
  114. return IRQ_HANDLED;
  115. }
  116. return IRQ_NONE;
  117. }
  118. /**
  119. * aac_rx_disable_interrupt - Disable interrupts
  120. * @dev: Adapter
  121. */
  122. static void aac_rx_disable_interrupt(struct aac_dev *dev)
  123. {
  124. rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  125. }
  126. /**
  127. * aac_rx_enable_interrupt_producer - Enable interrupts
  128. * @dev: Adapter
  129. */
  130. static void aac_rx_enable_interrupt_producer(struct aac_dev *dev)
  131. {
  132. rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  133. }
  134. /**
  135. * aac_rx_enable_interrupt_message - Enable interrupts
  136. * @dev: Adapter
  137. */
  138. static void aac_rx_enable_interrupt_message(struct aac_dev *dev)
  139. {
  140. rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
  141. }
  142. /**
  143. * rx_sync_cmd - send a command and wait
  144. * @dev: Adapter
  145. * @command: Command to execute
  146. * @p1: first parameter
  147. * @ret: adapter status
  148. *
  149. * This routine will send a synchronous command to the adapter and wait
  150. * for its completion.
  151. */
  152. static int rx_sync_cmd(struct aac_dev *dev, u32 command,
  153. u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
  154. u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
  155. {
  156. unsigned long start;
  157. int ok;
  158. /*
  159. * Write the command into Mailbox 0
  160. */
  161. writel(command, &dev->IndexRegs->Mailbox[0]);
  162. /*
  163. * Write the parameters into Mailboxes 1 - 6
  164. */
  165. writel(p1, &dev->IndexRegs->Mailbox[1]);
  166. writel(p2, &dev->IndexRegs->Mailbox[2]);
  167. writel(p3, &dev->IndexRegs->Mailbox[3]);
  168. writel(p4, &dev->IndexRegs->Mailbox[4]);
  169. /*
  170. * Clear the synch command doorbell to start on a clean slate.
  171. */
  172. rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  173. /*
  174. * Disable doorbell interrupts
  175. */
  176. rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  177. /*
  178. * Force the completion of the mask register write before issuing
  179. * the interrupt.
  180. */
  181. rx_readb (dev, MUnit.OIMR);
  182. /*
  183. * Signal that there is a new synch command
  184. */
  185. rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
  186. ok = 0;
  187. start = jiffies;
  188. /*
  189. * Wait up to 30 seconds
  190. */
  191. while (time_before(jiffies, start+30*HZ))
  192. {
  193. udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
  194. /*
  195. * Mon960 will set doorbell0 bit when it has completed the command.
  196. */
  197. if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
  198. /*
  199. * Clear the doorbell.
  200. */
  201. rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  202. ok = 1;
  203. break;
  204. }
  205. /*
  206. * Yield the processor in case we are slow
  207. */
  208. msleep(1);
  209. }
  210. if (unlikely(ok != 1)) {
  211. /*
  212. * Restore interrupt mask even though we timed out
  213. */
  214. aac_adapter_enable_int(dev);
  215. return -ETIMEDOUT;
  216. }
  217. /*
  218. * Pull the synch status from Mailbox 0.
  219. */
  220. if (status)
  221. *status = readl(&dev->IndexRegs->Mailbox[0]);
  222. if (r1)
  223. *r1 = readl(&dev->IndexRegs->Mailbox[1]);
  224. if (r2)
  225. *r2 = readl(&dev->IndexRegs->Mailbox[2]);
  226. if (r3)
  227. *r3 = readl(&dev->IndexRegs->Mailbox[3]);
  228. if (r4)
  229. *r4 = readl(&dev->IndexRegs->Mailbox[4]);
  230. /*
  231. * Clear the synch command doorbell.
  232. */
  233. rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  234. /*
  235. * Restore interrupt mask
  236. */
  237. aac_adapter_enable_int(dev);
  238. return 0;
  239. }
  240. /**
  241. * aac_rx_interrupt_adapter - interrupt adapter
  242. * @dev: Adapter
  243. *
  244. * Send an interrupt to the i960 and breakpoint it.
  245. */
  246. static void aac_rx_interrupt_adapter(struct aac_dev *dev)
  247. {
  248. rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  249. }
  250. /**
  251. * aac_rx_notify_adapter - send an event to the adapter
  252. * @dev: Adapter
  253. * @event: Event to send
  254. *
  255. * Notify the i960 that something it probably cares about has
  256. * happened.
  257. */
  258. static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event)
  259. {
  260. switch (event) {
  261. case AdapNormCmdQue:
  262. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
  263. break;
  264. case HostNormRespNotFull:
  265. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
  266. break;
  267. case AdapNormRespQue:
  268. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
  269. break;
  270. case HostNormCmdNotFull:
  271. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
  272. break;
  273. case HostShutdown:
  274. break;
  275. case FastIo:
  276. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
  277. break;
  278. case AdapPrintfDone:
  279. rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
  280. break;
  281. default:
  282. BUG();
  283. break;
  284. }
  285. }
  286. /**
  287. * aac_rx_start_adapter - activate adapter
  288. * @dev: Adapter
  289. *
  290. * Start up processing on an i960 based AAC adapter
  291. */
  292. static void aac_rx_start_adapter(struct aac_dev *dev)
  293. {
  294. struct aac_init *init;
  295. init = dev->init;
  296. init->HostElapsedSeconds = cpu_to_le32(get_seconds());
  297. // We can only use a 32 bit address here
  298. rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
  299. 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  300. }
  301. /**
  302. * aac_rx_check_health
  303. * @dev: device to check if healthy
  304. *
  305. * Will attempt to determine if the specified adapter is alive and
  306. * capable of handling requests, returning 0 if alive.
  307. */
  308. static int aac_rx_check_health(struct aac_dev *dev)
  309. {
  310. u32 status = rx_readl(dev, MUnit.OMRx[0]);
  311. /*
  312. * Check to see if the board failed any self tests.
  313. */
  314. if (unlikely(status & SELF_TEST_FAILED))
  315. return -1;
  316. /*
  317. * Check to see if the board panic'd.
  318. */
  319. if (unlikely(status & KERNEL_PANIC)) {
  320. char * buffer;
  321. struct POSTSTATUS {
  322. __le32 Post_Command;
  323. __le32 Post_Address;
  324. } * post;
  325. dma_addr_t paddr, baddr;
  326. int ret;
  327. if (likely((status & 0xFF000000L) == 0xBC000000L))
  328. return (status >> 16) & 0xFF;
  329. buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
  330. ret = -2;
  331. if (unlikely(buffer == NULL))
  332. return ret;
  333. post = pci_alloc_consistent(dev->pdev,
  334. sizeof(struct POSTSTATUS), &paddr);
  335. if (unlikely(post == NULL)) {
  336. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  337. return ret;
  338. }
  339. memset(buffer, 0, 512);
  340. post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
  341. post->Post_Address = cpu_to_le32(baddr);
  342. rx_writel(dev, MUnit.IMRx[0], paddr);
  343. rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
  344. NULL, NULL, NULL, NULL, NULL);
  345. pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
  346. post, paddr);
  347. if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) {
  348. ret = (hex_to_bin(buffer[2]) << 4) +
  349. hex_to_bin(buffer[3]);
  350. }
  351. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  352. return ret;
  353. }
  354. /*
  355. * Wait for the adapter to be up and running.
  356. */
  357. if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
  358. return -3;
  359. /*
  360. * Everything is OK
  361. */
  362. return 0;
  363. }
  364. /**
  365. * aac_rx_deliver_producer
  366. * @fib: fib to issue
  367. *
  368. * Will send a fib, returning 0 if successful.
  369. */
  370. int aac_rx_deliver_producer(struct fib * fib)
  371. {
  372. struct aac_dev *dev = fib->dev;
  373. struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
  374. unsigned long qflags;
  375. u32 Index;
  376. unsigned long nointr = 0;
  377. spin_lock_irqsave(q->lock, qflags);
  378. aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib_va, 1, fib, &nointr);
  379. q->numpending++;
  380. *(q->headers.producer) = cpu_to_le32(Index + 1);
  381. spin_unlock_irqrestore(q->lock, qflags);
  382. if (!(nointr & aac_config.irq_mod))
  383. aac_adapter_notify(dev, AdapNormCmdQueue);
  384. return 0;
  385. }
  386. /**
  387. * aac_rx_deliver_message
  388. * @fib: fib to issue
  389. *
  390. * Will send a fib, returning 0 if successful.
  391. */
  392. static int aac_rx_deliver_message(struct fib * fib)
  393. {
  394. struct aac_dev *dev = fib->dev;
  395. struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
  396. unsigned long qflags;
  397. u32 Index;
  398. u64 addr;
  399. volatile void __iomem *device;
  400. unsigned long count = 10000000L; /* 50 seconds */
  401. spin_lock_irqsave(q->lock, qflags);
  402. q->numpending++;
  403. spin_unlock_irqrestore(q->lock, qflags);
  404. for(;;) {
  405. Index = rx_readl(dev, MUnit.InboundQueue);
  406. if (unlikely(Index == 0xFFFFFFFFL))
  407. Index = rx_readl(dev, MUnit.InboundQueue);
  408. if (likely(Index != 0xFFFFFFFFL))
  409. break;
  410. if (--count == 0) {
  411. spin_lock_irqsave(q->lock, qflags);
  412. q->numpending--;
  413. spin_unlock_irqrestore(q->lock, qflags);
  414. return -ETIMEDOUT;
  415. }
  416. udelay(5);
  417. }
  418. device = dev->base + Index;
  419. addr = fib->hw_fib_pa;
  420. writel((u32)(addr & 0xffffffff), device);
  421. device += sizeof(u32);
  422. writel((u32)(addr >> 32), device);
  423. device += sizeof(u32);
  424. writel(le16_to_cpu(fib->hw_fib_va->header.Size), device);
  425. rx_writel(dev, MUnit.InboundQueue, Index);
  426. return 0;
  427. }
  428. /**
  429. * aac_rx_ioremap
  430. * @size: mapping resize request
  431. *
  432. */
  433. static int aac_rx_ioremap(struct aac_dev * dev, u32 size)
  434. {
  435. if (!size) {
  436. iounmap(dev->regs.rx);
  437. return 0;
  438. }
  439. dev->base = dev->regs.rx = ioremap(dev->scsi_host_ptr->base, size);
  440. if (dev->base == NULL)
  441. return -1;
  442. dev->IndexRegs = &dev->regs.rx->IndexRegs;
  443. return 0;
  444. }
  445. static int aac_rx_restart_adapter(struct aac_dev *dev, int bled)
  446. {
  447. u32 var;
  448. if (!(dev->supplement_adapter_info.SupportedOptions2 &
  449. AAC_OPTION_MU_RESET) || (bled >= 0) || (bled == -2)) {
  450. if (bled)
  451. printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n",
  452. dev->name, dev->id, bled);
  453. else {
  454. bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
  455. 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL);
  456. if (!bled && (var != 0x00000001) && (var != 0x3803000F))
  457. bled = -EINVAL;
  458. }
  459. if (bled && (bled != -ETIMEDOUT))
  460. bled = aac_adapter_sync_cmd(dev, IOP_RESET,
  461. 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL);
  462. if (bled && (bled != -ETIMEDOUT))
  463. return -EINVAL;
  464. }
  465. if (bled || (var == 0x3803000F)) { /* USE_OTHER_METHOD */
  466. rx_writel(dev, MUnit.reserved2, 3);
  467. msleep(5000); /* Delay 5 seconds */
  468. var = 0x00000001;
  469. }
  470. if (var != 0x00000001)
  471. return -EINVAL;
  472. if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC)
  473. return -ENODEV;
  474. if (startup_timeout < 300)
  475. startup_timeout = 300;
  476. return 0;
  477. }
  478. /**
  479. * aac_rx_select_comm - Select communications method
  480. * @dev: Adapter
  481. * @comm: communications method
  482. */
  483. int aac_rx_select_comm(struct aac_dev *dev, int comm)
  484. {
  485. switch (comm) {
  486. case AAC_COMM_PRODUCER:
  487. dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_producer;
  488. dev->a_ops.adapter_intr = aac_rx_intr_producer;
  489. dev->a_ops.adapter_deliver = aac_rx_deliver_producer;
  490. break;
  491. case AAC_COMM_MESSAGE:
  492. dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_message;
  493. dev->a_ops.adapter_intr = aac_rx_intr_message;
  494. dev->a_ops.adapter_deliver = aac_rx_deliver_message;
  495. break;
  496. default:
  497. return 1;
  498. }
  499. return 0;
  500. }
  501. /**
  502. * aac_rx_init - initialize an i960 based AAC card
  503. * @dev: device to configure
  504. *
  505. * Allocate and set up resources for the i960 based AAC variants. The
  506. * device_interface in the commregion will be allocated and linked
  507. * to the comm region.
  508. */
  509. int _aac_rx_init(struct aac_dev *dev)
  510. {
  511. unsigned long start;
  512. unsigned long status;
  513. int restart = 0;
  514. int instance = dev->id;
  515. const char * name = dev->name;
  516. if (aac_adapter_ioremap(dev, dev->base_size)) {
  517. printk(KERN_WARNING "%s: unable to map adapter.\n", name);
  518. goto error_iounmap;
  519. }
  520. /* Failure to reset here is an option ... */
  521. dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
  522. dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt;
  523. dev->OIMR = status = rx_readb (dev, MUnit.OIMR);
  524. if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) &&
  525. !aac_rx_restart_adapter(dev, 0))
  526. /* Make sure the Hardware FIFO is empty */
  527. while ((++restart < 512) &&
  528. (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL));
  529. /*
  530. * Check to see if the board panic'd while booting.
  531. */
  532. status = rx_readl(dev, MUnit.OMRx[0]);
  533. if (status & KERNEL_PANIC) {
  534. if (aac_rx_restart_adapter(dev, aac_rx_check_health(dev)))
  535. goto error_iounmap;
  536. ++restart;
  537. }
  538. /*
  539. * Check to see if the board failed any self tests.
  540. */
  541. status = rx_readl(dev, MUnit.OMRx[0]);
  542. if (status & SELF_TEST_FAILED) {
  543. printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
  544. goto error_iounmap;
  545. }
  546. /*
  547. * Check to see if the monitor panic'd while booting.
  548. */
  549. if (status & MONITOR_PANIC) {
  550. printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
  551. goto error_iounmap;
  552. }
  553. start = jiffies;
  554. /*
  555. * Wait for the adapter to be up and running. Wait up to 3 minutes
  556. */
  557. while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING))
  558. {
  559. if ((restart &&
  560. (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
  561. time_after(jiffies, start+HZ*startup_timeout)) {
  562. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  563. dev->name, instance, status);
  564. goto error_iounmap;
  565. }
  566. if (!restart &&
  567. ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
  568. time_after(jiffies, start + HZ *
  569. ((startup_timeout > 60)
  570. ? (startup_timeout - 60)
  571. : (startup_timeout / 2))))) {
  572. if (likely(!aac_rx_restart_adapter(dev, aac_rx_check_health(dev))))
  573. start = jiffies;
  574. ++restart;
  575. }
  576. msleep(1);
  577. }
  578. if (restart && aac_commit)
  579. aac_commit = 1;
  580. /*
  581. * Fill in the common function dispatch table.
  582. */
  583. dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
  584. dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
  585. dev->a_ops.adapter_notify = aac_rx_notify_adapter;
  586. dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
  587. dev->a_ops.adapter_check_health = aac_rx_check_health;
  588. dev->a_ops.adapter_restart = aac_rx_restart_adapter;
  589. /*
  590. * First clear out all interrupts. Then enable the one's that we
  591. * can handle.
  592. */
  593. aac_adapter_comm(dev, AAC_COMM_PRODUCER);
  594. aac_adapter_disable_int(dev);
  595. rx_writel(dev, MUnit.ODR, 0xffffffff);
  596. aac_adapter_enable_int(dev);
  597. if (aac_init_adapter(dev) == NULL)
  598. goto error_iounmap;
  599. aac_adapter_comm(dev, dev->comm_interface);
  600. dev->sync_mode = 0; /* sync. mode not supported */
  601. dev->msi = aac_msi && !pci_enable_msi(dev->pdev);
  602. if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
  603. IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) {
  604. if (dev->msi)
  605. pci_disable_msi(dev->pdev);
  606. printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
  607. name, instance);
  608. goto error_iounmap;
  609. }
  610. dev->dbg_base = dev->scsi_host_ptr->base;
  611. dev->dbg_base_mapped = dev->base;
  612. dev->dbg_size = dev->base_size;
  613. aac_adapter_enable_int(dev);
  614. /*
  615. * Tell the adapter that all is configured, and it can
  616. * start accepting requests
  617. */
  618. aac_rx_start_adapter(dev);
  619. return 0;
  620. error_iounmap:
  621. return -1;
  622. }
  623. int aac_rx_init(struct aac_dev *dev)
  624. {
  625. /*
  626. * Fill in the function dispatch table.
  627. */
  628. dev->a_ops.adapter_ioremap = aac_rx_ioremap;
  629. dev->a_ops.adapter_comm = aac_rx_select_comm;
  630. return _aac_rx_init(dev);
  631. }