rkt.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. unsigned long bellbits;
  49. u8 intstat, mask;
  50. intstat = rkt_readb(dev, MUnit.OISR);
  51. /*
  52. * Read mask and invert because drawbridge is reversed.
  53. * This allows us to only service interrupts that have
  54. * been enabled.
  55. */
  56. mask = ~(dev->OIMR);
  57. /* Check to see if this is our interrupt. If it isn't just return */
  58. if (intstat & mask)
  59. {
  60. bellbits = rkt_readl(dev, OutboundDoorbellReg);
  61. if (bellbits & DoorBellPrintfReady) {
  62. aac_printf(dev, rkt_readl(dev, IndexRegs.Mailbox[5]));
  63. rkt_writel(dev, MUnit.ODR,DoorBellPrintfReady);
  64. rkt_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
  65. }
  66. else if (bellbits & DoorBellAdapterNormCmdReady) {
  67. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
  68. aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
  69. }
  70. else if (bellbits & DoorBellAdapterNormRespReady) {
  71. aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
  72. rkt_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
  73. }
  74. else if (bellbits & DoorBellAdapterNormCmdNotFull) {
  75. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  76. }
  77. else if (bellbits & DoorBellAdapterNormRespNotFull) {
  78. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
  79. rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
  80. }
  81. return IRQ_HANDLED;
  82. }
  83. return IRQ_NONE;
  84. }
  85. /**
  86. * aac_rkt_disable_interrupt - Disable interrupts
  87. * @dev: Adapter
  88. */
  89. static void aac_rkt_disable_interrupt(struct aac_dev *dev)
  90. {
  91. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  92. }
  93. /**
  94. * rkt_sync_cmd - send a command and wait
  95. * @dev: Adapter
  96. * @command: Command to execute
  97. * @p1: first parameter
  98. * @ret: adapter status
  99. *
  100. * This routine will send a synchronous command to the adapter and wait
  101. * for its completion.
  102. */
  103. static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
  104. u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
  105. u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
  106. {
  107. unsigned long start;
  108. int ok;
  109. /*
  110. * Write the command into Mailbox 0
  111. */
  112. rkt_writel(dev, InboundMailbox0, command);
  113. /*
  114. * Write the parameters into Mailboxes 1 - 6
  115. */
  116. rkt_writel(dev, InboundMailbox1, p1);
  117. rkt_writel(dev, InboundMailbox2, p2);
  118. rkt_writel(dev, InboundMailbox3, p3);
  119. rkt_writel(dev, InboundMailbox4, p4);
  120. /*
  121. * Clear the synch command doorbell to start on a clean slate.
  122. */
  123. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  124. /*
  125. * Disable doorbell interrupts
  126. */
  127. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  128. /*
  129. * Force the completion of the mask register write before issuing
  130. * the interrupt.
  131. */
  132. rkt_readb (dev, MUnit.OIMR);
  133. /*
  134. * Signal that there is a new synch command
  135. */
  136. rkt_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
  137. ok = 0;
  138. start = jiffies;
  139. /*
  140. * Wait up to 30 seconds
  141. */
  142. while (time_before(jiffies, start+30*HZ))
  143. {
  144. udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
  145. /*
  146. * Mon960 will set doorbell0 bit when it has completed the command.
  147. */
  148. if (rkt_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
  149. /*
  150. * Clear the doorbell.
  151. */
  152. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  153. ok = 1;
  154. break;
  155. }
  156. /*
  157. * Yield the processor in case we are slow
  158. */
  159. set_current_state(TASK_UNINTERRUPTIBLE);
  160. schedule_timeout(1);
  161. }
  162. if (ok != 1) {
  163. /*
  164. * Restore interrupt mask even though we timed out
  165. */
  166. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  167. return -ETIMEDOUT;
  168. }
  169. /*
  170. * Pull the synch status from Mailbox 0.
  171. */
  172. if (status)
  173. *status = rkt_readl(dev, IndexRegs.Mailbox[0]);
  174. if (r1)
  175. *r1 = rkt_readl(dev, IndexRegs.Mailbox[1]);
  176. if (r2)
  177. *r2 = rkt_readl(dev, IndexRegs.Mailbox[2]);
  178. if (r3)
  179. *r3 = rkt_readl(dev, IndexRegs.Mailbox[3]);
  180. if (r4)
  181. *r4 = rkt_readl(dev, IndexRegs.Mailbox[4]);
  182. /*
  183. * Clear the synch command doorbell.
  184. */
  185. rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
  186. /*
  187. * Restore interrupt mask
  188. */
  189. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  190. return 0;
  191. }
  192. /**
  193. * aac_rkt_interrupt_adapter - interrupt adapter
  194. * @dev: Adapter
  195. *
  196. * Send an interrupt to the i960 and breakpoint it.
  197. */
  198. static void aac_rkt_interrupt_adapter(struct aac_dev *dev)
  199. {
  200. rkt_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
  201. NULL, NULL, NULL, NULL, NULL);
  202. }
  203. /**
  204. * aac_rkt_notify_adapter - send an event to the adapter
  205. * @dev: Adapter
  206. * @event: Event to send
  207. *
  208. * Notify the i960 that something it probably cares about has
  209. * happened.
  210. */
  211. static void aac_rkt_notify_adapter(struct aac_dev *dev, u32 event)
  212. {
  213. switch (event) {
  214. case AdapNormCmdQue:
  215. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
  216. break;
  217. case HostNormRespNotFull:
  218. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
  219. break;
  220. case AdapNormRespQue:
  221. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
  222. break;
  223. case HostNormCmdNotFull:
  224. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
  225. break;
  226. case HostShutdown:
  227. // rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
  228. // NULL, NULL, NULL, NULL, NULL);
  229. break;
  230. case FastIo:
  231. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
  232. break;
  233. case AdapPrintfDone:
  234. rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
  235. break;
  236. default:
  237. BUG();
  238. break;
  239. }
  240. }
  241. /**
  242. * aac_rkt_start_adapter - activate adapter
  243. * @dev: Adapter
  244. *
  245. * Start up processing on an i960 based AAC adapter
  246. */
  247. static void aac_rkt_start_adapter(struct aac_dev *dev)
  248. {
  249. struct aac_init *init;
  250. init = dev->init;
  251. init->HostElapsedSeconds = cpu_to_le32(get_seconds());
  252. /*
  253. * First clear out all interrupts. Then enable the one's that we
  254. * can handle.
  255. */
  256. rkt_writeb(dev, MUnit.OIMR, 0xff);
  257. rkt_writel(dev, MUnit.ODR, 0xffffffff);
  258. // rkt_writeb(dev, MUnit.OIMR, ~(u8)OUTBOUND_DOORBELL_INTERRUPT_MASK);
  259. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  260. // We can only use a 32 bit address here
  261. rkt_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
  262. 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
  263. }
  264. /**
  265. * aac_rkt_check_health
  266. * @dev: device to check if healthy
  267. *
  268. * Will attempt to determine if the specified adapter is alive and
  269. * capable of handling requests, returning 0 if alive.
  270. */
  271. static int aac_rkt_check_health(struct aac_dev *dev)
  272. {
  273. u32 status = rkt_readl(dev, MUnit.OMRx[0]);
  274. /*
  275. * Check to see if the board failed any self tests.
  276. */
  277. if (status & SELF_TEST_FAILED)
  278. return -1;
  279. /*
  280. * Check to see if the board panic'd.
  281. */
  282. if (status & KERNEL_PANIC) {
  283. char * buffer;
  284. struct POSTSTATUS {
  285. __le32 Post_Command;
  286. __le32 Post_Address;
  287. } * post;
  288. dma_addr_t paddr, baddr;
  289. int ret;
  290. if ((status & 0xFF000000L) == 0xBC000000L)
  291. return (status >> 16) & 0xFF;
  292. buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
  293. ret = -2;
  294. if (buffer == NULL)
  295. return ret;
  296. post = pci_alloc_consistent(dev->pdev,
  297. sizeof(struct POSTSTATUS), &paddr);
  298. if (post == NULL) {
  299. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  300. return ret;
  301. }
  302. memset(buffer, 0, 512);
  303. post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
  304. post->Post_Address = cpu_to_le32(baddr);
  305. rkt_writel(dev, MUnit.IMRx[0], paddr);
  306. rkt_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
  307. NULL, NULL, NULL, NULL, NULL);
  308. pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
  309. post, paddr);
  310. if ((buffer[0] == '0') && (buffer[1] == 'x')) {
  311. ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
  312. ret <<= 4;
  313. ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
  314. }
  315. pci_free_consistent(dev->pdev, 512, buffer, baddr);
  316. return ret;
  317. }
  318. /*
  319. * Wait for the adapter to be up and running.
  320. */
  321. if (!(status & KERNEL_UP_AND_RUNNING))
  322. return -3;
  323. /*
  324. * Everything is OK
  325. */
  326. return 0;
  327. }
  328. /**
  329. * aac_rkt_init - initialize an i960 based AAC card
  330. * @dev: device to configure
  331. *
  332. * Allocate and set up resources for the i960 based AAC variants. The
  333. * device_interface in the commregion will be allocated and linked
  334. * to the comm region.
  335. */
  336. int aac_rkt_init(struct aac_dev *dev)
  337. {
  338. unsigned long start;
  339. unsigned long status;
  340. int instance;
  341. const char * name;
  342. instance = dev->id;
  343. name = dev->name;
  344. /*
  345. * Map in the registers from the adapter.
  346. */
  347. if((dev->regs.rkt = ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
  348. {
  349. printk(KERN_WARNING "aacraid: unable to map i960.\n" );
  350. goto error_iounmap;
  351. }
  352. /*
  353. * Check to see if the board failed any self tests.
  354. */
  355. if (rkt_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) {
  356. printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
  357. goto error_iounmap;
  358. }
  359. /*
  360. * Check to see if the monitor panic'd while booting.
  361. */
  362. if (rkt_readl(dev, MUnit.OMRx[0]) & MONITOR_PANIC) {
  363. printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
  364. goto error_iounmap;
  365. }
  366. /*
  367. * Check to see if the board panic'd while booting.
  368. */
  369. if (rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) {
  370. printk(KERN_ERR "%s%d: adapter kernel panic'd.\n", dev->name, instance);
  371. goto error_iounmap;
  372. }
  373. start = jiffies;
  374. /*
  375. * Wait for the adapter to be up and running. Wait up to 3 minutes
  376. */
  377. while (!(rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING))
  378. {
  379. if(time_after(jiffies, start+180*HZ))
  380. {
  381. status = rkt_readl(dev, MUnit.OMRx[0]);
  382. printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
  383. dev->name, instance, status);
  384. goto error_iounmap;
  385. }
  386. set_current_state(TASK_UNINTERRUPTIBLE);
  387. schedule_timeout(1);
  388. }
  389. if (request_irq(dev->scsi_host_ptr->irq, aac_rkt_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0)
  390. {
  391. printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
  392. goto error_iounmap;
  393. }
  394. /*
  395. * Fill in the function dispatch table.
  396. */
  397. dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter;
  398. dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
  399. dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
  400. dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
  401. dev->a_ops.adapter_check_health = aac_rkt_check_health;
  402. /*
  403. * First clear out all interrupts. Then enable the one's that we
  404. * can handle.
  405. */
  406. rkt_writeb(dev, MUnit.OIMR, 0xff);
  407. rkt_writel(dev, MUnit.ODR, 0xffffffff);
  408. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
  409. if (aac_init_adapter(dev) == NULL)
  410. goto error_irq;
  411. /*
  412. * Start any kernel threads needed
  413. */
  414. dev->thread_pid = kernel_thread((int (*)(void *))aac_command_thread, dev, 0);
  415. if(dev->thread_pid < 0)
  416. {
  417. printk(KERN_ERR "aacraid: Unable to create rkt thread.\n");
  418. goto error_kfree;
  419. }
  420. /*
  421. * Tell the adapter that all is configured, and it can start
  422. * accepting requests
  423. */
  424. aac_rkt_start_adapter(dev);
  425. return 0;
  426. error_kfree:
  427. kfree(dev->queues);
  428. error_irq:
  429. rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
  430. free_irq(dev->scsi_host_ptr->irq, (void *)dev);
  431. error_iounmap:
  432. iounmap(dev->regs.rkt);
  433. return -1;
  434. }