src.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 int aac_src_get_sync_status(struct aac_dev *dev);
  45. static irqreturn_t aac_src_intr_message(int irq, void *dev_id)
  46. {
  47. struct aac_msix_ctx *ctx;
  48. struct aac_dev *dev;
  49. unsigned long bellbits, bellbits_shifted;
  50. int vector_no;
  51. int isFastResponse, mode;
  52. u32 index, handle;
  53. ctx = (struct aac_msix_ctx *)dev_id;
  54. dev = ctx->dev;
  55. vector_no = ctx->vector_no;
  56. if (dev->msi_enabled) {
  57. mode = AAC_INT_MODE_MSI;
  58. if (vector_no == 0) {
  59. bellbits = src_readl(dev, MUnit.ODR_MSI);
  60. if (bellbits & 0x40000)
  61. mode |= AAC_INT_MODE_AIF;
  62. if (bellbits & 0x1000)
  63. mode |= AAC_INT_MODE_SYNC;
  64. }
  65. } else {
  66. mode = AAC_INT_MODE_INTX;
  67. bellbits = src_readl(dev, MUnit.ODR_R);
  68. if (bellbits & PmDoorBellResponseSent) {
  69. bellbits = PmDoorBellResponseSent;
  70. src_writel(dev, MUnit.ODR_C, bellbits);
  71. src_readl(dev, MUnit.ODR_C);
  72. } else {
  73. bellbits_shifted = (bellbits >> SRC_ODR_SHIFT);
  74. src_writel(dev, MUnit.ODR_C, bellbits);
  75. src_readl(dev, MUnit.ODR_C);
  76. if (bellbits_shifted & DoorBellAifPending)
  77. mode |= AAC_INT_MODE_AIF;
  78. else if (bellbits_shifted & OUTBOUNDDOORBELL_0)
  79. mode |= AAC_INT_MODE_SYNC;
  80. }
  81. }
  82. if (mode & AAC_INT_MODE_SYNC) {
  83. unsigned long sflags;
  84. struct list_head *entry;
  85. int send_it = 0;
  86. extern int aac_sync_mode;
  87. if (!aac_sync_mode && !dev->msi_enabled) {
  88. src_writel(dev, MUnit.ODR_C, bellbits);
  89. src_readl(dev, MUnit.ODR_C);
  90. }
  91. if (dev->sync_fib) {
  92. if (dev->sync_fib->callback)
  93. dev->sync_fib->callback(dev->sync_fib->callback_data,
  94. dev->sync_fib);
  95. spin_lock_irqsave(&dev->sync_fib->event_lock, sflags);
  96. if (dev->sync_fib->flags & FIB_CONTEXT_FLAG_WAIT) {
  97. dev->management_fib_count--;
  98. up(&dev->sync_fib->event_wait);
  99. }
  100. spin_unlock_irqrestore(&dev->sync_fib->event_lock,
  101. sflags);
  102. spin_lock_irqsave(&dev->sync_lock, sflags);
  103. if (!list_empty(&dev->sync_fib_list)) {
  104. entry = dev->sync_fib_list.next;
  105. dev->sync_fib = list_entry(entry,
  106. struct fib,
  107. fiblink);
  108. list_del(entry);
  109. send_it = 1;
  110. } else {
  111. dev->sync_fib = NULL;
  112. }
  113. spin_unlock_irqrestore(&dev->sync_lock, sflags);
  114. if (send_it) {
  115. aac_adapter_sync_cmd(dev, SEND_SYNCHRONOUS_FIB,
  116. (u32)dev->sync_fib->hw_fib_pa,
  117. 0, 0, 0, 0, 0,
  118. NULL, NULL, NULL, NULL, NULL);
  119. }
  120. }
  121. if (!dev->msi_enabled)
  122. mode = 0;
  123. }
  124. if (mode & AAC_INT_MODE_AIF) {
  125. /* handle AIF */
  126. aac_intr_normal(dev, 0, 2, 0, NULL);
  127. if (dev->msi_enabled)
  128. aac_src_access_devreg(dev, AAC_CLEAR_AIF_BIT);
  129. mode = 0;
  130. }
  131. if (mode) {
  132. index = dev->host_rrq_idx[vector_no];
  133. for (;;) {
  134. isFastResponse = 0;
  135. /* remove toggle bit (31) */
  136. handle = (dev->host_rrq[index] & 0x7fffffff);
  137. /* check fast response bit (30) */
  138. if (handle & 0x40000000)
  139. isFastResponse = 1;
  140. handle &= 0x0000ffff;
  141. if (handle == 0)
  142. break;
  143. if (dev->msi_enabled && dev->max_msix > 1)
  144. atomic_dec(&dev->rrq_outstanding[vector_no]);
  145. dev->host_rrq[index++] = 0;
  146. aac_intr_normal(dev, handle-1, 0, isFastResponse, NULL);
  147. if (index == (vector_no + 1) * dev->vector_cap)
  148. index = vector_no * dev->vector_cap;
  149. dev->host_rrq_idx[vector_no] = index;
  150. }
  151. mode = 0;
  152. }
  153. return IRQ_HANDLED;
  154. }
  155. /**
  156. * aac_src_disable_interrupt - Disable interrupts
  157. * @dev: Adapter
  158. */
  159. static void aac_src_disable_interrupt(struct aac_dev *dev)
  160. {
  161. src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
  162. }
  163. /**
  164. * aac_src_enable_interrupt_message - Enable interrupts
  165. * @dev: Adapter
  166. */
  167. static void aac_src_enable_interrupt_message(struct aac_dev *dev)
  168. {
  169. aac_src_access_devreg(dev, AAC_ENABLE_INTERRUPT);
  170. }
  171. /**
  172. * src_sync_cmd - send a command and wait
  173. * @dev: Adapter
  174. * @command: Command to execute
  175. * @p1: first parameter
  176. * @ret: adapter status
  177. *
  178. * This routine will send a synchronous command to the adapter and wait
  179. * for its completion.
  180. */
  181. static int src_sync_cmd(struct aac_dev *dev, u32 command,
  182. u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
  183. u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
  184. {
  185. unsigned long start;
  186. unsigned long delay;
  187. int ok;
  188. /*
  189. * Write the command into Mailbox 0
  190. */
  191. writel(command, &dev->IndexRegs->Mailbox[0]);
  192. /*
  193. * Write the parameters into Mailboxes 1 - 6
  194. */
  195. writel(p1, &dev->IndexRegs->Mailbox[1]);
  196. writel(p2, &dev->IndexRegs->Mailbox[2]);
  197. writel(p3, &dev->IndexRegs->Mailbox[3]);
  198. writel(p4, &dev->IndexRegs->Mailbox[4]);
  199. /*
  200. * Clear the synch command doorbell to start on a clean slate.
  201. */
  202. if (!dev->msi_enabled)
  203. src_writel(dev,
  204. MUnit.ODR_C,
  205. OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  206. /*
  207. * Disable doorbell interrupts
  208. */
  209. src_writel(dev, MUnit.OIMR, dev->OIMR = 0xffffffff);
  210. /*
  211. * Force the completion of the mask register write before issuing
  212. * the interrupt.
  213. */
  214. src_readl(dev, MUnit.OIMR);
  215. /*
  216. * Signal that there is a new synch command
  217. */
  218. src_writel(dev, MUnit.IDR, INBOUNDDOORBELL_0 << SRC_IDR_SHIFT);
  219. if (!dev->sync_mode || command != SEND_SYNCHRONOUS_FIB) {
  220. ok = 0;
  221. start = jiffies;
  222. if (command == IOP_RESET_ALWAYS) {
  223. /* Wait up to 10 sec */
  224. delay = 10*HZ;
  225. } else {
  226. /* Wait up to 5 minutes */
  227. delay = 300*HZ;
  228. }
  229. while (time_before(jiffies, start+delay)) {
  230. udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
  231. /*
  232. * Mon960 will set doorbell0 bit when it has completed the command.
  233. */
  234. if (aac_src_get_sync_status(dev) & OUTBOUNDDOORBELL_0) {
  235. /*
  236. * Clear the doorbell.
  237. */
  238. if (dev->msi_enabled)
  239. aac_src_access_devreg(dev,
  240. AAC_CLEAR_SYNC_BIT);
  241. else
  242. src_writel(dev,
  243. MUnit.ODR_C,
  244. OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  245. ok = 1;
  246. break;
  247. }
  248. /*
  249. * Yield the processor in case we are slow
  250. */
  251. msleep(1);
  252. }
  253. if (unlikely(ok != 1)) {
  254. /*
  255. * Restore interrupt mask even though we timed out
  256. */
  257. aac_adapter_enable_int(dev);
  258. return -ETIMEDOUT;
  259. }
  260. /*
  261. * Pull the synch status from Mailbox 0.
  262. */
  263. if (status)
  264. *status = readl(&dev->IndexRegs->Mailbox[0]);
  265. if (r1)
  266. *r1 = readl(&dev->IndexRegs->Mailbox[1]);
  267. if (r2)
  268. *r2 = readl(&dev->IndexRegs->Mailbox[2]);
  269. if (r3)
  270. *r3 = readl(&dev->IndexRegs->Mailbox[3]);
  271. if (r4)
  272. *r4 = readl(&dev->IndexRegs->Mailbox[4]);
  273. if (command == GET_COMM_PREFERRED_SETTINGS)
  274. dev->max_msix =
  275. readl(&dev->IndexRegs->Mailbox[5]) & 0xFFFF;
  276. /*
  277. * Clear the synch command doorbell.
  278. */
  279. if (!dev->msi_enabled)
  280. src_writel(dev,
  281. MUnit.ODR_C,
  282. OUTBOUNDDOORBELL_0 << SRC_ODR_SHIFT);
  283. }
  284. /*
  285. * Restore interrupt mask
  286. */
  287. aac_adapter_enable_int(dev);
  288. return 0;
  289. }
  290. /**
  291. * aac_src_interrupt_adapter - interrupt adapter
  292. * @dev: Adapter
  293. *
  294. * Send an interrupt to the i960 and breakpoint it.
  295. */
  296. static void aac_src_interrupt_adapter(struct aac_dev *dev)
  297. {
  298. src_sync_cmd(dev, BREAKPOINT_REQUEST,
  299. 0, 0, 0, 0, 0, 0,
  300. NULL, NULL, NULL, NULL, NULL);
  301. }
  302. /**
  303. * aac_src_notify_adapter - send an event to the adapter
  304. * @dev: Adapter
  305. * @event: Event to send
  306. *
  307. * Notify the i960 that something it probably cares about has
  308. * happened.
  309. */
  310. static void aac_src_notify_adapter(struct aac_dev *dev, u32 event)
  311. {
  312. switch (event) {
  313. case AdapNormCmdQue:
  314. src_writel(dev, MUnit.ODR_C,
  315. INBOUNDDOORBELL_1 << SRC_ODR_SHIFT);
  316. break;
  317. case HostNormRespNotFull:
  318. src_writel(dev, MUnit.ODR_C,
  319. INBOUNDDOORBELL_4 << SRC_ODR_SHIFT);
  320. break;
  321. case AdapNormRespQue:
  322. src_writel(dev, MUnit.ODR_C,
  323. INBOUNDDOORBELL_2 << SRC_ODR_SHIFT);
  324. break;
  325. case HostNormCmdNotFull:
  326. src_writel(dev, MUnit.ODR_C,
  327. INBOUNDDOORBELL_3 << SRC_ODR_SHIFT);
  328. break;
  329. case FastIo:
  330. src_writel(dev, MUnit.ODR_C,
  331. INBOUNDDOORBELL_6 << SRC_ODR_SHIFT);
  332. break;
  333. case AdapPrintfDone:
  334. src_writel(dev, MUnit.ODR_C,
  335. INBOUNDDOORBELL_5 << SRC_ODR_SHIFT);
  336. break;
  337. default:
  338. BUG();
  339. break;
  340. }
  341. }
  342. /**
  343. * aac_src_start_adapter - activate adapter
  344. * @dev: Adapter
  345. *
  346. * Start up processing on an i960 based AAC adapter
  347. */
  348. static void aac_src_start_adapter(struct aac_dev *dev)
  349. {
  350. struct aac_init *init;
  351. int i;
  352. /* reset host_rrq_idx first */
  353. for (i = 0; i < dev->max_msix; i++) {
  354. dev->host_rrq_idx[i] = i * dev->vector_cap;
  355. atomic_set(&dev->rrq_outstanding[i], 0);
  356. }
  357. dev->fibs_pushed_no = 0;
  358. init = dev->init;
  359. init->HostElapsedSeconds = cpu_to_le32(get_seconds());
  360. /* We can only use a 32 bit address here */
  361. src_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
  362. 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  363. }
  364. /**
  365. * aac_src_check_health
  366. * @dev: device to check if healthy
  367. *
  368. * Will attempt to determine if the specified adapter is alive and
  369. * capable of handling requests, returning 0 if alive.
  370. */
  371. static int aac_src_check_health(struct aac_dev *dev)
  372. {
  373. u32 status = src_readl(dev, MUnit.OMR);
  374. /*
  375. * Check to see if the board panic'd.
  376. */
  377. if (unlikely(status & KERNEL_PANIC))
  378. goto err_blink;
  379. /*
  380. * Check to see if the board failed any self tests.
  381. */
  382. if (unlikely(status & SELF_TEST_FAILED))
  383. goto err_out;
  384. /*
  385. * Check to see if the board failed any self tests.
  386. */
  387. if (unlikely(status & MONITOR_PANIC))
  388. goto err_out;
  389. /*
  390. * Wait for the adapter to be up and running.
  391. */
  392. if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
  393. return -3;
  394. /*
  395. * Everything is OK
  396. */
  397. return 0;
  398. err_out:
  399. return -1;
  400. err_blink:
  401. return (status >> 16) & 0xFF;
  402. }
  403. /**
  404. * aac_src_deliver_message
  405. * @fib: fib to issue
  406. *
  407. * Will send a fib, returning 0 if successful.
  408. */
  409. static int aac_src_deliver_message(struct fib *fib)
  410. {
  411. struct aac_dev *dev = fib->dev;
  412. struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
  413. u32 fibsize;
  414. dma_addr_t address;
  415. struct aac_fib_xporthdr *pFibX;
  416. #if !defined(writeq)
  417. unsigned long flags;
  418. #endif
  419. u16 hdr_size = le16_to_cpu(fib->hw_fib_va->header.Size);
  420. u16 vector_no;
  421. atomic_inc(&q->numpending);
  422. if (dev->msi_enabled && fib->hw_fib_va->header.Command != AifRequest &&
  423. dev->max_msix > 1) {
  424. vector_no = fib->vector_no;
  425. fib->hw_fib_va->header.Handle += (vector_no << 16);
  426. } else {
  427. vector_no = 0;
  428. }
  429. atomic_inc(&dev->rrq_outstanding[vector_no]);
  430. if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
  431. /* Calculate the amount to the fibsize bits */
  432. fibsize = (hdr_size + 127) / 128 - 1;
  433. if (fibsize > (ALIGN32 - 1))
  434. return -EMSGSIZE;
  435. /* New FIB header, 32-bit */
  436. address = fib->hw_fib_pa;
  437. fib->hw_fib_va->header.StructType = FIB_MAGIC2;
  438. fib->hw_fib_va->header.SenderFibAddress = (u32)address;
  439. fib->hw_fib_va->header.u.TimeStamp = 0;
  440. BUG_ON(upper_32_bits(address) != 0L);
  441. address |= fibsize;
  442. } else {
  443. /* Calculate the amount to the fibsize bits */
  444. fibsize = (sizeof(struct aac_fib_xporthdr) + hdr_size + 127) / 128 - 1;
  445. if (fibsize > (ALIGN32 - 1))
  446. return -EMSGSIZE;
  447. /* Fill XPORT header */
  448. pFibX = (void *)fib->hw_fib_va - sizeof(struct aac_fib_xporthdr);
  449. pFibX->Handle = cpu_to_le32(fib->hw_fib_va->header.Handle);
  450. pFibX->HostAddress = cpu_to_le64(fib->hw_fib_pa);
  451. pFibX->Size = cpu_to_le32(hdr_size);
  452. /*
  453. * The xport header has been 32-byte aligned for us so that fibsize
  454. * can be masked out of this address by hardware. -- BenC
  455. */
  456. address = fib->hw_fib_pa - sizeof(struct aac_fib_xporthdr);
  457. if (address & (ALIGN32 - 1))
  458. return -EINVAL;
  459. address |= fibsize;
  460. }
  461. #if defined(writeq)
  462. src_writeq(dev, MUnit.IQ_L, (u64)address);
  463. #else
  464. spin_lock_irqsave(&fib->dev->iq_lock, flags);
  465. src_writel(dev, MUnit.IQ_H, upper_32_bits(address) & 0xffffffff);
  466. src_writel(dev, MUnit.IQ_L, address & 0xffffffff);
  467. spin_unlock_irqrestore(&fib->dev->iq_lock, flags);
  468. #endif
  469. return 0;
  470. }
  471. /**
  472. * aac_src_ioremap
  473. * @size: mapping resize request
  474. *
  475. */
  476. static int aac_src_ioremap(struct aac_dev *dev, u32 size)
  477. {
  478. if (!size) {
  479. iounmap(dev->regs.src.bar1);
  480. dev->regs.src.bar1 = NULL;
  481. iounmap(dev->regs.src.bar0);
  482. dev->base = dev->regs.src.bar0 = NULL;
  483. return 0;
  484. }
  485. dev->regs.src.bar1 = ioremap(pci_resource_start(dev->pdev, 2),
  486. AAC_MIN_SRC_BAR1_SIZE);
  487. dev->base = NULL;
  488. if (dev->regs.src.bar1 == NULL)
  489. return -1;
  490. dev->base = dev->regs.src.bar0 = ioremap(dev->base_start, size);
  491. if (dev->base == NULL) {
  492. iounmap(dev->regs.src.bar1);
  493. dev->regs.src.bar1 = NULL;
  494. return -1;
  495. }
  496. dev->IndexRegs = &((struct src_registers __iomem *)
  497. dev->base)->u.tupelo.IndexRegs;
  498. return 0;
  499. }
  500. /**
  501. * aac_srcv_ioremap
  502. * @size: mapping resize request
  503. *
  504. */
  505. static int aac_srcv_ioremap(struct aac_dev *dev, u32 size)
  506. {
  507. if (!size) {
  508. iounmap(dev->regs.src.bar0);
  509. dev->base = dev->regs.src.bar0 = NULL;
  510. return 0;
  511. }
  512. dev->base = dev->regs.src.bar0 = ioremap(dev->base_start, size);
  513. if (dev->base == NULL)
  514. return -1;
  515. dev->IndexRegs = &((struct src_registers __iomem *)
  516. dev->base)->u.denali.IndexRegs;
  517. return 0;
  518. }
  519. static int aac_src_restart_adapter(struct aac_dev *dev, int bled)
  520. {
  521. u32 var, reset_mask;
  522. if (bled >= 0) {
  523. if (bled)
  524. printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n",
  525. dev->name, dev->id, bled);
  526. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  527. bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
  528. 0, 0, 0, 0, 0, 0, &var, &reset_mask, NULL, NULL, NULL);
  529. if ((bled || (var != 0x00000001)) &&
  530. !dev->doorbell_mask)
  531. return -EINVAL;
  532. else if (dev->doorbell_mask) {
  533. reset_mask = dev->doorbell_mask;
  534. bled = 0;
  535. var = 0x00000001;
  536. }
  537. if ((dev->pdev->device == PMC_DEVICE_S7 ||
  538. dev->pdev->device == PMC_DEVICE_S8 ||
  539. dev->pdev->device == PMC_DEVICE_S9) && dev->msi_enabled) {
  540. aac_src_access_devreg(dev, AAC_ENABLE_INTX);
  541. dev->msi_enabled = 0;
  542. msleep(5000); /* Delay 5 seconds */
  543. }
  544. if (!bled && (dev->supplement_adapter_info.SupportedOptions2 &
  545. AAC_OPTION_DOORBELL_RESET)) {
  546. src_writel(dev, MUnit.IDR, reset_mask);
  547. ssleep(45);
  548. } else {
  549. src_writel(dev, MUnit.IDR, 0x100);
  550. ssleep(45);
  551. }
  552. }
  553. if (src_readl(dev, MUnit.OMR) & KERNEL_PANIC)
  554. return -ENODEV;
  555. if (startup_timeout < 300)
  556. startup_timeout = 300;
  557. return 0;
  558. }
  559. /**
  560. * aac_src_select_comm - Select communications method
  561. * @dev: Adapter
  562. * @comm: communications method
  563. */
  564. int aac_src_select_comm(struct aac_dev *dev, int comm)
  565. {
  566. switch (comm) {
  567. case AAC_COMM_MESSAGE:
  568. dev->a_ops.adapter_intr = aac_src_intr_message;
  569. dev->a_ops.adapter_deliver = aac_src_deliver_message;
  570. break;
  571. default:
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. /**
  577. * aac_src_init - initialize an Cardinal Frey Bar card
  578. * @dev: device to configure
  579. *
  580. */
  581. int aac_src_init(struct aac_dev *dev)
  582. {
  583. unsigned long start;
  584. unsigned long status;
  585. int restart = 0;
  586. int instance = dev->id;
  587. const char *name = dev->name;
  588. dev->a_ops.adapter_ioremap = aac_src_ioremap;
  589. dev->a_ops.adapter_comm = aac_src_select_comm;
  590. dev->base_size = AAC_MIN_SRC_BAR0_SIZE;
  591. if (aac_adapter_ioremap(dev, dev->base_size)) {
  592. printk(KERN_WARNING "%s: unable to map adapter.\n", name);
  593. goto error_iounmap;
  594. }
  595. /* Failure to reset here is an option ... */
  596. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  597. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  598. if ((aac_reset_devices || reset_devices) &&
  599. !aac_src_restart_adapter(dev, 0))
  600. ++restart;
  601. /*
  602. * Check to see if the board panic'd while booting.
  603. */
  604. status = src_readl(dev, MUnit.OMR);
  605. if (status & KERNEL_PANIC) {
  606. if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
  607. goto error_iounmap;
  608. ++restart;
  609. }
  610. /*
  611. * Check to see if the board failed any self tests.
  612. */
  613. status = src_readl(dev, MUnit.OMR);
  614. if (status & SELF_TEST_FAILED) {
  615. printk(KERN_ERR "%s%d: adapter self-test failed.\n",
  616. dev->name, instance);
  617. goto error_iounmap;
  618. }
  619. /*
  620. * Check to see if the monitor panic'd while booting.
  621. */
  622. if (status & MONITOR_PANIC) {
  623. printk(KERN_ERR "%s%d: adapter monitor panic.\n",
  624. dev->name, instance);
  625. goto error_iounmap;
  626. }
  627. start = jiffies;
  628. /*
  629. * Wait for the adapter to be up and running. Wait up to 3 minutes
  630. */
  631. while (!((status = src_readl(dev, MUnit.OMR)) &
  632. KERNEL_UP_AND_RUNNING)) {
  633. if ((restart &&
  634. (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
  635. time_after(jiffies, start+HZ*startup_timeout)) {
  636. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  637. dev->name, instance, status);
  638. goto error_iounmap;
  639. }
  640. if (!restart &&
  641. ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
  642. time_after(jiffies, start + HZ *
  643. ((startup_timeout > 60)
  644. ? (startup_timeout - 60)
  645. : (startup_timeout / 2))))) {
  646. if (likely(!aac_src_restart_adapter(dev,
  647. aac_src_check_health(dev))))
  648. start = jiffies;
  649. ++restart;
  650. }
  651. msleep(1);
  652. }
  653. if (restart && aac_commit)
  654. aac_commit = 1;
  655. /*
  656. * Fill in the common function dispatch table.
  657. */
  658. dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
  659. dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
  660. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  661. dev->a_ops.adapter_notify = aac_src_notify_adapter;
  662. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  663. dev->a_ops.adapter_check_health = aac_src_check_health;
  664. dev->a_ops.adapter_restart = aac_src_restart_adapter;
  665. dev->a_ops.adapter_start = aac_src_start_adapter;
  666. /*
  667. * First clear out all interrupts. Then enable the one's that we
  668. * can handle.
  669. */
  670. aac_adapter_comm(dev, AAC_COMM_MESSAGE);
  671. aac_adapter_disable_int(dev);
  672. src_writel(dev, MUnit.ODR_C, 0xffffffff);
  673. aac_adapter_enable_int(dev);
  674. if (aac_init_adapter(dev) == NULL)
  675. goto error_iounmap;
  676. if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE1)
  677. goto error_iounmap;
  678. dev->msi = !pci_enable_msi(dev->pdev);
  679. dev->aac_msix[0].vector_no = 0;
  680. dev->aac_msix[0].dev = dev;
  681. if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
  682. IRQF_SHARED, "aacraid", &(dev->aac_msix[0])) < 0) {
  683. if (dev->msi)
  684. pci_disable_msi(dev->pdev);
  685. printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
  686. name, instance);
  687. goto error_iounmap;
  688. }
  689. dev->dbg_base = pci_resource_start(dev->pdev, 2);
  690. dev->dbg_base_mapped = dev->regs.src.bar1;
  691. dev->dbg_size = AAC_MIN_SRC_BAR1_SIZE;
  692. dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
  693. aac_adapter_enable_int(dev);
  694. if (!dev->sync_mode) {
  695. /*
  696. * Tell the adapter that all is configured, and it can
  697. * start accepting requests
  698. */
  699. aac_src_start_adapter(dev);
  700. }
  701. return 0;
  702. error_iounmap:
  703. return -1;
  704. }
  705. /**
  706. * aac_srcv_init - initialize an SRCv card
  707. * @dev: device to configure
  708. *
  709. */
  710. int aac_srcv_init(struct aac_dev *dev)
  711. {
  712. unsigned long start;
  713. unsigned long status;
  714. int restart = 0;
  715. int instance = dev->id;
  716. const char *name = dev->name;
  717. dev->a_ops.adapter_ioremap = aac_srcv_ioremap;
  718. dev->a_ops.adapter_comm = aac_src_select_comm;
  719. dev->base_size = AAC_MIN_SRCV_BAR0_SIZE;
  720. if (aac_adapter_ioremap(dev, dev->base_size)) {
  721. printk(KERN_WARNING "%s: unable to map adapter.\n", name);
  722. goto error_iounmap;
  723. }
  724. /* Failure to reset here is an option ... */
  725. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  726. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  727. if ((aac_reset_devices || reset_devices) &&
  728. !aac_src_restart_adapter(dev, 0))
  729. ++restart;
  730. /*
  731. * Check to see if flash update is running.
  732. * Wait for the adapter to be up and running. Wait up to 5 minutes
  733. */
  734. status = src_readl(dev, MUnit.OMR);
  735. if (status & FLASH_UPD_PENDING) {
  736. start = jiffies;
  737. do {
  738. status = src_readl(dev, MUnit.OMR);
  739. if (time_after(jiffies, start+HZ*FWUPD_TIMEOUT)) {
  740. printk(KERN_ERR "%s%d: adapter flash update failed.\n",
  741. dev->name, instance);
  742. goto error_iounmap;
  743. }
  744. } while (!(status & FLASH_UPD_SUCCESS) &&
  745. !(status & FLASH_UPD_FAILED));
  746. /* Delay 10 seconds.
  747. * Because right now FW is doing a soft reset,
  748. * do not read scratch pad register at this time
  749. */
  750. ssleep(10);
  751. }
  752. /*
  753. * Check to see if the board panic'd while booting.
  754. */
  755. status = src_readl(dev, MUnit.OMR);
  756. if (status & KERNEL_PANIC) {
  757. if (aac_src_restart_adapter(dev, aac_src_check_health(dev)))
  758. goto error_iounmap;
  759. ++restart;
  760. }
  761. /*
  762. * Check to see if the board failed any self tests.
  763. */
  764. status = src_readl(dev, MUnit.OMR);
  765. if (status & SELF_TEST_FAILED) {
  766. printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
  767. goto error_iounmap;
  768. }
  769. /*
  770. * Check to see if the monitor panic'd while booting.
  771. */
  772. if (status & MONITOR_PANIC) {
  773. printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
  774. goto error_iounmap;
  775. }
  776. start = jiffies;
  777. /*
  778. * Wait for the adapter to be up and running. Wait up to 3 minutes
  779. */
  780. while (!((status = src_readl(dev, MUnit.OMR)) &
  781. KERNEL_UP_AND_RUNNING) ||
  782. status == 0xffffffff) {
  783. if ((restart &&
  784. (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
  785. time_after(jiffies, start+HZ*startup_timeout)) {
  786. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  787. dev->name, instance, status);
  788. goto error_iounmap;
  789. }
  790. if (!restart &&
  791. ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
  792. time_after(jiffies, start + HZ *
  793. ((startup_timeout > 60)
  794. ? (startup_timeout - 60)
  795. : (startup_timeout / 2))))) {
  796. if (likely(!aac_src_restart_adapter(dev, aac_src_check_health(dev))))
  797. start = jiffies;
  798. ++restart;
  799. }
  800. msleep(1);
  801. }
  802. if (restart && aac_commit)
  803. aac_commit = 1;
  804. /*
  805. * Fill in the common function dispatch table.
  806. */
  807. dev->a_ops.adapter_interrupt = aac_src_interrupt_adapter;
  808. dev->a_ops.adapter_disable_int = aac_src_disable_interrupt;
  809. dev->a_ops.adapter_enable_int = aac_src_disable_interrupt;
  810. dev->a_ops.adapter_notify = aac_src_notify_adapter;
  811. dev->a_ops.adapter_sync_cmd = src_sync_cmd;
  812. dev->a_ops.adapter_check_health = aac_src_check_health;
  813. dev->a_ops.adapter_restart = aac_src_restart_adapter;
  814. dev->a_ops.adapter_start = aac_src_start_adapter;
  815. /*
  816. * First clear out all interrupts. Then enable the one's that we
  817. * can handle.
  818. */
  819. aac_adapter_comm(dev, AAC_COMM_MESSAGE);
  820. aac_adapter_disable_int(dev);
  821. src_writel(dev, MUnit.ODR_C, 0xffffffff);
  822. aac_adapter_enable_int(dev);
  823. if (aac_init_adapter(dev) == NULL)
  824. goto error_iounmap;
  825. if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE2)
  826. goto error_iounmap;
  827. if (dev->msi_enabled)
  828. aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
  829. if (aac_acquire_irq(dev))
  830. goto error_iounmap;
  831. dev->dbg_base = dev->base_start;
  832. dev->dbg_base_mapped = dev->base;
  833. dev->dbg_size = dev->base_size;
  834. dev->a_ops.adapter_enable_int = aac_src_enable_interrupt_message;
  835. aac_adapter_enable_int(dev);
  836. if (!dev->sync_mode) {
  837. /*
  838. * Tell the adapter that all is configured, and it can
  839. * start accepting requests
  840. */
  841. aac_src_start_adapter(dev);
  842. }
  843. return 0;
  844. error_iounmap:
  845. return -1;
  846. }
  847. void aac_src_access_devreg(struct aac_dev *dev, int mode)
  848. {
  849. u_int32_t val;
  850. switch (mode) {
  851. case AAC_ENABLE_INTERRUPT:
  852. src_writel(dev,
  853. MUnit.OIMR,
  854. dev->OIMR = (dev->msi_enabled ?
  855. AAC_INT_ENABLE_TYPE1_MSIX :
  856. AAC_INT_ENABLE_TYPE1_INTX));
  857. break;
  858. case AAC_DISABLE_INTERRUPT:
  859. src_writel(dev,
  860. MUnit.OIMR,
  861. dev->OIMR = AAC_INT_DISABLE_ALL);
  862. break;
  863. case AAC_ENABLE_MSIX:
  864. /* set bit 6 */
  865. val = src_readl(dev, MUnit.IDR);
  866. val |= 0x40;
  867. src_writel(dev, MUnit.IDR, val);
  868. src_readl(dev, MUnit.IDR);
  869. /* unmask int. */
  870. val = PMC_ALL_INTERRUPT_BITS;
  871. src_writel(dev, MUnit.IOAR, val);
  872. val = src_readl(dev, MUnit.OIMR);
  873. src_writel(dev,
  874. MUnit.OIMR,
  875. val & (~(PMC_GLOBAL_INT_BIT2 | PMC_GLOBAL_INT_BIT0)));
  876. break;
  877. case AAC_DISABLE_MSIX:
  878. /* reset bit 6 */
  879. val = src_readl(dev, MUnit.IDR);
  880. val &= ~0x40;
  881. src_writel(dev, MUnit.IDR, val);
  882. src_readl(dev, MUnit.IDR);
  883. break;
  884. case AAC_CLEAR_AIF_BIT:
  885. /* set bit 5 */
  886. val = src_readl(dev, MUnit.IDR);
  887. val |= 0x20;
  888. src_writel(dev, MUnit.IDR, val);
  889. src_readl(dev, MUnit.IDR);
  890. break;
  891. case AAC_CLEAR_SYNC_BIT:
  892. /* set bit 4 */
  893. val = src_readl(dev, MUnit.IDR);
  894. val |= 0x10;
  895. src_writel(dev, MUnit.IDR, val);
  896. src_readl(dev, MUnit.IDR);
  897. break;
  898. case AAC_ENABLE_INTX:
  899. /* set bit 7 */
  900. val = src_readl(dev, MUnit.IDR);
  901. val |= 0x80;
  902. src_writel(dev, MUnit.IDR, val);
  903. src_readl(dev, MUnit.IDR);
  904. /* unmask int. */
  905. val = PMC_ALL_INTERRUPT_BITS;
  906. src_writel(dev, MUnit.IOAR, val);
  907. src_readl(dev, MUnit.IOAR);
  908. val = src_readl(dev, MUnit.OIMR);
  909. src_writel(dev, MUnit.OIMR,
  910. val & (~(PMC_GLOBAL_INT_BIT2)));
  911. break;
  912. default:
  913. break;
  914. }
  915. }
  916. static int aac_src_get_sync_status(struct aac_dev *dev)
  917. {
  918. int val;
  919. if (dev->msi_enabled)
  920. val = src_readl(dev, MUnit.ODR_MSI) & 0x1000 ? 1 : 0;
  921. else
  922. val = src_readl(dev, MUnit.ODR_R) >> SRC_ODR_SHIFT;
  923. return val;
  924. }