rkt.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. * Adaptec AAC series RAID controller driver
  3. * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
  4. *
  5. * based on the old aacraid driver that is..
  6. * Adaptec aacraid device driver for Linux.
  7. *
  8. * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; see the file COPYING. If not, write to
  22. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * Module Name:
  25. * rkt.c
  26. *
  27. * Abstract: Hardware miniport for Drawbridge specific hardware functions.
  28. *
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/init.h>
  32. #include <linux/types.h>
  33. #include <linux/sched.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 <asm/semaphore.h>
  43. #include <scsi/scsi_host.h>
  44. #include "aacraid.h"
  45. static irqreturn_t aac_rkt_intr(int irq, void *dev_id, struct pt_regs *regs)
  46. {
  47. struct aac_dev *dev = dev_id;
  48. if (dev->new_comm_interface) {
  49. u32 Index = rkt_readl(dev, MUnit.OutboundQueue);
  50. if (Index == 0xFFFFFFFFL)
  51. Index = rkt_readl(dev, MUnit.OutboundQueue);
  52. if (Index != 0xFFFFFFFFL) {
  53. do {
  54. if (aac_intr_normal(dev, Index)) {
  55. rkt_writel(dev, MUnit.OutboundQueue, Index);
  56. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
  57. }
  58. Index = rkt_readl(dev, MUnit.OutboundQueue);
  59. } while (Index != 0xFFFFFFFFL);
  60. return IRQ_HANDLED;
  61. }
  62. } else {
  63. unsigned long bellbits;
  64. u8 intstat;
  65. intstat = rkt_readb(dev, MUnit.OISR);
  66. /*
  67. * Read mask and invert because drawbridge is reversed.
  68. * This allows us to only service interrupts that have
  69. * been enabled.
  70. * Check to see if this is our interrupt. If it isn't just return
  71. */
  72. if (intstat & ~(dev->OIMR))
  73. {
  74. bellbits = rkt_readl(dev, OutboundDoorbellReg);
  75. if (bellbits & DoorBellPrintfReady) {
  76. aac_printf(dev, rkt_readl (dev, IndexRegs.Mailbox[5]));
  77. rkt_writel(dev, MUnit.ODR,DoorBellPrintfReady);
  78. rkt_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
  79. }
  80. else if (bellbits & DoorBellAdapterNormCmdReady) {
  81. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
  82. aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
  83. // rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
  84. }
  85. else if (bellbits & DoorBellAdapterNormRespReady) {
  86. rkt_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
  87. aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
  88. }
  89. else if (bellbits & DoorBellAdapterNormCmdNotFull) {
  90. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  91. }
  92. else if (bellbits & DoorBellAdapterNormRespNotFull) {
  93. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  94. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
  95. }
  96. return IRQ_HANDLED;
  97. }
  98. }
  99. return IRQ_NONE;
  100. }
  101. /**
  102. * aac_rkt_disable_interrupt - Disable interrupts
  103. * @dev: Adapter
  104. */
  105. static void aac_rkt_disable_interrupt(struct aac_dev *dev)
  106. {
  107. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  108. }
  109. /**
  110. * rkt_sync_cmd - send a command and wait
  111. * @dev: Adapter
  112. * @command: Command to execute
  113. * @p1: first parameter
  114. * @ret: adapter status
  115. *
  116. * This routine will send a synchronous command to the adapter and wait
  117. * for its completion.
  118. */
  119. static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
  120. u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
  121. u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
  122. {
  123. unsigned long start;
  124. int ok;
  125. /*
  126. * Write the command into Mailbox 0
  127. */
  128. rkt_writel(dev, InboundMailbox0, command);
  129. /*
  130. * Write the parameters into Mailboxes 1 - 6
  131. */
  132. rkt_writel(dev, InboundMailbox1, p1);
  133. rkt_writel(dev, InboundMailbox2, p2);
  134. rkt_writel(dev, InboundMailbox3, p3);
  135. rkt_writel(dev, InboundMailbox4, p4);
  136. /*
  137. * Clear the synch command doorbell to start on a clean slate.
  138. */
  139. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  140. /*
  141. * Disable doorbell interrupts
  142. */
  143. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  144. /*
  145. * Force the completion of the mask register write before issuing
  146. * the interrupt.
  147. */
  148. rkt_readb (dev, MUnit.OIMR);
  149. /*
  150. * Signal that there is a new synch command
  151. */
  152. rkt_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
  153. ok = 0;
  154. start = jiffies;
  155. /*
  156. * Wait up to 30 seconds
  157. */
  158. while (time_before(jiffies, start+30*HZ))
  159. {
  160. udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
  161. /*
  162. * Mon960 will set doorbell0 bit when it has completed the command.
  163. */
  164. if (rkt_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
  165. /*
  166. * Clear the doorbell.
  167. */
  168. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  169. ok = 1;
  170. break;
  171. }
  172. /*
  173. * Yield the processor in case we are slow
  174. */
  175. set_current_state(TASK_UNINTERRUPTIBLE);
  176. schedule_timeout(1);
  177. }
  178. if (ok != 1) {
  179. /*
  180. * Restore interrupt mask even though we timed out
  181. */
  182. if (dev->new_comm_interface)
  183. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
  184. else
  185. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  186. return -ETIMEDOUT;
  187. }
  188. /*
  189. * Pull the synch status from Mailbox 0.
  190. */
  191. if (status)
  192. *status = rkt_readl(dev, IndexRegs.Mailbox[0]);
  193. if (r1)
  194. *r1 = rkt_readl(dev, IndexRegs.Mailbox[1]);
  195. if (r2)
  196. *r2 = rkt_readl(dev, IndexRegs.Mailbox[2]);
  197. if (r3)
  198. *r3 = rkt_readl(dev, IndexRegs.Mailbox[3]);
  199. if (r4)
  200. *r4 = rkt_readl(dev, IndexRegs.Mailbox[4]);
  201. /*
  202. * Clear the synch command doorbell.
  203. */
  204. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  205. /*
  206. * Restore interrupt mask
  207. */
  208. if (dev->new_comm_interface)
  209. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
  210. else
  211. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  212. return 0;
  213. }
  214. /**
  215. * aac_rkt_interrupt_adapter - interrupt adapter
  216. * @dev: Adapter
  217. *
  218. * Send an interrupt to the i960 and breakpoint it.
  219. */
  220. static void aac_rkt_interrupt_adapter(struct aac_dev *dev)
  221. {
  222. rkt_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
  223. NULL, NULL, NULL, NULL, NULL);
  224. }
  225. /**
  226. * aac_rkt_notify_adapter - send an event to the adapter
  227. * @dev: Adapter
  228. * @event: Event to send
  229. *
  230. * Notify the i960 that something it probably cares about has
  231. * happened.
  232. */
  233. static void aac_rkt_notify_adapter(struct aac_dev *dev, u32 event)
  234. {
  235. switch (event) {
  236. case AdapNormCmdQue:
  237. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
  238. break;
  239. case HostNormRespNotFull:
  240. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
  241. break;
  242. case AdapNormRespQue:
  243. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
  244. break;
  245. case HostNormCmdNotFull:
  246. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
  247. break;
  248. case HostShutdown:
  249. // rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
  250. // NULL, NULL, NULL, NULL, NULL);
  251. break;
  252. case FastIo:
  253. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
  254. break;
  255. case AdapPrintfDone:
  256. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
  257. break;
  258. default:
  259. BUG();
  260. break;
  261. }
  262. }
  263. /**
  264. * aac_rkt_start_adapter - activate adapter
  265. * @dev: Adapter
  266. *
  267. * Start up processing on an i960 based AAC adapter
  268. */
  269. static void aac_rkt_start_adapter(struct aac_dev *dev)
  270. {
  271. struct aac_init *init;
  272. init = dev->init;
  273. init->HostElapsedSeconds = cpu_to_le32(get_seconds());
  274. // We can only use a 32 bit address here
  275. rkt_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
  276. 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  277. }
  278. /**
  279. * aac_rkt_check_health
  280. * @dev: device to check if healthy
  281. *
  282. * Will attempt to determine if the specified adapter is alive and
  283. * capable of handling requests, returning 0 if alive.
  284. */
  285. static int aac_rkt_check_health(struct aac_dev *dev)
  286. {
  287. u32 status = rkt_readl(dev, MUnit.OMRx[0]);
  288. /*
  289. * Check to see if the board failed any self tests.
  290. */
  291. if (status & SELF_TEST_FAILED)
  292. return -1;
  293. /*
  294. * Check to see if the board panic'd.
  295. */
  296. if (status & KERNEL_PANIC) {
  297. char * buffer;
  298. struct POSTSTATUS {
  299. __le32 Post_Command;
  300. __le32 Post_Address;
  301. } * post;
  302. dma_addr_t paddr, baddr;
  303. int ret;
  304. if ((status & 0xFF000000L) == 0xBC000000L)
  305. return (status >> 16) & 0xFF;
  306. buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
  307. ret = -2;
  308. if (buffer == NULL)
  309. return ret;
  310. post = pci_alloc_consistent(dev->pdev,
  311. sizeof(struct POSTSTATUS), &paddr);
  312. if (post == NULL) {
  313. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  314. return ret;
  315. }
  316. memset(buffer, 0, 512);
  317. post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
  318. post->Post_Address = cpu_to_le32(baddr);
  319. rkt_writel(dev, MUnit.IMRx[0], paddr);
  320. rkt_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
  321. NULL, NULL, NULL, NULL, NULL);
  322. pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
  323. post, paddr);
  324. if ((buffer[0] == '0') && (buffer[1] == 'x')) {
  325. ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
  326. ret <<= 4;
  327. ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
  328. }
  329. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  330. return ret;
  331. }
  332. /*
  333. * Wait for the adapter to be up and running.
  334. */
  335. if (!(status & KERNEL_UP_AND_RUNNING))
  336. return -3;
  337. /*
  338. * Everything is OK
  339. */
  340. return 0;
  341. }
  342. /**
  343. * aac_rkt_send
  344. * @fib: fib to issue
  345. *
  346. * Will send a fib, returning 0 if successful.
  347. */
  348. static int aac_rkt_send(struct fib * fib)
  349. {
  350. u64 addr = fib->hw_fib_pa;
  351. struct aac_dev *dev = fib->dev;
  352. volatile void __iomem *device = dev->regs.rkt;
  353. u32 Index;
  354. dprintk((KERN_DEBUG "%p->aac_rkt_send(%p->%llx)\n", dev, fib, addr));
  355. Index = rkt_readl(dev, MUnit.InboundQueue);
  356. if (Index == 0xFFFFFFFFL)
  357. Index = rkt_readl(dev, MUnit.InboundQueue);
  358. dprintk((KERN_DEBUG "Index = 0x%x\n", Index));
  359. if (Index == 0xFFFFFFFFL)
  360. return Index;
  361. device += Index;
  362. dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff),
  363. (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
  364. writel((u32)(addr & 0xffffffff), device);
  365. device += sizeof(u32);
  366. writel((u32)(addr >> 32), device);
  367. device += sizeof(u32);
  368. writel(le16_to_cpu(fib->hw_fib->header.Size), device);
  369. rkt_writel(dev, MUnit.InboundQueue, Index);
  370. dprintk((KERN_DEBUG "aac_rkt_send - return 0\n"));
  371. return 0;
  372. }
  373. /**
  374. * aac_rkt_init - initialize an i960 based AAC card
  375. * @dev: device to configure
  376. *
  377. * Allocate and set up resources for the i960 based AAC variants. The
  378. * device_interface in the commregion will be allocated and linked
  379. * to the comm region.
  380. */
  381. int aac_rkt_init(struct aac_dev *dev)
  382. {
  383. unsigned long start;
  384. unsigned long status;
  385. int instance;
  386. const char * name;
  387. instance = dev->id;
  388. name = dev->name;
  389. /*
  390. * Check to see if the board panic'd while booting.
  391. */
  392. /*
  393. * Check to see if the board failed any self tests.
  394. */
  395. if (rkt_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) {
  396. printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
  397. goto error_iounmap;
  398. }
  399. /*
  400. * Check to see if the monitor panic'd while booting.
  401. */
  402. if (rkt_readl(dev, MUnit.OMRx[0]) & MONITOR_PANIC) {
  403. printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
  404. goto error_iounmap;
  405. }
  406. /*
  407. * Check to see if the board panic'd while booting.
  408. */
  409. if (rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) {
  410. printk(KERN_ERR "%s%d: adapter kernel panic'd.\n", dev->name, instance);
  411. goto error_iounmap;
  412. }
  413. start = jiffies;
  414. /*
  415. * Wait for the adapter to be up and running. Wait up to 3 minutes
  416. */
  417. while (!(rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING))
  418. {
  419. if(time_after(jiffies, start+180*HZ))
  420. {
  421. status = rkt_readl(dev, MUnit.OMRx[0]);
  422. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  423. dev->name, instance, status);
  424. goto error_iounmap;
  425. }
  426. set_current_state(TASK_UNINTERRUPTIBLE);
  427. schedule_timeout(1);
  428. }
  429. if (request_irq(dev->scsi_host_ptr->irq, aac_rkt_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0)
  430. {
  431. printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
  432. goto error_iounmap;
  433. }
  434. /*
  435. * Fill in the function dispatch table.
  436. */
  437. dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter;
  438. dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
  439. dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
  440. dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
  441. dev->a_ops.adapter_check_health = aac_rkt_check_health;
  442. dev->a_ops.adapter_send = aac_rkt_send;
  443. /*
  444. * First clear out all interrupts. Then enable the one's that we
  445. * can handle.
  446. */
  447. rkt_writeb(dev, MUnit.OIMR, 0xff);
  448. rkt_writel(dev, MUnit.ODR, 0xffffffff);
  449. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  450. if (aac_init_adapter(dev) == NULL)
  451. goto error_irq;
  452. if (dev->new_comm_interface) {
  453. /*
  454. * FIB Setup has already been done, but we can minimize the
  455. * damage by at least ensuring the OS never issues more
  456. * commands than we can handle. The Rocket adapters currently
  457. * can only handle 246 commands and 8 AIFs at the same time,
  458. * and in fact do notify us accordingly if we negotiate the
  459. * FIB size. The problem that causes us to add this check is
  460. * to ensure that we do not overdo it with the adapter when a
  461. * hard coded FIB override is being utilized. This special
  462. * case warrants this half baked, but convenient, check here.
  463. */
  464. if (dev->scsi_host_ptr->can_queue > (246 - AAC_NUM_MGT_FIB)) {
  465. dev->init->MaxIoCommands = cpu_to_le32(246);
  466. dev->scsi_host_ptr->can_queue = 246 - AAC_NUM_MGT_FIB;
  467. }
  468. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
  469. }
  470. /*
  471. * Tell the adapter that all is configured, and it can start
  472. * accepting requests
  473. */
  474. aac_rkt_start_adapter(dev);
  475. return 0;
  476. error_irq:
  477. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  478. free_irq(dev->scsi_host_ptr->irq, (void *)dev);
  479. error_iounmap:
  480. return -1;
  481. }