3 * Linux MegaRAID device driver
5 * Copyright © 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.3 (Feb 19, 2003) - Atul Mukker <Atul.Mukker@lsil.com>
22 * Description: Linux device driver for LSI Logic MegaRAID controller
24 * Supported controllers: MegaRAID 418, 428, 438, 466, 762, 467, 471, 490, 493
27 * This driver is supported by LSI Logic, with assistance from Red Hat, Dell,
28 * and others. Please send updates to the mailing list
29 * linux-scsi@vger.kernel.org .
35 #include <linux/blkdev.h>
36 #include <asm/uaccess.h>
38 #include <linux/delay.h>
39 #include <linux/proc_fs.h>
40 #include <linux/reboot.h>
41 #include <linux/module.h>
42 #include <linux/list.h>
43 #include <linux/interrupt.h>
44 #include <linux/pci.h>
45 #include <linux/init.h>
46 #include <scsi/scsicam.h>
49 #include <scsi/scsi_host.h>
53 #define MEGARAID_MODULE_VERSION "2.00.3"
55 MODULE_AUTHOR ("LSI Logic Corporation");
56 MODULE_DESCRIPTION ("LSI Logic MegaRAID driver");
57 MODULE_LICENSE ("GPL");
58 MODULE_VERSION(MEGARAID_MODULE_VERSION);
60 static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
61 module_param(max_cmd_per_lun, uint, 0);
62 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)");
64 static unsigned short int max_sectors_per_io = MAX_SECTORS_PER_IO;
65 module_param(max_sectors_per_io, ushort, 0);
66 MODULE_PARM_DESC(max_sectors_per_io, "Maximum number of sectors per I/O request (default=MAX_SECTORS_PER_IO=128)");
69 static unsigned short int max_mbox_busy_wait = MBOX_BUSY_WAIT;
70 module_param(max_mbox_busy_wait, ushort, 0);
71 MODULE_PARM_DESC(max_mbox_busy_wait, "Maximum wait for mailbox in microseconds if busy (default=MBOX_BUSY_WAIT=10)");
73 #define RDINDOOR(adapter) readl((adapter)->base + 0x20)
74 #define RDOUTDOOR(adapter) readl((adapter)->base + 0x2C)
75 #define WRINDOOR(adapter,value) writel(value, (adapter)->base + 0x20)
76 #define WROUTDOOR(adapter,value) writel(value, (adapter)->base + 0x2C)
83 static adapter_t *hba_soft_state[MAX_CONTROLLERS];
84 static struct proc_dir_entry *mega_proc_dir_entry;
86 /* For controller re-ordering */
87 static struct mega_hbas mega_hbas[MAX_CONTROLLERS];
90 * The File Operations structure for the serial/ioctl interface of the driver
92 static struct file_operations megadev_fops = {
94 .ioctl = megadev_ioctl,
99 * Array to structures for storing the information about the controllers. This
100 * information is sent to the user level applications, when they do an ioctl
101 * for this information.
103 static struct mcontroller mcontroller[MAX_CONTROLLERS];
105 /* The current driver version */
106 static u32 driver_ver = 0x02000000;
108 /* major number used by the device for character interface */
111 #define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
115 * Debug variable to print some diagnostic messages
117 static int trace_level;
120 * mega_setup_mailbox()
121 * @adapter - pointer to our soft state
123 * Allocates a 8 byte aligned memory for the handshake mailbox.
126 mega_setup_mailbox(adapter_t *adapter)
130 adapter->una_mbox64 = pci_alloc_consistent(adapter->dev,
131 sizeof(mbox64_t), &adapter->una_mbox64_dma);
133 if( !adapter->una_mbox64 ) return -1;
135 adapter->mbox = &adapter->una_mbox64->mbox;
137 adapter->mbox = (mbox_t *)((((unsigned long) adapter->mbox) + 15) &
140 adapter->mbox64 = (mbox64_t *)(((unsigned long)adapter->mbox) - 8);
142 align = ((void *)adapter->mbox) - ((void *)&adapter->una_mbox64->mbox);
144 adapter->mbox_dma = adapter->una_mbox64_dma + 8 + align;
147 * Register the mailbox if the controller is an io-mapped controller
149 if( adapter->flag & BOARD_IOMAP ) {
151 outb_p(adapter->mbox_dma & 0xFF,
152 adapter->host->io_port + MBOX_PORT0);
154 outb_p((adapter->mbox_dma >> 8) & 0xFF,
155 adapter->host->io_port + MBOX_PORT1);
157 outb_p((adapter->mbox_dma >> 16) & 0xFF,
158 adapter->host->io_port + MBOX_PORT2);
160 outb_p((adapter->mbox_dma >> 24) & 0xFF,
161 adapter->host->io_port + MBOX_PORT3);
163 outb_p(ENABLE_MBOX_BYTE,
164 adapter->host->io_port + ENABLE_MBOX_REGION);
176 * mega_query_adapter()
177 * @adapter - pointer to our soft state
179 * Issue the adapter inquiry commands to the controller and find out
180 * information and parameter about the devices attached
183 mega_query_adapter(adapter_t *adapter)
185 dma_addr_t prod_info_dma_handle;
186 mega_inquiry3 *inquiry3;
187 u8 raw_mbox[sizeof(struct mbox_out)];
191 /* Initialize adapter inquiry mailbox */
193 mbox = (mbox_t *)raw_mbox;
195 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
196 memset(&mbox->m_out, 0, sizeof(raw_mbox));
199 * Try to issue Inquiry3 command
200 * if not succeeded, then issue MEGA_MBOXCMD_ADAPTERINQ command and
201 * update enquiry3 structure
203 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
205 inquiry3 = (mega_inquiry3 *)adapter->mega_buffer;
207 raw_mbox[0] = FC_NEW_CONFIG; /* i.e. mbox->cmd=0xA1 */
208 raw_mbox[2] = NC_SUBOP_ENQUIRY3; /* i.e. 0x0F */
209 raw_mbox[3] = ENQ3_GET_SOLICITED_FULL; /* i.e. 0x02 */
211 /* Issue a blocking command to the card */
212 if ((retval = issue_scb_block(adapter, raw_mbox))) {
213 /* the adapter does not support 40ld */
215 mraid_ext_inquiry *ext_inq;
217 dma_addr_t dma_handle;
219 ext_inq = pci_alloc_consistent(adapter->dev,
220 sizeof(mraid_ext_inquiry), &dma_handle);
222 if( ext_inq == NULL ) return -1;
224 inq = &ext_inq->raid_inq;
226 mbox->m_out.xferaddr = (u32)dma_handle;
228 /*issue old 0x04 command to adapter */
229 mbox->m_out.cmd = MEGA_MBOXCMD_ADPEXTINQ;
231 issue_scb_block(adapter, raw_mbox);
234 * update Enquiry3 and ProductInfo structures with
235 * mraid_inquiry structure
237 mega_8_to_40ld(inq, inquiry3,
238 (mega_product_info *)&adapter->product_info);
240 pci_free_consistent(adapter->dev, sizeof(mraid_ext_inquiry),
241 ext_inq, dma_handle);
243 } else { /*adapter supports 40ld */
244 adapter->flag |= BOARD_40LD;
247 * get product_info, which is static information and will be
250 prod_info_dma_handle = pci_map_single(adapter->dev, (void *)
251 &adapter->product_info,
252 sizeof(mega_product_info), PCI_DMA_FROMDEVICE);
254 mbox->m_out.xferaddr = prod_info_dma_handle;
256 raw_mbox[0] = FC_NEW_CONFIG; /* i.e. mbox->cmd=0xA1 */
257 raw_mbox[2] = NC_SUBOP_PRODUCT_INFO; /* i.e. 0x0E */
259 if ((retval = issue_scb_block(adapter, raw_mbox)))
261 "megaraid: Product_info cmd failed with error: %d\n",
264 pci_unmap_single(adapter->dev, prod_info_dma_handle,
265 sizeof(mega_product_info), PCI_DMA_FROMDEVICE);
270 * kernel scans the channels from 0 to <= max_channel
272 adapter->host->max_channel =
273 adapter->product_info.nchannels + NVIRT_CHAN -1;
275 adapter->host->max_id = 16; /* max targets per channel */
277 adapter->host->max_lun = 7; /* Upto 7 luns for non disk devices */
279 adapter->host->cmd_per_lun = max_cmd_per_lun;
281 adapter->numldrv = inquiry3->num_ldrv;
283 adapter->max_cmds = adapter->product_info.max_commands;
285 if(adapter->max_cmds > MAX_COMMANDS)
286 adapter->max_cmds = MAX_COMMANDS;
288 adapter->host->can_queue = adapter->max_cmds - 1;
291 * Get the maximum number of scatter-gather elements supported by this
294 mega_get_max_sgl(adapter);
296 adapter->host->sg_tablesize = adapter->sglen;
299 /* use HP firmware and bios version encoding */
300 if (adapter->product_info.subsysvid == HP_SUBSYS_VID) {
301 sprintf (adapter->fw_version, "%c%d%d.%d%d",
302 adapter->product_info.fw_version[2],
303 adapter->product_info.fw_version[1] >> 8,
304 adapter->product_info.fw_version[1] & 0x0f,
305 adapter->product_info.fw_version[0] >> 8,
306 adapter->product_info.fw_version[0] & 0x0f);
307 sprintf (adapter->bios_version, "%c%d%d.%d%d",
308 adapter->product_info.bios_version[2],
309 adapter->product_info.bios_version[1] >> 8,
310 adapter->product_info.bios_version[1] & 0x0f,
311 adapter->product_info.bios_version[0] >> 8,
312 adapter->product_info.bios_version[0] & 0x0f);
314 memcpy(adapter->fw_version,
315 (char *)adapter->product_info.fw_version, 4);
316 adapter->fw_version[4] = 0;
318 memcpy(adapter->bios_version,
319 (char *)adapter->product_info.bios_version, 4);
321 adapter->bios_version[4] = 0;
324 printk(KERN_NOTICE "megaraid: [%s:%s] detected %d logical drives.\n",
325 adapter->fw_version, adapter->bios_version, adapter->numldrv);
328 * Do we support extended (>10 bytes) cdbs
330 adapter->support_ext_cdb = mega_support_ext_cdb(adapter);
331 if (adapter->support_ext_cdb)
332 printk(KERN_NOTICE "megaraid: supports extended CDBs.\n");
340 * @adapter - pointer to our soft state
342 * Runs through the list of pending requests.
345 mega_runpendq(adapter_t *adapter)
347 if(!list_empty(&adapter->pending_list))
348 __mega_runpendq(adapter);
353 * @scmd - Issue this scsi command
354 * @done - the callback hook into the scsi mid-layer
356 * The command queuing entry point for the mid-layer.
359 megaraid_queue(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
365 adapter = (adapter_t *)scmd->device->host->hostdata;
367 scmd->scsi_done = done;
371 * Allocate and build a SCB request
372 * busy flag will be set if mega_build_cmd() command could not
373 * allocate scb. We will return non-zero status in that case.
374 * NOTE: scb can be null even though certain commands completed
375 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
376 * return 0 in that case.
379 scb = mega_build_cmd(adapter, scmd, &busy);
382 scb->state |= SCB_PENDQ;
383 list_add_tail(&scb->list, &adapter->pending_list);
386 * Check if the HBA is in quiescent state, e.g., during a
387 * delete logical drive opertion. If it is, don't run
390 if(atomic_read(&adapter->quiescent) == 0) {
391 mega_runpendq(adapter);
400 * mega_allocate_scb()
401 * @adapter - pointer to our soft state
402 * @cmd - scsi command from the mid-layer
404 * Allocate a SCB structure. This is the central structure for controller
407 static inline scb_t *
408 mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd)
410 struct list_head *head = &adapter->free_list;
413 /* Unlink command from Free List */
414 if( !list_empty(head) ) {
416 scb = list_entry(head->next, scb_t, list);
418 list_del_init(head->next);
420 scb->state = SCB_ACTIVE;
422 scb->dma_type = MEGA_DMA_TYPE_NONE;
431 * mega_get_ldrv_num()
432 * @adapter - pointer to our soft state
433 * @cmd - scsi mid layer command
434 * @channel - channel on the controller
436 * Calculate the logical drive number based on the information in scsi command
437 * and the channel number.
440 mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel)
445 tgt = cmd->device->id;
447 if ( tgt > adapter->this_id )
448 tgt--; /* we do not get inquires for initiator id */
450 ldrv_num = (channel * 15) + tgt;
454 * If we have a logical drive with boot enabled, project it first
456 if( adapter->boot_ldrv_enabled ) {
457 if( ldrv_num == 0 ) {
458 ldrv_num = adapter->boot_ldrv;
461 if( ldrv_num <= adapter->boot_ldrv ) {
468 * If "delete logical drive" feature is enabled on this controller.
469 * Do only if at least one delete logical drive operation was done.
471 * Also, after logical drive deletion, instead of logical drive number,
472 * the value returned should be 0x80+logical drive id.
474 * These is valid only for IO commands.
477 if (adapter->support_random_del && adapter->read_ldidmap )
478 switch (cmd->cmnd[0]) {
479 case READ_6: /* fall through */
480 case WRITE_6: /* fall through */
481 case READ_10: /* fall through */
491 * @adapter - pointer to our soft state
492 * @cmd - Prepare using this scsi command
493 * @busy - busy flag if no resources
495 * Prepares a command and scatter gather list for the controller. This routine
496 * also finds out if the commands is intended for a logical drive or a
497 * physical device and prepares the controller command accordingly.
499 * We also re-order the logical drives and physical devices based on their
503 mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy)
505 mega_ext_passthru *epthru;
506 mega_passthru *pthru;
514 int ldrv_num = 0; /* logical drive number */
518 * filter the internal and ioctl commands
520 if((cmd->cmnd[0] == MEGA_INTERNAL_CMD)) {
526 * We know what channels our logical drives are on - mega_find_card()
528 islogical = adapter->logdrv_chan[cmd->device->channel];
531 * The theory: If physical drive is chosen for boot, all the physical
532 * devices are exported before the logical drives, otherwise physical
533 * devices are pushed after logical drives, in which case - Kernel sees
534 * the physical devices on virtual channel which is obviously converted
535 * to actual channel on the HBA.
537 if( adapter->boot_pdrv_enabled ) {
539 /* logical channel */
540 channel = cmd->device->channel -
541 adapter->product_info.nchannels;
544 /* this is physical channel */
545 channel = cmd->device->channel;
546 target = cmd->device->id;
549 * boot from a physical disk, that disk needs to be
550 * exposed first IF both the channels are SCSI, then
551 * booting from the second channel is not allowed.
554 target = adapter->boot_pdrv_tgt;
556 else if( target == adapter->boot_pdrv_tgt ) {
563 /* this is the logical channel */
564 channel = cmd->device->channel;
567 /* physical channel */
568 channel = cmd->device->channel - NVIRT_CHAN;
569 target = cmd->device->id;
576 /* have just LUN 0 for each target on virtual channels */
577 if (cmd->device->lun) {
578 cmd->result = (DID_BAD_TARGET << 16);
583 ldrv_num = mega_get_ldrv_num(adapter, cmd, channel);
586 max_ldrv_num = (adapter->flag & BOARD_40LD) ?
587 MAX_LOGICAL_DRIVES_40LD : MAX_LOGICAL_DRIVES_8LD;
590 * max_ldrv_num increases by 0x80 if some logical drive was
593 if(adapter->read_ldidmap)
594 max_ldrv_num += 0x80;
596 if(ldrv_num > max_ldrv_num ) {
597 cmd->result = (DID_BAD_TARGET << 16);
604 if( cmd->device->lun > 7) {
606 * Do not support lun >7 for physically accessed
609 cmd->result = (DID_BAD_TARGET << 16);
617 * Logical drive commands
621 switch (cmd->cmnd[0]) {
622 case TEST_UNIT_READY:
623 memset(cmd->request_buffer, 0, cmd->request_bufflen);
625 #if MEGA_HAVE_CLUSTERING
627 * Do we support clustering and is the support enabled
628 * If no, return success always
630 if( !adapter->has_cluster ) {
631 cmd->result = (DID_OK << 16);
636 if(!(scb = mega_allocate_scb(adapter, cmd))) {
641 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
642 scb->raw_mbox[2] = MEGA_RESERVATION_STATUS;
643 scb->raw_mbox[3] = ldrv_num;
645 scb->dma_direction = PCI_DMA_NONE;
649 cmd->result = (DID_OK << 16);
655 memset(cmd->request_buffer, 0, cmd->cmnd[4]);
656 cmd->result = (DID_OK << 16);
663 if(!(adapter->flag & (1L << cmd->device->channel))) {
666 "scsi%d: scanning scsi channel %d ",
667 adapter->host->host_no,
668 cmd->device->channel);
669 printk("for logical drives.\n");
671 adapter->flag |= (1L << cmd->device->channel);
674 /* Allocate a SCB and initialize passthru */
675 if(!(scb = mega_allocate_scb(adapter, cmd))) {
681 mbox = (mbox_t *)scb->raw_mbox;
682 memset(mbox, 0, sizeof(scb->raw_mbox));
683 memset(pthru, 0, sizeof(mega_passthru));
687 pthru->reqsenselen = 14;
688 pthru->islogical = 1;
689 pthru->logdrv = ldrv_num;
690 pthru->cdblen = cmd->cmd_len;
691 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
693 if( adapter->has_64bit_addr ) {
694 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
697 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
700 scb->dma_direction = PCI_DMA_FROMDEVICE;
702 pthru->numsgelements = mega_build_sglist(adapter, scb,
703 &pthru->dataxferaddr, &pthru->dataxferlen);
705 mbox->m_out.xferaddr = scb->pthru_dma_addr;
716 /* Allocate a SCB and initialize mailbox */
717 if(!(scb = mega_allocate_scb(adapter, cmd))) {
721 mbox = (mbox_t *)scb->raw_mbox;
723 memset(mbox, 0, sizeof(scb->raw_mbox));
724 mbox->m_out.logdrv = ldrv_num;
727 * A little hack: 2nd bit is zero for all scsi read
728 * commands and is set for all scsi write commands
730 if( adapter->has_64bit_addr ) {
731 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
732 MEGA_MBOXCMD_LWRITE64:
733 MEGA_MBOXCMD_LREAD64 ;
736 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
742 * 6-byte READ(0x08) or WRITE(0x0A) cdb
744 if( cmd->cmd_len == 6 ) {
745 mbox->m_out.numsectors = (u32) cmd->cmnd[4];
747 ((u32)cmd->cmnd[1] << 16) |
748 ((u32)cmd->cmnd[2] << 8) |
751 mbox->m_out.lba &= 0x1FFFFF;
755 * Take modulo 0x80, since the logical drive
756 * number increases by 0x80 when a logical
759 if (*cmd->cmnd == READ_6) {
760 adapter->nreads[ldrv_num%0x80]++;
761 adapter->nreadblocks[ldrv_num%0x80] +=
762 mbox->m_out.numsectors;
764 adapter->nwrites[ldrv_num%0x80]++;
765 adapter->nwriteblocks[ldrv_num%0x80] +=
766 mbox->m_out.numsectors;
772 * 10-byte READ(0x28) or WRITE(0x2A) cdb
774 if( cmd->cmd_len == 10 ) {
775 mbox->m_out.numsectors =
777 ((u32)cmd->cmnd[7] << 8);
779 ((u32)cmd->cmnd[2] << 24) |
780 ((u32)cmd->cmnd[3] << 16) |
781 ((u32)cmd->cmnd[4] << 8) |
785 if (*cmd->cmnd == READ_10) {
786 adapter->nreads[ldrv_num%0x80]++;
787 adapter->nreadblocks[ldrv_num%0x80] +=
788 mbox->m_out.numsectors;
790 adapter->nwrites[ldrv_num%0x80]++;
791 adapter->nwriteblocks[ldrv_num%0x80] +=
792 mbox->m_out.numsectors;
798 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
800 if( cmd->cmd_len == 12 ) {
802 ((u32)cmd->cmnd[2] << 24) |
803 ((u32)cmd->cmnd[3] << 16) |
804 ((u32)cmd->cmnd[4] << 8) |
807 mbox->m_out.numsectors =
808 ((u32)cmd->cmnd[6] << 24) |
809 ((u32)cmd->cmnd[7] << 16) |
810 ((u32)cmd->cmnd[8] << 8) |
814 if (*cmd->cmnd == READ_12) {
815 adapter->nreads[ldrv_num%0x80]++;
816 adapter->nreadblocks[ldrv_num%0x80] +=
817 mbox->m_out.numsectors;
819 adapter->nwrites[ldrv_num%0x80]++;
820 adapter->nwriteblocks[ldrv_num%0x80] +=
821 mbox->m_out.numsectors;
827 * If it is a read command
829 if( (*cmd->cmnd & 0x0F) == 0x08 ) {
830 scb->dma_direction = PCI_DMA_FROMDEVICE;
833 scb->dma_direction = PCI_DMA_TODEVICE;
836 /* Calculate Scatter-Gather info */
837 mbox->m_out.numsgelements = mega_build_sglist(adapter, scb,
838 (u32 *)&mbox->m_out.xferaddr, (u32 *)&seg);
842 #if MEGA_HAVE_CLUSTERING
843 case RESERVE: /* Fall through */
847 * Do we support clustering and is the support enabled
849 if( ! adapter->has_cluster ) {
851 cmd->result = (DID_BAD_TARGET << 16);
856 /* Allocate a SCB and initialize mailbox */
857 if(!(scb = mega_allocate_scb(adapter, cmd))) {
862 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
863 scb->raw_mbox[2] = ( *cmd->cmnd == RESERVE ) ?
864 MEGA_RESERVE_LD : MEGA_RELEASE_LD;
866 scb->raw_mbox[3] = ldrv_num;
868 scb->dma_direction = PCI_DMA_NONE;
874 cmd->result = (DID_BAD_TARGET << 16);
881 * Passthru drive commands
884 /* Allocate a SCB and initialize passthru */
885 if(!(scb = mega_allocate_scb(adapter, cmd))) {
890 mbox = (mbox_t *)scb->raw_mbox;
891 memset(mbox, 0, sizeof(scb->raw_mbox));
893 if( adapter->support_ext_cdb ) {
895 epthru = mega_prepare_extpassthru(adapter, scb, cmd,
898 mbox->m_out.cmd = MEGA_MBOXCMD_EXTPTHRU;
900 mbox->m_out.xferaddr = scb->epthru_dma_addr;
905 pthru = mega_prepare_passthru(adapter, scb, cmd,
908 /* Initialize mailbox */
909 if( adapter->has_64bit_addr ) {
910 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
913 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
916 mbox->m_out.xferaddr = scb->pthru_dma_addr;
926 * mega_prepare_passthru()
927 * @adapter - pointer to our soft state
928 * @scb - our scsi control block
929 * @cmd - scsi command from the mid-layer
930 * @channel - actual channel on the controller
931 * @target - actual id on the controller.
933 * prepare a command for the scsi physical devices.
935 static mega_passthru *
936 mega_prepare_passthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
937 int channel, int target)
939 mega_passthru *pthru;
942 memset(pthru, 0, sizeof (mega_passthru));
944 /* 0=6sec/1=60sec/2=10min/3=3hrs */
948 pthru->reqsenselen = 14;
949 pthru->islogical = 0;
951 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
953 pthru->target = (adapter->flag & BOARD_40LD) ?
954 (channel << 4) | target : target;
956 pthru->cdblen = cmd->cmd_len;
957 pthru->logdrv = cmd->device->lun;
959 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
961 /* Not sure about the direction */
962 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
964 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
965 switch (cmd->cmnd[0]) {
968 if(!(adapter->flag & (1L << cmd->device->channel))) {
971 "scsi%d: scanning scsi channel %d [P%d] ",
972 adapter->host->host_no,
973 cmd->device->channel, channel);
974 printk("for physical devices.\n");
976 adapter->flag |= (1L << cmd->device->channel);
980 pthru->numsgelements = mega_build_sglist(adapter, scb,
981 &pthru->dataxferaddr, &pthru->dataxferlen);
989 * mega_prepare_extpassthru()
990 * @adapter - pointer to our soft state
991 * @scb - our scsi control block
992 * @cmd - scsi command from the mid-layer
993 * @channel - actual channel on the controller
994 * @target - actual id on the controller.
996 * prepare a command for the scsi physical devices. This rountine prepares
997 * commands for devices which can take extended CDBs (>10 bytes)
999 static mega_ext_passthru *
1000 mega_prepare_extpassthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
1001 int channel, int target)
1003 mega_ext_passthru *epthru;
1005 epthru = scb->epthru;
1006 memset(epthru, 0, sizeof(mega_ext_passthru));
1008 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1009 epthru->timeout = 2;
1012 epthru->reqsenselen = 14;
1013 epthru->islogical = 0;
1015 epthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
1016 epthru->target = (adapter->flag & BOARD_40LD) ?
1017 (channel << 4) | target : target;
1019 epthru->cdblen = cmd->cmd_len;
1020 epthru->logdrv = cmd->device->lun;
1022 memcpy(epthru->cdb, cmd->cmnd, cmd->cmd_len);
1024 /* Not sure about the direction */
1025 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
1027 switch(cmd->cmnd[0]) {
1030 if(!(adapter->flag & (1L << cmd->device->channel))) {
1033 "scsi%d: scanning scsi channel %d [P%d] ",
1034 adapter->host->host_no,
1035 cmd->device->channel, channel);
1036 printk("for physical devices.\n");
1038 adapter->flag |= (1L << cmd->device->channel);
1042 epthru->numsgelements = mega_build_sglist(adapter, scb,
1043 &epthru->dataxferaddr, &epthru->dataxferlen);
1051 __mega_runpendq(adapter_t *adapter)
1054 struct list_head *pos, *next;
1056 /* Issue any pending commands to the card */
1057 list_for_each_safe(pos, next, &adapter->pending_list) {
1059 scb = list_entry(pos, scb_t, list);
1061 if( !(scb->state & SCB_ISSUED) ) {
1063 if( issue_scb(adapter, scb) != 0 )
1074 * @adapter - pointer to our soft state
1075 * @scb - scsi control block
1077 * Post a command to the card if the mailbox is available, otherwise return
1078 * busy. We also take the scb from the pending list if the mailbox is
1082 issue_scb(adapter_t *adapter, scb_t *scb)
1084 volatile mbox64_t *mbox64 = adapter->mbox64;
1085 volatile mbox_t *mbox = adapter->mbox;
1088 if(unlikely(mbox->m_in.busy)) {
1092 } while( mbox->m_in.busy && (i < max_mbox_busy_wait) );
1094 if(mbox->m_in.busy) return -1;
1097 /* Copy mailbox data into host structure */
1098 memcpy((char *)&mbox->m_out, (char *)scb->raw_mbox,
1099 sizeof(struct mbox_out));
1101 mbox->m_out.cmdid = scb->idx; /* Set cmdid */
1102 mbox->m_in.busy = 1; /* Set busy */
1106 * Increment the pending queue counter
1108 atomic_inc(&adapter->pend_cmds);
1110 switch (mbox->m_out.cmd) {
1111 case MEGA_MBOXCMD_LREAD64:
1112 case MEGA_MBOXCMD_LWRITE64:
1113 case MEGA_MBOXCMD_PASSTHRU64:
1114 case MEGA_MBOXCMD_EXTPTHRU:
1115 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1116 mbox64->xfer_segment_hi = 0;
1117 mbox->m_out.xferaddr = 0xFFFFFFFF;
1120 mbox64->xfer_segment_lo = 0;
1121 mbox64->xfer_segment_hi = 0;
1127 scb->state |= SCB_ISSUED;
1129 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1130 mbox->m_in.poll = 0;
1132 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1135 irq_enable(adapter);
1136 issue_command(adapter);
1143 * Wait until the controller's mailbox is available
1146 mega_busywait_mbox (adapter_t *adapter)
1148 if (adapter->mbox->m_in.busy)
1149 return __mega_busywait_mbox(adapter);
1155 * @adapter - pointer to our soft state
1156 * @raw_mbox - the mailbox
1158 * Issue a scb in synchronous and non-interrupt mode
1161 issue_scb_block(adapter_t *adapter, u_char *raw_mbox)
1163 volatile mbox64_t *mbox64 = adapter->mbox64;
1164 volatile mbox_t *mbox = adapter->mbox;
1167 /* Wait until mailbox is free */
1168 if(mega_busywait_mbox (adapter))
1169 goto bug_blocked_mailbox;
1171 /* Copy mailbox data into host structure */
1172 memcpy((char *) mbox, raw_mbox, sizeof(struct mbox_out));
1173 mbox->m_out.cmdid = 0xFE;
1174 mbox->m_in.busy = 1;
1176 switch (raw_mbox[0]) {
1177 case MEGA_MBOXCMD_LREAD64:
1178 case MEGA_MBOXCMD_LWRITE64:
1179 case MEGA_MBOXCMD_PASSTHRU64:
1180 case MEGA_MBOXCMD_EXTPTHRU:
1181 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1182 mbox64->xfer_segment_hi = 0;
1183 mbox->m_out.xferaddr = 0xFFFFFFFF;
1186 mbox64->xfer_segment_lo = 0;
1187 mbox64->xfer_segment_hi = 0;
1190 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1191 mbox->m_in.poll = 0;
1193 mbox->m_in.numstatus = 0xFF;
1194 mbox->m_in.status = 0xFF;
1195 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1197 while((volatile u8)mbox->m_in.numstatus == 0xFF)
1200 mbox->m_in.numstatus = 0xFF;
1202 while( (volatile u8)mbox->m_in.poll != 0x77 )
1205 mbox->m_in.poll = 0;
1206 mbox->m_in.ack = 0x77;
1208 WRINDOOR(adapter, adapter->mbox_dma | 0x2);
1210 while(RDINDOOR(adapter) & 0x2)
1214 irq_disable(adapter);
1215 issue_command(adapter);
1217 while (!((byte = irq_state(adapter)) & INTR_VALID))
1220 set_irq_state(adapter, byte);
1221 irq_enable(adapter);
1225 return mbox->m_in.status;
1227 bug_blocked_mailbox:
1228 printk(KERN_WARNING "megaraid: Blocked mailbox......!!\n");
1235 * megaraid_isr_iomapped()
1237 * @devp - pointer to our soft state
1240 * Interrupt service routine for io-mapped controllers.
1241 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1242 * and service the completed commands.
1245 megaraid_isr_iomapped(int irq, void *devp, struct pt_regs *regs)
1247 adapter_t *adapter = devp;
1248 unsigned long flags;
1251 u8 completed[MAX_FIRMWARE_STATUS];
1257 * loop till F/W has more commands for us to complete.
1259 spin_lock_irqsave(&adapter->lock, flags);
1262 /* Check if a valid interrupt is pending */
1263 byte = irq_state(adapter);
1264 if( (byte & VALID_INTR_BYTE) == 0 ) {
1266 * No more pending commands
1270 set_irq_state(adapter, byte);
1272 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1275 adapter->mbox->m_in.numstatus = 0xFF;
1277 status = adapter->mbox->m_in.status;
1280 * decrement the pending queue counter
1282 atomic_sub(nstatus, &adapter->pend_cmds);
1284 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1287 /* Acknowledge interrupt */
1290 mega_cmd_done(adapter, completed, nstatus, status);
1292 mega_rundoneq(adapter);
1296 /* Loop through any pending requests */
1297 if(atomic_read(&adapter->quiescent) == 0) {
1298 mega_runpendq(adapter);
1305 spin_unlock_irqrestore(&adapter->lock, flags);
1307 return IRQ_RETVAL(handled);
1312 * megaraid_isr_memmapped()
1314 * @devp - pointer to our soft state
1317 * Interrupt service routine for memory-mapped controllers.
1318 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1319 * and service the completed commands.
1322 megaraid_isr_memmapped(int irq, void *devp, struct pt_regs *regs)
1324 adapter_t *adapter = devp;
1325 unsigned long flags;
1329 u8 completed[MAX_FIRMWARE_STATUS];
1334 * loop till F/W has more commands for us to complete.
1336 spin_lock_irqsave(&adapter->lock, flags);
1339 /* Check if a valid interrupt is pending */
1340 dword = RDOUTDOOR(adapter);
1341 if(dword != 0x10001234) {
1343 * No more pending commands
1347 WROUTDOOR(adapter, 0x10001234);
1349 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1353 adapter->mbox->m_in.numstatus = 0xFF;
1355 status = adapter->mbox->m_in.status;
1358 * decrement the pending queue counter
1360 atomic_sub(nstatus, &adapter->pend_cmds);
1362 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1365 /* Acknowledge interrupt */
1366 WRINDOOR(adapter, 0x2);
1370 while( RDINDOOR(adapter) & 0x02 ) cpu_relax();
1372 mega_cmd_done(adapter, completed, nstatus, status);
1374 mega_rundoneq(adapter);
1376 /* Loop through any pending requests */
1377 if(atomic_read(&adapter->quiescent) == 0) {
1378 mega_runpendq(adapter);
1385 spin_unlock_irqrestore(&adapter->lock, flags);
1387 return IRQ_RETVAL(handled);
1391 * @adapter - pointer to our soft state
1392 * @completed - array of ids of completed commands
1393 * @nstatus - number of completed commands
1394 * @status - status of the last command completed
1396 * Complete the comamnds and call the scsi mid-layer callback hooks.
1399 mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
1401 mega_ext_passthru *epthru = NULL;
1402 struct scatterlist *sgl;
1403 Scsi_Cmnd *cmd = NULL;
1404 mega_passthru *pthru = NULL;
1405 mbox_t *mbox = NULL;
1413 * for all the commands completed, call the mid-layer callback routine
1416 for( i = 0; i < nstatus; i++ ) {
1418 cmdid = completed[i];
1420 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1421 scb = &adapter->int_scb;
1423 mbox = (mbox_t *)scb->raw_mbox;
1426 * Internal command interface do not fire the extended
1427 * passthru or 64-bit passthru
1433 scb = &adapter->scb_list[cmdid];
1436 * Make sure f/w has completed a valid command
1438 if( !(scb->state & SCB_ISSUED) || scb->cmd == NULL ) {
1440 "megaraid: invalid command ");
1441 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1442 cmdid, scb->state, scb->cmd);
1448 * Was a abort issued for this command
1450 if( scb->state & SCB_ABORT ) {
1453 "megaraid: aborted cmd %lx[%x] complete.\n",
1454 scb->cmd->serial_number, scb->idx);
1456 scb->cmd->result = (DID_ABORT << 16);
1458 list_add_tail(SCSI_LIST(scb->cmd),
1459 &adapter->completed_list);
1461 mega_free_scb(adapter, scb);
1467 * Was a reset issued for this command
1469 if( scb->state & SCB_RESET ) {
1472 "megaraid: reset cmd %lx[%x] complete.\n",
1473 scb->cmd->serial_number, scb->idx);
1475 scb->cmd->result = (DID_RESET << 16);
1477 list_add_tail(SCSI_LIST(scb->cmd),
1478 &adapter->completed_list);
1480 mega_free_scb (adapter, scb);
1487 epthru = scb->epthru;
1488 mbox = (mbox_t *)scb->raw_mbox;
1493 int logdrv = mbox->m_out.logdrv;
1495 islogical = adapter->logdrv_chan[cmd->channel];
1497 * Maintain an error counter for the logical drive.
1498 * Some application like SNMP agent need such
1501 if( status && islogical && (cmd->cmnd[0] == READ_6 ||
1502 cmd->cmnd[0] == READ_10 ||
1503 cmd->cmnd[0] == READ_12)) {
1505 * Logical drive number increases by 0x80 when
1506 * a logical drive is deleted
1508 adapter->rd_errors[logdrv%0x80]++;
1511 if( status && islogical && (cmd->cmnd[0] == WRITE_6 ||
1512 cmd->cmnd[0] == WRITE_10 ||
1513 cmd->cmnd[0] == WRITE_12)) {
1515 * Logical drive number increases by 0x80 when
1516 * a logical drive is deleted
1518 adapter->wr_errors[logdrv%0x80]++;
1526 * Do not return the presence of hard disk on the channel so,
1527 * inquiry sent, and returned data==hard disk or removable
1528 * hard disk and not logical, request should return failure! -
1531 islogical = adapter->logdrv_chan[cmd->device->channel];
1532 if( cmd->cmnd[0] == INQUIRY && !islogical ) {
1535 sgl = (struct scatterlist *)
1536 cmd->request_buffer;
1539 c = *(unsigned char *)
1540 page_address((&sgl[0])->page) +
1545 "megaraid: invalid sg.\n");
1550 c = *(u8 *)cmd->request_buffer;
1553 if(IS_RAID_CH(adapter, cmd->device->channel) &&
1554 ((c & 0x1F ) == TYPE_DISK)) {
1559 /* clear result; otherwise, success returns corrupt value */
1562 /* Convert MegaRAID status to Linux error code */
1564 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1565 cmd->result |= (DID_OK << 16);
1568 case 0x02: /* ERROR_ABORTED, i.e.
1569 SCSI_STATUS_CHECK_CONDITION */
1571 /* set sense_buffer and result fields */
1572 if( mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU ||
1573 mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU64 ) {
1575 memcpy(cmd->sense_buffer, pthru->reqsensearea,
1578 cmd->result = (DRIVER_SENSE << 24) |
1580 (CHECK_CONDITION << 1);
1583 if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
1585 memcpy(cmd->sense_buffer,
1586 epthru->reqsensearea, 14);
1588 cmd->result = (DRIVER_SENSE << 24) |
1590 (CHECK_CONDITION << 1);
1592 cmd->sense_buffer[0] = 0x70;
1593 cmd->sense_buffer[2] = ABORTED_COMMAND;
1594 cmd->result |= (CHECK_CONDITION << 1);
1599 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1601 cmd->result |= (DID_BUS_BUSY << 16) | status;
1605 #if MEGA_HAVE_CLUSTERING
1607 * If TEST_UNIT_READY fails, we know
1608 * MEGA_RESERVATION_STATUS failed
1610 if( cmd->cmnd[0] == TEST_UNIT_READY ) {
1611 cmd->result |= (DID_ERROR << 16) |
1612 (RESERVATION_CONFLICT << 1);
1616 * Error code returned is 1 if Reserve or Release
1617 * failed or the input parameter is invalid
1620 (cmd->cmnd[0] == RESERVE ||
1621 cmd->cmnd[0] == RELEASE) ) {
1623 cmd->result |= (DID_ERROR << 16) |
1624 (RESERVATION_CONFLICT << 1);
1628 cmd->result |= (DID_BAD_TARGET << 16)|status;
1632 * Only free SCBs for the commands coming down from the
1633 * mid-layer, not for which were issued internally
1635 * For internal command, restore the status returned by the
1636 * firmware so that user can interpret it.
1638 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1639 cmd->result = status;
1642 * Remove the internal command from the pending list
1644 list_del_init(&scb->list);
1645 scb->state = SCB_FREE;
1648 mega_free_scb(adapter, scb);
1651 /* Add Scsi_Command to end of completed queue */
1652 list_add_tail(SCSI_LIST(cmd), &adapter->completed_list);
1660 * Run through the list of completed requests and finish it
1663 mega_rundoneq (adapter_t *adapter)
1666 struct list_head *pos;
1668 list_for_each(pos, &adapter->completed_list) {
1670 Scsi_Pointer* spos = (Scsi_Pointer *)pos;
1672 cmd = list_entry(spos, Scsi_Cmnd, SCp);
1673 cmd->scsi_done(cmd);
1676 INIT_LIST_HEAD(&adapter->completed_list);
1681 * Free a SCB structure
1682 * Note: We assume the scsi commands associated with this scb is not free yet.
1685 mega_free_scb(adapter_t *adapter, scb_t *scb)
1687 switch( scb->dma_type ) {
1689 case MEGA_DMA_TYPE_NONE:
1692 case MEGA_BULK_DATA:
1693 pci_unmap_page(adapter->dev, scb->dma_h_bulkdata,
1694 scb->cmd->request_bufflen, scb->dma_direction);
1698 pci_unmap_sg(adapter->dev, scb->cmd->request_buffer,
1699 scb->cmd->use_sg, scb->dma_direction);
1707 * Remove from the pending list
1709 list_del_init(&scb->list);
1711 /* Link the scb back into free list */
1712 scb->state = SCB_FREE;
1715 list_add(&scb->list, &adapter->free_list);
1720 __mega_busywait_mbox (adapter_t *adapter)
1722 volatile mbox_t *mbox = adapter->mbox;
1725 for (counter = 0; counter < 10000; counter++) {
1726 if (!mbox->m_in.busy)
1728 udelay(100); yield();
1730 return -1; /* give up after 1 second */
1734 * Copies data to SGLIST
1735 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1738 mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len)
1740 struct scatterlist *sgl;
1742 unsigned long offset;
1749 /* Scatter-gather not used */
1750 if( !cmd->use_sg ) {
1752 page = virt_to_page(cmd->request_buffer);
1753 offset = offset_in_page(cmd->request_buffer);
1755 scb->dma_h_bulkdata = pci_map_page(adapter->dev,
1757 cmd->request_bufflen,
1758 scb->dma_direction);
1759 scb->dma_type = MEGA_BULK_DATA;
1762 * We need to handle special 64-bit commands that need a
1765 if( adapter->has_64bit_addr ) {
1766 scb->sgl64[0].address = scb->dma_h_bulkdata;
1767 scb->sgl64[0].length = cmd->request_bufflen;
1768 *buf = (u32)scb->sgl_dma_addr;
1769 *len = (u32)cmd->request_bufflen;
1773 *buf = (u32)scb->dma_h_bulkdata;
1774 *len = (u32)cmd->request_bufflen;
1779 sgl = (struct scatterlist *)cmd->request_buffer;
1782 * Copy Scatter-Gather list info into controller structure.
1784 * The number of sg elements returned must not exceed our limit
1786 sgcnt = pci_map_sg(adapter->dev, sgl, cmd->use_sg,
1787 scb->dma_direction);
1789 scb->dma_type = MEGA_SGLIST;
1791 if( sgcnt > adapter->sglen ) BUG();
1793 for( idx = 0; idx < sgcnt; idx++, sgl++ ) {
1795 if( adapter->has_64bit_addr ) {
1796 scb->sgl64[idx].address = sg_dma_address(sgl);
1797 scb->sgl64[idx].length = sg_dma_len(sgl);
1800 scb->sgl[idx].address = sg_dma_address(sgl);
1801 scb->sgl[idx].length = sg_dma_len(sgl);
1805 /* Reset pointer and length fields */
1806 *buf = scb->sgl_dma_addr;
1809 * For passthru command, dataxferlen must be set, even for commands
1812 *len = (u32)cmd->request_bufflen;
1814 /* Return count of SG requests */
1822 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1823 * Enquiry3 structures for later use
1826 mega_8_to_40ld(mraid_inquiry *inquiry, mega_inquiry3 *enquiry3,
1827 mega_product_info *product_info)
1831 product_info->max_commands = inquiry->adapter_info.max_commands;
1832 enquiry3->rebuild_rate = inquiry->adapter_info.rebuild_rate;
1833 product_info->nchannels = inquiry->adapter_info.nchannels;
1835 for (i = 0; i < 4; i++) {
1836 product_info->fw_version[i] =
1837 inquiry->adapter_info.fw_version[i];
1839 product_info->bios_version[i] =
1840 inquiry->adapter_info.bios_version[i];
1842 enquiry3->cache_flush_interval =
1843 inquiry->adapter_info.cache_flush_interval;
1845 product_info->dram_size = inquiry->adapter_info.dram_size;
1847 enquiry3->num_ldrv = inquiry->logdrv_info.num_ldrv;
1849 for (i = 0; i < MAX_LOGICAL_DRIVES_8LD; i++) {
1850 enquiry3->ldrv_size[i] = inquiry->logdrv_info.ldrv_size[i];
1851 enquiry3->ldrv_prop[i] = inquiry->logdrv_info.ldrv_prop[i];
1852 enquiry3->ldrv_state[i] = inquiry->logdrv_info.ldrv_state[i];
1855 for (i = 0; i < (MAX_PHYSICAL_DRIVES); i++)
1856 enquiry3->pdrv_state[i] = inquiry->pdrv_info.pdrv_state[i];
1860 mega_free_sgl(adapter_t *adapter)
1865 for(i = 0; i < adapter->max_cmds; i++) {
1867 scb = &adapter->scb_list[i];
1870 pci_free_consistent(adapter->dev,
1871 sizeof(mega_sgl64) * adapter->sglen,
1879 pci_free_consistent(adapter->dev, sizeof(mega_passthru),
1880 scb->pthru, scb->pthru_dma_addr);
1886 pci_free_consistent(adapter->dev,
1887 sizeof(mega_ext_passthru),
1888 scb->epthru, scb->epthru_dma_addr);
1898 * Get information about the card/driver
1901 megaraid_info(struct Scsi_Host *host)
1903 static char buffer[512];
1906 adapter = (adapter_t *)host->hostdata;
1909 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1910 adapter->fw_version, adapter->product_info.max_commands,
1911 adapter->host->max_id, adapter->host->max_channel,
1912 adapter->host->max_lun);
1917 * Abort a previous SCSI request. Only commands on the pending list can be
1918 * aborted. All the commands issued to the F/W must complete.
1921 megaraid_abort(Scsi_Cmnd *cmd)
1926 adapter = (adapter_t *)cmd->device->host->hostdata;
1928 rval = megaraid_abort_and_reset(adapter, cmd, SCB_ABORT);
1931 * This is required here to complete any completed requests
1932 * to be communicated over to the mid layer.
1934 mega_rundoneq(adapter);
1941 megaraid_reset(struct scsi_cmnd *cmd)
1947 adapter = (adapter_t *)cmd->device->host->hostdata;
1949 #if MEGA_HAVE_CLUSTERING
1950 mc.cmd = MEGA_CLUSTER_CMD;
1951 mc.opcode = MEGA_RESET_RESERVATIONS;
1953 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
1955 "megaraid: reservation reset failed.\n");
1958 printk(KERN_INFO "megaraid: reservation reset.\n");
1962 spin_lock_irq(&adapter->lock);
1964 rval = megaraid_abort_and_reset(adapter, cmd, SCB_RESET);
1967 * This is required here to complete any completed requests
1968 * to be communicated over to the mid layer.
1970 mega_rundoneq(adapter);
1971 spin_unlock_irq(&adapter->lock);
1977 * megaraid_abort_and_reset()
1978 * @adapter - megaraid soft state
1979 * @cmd - scsi command to be aborted or reset
1980 * @aor - abort or reset flag
1982 * Try to locate the scsi command in the pending queue. If found and is not
1983 * issued to the controller, abort/reset it. Otherwise return failure
1986 megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1988 struct list_head *pos, *next;
1991 printk(KERN_WARNING "megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
1992 (aor == SCB_ABORT)? "ABORTING":"RESET", cmd->serial_number,
1993 cmd->cmnd[0], cmd->device->channel,
1994 cmd->device->id, cmd->device->lun);
1996 if(list_empty(&adapter->pending_list))
1999 list_for_each_safe(pos, next, &adapter->pending_list) {
2001 scb = list_entry(pos, scb_t, list);
2003 if (scb->cmd == cmd) { /* Found command */
2008 * Check if this command has firmare owenership. If
2009 * yes, we cannot reset this command. Whenever, f/w
2010 * completes this command, we will return appropriate
2013 if( scb->state & SCB_ISSUED ) {
2016 "megaraid: %s-%lx[%x], fw owner.\n",
2017 (aor==SCB_ABORT) ? "ABORTING":"RESET",
2018 cmd->serial_number, scb->idx);
2025 * Not yet issued! Remove from the pending
2029 "megaraid: %s-%lx[%x], driver owner.\n",
2030 (aor==SCB_ABORT) ? "ABORTING":"RESET",
2031 cmd->serial_number, scb->idx);
2033 mega_free_scb(adapter, scb);
2035 if( aor == SCB_ABORT ) {
2036 cmd->result = (DID_ABORT << 16);
2039 cmd->result = (DID_RESET << 16);
2042 list_add_tail(SCSI_LIST(cmd),
2043 &adapter->completed_list);
2054 make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
2056 *pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
2058 if( *pdev == NULL ) return -1;
2060 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
2062 if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) {
2071 free_local_pdev(struct pci_dev *pdev)
2077 * mega_allocate_inquiry()
2078 * @dma_handle - handle returned for dma address
2079 * @pdev - handle to pci device
2081 * allocates memory for inquiry structure
2083 static inline void *
2084 mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev)
2086 return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle);
2091 mega_free_inquiry(void *inquiry, dma_addr_t dma_handle, struct pci_dev *pdev)
2093 pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle);
2097 #ifdef CONFIG_PROC_FS
2098 /* Following code handles /proc fs */
2100 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2101 S_IRUSR | S_IFREG, \
2102 controller_proc_dir_entry, \
2106 * mega_create_proc_entry()
2107 * @index - index in soft state array
2108 * @parent - parent node for this /proc entry
2110 * Creates /proc entries for our controllers.
2113 mega_create_proc_entry(int index, struct proc_dir_entry *parent)
2115 struct proc_dir_entry *controller_proc_dir_entry = NULL;
2116 u8 string[64] = { 0 };
2117 adapter_t *adapter = hba_soft_state[index];
2119 sprintf(string, "hba%d", adapter->host->host_no);
2121 controller_proc_dir_entry =
2122 adapter->controller_proc_dir_entry = proc_mkdir(string, parent);
2124 if(!controller_proc_dir_entry) {
2125 printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
2128 adapter->proc_read = CREATE_READ_PROC("config", proc_read_config);
2129 adapter->proc_stat = CREATE_READ_PROC("stat", proc_read_stat);
2130 adapter->proc_mbox = CREATE_READ_PROC("mailbox", proc_read_mbox);
2131 #if MEGA_HAVE_ENH_PROC
2132 adapter->proc_rr = CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate);
2133 adapter->proc_battery = CREATE_READ_PROC("battery-status",
2137 * Display each physical drive on its channel
2139 adapter->proc_pdrvstat[0] = CREATE_READ_PROC("diskdrives-ch0",
2141 adapter->proc_pdrvstat[1] = CREATE_READ_PROC("diskdrives-ch1",
2143 adapter->proc_pdrvstat[2] = CREATE_READ_PROC("diskdrives-ch2",
2145 adapter->proc_pdrvstat[3] = CREATE_READ_PROC("diskdrives-ch3",
2149 * Display a set of up to 10 logical drive through each of following
2152 adapter->proc_rdrvstat[0] = CREATE_READ_PROC("raiddrives-0-9",
2154 adapter->proc_rdrvstat[1] = CREATE_READ_PROC("raiddrives-10-19",
2156 adapter->proc_rdrvstat[2] = CREATE_READ_PROC("raiddrives-20-29",
2158 adapter->proc_rdrvstat[3] = CREATE_READ_PROC("raiddrives-30-39",
2165 * proc_read_config()
2166 * @page - buffer to write the data in
2167 * @start - where the actual data has been written in page
2168 * @offset - same meaning as the read system call
2169 * @count - same meaning as the read system call
2170 * @eof - set if no more data needs to be returned
2171 * @data - pointer to our soft state
2173 * Display configuration information about the controller.
2176 proc_read_config(char *page, char **start, off_t offset, int count, int *eof,
2180 adapter_t *adapter = (adapter_t *)data;
2183 len += sprintf(page+len, "%s", MEGARAID_VERSION);
2185 if(adapter->product_info.product_name[0])
2186 len += sprintf(page+len, "%s\n",
2187 adapter->product_info.product_name);
2189 len += sprintf(page+len, "Controller Type: ");
2191 if( adapter->flag & BOARD_MEMMAP ) {
2192 len += sprintf(page+len,
2193 "438/466/467/471/493/518/520/531/532\n");
2196 len += sprintf(page+len,
2200 if(adapter->flag & BOARD_40LD) {
2201 len += sprintf(page+len,
2202 "Controller Supports 40 Logical Drives\n");
2205 if(adapter->flag & BOARD_64BIT) {
2206 len += sprintf(page+len,
2207 "Controller capable of 64-bit memory addressing\n");
2209 if( adapter->has_64bit_addr ) {
2210 len += sprintf(page+len,
2211 "Controller using 64-bit memory addressing\n");
2214 len += sprintf(page+len,
2215 "Controller is not using 64-bit memory addressing\n");
2218 len += sprintf(page+len, "Base = %08lx, Irq = %d, ", adapter->base,
2219 adapter->host->irq);
2221 len += sprintf(page+len, "Logical Drives = %d, Channels = %d\n",
2222 adapter->numldrv, adapter->product_info.nchannels);
2224 len += sprintf(page+len, "Version =%s:%s, DRAM = %dMb\n",
2225 adapter->fw_version, adapter->bios_version,
2226 adapter->product_info.dram_size);
2228 len += sprintf(page+len,
2229 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2230 adapter->product_info.max_commands, adapter->max_cmds);
2232 len += sprintf(page+len, "support_ext_cdb = %d\n",
2233 adapter->support_ext_cdb);
2234 len += sprintf(page+len, "support_random_del = %d\n",
2235 adapter->support_random_del);
2236 len += sprintf(page+len, "boot_ldrv_enabled = %d\n",
2237 adapter->boot_ldrv_enabled);
2238 len += sprintf(page+len, "boot_ldrv = %d\n",
2239 adapter->boot_ldrv);
2240 len += sprintf(page+len, "boot_pdrv_enabled = %d\n",
2241 adapter->boot_pdrv_enabled);
2242 len += sprintf(page+len, "boot_pdrv_ch = %d\n",
2243 adapter->boot_pdrv_ch);
2244 len += sprintf(page+len, "boot_pdrv_tgt = %d\n",
2245 adapter->boot_pdrv_tgt);
2246 len += sprintf(page+len, "quiescent = %d\n",
2247 atomic_read(&adapter->quiescent));
2248 len += sprintf(page+len, "has_cluster = %d\n",
2249 adapter->has_cluster);
2251 len += sprintf(page+len, "\nModule Parameters:\n");
2252 len += sprintf(page+len, "max_cmd_per_lun = %d\n",
2254 len += sprintf(page+len, "max_sectors_per_io = %d\n",
2255 max_sectors_per_io);
2266 * @page - buffer to write the data in
2267 * @start - where the actual data has been written in page
2268 * @offset - same meaning as the read system call
2269 * @count - same meaning as the read system call
2270 * @eof - set if no more data needs to be returned
2271 * @data - pointer to our soft state
2273 * Diaplay statistical information about the I/O activity.
2276 proc_read_stat(char *page, char **start, off_t offset, int count, int *eof,
2283 i = 0; /* avoid compilation warnings */
2285 adapter = (adapter_t *)data;
2287 len = sprintf(page, "Statistical Information for this controller\n");
2288 len += sprintf(page+len, "pend_cmds = %d\n",
2289 atomic_read(&adapter->pend_cmds));
2291 for(i = 0; i < adapter->numldrv; i++) {
2292 len += sprintf(page+len, "Logical Drive %d:\n", i);
2294 len += sprintf(page+len,
2295 "\tReads Issued = %lu, Writes Issued = %lu\n",
2296 adapter->nreads[i], adapter->nwrites[i]);
2298 len += sprintf(page+len,
2299 "\tSectors Read = %lu, Sectors Written = %lu\n",
2300 adapter->nreadblocks[i], adapter->nwriteblocks[i]);
2302 len += sprintf(page+len,
2303 "\tRead errors = %lu, Write errors = %lu\n\n",
2304 adapter->rd_errors[i], adapter->wr_errors[i]);
2307 len += sprintf(page+len,
2308 "IO and error counters not compiled in driver.\n");
2319 * @page - buffer to write the data in
2320 * @start - where the actual data has been written in page
2321 * @offset - same meaning as the read system call
2322 * @count - same meaning as the read system call
2323 * @eof - set if no more data needs to be returned
2324 * @data - pointer to our soft state
2326 * Display mailbox information for the last command issued. This information
2327 * is good for debugging.
2330 proc_read_mbox(char *page, char **start, off_t offset, int count, int *eof,
2334 adapter_t *adapter = (adapter_t *)data;
2335 volatile mbox_t *mbox = adapter->mbox;
2338 len = sprintf(page, "Contents of Mail Box Structure\n");
2339 len += sprintf(page+len, " Fw Command = 0x%02x\n",
2341 len += sprintf(page+len, " Cmd Sequence = 0x%02x\n",
2343 len += sprintf(page+len, " No of Sectors= %04d\n",
2344 mbox->m_out.numsectors);
2345 len += sprintf(page+len, " LBA = 0x%02x\n",
2347 len += sprintf(page+len, " DTA = 0x%08x\n",
2348 mbox->m_out.xferaddr);
2349 len += sprintf(page+len, " Logical Drive= 0x%02x\n",
2350 mbox->m_out.logdrv);
2351 len += sprintf(page+len, " No of SG Elmt= 0x%02x\n",
2352 mbox->m_out.numsgelements);
2353 len += sprintf(page+len, " Busy = %01x\n",
2355 len += sprintf(page+len, " Status = 0x%02x\n",
2365 * proc_rebuild_rate()
2366 * @page - buffer to write the data in
2367 * @start - where the actual data has been written in page
2368 * @offset - same meaning as the read system call
2369 * @count - same meaning as the read system call
2370 * @eof - set if no more data needs to be returned
2371 * @data - pointer to our soft state
2373 * Display current rebuild rate
2376 proc_rebuild_rate(char *page, char **start, off_t offset, int count, int *eof,
2379 adapter_t *adapter = (adapter_t *)data;
2380 dma_addr_t dma_handle;
2382 struct pci_dev *pdev;
2385 if( make_local_pdev(adapter, &pdev) != 0 ) {
2390 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2391 free_local_pdev(pdev);
2396 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2398 len = sprintf(page, "Adapter inquiry failed.\n");
2400 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2402 mega_free_inquiry(inquiry, dma_handle, pdev);
2404 free_local_pdev(pdev);
2411 if( adapter->flag & BOARD_40LD ) {
2412 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2413 ((mega_inquiry3 *)inquiry)->rebuild_rate);
2416 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2417 ((mraid_ext_inquiry *)
2418 inquiry)->raid_inq.adapter_info.rebuild_rate);
2422 mega_free_inquiry(inquiry, dma_handle, pdev);
2424 free_local_pdev(pdev);
2434 * @page - buffer to write the data in
2435 * @start - where the actual data has been written in page
2436 * @offset - same meaning as the read system call
2437 * @count - same meaning as the read system call
2438 * @eof - set if no more data needs to be returned
2439 * @data - pointer to our soft state
2441 * Display information about the battery module on the controller.
2444 proc_battery(char *page, char **start, off_t offset, int count, int *eof,
2447 adapter_t *adapter = (adapter_t *)data;
2448 dma_addr_t dma_handle;
2450 struct pci_dev *pdev;
2451 u8 battery_status = 0;
2455 if( make_local_pdev(adapter, &pdev) != 0 ) {
2460 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2461 free_local_pdev(pdev);
2466 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2468 len = sprintf(page, "Adapter inquiry failed.\n");
2470 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2472 mega_free_inquiry(inquiry, dma_handle, pdev);
2474 free_local_pdev(pdev);
2481 if( adapter->flag & BOARD_40LD ) {
2482 battery_status = ((mega_inquiry3 *)inquiry)->battery_status;
2485 battery_status = ((mraid_ext_inquiry *)inquiry)->
2486 raid_inq.adapter_info.battery_status;
2490 * Decode the battery status
2492 sprintf(str, "Battery Status:[%d]", battery_status);
2494 if(battery_status == MEGA_BATT_CHARGE_DONE)
2495 strcat(str, " Charge Done");
2497 if(battery_status & MEGA_BATT_MODULE_MISSING)
2498 strcat(str, " Module Missing");
2500 if(battery_status & MEGA_BATT_LOW_VOLTAGE)
2501 strcat(str, " Low Voltage");
2503 if(battery_status & MEGA_BATT_TEMP_HIGH)
2504 strcat(str, " Temperature High");
2506 if(battery_status & MEGA_BATT_PACK_MISSING)
2507 strcat(str, " Pack Missing");
2509 if(battery_status & MEGA_BATT_CHARGE_INPROG)
2510 strcat(str, " Charge In-progress");
2512 if(battery_status & MEGA_BATT_CHARGE_FAIL)
2513 strcat(str, " Charge Fail");
2515 if(battery_status & MEGA_BATT_CYCLES_EXCEEDED)
2516 strcat(str, " Cycles Exceeded");
2518 len = sprintf(page, "%s\n", str);
2521 mega_free_inquiry(inquiry, dma_handle, pdev);
2523 free_local_pdev(pdev);
2533 * @page - buffer to write the data in
2534 * @start - where the actual data has been written in page
2535 * @offset - same meaning as the read system call
2536 * @count - same meaning as the read system call
2537 * @eof - set if no more data needs to be returned
2538 * @data - pointer to our soft state
2540 * Display information about the physical drives on physical channel 0.
2543 proc_pdrv_ch0(char *page, char **start, off_t offset, int count, int *eof,
2546 adapter_t *adapter = (adapter_t *)data;
2550 return (proc_pdrv(adapter, page, 0));
2556 * @page - buffer to write the data in
2557 * @start - where the actual data has been written in page
2558 * @offset - same meaning as the read system call
2559 * @count - same meaning as the read system call
2560 * @eof - set if no more data needs to be returned
2561 * @data - pointer to our soft state
2563 * Display information about the physical drives on physical channel 1.
2566 proc_pdrv_ch1(char *page, char **start, off_t offset, int count, int *eof,
2569 adapter_t *adapter = (adapter_t *)data;
2573 return (proc_pdrv(adapter, page, 1));
2579 * @page - buffer to write the data in
2580 * @start - where the actual data has been written in page
2581 * @offset - same meaning as the read system call
2582 * @count - same meaning as the read system call
2583 * @eof - set if no more data needs to be returned
2584 * @data - pointer to our soft state
2586 * Display information about the physical drives on physical channel 2.
2589 proc_pdrv_ch2(char *page, char **start, off_t offset, int count, int *eof,
2592 adapter_t *adapter = (adapter_t *)data;
2596 return (proc_pdrv(adapter, page, 2));
2602 * @page - buffer to write the data in
2603 * @start - where the actual data has been written in page
2604 * @offset - same meaning as the read system call
2605 * @count - same meaning as the read system call
2606 * @eof - set if no more data needs to be returned
2607 * @data - pointer to our soft state
2609 * Display information about the physical drives on physical channel 3.
2612 proc_pdrv_ch3(char *page, char **start, off_t offset, int count, int *eof,
2615 adapter_t *adapter = (adapter_t *)data;
2619 return (proc_pdrv(adapter, page, 3));
2625 * @page - buffer to write the data in
2626 * @adapter - pointer to our soft state
2628 * Display information about the physical drives.
2631 proc_pdrv(adapter_t *adapter, char *page, int channel)
2633 dma_addr_t dma_handle;
2635 dma_addr_t scsi_inq_dma_handle;
2637 struct pci_dev *pdev;
2646 if( make_local_pdev(adapter, &pdev) != 0 ) {
2650 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2654 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2655 len = sprintf(page, "Adapter inquiry failed.\n");
2657 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2663 scsi_inq = pci_alloc_consistent(pdev, 256, &scsi_inq_dma_handle);
2665 if( scsi_inq == NULL ) {
2666 len = sprintf(page, "memory not available for scsi inq.\n");
2671 if( adapter->flag & BOARD_40LD ) {
2672 pdrv_state = ((mega_inquiry3 *)inquiry)->pdrv_state;
2675 pdrv_state = ((mraid_ext_inquiry *)inquiry)->
2676 raid_inq.pdrv_info.pdrv_state;
2679 max_channels = adapter->product_info.nchannels;
2681 if( channel >= max_channels ) {
2685 for( tgt = 0; tgt <= MAX_TARGET; tgt++ ) {
2687 i = channel*16 + tgt;
2689 state = *(pdrv_state + i);
2691 switch( state & 0x0F ) {
2695 "Channel:%2d Id:%2d State: Online",
2701 "Channel:%2d Id:%2d State: Failed",
2707 "Channel:%2d Id:%2d State: Rebuild",
2713 "Channel:%2d Id:%2d State: Hot spare",
2719 "Channel:%2d Id:%2d State: Un-configured",
2726 * This interface displays inquiries for disk drives
2727 * only. Inquries for logical drives and non-disk
2728 * devices are available through /proc/scsi/scsi
2730 memset(scsi_inq, 0, 256);
2731 if( mega_internal_dev_inquiry(adapter, channel, tgt,
2732 scsi_inq_dma_handle) ||
2733 (scsi_inq[0] & 0x1F) != TYPE_DISK ) {
2738 * Check for overflow. We print less than 240
2739 * characters for inquiry
2741 if( (len + 240) >= PAGE_SIZE ) break;
2743 len += sprintf(page+len, "%s.\n", str);
2745 len += mega_print_inquiry(page+len, scsi_inq);
2749 pci_free_consistent(pdev, 256, scsi_inq, scsi_inq_dma_handle);
2751 mega_free_inquiry(inquiry, dma_handle, pdev);
2753 free_local_pdev(pdev);
2760 * Display scsi inquiry
2763 mega_print_inquiry(char *page, char *scsi_inq)
2768 len = sprintf(page, " Vendor: ");
2769 for( i = 8; i < 16; i++ ) {
2770 len += sprintf(page+len, "%c", scsi_inq[i]);
2773 len += sprintf(page+len, " Model: ");
2775 for( i = 16; i < 32; i++ ) {
2776 len += sprintf(page+len, "%c", scsi_inq[i]);
2779 len += sprintf(page+len, " Rev: ");
2781 for( i = 32; i < 36; i++ ) {
2782 len += sprintf(page+len, "%c", scsi_inq[i]);
2785 len += sprintf(page+len, "\n");
2787 i = scsi_inq[0] & 0x1f;
2789 len += sprintf(page+len, " Type: %s ",
2790 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] :
2793 len += sprintf(page+len,
2794 " ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
2796 if( (scsi_inq[2] & 0x07) == 1 && (scsi_inq[3] & 0x0f) == 1 )
2797 len += sprintf(page+len, " CCS\n");
2799 len += sprintf(page+len, "\n");
2807 * @page - buffer to write the data in
2808 * @start - where the actual data has been written in page
2809 * @offset - same meaning as the read system call
2810 * @count - same meaning as the read system call
2811 * @eof - set if no more data needs to be returned
2812 * @data - pointer to our soft state
2814 * Display real time information about the logical drives 0 through 9.
2817 proc_rdrv_10(char *page, char **start, off_t offset, int count, int *eof,
2820 adapter_t *adapter = (adapter_t *)data;
2824 return (proc_rdrv(adapter, page, 0, 9));
2830 * @page - buffer to write the data in
2831 * @start - where the actual data has been written in page
2832 * @offset - same meaning as the read system call
2833 * @count - same meaning as the read system call
2834 * @eof - set if no more data needs to be returned
2835 * @data - pointer to our soft state
2837 * Display real time information about the logical drives 0 through 9.
2840 proc_rdrv_20(char *page, char **start, off_t offset, int count, int *eof,
2843 adapter_t *adapter = (adapter_t *)data;
2847 return (proc_rdrv(adapter, page, 10, 19));
2853 * @page - buffer to write the data in
2854 * @start - where the actual data has been written in page
2855 * @offset - same meaning as the read system call
2856 * @count - same meaning as the read system call
2857 * @eof - set if no more data needs to be returned
2858 * @data - pointer to our soft state
2860 * Display real time information about the logical drives 0 through 9.
2863 proc_rdrv_30(char *page, char **start, off_t offset, int count, int *eof,
2866 adapter_t *adapter = (adapter_t *)data;
2870 return (proc_rdrv(adapter, page, 20, 29));
2876 * @page - buffer to write the data in
2877 * @start - where the actual data has been written in page
2878 * @offset - same meaning as the read system call
2879 * @count - same meaning as the read system call
2880 * @eof - set if no more data needs to be returned
2881 * @data - pointer to our soft state
2883 * Display real time information about the logical drives 0 through 9.
2886 proc_rdrv_40(char *page, char **start, off_t offset, int count, int *eof,
2889 adapter_t *adapter = (adapter_t *)data;
2893 return (proc_rdrv(adapter, page, 30, 39));
2899 * @page - buffer to write the data in
2900 * @adapter - pointer to our soft state
2901 * @start - starting logical drive to display
2902 * @end - ending logical drive to display
2904 * We do not print the inquiry information since its already available through
2905 * /proc/scsi/scsi interface
2908 proc_rdrv(adapter_t *adapter, char *page, int start, int end )
2910 dma_addr_t dma_handle;
2911 logdrv_param *lparam;
2914 dma_addr_t disk_array_dma_handle;
2916 struct pci_dev *pdev;
2923 if( make_local_pdev(adapter, &pdev) != 0 ) {
2927 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2928 free_local_pdev(pdev);
2932 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2934 len = sprintf(page, "Adapter inquiry failed.\n");
2936 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2938 mega_free_inquiry(inquiry, dma_handle, pdev);
2940 free_local_pdev(pdev);
2945 memset(&mc, 0, sizeof(megacmd_t));
2947 if( adapter->flag & BOARD_40LD ) {
2948 array_sz = sizeof(disk_array_40ld);
2950 rdrv_state = ((mega_inquiry3 *)inquiry)->ldrv_state;
2952 num_ldrv = ((mega_inquiry3 *)inquiry)->num_ldrv;
2955 array_sz = sizeof(disk_array_8ld);
2957 rdrv_state = ((mraid_ext_inquiry *)inquiry)->
2958 raid_inq.logdrv_info.ldrv_state;
2960 num_ldrv = ((mraid_ext_inquiry *)inquiry)->
2961 raid_inq.logdrv_info.num_ldrv;
2964 disk_array = pci_alloc_consistent(pdev, array_sz,
2965 &disk_array_dma_handle);
2967 if( disk_array == NULL ) {
2968 len = sprintf(page, "memory not available.\n");
2970 mega_free_inquiry(inquiry, dma_handle, pdev);
2972 free_local_pdev(pdev);
2977 mc.xferaddr = (u32)disk_array_dma_handle;
2979 if( adapter->flag & BOARD_40LD ) {
2980 mc.cmd = FC_NEW_CONFIG;
2981 mc.opcode = OP_DCMD_READ_CONFIG;
2983 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
2985 len = sprintf(page, "40LD read config failed.\n");
2987 mega_free_inquiry(inquiry, dma_handle, pdev);
2989 pci_free_consistent(pdev, array_sz, disk_array,
2990 disk_array_dma_handle);
2992 free_local_pdev(pdev);
2999 mc.cmd = NEW_READ_CONFIG_8LD;
3001 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
3003 mc.cmd = READ_CONFIG_8LD;
3005 if( mega_internal_command(adapter, LOCK_INT, &mc,
3009 "8LD read config failed.\n");
3011 mega_free_inquiry(inquiry, dma_handle, pdev);
3013 pci_free_consistent(pdev, array_sz,
3015 disk_array_dma_handle);
3017 free_local_pdev(pdev);
3024 for( i = start; i < ( (end+1 < num_ldrv) ? end+1 : num_ldrv ); i++ ) {
3026 if( adapter->flag & BOARD_40LD ) {
3028 &((disk_array_40ld *)disk_array)->ldrv[i].lparam;
3032 &((disk_array_8ld *)disk_array)->ldrv[i].lparam;
3036 * Check for overflow. We print less than 240 characters for
3037 * information about each logical drive.
3039 if( (len + 240) >= PAGE_SIZE ) break;
3041 len += sprintf(page+len, "Logical drive:%2d:, ", i);
3043 switch( rdrv_state[i] & 0x0F ) {
3045 len += sprintf(page+len, "state: offline");
3049 len += sprintf(page+len, "state: degraded");
3053 len += sprintf(page+len, "state: optimal");
3057 len += sprintf(page+len, "state: deleted");
3061 len += sprintf(page+len, "state: unknown");
3066 * Check if check consistency or initialization is going on
3067 * for this logical drive.
3069 if( (rdrv_state[i] & 0xF0) == 0x20 ) {
3070 len += sprintf(page+len,
3071 ", check-consistency in progress");
3073 else if( (rdrv_state[i] & 0xF0) == 0x10 ) {
3074 len += sprintf(page+len,
3075 ", initialization in progress");
3078 len += sprintf(page+len, "\n");
3080 len += sprintf(page+len, "Span depth:%3d, ",
3081 lparam->span_depth);
3083 len += sprintf(page+len, "RAID level:%3d, ",
3086 len += sprintf(page+len, "Stripe size:%3d, ",
3087 lparam->stripe_sz ? lparam->stripe_sz/2: 128);
3089 len += sprintf(page+len, "Row size:%3d\n",
3093 len += sprintf(page+len, "Read Policy: ");
3095 switch(lparam->read_ahead) {
3098 len += sprintf(page+len, "No read ahead, ");
3102 len += sprintf(page+len, "Read ahead, ");
3105 case ADAP_READ_AHEAD:
3106 len += sprintf(page+len, "Adaptive, ");
3111 len += sprintf(page+len, "Write Policy: ");
3113 switch(lparam->write_mode) {
3115 case WRMODE_WRITE_THRU:
3116 len += sprintf(page+len, "Write thru, ");
3119 case WRMODE_WRITE_BACK:
3120 len += sprintf(page+len, "Write back, ");
3124 len += sprintf(page+len, "Cache Policy: ");
3126 switch(lparam->direct_io) {
3129 len += sprintf(page+len, "Cached IO\n\n");
3133 len += sprintf(page+len, "Direct IO\n\n");
3138 mega_free_inquiry(inquiry, dma_handle, pdev);
3140 pci_free_consistent(pdev, array_sz, disk_array,
3141 disk_array_dma_handle);
3143 free_local_pdev(pdev);
3152 * megaraid_biosparam()
3154 * Return the disk geometry for a particular disk
3157 megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
3158 sector_t capacity, int geom[])
3167 /* Get pointer to host config structure */
3168 adapter = (adapter_t *)sdev->host->hostdata;
3170 if (IS_RAID_CH(adapter, sdev->channel)) {
3171 /* Default heads (64) & sectors (32) */
3174 cylinders = (ulong)capacity / (heads * sectors);
3177 * Handle extended translation size for logical drives
3180 if ((ulong)capacity >= 0x200000) {
3183 cylinders = (ulong)capacity / (heads * sectors);
3189 geom[2] = cylinders;
3192 bh = scsi_bios_ptable(bdev);
3195 rval = scsi_partsize(bh, capacity,
3196 &geom[2], &geom[0], &geom[1]);
3203 "megaraid: invalid partition on this disk on channel %d\n",
3206 /* Default heads (64) & sectors (32) */
3209 cylinders = (ulong)capacity / (heads * sectors);
3211 /* Handle extended translation size for logical drives > 1Gb */
3212 if ((ulong)capacity >= 0x200000) {
3215 cylinders = (ulong)capacity / (heads * sectors);
3221 geom[2] = cylinders;
3229 * @adapter - pointer to our soft state
3231 * Allocate memory for the various pointers in the scb structures:
3232 * scatter-gather list pointer, passthru and extended passthru structure
3236 mega_init_scb(adapter_t *adapter)
3241 for( i = 0; i < adapter->max_cmds; i++ ) {
3243 scb = &adapter->scb_list[i];
3251 for( i = 0; i < adapter->max_cmds; i++ ) {
3253 scb = &adapter->scb_list[i];
3257 scb->sgl64 = pci_alloc_consistent(adapter->dev,
3258 sizeof(mega_sgl64) * adapter->sglen,
3259 &scb->sgl_dma_addr);
3261 scb->sgl = (mega_sglist *)scb->sgl64;
3264 printk(KERN_WARNING "RAID: Can't allocate sglist.\n");
3265 mega_free_sgl(adapter);
3269 scb->pthru = pci_alloc_consistent(adapter->dev,
3270 sizeof(mega_passthru),
3271 &scb->pthru_dma_addr);
3274 printk(KERN_WARNING "RAID: Can't allocate passthru.\n");
3275 mega_free_sgl(adapter);
3279 scb->epthru = pci_alloc_consistent(adapter->dev,
3280 sizeof(mega_ext_passthru),
3281 &scb->epthru_dma_addr);
3283 if( !scb->epthru ) {
3285 "Can't allocate extended passthru.\n");
3286 mega_free_sgl(adapter);
3291 scb->dma_type = MEGA_DMA_TYPE_NONE;
3295 * lock not required since we are loading the driver, so no
3296 * commands possible right now.
3298 scb->state = SCB_FREE;
3300 list_add(&scb->list, &adapter->free_list);
3312 * Routines for the character/ioctl interface to the driver. Find out if this
3313 * is a valid open. If yes, increment the module use count so that it cannot
3317 megadev_open (struct inode *inode, struct file *filep)
3320 * Only allow superuser to access private ioctl interface
3322 if( !capable(CAP_SYS_ADMIN) ) return -EACCES;
3330 * @inode - Our device inode
3332 * @cmd - ioctl command
3333 * @arg - user buffer
3335 * ioctl entry point for our private ioctl interface. We move the data in from
3336 * the user space, prepare the command (if necessary, convert the old MIMD
3337 * ioctl to new ioctl command), and issue a synchronous command to the
3341 megadev_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
3348 mega_passthru __user *upthru; /* user address for passthru */
3349 mega_passthru *pthru; /* copy user passthru here */
3350 dma_addr_t pthru_dma_hndl;
3351 void *data = NULL; /* data to be transferred */
3352 dma_addr_t data_dma_hndl; /* dma handle for data xfer area */
3354 megastat_t __user *ustats;
3357 struct pci_dev *pdev;
3359 ustats = NULL; /* avoid compilation warnings */
3363 * Make sure only USCSICMD are issued through this interface.
3364 * MIMD application would still fire different command.
3366 if( (_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD) ) {
3371 * Check and convert a possible MIMD command to NIT command.
3372 * mega_m_to_n() copies the data from the user space, so we do not
3373 * have to do it here.
3374 * NOTE: We will need some user address to copyout the data, therefore
3375 * the inteface layer will also provide us with the required user
3378 memset(&uioc, 0, sizeof(nitioctl_t));
3379 if( (rval = mega_m_to_n( (void __user *)arg, &uioc)) != 0 )
3383 switch( uioc.opcode ) {
3385 case GET_DRIVER_VER:
3386 if( put_user(driver_ver, (u32 __user *)uioc.uioc_uaddr) )
3392 if( put_user(hba_count, (u32 __user *)uioc.uioc_uaddr) )
3396 * Shucks. MIMD interface returns a positive value for number
3397 * of adapters. TODO: Change it to return 0 when there is no
3398 * applicatio using mimd interface.
3407 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3410 if( copy_to_user(uioc.uioc_uaddr, mcontroller+adapno,
3411 sizeof(struct mcontroller)) )
3421 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3424 adapter = hba_soft_state[adapno];
3426 ustats = uioc.uioc_uaddr;
3428 if( copy_from_user(&num_ldrv, &ustats->num_ldrv, sizeof(int)) )
3432 * Check for the validity of the logical drive number
3434 if( num_ldrv >= MAX_LOGICAL_DRIVES_40LD ) return -EINVAL;
3436 if( copy_to_user(ustats->nreads, adapter->nreads,
3437 num_ldrv*sizeof(u32)) )
3440 if( copy_to_user(ustats->nreadblocks, adapter->nreadblocks,
3441 num_ldrv*sizeof(u32)) )
3444 if( copy_to_user(ustats->nwrites, adapter->nwrites,
3445 num_ldrv*sizeof(u32)) )
3448 if( copy_to_user(ustats->nwriteblocks, adapter->nwriteblocks,
3449 num_ldrv*sizeof(u32)) )
3452 if( copy_to_user(ustats->rd_errors, adapter->rd_errors,
3453 num_ldrv*sizeof(u32)) )
3456 if( copy_to_user(ustats->wr_errors, adapter->wr_errors,
3457 num_ldrv*sizeof(u32)) )
3468 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3471 adapter = hba_soft_state[adapno];
3474 * Deletion of logical drive is a special case. The adapter
3475 * should be quiescent before this command is issued.
3477 if( uioc.uioc_rmbox[0] == FC_DEL_LOGDRV &&
3478 uioc.uioc_rmbox[2] == OP_DEL_LOGDRV ) {
3481 * Do we support this feature
3483 if( !adapter->support_random_del ) {
3484 printk(KERN_WARNING "megaraid: logdrv ");
3485 printk("delete on non-supporting F/W.\n");
3490 rval = mega_del_logdrv( adapter, uioc.uioc_rmbox[3] );
3493 memset(&mc, 0, sizeof(megacmd_t));
3497 rval = mega_n_to_m((void __user *)arg, &mc);
3503 * This interface only support the regular passthru commands.
3504 * Reject extended passthru and 64-bit passthru
3506 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU64 ||
3507 uioc.uioc_rmbox[0] == MEGA_MBOXCMD_EXTPTHRU ) {
3509 printk(KERN_WARNING "megaraid: rejected passthru.\n");
3515 * For all internal commands, the buffer must be allocated in
3516 * <4GB address range
3518 if( make_local_pdev(adapter, &pdev) != 0 )
3521 /* Is it a passthru command or a DCMD */
3522 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
3523 /* Passthru commands */
3525 pthru = pci_alloc_consistent(pdev,
3526 sizeof(mega_passthru),
3529 if( pthru == NULL ) {
3530 free_local_pdev(pdev);
3535 * The user passthru structure
3537 upthru = (mega_passthru __user *)MBOX(uioc)->xferaddr;
3540 * Copy in the user passthru here.
3542 if( copy_from_user(pthru, upthru,
3543 sizeof(mega_passthru)) ) {
3545 pci_free_consistent(pdev,
3546 sizeof(mega_passthru), pthru,
3549 free_local_pdev(pdev);
3555 * Is there a data transfer
3557 if( pthru->dataxferlen ) {
3558 data = pci_alloc_consistent(pdev,
3562 if( data == NULL ) {
3563 pci_free_consistent(pdev,
3564 sizeof(mega_passthru),
3568 free_local_pdev(pdev);
3574 * Save the user address and point the kernel
3575 * address at just allocated memory
3577 uxferaddr = pthru->dataxferaddr;
3578 pthru->dataxferaddr = data_dma_hndl;
3583 * Is data coming down-stream
3585 if( pthru->dataxferlen && (uioc.flags & UIOC_WR) ) {
3589 if( copy_from_user(data, (char __user *)uxferaddr,
3590 pthru->dataxferlen) ) {
3592 goto freemem_and_return;
3596 memset(&mc, 0, sizeof(megacmd_t));
3598 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
3599 mc.xferaddr = (u32)pthru_dma_hndl;
3604 mega_internal_command(adapter, LOCK_INT, &mc, pthru);
3606 rval = mega_n_to_m((void __user *)arg, &mc);
3608 if( rval ) goto freemem_and_return;
3612 * Is data going up-stream
3614 if( pthru->dataxferlen && (uioc.flags & UIOC_RD) ) {
3615 if( copy_to_user((char __user *)uxferaddr, data,
3616 pthru->dataxferlen) ) {
3622 * Send the request sense data also, irrespective of
3623 * whether the user has asked for it or not.
3625 copy_to_user(upthru->reqsensearea,
3626 pthru->reqsensearea, 14);
3629 if( pthru->dataxferlen ) {
3630 pci_free_consistent(pdev,
3631 pthru->dataxferlen, data,
3635 pci_free_consistent(pdev, sizeof(mega_passthru),
3636 pthru, pthru_dma_hndl);
3638 free_local_pdev(pdev);
3646 * Is there a data transfer
3648 if( uioc.xferlen ) {
3649 data = pci_alloc_consistent(pdev,
3650 uioc.xferlen, &data_dma_hndl);
3652 if( data == NULL ) {
3653 free_local_pdev(pdev);
3657 uxferaddr = MBOX(uioc)->xferaddr;
3661 * Is data coming down-stream
3663 if( uioc.xferlen && (uioc.flags & UIOC_WR) ) {
3667 if( copy_from_user(data, (char __user *)uxferaddr,
3670 pci_free_consistent(pdev,
3672 data, data_dma_hndl);
3674 free_local_pdev(pdev);
3680 memcpy(&mc, MBOX(uioc), sizeof(megacmd_t));
3682 mc.xferaddr = (u32)data_dma_hndl;
3687 mega_internal_command(adapter, LOCK_INT, &mc, NULL);
3689 rval = mega_n_to_m((void __user *)arg, &mc);
3692 if( uioc.xferlen ) {
3693 pci_free_consistent(pdev,
3698 free_local_pdev(pdev);
3704 * Is data going up-stream
3706 if( uioc.xferlen && (uioc.flags & UIOC_RD) ) {
3707 if( copy_to_user((char __user *)uxferaddr, data,
3714 if( uioc.xferlen ) {
3715 pci_free_consistent(pdev,
3720 free_local_pdev(pdev);
3734 * @arg - user address
3735 * @uioc - new ioctl structure
3737 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3740 * Converts the older mimd ioctl structure to newer NIT structure
3743 mega_m_to_n(void __user *arg, nitioctl_t *uioc)
3745 struct uioctl_t uioc_mimd;
3746 char signature[8] = {0};
3752 * check is the application conforms to NIT. We do not have to do much
3754 * We exploit the fact that the signature is stored in the very
3755 * begining of the structure.
3758 if( copy_from_user(signature, arg, 7) )
3761 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3764 * NOTE NOTE: The nit ioctl is still under flux because of
3765 * change of mailbox definition, in HPE. No applications yet
3766 * use this interface and let's not have applications use this
3767 * interface till the new specifitions are in place.
3771 if( copy_from_user(uioc, arg, sizeof(nitioctl_t)) )
3778 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3780 * Get the user ioctl structure
3782 if( copy_from_user(&uioc_mimd, arg, sizeof(struct uioctl_t)) )
3787 * Get the opcode and subopcode for the commands
3789 opcode = uioc_mimd.ui.fcs.opcode;
3790 subopcode = uioc_mimd.ui.fcs.subopcode;
3795 switch (subopcode) {
3797 case MEGAIOC_QDRVRVER: /* Query driver version */
3798 uioc->opcode = GET_DRIVER_VER;
3799 uioc->uioc_uaddr = uioc_mimd.data;
3802 case MEGAIOC_QNADAP: /* Get # of adapters */
3803 uioc->opcode = GET_N_ADAP;
3804 uioc->uioc_uaddr = uioc_mimd.data;
3807 case MEGAIOC_QADAPINFO: /* Get adapter information */
3808 uioc->opcode = GET_ADAP_INFO;
3809 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3810 uioc->uioc_uaddr = uioc_mimd.data;
3822 uioc->opcode = MBOX_CMD;
3823 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3825 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3827 uioc->xferlen = uioc_mimd.ui.fcs.length;
3829 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3830 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3836 uioc->opcode = MBOX_CMD;
3837 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3839 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3842 * Choose the xferlen bigger of input and output data
3844 uioc->xferlen = uioc_mimd.outlen > uioc_mimd.inlen ?
3845 uioc_mimd.outlen : uioc_mimd.inlen;
3847 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3848 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3862 * @arg - user address
3863 * @mc - mailbox command
3865 * Updates the status information to the application, depending on application
3866 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3869 mega_n_to_m(void __user *arg, megacmd_t *mc)
3871 nitioctl_t __user *uiocp;
3872 megacmd_t __user *umc;
3873 mega_passthru __user *upthru;
3874 struct uioctl_t __user *uioc_mimd;
3875 char signature[8] = {0};
3878 * check is the application conforms to NIT.
3880 if( copy_from_user(signature, arg, 7) )
3883 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3887 if( put_user(mc->status, (u8 __user *)&MBOX_P(uiocp)->status) )
3890 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3892 umc = MBOX_P(uiocp);
3894 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3897 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus))
3904 if( put_user(mc->status, (u8 __user *)&uioc_mimd->mbox[17]) )
3907 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3909 umc = (megacmd_t __user *)uioc_mimd->mbox;
3911 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3914 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus) )
3924 * MEGARAID 'FW' commands.
3928 * mega_is_bios_enabled()
3929 * @adapter - pointer to our soft state
3931 * issue command to find out if the BIOS is enabled for this controller
3934 mega_is_bios_enabled(adapter_t *adapter)
3936 unsigned char raw_mbox[sizeof(struct mbox_out)];
3940 mbox = (mbox_t *)raw_mbox;
3942 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3944 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3946 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3948 raw_mbox[0] = IS_BIOS_ENABLED;
3949 raw_mbox[2] = GET_BIOS;
3952 ret = issue_scb_block(adapter, raw_mbox);
3954 return *(char *)adapter->mega_buffer;
3959 * mega_enum_raid_scsi()
3960 * @adapter - pointer to our soft state
3962 * Find out what channels are RAID/SCSI. This information is used to
3963 * differentiate the virtual channels and physical channels and to support
3964 * ROMB feature and non-disk devices.
3967 mega_enum_raid_scsi(adapter_t *adapter)
3969 unsigned char raw_mbox[sizeof(struct mbox_out)];
3973 mbox = (mbox_t *)raw_mbox;
3975 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3978 * issue command to find out what channels are raid/scsi
3980 raw_mbox[0] = CHNL_CLASS;
3981 raw_mbox[2] = GET_CHNL_CLASS;
3983 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3985 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3988 * Non-ROMB firmware fail this command, so all channels
3989 * must be shown RAID
3991 adapter->mega_ch_class = 0xFF;
3993 if(!issue_scb_block(adapter, raw_mbox)) {
3994 adapter->mega_ch_class = *((char *)adapter->mega_buffer);
3998 for( i = 0; i < adapter->product_info.nchannels; i++ ) {
3999 if( (adapter->mega_ch_class >> i) & 0x01 ) {
4000 printk(KERN_INFO "megaraid: channel[%d] is raid.\n",
4004 printk(KERN_INFO "megaraid: channel[%d] is scsi.\n",
4014 * mega_get_boot_drv()
4015 * @adapter - pointer to our soft state
4017 * Find out which device is the boot device. Note, any logical drive or any
4018 * phyical device (e.g., a CDROM) can be designated as a boot device.
4021 mega_get_boot_drv(adapter_t *adapter)
4023 struct private_bios_data *prv_bios_data;
4024 unsigned char raw_mbox[sizeof(struct mbox_out)];
4031 mbox = (mbox_t *)raw_mbox;
4033 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4035 raw_mbox[0] = BIOS_PVT_DATA;
4036 raw_mbox[2] = GET_BIOS_PVT_DATA;
4038 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4040 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4042 adapter->boot_ldrv_enabled = 0;
4043 adapter->boot_ldrv = 0;
4045 adapter->boot_pdrv_enabled = 0;
4046 adapter->boot_pdrv_ch = 0;
4047 adapter->boot_pdrv_tgt = 0;
4049 if(issue_scb_block(adapter, raw_mbox) == 0) {
4051 (struct private_bios_data *)adapter->mega_buffer;
4054 cksum_p = (char *)prv_bios_data;
4055 for (i = 0; i < 14; i++ ) {
4056 cksum += (u16)(*cksum_p++);
4059 if (prv_bios_data->cksum == (u16)(0-cksum) ) {
4062 * If MSB is set, a physical drive is set as boot
4065 if( prv_bios_data->boot_drv & 0x80 ) {
4066 adapter->boot_pdrv_enabled = 1;
4067 boot_pdrv = prv_bios_data->boot_drv & 0x7F;
4068 adapter->boot_pdrv_ch = boot_pdrv / 16;
4069 adapter->boot_pdrv_tgt = boot_pdrv % 16;
4072 adapter->boot_ldrv_enabled = 1;
4073 adapter->boot_ldrv = prv_bios_data->boot_drv;
4081 * mega_support_random_del()
4082 * @adapter - pointer to our soft state
4084 * Find out if this controller supports random deletion and addition of
4088 mega_support_random_del(adapter_t *adapter)
4090 unsigned char raw_mbox[sizeof(struct mbox_out)];
4094 mbox = (mbox_t *)raw_mbox;
4096 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4101 raw_mbox[0] = FC_DEL_LOGDRV;
4102 raw_mbox[2] = OP_SUP_DEL_LOGDRV;
4104 rval = issue_scb_block(adapter, raw_mbox);
4111 * mega_support_ext_cdb()
4112 * @adapter - pointer to our soft state
4114 * Find out if this firmware support cdblen > 10
4117 mega_support_ext_cdb(adapter_t *adapter)
4119 unsigned char raw_mbox[sizeof(struct mbox_out)];
4123 mbox = (mbox_t *)raw_mbox;
4125 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4127 * issue command to find out if controller supports extended CDBs.
4132 rval = issue_scb_block(adapter, raw_mbox);
4140 * @adapter - pointer to our soft state
4141 * @logdrv - logical drive to be deleted
4143 * Delete the specified logical drive. It is the responsibility of the user
4144 * app to let the OS know about this operation.
4147 mega_del_logdrv(adapter_t *adapter, int logdrv)
4149 unsigned long flags;
4154 * Stop sending commands to the controller, queue them internally.
4155 * When deletion is complete, ISR will flush the queue.
4157 atomic_set(&adapter->quiescent, 1);
4160 * Wait till all the issued commands are complete and there are no
4161 * commands in the pending queue
4163 while (atomic_read(&adapter->pend_cmds) > 0 ||
4164 !list_empty(&adapter->pending_list))
4165 msleep(1000); /* sleep for 1s */
4167 rval = mega_do_del_logdrv(adapter, logdrv);
4169 spin_lock_irqsave(&adapter->lock, flags);
4172 * If delete operation was successful, add 0x80 to the logical drive
4173 * ids for commands in the pending queue.
4175 if (adapter->read_ldidmap) {
4176 struct list_head *pos;
4177 list_for_each(pos, &adapter->pending_list) {
4178 scb = list_entry(pos, scb_t, list);
4179 if (scb->pthru->logdrv < 0x80 )
4180 scb->pthru->logdrv += 0x80;
4184 atomic_set(&adapter->quiescent, 0);
4186 mega_runpendq(adapter);
4188 spin_unlock_irqrestore(&adapter->lock, flags);
4195 mega_do_del_logdrv(adapter_t *adapter, int logdrv)
4200 memset( &mc, 0, sizeof(megacmd_t));
4202 mc.cmd = FC_DEL_LOGDRV;
4203 mc.opcode = OP_DEL_LOGDRV;
4204 mc.subopcode = logdrv;
4206 rval = mega_internal_command(adapter, LOCK_INT, &mc, NULL);
4208 /* log this event */
4210 printk(KERN_WARNING "megaraid: Delete LD-%d failed.", logdrv);
4215 * After deleting first logical drive, the logical drives must be
4216 * addressed by adding 0x80 to the logical drive id.
4218 adapter->read_ldidmap = 1;
4225 * mega_get_max_sgl()
4226 * @adapter - pointer to our soft state
4228 * Find out the maximum number of scatter-gather elements supported by this
4229 * version of the firmware
4232 mega_get_max_sgl(adapter_t *adapter)
4234 unsigned char raw_mbox[sizeof(struct mbox_out)];
4237 mbox = (mbox_t *)raw_mbox;
4239 memset(mbox, 0, sizeof(raw_mbox));
4241 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4243 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4245 raw_mbox[0] = MAIN_MISC_OPCODE;
4246 raw_mbox[2] = GET_MAX_SG_SUPPORT;
4249 if( issue_scb_block(adapter, raw_mbox) ) {
4251 * f/w does not support this command. Choose the default value
4253 adapter->sglen = MIN_SGLIST;
4256 adapter->sglen = *((char *)adapter->mega_buffer);
4259 * Make sure this is not more than the resources we are
4260 * planning to allocate
4262 if ( adapter->sglen > MAX_SGLIST )
4263 adapter->sglen = MAX_SGLIST;
4271 * mega_support_cluster()
4272 * @adapter - pointer to our soft state
4274 * Find out if this firmware support cluster calls.
4277 mega_support_cluster(adapter_t *adapter)
4279 unsigned char raw_mbox[sizeof(struct mbox_out)];
4282 mbox = (mbox_t *)raw_mbox;
4284 memset(mbox, 0, sizeof(raw_mbox));
4286 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4288 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4291 * Try to get the initiator id. This command will succeed iff the
4292 * clustering is available on this HBA.
4294 raw_mbox[0] = MEGA_GET_TARGET_ID;
4296 if( issue_scb_block(adapter, raw_mbox) == 0 ) {
4299 * Cluster support available. Get the initiator target id.
4300 * Tell our id to mid-layer too.
4302 adapter->this_id = *(u32 *)adapter->mega_buffer;
4303 adapter->host->this_id = adapter->this_id;
4314 * @adapter - pointer to our soft state
4315 * @dma_handle - DMA address of the buffer
4317 * Issue internal comamnds while interrupts are available.
4318 * We only issue direct mailbox commands from within the driver. ioctl()
4319 * interface using these routines can issue passthru commands.
4322 mega_adapinq(adapter_t *adapter, dma_addr_t dma_handle)
4326 memset(&mc, 0, sizeof(megacmd_t));
4328 if( adapter->flag & BOARD_40LD ) {
4329 mc.cmd = FC_NEW_CONFIG;
4330 mc.opcode = NC_SUBOP_ENQUIRY3;
4331 mc.subopcode = ENQ3_GET_SOLICITED_FULL;
4334 mc.cmd = MEGA_MBOXCMD_ADPEXTINQ;
4337 mc.xferaddr = (u32)dma_handle;
4339 if ( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
4347 /** mega_internal_dev_inquiry()
4348 * @adapter - pointer to our soft state
4349 * @ch - channel for this device
4350 * @tgt - ID of this device
4351 * @buf_dma_handle - DMA address of the buffer
4353 * Issue the scsi inquiry for the specified device.
4356 mega_internal_dev_inquiry(adapter_t *adapter, u8 ch, u8 tgt,
4357 dma_addr_t buf_dma_handle)
4359 mega_passthru *pthru;
4360 dma_addr_t pthru_dma_handle;
4363 struct pci_dev *pdev;
4367 * For all internal commands, the buffer must be allocated in <4GB
4370 if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
4372 pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
4375 if( pthru == NULL ) {
4376 free_local_pdev(pdev);
4382 pthru->reqsenselen = 14;
4383 pthru->islogical = 0;
4385 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : ch;
4387 pthru->target = (adapter->flag & BOARD_40LD) ? (ch << 4)|tgt : tgt;
4391 pthru->cdb[0] = INQUIRY;
4395 pthru->cdb[4] = 255;
4399 pthru->dataxferaddr = (u32)buf_dma_handle;
4400 pthru->dataxferlen = 256;
4402 memset(&mc, 0, sizeof(megacmd_t));
4404 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
4405 mc.xferaddr = (u32)pthru_dma_handle;
4407 rval = mega_internal_command(adapter, LOCK_INT, &mc, pthru);
4409 pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
4412 free_local_pdev(pdev);
4419 * mega_internal_command()
4420 * @adapter - pointer to our soft state
4421 * @ls - the scope of the exclusion lock.
4422 * @mc - the mailbox command
4423 * @pthru - Passthru structure for DCDB commands
4425 * Issue the internal commands in interrupt mode.
4426 * The last argument is the address of the passthru structure if the command
4427 * to be fired is a passthru command
4429 * lockscope specifies whether the caller has already acquired the lock. Of
4430 * course, the caller must know which lock we are talking about.
4432 * Note: parameter 'pthru' is null for non-passthru commands.
4435 mega_internal_command(adapter_t *adapter, lockscope_t ls, megacmd_t *mc,
4436 mega_passthru *pthru )
4439 struct scsi_device *sdev;
4440 unsigned long flags = 0;
4445 * The internal commands share one command id and hence are
4446 * serialized. This is so because we want to reserve maximum number of
4447 * available command ids for the I/O commands.
4449 down(&adapter->int_mtx);
4451 scb = &adapter->int_scb;
4452 memset(scb, 0, sizeof(scb_t));
4454 scmd = &adapter->int_scmd;
4455 memset(scmd, 0, sizeof(Scsi_Cmnd));
4457 sdev = kmalloc(sizeof(struct scsi_device), GFP_KERNEL);
4458 memset(sdev, 0, sizeof(struct scsi_device));
4459 scmd->device = sdev;
4461 scmd->device->host = adapter->host;
4462 scmd->buffer = (void *)scb;
4463 scmd->cmnd[0] = MEGA_INTERNAL_CMD;
4465 scb->state |= SCB_ACTIVE;
4468 memcpy(scb->raw_mbox, mc, sizeof(megacmd_t));
4471 * Is it a passthru command
4473 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
4478 scb->idx = CMDID_INT_CMDS;
4483 * Get the lock only if the caller has not acquired it already
4485 if( ls == LOCK_INT ) spin_lock_irqsave(&adapter->lock, flags);
4487 megaraid_queue(scmd, mega_internal_done);
4489 if( ls == LOCK_INT ) spin_unlock_irqrestore(&adapter->lock, flags);
4492 * Wait till this command finishes. Do not use
4493 * wait_event_interruptible(). It causes panic if CTRL-C is hit when
4494 * dumping e.g., physical disk information through /proc interface.
4497 wait_event_interruptible(adapter->int_waitq, scmd->state);
4499 wait_event(adapter->int_waitq, scmd->state);
4501 rval = scmd->result;
4502 mc->status = scmd->result;
4506 * Print a debug message for all failed commands. Applications can use
4509 if( scmd->result && trace_level ) {
4510 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4511 mc->cmd, mc->opcode, mc->subopcode, scmd->result);
4514 up(&adapter->int_mtx);
4521 * mega_internal_done()
4522 * @scmd - internal scsi command
4524 * Callback routine for internal commands.
4527 mega_internal_done(Scsi_Cmnd *scmd)
4531 adapter = (adapter_t *)scmd->device->host->hostdata;
4533 scmd->state = 1; /* thread waiting for its command to complete */
4536 * See comment in mega_internal_command() routine for
4537 * wait_event_interruptible()
4540 wake_up_interruptible(&adapter->int_waitq);
4542 wake_up(&adapter->int_waitq);
4547 static struct scsi_host_template megaraid_template = {
4548 .module = THIS_MODULE,
4550 .proc_name = "megaraid",
4551 .info = megaraid_info,
4552 .queuecommand = megaraid_queue,
4553 .bios_param = megaraid_biosparam,
4554 .max_sectors = MAX_SECTORS_PER_IO,
4555 .can_queue = MAX_COMMANDS,
4556 .this_id = DEFAULT_INITIATOR_ID,
4557 .sg_tablesize = MAX_SGLIST,
4558 .cmd_per_lun = DEF_CMD_PER_LUN,
4559 .use_clustering = ENABLE_CLUSTERING,
4560 .eh_abort_handler = megaraid_abort,
4561 .eh_device_reset_handler = megaraid_reset,
4562 .eh_bus_reset_handler = megaraid_reset,
4563 .eh_host_reset_handler = megaraid_reset,
4566 static int __devinit
4567 megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4569 struct Scsi_Host *host;
4571 unsigned long mega_baseport, tbase, flag = 0;
4572 u16 subsysid, subsysvid;
4573 u8 pci_bus, pci_dev_func;
4575 int error = -ENODEV;
4577 if (pci_enable_device(pdev))
4579 pci_set_master(pdev);
4581 pci_bus = pdev->bus->number;
4582 pci_dev_func = pdev->devfn;
4585 * The megaraid3 stuff reports the ID of the Intel part which is not
4586 * remotely specific to the megaraid
4588 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
4591 * Don't fall over the Compaq management cards using the same
4594 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ &&
4595 pdev->subsystem_device == 0xC000)
4597 /* Now check the magic signature byte */
4598 pci_read_config_word(pdev, PCI_CONF_AMISIG, &magic);
4599 if (magic != HBA_SIGNATURE_471 && magic != HBA_SIGNATURE)
4601 /* Ok it is probably a megaraid */
4605 * For these vendor and device ids, signature offsets are not
4606 * valid and 64 bit is implicit
4608 if (id->driver_data & BOARD_64BIT)
4609 flag |= BOARD_64BIT;
4613 pci_read_config_dword(pdev, PCI_CONF_AMISIG64, &magic64);
4614 if (magic64 == HBA_SIGNATURE_64BIT)
4615 flag |= BOARD_64BIT;
4618 subsysvid = pdev->subsystem_vendor;
4619 subsysid = pdev->subsystem_device;
4621 printk(KERN_NOTICE "megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4622 id->vendor, id->device, pci_bus);
4624 printk("slot %d:func %d\n",
4625 PCI_SLOT(pci_dev_func), PCI_FUNC(pci_dev_func));
4627 /* Read the base port and IRQ from PCI */
4628 mega_baseport = pci_resource_start(pdev, 0);
4631 tbase = mega_baseport;
4632 if (pci_resource_flags(pdev, 0) & IORESOURCE_MEM) {
4633 flag |= BOARD_MEMMAP;
4635 if (!request_mem_region(mega_baseport, 128, "megaraid")) {
4636 printk(KERN_WARNING "megaraid: mem region busy!\n");
4637 goto out_disable_device;
4640 mega_baseport = (unsigned long)ioremap(mega_baseport, 128);
4641 if (!mega_baseport) {
4643 "megaraid: could not map hba memory\n");
4644 goto out_release_region;
4647 flag |= BOARD_IOMAP;
4648 mega_baseport += 0x10;
4650 if (!request_region(mega_baseport, 16, "megaraid"))
4651 goto out_disable_device;
4654 /* Initialize SCSI Host structure */
4655 host = scsi_host_alloc(&megaraid_template, sizeof(adapter_t));
4659 adapter = (adapter_t *)host->hostdata;
4660 memset(adapter, 0, sizeof(adapter_t));
4663 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4664 host->host_no, mega_baseport, irq);
4666 adapter->base = mega_baseport;
4668 INIT_LIST_HEAD(&adapter->free_list);
4669 INIT_LIST_HEAD(&adapter->pending_list);
4670 INIT_LIST_HEAD(&adapter->completed_list);
4672 adapter->flag = flag;
4673 spin_lock_init(&adapter->lock);
4674 scsi_assign_lock(host, &adapter->lock);
4676 host->cmd_per_lun = max_cmd_per_lun;
4677 host->max_sectors = max_sectors_per_io;
4679 adapter->dev = pdev;
4680 adapter->host = host;
4682 adapter->host->irq = irq;
4684 if (flag & BOARD_MEMMAP)
4685 adapter->host->base = tbase;
4687 adapter->host->io_port = tbase;
4688 adapter->host->n_io_port = 16;
4691 adapter->host->unique_id = (pci_bus << 8) | pci_dev_func;
4694 * Allocate buffer to issue internal commands.
4696 adapter->mega_buffer = pci_alloc_consistent(adapter->dev,
4697 MEGA_BUFFER_SIZE, &adapter->buf_dma_handle);
4698 if (!adapter->mega_buffer) {
4699 printk(KERN_WARNING "megaraid: out of RAM.\n");
4703 adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
4704 if (!adapter->scb_list) {
4705 printk(KERN_WARNING "megaraid: out of RAM.\n");
4706 goto out_free_cmd_buffer;
4709 if (request_irq(irq, (adapter->flag & BOARD_MEMMAP) ?
4710 megaraid_isr_memmapped : megaraid_isr_iomapped,
4711 SA_SHIRQ, "megaraid", adapter)) {
4713 "megaraid: Couldn't register IRQ %d!\n", irq);
4714 goto out_free_scb_list;
4717 if (mega_setup_mailbox(adapter))
4720 if (mega_query_adapter(adapter))
4724 * Have checks for some buggy f/w
4726 if ((subsysid == 0x1111) && (subsysvid == 0x1111)) {
4730 if (!strcmp(adapter->fw_version, "3.00") ||
4731 !strcmp(adapter->fw_version, "3.01")) {
4733 printk( KERN_WARNING
4734 "megaraid: Your card is a Dell PERC "
4735 "2/SC RAID controller with "
4736 "firmware\nmegaraid: 3.00 or 3.01. "
4737 "This driver is known to have "
4738 "corruption issues\nmegaraid: with "
4739 "those firmware versions on this "
4740 "specific card. In order\nmegaraid: "
4741 "to protect your data, please upgrade "
4742 "your firmware to version\nmegaraid: "
4743 "3.10 or later, available from the "
4744 "Dell Technical Support web\n"
4745 "megaraid: site at\nhttp://support."
4746 "dell.com/us/en/filelib/download/"
4747 "index.asp?fileid=2940\n"
4753 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4754 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4755 * support, since this firmware cannot handle 64 bit
4758 if ((subsysvid == HP_SUBSYS_VID) &&
4759 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) {
4763 if (!strcmp(adapter->fw_version, "H01.07") ||
4764 !strcmp(adapter->fw_version, "H01.08") ||
4765 !strcmp(adapter->fw_version, "H01.09") ) {
4767 "megaraid: Firmware H.01.07, "
4768 "H.01.08, and H.01.09 on 1M/2M "
4770 "megaraid: do not support 64 bit "
4771 "addressing.\nmegaraid: DISABLING "
4772 "64 bit support.\n");
4773 adapter->flag &= ~BOARD_64BIT;
4777 if (mega_is_bios_enabled(adapter))
4778 mega_hbas[hba_count].is_bios_enabled = 1;
4779 mega_hbas[hba_count].hostdata_addr = adapter;
4782 * Find out which channel is raid and which is scsi. This is
4785 mega_enum_raid_scsi(adapter);
4788 * Find out if a logical drive is set as the boot drive. If
4789 * there is one, will make that as the first logical drive.
4790 * ROMB: Do we have to boot from a physical drive. Then all
4791 * the physical drives would appear before the logical disks.
4792 * Else, all the physical drives would be exported to the mid
4793 * layer after logical drives.
4795 mega_get_boot_drv(adapter);
4797 if (adapter->boot_pdrv_enabled) {
4798 j = adapter->product_info.nchannels;
4799 for( i = 0; i < j; i++ )
4800 adapter->logdrv_chan[i] = 0;
4801 for( i = j; i < NVIRT_CHAN + j; i++ )
4802 adapter->logdrv_chan[i] = 1;
4804 for (i = 0; i < NVIRT_CHAN; i++)
4805 adapter->logdrv_chan[i] = 1;
4806 for (i = NVIRT_CHAN; i < MAX_CHANNELS+NVIRT_CHAN; i++)
4807 adapter->logdrv_chan[i] = 0;
4808 adapter->mega_ch_class <<= NVIRT_CHAN;
4812 * Do we support random deletion and addition of logical
4815 adapter->read_ldidmap = 0; /* set it after first logdrv
4817 adapter->support_random_del = mega_support_random_del(adapter);
4819 /* Initialize SCBs */
4820 if (mega_init_scb(adapter))
4824 * Reset the pending commands counter
4826 atomic_set(&adapter->pend_cmds, 0);
4829 * Reset the adapter quiescent flag
4831 atomic_set(&adapter->quiescent, 0);
4833 hba_soft_state[hba_count] = adapter;
4836 * Fill in the structure which needs to be passed back to the
4837 * application when it does an ioctl() for controller related
4842 mcontroller[i].base = mega_baseport;
4843 mcontroller[i].irq = irq;
4844 mcontroller[i].numldrv = adapter->numldrv;
4845 mcontroller[i].pcibus = pci_bus;
4846 mcontroller[i].pcidev = id->device;
4847 mcontroller[i].pcifun = PCI_FUNC (pci_dev_func);
4848 mcontroller[i].pciid = -1;
4849 mcontroller[i].pcivendor = id->vendor;
4850 mcontroller[i].pcislot = PCI_SLOT(pci_dev_func);
4851 mcontroller[i].uid = (pci_bus << 8) | pci_dev_func;
4854 /* Set the Mode of addressing to 64 bit if we can */
4855 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) {
4856 pci_set_dma_mask(pdev, 0xffffffffffffffffULL);
4857 adapter->has_64bit_addr = 1;
4859 pci_set_dma_mask(pdev, 0xffffffff);
4860 adapter->has_64bit_addr = 0;
4863 init_MUTEX(&adapter->int_mtx);
4864 init_waitqueue_head(&adapter->int_waitq);
4866 adapter->this_id = DEFAULT_INITIATOR_ID;
4867 adapter->host->this_id = DEFAULT_INITIATOR_ID;
4869 #if MEGA_HAVE_CLUSTERING
4871 * Is cluster support enabled on this controller
4872 * Note: In a cluster the HBAs ( the initiators ) will have
4873 * different target IDs and we cannot assume it to be 7. Call
4874 * to mega_support_cluster() will get the target ids also if
4875 * the cluster support is available
4877 adapter->has_cluster = mega_support_cluster(adapter);
4878 if (adapter->has_cluster) {
4880 "megaraid: Cluster driver, initiator id:%d\n",
4885 pci_set_drvdata(pdev, host);
4887 mega_create_proc_entry(hba_count, mega_proc_dir_entry);
4889 error = scsi_add_host(host, &pdev->dev);
4893 scsi_scan_host(host);
4898 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
4899 adapter->una_mbox64, adapter->una_mbox64_dma);
4901 free_irq(adapter->host->irq, adapter);
4903 kfree(adapter->scb_list);
4904 out_free_cmd_buffer:
4905 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
4906 adapter->mega_buffer, adapter->buf_dma_handle);
4908 scsi_host_put(host);
4910 if (flag & BOARD_MEMMAP)
4911 iounmap((void *)mega_baseport);
4913 if (flag & BOARD_MEMMAP)
4914 release_mem_region(tbase, 128);
4916 release_region(mega_baseport, 16);
4918 pci_disable_device(pdev);
4924 __megaraid_shutdown(adapter_t *adapter)
4926 u_char raw_mbox[sizeof(struct mbox_out)];
4927 mbox_t *mbox = (mbox_t *)raw_mbox;
4930 /* Flush adapter cache */
4931 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4932 raw_mbox[0] = FLUSH_ADAPTER;
4934 free_irq(adapter->host->irq, adapter);
4936 /* Issue a blocking (interrupts disabled) command to the card */
4937 issue_scb_block(adapter, raw_mbox);
4939 /* Flush disks cache */
4940 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4941 raw_mbox[0] = FLUSH_SYSTEM;
4943 /* Issue a blocking (interrupts disabled) command to the card */
4944 issue_scb_block(adapter, raw_mbox);
4946 if (atomic_read(&adapter->pend_cmds) > 0)
4947 printk(KERN_WARNING "megaraid: pending commands!!\n");
4950 * Have a delibrate delay to make sure all the caches are
4953 for (i = 0; i <= 10; i++)
4958 megaraid_remove_one(struct pci_dev *pdev)
4960 struct Scsi_Host *host = pci_get_drvdata(pdev);
4961 adapter_t *adapter = (adapter_t *)host->hostdata;
4962 char buf[12] = { 0 };
4964 scsi_remove_host(host);
4966 __megaraid_shutdown(adapter);
4968 /* Free our resources */
4969 if (adapter->flag & BOARD_MEMMAP) {
4970 iounmap((void *)adapter->base);
4971 release_mem_region(adapter->host->base, 128);
4973 release_region(adapter->base, 16);
4975 mega_free_sgl(adapter);
4977 #ifdef CONFIG_PROC_FS
4978 if (adapter->controller_proc_dir_entry) {
4979 remove_proc_entry("stat", adapter->controller_proc_dir_entry);
4980 remove_proc_entry("config",
4981 adapter->controller_proc_dir_entry);
4982 remove_proc_entry("mailbox",
4983 adapter->controller_proc_dir_entry);
4984 #if MEGA_HAVE_ENH_PROC
4985 remove_proc_entry("rebuild-rate",
4986 adapter->controller_proc_dir_entry);
4987 remove_proc_entry("battery-status",
4988 adapter->controller_proc_dir_entry);
4990 remove_proc_entry("diskdrives-ch0",
4991 adapter->controller_proc_dir_entry);
4992 remove_proc_entry("diskdrives-ch1",
4993 adapter->controller_proc_dir_entry);
4994 remove_proc_entry("diskdrives-ch2",
4995 adapter->controller_proc_dir_entry);
4996 remove_proc_entry("diskdrives-ch3",
4997 adapter->controller_proc_dir_entry);
4999 remove_proc_entry("raiddrives-0-9",
5000 adapter->controller_proc_dir_entry);
5001 remove_proc_entry("raiddrives-10-19",
5002 adapter->controller_proc_dir_entry);
5003 remove_proc_entry("raiddrives-20-29",
5004 adapter->controller_proc_dir_entry);
5005 remove_proc_entry("raiddrives-30-39",
5006 adapter->controller_proc_dir_entry);
5008 sprintf(buf, "hba%d", adapter->host->host_no);
5009 remove_proc_entry(buf, mega_proc_dir_entry);
5013 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
5014 adapter->mega_buffer, adapter->buf_dma_handle);
5015 kfree(adapter->scb_list);
5016 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
5017 adapter->una_mbox64, adapter->una_mbox64_dma);
5019 scsi_host_put(host);
5020 pci_disable_device(pdev);
5026 megaraid_shutdown(struct device *dev)
5028 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev));
5029 adapter_t *adapter = (adapter_t *)host->hostdata;
5031 __megaraid_shutdown(adapter);
5034 static struct pci_device_id megaraid_pci_tbl[] = {
5035 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DISCOVERY,
5036 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5037 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_PERC4_DI,
5038 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
5039 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_PERC4_QC_VERDE,
5040 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
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_AMI, PCI_DEVICE_ID_AMI_MEGARAID3,
5046 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5047 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_AMI_MEGARAID3,
5048 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5049 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_AMI_MEGARAID3,
5050 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5053 MODULE_DEVICE_TABLE(pci, megaraid_pci_tbl);
5055 static struct pci_driver megaraid_pci_driver = {
5057 .id_table = megaraid_pci_tbl,
5058 .probe = megaraid_probe_one,
5059 .remove = __devexit_p(megaraid_remove_one),
5061 .shutdown = megaraid_shutdown,
5065 static int __init megaraid_init(void)
5069 if ((max_cmd_per_lun <= 0) || (max_cmd_per_lun > MAX_CMD_PER_LUN))
5070 max_cmd_per_lun = MAX_CMD_PER_LUN;
5071 if (max_mbox_busy_wait > MBOX_BUSY_WAIT)
5072 max_mbox_busy_wait = MBOX_BUSY_WAIT;
5074 #ifdef CONFIG_PROC_FS
5075 mega_proc_dir_entry = proc_mkdir("megaraid", &proc_root);
5076 if (!mega_proc_dir_entry) {
5078 "megaraid: failed to create megaraid root\n");
5081 error = pci_module_init(&megaraid_pci_driver);
5083 #ifdef CONFIG_PROC_FS
5084 remove_proc_entry("megaraid", &proc_root);
5090 * Register the driver as a character device, for applications
5091 * to access it for ioctls.
5092 * First argument (major) to register_chrdev implies a dynamic
5093 * major number allocation.
5095 major = register_chrdev(0, "megadev", &megadev_fops);
5098 "megaraid: failed to register char device\n");
5104 static void __exit megaraid_exit(void)
5107 * Unregister the character device interface to the driver.
5109 unregister_chrdev(major, "megadev");
5111 pci_unregister_driver(&megaraid_pci_driver);
5113 #ifdef CONFIG_PROC_FS
5114 remove_proc_entry("megaraid", &proc_root);
5118 module_init(megaraid_init);
5119 module_exit(megaraid_exit);
5121 /* vi: set ts=8 sw=8 tw=78: */