blob: 9c7408fe8c7d1cb2d630e40e245cc9e642912441 [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 *
Mark Haverkamp03d44332007-03-15 10:27:45 -07008 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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 * dpcsup.c
26 *
27 * Abstract: All DPC processing routines for the cyclone board occur here.
28 *
29 *
30 */
31
32#include <linux/kernel.h>
33#include <linux/init.h>
34#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/spinlock.h>
36#include <linux/slab.h>
37#include <linux/completion.h>
38#include <linux/blkdev.h>
Matthew Wilcox6188e102008-04-18 22:21:05 -040039#include <linux/semaphore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include "aacraid.h"
42
43/**
44 * aac_response_normal - Handle command replies
45 * @q: Queue to read from
46 *
47 * This DPC routine will be run when the adapter interrupts us to let us
48 * know there is a response on our normal priority queue. We will pull off
49 * all QE there are and wake up all the waiters before exiting. We will
50 * take a spinlock out on the queue before operating on it.
51 */
52
53unsigned int aac_response_normal(struct aac_queue * q)
54{
55 struct aac_dev * dev = q->dev;
56 struct aac_entry *entry;
57 struct hw_fib * hwfib;
58 struct fib * fib;
59 int consumed = 0;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +053060 unsigned long flags, mflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +053062 spin_lock_irqsave(q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /*
64 * Keep pulling response QEs off the response queue and waking
65 * up the waiters until there are no more QEs. We then return
66 * back to the system. If no response was requesed we just
67 * deallocate the Fib here and continue.
68 */
69 while(aac_consumer_get(dev, q, &entry))
70 {
71 int fast;
72 u32 index = le32_to_cpu(entry->addr);
73 fast = index & 0x01;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -070074 fib = &dev->fibs[index >> 2];
Mark Haverkampa8166a52007-03-15 10:26:22 -070075 hwfib = fib->hw_fib_va;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 aac_consumer_free(dev, q, HostNormRespQueue);
78 /*
79 * Remove this fib from the Outstanding I/O queue.
80 * But only if it has not already been timed out.
81 *
82 * If the fib has been timed out already, then just
83 * continue. The caller has already been notified that
84 * the fib timed out.
85 */
Mark Haverkamp03d44332007-03-15 10:27:45 -070086 dev->queues->queue[AdapNormCmdQueue].numpending--;
87
88 if (unlikely(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
89 spin_unlock_irqrestore(q->lock, flags);
90 aac_fib_complete(fib);
91 aac_fib_free(fib);
92 spin_lock_irqsave(q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 continue;
94 }
95 spin_unlock_irqrestore(q->lock, flags);
96
97 if (fast) {
98 /*
99 * Doctor the fib
100 */
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700101 *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
103 }
104
105 FIB_COUNTER_INCREMENT(aac_config.FibRecved);
106
107 if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
108 {
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700109 __le32 *pstatus = (__le32 *)hwfib->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 if (*pstatus & cpu_to_le32(0xffff0000))
111 *pstatus = cpu_to_le32(ST_OK);
112 }
113 if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
114 {
115 if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
116 FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
117 else
118 FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
119 /*
120 * NOTE: we cannot touch the fib after this
121 * call, because it may have been deallocated.
122 */
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800123 fib->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 fib->callback(fib->callback_data, fib);
125 } else {
126 unsigned long flagv;
127 spin_lock_irqsave(&fib->event_lock, flagv);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530128 if (!fib->done) {
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700129 fib->done = 1;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530130 up(&fib->event_wait);
131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 spin_unlock_irqrestore(&fib->event_lock, flagv);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530133
134 spin_lock_irqsave(&dev->manage_lock, mflags);
135 dev->management_fib_count--;
136 spin_unlock_irqrestore(&dev->manage_lock, mflags);
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700139 if (fib->done == 2) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530140 spin_lock_irqsave(&fib->event_lock, flagv);
141 fib->done = 0;
142 spin_unlock_irqrestore(&fib->event_lock, flagv);
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700143 aac_fib_complete(fib);
144 aac_fib_free(fib);
145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147 consumed++;
148 spin_lock_irqsave(q->lock, flags);
149 }
150
151 if (consumed > aac_config.peak_fibs)
152 aac_config.peak_fibs = consumed;
153 if (consumed == 0)
154 aac_config.zero_fibs++;
155
156 spin_unlock_irqrestore(q->lock, flags);
157 return 0;
158}
159
160
161/**
162 * aac_command_normal - handle commands
163 * @q: queue to process
164 *
165 * This DPC routine will be queued when the adapter interrupts us to
166 * let us know there is a command on our normal priority queue. We will
167 * pull off all QE there are and wake up all the waiters before exiting.
168 * We will take a spinlock out on the queue before operating on it.
169 */
170
171unsigned int aac_command_normal(struct aac_queue *q)
172{
173 struct aac_dev * dev = q->dev;
174 struct aac_entry *entry;
175 unsigned long flags;
176
177 spin_lock_irqsave(q->lock, flags);
178
179 /*
180 * Keep pulling response QEs off the response queue and waking
181 * up the waiters until there are no more QEs. We then return
182 * back to the system.
183 */
184 while(aac_consumer_get(dev, q, &entry))
185 {
186 struct fib fibctx;
187 struct hw_fib * hw_fib;
188 u32 index;
189 struct fib *fib = &fibctx;
190
191 index = le32_to_cpu(entry->addr) / sizeof(struct hw_fib);
192 hw_fib = &dev->aif_base_va[index];
193
194 /*
195 * Allocate a FIB at all costs. For non queued stuff
196 * we can just use the stack so we are happy. We need
197 * a fib object in order to manage the linked lists
198 */
199 if (dev->aif_thread)
200 if((fib = kmalloc(sizeof(struct fib), GFP_ATOMIC)) == NULL)
201 fib = &fibctx;
202
203 memset(fib, 0, sizeof(struct fib));
204 INIT_LIST_HEAD(&fib->fiblink);
205 fib->type = FSAFS_NTC_FIB_CONTEXT;
206 fib->size = sizeof(struct fib);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700207 fib->hw_fib_va = hw_fib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 fib->data = hw_fib->data;
209 fib->dev = dev;
210
211
212 if (dev->aif_thread && fib != &fibctx) {
213 list_add_tail(&fib->fiblink, &q->cmdq);
214 aac_consumer_free(dev, q, HostNormCmdQueue);
215 wake_up_interruptible(&q->cmdready);
216 } else {
217 aac_consumer_free(dev, q, HostNormCmdQueue);
218 spin_unlock_irqrestore(q->lock, flags);
219 /*
220 * Set the status of this FIB
221 */
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700222 *(__le32 *)hw_fib->data = cpu_to_le32(ST_OK);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800223 aac_fib_adapter_complete(fib, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 spin_lock_irqsave(q->lock, flags);
225 }
226 }
227 spin_unlock_irqrestore(q->lock, flags);
228 return 0;
229}
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700230
231
232/**
233 * aac_intr_normal - Handle command replies
234 * @dev: Device
235 * @index: completion reference
236 *
237 * This DPC routine will be run when the adapter interrupts us to let us
238 * know there is a response on our normal priority queue. We will pull off
239 * all QE there are and wake up all the waiters before exiting.
240 */
241
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800242unsigned int aac_intr_normal(struct aac_dev * dev, u32 index)
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700243{
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530244 unsigned long mflags;
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000245 dprintk((KERN_INFO "aac_intr_normal(%p,%x)\n", dev, index));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700246 if ((index & 0x00000002L)) {
247 struct hw_fib * hw_fib;
248 struct fib * fib;
249 struct aac_queue *q = &dev->queues->queue[HostNormCmdQueue];
250 unsigned long flags;
251
252 if (index == 0xFFFFFFFEL) /* Special Case */
253 return 0; /* Do nothing */
254 /*
255 * Allocate a FIB. For non queued stuff we can just use
256 * the stack so we are happy. We need a fib object in order to
257 * manage the linked lists.
258 */
259 if ((!dev->aif_thread)
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -0400260 || (!(fib = kzalloc(sizeof(struct fib),GFP_ATOMIC))))
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700261 return 1;
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -0400262 if (!(hw_fib = kzalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700263 kfree (fib);
264 return 1;
265 }
Al Viro142956a2007-10-29 05:11:28 +0000266 memcpy(hw_fib, (struct hw_fib *)(((uintptr_t)(dev->regs.sa)) +
Salyzyn, Mark4dfb7cb2007-03-27 15:07:28 -0400267 (index & ~0x00000002L)), sizeof(struct hw_fib));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700268 INIT_LIST_HEAD(&fib->fiblink);
269 fib->type = FSAFS_NTC_FIB_CONTEXT;
270 fib->size = sizeof(struct fib);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700271 fib->hw_fib_va = hw_fib;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700272 fib->data = hw_fib->data;
273 fib->dev = dev;
274
275 spin_lock_irqsave(q->lock, flags);
276 list_add_tail(&fib->fiblink, &q->cmdq);
277 wake_up_interruptible(&q->cmdready);
278 spin_unlock_irqrestore(q->lock, flags);
279 return 1;
280 } else {
281 int fast = index & 0x01;
282 struct fib * fib = &dev->fibs[index >> 2];
Mark Haverkampa8166a52007-03-15 10:26:22 -0700283 struct hw_fib * hwfib = fib->hw_fib_va;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700284
285 /*
286 * Remove this fib from the Outstanding I/O queue.
287 * But only if it has not already been timed out.
288 *
289 * If the fib has been timed out already, then just
290 * continue. The caller has already been notified that
291 * the fib timed out.
292 */
Mark Haverkamp03d44332007-03-15 10:27:45 -0700293 dev->queues->queue[AdapNormCmdQueue].numpending--;
294
295 if (unlikely(fib->flags & FIB_CONTEXT_FLAG_TIMED_OUT)) {
296 aac_fib_complete(fib);
297 aac_fib_free(fib);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700298 return 0;
299 }
300
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700301 if (fast) {
302 /*
303 * Doctor the fib
304 */
305 *(__le32 *)hwfib->data = cpu_to_le32(ST_OK);
306 hwfib->header.XferState |= cpu_to_le32(AdapterProcessed);
307 }
308
309 FIB_COUNTER_INCREMENT(aac_config.FibRecved);
310
311 if (hwfib->header.Command == cpu_to_le16(NuFileSystem))
312 {
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000313 __le32 *pstatus = (__le32 *)hwfib->data;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700314 if (*pstatus & cpu_to_le32(0xffff0000))
315 *pstatus = cpu_to_le32(ST_OK);
316 }
317 if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected | Async))
318 {
319 if (hwfib->header.XferState & cpu_to_le32(NoResponseExpected))
320 FIB_COUNTER_INCREMENT(aac_config.NoResponseRecved);
321 else
322 FIB_COUNTER_INCREMENT(aac_config.AsyncRecved);
323 /*
324 * NOTE: we cannot touch the fib after this
325 * call, because it may have been deallocated.
326 */
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800327 fib->flags = 0;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700328 fib->callback(fib->callback_data, fib);
329 } else {
330 unsigned long flagv;
331 dprintk((KERN_INFO "event_wait up\n"));
332 spin_lock_irqsave(&fib->event_lock, flagv);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530333 if (!fib->done) {
Mark Haverkampc8f7b072006-08-03 08:02:24 -0700334 fib->done = 1;
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530335 up(&fib->event_wait);
336 }
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700337 spin_unlock_irqrestore(&fib->event_lock, flagv);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530338
339 spin_lock_irqsave(&dev->manage_lock, mflags);
340 dev->management_fib_count--;
341 spin_unlock_irqrestore(&dev->manage_lock, mflags);
342
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700343 FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530344 if (fib->done == 2) {
345 spin_lock_irqsave(&fib->event_lock, flagv);
346 fib->done = 0;
347 spin_unlock_irqrestore(&fib->event_lock, flagv);
348 aac_fib_complete(fib);
349 aac_fib_free(fib);
350 }
351
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700352 }
353 return 0;
354 }
355}