src.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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. * src.c
  27. *
  28. * Abstract: Hardware Device Interface for PMC SRC based controllers
  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/slab.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/delay.h>
  39. #include <linux/completion.h>
  40. #include <linux/time.h>
  41. #include <linux/interrupt.h>
  42. #include <scsi/scsi_host.h>
  43. #include "aacraid.h"
  44. static irqreturn_t aac_src_intr_message(int irq, void *dev_id)
  45. {
  46. struct aac_dev *dev = dev_id;
  47. unsigned long bellbits, bellbits_shifted;
  48. int our_interrupt = 0;
  49. int isFastResponse;
  50. u32 index, handle;
  51. bellbits = src_readl(dev, MUnit.ODR_R);
  52. if (bellbits & PmDoorBellResponseSent) {
  53. bellbits = PmDoorBellResponseSent;
  54. /* handle async. status */
  55. our_interrupt = 1;
  56. index = dev->host_rrq_idx;
  57. if (dev->host_rrq[index] == 0) {
  58. u32 old_index = index;
  59. /* adjust index */
  60. do {
  61. index++;
  62. if (index == dev->scsi_host_ptr->can_queue +
  63. AAC_NUM_MGT_FIB)
  64. index = 0;
  65. if (dev->host_rrq[index] != 0)
  66. break;
  67. } while (index != old_index);
  68. dev->host_rrq_idx = index;
  69. }
  70. for (;;) {
  71. isFastResponse = 0;
  72. /* remove toggle bit (31) */
  73. handle = (dev->host_rrq[index] & 0x7fffffff);
  74. /* check fast response bit (30) */
  75. if (handle & 0x40000000)
  76. isFastResponse = 1;
  77. handle &= 0x0000ffff;
  78. if (handle == 0)
  79. break;
  80. aac_intr_normal(dev, handle-1, 0, isFastResponse, NULL);
  81. dev->host_rrq[index++] = 0;
  82. if (index == dev->scsi_host_ptr->can_queue +
  83. AAC_NUM_MGT_FIB)
  84. index = 0;
  85. dev->host_rrq_idx = index;
  86. }
  87. } else {
  88. bellbits_shifted = (bellbits >> SRC_ODR_SHIFT);
  89. if (bellbits_shifted & DoorBellAifPending) {
  90. our_interrupt = 1;
  91. /* handle AIF */
  92. aac_intr_normal(dev, 0, 2, 0, NULL);
  93. } else if (bellbits_shifted & OUTBOUNDDOORBELL_0) {
  94. unsigned long sflags;
  95. struct list_head *entry;
  96. int send_it = 0;
  97. if (dev->sync_fib) {
  98. our_interrupt = 1;
  99. if (dev->sync_fib->callback)
  100. dev->sync_fib->callback(dev->sync_fib->callback_data,
  101. dev->sync_fib);
  102. spin_lock_irqsave(&dev->sync_fib->event_lock, sflags);
  103. if (dev->sync_fib->flags & FIB_CONTEXT_FLAG_WAIT) {
  104. dev->management_fib_count--;
  105. up(&dev->sync_fib->event_wait);
  106. }
  107. spin_unlock_irqrestore(&dev->sync_fib->event_lock, sflags);
  108. spin_lock_irqsave(&dev->sync_lock, sflags);
  109. if (!list_empty(&dev->sync_fib_list)) {
  110. entry = dev->sync_fib_list.next;
  111. dev->sync_fib = list_entry(entry, struct fib, fiblink);
  112. list_del(entry);
  113. send_it = 1;
  114. } else {
  115. dev->sync_fib = NULL;
  116. }
  117. spin_unlock_irqrestore(&dev->sync_lock, sflags);
  118. if (send_it) {
  119. aac_adapter_sync_cmd(dev, SEND_SYNCHRONOUS_FIB,
  120. (u32)dev->sync_fib->hw_fib_pa, 0, 0, 0, 0, 0,
  121. NULL, NULL, NULL, NULL, NULL);
  122. }
  123. }
  124. }
  125. }
  126. if (our_interrupt) {
  127. src_writel(dev, MUnit.ODR_C, bellbits);
  128. return IRQ_HANDLED;
  129. }
  130. return IRQ_NONE;
  131. }
  132. /**
  133. * aac_src_disable_interrupt - Disable interrupts
  134. * @dev: Adapter
  135. */
  136. static void aac_src_disable_interrupt(struct aac_dev *dev)
  137. {
  138. src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
  139. }
  140. /**
  141. * aac_src_enable_interrupt_message - Enable interrupts
  142. * @dev: Adapter
  143. */
  144. static void aac_src_enable_interrupt_message(struct aac_dev *dev)
  145. {
  146. src_writel(dev, MUnit.OIMR, dev->OIMR = 0xfffffff8);
  147. }
  148. /**
  149. * src_sync_cmd - send a command and wait
  150. * @dev: Adapter
  151. * @command: Command to execute
  152. * @p1: first parameter
  153. * @ret: adapter status
  154. *
  155. * This routine will send a synchronous command to the adapter and wait
  156. * for its completion.
  157. */
  158. static int src_sync_cmd(struct aac_dev *dev, u32 command,
  159. u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
  160. u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
  161. {
  162. unsigned long start;
  163. int ok;
  164. /*
  165. * Write the command into Mailbox 0
  166. */
  167. writel(command, &dev->IndexRegs->Mailbox[0]);
  168. /*
  169. * Write the parameters into Mailboxes 1 - 6
  170. */
  171. writel(p1, &dev->IndexRegs->Mailbox[1]);
  172. writel(p2, &dev->IndexRegs->Mailbox[2]);
  173. writel(p3, &dev->IndexRegs->Mailbox[3]);
  174. writel(p4, &dev->IndexRegs->Mailbox[4]);
  175. /*
  176. * Clear the synch command doorbell to start on a clean slate.
  177. */
  178. src_writel(dev, MUnit.ODR_C, OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  179. /*
  180. * Disable doorbell interrupts
  181. */
  182. src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
  183. /*
  184. * Force the completion of the mask register write before issuing
  185. * the interrupt.
  186. */
  187. src_readl(dev, MUnit.OIMR);
  188. /*
  189. * Signal that there is a new synch command
  190. */
  191. src_writel(dev, MUnit.IDR, INBOUNDDOORBELL_0 << SRC_IDR_SHIFT);
  192. if (!dev->sync_mode || command != SEND_SYNCHRONOUS_FIB) {
  193. ok = 0;
  194. start = jiffies;
  195. /*
  196. * Wait up to 5 minutes
  197. */
  198. while (time_before(jiffies, start+300*HZ)) {
  199. udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
  200. /*
  201. * Mon960 will set doorbell0 bit when it has completed the command.
  202. */
  203. if ((src_readl(dev, MUnit.ODR_R) >> SRC_ODR_SHIFT) & OUTBOUNDDOORBELL_0) {
  204. /*
  205. * Clear the doorbell.
  206. */
  207. src_writel(dev, MUnit.ODR_C, OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  208. ok = 1;
  209. break;
  210. }
  211. /*
  212. * Yield the processor in case we are slow
  213. */
  214. msleep(1);
  215. }
  216. if (unlikely(ok != 1)) {
  217. /*
  218. * Restore interrupt mask even though we timed out
  219. */
  220. aac_adapter_enable_int(dev);
  221. return -ETIMEDOUT;
  222. }
  223. /*
  224. * Pull the synch status from Mailbox 0.
  225. */
  226. if (status)
  227. *status = readl(&dev->IndexRegs->Mailbox[0]);
  228. if (r1)
  229. *r1 = readl(&dev->IndexRegs->Mailbox[1]);
  230. if (r2)
  231. *r2 = readl(&dev->IndexRegs->Mailbox[2]);
  232. if (r3)
  233. *r3 = readl(&dev->IndexRegs->Mailbox[3]);
  234. if (r4)
  235. *r4 = readl(&dev->IndexRegs->Mailbox[4]);
  236. /*
  237. * Clear the synch command doorbell.
  238. */
  239. src_writel(dev, MUnit.ODR_C, OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  240. }
  241. /*
  242. * Restore interrupt mask
  243. */
  244. aac_adapter_enable_int(dev);
  245. return 0;
  246. }
  247. /**
  248. * aac_src_interrupt_adapter - interrupt adapter
  249. * @dev: Adapter
  250. *
  251. * Send an interrupt to the i960 and breakpoint it.
  252. */
  253. static void aac_src_interrupt_adapter(struct aac_dev *dev)
  254. {
  255. src_sync_cmd(dev, BREAKPOINT_REQUEST,
  256. 0, 0, 0, 0, 0, 0,
  257. NULL, NULL, NULL, NULL, NULL);
  258. }
  259. /**
  260. * aac_src_notify_adapter - send an event to the adapter
  261. * @dev: Adapter
  262. * @event: Event to send
  263. *
  264. * Notify the i960 that something it probably cares about has
  265. * happened.
  266. */
  267. static void aac_src_notify_adapter(struct aac_dev *dev, u32 event)
  268. {
  269. switch (event) {
  270. case AdapNormCmdQue:
  271. src_writel(dev, MUnit.ODR_C,
  272. INBOUNDDOORBELL_1 << SRC_ODR_SHIFT);
  273. break;
  274. case HostNormRespNotFull:
  275. src_writel(dev, MUnit.ODR_C,
  276. INBOUNDDOORBELL_4 << SRC_ODR_SHIFT);
  277. break;
  278. case AdapNormRespQue:
  279. src_writel(dev, MUnit.ODR_C,
  280. INBOUNDDOORBELL_2 << SRC_ODR_SHIFT);
  281. break;
  282. case HostNormCmdNotFull:
  283. src_writel(dev, MUnit.ODR_C,
  284. INBOUNDDOORBELL_3 << SRC_ODR_SHIFT);
  285. break;
  286. case FastIo:
  287. src_writel(dev, MUnit.ODR_C,
  288. INBOUNDDOORBELL_6 << SRC_ODR_SHIFT);
  289. break;
  290. case AdapPrintfDone:
  291. src_writel(dev, MUnit.ODR_C,
  292. INBOUNDDOORBELL_5 << SRC_ODR_SHIFT);
  293. break;
  294. default:
  295. BUG();
  296. break;
  297. }
  298. }
  299. /**
  300. * aac_src_start_adapter - activate adapter
  301. * @dev: Adapter
  302. *
  303. * Start up processing on an i960 based AAC adapter
  304. */
  305. static void aac_src_start_adapter(struct aac_dev *dev)
  306. {
  307. struct aac_init *init;
  308. init = dev->init;
  309. init->HostElapsedSeconds = cpu_to_le32(get_seconds());
  310. /* We can only use a 32 bit address here */
  311. src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
  312. 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  313. }
  314. /**
  315. * aac_src_check_health
  316. * @dev: device to check if healthy
  317. *
  318. * Will attempt to determine if the specified adapter is alive and
  319. * capable of handling requests, returning 0 if alive.
  320. */
  321. static int aac_src_check_health(struct aac_dev *dev)
  322. {
  323. u32 status = src_readl(dev, MUnit.OMR);
  324. /*
  325. * Check to see if the board failed any self tests.
  326. */
  327. if (unlikely(status & SELF_TEST_FAILED))
  328. return -1;
  329. /*
  330. * Check to see if the board panic'd.
  331. */
  332. if (unlikely(status & KERNEL_PANIC))
  333. return (status >> 16) & 0xFF;
  334. /*
  335. * Wait for the adapter to be up and running.
  336. */
  337. if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
  338. return -3;
  339. /*
  340. * Everything is OK
  341. */
  342. return 0;
  343. }
  344. /**
  345. * aac_src_deliver_message
  346. * @fib: fib to issue
  347. *
  348. * Will send a fib, returning 0 if successful.
  349. */
  350. static int aac_src_deliver_message(struct fib *fib)
  351. {
  352. struct aac_dev *dev = fib->dev;
  353. struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
  354. unsigned long qflags;
  355. u32 fibsize;
  356. u64 address;
  357. struct aac_fib_xporthdr *pFibX;
  358. spin_lock_irqsave(q->lock, qflags);
  359. q->numpending++;
  360. spin_unlock_irqrestore(q->lock, qflags);
  361. /* Calculate the amount to the fibsize bits */
  362. fibsize = (sizeof(struct aac_fib_xporthdr) +
  363. fib->hw_fib_va->header.Size + 127) / 128 - 1;
  364. if (fibsize > (ALIGN32 - 1))
  365. fibsize = ALIGN32 - 1;
  366. /* Fill XPORT header */
  367. pFibX = (struct aac_fib_xporthdr *)
  368. ((unsigned char *)fib->hw_fib_va -
  369. sizeof(struct aac_fib_xporthdr));
  370. pFibX->Handle = fib->hw_fib_va->header.SenderData + 1;
  371. pFibX->HostAddress = fib->hw_fib_pa;
  372. pFibX->Size = fib->hw_fib_va->header.Size;
  373. address = fib->hw_fib_pa - (u64)sizeof(struct aac_fib_xporthdr);
  374. src_writel(dev, MUnit.IQ_H, (u32)(address >> 32));
  375. src_writel(dev, MUnit.IQ_L, (u32)(address & 0xffffffff) + fibsize);
  376. return 0;
  377. }
  378. /**
  379. * aac_src_ioremap
  380. * @size: mapping resize request
  381. *
  382. */
  383. static int aac_src_ioremap(struct aac_dev *dev, u32 size)
  384. {
  385. if (!size) {
  386. iounmap(dev->regs.src.bar0);
  387. dev->base = dev->regs.src.bar0 = NULL;
  388. return 0;
  389. }
  390. dev->regs.src.bar1 = ioremap(pci_resource_start(dev->pdev, 2),
  391. AAC_MIN_SRC_BAR1_SIZE);
  392. dev->base = NULL;
  393. if (dev->regs.src.bar1 == NULL)
  394. return -1;
  395. dev->base = dev->regs.src.bar0 = ioremap(dev->scsi_host_ptr->base,
  396. size);
  397. if (dev->base == NULL) {
  398. iounmap(dev->regs.src.bar1);
  399. dev->regs.src.bar1 = NULL;
  400. return -1;
  401. }
  402. dev->IndexRegs = &((struct src_registers __iomem *)
  403. dev->base)->u.tupelo.IndexRegs;
  404. return 0;
  405. }
  406. /**
  407. * aac_srcv_ioremap
  408. * @size: mapping resize request
  409. *
  410. */
  411. static int aac_srcv_ioremap(struct aac_dev *dev, u32 size)
  412. {
  413. if (!size) {
  414. iounmap(dev->regs.src.bar0);
  415. dev->base = dev->regs.src.bar0 = NULL;
  416. return 0;
  417. }
  418. dev->base = dev->regs.src.bar0 = ioremap(dev->scsi_host_ptr->base, size);
  419. if (dev->base == NULL)
  420. return -1;
  421. dev->IndexRegs = &((struct src_registers __iomem *)
  422. dev->base)->u.denali.IndexRegs;
  423. return 0;
  424. }
  425. static int aac_src_restart_adapter(struct aac_dev *dev, int bled)
  426. {
  427. u32 var, reset_mask;
  428. if (bled >= 0) {
  429. if (bled)
  430. printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n",
  431. dev->name, dev->id, bled);
  432. bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
  433. 0, 0, 0, 0, 0, 0, &var, &reset_mask, NULL, NULL, NULL);
  434. if (bled || (var != 0x00000001))
  435. return -EINVAL;
  436. if (dev->supplement_adapter_info.SupportedOptions2 &
  437. AAC_OPTION_DOORBELL_RESET) {
  438. src_writel(dev, MUnit.IDR, reset_mask);
  439. msleep(5000); /* Delay 5 seconds */
  440. }
  441. }
  442. if (src_readl(dev, MUnit.OMR) & KERNEL_PANIC)
  443. return -ENODEV;
  444. if (startup_timeout < 300)
  445. startup_timeout = 300;
  446. return 0;
  447. }
  448. /**
  449. * aac_src_select_comm - Select communications method
  450. * @dev: Adapter
  451. * @comm: communications method
  452. */
  453. int aac_src_select_comm(struct aac_dev *dev, int comm)
  454. {
  455. switch (comm) {
  456. case AAC_COMM_MESSAGE:
  457. dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
  458. dev->a_ops.adapter_intr = aac_src_intr_message;
  459. dev->a_ops.adapter_deliver = aac_src_deliver_message;
  460. break;
  461. default:
  462. return 1;
  463. }
  464. return 0;
  465. }
  466. /**
  467. * aac_src_init - initialize an Cardinal Frey Bar card
  468. * @dev: device to configure
  469. *
  470. */
  471. int aac_src_init(struct aac_dev *dev)
  472. {
  473. unsigned long start;
  474. unsigned long status;
  475. int restart = 0;
  476. int instance = dev->id;
  477. const char *name = dev->name;
  478. dev->a_ops.adapter_ioremap = aac_src_ioremap;
  479. dev->a_ops.adapter_comm = aac_src_select_comm;
  480. dev->base_size = AAC_MIN_SRC_BAR0_SIZE;
  481. if (aac_adapter_ioremap(dev, dev->base_size)) {
  482. printk(KERN_WARNING "%s: unable to map adapter.\n", name);
  483. goto error_iounmap;
  484. }
  485. /* Failure to reset here is an option ... */
  486. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  487. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  488. if ((aac_reset_devices || reset_devices) &&
  489. !aac_src_restart_adapter(dev, 0))
  490. ++restart;
  491. /*
  492. * Check to see if the board panic'd while booting.
  493. */
  494. status = src_readl(dev, MUnit.OMR);
  495. if (status & KERNEL_PANIC) {
  496. if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
  497. goto error_iounmap;
  498. ++restart;
  499. }
  500. /*
  501. * Check to see if the board failed any self tests.
  502. */
  503. status = src_readl(dev, MUnit.OMR);
  504. if (status & SELF_TEST_FAILED) {
  505. printk(KERN_ERR "%s%d: adapter self-test failed.\n",
  506. dev->name, instance);
  507. goto error_iounmap;
  508. }
  509. /*
  510. * Check to see if the monitor panic'd while booting.
  511. */
  512. if (status & MONITOR_PANIC) {
  513. printk(KERN_ERR "%s%d: adapter monitor panic.\n",
  514. dev->name, instance);
  515. goto error_iounmap;
  516. }
  517. start = jiffies;
  518. /*
  519. * Wait for the adapter to be up and running. Wait up to 3 minutes
  520. */
  521. while (!((status = src_readl(dev, MUnit.OMR)) &
  522. KERNEL_UP_AND_RUNNING)) {
  523. if ((restart &&
  524. (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
  525. time_after(jiffies, start+HZ*startup_timeout)) {
  526. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  527. dev->name, instance, status);
  528. goto error_iounmap;
  529. }
  530. if (!restart &&
  531. ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
  532. time_after(jiffies, start + HZ *
  533. ((startup_timeout > 60)
  534. ? (startup_timeout - 60)
  535. : (startup_timeout / 2))))) {
  536. if (likely(!aac_src_restart_adapter(dev,
  537. aac_src_check_health(dev))))
  538. start = jiffies;
  539. ++restart;
  540. }
  541. msleep(1);
  542. }
  543. if (restart && aac_commit)
  544. aac_commit = 1;
  545. /*
  546. * Fill in the common function dispatch table.
  547. */
  548. dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
  549. dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
  550. dev->a_ops.adapter_notify = aac_src_notify_adapter;
  551. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  552. dev->a_ops.adapter_check_health = aac_src_check_health;
  553. dev->a_ops.adapter_restart = aac_src_restart_adapter;
  554. /*
  555. * First clear out all interrupts. Then enable the one's that we
  556. * can handle.
  557. */
  558. aac_adapter_comm(dev, AAC_COMM_MESSAGE);
  559. aac_adapter_disable_int(dev);
  560. src_writel(dev, MUnit.ODR_C, 0xffffffff);
  561. aac_adapter_enable_int(dev);
  562. if (aac_init_adapter(dev) == NULL)
  563. goto error_iounmap;
  564. if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE1)
  565. goto error_iounmap;
  566. dev->msi = aac_msi && !pci_enable_msi(dev->pdev);
  567. if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
  568. IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) {
  569. if (dev->msi)
  570. pci_disable_msi(dev->pdev);
  571. printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
  572. name, instance);
  573. goto error_iounmap;
  574. }
  575. dev->dbg_base = pci_resource_start(dev->pdev, 2);
  576. dev->dbg_base_mapped = dev->regs.src.bar1;
  577. dev->dbg_size = AAC_MIN_SRC_BAR1_SIZE;
  578. aac_adapter_enable_int(dev);
  579. if (!dev->sync_mode) {
  580. /*
  581. * Tell the adapter that all is configured, and it can
  582. * start accepting requests
  583. */
  584. aac_src_start_adapter(dev);
  585. }
  586. return 0;
  587. error_iounmap:
  588. return -1;
  589. }
  590. /**
  591. * aac_srcv_init - initialize an SRCv card
  592. * @dev: device to configure
  593. *
  594. */
  595. int aac_srcv_init(struct aac_dev *dev)
  596. {
  597. unsigned long start;
  598. unsigned long status;
  599. int restart = 0;
  600. int instance = dev->id;
  601. const char *name = dev->name;
  602. dev->a_ops.adapter_ioremap = aac_srcv_ioremap;
  603. dev->a_ops.adapter_comm = aac_src_select_comm;
  604. dev->base_size = AAC_MIN_SRCV_BAR0_SIZE;
  605. if (aac_adapter_ioremap(dev, dev->base_size)) {
  606. printk(KERN_WARNING "%s: unable to map adapter.\n", name);
  607. goto error_iounmap;
  608. }
  609. /* Failure to reset here is an option ... */
  610. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  611. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  612. if ((aac_reset_devices || reset_devices) &&
  613. !aac_src_restart_adapter(dev, 0))
  614. ++restart;
  615. /*
  616. * Check to see if the board panic'd while booting.
  617. */
  618. status = src_readl(dev, MUnit.OMR);
  619. if (status & KERNEL_PANIC) {
  620. if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
  621. goto error_iounmap;
  622. ++restart;
  623. }
  624. /*
  625. * Check to see if the board failed any self tests.
  626. */
  627. status = src_readl(dev, MUnit.OMR);
  628. if (status & SELF_TEST_FAILED) {
  629. printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
  630. goto error_iounmap;
  631. }
  632. /*
  633. * Check to see if the monitor panic'd while booting.
  634. */
  635. if (status & MONITOR_PANIC) {
  636. printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
  637. goto error_iounmap;
  638. }
  639. start = jiffies;
  640. /*
  641. * Wait for the adapter to be up and running. Wait up to 3 minutes
  642. */
  643. while (!((status = src_readl(dev, MUnit.OMR)) & KERNEL_UP_AND_RUNNING)) {
  644. if ((restart &&
  645. (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
  646. time_after(jiffies, start+HZ*startup_timeout)) {
  647. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  648. dev->name, instance, status);
  649. goto error_iounmap;
  650. }
  651. if (!restart &&
  652. ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
  653. time_after(jiffies, start + HZ *
  654. ((startup_timeout > 60)
  655. ? (startup_timeout - 60)
  656. : (startup_timeout / 2))))) {
  657. if (likely(!aac_src_restart_adapter(dev, aac_src_check_health(dev))))
  658. start = jiffies;
  659. ++restart;
  660. }
  661. msleep(1);
  662. }
  663. if (restart && aac_commit)
  664. aac_commit = 1;
  665. /*
  666. * Fill in the common function dispatch table.
  667. */
  668. dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
  669. dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
  670. dev->a_ops.adapter_notify = aac_src_notify_adapter;
  671. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  672. dev->a_ops.adapter_check_health = aac_src_check_health;
  673. dev->a_ops.adapter_restart = aac_src_restart_adapter;
  674. /*
  675. * First clear out all interrupts. Then enable the one's that we
  676. * can handle.
  677. */
  678. aac_adapter_comm(dev, AAC_COMM_MESSAGE);
  679. aac_adapter_disable_int(dev);
  680. src_writel(dev, MUnit.ODR_C, 0xffffffff);
  681. aac_adapter_enable_int(dev);
  682. if (aac_init_adapter(dev) == NULL)
  683. goto error_iounmap;
  684. if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE1)
  685. goto error_iounmap;
  686. dev->msi = aac_msi && !pci_enable_msi(dev->pdev);
  687. if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
  688. IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) {
  689. if (dev->msi)
  690. pci_disable_msi(dev->pdev);
  691. printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
  692. name, instance);
  693. goto error_iounmap;
  694. }
  695. dev->dbg_base = dev->scsi_host_ptr->base;
  696. dev->dbg_base_mapped = dev->base;
  697. dev->dbg_size = dev->base_size;
  698. aac_adapter_enable_int(dev);
  699. if (!dev->sync_mode) {
  700. /*
  701. * Tell the adapter that all is configured, and it can
  702. * start accepting requests
  703. */
  704. aac_src_start_adapter(dev);
  705. }
  706. return 0;
  707. error_iounmap:
  708. return -1;
  709. }