blob: 93ef7c37e568e0e2ca4a38d8a08dd1b987482626 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -08009 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
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 Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/pci.h>
37#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#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 Torvalds1da177e2005-04-16 15:20:36 -070043
44#include <scsi/scsi_host.h>
45
46#include "aacraid.h"
47
Mark Haverkamp28713322007-01-23 14:59:20 -080048static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 struct aac_dev *dev = dev_id;
Mark Haverkamp28713322007-01-23 14:59:20 -080051 unsigned long bellbits;
52 u8 intstat = rx_readb(dev, MUnit.OISR);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -070053
Mark Haverkamp28713322007-01-23 14:59:20 -080054 /*
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, Mark912d4e82007-03-26 09:21:14 -040060 if (likely(intstat & ~(dev->OIMR))) {
Mark Haverkamp28713322007-01-23 14:59:20 -080061 bellbits = rx_readl(dev, OutboundDoorbellReg);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040062 if (unlikely(bellbits & DoorBellPrintfReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080063 aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
64 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
65 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
66 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040067 else if (unlikely(bellbits & DoorBellAdapterNormCmdReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080068 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
69 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
70 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040071 else if (likely(bellbits & DoorBellAdapterNormRespReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080072 rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
73 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
74 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040075 else if (unlikely(bellbits & DoorBellAdapterNormCmdNotFull)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080076 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
77 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040078 else if (unlikely(bellbits & DoorBellAdapterNormRespNotFull)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080079 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
87static irqreturn_t aac_rx_intr_message(int irq, void *dev_id)
88{
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070089 int isAif, isFastResponse, isSpecial;
Mark Haverkamp28713322007-01-23 14:59:20 -080090 struct aac_dev *dev = dev_id;
91 u32 Index = rx_readl(dev, MUnit.OutboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040092 if (unlikely(Index == 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -080093 Index = rx_readl(dev, MUnit.OutboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040094 if (likely(Index != 0xFFFFFFFFL)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080095 do {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070096 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 Haverkamp28713322007-01-23 14:59:20 -0800118 }
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700119 Index = rx_readl(dev, MUnit.OutboundQueue);
Mark Haverkamp28713322007-01-23 14:59:20 -0800120 } while (Index != 0xFFFFFFFFL);
121 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123 return IRQ_NONE;
124}
125
126/**
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700127 * aac_rx_disable_interrupt - Disable interrupts
128 * @dev: Adapter
129 */
130
131static void aac_rx_disable_interrupt(struct aac_dev *dev)
132{
133 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
134}
135
136/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800137 * aac_rx_enable_interrupt_producer - Enable interrupts
138 * @dev: Adapter
139 */
140
141static 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
151static void aac_rx_enable_interrupt_message(struct aac_dev *dev)
152{
153 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
154}
155
156/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 * 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 7c00ffa2005-05-16 18:28:42 -0700167static 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 Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 unsigned long start;
172 int ok;
173 /*
174 * Write the command into Mailbox 0
175 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700176 writel(command, &dev->IndexRegs->Mailbox[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700178 * Write the parameters into Mailboxes 1 - 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700180 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 Torvalds1da177e2005-04-16 15:20:36 -0700184 /*
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 7c00ffa2005-05-16 18:28:42 -0700191 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /*
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 Haverkamp1241f352006-03-27 09:44:23 -0800225 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400227 if (unlikely(ok != 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /*
229 * Restore interrupt mask even though we timed out
230 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800231 aac_adapter_enable_int(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return -ETIMEDOUT;
233 }
234 /*
235 * Pull the synch status from Mailbox 0.
236 */
237 if (status)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700238 *status = readl(&dev->IndexRegs->Mailbox[0]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700239 if (r1)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700240 *r1 = readl(&dev->IndexRegs->Mailbox[1]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700241 if (r2)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700242 *r2 = readl(&dev->IndexRegs->Mailbox[2]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700243 if (r3)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700244 *r3 = readl(&dev->IndexRegs->Mailbox[3]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700245 if (r4)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700246 *r4 = readl(&dev->IndexRegs->Mailbox[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 /*
248 * Clear the synch command doorbell.
249 */
250 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
251 /*
252 * Restore interrupt mask
253 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800254 aac_adapter_enable_int(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 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
266static void aac_rx_interrupt_adapter(struct aac_dev *dev)
267{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700268 rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
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
280static 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 Torvalds1da177e2005-04-16 15:20:36 -0700297 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 Bunk9695a252007-03-26 21:59:35 -0800317static void aac_rx_start_adapter(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -0800319 union aac_init *init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 init = dev->init;
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -0800322 init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 // We can only use a 32 bit address here
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700324 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 Torvalds1da177e2005-04-16 15:20:36 -0700326}
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 */
335static 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, Mark912d4e82007-03-26 09:21:14 -0400342 if (unlikely(status & SELF_TEST_FAILED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return -1;
344 /*
345 * Check to see if the board panic'd.
346 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400347 if (unlikely(status & KERNEL_PANIC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 char * buffer;
349 struct POSTSTATUS {
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700350 __le32 Post_Command;
351 __le32 Post_Address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 } * post;
353 dma_addr_t paddr, baddr;
354 int ret;
355
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400356 if (likely((status & 0xFF000000L) == 0xBC000000L))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return (status >> 16) & 0xFF;
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530358 buffer = dma_alloc_coherent(&dev->pdev->dev, 512, &baddr,
359 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 ret = -2;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400361 if (unlikely(buffer == NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return ret;
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530363 post = dma_alloc_coherent(&dev->pdev->dev,
364 sizeof(struct POSTSTATUS), &paddr,
365 GFP_KERNEL);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400366 if (unlikely(post == NULL)) {
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530367 dma_free_coherent(&dev->pdev->dev, 512, buffer, baddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 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 7c00ffa2005-05-16 18:28:42 -0700374 rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
375 NULL, NULL, NULL, NULL, NULL);
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530376 dma_free_coherent(&dev->pdev->dev, sizeof(struct POSTSTATUS),
377 post, paddr);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400378 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) {
Andy Shevchenkoecc30992010-08-10 18:01:27 -0700379 ret = (hex_to_bin(buffer[2]) << 4) +
380 hex_to_bin(buffer[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
Mahesh Rajashekharaf4819732017-04-05 16:14:16 +0530382 dma_free_coherent(&dev->pdev->dev, 512, buffer, baddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return ret;
384 }
385 /*
386 * Wait for the adapter to be up and running.
387 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400388 if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return -3;
390 /*
391 * Everything is OK
392 */
393 return 0;
394}
395
396/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800397 * aac_rx_deliver_producer
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700398 * @fib: fib to issue
399 *
400 * Will send a fib, returning 0 if successful.
401 */
Salyzyn, Mark2ab01ef2007-05-15 09:14:21 -0400402int aac_rx_deliver_producer(struct fib * fib)
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700403{
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700404 struct aac_dev *dev = fib->dev;
Mark Haverkamp28713322007-01-23 14:59:20 -0800405 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700406 u32 Index;
Mark Haverkamp28713322007-01-23 14:59:20 -0800407 unsigned long nointr = 0;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700408
Mark Haverkampa8166a52007-03-15 10:26:22 -0700409 aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib_va, 1, fib, &nointr);
Mark Haverkamp28713322007-01-23 14:59:20 -0800410
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400411 atomic_inc(&q->numpending);
Mark Haverkamp28713322007-01-23 14:59:20 -0800412 *(q->headers.producer) = cpu_to_le32(Index + 1);
Mark Haverkamp28713322007-01-23 14:59:20 -0800413 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 */
425static 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 Haverkamp28713322007-01-23 14:59:20 -0800429 u32 Index;
430 u64 addr;
431 volatile void __iomem *device;
432
433 unsigned long count = 10000000L; /* 50 seconds */
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400434 atomic_inc(&q->numpending);
Mark Haverkamp28713322007-01-23 14:59:20 -0800435 for(;;) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700436 Index = rx_readl(dev, MUnit.InboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400437 if (unlikely(Index == 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -0800438 Index = rx_readl(dev, MUnit.InboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400439 if (likely(Index != 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -0800440 break;
441 if (--count == 0) {
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400442 atomic_dec(&q->numpending);
Mark Haverkamp28713322007-01-23 14:59:20 -0800443 return -ETIMEDOUT;
444 }
445 udelay(5);
446 }
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700447 device = dev->base + Index;
Mark Haverkamp28713322007-01-23 14:59:20 -0800448 addr = fib->hw_fib_pa;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700449 writel((u32)(addr & 0xffffffff), device);
450 device += sizeof(u32);
451 writel((u32)(addr >> 32), device);
452 device += sizeof(u32);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700453 writel(le16_to_cpu(fib->hw_fib_va->header.Size), device);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700454 rx_writel(dev, MUnit.InboundQueue, Index);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700455 return 0;
456}
457
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700458/**
459 * aac_rx_ioremap
460 * @size: mapping resize request
461 *
462 */
463static int aac_rx_ioremap(struct aac_dev * dev, u32 size)
464{
465 if (!size) {
466 iounmap(dev->regs.rx);
467 return 0;
468 }
Ben Collinsff087842012-06-11 14:05:02 -0400469 dev->base = dev->regs.rx = ioremap(dev->base_start, size);
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700470 if (dev->base == NULL)
471 return -1;
472 dev->IndexRegs = &dev->regs.rx->IndexRegs;
473 return 0;
474}
475
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -0800476static int aac_rx_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700477{
Mahesh Rajashekhara6e40e5f2014-01-13 13:50:30 +0530478 u32 var = 0;
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700479
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800480 if (!(dev->supplement_adapter_info.supported_options2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800481 AAC_OPTION_MU_RESET) || (bled >= 0) || (bled == -2)) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400482 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, Mark9859c1a2007-07-27 10:29:26 -0400488 if (!bled && (var != 0x00000001) && (var != 0x3803000F))
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400489 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 Haverkamp8c23cd72006-08-08 08:52:14 -0700494
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400495 if (bled && (bled != -ETIMEDOUT))
496 return -EINVAL;
497 }
Mahesh Rajashekhara6e40e5f2014-01-13 13:50:30 +0530498 if (bled && (var == 0x3803000F)) { /* USE_OTHER_METHOD */
Mark Haverkamp84188522007-03-15 10:26:05 -0700499 rx_writel(dev, MUnit.reserved2, 3);
500 msleep(5000); /* Delay 5 seconds */
501 var = 0x00000001;
502 }
Mahesh Rajashekhara6e40e5f2014-01-13 13:50:30 +0530503 if (bled && (var != 0x00000001))
Mark Haverkamp84188522007-03-15 10:26:05 -0700504 return -EINVAL;
Mahesh Rajashekhara6e40e5f2014-01-13 13:50:30 +0530505 ssleep(5);
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700506 if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC)
Mark Haverkamp84188522007-03-15 10:26:05 -0700507 return -ENODEV;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400508 if (startup_timeout < 300)
509 startup_timeout = 300;
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700510 return 0;
511}
512
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700513/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800514 * aac_rx_select_comm - Select communications method
515 * @dev: Adapter
516 * @comm: communications method
517 */
518
519int 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 Torvalds1da177e2005-04-16 15:20:36 -0700539 * 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 Haverkamp76a7f8f2006-09-19 09:00:02 -0700547int _aac_rx_init(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 unsigned long start;
550 unsigned long status;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400551 int restart = 0;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400552 int instance = dev->id;
553 const char * name = dev->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700555 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, Mark18a65982007-03-30 10:30:48 -0400560 /* Failure to reset here is an option ... */
Salyzyn, Marka5694ec2007-04-30 13:22:24 -0400561 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
562 dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400563 dev->OIMR = status = rx_readb (dev, MUnit.OIMR);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400564 if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) &&
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -0800565 !aac_rx_restart_adapter(dev, 0, IOP_HWSOFT_RESET))
Salyzyn, Markf8583172007-10-30 15:50:49 -0400566 /* Make sure the Hardware FIFO is empty */
567 while ((++restart < 512) &&
568 (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /*
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700570 * Check to see if the board panic'd while booting.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700572 status = rx_readl(dev, MUnit.OMRx[0]);
Mark Haverkamp84188522007-03-15 10:26:05 -0700573 if (status & KERNEL_PANIC) {
Raghava Aditya Renukunta31364322017-02-02 15:53:33 -0800574 if (aac_rx_restart_adapter(dev,
575 aac_rx_check_health(dev), IOP_HWSOFT_RESET))
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700576 goto error_iounmap;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400577 ++restart;
Mark Haverkamp84188522007-03-15 10:26:05 -0700578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 /*
580 * Check to see if the board failed any self tests.
581 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700582 status = rx_readl(dev, MUnit.OMRx[0]);
583 if (status & SELF_TEST_FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
585 goto error_iounmap;
586 }
587 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 * Check to see if the monitor panic'd while booting.
589 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700590 if (status & MONITOR_PANIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 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 Haverkamp76a7f8f2006-09-19 09:00:02 -0700598 while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400600 if ((restart &&
601 (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
602 time_after(jiffies, start+HZ*startup_timeout)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 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, Mark18a65982007-03-30 10:30:48 -0400607 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 Renukunta31364322017-02-02 15:53:33 -0800613 if (likely(!aac_rx_restart_adapter(dev,
614 aac_rx_check_health(dev), IOP_HWSOFT_RESET)))
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400615 start = jiffies;
616 ++restart;
617 }
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700618 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400620 if (restart && aac_commit)
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400621 aac_commit = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 /*
Mark Haverkamp28713322007-01-23 14:59:20 -0800623 * Fill in the common function dispatch table.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 */
625 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700626 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 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 Haverkamp84188522007-03-15 10:26:05 -0700630 dev->a_ops.adapter_restart = aac_rx_restart_adapter;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400631 dev->a_ops.adapter_start = aac_rx_start_adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700633 /*
634 * First clear out all interrupts. Then enable the one's that we
635 * can handle.
636 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800637 aac_adapter_comm(dev, AAC_COMM_PRODUCER);
638 aac_adapter_disable_int(dev);
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700639 rx_writel(dev, MUnit.ODR, 0xffffffff);
Mark Haverkamp28713322007-01-23 14:59:20 -0800640 aac_adapter_enable_int(dev);
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (aac_init_adapter(dev) == NULL)
Mark Haverkamp28713322007-01-23 14:59:20 -0800643 goto error_iounmap;
644 aac_adapter_comm(dev, dev->comm_interface);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800645 dev->sync_mode = 0; /* sync. mode not supported */
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800646 dev->msi = aac_msi && !pci_enable_msi(dev->pdev);
647 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
Michael Opdenacker4909cc22014-03-05 06:09:41 +0100648 IRQF_SHARED, "aacraid", dev) < 0) {
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800649 if (dev->msi)
650 pci_disable_msi(dev->pdev);
Mark Haverkamp28713322007-01-23 14:59:20 -0800651 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
652 name, instance);
653 goto error_iounmap;
654 }
Ben Collinsff087842012-06-11 14:05:02 -0400655 dev->dbg_base = dev->base_start;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700656 dev->dbg_base_mapped = dev->base;
657 dev->dbg_size = dev->base_size;
658
Mark Haverkamp28713322007-01-23 14:59:20 -0800659 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 Haverkamp8e0c5eb2005-10-24 10:52:22 -0700665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return 0;
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668error_iounmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 return -1;
671}
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700672
673int aac_rx_init(struct aac_dev *dev)
674{
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700675 /*
676 * Fill in the function dispatch table.
677 */
678 dev->a_ops.adapter_ioremap = aac_rx_ioremap;
Mark Haverkamp28713322007-01-23 14:59:20 -0800679 dev->a_ops.adapter_comm = aac_rx_select_comm;
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700680
Mark Haverkamp28713322007-01-23 14:59:20 -0800681 return _aac_rx_init(dev);
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700682}