2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Abstract: Contain all routines that are required for FSA host/adapter
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/sched.h>
37 #include <linux/pci.h>
38 #include <linux/spinlock.h>
39 #include <linux/slab.h>
40 #include <linux/completion.h>
41 #include <linux/blkdev.h>
42 #include <linux/delay.h>
43 #include <linux/kthread.h>
44 #include <linux/interrupt.h>
45 #include <linux/semaphore.h>
46 #include <linux/bcd.h>
47 #include <scsi/scsi.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_device.h>
50 #include <scsi/scsi_cmnd.h>
55 * fib_map_alloc - allocate the fib objects
56 * @dev: Adapter to allocate for
58 * Allocate and map the shared PCI space for the FIB blocks used to
59 * talk to the Adaptec firmware.
62 static int fib_map_alloc(struct aac_dev
*dev
)
64 if (dev
->max_fib_size
> AAC_MAX_NATIVE_SIZE
)
65 dev
->max_cmd_size
= AAC_MAX_NATIVE_SIZE
;
67 dev
->max_cmd_size
= dev
->max_fib_size
;
70 "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",
71 dev
->pdev
, dev
->max_cmd_size
, dev
->scsi_host_ptr
->can_queue
,
72 AAC_NUM_MGT_FIB
, &dev
->hw_fib_pa
));
73 dev
->hw_fib_va
= pci_alloc_consistent(dev
->pdev
,
74 (dev
->max_cmd_size
+ sizeof(struct aac_fib_xporthdr
))
75 * (dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
) + (ALIGN32
- 1),
77 if (dev
->hw_fib_va
== NULL
)
83 * aac_fib_map_free - free the fib objects
84 * @dev: Adapter to free
86 * Free the PCI mappings and the memory allocated for FIB blocks
90 void aac_fib_map_free(struct aac_dev
*dev
)
92 if (dev
->hw_fib_va
&& dev
->max_cmd_size
) {
93 pci_free_consistent(dev
->pdev
,
95 (dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
)),
96 dev
->hw_fib_va
, dev
->hw_fib_pa
);
98 dev
->hw_fib_va
= NULL
;
102 void aac_fib_vector_assign(struct aac_dev
*dev
)
106 struct fib
*fibptr
= NULL
;
108 for (i
= 0, fibptr
= &dev
->fibs
[i
];
109 i
< (dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
);
111 if ((dev
->max_msix
== 1) ||
112 (i
> ((dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
- 1)
113 - dev
->vector_cap
))) {
114 fibptr
->vector_no
= 0;
116 fibptr
->vector_no
= vector
;
118 if (vector
== dev
->max_msix
)
125 * aac_fib_setup - setup the fibs
126 * @dev: Adapter to set up
128 * Allocate the PCI space for the fibs, map it and then initialise the
129 * fib area, the unmapped fib data and also the free list
132 int aac_fib_setup(struct aac_dev
* dev
)
135 struct hw_fib
*hw_fib
;
136 dma_addr_t hw_fib_pa
;
140 while (((i
= fib_map_alloc(dev
)) == -ENOMEM
)
141 && (dev
->scsi_host_ptr
->can_queue
> (64 - AAC_NUM_MGT_FIB
))) {
142 max_cmds
= (dev
->scsi_host_ptr
->can_queue
+AAC_NUM_MGT_FIB
) >> 1;
143 dev
->scsi_host_ptr
->can_queue
= max_cmds
- AAC_NUM_MGT_FIB
;
144 if (dev
->comm_interface
!= AAC_COMM_MESSAGE_TYPE3
)
145 dev
->init
->r7
.max_io_commands
= cpu_to_le32(max_cmds
);
150 /* 32 byte alignment for PMC */
151 hw_fib_pa
= (dev
->hw_fib_pa
+ (ALIGN32
- 1)) & ~(ALIGN32
- 1);
152 dev
->hw_fib_va
= (struct hw_fib
*)((unsigned char *)dev
->hw_fib_va
+
153 (hw_fib_pa
- dev
->hw_fib_pa
));
154 dev
->hw_fib_pa
= hw_fib_pa
;
155 memset(dev
->hw_fib_va
, 0,
156 (dev
->max_fib_size
+ sizeof(struct aac_fib_xporthdr
)) *
157 (dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
));
159 /* add Xport header */
160 dev
->hw_fib_va
= (struct hw_fib
*)((unsigned char *)dev
->hw_fib_va
+
161 sizeof(struct aac_fib_xporthdr
));
162 dev
->hw_fib_pa
+= sizeof(struct aac_fib_xporthdr
);
164 hw_fib
= dev
->hw_fib_va
;
165 hw_fib_pa
= dev
->hw_fib_pa
;
167 * Initialise the fibs
169 for (i
= 0, fibptr
= &dev
->fibs
[i
];
170 i
< (dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
);
174 fibptr
->size
= sizeof(struct fib
);
176 fibptr
->hw_fib_va
= hw_fib
;
177 fibptr
->data
= (void *) fibptr
->hw_fib_va
->data
;
178 fibptr
->next
= fibptr
+1; /* Forward chain the fibs */
179 sema_init(&fibptr
->event_wait
, 0);
180 spin_lock_init(&fibptr
->event_lock
);
181 hw_fib
->header
.XferState
= cpu_to_le32(0xffffffff);
182 hw_fib
->header
.SenderSize
= cpu_to_le16(dev
->max_fib_size
);
183 fibptr
->hw_fib_pa
= hw_fib_pa
;
184 hw_fib
= (struct hw_fib
*)((unsigned char *)hw_fib
+
185 dev
->max_cmd_size
+ sizeof(struct aac_fib_xporthdr
));
186 hw_fib_pa
= hw_fib_pa
+
187 dev
->max_cmd_size
+ sizeof(struct aac_fib_xporthdr
);
191 *Assign vector numbers to fibs
193 aac_fib_vector_assign(dev
);
196 * Add the fib chain to the free list
198 dev
->fibs
[dev
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
- 1].next
= NULL
;
200 * Set 8 fibs aside for management tools
202 dev
->free_fib
= &dev
->fibs
[dev
->scsi_host_ptr
->can_queue
];
207 * aac_fib_alloc_tag-allocate a fib using tags
208 * @dev: Adapter to allocate the fib for
210 * Allocate a fib from the adapter fib pool using tags
211 * from the blk layer.
214 struct fib
*aac_fib_alloc_tag(struct aac_dev
*dev
, struct scsi_cmnd
*scmd
)
218 fibptr
= &dev
->fibs
[scmd
->request
->tag
];
220 * Null out fields that depend on being zero at the start of
223 fibptr
->hw_fib_va
->header
.XferState
= 0;
224 fibptr
->type
= FSAFS_NTC_FIB_CONTEXT
;
225 fibptr
->callback_data
= NULL
;
226 fibptr
->callback
= NULL
;
232 * aac_fib_alloc - allocate a fib
233 * @dev: Adapter to allocate the fib for
235 * Allocate a fib from the adapter fib pool. If the pool is empty we
239 struct fib
*aac_fib_alloc(struct aac_dev
*dev
)
243 spin_lock_irqsave(&dev
->fib_lock
, flags
);
244 fibptr
= dev
->free_fib
;
246 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
249 dev
->free_fib
= fibptr
->next
;
250 spin_unlock_irqrestore(&dev
->fib_lock
, flags
);
252 * Set the proper node type code and node byte size
254 fibptr
->type
= FSAFS_NTC_FIB_CONTEXT
;
255 fibptr
->size
= sizeof(struct fib
);
257 * Null out fields that depend on being zero at the start of
260 fibptr
->hw_fib_va
->header
.XferState
= 0;
262 fibptr
->callback
= NULL
;
263 fibptr
->callback_data
= NULL
;
269 * aac_fib_free - free a fib
270 * @fibptr: fib to free up
272 * Frees up a fib and places it on the appropriate queue
275 void aac_fib_free(struct fib
*fibptr
)
279 if (fibptr
->done
== 2)
282 spin_lock_irqsave(&fibptr
->dev
->fib_lock
, flags
);
283 if (unlikely(fibptr
->flags
& FIB_CONTEXT_FLAG_TIMED_OUT
))
284 aac_config
.fib_timeouts
++;
285 if (fibptr
->hw_fib_va
->header
.XferState
!= 0) {
286 printk(KERN_WARNING
"aac_fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n",
288 le32_to_cpu(fibptr
->hw_fib_va
->header
.XferState
));
290 fibptr
->next
= fibptr
->dev
->free_fib
;
291 fibptr
->dev
->free_fib
= fibptr
;
292 spin_unlock_irqrestore(&fibptr
->dev
->fib_lock
, flags
);
296 * aac_fib_init - initialise a fib
297 * @fibptr: The fib to initialize
299 * Set up the generic fib fields ready for use
302 void aac_fib_init(struct fib
*fibptr
)
304 struct hw_fib
*hw_fib
= fibptr
->hw_fib_va
;
306 memset(&hw_fib
->header
, 0, sizeof(struct aac_fibhdr
));
307 hw_fib
->header
.StructType
= FIB_MAGIC
;
308 hw_fib
->header
.Size
= cpu_to_le16(fibptr
->dev
->max_fib_size
);
309 hw_fib
->header
.XferState
= cpu_to_le32(HostOwned
| FibInitialized
| FibEmpty
| FastResponseCapable
);
310 hw_fib
->header
.u
.ReceiverFibAddress
= cpu_to_le32(fibptr
->hw_fib_pa
);
311 hw_fib
->header
.SenderSize
= cpu_to_le16(fibptr
->dev
->max_fib_size
);
315 * fib_deallocate - deallocate a fib
316 * @fibptr: fib to deallocate
318 * Will deallocate and return to the free pool the FIB pointed to by the
322 static void fib_dealloc(struct fib
* fibptr
)
324 struct hw_fib
*hw_fib
= fibptr
->hw_fib_va
;
325 hw_fib
->header
.XferState
= 0;
329 * Commuication primitives define and support the queuing method we use to
330 * support host to adapter commuication. All queue accesses happen through
331 * these routines and are the only routines which have a knowledge of the
332 * how these queues are implemented.
336 * aac_get_entry - get a queue entry
339 * @entry: Entry return
340 * @index: Index return
341 * @nonotify: notification control
343 * With a priority the routine returns a queue entry if the queue has free entries. If the queue
344 * is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is
348 static int aac_get_entry (struct aac_dev
* dev
, u32 qid
, struct aac_entry
**entry
, u32
* index
, unsigned long *nonotify
)
350 struct aac_queue
* q
;
354 * All of the queues wrap when they reach the end, so we check
355 * to see if they have reached the end and if they have we just
356 * set the index back to zero. This is a wrap. You could or off
357 * the high bits in all updates but this is a bit faster I think.
360 q
= &dev
->queues
->queue
[qid
];
362 idx
= *index
= le32_to_cpu(*(q
->headers
.producer
));
363 /* Interrupt Moderation, only interrupt for first two entries */
364 if (idx
!= le32_to_cpu(*(q
->headers
.consumer
))) {
366 if (qid
== AdapNormCmdQueue
)
367 idx
= ADAP_NORM_CMD_ENTRIES
;
369 idx
= ADAP_NORM_RESP_ENTRIES
;
371 if (idx
!= le32_to_cpu(*(q
->headers
.consumer
)))
375 if (qid
== AdapNormCmdQueue
) {
376 if (*index
>= ADAP_NORM_CMD_ENTRIES
)
377 *index
= 0; /* Wrap to front of the Producer Queue. */
379 if (*index
>= ADAP_NORM_RESP_ENTRIES
)
380 *index
= 0; /* Wrap to front of the Producer Queue. */
384 if ((*index
+ 1) == le32_to_cpu(*(q
->headers
.consumer
))) {
385 printk(KERN_WARNING
"Queue %d full, %u outstanding.\n",
386 qid
, atomic_read(&q
->numpending
));
389 *entry
= q
->base
+ *index
;
395 * aac_queue_get - get the next free QE
397 * @index: Returned index
398 * @priority: Priority of fib
399 * @fib: Fib to associate with the queue entry
400 * @wait: Wait if queue full
401 * @fibptr: Driver fib object to go with fib
402 * @nonotify: Don't notify the adapter
404 * Gets the next free QE off the requested priorty adapter command
405 * queue and associates the Fib with the QE. The QE represented by
406 * index is ready to insert on the queue when this routine returns
410 int aac_queue_get(struct aac_dev
* dev
, u32
* index
, u32 qid
, struct hw_fib
* hw_fib
, int wait
, struct fib
* fibptr
, unsigned long *nonotify
)
412 struct aac_entry
* entry
= NULL
;
415 if (qid
== AdapNormCmdQueue
) {
416 /* if no entries wait for some if caller wants to */
417 while (!aac_get_entry(dev
, qid
, &entry
, index
, nonotify
)) {
418 printk(KERN_ERR
"GetEntries failed\n");
421 * Setup queue entry with a command, status and fib mapped
423 entry
->size
= cpu_to_le32(le16_to_cpu(hw_fib
->header
.Size
));
426 while (!aac_get_entry(dev
, qid
, &entry
, index
, nonotify
)) {
427 /* if no entries wait for some if caller wants to */
430 * Setup queue entry with command, status and fib mapped
432 entry
->size
= cpu_to_le32(le16_to_cpu(hw_fib
->header
.Size
));
433 entry
->addr
= hw_fib
->header
.SenderFibAddress
;
434 /* Restore adapters pointer to the FIB */
435 hw_fib
->header
.u
.ReceiverFibAddress
= hw_fib
->header
.SenderFibAddress
; /* Let the adapter now where to find its data */
439 * If MapFib is true than we need to map the Fib and put pointers
440 * in the queue entry.
443 entry
->addr
= cpu_to_le32(fibptr
->hw_fib_pa
);
448 * Define the highest level of host to adapter communication routines.
449 * These routines will support host to adapter FS commuication. These
450 * routines have no knowledge of the commuication method used. This level
451 * sends and receives FIBs. This level has no knowledge of how these FIBs
452 * get passed back and forth.
456 * aac_fib_send - send a fib to the adapter
457 * @command: Command to send
459 * @size: Size of fib data area
460 * @priority: Priority of Fib
461 * @wait: Async/sync select
462 * @reply: True if a reply is wanted
463 * @callback: Called with reply
464 * @callback_data: Passed to callback
466 * Sends the requested FIB to the adapter and optionally will wait for a
467 * response FIB. If the caller does not wish to wait for a response than
468 * an event to wait on must be supplied. This event will be set when a
469 * response FIB is received from the adapter.
472 int aac_fib_send(u16 command
, struct fib
*fibptr
, unsigned long size
,
473 int priority
, int wait
, int reply
, fib_callback callback
,
476 struct aac_dev
* dev
= fibptr
->dev
;
477 struct hw_fib
* hw_fib
= fibptr
->hw_fib_va
;
478 unsigned long flags
= 0;
479 unsigned long mflags
= 0;
480 unsigned long sflags
= 0;
483 if (!(hw_fib
->header
.XferState
& cpu_to_le32(HostOwned
)))
486 * There are 5 cases with the wait and response requested flags.
487 * The only invalid cases are if the caller requests to wait and
488 * does not request a response and if the caller does not want a
489 * response and the Fib is not allocated from pool. If a response
490 * is not requesed the Fib will just be deallocaed by the DPC
491 * routine when the response comes back from the adapter. No
492 * further processing will be done besides deleting the Fib. We
493 * will have a debug mode where the adapter can notify the host
494 * it had a problem and the host can log that fact.
497 if (wait
&& !reply
) {
499 } else if (!wait
&& reply
) {
500 hw_fib
->header
.XferState
|= cpu_to_le32(Async
| ResponseExpected
);
501 FIB_COUNTER_INCREMENT(aac_config
.AsyncSent
);
502 } else if (!wait
&& !reply
) {
503 hw_fib
->header
.XferState
|= cpu_to_le32(NoResponseExpected
);
504 FIB_COUNTER_INCREMENT(aac_config
.NoResponseSent
);
505 } else if (wait
&& reply
) {
506 hw_fib
->header
.XferState
|= cpu_to_le32(ResponseExpected
);
507 FIB_COUNTER_INCREMENT(aac_config
.NormalSent
);
510 * Map the fib into 32bits by using the fib number
513 hw_fib
->header
.SenderFibAddress
= cpu_to_le32(((u32
)(fibptr
- dev
->fibs
)) << 2);
514 hw_fib
->header
.Handle
= (u32
)(fibptr
- dev
->fibs
) + 1;
516 * Set FIB state to indicate where it came from and if we want a
517 * response from the adapter. Also load the command from the
520 * Map the hw fib pointer as a 32bit value
522 hw_fib
->header
.Command
= cpu_to_le16(command
);
523 hw_fib
->header
.XferState
|= cpu_to_le32(SentFromHost
);
525 * Set the size of the Fib we want to send to the adapter
527 hw_fib
->header
.Size
= cpu_to_le16(sizeof(struct aac_fibhdr
) + size
);
528 if (le16_to_cpu(hw_fib
->header
.Size
) > le16_to_cpu(hw_fib
->header
.SenderSize
)) {
532 * Get a queue entry connect the FIB to it and send an notify
533 * the adapter a command is ready.
535 hw_fib
->header
.XferState
|= cpu_to_le32(NormalPriority
);
538 * Fill in the Callback and CallbackContext if we are not
542 fibptr
->callback
= callback
;
543 fibptr
->callback_data
= callback_data
;
544 fibptr
->flags
= FIB_CONTEXT_FLAG
;
549 FIB_COUNTER_INCREMENT(aac_config
.FibsSent
);
551 dprintk((KERN_DEBUG
"Fib contents:.\n"));
552 dprintk((KERN_DEBUG
" Command = %d.\n", le32_to_cpu(hw_fib
->header
.Command
)));
553 dprintk((KERN_DEBUG
" SubCommand = %d.\n", le32_to_cpu(((struct aac_query_mount
*)fib_data(fibptr
))->command
)));
554 dprintk((KERN_DEBUG
" XferState = %x.\n", le32_to_cpu(hw_fib
->header
.XferState
)));
555 dprintk((KERN_DEBUG
" hw_fib va being sent=%p\n",fibptr
->hw_fib_va
));
556 dprintk((KERN_DEBUG
" hw_fib pa being sent=%lx\n",(ulong
)fibptr
->hw_fib_pa
));
557 dprintk((KERN_DEBUG
" fib being sent=%p\n",fibptr
));
564 spin_lock_irqsave(&dev
->manage_lock
, mflags
);
565 if (dev
->management_fib_count
>= AAC_NUM_MGT_FIB
) {
566 printk(KERN_INFO
"No management Fibs Available:%d\n",
567 dev
->management_fib_count
);
568 spin_unlock_irqrestore(&dev
->manage_lock
, mflags
);
571 dev
->management_fib_count
++;
572 spin_unlock_irqrestore(&dev
->manage_lock
, mflags
);
573 spin_lock_irqsave(&fibptr
->event_lock
, flags
);
576 if (dev
->sync_mode
) {
578 spin_unlock_irqrestore(&fibptr
->event_lock
, flags
);
579 spin_lock_irqsave(&dev
->sync_lock
, sflags
);
581 list_add_tail(&fibptr
->fiblink
, &dev
->sync_fib_list
);
582 spin_unlock_irqrestore(&dev
->sync_lock
, sflags
);
584 dev
->sync_fib
= fibptr
;
585 spin_unlock_irqrestore(&dev
->sync_lock
, sflags
);
586 aac_adapter_sync_cmd(dev
, SEND_SYNCHRONOUS_FIB
,
587 (u32
)fibptr
->hw_fib_pa
, 0, 0, 0, 0, 0,
588 NULL
, NULL
, NULL
, NULL
, NULL
);
591 fibptr
->flags
|= FIB_CONTEXT_FLAG_WAIT
;
592 if (down_interruptible(&fibptr
->event_wait
)) {
593 fibptr
->flags
&= ~FIB_CONTEXT_FLAG_WAIT
;
601 if (aac_adapter_deliver(fibptr
) != 0) {
602 printk(KERN_ERR
"aac_fib_send: returned -EBUSY\n");
604 spin_unlock_irqrestore(&fibptr
->event_lock
, flags
);
605 spin_lock_irqsave(&dev
->manage_lock
, mflags
);
606 dev
->management_fib_count
--;
607 spin_unlock_irqrestore(&dev
->manage_lock
, mflags
);
614 * If the caller wanted us to wait for response wait now.
618 spin_unlock_irqrestore(&fibptr
->event_lock
, flags
);
619 /* Only set for first known interruptable command */
622 * *VERY* Dangerous to time out a command, the
623 * assumption is made that we have no hope of
624 * functioning because an interrupt routing or other
625 * hardware failure has occurred.
627 unsigned long timeout
= jiffies
+ (180 * HZ
); /* 3 minutes */
628 while (down_trylock(&fibptr
->event_wait
)) {
630 if (time_is_before_eq_jiffies(timeout
)) {
631 struct aac_queue
* q
= &dev
->queues
->queue
[AdapNormCmdQueue
];
632 atomic_dec(&q
->numpending
);
634 printk(KERN_ERR
"aacraid: aac_fib_send: first asynchronous command timed out.\n"
635 "Usually a result of a PCI interrupt routing problem;\n"
636 "update mother board BIOS or consider utilizing one of\n"
637 "the SAFE mode kernel options (acpi, apic etc)\n");
641 if ((blink
= aac_adapter_check_health(dev
)) > 0) {
643 printk(KERN_ERR
"aacraid: aac_fib_send: adapter blinkLED 0x%x.\n"
644 "Usually a result of a serious unrecoverable hardware problem\n",
650 * Allow other processes / CPUS to use core
654 } else if (down_interruptible(&fibptr
->event_wait
)) {
655 /* Do nothing ... satisfy
656 * down_interruptible must_check */
659 spin_lock_irqsave(&fibptr
->event_lock
, flags
);
660 if (fibptr
->done
== 0) {
661 fibptr
->done
= 2; /* Tell interrupt we aborted */
662 spin_unlock_irqrestore(&fibptr
->event_lock
, flags
);
665 spin_unlock_irqrestore(&fibptr
->event_lock
, flags
);
666 BUG_ON(fibptr
->done
== 0);
668 if(unlikely(fibptr
->flags
& FIB_CONTEXT_FLAG_TIMED_OUT
))
673 * If the user does not want a response than return success otherwise
683 * aac_consumer_get - get the top of the queue
686 * @entry: Return entry
688 * Will return a pointer to the entry on the top of the queue requested that
689 * we are a consumer of, and return the address of the queue entry. It does
690 * not change the state of the queue.
693 int aac_consumer_get(struct aac_dev
* dev
, struct aac_queue
* q
, struct aac_entry
**entry
)
697 if (le32_to_cpu(*q
->headers
.producer
) == le32_to_cpu(*q
->headers
.consumer
)) {
701 * The consumer index must be wrapped if we have reached
702 * the end of the queue, else we just use the entry
703 * pointed to by the header index
705 if (le32_to_cpu(*q
->headers
.consumer
) >= q
->entries
)
708 index
= le32_to_cpu(*q
->headers
.consumer
);
709 *entry
= q
->base
+ index
;
716 * aac_consumer_free - free consumer entry
721 * Frees up the current top of the queue we are a consumer of. If the
722 * queue was full notify the producer that the queue is no longer full.
725 void aac_consumer_free(struct aac_dev
* dev
, struct aac_queue
*q
, u32 qid
)
730 if ((le32_to_cpu(*q
->headers
.producer
)+1) == le32_to_cpu(*q
->headers
.consumer
))
733 if (le32_to_cpu(*q
->headers
.consumer
) >= q
->entries
)
734 *q
->headers
.consumer
= cpu_to_le32(1);
736 le32_add_cpu(q
->headers
.consumer
, 1);
741 case HostNormCmdQueue
:
742 notify
= HostNormCmdNotFull
;
744 case HostNormRespQueue
:
745 notify
= HostNormRespNotFull
;
751 aac_adapter_notify(dev
, notify
);
756 * aac_fib_adapter_complete - complete adapter issued fib
757 * @fibptr: fib to complete
760 * Will do all necessary work to complete a FIB that was sent from
764 int aac_fib_adapter_complete(struct fib
*fibptr
, unsigned short size
)
766 struct hw_fib
* hw_fib
= fibptr
->hw_fib_va
;
767 struct aac_dev
* dev
= fibptr
->dev
;
768 struct aac_queue
* q
;
769 unsigned long nointr
= 0;
770 unsigned long qflags
;
772 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE1
||
773 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
774 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) {
779 if (hw_fib
->header
.XferState
== 0) {
780 if (dev
->comm_interface
== AAC_COMM_MESSAGE
)
785 * If we plan to do anything check the structure type first.
787 if (hw_fib
->header
.StructType
!= FIB_MAGIC
&&
788 hw_fib
->header
.StructType
!= FIB_MAGIC2
&&
789 hw_fib
->header
.StructType
!= FIB_MAGIC2_64
) {
790 if (dev
->comm_interface
== AAC_COMM_MESSAGE
)
795 * This block handles the case where the adapter had sent us a
796 * command and we have finished processing the command. We
797 * call completeFib when we are done processing the command
798 * and want to send a response back to the adapter. This will
799 * send the completed cdb to the adapter.
801 if (hw_fib
->header
.XferState
& cpu_to_le32(SentFromAdapter
)) {
802 if (dev
->comm_interface
== AAC_COMM_MESSAGE
) {
806 hw_fib
->header
.XferState
|= cpu_to_le32(HostProcessed
);
808 size
+= sizeof(struct aac_fibhdr
);
809 if (size
> le16_to_cpu(hw_fib
->header
.SenderSize
))
811 hw_fib
->header
.Size
= cpu_to_le16(size
);
813 q
= &dev
->queues
->queue
[AdapNormRespQueue
];
814 spin_lock_irqsave(q
->lock
, qflags
);
815 aac_queue_get(dev
, &index
, AdapNormRespQueue
, hw_fib
, 1, NULL
, &nointr
);
816 *(q
->headers
.producer
) = cpu_to_le32(index
+ 1);
817 spin_unlock_irqrestore(q
->lock
, qflags
);
818 if (!(nointr
& (int)aac_config
.irq_mod
))
819 aac_adapter_notify(dev
, AdapNormRespQueue
);
822 printk(KERN_WARNING
"aac_fib_adapter_complete: "
823 "Unknown xferstate detected.\n");
830 * aac_fib_complete - fib completion handler
831 * @fib: FIB to complete
833 * Will do all necessary work to complete a FIB.
836 int aac_fib_complete(struct fib
*fibptr
)
838 struct hw_fib
* hw_fib
= fibptr
->hw_fib_va
;
841 * Check for a fib which has already been completed
844 if (hw_fib
->header
.XferState
== 0)
847 * If we plan to do anything check the structure type first.
850 if (hw_fib
->header
.StructType
!= FIB_MAGIC
&&
851 hw_fib
->header
.StructType
!= FIB_MAGIC2
&&
852 hw_fib
->header
.StructType
!= FIB_MAGIC2_64
)
855 * This block completes a cdb which orginated on the host and we
856 * just need to deallocate the cdb or reinit it. At this point the
857 * command is complete that we had sent to the adapter and this
858 * cdb could be reused.
861 if((hw_fib
->header
.XferState
& cpu_to_le32(SentFromHost
)) &&
862 (hw_fib
->header
.XferState
& cpu_to_le32(AdapterProcessed
)))
866 else if(hw_fib
->header
.XferState
& cpu_to_le32(SentFromHost
))
869 * This handles the case when the host has aborted the I/O
870 * to the adapter because the adapter is not responding
873 } else if(hw_fib
->header
.XferState
& cpu_to_le32(HostOwned
)) {
882 * aac_printf - handle printf from firmware
886 * Print a message passed to us by the controller firmware on the
890 void aac_printf(struct aac_dev
*dev
, u32 val
)
892 char *cp
= dev
->printfbuf
;
893 if (dev
->printf_enabled
)
895 int length
= val
& 0xffff;
896 int level
= (val
>> 16) & 0xffff;
899 * The size of the printfbuf is set in port.c
900 * There is no variable or define for it
906 if (level
== LOG_AAC_HIGH_ERROR
)
907 printk(KERN_WARNING
"%s:%s", dev
->name
, cp
);
909 printk(KERN_INFO
"%s:%s", dev
->name
, cp
);
914 static inline int aac_aif_data(struct aac_aifcmd
*aifcmd
, uint32_t index
)
916 return le32_to_cpu(((__le32
*)aifcmd
->data
)[index
]);
920 static void aac_handle_aif_bu(struct aac_dev
*dev
, struct aac_aifcmd
*aifcmd
)
922 switch (aac_aif_data(aifcmd
, 1)) {
923 case AifBuCacheDataLoss
:
924 if (aac_aif_data(aifcmd
, 2))
925 dev_info(&dev
->pdev
->dev
, "Backup unit had cache data loss - [%d]\n",
926 aac_aif_data(aifcmd
, 2));
928 dev_info(&dev
->pdev
->dev
, "Backup Unit had cache data loss\n");
930 case AifBuCacheDataRecover
:
931 if (aac_aif_data(aifcmd
, 2))
932 dev_info(&dev
->pdev
->dev
, "DDR cache data recovered successfully - [%d]\n",
933 aac_aif_data(aifcmd
, 2));
935 dev_info(&dev
->pdev
->dev
, "DDR cache data recovered successfully\n");
941 * aac_handle_aif - Handle a message from the firmware
942 * @dev: Which adapter this fib is from
943 * @fibptr: Pointer to fibptr from adapter
945 * This routine handles a driver notify fib from the adapter and
946 * dispatches it to the appropriate routine for handling.
949 #define AIF_SNIFF_TIMEOUT (500*HZ)
950 static void aac_handle_aif(struct aac_dev
* dev
, struct fib
* fibptr
)
952 struct hw_fib
* hw_fib
= fibptr
->hw_fib_va
;
953 struct aac_aifcmd
* aifcmd
= (struct aac_aifcmd
*)hw_fib
->data
;
954 u32 channel
, id
, lun
, container
;
955 struct scsi_device
*device
;
961 } device_config_needed
= NOTHING
;
963 /* Sniff for container changes */
965 if (!dev
|| !dev
->fsa_dev
)
967 container
= channel
= id
= lun
= (u32
)-1;
970 * We have set this up to try and minimize the number of
971 * re-configures that take place. As a result of this when
972 * certain AIF's come in we will set a flag waiting for another
973 * type of AIF before setting the re-config flag.
975 switch (le32_to_cpu(aifcmd
->command
)) {
976 case AifCmdDriverNotify
:
977 switch (le32_to_cpu(((__le32
*)aifcmd
->data
)[0])) {
978 case AifRawDeviceRemove
:
979 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
980 if ((container
>> 28)) {
984 channel
= (container
>> 24) & 0xF;
985 if (channel
>= dev
->maximum_num_channels
) {
989 id
= container
& 0xFFFF;
990 if (id
>= dev
->maximum_num_physicals
) {
994 lun
= (container
>> 16) & 0xFF;
996 channel
= aac_phys_to_logical(channel
);
997 device_config_needed
=
998 (((__le32
*)aifcmd
->data
)[0] ==
999 cpu_to_le32(AifRawDeviceRemove
)) ? DELETE
: ADD
;
1001 if (device_config_needed
== ADD
) {
1002 device
= scsi_device_lookup(
1006 scsi_remove_device(device
);
1007 scsi_device_put(device
);
1012 * Morph or Expand complete
1014 case AifDenMorphComplete
:
1015 case AifDenVolumeExtendComplete
:
1016 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
1017 if (container
>= dev
->maximum_num_containers
)
1021 * Find the scsi_device associated with the SCSI
1022 * address. Make sure we have the right array, and if
1023 * so set the flag to initiate a new re-config once we
1024 * see an AifEnConfigChange AIF come through.
1027 if ((dev
!= NULL
) && (dev
->scsi_host_ptr
!= NULL
)) {
1028 device
= scsi_device_lookup(dev
->scsi_host_ptr
,
1029 CONTAINER_TO_CHANNEL(container
),
1030 CONTAINER_TO_ID(container
),
1031 CONTAINER_TO_LUN(container
));
1033 dev
->fsa_dev
[container
].config_needed
= CHANGE
;
1034 dev
->fsa_dev
[container
].config_waiting_on
= AifEnConfigChange
;
1035 dev
->fsa_dev
[container
].config_waiting_stamp
= jiffies
;
1036 scsi_device_put(device
);
1042 * If we are waiting on something and this happens to be
1043 * that thing then set the re-configure flag.
1045 if (container
!= (u32
)-1) {
1046 if (container
>= dev
->maximum_num_containers
)
1048 if ((dev
->fsa_dev
[container
].config_waiting_on
==
1049 le32_to_cpu(*(__le32
*)aifcmd
->data
)) &&
1050 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
))
1051 dev
->fsa_dev
[container
].config_waiting_on
= 0;
1052 } else for (container
= 0;
1053 container
< dev
->maximum_num_containers
; ++container
) {
1054 if ((dev
->fsa_dev
[container
].config_waiting_on
==
1055 le32_to_cpu(*(__le32
*)aifcmd
->data
)) &&
1056 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
))
1057 dev
->fsa_dev
[container
].config_waiting_on
= 0;
1061 case AifCmdEventNotify
:
1062 switch (le32_to_cpu(((__le32
*)aifcmd
->data
)[0])) {
1063 case AifEnBatteryEvent
:
1064 dev
->cache_protected
=
1065 (((__le32
*)aifcmd
->data
)[1] == cpu_to_le32(3));
1070 case AifEnAddContainer
:
1071 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
1072 if (container
>= dev
->maximum_num_containers
)
1074 dev
->fsa_dev
[container
].config_needed
= ADD
;
1075 dev
->fsa_dev
[container
].config_waiting_on
=
1077 dev
->fsa_dev
[container
].config_waiting_stamp
= jiffies
;
1083 case AifEnDeleteContainer
:
1084 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
1085 if (container
>= dev
->maximum_num_containers
)
1087 dev
->fsa_dev
[container
].config_needed
= DELETE
;
1088 dev
->fsa_dev
[container
].config_waiting_on
=
1090 dev
->fsa_dev
[container
].config_waiting_stamp
= jiffies
;
1094 * Container change detected. If we currently are not
1095 * waiting on something else, setup to wait on a Config Change.
1097 case AifEnContainerChange
:
1098 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
1099 if (container
>= dev
->maximum_num_containers
)
1101 if (dev
->fsa_dev
[container
].config_waiting_on
&&
1102 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
))
1104 dev
->fsa_dev
[container
].config_needed
= CHANGE
;
1105 dev
->fsa_dev
[container
].config_waiting_on
=
1107 dev
->fsa_dev
[container
].config_waiting_stamp
= jiffies
;
1110 case AifEnConfigChange
:
1114 case AifEnDeleteJBOD
:
1115 container
= le32_to_cpu(((__le32
*)aifcmd
->data
)[1]);
1116 if ((container
>> 28)) {
1117 container
= (u32
)-1;
1120 channel
= (container
>> 24) & 0xF;
1121 if (channel
>= dev
->maximum_num_channels
) {
1122 container
= (u32
)-1;
1125 id
= container
& 0xFFFF;
1126 if (id
>= dev
->maximum_num_physicals
) {
1127 container
= (u32
)-1;
1130 lun
= (container
>> 16) & 0xFF;
1131 container
= (u32
)-1;
1132 channel
= aac_phys_to_logical(channel
);
1133 device_config_needed
=
1134 (((__le32
*)aifcmd
->data
)[0] ==
1135 cpu_to_le32(AifEnAddJBOD
)) ? ADD
: DELETE
;
1136 if (device_config_needed
== ADD
) {
1137 device
= scsi_device_lookup(dev
->scsi_host_ptr
,
1142 scsi_remove_device(device
);
1143 scsi_device_put(device
);
1148 case AifEnEnclosureManagement
:
1150 * If in JBOD mode, automatic exposure of new
1151 * physical target to be suppressed until configured.
1155 switch (le32_to_cpu(((__le32
*)aifcmd
->data
)[3])) {
1156 case EM_DRIVE_INSERTION
:
1157 case EM_DRIVE_REMOVAL
:
1158 case EM_SES_DRIVE_INSERTION
:
1159 case EM_SES_DRIVE_REMOVAL
:
1160 container
= le32_to_cpu(
1161 ((__le32
*)aifcmd
->data
)[2]);
1162 if ((container
>> 28)) {
1163 container
= (u32
)-1;
1166 channel
= (container
>> 24) & 0xF;
1167 if (channel
>= dev
->maximum_num_channels
) {
1168 container
= (u32
)-1;
1171 id
= container
& 0xFFFF;
1172 lun
= (container
>> 16) & 0xFF;
1173 container
= (u32
)-1;
1174 if (id
>= dev
->maximum_num_physicals
) {
1175 /* legacy dev_t ? */
1176 if ((0x2000 <= id
) || lun
|| channel
||
1177 ((channel
= (id
>> 7) & 0x3F) >=
1178 dev
->maximum_num_channels
))
1180 lun
= (id
>> 4) & 7;
1183 channel
= aac_phys_to_logical(channel
);
1184 device_config_needed
=
1185 ((((__le32
*)aifcmd
->data
)[3]
1186 == cpu_to_le32(EM_DRIVE_INSERTION
)) ||
1187 (((__le32
*)aifcmd
->data
)[3]
1188 == cpu_to_le32(EM_SES_DRIVE_INSERTION
))) ?
1192 case AifBuManagerEvent
:
1193 aac_handle_aif_bu(dev
, aifcmd
);
1198 * If we are waiting on something and this happens to be
1199 * that thing then set the re-configure flag.
1201 if (container
!= (u32
)-1) {
1202 if (container
>= dev
->maximum_num_containers
)
1204 if ((dev
->fsa_dev
[container
].config_waiting_on
==
1205 le32_to_cpu(*(__le32
*)aifcmd
->data
)) &&
1206 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
))
1207 dev
->fsa_dev
[container
].config_waiting_on
= 0;
1208 } else for (container
= 0;
1209 container
< dev
->maximum_num_containers
; ++container
) {
1210 if ((dev
->fsa_dev
[container
].config_waiting_on
==
1211 le32_to_cpu(*(__le32
*)aifcmd
->data
)) &&
1212 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
))
1213 dev
->fsa_dev
[container
].config_waiting_on
= 0;
1217 case AifCmdJobProgress
:
1219 * These are job progress AIF's. When a Clear is being
1220 * done on a container it is initially created then hidden from
1221 * the OS. When the clear completes we don't get a config
1222 * change so we monitor the job status complete on a clear then
1223 * wait for a container change.
1226 if (((__le32
*)aifcmd
->data
)[1] == cpu_to_le32(AifJobCtrZero
) &&
1227 (((__le32
*)aifcmd
->data
)[6] == ((__le32
*)aifcmd
->data
)[5] ||
1228 ((__le32
*)aifcmd
->data
)[4] == cpu_to_le32(AifJobStsSuccess
))) {
1230 container
< dev
->maximum_num_containers
;
1233 * Stomp on all config sequencing for all
1236 dev
->fsa_dev
[container
].config_waiting_on
=
1237 AifEnContainerChange
;
1238 dev
->fsa_dev
[container
].config_needed
= ADD
;
1239 dev
->fsa_dev
[container
].config_waiting_stamp
=
1243 if (((__le32
*)aifcmd
->data
)[1] == cpu_to_le32(AifJobCtrZero
) &&
1244 ((__le32
*)aifcmd
->data
)[6] == 0 &&
1245 ((__le32
*)aifcmd
->data
)[4] == cpu_to_le32(AifJobStsRunning
)) {
1247 container
< dev
->maximum_num_containers
;
1250 * Stomp on all config sequencing for all
1253 dev
->fsa_dev
[container
].config_waiting_on
=
1254 AifEnContainerChange
;
1255 dev
->fsa_dev
[container
].config_needed
= DELETE
;
1256 dev
->fsa_dev
[container
].config_waiting_stamp
=
1265 if (device_config_needed
== NOTHING
)
1266 for (; container
< dev
->maximum_num_containers
; ++container
) {
1267 if ((dev
->fsa_dev
[container
].config_waiting_on
== 0) &&
1268 (dev
->fsa_dev
[container
].config_needed
!= NOTHING
) &&
1269 time_before(jiffies
, dev
->fsa_dev
[container
].config_waiting_stamp
+ AIF_SNIFF_TIMEOUT
)) {
1270 device_config_needed
=
1271 dev
->fsa_dev
[container
].config_needed
;
1272 dev
->fsa_dev
[container
].config_needed
= NOTHING
;
1273 channel
= CONTAINER_TO_CHANNEL(container
);
1274 id
= CONTAINER_TO_ID(container
);
1275 lun
= CONTAINER_TO_LUN(container
);
1279 if (device_config_needed
== NOTHING
)
1283 * If we decided that a re-configuration needs to be done,
1284 * schedule it here on the way out the door, please close the door
1289 * Find the scsi_device associated with the SCSI address,
1290 * and mark it as changed, invalidating the cache. This deals
1291 * with changes to existing device IDs.
1294 if (!dev
|| !dev
->scsi_host_ptr
)
1297 * force reload of disk info via aac_probe_container
1299 if ((channel
== CONTAINER_CHANNEL
) &&
1300 (device_config_needed
!= NOTHING
)) {
1301 if (dev
->fsa_dev
[container
].valid
== 1)
1302 dev
->fsa_dev
[container
].valid
= 2;
1303 aac_probe_container(dev
, container
);
1305 device
= scsi_device_lookup(dev
->scsi_host_ptr
, channel
, id
, lun
);
1307 switch (device_config_needed
) {
1309 #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1310 scsi_remove_device(device
);
1312 if (scsi_device_online(device
)) {
1313 scsi_device_set_state(device
, SDEV_OFFLINE
);
1314 sdev_printk(KERN_INFO
, device
,
1315 "Device offlined - %s\n",
1316 (channel
== CONTAINER_CHANNEL
) ?
1318 "enclosure services event");
1323 if (!scsi_device_online(device
)) {
1324 sdev_printk(KERN_INFO
, device
,
1325 "Device online - %s\n",
1326 (channel
== CONTAINER_CHANNEL
) ?
1328 "enclosure services event");
1329 scsi_device_set_state(device
, SDEV_RUNNING
);
1333 if ((channel
== CONTAINER_CHANNEL
)
1334 && (!dev
->fsa_dev
[container
].valid
)) {
1335 #if (defined(AAC_DEBUG_INSTRUMENT_AIF_DELETE))
1336 scsi_remove_device(device
);
1338 if (!scsi_device_online(device
))
1340 scsi_device_set_state(device
, SDEV_OFFLINE
);
1341 sdev_printk(KERN_INFO
, device
,
1342 "Device offlined - %s\n",
1347 scsi_rescan_device(&device
->sdev_gendev
);
1352 scsi_device_put(device
);
1353 device_config_needed
= NOTHING
;
1355 if (device_config_needed
== ADD
)
1356 scsi_add_device(dev
->scsi_host_ptr
, channel
, id
, lun
);
1357 if (channel
== CONTAINER_CHANNEL
) {
1359 device_config_needed
= NOTHING
;
1364 static int _aac_reset_adapter(struct aac_dev
*aac
, int forced
)
1368 struct Scsi_Host
*host
;
1369 struct scsi_device
*dev
;
1370 struct scsi_cmnd
*command
;
1371 struct scsi_cmnd
*command_list
;
1376 * - host is locked, unless called by the aacraid thread.
1377 * (a matter of convenience, due to legacy issues surrounding
1378 * eh_host_adapter_reset).
1379 * - in_reset is asserted, so no new i/o is getting to the
1381 * - The card is dead, or will be very shortly ;-/ so no new
1382 * commands are completing in the interrupt service.
1384 host
= aac
->scsi_host_ptr
;
1385 scsi_block_requests(host
);
1386 aac_adapter_disable_int(aac
);
1387 if (aac
->thread
->pid
!= current
->pid
) {
1388 spin_unlock_irq(host
->host_lock
);
1389 kthread_stop(aac
->thread
);
1394 * If a positive health, means in a known DEAD PANIC
1395 * state and the adapter could be reset to `try again'.
1397 retval
= aac_adapter_restart(aac
, forced
? 0 : aac_adapter_check_health(aac
));
1403 * Loop through the fibs, close the synchronous FIBS
1405 for (retval
= 1, index
= 0; index
< (aac
->scsi_host_ptr
->can_queue
+ AAC_NUM_MGT_FIB
); index
++) {
1406 struct fib
*fib
= &aac
->fibs
[index
];
1407 if (!(fib
->hw_fib_va
->header
.XferState
& cpu_to_le32(NoResponseExpected
| Async
)) &&
1408 (fib
->hw_fib_va
->header
.XferState
& cpu_to_le32(ResponseExpected
))) {
1409 unsigned long flagv
;
1410 spin_lock_irqsave(&fib
->event_lock
, flagv
);
1411 up(&fib
->event_wait
);
1412 spin_unlock_irqrestore(&fib
->event_lock
, flagv
);
1417 /* Give some extra time for ioctls to complete. */
1420 index
= aac
->cardtype
;
1423 * Re-initialize the adapter, first free resources, then carefully
1424 * apply the initialization sequence to come back again. Only risk
1425 * is a change in Firmware dropping cache, it is assumed the caller
1426 * will ensure that i/o is queisced and the card is flushed in that
1429 aac_fib_map_free(aac
);
1430 pci_free_consistent(aac
->pdev
, aac
->comm_size
, aac
->comm_addr
, aac
->comm_phys
);
1431 aac
->comm_addr
= NULL
;
1436 kfree(aac
->fsa_dev
);
1437 aac
->fsa_dev
= NULL
;
1438 quirks
= aac_get_driver_ident(index
)->quirks
;
1439 if (quirks
& AAC_QUIRK_31BIT
) {
1440 if (((retval
= pci_set_dma_mask(aac
->pdev
, DMA_BIT_MASK(31)))) ||
1441 ((retval
= pci_set_consistent_dma_mask(aac
->pdev
, DMA_BIT_MASK(31)))))
1444 if (((retval
= pci_set_dma_mask(aac
->pdev
, DMA_BIT_MASK(32)))) ||
1445 ((retval
= pci_set_consistent_dma_mask(aac
->pdev
, DMA_BIT_MASK(32)))))
1448 if ((retval
= (*(aac_get_driver_ident(index
)->init
))(aac
)))
1450 if (quirks
& AAC_QUIRK_31BIT
)
1451 if ((retval
= pci_set_dma_mask(aac
->pdev
, DMA_BIT_MASK(32))))
1454 aac
->thread
= kthread_run(aac_command_thread
, aac
, "%s",
1456 if (IS_ERR(aac
->thread
)) {
1457 retval
= PTR_ERR(aac
->thread
);
1461 (void)aac_get_adapter_info(aac
);
1462 if ((quirks
& AAC_QUIRK_34SG
) && (host
->sg_tablesize
> 34)) {
1463 host
->sg_tablesize
= 34;
1464 host
->max_sectors
= (host
->sg_tablesize
* 8) + 112;
1466 if ((quirks
& AAC_QUIRK_17SG
) && (host
->sg_tablesize
> 17)) {
1467 host
->sg_tablesize
= 17;
1468 host
->max_sectors
= (host
->sg_tablesize
* 8) + 112;
1470 aac_get_config_status(aac
, 1);
1471 aac_get_containers(aac
);
1473 * This is where the assumption that the Adapter is quiesced
1476 command_list
= NULL
;
1477 __shost_for_each_device(dev
, host
) {
1478 unsigned long flags
;
1479 spin_lock_irqsave(&dev
->list_lock
, flags
);
1480 list_for_each_entry(command
, &dev
->cmd_list
, list
)
1481 if (command
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
1482 command
->SCp
.buffer
= (struct scatterlist
*)command_list
;
1483 command_list
= command
;
1485 spin_unlock_irqrestore(&dev
->list_lock
, flags
);
1487 while ((command
= command_list
)) {
1488 command_list
= (struct scsi_cmnd
*)command
->SCp
.buffer
;
1489 command
->SCp
.buffer
= NULL
;
1490 command
->result
= DID_OK
<< 16
1491 | COMMAND_COMPLETE
<< 8
1492 | SAM_STAT_TASK_SET_FULL
;
1493 command
->SCp
.phase
= AAC_OWNER_ERROR_HANDLER
;
1494 command
->scsi_done(command
);
1500 scsi_unblock_requests(host
);
1502 spin_lock_irq(host
->host_lock
);
1507 int aac_reset_adapter(struct aac_dev
* aac
, int forced
)
1509 unsigned long flagv
= 0;
1511 struct Scsi_Host
* host
;
1513 if (spin_trylock_irqsave(&aac
->fib_lock
, flagv
) == 0)
1516 if (aac
->in_reset
) {
1517 spin_unlock_irqrestore(&aac
->fib_lock
, flagv
);
1521 spin_unlock_irqrestore(&aac
->fib_lock
, flagv
);
1524 * Wait for all commands to complete to this specific
1525 * target (block maximum 60 seconds). Although not necessary,
1526 * it does make us a good storage citizen.
1528 host
= aac
->scsi_host_ptr
;
1529 scsi_block_requests(host
);
1530 if (forced
< 2) for (retval
= 60; retval
; --retval
) {
1531 struct scsi_device
* dev
;
1532 struct scsi_cmnd
* command
;
1535 __shost_for_each_device(dev
, host
) {
1536 spin_lock_irqsave(&dev
->list_lock
, flagv
);
1537 list_for_each_entry(command
, &dev
->cmd_list
, list
) {
1538 if (command
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
1543 spin_unlock_irqrestore(&dev
->list_lock
, flagv
);
1549 * We can exit If all the commands are complete
1556 /* Quiesce build, flush cache, write through mode */
1558 aac_send_shutdown(aac
);
1559 spin_lock_irqsave(host
->host_lock
, flagv
);
1560 retval
= _aac_reset_adapter(aac
, forced
? forced
: ((aac_check_reset
!= 0) && (aac_check_reset
!= 1)));
1561 spin_unlock_irqrestore(host
->host_lock
, flagv
);
1563 if ((forced
< 2) && (retval
== -ENODEV
)) {
1564 /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
1565 struct fib
* fibctx
= aac_fib_alloc(aac
);
1567 struct aac_pause
*cmd
;
1570 aac_fib_init(fibctx
);
1572 cmd
= (struct aac_pause
*) fib_data(fibctx
);
1574 cmd
->command
= cpu_to_le32(VM_ContainerConfig
);
1575 cmd
->type
= cpu_to_le32(CT_PAUSE_IO
);
1576 cmd
->timeout
= cpu_to_le32(1);
1577 cmd
->min
= cpu_to_le32(1);
1578 cmd
->noRescan
= cpu_to_le32(1);
1579 cmd
->count
= cpu_to_le32(0);
1581 status
= aac_fib_send(ContainerCommand
,
1583 sizeof(struct aac_pause
),
1585 -2 /* Timeout silently */, 1,
1589 aac_fib_complete(fibctx
);
1590 /* FIB should be freed only after getting
1591 * the response from the F/W */
1592 if (status
!= -ERESTARTSYS
)
1593 aac_fib_free(fibctx
);
1600 int aac_check_health(struct aac_dev
* aac
)
1603 unsigned long time_now
, flagv
= 0;
1604 struct list_head
* entry
;
1605 struct Scsi_Host
* host
;
1607 /* Extending the scope of fib_lock slightly to protect aac->in_reset */
1608 if (spin_trylock_irqsave(&aac
->fib_lock
, flagv
) == 0)
1611 if (aac
->in_reset
|| !(BlinkLED
= aac_adapter_check_health(aac
))) {
1612 spin_unlock_irqrestore(&aac
->fib_lock
, flagv
);
1619 * aac_aifcmd.command = AifCmdEventNotify = 1
1620 * aac_aifcmd.seqnum = 0xFFFFFFFF
1621 * aac_aifcmd.data[0] = AifEnExpEvent = 23
1622 * aac_aifcmd.data[1] = AifExeFirmwarePanic = 3
1623 * aac.aifcmd.data[2] = AifHighPriority = 3
1624 * aac.aifcmd.data[3] = BlinkLED
1627 time_now
= jiffies
/HZ
;
1628 entry
= aac
->fib_list
.next
;
1631 * For each Context that is on the
1632 * fibctxList, make a copy of the
1633 * fib, and then set the event to wake up the
1634 * thread that is waiting for it.
1636 while (entry
!= &aac
->fib_list
) {
1638 * Extract the fibctx
1640 struct aac_fib_context
*fibctx
= list_entry(entry
, struct aac_fib_context
, next
);
1641 struct hw_fib
* hw_fib
;
1644 * Check if the queue is getting
1647 if (fibctx
->count
> 20) {
1649 * It's *not* jiffies folks,
1650 * but jiffies / HZ, so do not
1653 u32 time_last
= fibctx
->jiffies
;
1655 * Has it been > 2 minutes
1656 * since the last read off
1659 if ((time_now
- time_last
) > aif_timeout
) {
1660 entry
= entry
->next
;
1661 aac_close_fib_context(aac
, fibctx
);
1666 * Warning: no sleep allowed while
1669 hw_fib
= kzalloc(sizeof(struct hw_fib
), GFP_ATOMIC
);
1670 fib
= kzalloc(sizeof(struct fib
), GFP_ATOMIC
);
1671 if (fib
&& hw_fib
) {
1672 struct aac_aifcmd
* aif
;
1674 fib
->hw_fib_va
= hw_fib
;
1677 fib
->type
= FSAFS_NTC_FIB_CONTEXT
;
1678 fib
->size
= sizeof (struct fib
);
1679 fib
->data
= hw_fib
->data
;
1680 aif
= (struct aac_aifcmd
*)hw_fib
->data
;
1681 aif
->command
= cpu_to_le32(AifCmdEventNotify
);
1682 aif
->seqnum
= cpu_to_le32(0xFFFFFFFF);
1683 ((__le32
*)aif
->data
)[0] = cpu_to_le32(AifEnExpEvent
);
1684 ((__le32
*)aif
->data
)[1] = cpu_to_le32(AifExeFirmwarePanic
);
1685 ((__le32
*)aif
->data
)[2] = cpu_to_le32(AifHighPriority
);
1686 ((__le32
*)aif
->data
)[3] = cpu_to_le32(BlinkLED
);
1689 * Put the FIB onto the
1692 list_add_tail(&fib
->fiblink
, &fibctx
->fib_list
);
1695 * Set the event to wake up the
1696 * thread that will waiting.
1698 up(&fibctx
->wait_sem
);
1700 printk(KERN_WARNING
"aifd: didn't allocate NewFib.\n");
1704 entry
= entry
->next
;
1707 spin_unlock_irqrestore(&aac
->fib_lock
, flagv
);
1710 printk(KERN_ERR
"%s: Host adapter dead %d\n", aac
->name
, BlinkLED
);
1714 printk(KERN_ERR
"%s: Host adapter BLINK LED 0x%x\n", aac
->name
, BlinkLED
);
1716 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1717 (aac
->supplement_adapter_info
.SupportedOptions2
&
1718 AAC_OPTION_IGNORE_RESET
)))
1720 host
= aac
->scsi_host_ptr
;
1721 if (aac
->thread
->pid
!= current
->pid
)
1722 spin_lock_irqsave(host
->host_lock
, flagv
);
1723 BlinkLED
= _aac_reset_adapter(aac
, aac_check_reset
!= 1);
1724 if (aac
->thread
->pid
!= current
->pid
)
1725 spin_unlock_irqrestore(host
->host_lock
, flagv
);
1733 static int get_fib_count(struct aac_dev
*dev
)
1735 unsigned int num
= 0;
1736 struct list_head
*entry
;
1737 unsigned long flagv
;
1740 * Warning: no sleep allowed while
1741 * holding spinlock. We take the estimate
1742 * and pre-allocate a set of fibs outside the
1745 num
= le32_to_cpu(dev
->init
->r7
.adapter_fibs_size
)
1746 / sizeof(struct hw_fib
); /* some extra */
1747 spin_lock_irqsave(&dev
->fib_lock
, flagv
);
1748 entry
= dev
->fib_list
.next
;
1749 while (entry
!= &dev
->fib_list
) {
1750 entry
= entry
->next
;
1753 spin_unlock_irqrestore(&dev
->fib_lock
, flagv
);
1758 static int fillup_pools(struct aac_dev
*dev
, struct hw_fib
**hw_fib_pool
,
1759 struct fib
**fib_pool
,
1762 struct hw_fib
**hw_fib_p
;
1766 hw_fib_p
= hw_fib_pool
;
1768 while (hw_fib_p
< &hw_fib_pool
[num
]) {
1769 *(hw_fib_p
) = kmalloc(sizeof(struct hw_fib
), GFP_KERNEL
);
1770 if (!(*(hw_fib_p
++))) {
1775 *(fib_p
) = kmalloc(sizeof(struct fib
), GFP_KERNEL
);
1776 if (!(*(fib_p
++))) {
1777 kfree(*(--hw_fib_p
));
1782 num
= hw_fib_p
- hw_fib_pool
;
1789 static void wakeup_fibctx_threads(struct aac_dev
*dev
,
1790 struct hw_fib
**hw_fib_pool
,
1791 struct fib
**fib_pool
,
1793 struct hw_fib
*hw_fib
,
1796 unsigned long flagv
;
1797 struct list_head
*entry
;
1798 struct hw_fib
**hw_fib_p
;
1800 u32 time_now
, time_last
;
1801 struct hw_fib
*hw_newfib
;
1803 struct aac_fib_context
*fibctx
;
1805 time_now
= jiffies
/HZ
;
1806 spin_lock_irqsave(&dev
->fib_lock
, flagv
);
1807 entry
= dev
->fib_list
.next
;
1809 * For each Context that is on the
1810 * fibctxList, make a copy of the
1811 * fib, and then set the event to wake up the
1812 * thread that is waiting for it.
1815 hw_fib_p
= hw_fib_pool
;
1817 while (entry
!= &dev
->fib_list
) {
1819 * Extract the fibctx
1821 fibctx
= list_entry(entry
, struct aac_fib_context
,
1824 * Check if the queue is getting
1827 if (fibctx
->count
> 20) {
1829 * It's *not* jiffies folks,
1830 * but jiffies / HZ so do not
1833 time_last
= fibctx
->jiffies
;
1835 * Has it been > 2 minutes
1836 * since the last read off
1839 if ((time_now
- time_last
) > aif_timeout
) {
1840 entry
= entry
->next
;
1841 aac_close_fib_context(dev
, fibctx
);
1846 * Warning: no sleep allowed while
1849 if (hw_fib_p
>= &hw_fib_pool
[num
]) {
1850 pr_warn("aifd: didn't allocate NewFib\n");
1851 entry
= entry
->next
;
1855 hw_newfib
= *hw_fib_p
;
1856 *(hw_fib_p
++) = NULL
;
1860 * Make the copy of the FIB
1862 memcpy(hw_newfib
, hw_fib
, sizeof(struct hw_fib
));
1863 memcpy(newfib
, fib
, sizeof(struct fib
));
1864 newfib
->hw_fib_va
= hw_newfib
;
1866 * Put the FIB onto the
1869 list_add_tail(&newfib
->fiblink
, &fibctx
->fib_list
);
1872 * Set the event to wake up the
1873 * thread that is waiting.
1875 up(&fibctx
->wait_sem
);
1877 entry
= entry
->next
;
1880 * Set the status of this FIB
1882 *(__le32
*)hw_fib
->data
= cpu_to_le32(ST_OK
);
1883 aac_fib_adapter_complete(fib
, sizeof(u32
));
1884 spin_unlock_irqrestore(&dev
->fib_lock
, flagv
);
1888 static void aac_process_events(struct aac_dev
*dev
)
1890 struct hw_fib
*hw_fib
;
1892 unsigned long flags
;
1896 t_lock
= dev
->queues
->queue
[HostNormCmdQueue
].lock
;
1897 spin_lock_irqsave(t_lock
, flags
);
1899 while (!list_empty(&(dev
->queues
->queue
[HostNormCmdQueue
].cmdq
))) {
1900 struct list_head
*entry
;
1901 struct aac_aifcmd
*aifcmd
;
1903 struct hw_fib
**hw_fib_pool
, **hw_fib_p
;
1904 struct fib
**fib_pool
, **fib_p
;
1906 set_current_state(TASK_RUNNING
);
1908 entry
= dev
->queues
->queue
[HostNormCmdQueue
].cmdq
.next
;
1911 t_lock
= dev
->queues
->queue
[HostNormCmdQueue
].lock
;
1912 spin_unlock_irqrestore(t_lock
, flags
);
1914 fib
= list_entry(entry
, struct fib
, fiblink
);
1915 hw_fib
= fib
->hw_fib_va
;
1917 * We will process the FIB here or pass it to a
1918 * worker thread that is TBD. We Really can't
1919 * do anything at this point since we don't have
1920 * anything defined for this thread to do.
1922 memset(fib
, 0, sizeof(struct fib
));
1923 fib
->type
= FSAFS_NTC_FIB_CONTEXT
;
1924 fib
->size
= sizeof(struct fib
);
1925 fib
->hw_fib_va
= hw_fib
;
1926 fib
->data
= hw_fib
->data
;
1929 * We only handle AifRequest fibs from the adapter.
1932 aifcmd
= (struct aac_aifcmd
*) hw_fib
->data
;
1933 if (aifcmd
->command
== cpu_to_le32(AifCmdDriverNotify
)) {
1934 /* Handle Driver Notify Events */
1935 aac_handle_aif(dev
, fib
);
1936 *(__le32
*)hw_fib
->data
= cpu_to_le32(ST_OK
);
1937 aac_fib_adapter_complete(fib
, (u16
)sizeof(u32
));
1941 * The u32 here is important and intended. We are using
1942 * 32bit wrapping time to fit the adapter field
1946 if (aifcmd
->command
== cpu_to_le32(AifCmdEventNotify
)
1947 || aifcmd
->command
== cpu_to_le32(AifCmdJobProgress
)) {
1948 aac_handle_aif(dev
, fib
);
1952 * get number of fibs to process
1954 num
= get_fib_count(dev
);
1958 hw_fib_pool
= kmalloc_array(num
, sizeof(struct hw_fib
*),
1963 fib_pool
= kmalloc_array(num
, sizeof(struct fib
*), GFP_KERNEL
);
1965 goto free_hw_fib_pool
;
1968 * Fill up fib pointer pools with actual fibs
1971 rcode
= fillup_pools(dev
, hw_fib_pool
, fib_pool
, num
);
1976 * wakeup the thread that is waiting for
1977 * the response from fw (ioctl)
1979 wakeup_fibctx_threads(dev
, hw_fib_pool
, fib_pool
,
1983 /* Free up the remaining resources */
1984 hw_fib_p
= hw_fib_pool
;
1986 while (hw_fib_p
< &hw_fib_pool
[num
]) {
1997 t_lock
= dev
->queues
->queue
[HostNormCmdQueue
].lock
;
1998 spin_lock_irqsave(t_lock
, flags
);
2001 * There are no more AIF's
2003 t_lock
= dev
->queues
->queue
[HostNormCmdQueue
].lock
;
2004 spin_unlock_irqrestore(t_lock
, flags
);
2007 static int aac_send_wellness_command(struct aac_dev
*dev
, char *wellness_str
,
2010 struct aac_srb
*srbcmd
;
2011 struct sgmap64
*sg64
;
2018 fibptr
= aac_fib_alloc(dev
);
2022 dma_buf
= pci_alloc_consistent(dev
->pdev
, datasize
, &addr
);
2026 aac_fib_init(fibptr
);
2028 vbus
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceBus
);
2029 vid
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceTarget
);
2031 srbcmd
= (struct aac_srb
*)fib_data(fibptr
);
2033 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
2034 srbcmd
->channel
= cpu_to_le32(vbus
);
2035 srbcmd
->id
= cpu_to_le32(vid
);
2037 srbcmd
->flags
= cpu_to_le32(SRB_DataOut
);
2038 srbcmd
->timeout
= cpu_to_le32(10);
2039 srbcmd
->retry_limit
= 0;
2040 srbcmd
->cdb_size
= cpu_to_le32(12);
2041 srbcmd
->count
= cpu_to_le32(datasize
);
2043 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
2044 srbcmd
->cdb
[0] = BMIC_OUT
;
2045 srbcmd
->cdb
[6] = WRITE_HOST_WELLNESS
;
2046 memcpy(dma_buf
, (char *)wellness_str
, datasize
);
2048 sg64
= (struct sgmap64
*)&srbcmd
->sg
;
2049 sg64
->count
= cpu_to_le32(1);
2050 sg64
->sg
[0].addr
[1] = cpu_to_le32((u32
)(((addr
) >> 16) >> 16));
2051 sg64
->sg
[0].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
2052 sg64
->sg
[0].count
= cpu_to_le32(datasize
);
2054 ret
= aac_fib_send(ScsiPortCommand64
, fibptr
, sizeof(struct aac_srb
),
2055 FsaNormal
, 1, 1, NULL
, NULL
);
2057 pci_free_consistent(dev
->pdev
, datasize
, (void *)dma_buf
, addr
);
2060 * Do not set XferState to zero unless
2061 * receives a response from F/W
2064 aac_fib_complete(fibptr
);
2067 * FIB should be freed only after
2068 * getting the response from the F/W
2070 if (ret
!= -ERESTARTSYS
)
2076 aac_fib_free(fibptr
);
2080 int aac_send_safw_hostttime(struct aac_dev
*dev
, struct timeval
*now
)
2083 char wellness_str
[] = "<HW>TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ";
2084 u32 datasize
= sizeof(wellness_str
);
2085 unsigned long local_time
;
2088 if (!dev
->sa_firmware
)
2091 local_time
= (u32
)(now
->tv_sec
- (sys_tz
.tz_minuteswest
* 60));
2092 time_to_tm(local_time
, 0, &cur_tm
);
2094 cur_tm
.tm_year
+= 1900;
2095 wellness_str
[8] = bin2bcd(cur_tm
.tm_hour
);
2096 wellness_str
[9] = bin2bcd(cur_tm
.tm_min
);
2097 wellness_str
[10] = bin2bcd(cur_tm
.tm_sec
);
2098 wellness_str
[12] = bin2bcd(cur_tm
.tm_mon
);
2099 wellness_str
[13] = bin2bcd(cur_tm
.tm_mday
);
2100 wellness_str
[14] = bin2bcd(cur_tm
.tm_year
/ 100);
2101 wellness_str
[15] = bin2bcd(cur_tm
.tm_year
% 100);
2103 ret
= aac_send_wellness_command(dev
, wellness_str
, datasize
);
2109 int aac_send_hosttime(struct aac_dev
*dev
, struct timeval
*now
)
2115 fibptr
= aac_fib_alloc(dev
);
2119 aac_fib_init(fibptr
);
2120 info
= (__le32
*)fib_data(fibptr
);
2121 *info
= cpu_to_le32(now
->tv_sec
);
2122 ret
= aac_fib_send(SendHostTime
, fibptr
, sizeof(*info
), FsaNormal
,
2126 * Do not set XferState to zero unless
2127 * receives a response from F/W
2130 aac_fib_complete(fibptr
);
2133 * FIB should be freed only after
2134 * getting the response from the F/W
2136 if (ret
!= -ERESTARTSYS
)
2137 aac_fib_free(fibptr
);
2144 * aac_command_thread - command processing thread
2145 * @dev: Adapter to monitor
2147 * Waits on the commandready event in it's queue. When the event gets set
2148 * it will pull FIBs off it's queue. It will continue to pull FIBs off
2149 * until the queue is empty. When the queue is empty it will wait for
2153 int aac_command_thread(void *data
)
2155 struct aac_dev
*dev
= data
;
2156 DECLARE_WAITQUEUE(wait
, current
);
2157 unsigned long next_jiffies
= jiffies
+ HZ
;
2158 unsigned long next_check_jiffies
= next_jiffies
;
2159 long difference
= HZ
;
2162 * We can only have one thread per adapter for AIF's.
2164 if (dev
->aif_thread
)
2168 * Let the DPC know it has a place to send the AIF's to.
2170 dev
->aif_thread
= 1;
2171 add_wait_queue(&dev
->queues
->queue
[HostNormCmdQueue
].cmdready
, &wait
);
2172 set_current_state(TASK_INTERRUPTIBLE
);
2173 dprintk ((KERN_INFO
"aac_command_thread start\n"));
2176 aac_process_events(dev
);
2179 * Background activity
2181 if ((time_before(next_check_jiffies
,next_jiffies
))
2182 && ((difference
= next_check_jiffies
- jiffies
) <= 0)) {
2183 next_check_jiffies
= next_jiffies
;
2184 if (aac_check_health(dev
) == 0) {
2185 difference
= ((long)(unsigned)check_interval
)
2187 next_check_jiffies
= jiffies
+ difference
;
2188 } else if (!dev
->queues
)
2191 if (!time_before(next_check_jiffies
,next_jiffies
)
2192 && ((difference
= next_jiffies
- jiffies
) <= 0)) {
2196 /* Don't even try to talk to adapter if its sick */
2197 ret
= aac_check_health(dev
);
2200 next_check_jiffies
= jiffies
2201 + ((long)(unsigned)check_interval
)
2203 do_gettimeofday(&now
);
2205 /* Synchronize our watches */
2206 if (((1000000 - (1000000 / HZ
)) > now
.tv_usec
)
2207 && (now
.tv_usec
> (1000000 / HZ
)))
2208 difference
= (((1000000 - now
.tv_usec
) * HZ
)
2209 + 500000) / 1000000;
2210 else if (ret
== 0) {
2212 if (now
.tv_usec
> 500000)
2215 if (dev
->sa_firmware
)
2217 aac_send_safw_hostttime(dev
, &now
);
2219 ret
= aac_send_hosttime(dev
, &now
);
2221 difference
= (long)(unsigned)update_interval
*HZ
;
2224 difference
= 10 * HZ
;
2226 next_jiffies
= jiffies
+ difference
;
2227 if (time_before(next_check_jiffies
,next_jiffies
))
2228 difference
= next_check_jiffies
- jiffies
;
2230 if (difference
<= 0)
2232 set_current_state(TASK_INTERRUPTIBLE
);
2234 if (kthread_should_stop())
2237 schedule_timeout(difference
);
2239 if (kthread_should_stop())
2243 remove_wait_queue(&dev
->queues
->queue
[HostNormCmdQueue
].cmdready
, &wait
);
2244 dev
->aif_thread
= 0;
2248 int aac_acquire_irq(struct aac_dev
*dev
)
2254 if (!dev
->sync_mode
&& dev
->msi_enabled
&& dev
->max_msix
> 1) {
2255 for (i
= 0; i
< dev
->max_msix
; i
++) {
2256 dev
->aac_msix
[i
].vector_no
= i
;
2257 dev
->aac_msix
[i
].dev
= dev
;
2258 if (request_irq(pci_irq_vector(dev
->pdev
, i
),
2259 dev
->a_ops
.adapter_intr
,
2260 0, "aacraid", &(dev
->aac_msix
[i
]))) {
2261 printk(KERN_ERR
"%s%d: Failed to register IRQ for vector %d.\n",
2262 dev
->name
, dev
->id
, i
);
2263 for (j
= 0 ; j
< i
; j
++)
2264 free_irq(pci_irq_vector(dev
->pdev
, j
),
2265 &(dev
->aac_msix
[j
]));
2266 pci_disable_msix(dev
->pdev
);
2271 dev
->aac_msix
[0].vector_no
= 0;
2272 dev
->aac_msix
[0].dev
= dev
;
2274 if (request_irq(dev
->pdev
->irq
, dev
->a_ops
.adapter_intr
,
2275 IRQF_SHARED
, "aacraid",
2276 &(dev
->aac_msix
[0])) < 0) {
2278 pci_disable_msi(dev
->pdev
);
2279 printk(KERN_ERR
"%s%d: Interrupt unavailable.\n",
2280 dev
->name
, dev
->id
);
2287 void aac_free_irq(struct aac_dev
*dev
)
2292 cpu
= cpumask_first(cpu_online_mask
);
2293 if (dev
->pdev
->device
== PMC_DEVICE_S6
||
2294 dev
->pdev
->device
== PMC_DEVICE_S7
||
2295 dev
->pdev
->device
== PMC_DEVICE_S8
||
2296 dev
->pdev
->device
== PMC_DEVICE_S9
) {
2297 if (dev
->max_msix
> 1) {
2298 for (i
= 0; i
< dev
->max_msix
; i
++)
2299 free_irq(pci_irq_vector(dev
->pdev
, i
),
2300 &(dev
->aac_msix
[i
]));
2302 free_irq(dev
->pdev
->irq
, &(dev
->aac_msix
[0]));
2305 free_irq(dev
->pdev
->irq
, dev
);
2308 pci_disable_msi(dev
->pdev
);
2309 else if (dev
->max_msix
> 1)
2310 pci_disable_msix(dev
->pdev
);