Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AAC series RAID controller driver |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 3 | * (c) Copyright 2001 Red Hat Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * based on the old aacraid driver that is.. |
| 6 | * Adaptec aacraid device driver for Linux. |
| 7 | * |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 8 | * Copyright (c) 2000-2010 Adaptec, Inc. |
Raghava Aditya Renukunta | f4babba | 2017-02-02 15:53:36 -0800 | [diff] [blame] | 9 | * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com) |
| 10 | * 2016-2017 Microsemi Corp. (aacraid@microsemi.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; see the file COPYING. If not, write to |
| 24 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
| 26 | * Module Name: |
| 27 | * rx.c |
| 28 | * |
| 29 | * Abstract: Hardware miniport for Drawbridge specific hardware functions. |
| 30 | * |
| 31 | */ |
| 32 | |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/pci.h> |
| 37 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/blkdev.h> |
| 39 | #include <linux/delay.h> |
| 40 | #include <linux/completion.h> |
| 41 | #include <linux/time.h> |
| 42 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 89 | int isAif, isFastResponse, isSpecial; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 90 | struct aac_dev *dev = dev_id; |
| 91 | u32 Index = rx_readl(dev, MUnit.OutboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 92 | if (unlikely(Index == 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 93 | Index = rx_readl(dev, MUnit.OutboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 94 | if (likely(Index != 0xFFFFFFFFL)) { |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 95 | do { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 96 | isAif = isFastResponse = isSpecial = 0; |
| 97 | if (Index & 0x00000002L) { |
| 98 | isAif = 1; |
| 99 | if (Index == 0xFFFFFFFEL) |
| 100 | isSpecial = 1; |
| 101 | Index &= ~0x00000002L; |
| 102 | } else { |
| 103 | if (Index & 0x00000001L) |
| 104 | isFastResponse = 1; |
| 105 | Index >>= 2; |
| 106 | } |
| 107 | if (!isSpecial) { |
| 108 | if (unlikely(aac_intr_normal(dev, |
| 109 | Index, isAif, |
| 110 | isFastResponse, NULL))) { |
| 111 | rx_writel(dev, |
| 112 | MUnit.OutboundQueue, |
| 113 | Index); |
| 114 | rx_writel(dev, |
| 115 | MUnit.ODR, |
| 116 | DoorBellAdapterNormRespReady); |
| 117 | } |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 118 | } |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 119 | Index = rx_readl(dev, MUnit.OutboundQueue); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 120 | } while (Index != 0xFFFFFFFFL); |
| 121 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | return IRQ_NONE; |
| 124 | } |
| 125 | |
| 126 | /** |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 127 | * aac_rx_disable_interrupt - Disable interrupts |
| 128 | * @dev: Adapter |
| 129 | */ |
| 130 | |
| 131 | static void aac_rx_disable_interrupt(struct aac_dev *dev) |
| 132 | { |
| 133 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); |
| 134 | } |
| 135 | |
| 136 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 137 | * aac_rx_enable_interrupt_producer - Enable interrupts |
| 138 | * @dev: Adapter |
| 139 | */ |
| 140 | |
| 141 | static void aac_rx_enable_interrupt_producer(struct aac_dev *dev) |
| 142 | { |
| 143 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * aac_rx_enable_interrupt_message - Enable interrupts |
| 148 | * @dev: Adapter |
| 149 | */ |
| 150 | |
| 151 | static void aac_rx_enable_interrupt_message(struct aac_dev *dev) |
| 152 | { |
| 153 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7); |
| 154 | } |
| 155 | |
| 156 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | * rx_sync_cmd - send a command and wait |
| 158 | * @dev: Adapter |
| 159 | * @command: Command to execute |
| 160 | * @p1: first parameter |
| 161 | * @ret: adapter status |
| 162 | * |
| 163 | * This routine will send a synchronous command to the adapter and wait |
| 164 | * for its completion. |
| 165 | */ |
| 166 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 167 | static int rx_sync_cmd(struct aac_dev *dev, u32 command, |
| 168 | u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, |
| 169 | u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | unsigned long start; |
| 172 | int ok; |
| 173 | /* |
| 174 | * Write the command into Mailbox 0 |
| 175 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 176 | writel(command, &dev->IndexRegs->Mailbox[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | /* |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 178 | * Write the parameters into Mailboxes 1 - 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 180 | writel(p1, &dev->IndexRegs->Mailbox[1]); |
| 181 | writel(p2, &dev->IndexRegs->Mailbox[2]); |
| 182 | writel(p3, &dev->IndexRegs->Mailbox[3]); |
| 183 | writel(p4, &dev->IndexRegs->Mailbox[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* |
| 185 | * Clear the synch command doorbell to start on a clean slate. |
| 186 | */ |
| 187 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 188 | /* |
| 189 | * Disable doorbell interrupts |
| 190 | */ |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 191 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Force the completion of the mask register write before issuing |
| 194 | * the interrupt. |
| 195 | */ |
| 196 | rx_readb (dev, MUnit.OIMR); |
| 197 | /* |
| 198 | * Signal that there is a new synch command |
| 199 | */ |
| 200 | rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0); |
| 201 | |
| 202 | ok = 0; |
| 203 | start = jiffies; |
| 204 | |
| 205 | /* |
| 206 | * Wait up to 30 seconds |
| 207 | */ |
| 208 | while (time_before(jiffies, start+30*HZ)) |
| 209 | { |
| 210 | udelay(5); /* Delay 5 microseconds to let Mon960 get info. */ |
| 211 | /* |
| 212 | * Mon960 will set doorbell0 bit when it has completed the command. |
| 213 | */ |
| 214 | if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) { |
| 215 | /* |
| 216 | * Clear the doorbell. |
| 217 | */ |
| 218 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 219 | ok = 1; |
| 220 | break; |
| 221 | } |
| 222 | /* |
| 223 | * Yield the processor in case we are slow |
| 224 | */ |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 225 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 227 | if (unlikely(ok != 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* |
| 229 | * Restore interrupt mask even though we timed out |
| 230 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 231 | aac_adapter_enable_int(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return -ETIMEDOUT; |
| 233 | } |
| 234 | /* |
| 235 | * Pull the synch status from Mailbox 0. |
| 236 | */ |
| 237 | if (status) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 238 | *status = readl(&dev->IndexRegs->Mailbox[0]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 239 | if (r1) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 240 | *r1 = readl(&dev->IndexRegs->Mailbox[1]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 241 | if (r2) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 242 | *r2 = readl(&dev->IndexRegs->Mailbox[2]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 243 | if (r3) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 244 | *r3 = readl(&dev->IndexRegs->Mailbox[3]); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 245 | if (r4) |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 246 | *r4 = readl(&dev->IndexRegs->Mailbox[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /* |
| 248 | * Clear the synch command doorbell. |
| 249 | */ |
| 250 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); |
| 251 | /* |
| 252 | * Restore interrupt mask |
| 253 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 254 | aac_adapter_enable_int(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * aac_rx_interrupt_adapter - interrupt adapter |
| 261 | * @dev: Adapter |
| 262 | * |
| 263 | * Send an interrupt to the i960 and breakpoint it. |
| 264 | */ |
| 265 | |
| 266 | static void aac_rx_interrupt_adapter(struct aac_dev *dev) |
| 267 | { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 268 | 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] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * aac_rx_notify_adapter - send an event to the adapter |
| 273 | * @dev: Adapter |
| 274 | * @event: Event to send |
| 275 | * |
| 276 | * Notify the i960 that something it probably cares about has |
| 277 | * happened. |
| 278 | */ |
| 279 | |
| 280 | static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event) |
| 281 | { |
| 282 | switch (event) { |
| 283 | |
| 284 | case AdapNormCmdQue: |
| 285 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1); |
| 286 | break; |
| 287 | case HostNormRespNotFull: |
| 288 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4); |
| 289 | break; |
| 290 | case AdapNormRespQue: |
| 291 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2); |
| 292 | break; |
| 293 | case HostNormCmdNotFull: |
| 294 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3); |
| 295 | break; |
| 296 | case HostShutdown: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | break; |
| 298 | case FastIo: |
| 299 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6); |
| 300 | break; |
| 301 | case AdapPrintfDone: |
| 302 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5); |
| 303 | break; |
| 304 | default: |
| 305 | BUG(); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * aac_rx_start_adapter - activate adapter |
| 312 | * @dev: Adapter |
| 313 | * |
| 314 | * Start up processing on an i960 based AAC adapter |
| 315 | */ |
| 316 | |
Adrian Bunk | 9695a25 | 2007-03-26 21:59:35 -0800 | [diff] [blame] | 317 | static void aac_rx_start_adapter(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
Raghava Aditya Renukunta | d1ef4da | 2017-02-02 15:53:17 -0800 | [diff] [blame] | 319 | union aac_init *init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | init = dev->init; |
Raghava Aditya Renukunta | d1ef4da | 2017-02-02 15:53:17 -0800 | [diff] [blame] | 322 | init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | // We can only use a 32 bit address here |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 324 | rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, |
| 325 | 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
| 329 | * aac_rx_check_health |
| 330 | * @dev: device to check if healthy |
| 331 | * |
| 332 | * Will attempt to determine if the specified adapter is alive and |
| 333 | * capable of handling requests, returning 0 if alive. |
| 334 | */ |
| 335 | static int aac_rx_check_health(struct aac_dev *dev) |
| 336 | { |
| 337 | u32 status = rx_readl(dev, MUnit.OMRx[0]); |
| 338 | |
| 339 | /* |
| 340 | * Check to see if the board failed any self tests. |
| 341 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 342 | if (unlikely(status & SELF_TEST_FAILED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return -1; |
| 344 | /* |
| 345 | * Check to see if the board panic'd. |
| 346 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 347 | if (unlikely(status & KERNEL_PANIC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | char * buffer; |
| 349 | struct POSTSTATUS { |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 350 | __le32 Post_Command; |
| 351 | __le32 Post_Address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } * post; |
| 353 | dma_addr_t paddr, baddr; |
| 354 | int ret; |
| 355 | |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 356 | if (likely((status & 0xFF000000L) == 0xBC000000L)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return (status >> 16) & 0xFF; |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 358 | buffer = dma_alloc_coherent(&dev->pdev->dev, 512, &baddr, |
| 359 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | ret = -2; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 361 | if (unlikely(buffer == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return ret; |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 363 | post = dma_alloc_coherent(&dev->pdev->dev, |
| 364 | sizeof(struct POSTSTATUS), &paddr, |
| 365 | GFP_KERNEL); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 366 | if (unlikely(post == NULL)) { |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 367 | dma_free_coherent(&dev->pdev->dev, 512, buffer, baddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return ret; |
| 369 | } |
| 370 | memset(buffer, 0, 512); |
| 371 | post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS); |
| 372 | post->Post_Address = cpu_to_le32(baddr); |
| 373 | rx_writel(dev, MUnit.IMRx[0], paddr); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 374 | rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0, |
| 375 | NULL, NULL, NULL, NULL, NULL); |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 376 | dma_free_coherent(&dev->pdev->dev, sizeof(struct POSTSTATUS), |
| 377 | post, paddr); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 378 | if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { |
Andy Shevchenko | ecc3099 | 2010-08-10 18:01:27 -0700 | [diff] [blame] | 379 | ret = (hex_to_bin(buffer[2]) << 4) + |
| 380 | hex_to_bin(buffer[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
Mahesh Rajashekhara | f481973 | 2017-04-05 16:14:16 +0530 | [diff] [blame] | 382 | dma_free_coherent(&dev->pdev->dev, 512, buffer, baddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return ret; |
| 384 | } |
| 385 | /* |
| 386 | * Wait for the adapter to be up and running. |
| 387 | */ |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 388 | if (unlikely(!(status & KERNEL_UP_AND_RUNNING))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return -3; |
| 390 | /* |
| 391 | * Everything is OK |
| 392 | */ |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 397 | * aac_rx_deliver_producer |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 398 | * @fib: fib to issue |
| 399 | * |
| 400 | * Will send a fib, returning 0 if successful. |
| 401 | */ |
Salyzyn, Mark | 2ab01ef | 2007-05-15 09:14:21 -0400 | [diff] [blame] | 402 | int aac_rx_deliver_producer(struct fib * fib) |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 403 | { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 404 | struct aac_dev *dev = fib->dev; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 405 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 406 | u32 Index; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 407 | unsigned long nointr = 0; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 408 | |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 409 | 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] | 410 | |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 411 | atomic_inc(&q->numpending); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 412 | *(q->headers.producer) = cpu_to_le32(Index + 1); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 413 | if (!(nointr & aac_config.irq_mod)) |
| 414 | aac_adapter_notify(dev, AdapNormCmdQueue); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * aac_rx_deliver_message |
| 421 | * @fib: fib to issue |
| 422 | * |
| 423 | * Will send a fib, returning 0 if successful. |
| 424 | */ |
| 425 | static int aac_rx_deliver_message(struct fib * fib) |
| 426 | { |
| 427 | struct aac_dev *dev = fib->dev; |
| 428 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 429 | u32 Index; |
| 430 | u64 addr; |
| 431 | volatile void __iomem *device; |
| 432 | |
| 433 | unsigned long count = 10000000L; /* 50 seconds */ |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 434 | atomic_inc(&q->numpending); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 435 | for(;;) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 436 | Index = rx_readl(dev, MUnit.InboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 437 | if (unlikely(Index == 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 438 | Index = rx_readl(dev, MUnit.InboundQueue); |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 439 | if (likely(Index != 0xFFFFFFFFL)) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 440 | break; |
| 441 | if (--count == 0) { |
Mahesh Rajashekhara | ef61623 | 2015-03-26 10:41:30 -0400 | [diff] [blame] | 442 | atomic_dec(&q->numpending); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 443 | return -ETIMEDOUT; |
| 444 | } |
| 445 | udelay(5); |
| 446 | } |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 447 | device = dev->base + Index; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 448 | addr = fib->hw_fib_pa; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 449 | writel((u32)(addr & 0xffffffff), device); |
| 450 | device += sizeof(u32); |
| 451 | writel((u32)(addr >> 32), device); |
| 452 | device += sizeof(u32); |
Mark Haverkamp | a8166a5 | 2007-03-15 10:26:22 -0700 | [diff] [blame] | 453 | writel(le16_to_cpu(fib->hw_fib_va->header.Size), device); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 454 | rx_writel(dev, MUnit.InboundQueue, Index); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 458 | /** |
| 459 | * aac_rx_ioremap |
| 460 | * @size: mapping resize request |
| 461 | * |
| 462 | */ |
| 463 | static int aac_rx_ioremap(struct aac_dev * dev, u32 size) |
| 464 | { |
| 465 | if (!size) { |
| 466 | iounmap(dev->regs.rx); |
| 467 | return 0; |
| 468 | } |
Ben Collins | ff08784 | 2012-06-11 14:05:02 -0400 | [diff] [blame] | 469 | dev->base = dev->regs.rx = ioremap(dev->base_start, size); |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 470 | if (dev->base == NULL) |
| 471 | return -1; |
| 472 | dev->IndexRegs = &dev->regs.rx->IndexRegs; |
| 473 | return 0; |
| 474 | } |
| 475 | |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 476 | static int aac_rx_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type) |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 477 | { |
Mahesh Rajashekhara | 6e40e5f | 2014-01-13 13:50:30 +0530 | [diff] [blame] | 478 | u32 var = 0; |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 479 | |
Raghava Aditya Renukunta | 1c68856 | 2017-02-16 12:51:10 -0800 | [diff] [blame] | 480 | if (!(dev->supplement_adapter_info.supported_options2 & |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 481 | AAC_OPTION_MU_RESET) || (bled >= 0) || (bled == -2)) { |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 482 | if (bled) |
| 483 | printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n", |
| 484 | dev->name, dev->id, bled); |
| 485 | else { |
| 486 | bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS, |
| 487 | 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL); |
Salyzyn, Mark | 9859c1a | 2007-07-27 10:29:26 -0400 | [diff] [blame] | 488 | if (!bled && (var != 0x00000001) && (var != 0x3803000F)) |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 489 | bled = -EINVAL; |
| 490 | } |
| 491 | if (bled && (bled != -ETIMEDOUT)) |
| 492 | bled = aac_adapter_sync_cmd(dev, IOP_RESET, |
| 493 | 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL); |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 494 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 495 | if (bled && (bled != -ETIMEDOUT)) |
| 496 | return -EINVAL; |
| 497 | } |
Mahesh Rajashekhara | 6e40e5f | 2014-01-13 13:50:30 +0530 | [diff] [blame] | 498 | if (bled && (var == 0x3803000F)) { /* USE_OTHER_METHOD */ |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 499 | rx_writel(dev, MUnit.reserved2, 3); |
| 500 | msleep(5000); /* Delay 5 seconds */ |
| 501 | var = 0x00000001; |
| 502 | } |
Mahesh Rajashekhara | 6e40e5f | 2014-01-13 13:50:30 +0530 | [diff] [blame] | 503 | if (bled && (var != 0x00000001)) |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 504 | return -EINVAL; |
Mahesh Rajashekhara | 6e40e5f | 2014-01-13 13:50:30 +0530 | [diff] [blame] | 505 | ssleep(5); |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 506 | if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 507 | return -ENODEV; |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 508 | if (startup_timeout < 300) |
| 509 | startup_timeout = 300; |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 510 | return 0; |
| 511 | } |
| 512 | |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 513 | /** |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 514 | * aac_rx_select_comm - Select communications method |
| 515 | * @dev: Adapter |
| 516 | * @comm: communications method |
| 517 | */ |
| 518 | |
| 519 | int aac_rx_select_comm(struct aac_dev *dev, int comm) |
| 520 | { |
| 521 | switch (comm) { |
| 522 | case AAC_COMM_PRODUCER: |
| 523 | dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_producer; |
| 524 | dev->a_ops.adapter_intr = aac_rx_intr_producer; |
| 525 | dev->a_ops.adapter_deliver = aac_rx_deliver_producer; |
| 526 | break; |
| 527 | case AAC_COMM_MESSAGE: |
| 528 | dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_message; |
| 529 | dev->a_ops.adapter_intr = aac_rx_intr_message; |
| 530 | dev->a_ops.adapter_deliver = aac_rx_deliver_message; |
| 531 | break; |
| 532 | default: |
| 533 | return 1; |
| 534 | } |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | * aac_rx_init - initialize an i960 based AAC card |
| 540 | * @dev: device to configure |
| 541 | * |
| 542 | * Allocate and set up resources for the i960 based AAC variants. The |
| 543 | * device_interface in the commregion will be allocated and linked |
| 544 | * to the comm region. |
| 545 | */ |
| 546 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 547 | int _aac_rx_init(struct aac_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { |
| 549 | unsigned long start; |
| 550 | unsigned long status; |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 551 | int restart = 0; |
Salyzyn, Mark | 912d4e8 | 2007-03-26 09:21:14 -0400 | [diff] [blame] | 552 | int instance = dev->id; |
| 553 | const char * name = dev->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 555 | if (aac_adapter_ioremap(dev, dev->base_size)) { |
| 556 | printk(KERN_WARNING "%s: unable to map adapter.\n", name); |
| 557 | goto error_iounmap; |
| 558 | } |
| 559 | |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 560 | /* Failure to reset here is an option ... */ |
Salyzyn, Mark | a5694ec | 2007-04-30 13:22:24 -0400 | [diff] [blame] | 561 | dev->a_ops.adapter_sync_cmd = rx_sync_cmd; |
| 562 | dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt; |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 563 | dev->OIMR = status = rx_readb (dev, MUnit.OIMR); |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 564 | if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) && |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 565 | !aac_rx_restart_adapter(dev, 0, IOP_HWSOFT_RESET)) |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 566 | /* Make sure the Hardware FIFO is empty */ |
| 567 | while ((++restart < 512) && |
| 568 | (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /* |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 570 | * Check to see if the board panic'd while booting. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 572 | status = rx_readl(dev, MUnit.OMRx[0]); |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 573 | if (status & KERNEL_PANIC) { |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 574 | if (aac_rx_restart_adapter(dev, |
| 575 | aac_rx_check_health(dev), IOP_HWSOFT_RESET)) |
Mark Haverkamp | 8c23cd7 | 2006-08-08 08:52:14 -0700 | [diff] [blame] | 576 | goto error_iounmap; |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 577 | ++restart; |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Check to see if the board failed any self tests. |
| 581 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 582 | status = rx_readl(dev, MUnit.OMRx[0]); |
| 583 | if (status & SELF_TEST_FAILED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance); |
| 585 | goto error_iounmap; |
| 586 | } |
| 587 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | * Check to see if the monitor panic'd while booting. |
| 589 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 590 | if (status & MONITOR_PANIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance); |
| 592 | goto error_iounmap; |
| 593 | } |
| 594 | start = jiffies; |
| 595 | /* |
| 596 | * Wait for the adapter to be up and running. Wait up to 3 minutes |
| 597 | */ |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 598 | while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 600 | if ((restart && |
| 601 | (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) || |
| 602 | time_after(jiffies, start+HZ*startup_timeout)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", |
| 604 | dev->name, instance, status); |
| 605 | goto error_iounmap; |
| 606 | } |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 607 | if (!restart && |
| 608 | ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) || |
| 609 | time_after(jiffies, start + HZ * |
| 610 | ((startup_timeout > 60) |
| 611 | ? (startup_timeout - 60) |
| 612 | : (startup_timeout / 2))))) { |
Raghava Aditya Renukunta | 3136432 | 2017-02-02 15:53:33 -0800 | [diff] [blame] | 613 | if (likely(!aac_rx_restart_adapter(dev, |
| 614 | aac_rx_check_health(dev), IOP_HWSOFT_RESET))) |
Salyzyn, Mark | 18a6598 | 2007-03-30 10:30:48 -0400 | [diff] [blame] | 615 | start = jiffies; |
| 616 | ++restart; |
| 617 | } |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 618 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 620 | if (restart && aac_commit) |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 621 | aac_commit = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | /* |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 623 | * Fill in the common function dispatch table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | */ |
| 625 | dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter; |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 626 | dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | dev->a_ops.adapter_notify = aac_rx_notify_adapter; |
| 628 | dev->a_ops.adapter_sync_cmd = rx_sync_cmd; |
| 629 | dev->a_ops.adapter_check_health = aac_rx_check_health; |
Mark Haverkamp | 8418852 | 2007-03-15 10:26:05 -0700 | [diff] [blame] | 630 | dev->a_ops.adapter_restart = aac_rx_restart_adapter; |
Mahesh Rajashekhara | de665f2 | 2015-08-28 06:38:34 -0400 | [diff] [blame] | 631 | dev->a_ops.adapter_start = aac_rx_start_adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 633 | /* |
| 634 | * First clear out all interrupts. Then enable the one's that we |
| 635 | * can handle. |
| 636 | */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 637 | aac_adapter_comm(dev, AAC_COMM_PRODUCER); |
| 638 | aac_adapter_disable_int(dev); |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 639 | rx_writel(dev, MUnit.ODR, 0xffffffff); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 640 | aac_adapter_enable_int(dev); |
Mark Haverkamp | bd1aac8 | 2005-08-03 15:39:01 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if (aac_init_adapter(dev) == NULL) |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 643 | goto error_iounmap; |
| 644 | aac_adapter_comm(dev, dev->comm_interface); |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 645 | dev->sync_mode = 0; /* sync. mode not supported */ |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 646 | dev->msi = aac_msi && !pci_enable_msi(dev->pdev); |
| 647 | if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr, |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 648 | IRQF_SHARED, "aacraid", dev) < 0) { |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 649 | if (dev->msi) |
| 650 | pci_disable_msi(dev->pdev); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 651 | printk(KERN_ERR "%s%d: Interrupt unavailable.\n", |
| 652 | name, instance); |
| 653 | goto error_iounmap; |
| 654 | } |
Ben Collins | ff08784 | 2012-06-11 14:05:02 -0400 | [diff] [blame] | 655 | dev->dbg_base = dev->base_start; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 656 | dev->dbg_base_mapped = dev->base; |
| 657 | dev->dbg_size = dev->base_size; |
| 658 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 659 | aac_adapter_enable_int(dev); |
| 660 | /* |
| 661 | * Tell the adapter that all is configured, and it can |
| 662 | * start accepting requests |
| 663 | */ |
| 664 | aac_rx_start_adapter(dev); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return 0; |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | error_iounmap: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | return -1; |
| 671 | } |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 672 | |
| 673 | int aac_rx_init(struct aac_dev *dev) |
| 674 | { |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 675 | /* |
| 676 | * Fill in the function dispatch table. |
| 677 | */ |
| 678 | dev->a_ops.adapter_ioremap = aac_rx_ioremap; |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 679 | dev->a_ops.adapter_comm = aac_rx_select_comm; |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 680 | |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 681 | return _aac_rx_init(dev); |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 682 | } |