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 <scsi/scsicam.h>
52 #include <scsi/scsi_host.h>
56 #define MEGARAID_MODULE_VERSION "2.00.4"
58 MODULE_AUTHOR ("sju@lsil.com");
59 MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
60 MODULE_LICENSE ("GPL");
61 MODULE_VERSION(MEGARAID_MODULE_VERSION
);
63 static unsigned int max_cmd_per_lun
= DEF_CMD_PER_LUN
;
64 module_param(max_cmd_per_lun
, uint
, 0);
65 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)");
67 static unsigned short int max_sectors_per_io
= MAX_SECTORS_PER_IO
;
68 module_param(max_sectors_per_io
, ushort
, 0);
69 MODULE_PARM_DESC(max_sectors_per_io
, "Maximum number of sectors per I/O request (default=MAX_SECTORS_PER_IO=128)");
72 static unsigned short int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
73 module_param(max_mbox_busy_wait
, ushort
, 0);
74 MODULE_PARM_DESC(max_mbox_busy_wait
, "Maximum wait for mailbox in microseconds if busy (default=MBOX_BUSY_WAIT=10)");
76 #define RDINDOOR(adapter) readl((adapter)->base + 0x20)
77 #define RDOUTDOOR(adapter) readl((adapter)->base + 0x2C)
78 #define WRINDOOR(adapter,value) writel(value, (adapter)->base + 0x20)
79 #define WROUTDOOR(adapter,value) writel(value, (adapter)->base + 0x2C)
86 static adapter_t
*hba_soft_state
[MAX_CONTROLLERS
];
87 static struct proc_dir_entry
*mega_proc_dir_entry
;
89 /* For controller re-ordering */
90 static struct mega_hbas mega_hbas
[MAX_CONTROLLERS
];
93 * The File Operations structure for the serial/ioctl interface of the driver
95 static struct file_operations megadev_fops
= {
97 .ioctl
= megadev_ioctl
,
102 * Array to structures for storing the information about the controllers. This
103 * information is sent to the user level applications, when they do an ioctl
104 * for this information.
106 static struct mcontroller mcontroller
[MAX_CONTROLLERS
];
108 /* The current driver version */
109 static u32 driver_ver
= 0x02000000;
111 /* major number used by the device for character interface */
114 #define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
118 * Debug variable to print some diagnostic messages
120 static int trace_level
;
123 * mega_setup_mailbox()
124 * @adapter - pointer to our soft state
126 * Allocates a 8 byte aligned memory for the handshake mailbox.
129 mega_setup_mailbox(adapter_t
*adapter
)
133 adapter
->una_mbox64
= pci_alloc_consistent(adapter
->dev
,
134 sizeof(mbox64_t
), &adapter
->una_mbox64_dma
);
136 if( !adapter
->una_mbox64
) return -1;
138 adapter
->mbox
= &adapter
->una_mbox64
->mbox
;
140 adapter
->mbox
= (mbox_t
*)((((unsigned long) adapter
->mbox
) + 15) &
143 adapter
->mbox64
= (mbox64_t
*)(((unsigned long)adapter
->mbox
) - 8);
145 align
= ((void *)adapter
->mbox
) - ((void *)&adapter
->una_mbox64
->mbox
);
147 adapter
->mbox_dma
= adapter
->una_mbox64_dma
+ 8 + align
;
150 * Register the mailbox if the controller is an io-mapped controller
152 if( adapter
->flag
& BOARD_IOMAP
) {
154 outb_p(adapter
->mbox_dma
& 0xFF,
155 adapter
->host
->io_port
+ MBOX_PORT0
);
157 outb_p((adapter
->mbox_dma
>> 8) & 0xFF,
158 adapter
->host
->io_port
+ MBOX_PORT1
);
160 outb_p((adapter
->mbox_dma
>> 16) & 0xFF,
161 adapter
->host
->io_port
+ MBOX_PORT2
);
163 outb_p((adapter
->mbox_dma
>> 24) & 0xFF,
164 adapter
->host
->io_port
+ MBOX_PORT3
);
166 outb_p(ENABLE_MBOX_BYTE
,
167 adapter
->host
->io_port
+ ENABLE_MBOX_REGION
);
179 * mega_query_adapter()
180 * @adapter - pointer to our soft state
182 * Issue the adapter inquiry commands to the controller and find out
183 * information and parameter about the devices attached
186 mega_query_adapter(adapter_t
*adapter
)
188 dma_addr_t prod_info_dma_handle
;
189 mega_inquiry3
*inquiry3
;
190 u8 raw_mbox
[sizeof(struct mbox_out
)];
194 /* Initialize adapter inquiry mailbox */
196 mbox
= (mbox_t
*)raw_mbox
;
198 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
199 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
202 * Try to issue Inquiry3 command
203 * if not succeeded, then issue MEGA_MBOXCMD_ADAPTERINQ command and
204 * update enquiry3 structure
206 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
208 inquiry3
= (mega_inquiry3
*)adapter
->mega_buffer
;
210 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
211 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
; /* i.e. 0x0F */
212 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
; /* i.e. 0x02 */
214 /* Issue a blocking command to the card */
215 if ((retval
= issue_scb_block(adapter
, raw_mbox
))) {
216 /* the adapter does not support 40ld */
218 mraid_ext_inquiry
*ext_inq
;
220 dma_addr_t dma_handle
;
222 ext_inq
= pci_alloc_consistent(adapter
->dev
,
223 sizeof(mraid_ext_inquiry
), &dma_handle
);
225 if( ext_inq
== NULL
) return -1;
227 inq
= &ext_inq
->raid_inq
;
229 mbox
->m_out
.xferaddr
= (u32
)dma_handle
;
231 /*issue old 0x04 command to adapter */
232 mbox
->m_out
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
234 issue_scb_block(adapter
, raw_mbox
);
237 * update Enquiry3 and ProductInfo structures with
238 * mraid_inquiry structure
240 mega_8_to_40ld(inq
, inquiry3
,
241 (mega_product_info
*)&adapter
->product_info
);
243 pci_free_consistent(adapter
->dev
, sizeof(mraid_ext_inquiry
),
244 ext_inq
, dma_handle
);
246 } else { /*adapter supports 40ld */
247 adapter
->flag
|= BOARD_40LD
;
250 * get product_info, which is static information and will be
253 prod_info_dma_handle
= pci_map_single(adapter
->dev
, (void *)
254 &adapter
->product_info
,
255 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
257 mbox
->m_out
.xferaddr
= prod_info_dma_handle
;
259 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
260 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
; /* i.e. 0x0E */
262 if ((retval
= issue_scb_block(adapter
, raw_mbox
)))
264 "megaraid: Product_info cmd failed with error: %d\n",
267 pci_unmap_single(adapter
->dev
, prod_info_dma_handle
,
268 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
273 * kernel scans the channels from 0 to <= max_channel
275 adapter
->host
->max_channel
=
276 adapter
->product_info
.nchannels
+ NVIRT_CHAN
-1;
278 adapter
->host
->max_id
= 16; /* max targets per channel */
280 adapter
->host
->max_lun
= 7; /* Upto 7 luns for non disk devices */
282 adapter
->host
->cmd_per_lun
= max_cmd_per_lun
;
284 adapter
->numldrv
= inquiry3
->num_ldrv
;
286 adapter
->max_cmds
= adapter
->product_info
.max_commands
;
288 if(adapter
->max_cmds
> MAX_COMMANDS
)
289 adapter
->max_cmds
= MAX_COMMANDS
;
291 adapter
->host
->can_queue
= adapter
->max_cmds
- 1;
294 * Get the maximum number of scatter-gather elements supported by this
297 mega_get_max_sgl(adapter
);
299 adapter
->host
->sg_tablesize
= adapter
->sglen
;
302 /* use HP firmware and bios version encoding */
303 if (adapter
->product_info
.subsysvid
== HP_SUBSYS_VID
) {
304 sprintf (adapter
->fw_version
, "%c%d%d.%d%d",
305 adapter
->product_info
.fw_version
[2],
306 adapter
->product_info
.fw_version
[1] >> 8,
307 adapter
->product_info
.fw_version
[1] & 0x0f,
308 adapter
->product_info
.fw_version
[0] >> 8,
309 adapter
->product_info
.fw_version
[0] & 0x0f);
310 sprintf (adapter
->bios_version
, "%c%d%d.%d%d",
311 adapter
->product_info
.bios_version
[2],
312 adapter
->product_info
.bios_version
[1] >> 8,
313 adapter
->product_info
.bios_version
[1] & 0x0f,
314 adapter
->product_info
.bios_version
[0] >> 8,
315 adapter
->product_info
.bios_version
[0] & 0x0f);
317 memcpy(adapter
->fw_version
,
318 (char *)adapter
->product_info
.fw_version
, 4);
319 adapter
->fw_version
[4] = 0;
321 memcpy(adapter
->bios_version
,
322 (char *)adapter
->product_info
.bios_version
, 4);
324 adapter
->bios_version
[4] = 0;
327 printk(KERN_NOTICE
"megaraid: [%s:%s] detected %d logical drives.\n",
328 adapter
->fw_version
, adapter
->bios_version
, adapter
->numldrv
);
331 * Do we support extended (>10 bytes) cdbs
333 adapter
->support_ext_cdb
= mega_support_ext_cdb(adapter
);
334 if (adapter
->support_ext_cdb
)
335 printk(KERN_NOTICE
"megaraid: supports extended CDBs.\n");
343 * @adapter - pointer to our soft state
345 * Runs through the list of pending requests.
348 mega_runpendq(adapter_t
*adapter
)
350 if(!list_empty(&adapter
->pending_list
))
351 __mega_runpendq(adapter
);
356 * @scmd - Issue this scsi command
357 * @done - the callback hook into the scsi mid-layer
359 * The command queuing entry point for the mid-layer.
362 megaraid_queue(Scsi_Cmnd
*scmd
, void (*done
)(Scsi_Cmnd
*))
369 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
371 scmd
->scsi_done
= done
;
375 * Allocate and build a SCB request
376 * busy flag will be set if mega_build_cmd() command could not
377 * allocate scb. We will return non-zero status in that case.
378 * NOTE: scb can be null even though certain commands completed
379 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
380 * return 0 in that case.
383 spin_lock_irqsave(&adapter
->lock
, flags
);
384 scb
= mega_build_cmd(adapter
, scmd
, &busy
);
388 scb
->state
|= SCB_PENDQ
;
389 list_add_tail(&scb
->list
, &adapter
->pending_list
);
392 * Check if the HBA is in quiescent state, e.g., during a
393 * delete logical drive opertion. If it is, don't run
396 if (atomic_read(&adapter
->quiescent
) == 0)
397 mega_runpendq(adapter
);
401 spin_unlock_irqrestore(&adapter
->lock
, flags
);
406 * mega_allocate_scb()
407 * @adapter - pointer to our soft state
408 * @cmd - scsi command from the mid-layer
410 * Allocate a SCB structure. This is the central structure for controller
413 static inline scb_t
*
414 mega_allocate_scb(adapter_t
*adapter
, Scsi_Cmnd
*cmd
)
416 struct list_head
*head
= &adapter
->free_list
;
419 /* Unlink command from Free List */
420 if( !list_empty(head
) ) {
422 scb
= list_entry(head
->next
, scb_t
, list
);
424 list_del_init(head
->next
);
426 scb
->state
= SCB_ACTIVE
;
428 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
437 * mega_get_ldrv_num()
438 * @adapter - pointer to our soft state
439 * @cmd - scsi mid layer command
440 * @channel - channel on the controller
442 * Calculate the logical drive number based on the information in scsi command
443 * and the channel number.
446 mega_get_ldrv_num(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int channel
)
451 tgt
= cmd
->device
->id
;
453 if ( tgt
> adapter
->this_id
)
454 tgt
--; /* we do not get inquires for initiator id */
456 ldrv_num
= (channel
* 15) + tgt
;
460 * If we have a logical drive with boot enabled, project it first
462 if( adapter
->boot_ldrv_enabled
) {
463 if( ldrv_num
== 0 ) {
464 ldrv_num
= adapter
->boot_ldrv
;
467 if( ldrv_num
<= adapter
->boot_ldrv
) {
474 * If "delete logical drive" feature is enabled on this controller.
475 * Do only if at least one delete logical drive operation was done.
477 * Also, after logical drive deletion, instead of logical drive number,
478 * the value returned should be 0x80+logical drive id.
480 * These is valid only for IO commands.
483 if (adapter
->support_random_del
&& adapter
->read_ldidmap
)
484 switch (cmd
->cmnd
[0]) {
485 case READ_6
: /* fall through */
486 case WRITE_6
: /* fall through */
487 case READ_10
: /* fall through */
497 * @adapter - pointer to our soft state
498 * @cmd - Prepare using this scsi command
499 * @busy - busy flag if no resources
501 * Prepares a command and scatter gather list for the controller. This routine
502 * also finds out if the commands is intended for a logical drive or a
503 * physical device and prepares the controller command accordingly.
505 * We also re-order the logical drives and physical devices based on their
509 mega_build_cmd(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int *busy
)
511 mega_ext_passthru
*epthru
;
512 mega_passthru
*pthru
;
520 int ldrv_num
= 0; /* logical drive number */
524 * filter the internal and ioctl commands
526 if((cmd
->cmnd
[0] == MEGA_INTERNAL_CMD
)) {
527 return cmd
->request_buffer
;
532 * We know what channels our logical drives are on - mega_find_card()
534 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
537 * The theory: If physical drive is chosen for boot, all the physical
538 * devices are exported before the logical drives, otherwise physical
539 * devices are pushed after logical drives, in which case - Kernel sees
540 * the physical devices on virtual channel which is obviously converted
541 * to actual channel on the HBA.
543 if( adapter
->boot_pdrv_enabled
) {
545 /* logical channel */
546 channel
= cmd
->device
->channel
-
547 adapter
->product_info
.nchannels
;
550 /* this is physical channel */
551 channel
= cmd
->device
->channel
;
552 target
= cmd
->device
->id
;
555 * boot from a physical disk, that disk needs to be
556 * exposed first IF both the channels are SCSI, then
557 * booting from the second channel is not allowed.
560 target
= adapter
->boot_pdrv_tgt
;
562 else if( target
== adapter
->boot_pdrv_tgt
) {
569 /* this is the logical channel */
570 channel
= cmd
->device
->channel
;
573 /* physical channel */
574 channel
= cmd
->device
->channel
- NVIRT_CHAN
;
575 target
= cmd
->device
->id
;
582 /* have just LUN 0 for each target on virtual channels */
583 if (cmd
->device
->lun
) {
584 cmd
->result
= (DID_BAD_TARGET
<< 16);
589 ldrv_num
= mega_get_ldrv_num(adapter
, cmd
, channel
);
592 max_ldrv_num
= (adapter
->flag
& BOARD_40LD
) ?
593 MAX_LOGICAL_DRIVES_40LD
: MAX_LOGICAL_DRIVES_8LD
;
596 * max_ldrv_num increases by 0x80 if some logical drive was
599 if(adapter
->read_ldidmap
)
600 max_ldrv_num
+= 0x80;
602 if(ldrv_num
> max_ldrv_num
) {
603 cmd
->result
= (DID_BAD_TARGET
<< 16);
610 if( cmd
->device
->lun
> 7) {
612 * Do not support lun >7 for physically accessed
615 cmd
->result
= (DID_BAD_TARGET
<< 16);
623 * Logical drive commands
627 switch (cmd
->cmnd
[0]) {
628 case TEST_UNIT_READY
:
629 #if MEGA_HAVE_CLUSTERING
631 * Do we support clustering and is the support enabled
632 * If no, return success always
634 if( !adapter
->has_cluster
) {
635 cmd
->result
= (DID_OK
<< 16);
640 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
645 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
646 scb
->raw_mbox
[2] = MEGA_RESERVATION_STATUS
;
647 scb
->raw_mbox
[3] = ldrv_num
;
649 scb
->dma_direction
= PCI_DMA_NONE
;
653 cmd
->result
= (DID_OK
<< 16);
662 struct scatterlist
*sg
;
664 sg
= (struct scatterlist
*)cmd
->request_buffer
;
665 buf
= kmap_atomic(sg
->page
, KM_IRQ0
) +
668 buf
= cmd
->request_buffer
;
669 memset(buf
, 0, cmd
->cmnd
[4]);
671 struct scatterlist
*sg
;
673 sg
= (struct scatterlist
*)cmd
->request_buffer
;
674 kunmap_atomic(buf
- sg
->offset
, KM_IRQ0
);
676 cmd
->result
= (DID_OK
<< 16);
684 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
687 "scsi%d: scanning scsi channel %d ",
688 adapter
->host
->host_no
,
689 cmd
->device
->channel
);
690 printk("for logical drives.\n");
692 adapter
->flag
|= (1L << cmd
->device
->channel
);
695 /* Allocate a SCB and initialize passthru */
696 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
702 mbox
= (mbox_t
*)scb
->raw_mbox
;
703 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
704 memset(pthru
, 0, sizeof(mega_passthru
));
708 pthru
->reqsenselen
= 14;
709 pthru
->islogical
= 1;
710 pthru
->logdrv
= ldrv_num
;
711 pthru
->cdblen
= cmd
->cmd_len
;
712 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
714 if( adapter
->has_64bit_addr
) {
715 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
718 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
721 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
723 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
724 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
726 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
737 /* Allocate a SCB and initialize mailbox */
738 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
742 mbox
= (mbox_t
*)scb
->raw_mbox
;
744 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
745 mbox
->m_out
.logdrv
= ldrv_num
;
748 * A little hack: 2nd bit is zero for all scsi read
749 * commands and is set for all scsi write commands
751 if( adapter
->has_64bit_addr
) {
752 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
753 MEGA_MBOXCMD_LWRITE64
:
754 MEGA_MBOXCMD_LREAD64
;
757 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
763 * 6-byte READ(0x08) or WRITE(0x0A) cdb
765 if( cmd
->cmd_len
== 6 ) {
766 mbox
->m_out
.numsectors
= (u32
) cmd
->cmnd
[4];
768 ((u32
)cmd
->cmnd
[1] << 16) |
769 ((u32
)cmd
->cmnd
[2] << 8) |
772 mbox
->m_out
.lba
&= 0x1FFFFF;
776 * Take modulo 0x80, since the logical drive
777 * number increases by 0x80 when a logical
780 if (*cmd
->cmnd
== READ_6
) {
781 adapter
->nreads
[ldrv_num
%0x80]++;
782 adapter
->nreadblocks
[ldrv_num
%0x80] +=
783 mbox
->m_out
.numsectors
;
785 adapter
->nwrites
[ldrv_num
%0x80]++;
786 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
787 mbox
->m_out
.numsectors
;
793 * 10-byte READ(0x28) or WRITE(0x2A) cdb
795 if( cmd
->cmd_len
== 10 ) {
796 mbox
->m_out
.numsectors
=
798 ((u32
)cmd
->cmnd
[7] << 8);
800 ((u32
)cmd
->cmnd
[2] << 24) |
801 ((u32
)cmd
->cmnd
[3] << 16) |
802 ((u32
)cmd
->cmnd
[4] << 8) |
806 if (*cmd
->cmnd
== READ_10
) {
807 adapter
->nreads
[ldrv_num
%0x80]++;
808 adapter
->nreadblocks
[ldrv_num
%0x80] +=
809 mbox
->m_out
.numsectors
;
811 adapter
->nwrites
[ldrv_num
%0x80]++;
812 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
813 mbox
->m_out
.numsectors
;
819 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
821 if( cmd
->cmd_len
== 12 ) {
823 ((u32
)cmd
->cmnd
[2] << 24) |
824 ((u32
)cmd
->cmnd
[3] << 16) |
825 ((u32
)cmd
->cmnd
[4] << 8) |
828 mbox
->m_out
.numsectors
=
829 ((u32
)cmd
->cmnd
[6] << 24) |
830 ((u32
)cmd
->cmnd
[7] << 16) |
831 ((u32
)cmd
->cmnd
[8] << 8) |
835 if (*cmd
->cmnd
== READ_12
) {
836 adapter
->nreads
[ldrv_num
%0x80]++;
837 adapter
->nreadblocks
[ldrv_num
%0x80] +=
838 mbox
->m_out
.numsectors
;
840 adapter
->nwrites
[ldrv_num
%0x80]++;
841 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
842 mbox
->m_out
.numsectors
;
848 * If it is a read command
850 if( (*cmd
->cmnd
& 0x0F) == 0x08 ) {
851 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
854 scb
->dma_direction
= PCI_DMA_TODEVICE
;
857 /* Calculate Scatter-Gather info */
858 mbox
->m_out
.numsgelements
= mega_build_sglist(adapter
, scb
,
859 (u32
*)&mbox
->m_out
.xferaddr
, (u32
*)&seg
);
863 #if MEGA_HAVE_CLUSTERING
864 case RESERVE
: /* Fall through */
868 * Do we support clustering and is the support enabled
870 if( ! adapter
->has_cluster
) {
872 cmd
->result
= (DID_BAD_TARGET
<< 16);
877 /* Allocate a SCB and initialize mailbox */
878 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
883 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
884 scb
->raw_mbox
[2] = ( *cmd
->cmnd
== RESERVE
) ?
885 MEGA_RESERVE_LD
: MEGA_RELEASE_LD
;
887 scb
->raw_mbox
[3] = ldrv_num
;
889 scb
->dma_direction
= PCI_DMA_NONE
;
895 cmd
->result
= (DID_BAD_TARGET
<< 16);
902 * Passthru drive commands
905 /* Allocate a SCB and initialize passthru */
906 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
911 mbox
= (mbox_t
*)scb
->raw_mbox
;
912 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
914 if( adapter
->support_ext_cdb
) {
916 epthru
= mega_prepare_extpassthru(adapter
, scb
, cmd
,
919 mbox
->m_out
.cmd
= MEGA_MBOXCMD_EXTPTHRU
;
921 mbox
->m_out
.xferaddr
= scb
->epthru_dma_addr
;
926 pthru
= mega_prepare_passthru(adapter
, scb
, cmd
,
929 /* Initialize mailbox */
930 if( adapter
->has_64bit_addr
) {
931 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
934 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
937 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
947 * mega_prepare_passthru()
948 * @adapter - pointer to our soft state
949 * @scb - our scsi control block
950 * @cmd - scsi command from the mid-layer
951 * @channel - actual channel on the controller
952 * @target - actual id on the controller.
954 * prepare a command for the scsi physical devices.
956 static mega_passthru
*
957 mega_prepare_passthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
958 int channel
, int target
)
960 mega_passthru
*pthru
;
963 memset(pthru
, 0, sizeof (mega_passthru
));
965 /* 0=6sec/1=60sec/2=10min/3=3hrs */
969 pthru
->reqsenselen
= 14;
970 pthru
->islogical
= 0;
972 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
974 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
975 (channel
<< 4) | target
: target
;
977 pthru
->cdblen
= cmd
->cmd_len
;
978 pthru
->logdrv
= cmd
->device
->lun
;
980 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
982 /* Not sure about the direction */
983 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
985 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
986 switch (cmd
->cmnd
[0]) {
989 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
992 "scsi%d: scanning scsi channel %d [P%d] ",
993 adapter
->host
->host_no
,
994 cmd
->device
->channel
, channel
);
995 printk("for physical devices.\n");
997 adapter
->flag
|= (1L << cmd
->device
->channel
);
1001 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
1002 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
1010 * mega_prepare_extpassthru()
1011 * @adapter - pointer to our soft state
1012 * @scb - our scsi control block
1013 * @cmd - scsi command from the mid-layer
1014 * @channel - actual channel on the controller
1015 * @target - actual id on the controller.
1017 * prepare a command for the scsi physical devices. This rountine prepares
1018 * commands for devices which can take extended CDBs (>10 bytes)
1020 static mega_ext_passthru
*
1021 mega_prepare_extpassthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
1022 int channel
, int target
)
1024 mega_ext_passthru
*epthru
;
1026 epthru
= scb
->epthru
;
1027 memset(epthru
, 0, sizeof(mega_ext_passthru
));
1029 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1030 epthru
->timeout
= 2;
1033 epthru
->reqsenselen
= 14;
1034 epthru
->islogical
= 0;
1036 epthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
1037 epthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
1038 (channel
<< 4) | target
: target
;
1040 epthru
->cdblen
= cmd
->cmd_len
;
1041 epthru
->logdrv
= cmd
->device
->lun
;
1043 memcpy(epthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1045 /* Not sure about the direction */
1046 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
1048 switch(cmd
->cmnd
[0]) {
1051 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
1054 "scsi%d: scanning scsi channel %d [P%d] ",
1055 adapter
->host
->host_no
,
1056 cmd
->device
->channel
, channel
);
1057 printk("for physical devices.\n");
1059 adapter
->flag
|= (1L << cmd
->device
->channel
);
1063 epthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
1064 &epthru
->dataxferaddr
, &epthru
->dataxferlen
);
1072 __mega_runpendq(adapter_t
*adapter
)
1075 struct list_head
*pos
, *next
;
1077 /* Issue any pending commands to the card */
1078 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
1080 scb
= list_entry(pos
, scb_t
, list
);
1082 if( !(scb
->state
& SCB_ISSUED
) ) {
1084 if( issue_scb(adapter
, scb
) != 0 )
1095 * @adapter - pointer to our soft state
1096 * @scb - scsi control block
1098 * Post a command to the card if the mailbox is available, otherwise return
1099 * busy. We also take the scb from the pending list if the mailbox is
1103 issue_scb(adapter_t
*adapter
, scb_t
*scb
)
1105 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1106 volatile mbox_t
*mbox
= adapter
->mbox
;
1109 if(unlikely(mbox
->m_in
.busy
)) {
1113 } while( mbox
->m_in
.busy
&& (i
< max_mbox_busy_wait
) );
1115 if(mbox
->m_in
.busy
) return -1;
1118 /* Copy mailbox data into host structure */
1119 memcpy((char *)&mbox
->m_out
, (char *)scb
->raw_mbox
,
1120 sizeof(struct mbox_out
));
1122 mbox
->m_out
.cmdid
= scb
->idx
; /* Set cmdid */
1123 mbox
->m_in
.busy
= 1; /* Set busy */
1127 * Increment the pending queue counter
1129 atomic_inc(&adapter
->pend_cmds
);
1131 switch (mbox
->m_out
.cmd
) {
1132 case MEGA_MBOXCMD_LREAD64
:
1133 case MEGA_MBOXCMD_LWRITE64
:
1134 case MEGA_MBOXCMD_PASSTHRU64
:
1135 case MEGA_MBOXCMD_EXTPTHRU
:
1136 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1137 mbox64
->xfer_segment_hi
= 0;
1138 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1141 mbox64
->xfer_segment_lo
= 0;
1142 mbox64
->xfer_segment_hi
= 0;
1148 scb
->state
|= SCB_ISSUED
;
1150 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1151 mbox
->m_in
.poll
= 0;
1153 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1156 irq_enable(adapter
);
1157 issue_command(adapter
);
1164 * Wait until the controller's mailbox is available
1167 mega_busywait_mbox (adapter_t
*adapter
)
1169 if (adapter
->mbox
->m_in
.busy
)
1170 return __mega_busywait_mbox(adapter
);
1176 * @adapter - pointer to our soft state
1177 * @raw_mbox - the mailbox
1179 * Issue a scb in synchronous and non-interrupt mode
1182 issue_scb_block(adapter_t
*adapter
, u_char
*raw_mbox
)
1184 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1185 volatile mbox_t
*mbox
= adapter
->mbox
;
1188 /* Wait until mailbox is free */
1189 if(mega_busywait_mbox (adapter
))
1190 goto bug_blocked_mailbox
;
1192 /* Copy mailbox data into host structure */
1193 memcpy((char *) mbox
, raw_mbox
, sizeof(struct mbox_out
));
1194 mbox
->m_out
.cmdid
= 0xFE;
1195 mbox
->m_in
.busy
= 1;
1197 switch (raw_mbox
[0]) {
1198 case MEGA_MBOXCMD_LREAD64
:
1199 case MEGA_MBOXCMD_LWRITE64
:
1200 case MEGA_MBOXCMD_PASSTHRU64
:
1201 case MEGA_MBOXCMD_EXTPTHRU
:
1202 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1203 mbox64
->xfer_segment_hi
= 0;
1204 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1207 mbox64
->xfer_segment_lo
= 0;
1208 mbox64
->xfer_segment_hi
= 0;
1211 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1212 mbox
->m_in
.poll
= 0;
1214 mbox
->m_in
.numstatus
= 0xFF;
1215 mbox
->m_in
.status
= 0xFF;
1216 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1218 while((volatile u8
)mbox
->m_in
.numstatus
== 0xFF)
1221 mbox
->m_in
.numstatus
= 0xFF;
1223 while( (volatile u8
)mbox
->m_in
.poll
!= 0x77 )
1226 mbox
->m_in
.poll
= 0;
1227 mbox
->m_in
.ack
= 0x77;
1229 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x2);
1231 while(RDINDOOR(adapter
) & 0x2)
1235 irq_disable(adapter
);
1236 issue_command(adapter
);
1238 while (!((byte
= irq_state(adapter
)) & INTR_VALID
))
1241 set_irq_state(adapter
, byte
);
1242 irq_enable(adapter
);
1246 return mbox
->m_in
.status
;
1248 bug_blocked_mailbox
:
1249 printk(KERN_WARNING
"megaraid: Blocked mailbox......!!\n");
1256 * megaraid_isr_iomapped()
1258 * @devp - pointer to our soft state
1260 * Interrupt service routine for io-mapped controllers.
1261 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1262 * and service the completed commands.
1265 megaraid_isr_iomapped(int irq
, void *devp
)
1267 adapter_t
*adapter
= devp
;
1268 unsigned long flags
;
1271 u8 completed
[MAX_FIRMWARE_STATUS
];
1277 * loop till F/W has more commands for us to complete.
1279 spin_lock_irqsave(&adapter
->lock
, flags
);
1282 /* Check if a valid interrupt is pending */
1283 byte
= irq_state(adapter
);
1284 if( (byte
& VALID_INTR_BYTE
) == 0 ) {
1286 * No more pending commands
1290 set_irq_state(adapter
, byte
);
1292 while((nstatus
= (volatile u8
)adapter
->mbox
->m_in
.numstatus
)
1295 adapter
->mbox
->m_in
.numstatus
= 0xFF;
1297 status
= adapter
->mbox
->m_in
.status
;
1300 * decrement the pending queue counter
1302 atomic_sub(nstatus
, &adapter
->pend_cmds
);
1304 memcpy(completed
, (void *)adapter
->mbox
->m_in
.completed
,
1307 /* Acknowledge interrupt */
1310 mega_cmd_done(adapter
, completed
, nstatus
, status
);
1312 mega_rundoneq(adapter
);
1316 /* Loop through any pending requests */
1317 if(atomic_read(&adapter
->quiescent
) == 0) {
1318 mega_runpendq(adapter
);
1325 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1327 return IRQ_RETVAL(handled
);
1332 * megaraid_isr_memmapped()
1334 * @devp - pointer to our soft state
1336 * Interrupt service routine for memory-mapped controllers.
1337 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1338 * and service the completed commands.
1341 megaraid_isr_memmapped(int irq
, void *devp
)
1343 adapter_t
*adapter
= devp
;
1344 unsigned long flags
;
1348 u8 completed
[MAX_FIRMWARE_STATUS
];
1353 * loop till F/W has more commands for us to complete.
1355 spin_lock_irqsave(&adapter
->lock
, flags
);
1358 /* Check if a valid interrupt is pending */
1359 dword
= RDOUTDOOR(adapter
);
1360 if(dword
!= 0x10001234) {
1362 * No more pending commands
1366 WROUTDOOR(adapter
, 0x10001234);
1368 while((nstatus
= (volatile u8
)adapter
->mbox
->m_in
.numstatus
)
1372 adapter
->mbox
->m_in
.numstatus
= 0xFF;
1374 status
= adapter
->mbox
->m_in
.status
;
1377 * decrement the pending queue counter
1379 atomic_sub(nstatus
, &adapter
->pend_cmds
);
1381 memcpy(completed
, (void *)adapter
->mbox
->m_in
.completed
,
1384 /* Acknowledge interrupt */
1385 WRINDOOR(adapter
, 0x2);
1389 while( RDINDOOR(adapter
) & 0x02 ) cpu_relax();
1391 mega_cmd_done(adapter
, completed
, nstatus
, status
);
1393 mega_rundoneq(adapter
);
1395 /* Loop through any pending requests */
1396 if(atomic_read(&adapter
->quiescent
) == 0) {
1397 mega_runpendq(adapter
);
1404 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1406 return IRQ_RETVAL(handled
);
1410 * @adapter - pointer to our soft state
1411 * @completed - array of ids of completed commands
1412 * @nstatus - number of completed commands
1413 * @status - status of the last command completed
1415 * Complete the comamnds and call the scsi mid-layer callback hooks.
1418 mega_cmd_done(adapter_t
*adapter
, u8 completed
[], int nstatus
, int status
)
1420 mega_ext_passthru
*epthru
= NULL
;
1421 struct scatterlist
*sgl
;
1422 Scsi_Cmnd
*cmd
= NULL
;
1423 mega_passthru
*pthru
= NULL
;
1424 mbox_t
*mbox
= NULL
;
1432 * for all the commands completed, call the mid-layer callback routine
1435 for( i
= 0; i
< nstatus
; i
++ ) {
1437 cmdid
= completed
[i
];
1439 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1440 scb
= &adapter
->int_scb
;
1442 mbox
= (mbox_t
*)scb
->raw_mbox
;
1445 * Internal command interface do not fire the extended
1446 * passthru or 64-bit passthru
1452 scb
= &adapter
->scb_list
[cmdid
];
1455 * Make sure f/w has completed a valid command
1457 if( !(scb
->state
& SCB_ISSUED
) || scb
->cmd
== NULL
) {
1459 "megaraid: invalid command ");
1460 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1461 cmdid
, scb
->state
, scb
->cmd
);
1467 * Was a abort issued for this command
1469 if( scb
->state
& SCB_ABORT
) {
1472 "megaraid: aborted cmd %lx[%x] complete.\n",
1473 scb
->cmd
->serial_number
, scb
->idx
);
1475 scb
->cmd
->result
= (DID_ABORT
<< 16);
1477 list_add_tail(SCSI_LIST(scb
->cmd
),
1478 &adapter
->completed_list
);
1480 mega_free_scb(adapter
, scb
);
1486 * Was a reset issued for this command
1488 if( scb
->state
& SCB_RESET
) {
1491 "megaraid: reset cmd %lx[%x] complete.\n",
1492 scb
->cmd
->serial_number
, scb
->idx
);
1494 scb
->cmd
->result
= (DID_RESET
<< 16);
1496 list_add_tail(SCSI_LIST(scb
->cmd
),
1497 &adapter
->completed_list
);
1499 mega_free_scb (adapter
, scb
);
1506 epthru
= scb
->epthru
;
1507 mbox
= (mbox_t
*)scb
->raw_mbox
;
1512 int logdrv
= mbox
->m_out
.logdrv
;
1514 islogical
= adapter
->logdrv_chan
[cmd
->channel
];
1516 * Maintain an error counter for the logical drive.
1517 * Some application like SNMP agent need such
1520 if( status
&& islogical
&& (cmd
->cmnd
[0] == READ_6
||
1521 cmd
->cmnd
[0] == READ_10
||
1522 cmd
->cmnd
[0] == READ_12
)) {
1524 * Logical drive number increases by 0x80 when
1525 * a logical drive is deleted
1527 adapter
->rd_errors
[logdrv
%0x80]++;
1530 if( status
&& islogical
&& (cmd
->cmnd
[0] == WRITE_6
||
1531 cmd
->cmnd
[0] == WRITE_10
||
1532 cmd
->cmnd
[0] == WRITE_12
)) {
1534 * Logical drive number increases by 0x80 when
1535 * a logical drive is deleted
1537 adapter
->wr_errors
[logdrv
%0x80]++;
1545 * Do not return the presence of hard disk on the channel so,
1546 * inquiry sent, and returned data==hard disk or removable
1547 * hard disk and not logical, request should return failure! -
1550 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
1551 if( cmd
->cmnd
[0] == INQUIRY
&& !islogical
) {
1554 sgl
= (struct scatterlist
*)
1555 cmd
->request_buffer
;
1558 c
= *(unsigned char *)
1559 page_address((&sgl
[0])->page
) +
1564 "megaraid: invalid sg.\n");
1569 c
= *(u8
*)cmd
->request_buffer
;
1572 if(IS_RAID_CH(adapter
, cmd
->device
->channel
) &&
1573 ((c
& 0x1F ) == TYPE_DISK
)) {
1578 /* clear result; otherwise, success returns corrupt value */
1581 /* Convert MegaRAID status to Linux error code */
1583 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1584 cmd
->result
|= (DID_OK
<< 16);
1587 case 0x02: /* ERROR_ABORTED, i.e.
1588 SCSI_STATUS_CHECK_CONDITION */
1590 /* set sense_buffer and result fields */
1591 if( mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU
||
1592 mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU64
) {
1594 memcpy(cmd
->sense_buffer
, pthru
->reqsensearea
,
1597 cmd
->result
= (DRIVER_SENSE
<< 24) |
1599 (CHECK_CONDITION
<< 1);
1602 if (mbox
->m_out
.cmd
== MEGA_MBOXCMD_EXTPTHRU
) {
1604 memcpy(cmd
->sense_buffer
,
1605 epthru
->reqsensearea
, 14);
1607 cmd
->result
= (DRIVER_SENSE
<< 24) |
1609 (CHECK_CONDITION
<< 1);
1611 cmd
->sense_buffer
[0] = 0x70;
1612 cmd
->sense_buffer
[2] = ABORTED_COMMAND
;
1613 cmd
->result
|= (CHECK_CONDITION
<< 1);
1618 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1620 cmd
->result
|= (DID_BUS_BUSY
<< 16) | status
;
1624 #if MEGA_HAVE_CLUSTERING
1626 * If TEST_UNIT_READY fails, we know
1627 * MEGA_RESERVATION_STATUS failed
1629 if( cmd
->cmnd
[0] == TEST_UNIT_READY
) {
1630 cmd
->result
|= (DID_ERROR
<< 16) |
1631 (RESERVATION_CONFLICT
<< 1);
1635 * Error code returned is 1 if Reserve or Release
1636 * failed or the input parameter is invalid
1639 (cmd
->cmnd
[0] == RESERVE
||
1640 cmd
->cmnd
[0] == RELEASE
) ) {
1642 cmd
->result
|= (DID_ERROR
<< 16) |
1643 (RESERVATION_CONFLICT
<< 1);
1647 cmd
->result
|= (DID_BAD_TARGET
<< 16)|status
;
1651 * Only free SCBs for the commands coming down from the
1652 * mid-layer, not for which were issued internally
1654 * For internal command, restore the status returned by the
1655 * firmware so that user can interpret it.
1657 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1658 cmd
->result
= status
;
1661 * Remove the internal command from the pending list
1663 list_del_init(&scb
->list
);
1664 scb
->state
= SCB_FREE
;
1667 mega_free_scb(adapter
, scb
);
1670 /* Add Scsi_Command to end of completed queue */
1671 list_add_tail(SCSI_LIST(cmd
), &adapter
->completed_list
);
1679 * Run through the list of completed requests and finish it
1682 mega_rundoneq (adapter_t
*adapter
)
1685 struct list_head
*pos
;
1687 list_for_each(pos
, &adapter
->completed_list
) {
1689 struct scsi_pointer
* spos
= (struct scsi_pointer
*)pos
;
1691 cmd
= list_entry(spos
, Scsi_Cmnd
, SCp
);
1692 cmd
->scsi_done(cmd
);
1695 INIT_LIST_HEAD(&adapter
->completed_list
);
1700 * Free a SCB structure
1701 * Note: We assume the scsi commands associated with this scb is not free yet.
1704 mega_free_scb(adapter_t
*adapter
, scb_t
*scb
)
1706 unsigned long length
;
1708 switch( scb
->dma_type
) {
1710 case MEGA_DMA_TYPE_NONE
:
1713 case MEGA_BULK_DATA
:
1714 if (scb
->cmd
->use_sg
== 0)
1715 length
= scb
->cmd
->request_bufflen
;
1717 struct scatterlist
*sgl
=
1718 (struct scatterlist
*)scb
->cmd
->request_buffer
;
1719 length
= sgl
->length
;
1721 pci_unmap_page(adapter
->dev
, scb
->dma_h_bulkdata
,
1722 length
, scb
->dma_direction
);
1726 pci_unmap_sg(adapter
->dev
, scb
->cmd
->request_buffer
,
1727 scb
->cmd
->use_sg
, scb
->dma_direction
);
1735 * Remove from the pending list
1737 list_del_init(&scb
->list
);
1739 /* Link the scb back into free list */
1740 scb
->state
= SCB_FREE
;
1743 list_add(&scb
->list
, &adapter
->free_list
);
1748 __mega_busywait_mbox (adapter_t
*adapter
)
1750 volatile mbox_t
*mbox
= adapter
->mbox
;
1753 for (counter
= 0; counter
< 10000; counter
++) {
1754 if (!mbox
->m_in
.busy
)
1756 udelay(100); yield();
1758 return -1; /* give up after 1 second */
1762 * Copies data to SGLIST
1763 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1766 mega_build_sglist(adapter_t
*adapter
, scb_t
*scb
, u32
*buf
, u32
*len
)
1768 struct scatterlist
*sgl
;
1770 unsigned long offset
;
1771 unsigned int length
;
1778 /* Scatter-gather not used */
1779 if( cmd
->use_sg
== 0 || (cmd
->use_sg
== 1 &&
1780 !adapter
->has_64bit_addr
)) {
1782 if (cmd
->use_sg
== 0) {
1783 page
= virt_to_page(cmd
->request_buffer
);
1784 offset
= offset_in_page(cmd
->request_buffer
);
1785 length
= cmd
->request_bufflen
;
1787 sgl
= (struct scatterlist
*)cmd
->request_buffer
;
1789 offset
= sgl
->offset
;
1790 length
= sgl
->length
;
1793 scb
->dma_h_bulkdata
= pci_map_page(adapter
->dev
,
1796 scb
->dma_direction
);
1797 scb
->dma_type
= MEGA_BULK_DATA
;
1800 * We need to handle special 64-bit commands that need a
1803 if( adapter
->has_64bit_addr
) {
1804 scb
->sgl64
[0].address
= scb
->dma_h_bulkdata
;
1805 scb
->sgl64
[0].length
= length
;
1806 *buf
= (u32
)scb
->sgl_dma_addr
;
1811 *buf
= (u32
)scb
->dma_h_bulkdata
;
1817 sgl
= (struct scatterlist
*)cmd
->request_buffer
;
1820 * Copy Scatter-Gather list info into controller structure.
1822 * The number of sg elements returned must not exceed our limit
1824 sgcnt
= pci_map_sg(adapter
->dev
, sgl
, cmd
->use_sg
,
1825 scb
->dma_direction
);
1827 scb
->dma_type
= MEGA_SGLIST
;
1829 BUG_ON(sgcnt
> adapter
->sglen
);
1833 for( idx
= 0; idx
< sgcnt
; idx
++, sgl
++ ) {
1835 if( adapter
->has_64bit_addr
) {
1836 scb
->sgl64
[idx
].address
= sg_dma_address(sgl
);
1837 *len
+= scb
->sgl64
[idx
].length
= sg_dma_len(sgl
);
1840 scb
->sgl
[idx
].address
= sg_dma_address(sgl
);
1841 *len
+= scb
->sgl
[idx
].length
= sg_dma_len(sgl
);
1845 /* Reset pointer and length fields */
1846 *buf
= scb
->sgl_dma_addr
;
1848 /* Return count of SG requests */
1856 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1857 * Enquiry3 structures for later use
1860 mega_8_to_40ld(mraid_inquiry
*inquiry
, mega_inquiry3
*enquiry3
,
1861 mega_product_info
*product_info
)
1865 product_info
->max_commands
= inquiry
->adapter_info
.max_commands
;
1866 enquiry3
->rebuild_rate
= inquiry
->adapter_info
.rebuild_rate
;
1867 product_info
->nchannels
= inquiry
->adapter_info
.nchannels
;
1869 for (i
= 0; i
< 4; i
++) {
1870 product_info
->fw_version
[i
] =
1871 inquiry
->adapter_info
.fw_version
[i
];
1873 product_info
->bios_version
[i
] =
1874 inquiry
->adapter_info
.bios_version
[i
];
1876 enquiry3
->cache_flush_interval
=
1877 inquiry
->adapter_info
.cache_flush_interval
;
1879 product_info
->dram_size
= inquiry
->adapter_info
.dram_size
;
1881 enquiry3
->num_ldrv
= inquiry
->logdrv_info
.num_ldrv
;
1883 for (i
= 0; i
< MAX_LOGICAL_DRIVES_8LD
; i
++) {
1884 enquiry3
->ldrv_size
[i
] = inquiry
->logdrv_info
.ldrv_size
[i
];
1885 enquiry3
->ldrv_prop
[i
] = inquiry
->logdrv_info
.ldrv_prop
[i
];
1886 enquiry3
->ldrv_state
[i
] = inquiry
->logdrv_info
.ldrv_state
[i
];
1889 for (i
= 0; i
< (MAX_PHYSICAL_DRIVES
); i
++)
1890 enquiry3
->pdrv_state
[i
] = inquiry
->pdrv_info
.pdrv_state
[i
];
1894 mega_free_sgl(adapter_t
*adapter
)
1899 for(i
= 0; i
< adapter
->max_cmds
; i
++) {
1901 scb
= &adapter
->scb_list
[i
];
1904 pci_free_consistent(adapter
->dev
,
1905 sizeof(mega_sgl64
) * adapter
->sglen
,
1913 pci_free_consistent(adapter
->dev
, sizeof(mega_passthru
),
1914 scb
->pthru
, scb
->pthru_dma_addr
);
1920 pci_free_consistent(adapter
->dev
,
1921 sizeof(mega_ext_passthru
),
1922 scb
->epthru
, scb
->epthru_dma_addr
);
1932 * Get information about the card/driver
1935 megaraid_info(struct Scsi_Host
*host
)
1937 static char buffer
[512];
1940 adapter
= (adapter_t
*)host
->hostdata
;
1943 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1944 adapter
->fw_version
, adapter
->product_info
.max_commands
,
1945 adapter
->host
->max_id
, adapter
->host
->max_channel
,
1946 adapter
->host
->max_lun
);
1951 * Abort a previous SCSI request. Only commands on the pending list can be
1952 * aborted. All the commands issued to the F/W must complete.
1955 megaraid_abort(Scsi_Cmnd
*cmd
)
1960 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1962 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_ABORT
);
1965 * This is required here to complete any completed requests
1966 * to be communicated over to the mid layer.
1968 mega_rundoneq(adapter
);
1975 megaraid_reset(struct scsi_cmnd
*cmd
)
1981 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1983 #if MEGA_HAVE_CLUSTERING
1984 mc
.cmd
= MEGA_CLUSTER_CMD
;
1985 mc
.opcode
= MEGA_RESET_RESERVATIONS
;
1987 if( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
1989 "megaraid: reservation reset failed.\n");
1992 printk(KERN_INFO
"megaraid: reservation reset.\n");
1996 spin_lock_irq(&adapter
->lock
);
1998 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_RESET
);
2001 * This is required here to complete any completed requests
2002 * to be communicated over to the mid layer.
2004 mega_rundoneq(adapter
);
2005 spin_unlock_irq(&adapter
->lock
);
2011 * megaraid_abort_and_reset()
2012 * @adapter - megaraid soft state
2013 * @cmd - scsi command to be aborted or reset
2014 * @aor - abort or reset flag
2016 * Try to locate the scsi command in the pending queue. If found and is not
2017 * issued to the controller, abort/reset it. Otherwise return failure
2020 megaraid_abort_and_reset(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int aor
)
2022 struct list_head
*pos
, *next
;
2025 printk(KERN_WARNING
"megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
2026 (aor
== SCB_ABORT
)? "ABORTING":"RESET", cmd
->serial_number
,
2027 cmd
->cmnd
[0], cmd
->device
->channel
,
2028 cmd
->device
->id
, cmd
->device
->lun
);
2030 if(list_empty(&adapter
->pending_list
))
2033 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
2035 scb
= list_entry(pos
, scb_t
, list
);
2037 if (scb
->cmd
== cmd
) { /* Found command */
2042 * Check if this command has firmare owenership. If
2043 * yes, we cannot reset this command. Whenever, f/w
2044 * completes this command, we will return appropriate
2047 if( scb
->state
& SCB_ISSUED
) {
2050 "megaraid: %s-%lx[%x], fw owner.\n",
2051 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
2052 cmd
->serial_number
, scb
->idx
);
2059 * Not yet issued! Remove from the pending
2063 "megaraid: %s-%lx[%x], driver owner.\n",
2064 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
2065 cmd
->serial_number
, scb
->idx
);
2067 mega_free_scb(adapter
, scb
);
2069 if( aor
== SCB_ABORT
) {
2070 cmd
->result
= (DID_ABORT
<< 16);
2073 cmd
->result
= (DID_RESET
<< 16);
2076 list_add_tail(SCSI_LIST(cmd
),
2077 &adapter
->completed_list
);
2088 make_local_pdev(adapter_t
*adapter
, struct pci_dev
**pdev
)
2090 *pdev
= kmalloc(sizeof(struct pci_dev
), GFP_KERNEL
);
2092 if( *pdev
== NULL
) return -1;
2094 memcpy(*pdev
, adapter
->dev
, sizeof(struct pci_dev
));
2096 if( pci_set_dma_mask(*pdev
, DMA_32BIT_MASK
) != 0 ) {
2105 free_local_pdev(struct pci_dev
*pdev
)
2111 * mega_allocate_inquiry()
2112 * @dma_handle - handle returned for dma address
2113 * @pdev - handle to pci device
2115 * allocates memory for inquiry structure
2117 static inline void *
2118 mega_allocate_inquiry(dma_addr_t
*dma_handle
, struct pci_dev
*pdev
)
2120 return pci_alloc_consistent(pdev
, sizeof(mega_inquiry3
), dma_handle
);
2125 mega_free_inquiry(void *inquiry
, dma_addr_t dma_handle
, struct pci_dev
*pdev
)
2127 pci_free_consistent(pdev
, sizeof(mega_inquiry3
), inquiry
, dma_handle
);
2131 #ifdef CONFIG_PROC_FS
2132 /* Following code handles /proc fs */
2134 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2135 S_IRUSR | S_IFREG, \
2136 controller_proc_dir_entry, \
2140 * mega_create_proc_entry()
2141 * @index - index in soft state array
2142 * @parent - parent node for this /proc entry
2144 * Creates /proc entries for our controllers.
2147 mega_create_proc_entry(int index
, struct proc_dir_entry
*parent
)
2149 struct proc_dir_entry
*controller_proc_dir_entry
= NULL
;
2150 u8 string
[64] = { 0 };
2151 adapter_t
*adapter
= hba_soft_state
[index
];
2153 sprintf(string
, "hba%d", adapter
->host
->host_no
);
2155 controller_proc_dir_entry
=
2156 adapter
->controller_proc_dir_entry
= proc_mkdir(string
, parent
);
2158 if(!controller_proc_dir_entry
) {
2159 printk(KERN_WARNING
"\nmegaraid: proc_mkdir failed\n");
2162 adapter
->proc_read
= CREATE_READ_PROC("config", proc_read_config
);
2163 adapter
->proc_stat
= CREATE_READ_PROC("stat", proc_read_stat
);
2164 adapter
->proc_mbox
= CREATE_READ_PROC("mailbox", proc_read_mbox
);
2165 #if MEGA_HAVE_ENH_PROC
2166 adapter
->proc_rr
= CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate
);
2167 adapter
->proc_battery
= CREATE_READ_PROC("battery-status",
2171 * Display each physical drive on its channel
2173 adapter
->proc_pdrvstat
[0] = CREATE_READ_PROC("diskdrives-ch0",
2175 adapter
->proc_pdrvstat
[1] = CREATE_READ_PROC("diskdrives-ch1",
2177 adapter
->proc_pdrvstat
[2] = CREATE_READ_PROC("diskdrives-ch2",
2179 adapter
->proc_pdrvstat
[3] = CREATE_READ_PROC("diskdrives-ch3",
2183 * Display a set of up to 10 logical drive through each of following
2186 adapter
->proc_rdrvstat
[0] = CREATE_READ_PROC("raiddrives-0-9",
2188 adapter
->proc_rdrvstat
[1] = CREATE_READ_PROC("raiddrives-10-19",
2190 adapter
->proc_rdrvstat
[2] = CREATE_READ_PROC("raiddrives-20-29",
2192 adapter
->proc_rdrvstat
[3] = CREATE_READ_PROC("raiddrives-30-39",
2199 * proc_read_config()
2200 * @page - buffer to write the data in
2201 * @start - where the actual data has been written in page
2202 * @offset - same meaning as the read system call
2203 * @count - same meaning as the read system call
2204 * @eof - set if no more data needs to be returned
2205 * @data - pointer to our soft state
2207 * Display configuration information about the controller.
2210 proc_read_config(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2214 adapter_t
*adapter
= (adapter_t
*)data
;
2217 len
+= sprintf(page
+len
, "%s", MEGARAID_VERSION
);
2219 if(adapter
->product_info
.product_name
[0])
2220 len
+= sprintf(page
+len
, "%s\n",
2221 adapter
->product_info
.product_name
);
2223 len
+= sprintf(page
+len
, "Controller Type: ");
2225 if( adapter
->flag
& BOARD_MEMMAP
) {
2226 len
+= sprintf(page
+len
,
2227 "438/466/467/471/493/518/520/531/532\n");
2230 len
+= sprintf(page
+len
,
2234 if(adapter
->flag
& BOARD_40LD
) {
2235 len
+= sprintf(page
+len
,
2236 "Controller Supports 40 Logical Drives\n");
2239 if(adapter
->flag
& BOARD_64BIT
) {
2240 len
+= sprintf(page
+len
,
2241 "Controller capable of 64-bit memory addressing\n");
2243 if( adapter
->has_64bit_addr
) {
2244 len
+= sprintf(page
+len
,
2245 "Controller using 64-bit memory addressing\n");
2248 len
+= sprintf(page
+len
,
2249 "Controller is not using 64-bit memory addressing\n");
2252 len
+= sprintf(page
+len
, "Base = %08lx, Irq = %d, ", adapter
->base
,
2253 adapter
->host
->irq
);
2255 len
+= sprintf(page
+len
, "Logical Drives = %d, Channels = %d\n",
2256 adapter
->numldrv
, adapter
->product_info
.nchannels
);
2258 len
+= sprintf(page
+len
, "Version =%s:%s, DRAM = %dMb\n",
2259 adapter
->fw_version
, adapter
->bios_version
,
2260 adapter
->product_info
.dram_size
);
2262 len
+= sprintf(page
+len
,
2263 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2264 adapter
->product_info
.max_commands
, adapter
->max_cmds
);
2266 len
+= sprintf(page
+len
, "support_ext_cdb = %d\n",
2267 adapter
->support_ext_cdb
);
2268 len
+= sprintf(page
+len
, "support_random_del = %d\n",
2269 adapter
->support_random_del
);
2270 len
+= sprintf(page
+len
, "boot_ldrv_enabled = %d\n",
2271 adapter
->boot_ldrv_enabled
);
2272 len
+= sprintf(page
+len
, "boot_ldrv = %d\n",
2273 adapter
->boot_ldrv
);
2274 len
+= sprintf(page
+len
, "boot_pdrv_enabled = %d\n",
2275 adapter
->boot_pdrv_enabled
);
2276 len
+= sprintf(page
+len
, "boot_pdrv_ch = %d\n",
2277 adapter
->boot_pdrv_ch
);
2278 len
+= sprintf(page
+len
, "boot_pdrv_tgt = %d\n",
2279 adapter
->boot_pdrv_tgt
);
2280 len
+= sprintf(page
+len
, "quiescent = %d\n",
2281 atomic_read(&adapter
->quiescent
));
2282 len
+= sprintf(page
+len
, "has_cluster = %d\n",
2283 adapter
->has_cluster
);
2285 len
+= sprintf(page
+len
, "\nModule Parameters:\n");
2286 len
+= sprintf(page
+len
, "max_cmd_per_lun = %d\n",
2288 len
+= sprintf(page
+len
, "max_sectors_per_io = %d\n",
2289 max_sectors_per_io
);
2300 * @page - buffer to write the data in
2301 * @start - where the actual data has been written in page
2302 * @offset - same meaning as the read system call
2303 * @count - same meaning as the read system call
2304 * @eof - set if no more data needs to be returned
2305 * @data - pointer to our soft state
2307 * Diaplay statistical information about the I/O activity.
2310 proc_read_stat(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2317 i
= 0; /* avoid compilation warnings */
2319 adapter
= (adapter_t
*)data
;
2321 len
= sprintf(page
, "Statistical Information for this controller\n");
2322 len
+= sprintf(page
+len
, "pend_cmds = %d\n",
2323 atomic_read(&adapter
->pend_cmds
));
2325 for(i
= 0; i
< adapter
->numldrv
; i
++) {
2326 len
+= sprintf(page
+len
, "Logical Drive %d:\n", i
);
2328 len
+= sprintf(page
+len
,
2329 "\tReads Issued = %lu, Writes Issued = %lu\n",
2330 adapter
->nreads
[i
], adapter
->nwrites
[i
]);
2332 len
+= sprintf(page
+len
,
2333 "\tSectors Read = %lu, Sectors Written = %lu\n",
2334 adapter
->nreadblocks
[i
], adapter
->nwriteblocks
[i
]);
2336 len
+= sprintf(page
+len
,
2337 "\tRead errors = %lu, Write errors = %lu\n\n",
2338 adapter
->rd_errors
[i
], adapter
->wr_errors
[i
]);
2341 len
+= sprintf(page
+len
,
2342 "IO and error counters not compiled in driver.\n");
2353 * @page - buffer to write the data in
2354 * @start - where the actual data has been written in page
2355 * @offset - same meaning as the read system call
2356 * @count - same meaning as the read system call
2357 * @eof - set if no more data needs to be returned
2358 * @data - pointer to our soft state
2360 * Display mailbox information for the last command issued. This information
2361 * is good for debugging.
2364 proc_read_mbox(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2368 adapter_t
*adapter
= (adapter_t
*)data
;
2369 volatile mbox_t
*mbox
= adapter
->mbox
;
2372 len
= sprintf(page
, "Contents of Mail Box Structure\n");
2373 len
+= sprintf(page
+len
, " Fw Command = 0x%02x\n",
2375 len
+= sprintf(page
+len
, " Cmd Sequence = 0x%02x\n",
2377 len
+= sprintf(page
+len
, " No of Sectors= %04d\n",
2378 mbox
->m_out
.numsectors
);
2379 len
+= sprintf(page
+len
, " LBA = 0x%02x\n",
2381 len
+= sprintf(page
+len
, " DTA = 0x%08x\n",
2382 mbox
->m_out
.xferaddr
);
2383 len
+= sprintf(page
+len
, " Logical Drive= 0x%02x\n",
2384 mbox
->m_out
.logdrv
);
2385 len
+= sprintf(page
+len
, " No of SG Elmt= 0x%02x\n",
2386 mbox
->m_out
.numsgelements
);
2387 len
+= sprintf(page
+len
, " Busy = %01x\n",
2389 len
+= sprintf(page
+len
, " Status = 0x%02x\n",
2399 * proc_rebuild_rate()
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 current rebuild rate
2410 proc_rebuild_rate(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
;
2419 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2424 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2425 free_local_pdev(pdev
);
2430 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2432 len
= sprintf(page
, "Adapter inquiry failed.\n");
2434 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2436 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2438 free_local_pdev(pdev
);
2445 if( adapter
->flag
& BOARD_40LD
) {
2446 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2447 ((mega_inquiry3
*)inquiry
)->rebuild_rate
);
2450 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2451 ((mraid_ext_inquiry
*)
2452 inquiry
)->raid_inq
.adapter_info
.rebuild_rate
);
2456 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2458 free_local_pdev(pdev
);
2468 * @page - buffer to write the data in
2469 * @start - where the actual data has been written in page
2470 * @offset - same meaning as the read system call
2471 * @count - same meaning as the read system call
2472 * @eof - set if no more data needs to be returned
2473 * @data - pointer to our soft state
2475 * Display information about the battery module on the controller.
2478 proc_battery(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2481 adapter_t
*adapter
= (adapter_t
*)data
;
2482 dma_addr_t dma_handle
;
2484 struct pci_dev
*pdev
;
2485 u8 battery_status
= 0;
2489 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2494 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2495 free_local_pdev(pdev
);
2500 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2502 len
= sprintf(page
, "Adapter inquiry failed.\n");
2504 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2506 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2508 free_local_pdev(pdev
);
2515 if( adapter
->flag
& BOARD_40LD
) {
2516 battery_status
= ((mega_inquiry3
*)inquiry
)->battery_status
;
2519 battery_status
= ((mraid_ext_inquiry
*)inquiry
)->
2520 raid_inq
.adapter_info
.battery_status
;
2524 * Decode the battery status
2526 sprintf(str
, "Battery Status:[%d]", battery_status
);
2528 if(battery_status
== MEGA_BATT_CHARGE_DONE
)
2529 strcat(str
, " Charge Done");
2531 if(battery_status
& MEGA_BATT_MODULE_MISSING
)
2532 strcat(str
, " Module Missing");
2534 if(battery_status
& MEGA_BATT_LOW_VOLTAGE
)
2535 strcat(str
, " Low Voltage");
2537 if(battery_status
& MEGA_BATT_TEMP_HIGH
)
2538 strcat(str
, " Temperature High");
2540 if(battery_status
& MEGA_BATT_PACK_MISSING
)
2541 strcat(str
, " Pack Missing");
2543 if(battery_status
& MEGA_BATT_CHARGE_INPROG
)
2544 strcat(str
, " Charge In-progress");
2546 if(battery_status
& MEGA_BATT_CHARGE_FAIL
)
2547 strcat(str
, " Charge Fail");
2549 if(battery_status
& MEGA_BATT_CYCLES_EXCEEDED
)
2550 strcat(str
, " Cycles Exceeded");
2552 len
= sprintf(page
, "%s\n", str
);
2555 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2557 free_local_pdev(pdev
);
2567 * @page - buffer to write the data in
2568 * @start - where the actual data has been written in page
2569 * @offset - same meaning as the read system call
2570 * @count - same meaning as the read system call
2571 * @eof - set if no more data needs to be returned
2572 * @data - pointer to our soft state
2574 * Display information about the physical drives on physical channel 0.
2577 proc_pdrv_ch0(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2580 adapter_t
*adapter
= (adapter_t
*)data
;
2584 return (proc_pdrv(adapter
, page
, 0));
2590 * @page - buffer to write the data in
2591 * @start - where the actual data has been written in page
2592 * @offset - same meaning as the read system call
2593 * @count - same meaning as the read system call
2594 * @eof - set if no more data needs to be returned
2595 * @data - pointer to our soft state
2597 * Display information about the physical drives on physical channel 1.
2600 proc_pdrv_ch1(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2603 adapter_t
*adapter
= (adapter_t
*)data
;
2607 return (proc_pdrv(adapter
, page
, 1));
2613 * @page - buffer to write the data in
2614 * @start - where the actual data has been written in page
2615 * @offset - same meaning as the read system call
2616 * @count - same meaning as the read system call
2617 * @eof - set if no more data needs to be returned
2618 * @data - pointer to our soft state
2620 * Display information about the physical drives on physical channel 2.
2623 proc_pdrv_ch2(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2626 adapter_t
*adapter
= (adapter_t
*)data
;
2630 return (proc_pdrv(adapter
, page
, 2));
2636 * @page - buffer to write the data in
2637 * @start - where the actual data has been written in page
2638 * @offset - same meaning as the read system call
2639 * @count - same meaning as the read system call
2640 * @eof - set if no more data needs to be returned
2641 * @data - pointer to our soft state
2643 * Display information about the physical drives on physical channel 3.
2646 proc_pdrv_ch3(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2649 adapter_t
*adapter
= (adapter_t
*)data
;
2653 return (proc_pdrv(adapter
, page
, 3));
2659 * @page - buffer to write the data in
2660 * @adapter - pointer to our soft state
2662 * Display information about the physical drives.
2665 proc_pdrv(adapter_t
*adapter
, char *page
, int channel
)
2667 dma_addr_t dma_handle
;
2669 dma_addr_t scsi_inq_dma_handle
;
2671 struct pci_dev
*pdev
;
2680 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2684 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2688 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2689 len
= sprintf(page
, "Adapter inquiry failed.\n");
2691 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2697 scsi_inq
= pci_alloc_consistent(pdev
, 256, &scsi_inq_dma_handle
);
2699 if( scsi_inq
== NULL
) {
2700 len
= sprintf(page
, "memory not available for scsi inq.\n");
2705 if( adapter
->flag
& BOARD_40LD
) {
2706 pdrv_state
= ((mega_inquiry3
*)inquiry
)->pdrv_state
;
2709 pdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2710 raid_inq
.pdrv_info
.pdrv_state
;
2713 max_channels
= adapter
->product_info
.nchannels
;
2715 if( channel
>= max_channels
) {
2719 for( tgt
= 0; tgt
<= MAX_TARGET
; tgt
++ ) {
2721 i
= channel
*16 + tgt
;
2723 state
= *(pdrv_state
+ i
);
2725 switch( state
& 0x0F ) {
2729 "Channel:%2d Id:%2d State: Online",
2735 "Channel:%2d Id:%2d State: Failed",
2741 "Channel:%2d Id:%2d State: Rebuild",
2747 "Channel:%2d Id:%2d State: Hot spare",
2753 "Channel:%2d Id:%2d State: Un-configured",
2760 * This interface displays inquiries for disk drives
2761 * only. Inquries for logical drives and non-disk
2762 * devices are available through /proc/scsi/scsi
2764 memset(scsi_inq
, 0, 256);
2765 if( mega_internal_dev_inquiry(adapter
, channel
, tgt
,
2766 scsi_inq_dma_handle
) ||
2767 (scsi_inq
[0] & 0x1F) != TYPE_DISK
) {
2772 * Check for overflow. We print less than 240
2773 * characters for inquiry
2775 if( (len
+ 240) >= PAGE_SIZE
) break;
2777 len
+= sprintf(page
+len
, "%s.\n", str
);
2779 len
+= mega_print_inquiry(page
+len
, scsi_inq
);
2783 pci_free_consistent(pdev
, 256, scsi_inq
, scsi_inq_dma_handle
);
2785 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2787 free_local_pdev(pdev
);
2794 * Display scsi inquiry
2797 mega_print_inquiry(char *page
, char *scsi_inq
)
2802 len
= sprintf(page
, " Vendor: ");
2803 for( i
= 8; i
< 16; i
++ ) {
2804 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2807 len
+= sprintf(page
+len
, " Model: ");
2809 for( i
= 16; i
< 32; i
++ ) {
2810 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2813 len
+= sprintf(page
+len
, " Rev: ");
2815 for( i
= 32; i
< 36; i
++ ) {
2816 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2819 len
+= sprintf(page
+len
, "\n");
2821 i
= scsi_inq
[0] & 0x1f;
2823 len
+= sprintf(page
+len
, " Type: %s ", scsi_device_type(i
));
2825 len
+= sprintf(page
+len
,
2826 " ANSI SCSI revision: %02x", scsi_inq
[2] & 0x07);
2828 if( (scsi_inq
[2] & 0x07) == 1 && (scsi_inq
[3] & 0x0f) == 1 )
2829 len
+= sprintf(page
+len
, " CCS\n");
2831 len
+= sprintf(page
+len
, "\n");
2839 * @page - buffer to write the data in
2840 * @start - where the actual data has been written in page
2841 * @offset - same meaning as the read system call
2842 * @count - same meaning as the read system call
2843 * @eof - set if no more data needs to be returned
2844 * @data - pointer to our soft state
2846 * Display real time information about the logical drives 0 through 9.
2849 proc_rdrv_10(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2852 adapter_t
*adapter
= (adapter_t
*)data
;
2856 return (proc_rdrv(adapter
, page
, 0, 9));
2862 * @page - buffer to write the data in
2863 * @start - where the actual data has been written in page
2864 * @offset - same meaning as the read system call
2865 * @count - same meaning as the read system call
2866 * @eof - set if no more data needs to be returned
2867 * @data - pointer to our soft state
2869 * Display real time information about the logical drives 0 through 9.
2872 proc_rdrv_20(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2875 adapter_t
*adapter
= (adapter_t
*)data
;
2879 return (proc_rdrv(adapter
, page
, 10, 19));
2885 * @page - buffer to write the data in
2886 * @start - where the actual data has been written in page
2887 * @offset - same meaning as the read system call
2888 * @count - same meaning as the read system call
2889 * @eof - set if no more data needs to be returned
2890 * @data - pointer to our soft state
2892 * Display real time information about the logical drives 0 through 9.
2895 proc_rdrv_30(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2898 adapter_t
*adapter
= (adapter_t
*)data
;
2902 return (proc_rdrv(adapter
, page
, 20, 29));
2908 * @page - buffer to write the data in
2909 * @start - where the actual data has been written in page
2910 * @offset - same meaning as the read system call
2911 * @count - same meaning as the read system call
2912 * @eof - set if no more data needs to be returned
2913 * @data - pointer to our soft state
2915 * Display real time information about the logical drives 0 through 9.
2918 proc_rdrv_40(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2921 adapter_t
*adapter
= (adapter_t
*)data
;
2925 return (proc_rdrv(adapter
, page
, 30, 39));
2931 * @page - buffer to write the data in
2932 * @adapter - pointer to our soft state
2933 * @start - starting logical drive to display
2934 * @end - ending logical drive to display
2936 * We do not print the inquiry information since its already available through
2937 * /proc/scsi/scsi interface
2940 proc_rdrv(adapter_t
*adapter
, char *page
, int start
, int end
)
2942 dma_addr_t dma_handle
;
2943 logdrv_param
*lparam
;
2946 dma_addr_t disk_array_dma_handle
;
2948 struct pci_dev
*pdev
;
2955 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2959 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2960 free_local_pdev(pdev
);
2964 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2966 len
= sprintf(page
, "Adapter inquiry failed.\n");
2968 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2970 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2972 free_local_pdev(pdev
);
2977 memset(&mc
, 0, sizeof(megacmd_t
));
2979 if( adapter
->flag
& BOARD_40LD
) {
2980 array_sz
= sizeof(disk_array_40ld
);
2982 rdrv_state
= ((mega_inquiry3
*)inquiry
)->ldrv_state
;
2984 num_ldrv
= ((mega_inquiry3
*)inquiry
)->num_ldrv
;
2987 array_sz
= sizeof(disk_array_8ld
);
2989 rdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2990 raid_inq
.logdrv_info
.ldrv_state
;
2992 num_ldrv
= ((mraid_ext_inquiry
*)inquiry
)->
2993 raid_inq
.logdrv_info
.num_ldrv
;
2996 disk_array
= pci_alloc_consistent(pdev
, array_sz
,
2997 &disk_array_dma_handle
);
2999 if( disk_array
== NULL
) {
3000 len
= sprintf(page
, "memory not available.\n");
3002 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3004 free_local_pdev(pdev
);
3009 mc
.xferaddr
= (u32
)disk_array_dma_handle
;
3011 if( adapter
->flag
& BOARD_40LD
) {
3012 mc
.cmd
= FC_NEW_CONFIG
;
3013 mc
.opcode
= OP_DCMD_READ_CONFIG
;
3015 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
3017 len
= sprintf(page
, "40LD read config failed.\n");
3019 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3021 pci_free_consistent(pdev
, array_sz
, disk_array
,
3022 disk_array_dma_handle
);
3024 free_local_pdev(pdev
);
3031 mc
.cmd
= NEW_READ_CONFIG_8LD
;
3033 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
3035 mc
.cmd
= READ_CONFIG_8LD
;
3037 if( mega_internal_command(adapter
, &mc
,
3041 "8LD read config failed.\n");
3043 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3045 pci_free_consistent(pdev
, array_sz
,
3047 disk_array_dma_handle
);
3049 free_local_pdev(pdev
);
3056 for( i
= start
; i
< ( (end
+1 < num_ldrv
) ? end
+1 : num_ldrv
); i
++ ) {
3058 if( adapter
->flag
& BOARD_40LD
) {
3060 &((disk_array_40ld
*)disk_array
)->ldrv
[i
].lparam
;
3064 &((disk_array_8ld
*)disk_array
)->ldrv
[i
].lparam
;
3068 * Check for overflow. We print less than 240 characters for
3069 * information about each logical drive.
3071 if( (len
+ 240) >= PAGE_SIZE
) break;
3073 len
+= sprintf(page
+len
, "Logical drive:%2d:, ", i
);
3075 switch( rdrv_state
[i
] & 0x0F ) {
3077 len
+= sprintf(page
+len
, "state: offline");
3081 len
+= sprintf(page
+len
, "state: degraded");
3085 len
+= sprintf(page
+len
, "state: optimal");
3089 len
+= sprintf(page
+len
, "state: deleted");
3093 len
+= sprintf(page
+len
, "state: unknown");
3098 * Check if check consistency or initialization is going on
3099 * for this logical drive.
3101 if( (rdrv_state
[i
] & 0xF0) == 0x20 ) {
3102 len
+= sprintf(page
+len
,
3103 ", check-consistency in progress");
3105 else if( (rdrv_state
[i
] & 0xF0) == 0x10 ) {
3106 len
+= sprintf(page
+len
,
3107 ", initialization in progress");
3110 len
+= sprintf(page
+len
, "\n");
3112 len
+= sprintf(page
+len
, "Span depth:%3d, ",
3113 lparam
->span_depth
);
3115 len
+= sprintf(page
+len
, "RAID level:%3d, ",
3118 len
+= sprintf(page
+len
, "Stripe size:%3d, ",
3119 lparam
->stripe_sz
? lparam
->stripe_sz
/2: 128);
3121 len
+= sprintf(page
+len
, "Row size:%3d\n",
3125 len
+= sprintf(page
+len
, "Read Policy: ");
3127 switch(lparam
->read_ahead
) {
3130 len
+= sprintf(page
+len
, "No read ahead, ");
3134 len
+= sprintf(page
+len
, "Read ahead, ");
3137 case ADAP_READ_AHEAD
:
3138 len
+= sprintf(page
+len
, "Adaptive, ");
3143 len
+= sprintf(page
+len
, "Write Policy: ");
3145 switch(lparam
->write_mode
) {
3147 case WRMODE_WRITE_THRU
:
3148 len
+= sprintf(page
+len
, "Write thru, ");
3151 case WRMODE_WRITE_BACK
:
3152 len
+= sprintf(page
+len
, "Write back, ");
3156 len
+= sprintf(page
+len
, "Cache Policy: ");
3158 switch(lparam
->direct_io
) {
3161 len
+= sprintf(page
+len
, "Cached IO\n\n");
3165 len
+= sprintf(page
+len
, "Direct IO\n\n");
3170 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3172 pci_free_consistent(pdev
, array_sz
, disk_array
,
3173 disk_array_dma_handle
);
3175 free_local_pdev(pdev
);
3184 * megaraid_biosparam()
3186 * Return the disk geometry for a particular disk
3189 megaraid_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
3190 sector_t capacity
, int geom
[])
3199 /* Get pointer to host config structure */
3200 adapter
= (adapter_t
*)sdev
->host
->hostdata
;
3202 if (IS_RAID_CH(adapter
, sdev
->channel
)) {
3203 /* Default heads (64) & sectors (32) */
3206 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3209 * Handle extended translation size for logical drives
3212 if ((ulong
)capacity
>= 0x200000) {
3215 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3221 geom
[2] = cylinders
;
3224 bh
= scsi_bios_ptable(bdev
);
3227 rval
= scsi_partsize(bh
, capacity
,
3228 &geom
[2], &geom
[0], &geom
[1]);
3235 "megaraid: invalid partition on this disk on channel %d\n",
3238 /* Default heads (64) & sectors (32) */
3241 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3243 /* Handle extended translation size for logical drives > 1Gb */
3244 if ((ulong
)capacity
>= 0x200000) {
3247 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3253 geom
[2] = cylinders
;
3261 * @adapter - pointer to our soft state
3263 * Allocate memory for the various pointers in the scb structures:
3264 * scatter-gather list pointer, passthru and extended passthru structure
3268 mega_init_scb(adapter_t
*adapter
)
3273 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3275 scb
= &adapter
->scb_list
[i
];
3283 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3285 scb
= &adapter
->scb_list
[i
];
3289 scb
->sgl64
= pci_alloc_consistent(adapter
->dev
,
3290 sizeof(mega_sgl64
) * adapter
->sglen
,
3291 &scb
->sgl_dma_addr
);
3293 scb
->sgl
= (mega_sglist
*)scb
->sgl64
;
3296 printk(KERN_WARNING
"RAID: Can't allocate sglist.\n");
3297 mega_free_sgl(adapter
);
3301 scb
->pthru
= pci_alloc_consistent(adapter
->dev
,
3302 sizeof(mega_passthru
),
3303 &scb
->pthru_dma_addr
);
3306 printk(KERN_WARNING
"RAID: Can't allocate passthru.\n");
3307 mega_free_sgl(adapter
);
3311 scb
->epthru
= pci_alloc_consistent(adapter
->dev
,
3312 sizeof(mega_ext_passthru
),
3313 &scb
->epthru_dma_addr
);
3315 if( !scb
->epthru
) {
3317 "Can't allocate extended passthru.\n");
3318 mega_free_sgl(adapter
);
3323 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
3327 * lock not required since we are loading the driver, so no
3328 * commands possible right now.
3330 scb
->state
= SCB_FREE
;
3332 list_add(&scb
->list
, &adapter
->free_list
);
3344 * Routines for the character/ioctl interface to the driver. Find out if this
3345 * is a valid open. If yes, increment the module use count so that it cannot
3349 megadev_open (struct inode
*inode
, struct file
*filep
)
3352 * Only allow superuser to access private ioctl interface
3354 if( !capable(CAP_SYS_ADMIN
) ) return -EACCES
;
3362 * @inode - Our device inode
3364 * @cmd - ioctl command
3365 * @arg - user buffer
3367 * ioctl entry point for our private ioctl interface. We move the data in from
3368 * the user space, prepare the command (if necessary, convert the old MIMD
3369 * ioctl to new ioctl command), and issue a synchronous command to the
3373 megadev_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
,
3380 mega_passthru __user
*upthru
; /* user address for passthru */
3381 mega_passthru
*pthru
; /* copy user passthru here */
3382 dma_addr_t pthru_dma_hndl
;
3383 void *data
= NULL
; /* data to be transferred */
3384 dma_addr_t data_dma_hndl
; /* dma handle for data xfer area */
3386 megastat_t __user
*ustats
;
3389 struct pci_dev
*pdev
;
3391 ustats
= NULL
; /* avoid compilation warnings */
3395 * Make sure only USCSICMD are issued through this interface.
3396 * MIMD application would still fire different command.
3398 if( (_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
) ) {
3403 * Check and convert a possible MIMD command to NIT command.
3404 * mega_m_to_n() copies the data from the user space, so we do not
3405 * have to do it here.
3406 * NOTE: We will need some user address to copyout the data, therefore
3407 * the inteface layer will also provide us with the required user
3410 memset(&uioc
, 0, sizeof(nitioctl_t
));
3411 if( (rval
= mega_m_to_n( (void __user
*)arg
, &uioc
)) != 0 )
3415 switch( uioc
.opcode
) {
3417 case GET_DRIVER_VER
:
3418 if( put_user(driver_ver
, (u32 __user
*)uioc
.uioc_uaddr
) )
3424 if( put_user(hba_count
, (u32 __user
*)uioc
.uioc_uaddr
) )
3428 * Shucks. MIMD interface returns a positive value for number
3429 * of adapters. TODO: Change it to return 0 when there is no
3430 * applicatio using mimd interface.
3439 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3442 if( copy_to_user(uioc
.uioc_uaddr
, mcontroller
+adapno
,
3443 sizeof(struct mcontroller
)) )
3453 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3456 adapter
= hba_soft_state
[adapno
];
3458 ustats
= uioc
.uioc_uaddr
;
3460 if( copy_from_user(&num_ldrv
, &ustats
->num_ldrv
, sizeof(int)) )
3464 * Check for the validity of the logical drive number
3466 if( num_ldrv
>= MAX_LOGICAL_DRIVES_40LD
) return -EINVAL
;
3468 if( copy_to_user(ustats
->nreads
, adapter
->nreads
,
3469 num_ldrv
*sizeof(u32
)) )
3472 if( copy_to_user(ustats
->nreadblocks
, adapter
->nreadblocks
,
3473 num_ldrv
*sizeof(u32
)) )
3476 if( copy_to_user(ustats
->nwrites
, adapter
->nwrites
,
3477 num_ldrv
*sizeof(u32
)) )
3480 if( copy_to_user(ustats
->nwriteblocks
, adapter
->nwriteblocks
,
3481 num_ldrv
*sizeof(u32
)) )
3484 if( copy_to_user(ustats
->rd_errors
, adapter
->rd_errors
,
3485 num_ldrv
*sizeof(u32
)) )
3488 if( copy_to_user(ustats
->wr_errors
, adapter
->wr_errors
,
3489 num_ldrv
*sizeof(u32
)) )
3500 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3503 adapter
= hba_soft_state
[adapno
];
3506 * Deletion of logical drive is a special case. The adapter
3507 * should be quiescent before this command is issued.
3509 if( uioc
.uioc_rmbox
[0] == FC_DEL_LOGDRV
&&
3510 uioc
.uioc_rmbox
[2] == OP_DEL_LOGDRV
) {
3513 * Do we support this feature
3515 if( !adapter
->support_random_del
) {
3516 printk(KERN_WARNING
"megaraid: logdrv ");
3517 printk("delete on non-supporting F/W.\n");
3522 rval
= mega_del_logdrv( adapter
, uioc
.uioc_rmbox
[3] );
3525 memset(&mc
, 0, sizeof(megacmd_t
));
3529 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3535 * This interface only support the regular passthru commands.
3536 * Reject extended passthru and 64-bit passthru
3538 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU64
||
3539 uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_EXTPTHRU
) {
3541 printk(KERN_WARNING
"megaraid: rejected passthru.\n");
3547 * For all internal commands, the buffer must be allocated in
3548 * <4GB address range
3550 if( make_local_pdev(adapter
, &pdev
) != 0 )
3553 /* Is it a passthru command or a DCMD */
3554 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU
) {
3555 /* Passthru commands */
3557 pthru
= pci_alloc_consistent(pdev
,
3558 sizeof(mega_passthru
),
3561 if( pthru
== NULL
) {
3562 free_local_pdev(pdev
);
3567 * The user passthru structure
3569 upthru
= (mega_passthru __user
*)MBOX(uioc
)->xferaddr
;
3572 * Copy in the user passthru here.
3574 if( copy_from_user(pthru
, upthru
,
3575 sizeof(mega_passthru
)) ) {
3577 pci_free_consistent(pdev
,
3578 sizeof(mega_passthru
), pthru
,
3581 free_local_pdev(pdev
);
3587 * Is there a data transfer
3589 if( pthru
->dataxferlen
) {
3590 data
= pci_alloc_consistent(pdev
,
3594 if( data
== NULL
) {
3595 pci_free_consistent(pdev
,
3596 sizeof(mega_passthru
),
3600 free_local_pdev(pdev
);
3606 * Save the user address and point the kernel
3607 * address at just allocated memory
3609 uxferaddr
= pthru
->dataxferaddr
;
3610 pthru
->dataxferaddr
= data_dma_hndl
;
3615 * Is data coming down-stream
3617 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3621 if( copy_from_user(data
, (char __user
*)uxferaddr
,
3622 pthru
->dataxferlen
) ) {
3624 goto freemem_and_return
;
3628 memset(&mc
, 0, sizeof(megacmd_t
));
3630 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
3631 mc
.xferaddr
= (u32
)pthru_dma_hndl
;
3636 mega_internal_command(adapter
, &mc
, pthru
);
3638 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3640 if( rval
) goto freemem_and_return
;
3644 * Is data going up-stream
3646 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3647 if( copy_to_user((char __user
*)uxferaddr
, data
,
3648 pthru
->dataxferlen
) ) {
3654 * Send the request sense data also, irrespective of
3655 * whether the user has asked for it or not.
3657 if (copy_to_user(upthru
->reqsensearea
,
3658 pthru
->reqsensearea
, 14))
3662 if( pthru
->dataxferlen
) {
3663 pci_free_consistent(pdev
,
3664 pthru
->dataxferlen
, data
,
3668 pci_free_consistent(pdev
, sizeof(mega_passthru
),
3669 pthru
, pthru_dma_hndl
);
3671 free_local_pdev(pdev
);
3679 * Is there a data transfer
3681 if( uioc
.xferlen
) {
3682 data
= pci_alloc_consistent(pdev
,
3683 uioc
.xferlen
, &data_dma_hndl
);
3685 if( data
== NULL
) {
3686 free_local_pdev(pdev
);
3690 uxferaddr
= MBOX(uioc
)->xferaddr
;
3694 * Is data coming down-stream
3696 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3700 if( copy_from_user(data
, (char __user
*)uxferaddr
,
3703 pci_free_consistent(pdev
,
3705 data
, data_dma_hndl
);
3707 free_local_pdev(pdev
);
3713 memcpy(&mc
, MBOX(uioc
), sizeof(megacmd_t
));
3715 mc
.xferaddr
= (u32
)data_dma_hndl
;
3720 mega_internal_command(adapter
, &mc
, NULL
);
3722 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3725 if( uioc
.xferlen
) {
3726 pci_free_consistent(pdev
,
3731 free_local_pdev(pdev
);
3737 * Is data going up-stream
3739 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3740 if( copy_to_user((char __user
*)uxferaddr
, data
,
3747 if( uioc
.xferlen
) {
3748 pci_free_consistent(pdev
,
3753 free_local_pdev(pdev
);
3767 * @arg - user address
3768 * @uioc - new ioctl structure
3770 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3773 * Converts the older mimd ioctl structure to newer NIT structure
3776 mega_m_to_n(void __user
*arg
, nitioctl_t
*uioc
)
3778 struct uioctl_t uioc_mimd
;
3779 char signature
[8] = {0};
3785 * check is the application conforms to NIT. We do not have to do much
3787 * We exploit the fact that the signature is stored in the very
3788 * begining of the structure.
3791 if( copy_from_user(signature
, arg
, 7) )
3794 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3797 * NOTE NOTE: The nit ioctl is still under flux because of
3798 * change of mailbox definition, in HPE. No applications yet
3799 * use this interface and let's not have applications use this
3800 * interface till the new specifitions are in place.
3804 if( copy_from_user(uioc
, arg
, sizeof(nitioctl_t
)) )
3811 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3813 * Get the user ioctl structure
3815 if( copy_from_user(&uioc_mimd
, arg
, sizeof(struct uioctl_t
)) )
3820 * Get the opcode and subopcode for the commands
3822 opcode
= uioc_mimd
.ui
.fcs
.opcode
;
3823 subopcode
= uioc_mimd
.ui
.fcs
.subopcode
;
3828 switch (subopcode
) {
3830 case MEGAIOC_QDRVRVER
: /* Query driver version */
3831 uioc
->opcode
= GET_DRIVER_VER
;
3832 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3835 case MEGAIOC_QNADAP
: /* Get # of adapters */
3836 uioc
->opcode
= GET_N_ADAP
;
3837 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3840 case MEGAIOC_QADAPINFO
: /* Get adapter information */
3841 uioc
->opcode
= GET_ADAP_INFO
;
3842 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3843 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3855 uioc
->opcode
= MBOX_CMD
;
3856 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3858 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3860 uioc
->xferlen
= uioc_mimd
.ui
.fcs
.length
;
3862 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3863 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3869 uioc
->opcode
= MBOX_CMD
;
3870 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3872 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3875 * Choose the xferlen bigger of input and output data
3877 uioc
->xferlen
= uioc_mimd
.outlen
> uioc_mimd
.inlen
?
3878 uioc_mimd
.outlen
: uioc_mimd
.inlen
;
3880 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3881 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3895 * @arg - user address
3896 * @mc - mailbox command
3898 * Updates the status information to the application, depending on application
3899 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3902 mega_n_to_m(void __user
*arg
, megacmd_t
*mc
)
3904 nitioctl_t __user
*uiocp
;
3905 megacmd_t __user
*umc
;
3906 mega_passthru __user
*upthru
;
3907 struct uioctl_t __user
*uioc_mimd
;
3908 char signature
[8] = {0};
3911 * check is the application conforms to NIT.
3913 if( copy_from_user(signature
, arg
, 7) )
3916 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3920 if( put_user(mc
->status
, (u8 __user
*)&MBOX_P(uiocp
)->status
) )
3923 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3925 umc
= MBOX_P(uiocp
);
3927 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3930 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
))
3937 if( put_user(mc
->status
, (u8 __user
*)&uioc_mimd
->mbox
[17]) )
3940 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3942 umc
= (megacmd_t __user
*)uioc_mimd
->mbox
;
3944 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3947 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
) )
3957 * MEGARAID 'FW' commands.
3961 * mega_is_bios_enabled()
3962 * @adapter - pointer to our soft state
3964 * issue command to find out if the BIOS is enabled for this controller
3967 mega_is_bios_enabled(adapter_t
*adapter
)
3969 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
3973 mbox
= (mbox_t
*)raw_mbox
;
3975 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
3977 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
3979 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
3981 raw_mbox
[0] = IS_BIOS_ENABLED
;
3982 raw_mbox
[2] = GET_BIOS
;
3985 ret
= issue_scb_block(adapter
, raw_mbox
);
3987 return *(char *)adapter
->mega_buffer
;
3992 * mega_enum_raid_scsi()
3993 * @adapter - pointer to our soft state
3995 * Find out what channels are RAID/SCSI. This information is used to
3996 * differentiate the virtual channels and physical channels and to support
3997 * ROMB feature and non-disk devices.
4000 mega_enum_raid_scsi(adapter_t
*adapter
)
4002 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4006 mbox
= (mbox_t
*)raw_mbox
;
4008 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4011 * issue command to find out what channels are raid/scsi
4013 raw_mbox
[0] = CHNL_CLASS
;
4014 raw_mbox
[2] = GET_CHNL_CLASS
;
4016 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4018 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4021 * Non-ROMB firmware fail this command, so all channels
4022 * must be shown RAID
4024 adapter
->mega_ch_class
= 0xFF;
4026 if(!issue_scb_block(adapter
, raw_mbox
)) {
4027 adapter
->mega_ch_class
= *((char *)adapter
->mega_buffer
);
4031 for( i
= 0; i
< adapter
->product_info
.nchannels
; i
++ ) {
4032 if( (adapter
->mega_ch_class
>> i
) & 0x01 ) {
4033 printk(KERN_INFO
"megaraid: channel[%d] is raid.\n",
4037 printk(KERN_INFO
"megaraid: channel[%d] is scsi.\n",
4047 * mega_get_boot_drv()
4048 * @adapter - pointer to our soft state
4050 * Find out which device is the boot device. Note, any logical drive or any
4051 * phyical device (e.g., a CDROM) can be designated as a boot device.
4054 mega_get_boot_drv(adapter_t
*adapter
)
4056 struct private_bios_data
*prv_bios_data
;
4057 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4064 mbox
= (mbox_t
*)raw_mbox
;
4066 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4068 raw_mbox
[0] = BIOS_PVT_DATA
;
4069 raw_mbox
[2] = GET_BIOS_PVT_DATA
;
4071 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4073 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4075 adapter
->boot_ldrv_enabled
= 0;
4076 adapter
->boot_ldrv
= 0;
4078 adapter
->boot_pdrv_enabled
= 0;
4079 adapter
->boot_pdrv_ch
= 0;
4080 adapter
->boot_pdrv_tgt
= 0;
4082 if(issue_scb_block(adapter
, raw_mbox
) == 0) {
4084 (struct private_bios_data
*)adapter
->mega_buffer
;
4087 cksum_p
= (char *)prv_bios_data
;
4088 for (i
= 0; i
< 14; i
++ ) {
4089 cksum
+= (u16
)(*cksum_p
++);
4092 if (prv_bios_data
->cksum
== (u16
)(0-cksum
) ) {
4095 * If MSB is set, a physical drive is set as boot
4098 if( prv_bios_data
->boot_drv
& 0x80 ) {
4099 adapter
->boot_pdrv_enabled
= 1;
4100 boot_pdrv
= prv_bios_data
->boot_drv
& 0x7F;
4101 adapter
->boot_pdrv_ch
= boot_pdrv
/ 16;
4102 adapter
->boot_pdrv_tgt
= boot_pdrv
% 16;
4105 adapter
->boot_ldrv_enabled
= 1;
4106 adapter
->boot_ldrv
= prv_bios_data
->boot_drv
;
4114 * mega_support_random_del()
4115 * @adapter - pointer to our soft state
4117 * Find out if this controller supports random deletion and addition of
4121 mega_support_random_del(adapter_t
*adapter
)
4123 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4127 mbox
= (mbox_t
*)raw_mbox
;
4129 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4134 raw_mbox
[0] = FC_DEL_LOGDRV
;
4135 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
4137 rval
= issue_scb_block(adapter
, raw_mbox
);
4144 * mega_support_ext_cdb()
4145 * @adapter - pointer to our soft state
4147 * Find out if this firmware support cdblen > 10
4150 mega_support_ext_cdb(adapter_t
*adapter
)
4152 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4156 mbox
= (mbox_t
*)raw_mbox
;
4158 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4160 * issue command to find out if controller supports extended CDBs.
4165 rval
= issue_scb_block(adapter
, raw_mbox
);
4173 * @adapter - pointer to our soft state
4174 * @logdrv - logical drive to be deleted
4176 * Delete the specified logical drive. It is the responsibility of the user
4177 * app to let the OS know about this operation.
4180 mega_del_logdrv(adapter_t
*adapter
, int logdrv
)
4182 unsigned long flags
;
4187 * Stop sending commands to the controller, queue them internally.
4188 * When deletion is complete, ISR will flush the queue.
4190 atomic_set(&adapter
->quiescent
, 1);
4193 * Wait till all the issued commands are complete and there are no
4194 * commands in the pending queue
4196 while (atomic_read(&adapter
->pend_cmds
) > 0 ||
4197 !list_empty(&adapter
->pending_list
))
4198 msleep(1000); /* sleep for 1s */
4200 rval
= mega_do_del_logdrv(adapter
, logdrv
);
4202 spin_lock_irqsave(&adapter
->lock
, flags
);
4205 * If delete operation was successful, add 0x80 to the logical drive
4206 * ids for commands in the pending queue.
4208 if (adapter
->read_ldidmap
) {
4209 struct list_head
*pos
;
4210 list_for_each(pos
, &adapter
->pending_list
) {
4211 scb
= list_entry(pos
, scb_t
, list
);
4212 if (scb
->pthru
->logdrv
< 0x80 )
4213 scb
->pthru
->logdrv
+= 0x80;
4217 atomic_set(&adapter
->quiescent
, 0);
4219 mega_runpendq(adapter
);
4221 spin_unlock_irqrestore(&adapter
->lock
, flags
);
4228 mega_do_del_logdrv(adapter_t
*adapter
, int logdrv
)
4233 memset( &mc
, 0, sizeof(megacmd_t
));
4235 mc
.cmd
= FC_DEL_LOGDRV
;
4236 mc
.opcode
= OP_DEL_LOGDRV
;
4237 mc
.subopcode
= logdrv
;
4239 rval
= mega_internal_command(adapter
, &mc
, NULL
);
4241 /* log this event */
4243 printk(KERN_WARNING
"megaraid: Delete LD-%d failed.", logdrv
);
4248 * After deleting first logical drive, the logical drives must be
4249 * addressed by adding 0x80 to the logical drive id.
4251 adapter
->read_ldidmap
= 1;
4258 * mega_get_max_sgl()
4259 * @adapter - pointer to our soft state
4261 * Find out the maximum number of scatter-gather elements supported by this
4262 * version of the firmware
4265 mega_get_max_sgl(adapter_t
*adapter
)
4267 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4270 mbox
= (mbox_t
*)raw_mbox
;
4272 memset(mbox
, 0, sizeof(raw_mbox
));
4274 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4276 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4278 raw_mbox
[0] = MAIN_MISC_OPCODE
;
4279 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
4282 if( issue_scb_block(adapter
, raw_mbox
) ) {
4284 * f/w does not support this command. Choose the default value
4286 adapter
->sglen
= MIN_SGLIST
;
4289 adapter
->sglen
= *((char *)adapter
->mega_buffer
);
4292 * Make sure this is not more than the resources we are
4293 * planning to allocate
4295 if ( adapter
->sglen
> MAX_SGLIST
)
4296 adapter
->sglen
= MAX_SGLIST
;
4304 * mega_support_cluster()
4305 * @adapter - pointer to our soft state
4307 * Find out if this firmware support cluster calls.
4310 mega_support_cluster(adapter_t
*adapter
)
4312 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4315 mbox
= (mbox_t
*)raw_mbox
;
4317 memset(mbox
, 0, sizeof(raw_mbox
));
4319 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4321 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4324 * Try to get the initiator id. This command will succeed iff the
4325 * clustering is available on this HBA.
4327 raw_mbox
[0] = MEGA_GET_TARGET_ID
;
4329 if( issue_scb_block(adapter
, raw_mbox
) == 0 ) {
4332 * Cluster support available. Get the initiator target id.
4333 * Tell our id to mid-layer too.
4335 adapter
->this_id
= *(u32
*)adapter
->mega_buffer
;
4336 adapter
->host
->this_id
= adapter
->this_id
;
4347 * @adapter - pointer to our soft state
4348 * @dma_handle - DMA address of the buffer
4350 * Issue internal comamnds while interrupts are available.
4351 * We only issue direct mailbox commands from within the driver. ioctl()
4352 * interface using these routines can issue passthru commands.
4355 mega_adapinq(adapter_t
*adapter
, dma_addr_t dma_handle
)
4359 memset(&mc
, 0, sizeof(megacmd_t
));
4361 if( adapter
->flag
& BOARD_40LD
) {
4362 mc
.cmd
= FC_NEW_CONFIG
;
4363 mc
.opcode
= NC_SUBOP_ENQUIRY3
;
4364 mc
.subopcode
= ENQ3_GET_SOLICITED_FULL
;
4367 mc
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
4370 mc
.xferaddr
= (u32
)dma_handle
;
4372 if ( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
4380 /** mega_internal_dev_inquiry()
4381 * @adapter - pointer to our soft state
4382 * @ch - channel for this device
4383 * @tgt - ID of this device
4384 * @buf_dma_handle - DMA address of the buffer
4386 * Issue the scsi inquiry for the specified device.
4389 mega_internal_dev_inquiry(adapter_t
*adapter
, u8 ch
, u8 tgt
,
4390 dma_addr_t buf_dma_handle
)
4392 mega_passthru
*pthru
;
4393 dma_addr_t pthru_dma_handle
;
4396 struct pci_dev
*pdev
;
4400 * For all internal commands, the buffer must be allocated in <4GB
4403 if( make_local_pdev(adapter
, &pdev
) != 0 ) return -1;
4405 pthru
= pci_alloc_consistent(pdev
, sizeof(mega_passthru
),
4408 if( pthru
== NULL
) {
4409 free_local_pdev(pdev
);
4415 pthru
->reqsenselen
= 14;
4416 pthru
->islogical
= 0;
4418 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : ch
;
4420 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ? (ch
<< 4)|tgt
: tgt
;
4424 pthru
->cdb
[0] = INQUIRY
;
4428 pthru
->cdb
[4] = 255;
4432 pthru
->dataxferaddr
= (u32
)buf_dma_handle
;
4433 pthru
->dataxferlen
= 256;
4435 memset(&mc
, 0, sizeof(megacmd_t
));
4437 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
4438 mc
.xferaddr
= (u32
)pthru_dma_handle
;
4440 rval
= mega_internal_command(adapter
, &mc
, pthru
);
4442 pci_free_consistent(pdev
, sizeof(mega_passthru
), pthru
,
4445 free_local_pdev(pdev
);
4452 * mega_internal_command()
4453 * @adapter - pointer to our soft state
4454 * @mc - the mailbox command
4455 * @pthru - Passthru structure for DCDB commands
4457 * Issue the internal commands in interrupt mode.
4458 * The last argument is the address of the passthru structure if the command
4459 * to be fired is a passthru command
4461 * lockscope specifies whether the caller has already acquired the lock. Of
4462 * course, the caller must know which lock we are talking about.
4464 * Note: parameter 'pthru' is null for non-passthru commands.
4467 mega_internal_command(adapter_t
*adapter
, megacmd_t
*mc
, mega_passthru
*pthru
)
4470 struct scsi_device
*sdev
;
4475 * The internal commands share one command id and hence are
4476 * serialized. This is so because we want to reserve maximum number of
4477 * available command ids for the I/O commands.
4479 mutex_lock(&adapter
->int_mtx
);
4481 scb
= &adapter
->int_scb
;
4482 memset(scb
, 0, sizeof(scb_t
));
4484 scmd
= &adapter
->int_scmd
;
4485 memset(scmd
, 0, sizeof(Scsi_Cmnd
));
4487 sdev
= kmalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
4488 memset(sdev
, 0, sizeof(struct scsi_device
));
4489 scmd
->device
= sdev
;
4491 scmd
->device
->host
= adapter
->host
;
4492 scmd
->request_buffer
= (void *)scb
;
4493 scmd
->cmnd
[0] = MEGA_INTERNAL_CMD
;
4495 scb
->state
|= SCB_ACTIVE
;
4498 memcpy(scb
->raw_mbox
, mc
, sizeof(megacmd_t
));
4501 * Is it a passthru command
4503 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
4508 scb
->idx
= CMDID_INT_CMDS
;
4510 megaraid_queue(scmd
, mega_internal_done
);
4512 wait_for_completion(&adapter
->int_waitq
);
4514 rval
= scmd
->result
;
4515 mc
->status
= scmd
->result
;
4519 * Print a debug message for all failed commands. Applications can use
4522 if( scmd
->result
&& trace_level
) {
4523 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4524 mc
->cmd
, mc
->opcode
, mc
->subopcode
, scmd
->result
);
4527 mutex_unlock(&adapter
->int_mtx
);
4534 * mega_internal_done()
4535 * @scmd - internal scsi command
4537 * Callback routine for internal commands.
4540 mega_internal_done(Scsi_Cmnd
*scmd
)
4544 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
4546 complete(&adapter
->int_waitq
);
4551 static struct scsi_host_template megaraid_template
= {
4552 .module
= THIS_MODULE
,
4554 .proc_name
= "megaraid_legacy",
4555 .info
= megaraid_info
,
4556 .queuecommand
= megaraid_queue
,
4557 .bios_param
= megaraid_biosparam
,
4558 .max_sectors
= MAX_SECTORS_PER_IO
,
4559 .can_queue
= MAX_COMMANDS
,
4560 .this_id
= DEFAULT_INITIATOR_ID
,
4561 .sg_tablesize
= MAX_SGLIST
,
4562 .cmd_per_lun
= DEF_CMD_PER_LUN
,
4563 .use_clustering
= ENABLE_CLUSTERING
,
4564 .eh_abort_handler
= megaraid_abort
,
4565 .eh_device_reset_handler
= megaraid_reset
,
4566 .eh_bus_reset_handler
= megaraid_reset
,
4567 .eh_host_reset_handler
= megaraid_reset
,
4570 static int __devinit
4571 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
4573 struct Scsi_Host
*host
;
4575 unsigned long mega_baseport
, tbase
, flag
= 0;
4576 u16 subsysid
, subsysvid
;
4577 u8 pci_bus
, pci_dev_func
;
4579 int error
= -ENODEV
;
4581 if (pci_enable_device(pdev
))
4583 pci_set_master(pdev
);
4585 pci_bus
= pdev
->bus
->number
;
4586 pci_dev_func
= pdev
->devfn
;
4589 * The megaraid3 stuff reports the ID of the Intel part which is not
4590 * remotely specific to the megaraid
4592 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
) {
4595 * Don't fall over the Compaq management cards using the same
4598 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_COMPAQ
&&
4599 pdev
->subsystem_device
== 0xC000)
4601 /* Now check the magic signature byte */
4602 pci_read_config_word(pdev
, PCI_CONF_AMISIG
, &magic
);
4603 if (magic
!= HBA_SIGNATURE_471
&& magic
!= HBA_SIGNATURE
)
4605 /* Ok it is probably a megaraid */
4609 * For these vendor and device ids, signature offsets are not
4610 * valid and 64 bit is implicit
4612 if (id
->driver_data
& BOARD_64BIT
)
4613 flag
|= BOARD_64BIT
;
4617 pci_read_config_dword(pdev
, PCI_CONF_AMISIG64
, &magic64
);
4618 if (magic64
== HBA_SIGNATURE_64BIT
)
4619 flag
|= BOARD_64BIT
;
4622 subsysvid
= pdev
->subsystem_vendor
;
4623 subsysid
= pdev
->subsystem_device
;
4625 printk(KERN_NOTICE
"megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4626 id
->vendor
, id
->device
, pci_bus
);
4628 printk("slot %d:func %d\n",
4629 PCI_SLOT(pci_dev_func
), PCI_FUNC(pci_dev_func
));
4631 /* Read the base port and IRQ from PCI */
4632 mega_baseport
= pci_resource_start(pdev
, 0);
4635 tbase
= mega_baseport
;
4636 if (pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) {
4637 flag
|= BOARD_MEMMAP
;
4639 if (!request_mem_region(mega_baseport
, 128, "megaraid")) {
4640 printk(KERN_WARNING
"megaraid: mem region busy!\n");
4641 goto out_disable_device
;
4644 mega_baseport
= (unsigned long)ioremap(mega_baseport
, 128);
4645 if (!mega_baseport
) {
4647 "megaraid: could not map hba memory\n");
4648 goto out_release_region
;
4651 flag
|= BOARD_IOMAP
;
4652 mega_baseport
+= 0x10;
4654 if (!request_region(mega_baseport
, 16, "megaraid"))
4655 goto out_disable_device
;
4658 /* Initialize SCSI Host structure */
4659 host
= scsi_host_alloc(&megaraid_template
, sizeof(adapter_t
));
4663 adapter
= (adapter_t
*)host
->hostdata
;
4664 memset(adapter
, 0, sizeof(adapter_t
));
4667 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4668 host
->host_no
, mega_baseport
, irq
);
4670 adapter
->base
= mega_baseport
;
4672 INIT_LIST_HEAD(&adapter
->free_list
);
4673 INIT_LIST_HEAD(&adapter
->pending_list
);
4674 INIT_LIST_HEAD(&adapter
->completed_list
);
4676 adapter
->flag
= flag
;
4677 spin_lock_init(&adapter
->lock
);
4679 host
->cmd_per_lun
= max_cmd_per_lun
;
4680 host
->max_sectors
= max_sectors_per_io
;
4682 adapter
->dev
= pdev
;
4683 adapter
->host
= host
;
4685 adapter
->host
->irq
= irq
;
4687 if (flag
& BOARD_MEMMAP
)
4688 adapter
->host
->base
= tbase
;
4690 adapter
->host
->io_port
= tbase
;
4691 adapter
->host
->n_io_port
= 16;
4694 adapter
->host
->unique_id
= (pci_bus
<< 8) | pci_dev_func
;
4697 * Allocate buffer to issue internal commands.
4699 adapter
->mega_buffer
= pci_alloc_consistent(adapter
->dev
,
4700 MEGA_BUFFER_SIZE
, &adapter
->buf_dma_handle
);
4701 if (!adapter
->mega_buffer
) {
4702 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4706 adapter
->scb_list
= kmalloc(sizeof(scb_t
) * MAX_COMMANDS
, GFP_KERNEL
);
4707 if (!adapter
->scb_list
) {
4708 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4709 goto out_free_cmd_buffer
;
4712 if (request_irq(irq
, (adapter
->flag
& BOARD_MEMMAP
) ?
4713 megaraid_isr_memmapped
: megaraid_isr_iomapped
,
4714 IRQF_SHARED
, "megaraid", adapter
)) {
4716 "megaraid: Couldn't register IRQ %d!\n", irq
);
4717 goto out_free_scb_list
;
4720 if (mega_setup_mailbox(adapter
))
4723 if (mega_query_adapter(adapter
))
4727 * Have checks for some buggy f/w
4729 if ((subsysid
== 0x1111) && (subsysvid
== 0x1111)) {
4733 if (!strcmp(adapter
->fw_version
, "3.00") ||
4734 !strcmp(adapter
->fw_version
, "3.01")) {
4736 printk( KERN_WARNING
4737 "megaraid: Your card is a Dell PERC "
4738 "2/SC RAID controller with "
4739 "firmware\nmegaraid: 3.00 or 3.01. "
4740 "This driver is known to have "
4741 "corruption issues\nmegaraid: with "
4742 "those firmware versions on this "
4743 "specific card. In order\nmegaraid: "
4744 "to protect your data, please upgrade "
4745 "your firmware to version\nmegaraid: "
4746 "3.10 or later, available from the "
4747 "Dell Technical Support web\n"
4748 "megaraid: site at\nhttp://support."
4749 "dell.com/us/en/filelib/download/"
4750 "index.asp?fileid=2940\n"
4756 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4757 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4758 * support, since this firmware cannot handle 64 bit
4761 if ((subsysvid
== HP_SUBSYS_VID
) &&
4762 ((subsysid
== 0x60E7) || (subsysid
== 0x60E8))) {
4766 if (!strcmp(adapter
->fw_version
, "H01.07") ||
4767 !strcmp(adapter
->fw_version
, "H01.08") ||
4768 !strcmp(adapter
->fw_version
, "H01.09") ) {
4770 "megaraid: Firmware H.01.07, "
4771 "H.01.08, and H.01.09 on 1M/2M "
4773 "megaraid: do not support 64 bit "
4774 "addressing.\nmegaraid: DISABLING "
4775 "64 bit support.\n");
4776 adapter
->flag
&= ~BOARD_64BIT
;
4780 if (mega_is_bios_enabled(adapter
))
4781 mega_hbas
[hba_count
].is_bios_enabled
= 1;
4782 mega_hbas
[hba_count
].hostdata_addr
= adapter
;
4785 * Find out which channel is raid and which is scsi. This is
4788 mega_enum_raid_scsi(adapter
);
4791 * Find out if a logical drive is set as the boot drive. If
4792 * there is one, will make that as the first logical drive.
4793 * ROMB: Do we have to boot from a physical drive. Then all
4794 * the physical drives would appear before the logical disks.
4795 * Else, all the physical drives would be exported to the mid
4796 * layer after logical drives.
4798 mega_get_boot_drv(adapter
);
4800 if (adapter
->boot_pdrv_enabled
) {
4801 j
= adapter
->product_info
.nchannels
;
4802 for( i
= 0; i
< j
; i
++ )
4803 adapter
->logdrv_chan
[i
] = 0;
4804 for( i
= j
; i
< NVIRT_CHAN
+ j
; i
++ )
4805 adapter
->logdrv_chan
[i
] = 1;
4807 for (i
= 0; i
< NVIRT_CHAN
; i
++)
4808 adapter
->logdrv_chan
[i
] = 1;
4809 for (i
= NVIRT_CHAN
; i
< MAX_CHANNELS
+NVIRT_CHAN
; i
++)
4810 adapter
->logdrv_chan
[i
] = 0;
4811 adapter
->mega_ch_class
<<= NVIRT_CHAN
;
4815 * Do we support random deletion and addition of logical
4818 adapter
->read_ldidmap
= 0; /* set it after first logdrv
4820 adapter
->support_random_del
= mega_support_random_del(adapter
);
4822 /* Initialize SCBs */
4823 if (mega_init_scb(adapter
))
4827 * Reset the pending commands counter
4829 atomic_set(&adapter
->pend_cmds
, 0);
4832 * Reset the adapter quiescent flag
4834 atomic_set(&adapter
->quiescent
, 0);
4836 hba_soft_state
[hba_count
] = adapter
;
4839 * Fill in the structure which needs to be passed back to the
4840 * application when it does an ioctl() for controller related
4845 mcontroller
[i
].base
= mega_baseport
;
4846 mcontroller
[i
].irq
= irq
;
4847 mcontroller
[i
].numldrv
= adapter
->numldrv
;
4848 mcontroller
[i
].pcibus
= pci_bus
;
4849 mcontroller
[i
].pcidev
= id
->device
;
4850 mcontroller
[i
].pcifun
= PCI_FUNC (pci_dev_func
);
4851 mcontroller
[i
].pciid
= -1;
4852 mcontroller
[i
].pcivendor
= id
->vendor
;
4853 mcontroller
[i
].pcislot
= PCI_SLOT(pci_dev_func
);
4854 mcontroller
[i
].uid
= (pci_bus
<< 8) | pci_dev_func
;
4857 /* Set the Mode of addressing to 64 bit if we can */
4858 if ((adapter
->flag
& BOARD_64BIT
) && (sizeof(dma_addr_t
) == 8)) {
4859 pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
4860 adapter
->has_64bit_addr
= 1;
4862 pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
4863 adapter
->has_64bit_addr
= 0;
4866 mutex_init(&adapter
->int_mtx
);
4867 init_completion(&adapter
->int_waitq
);
4869 adapter
->this_id
= DEFAULT_INITIATOR_ID
;
4870 adapter
->host
->this_id
= DEFAULT_INITIATOR_ID
;
4872 #if MEGA_HAVE_CLUSTERING
4874 * Is cluster support enabled on this controller
4875 * Note: In a cluster the HBAs ( the initiators ) will have
4876 * different target IDs and we cannot assume it to be 7. Call
4877 * to mega_support_cluster() will get the target ids also if
4878 * the cluster support is available
4880 adapter
->has_cluster
= mega_support_cluster(adapter
);
4881 if (adapter
->has_cluster
) {
4883 "megaraid: Cluster driver, initiator id:%d\n",
4888 pci_set_drvdata(pdev
, host
);
4890 mega_create_proc_entry(hba_count
, mega_proc_dir_entry
);
4892 error
= scsi_add_host(host
, &pdev
->dev
);
4896 scsi_scan_host(host
);
4901 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
4902 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
4904 free_irq(adapter
->host
->irq
, adapter
);
4906 kfree(adapter
->scb_list
);
4907 out_free_cmd_buffer
:
4908 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
4909 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
4911 scsi_host_put(host
);
4913 if (flag
& BOARD_MEMMAP
)
4914 iounmap((void *)mega_baseport
);
4916 if (flag
& BOARD_MEMMAP
)
4917 release_mem_region(tbase
, 128);
4919 release_region(mega_baseport
, 16);
4921 pci_disable_device(pdev
);
4927 __megaraid_shutdown(adapter_t
*adapter
)
4929 u_char raw_mbox
[sizeof(struct mbox_out
)];
4930 mbox_t
*mbox
= (mbox_t
*)raw_mbox
;
4933 /* Flush adapter cache */
4934 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4935 raw_mbox
[0] = FLUSH_ADAPTER
;
4937 free_irq(adapter
->host
->irq
, adapter
);
4939 /* Issue a blocking (interrupts disabled) command to the card */
4940 issue_scb_block(adapter
, raw_mbox
);
4942 /* Flush disks cache */
4943 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4944 raw_mbox
[0] = FLUSH_SYSTEM
;
4946 /* Issue a blocking (interrupts disabled) command to the card */
4947 issue_scb_block(adapter
, raw_mbox
);
4949 if (atomic_read(&adapter
->pend_cmds
) > 0)
4950 printk(KERN_WARNING
"megaraid: pending commands!!\n");
4953 * Have a delibrate delay to make sure all the caches are
4956 for (i
= 0; i
<= 10; i
++)
4961 megaraid_remove_one(struct pci_dev
*pdev
)
4963 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4964 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
4965 char buf
[12] = { 0 };
4967 scsi_remove_host(host
);
4969 __megaraid_shutdown(adapter
);
4971 /* Free our resources */
4972 if (adapter
->flag
& BOARD_MEMMAP
) {
4973 iounmap((void *)adapter
->base
);
4974 release_mem_region(adapter
->host
->base
, 128);
4976 release_region(adapter
->base
, 16);
4978 mega_free_sgl(adapter
);
4980 #ifdef CONFIG_PROC_FS
4981 if (adapter
->controller_proc_dir_entry
) {
4982 remove_proc_entry("stat", adapter
->controller_proc_dir_entry
);
4983 remove_proc_entry("config",
4984 adapter
->controller_proc_dir_entry
);
4985 remove_proc_entry("mailbox",
4986 adapter
->controller_proc_dir_entry
);
4987 #if MEGA_HAVE_ENH_PROC
4988 remove_proc_entry("rebuild-rate",
4989 adapter
->controller_proc_dir_entry
);
4990 remove_proc_entry("battery-status",
4991 adapter
->controller_proc_dir_entry
);
4993 remove_proc_entry("diskdrives-ch0",
4994 adapter
->controller_proc_dir_entry
);
4995 remove_proc_entry("diskdrives-ch1",
4996 adapter
->controller_proc_dir_entry
);
4997 remove_proc_entry("diskdrives-ch2",
4998 adapter
->controller_proc_dir_entry
);
4999 remove_proc_entry("diskdrives-ch3",
5000 adapter
->controller_proc_dir_entry
);
5002 remove_proc_entry("raiddrives-0-9",
5003 adapter
->controller_proc_dir_entry
);
5004 remove_proc_entry("raiddrives-10-19",
5005 adapter
->controller_proc_dir_entry
);
5006 remove_proc_entry("raiddrives-20-29",
5007 adapter
->controller_proc_dir_entry
);
5008 remove_proc_entry("raiddrives-30-39",
5009 adapter
->controller_proc_dir_entry
);
5011 sprintf(buf
, "hba%d", adapter
->host
->host_no
);
5012 remove_proc_entry(buf
, mega_proc_dir_entry
);
5016 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
5017 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
5018 kfree(adapter
->scb_list
);
5019 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
5020 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
5022 scsi_host_put(host
);
5023 pci_disable_device(pdev
);
5029 megaraid_shutdown(struct pci_dev
*pdev
)
5031 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
5032 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
5034 __megaraid_shutdown(adapter
);
5037 static struct pci_device_id megaraid_pci_tbl
[] = {
5038 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID
,
5039 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5040 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID2
,
5041 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5042 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_AMI_MEGARAID3
,
5043 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5046 MODULE_DEVICE_TABLE(pci
, megaraid_pci_tbl
);
5048 static struct pci_driver megaraid_pci_driver
= {
5049 .name
= "megaraid_legacy",
5050 .id_table
= megaraid_pci_tbl
,
5051 .probe
= megaraid_probe_one
,
5052 .remove
= __devexit_p(megaraid_remove_one
),
5053 .shutdown
= megaraid_shutdown
,
5056 static int __init
megaraid_init(void)
5060 if ((max_cmd_per_lun
<= 0) || (max_cmd_per_lun
> MAX_CMD_PER_LUN
))
5061 max_cmd_per_lun
= MAX_CMD_PER_LUN
;
5062 if (max_mbox_busy_wait
> MBOX_BUSY_WAIT
)
5063 max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
5065 #ifdef CONFIG_PROC_FS
5066 mega_proc_dir_entry
= proc_mkdir("megaraid", &proc_root
);
5067 if (!mega_proc_dir_entry
) {
5069 "megaraid: failed to create megaraid root\n");
5072 error
= pci_module_init(&megaraid_pci_driver
);
5074 #ifdef CONFIG_PROC_FS
5075 remove_proc_entry("megaraid", &proc_root
);
5081 * Register the driver as a character device, for applications
5082 * to access it for ioctls.
5083 * First argument (major) to register_chrdev implies a dynamic
5084 * major number allocation.
5086 major
= register_chrdev(0, "megadev_legacy", &megadev_fops
);
5089 "megaraid: failed to register char device\n");
5095 static void __exit
megaraid_exit(void)
5098 * Unregister the character device interface to the driver.
5100 unregister_chrdev(major
, "megadev_legacy");
5102 pci_unregister_driver(&megaraid_pci_driver
);
5104 #ifdef CONFIG_PROC_FS
5105 remove_proc_entry("megaraid", &proc_root
);
5109 module_init(megaraid_init
);
5110 module_exit(megaraid_exit
);
5112 /* vi: set ts=8 sw=8 tw=78: */