Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 8 | * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * rx.c |
| 26 | * |
| 27 | * Abstract: Hardware miniport for Drawbridge specific hardware functions. |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 44 | #include <scsi/scsi_host.h> |
| 45 | |
| 46 | #include "aacraid.h" |
| 47 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 48 | static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | struct aac_dev *dev = dev_id; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 51 | unsigned long bellbits; |
| 52 | u8 intstat = rx_readb(dev, MUnit.OISR); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 53 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 54 | /* |
| 55 | * Read mask and invert because drawbridge is reversed. |
| 56 | * This allows us to only service interrupts that have |
| 57 | * been enabled. |
| 58 | * Check to see if this is our interrupt. If it isn't just return |
| 59 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 60 | if (likely(intstat & ~(dev->OIMR))) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 61 | bellbits = rx_readl(dev, OutboundDoorbellReg); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 62 | if (unlikely(bellbits & DoorBellPrintfReady)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 63 | aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5])); |
| 64 | rx_writel(dev, MUnit.ODR,DoorBellPrintfReady); |
| 65 | rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone); |
| 66 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 67 | else if (unlikely(bellbits & DoorBellAdapterNormCmdReady)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 68 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady); |
| 69 | aac_command_normal(&dev->queues->queue[HostNormCmdQueue]); |
| 70 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 71 | else if (likely(bellbits & DoorBellAdapterNormRespReady)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 72 | rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady); |
| 73 | aac_response_normal(&dev->queues->queue[HostNormRespQueue]); |
| 74 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 75 | else if (unlikely(bellbits & DoorBellAdapterNormCmdNotFull)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 76 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull); |
| 77 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 78 | else if (unlikely(bellbits & DoorBellAdapterNormRespNotFull)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 79 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull); |
| 80 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull); |
| 81 | } |
| 82 | return IRQ_HANDLED; |
| 83 | } |
| 84 | return IRQ_NONE; |
| 85 | } |
| 86 | |
| 87 | static irqreturn_t aac_rx_intr_message(int irq, void *dev_id) |
| 88 | { |
| 89 | struct aac_dev *dev = dev_id; |
| 90 | u32 Index = rx_readl(dev, MUnit.OutboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 91 | if (unlikely(Index == 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 92 | Index = rx_readl(dev, MUnit.OutboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 93 | if (likely(Index != 0xFFFFFFFFL)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 94 | do { |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 95 | if (unlikely(aac_intr_normal(dev, Index))) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 96 | rx_writel(dev, MUnit.OutboundQueue, Index); |
| 97 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady); |
| 98 | } |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 99 | Index = rx_readl(dev, MUnit.OutboundQueue); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 100 | } while (Index != 0xFFFFFFFFL); |
| 101 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | return IRQ_NONE; |
| 104 | } |
| 105 | |
| 106 | /** |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 107 | * aac_rx_disable_interrupt - Disable interrupts |
| 108 | * @dev: Adapter |
| 109 | */ |
| 110 | |
| 111 | static void aac_rx_disable_interrupt(struct aac_dev *dev) |
| 112 | { |
| 113 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); |
| 114 | } |
| 115 | |
| 116 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 117 | * aac_rx_enable_interrupt_producer - Enable interrupts |
| 118 | * @dev: Adapter |
| 119 | */ |
| 120 | |
| 121 | static void aac_rx_enable_interrupt_producer(struct aac_dev *dev) |
| 122 | { |
| 123 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * aac_rx_enable_interrupt_message - Enable interrupts |
| 128 | * @dev: Adapter |
| 129 | */ |
| 130 | |
| 131 | static void aac_rx_enable_interrupt_message(struct aac_dev *dev) |
| 132 | { |
| 133 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7); |
| 134 | } |
| 135 | |
| 136 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | * rx_sync_cmd - send a command and wait |
| 138 | * @dev: Adapter |
| 139 | * @command: Command to execute |
| 140 | * @p1: first parameter |
| 141 | * @ret: adapter status |
| 142 | * |
| 143 | * This routine will send a synchronous command to the adapter and wait |
| 144 | * for its completion. |
| 145 | */ |
| 146 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 147 | static int rx_sync_cmd(struct aac_dev *dev, u32 command, |
| 148 | u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, |
| 149 | u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | unsigned long start; |
| 152 | int ok; |
| 153 | /* |
| 154 | * Write the command into Mailbox 0 |
| 155 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 156 | writel(command, &dev->IndexRegs->Mailbox[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 158 | * Write the parameters into Mailboxes 1 - 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 160 | writel(p1, &dev->IndexRegs->Mailbox[1]); |
| 161 | writel(p2, &dev->IndexRegs->Mailbox[2]); |
| 162 | writel(p3, &dev->IndexRegs->Mailbox[3]); |
| 163 | writel(p4, &dev->IndexRegs->Mailbox[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* |
| 165 | * Clear the synch command doorbell to start on a clean slate. |
| 166 | */ |
| 167 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 168 | /* |
| 169 | * Disable doorbell interrupts |
| 170 | */ |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 171 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* |
| 173 | * Force the completion of the mask register write before issuing |
| 174 | * the interrupt. |
| 175 | */ |
| 176 | rx_readb (dev, MUnit.OIMR); |
| 177 | /* |
| 178 | * Signal that there is a new synch command |
| 179 | */ |
| 180 | rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0); |
| 181 | |
| 182 | ok = 0; |
| 183 | start = jiffies; |
| 184 | |
| 185 | /* |
| 186 | * Wait up to 30 seconds |
| 187 | */ |
| 188 | while (time_before(jiffies, start+30*HZ)) |
| 189 | { |
| 190 | udelay(5); /* Delay 5 microseconds to let Mon960 get info. */ |
| 191 | /* |
| 192 | * Mon960 will set doorbell0 bit when it has completed the command. |
| 193 | */ |
| 194 | if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) { |
| 195 | /* |
| 196 | * Clear the doorbell. |
| 197 | */ |
| 198 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 199 | ok = 1; |
| 200 | break; |
| 201 | } |
| 202 | /* |
| 203 | * Yield the processor in case we are slow |
| 204 | */ |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 205 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 207 | if (unlikely(ok != 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* |
| 209 | * Restore interrupt mask even though we timed out |
| 210 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 211 | aac_adapter_enable_int(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return -ETIMEDOUT; |
| 213 | } |
| 214 | /* |
| 215 | * Pull the synch status from Mailbox 0. |
| 216 | */ |
| 217 | if (status) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 218 | *status = readl(&dev->IndexRegs->Mailbox[0]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 219 | if (r1) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 220 | *r1 = readl(&dev->IndexRegs->Mailbox[1]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 221 | if (r2) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 222 | *r2 = readl(&dev->IndexRegs->Mailbox[2]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 223 | if (r3) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 224 | *r3 = readl(&dev->IndexRegs->Mailbox[3]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 225 | if (r4) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 226 | *r4 = readl(&dev->IndexRegs->Mailbox[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* |
| 228 | * Clear the synch command doorbell. |
| 229 | */ |
| 230 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 231 | /* |
| 232 | * Restore interrupt mask |
| 233 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 234 | aac_adapter_enable_int(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * aac_rx_interrupt_adapter - interrupt adapter |
| 241 | * @dev: Adapter |
| 242 | * |
| 243 | * Send an interrupt to the i960 and breakpoint it. |
| 244 | */ |
| 245 | |
| 246 | static void aac_rx_interrupt_adapter(struct aac_dev *dev) |
| 247 | { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 248 | rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * aac_rx_notify_adapter - send an event to the adapter |
| 253 | * @dev: Adapter |
| 254 | * @event: Event to send |
| 255 | * |
| 256 | * Notify the i960 that something it probably cares about has |
| 257 | * happened. |
| 258 | */ |
| 259 | |
| 260 | static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event) |
| 261 | { |
| 262 | switch (event) { |
| 263 | |
| 264 | case AdapNormCmdQue: |
| 265 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1); |
| 266 | break; |
| 267 | case HostNormRespNotFull: |
| 268 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4); |
| 269 | break; |
| 270 | case AdapNormRespQue: |
| 271 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2); |
| 272 | break; |
| 273 | case HostNormCmdNotFull: |
| 274 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3); |
| 275 | break; |
| 276 | case HostShutdown: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | case FastIo: |
| 279 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6); |
| 280 | break; |
| 281 | case AdapPrintfDone: |
| 282 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5); |
| 283 | break; |
| 284 | default: |
| 285 | BUG(); |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * aac_rx_start_adapter - activate adapter |
| 292 | * @dev: Adapter |
| 293 | * |
| 294 | * Start up processing on an i960 based AAC adapter |
| 295 | */ |
| 296 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 297 | void aac_rx_start_adapter(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | struct aac_init *init; |
| 300 | |
| 301 | init = dev->init; |
| 302 | init->HostElapsedSeconds = cpu_to_le32(get_seconds()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | // We can only use a 32 bit address here |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 304 | rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, |
| 305 | 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
| 309 | * aac_rx_check_health |
| 310 | * @dev: device to check if healthy |
| 311 | * |
| 312 | * Will attempt to determine if the specified adapter is alive and |
| 313 | * capable of handling requests, returning 0 if alive. |
| 314 | */ |
| 315 | static int aac_rx_check_health(struct aac_dev *dev) |
| 316 | { |
| 317 | u32 status = rx_readl(dev, MUnit.OMRx[0]); |
| 318 | |
| 319 | /* |
| 320 | * Check to see if the board failed any self tests. |
| 321 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 322 | if (unlikely(status & SELF_TEST_FAILED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return -1; |
| 324 | /* |
| 325 | * Check to see if the board panic'd. |
| 326 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 327 | if (unlikely(status & KERNEL_PANIC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | char * buffer; |
| 329 | struct POSTSTATUS { |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 330 | __le32 Post_Command; |
| 331 | __le32 Post_Address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } * post; |
| 333 | dma_addr_t paddr, baddr; |
| 334 | int ret; |
| 335 | |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 336 | if (likely((status & 0xFF000000L) == 0xBC000000L)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return (status >> 16) & 0xFF; |
| 338 | buffer = pci_alloc_consistent(dev->pdev, 512, &baddr); |
| 339 | ret = -2; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 340 | if (unlikely(buffer == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | return ret; |
| 342 | post = pci_alloc_consistent(dev->pdev, |
| 343 | sizeof(struct POSTSTATUS), &paddr); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 344 | if (unlikely(post == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | pci_free_consistent(dev->pdev, 512, buffer, baddr); |
| 346 | return ret; |
| 347 | } |
| 348 | memset(buffer, 0, 512); |
| 349 | post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS); |
| 350 | post->Post_Address = cpu_to_le32(baddr); |
| 351 | rx_writel(dev, MUnit.IMRx[0], paddr); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 352 | rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0, |
| 353 | NULL, NULL, NULL, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), |
| 355 | post, paddr); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 356 | if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); |
| 358 | ret <<= 4; |
| 359 | ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10); |
| 360 | } |
| 361 | pci_free_consistent(dev->pdev, 512, buffer, baddr); |
| 362 | return ret; |
| 363 | } |
| 364 | /* |
| 365 | * Wait for the adapter to be up and running. |
| 366 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 367 | if (unlikely(!(status & KERNEL_UP_AND_RUNNING))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return -3; |
| 369 | /* |
| 370 | * Everything is OK |
| 371 | */ |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 376 | * aac_rx_deliver_producer |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 377 | * @fib: fib to issue |
| 378 | * |
| 379 | * Will send a fib, returning 0 if successful. |
| 380 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 381 | static int aac_rx_deliver_producer(struct fib * fib) |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 382 | { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 383 | struct aac_dev *dev = fib->dev; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 384 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; |
| 385 | unsigned long qflags; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 386 | u32 Index; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 387 | unsigned long nointr = 0; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 388 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 389 | spin_lock_irqsave(q->lock, qflags); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 390 | aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib_va, 1, fib, &nointr); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 391 | |
| 392 | q->numpending++; |
| 393 | *(q->headers.producer) = cpu_to_le32(Index + 1); |
| 394 | spin_unlock_irqrestore(q->lock, qflags); |
| 395 | if (!(nointr & aac_config.irq_mod)) |
| 396 | aac_adapter_notify(dev, AdapNormCmdQueue); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * aac_rx_deliver_message |
| 403 | * @fib: fib to issue |
| 404 | * |
| 405 | * Will send a fib, returning 0 if successful. |
| 406 | */ |
| 407 | static int aac_rx_deliver_message(struct fib * fib) |
| 408 | { |
| 409 | struct aac_dev *dev = fib->dev; |
| 410 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; |
| 411 | unsigned long qflags; |
| 412 | u32 Index; |
| 413 | u64 addr; |
| 414 | volatile void __iomem *device; |
| 415 | |
| 416 | unsigned long count = 10000000L; /* 50 seconds */ |
| 417 | spin_lock_irqsave(q->lock, qflags); |
| 418 | q->numpending++; |
| 419 | spin_unlock_irqrestore(q->lock, qflags); |
| 420 | for(;;) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 421 | Index = rx_readl(dev, MUnit.InboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 422 | if (unlikely(Index == 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 423 | Index = rx_readl(dev, MUnit.InboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 424 | if (likely(Index != 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 425 | break; |
| 426 | if (--count == 0) { |
| 427 | spin_lock_irqsave(q->lock, qflags); |
| 428 | q->numpending--; |
| 429 | spin_unlock_irqrestore(q->lock, qflags); |
| 430 | return -ETIMEDOUT; |
| 431 | } |
| 432 | udelay(5); |
| 433 | } |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 434 | device = dev->base + Index; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 435 | addr = fib->hw_fib_pa; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 436 | writel((u32)(addr & 0xffffffff), device); |
| 437 | device += sizeof(u32); |
| 438 | writel((u32)(addr >> 32), device); |
| 439 | device += sizeof(u32); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 440 | writel(le16_to_cpu(fib->hw_fib_va->header.Size), device); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 441 | rx_writel(dev, MUnit.InboundQueue, Index); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 445 | /** |
| 446 | * aac_rx_ioremap |
| 447 | * @size: mapping resize request |
| 448 | * |
| 449 | */ |
| 450 | static int aac_rx_ioremap(struct aac_dev * dev, u32 size) |
| 451 | { |
| 452 | if (!size) { |
| 453 | iounmap(dev->regs.rx); |
| 454 | return 0; |
| 455 | } |
| 456 | dev->base = dev->regs.rx = ioremap(dev->scsi_host_ptr->base, size); |
| 457 | if (dev->base == NULL) |
| 458 | return -1; |
| 459 | dev->IndexRegs = &dev->regs.rx->IndexRegs; |
| 460 | return 0; |
| 461 | } |
| 462 | |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 463 | static int aac_rx_restart_adapter(struct aac_dev *dev, int bled) |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 464 | { |
| 465 | u32 var; |
| 466 | |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 467 | if (bled) |
| 468 | printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n", |
| 469 | dev->name, dev->id, bled); |
| 470 | else |
| 471 | bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS, |
| 472 | 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL); |
| 473 | if (bled) |
| 474 | bled = aac_adapter_sync_cmd(dev, IOP_RESET, |
| 475 | 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL); |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 476 | |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 477 | if (bled) |
| 478 | return -EINVAL; |
| 479 | if (var == 0x3803000F) { /* USE_OTHER_METHOD */ |
| 480 | rx_writel(dev, MUnit.reserved2, 3); |
| 481 | msleep(5000); /* Delay 5 seconds */ |
| 482 | var = 0x00000001; |
| 483 | } |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 484 | if (var != 0x00000001) |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 485 | return -EINVAL; |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 486 | if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 487 | return -ENODEV; |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 491 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 492 | * aac_rx_select_comm - Select communications method |
| 493 | * @dev: Adapter |
| 494 | * @comm: communications method |
| 495 | */ |
| 496 | |
| 497 | int aac_rx_select_comm(struct aac_dev *dev, int comm) |
| 498 | { |
| 499 | switch (comm) { |
| 500 | case AAC_COMM_PRODUCER: |
| 501 | dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_producer; |
| 502 | dev->a_ops.adapter_intr = aac_rx_intr_producer; |
| 503 | dev->a_ops.adapter_deliver = aac_rx_deliver_producer; |
| 504 | break; |
| 505 | case AAC_COMM_MESSAGE: |
| 506 | dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_message; |
| 507 | dev->a_ops.adapter_intr = aac_rx_intr_message; |
| 508 | dev->a_ops.adapter_deliver = aac_rx_deliver_message; |
| 509 | break; |
| 510 | default: |
| 511 | return 1; |
| 512 | } |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | * aac_rx_init - initialize an i960 based AAC card |
| 518 | * @dev: device to configure |
| 519 | * |
| 520 | * Allocate and set up resources for the i960 based AAC variants. The |
| 521 | * device_interface in the commregion will be allocated and linked |
| 522 | * to the comm region. |
| 523 | */ |
| 524 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 525 | int _aac_rx_init(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
| 527 | unsigned long start; |
| 528 | unsigned long status; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 529 | int instance = dev->id; |
| 530 | const char * name = dev->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 532 | if (aac_adapter_ioremap(dev, dev->base_size)) { |
| 533 | printk(KERN_WARNING "%s: unable to map adapter.\n", name); |
| 534 | goto error_iounmap; |
| 535 | } |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 538 | * Check to see if the board panic'd while booting. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 540 | status = rx_readl(dev, MUnit.OMRx[0]); |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 541 | if (status & KERNEL_PANIC) { |
| 542 | if ((status = aac_rx_check_health(dev)) <= 0) |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 543 | goto error_iounmap; |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 544 | if (aac_rx_restart_adapter(dev, status)) |
| 545 | goto error_iounmap; |
| 546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | /* |
| 548 | * Check to see if the board failed any self tests. |
| 549 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 550 | status = rx_readl(dev, MUnit.OMRx[0]); |
| 551 | if (status & SELF_TEST_FAILED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance); |
| 553 | goto error_iounmap; |
| 554 | } |
| 555 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | * Check to see if the monitor panic'd while booting. |
| 557 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 558 | if (status & MONITOR_PANIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance); |
| 560 | goto error_iounmap; |
| 561 | } |
| 562 | start = jiffies; |
| 563 | /* |
| 564 | * Wait for the adapter to be up and running. Wait up to 3 minutes |
| 565 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 566 | while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame^] | 568 | if(time_after(jiffies, start+startup_timeout*HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", |
| 570 | dev->name, instance, status); |
| 571 | goto error_iounmap; |
| 572 | } |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 573 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | /* |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 576 | * Fill in the common function dispatch table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | */ |
| 578 | dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter; |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 579 | dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | dev->a_ops.adapter_notify = aac_rx_notify_adapter; |
| 581 | dev->a_ops.adapter_sync_cmd = rx_sync_cmd; |
| 582 | dev->a_ops.adapter_check_health = aac_rx_check_health; |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 583 | dev->a_ops.adapter_restart = aac_rx_restart_adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 585 | /* |
| 586 | * First clear out all interrupts. Then enable the one's that we |
| 587 | * can handle. |
| 588 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 589 | aac_adapter_comm(dev, AAC_COMM_PRODUCER); |
| 590 | aac_adapter_disable_int(dev); |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 591 | rx_writel(dev, MUnit.ODR, 0xffffffff); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 592 | aac_adapter_enable_int(dev); |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | if (aac_init_adapter(dev) == NULL) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 595 | goto error_iounmap; |
| 596 | aac_adapter_comm(dev, dev->comm_interface); |
| 597 | if (request_irq(dev->scsi_host_ptr->irq, dev->a_ops.adapter_intr, |
| 598 | IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) { |
| 599 | printk(KERN_ERR "%s%d: Interrupt unavailable.\n", |
| 600 | name, instance); |
| 601 | goto error_iounmap; |
| 602 | } |
| 603 | aac_adapter_enable_int(dev); |
| 604 | /* |
| 605 | * Tell the adapter that all is configured, and it can |
| 606 | * start accepting requests |
| 607 | */ |
| 608 | aac_rx_start_adapter(dev); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | return 0; |
| 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | error_iounmap: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | return -1; |
| 615 | } |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 616 | |
| 617 | int aac_rx_init(struct aac_dev *dev) |
| 618 | { |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 619 | /* |
| 620 | * Fill in the function dispatch table. |
| 621 | */ |
| 622 | dev->a_ops.adapter_ioremap = aac_rx_ioremap; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 623 | dev->a_ops.adapter_comm = aac_rx_select_comm; |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 624 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 625 | return _aac_rx_init(dev); |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 626 | } |