rkt.c 12 KB

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