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 <scsi/scsicam.h>
51 #include <scsi/scsi_host.h>
55 #define MEGARAID_MODULE_VERSION "2.00.4"
57 MODULE_AUTHOR ("sju@lsil.com");
58 MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
59 MODULE_LICENSE ("GPL");
60 MODULE_VERSION(MEGARAID_MODULE_VERSION
);
62 static unsigned int max_cmd_per_lun
= DEF_CMD_PER_LUN
;
63 module_param(max_cmd_per_lun
, uint
, 0);
64 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)");
66 static unsigned short int max_sectors_per_io
= MAX_SECTORS_PER_IO
;
67 module_param(max_sectors_per_io
, ushort
, 0);
68 MODULE_PARM_DESC(max_sectors_per_io
, "Maximum number of sectors per I/O request (default=MAX_SECTORS_PER_IO=128)");
71 static unsigned short int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
72 module_param(max_mbox_busy_wait
, ushort
, 0);
73 MODULE_PARM_DESC(max_mbox_busy_wait
, "Maximum wait for mailbox in microseconds if busy (default=MBOX_BUSY_WAIT=10)");
75 #define RDINDOOR(adapter) readl((adapter)->base + 0x20)
76 #define RDOUTDOOR(adapter) readl((adapter)->base + 0x2C)
77 #define WRINDOOR(adapter,value) writel(value, (adapter)->base + 0x20)
78 #define WROUTDOOR(adapter,value) writel(value, (adapter)->base + 0x2C)
85 static adapter_t
*hba_soft_state
[MAX_CONTROLLERS
];
86 static struct proc_dir_entry
*mega_proc_dir_entry
;
88 /* For controller re-ordering */
89 static struct mega_hbas mega_hbas
[MAX_CONTROLLERS
];
92 * The File Operations structure for the serial/ioctl interface of the driver
94 static struct file_operations megadev_fops
= {
96 .ioctl
= megadev_ioctl
,
101 * Array to structures for storing the information about the controllers. This
102 * information is sent to the user level applications, when they do an ioctl
103 * for this information.
105 static struct mcontroller mcontroller
[MAX_CONTROLLERS
];
107 /* The current driver version */
108 static u32 driver_ver
= 0x02000000;
110 /* major number used by the device for character interface */
113 #define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
117 * Debug variable to print some diagnostic messages
119 static int trace_level
;
122 * mega_setup_mailbox()
123 * @adapter - pointer to our soft state
125 * Allocates a 8 byte aligned memory for the handshake mailbox.
128 mega_setup_mailbox(adapter_t
*adapter
)
132 adapter
->una_mbox64
= pci_alloc_consistent(adapter
->dev
,
133 sizeof(mbox64_t
), &adapter
->una_mbox64_dma
);
135 if( !adapter
->una_mbox64
) return -1;
137 adapter
->mbox
= &adapter
->una_mbox64
->mbox
;
139 adapter
->mbox
= (mbox_t
*)((((unsigned long) adapter
->mbox
) + 15) &
142 adapter
->mbox64
= (mbox64_t
*)(((unsigned long)adapter
->mbox
) - 8);
144 align
= ((void *)adapter
->mbox
) - ((void *)&adapter
->una_mbox64
->mbox
);
146 adapter
->mbox_dma
= adapter
->una_mbox64_dma
+ 8 + align
;
149 * Register the mailbox if the controller is an io-mapped controller
151 if( adapter
->flag
& BOARD_IOMAP
) {
153 outb_p(adapter
->mbox_dma
& 0xFF,
154 adapter
->host
->io_port
+ MBOX_PORT0
);
156 outb_p((adapter
->mbox_dma
>> 8) & 0xFF,
157 adapter
->host
->io_port
+ MBOX_PORT1
);
159 outb_p((adapter
->mbox_dma
>> 16) & 0xFF,
160 adapter
->host
->io_port
+ MBOX_PORT2
);
162 outb_p((adapter
->mbox_dma
>> 24) & 0xFF,
163 adapter
->host
->io_port
+ MBOX_PORT3
);
165 outb_p(ENABLE_MBOX_BYTE
,
166 adapter
->host
->io_port
+ ENABLE_MBOX_REGION
);
178 * mega_query_adapter()
179 * @adapter - pointer to our soft state
181 * Issue the adapter inquiry commands to the controller and find out
182 * information and parameter about the devices attached
185 mega_query_adapter(adapter_t
*adapter
)
187 dma_addr_t prod_info_dma_handle
;
188 mega_inquiry3
*inquiry3
;
189 u8 raw_mbox
[sizeof(struct mbox_out
)];
193 /* Initialize adapter inquiry mailbox */
195 mbox
= (mbox_t
*)raw_mbox
;
197 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
198 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
201 * Try to issue Inquiry3 command
202 * if not succeeded, then issue MEGA_MBOXCMD_ADAPTERINQ command and
203 * update enquiry3 structure
205 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
207 inquiry3
= (mega_inquiry3
*)adapter
->mega_buffer
;
209 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
210 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
; /* i.e. 0x0F */
211 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
; /* i.e. 0x02 */
213 /* Issue a blocking command to the card */
214 if ((retval
= issue_scb_block(adapter
, raw_mbox
))) {
215 /* the adapter does not support 40ld */
217 mraid_ext_inquiry
*ext_inq
;
219 dma_addr_t dma_handle
;
221 ext_inq
= pci_alloc_consistent(adapter
->dev
,
222 sizeof(mraid_ext_inquiry
), &dma_handle
);
224 if( ext_inq
== NULL
) return -1;
226 inq
= &ext_inq
->raid_inq
;
228 mbox
->m_out
.xferaddr
= (u32
)dma_handle
;
230 /*issue old 0x04 command to adapter */
231 mbox
->m_out
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
233 issue_scb_block(adapter
, raw_mbox
);
236 * update Enquiry3 and ProductInfo structures with
237 * mraid_inquiry structure
239 mega_8_to_40ld(inq
, inquiry3
,
240 (mega_product_info
*)&adapter
->product_info
);
242 pci_free_consistent(adapter
->dev
, sizeof(mraid_ext_inquiry
),
243 ext_inq
, dma_handle
);
245 } else { /*adapter supports 40ld */
246 adapter
->flag
|= BOARD_40LD
;
249 * get product_info, which is static information and will be
252 prod_info_dma_handle
= pci_map_single(adapter
->dev
, (void *)
253 &adapter
->product_info
,
254 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
256 mbox
->m_out
.xferaddr
= prod_info_dma_handle
;
258 raw_mbox
[0] = FC_NEW_CONFIG
; /* i.e. mbox->cmd=0xA1 */
259 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
; /* i.e. 0x0E */
261 if ((retval
= issue_scb_block(adapter
, raw_mbox
)))
263 "megaraid: Product_info cmd failed with error: %d\n",
266 pci_unmap_single(adapter
->dev
, prod_info_dma_handle
,
267 sizeof(mega_product_info
), PCI_DMA_FROMDEVICE
);
272 * kernel scans the channels from 0 to <= max_channel
274 adapter
->host
->max_channel
=
275 adapter
->product_info
.nchannels
+ NVIRT_CHAN
-1;
277 adapter
->host
->max_id
= 16; /* max targets per channel */
279 adapter
->host
->max_lun
= 7; /* Upto 7 luns for non disk devices */
281 adapter
->host
->cmd_per_lun
= max_cmd_per_lun
;
283 adapter
->numldrv
= inquiry3
->num_ldrv
;
285 adapter
->max_cmds
= adapter
->product_info
.max_commands
;
287 if(adapter
->max_cmds
> MAX_COMMANDS
)
288 adapter
->max_cmds
= MAX_COMMANDS
;
290 adapter
->host
->can_queue
= adapter
->max_cmds
- 1;
293 * Get the maximum number of scatter-gather elements supported by this
296 mega_get_max_sgl(adapter
);
298 adapter
->host
->sg_tablesize
= adapter
->sglen
;
301 /* use HP firmware and bios version encoding */
302 if (adapter
->product_info
.subsysvid
== HP_SUBSYS_VID
) {
303 sprintf (adapter
->fw_version
, "%c%d%d.%d%d",
304 adapter
->product_info
.fw_version
[2],
305 adapter
->product_info
.fw_version
[1] >> 8,
306 adapter
->product_info
.fw_version
[1] & 0x0f,
307 adapter
->product_info
.fw_version
[0] >> 8,
308 adapter
->product_info
.fw_version
[0] & 0x0f);
309 sprintf (adapter
->bios_version
, "%c%d%d.%d%d",
310 adapter
->product_info
.bios_version
[2],
311 adapter
->product_info
.bios_version
[1] >> 8,
312 adapter
->product_info
.bios_version
[1] & 0x0f,
313 adapter
->product_info
.bios_version
[0] >> 8,
314 adapter
->product_info
.bios_version
[0] & 0x0f);
316 memcpy(adapter
->fw_version
,
317 (char *)adapter
->product_info
.fw_version
, 4);
318 adapter
->fw_version
[4] = 0;
320 memcpy(adapter
->bios_version
,
321 (char *)adapter
->product_info
.bios_version
, 4);
323 adapter
->bios_version
[4] = 0;
326 printk(KERN_NOTICE
"megaraid: [%s:%s] detected %d logical drives.\n",
327 adapter
->fw_version
, adapter
->bios_version
, adapter
->numldrv
);
330 * Do we support extended (>10 bytes) cdbs
332 adapter
->support_ext_cdb
= mega_support_ext_cdb(adapter
);
333 if (adapter
->support_ext_cdb
)
334 printk(KERN_NOTICE
"megaraid: supports extended CDBs.\n");
342 * @adapter - pointer to our soft state
344 * Runs through the list of pending requests.
347 mega_runpendq(adapter_t
*adapter
)
349 if(!list_empty(&adapter
->pending_list
))
350 __mega_runpendq(adapter
);
355 * @scmd - Issue this scsi command
356 * @done - the callback hook into the scsi mid-layer
358 * The command queuing entry point for the mid-layer.
361 megaraid_queue(Scsi_Cmnd
*scmd
, void (*done
)(Scsi_Cmnd
*))
368 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
370 scmd
->scsi_done
= done
;
374 * Allocate and build a SCB request
375 * busy flag will be set if mega_build_cmd() command could not
376 * allocate scb. We will return non-zero status in that case.
377 * NOTE: scb can be null even though certain commands completed
378 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
379 * return 0 in that case.
382 spin_lock_irqsave(&adapter
->lock
, flags
);
383 scb
= mega_build_cmd(adapter
, scmd
, &busy
);
387 scb
->state
|= SCB_PENDQ
;
388 list_add_tail(&scb
->list
, &adapter
->pending_list
);
391 * Check if the HBA is in quiescent state, e.g., during a
392 * delete logical drive opertion. If it is, don't run
395 if (atomic_read(&adapter
->quiescent
) == 0)
396 mega_runpendq(adapter
);
400 spin_unlock_irqrestore(&adapter
->lock
, flags
);
405 * mega_allocate_scb()
406 * @adapter - pointer to our soft state
407 * @cmd - scsi command from the mid-layer
409 * Allocate a SCB structure. This is the central structure for controller
412 static inline scb_t
*
413 mega_allocate_scb(adapter_t
*adapter
, Scsi_Cmnd
*cmd
)
415 struct list_head
*head
= &adapter
->free_list
;
418 /* Unlink command from Free List */
419 if( !list_empty(head
) ) {
421 scb
= list_entry(head
->next
, scb_t
, list
);
423 list_del_init(head
->next
);
425 scb
->state
= SCB_ACTIVE
;
427 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
436 * mega_get_ldrv_num()
437 * @adapter - pointer to our soft state
438 * @cmd - scsi mid layer command
439 * @channel - channel on the controller
441 * Calculate the logical drive number based on the information in scsi command
442 * and the channel number.
445 mega_get_ldrv_num(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int channel
)
450 tgt
= cmd
->device
->id
;
452 if ( tgt
> adapter
->this_id
)
453 tgt
--; /* we do not get inquires for initiator id */
455 ldrv_num
= (channel
* 15) + tgt
;
459 * If we have a logical drive with boot enabled, project it first
461 if( adapter
->boot_ldrv_enabled
) {
462 if( ldrv_num
== 0 ) {
463 ldrv_num
= adapter
->boot_ldrv
;
466 if( ldrv_num
<= adapter
->boot_ldrv
) {
473 * If "delete logical drive" feature is enabled on this controller.
474 * Do only if at least one delete logical drive operation was done.
476 * Also, after logical drive deletion, instead of logical drive number,
477 * the value returned should be 0x80+logical drive id.
479 * These is valid only for IO commands.
482 if (adapter
->support_random_del
&& adapter
->read_ldidmap
)
483 switch (cmd
->cmnd
[0]) {
484 case READ_6
: /* fall through */
485 case WRITE_6
: /* fall through */
486 case READ_10
: /* fall through */
496 * @adapter - pointer to our soft state
497 * @cmd - Prepare using this scsi command
498 * @busy - busy flag if no resources
500 * Prepares a command and scatter gather list for the controller. This routine
501 * also finds out if the commands is intended for a logical drive or a
502 * physical device and prepares the controller command accordingly.
504 * We also re-order the logical drives and physical devices based on their
508 mega_build_cmd(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int *busy
)
510 mega_ext_passthru
*epthru
;
511 mega_passthru
*pthru
;
519 int ldrv_num
= 0; /* logical drive number */
523 * filter the internal and ioctl commands
525 if((cmd
->cmnd
[0] == MEGA_INTERNAL_CMD
)) {
531 * We know what channels our logical drives are on - mega_find_card()
533 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
536 * The theory: If physical drive is chosen for boot, all the physical
537 * devices are exported before the logical drives, otherwise physical
538 * devices are pushed after logical drives, in which case - Kernel sees
539 * the physical devices on virtual channel which is obviously converted
540 * to actual channel on the HBA.
542 if( adapter
->boot_pdrv_enabled
) {
544 /* logical channel */
545 channel
= cmd
->device
->channel
-
546 adapter
->product_info
.nchannels
;
549 /* this is physical channel */
550 channel
= cmd
->device
->channel
;
551 target
= cmd
->device
->id
;
554 * boot from a physical disk, that disk needs to be
555 * exposed first IF both the channels are SCSI, then
556 * booting from the second channel is not allowed.
559 target
= adapter
->boot_pdrv_tgt
;
561 else if( target
== adapter
->boot_pdrv_tgt
) {
568 /* this is the logical channel */
569 channel
= cmd
->device
->channel
;
572 /* physical channel */
573 channel
= cmd
->device
->channel
- NVIRT_CHAN
;
574 target
= cmd
->device
->id
;
581 /* have just LUN 0 for each target on virtual channels */
582 if (cmd
->device
->lun
) {
583 cmd
->result
= (DID_BAD_TARGET
<< 16);
588 ldrv_num
= mega_get_ldrv_num(adapter
, cmd
, channel
);
591 max_ldrv_num
= (adapter
->flag
& BOARD_40LD
) ?
592 MAX_LOGICAL_DRIVES_40LD
: MAX_LOGICAL_DRIVES_8LD
;
595 * max_ldrv_num increases by 0x80 if some logical drive was
598 if(adapter
->read_ldidmap
)
599 max_ldrv_num
+= 0x80;
601 if(ldrv_num
> max_ldrv_num
) {
602 cmd
->result
= (DID_BAD_TARGET
<< 16);
609 if( cmd
->device
->lun
> 7) {
611 * Do not support lun >7 for physically accessed
614 cmd
->result
= (DID_BAD_TARGET
<< 16);
622 * Logical drive commands
626 switch (cmd
->cmnd
[0]) {
627 case TEST_UNIT_READY
:
628 #if MEGA_HAVE_CLUSTERING
630 * Do we support clustering and is the support enabled
631 * If no, return success always
633 if( !adapter
->has_cluster
) {
634 cmd
->result
= (DID_OK
<< 16);
639 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
644 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
645 scb
->raw_mbox
[2] = MEGA_RESERVATION_STATUS
;
646 scb
->raw_mbox
[3] = ldrv_num
;
648 scb
->dma_direction
= PCI_DMA_NONE
;
652 cmd
->result
= (DID_OK
<< 16);
661 struct scatterlist
*sg
;
663 sg
= (struct scatterlist
*)cmd
->request_buffer
;
664 buf
= kmap_atomic(sg
->page
, KM_IRQ0
) +
667 buf
= cmd
->request_buffer
;
668 memset(buf
, 0, cmd
->cmnd
[4]);
670 struct scatterlist
*sg
;
672 sg
= (struct scatterlist
*)cmd
->request_buffer
;
673 kunmap_atomic(buf
- sg
->offset
, KM_IRQ0
);
675 cmd
->result
= (DID_OK
<< 16);
683 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
686 "scsi%d: scanning scsi channel %d ",
687 adapter
->host
->host_no
,
688 cmd
->device
->channel
);
689 printk("for logical drives.\n");
691 adapter
->flag
|= (1L << cmd
->device
->channel
);
694 /* Allocate a SCB and initialize passthru */
695 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
701 mbox
= (mbox_t
*)scb
->raw_mbox
;
702 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
703 memset(pthru
, 0, sizeof(mega_passthru
));
707 pthru
->reqsenselen
= 14;
708 pthru
->islogical
= 1;
709 pthru
->logdrv
= ldrv_num
;
710 pthru
->cdblen
= cmd
->cmd_len
;
711 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
713 if( adapter
->has_64bit_addr
) {
714 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
717 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
720 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
722 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
723 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
725 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
736 /* Allocate a SCB and initialize mailbox */
737 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
741 mbox
= (mbox_t
*)scb
->raw_mbox
;
743 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
744 mbox
->m_out
.logdrv
= ldrv_num
;
747 * A little hack: 2nd bit is zero for all scsi read
748 * commands and is set for all scsi write commands
750 if( adapter
->has_64bit_addr
) {
751 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
752 MEGA_MBOXCMD_LWRITE64
:
753 MEGA_MBOXCMD_LREAD64
;
756 mbox
->m_out
.cmd
= (*cmd
->cmnd
& 0x02) ?
762 * 6-byte READ(0x08) or WRITE(0x0A) cdb
764 if( cmd
->cmd_len
== 6 ) {
765 mbox
->m_out
.numsectors
= (u32
) cmd
->cmnd
[4];
767 ((u32
)cmd
->cmnd
[1] << 16) |
768 ((u32
)cmd
->cmnd
[2] << 8) |
771 mbox
->m_out
.lba
&= 0x1FFFFF;
775 * Take modulo 0x80, since the logical drive
776 * number increases by 0x80 when a logical
779 if (*cmd
->cmnd
== READ_6
) {
780 adapter
->nreads
[ldrv_num
%0x80]++;
781 adapter
->nreadblocks
[ldrv_num
%0x80] +=
782 mbox
->m_out
.numsectors
;
784 adapter
->nwrites
[ldrv_num
%0x80]++;
785 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
786 mbox
->m_out
.numsectors
;
792 * 10-byte READ(0x28) or WRITE(0x2A) cdb
794 if( cmd
->cmd_len
== 10 ) {
795 mbox
->m_out
.numsectors
=
797 ((u32
)cmd
->cmnd
[7] << 8);
799 ((u32
)cmd
->cmnd
[2] << 24) |
800 ((u32
)cmd
->cmnd
[3] << 16) |
801 ((u32
)cmd
->cmnd
[4] << 8) |
805 if (*cmd
->cmnd
== READ_10
) {
806 adapter
->nreads
[ldrv_num
%0x80]++;
807 adapter
->nreadblocks
[ldrv_num
%0x80] +=
808 mbox
->m_out
.numsectors
;
810 adapter
->nwrites
[ldrv_num
%0x80]++;
811 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
812 mbox
->m_out
.numsectors
;
818 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
820 if( cmd
->cmd_len
== 12 ) {
822 ((u32
)cmd
->cmnd
[2] << 24) |
823 ((u32
)cmd
->cmnd
[3] << 16) |
824 ((u32
)cmd
->cmnd
[4] << 8) |
827 mbox
->m_out
.numsectors
=
828 ((u32
)cmd
->cmnd
[6] << 24) |
829 ((u32
)cmd
->cmnd
[7] << 16) |
830 ((u32
)cmd
->cmnd
[8] << 8) |
834 if (*cmd
->cmnd
== READ_12
) {
835 adapter
->nreads
[ldrv_num
%0x80]++;
836 adapter
->nreadblocks
[ldrv_num
%0x80] +=
837 mbox
->m_out
.numsectors
;
839 adapter
->nwrites
[ldrv_num
%0x80]++;
840 adapter
->nwriteblocks
[ldrv_num
%0x80] +=
841 mbox
->m_out
.numsectors
;
847 * If it is a read command
849 if( (*cmd
->cmnd
& 0x0F) == 0x08 ) {
850 scb
->dma_direction
= PCI_DMA_FROMDEVICE
;
853 scb
->dma_direction
= PCI_DMA_TODEVICE
;
856 /* Calculate Scatter-Gather info */
857 mbox
->m_out
.numsgelements
= mega_build_sglist(adapter
, scb
,
858 (u32
*)&mbox
->m_out
.xferaddr
, (u32
*)&seg
);
862 #if MEGA_HAVE_CLUSTERING
863 case RESERVE
: /* Fall through */
867 * Do we support clustering and is the support enabled
869 if( ! adapter
->has_cluster
) {
871 cmd
->result
= (DID_BAD_TARGET
<< 16);
876 /* Allocate a SCB and initialize mailbox */
877 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
882 scb
->raw_mbox
[0] = MEGA_CLUSTER_CMD
;
883 scb
->raw_mbox
[2] = ( *cmd
->cmnd
== RESERVE
) ?
884 MEGA_RESERVE_LD
: MEGA_RELEASE_LD
;
886 scb
->raw_mbox
[3] = ldrv_num
;
888 scb
->dma_direction
= PCI_DMA_NONE
;
894 cmd
->result
= (DID_BAD_TARGET
<< 16);
901 * Passthru drive commands
904 /* Allocate a SCB and initialize passthru */
905 if(!(scb
= mega_allocate_scb(adapter
, cmd
))) {
910 mbox
= (mbox_t
*)scb
->raw_mbox
;
911 memset(mbox
, 0, sizeof(scb
->raw_mbox
));
913 if( adapter
->support_ext_cdb
) {
915 epthru
= mega_prepare_extpassthru(adapter
, scb
, cmd
,
918 mbox
->m_out
.cmd
= MEGA_MBOXCMD_EXTPTHRU
;
920 mbox
->m_out
.xferaddr
= scb
->epthru_dma_addr
;
925 pthru
= mega_prepare_passthru(adapter
, scb
, cmd
,
928 /* Initialize mailbox */
929 if( adapter
->has_64bit_addr
) {
930 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU64
;
933 mbox
->m_out
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
936 mbox
->m_out
.xferaddr
= scb
->pthru_dma_addr
;
946 * mega_prepare_passthru()
947 * @adapter - pointer to our soft state
948 * @scb - our scsi control block
949 * @cmd - scsi command from the mid-layer
950 * @channel - actual channel on the controller
951 * @target - actual id on the controller.
953 * prepare a command for the scsi physical devices.
955 static mega_passthru
*
956 mega_prepare_passthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
957 int channel
, int target
)
959 mega_passthru
*pthru
;
962 memset(pthru
, 0, sizeof (mega_passthru
));
964 /* 0=6sec/1=60sec/2=10min/3=3hrs */
968 pthru
->reqsenselen
= 14;
969 pthru
->islogical
= 0;
971 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
973 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
974 (channel
<< 4) | target
: target
;
976 pthru
->cdblen
= cmd
->cmd_len
;
977 pthru
->logdrv
= cmd
->device
->lun
;
979 memcpy(pthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
981 /* Not sure about the direction */
982 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
984 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
985 switch (cmd
->cmnd
[0]) {
988 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
991 "scsi%d: scanning scsi channel %d [P%d] ",
992 adapter
->host
->host_no
,
993 cmd
->device
->channel
, channel
);
994 printk("for physical devices.\n");
996 adapter
->flag
|= (1L << cmd
->device
->channel
);
1000 pthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
1001 &pthru
->dataxferaddr
, &pthru
->dataxferlen
);
1009 * mega_prepare_extpassthru()
1010 * @adapter - pointer to our soft state
1011 * @scb - our scsi control block
1012 * @cmd - scsi command from the mid-layer
1013 * @channel - actual channel on the controller
1014 * @target - actual id on the controller.
1016 * prepare a command for the scsi physical devices. This rountine prepares
1017 * commands for devices which can take extended CDBs (>10 bytes)
1019 static mega_ext_passthru
*
1020 mega_prepare_extpassthru(adapter_t
*adapter
, scb_t
*scb
, Scsi_Cmnd
*cmd
,
1021 int channel
, int target
)
1023 mega_ext_passthru
*epthru
;
1025 epthru
= scb
->epthru
;
1026 memset(epthru
, 0, sizeof(mega_ext_passthru
));
1028 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1029 epthru
->timeout
= 2;
1032 epthru
->reqsenselen
= 14;
1033 epthru
->islogical
= 0;
1035 epthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : channel
;
1036 epthru
->target
= (adapter
->flag
& BOARD_40LD
) ?
1037 (channel
<< 4) | target
: target
;
1039 epthru
->cdblen
= cmd
->cmd_len
;
1040 epthru
->logdrv
= cmd
->device
->lun
;
1042 memcpy(epthru
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1044 /* Not sure about the direction */
1045 scb
->dma_direction
= PCI_DMA_BIDIRECTIONAL
;
1047 switch(cmd
->cmnd
[0]) {
1050 if(!(adapter
->flag
& (1L << cmd
->device
->channel
))) {
1053 "scsi%d: scanning scsi channel %d [P%d] ",
1054 adapter
->host
->host_no
,
1055 cmd
->device
->channel
, channel
);
1056 printk("for physical devices.\n");
1058 adapter
->flag
|= (1L << cmd
->device
->channel
);
1062 epthru
->numsgelements
= mega_build_sglist(adapter
, scb
,
1063 &epthru
->dataxferaddr
, &epthru
->dataxferlen
);
1071 __mega_runpendq(adapter_t
*adapter
)
1074 struct list_head
*pos
, *next
;
1076 /* Issue any pending commands to the card */
1077 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
1079 scb
= list_entry(pos
, scb_t
, list
);
1081 if( !(scb
->state
& SCB_ISSUED
) ) {
1083 if( issue_scb(adapter
, scb
) != 0 )
1094 * @adapter - pointer to our soft state
1095 * @scb - scsi control block
1097 * Post a command to the card if the mailbox is available, otherwise return
1098 * busy. We also take the scb from the pending list if the mailbox is
1102 issue_scb(adapter_t
*adapter
, scb_t
*scb
)
1104 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1105 volatile mbox_t
*mbox
= adapter
->mbox
;
1108 if(unlikely(mbox
->m_in
.busy
)) {
1112 } while( mbox
->m_in
.busy
&& (i
< max_mbox_busy_wait
) );
1114 if(mbox
->m_in
.busy
) return -1;
1117 /* Copy mailbox data into host structure */
1118 memcpy((char *)&mbox
->m_out
, (char *)scb
->raw_mbox
,
1119 sizeof(struct mbox_out
));
1121 mbox
->m_out
.cmdid
= scb
->idx
; /* Set cmdid */
1122 mbox
->m_in
.busy
= 1; /* Set busy */
1126 * Increment the pending queue counter
1128 atomic_inc(&adapter
->pend_cmds
);
1130 switch (mbox
->m_out
.cmd
) {
1131 case MEGA_MBOXCMD_LREAD64
:
1132 case MEGA_MBOXCMD_LWRITE64
:
1133 case MEGA_MBOXCMD_PASSTHRU64
:
1134 case MEGA_MBOXCMD_EXTPTHRU
:
1135 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1136 mbox64
->xfer_segment_hi
= 0;
1137 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1140 mbox64
->xfer_segment_lo
= 0;
1141 mbox64
->xfer_segment_hi
= 0;
1147 scb
->state
|= SCB_ISSUED
;
1149 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1150 mbox
->m_in
.poll
= 0;
1152 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1155 irq_enable(adapter
);
1156 issue_command(adapter
);
1163 * Wait until the controller's mailbox is available
1166 mega_busywait_mbox (adapter_t
*adapter
)
1168 if (adapter
->mbox
->m_in
.busy
)
1169 return __mega_busywait_mbox(adapter
);
1175 * @adapter - pointer to our soft state
1176 * @raw_mbox - the mailbox
1178 * Issue a scb in synchronous and non-interrupt mode
1181 issue_scb_block(adapter_t
*adapter
, u_char
*raw_mbox
)
1183 volatile mbox64_t
*mbox64
= adapter
->mbox64
;
1184 volatile mbox_t
*mbox
= adapter
->mbox
;
1187 /* Wait until mailbox is free */
1188 if(mega_busywait_mbox (adapter
))
1189 goto bug_blocked_mailbox
;
1191 /* Copy mailbox data into host structure */
1192 memcpy((char *) mbox
, raw_mbox
, sizeof(struct mbox_out
));
1193 mbox
->m_out
.cmdid
= 0xFE;
1194 mbox
->m_in
.busy
= 1;
1196 switch (raw_mbox
[0]) {
1197 case MEGA_MBOXCMD_LREAD64
:
1198 case MEGA_MBOXCMD_LWRITE64
:
1199 case MEGA_MBOXCMD_PASSTHRU64
:
1200 case MEGA_MBOXCMD_EXTPTHRU
:
1201 mbox64
->xfer_segment_lo
= mbox
->m_out
.xferaddr
;
1202 mbox64
->xfer_segment_hi
= 0;
1203 mbox
->m_out
.xferaddr
= 0xFFFFFFFF;
1206 mbox64
->xfer_segment_lo
= 0;
1207 mbox64
->xfer_segment_hi
= 0;
1210 if( likely(adapter
->flag
& BOARD_MEMMAP
) ) {
1211 mbox
->m_in
.poll
= 0;
1213 mbox
->m_in
.numstatus
= 0xFF;
1214 mbox
->m_in
.status
= 0xFF;
1215 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x1);
1217 while((volatile u8
)mbox
->m_in
.numstatus
== 0xFF)
1220 mbox
->m_in
.numstatus
= 0xFF;
1222 while( (volatile u8
)mbox
->m_in
.poll
!= 0x77 )
1225 mbox
->m_in
.poll
= 0;
1226 mbox
->m_in
.ack
= 0x77;
1228 WRINDOOR(adapter
, adapter
->mbox_dma
| 0x2);
1230 while(RDINDOOR(adapter
) & 0x2)
1234 irq_disable(adapter
);
1235 issue_command(adapter
);
1237 while (!((byte
= irq_state(adapter
)) & INTR_VALID
))
1240 set_irq_state(adapter
, byte
);
1241 irq_enable(adapter
);
1245 return mbox
->m_in
.status
;
1247 bug_blocked_mailbox
:
1248 printk(KERN_WARNING
"megaraid: Blocked mailbox......!!\n");
1255 * megaraid_isr_iomapped()
1257 * @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
, struct pt_regs
*regs
)
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
1337 * Interrupt service routine for memory-mapped controllers.
1338 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1339 * and service the completed commands.
1342 megaraid_isr_memmapped(int irq
, void *devp
, struct pt_regs
*regs
)
1344 adapter_t
*adapter
= devp
;
1345 unsigned long flags
;
1349 u8 completed
[MAX_FIRMWARE_STATUS
];
1354 * loop till F/W has more commands for us to complete.
1356 spin_lock_irqsave(&adapter
->lock
, flags
);
1359 /* Check if a valid interrupt is pending */
1360 dword
= RDOUTDOOR(adapter
);
1361 if(dword
!= 0x10001234) {
1363 * No more pending commands
1367 WROUTDOOR(adapter
, 0x10001234);
1369 while((nstatus
= (volatile u8
)adapter
->mbox
->m_in
.numstatus
)
1373 adapter
->mbox
->m_in
.numstatus
= 0xFF;
1375 status
= adapter
->mbox
->m_in
.status
;
1378 * decrement the pending queue counter
1380 atomic_sub(nstatus
, &adapter
->pend_cmds
);
1382 memcpy(completed
, (void *)adapter
->mbox
->m_in
.completed
,
1385 /* Acknowledge interrupt */
1386 WRINDOOR(adapter
, 0x2);
1390 while( RDINDOOR(adapter
) & 0x02 ) cpu_relax();
1392 mega_cmd_done(adapter
, completed
, nstatus
, status
);
1394 mega_rundoneq(adapter
);
1396 /* Loop through any pending requests */
1397 if(atomic_read(&adapter
->quiescent
) == 0) {
1398 mega_runpendq(adapter
);
1405 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1407 return IRQ_RETVAL(handled
);
1411 * @adapter - pointer to our soft state
1412 * @completed - array of ids of completed commands
1413 * @nstatus - number of completed commands
1414 * @status - status of the last command completed
1416 * Complete the comamnds and call the scsi mid-layer callback hooks.
1419 mega_cmd_done(adapter_t
*adapter
, u8 completed
[], int nstatus
, int status
)
1421 mega_ext_passthru
*epthru
= NULL
;
1422 struct scatterlist
*sgl
;
1423 Scsi_Cmnd
*cmd
= NULL
;
1424 mega_passthru
*pthru
= NULL
;
1425 mbox_t
*mbox
= NULL
;
1433 * for all the commands completed, call the mid-layer callback routine
1436 for( i
= 0; i
< nstatus
; i
++ ) {
1438 cmdid
= completed
[i
];
1440 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1441 scb
= &adapter
->int_scb
;
1443 mbox
= (mbox_t
*)scb
->raw_mbox
;
1446 * Internal command interface do not fire the extended
1447 * passthru or 64-bit passthru
1453 scb
= &adapter
->scb_list
[cmdid
];
1456 * Make sure f/w has completed a valid command
1458 if( !(scb
->state
& SCB_ISSUED
) || scb
->cmd
== NULL
) {
1460 "megaraid: invalid command ");
1461 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1462 cmdid
, scb
->state
, scb
->cmd
);
1468 * Was a abort issued for this command
1470 if( scb
->state
& SCB_ABORT
) {
1473 "megaraid: aborted cmd %lx[%x] complete.\n",
1474 scb
->cmd
->serial_number
, scb
->idx
);
1476 scb
->cmd
->result
= (DID_ABORT
<< 16);
1478 list_add_tail(SCSI_LIST(scb
->cmd
),
1479 &adapter
->completed_list
);
1481 mega_free_scb(adapter
, scb
);
1487 * Was a reset issued for this command
1489 if( scb
->state
& SCB_RESET
) {
1492 "megaraid: reset cmd %lx[%x] complete.\n",
1493 scb
->cmd
->serial_number
, scb
->idx
);
1495 scb
->cmd
->result
= (DID_RESET
<< 16);
1497 list_add_tail(SCSI_LIST(scb
->cmd
),
1498 &adapter
->completed_list
);
1500 mega_free_scb (adapter
, scb
);
1507 epthru
= scb
->epthru
;
1508 mbox
= (mbox_t
*)scb
->raw_mbox
;
1513 int logdrv
= mbox
->m_out
.logdrv
;
1515 islogical
= adapter
->logdrv_chan
[cmd
->channel
];
1517 * Maintain an error counter for the logical drive.
1518 * Some application like SNMP agent need such
1521 if( status
&& islogical
&& (cmd
->cmnd
[0] == READ_6
||
1522 cmd
->cmnd
[0] == READ_10
||
1523 cmd
->cmnd
[0] == READ_12
)) {
1525 * Logical drive number increases by 0x80 when
1526 * a logical drive is deleted
1528 adapter
->rd_errors
[logdrv
%0x80]++;
1531 if( status
&& islogical
&& (cmd
->cmnd
[0] == WRITE_6
||
1532 cmd
->cmnd
[0] == WRITE_10
||
1533 cmd
->cmnd
[0] == WRITE_12
)) {
1535 * Logical drive number increases by 0x80 when
1536 * a logical drive is deleted
1538 adapter
->wr_errors
[logdrv
%0x80]++;
1546 * Do not return the presence of hard disk on the channel so,
1547 * inquiry sent, and returned data==hard disk or removable
1548 * hard disk and not logical, request should return failure! -
1551 islogical
= adapter
->logdrv_chan
[cmd
->device
->channel
];
1552 if( cmd
->cmnd
[0] == INQUIRY
&& !islogical
) {
1555 sgl
= (struct scatterlist
*)
1556 cmd
->request_buffer
;
1559 c
= *(unsigned char *)
1560 page_address((&sgl
[0])->page
) +
1565 "megaraid: invalid sg.\n");
1570 c
= *(u8
*)cmd
->request_buffer
;
1573 if(IS_RAID_CH(adapter
, cmd
->device
->channel
) &&
1574 ((c
& 0x1F ) == TYPE_DISK
)) {
1579 /* clear result; otherwise, success returns corrupt value */
1582 /* Convert MegaRAID status to Linux error code */
1584 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1585 cmd
->result
|= (DID_OK
<< 16);
1588 case 0x02: /* ERROR_ABORTED, i.e.
1589 SCSI_STATUS_CHECK_CONDITION */
1591 /* set sense_buffer and result fields */
1592 if( mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU
||
1593 mbox
->m_out
.cmd
== MEGA_MBOXCMD_PASSTHRU64
) {
1595 memcpy(cmd
->sense_buffer
, pthru
->reqsensearea
,
1598 cmd
->result
= (DRIVER_SENSE
<< 24) |
1600 (CHECK_CONDITION
<< 1);
1603 if (mbox
->m_out
.cmd
== MEGA_MBOXCMD_EXTPTHRU
) {
1605 memcpy(cmd
->sense_buffer
,
1606 epthru
->reqsensearea
, 14);
1608 cmd
->result
= (DRIVER_SENSE
<< 24) |
1610 (CHECK_CONDITION
<< 1);
1612 cmd
->sense_buffer
[0] = 0x70;
1613 cmd
->sense_buffer
[2] = ABORTED_COMMAND
;
1614 cmd
->result
|= (CHECK_CONDITION
<< 1);
1619 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1621 cmd
->result
|= (DID_BUS_BUSY
<< 16) | status
;
1625 #if MEGA_HAVE_CLUSTERING
1627 * If TEST_UNIT_READY fails, we know
1628 * MEGA_RESERVATION_STATUS failed
1630 if( cmd
->cmnd
[0] == TEST_UNIT_READY
) {
1631 cmd
->result
|= (DID_ERROR
<< 16) |
1632 (RESERVATION_CONFLICT
<< 1);
1636 * Error code returned is 1 if Reserve or Release
1637 * failed or the input parameter is invalid
1640 (cmd
->cmnd
[0] == RESERVE
||
1641 cmd
->cmnd
[0] == RELEASE
) ) {
1643 cmd
->result
|= (DID_ERROR
<< 16) |
1644 (RESERVATION_CONFLICT
<< 1);
1648 cmd
->result
|= (DID_BAD_TARGET
<< 16)|status
;
1652 * Only free SCBs for the commands coming down from the
1653 * mid-layer, not for which were issued internally
1655 * For internal command, restore the status returned by the
1656 * firmware so that user can interpret it.
1658 if( cmdid
== CMDID_INT_CMDS
) { /* internal command */
1659 cmd
->result
= status
;
1662 * Remove the internal command from the pending list
1664 list_del_init(&scb
->list
);
1665 scb
->state
= SCB_FREE
;
1668 mega_free_scb(adapter
, scb
);
1671 /* Add Scsi_Command to end of completed queue */
1672 list_add_tail(SCSI_LIST(cmd
), &adapter
->completed_list
);
1680 * Run through the list of completed requests and finish it
1683 mega_rundoneq (adapter_t
*adapter
)
1686 struct list_head
*pos
;
1688 list_for_each(pos
, &adapter
->completed_list
) {
1690 struct scsi_pointer
* spos
= (struct scsi_pointer
*)pos
;
1692 cmd
= list_entry(spos
, Scsi_Cmnd
, SCp
);
1693 cmd
->scsi_done(cmd
);
1696 INIT_LIST_HEAD(&adapter
->completed_list
);
1701 * Free a SCB structure
1702 * Note: We assume the scsi commands associated with this scb is not free yet.
1705 mega_free_scb(adapter_t
*adapter
, scb_t
*scb
)
1707 unsigned long length
;
1709 switch( scb
->dma_type
) {
1711 case MEGA_DMA_TYPE_NONE
:
1714 case MEGA_BULK_DATA
:
1715 if (scb
->cmd
->use_sg
== 0)
1716 length
= scb
->cmd
->request_bufflen
;
1718 struct scatterlist
*sgl
=
1719 (struct scatterlist
*)scb
->cmd
->request_buffer
;
1720 length
= sgl
->length
;
1722 pci_unmap_page(adapter
->dev
, scb
->dma_h_bulkdata
,
1723 length
, scb
->dma_direction
);
1727 pci_unmap_sg(adapter
->dev
, scb
->cmd
->request_buffer
,
1728 scb
->cmd
->use_sg
, scb
->dma_direction
);
1736 * Remove from the pending list
1738 list_del_init(&scb
->list
);
1740 /* Link the scb back into free list */
1741 scb
->state
= SCB_FREE
;
1744 list_add(&scb
->list
, &adapter
->free_list
);
1749 __mega_busywait_mbox (adapter_t
*adapter
)
1751 volatile mbox_t
*mbox
= adapter
->mbox
;
1754 for (counter
= 0; counter
< 10000; counter
++) {
1755 if (!mbox
->m_in
.busy
)
1757 udelay(100); yield();
1759 return -1; /* give up after 1 second */
1763 * Copies data to SGLIST
1764 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1767 mega_build_sglist(adapter_t
*adapter
, scb_t
*scb
, u32
*buf
, u32
*len
)
1769 struct scatterlist
*sgl
;
1771 unsigned long offset
;
1772 unsigned int length
;
1779 /* Scatter-gather not used */
1780 if( cmd
->use_sg
== 0 || (cmd
->use_sg
== 1 &&
1781 !adapter
->has_64bit_addr
)) {
1783 if (cmd
->use_sg
== 0) {
1784 page
= virt_to_page(cmd
->request_buffer
);
1785 offset
= offset_in_page(cmd
->request_buffer
);
1786 length
= cmd
->request_bufflen
;
1788 sgl
= (struct scatterlist
*)cmd
->request_buffer
;
1790 offset
= sgl
->offset
;
1791 length
= sgl
->length
;
1794 scb
->dma_h_bulkdata
= pci_map_page(adapter
->dev
,
1797 scb
->dma_direction
);
1798 scb
->dma_type
= MEGA_BULK_DATA
;
1801 * We need to handle special 64-bit commands that need a
1804 if( adapter
->has_64bit_addr
) {
1805 scb
->sgl64
[0].address
= scb
->dma_h_bulkdata
;
1806 scb
->sgl64
[0].length
= length
;
1807 *buf
= (u32
)scb
->sgl_dma_addr
;
1812 *buf
= (u32
)scb
->dma_h_bulkdata
;
1818 sgl
= (struct scatterlist
*)cmd
->request_buffer
;
1821 * Copy Scatter-Gather list info into controller structure.
1823 * The number of sg elements returned must not exceed our limit
1825 sgcnt
= pci_map_sg(adapter
->dev
, sgl
, cmd
->use_sg
,
1826 scb
->dma_direction
);
1828 scb
->dma_type
= MEGA_SGLIST
;
1830 if( sgcnt
> adapter
->sglen
) BUG();
1834 for( idx
= 0; idx
< sgcnt
; idx
++, sgl
++ ) {
1836 if( adapter
->has_64bit_addr
) {
1837 scb
->sgl64
[idx
].address
= sg_dma_address(sgl
);
1838 *len
+= scb
->sgl64
[idx
].length
= sg_dma_len(sgl
);
1841 scb
->sgl
[idx
].address
= sg_dma_address(sgl
);
1842 *len
+= scb
->sgl
[idx
].length
= sg_dma_len(sgl
);
1846 /* Reset pointer and length fields */
1847 *buf
= scb
->sgl_dma_addr
;
1849 /* Return count of SG requests */
1857 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1858 * Enquiry3 structures for later use
1861 mega_8_to_40ld(mraid_inquiry
*inquiry
, mega_inquiry3
*enquiry3
,
1862 mega_product_info
*product_info
)
1866 product_info
->max_commands
= inquiry
->adapter_info
.max_commands
;
1867 enquiry3
->rebuild_rate
= inquiry
->adapter_info
.rebuild_rate
;
1868 product_info
->nchannels
= inquiry
->adapter_info
.nchannels
;
1870 for (i
= 0; i
< 4; i
++) {
1871 product_info
->fw_version
[i
] =
1872 inquiry
->adapter_info
.fw_version
[i
];
1874 product_info
->bios_version
[i
] =
1875 inquiry
->adapter_info
.bios_version
[i
];
1877 enquiry3
->cache_flush_interval
=
1878 inquiry
->adapter_info
.cache_flush_interval
;
1880 product_info
->dram_size
= inquiry
->adapter_info
.dram_size
;
1882 enquiry3
->num_ldrv
= inquiry
->logdrv_info
.num_ldrv
;
1884 for (i
= 0; i
< MAX_LOGICAL_DRIVES_8LD
; i
++) {
1885 enquiry3
->ldrv_size
[i
] = inquiry
->logdrv_info
.ldrv_size
[i
];
1886 enquiry3
->ldrv_prop
[i
] = inquiry
->logdrv_info
.ldrv_prop
[i
];
1887 enquiry3
->ldrv_state
[i
] = inquiry
->logdrv_info
.ldrv_state
[i
];
1890 for (i
= 0; i
< (MAX_PHYSICAL_DRIVES
); i
++)
1891 enquiry3
->pdrv_state
[i
] = inquiry
->pdrv_info
.pdrv_state
[i
];
1895 mega_free_sgl(adapter_t
*adapter
)
1900 for(i
= 0; i
< adapter
->max_cmds
; i
++) {
1902 scb
= &adapter
->scb_list
[i
];
1905 pci_free_consistent(adapter
->dev
,
1906 sizeof(mega_sgl64
) * adapter
->sglen
,
1914 pci_free_consistent(adapter
->dev
, sizeof(mega_passthru
),
1915 scb
->pthru
, scb
->pthru_dma_addr
);
1921 pci_free_consistent(adapter
->dev
,
1922 sizeof(mega_ext_passthru
),
1923 scb
->epthru
, scb
->epthru_dma_addr
);
1933 * Get information about the card/driver
1936 megaraid_info(struct Scsi_Host
*host
)
1938 static char buffer
[512];
1941 adapter
= (adapter_t
*)host
->hostdata
;
1944 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1945 adapter
->fw_version
, adapter
->product_info
.max_commands
,
1946 adapter
->host
->max_id
, adapter
->host
->max_channel
,
1947 adapter
->host
->max_lun
);
1952 * Abort a previous SCSI request. Only commands on the pending list can be
1953 * aborted. All the commands issued to the F/W must complete.
1956 megaraid_abort(Scsi_Cmnd
*cmd
)
1961 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1963 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_ABORT
);
1966 * This is required here to complete any completed requests
1967 * to be communicated over to the mid layer.
1969 mega_rundoneq(adapter
);
1976 megaraid_reset(struct scsi_cmnd
*cmd
)
1982 adapter
= (adapter_t
*)cmd
->device
->host
->hostdata
;
1984 #if MEGA_HAVE_CLUSTERING
1985 mc
.cmd
= MEGA_CLUSTER_CMD
;
1986 mc
.opcode
= MEGA_RESET_RESERVATIONS
;
1988 if( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
1990 "megaraid: reservation reset failed.\n");
1993 printk(KERN_INFO
"megaraid: reservation reset.\n");
1997 spin_lock_irq(&adapter
->lock
);
1999 rval
= megaraid_abort_and_reset(adapter
, cmd
, SCB_RESET
);
2002 * This is required here to complete any completed requests
2003 * to be communicated over to the mid layer.
2005 mega_rundoneq(adapter
);
2006 spin_unlock_irq(&adapter
->lock
);
2012 * megaraid_abort_and_reset()
2013 * @adapter - megaraid soft state
2014 * @cmd - scsi command to be aborted or reset
2015 * @aor - abort or reset flag
2017 * Try to locate the scsi command in the pending queue. If found and is not
2018 * issued to the controller, abort/reset it. Otherwise return failure
2021 megaraid_abort_and_reset(adapter_t
*adapter
, Scsi_Cmnd
*cmd
, int aor
)
2023 struct list_head
*pos
, *next
;
2026 printk(KERN_WARNING
"megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
2027 (aor
== SCB_ABORT
)? "ABORTING":"RESET", cmd
->serial_number
,
2028 cmd
->cmnd
[0], cmd
->device
->channel
,
2029 cmd
->device
->id
, cmd
->device
->lun
);
2031 if(list_empty(&adapter
->pending_list
))
2034 list_for_each_safe(pos
, next
, &adapter
->pending_list
) {
2036 scb
= list_entry(pos
, scb_t
, list
);
2038 if (scb
->cmd
== cmd
) { /* Found command */
2043 * Check if this command has firmare owenership. If
2044 * yes, we cannot reset this command. Whenever, f/w
2045 * completes this command, we will return appropriate
2048 if( scb
->state
& SCB_ISSUED
) {
2051 "megaraid: %s-%lx[%x], fw owner.\n",
2052 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
2053 cmd
->serial_number
, scb
->idx
);
2060 * Not yet issued! Remove from the pending
2064 "megaraid: %s-%lx[%x], driver owner.\n",
2065 (aor
==SCB_ABORT
) ? "ABORTING":"RESET",
2066 cmd
->serial_number
, scb
->idx
);
2068 mega_free_scb(adapter
, scb
);
2070 if( aor
== SCB_ABORT
) {
2071 cmd
->result
= (DID_ABORT
<< 16);
2074 cmd
->result
= (DID_RESET
<< 16);
2077 list_add_tail(SCSI_LIST(cmd
),
2078 &adapter
->completed_list
);
2089 make_local_pdev(adapter_t
*adapter
, struct pci_dev
**pdev
)
2091 *pdev
= kmalloc(sizeof(struct pci_dev
), GFP_KERNEL
);
2093 if( *pdev
== NULL
) return -1;
2095 memcpy(*pdev
, adapter
->dev
, sizeof(struct pci_dev
));
2097 if( pci_set_dma_mask(*pdev
, 0xffffffff) != 0 ) {
2106 free_local_pdev(struct pci_dev
*pdev
)
2112 * mega_allocate_inquiry()
2113 * @dma_handle - handle returned for dma address
2114 * @pdev - handle to pci device
2116 * allocates memory for inquiry structure
2118 static inline void *
2119 mega_allocate_inquiry(dma_addr_t
*dma_handle
, struct pci_dev
*pdev
)
2121 return pci_alloc_consistent(pdev
, sizeof(mega_inquiry3
), dma_handle
);
2126 mega_free_inquiry(void *inquiry
, dma_addr_t dma_handle
, struct pci_dev
*pdev
)
2128 pci_free_consistent(pdev
, sizeof(mega_inquiry3
), inquiry
, dma_handle
);
2132 #ifdef CONFIG_PROC_FS
2133 /* Following code handles /proc fs */
2135 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2136 S_IRUSR | S_IFREG, \
2137 controller_proc_dir_entry, \
2141 * mega_create_proc_entry()
2142 * @index - index in soft state array
2143 * @parent - parent node for this /proc entry
2145 * Creates /proc entries for our controllers.
2148 mega_create_proc_entry(int index
, struct proc_dir_entry
*parent
)
2150 struct proc_dir_entry
*controller_proc_dir_entry
= NULL
;
2151 u8 string
[64] = { 0 };
2152 adapter_t
*adapter
= hba_soft_state
[index
];
2154 sprintf(string
, "hba%d", adapter
->host
->host_no
);
2156 controller_proc_dir_entry
=
2157 adapter
->controller_proc_dir_entry
= proc_mkdir(string
, parent
);
2159 if(!controller_proc_dir_entry
) {
2160 printk(KERN_WARNING
"\nmegaraid: proc_mkdir failed\n");
2163 adapter
->proc_read
= CREATE_READ_PROC("config", proc_read_config
);
2164 adapter
->proc_stat
= CREATE_READ_PROC("stat", proc_read_stat
);
2165 adapter
->proc_mbox
= CREATE_READ_PROC("mailbox", proc_read_mbox
);
2166 #if MEGA_HAVE_ENH_PROC
2167 adapter
->proc_rr
= CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate
);
2168 adapter
->proc_battery
= CREATE_READ_PROC("battery-status",
2172 * Display each physical drive on its channel
2174 adapter
->proc_pdrvstat
[0] = CREATE_READ_PROC("diskdrives-ch0",
2176 adapter
->proc_pdrvstat
[1] = CREATE_READ_PROC("diskdrives-ch1",
2178 adapter
->proc_pdrvstat
[2] = CREATE_READ_PROC("diskdrives-ch2",
2180 adapter
->proc_pdrvstat
[3] = CREATE_READ_PROC("diskdrives-ch3",
2184 * Display a set of up to 10 logical drive through each of following
2187 adapter
->proc_rdrvstat
[0] = CREATE_READ_PROC("raiddrives-0-9",
2189 adapter
->proc_rdrvstat
[1] = CREATE_READ_PROC("raiddrives-10-19",
2191 adapter
->proc_rdrvstat
[2] = CREATE_READ_PROC("raiddrives-20-29",
2193 adapter
->proc_rdrvstat
[3] = CREATE_READ_PROC("raiddrives-30-39",
2200 * proc_read_config()
2201 * @page - buffer to write the data in
2202 * @start - where the actual data has been written in page
2203 * @offset - same meaning as the read system call
2204 * @count - same meaning as the read system call
2205 * @eof - set if no more data needs to be returned
2206 * @data - pointer to our soft state
2208 * Display configuration information about the controller.
2211 proc_read_config(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2215 adapter_t
*adapter
= (adapter_t
*)data
;
2218 len
+= sprintf(page
+len
, "%s", MEGARAID_VERSION
);
2220 if(adapter
->product_info
.product_name
[0])
2221 len
+= sprintf(page
+len
, "%s\n",
2222 adapter
->product_info
.product_name
);
2224 len
+= sprintf(page
+len
, "Controller Type: ");
2226 if( adapter
->flag
& BOARD_MEMMAP
) {
2227 len
+= sprintf(page
+len
,
2228 "438/466/467/471/493/518/520/531/532\n");
2231 len
+= sprintf(page
+len
,
2235 if(adapter
->flag
& BOARD_40LD
) {
2236 len
+= sprintf(page
+len
,
2237 "Controller Supports 40 Logical Drives\n");
2240 if(adapter
->flag
& BOARD_64BIT
) {
2241 len
+= sprintf(page
+len
,
2242 "Controller capable of 64-bit memory addressing\n");
2244 if( adapter
->has_64bit_addr
) {
2245 len
+= sprintf(page
+len
,
2246 "Controller using 64-bit memory addressing\n");
2249 len
+= sprintf(page
+len
,
2250 "Controller is not using 64-bit memory addressing\n");
2253 len
+= sprintf(page
+len
, "Base = %08lx, Irq = %d, ", adapter
->base
,
2254 adapter
->host
->irq
);
2256 len
+= sprintf(page
+len
, "Logical Drives = %d, Channels = %d\n",
2257 adapter
->numldrv
, adapter
->product_info
.nchannels
);
2259 len
+= sprintf(page
+len
, "Version =%s:%s, DRAM = %dMb\n",
2260 adapter
->fw_version
, adapter
->bios_version
,
2261 adapter
->product_info
.dram_size
);
2263 len
+= sprintf(page
+len
,
2264 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2265 adapter
->product_info
.max_commands
, adapter
->max_cmds
);
2267 len
+= sprintf(page
+len
, "support_ext_cdb = %d\n",
2268 adapter
->support_ext_cdb
);
2269 len
+= sprintf(page
+len
, "support_random_del = %d\n",
2270 adapter
->support_random_del
);
2271 len
+= sprintf(page
+len
, "boot_ldrv_enabled = %d\n",
2272 adapter
->boot_ldrv_enabled
);
2273 len
+= sprintf(page
+len
, "boot_ldrv = %d\n",
2274 adapter
->boot_ldrv
);
2275 len
+= sprintf(page
+len
, "boot_pdrv_enabled = %d\n",
2276 adapter
->boot_pdrv_enabled
);
2277 len
+= sprintf(page
+len
, "boot_pdrv_ch = %d\n",
2278 adapter
->boot_pdrv_ch
);
2279 len
+= sprintf(page
+len
, "boot_pdrv_tgt = %d\n",
2280 adapter
->boot_pdrv_tgt
);
2281 len
+= sprintf(page
+len
, "quiescent = %d\n",
2282 atomic_read(&adapter
->quiescent
));
2283 len
+= sprintf(page
+len
, "has_cluster = %d\n",
2284 adapter
->has_cluster
);
2286 len
+= sprintf(page
+len
, "\nModule Parameters:\n");
2287 len
+= sprintf(page
+len
, "max_cmd_per_lun = %d\n",
2289 len
+= sprintf(page
+len
, "max_sectors_per_io = %d\n",
2290 max_sectors_per_io
);
2301 * @page - buffer to write the data in
2302 * @start - where the actual data has been written in page
2303 * @offset - same meaning as the read system call
2304 * @count - same meaning as the read system call
2305 * @eof - set if no more data needs to be returned
2306 * @data - pointer to our soft state
2308 * Diaplay statistical information about the I/O activity.
2311 proc_read_stat(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2318 i
= 0; /* avoid compilation warnings */
2320 adapter
= (adapter_t
*)data
;
2322 len
= sprintf(page
, "Statistical Information for this controller\n");
2323 len
+= sprintf(page
+len
, "pend_cmds = %d\n",
2324 atomic_read(&adapter
->pend_cmds
));
2326 for(i
= 0; i
< adapter
->numldrv
; i
++) {
2327 len
+= sprintf(page
+len
, "Logical Drive %d:\n", i
);
2329 len
+= sprintf(page
+len
,
2330 "\tReads Issued = %lu, Writes Issued = %lu\n",
2331 adapter
->nreads
[i
], adapter
->nwrites
[i
]);
2333 len
+= sprintf(page
+len
,
2334 "\tSectors Read = %lu, Sectors Written = %lu\n",
2335 adapter
->nreadblocks
[i
], adapter
->nwriteblocks
[i
]);
2337 len
+= sprintf(page
+len
,
2338 "\tRead errors = %lu, Write errors = %lu\n\n",
2339 adapter
->rd_errors
[i
], adapter
->wr_errors
[i
]);
2342 len
+= sprintf(page
+len
,
2343 "IO and error counters not compiled in driver.\n");
2354 * @page - buffer to write the data in
2355 * @start - where the actual data has been written in page
2356 * @offset - same meaning as the read system call
2357 * @count - same meaning as the read system call
2358 * @eof - set if no more data needs to be returned
2359 * @data - pointer to our soft state
2361 * Display mailbox information for the last command issued. This information
2362 * is good for debugging.
2365 proc_read_mbox(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2369 adapter_t
*adapter
= (adapter_t
*)data
;
2370 volatile mbox_t
*mbox
= adapter
->mbox
;
2373 len
= sprintf(page
, "Contents of Mail Box Structure\n");
2374 len
+= sprintf(page
+len
, " Fw Command = 0x%02x\n",
2376 len
+= sprintf(page
+len
, " Cmd Sequence = 0x%02x\n",
2378 len
+= sprintf(page
+len
, " No of Sectors= %04d\n",
2379 mbox
->m_out
.numsectors
);
2380 len
+= sprintf(page
+len
, " LBA = 0x%02x\n",
2382 len
+= sprintf(page
+len
, " DTA = 0x%08x\n",
2383 mbox
->m_out
.xferaddr
);
2384 len
+= sprintf(page
+len
, " Logical Drive= 0x%02x\n",
2385 mbox
->m_out
.logdrv
);
2386 len
+= sprintf(page
+len
, " No of SG Elmt= 0x%02x\n",
2387 mbox
->m_out
.numsgelements
);
2388 len
+= sprintf(page
+len
, " Busy = %01x\n",
2390 len
+= sprintf(page
+len
, " Status = 0x%02x\n",
2400 * proc_rebuild_rate()
2401 * @page - buffer to write the data in
2402 * @start - where the actual data has been written in page
2403 * @offset - same meaning as the read system call
2404 * @count - same meaning as the read system call
2405 * @eof - set if no more data needs to be returned
2406 * @data - pointer to our soft state
2408 * Display current rebuild rate
2411 proc_rebuild_rate(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2414 adapter_t
*adapter
= (adapter_t
*)data
;
2415 dma_addr_t dma_handle
;
2417 struct pci_dev
*pdev
;
2420 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2425 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2426 free_local_pdev(pdev
);
2431 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2433 len
= sprintf(page
, "Adapter inquiry failed.\n");
2435 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2437 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2439 free_local_pdev(pdev
);
2446 if( adapter
->flag
& BOARD_40LD
) {
2447 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2448 ((mega_inquiry3
*)inquiry
)->rebuild_rate
);
2451 len
= sprintf(page
, "Rebuild Rate: [%d%%]\n",
2452 ((mraid_ext_inquiry
*)
2453 inquiry
)->raid_inq
.adapter_info
.rebuild_rate
);
2457 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2459 free_local_pdev(pdev
);
2469 * @page - buffer to write the data in
2470 * @start - where the actual data has been written in page
2471 * @offset - same meaning as the read system call
2472 * @count - same meaning as the read system call
2473 * @eof - set if no more data needs to be returned
2474 * @data - pointer to our soft state
2476 * Display information about the battery module on the controller.
2479 proc_battery(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2482 adapter_t
*adapter
= (adapter_t
*)data
;
2483 dma_addr_t dma_handle
;
2485 struct pci_dev
*pdev
;
2486 u8 battery_status
= 0;
2490 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2495 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2496 free_local_pdev(pdev
);
2501 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2503 len
= sprintf(page
, "Adapter inquiry failed.\n");
2505 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2507 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2509 free_local_pdev(pdev
);
2516 if( adapter
->flag
& BOARD_40LD
) {
2517 battery_status
= ((mega_inquiry3
*)inquiry
)->battery_status
;
2520 battery_status
= ((mraid_ext_inquiry
*)inquiry
)->
2521 raid_inq
.adapter_info
.battery_status
;
2525 * Decode the battery status
2527 sprintf(str
, "Battery Status:[%d]", battery_status
);
2529 if(battery_status
== MEGA_BATT_CHARGE_DONE
)
2530 strcat(str
, " Charge Done");
2532 if(battery_status
& MEGA_BATT_MODULE_MISSING
)
2533 strcat(str
, " Module Missing");
2535 if(battery_status
& MEGA_BATT_LOW_VOLTAGE
)
2536 strcat(str
, " Low Voltage");
2538 if(battery_status
& MEGA_BATT_TEMP_HIGH
)
2539 strcat(str
, " Temperature High");
2541 if(battery_status
& MEGA_BATT_PACK_MISSING
)
2542 strcat(str
, " Pack Missing");
2544 if(battery_status
& MEGA_BATT_CHARGE_INPROG
)
2545 strcat(str
, " Charge In-progress");
2547 if(battery_status
& MEGA_BATT_CHARGE_FAIL
)
2548 strcat(str
, " Charge Fail");
2550 if(battery_status
& MEGA_BATT_CYCLES_EXCEEDED
)
2551 strcat(str
, " Cycles Exceeded");
2553 len
= sprintf(page
, "%s\n", str
);
2556 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2558 free_local_pdev(pdev
);
2568 * @page - buffer to write the data in
2569 * @start - where the actual data has been written in page
2570 * @offset - same meaning as the read system call
2571 * @count - same meaning as the read system call
2572 * @eof - set if no more data needs to be returned
2573 * @data - pointer to our soft state
2575 * Display information about the physical drives on physical channel 0.
2578 proc_pdrv_ch0(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2581 adapter_t
*adapter
= (adapter_t
*)data
;
2585 return (proc_pdrv(adapter
, page
, 0));
2591 * @page - buffer to write the data in
2592 * @start - where the actual data has been written in page
2593 * @offset - same meaning as the read system call
2594 * @count - same meaning as the read system call
2595 * @eof - set if no more data needs to be returned
2596 * @data - pointer to our soft state
2598 * Display information about the physical drives on physical channel 1.
2601 proc_pdrv_ch1(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2604 adapter_t
*adapter
= (adapter_t
*)data
;
2608 return (proc_pdrv(adapter
, page
, 1));
2614 * @page - buffer to write the data in
2615 * @start - where the actual data has been written in page
2616 * @offset - same meaning as the read system call
2617 * @count - same meaning as the read system call
2618 * @eof - set if no more data needs to be returned
2619 * @data - pointer to our soft state
2621 * Display information about the physical drives on physical channel 2.
2624 proc_pdrv_ch2(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2627 adapter_t
*adapter
= (adapter_t
*)data
;
2631 return (proc_pdrv(adapter
, page
, 2));
2637 * @page - buffer to write the data in
2638 * @start - where the actual data has been written in page
2639 * @offset - same meaning as the read system call
2640 * @count - same meaning as the read system call
2641 * @eof - set if no more data needs to be returned
2642 * @data - pointer to our soft state
2644 * Display information about the physical drives on physical channel 3.
2647 proc_pdrv_ch3(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2650 adapter_t
*adapter
= (adapter_t
*)data
;
2654 return (proc_pdrv(adapter
, page
, 3));
2660 * @page - buffer to write the data in
2661 * @adapter - pointer to our soft state
2663 * Display information about the physical drives.
2666 proc_pdrv(adapter_t
*adapter
, char *page
, int channel
)
2668 dma_addr_t dma_handle
;
2670 dma_addr_t scsi_inq_dma_handle
;
2672 struct pci_dev
*pdev
;
2681 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2685 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2689 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2690 len
= sprintf(page
, "Adapter inquiry failed.\n");
2692 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2698 scsi_inq
= pci_alloc_consistent(pdev
, 256, &scsi_inq_dma_handle
);
2700 if( scsi_inq
== NULL
) {
2701 len
= sprintf(page
, "memory not available for scsi inq.\n");
2706 if( adapter
->flag
& BOARD_40LD
) {
2707 pdrv_state
= ((mega_inquiry3
*)inquiry
)->pdrv_state
;
2710 pdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2711 raid_inq
.pdrv_info
.pdrv_state
;
2714 max_channels
= adapter
->product_info
.nchannels
;
2716 if( channel
>= max_channels
) {
2720 for( tgt
= 0; tgt
<= MAX_TARGET
; tgt
++ ) {
2722 i
= channel
*16 + tgt
;
2724 state
= *(pdrv_state
+ i
);
2726 switch( state
& 0x0F ) {
2730 "Channel:%2d Id:%2d State: Online",
2736 "Channel:%2d Id:%2d State: Failed",
2742 "Channel:%2d Id:%2d State: Rebuild",
2748 "Channel:%2d Id:%2d State: Hot spare",
2754 "Channel:%2d Id:%2d State: Un-configured",
2761 * This interface displays inquiries for disk drives
2762 * only. Inquries for logical drives and non-disk
2763 * devices are available through /proc/scsi/scsi
2765 memset(scsi_inq
, 0, 256);
2766 if( mega_internal_dev_inquiry(adapter
, channel
, tgt
,
2767 scsi_inq_dma_handle
) ||
2768 (scsi_inq
[0] & 0x1F) != TYPE_DISK
) {
2773 * Check for overflow. We print less than 240
2774 * characters for inquiry
2776 if( (len
+ 240) >= PAGE_SIZE
) break;
2778 len
+= sprintf(page
+len
, "%s.\n", str
);
2780 len
+= mega_print_inquiry(page
+len
, scsi_inq
);
2784 pci_free_consistent(pdev
, 256, scsi_inq
, scsi_inq_dma_handle
);
2786 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2788 free_local_pdev(pdev
);
2795 * Display scsi inquiry
2798 mega_print_inquiry(char *page
, char *scsi_inq
)
2803 len
= sprintf(page
, " Vendor: ");
2804 for( i
= 8; i
< 16; i
++ ) {
2805 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2808 len
+= sprintf(page
+len
, " Model: ");
2810 for( i
= 16; i
< 32; i
++ ) {
2811 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2814 len
+= sprintf(page
+len
, " Rev: ");
2816 for( i
= 32; i
< 36; i
++ ) {
2817 len
+= sprintf(page
+len
, "%c", scsi_inq
[i
]);
2820 len
+= sprintf(page
+len
, "\n");
2822 i
= scsi_inq
[0] & 0x1f;
2824 len
+= sprintf(page
+len
, " Type: %s ",
2825 i
< MAX_SCSI_DEVICE_CODE
? scsi_device_types
[i
] :
2828 len
+= sprintf(page
+len
,
2829 " ANSI SCSI revision: %02x", scsi_inq
[2] & 0x07);
2831 if( (scsi_inq
[2] & 0x07) == 1 && (scsi_inq
[3] & 0x0f) == 1 )
2832 len
+= sprintf(page
+len
, " CCS\n");
2834 len
+= sprintf(page
+len
, "\n");
2842 * @page - buffer to write the data in
2843 * @start - where the actual data has been written in page
2844 * @offset - same meaning as the read system call
2845 * @count - same meaning as the read system call
2846 * @eof - set if no more data needs to be returned
2847 * @data - pointer to our soft state
2849 * Display real time information about the logical drives 0 through 9.
2852 proc_rdrv_10(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2855 adapter_t
*adapter
= (adapter_t
*)data
;
2859 return (proc_rdrv(adapter
, page
, 0, 9));
2865 * @page - buffer to write the data in
2866 * @start - where the actual data has been written in page
2867 * @offset - same meaning as the read system call
2868 * @count - same meaning as the read system call
2869 * @eof - set if no more data needs to be returned
2870 * @data - pointer to our soft state
2872 * Display real time information about the logical drives 0 through 9.
2875 proc_rdrv_20(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2878 adapter_t
*adapter
= (adapter_t
*)data
;
2882 return (proc_rdrv(adapter
, page
, 10, 19));
2888 * @page - buffer to write the data in
2889 * @start - where the actual data has been written in page
2890 * @offset - same meaning as the read system call
2891 * @count - same meaning as the read system call
2892 * @eof - set if no more data needs to be returned
2893 * @data - pointer to our soft state
2895 * Display real time information about the logical drives 0 through 9.
2898 proc_rdrv_30(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2901 adapter_t
*adapter
= (adapter_t
*)data
;
2905 return (proc_rdrv(adapter
, page
, 20, 29));
2911 * @page - buffer to write the data in
2912 * @start - where the actual data has been written in page
2913 * @offset - same meaning as the read system call
2914 * @count - same meaning as the read system call
2915 * @eof - set if no more data needs to be returned
2916 * @data - pointer to our soft state
2918 * Display real time information about the logical drives 0 through 9.
2921 proc_rdrv_40(char *page
, char **start
, off_t offset
, int count
, int *eof
,
2924 adapter_t
*adapter
= (adapter_t
*)data
;
2928 return (proc_rdrv(adapter
, page
, 30, 39));
2934 * @page - buffer to write the data in
2935 * @adapter - pointer to our soft state
2936 * @start - starting logical drive to display
2937 * @end - ending logical drive to display
2939 * We do not print the inquiry information since its already available through
2940 * /proc/scsi/scsi interface
2943 proc_rdrv(adapter_t
*adapter
, char *page
, int start
, int end
)
2945 dma_addr_t dma_handle
;
2946 logdrv_param
*lparam
;
2949 dma_addr_t disk_array_dma_handle
;
2951 struct pci_dev
*pdev
;
2958 if( make_local_pdev(adapter
, &pdev
) != 0 ) {
2962 if( (inquiry
= mega_allocate_inquiry(&dma_handle
, pdev
)) == NULL
) {
2963 free_local_pdev(pdev
);
2967 if( mega_adapinq(adapter
, dma_handle
) != 0 ) {
2969 len
= sprintf(page
, "Adapter inquiry failed.\n");
2971 printk(KERN_WARNING
"megaraid: inquiry failed.\n");
2973 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
2975 free_local_pdev(pdev
);
2980 memset(&mc
, 0, sizeof(megacmd_t
));
2982 if( adapter
->flag
& BOARD_40LD
) {
2983 array_sz
= sizeof(disk_array_40ld
);
2985 rdrv_state
= ((mega_inquiry3
*)inquiry
)->ldrv_state
;
2987 num_ldrv
= ((mega_inquiry3
*)inquiry
)->num_ldrv
;
2990 array_sz
= sizeof(disk_array_8ld
);
2992 rdrv_state
= ((mraid_ext_inquiry
*)inquiry
)->
2993 raid_inq
.logdrv_info
.ldrv_state
;
2995 num_ldrv
= ((mraid_ext_inquiry
*)inquiry
)->
2996 raid_inq
.logdrv_info
.num_ldrv
;
2999 disk_array
= pci_alloc_consistent(pdev
, array_sz
,
3000 &disk_array_dma_handle
);
3002 if( disk_array
== NULL
) {
3003 len
= sprintf(page
, "memory not available.\n");
3005 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3007 free_local_pdev(pdev
);
3012 mc
.xferaddr
= (u32
)disk_array_dma_handle
;
3014 if( adapter
->flag
& BOARD_40LD
) {
3015 mc
.cmd
= FC_NEW_CONFIG
;
3016 mc
.opcode
= OP_DCMD_READ_CONFIG
;
3018 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
3020 len
= sprintf(page
, "40LD read config failed.\n");
3022 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3024 pci_free_consistent(pdev
, array_sz
, disk_array
,
3025 disk_array_dma_handle
);
3027 free_local_pdev(pdev
);
3034 mc
.cmd
= NEW_READ_CONFIG_8LD
;
3036 if( mega_internal_command(adapter
, &mc
, NULL
) ) {
3038 mc
.cmd
= READ_CONFIG_8LD
;
3040 if( mega_internal_command(adapter
, &mc
,
3044 "8LD read config failed.\n");
3046 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3048 pci_free_consistent(pdev
, array_sz
,
3050 disk_array_dma_handle
);
3052 free_local_pdev(pdev
);
3059 for( i
= start
; i
< ( (end
+1 < num_ldrv
) ? end
+1 : num_ldrv
); i
++ ) {
3061 if( adapter
->flag
& BOARD_40LD
) {
3063 &((disk_array_40ld
*)disk_array
)->ldrv
[i
].lparam
;
3067 &((disk_array_8ld
*)disk_array
)->ldrv
[i
].lparam
;
3071 * Check for overflow. We print less than 240 characters for
3072 * information about each logical drive.
3074 if( (len
+ 240) >= PAGE_SIZE
) break;
3076 len
+= sprintf(page
+len
, "Logical drive:%2d:, ", i
);
3078 switch( rdrv_state
[i
] & 0x0F ) {
3080 len
+= sprintf(page
+len
, "state: offline");
3084 len
+= sprintf(page
+len
, "state: degraded");
3088 len
+= sprintf(page
+len
, "state: optimal");
3092 len
+= sprintf(page
+len
, "state: deleted");
3096 len
+= sprintf(page
+len
, "state: unknown");
3101 * Check if check consistency or initialization is going on
3102 * for this logical drive.
3104 if( (rdrv_state
[i
] & 0xF0) == 0x20 ) {
3105 len
+= sprintf(page
+len
,
3106 ", check-consistency in progress");
3108 else if( (rdrv_state
[i
] & 0xF0) == 0x10 ) {
3109 len
+= sprintf(page
+len
,
3110 ", initialization in progress");
3113 len
+= sprintf(page
+len
, "\n");
3115 len
+= sprintf(page
+len
, "Span depth:%3d, ",
3116 lparam
->span_depth
);
3118 len
+= sprintf(page
+len
, "RAID level:%3d, ",
3121 len
+= sprintf(page
+len
, "Stripe size:%3d, ",
3122 lparam
->stripe_sz
? lparam
->stripe_sz
/2: 128);
3124 len
+= sprintf(page
+len
, "Row size:%3d\n",
3128 len
+= sprintf(page
+len
, "Read Policy: ");
3130 switch(lparam
->read_ahead
) {
3133 len
+= sprintf(page
+len
, "No read ahead, ");
3137 len
+= sprintf(page
+len
, "Read ahead, ");
3140 case ADAP_READ_AHEAD
:
3141 len
+= sprintf(page
+len
, "Adaptive, ");
3146 len
+= sprintf(page
+len
, "Write Policy: ");
3148 switch(lparam
->write_mode
) {
3150 case WRMODE_WRITE_THRU
:
3151 len
+= sprintf(page
+len
, "Write thru, ");
3154 case WRMODE_WRITE_BACK
:
3155 len
+= sprintf(page
+len
, "Write back, ");
3159 len
+= sprintf(page
+len
, "Cache Policy: ");
3161 switch(lparam
->direct_io
) {
3164 len
+= sprintf(page
+len
, "Cached IO\n\n");
3168 len
+= sprintf(page
+len
, "Direct IO\n\n");
3173 mega_free_inquiry(inquiry
, dma_handle
, pdev
);
3175 pci_free_consistent(pdev
, array_sz
, disk_array
,
3176 disk_array_dma_handle
);
3178 free_local_pdev(pdev
);
3187 * megaraid_biosparam()
3189 * Return the disk geometry for a particular disk
3192 megaraid_biosparam(struct scsi_device
*sdev
, struct block_device
*bdev
,
3193 sector_t capacity
, int geom
[])
3202 /* Get pointer to host config structure */
3203 adapter
= (adapter_t
*)sdev
->host
->hostdata
;
3205 if (IS_RAID_CH(adapter
, sdev
->channel
)) {
3206 /* Default heads (64) & sectors (32) */
3209 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3212 * Handle extended translation size for logical drives
3215 if ((ulong
)capacity
>= 0x200000) {
3218 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3224 geom
[2] = cylinders
;
3227 bh
= scsi_bios_ptable(bdev
);
3230 rval
= scsi_partsize(bh
, capacity
,
3231 &geom
[2], &geom
[0], &geom
[1]);
3238 "megaraid: invalid partition on this disk on channel %d\n",
3241 /* Default heads (64) & sectors (32) */
3244 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3246 /* Handle extended translation size for logical drives > 1Gb */
3247 if ((ulong
)capacity
>= 0x200000) {
3250 cylinders
= (ulong
)capacity
/ (heads
* sectors
);
3256 geom
[2] = cylinders
;
3264 * @adapter - pointer to our soft state
3266 * Allocate memory for the various pointers in the scb structures:
3267 * scatter-gather list pointer, passthru and extended passthru structure
3271 mega_init_scb(adapter_t
*adapter
)
3276 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3278 scb
= &adapter
->scb_list
[i
];
3286 for( i
= 0; i
< adapter
->max_cmds
; i
++ ) {
3288 scb
= &adapter
->scb_list
[i
];
3292 scb
->sgl64
= pci_alloc_consistent(adapter
->dev
,
3293 sizeof(mega_sgl64
) * adapter
->sglen
,
3294 &scb
->sgl_dma_addr
);
3296 scb
->sgl
= (mega_sglist
*)scb
->sgl64
;
3299 printk(KERN_WARNING
"RAID: Can't allocate sglist.\n");
3300 mega_free_sgl(adapter
);
3304 scb
->pthru
= pci_alloc_consistent(adapter
->dev
,
3305 sizeof(mega_passthru
),
3306 &scb
->pthru_dma_addr
);
3309 printk(KERN_WARNING
"RAID: Can't allocate passthru.\n");
3310 mega_free_sgl(adapter
);
3314 scb
->epthru
= pci_alloc_consistent(adapter
->dev
,
3315 sizeof(mega_ext_passthru
),
3316 &scb
->epthru_dma_addr
);
3318 if( !scb
->epthru
) {
3320 "Can't allocate extended passthru.\n");
3321 mega_free_sgl(adapter
);
3326 scb
->dma_type
= MEGA_DMA_TYPE_NONE
;
3330 * lock not required since we are loading the driver, so no
3331 * commands possible right now.
3333 scb
->state
= SCB_FREE
;
3335 list_add(&scb
->list
, &adapter
->free_list
);
3347 * Routines for the character/ioctl interface to the driver. Find out if this
3348 * is a valid open. If yes, increment the module use count so that it cannot
3352 megadev_open (struct inode
*inode
, struct file
*filep
)
3355 * Only allow superuser to access private ioctl interface
3357 if( !capable(CAP_SYS_ADMIN
) ) return -EACCES
;
3365 * @inode - Our device inode
3367 * @cmd - ioctl command
3368 * @arg - user buffer
3370 * ioctl entry point for our private ioctl interface. We move the data in from
3371 * the user space, prepare the command (if necessary, convert the old MIMD
3372 * ioctl to new ioctl command), and issue a synchronous command to the
3376 megadev_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
,
3383 mega_passthru __user
*upthru
; /* user address for passthru */
3384 mega_passthru
*pthru
; /* copy user passthru here */
3385 dma_addr_t pthru_dma_hndl
;
3386 void *data
= NULL
; /* data to be transferred */
3387 dma_addr_t data_dma_hndl
; /* dma handle for data xfer area */
3389 megastat_t __user
*ustats
;
3392 struct pci_dev
*pdev
;
3394 ustats
= NULL
; /* avoid compilation warnings */
3398 * Make sure only USCSICMD are issued through this interface.
3399 * MIMD application would still fire different command.
3401 if( (_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
) ) {
3406 * Check and convert a possible MIMD command to NIT command.
3407 * mega_m_to_n() copies the data from the user space, so we do not
3408 * have to do it here.
3409 * NOTE: We will need some user address to copyout the data, therefore
3410 * the inteface layer will also provide us with the required user
3413 memset(&uioc
, 0, sizeof(nitioctl_t
));
3414 if( (rval
= mega_m_to_n( (void __user
*)arg
, &uioc
)) != 0 )
3418 switch( uioc
.opcode
) {
3420 case GET_DRIVER_VER
:
3421 if( put_user(driver_ver
, (u32 __user
*)uioc
.uioc_uaddr
) )
3427 if( put_user(hba_count
, (u32 __user
*)uioc
.uioc_uaddr
) )
3431 * Shucks. MIMD interface returns a positive value for number
3432 * of adapters. TODO: Change it to return 0 when there is no
3433 * applicatio using mimd interface.
3442 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3445 if( copy_to_user(uioc
.uioc_uaddr
, mcontroller
+adapno
,
3446 sizeof(struct mcontroller
)) )
3456 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3459 adapter
= hba_soft_state
[adapno
];
3461 ustats
= uioc
.uioc_uaddr
;
3463 if( copy_from_user(&num_ldrv
, &ustats
->num_ldrv
, sizeof(int)) )
3467 * Check for the validity of the logical drive number
3469 if( num_ldrv
>= MAX_LOGICAL_DRIVES_40LD
) return -EINVAL
;
3471 if( copy_to_user(ustats
->nreads
, adapter
->nreads
,
3472 num_ldrv
*sizeof(u32
)) )
3475 if( copy_to_user(ustats
->nreadblocks
, adapter
->nreadblocks
,
3476 num_ldrv
*sizeof(u32
)) )
3479 if( copy_to_user(ustats
->nwrites
, adapter
->nwrites
,
3480 num_ldrv
*sizeof(u32
)) )
3483 if( copy_to_user(ustats
->nwriteblocks
, adapter
->nwriteblocks
,
3484 num_ldrv
*sizeof(u32
)) )
3487 if( copy_to_user(ustats
->rd_errors
, adapter
->rd_errors
,
3488 num_ldrv
*sizeof(u32
)) )
3491 if( copy_to_user(ustats
->wr_errors
, adapter
->wr_errors
,
3492 num_ldrv
*sizeof(u32
)) )
3503 if( (adapno
= GETADAP(uioc
.adapno
)) >= hba_count
)
3506 adapter
= hba_soft_state
[adapno
];
3509 * Deletion of logical drive is a special case. The adapter
3510 * should be quiescent before this command is issued.
3512 if( uioc
.uioc_rmbox
[0] == FC_DEL_LOGDRV
&&
3513 uioc
.uioc_rmbox
[2] == OP_DEL_LOGDRV
) {
3516 * Do we support this feature
3518 if( !adapter
->support_random_del
) {
3519 printk(KERN_WARNING
"megaraid: logdrv ");
3520 printk("delete on non-supporting F/W.\n");
3525 rval
= mega_del_logdrv( adapter
, uioc
.uioc_rmbox
[3] );
3528 memset(&mc
, 0, sizeof(megacmd_t
));
3532 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3538 * This interface only support the regular passthru commands.
3539 * Reject extended passthru and 64-bit passthru
3541 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU64
||
3542 uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_EXTPTHRU
) {
3544 printk(KERN_WARNING
"megaraid: rejected passthru.\n");
3550 * For all internal commands, the buffer must be allocated in
3551 * <4GB address range
3553 if( make_local_pdev(adapter
, &pdev
) != 0 )
3556 /* Is it a passthru command or a DCMD */
3557 if( uioc
.uioc_rmbox
[0] == MEGA_MBOXCMD_PASSTHRU
) {
3558 /* Passthru commands */
3560 pthru
= pci_alloc_consistent(pdev
,
3561 sizeof(mega_passthru
),
3564 if( pthru
== NULL
) {
3565 free_local_pdev(pdev
);
3570 * The user passthru structure
3572 upthru
= (mega_passthru __user
*)MBOX(uioc
)->xferaddr
;
3575 * Copy in the user passthru here.
3577 if( copy_from_user(pthru
, upthru
,
3578 sizeof(mega_passthru
)) ) {
3580 pci_free_consistent(pdev
,
3581 sizeof(mega_passthru
), pthru
,
3584 free_local_pdev(pdev
);
3590 * Is there a data transfer
3592 if( pthru
->dataxferlen
) {
3593 data
= pci_alloc_consistent(pdev
,
3597 if( data
== NULL
) {
3598 pci_free_consistent(pdev
,
3599 sizeof(mega_passthru
),
3603 free_local_pdev(pdev
);
3609 * Save the user address and point the kernel
3610 * address at just allocated memory
3612 uxferaddr
= pthru
->dataxferaddr
;
3613 pthru
->dataxferaddr
= data_dma_hndl
;
3618 * Is data coming down-stream
3620 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3624 if( copy_from_user(data
, (char __user
*)uxferaddr
,
3625 pthru
->dataxferlen
) ) {
3627 goto freemem_and_return
;
3631 memset(&mc
, 0, sizeof(megacmd_t
));
3633 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
3634 mc
.xferaddr
= (u32
)pthru_dma_hndl
;
3639 mega_internal_command(adapter
, &mc
, pthru
);
3641 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3643 if( rval
) goto freemem_and_return
;
3647 * Is data going up-stream
3649 if( pthru
->dataxferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3650 if( copy_to_user((char __user
*)uxferaddr
, data
,
3651 pthru
->dataxferlen
) ) {
3657 * Send the request sense data also, irrespective of
3658 * whether the user has asked for it or not.
3660 copy_to_user(upthru
->reqsensearea
,
3661 pthru
->reqsensearea
, 14);
3664 if( pthru
->dataxferlen
) {
3665 pci_free_consistent(pdev
,
3666 pthru
->dataxferlen
, data
,
3670 pci_free_consistent(pdev
, sizeof(mega_passthru
),
3671 pthru
, pthru_dma_hndl
);
3673 free_local_pdev(pdev
);
3681 * Is there a data transfer
3683 if( uioc
.xferlen
) {
3684 data
= pci_alloc_consistent(pdev
,
3685 uioc
.xferlen
, &data_dma_hndl
);
3687 if( data
== NULL
) {
3688 free_local_pdev(pdev
);
3692 uxferaddr
= MBOX(uioc
)->xferaddr
;
3696 * Is data coming down-stream
3698 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_WR
) ) {
3702 if( copy_from_user(data
, (char __user
*)uxferaddr
,
3705 pci_free_consistent(pdev
,
3707 data
, data_dma_hndl
);
3709 free_local_pdev(pdev
);
3715 memcpy(&mc
, MBOX(uioc
), sizeof(megacmd_t
));
3717 mc
.xferaddr
= (u32
)data_dma_hndl
;
3722 mega_internal_command(adapter
, &mc
, NULL
);
3724 rval
= mega_n_to_m((void __user
*)arg
, &mc
);
3727 if( uioc
.xferlen
) {
3728 pci_free_consistent(pdev
,
3733 free_local_pdev(pdev
);
3739 * Is data going up-stream
3741 if( uioc
.xferlen
&& (uioc
.flags
& UIOC_RD
) ) {
3742 if( copy_to_user((char __user
*)uxferaddr
, data
,
3749 if( uioc
.xferlen
) {
3750 pci_free_consistent(pdev
,
3755 free_local_pdev(pdev
);
3769 * @arg - user address
3770 * @uioc - new ioctl structure
3772 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3775 * Converts the older mimd ioctl structure to newer NIT structure
3778 mega_m_to_n(void __user
*arg
, nitioctl_t
*uioc
)
3780 struct uioctl_t uioc_mimd
;
3781 char signature
[8] = {0};
3787 * check is the application conforms to NIT. We do not have to do much
3789 * We exploit the fact that the signature is stored in the very
3790 * begining of the structure.
3793 if( copy_from_user(signature
, arg
, 7) )
3796 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3799 * NOTE NOTE: The nit ioctl is still under flux because of
3800 * change of mailbox definition, in HPE. No applications yet
3801 * use this interface and let's not have applications use this
3802 * interface till the new specifitions are in place.
3806 if( copy_from_user(uioc
, arg
, sizeof(nitioctl_t
)) )
3813 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3815 * Get the user ioctl structure
3817 if( copy_from_user(&uioc_mimd
, arg
, sizeof(struct uioctl_t
)) )
3822 * Get the opcode and subopcode for the commands
3824 opcode
= uioc_mimd
.ui
.fcs
.opcode
;
3825 subopcode
= uioc_mimd
.ui
.fcs
.subopcode
;
3830 switch (subopcode
) {
3832 case MEGAIOC_QDRVRVER
: /* Query driver version */
3833 uioc
->opcode
= GET_DRIVER_VER
;
3834 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3837 case MEGAIOC_QNADAP
: /* Get # of adapters */
3838 uioc
->opcode
= GET_N_ADAP
;
3839 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3842 case MEGAIOC_QADAPINFO
: /* Get adapter information */
3843 uioc
->opcode
= GET_ADAP_INFO
;
3844 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3845 uioc
->uioc_uaddr
= uioc_mimd
.data
;
3857 uioc
->opcode
= MBOX_CMD
;
3858 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3860 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3862 uioc
->xferlen
= uioc_mimd
.ui
.fcs
.length
;
3864 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3865 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3871 uioc
->opcode
= MBOX_CMD
;
3872 uioc
->adapno
= uioc_mimd
.ui
.fcs
.adapno
;
3874 memcpy(uioc
->uioc_rmbox
, uioc_mimd
.mbox
, 18);
3877 * Choose the xferlen bigger of input and output data
3879 uioc
->xferlen
= uioc_mimd
.outlen
> uioc_mimd
.inlen
?
3880 uioc_mimd
.outlen
: uioc_mimd
.inlen
;
3882 if( uioc_mimd
.outlen
) uioc
->flags
= UIOC_RD
;
3883 if( uioc_mimd
.inlen
) uioc
->flags
|= UIOC_WR
;
3897 * @arg - user address
3898 * @mc - mailbox command
3900 * Updates the status information to the application, depending on application
3901 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3904 mega_n_to_m(void __user
*arg
, megacmd_t
*mc
)
3906 nitioctl_t __user
*uiocp
;
3907 megacmd_t __user
*umc
;
3908 mega_passthru __user
*upthru
;
3909 struct uioctl_t __user
*uioc_mimd
;
3910 char signature
[8] = {0};
3913 * check is the application conforms to NIT.
3915 if( copy_from_user(signature
, arg
, 7) )
3918 if( memcmp(signature
, "MEGANIT", 7) == 0 ) {
3922 if( put_user(mc
->status
, (u8 __user
*)&MBOX_P(uiocp
)->status
) )
3925 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3927 umc
= MBOX_P(uiocp
);
3929 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3932 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
))
3939 if( put_user(mc
->status
, (u8 __user
*)&uioc_mimd
->mbox
[17]) )
3942 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
3944 umc
= (megacmd_t __user
*)uioc_mimd
->mbox
;
3946 if (get_user(upthru
, (mega_passthru __user
* __user
*)&umc
->xferaddr
))
3949 if( put_user(mc
->status
, (u8 __user
*)&upthru
->scsistatus
) )
3959 * MEGARAID 'FW' commands.
3963 * mega_is_bios_enabled()
3964 * @adapter - pointer to our soft state
3966 * issue command to find out if the BIOS is enabled for this controller
3969 mega_is_bios_enabled(adapter_t
*adapter
)
3971 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
3975 mbox
= (mbox_t
*)raw_mbox
;
3977 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
3979 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
3981 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
3983 raw_mbox
[0] = IS_BIOS_ENABLED
;
3984 raw_mbox
[2] = GET_BIOS
;
3987 ret
= issue_scb_block(adapter
, raw_mbox
);
3989 return *(char *)adapter
->mega_buffer
;
3994 * mega_enum_raid_scsi()
3995 * @adapter - pointer to our soft state
3997 * Find out what channels are RAID/SCSI. This information is used to
3998 * differentiate the virtual channels and physical channels and to support
3999 * ROMB feature and non-disk devices.
4002 mega_enum_raid_scsi(adapter_t
*adapter
)
4004 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4008 mbox
= (mbox_t
*)raw_mbox
;
4010 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4013 * issue command to find out what channels are raid/scsi
4015 raw_mbox
[0] = CHNL_CLASS
;
4016 raw_mbox
[2] = GET_CHNL_CLASS
;
4018 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4020 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4023 * Non-ROMB firmware fail this command, so all channels
4024 * must be shown RAID
4026 adapter
->mega_ch_class
= 0xFF;
4028 if(!issue_scb_block(adapter
, raw_mbox
)) {
4029 adapter
->mega_ch_class
= *((char *)adapter
->mega_buffer
);
4033 for( i
= 0; i
< adapter
->product_info
.nchannels
; i
++ ) {
4034 if( (adapter
->mega_ch_class
>> i
) & 0x01 ) {
4035 printk(KERN_INFO
"megaraid: channel[%d] is raid.\n",
4039 printk(KERN_INFO
"megaraid: channel[%d] is scsi.\n",
4049 * mega_get_boot_drv()
4050 * @adapter - pointer to our soft state
4052 * Find out which device is the boot device. Note, any logical drive or any
4053 * phyical device (e.g., a CDROM) can be designated as a boot device.
4056 mega_get_boot_drv(adapter_t
*adapter
)
4058 struct private_bios_data
*prv_bios_data
;
4059 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4066 mbox
= (mbox_t
*)raw_mbox
;
4068 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4070 raw_mbox
[0] = BIOS_PVT_DATA
;
4071 raw_mbox
[2] = GET_BIOS_PVT_DATA
;
4073 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4075 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4077 adapter
->boot_ldrv_enabled
= 0;
4078 adapter
->boot_ldrv
= 0;
4080 adapter
->boot_pdrv_enabled
= 0;
4081 adapter
->boot_pdrv_ch
= 0;
4082 adapter
->boot_pdrv_tgt
= 0;
4084 if(issue_scb_block(adapter
, raw_mbox
) == 0) {
4086 (struct private_bios_data
*)adapter
->mega_buffer
;
4089 cksum_p
= (char *)prv_bios_data
;
4090 for (i
= 0; i
< 14; i
++ ) {
4091 cksum
+= (u16
)(*cksum_p
++);
4094 if (prv_bios_data
->cksum
== (u16
)(0-cksum
) ) {
4097 * If MSB is set, a physical drive is set as boot
4100 if( prv_bios_data
->boot_drv
& 0x80 ) {
4101 adapter
->boot_pdrv_enabled
= 1;
4102 boot_pdrv
= prv_bios_data
->boot_drv
& 0x7F;
4103 adapter
->boot_pdrv_ch
= boot_pdrv
/ 16;
4104 adapter
->boot_pdrv_tgt
= boot_pdrv
% 16;
4107 adapter
->boot_ldrv_enabled
= 1;
4108 adapter
->boot_ldrv
= prv_bios_data
->boot_drv
;
4116 * mega_support_random_del()
4117 * @adapter - pointer to our soft state
4119 * Find out if this controller supports random deletion and addition of
4123 mega_support_random_del(adapter_t
*adapter
)
4125 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4129 mbox
= (mbox_t
*)raw_mbox
;
4131 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4136 raw_mbox
[0] = FC_DEL_LOGDRV
;
4137 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
4139 rval
= issue_scb_block(adapter
, raw_mbox
);
4146 * mega_support_ext_cdb()
4147 * @adapter - pointer to our soft state
4149 * Find out if this firmware support cdblen > 10
4152 mega_support_ext_cdb(adapter_t
*adapter
)
4154 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4158 mbox
= (mbox_t
*)raw_mbox
;
4160 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4162 * issue command to find out if controller supports extended CDBs.
4167 rval
= issue_scb_block(adapter
, raw_mbox
);
4175 * @adapter - pointer to our soft state
4176 * @logdrv - logical drive to be deleted
4178 * Delete the specified logical drive. It is the responsibility of the user
4179 * app to let the OS know about this operation.
4182 mega_del_logdrv(adapter_t
*adapter
, int logdrv
)
4184 unsigned long flags
;
4189 * Stop sending commands to the controller, queue them internally.
4190 * When deletion is complete, ISR will flush the queue.
4192 atomic_set(&adapter
->quiescent
, 1);
4195 * Wait till all the issued commands are complete and there are no
4196 * commands in the pending queue
4198 while (atomic_read(&adapter
->pend_cmds
) > 0 ||
4199 !list_empty(&adapter
->pending_list
))
4200 msleep(1000); /* sleep for 1s */
4202 rval
= mega_do_del_logdrv(adapter
, logdrv
);
4204 spin_lock_irqsave(&adapter
->lock
, flags
);
4207 * If delete operation was successful, add 0x80 to the logical drive
4208 * ids for commands in the pending queue.
4210 if (adapter
->read_ldidmap
) {
4211 struct list_head
*pos
;
4212 list_for_each(pos
, &adapter
->pending_list
) {
4213 scb
= list_entry(pos
, scb_t
, list
);
4214 if (scb
->pthru
->logdrv
< 0x80 )
4215 scb
->pthru
->logdrv
+= 0x80;
4219 atomic_set(&adapter
->quiescent
, 0);
4221 mega_runpendq(adapter
);
4223 spin_unlock_irqrestore(&adapter
->lock
, flags
);
4230 mega_do_del_logdrv(adapter_t
*adapter
, int logdrv
)
4235 memset( &mc
, 0, sizeof(megacmd_t
));
4237 mc
.cmd
= FC_DEL_LOGDRV
;
4238 mc
.opcode
= OP_DEL_LOGDRV
;
4239 mc
.subopcode
= logdrv
;
4241 rval
= mega_internal_command(adapter
, &mc
, NULL
);
4243 /* log this event */
4245 printk(KERN_WARNING
"megaraid: Delete LD-%d failed.", logdrv
);
4250 * After deleting first logical drive, the logical drives must be
4251 * addressed by adding 0x80 to the logical drive id.
4253 adapter
->read_ldidmap
= 1;
4260 * mega_get_max_sgl()
4261 * @adapter - pointer to our soft state
4263 * Find out the maximum number of scatter-gather elements supported by this
4264 * version of the firmware
4267 mega_get_max_sgl(adapter_t
*adapter
)
4269 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4272 mbox
= (mbox_t
*)raw_mbox
;
4274 memset(mbox
, 0, sizeof(raw_mbox
));
4276 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4278 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4280 raw_mbox
[0] = MAIN_MISC_OPCODE
;
4281 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
4284 if( issue_scb_block(adapter
, raw_mbox
) ) {
4286 * f/w does not support this command. Choose the default value
4288 adapter
->sglen
= MIN_SGLIST
;
4291 adapter
->sglen
= *((char *)adapter
->mega_buffer
);
4294 * Make sure this is not more than the resources we are
4295 * planning to allocate
4297 if ( adapter
->sglen
> MAX_SGLIST
)
4298 adapter
->sglen
= MAX_SGLIST
;
4306 * mega_support_cluster()
4307 * @adapter - pointer to our soft state
4309 * Find out if this firmware support cluster calls.
4312 mega_support_cluster(adapter_t
*adapter
)
4314 unsigned char raw_mbox
[sizeof(struct mbox_out
)];
4317 mbox
= (mbox_t
*)raw_mbox
;
4319 memset(mbox
, 0, sizeof(raw_mbox
));
4321 memset((void *)adapter
->mega_buffer
, 0, MEGA_BUFFER_SIZE
);
4323 mbox
->m_out
.xferaddr
= (u32
)adapter
->buf_dma_handle
;
4326 * Try to get the initiator id. This command will succeed iff the
4327 * clustering is available on this HBA.
4329 raw_mbox
[0] = MEGA_GET_TARGET_ID
;
4331 if( issue_scb_block(adapter
, raw_mbox
) == 0 ) {
4334 * Cluster support available. Get the initiator target id.
4335 * Tell our id to mid-layer too.
4337 adapter
->this_id
= *(u32
*)adapter
->mega_buffer
;
4338 adapter
->host
->this_id
= adapter
->this_id
;
4349 * @adapter - pointer to our soft state
4350 * @dma_handle - DMA address of the buffer
4352 * Issue internal comamnds while interrupts are available.
4353 * We only issue direct mailbox commands from within the driver. ioctl()
4354 * interface using these routines can issue passthru commands.
4357 mega_adapinq(adapter_t
*adapter
, dma_addr_t dma_handle
)
4361 memset(&mc
, 0, sizeof(megacmd_t
));
4363 if( adapter
->flag
& BOARD_40LD
) {
4364 mc
.cmd
= FC_NEW_CONFIG
;
4365 mc
.opcode
= NC_SUBOP_ENQUIRY3
;
4366 mc
.subopcode
= ENQ3_GET_SOLICITED_FULL
;
4369 mc
.cmd
= MEGA_MBOXCMD_ADPEXTINQ
;
4372 mc
.xferaddr
= (u32
)dma_handle
;
4374 if ( mega_internal_command(adapter
, &mc
, NULL
) != 0 ) {
4382 /** mega_internal_dev_inquiry()
4383 * @adapter - pointer to our soft state
4384 * @ch - channel for this device
4385 * @tgt - ID of this device
4386 * @buf_dma_handle - DMA address of the buffer
4388 * Issue the scsi inquiry for the specified device.
4391 mega_internal_dev_inquiry(adapter_t
*adapter
, u8 ch
, u8 tgt
,
4392 dma_addr_t buf_dma_handle
)
4394 mega_passthru
*pthru
;
4395 dma_addr_t pthru_dma_handle
;
4398 struct pci_dev
*pdev
;
4402 * For all internal commands, the buffer must be allocated in <4GB
4405 if( make_local_pdev(adapter
, &pdev
) != 0 ) return -1;
4407 pthru
= pci_alloc_consistent(pdev
, sizeof(mega_passthru
),
4410 if( pthru
== NULL
) {
4411 free_local_pdev(pdev
);
4417 pthru
->reqsenselen
= 14;
4418 pthru
->islogical
= 0;
4420 pthru
->channel
= (adapter
->flag
& BOARD_40LD
) ? 0 : ch
;
4422 pthru
->target
= (adapter
->flag
& BOARD_40LD
) ? (ch
<< 4)|tgt
: tgt
;
4426 pthru
->cdb
[0] = INQUIRY
;
4430 pthru
->cdb
[4] = 255;
4434 pthru
->dataxferaddr
= (u32
)buf_dma_handle
;
4435 pthru
->dataxferlen
= 256;
4437 memset(&mc
, 0, sizeof(megacmd_t
));
4439 mc
.cmd
= MEGA_MBOXCMD_PASSTHRU
;
4440 mc
.xferaddr
= (u32
)pthru_dma_handle
;
4442 rval
= mega_internal_command(adapter
, &mc
, pthru
);
4444 pci_free_consistent(pdev
, sizeof(mega_passthru
), pthru
,
4447 free_local_pdev(pdev
);
4454 * mega_internal_command()
4455 * @adapter - pointer to our soft state
4456 * @mc - the mailbox command
4457 * @pthru - Passthru structure for DCDB commands
4459 * Issue the internal commands in interrupt mode.
4460 * The last argument is the address of the passthru structure if the command
4461 * to be fired is a passthru command
4463 * lockscope specifies whether the caller has already acquired the lock. Of
4464 * course, the caller must know which lock we are talking about.
4466 * Note: parameter 'pthru' is null for non-passthru commands.
4469 mega_internal_command(adapter_t
*adapter
, megacmd_t
*mc
, mega_passthru
*pthru
)
4472 struct scsi_device
*sdev
;
4473 unsigned long flags
= 0;
4478 * The internal commands share one command id and hence are
4479 * serialized. This is so because we want to reserve maximum number of
4480 * available command ids for the I/O commands.
4482 mutex_lock(&adapter
->int_mtx
);
4484 scb
= &adapter
->int_scb
;
4485 memset(scb
, 0, sizeof(scb_t
));
4487 scmd
= &adapter
->int_scmd
;
4488 memset(scmd
, 0, sizeof(Scsi_Cmnd
));
4490 sdev
= kmalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
4491 memset(sdev
, 0, sizeof(struct scsi_device
));
4492 scmd
->device
= sdev
;
4494 scmd
->device
->host
= adapter
->host
;
4495 scmd
->buffer
= (void *)scb
;
4496 scmd
->cmnd
[0] = MEGA_INTERNAL_CMD
;
4498 scb
->state
|= SCB_ACTIVE
;
4501 memcpy(scb
->raw_mbox
, mc
, sizeof(megacmd_t
));
4504 * Is it a passthru command
4506 if( mc
->cmd
== MEGA_MBOXCMD_PASSTHRU
) {
4511 scb
->idx
= CMDID_INT_CMDS
;
4513 megaraid_queue(scmd
, mega_internal_done
);
4515 wait_for_completion(&adapter
->int_waitq
);
4517 rval
= scmd
->result
;
4518 mc
->status
= scmd
->result
;
4522 * Print a debug message for all failed commands. Applications can use
4525 if( scmd
->result
&& trace_level
) {
4526 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4527 mc
->cmd
, mc
->opcode
, mc
->subopcode
, scmd
->result
);
4530 mutex_unlock(&adapter
->int_mtx
);
4537 * mega_internal_done()
4538 * @scmd - internal scsi command
4540 * Callback routine for internal commands.
4543 mega_internal_done(Scsi_Cmnd
*scmd
)
4547 adapter
= (adapter_t
*)scmd
->device
->host
->hostdata
;
4549 complete(&adapter
->int_waitq
);
4554 static struct scsi_host_template megaraid_template
= {
4555 .module
= THIS_MODULE
,
4557 .proc_name
= "megaraid_legacy",
4558 .info
= megaraid_info
,
4559 .queuecommand
= megaraid_queue
,
4560 .bios_param
= megaraid_biosparam
,
4561 .max_sectors
= MAX_SECTORS_PER_IO
,
4562 .can_queue
= MAX_COMMANDS
,
4563 .this_id
= DEFAULT_INITIATOR_ID
,
4564 .sg_tablesize
= MAX_SGLIST
,
4565 .cmd_per_lun
= DEF_CMD_PER_LUN
,
4566 .use_clustering
= ENABLE_CLUSTERING
,
4567 .eh_abort_handler
= megaraid_abort
,
4568 .eh_device_reset_handler
= megaraid_reset
,
4569 .eh_bus_reset_handler
= megaraid_reset
,
4570 .eh_host_reset_handler
= megaraid_reset
,
4573 static int __devinit
4574 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
4576 struct Scsi_Host
*host
;
4578 unsigned long mega_baseport
, tbase
, flag
= 0;
4579 u16 subsysid
, subsysvid
;
4580 u8 pci_bus
, pci_dev_func
;
4582 int error
= -ENODEV
;
4584 if (pci_enable_device(pdev
))
4586 pci_set_master(pdev
);
4588 pci_bus
= pdev
->bus
->number
;
4589 pci_dev_func
= pdev
->devfn
;
4592 * The megaraid3 stuff reports the ID of the Intel part which is not
4593 * remotely specific to the megaraid
4595 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
) {
4598 * Don't fall over the Compaq management cards using the same
4601 if (pdev
->subsystem_vendor
== PCI_VENDOR_ID_COMPAQ
&&
4602 pdev
->subsystem_device
== 0xC000)
4604 /* Now check the magic signature byte */
4605 pci_read_config_word(pdev
, PCI_CONF_AMISIG
, &magic
);
4606 if (magic
!= HBA_SIGNATURE_471
&& magic
!= HBA_SIGNATURE
)
4608 /* Ok it is probably a megaraid */
4612 * For these vendor and device ids, signature offsets are not
4613 * valid and 64 bit is implicit
4615 if (id
->driver_data
& BOARD_64BIT
)
4616 flag
|= BOARD_64BIT
;
4620 pci_read_config_dword(pdev
, PCI_CONF_AMISIG64
, &magic64
);
4621 if (magic64
== HBA_SIGNATURE_64BIT
)
4622 flag
|= BOARD_64BIT
;
4625 subsysvid
= pdev
->subsystem_vendor
;
4626 subsysid
= pdev
->subsystem_device
;
4628 printk(KERN_NOTICE
"megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4629 id
->vendor
, id
->device
, pci_bus
);
4631 printk("slot %d:func %d\n",
4632 PCI_SLOT(pci_dev_func
), PCI_FUNC(pci_dev_func
));
4634 /* Read the base port and IRQ from PCI */
4635 mega_baseport
= pci_resource_start(pdev
, 0);
4638 tbase
= mega_baseport
;
4639 if (pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) {
4640 flag
|= BOARD_MEMMAP
;
4642 if (!request_mem_region(mega_baseport
, 128, "megaraid")) {
4643 printk(KERN_WARNING
"megaraid: mem region busy!\n");
4644 goto out_disable_device
;
4647 mega_baseport
= (unsigned long)ioremap(mega_baseport
, 128);
4648 if (!mega_baseport
) {
4650 "megaraid: could not map hba memory\n");
4651 goto out_release_region
;
4654 flag
|= BOARD_IOMAP
;
4655 mega_baseport
+= 0x10;
4657 if (!request_region(mega_baseport
, 16, "megaraid"))
4658 goto out_disable_device
;
4661 /* Initialize SCSI Host structure */
4662 host
= scsi_host_alloc(&megaraid_template
, sizeof(adapter_t
));
4666 adapter
= (adapter_t
*)host
->hostdata
;
4667 memset(adapter
, 0, sizeof(adapter_t
));
4670 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4671 host
->host_no
, mega_baseport
, irq
);
4673 adapter
->base
= mega_baseport
;
4675 INIT_LIST_HEAD(&adapter
->free_list
);
4676 INIT_LIST_HEAD(&adapter
->pending_list
);
4677 INIT_LIST_HEAD(&adapter
->completed_list
);
4679 adapter
->flag
= flag
;
4680 spin_lock_init(&adapter
->lock
);
4682 host
->cmd_per_lun
= max_cmd_per_lun
;
4683 host
->max_sectors
= max_sectors_per_io
;
4685 adapter
->dev
= pdev
;
4686 adapter
->host
= host
;
4688 adapter
->host
->irq
= irq
;
4690 if (flag
& BOARD_MEMMAP
)
4691 adapter
->host
->base
= tbase
;
4693 adapter
->host
->io_port
= tbase
;
4694 adapter
->host
->n_io_port
= 16;
4697 adapter
->host
->unique_id
= (pci_bus
<< 8) | pci_dev_func
;
4700 * Allocate buffer to issue internal commands.
4702 adapter
->mega_buffer
= pci_alloc_consistent(adapter
->dev
,
4703 MEGA_BUFFER_SIZE
, &adapter
->buf_dma_handle
);
4704 if (!adapter
->mega_buffer
) {
4705 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4709 adapter
->scb_list
= kmalloc(sizeof(scb_t
) * MAX_COMMANDS
, GFP_KERNEL
);
4710 if (!adapter
->scb_list
) {
4711 printk(KERN_WARNING
"megaraid: out of RAM.\n");
4712 goto out_free_cmd_buffer
;
4715 if (request_irq(irq
, (adapter
->flag
& BOARD_MEMMAP
) ?
4716 megaraid_isr_memmapped
: megaraid_isr_iomapped
,
4717 SA_SHIRQ
, "megaraid", adapter
)) {
4719 "megaraid: Couldn't register IRQ %d!\n", irq
);
4720 goto out_free_scb_list
;
4723 if (mega_setup_mailbox(adapter
))
4726 if (mega_query_adapter(adapter
))
4730 * Have checks for some buggy f/w
4732 if ((subsysid
== 0x1111) && (subsysvid
== 0x1111)) {
4736 if (!strcmp(adapter
->fw_version
, "3.00") ||
4737 !strcmp(adapter
->fw_version
, "3.01")) {
4739 printk( KERN_WARNING
4740 "megaraid: Your card is a Dell PERC "
4741 "2/SC RAID controller with "
4742 "firmware\nmegaraid: 3.00 or 3.01. "
4743 "This driver is known to have "
4744 "corruption issues\nmegaraid: with "
4745 "those firmware versions on this "
4746 "specific card. In order\nmegaraid: "
4747 "to protect your data, please upgrade "
4748 "your firmware to version\nmegaraid: "
4749 "3.10 or later, available from the "
4750 "Dell Technical Support web\n"
4751 "megaraid: site at\nhttp://support."
4752 "dell.com/us/en/filelib/download/"
4753 "index.asp?fileid=2940\n"
4759 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4760 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4761 * support, since this firmware cannot handle 64 bit
4764 if ((subsysvid
== HP_SUBSYS_VID
) &&
4765 ((subsysid
== 0x60E7) || (subsysid
== 0x60E8))) {
4769 if (!strcmp(adapter
->fw_version
, "H01.07") ||
4770 !strcmp(adapter
->fw_version
, "H01.08") ||
4771 !strcmp(adapter
->fw_version
, "H01.09") ) {
4773 "megaraid: Firmware H.01.07, "
4774 "H.01.08, and H.01.09 on 1M/2M "
4776 "megaraid: do not support 64 bit "
4777 "addressing.\nmegaraid: DISABLING "
4778 "64 bit support.\n");
4779 adapter
->flag
&= ~BOARD_64BIT
;
4783 if (mega_is_bios_enabled(adapter
))
4784 mega_hbas
[hba_count
].is_bios_enabled
= 1;
4785 mega_hbas
[hba_count
].hostdata_addr
= adapter
;
4788 * Find out which channel is raid and which is scsi. This is
4791 mega_enum_raid_scsi(adapter
);
4794 * Find out if a logical drive is set as the boot drive. If
4795 * there is one, will make that as the first logical drive.
4796 * ROMB: Do we have to boot from a physical drive. Then all
4797 * the physical drives would appear before the logical disks.
4798 * Else, all the physical drives would be exported to the mid
4799 * layer after logical drives.
4801 mega_get_boot_drv(adapter
);
4803 if (adapter
->boot_pdrv_enabled
) {
4804 j
= adapter
->product_info
.nchannels
;
4805 for( i
= 0; i
< j
; i
++ )
4806 adapter
->logdrv_chan
[i
] = 0;
4807 for( i
= j
; i
< NVIRT_CHAN
+ j
; i
++ )
4808 adapter
->logdrv_chan
[i
] = 1;
4810 for (i
= 0; i
< NVIRT_CHAN
; i
++)
4811 adapter
->logdrv_chan
[i
] = 1;
4812 for (i
= NVIRT_CHAN
; i
< MAX_CHANNELS
+NVIRT_CHAN
; i
++)
4813 adapter
->logdrv_chan
[i
] = 0;
4814 adapter
->mega_ch_class
<<= NVIRT_CHAN
;
4818 * Do we support random deletion and addition of logical
4821 adapter
->read_ldidmap
= 0; /* set it after first logdrv
4823 adapter
->support_random_del
= mega_support_random_del(adapter
);
4825 /* Initialize SCBs */
4826 if (mega_init_scb(adapter
))
4830 * Reset the pending commands counter
4832 atomic_set(&adapter
->pend_cmds
, 0);
4835 * Reset the adapter quiescent flag
4837 atomic_set(&adapter
->quiescent
, 0);
4839 hba_soft_state
[hba_count
] = adapter
;
4842 * Fill in the structure which needs to be passed back to the
4843 * application when it does an ioctl() for controller related
4848 mcontroller
[i
].base
= mega_baseport
;
4849 mcontroller
[i
].irq
= irq
;
4850 mcontroller
[i
].numldrv
= adapter
->numldrv
;
4851 mcontroller
[i
].pcibus
= pci_bus
;
4852 mcontroller
[i
].pcidev
= id
->device
;
4853 mcontroller
[i
].pcifun
= PCI_FUNC (pci_dev_func
);
4854 mcontroller
[i
].pciid
= -1;
4855 mcontroller
[i
].pcivendor
= id
->vendor
;
4856 mcontroller
[i
].pcislot
= PCI_SLOT(pci_dev_func
);
4857 mcontroller
[i
].uid
= (pci_bus
<< 8) | pci_dev_func
;
4860 /* Set the Mode of addressing to 64 bit if we can */
4861 if ((adapter
->flag
& BOARD_64BIT
) && (sizeof(dma_addr_t
) == 8)) {
4862 pci_set_dma_mask(pdev
, 0xffffffffffffffffULL
);
4863 adapter
->has_64bit_addr
= 1;
4865 pci_set_dma_mask(pdev
, 0xffffffff);
4866 adapter
->has_64bit_addr
= 0;
4869 mutex_init(&adapter
->int_mtx
);
4870 init_completion(&adapter
->int_waitq
);
4872 adapter
->this_id
= DEFAULT_INITIATOR_ID
;
4873 adapter
->host
->this_id
= DEFAULT_INITIATOR_ID
;
4875 #if MEGA_HAVE_CLUSTERING
4877 * Is cluster support enabled on this controller
4878 * Note: In a cluster the HBAs ( the initiators ) will have
4879 * different target IDs and we cannot assume it to be 7. Call
4880 * to mega_support_cluster() will get the target ids also if
4881 * the cluster support is available
4883 adapter
->has_cluster
= mega_support_cluster(adapter
);
4884 if (adapter
->has_cluster
) {
4886 "megaraid: Cluster driver, initiator id:%d\n",
4891 pci_set_drvdata(pdev
, host
);
4893 mega_create_proc_entry(hba_count
, mega_proc_dir_entry
);
4895 error
= scsi_add_host(host
, &pdev
->dev
);
4899 scsi_scan_host(host
);
4904 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
4905 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
4907 free_irq(adapter
->host
->irq
, adapter
);
4909 kfree(adapter
->scb_list
);
4910 out_free_cmd_buffer
:
4911 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
4912 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
4914 scsi_host_put(host
);
4916 if (flag
& BOARD_MEMMAP
)
4917 iounmap((void *)mega_baseport
);
4919 if (flag
& BOARD_MEMMAP
)
4920 release_mem_region(tbase
, 128);
4922 release_region(mega_baseport
, 16);
4924 pci_disable_device(pdev
);
4930 __megaraid_shutdown(adapter_t
*adapter
)
4932 u_char raw_mbox
[sizeof(struct mbox_out
)];
4933 mbox_t
*mbox
= (mbox_t
*)raw_mbox
;
4936 /* Flush adapter cache */
4937 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4938 raw_mbox
[0] = FLUSH_ADAPTER
;
4940 free_irq(adapter
->host
->irq
, adapter
);
4942 /* Issue a blocking (interrupts disabled) command to the card */
4943 issue_scb_block(adapter
, raw_mbox
);
4945 /* Flush disks cache */
4946 memset(&mbox
->m_out
, 0, sizeof(raw_mbox
));
4947 raw_mbox
[0] = FLUSH_SYSTEM
;
4949 /* Issue a blocking (interrupts disabled) command to the card */
4950 issue_scb_block(adapter
, raw_mbox
);
4952 if (atomic_read(&adapter
->pend_cmds
) > 0)
4953 printk(KERN_WARNING
"megaraid: pending commands!!\n");
4956 * Have a delibrate delay to make sure all the caches are
4959 for (i
= 0; i
<= 10; i
++)
4964 megaraid_remove_one(struct pci_dev
*pdev
)
4966 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
4967 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
4968 char buf
[12] = { 0 };
4970 scsi_remove_host(host
);
4972 __megaraid_shutdown(adapter
);
4974 /* Free our resources */
4975 if (adapter
->flag
& BOARD_MEMMAP
) {
4976 iounmap((void *)adapter
->base
);
4977 release_mem_region(adapter
->host
->base
, 128);
4979 release_region(adapter
->base
, 16);
4981 mega_free_sgl(adapter
);
4983 #ifdef CONFIG_PROC_FS
4984 if (adapter
->controller_proc_dir_entry
) {
4985 remove_proc_entry("stat", adapter
->controller_proc_dir_entry
);
4986 remove_proc_entry("config",
4987 adapter
->controller_proc_dir_entry
);
4988 remove_proc_entry("mailbox",
4989 adapter
->controller_proc_dir_entry
);
4990 #if MEGA_HAVE_ENH_PROC
4991 remove_proc_entry("rebuild-rate",
4992 adapter
->controller_proc_dir_entry
);
4993 remove_proc_entry("battery-status",
4994 adapter
->controller_proc_dir_entry
);
4996 remove_proc_entry("diskdrives-ch0",
4997 adapter
->controller_proc_dir_entry
);
4998 remove_proc_entry("diskdrives-ch1",
4999 adapter
->controller_proc_dir_entry
);
5000 remove_proc_entry("diskdrives-ch2",
5001 adapter
->controller_proc_dir_entry
);
5002 remove_proc_entry("diskdrives-ch3",
5003 adapter
->controller_proc_dir_entry
);
5005 remove_proc_entry("raiddrives-0-9",
5006 adapter
->controller_proc_dir_entry
);
5007 remove_proc_entry("raiddrives-10-19",
5008 adapter
->controller_proc_dir_entry
);
5009 remove_proc_entry("raiddrives-20-29",
5010 adapter
->controller_proc_dir_entry
);
5011 remove_proc_entry("raiddrives-30-39",
5012 adapter
->controller_proc_dir_entry
);
5014 sprintf(buf
, "hba%d", adapter
->host
->host_no
);
5015 remove_proc_entry(buf
, mega_proc_dir_entry
);
5019 pci_free_consistent(adapter
->dev
, MEGA_BUFFER_SIZE
,
5020 adapter
->mega_buffer
, adapter
->buf_dma_handle
);
5021 kfree(adapter
->scb_list
);
5022 pci_free_consistent(adapter
->dev
, sizeof(mbox64_t
),
5023 adapter
->una_mbox64
, adapter
->una_mbox64_dma
);
5025 scsi_host_put(host
);
5026 pci_disable_device(pdev
);
5032 megaraid_shutdown(struct pci_dev
*pdev
)
5034 struct Scsi_Host
*host
= pci_get_drvdata(pdev
);
5035 adapter_t
*adapter
= (adapter_t
*)host
->hostdata
;
5037 __megaraid_shutdown(adapter
);
5040 static struct pci_device_id megaraid_pci_tbl
[] = {
5041 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID
,
5042 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5043 {PCI_VENDOR_ID_AMI
, PCI_DEVICE_ID_AMI_MEGARAID2
,
5044 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5045 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_AMI_MEGARAID3
,
5046 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
5049 MODULE_DEVICE_TABLE(pci
, megaraid_pci_tbl
);
5051 static struct pci_driver megaraid_pci_driver
= {
5052 .name
= "megaraid_legacy",
5053 .id_table
= megaraid_pci_tbl
,
5054 .probe
= megaraid_probe_one
,
5055 .remove
= __devexit_p(megaraid_remove_one
),
5056 .shutdown
= megaraid_shutdown
,
5059 static int __init
megaraid_init(void)
5063 if ((max_cmd_per_lun
<= 0) || (max_cmd_per_lun
> MAX_CMD_PER_LUN
))
5064 max_cmd_per_lun
= MAX_CMD_PER_LUN
;
5065 if (max_mbox_busy_wait
> MBOX_BUSY_WAIT
)
5066 max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
5068 #ifdef CONFIG_PROC_FS
5069 mega_proc_dir_entry
= proc_mkdir("megaraid", &proc_root
);
5070 if (!mega_proc_dir_entry
) {
5072 "megaraid: failed to create megaraid root\n");
5075 error
= pci_module_init(&megaraid_pci_driver
);
5077 #ifdef CONFIG_PROC_FS
5078 remove_proc_entry("megaraid", &proc_root
);
5084 * Register the driver as a character device, for applications
5085 * to access it for ioctls.
5086 * First argument (major) to register_chrdev implies a dynamic
5087 * major number allocation.
5089 major
= register_chrdev(0, "megadev_legacy", &megadev_fops
);
5092 "megaraid: failed to register char device\n");
5098 static void __exit
megaraid_exit(void)
5101 * Unregister the character device interface to the driver.
5103 unregister_chrdev(major
, "megadev_legacy");
5105 pci_unregister_driver(&megaraid_pci_driver
);
5107 #ifdef CONFIG_PROC_FS
5108 remove_proc_entry("megaraid", &proc_root
);
5112 module_init(megaraid_init
);
5113 module_exit(megaraid_exit
);
5115 /* vi: set ts=8 sw=8 tw=78: */