3 * Linux MegaRAID device driver
5 * Copyright (c) 2002 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
14 * - speed-ups (list handling fixes, issued_list, optimizations.)
17 * Copyright (c) 2003 Christoph Hellwig <hch@lst.de>
18 * - new-style, hotplug-aware pci probing and scsi registration
20 * Version : v2.00.4 Mon Nov 14 14:02:43 EST 2005 - Seokmann Ju
21 * <Seokmann.Ju@lsil.com>
23 * Description: Linux device driver for LSI Logic MegaRAID controller
25 * Supported controllers: MegaRAID 418, 428, 438, 466, 762, 467, 471, 490, 493
28 * This driver is supported by LSI Logic, with assistance from Red Hat, Dell,
29 * and others. Please send updates to the mailing list
30 * linux-scsi@vger.kernel.org .
36 #include <linux/blkdev.h>
37 #include <asm/uaccess.h>
39 #include <linux/completion.h>
40 #include <linux/delay.h>
41 #include <linux/proc_fs.h>
42 #include <linux/reboot.h>
43 #include <linux/module.h>
44 #include <linux/list.h>
45 #include <linux/interrupt.h>
46 #include <linux/pci.h>
47 #include <linux/init.h>
48 #include <linux/dma-mapping.h>
49 #include <linux/smp_lock.h>
50 #include <linux/slab.h>
51 #include <scsi/scsicam.h>
54 #include <scsi/scsi_host.h>
58 #define MEGARAID_MODULE_VERSION "2.00.4"
60 MODULE_AUTHOR ("sju@lsil.com");
61 MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
62 MODULE_LICENSE ("GPL");
63 MODULE_VERSION(MEGARAID_MODULE_VERSION
);
65 static unsigned int max_cmd_per_lun
= DEF_CMD_PER_LUN
;
66 module_param(max_cmd_per_lun
, uint
, 0);
67 MODULE_PARM_DESC(max_cmd_per_lun
, "Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)");
69 static unsigned short int max_sectors_per_io
= MAX_SECTORS_PER_IO
;
70 module_param(max_sectors_per_io
, ushort
, 0);
71 MODULE_PARM_DESC(max_sectors_per_io
, "Maximum number of sectors per I/O request (default=MAX_SECTORS_PER_IO=128)");
74 static unsigned short int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
75 module_param(max_mbox_busy_wait
, ushort
, 0);
76 MODULE_PARM_DESC(max_mbox_busy_wait
, "Maximum wait for mailbox in microseconds if busy (default=MBOX_BUSY_WAIT=10)");
78 #define RDINDOOR(adapter) readl((adapter)->mmio_base + 0x20)
79 #define RDOUTDOOR(adapter) readl((adapter)->mmio_base + 0x2C)
80 #define WRINDOOR(adapter,value) writel(value, (adapter)->mmio_base + 0x20)
81 #define WROUTDOOR(adapter,value) writel(value, (adapter)->mmio_base + 0x2C)
88 static adapter_t
*hba_soft_state
[MAX_CONTROLLERS
];
89 static struct proc_dir_entry
*mega_proc_dir_entry
;
91 /* For controller re-ordering */
92 static struct mega_hbas mega_hbas
[MAX_CONTROLLERS
];
95 megadev_unlocked_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
);
98 * The File Operations structure for the serial/ioctl interface of the driver
100 static const struct file_operations megadev_fops
= {
101 .owner
= THIS_MODULE
,
102 .unlocked_ioctl
= megadev_unlocked_ioctl
,
103 .open
= megadev_open
,
107 * Array to structures for storing the information about the controllers. This
108 * information is sent to the user level applications, when they do an ioctl
109 * for this information.
111 static struct mcontroller mcontroller
[MAX_CONTROLLERS
];
113 /* The current driver version */
114 static u32 driver_ver
= 0x02000000;
116 /* major number used by the device for character interface */
119 #define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
123 * Debug variable to print some diagnostic messages
125 static int trace_level
;
128 * mega_setup_mailbox()
129 * @adapter - pointer to our soft state
131 * Allocates a 8 byte aligned memory for the handshake mailbox.
134 mega_setup_mailbox(adapter_t
*adapter
)
138 adapter
->una_mbox64
= pci_alloc_consistent(adapter
->dev
,
139 sizeof(mbox64_t
), &adapter
->una_mbox64_dma
);
141 if( !adapter
->una_mbox64
) return -1;
143 adapter
->mbox
= &adapter
->una_mbox64
->mbox
;
145 adapter
->mbox
= (mbox_t
*)((((unsigned long) adapter
->mbox
) + 15) &
148 adapter
->mbox64
= (mbox64_t
*)(((unsigned long)adapter
->mbox
) - 8);
150 align
= ((void *)adapter
->mbox
) - ((void *)&adapter
->una_mbox64
->mbox
);
152 adapter
->mbox_dma
= adapter
->una_mbox64_dma
+ 8 + align
;
155 * Register the mailbox if the controller is an io-mapped controller
157 if( adapter
->flag
& BOARD_IOMAP
) {
159 outb(adapter
->mbox_dma
& 0xFF,
160 adapter
->host
->io_port
+ MBOX_PORT0
);
162 outb((adapter
->mbox_dma
>> 8) & 0xFF,
163 adapter
->host
->io_port
+ MBOX_PORT1
);
165 outb((adapter
->mbox_dma
>> 16) & 0xFF,
166 adapter
->host
->io_port
+ MBOX_PORT2
);
168 outb((adapter
->mbox_dma
>> 24) & 0xFF,
169 adapter
->host
->io_port
+ MBOX_PORT3
);
171 outb(ENABLE_MBOX_BYTE
,
172 adapter
->host
->io_port
+ ENABLE_MBOX_REGION
);
184 * mega_query_adapter()
185 * @adapter - pointer to our soft state
187 * Issue the adapter inquiry commands to the controller and find out
188 * information and parameter about the devices attached
191 mega_query_adapter(adapter_t
*adapter
)
193 dma_addr_t prod_info_dma_handle
;
194 mega_inquiry3
*inquiry3
;
195 u8 raw_mbox
[sizeof(struct mbox_out
)];
199 /* Initialize adapter inquiry mailbox */
201 mbox
= (mbox_t
*)raw_mbox
;
203 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
204 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
207 * Try to issue Inquiry3 command
208 * if not succeeded, then issue MEGA_MBOXCMD_ADAPTERINQ command and
209 * update enquiry3 structure
211 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
213 inquiry3
= (mega_inquiry3
*)adapter
->mega_buffer
;
215 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
216 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
; /* i.e. 0x0F */
217 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
; /* i.e. 0x02 */
219 /* Issue a blocking command to the card */
220 if ((retval
= issue_scb_block(adapter
, raw_mbox
))) {
221 /* the adapter does not support 40ld */
223 mraid_ext_inquiry
*ext_inq
;
225 dma_addr_t dma_handle
;
227 ext_inq
= pci_alloc_consistent(adapter
->dev
,
228 sizeof(mraid_ext_inquiry
), &dma_handle
);
230 if( ext_inq
== NULL
) return -1;
232 inq
= &ext_inq
->raid_inq
;
234 mbox
->m_out
.xferaddr
= (u32
)dma_handle
;
236 /*issue old 0x04 command to adapter */
237 mbox
->m_out
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
239 issue_scb_block(adapter
, raw_mbox
);
242 * update Enquiry3 and ProductInfo structures with
243 * mraid_inquiry structure
245 mega_8_to_40ld(inq
, inquiry3
,
246 (mega_product_info
*)&adapter
->product_info
);
248 pci_free_consistent(adapter
->dev
, sizeof(mraid_ext_inquiry
),
249 ext_inq
, dma_handle
);
251 } else { /*adapter supports 40ld */
252 adapter
->flag
|= BOARD_40LD
;
255 * get product_info, which is static information and will be
258 prod_info_dma_handle
= pci_map_single(adapter
->dev
, (void *)
259 &adapter
->product_info
,
260 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
262 mbox
->m_out
.xferaddr
= prod_info_dma_handle
;
264 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
265 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
; /* i.e. 0x0E */
267 if ((retval
= issue_scb_block(adapter
, raw_mbox
)))
269 "megaraid: Product_info cmd failed with error: %d\n",
272 pci_unmap_single(adapter
->dev
, prod_info_dma_handle
,
273 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
278 * kernel scans the channels from 0 to <= max_channel
280 adapter
->host
->max_channel
=
281 adapter
->product_info
.nchannels
+ NVIRT_CHAN
-1;
283 adapter
->host
->max_id
= 16; /* max targets per channel */
285 adapter
->host
->max_lun
= 7; /* Upto 7 luns for non disk devices */
287 adapter
->host
->cmd_per_lun
= max_cmd_per_lun
;
289 adapter
->numldrv
= inquiry3
->num_ldrv
;
291 adapter
->max_cmds
= adapter
->product_info
.max_commands
;
293 if(adapter
->max_cmds
> MAX_COMMANDS
)
294 adapter
->max_cmds
= MAX_COMMANDS
;
296 adapter
->host
->can_queue
= adapter
->max_cmds
- 1;
299 * Get the maximum number of scatter-gather elements supported by this
302 mega_get_max_sgl(adapter
);
304 adapter
->host
->sg_tablesize
= adapter
->sglen
;
307 /* use HP firmware and bios version encoding */
308 if (adapter
->product_info
.subsysvid
== HP_SUBSYS_VID
) {
309 sprintf (adapter
->fw_version
, "%c%d%d.%d%d",
310 adapter
->product_info
.fw_version
[2],
311 adapter
->product_info
.fw_version
[1] >> 8,
312 adapter
->product_info
.fw_version
[1] & 0x0f,
313 adapter
->product_info
.fw_version
[0] >> 8,
314 adapter
->product_info
.fw_version
[0] & 0x0f);
315 sprintf (adapter
->bios_version
, "%c%d%d.%d%d",
316 adapter
->product_info
.bios_version
[2],
317 adapter
->product_info
.bios_version
[1] >> 8,
318 adapter
->product_info
.bios_version
[1] & 0x0f,
319 adapter
->product_info
.bios_version
[0] >> 8,
320 adapter
->product_info
.bios_version
[0] & 0x0f);
322 memcpy(adapter
->fw_version
,
323 (char *)adapter
->product_info
.fw_version
, 4);
324 adapter
->fw_version
[4] = 0;
326 memcpy(adapter
->bios_version
,
327 (char *)adapter
->product_info
.bios_version
, 4);
329 adapter
->bios_version
[4] = 0;
332 printk(KERN_NOTICE
"megaraid: [%s:%s] detected %d logical drives.\n",
333 adapter
->fw_version
, adapter
->bios_version
, adapter
->numldrv
);
336 * Do we support extended (>10 bytes) cdbs
338 adapter
->support_ext_cdb
= mega_support_ext_cdb(adapter
);
339 if (adapter
->support_ext_cdb
)
340 printk(KERN_NOTICE
"megaraid: supports extended CDBs.\n");
348 * @adapter - pointer to our soft state
350 * Runs through the list of pending requests.
353 mega_runpendq(adapter_t
*adapter
)
355 if(!list_empty(&adapter
->pending_list
))
356 __mega_runpendq(adapter
);
361 * @scmd - Issue this scsi command
362 * @done - the callback hook into the scsi mid-layer
364 * The command queuing entry point for the mid-layer.
367 megaraid_queue(Scsi_Cmnd
*scmd
, void (*done
)(Scsi_Cmnd
*))
374 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
376 scmd
->scsi_done
= done
;
380 * Allocate and build a SCB request
381 * busy flag will be set if mega_build_cmd() command could not
382 * allocate scb. We will return non-zero status in that case.
383 * NOTE: scb can be null even though certain commands completed
384 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
385 * return 0 in that case.
388 spin_lock_irqsave(&adapter
->lock
, flags
);
389 scb
= mega_build_cmd(adapter
, scmd
, &busy
);
393 scb
->state
|= SCB_PENDQ
;
394 list_add_tail(&scb
->list
, &adapter
->pending_list
);
397 * Check if the HBA is in quiescent state, e.g., during a
398 * delete logical drive opertion. If it is, don't run
401 if (atomic_read(&adapter
->quiescent
) == 0)
402 mega_runpendq(adapter
);
406 spin_unlock_irqrestore(&adapter
->lock
, flags
);
411 * mega_allocate_scb()
412 * @adapter - pointer to our soft state
413 * @cmd - scsi command from the mid-layer
415 * Allocate a SCB structure. This is the central structure for controller
418 static inline scb_t
*
419 mega_allocate_scb(adapter_t
*adapter
, Scsi_Cmnd
*cmd
)
421 struct list_head
*head
= &adapter
->free_list
;
424 /* Unlink command from Free List */
425 if( !list_empty(head
) ) {
427 scb
= list_entry(head
->next
, scb_t
, list
);
429 list_del_init(head
->next
);
431 scb
->state
= SCB_ACTIVE
;
433 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
442 * mega_get_ldrv_num()
443 * @adapter - pointer to our soft state
444 * @cmd - scsi mid layer command
445 * @channel - channel on the controller
447 * Calculate the logical drive number based on the information in scsi command
448 * and the channel number.
451 mega_get_ldrv_num(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int channel
)
456 tgt
= cmd
->device
->id
;
458 if ( tgt
> adapter
->this_id
)
459 tgt
--; /* we do not get inquires for initiator id */
461 ldrv_num
= (channel
* 15) + tgt
;
465 * If we have a logical drive with boot enabled, project it first
467 if( adapter
->boot_ldrv_enabled
) {
468 if( ldrv_num
== 0 ) {
469 ldrv_num
= adapter
->boot_ldrv
;
472 if( ldrv_num
<= adapter
->boot_ldrv
) {
479 * If "delete logical drive" feature is enabled on this controller.
480 * Do only if at least one delete logical drive operation was done.
482 * Also, after logical drive deletion, instead of logical drive number,
483 * the value returned should be 0x80+logical drive id.
485 * These is valid only for IO commands.
488 if (adapter
->support_random_del
&& adapter
->read_ldidmap
)
489 switch (cmd
->cmnd
[0]) {
490 case READ_6
: /* fall through */
491 case WRITE_6
: /* fall through */
492 case READ_10
: /* fall through */
502 * @adapter - pointer to our soft state
503 * @cmd - Prepare using this scsi command
504 * @busy - busy flag if no resources
506 * Prepares a command and scatter gather list for the controller. This routine
507 * also finds out if the commands is intended for a logical drive or a
508 * physical device and prepares the controller command accordingly.
510 * We also re-order the logical drives and physical devices based on their
514 mega_build_cmd(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int *busy
)
516 mega_ext_passthru
*epthru
;
517 mega_passthru
*pthru
;
525 int ldrv_num
= 0; /* logical drive number */
529 * filter the internal and ioctl commands
531 if((cmd
->cmnd
[0] == MEGA_INTERNAL_CMD
))
532 return (scb_t
*)cmd
->host_scribble
;
535 * We know what channels our logical drives are on - mega_find_card()
537 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
540 * The theory: If physical drive is chosen for boot, all the physical
541 * devices are exported before the logical drives, otherwise physical
542 * devices are pushed after logical drives, in which case - Kernel sees
543 * the physical devices on virtual channel which is obviously converted
544 * to actual channel on the HBA.
546 if( adapter
->boot_pdrv_enabled
) {
548 /* logical channel */
549 channel
= cmd
->device
->channel
-
550 adapter
->product_info
.nchannels
;
553 /* this is physical channel */
554 channel
= cmd
->device
->channel
;
555 target
= cmd
->device
->id
;
558 * boot from a physical disk, that disk needs to be
559 * exposed first IF both the channels are SCSI, then
560 * booting from the second channel is not allowed.
563 target
= adapter
->boot_pdrv_tgt
;
565 else if( target
== adapter
->boot_pdrv_tgt
) {
572 /* this is the logical channel */
573 channel
= cmd
->device
->channel
;
576 /* physical channel */
577 channel
= cmd
->device
->channel
- NVIRT_CHAN
;
578 target
= cmd
->device
->id
;
585 /* have just LUN 0 for each target on virtual channels */
586 if (cmd
->device
->lun
) {
587 cmd
->result
= (DID_BAD_TARGET
<< 16);
592 ldrv_num
= mega_get_ldrv_num(adapter
, cmd
, channel
);
595 max_ldrv_num
= (adapter
->flag
& BOARD_40LD
) ?
596 MAX_LOGICAL_DRIVES_40LD
: MAX_LOGICAL_DRIVES_8LD
;
599 * max_ldrv_num increases by 0x80 if some logical drive was
602 if(adapter
->read_ldidmap
)
603 max_ldrv_num
+= 0x80;
605 if(ldrv_num
> max_ldrv_num
) {
606 cmd
->result
= (DID_BAD_TARGET
<< 16);
613 if( cmd
->device
->lun
> 7) {
615 * Do not support lun >7 for physically accessed
618 cmd
->result
= (DID_BAD_TARGET
<< 16);
626 * Logical drive commands
630 switch (cmd
->cmnd
[0]) {
631 case TEST_UNIT_READY
:
632 #if MEGA_HAVE_CLUSTERING
634 * Do we support clustering and is the support enabled
635 * If no, return success always
637 if( !adapter
->has_cluster
) {
638 cmd
->result
= (DID_OK
<< 16);
643 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
648 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
649 scb
->raw_mbox
[2] = MEGA_RESERVATION_STATUS
;
650 scb
->raw_mbox
[3] = ldrv_num
;
652 scb
->dma_direction
= PCI_DMA_NONE
;
656 cmd
->result
= (DID_OK
<< 16);
663 struct scatterlist
*sg
;
665 sg
= scsi_sglist(cmd
);
666 buf
= kmap_atomic(sg_page(sg
), KM_IRQ0
) + sg
->offset
;
668 memset(buf
, 0, cmd
->cmnd
[4]);
669 kunmap_atomic(buf
- sg
->offset
, KM_IRQ0
);
671 cmd
->result
= (DID_OK
<< 16);
679 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
682 "scsi%d: scanning scsi channel %d ",
683 adapter
->host
->host_no
,
684 cmd
->device
->channel
);
685 printk("for logical drives.\n");
687 adapter
->flag
|= (1L << cmd
->device
->channel
);
690 /* Allocate a SCB and initialize passthru */
691 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
697 mbox
= (mbox_t
*)scb
->raw_mbox
;
698 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
699 memset(pthru
, 0, sizeof(mega_passthru
));
703 pthru
->reqsenselen
= 14;
704 pthru
->islogical
= 1;
705 pthru
->logdrv
= ldrv_num
;
706 pthru
->cdblen
= cmd
->cmd_len
;
707 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
709 if( adapter
->has_64bit_addr
) {
710 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
713 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
716 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
718 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
719 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
721 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
732 /* Allocate a SCB and initialize mailbox */
733 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
737 mbox
= (mbox_t
*)scb
->raw_mbox
;
739 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
740 mbox
->m_out
.logdrv
= ldrv_num
;
743 * A little hack: 2nd bit is zero for all scsi read
744 * commands and is set for all scsi write commands
746 if( adapter
->has_64bit_addr
) {
747 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
748 MEGA_MBOXCMD_LWRITE64
:
749 MEGA_MBOXCMD_LREAD64
;
752 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
758 * 6-byte READ(0x08) or WRITE(0x0A) cdb
760 if( cmd
->cmd_len
== 6 ) {
761 mbox
->m_out
.numsectors
= (u32
) cmd
->cmnd
[4];
763 ((u32
)cmd
->cmnd
[1] << 16) |
764 ((u32
)cmd
->cmnd
[2] << 8) |
767 mbox
->m_out
.lba
&= 0x1FFFFF;
771 * Take modulo 0x80, since the logical drive
772 * number increases by 0x80 when a logical
775 if (*cmd
->cmnd
== READ_6
) {
776 adapter
->nreads
[ldrv_num
%0x80]++;
777 adapter
->nreadblocks
[ldrv_num
%0x80] +=
778 mbox
->m_out
.numsectors
;
780 adapter
->nwrites
[ldrv_num
%0x80]++;
781 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
782 mbox
->m_out
.numsectors
;
788 * 10-byte READ(0x28) or WRITE(0x2A) cdb
790 if( cmd
->cmd_len
== 10 ) {
791 mbox
->m_out
.numsectors
=
793 ((u32
)cmd
->cmnd
[7] << 8);
795 ((u32
)cmd
->cmnd
[2] << 24) |
796 ((u32
)cmd
->cmnd
[3] << 16) |
797 ((u32
)cmd
->cmnd
[4] << 8) |
801 if (*cmd
->cmnd
== READ_10
) {
802 adapter
->nreads
[ldrv_num
%0x80]++;
803 adapter
->nreadblocks
[ldrv_num
%0x80] +=
804 mbox
->m_out
.numsectors
;
806 adapter
->nwrites
[ldrv_num
%0x80]++;
807 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
808 mbox
->m_out
.numsectors
;
814 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
816 if( cmd
->cmd_len
== 12 ) {
818 ((u32
)cmd
->cmnd
[2] << 24) |
819 ((u32
)cmd
->cmnd
[3] << 16) |
820 ((u32
)cmd
->cmnd
[4] << 8) |
823 mbox
->m_out
.numsectors
=
824 ((u32
)cmd
->cmnd
[6] << 24) |
825 ((u32
)cmd
->cmnd
[7] << 16) |
826 ((u32
)cmd
->cmnd
[8] << 8) |
830 if (*cmd
->cmnd
== READ_12
) {
831 adapter
->nreads
[ldrv_num
%0x80]++;
832 adapter
->nreadblocks
[ldrv_num
%0x80] +=
833 mbox
->m_out
.numsectors
;
835 adapter
->nwrites
[ldrv_num
%0x80]++;
836 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
837 mbox
->m_out
.numsectors
;
843 * If it is a read command
845 if( (*cmd
->cmnd
& 0x0F) == 0x08 ) {
846 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
849 scb
->dma_direction
= PCI_DMA_TODEVICE
;
852 /* Calculate Scatter-Gather info */
853 mbox
->m_out
.numsgelements
= mega_build_sglist(adapter
, scb
,
854 (u32
*)&mbox
->m_out
.xferaddr
, (u32
*)&seg
);
858 #if MEGA_HAVE_CLUSTERING
859 case RESERVE
: /* Fall through */
863 * Do we support clustering and is the support enabled
865 if( ! adapter
->has_cluster
) {
867 cmd
->result
= (DID_BAD_TARGET
<< 16);
872 /* Allocate a SCB and initialize mailbox */
873 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
878 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
879 scb
->raw_mbox
[2] = ( *cmd
->cmnd
== RESERVE
) ?
880 MEGA_RESERVE_LD
: MEGA_RELEASE_LD
;
882 scb
->raw_mbox
[3] = ldrv_num
;
884 scb
->dma_direction
= PCI_DMA_NONE
;
890 cmd
->result
= (DID_BAD_TARGET
<< 16);
897 * Passthru drive commands
900 /* Allocate a SCB and initialize passthru */
901 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
906 mbox
= (mbox_t
*)scb
->raw_mbox
;
907 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
909 if( adapter
->support_ext_cdb
) {
911 epthru
= mega_prepare_extpassthru(adapter
, scb
, cmd
,
914 mbox
->m_out
.cmd
= MEGA_MBOXCMD_EXTPTHRU
;
916 mbox
->m_out
.xferaddr
= scb
->epthru_dma_addr
;
921 pthru
= mega_prepare_passthru(adapter
, scb
, cmd
,
924 /* Initialize mailbox */
925 if( adapter
->has_64bit_addr
) {
926 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
929 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
932 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
942 * mega_prepare_passthru()
943 * @adapter - pointer to our soft state
944 * @scb - our scsi control block
945 * @cmd - scsi command from the mid-layer
946 * @channel - actual channel on the controller
947 * @target - actual id on the controller.
949 * prepare a command for the scsi physical devices.
951 static mega_passthru
*
952 mega_prepare_passthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
953 int channel
, int target
)
955 mega_passthru
*pthru
;
958 memset(pthru
, 0, sizeof (mega_passthru
));
960 /* 0=6sec/1=60sec/2=10min/3=3hrs */
964 pthru
->reqsenselen
= 14;
965 pthru
->islogical
= 0;
967 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
969 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
970 (channel
<< 4) | target
: target
;
972 pthru
->cdblen
= cmd
->cmd_len
;
973 pthru
->logdrv
= cmd
->device
->lun
;
975 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
977 /* Not sure about the direction */
978 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
980 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
981 switch (cmd
->cmnd
[0]) {
984 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
987 "scsi%d: scanning scsi channel %d [P%d] ",
988 adapter
->host
->host_no
,
989 cmd
->device
->channel
, channel
);
990 printk("for physical devices.\n");
992 adapter
->flag
|= (1L << cmd
->device
->channel
);
996 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
997 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
1005 * mega_prepare_extpassthru()
1006 * @adapter - pointer to our soft state
1007 * @scb - our scsi control block
1008 * @cmd - scsi command from the mid-layer
1009 * @channel - actual channel on the controller
1010 * @target - actual id on the controller.
1012 * prepare a command for the scsi physical devices. This rountine prepares
1013 * commands for devices which can take extended CDBs (>10 bytes)
1015 static mega_ext_passthru
*
1016 mega_prepare_extpassthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
1017 int channel
, int target
)
1019 mega_ext_passthru
*epthru
;
1021 epthru
= scb
->epthru
;
1022 memset(epthru
, 0, sizeof(mega_ext_passthru
));
1024 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1025 epthru
->timeout
= 2;
1028 epthru
->reqsenselen
= 14;
1029 epthru
->islogical
= 0;
1031 epthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
1032 epthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
1033 (channel
<< 4) | target
: target
;
1035 epthru
->cdblen
= cmd
->cmd_len
;
1036 epthru
->logdrv
= cmd
->device
->lun
;
1038 memcpy(epthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1040 /* Not sure about the direction */
1041 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
1043 switch(cmd
->cmnd
[0]) {
1046 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
1049 "scsi%d: scanning scsi channel %d [P%d] ",
1050 adapter
->host
->host_no
,
1051 cmd
->device
->channel
, channel
);
1052 printk("for physical devices.\n");
1054 adapter
->flag
|= (1L << cmd
->device
->channel
);
1058 epthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
1059 &epthru
->dataxferaddr
, &epthru
->dataxferlen
);
1067 __mega_runpendq(adapter_t
*adapter
)
1070 struct list_head
*pos
, *next
;
1072 /* Issue any pending commands to the card */
1073 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
1075 scb
= list_entry(pos
, scb_t
, list
);
1077 if( !(scb
->state
& SCB_ISSUED
) ) {
1079 if( issue_scb(adapter
, scb
) != 0 )
1090 * @adapter - pointer to our soft state
1091 * @scb - scsi control block
1093 * Post a command to the card if the mailbox is available, otherwise return
1094 * busy. We also take the scb from the pending list if the mailbox is
1098 issue_scb(adapter_t
*adapter
, scb_t
*scb
)
1100 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1101 volatile mbox_t
*mbox
= adapter
->mbox
;
1104 if(unlikely(mbox
->m_in
.busy
)) {
1108 } while( mbox
->m_in
.busy
&& (i
< max_mbox_busy_wait
) );
1110 if(mbox
->m_in
.busy
) return -1;
1113 /* Copy mailbox data into host structure */
1114 memcpy((char *)&mbox
->m_out
, (char *)scb
->raw_mbox
,
1115 sizeof(struct mbox_out
));
1117 mbox
->m_out
.cmdid
= scb
->idx
; /* Set cmdid */
1118 mbox
->m_in
.busy
= 1; /* Set busy */
1122 * Increment the pending queue counter
1124 atomic_inc(&adapter
->pend_cmds
);
1126 switch (mbox
->m_out
.cmd
) {
1127 case MEGA_MBOXCMD_LREAD64
:
1128 case MEGA_MBOXCMD_LWRITE64
:
1129 case MEGA_MBOXCMD_PASSTHRU64
:
1130 case MEGA_MBOXCMD_EXTPTHRU
:
1131 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1132 mbox64
->xfer_segment_hi
= 0;
1133 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1136 mbox64
->xfer_segment_lo
= 0;
1137 mbox64
->xfer_segment_hi
= 0;
1143 scb
->state
|= SCB_ISSUED
;
1145 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1146 mbox
->m_in
.poll
= 0;
1148 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1151 irq_enable(adapter
);
1152 issue_command(adapter
);
1159 * Wait until the controller's mailbox is available
1162 mega_busywait_mbox (adapter_t
*adapter
)
1164 if (adapter
->mbox
->m_in
.busy
)
1165 return __mega_busywait_mbox(adapter
);
1171 * @adapter - pointer to our soft state
1172 * @raw_mbox - the mailbox
1174 * Issue a scb in synchronous and non-interrupt mode
1177 issue_scb_block(adapter_t
*adapter
, u_char
*raw_mbox
)
1179 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1180 volatile mbox_t
*mbox
= adapter
->mbox
;
1183 /* Wait until mailbox is free */
1184 if(mega_busywait_mbox (adapter
))
1185 goto bug_blocked_mailbox
;
1187 /* Copy mailbox data into host structure */
1188 memcpy((char *) mbox
, raw_mbox
, sizeof(struct mbox_out
));
1189 mbox
->m_out
.cmdid
= 0xFE;
1190 mbox
->m_in
.busy
= 1;
1192 switch (raw_mbox
[0]) {
1193 case MEGA_MBOXCMD_LREAD64
:
1194 case MEGA_MBOXCMD_LWRITE64
:
1195 case MEGA_MBOXCMD_PASSTHRU64
:
1196 case MEGA_MBOXCMD_EXTPTHRU
:
1197 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1198 mbox64
->xfer_segment_hi
= 0;
1199 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1202 mbox64
->xfer_segment_lo
= 0;
1203 mbox64
->xfer_segment_hi
= 0;
1206 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1207 mbox
->m_in
.poll
= 0;
1209 mbox
->m_in
.numstatus
= 0xFF;
1210 mbox
->m_in
.status
= 0xFF;
1211 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1213 while((volatile u8
)mbox
->m_in
.numstatus
== 0xFF)
1216 mbox
->m_in
.numstatus
= 0xFF;
1218 while( (volatile u8
)mbox
->m_in
.poll
!= 0x77 )
1221 mbox
->m_in
.poll
= 0;
1222 mbox
->m_in
.ack
= 0x77;
1224 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x2);
1226 while(RDINDOOR(adapter
) & 0x2)
1230 irq_disable(adapter
);
1231 issue_command(adapter
);
1233 while (!((byte
= irq_state(adapter
)) & INTR_VALID
))
1236 set_irq_state(adapter
, byte
);
1237 irq_enable(adapter
);
1241 return mbox
->m_in
.status
;
1243 bug_blocked_mailbox
:
1244 printk(KERN_WARNING
"megaraid: Blocked mailbox......!!\n");
1251 * megaraid_isr_iomapped()
1253 * @devp - pointer to our soft state
1255 * Interrupt service routine for io-mapped controllers.
1256 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1257 * and service the completed commands.
1260 megaraid_isr_iomapped(int irq
, void *devp
)
1262 adapter_t
*adapter
= devp
;
1263 unsigned long flags
;
1266 u8 completed
[MAX_FIRMWARE_STATUS
];
1272 * loop till F/W has more commands for us to complete.
1274 spin_lock_irqsave(&adapter
->lock
, flags
);
1277 /* Check if a valid interrupt is pending */
1278 byte
= irq_state(adapter
);
1279 if( (byte
& VALID_INTR_BYTE
) == 0 ) {
1281 * No more pending commands
1285 set_irq_state(adapter
, byte
);
1287 while((nstatus
= (volatile u8
)adapter
->mbox
->m_in
.numstatus
)
1290 adapter
->mbox
->m_in
.numstatus
= 0xFF;
1292 status
= adapter
->mbox
->m_in
.status
;
1295 * decrement the pending queue counter
1297 atomic_sub(nstatus
, &adapter
->pend_cmds
);
1299 memcpy(completed
, (void *)adapter
->mbox
->m_in
.completed
,
1302 /* Acknowledge interrupt */
1305 mega_cmd_done(adapter
, completed
, nstatus
, status
);
1307 mega_rundoneq(adapter
);
1311 /* Loop through any pending requests */
1312 if(atomic_read(&adapter
->quiescent
) == 0) {
1313 mega_runpendq(adapter
);
1320 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1322 return IRQ_RETVAL(handled
);
1327 * megaraid_isr_memmapped()
1329 * @devp - pointer to our soft state
1331 * Interrupt service routine for memory-mapped controllers.
1332 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1333 * and service the completed commands.
1336 megaraid_isr_memmapped(int irq
, void *devp
)
1338 adapter_t
*adapter
= devp
;
1339 unsigned long flags
;
1343 u8 completed
[MAX_FIRMWARE_STATUS
];
1348 * loop till F/W has more commands for us to complete.
1350 spin_lock_irqsave(&adapter
->lock
, flags
);
1353 /* Check if a valid interrupt is pending */
1354 dword
= RDOUTDOOR(adapter
);
1355 if(dword
!= 0x10001234) {
1357 * No more pending commands
1361 WROUTDOOR(adapter
, 0x10001234);
1363 while((nstatus
= (volatile u8
)adapter
->mbox
->m_in
.numstatus
)
1367 adapter
->mbox
->m_in
.numstatus
= 0xFF;
1369 status
= adapter
->mbox
->m_in
.status
;
1372 * decrement the pending queue counter
1374 atomic_sub(nstatus
, &adapter
->pend_cmds
);
1376 memcpy(completed
, (void *)adapter
->mbox
->m_in
.completed
,
1379 /* Acknowledge interrupt */
1380 WRINDOOR(adapter
, 0x2);
1384 while( RDINDOOR(adapter
) & 0x02 )
1387 mega_cmd_done(adapter
, completed
, nstatus
, status
);
1389 mega_rundoneq(adapter
);
1391 /* Loop through any pending requests */
1392 if(atomic_read(&adapter
->quiescent
) == 0) {
1393 mega_runpendq(adapter
);
1400 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1402 return IRQ_RETVAL(handled
);
1406 * @adapter - pointer to our soft state
1407 * @completed - array of ids of completed commands
1408 * @nstatus - number of completed commands
1409 * @status - status of the last command completed
1411 * Complete the comamnds and call the scsi mid-layer callback hooks.
1414 mega_cmd_done(adapter_t
*adapter
, u8 completed
[], int nstatus
, int status
)
1416 mega_ext_passthru
*epthru
= NULL
;
1417 struct scatterlist
*sgl
;
1418 Scsi_Cmnd
*cmd
= NULL
;
1419 mega_passthru
*pthru
= NULL
;
1420 mbox_t
*mbox
= NULL
;
1428 * for all the commands completed, call the mid-layer callback routine
1431 for( i
= 0; i
< nstatus
; i
++ ) {
1433 cmdid
= completed
[i
];
1435 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1436 scb
= &adapter
->int_scb
;
1438 mbox
= (mbox_t
*)scb
->raw_mbox
;
1441 * Internal command interface do not fire the extended
1442 * passthru or 64-bit passthru
1448 scb
= &adapter
->scb_list
[cmdid
];
1451 * Make sure f/w has completed a valid command
1453 if( !(scb
->state
& SCB_ISSUED
) || scb
->cmd
== NULL
) {
1455 "megaraid: invalid command ");
1456 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1457 cmdid
, scb
->state
, scb
->cmd
);
1463 * Was a abort issued for this command
1465 if( scb
->state
& SCB_ABORT
) {
1468 "megaraid: aborted cmd %lx[%x] complete.\n",
1469 scb
->cmd
->serial_number
, scb
->idx
);
1471 scb
->cmd
->result
= (DID_ABORT
<< 16);
1473 list_add_tail(SCSI_LIST(scb
->cmd
),
1474 &adapter
->completed_list
);
1476 mega_free_scb(adapter
, scb
);
1482 * Was a reset issued for this command
1484 if( scb
->state
& SCB_RESET
) {
1487 "megaraid: reset cmd %lx[%x] complete.\n",
1488 scb
->cmd
->serial_number
, scb
->idx
);
1490 scb
->cmd
->result
= (DID_RESET
<< 16);
1492 list_add_tail(SCSI_LIST(scb
->cmd
),
1493 &adapter
->completed_list
);
1495 mega_free_scb (adapter
, scb
);
1502 epthru
= scb
->epthru
;
1503 mbox
= (mbox_t
*)scb
->raw_mbox
;
1508 int logdrv
= mbox
->m_out
.logdrv
;
1510 islogical
= adapter
->logdrv_chan
[cmd
->channel
];
1512 * Maintain an error counter for the logical drive.
1513 * Some application like SNMP agent need such
1516 if( status
&& islogical
&& (cmd
->cmnd
[0] == READ_6
||
1517 cmd
->cmnd
[0] == READ_10
||
1518 cmd
->cmnd
[0] == READ_12
)) {
1520 * Logical drive number increases by 0x80 when
1521 * a logical drive is deleted
1523 adapter
->rd_errors
[logdrv
%0x80]++;
1526 if( status
&& islogical
&& (cmd
->cmnd
[0] == WRITE_6
||
1527 cmd
->cmnd
[0] == WRITE_10
||
1528 cmd
->cmnd
[0] == WRITE_12
)) {
1530 * Logical drive number increases by 0x80 when
1531 * a logical drive is deleted
1533 adapter
->wr_errors
[logdrv
%0x80]++;
1541 * Do not return the presence of hard disk on the channel so,
1542 * inquiry sent, and returned data==hard disk or removable
1543 * hard disk and not logical, request should return failure! -
1546 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
1547 if( cmd
->cmnd
[0] == INQUIRY
&& !islogical
) {
1549 sgl
= scsi_sglist(cmd
);
1550 if( sg_page(sgl
) ) {
1551 c
= *(unsigned char *) sg_virt(&sgl
[0]);
1554 "megaraid: invalid sg.\n");
1558 if(IS_RAID_CH(adapter
, cmd
->device
->channel
) &&
1559 ((c
& 0x1F ) == TYPE_DISK
)) {
1564 /* clear result; otherwise, success returns corrupt value */
1567 /* Convert MegaRAID status to Linux error code */
1569 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1570 cmd
->result
|= (DID_OK
<< 16);
1573 case 0x02: /* ERROR_ABORTED, i.e.
1574 SCSI_STATUS_CHECK_CONDITION */
1576 /* set sense_buffer and result fields */
1577 if( mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU
||
1578 mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU64
) {
1580 memcpy(cmd
->sense_buffer
, pthru
->reqsensearea
,
1583 cmd
->result
= (DRIVER_SENSE
<< 24) |
1585 (CHECK_CONDITION
<< 1);
1588 if (mbox
->m_out
.cmd
== MEGA_MBOXCMD_EXTPTHRU
) {
1590 memcpy(cmd
->sense_buffer
,
1591 epthru
->reqsensearea
, 14);
1593 cmd
->result
= (DRIVER_SENSE
<< 24) |
1595 (CHECK_CONDITION
<< 1);
1597 cmd
->sense_buffer
[0] = 0x70;
1598 cmd
->sense_buffer
[2] = ABORTED_COMMAND
;
1599 cmd
->result
|= (CHECK_CONDITION
<< 1);
1604 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1606 cmd
->result
|= (DID_BUS_BUSY
<< 16) | status
;
1610 #if MEGA_HAVE_CLUSTERING
1612 * If TEST_UNIT_READY fails, we know
1613 * MEGA_RESERVATION_STATUS failed
1615 if( cmd
->cmnd
[0] == TEST_UNIT_READY
) {
1616 cmd
->result
|= (DID_ERROR
<< 16) |
1617 (RESERVATION_CONFLICT
<< 1);
1621 * Error code returned is 1 if Reserve or Release
1622 * failed or the input parameter is invalid
1625 (cmd
->cmnd
[0] == RESERVE
||
1626 cmd
->cmnd
[0] == RELEASE
) ) {
1628 cmd
->result
|= (DID_ERROR
<< 16) |
1629 (RESERVATION_CONFLICT
<< 1);
1633 cmd
->result
|= (DID_BAD_TARGET
<< 16)|status
;
1637 * Only free SCBs for the commands coming down from the
1638 * mid-layer, not for which were issued internally
1640 * For internal command, restore the status returned by the
1641 * firmware so that user can interpret it.
1643 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1644 cmd
->result
= status
;
1647 * Remove the internal command from the pending list
1649 list_del_init(&scb
->list
);
1650 scb
->state
= SCB_FREE
;
1653 mega_free_scb(adapter
, scb
);
1656 /* Add Scsi_Command to end of completed queue */
1657 list_add_tail(SCSI_LIST(cmd
), &adapter
->completed_list
);
1665 * Run through the list of completed requests and finish it
1668 mega_rundoneq (adapter_t
*adapter
)
1671 struct list_head
*pos
;
1673 list_for_each(pos
, &adapter
->completed_list
) {
1675 struct scsi_pointer
* spos
= (struct scsi_pointer
*)pos
;
1677 cmd
= list_entry(spos
, Scsi_Cmnd
, SCp
);
1678 cmd
->scsi_done(cmd
);
1681 INIT_LIST_HEAD(&adapter
->completed_list
);
1686 * Free a SCB structure
1687 * Note: We assume the scsi commands associated with this scb is not free yet.
1690 mega_free_scb(adapter_t
*adapter
, scb_t
*scb
)
1692 switch( scb
->dma_type
) {
1694 case MEGA_DMA_TYPE_NONE
:
1698 scsi_dma_unmap(scb
->cmd
);
1705 * Remove from the pending list
1707 list_del_init(&scb
->list
);
1709 /* Link the scb back into free list */
1710 scb
->state
= SCB_FREE
;
1713 list_add(&scb
->list
, &adapter
->free_list
);
1718 __mega_busywait_mbox (adapter_t
*adapter
)
1720 volatile mbox_t
*mbox
= adapter
->mbox
;
1723 for (counter
= 0; counter
< 10000; counter
++) {
1724 if (!mbox
->m_in
.busy
)
1729 return -1; /* give up after 1 second */
1733 * Copies data to SGLIST
1734 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1737 mega_build_sglist(adapter_t
*adapter
, scb_t
*scb
, u32
*buf
, u32
*len
)
1739 struct scatterlist
*sg
;
1747 * Copy Scatter-Gather list info into controller structure.
1749 * The number of sg elements returned must not exceed our limit
1751 sgcnt
= scsi_dma_map(cmd
);
1753 scb
->dma_type
= MEGA_SGLIST
;
1755 BUG_ON(sgcnt
> adapter
->sglen
|| sgcnt
< 0);
1759 if (scsi_sg_count(cmd
) == 1 && !adapter
->has_64bit_addr
) {
1760 sg
= scsi_sglist(cmd
);
1761 scb
->dma_h_bulkdata
= sg_dma_address(sg
);
1762 *buf
= (u32
)scb
->dma_h_bulkdata
;
1763 *len
= sg_dma_len(sg
);
1767 scsi_for_each_sg(cmd
, sg
, sgcnt
, idx
) {
1768 if (adapter
->has_64bit_addr
) {
1769 scb
->sgl64
[idx
].address
= sg_dma_address(sg
);
1770 *len
+= scb
->sgl64
[idx
].length
= sg_dma_len(sg
);
1772 scb
->sgl
[idx
].address
= sg_dma_address(sg
);
1773 *len
+= scb
->sgl
[idx
].length
= sg_dma_len(sg
);
1777 /* Reset pointer and length fields */
1778 *buf
= scb
->sgl_dma_addr
;
1780 /* Return count of SG requests */
1788 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1789 * Enquiry3 structures for later use
1792 mega_8_to_40ld(mraid_inquiry
*inquiry
, mega_inquiry3
*enquiry3
,
1793 mega_product_info
*product_info
)
1797 product_info
->max_commands
= inquiry
->adapter_info
.max_commands
;
1798 enquiry3
->rebuild_rate
= inquiry
->adapter_info
.rebuild_rate
;
1799 product_info
->nchannels
= inquiry
->adapter_info
.nchannels
;
1801 for (i
= 0; i
< 4; i
++) {
1802 product_info
->fw_version
[i
] =
1803 inquiry
->adapter_info
.fw_version
[i
];
1805 product_info
->bios_version
[i
] =
1806 inquiry
->adapter_info
.bios_version
[i
];
1808 enquiry3
->cache_flush_interval
=
1809 inquiry
->adapter_info
.cache_flush_interval
;
1811 product_info
->dram_size
= inquiry
->adapter_info
.dram_size
;
1813 enquiry3
->num_ldrv
= inquiry
->logdrv_info
.num_ldrv
;
1815 for (i
= 0; i
< MAX_LOGICAL_DRIVES_8LD
; i
++) {
1816 enquiry3
->ldrv_size
[i
] = inquiry
->logdrv_info
.ldrv_size
[i
];
1817 enquiry3
->ldrv_prop
[i
] = inquiry
->logdrv_info
.ldrv_prop
[i
];
1818 enquiry3
->ldrv_state
[i
] = inquiry
->logdrv_info
.ldrv_state
[i
];
1821 for (i
= 0; i
< (MAX_PHYSICAL_DRIVES
); i
++)
1822 enquiry3
->pdrv_state
[i
] = inquiry
->pdrv_info
.pdrv_state
[i
];
1826 mega_free_sgl(adapter_t
*adapter
)
1831 for(i
= 0; i
< adapter
->max_cmds
; i
++) {
1833 scb
= &adapter
->scb_list
[i
];
1836 pci_free_consistent(adapter
->dev
,
1837 sizeof(mega_sgl64
) * adapter
->sglen
,
1845 pci_free_consistent(adapter
->dev
, sizeof(mega_passthru
),
1846 scb
->pthru
, scb
->pthru_dma_addr
);
1852 pci_free_consistent(adapter
->dev
,
1853 sizeof(mega_ext_passthru
),
1854 scb
->epthru
, scb
->epthru_dma_addr
);
1864 * Get information about the card/driver
1867 megaraid_info(struct Scsi_Host
*host
)
1869 static char buffer
[512];
1872 adapter
= (adapter_t
*)host
->hostdata
;
1875 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1876 adapter
->fw_version
, adapter
->product_info
.max_commands
,
1877 adapter
->host
->max_id
, adapter
->host
->max_channel
,
1878 adapter
->host
->max_lun
);
1883 * Abort a previous SCSI request. Only commands on the pending list can be
1884 * aborted. All the commands issued to the F/W must complete.
1887 megaraid_abort(Scsi_Cmnd
*cmd
)
1892 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1894 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_ABORT
);
1897 * This is required here to complete any completed requests
1898 * to be communicated over to the mid layer.
1900 mega_rundoneq(adapter
);
1907 megaraid_reset(struct scsi_cmnd
*cmd
)
1913 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1915 #if MEGA_HAVE_CLUSTERING
1916 mc
.cmd
= MEGA_CLUSTER_CMD
;
1917 mc
.opcode
= MEGA_RESET_RESERVATIONS
;
1919 if( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
1921 "megaraid: reservation reset failed.\n");
1924 printk(KERN_INFO
"megaraid: reservation reset.\n");
1928 spin_lock_irq(&adapter
->lock
);
1930 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_RESET
);
1933 * This is required here to complete any completed requests
1934 * to be communicated over to the mid layer.
1936 mega_rundoneq(adapter
);
1937 spin_unlock_irq(&adapter
->lock
);
1943 * megaraid_abort_and_reset()
1944 * @adapter - megaraid soft state
1945 * @cmd - scsi command to be aborted or reset
1946 * @aor - abort or reset flag
1948 * Try to locate the scsi command in the pending queue. If found and is not
1949 * issued to the controller, abort/reset it. Otherwise return failure
1952 megaraid_abort_and_reset(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int aor
)
1954 struct list_head
*pos
, *next
;
1957 printk(KERN_WARNING
"megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
1958 (aor
== SCB_ABORT
)? "ABORTING":"RESET", cmd
->serial_number
,
1959 cmd
->cmnd
[0], cmd
->device
->channel
,
1960 cmd
->device
->id
, cmd
->device
->lun
);
1962 if(list_empty(&adapter
->pending_list
))
1965 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
1967 scb
= list_entry(pos
, scb_t
, list
);
1969 if (scb
->cmd
== cmd
) { /* Found command */
1974 * Check if this command has firmware ownership. If
1975 * yes, we cannot reset this command. Whenever f/w
1976 * completes this command, we will return appropriate
1979 if( scb
->state
& SCB_ISSUED
) {
1982 "megaraid: %s-%lx[%x], fw owner.\n",
1983 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
1984 cmd
->serial_number
, scb
->idx
);
1991 * Not yet issued! Remove from the pending
1995 "megaraid: %s-%lx[%x], driver owner.\n",
1996 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
1997 cmd
->serial_number
, scb
->idx
);
1999 mega_free_scb(adapter
, scb
);
2001 if( aor
== SCB_ABORT
) {
2002 cmd
->result
= (DID_ABORT
<< 16);
2005 cmd
->result
= (DID_RESET
<< 16);
2008 list_add_tail(SCSI_LIST(cmd
),
2009 &adapter
->completed_list
);
2020 make_local_pdev(adapter_t
*adapter
, struct pci_dev
**pdev
)
2022 *pdev
= alloc_pci_dev();
2024 if( *pdev
== NULL
) return -1;
2026 memcpy(*pdev
, adapter
->dev
, sizeof(struct pci_dev
));
2028 if( pci_set_dma_mask(*pdev
, DMA_BIT_MASK(32)) != 0 ) {
2037 free_local_pdev(struct pci_dev
*pdev
)
2043 * mega_allocate_inquiry()
2044 * @dma_handle - handle returned for dma address
2045 * @pdev - handle to pci device
2047 * allocates memory for inquiry structure
2049 static inline void *
2050 mega_allocate_inquiry(dma_addr_t
*dma_handle
, struct pci_dev
*pdev
)
2052 return pci_alloc_consistent(pdev
, sizeof(mega_inquiry3
), dma_handle
);
2057 mega_free_inquiry(void *inquiry
, dma_addr_t dma_handle
, struct pci_dev
*pdev
)
2059 pci_free_consistent(pdev
, sizeof(mega_inquiry3
), inquiry
, dma_handle
);
2063 #ifdef CONFIG_PROC_FS
2064 /* Following code handles /proc fs */
2066 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2067 S_IRUSR | S_IFREG, \
2068 controller_proc_dir_entry, \
2072 * mega_create_proc_entry()
2073 * @index - index in soft state array
2074 * @parent - parent node for this /proc entry
2076 * Creates /proc entries for our controllers.
2079 mega_create_proc_entry(int index
, struct proc_dir_entry
*parent
)
2081 struct proc_dir_entry
*controller_proc_dir_entry
= NULL
;
2082 u8 string
[64] = { 0 };
2083 adapter_t
*adapter
= hba_soft_state
[index
];
2085 sprintf(string
, "hba%d", adapter
->host
->host_no
);
2087 controller_proc_dir_entry
=
2088 adapter
->controller_proc_dir_entry
= proc_mkdir(string
, parent
);
2090 if(!controller_proc_dir_entry
) {
2091 printk(KERN_WARNING
"\nmegaraid: proc_mkdir failed\n");
2094 adapter
->proc_read
= CREATE_READ_PROC("config", proc_read_config
);
2095 adapter
->proc_stat
= CREATE_READ_PROC("stat", proc_read_stat
);
2096 adapter
->proc_mbox
= CREATE_READ_PROC("mailbox", proc_read_mbox
);
2097 #if MEGA_HAVE_ENH_PROC
2098 adapter
->proc_rr
= CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate
);
2099 adapter
->proc_battery
= CREATE_READ_PROC("battery-status",
2103 * Display each physical drive on its channel
2105 adapter
->proc_pdrvstat
[0] = CREATE_READ_PROC("diskdrives-ch0",
2107 adapter
->proc_pdrvstat
[1] = CREATE_READ_PROC("diskdrives-ch1",
2109 adapter
->proc_pdrvstat
[2] = CREATE_READ_PROC("diskdrives-ch2",
2111 adapter
->proc_pdrvstat
[3] = CREATE_READ_PROC("diskdrives-ch3",
2115 * Display a set of up to 10 logical drive through each of following
2118 adapter
->proc_rdrvstat
[0] = CREATE_READ_PROC("raiddrives-0-9",
2120 adapter
->proc_rdrvstat
[1] = CREATE_READ_PROC("raiddrives-10-19",
2122 adapter
->proc_rdrvstat
[2] = CREATE_READ_PROC("raiddrives-20-29",
2124 adapter
->proc_rdrvstat
[3] = CREATE_READ_PROC("raiddrives-30-39",
2131 * proc_read_config()
2132 * @page - buffer to write the data in
2133 * @start - where the actual data has been written in page
2134 * @offset - same meaning as the read system call
2135 * @count - same meaning as the read system call
2136 * @eof - set if no more data needs to be returned
2137 * @data - pointer to our soft state
2139 * Display configuration information about the controller.
2142 proc_read_config(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2146 adapter_t
*adapter
= (adapter_t
*)data
;
2149 len
+= sprintf(page
+len
, "%s", MEGARAID_VERSION
);
2151 if(adapter
->product_info
.product_name
[0])
2152 len
+= sprintf(page
+len
, "%s\n",
2153 adapter
->product_info
.product_name
);
2155 len
+= sprintf(page
+len
, "Controller Type: ");
2157 if( adapter
->flag
& BOARD_MEMMAP
) {
2158 len
+= sprintf(page
+len
,
2159 "438/466/467/471/493/518/520/531/532\n");
2162 len
+= sprintf(page
+len
,
2166 if(adapter
->flag
& BOARD_40LD
) {
2167 len
+= sprintf(page
+len
,
2168 "Controller Supports 40 Logical Drives\n");
2171 if(adapter
->flag
& BOARD_64BIT
) {
2172 len
+= sprintf(page
+len
,
2173 "Controller capable of 64-bit memory addressing\n");
2175 if( adapter
->has_64bit_addr
) {
2176 len
+= sprintf(page
+len
,
2177 "Controller using 64-bit memory addressing\n");
2180 len
+= sprintf(page
+len
,
2181 "Controller is not using 64-bit memory addressing\n");
2184 len
+= sprintf(page
+len
, "Base = %08lx, Irq = %d, ", adapter
->base
,
2185 adapter
->host
->irq
);
2187 len
+= sprintf(page
+len
, "Logical Drives = %d, Channels = %d\n",
2188 adapter
->numldrv
, adapter
->product_info
.nchannels
);
2190 len
+= sprintf(page
+len
, "Version =%s:%s, DRAM = %dMb\n",
2191 adapter
->fw_version
, adapter
->bios_version
,
2192 adapter
->product_info
.dram_size
);
2194 len
+= sprintf(page
+len
,
2195 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2196 adapter
->product_info
.max_commands
, adapter
->max_cmds
);
2198 len
+= sprintf(page
+len
, "support_ext_cdb = %d\n",
2199 adapter
->support_ext_cdb
);
2200 len
+= sprintf(page
+len
, "support_random_del = %d\n",
2201 adapter
->support_random_del
);
2202 len
+= sprintf(page
+len
, "boot_ldrv_enabled = %d\n",
2203 adapter
->boot_ldrv_enabled
);
2204 len
+= sprintf(page
+len
, "boot_ldrv = %d\n",
2205 adapter
->boot_ldrv
);
2206 len
+= sprintf(page
+len
, "boot_pdrv_enabled = %d\n",
2207 adapter
->boot_pdrv_enabled
);
2208 len
+= sprintf(page
+len
, "boot_pdrv_ch = %d\n",
2209 adapter
->boot_pdrv_ch
);
2210 len
+= sprintf(page
+len
, "boot_pdrv_tgt = %d\n",
2211 adapter
->boot_pdrv_tgt
);
2212 len
+= sprintf(page
+len
, "quiescent = %d\n",
2213 atomic_read(&adapter
->quiescent
));
2214 len
+= sprintf(page
+len
, "has_cluster = %d\n",
2215 adapter
->has_cluster
);
2217 len
+= sprintf(page
+len
, "\nModule Parameters:\n");
2218 len
+= sprintf(page
+len
, "max_cmd_per_lun = %d\n",
2220 len
+= sprintf(page
+len
, "max_sectors_per_io = %d\n",
2221 max_sectors_per_io
);
2232 * @page - buffer to write the data in
2233 * @start - where the actual data has been written in page
2234 * @offset - same meaning as the read system call
2235 * @count - same meaning as the read system call
2236 * @eof - set if no more data needs to be returned
2237 * @data - pointer to our soft state
2239 * Diaplay statistical information about the I/O activity.
2242 proc_read_stat(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2249 i
= 0; /* avoid compilation warnings */
2251 adapter
= (adapter_t
*)data
;
2253 len
= sprintf(page
, "Statistical Information for this controller\n");
2254 len
+= sprintf(page
+len
, "pend_cmds = %d\n",
2255 atomic_read(&adapter
->pend_cmds
));
2257 for(i
= 0; i
< adapter
->numldrv
; i
++) {
2258 len
+= sprintf(page
+len
, "Logical Drive %d:\n", i
);
2260 len
+= sprintf(page
+len
,
2261 "\tReads Issued = %lu, Writes Issued = %lu\n",
2262 adapter
->nreads
[i
], adapter
->nwrites
[i
]);
2264 len
+= sprintf(page
+len
,
2265 "\tSectors Read = %lu, Sectors Written = %lu\n",
2266 adapter
->nreadblocks
[i
], adapter
->nwriteblocks
[i
]);
2268 len
+= sprintf(page
+len
,
2269 "\tRead errors = %lu, Write errors = %lu\n\n",
2270 adapter
->rd_errors
[i
], adapter
->wr_errors
[i
]);
2273 len
+= sprintf(page
+len
,
2274 "IO and error counters not compiled in driver.\n");
2285 * @page - buffer to write the data in
2286 * @start - where the actual data has been written in page
2287 * @offset - same meaning as the read system call
2288 * @count - same meaning as the read system call
2289 * @eof - set if no more data needs to be returned
2290 * @data - pointer to our soft state
2292 * Display mailbox information for the last command issued. This information
2293 * is good for debugging.
2296 proc_read_mbox(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2300 adapter_t
*adapter
= (adapter_t
*)data
;
2301 volatile mbox_t
*mbox
= adapter
->mbox
;
2304 len
= sprintf(page
, "Contents of Mail Box Structure\n");
2305 len
+= sprintf(page
+len
, " Fw Command = 0x%02x\n",
2307 len
+= sprintf(page
+len
, " Cmd Sequence = 0x%02x\n",
2309 len
+= sprintf(page
+len
, " No of Sectors= %04d\n",
2310 mbox
->m_out
.numsectors
);
2311 len
+= sprintf(page
+len
, " LBA = 0x%02x\n",
2313 len
+= sprintf(page
+len
, " DTA = 0x%08x\n",
2314 mbox
->m_out
.xferaddr
);
2315 len
+= sprintf(page
+len
, " Logical Drive= 0x%02x\n",
2316 mbox
->m_out
.logdrv
);
2317 len
+= sprintf(page
+len
, " No of SG Elmt= 0x%02x\n",
2318 mbox
->m_out
.numsgelements
);
2319 len
+= sprintf(page
+len
, " Busy = %01x\n",
2321 len
+= sprintf(page
+len
, " Status = 0x%02x\n",
2331 * proc_rebuild_rate()
2332 * @page - buffer to write the data in
2333 * @start - where the actual data has been written in page
2334 * @offset - same meaning as the read system call
2335 * @count - same meaning as the read system call
2336 * @eof - set if no more data needs to be returned
2337 * @data - pointer to our soft state
2339 * Display current rebuild rate
2342 proc_rebuild_rate(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2345 adapter_t
*adapter
= (adapter_t
*)data
;
2346 dma_addr_t dma_handle
;
2348 struct pci_dev
*pdev
;
2351 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2356 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2357 free_local_pdev(pdev
);
2362 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2364 len
= sprintf(page
, "Adapter inquiry failed.\n");
2366 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2368 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2370 free_local_pdev(pdev
);
2377 if( adapter
->flag
& BOARD_40LD
) {
2378 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2379 ((mega_inquiry3
*)inquiry
)->rebuild_rate
);
2382 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2383 ((mraid_ext_inquiry
*)
2384 inquiry
)->raid_inq
.adapter_info
.rebuild_rate
);
2388 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2390 free_local_pdev(pdev
);
2400 * @page - buffer to write the data in
2401 * @start - where the actual data has been written in page
2402 * @offset - same meaning as the read system call
2403 * @count - same meaning as the read system call
2404 * @eof - set if no more data needs to be returned
2405 * @data - pointer to our soft state
2407 * Display information about the battery module on the controller.
2410 proc_battery(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2413 adapter_t
*adapter
= (adapter_t
*)data
;
2414 dma_addr_t dma_handle
;
2416 struct pci_dev
*pdev
;
2417 u8 battery_status
= 0;
2421 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2426 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2427 free_local_pdev(pdev
);
2432 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2434 len
= sprintf(page
, "Adapter inquiry failed.\n");
2436 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2438 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2440 free_local_pdev(pdev
);
2447 if( adapter
->flag
& BOARD_40LD
) {
2448 battery_status
= ((mega_inquiry3
*)inquiry
)->battery_status
;
2451 battery_status
= ((mraid_ext_inquiry
*)inquiry
)->
2452 raid_inq
.adapter_info
.battery_status
;
2456 * Decode the battery status
2458 sprintf(str
, "Battery Status:[%d]", battery_status
);
2460 if(battery_status
== MEGA_BATT_CHARGE_DONE
)
2461 strcat(str
, " Charge Done");
2463 if(battery_status
& MEGA_BATT_MODULE_MISSING
)
2464 strcat(str
, " Module Missing");
2466 if(battery_status
& MEGA_BATT_LOW_VOLTAGE
)
2467 strcat(str
, " Low Voltage");
2469 if(battery_status
& MEGA_BATT_TEMP_HIGH
)
2470 strcat(str
, " Temperature High");
2472 if(battery_status
& MEGA_BATT_PACK_MISSING
)
2473 strcat(str
, " Pack Missing");
2475 if(battery_status
& MEGA_BATT_CHARGE_INPROG
)
2476 strcat(str
, " Charge In-progress");
2478 if(battery_status
& MEGA_BATT_CHARGE_FAIL
)
2479 strcat(str
, " Charge Fail");
2481 if(battery_status
& MEGA_BATT_CYCLES_EXCEEDED
)
2482 strcat(str
, " Cycles Exceeded");
2484 len
= sprintf(page
, "%s\n", str
);
2487 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2489 free_local_pdev(pdev
);
2499 * @page - buffer to write the data in
2500 * @start - where the actual data has been written in page
2501 * @offset - same meaning as the read system call
2502 * @count - same meaning as the read system call
2503 * @eof - set if no more data needs to be returned
2504 * @data - pointer to our soft state
2506 * Display information about the physical drives on physical channel 0.
2509 proc_pdrv_ch0(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2512 adapter_t
*adapter
= (adapter_t
*)data
;
2516 return (proc_pdrv(adapter
, page
, 0));
2522 * @page - buffer to write the data in
2523 * @start - where the actual data has been written in page
2524 * @offset - same meaning as the read system call
2525 * @count - same meaning as the read system call
2526 * @eof - set if no more data needs to be returned
2527 * @data - pointer to our soft state
2529 * Display information about the physical drives on physical channel 1.
2532 proc_pdrv_ch1(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2535 adapter_t
*adapter
= (adapter_t
*)data
;
2539 return (proc_pdrv(adapter
, page
, 1));
2545 * @page - buffer to write the data in
2546 * @start - where the actual data has been written in page
2547 * @offset - same meaning as the read system call
2548 * @count - same meaning as the read system call
2549 * @eof - set if no more data needs to be returned
2550 * @data - pointer to our soft state
2552 * Display information about the physical drives on physical channel 2.
2555 proc_pdrv_ch2(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2558 adapter_t
*adapter
= (adapter_t
*)data
;
2562 return (proc_pdrv(adapter
, page
, 2));
2568 * @page - buffer to write the data in
2569 * @start - where the actual data has been written in page
2570 * @offset - same meaning as the read system call
2571 * @count - same meaning as the read system call
2572 * @eof - set if no more data needs to be returned
2573 * @data - pointer to our soft state
2575 * Display information about the physical drives on physical channel 3.
2578 proc_pdrv_ch3(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2581 adapter_t
*adapter
= (adapter_t
*)data
;
2585 return (proc_pdrv(adapter
, page
, 3));
2591 * @page - buffer to write the data in
2592 * @adapter - pointer to our soft state
2594 * Display information about the physical drives.
2597 proc_pdrv(adapter_t
*adapter
, char *page
, int channel
)
2599 dma_addr_t dma_handle
;
2601 dma_addr_t scsi_inq_dma_handle
;
2603 struct pci_dev
*pdev
;
2612 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2616 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2620 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2621 len
= sprintf(page
, "Adapter inquiry failed.\n");
2623 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2629 scsi_inq
= pci_alloc_consistent(pdev
, 256, &scsi_inq_dma_handle
);
2631 if( scsi_inq
== NULL
) {
2632 len
= sprintf(page
, "memory not available for scsi inq.\n");
2637 if( adapter
->flag
& BOARD_40LD
) {
2638 pdrv_state
= ((mega_inquiry3
*)inquiry
)->pdrv_state
;
2641 pdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2642 raid_inq
.pdrv_info
.pdrv_state
;
2645 max_channels
= adapter
->product_info
.nchannels
;
2647 if( channel
>= max_channels
) {
2651 for( tgt
= 0; tgt
<= MAX_TARGET
; tgt
++ ) {
2653 i
= channel
*16 + tgt
;
2655 state
= *(pdrv_state
+ i
);
2657 switch( state
& 0x0F ) {
2661 "Channel:%2d Id:%2d State: Online",
2667 "Channel:%2d Id:%2d State: Failed",
2673 "Channel:%2d Id:%2d State: Rebuild",
2679 "Channel:%2d Id:%2d State: Hot spare",
2685 "Channel:%2d Id:%2d State: Un-configured",
2692 * This interface displays inquiries for disk drives
2693 * only. Inquries for logical drives and non-disk
2694 * devices are available through /proc/scsi/scsi
2696 memset(scsi_inq
, 0, 256);
2697 if( mega_internal_dev_inquiry(adapter
, channel
, tgt
,
2698 scsi_inq_dma_handle
) ||
2699 (scsi_inq
[0] & 0x1F) != TYPE_DISK
) {
2704 * Check for overflow. We print less than 240
2705 * characters for inquiry
2707 if( (len
+ 240) >= PAGE_SIZE
) break;
2709 len
+= sprintf(page
+len
, "%s.\n", str
);
2711 len
+= mega_print_inquiry(page
+len
, scsi_inq
);
2715 pci_free_consistent(pdev
, 256, scsi_inq
, scsi_inq_dma_handle
);
2717 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2719 free_local_pdev(pdev
);
2726 * Display scsi inquiry
2729 mega_print_inquiry(char *page
, char *scsi_inq
)
2734 len
= sprintf(page
, " Vendor: ");
2735 for( i
= 8; i
< 16; i
++ ) {
2736 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2739 len
+= sprintf(page
+len
, " Model: ");
2741 for( i
= 16; i
< 32; i
++ ) {
2742 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2745 len
+= sprintf(page
+len
, " Rev: ");
2747 for( i
= 32; i
< 36; i
++ ) {
2748 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2751 len
+= sprintf(page
+len
, "\n");
2753 i
= scsi_inq
[0] & 0x1f;
2755 len
+= sprintf(page
+len
, " Type: %s ", scsi_device_type(i
));
2757 len
+= sprintf(page
+len
,
2758 " ANSI SCSI revision: %02x", scsi_inq
[2] & 0x07);
2760 if( (scsi_inq
[2] & 0x07) == 1 && (scsi_inq
[3] & 0x0f) == 1 )
2761 len
+= sprintf(page
+len
, " CCS\n");
2763 len
+= sprintf(page
+len
, "\n");
2771 * @page - buffer to write the data in
2772 * @start - where the actual data has been written in page
2773 * @offset - same meaning as the read system call
2774 * @count - same meaning as the read system call
2775 * @eof - set if no more data needs to be returned
2776 * @data - pointer to our soft state
2778 * Display real time information about the logical drives 0 through 9.
2781 proc_rdrv_10(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2784 adapter_t
*adapter
= (adapter_t
*)data
;
2788 return (proc_rdrv(adapter
, page
, 0, 9));
2794 * @page - buffer to write the data in
2795 * @start - where the actual data has been written in page
2796 * @offset - same meaning as the read system call
2797 * @count - same meaning as the read system call
2798 * @eof - set if no more data needs to be returned
2799 * @data - pointer to our soft state
2801 * Display real time information about the logical drives 0 through 9.
2804 proc_rdrv_20(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2807 adapter_t
*adapter
= (adapter_t
*)data
;
2811 return (proc_rdrv(adapter
, page
, 10, 19));
2817 * @page - buffer to write the data in
2818 * @start - where the actual data has been written in page
2819 * @offset - same meaning as the read system call
2820 * @count - same meaning as the read system call
2821 * @eof - set if no more data needs to be returned
2822 * @data - pointer to our soft state
2824 * Display real time information about the logical drives 0 through 9.
2827 proc_rdrv_30(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2830 adapter_t
*adapter
= (adapter_t
*)data
;
2834 return (proc_rdrv(adapter
, page
, 20, 29));
2840 * @page - buffer to write the data in
2841 * @start - where the actual data has been written in page
2842 * @offset - same meaning as the read system call
2843 * @count - same meaning as the read system call
2844 * @eof - set if no more data needs to be returned
2845 * @data - pointer to our soft state
2847 * Display real time information about the logical drives 0 through 9.
2850 proc_rdrv_40(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2853 adapter_t
*adapter
= (adapter_t
*)data
;
2857 return (proc_rdrv(adapter
, page
, 30, 39));
2863 * @page - buffer to write the data in
2864 * @adapter - pointer to our soft state
2865 * @start - starting logical drive to display
2866 * @end - ending logical drive to display
2868 * We do not print the inquiry information since its already available through
2869 * /proc/scsi/scsi interface
2872 proc_rdrv(adapter_t
*adapter
, char *page
, int start
, int end
)
2874 dma_addr_t dma_handle
;
2875 logdrv_param
*lparam
;
2878 dma_addr_t disk_array_dma_handle
;
2880 struct pci_dev
*pdev
;
2887 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2891 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2892 free_local_pdev(pdev
);
2896 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2898 len
= sprintf(page
, "Adapter inquiry failed.\n");
2900 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2902 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2904 free_local_pdev(pdev
);
2909 memset(&mc
, 0, sizeof(megacmd_t
));
2911 if( adapter
->flag
& BOARD_40LD
) {
2912 array_sz
= sizeof(disk_array_40ld
);
2914 rdrv_state
= ((mega_inquiry3
*)inquiry
)->ldrv_state
;
2916 num_ldrv
= ((mega_inquiry3
*)inquiry
)->num_ldrv
;
2919 array_sz
= sizeof(disk_array_8ld
);
2921 rdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2922 raid_inq
.logdrv_info
.ldrv_state
;
2924 num_ldrv
= ((mraid_ext_inquiry
*)inquiry
)->
2925 raid_inq
.logdrv_info
.num_ldrv
;
2928 disk_array
= pci_alloc_consistent(pdev
, array_sz
,
2929 &disk_array_dma_handle
);
2931 if( disk_array
== NULL
) {
2932 len
= sprintf(page
, "memory not available.\n");
2934 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2936 free_local_pdev(pdev
);
2941 mc
.xferaddr
= (u32
)disk_array_dma_handle
;
2943 if( adapter
->flag
& BOARD_40LD
) {
2944 mc
.cmd
= FC_NEW_CONFIG
;
2945 mc
.opcode
= OP_DCMD_READ_CONFIG
;
2947 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
2949 len
= sprintf(page
, "40LD read config failed.\n");
2951 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2953 pci_free_consistent(pdev
, array_sz
, disk_array
,
2954 disk_array_dma_handle
);
2956 free_local_pdev(pdev
);
2963 mc
.cmd
= NEW_READ_CONFIG_8LD
;
2965 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
2967 mc
.cmd
= READ_CONFIG_8LD
;
2969 if( mega_internal_command(adapter
, &mc
,
2973 "8LD read config failed.\n");
2975 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2977 pci_free_consistent(pdev
, array_sz
,
2979 disk_array_dma_handle
);
2981 free_local_pdev(pdev
);
2988 for( i
= start
; i
< ( (end
+1 < num_ldrv
) ? end
+1 : num_ldrv
); i
++ ) {
2990 if( adapter
->flag
& BOARD_40LD
) {
2992 &((disk_array_40ld
*)disk_array
)->ldrv
[i
].lparam
;
2996 &((disk_array_8ld
*)disk_array
)->ldrv
[i
].lparam
;
3000 * Check for overflow. We print less than 240 characters for
3001 * information about each logical drive.
3003 if( (len
+ 240) >= PAGE_SIZE
) break;
3005 len
+= sprintf(page
+len
, "Logical drive:%2d:, ", i
);
3007 switch( rdrv_state
[i
] & 0x0F ) {
3009 len
+= sprintf(page
+len
, "state: offline");
3013 len
+= sprintf(page
+len
, "state: degraded");
3017 len
+= sprintf(page
+len
, "state: optimal");
3021 len
+= sprintf(page
+len
, "state: deleted");
3025 len
+= sprintf(page
+len
, "state: unknown");
3030 * Check if check consistency or initialization is going on
3031 * for this logical drive.
3033 if( (rdrv_state
[i
] & 0xF0) == 0x20 ) {
3034 len
+= sprintf(page
+len
,
3035 ", check-consistency in progress");
3037 else if( (rdrv_state
[i
] & 0xF0) == 0x10 ) {
3038 len
+= sprintf(page
+len
,
3039 ", initialization in progress");
3042 len
+= sprintf(page
+len
, "\n");
3044 len
+= sprintf(page
+len
, "Span depth:%3d, ",
3045 lparam
->span_depth
);
3047 len
+= sprintf(page
+len
, "RAID level:%3d, ",
3050 len
+= sprintf(page
+len
, "Stripe size:%3d, ",
3051 lparam
->stripe_sz
? lparam
->stripe_sz
/2: 128);
3053 len
+= sprintf(page
+len
, "Row size:%3d\n",
3057 len
+= sprintf(page
+len
, "Read Policy: ");
3059 switch(lparam
->read_ahead
) {
3062 len
+= sprintf(page
+len
, "No read ahead, ");
3066 len
+= sprintf(page
+len
, "Read ahead, ");
3069 case ADAP_READ_AHEAD
:
3070 len
+= sprintf(page
+len
, "Adaptive, ");
3075 len
+= sprintf(page
+len
, "Write Policy: ");
3077 switch(lparam
->write_mode
) {
3079 case WRMODE_WRITE_THRU
:
3080 len
+= sprintf(page
+len
, "Write thru, ");
3083 case WRMODE_WRITE_BACK
:
3084 len
+= sprintf(page
+len
, "Write back, ");
3088 len
+= sprintf(page
+len
, "Cache Policy: ");
3090 switch(lparam
->direct_io
) {
3093 len
+= sprintf(page
+len
, "Cached IO\n\n");
3097 len
+= sprintf(page
+len
, "Direct IO\n\n");
3102 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3104 pci_free_consistent(pdev
, array_sz
, disk_array
,
3105 disk_array_dma_handle
);
3107 free_local_pdev(pdev
);
3112 static inline void mega_create_proc_entry(int index
, struct proc_dir_entry
*parent
)
3119 * megaraid_biosparam()
3121 * Return the disk geometry for a particular disk
3124 megaraid_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
3125 sector_t capacity
, int geom
[])
3134 /* Get pointer to host config structure */
3135 adapter
= (adapter_t
*)sdev
->host
->hostdata
;
3137 if (IS_RAID_CH(adapter
, sdev
->channel
)) {
3138 /* Default heads (64) & sectors (32) */
3141 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3144 * Handle extended translation size for logical drives
3147 if ((ulong
)capacity
>= 0x200000) {
3150 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3156 geom
[2] = cylinders
;
3159 bh
= scsi_bios_ptable(bdev
);
3162 rval
= scsi_partsize(bh
, capacity
,
3163 &geom
[2], &geom
[0], &geom
[1]);
3170 "megaraid: invalid partition on this disk on channel %d\n",
3173 /* Default heads (64) & sectors (32) */
3176 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3178 /* Handle extended translation size for logical drives > 1Gb */
3179 if ((ulong
)capacity
>= 0x200000) {
3182 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3188 geom
[2] = cylinders
;
3196 * @adapter - pointer to our soft state
3198 * Allocate memory for the various pointers in the scb structures:
3199 * scatter-gather list pointer, passthru and extended passthru structure
3203 mega_init_scb(adapter_t
*adapter
)
3208 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3210 scb
= &adapter
->scb_list
[i
];
3218 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3220 scb
= &adapter
->scb_list
[i
];
3224 scb
->sgl64
= pci_alloc_consistent(adapter
->dev
,
3225 sizeof(mega_sgl64
) * adapter
->sglen
,
3226 &scb
->sgl_dma_addr
);
3228 scb
->sgl
= (mega_sglist
*)scb
->sgl64
;
3231 printk(KERN_WARNING
"RAID: Can't allocate sglist.\n");
3232 mega_free_sgl(adapter
);
3236 scb
->pthru
= pci_alloc_consistent(adapter
->dev
,
3237 sizeof(mega_passthru
),
3238 &scb
->pthru_dma_addr
);
3241 printk(KERN_WARNING
"RAID: Can't allocate passthru.\n");
3242 mega_free_sgl(adapter
);
3246 scb
->epthru
= pci_alloc_consistent(adapter
->dev
,
3247 sizeof(mega_ext_passthru
),
3248 &scb
->epthru_dma_addr
);
3250 if( !scb
->epthru
) {
3252 "Can't allocate extended passthru.\n");
3253 mega_free_sgl(adapter
);
3258 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
3262 * lock not required since we are loading the driver, so no
3263 * commands possible right now.
3265 scb
->state
= SCB_FREE
;
3267 list_add(&scb
->list
, &adapter
->free_list
);
3279 * Routines for the character/ioctl interface to the driver. Find out if this
3283 megadev_open (struct inode
*inode
, struct file
*filep
)
3285 cycle_kernel_lock();
3287 * Only allow superuser to access private ioctl interface
3289 if( !capable(CAP_SYS_ADMIN
) ) return -EACCES
;
3297 * @inode - Our device inode
3299 * @cmd - ioctl command
3300 * @arg - user buffer
3302 * ioctl entry point for our private ioctl interface. We move the data in from
3303 * the user space, prepare the command (if necessary, convert the old MIMD
3304 * ioctl to new ioctl command), and issue a synchronous command to the
3308 megadev_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
)
3314 mega_passthru __user
*upthru
; /* user address for passthru */
3315 mega_passthru
*pthru
; /* copy user passthru here */
3316 dma_addr_t pthru_dma_hndl
;
3317 void *data
= NULL
; /* data to be transferred */
3318 dma_addr_t data_dma_hndl
; /* dma handle for data xfer area */
3320 megastat_t __user
*ustats
;
3323 struct pci_dev
*pdev
;
3325 ustats
= NULL
; /* avoid compilation warnings */
3329 * Make sure only USCSICMD are issued through this interface.
3330 * MIMD application would still fire different command.
3332 if( (_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
) ) {
3337 * Check and convert a possible MIMD command to NIT command.
3338 * mega_m_to_n() copies the data from the user space, so we do not
3339 * have to do it here.
3340 * NOTE: We will need some user address to copyout the data, therefore
3341 * the inteface layer will also provide us with the required user
3344 memset(&uioc
, 0, sizeof(nitioctl_t
));
3345 if( (rval
= mega_m_to_n( (void __user
*)arg
, &uioc
)) != 0 )
3349 switch( uioc
.opcode
) {
3351 case GET_DRIVER_VER
:
3352 if( put_user(driver_ver
, (u32 __user
*)uioc
.uioc_uaddr
) )
3358 if( put_user(hba_count
, (u32 __user
*)uioc
.uioc_uaddr
) )
3362 * Shucks. MIMD interface returns a positive value for number
3363 * of adapters. TODO: Change it to return 0 when there is no
3364 * applicatio using mimd interface.
3373 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3376 if( copy_to_user(uioc
.uioc_uaddr
, mcontroller
+adapno
,
3377 sizeof(struct mcontroller
)) )
3387 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3390 adapter
= hba_soft_state
[adapno
];
3392 ustats
= uioc
.uioc_uaddr
;
3394 if( copy_from_user(&num_ldrv
, &ustats
->num_ldrv
, sizeof(int)) )
3398 * Check for the validity of the logical drive number
3400 if( num_ldrv
>= MAX_LOGICAL_DRIVES_40LD
) return -EINVAL
;
3402 if( copy_to_user(ustats
->nreads
, adapter
->nreads
,
3403 num_ldrv
*sizeof(u32
)) )
3406 if( copy_to_user(ustats
->nreadblocks
, adapter
->nreadblocks
,
3407 num_ldrv
*sizeof(u32
)) )
3410 if( copy_to_user(ustats
->nwrites
, adapter
->nwrites
,
3411 num_ldrv
*sizeof(u32
)) )
3414 if( copy_to_user(ustats
->nwriteblocks
, adapter
->nwriteblocks
,
3415 num_ldrv
*sizeof(u32
)) )
3418 if( copy_to_user(ustats
->rd_errors
, adapter
->rd_errors
,
3419 num_ldrv
*sizeof(u32
)) )
3422 if( copy_to_user(ustats
->wr_errors
, adapter
->wr_errors
,
3423 num_ldrv
*sizeof(u32
)) )
3434 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3437 adapter
= hba_soft_state
[adapno
];
3440 * Deletion of logical drive is a special case. The adapter
3441 * should be quiescent before this command is issued.
3443 if( uioc
.uioc_rmbox
[0] == FC_DEL_LOGDRV
&&
3444 uioc
.uioc_rmbox
[2] == OP_DEL_LOGDRV
) {
3447 * Do we support this feature
3449 if( !adapter
->support_random_del
) {
3450 printk(KERN_WARNING
"megaraid: logdrv ");
3451 printk("delete on non-supporting F/W.\n");
3456 rval
= mega_del_logdrv( adapter
, uioc
.uioc_rmbox
[3] );
3459 memset(&mc
, 0, sizeof(megacmd_t
));
3463 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3469 * This interface only support the regular passthru commands.
3470 * Reject extended passthru and 64-bit passthru
3472 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU64
||
3473 uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_EXTPTHRU
) {
3475 printk(KERN_WARNING
"megaraid: rejected passthru.\n");
3481 * For all internal commands, the buffer must be allocated in
3482 * <4GB address range
3484 if( make_local_pdev(adapter
, &pdev
) != 0 )
3487 /* Is it a passthru command or a DCMD */
3488 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU
) {
3489 /* Passthru commands */
3491 pthru
= pci_alloc_consistent(pdev
,
3492 sizeof(mega_passthru
),
3495 if( pthru
== NULL
) {
3496 free_local_pdev(pdev
);
3501 * The user passthru structure
3503 upthru
= (mega_passthru __user
*)(unsigned long)MBOX(uioc
)->xferaddr
;
3506 * Copy in the user passthru here.
3508 if( copy_from_user(pthru
, upthru
,
3509 sizeof(mega_passthru
)) ) {
3511 pci_free_consistent(pdev
,
3512 sizeof(mega_passthru
), pthru
,
3515 free_local_pdev(pdev
);
3521 * Is there a data transfer
3523 if( pthru
->dataxferlen
) {
3524 data
= pci_alloc_consistent(pdev
,
3528 if( data
== NULL
) {
3529 pci_free_consistent(pdev
,
3530 sizeof(mega_passthru
),
3534 free_local_pdev(pdev
);
3540 * Save the user address and point the kernel
3541 * address at just allocated memory
3543 uxferaddr
= pthru
->dataxferaddr
;
3544 pthru
->dataxferaddr
= data_dma_hndl
;
3549 * Is data coming down-stream
3551 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3555 if( copy_from_user(data
, (char __user
*)(unsigned long) uxferaddr
,
3556 pthru
->dataxferlen
) ) {
3558 goto freemem_and_return
;
3562 memset(&mc
, 0, sizeof(megacmd_t
));
3564 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
3565 mc
.xferaddr
= (u32
)pthru_dma_hndl
;
3570 mega_internal_command(adapter
, &mc
, pthru
);
3572 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3574 if( rval
) goto freemem_and_return
;
3578 * Is data going up-stream
3580 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3581 if( copy_to_user((char __user
*)(unsigned long) uxferaddr
, data
,
3582 pthru
->dataxferlen
) ) {
3588 * Send the request sense data also, irrespective of
3589 * whether the user has asked for it or not.
3591 if (copy_to_user(upthru
->reqsensearea
,
3592 pthru
->reqsensearea
, 14))
3596 if( pthru
->dataxferlen
) {
3597 pci_free_consistent(pdev
,
3598 pthru
->dataxferlen
, data
,
3602 pci_free_consistent(pdev
, sizeof(mega_passthru
),
3603 pthru
, pthru_dma_hndl
);
3605 free_local_pdev(pdev
);
3613 * Is there a data transfer
3615 if( uioc
.xferlen
) {
3616 data
= pci_alloc_consistent(pdev
,
3617 uioc
.xferlen
, &data_dma_hndl
);
3619 if( data
== NULL
) {
3620 free_local_pdev(pdev
);
3624 uxferaddr
= MBOX(uioc
)->xferaddr
;
3628 * Is data coming down-stream
3630 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3634 if( copy_from_user(data
, (char __user
*)(unsigned long) uxferaddr
,
3637 pci_free_consistent(pdev
,
3639 data
, data_dma_hndl
);
3641 free_local_pdev(pdev
);
3647 memcpy(&mc
, MBOX(uioc
), sizeof(megacmd_t
));
3649 mc
.xferaddr
= (u32
)data_dma_hndl
;
3654 mega_internal_command(adapter
, &mc
, NULL
);
3656 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3659 if( uioc
.xferlen
) {
3660 pci_free_consistent(pdev
,
3665 free_local_pdev(pdev
);
3671 * Is data going up-stream
3673 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3674 if( copy_to_user((char __user
*)(unsigned long) uxferaddr
, data
,
3681 if( uioc
.xferlen
) {
3682 pci_free_consistent(pdev
,
3687 free_local_pdev(pdev
);
3700 megadev_unlocked_ioctl(struct file
*filep
, unsigned int cmd
, unsigned long arg
)
3705 ret
= megadev_ioctl(filep
, cmd
, arg
);
3713 * @arg - user address
3714 * @uioc - new ioctl structure
3716 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3719 * Converts the older mimd ioctl structure to newer NIT structure
3722 mega_m_to_n(void __user
*arg
, nitioctl_t
*uioc
)
3724 struct uioctl_t uioc_mimd
;
3725 char signature
[8] = {0};
3731 * check is the application conforms to NIT. We do not have to do much
3733 * We exploit the fact that the signature is stored in the very
3734 * begining of the structure.
3737 if( copy_from_user(signature
, arg
, 7) )
3740 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3743 * NOTE NOTE: The nit ioctl is still under flux because of
3744 * change of mailbox definition, in HPE. No applications yet
3745 * use this interface and let's not have applications use this
3746 * interface till the new specifitions are in place.
3750 if( copy_from_user(uioc
, arg
, sizeof(nitioctl_t
)) )
3757 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3759 * Get the user ioctl structure
3761 if( copy_from_user(&uioc_mimd
, arg
, sizeof(struct uioctl_t
)) )
3766 * Get the opcode and subopcode for the commands
3768 opcode
= uioc_mimd
.ui
.fcs
.opcode
;
3769 subopcode
= uioc_mimd
.ui
.fcs
.subopcode
;
3774 switch (subopcode
) {
3776 case MEGAIOC_QDRVRVER
: /* Query driver version */
3777 uioc
->opcode
= GET_DRIVER_VER
;
3778 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3781 case MEGAIOC_QNADAP
: /* Get # of adapters */
3782 uioc
->opcode
= GET_N_ADAP
;
3783 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3786 case MEGAIOC_QADAPINFO
: /* Get adapter information */
3787 uioc
->opcode
= GET_ADAP_INFO
;
3788 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3789 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3801 uioc
->opcode
= MBOX_CMD
;
3802 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3804 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3806 uioc
->xferlen
= uioc_mimd
.ui
.fcs
.length
;
3808 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3809 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3815 uioc
->opcode
= MBOX_CMD
;
3816 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3818 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3821 * Choose the xferlen bigger of input and output data
3823 uioc
->xferlen
= uioc_mimd
.outlen
> uioc_mimd
.inlen
?
3824 uioc_mimd
.outlen
: uioc_mimd
.inlen
;
3826 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3827 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3841 * @arg - user address
3842 * @mc - mailbox command
3844 * Updates the status information to the application, depending on application
3845 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3848 mega_n_to_m(void __user
*arg
, megacmd_t
*mc
)
3850 nitioctl_t __user
*uiocp
;
3851 megacmd_t __user
*umc
;
3852 mega_passthru __user
*upthru
;
3853 struct uioctl_t __user
*uioc_mimd
;
3854 char signature
[8] = {0};
3857 * check is the application conforms to NIT.
3859 if( copy_from_user(signature
, arg
, 7) )
3862 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3866 if( put_user(mc
->status
, (u8 __user
*)&MBOX_P(uiocp
)->status
) )
3869 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3871 umc
= MBOX_P(uiocp
);
3873 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3876 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
))
3883 if( put_user(mc
->status
, (u8 __user
*)&uioc_mimd
->mbox
[17]) )
3886 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3888 umc
= (megacmd_t __user
*)uioc_mimd
->mbox
;
3890 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3893 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
) )
3903 * MEGARAID 'FW' commands.
3907 * mega_is_bios_enabled()
3908 * @adapter - pointer to our soft state
3910 * issue command to find out if the BIOS is enabled for this controller
3913 mega_is_bios_enabled(adapter_t
*adapter
)
3915 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
3919 mbox
= (mbox_t
*)raw_mbox
;
3921 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
3923 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
3925 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
3927 raw_mbox
[0] = IS_BIOS_ENABLED
;
3928 raw_mbox
[2] = GET_BIOS
;
3931 ret
= issue_scb_block(adapter
, raw_mbox
);
3933 return *(char *)adapter
->mega_buffer
;
3938 * mega_enum_raid_scsi()
3939 * @adapter - pointer to our soft state
3941 * Find out what channels are RAID/SCSI. This information is used to
3942 * differentiate the virtual channels and physical channels and to support
3943 * ROMB feature and non-disk devices.
3946 mega_enum_raid_scsi(adapter_t
*adapter
)
3948 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
3952 mbox
= (mbox_t
*)raw_mbox
;
3954 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
3957 * issue command to find out what channels are raid/scsi
3959 raw_mbox
[0] = CHNL_CLASS
;
3960 raw_mbox
[2] = GET_CHNL_CLASS
;
3962 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
3964 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
3967 * Non-ROMB firmware fail this command, so all channels
3968 * must be shown RAID
3970 adapter
->mega_ch_class
= 0xFF;
3972 if(!issue_scb_block(adapter
, raw_mbox
)) {
3973 adapter
->mega_ch_class
= *((char *)adapter
->mega_buffer
);
3977 for( i
= 0; i
< adapter
->product_info
.nchannels
; i
++ ) {
3978 if( (adapter
->mega_ch_class
>> i
) & 0x01 ) {
3979 printk(KERN_INFO
"megaraid: channel[%d] is raid.\n",
3983 printk(KERN_INFO
"megaraid: channel[%d] is scsi.\n",
3993 * mega_get_boot_drv()
3994 * @adapter - pointer to our soft state
3996 * Find out which device is the boot device. Note, any logical drive or any
3997 * phyical device (e.g., a CDROM) can be designated as a boot device.
4000 mega_get_boot_drv(adapter_t
*adapter
)
4002 struct private_bios_data
*prv_bios_data
;
4003 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4010 mbox
= (mbox_t
*)raw_mbox
;
4012 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4014 raw_mbox
[0] = BIOS_PVT_DATA
;
4015 raw_mbox
[2] = GET_BIOS_PVT_DATA
;
4017 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4019 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4021 adapter
->boot_ldrv_enabled
= 0;
4022 adapter
->boot_ldrv
= 0;
4024 adapter
->boot_pdrv_enabled
= 0;
4025 adapter
->boot_pdrv_ch
= 0;
4026 adapter
->boot_pdrv_tgt
= 0;
4028 if(issue_scb_block(adapter
, raw_mbox
) == 0) {
4030 (struct private_bios_data
*)adapter
->mega_buffer
;
4033 cksum_p
= (char *)prv_bios_data
;
4034 for (i
= 0; i
< 14; i
++ ) {
4035 cksum
+= (u16
)(*cksum_p
++);
4038 if (prv_bios_data
->cksum
== (u16
)(0-cksum
) ) {
4041 * If MSB is set, a physical drive is set as boot
4044 if( prv_bios_data
->boot_drv
& 0x80 ) {
4045 adapter
->boot_pdrv_enabled
= 1;
4046 boot_pdrv
= prv_bios_data
->boot_drv
& 0x7F;
4047 adapter
->boot_pdrv_ch
= boot_pdrv
/ 16;
4048 adapter
->boot_pdrv_tgt
= boot_pdrv
% 16;
4051 adapter
->boot_ldrv_enabled
= 1;
4052 adapter
->boot_ldrv
= prv_bios_data
->boot_drv
;
4060 * mega_support_random_del()
4061 * @adapter - pointer to our soft state
4063 * Find out if this controller supports random deletion and addition of
4067 mega_support_random_del(adapter_t
*adapter
)
4069 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4073 mbox
= (mbox_t
*)raw_mbox
;
4075 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4080 raw_mbox
[0] = FC_DEL_LOGDRV
;
4081 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
4083 rval
= issue_scb_block(adapter
, raw_mbox
);
4090 * mega_support_ext_cdb()
4091 * @adapter - pointer to our soft state
4093 * Find out if this firmware support cdblen > 10
4096 mega_support_ext_cdb(adapter_t
*adapter
)
4098 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4102 mbox
= (mbox_t
*)raw_mbox
;
4104 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4106 * issue command to find out if controller supports extended CDBs.
4111 rval
= issue_scb_block(adapter
, raw_mbox
);
4119 * @adapter - pointer to our soft state
4120 * @logdrv - logical drive to be deleted
4122 * Delete the specified logical drive. It is the responsibility of the user
4123 * app to let the OS know about this operation.
4126 mega_del_logdrv(adapter_t
*adapter
, int logdrv
)
4128 unsigned long flags
;
4133 * Stop sending commands to the controller, queue them internally.
4134 * When deletion is complete, ISR will flush the queue.
4136 atomic_set(&adapter
->quiescent
, 1);
4139 * Wait till all the issued commands are complete and there are no
4140 * commands in the pending queue
4142 while (atomic_read(&adapter
->pend_cmds
) > 0 ||
4143 !list_empty(&adapter
->pending_list
))
4144 msleep(1000); /* sleep for 1s */
4146 rval
= mega_do_del_logdrv(adapter
, logdrv
);
4148 spin_lock_irqsave(&adapter
->lock
, flags
);
4151 * If delete operation was successful, add 0x80 to the logical drive
4152 * ids for commands in the pending queue.
4154 if (adapter
->read_ldidmap
) {
4155 struct list_head
*pos
;
4156 list_for_each(pos
, &adapter
->pending_list
) {
4157 scb
= list_entry(pos
, scb_t
, list
);
4158 if (scb
->pthru
->logdrv
< 0x80 )
4159 scb
->pthru
->logdrv
+= 0x80;
4163 atomic_set(&adapter
->quiescent
, 0);
4165 mega_runpendq(adapter
);
4167 spin_unlock_irqrestore(&adapter
->lock
, flags
);
4174 mega_do_del_logdrv(adapter_t
*adapter
, int logdrv
)
4179 memset( &mc
, 0, sizeof(megacmd_t
));
4181 mc
.cmd
= FC_DEL_LOGDRV
;
4182 mc
.opcode
= OP_DEL_LOGDRV
;
4183 mc
.subopcode
= logdrv
;
4185 rval
= mega_internal_command(adapter
, &mc
, NULL
);
4187 /* log this event */
4189 printk(KERN_WARNING
"megaraid: Delete LD-%d failed.", logdrv
);
4194 * After deleting first logical drive, the logical drives must be
4195 * addressed by adding 0x80 to the logical drive id.
4197 adapter
->read_ldidmap
= 1;
4204 * mega_get_max_sgl()
4205 * @adapter - pointer to our soft state
4207 * Find out the maximum number of scatter-gather elements supported by this
4208 * version of the firmware
4211 mega_get_max_sgl(adapter_t
*adapter
)
4213 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4216 mbox
= (mbox_t
*)raw_mbox
;
4218 memset(mbox
, 0, sizeof(raw_mbox
));
4220 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4222 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4224 raw_mbox
[0] = MAIN_MISC_OPCODE
;
4225 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
4228 if( issue_scb_block(adapter
, raw_mbox
) ) {
4230 * f/w does not support this command. Choose the default value
4232 adapter
->sglen
= MIN_SGLIST
;
4235 adapter
->sglen
= *((char *)adapter
->mega_buffer
);
4238 * Make sure this is not more than the resources we are
4239 * planning to allocate
4241 if ( adapter
->sglen
> MAX_SGLIST
)
4242 adapter
->sglen
= MAX_SGLIST
;
4250 * mega_support_cluster()
4251 * @adapter - pointer to our soft state
4253 * Find out if this firmware support cluster calls.
4256 mega_support_cluster(adapter_t
*adapter
)
4258 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4261 mbox
= (mbox_t
*)raw_mbox
;
4263 memset(mbox
, 0, sizeof(raw_mbox
));
4265 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4267 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4270 * Try to get the initiator id. This command will succeed iff the
4271 * clustering is available on this HBA.
4273 raw_mbox
[0] = MEGA_GET_TARGET_ID
;
4275 if( issue_scb_block(adapter
, raw_mbox
) == 0 ) {
4278 * Cluster support available. Get the initiator target id.
4279 * Tell our id to mid-layer too.
4281 adapter
->this_id
= *(u32
*)adapter
->mega_buffer
;
4282 adapter
->host
->this_id
= adapter
->this_id
;
4290 #ifdef CONFIG_PROC_FS
4293 * @adapter - pointer to our soft state
4294 * @dma_handle - DMA address of the buffer
4296 * Issue internal comamnds while interrupts are available.
4297 * We only issue direct mailbox commands from within the driver. ioctl()
4298 * interface using these routines can issue passthru commands.
4301 mega_adapinq(adapter_t
*adapter
, dma_addr_t dma_handle
)
4305 memset(&mc
, 0, sizeof(megacmd_t
));
4307 if( adapter
->flag
& BOARD_40LD
) {
4308 mc
.cmd
= FC_NEW_CONFIG
;
4309 mc
.opcode
= NC_SUBOP_ENQUIRY3
;
4310 mc
.subopcode
= ENQ3_GET_SOLICITED_FULL
;
4313 mc
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
4316 mc
.xferaddr
= (u32
)dma_handle
;
4318 if ( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
4326 /** mega_internal_dev_inquiry()
4327 * @adapter - pointer to our soft state
4328 * @ch - channel for this device
4329 * @tgt - ID of this device
4330 * @buf_dma_handle - DMA address of the buffer
4332 * Issue the scsi inquiry for the specified device.
4335 mega_internal_dev_inquiry(adapter_t
*adapter
, u8 ch
, u8 tgt
,
4336 dma_addr_t buf_dma_handle
)
4338 mega_passthru
*pthru
;
4339 dma_addr_t pthru_dma_handle
;
4342 struct pci_dev
*pdev
;
4346 * For all internal commands, the buffer must be allocated in <4GB
4349 if( make_local_pdev(adapter
, &pdev
) != 0 ) return -1;
4351 pthru
= pci_alloc_consistent(pdev
, sizeof(mega_passthru
),
4354 if( pthru
== NULL
) {
4355 free_local_pdev(pdev
);
4361 pthru
->reqsenselen
= 14;
4362 pthru
->islogical
= 0;
4364 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : ch
;
4366 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ? (ch
<< 4)|tgt
: tgt
;
4370 pthru
->cdb
[0] = INQUIRY
;
4374 pthru
->cdb
[4] = 255;
4378 pthru
->dataxferaddr
= (u32
)buf_dma_handle
;
4379 pthru
->dataxferlen
= 256;
4381 memset(&mc
, 0, sizeof(megacmd_t
));
4383 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
4384 mc
.xferaddr
= (u32
)pthru_dma_handle
;
4386 rval
= mega_internal_command(adapter
, &mc
, pthru
);
4388 pci_free_consistent(pdev
, sizeof(mega_passthru
), pthru
,
4391 free_local_pdev(pdev
);
4398 * mega_internal_command()
4399 * @adapter - pointer to our soft state
4400 * @mc - the mailbox command
4401 * @pthru - Passthru structure for DCDB commands
4403 * Issue the internal commands in interrupt mode.
4404 * The last argument is the address of the passthru structure if the command
4405 * to be fired is a passthru command
4407 * lockscope specifies whether the caller has already acquired the lock. Of
4408 * course, the caller must know which lock we are talking about.
4410 * Note: parameter 'pthru' is null for non-passthru commands.
4413 mega_internal_command(adapter_t
*adapter
, megacmd_t
*mc
, mega_passthru
*pthru
)
4416 struct scsi_device
*sdev
;
4420 scmd
= scsi_allocate_command(GFP_KERNEL
);
4425 * The internal commands share one command id and hence are
4426 * serialized. This is so because we want to reserve maximum number of
4427 * available command ids for the I/O commands.
4429 mutex_lock(&adapter
->int_mtx
);
4431 scb
= &adapter
->int_scb
;
4432 memset(scb
, 0, sizeof(scb_t
));
4434 sdev
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
4435 scmd
->device
= sdev
;
4437 memset(adapter
->int_cdb
, 0, sizeof(adapter
->int_cdb
));
4438 scmd
->cmnd
= adapter
->int_cdb
;
4439 scmd
->device
->host
= adapter
->host
;
4440 scmd
->host_scribble
= (void *)scb
;
4441 scmd
->cmnd
[0] = MEGA_INTERNAL_CMD
;
4443 scb
->state
|= SCB_ACTIVE
;
4446 memcpy(scb
->raw_mbox
, mc
, sizeof(megacmd_t
));
4449 * Is it a passthru command
4451 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
4456 scb
->idx
= CMDID_INT_CMDS
;
4458 megaraid_queue(scmd
, mega_internal_done
);
4460 wait_for_completion(&adapter
->int_waitq
);
4462 rval
= scmd
->result
;
4463 mc
->status
= scmd
->result
;
4467 * Print a debug message for all failed commands. Applications can use
4470 if( scmd
->result
&& trace_level
) {
4471 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4472 mc
->cmd
, mc
->opcode
, mc
->subopcode
, scmd
->result
);
4475 mutex_unlock(&adapter
->int_mtx
);
4477 scsi_free_command(GFP_KERNEL
, scmd
);
4484 * mega_internal_done()
4485 * @scmd - internal scsi command
4487 * Callback routine for internal commands.
4490 mega_internal_done(Scsi_Cmnd
*scmd
)
4494 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
4496 complete(&adapter
->int_waitq
);
4501 static struct scsi_host_template megaraid_template
= {
4502 .module
= THIS_MODULE
,
4504 .proc_name
= "megaraid_legacy",
4505 .info
= megaraid_info
,
4506 .queuecommand
= megaraid_queue
,
4507 .bios_param
= megaraid_biosparam
,
4508 .max_sectors
= MAX_SECTORS_PER_IO
,
4509 .can_queue
= MAX_COMMANDS
,
4510 .this_id
= DEFAULT_INITIATOR_ID
,
4511 .sg_tablesize
= MAX_SGLIST
,
4512 .cmd_per_lun
= DEF_CMD_PER_LUN
,
4513 .use_clustering
= ENABLE_CLUSTERING
,
4514 .eh_abort_handler
= megaraid_abort
,
4515 .eh_device_reset_handler
= megaraid_reset
,
4516 .eh_bus_reset_handler
= megaraid_reset
,
4517 .eh_host_reset_handler
= megaraid_reset
,
4520 static int __devinit
4521 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
4523 struct Scsi_Host
*host
;
4525 unsigned long mega_baseport
, tbase
, flag
= 0;
4526 u16 subsysid
, subsysvid
;
4527 u8 pci_bus
, pci_dev_func
;
4529 int error
= -ENODEV
;
4531 if (pci_enable_device(pdev
))
4533 pci_set_master(pdev
);
4535 pci_bus
= pdev
->bus
->number
;
4536 pci_dev_func
= pdev
->devfn
;
4539 * The megaraid3 stuff reports the ID of the Intel part which is not
4540 * remotely specific to the megaraid
4542 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
) {
4545 * Don't fall over the Compaq management cards using the same
4548 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_COMPAQ
&&
4549 pdev
->subsystem_device
== 0xC000)
4551 /* Now check the magic signature byte */
4552 pci_read_config_word(pdev
, PCI_CONF_AMISIG
, &magic
);
4553 if (magic
!= HBA_SIGNATURE_471
&& magic
!= HBA_SIGNATURE
)
4555 /* Ok it is probably a megaraid */
4559 * For these vendor and device ids, signature offsets are not
4560 * valid and 64 bit is implicit
4562 if (id
->driver_data
& BOARD_64BIT
)
4563 flag
|= BOARD_64BIT
;
4567 pci_read_config_dword(pdev
, PCI_CONF_AMISIG64
, &magic64
);
4568 if (magic64
== HBA_SIGNATURE_64BIT
)
4569 flag
|= BOARD_64BIT
;
4572 subsysvid
= pdev
->subsystem_vendor
;
4573 subsysid
= pdev
->subsystem_device
;
4575 printk(KERN_NOTICE
"megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4576 id
->vendor
, id
->device
, pci_bus
);
4578 printk("slot %d:func %d\n",
4579 PCI_SLOT(pci_dev_func
), PCI_FUNC(pci_dev_func
));
4581 /* Read the base port and IRQ from PCI */
4582 mega_baseport
= pci_resource_start(pdev
, 0);
4585 tbase
= mega_baseport
;
4586 if (pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) {
4587 flag
|= BOARD_MEMMAP
;
4589 if (!request_mem_region(mega_baseport
, 128, "megaraid")) {
4590 printk(KERN_WARNING
"megaraid: mem region busy!\n");
4591 goto out_disable_device
;
4594 mega_baseport
= (unsigned long)ioremap(mega_baseport
, 128);
4595 if (!mega_baseport
) {
4597 "megaraid: could not map hba memory\n");
4598 goto out_release_region
;
4601 flag
|= BOARD_IOMAP
;
4602 mega_baseport
+= 0x10;
4604 if (!request_region(mega_baseport
, 16, "megaraid"))
4605 goto out_disable_device
;
4608 /* Initialize SCSI Host structure */
4609 host
= scsi_host_alloc(&megaraid_template
, sizeof(adapter_t
));
4613 adapter
= (adapter_t
*)host
->hostdata
;
4614 memset(adapter
, 0, sizeof(adapter_t
));
4617 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4618 host
->host_no
, mega_baseport
, irq
);
4620 adapter
->base
= mega_baseport
;
4621 if (flag
& BOARD_MEMMAP
)
4622 adapter
->mmio_base
= (void __iomem
*) mega_baseport
;
4624 INIT_LIST_HEAD(&adapter
->free_list
);
4625 INIT_LIST_HEAD(&adapter
->pending_list
);
4626 INIT_LIST_HEAD(&adapter
->completed_list
);
4628 adapter
->flag
= flag
;
4629 spin_lock_init(&adapter
->lock
);
4631 host
->cmd_per_lun
= max_cmd_per_lun
;
4632 host
->max_sectors
= max_sectors_per_io
;
4634 adapter
->dev
= pdev
;
4635 adapter
->host
= host
;
4637 adapter
->host
->irq
= irq
;
4639 if (flag
& BOARD_MEMMAP
)
4640 adapter
->host
->base
= tbase
;
4642 adapter
->host
->io_port
= tbase
;
4643 adapter
->host
->n_io_port
= 16;
4646 adapter
->host
->unique_id
= (pci_bus
<< 8) | pci_dev_func
;
4649 * Allocate buffer to issue internal commands.
4651 adapter
->mega_buffer
= pci_alloc_consistent(adapter
->dev
,
4652 MEGA_BUFFER_SIZE
, &adapter
->buf_dma_handle
);
4653 if (!adapter
->mega_buffer
) {
4654 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4658 adapter
->scb_list
= kmalloc(sizeof(scb_t
) * MAX_COMMANDS
, GFP_KERNEL
);
4659 if (!adapter
->scb_list
) {
4660 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4661 goto out_free_cmd_buffer
;
4664 if (request_irq(irq
, (adapter
->flag
& BOARD_MEMMAP
) ?
4665 megaraid_isr_memmapped
: megaraid_isr_iomapped
,
4666 IRQF_SHARED
, "megaraid", adapter
)) {
4668 "megaraid: Couldn't register IRQ %d!\n", irq
);
4669 goto out_free_scb_list
;
4672 if (mega_setup_mailbox(adapter
))
4675 if (mega_query_adapter(adapter
))
4679 * Have checks for some buggy f/w
4681 if ((subsysid
== 0x1111) && (subsysvid
== 0x1111)) {
4685 if (!strcmp(adapter
->fw_version
, "3.00") ||
4686 !strcmp(adapter
->fw_version
, "3.01")) {
4688 printk( KERN_WARNING
4689 "megaraid: Your card is a Dell PERC "
4690 "2/SC RAID controller with "
4691 "firmware\nmegaraid: 3.00 or 3.01. "
4692 "This driver is known to have "
4693 "corruption issues\nmegaraid: with "
4694 "those firmware versions on this "
4695 "specific card. In order\nmegaraid: "
4696 "to protect your data, please upgrade "
4697 "your firmware to version\nmegaraid: "
4698 "3.10 or later, available from the "
4699 "Dell Technical Support web\n"
4700 "megaraid: site at\nhttp://support."
4701 "dell.com/us/en/filelib/download/"
4702 "index.asp?fileid=2940\n"
4708 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4709 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4710 * support, since this firmware cannot handle 64 bit
4713 if ((subsysvid
== HP_SUBSYS_VID
) &&
4714 ((subsysid
== 0x60E7) || (subsysid
== 0x60E8))) {
4718 if (!strcmp(adapter
->fw_version
, "H01.07") ||
4719 !strcmp(adapter
->fw_version
, "H01.08") ||
4720 !strcmp(adapter
->fw_version
, "H01.09") ) {
4722 "megaraid: Firmware H.01.07, "
4723 "H.01.08, and H.01.09 on 1M/2M "
4725 "megaraid: do not support 64 bit "
4726 "addressing.\nmegaraid: DISABLING "
4727 "64 bit support.\n");
4728 adapter
->flag
&= ~BOARD_64BIT
;
4732 if (mega_is_bios_enabled(adapter
))
4733 mega_hbas
[hba_count
].is_bios_enabled
= 1;
4734 mega_hbas
[hba_count
].hostdata_addr
= adapter
;
4737 * Find out which channel is raid and which is scsi. This is
4740 mega_enum_raid_scsi(adapter
);
4743 * Find out if a logical drive is set as the boot drive. If
4744 * there is one, will make that as the first logical drive.
4745 * ROMB: Do we have to boot from a physical drive. Then all
4746 * the physical drives would appear before the logical disks.
4747 * Else, all the physical drives would be exported to the mid
4748 * layer after logical drives.
4750 mega_get_boot_drv(adapter
);
4752 if (adapter
->boot_pdrv_enabled
) {
4753 j
= adapter
->product_info
.nchannels
;
4754 for( i
= 0; i
< j
; i
++ )
4755 adapter
->logdrv_chan
[i
] = 0;
4756 for( i
= j
; i
< NVIRT_CHAN
+ j
; i
++ )
4757 adapter
->logdrv_chan
[i
] = 1;
4759 for (i
= 0; i
< NVIRT_CHAN
; i
++)
4760 adapter
->logdrv_chan
[i
] = 1;
4761 for (i
= NVIRT_CHAN
; i
< MAX_CHANNELS
+NVIRT_CHAN
; i
++)
4762 adapter
->logdrv_chan
[i
] = 0;
4763 adapter
->mega_ch_class
<<= NVIRT_CHAN
;
4767 * Do we support random deletion and addition of logical
4770 adapter
->read_ldidmap
= 0; /* set it after first logdrv
4772 adapter
->support_random_del
= mega_support_random_del(adapter
);
4774 /* Initialize SCBs */
4775 if (mega_init_scb(adapter
))
4779 * Reset the pending commands counter
4781 atomic_set(&adapter
->pend_cmds
, 0);
4784 * Reset the adapter quiescent flag
4786 atomic_set(&adapter
->quiescent
, 0);
4788 hba_soft_state
[hba_count
] = adapter
;
4791 * Fill in the structure which needs to be passed back to the
4792 * application when it does an ioctl() for controller related
4797 mcontroller
[i
].base
= mega_baseport
;
4798 mcontroller
[i
].irq
= irq
;
4799 mcontroller
[i
].numldrv
= adapter
->numldrv
;
4800 mcontroller
[i
].pcibus
= pci_bus
;
4801 mcontroller
[i
].pcidev
= id
->device
;
4802 mcontroller
[i
].pcifun
= PCI_FUNC (pci_dev_func
);
4803 mcontroller
[i
].pciid
= -1;
4804 mcontroller
[i
].pcivendor
= id
->vendor
;
4805 mcontroller
[i
].pcislot
= PCI_SLOT(pci_dev_func
);
4806 mcontroller
[i
].uid
= (pci_bus
<< 8) | pci_dev_func
;
4809 /* Set the Mode of addressing to 64 bit if we can */
4810 if ((adapter
->flag
& BOARD_64BIT
) && (sizeof(dma_addr_t
) == 8)) {
4811 pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
4812 adapter
->has_64bit_addr
= 1;
4814 pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
4815 adapter
->has_64bit_addr
= 0;
4818 mutex_init(&adapter
->int_mtx
);
4819 init_completion(&adapter
->int_waitq
);
4821 adapter
->this_id
= DEFAULT_INITIATOR_ID
;
4822 adapter
->host
->this_id
= DEFAULT_INITIATOR_ID
;
4824 #if MEGA_HAVE_CLUSTERING
4826 * Is cluster support enabled on this controller
4827 * Note: In a cluster the HBAs ( the initiators ) will have
4828 * different target IDs and we cannot assume it to be 7. Call
4829 * to mega_support_cluster() will get the target ids also if
4830 * the cluster support is available
4832 adapter
->has_cluster
= mega_support_cluster(adapter
);
4833 if (adapter
->has_cluster
) {
4835 "megaraid: Cluster driver, initiator id:%d\n",
4840 pci_set_drvdata(pdev
, host
);
4842 mega_create_proc_entry(hba_count
, mega_proc_dir_entry
);
4844 error
= scsi_add_host(host
, &pdev
->dev
);
4848 scsi_scan_host(host
);
4853 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
4854 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
4856 free_irq(adapter
->host
->irq
, adapter
);
4858 kfree(adapter
->scb_list
);
4859 out_free_cmd_buffer
:
4860 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
4861 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
4863 scsi_host_put(host
);
4865 if (flag
& BOARD_MEMMAP
)
4866 iounmap((void *)mega_baseport
);
4868 if (flag
& BOARD_MEMMAP
)
4869 release_mem_region(tbase
, 128);
4871 release_region(mega_baseport
, 16);
4873 pci_disable_device(pdev
);
4879 __megaraid_shutdown(adapter_t
*adapter
)
4881 u_char raw_mbox
[sizeof(struct mbox_out
)];
4882 mbox_t
*mbox
= (mbox_t
*)raw_mbox
;
4885 /* Flush adapter cache */
4886 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4887 raw_mbox
[0] = FLUSH_ADAPTER
;
4889 free_irq(adapter
->host
->irq
, adapter
);
4891 /* Issue a blocking (interrupts disabled) command to the card */
4892 issue_scb_block(adapter
, raw_mbox
);
4894 /* Flush disks cache */
4895 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4896 raw_mbox
[0] = FLUSH_SYSTEM
;
4898 /* Issue a blocking (interrupts disabled) command to the card */
4899 issue_scb_block(adapter
, raw_mbox
);
4901 if (atomic_read(&adapter
->pend_cmds
) > 0)
4902 printk(KERN_WARNING
"megaraid: pending commands!!\n");
4905 * Have a delibrate delay to make sure all the caches are
4908 for (i
= 0; i
<= 10; i
++)
4912 static void __devexit
4913 megaraid_remove_one(struct pci_dev
*pdev
)
4915 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4916 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
4918 scsi_remove_host(host
);
4920 __megaraid_shutdown(adapter
);
4922 /* Free our resources */
4923 if (adapter
->flag
& BOARD_MEMMAP
) {
4924 iounmap((void *)adapter
->base
);
4925 release_mem_region(adapter
->host
->base
, 128);
4927 release_region(adapter
->base
, 16);
4929 mega_free_sgl(adapter
);
4931 #ifdef CONFIG_PROC_FS
4932 if (adapter
->controller_proc_dir_entry
) {
4933 remove_proc_entry("stat", adapter
->controller_proc_dir_entry
);
4934 remove_proc_entry("config",
4935 adapter
->controller_proc_dir_entry
);
4936 remove_proc_entry("mailbox",
4937 adapter
->controller_proc_dir_entry
);
4938 #if MEGA_HAVE_ENH_PROC
4939 remove_proc_entry("rebuild-rate",
4940 adapter
->controller_proc_dir_entry
);
4941 remove_proc_entry("battery-status",
4942 adapter
->controller_proc_dir_entry
);
4944 remove_proc_entry("diskdrives-ch0",
4945 adapter
->controller_proc_dir_entry
);
4946 remove_proc_entry("diskdrives-ch1",
4947 adapter
->controller_proc_dir_entry
);
4948 remove_proc_entry("diskdrives-ch2",
4949 adapter
->controller_proc_dir_entry
);
4950 remove_proc_entry("diskdrives-ch3",
4951 adapter
->controller_proc_dir_entry
);
4953 remove_proc_entry("raiddrives-0-9",
4954 adapter
->controller_proc_dir_entry
);
4955 remove_proc_entry("raiddrives-10-19",
4956 adapter
->controller_proc_dir_entry
);
4957 remove_proc_entry("raiddrives-20-29",
4958 adapter
->controller_proc_dir_entry
);
4959 remove_proc_entry("raiddrives-30-39",
4960 adapter
->controller_proc_dir_entry
);
4963 char buf
[12] = { 0 };
4964 sprintf(buf
, "hba%d", adapter
->host
->host_no
);
4965 remove_proc_entry(buf
, mega_proc_dir_entry
);
4970 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
4971 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
4972 kfree(adapter
->scb_list
);
4973 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
4974 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
4976 scsi_host_put(host
);
4977 pci_disable_device(pdev
);
4983 megaraid_shutdown(struct pci_dev
*pdev
)
4985 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4986 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
4988 __megaraid_shutdown(adapter
);
4991 static struct pci_device_id megaraid_pci_tbl
[] = {
4992 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID
,
4993 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
4994 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID2
,
4995 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
4996 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_AMI_MEGARAID3
,
4997 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5000 MODULE_DEVICE_TABLE(pci
, megaraid_pci_tbl
);
5002 static struct pci_driver megaraid_pci_driver
= {
5003 .name
= "megaraid_legacy",
5004 .id_table
= megaraid_pci_tbl
,
5005 .probe
= megaraid_probe_one
,
5006 .remove
= __devexit_p(megaraid_remove_one
),
5007 .shutdown
= megaraid_shutdown
,
5010 static int __init
megaraid_init(void)
5014 if ((max_cmd_per_lun
<= 0) || (max_cmd_per_lun
> MAX_CMD_PER_LUN
))
5015 max_cmd_per_lun
= MAX_CMD_PER_LUN
;
5016 if (max_mbox_busy_wait
> MBOX_BUSY_WAIT
)
5017 max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
5019 #ifdef CONFIG_PROC_FS
5020 mega_proc_dir_entry
= proc_mkdir("megaraid", NULL
);
5021 if (!mega_proc_dir_entry
) {
5023 "megaraid: failed to create megaraid root\n");
5026 error
= pci_register_driver(&megaraid_pci_driver
);
5028 #ifdef CONFIG_PROC_FS
5029 remove_proc_entry("megaraid", NULL
);
5035 * Register the driver as a character device, for applications
5036 * to access it for ioctls.
5037 * First argument (major) to register_chrdev implies a dynamic
5038 * major number allocation.
5040 major
= register_chrdev(0, "megadev_legacy", &megadev_fops
);
5043 "megaraid: failed to register char device\n");
5049 static void __exit
megaraid_exit(void)
5052 * Unregister the character device interface to the driver.
5054 unregister_chrdev(major
, "megadev_legacy");
5056 pci_unregister_driver(&megaraid_pci_driver
);
5058 #ifdef CONFIG_PROC_FS
5059 remove_proc_entry("megaraid", NULL
);
5063 module_init(megaraid_init
);
5064 module_exit(megaraid_exit
);
5066 /* vi: set ts=8 sw=8 tw=78: */