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 public mailing list
29 * linux-megaraid-devel@dell.com, and subscribe to and read archives of this
30 * list at http://lists.us.dell.com/.
32 * For history of changes, see ChangeLog.megaraid.
38 #include <linux/blkdev.h>
39 #include <asm/uaccess.h>
41 #include <linux/delay.h>
42 #include <linux/proc_fs.h>
43 #include <linux/reboot.h>
44 #include <linux/module.h>
45 #include <linux/list.h>
46 #include <linux/interrupt.h>
47 #include <linux/pci.h>
48 #include <linux/init.h>
49 #include <scsi/scsicam.h>
52 #include <scsi/scsi_host.h>
56 MODULE_AUTHOR ("LSI Logic Corporation");
57 MODULE_DESCRIPTION ("LSI Logic MegaRAID driver");
58 MODULE_LICENSE ("GPL");
60 static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
61 MODULE_PARM(max_cmd_per_lun, "i");
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_PARM(max_sectors_per_io, "h");
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_PARM(max_mbox_busy_wait, "h");
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");
341 * @scmd - Issue this scsi command
342 * @done - the callback hook into the scsi mid-layer
344 * The command queuing entry point for the mid-layer.
347 megaraid_queue(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
353 adapter = (adapter_t *)scmd->device->host->hostdata;
355 scmd->scsi_done = done;
359 * Allocate and build a SCB request
360 * busy flag will be set if mega_build_cmd() command could not
361 * allocate scb. We will return non-zero status in that case.
362 * NOTE: scb can be null even though certain commands completed
363 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
364 * return 0 in that case.
367 scb = mega_build_cmd(adapter, scmd, &busy);
370 scb->state |= SCB_PENDQ;
371 list_add_tail(&scb->list, &adapter->pending_list);
374 * Check if the HBA is in quiescent state, e.g., during a
375 * delete logical drive opertion. If it is, don't run
378 if(atomic_read(&adapter->quiescent) == 0) {
379 mega_runpendq(adapter);
390 * @adapter - pointer to our soft state
391 * @cmd - Prepare using this scsi command
392 * @busy - busy flag if no resources
394 * Prepares a command and scatter gather list for the controller. This routine
395 * also finds out if the commands is intended for a logical drive or a
396 * physical device and prepares the controller command accordingly.
398 * We also re-order the logical drives and physical devices based on their
402 mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy)
404 mega_ext_passthru *epthru;
405 mega_passthru *pthru;
413 int ldrv_num = 0; /* logical drive number */
417 * filter the internal and ioctl commands
419 if((cmd->cmnd[0] == MEGA_INTERNAL_CMD)) {
425 * We know what channels our logical drives are on - mega_find_card()
427 islogical = adapter->logdrv_chan[cmd->device->channel];
430 * The theory: If physical drive is chosen for boot, all the physical
431 * devices are exported before the logical drives, otherwise physical
432 * devices are pushed after logical drives, in which case - Kernel sees
433 * the physical devices on virtual channel which is obviously converted
434 * to actual channel on the HBA.
436 if( adapter->boot_pdrv_enabled ) {
438 /* logical channel */
439 channel = cmd->device->channel -
440 adapter->product_info.nchannels;
443 /* this is physical channel */
444 channel = cmd->device->channel;
445 target = cmd->device->id;
448 * boot from a physical disk, that disk needs to be
449 * exposed first IF both the channels are SCSI, then
450 * booting from the second channel is not allowed.
453 target = adapter->boot_pdrv_tgt;
455 else if( target == adapter->boot_pdrv_tgt ) {
462 /* this is the logical channel */
463 channel = cmd->device->channel;
466 /* physical channel */
467 channel = cmd->device->channel - NVIRT_CHAN;
468 target = cmd->device->id;
475 /* have just LUN 0 for each target on virtual channels */
476 if (cmd->device->lun) {
477 cmd->result = (DID_BAD_TARGET << 16);
482 ldrv_num = mega_get_ldrv_num(adapter, cmd, channel);
485 max_ldrv_num = (adapter->flag & BOARD_40LD) ?
486 MAX_LOGICAL_DRIVES_40LD : MAX_LOGICAL_DRIVES_8LD;
489 * max_ldrv_num increases by 0x80 if some logical drive was
492 if(adapter->read_ldidmap)
493 max_ldrv_num += 0x80;
495 if(ldrv_num > max_ldrv_num ) {
496 cmd->result = (DID_BAD_TARGET << 16);
503 if( cmd->device->lun > 7) {
505 * Do not support lun >7 for physically accessed
508 cmd->result = (DID_BAD_TARGET << 16);
516 * Logical drive commands
520 switch (cmd->cmnd[0]) {
521 case TEST_UNIT_READY:
522 memset(cmd->request_buffer, 0, cmd->request_bufflen);
524 #if MEGA_HAVE_CLUSTERING
526 * Do we support clustering and is the support enabled
527 * If no, return success always
529 if( !adapter->has_cluster ) {
530 cmd->result = (DID_OK << 16);
535 if(!(scb = mega_allocate_scb(adapter, cmd))) {
537 cmd->result = (DID_ERROR << 16);
544 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
545 scb->raw_mbox[2] = MEGA_RESERVATION_STATUS;
546 scb->raw_mbox[3] = ldrv_num;
548 scb->dma_direction = PCI_DMA_NONE;
552 cmd->result = (DID_OK << 16);
558 memset(cmd->request_buffer, 0, cmd->cmnd[4]);
559 cmd->result = (DID_OK << 16);
566 if(!(adapter->flag & (1L << cmd->device->channel))) {
569 "scsi%d: scanning scsi channel %d ",
570 adapter->host->host_no,
571 cmd->device->channel);
572 printk("for logical drives.\n");
574 adapter->flag |= (1L << cmd->device->channel);
577 /* Allocate a SCB and initialize passthru */
578 if(!(scb = mega_allocate_scb(adapter, cmd))) {
580 cmd->result = (DID_ERROR << 16);
588 mbox = (mbox_t *)scb->raw_mbox;
589 memset(mbox, 0, sizeof(scb->raw_mbox));
590 memset(pthru, 0, sizeof(mega_passthru));
594 pthru->reqsenselen = 14;
595 pthru->islogical = 1;
596 pthru->logdrv = ldrv_num;
597 pthru->cdblen = cmd->cmd_len;
598 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
600 if( adapter->has_64bit_addr ) {
601 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
604 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
607 scb->dma_direction = PCI_DMA_FROMDEVICE;
609 pthru->numsgelements = mega_build_sglist(adapter, scb,
610 &pthru->dataxferaddr, &pthru->dataxferlen);
612 mbox->m_out.xferaddr = scb->pthru_dma_addr;
623 /* Allocate a SCB and initialize mailbox */
624 if(!(scb = mega_allocate_scb(adapter, cmd))) {
626 cmd->result = (DID_ERROR << 16);
632 mbox = (mbox_t *)scb->raw_mbox;
634 memset(mbox, 0, sizeof(scb->raw_mbox));
635 mbox->m_out.logdrv = ldrv_num;
638 * A little hack: 2nd bit is zero for all scsi read
639 * commands and is set for all scsi write commands
641 if( adapter->has_64bit_addr ) {
642 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
643 MEGA_MBOXCMD_LWRITE64:
644 MEGA_MBOXCMD_LREAD64 ;
647 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
653 * 6-byte READ(0x08) or WRITE(0x0A) cdb
655 if( cmd->cmd_len == 6 ) {
656 mbox->m_out.numsectors = (u32) cmd->cmnd[4];
658 ((u32)cmd->cmnd[1] << 16) |
659 ((u32)cmd->cmnd[2] << 8) |
662 mbox->m_out.lba &= 0x1FFFFF;
666 * Take modulo 0x80, since the logical drive
667 * number increases by 0x80 when a logical
670 if (*cmd->cmnd == READ_6) {
671 adapter->nreads[ldrv_num%0x80]++;
672 adapter->nreadblocks[ldrv_num%0x80] +=
673 mbox->m_out.numsectors;
675 adapter->nwrites[ldrv_num%0x80]++;
676 adapter->nwriteblocks[ldrv_num%0x80] +=
677 mbox->m_out.numsectors;
683 * 10-byte READ(0x28) or WRITE(0x2A) cdb
685 if( cmd->cmd_len == 10 ) {
686 mbox->m_out.numsectors =
688 ((u32)cmd->cmnd[7] << 8);
690 ((u32)cmd->cmnd[2] << 24) |
691 ((u32)cmd->cmnd[3] << 16) |
692 ((u32)cmd->cmnd[4] << 8) |
696 if (*cmd->cmnd == READ_10) {
697 adapter->nreads[ldrv_num%0x80]++;
698 adapter->nreadblocks[ldrv_num%0x80] +=
699 mbox->m_out.numsectors;
701 adapter->nwrites[ldrv_num%0x80]++;
702 adapter->nwriteblocks[ldrv_num%0x80] +=
703 mbox->m_out.numsectors;
709 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
711 if( cmd->cmd_len == 12 ) {
713 ((u32)cmd->cmnd[2] << 24) |
714 ((u32)cmd->cmnd[3] << 16) |
715 ((u32)cmd->cmnd[4] << 8) |
718 mbox->m_out.numsectors =
719 ((u32)cmd->cmnd[6] << 24) |
720 ((u32)cmd->cmnd[7] << 16) |
721 ((u32)cmd->cmnd[8] << 8) |
725 if (*cmd->cmnd == READ_12) {
726 adapter->nreads[ldrv_num%0x80]++;
727 adapter->nreadblocks[ldrv_num%0x80] +=
728 mbox->m_out.numsectors;
730 adapter->nwrites[ldrv_num%0x80]++;
731 adapter->nwriteblocks[ldrv_num%0x80] +=
732 mbox->m_out.numsectors;
738 * If it is a read command
740 if( (*cmd->cmnd & 0x0F) == 0x08 ) {
741 scb->dma_direction = PCI_DMA_FROMDEVICE;
744 scb->dma_direction = PCI_DMA_TODEVICE;
747 /* Calculate Scatter-Gather info */
748 mbox->m_out.numsgelements = mega_build_sglist(adapter, scb,
749 (u32 *)&mbox->m_out.xferaddr, (u32 *)&seg);
753 #if MEGA_HAVE_CLUSTERING
754 case RESERVE: /* Fall through */
758 * Do we support clustering and is the support enabled
760 if( ! adapter->has_cluster ) {
762 cmd->result = (DID_BAD_TARGET << 16);
767 /* Allocate a SCB and initialize mailbox */
768 if(!(scb = mega_allocate_scb(adapter, cmd))) {
770 cmd->result = (DID_ERROR << 16);
777 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
778 scb->raw_mbox[2] = ( *cmd->cmnd == RESERVE ) ?
779 MEGA_RESERVE_LD : MEGA_RELEASE_LD;
781 scb->raw_mbox[3] = ldrv_num;
783 scb->dma_direction = PCI_DMA_NONE;
789 cmd->result = (DID_BAD_TARGET << 16);
796 * Passthru drive commands
799 /* Allocate a SCB and initialize passthru */
800 if(!(scb = mega_allocate_scb(adapter, cmd))) {
802 cmd->result = (DID_ERROR << 16);
809 mbox = (mbox_t *)scb->raw_mbox;
810 memset(mbox, 0, sizeof(scb->raw_mbox));
812 if( adapter->support_ext_cdb ) {
814 epthru = mega_prepare_extpassthru(adapter, scb, cmd,
817 mbox->m_out.cmd = MEGA_MBOXCMD_EXTPTHRU;
819 mbox->m_out.xferaddr = scb->epthru_dma_addr;
824 pthru = mega_prepare_passthru(adapter, scb, cmd,
827 /* Initialize mailbox */
828 if( adapter->has_64bit_addr ) {
829 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
832 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
835 mbox->m_out.xferaddr = scb->pthru_dma_addr;
845 * mega_prepare_passthru()
846 * @adapter - pointer to our soft state
847 * @scb - our scsi control block
848 * @cmd - scsi command from the mid-layer
849 * @channel - actual channel on the controller
850 * @target - actual id on the controller.
852 * prepare a command for the scsi physical devices.
854 static mega_passthru *
855 mega_prepare_passthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
856 int channel, int target)
858 mega_passthru *pthru;
861 memset(pthru, 0, sizeof (mega_passthru));
863 /* 0=6sec/1=60sec/2=10min/3=3hrs */
867 pthru->reqsenselen = 14;
868 pthru->islogical = 0;
870 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
872 pthru->target = (adapter->flag & BOARD_40LD) ?
873 (channel << 4) | target : target;
875 pthru->cdblen = cmd->cmd_len;
876 pthru->logdrv = cmd->device->lun;
878 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
880 /* Not sure about the direction */
881 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
883 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
884 switch (cmd->cmnd[0]) {
887 if(!(adapter->flag & (1L << cmd->device->channel))) {
890 "scsi%d: scanning scsi channel %d [P%d] ",
891 adapter->host->host_no,
892 cmd->device->channel, channel);
893 printk("for physical devices.\n");
895 adapter->flag |= (1L << cmd->device->channel);
899 pthru->numsgelements = mega_build_sglist(adapter, scb,
900 &pthru->dataxferaddr, &pthru->dataxferlen);
908 * mega_prepare_extpassthru()
909 * @adapter - pointer to our soft state
910 * @scb - our scsi control block
911 * @cmd - scsi command from the mid-layer
912 * @channel - actual channel on the controller
913 * @target - actual id on the controller.
915 * prepare a command for the scsi physical devices. This rountine prepares
916 * commands for devices which can take extended CDBs (>10 bytes)
918 static mega_ext_passthru *
919 mega_prepare_extpassthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
920 int channel, int target)
922 mega_ext_passthru *epthru;
924 epthru = scb->epthru;
925 memset(epthru, 0, sizeof(mega_ext_passthru));
927 /* 0=6sec/1=60sec/2=10min/3=3hrs */
931 epthru->reqsenselen = 14;
932 epthru->islogical = 0;
934 epthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
935 epthru->target = (adapter->flag & BOARD_40LD) ?
936 (channel << 4) | target : target;
938 epthru->cdblen = cmd->cmd_len;
939 epthru->logdrv = cmd->device->lun;
941 memcpy(epthru->cdb, cmd->cmnd, cmd->cmd_len);
943 /* Not sure about the direction */
944 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
946 switch(cmd->cmnd[0]) {
949 if(!(adapter->flag & (1L << cmd->device->channel))) {
952 "scsi%d: scanning scsi channel %d [P%d] ",
953 adapter->host->host_no,
954 cmd->device->channel, channel);
955 printk("for physical devices.\n");
957 adapter->flag |= (1L << cmd->device->channel);
961 epthru->numsgelements = mega_build_sglist(adapter, scb,
962 &epthru->dataxferaddr, &epthru->dataxferlen);
971 * mega_allocate_scb()
972 * @adapter - pointer to our soft state
973 * @cmd - scsi command from the mid-layer
975 * Allocate a SCB structure. This is the central structure for controller
978 static inline scb_t *
979 mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd)
981 struct list_head *head = &adapter->free_list;
984 /* Unlink command from Free List */
985 if( !list_empty(head) ) {
987 scb = list_entry(head->next, scb_t, list);
989 list_del_init(head->next);
991 scb->state = SCB_ACTIVE;
993 scb->dma_type = MEGA_DMA_TYPE_NONE;
1004 * @adapter - pointer to our soft state
1006 * Runs through the list of pending requests.
1009 mega_runpendq(adapter_t *adapter)
1011 if(!list_empty(&adapter->pending_list))
1012 __mega_runpendq(adapter);
1016 __mega_runpendq(adapter_t *adapter)
1019 struct list_head *pos, *next;
1021 /* Issue any pending commands to the card */
1022 list_for_each_safe(pos, next, &adapter->pending_list) {
1024 scb = list_entry(pos, scb_t, list);
1026 if( !(scb->state & SCB_ISSUED) ) {
1028 if( issue_scb(adapter, scb) != 0 )
1039 * @adapter - pointer to our soft state
1040 * @scb - scsi control block
1042 * Post a command to the card if the mailbox is available, otherwise return
1043 * busy. We also take the scb from the pending list if the mailbox is
1047 issue_scb(adapter_t *adapter, scb_t *scb)
1049 volatile mbox64_t *mbox64 = adapter->mbox64;
1050 volatile mbox_t *mbox = adapter->mbox;
1053 if(unlikely(mbox->m_in.busy)) {
1057 } while( mbox->m_in.busy && (i < max_mbox_busy_wait) );
1059 if(mbox->m_in.busy) return -1;
1062 /* Copy mailbox data into host structure */
1063 memcpy((char *)&mbox->m_out, (char *)scb->raw_mbox,
1064 sizeof(struct mbox_out));
1066 mbox->m_out.cmdid = scb->idx; /* Set cmdid */
1067 mbox->m_in.busy = 1; /* Set busy */
1071 * Increment the pending queue counter
1073 atomic_inc(&adapter->pend_cmds);
1075 switch (mbox->m_out.cmd) {
1076 case MEGA_MBOXCMD_LREAD64:
1077 case MEGA_MBOXCMD_LWRITE64:
1078 case MEGA_MBOXCMD_PASSTHRU64:
1079 case MEGA_MBOXCMD_EXTPTHRU:
1080 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1081 mbox64->xfer_segment_hi = 0;
1082 mbox->m_out.xferaddr = 0xFFFFFFFF;
1085 mbox64->xfer_segment_lo = 0;
1086 mbox64->xfer_segment_hi = 0;
1092 scb->state |= SCB_ISSUED;
1094 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1095 mbox->m_in.poll = 0;
1097 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1100 irq_enable(adapter);
1101 issue_command(adapter);
1110 * @adapter - pointer to our soft state
1111 * @raw_mbox - the mailbox
1113 * Issue a scb in synchronous and non-interrupt mode
1116 issue_scb_block(adapter_t *adapter, u_char *raw_mbox)
1118 volatile mbox64_t *mbox64 = adapter->mbox64;
1119 volatile mbox_t *mbox = adapter->mbox;
1122 /* Wait until mailbox is free */
1123 if(mega_busywait_mbox (adapter))
1124 goto bug_blocked_mailbox;
1126 /* Copy mailbox data into host structure */
1127 memcpy((char *) mbox, raw_mbox, sizeof(struct mbox_out));
1128 mbox->m_out.cmdid = 0xFE;
1129 mbox->m_in.busy = 1;
1131 switch (raw_mbox[0]) {
1132 case MEGA_MBOXCMD_LREAD64:
1133 case MEGA_MBOXCMD_LWRITE64:
1134 case MEGA_MBOXCMD_PASSTHRU64:
1135 case MEGA_MBOXCMD_EXTPTHRU:
1136 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1137 mbox64->xfer_segment_hi = 0;
1138 mbox->m_out.xferaddr = 0xFFFFFFFF;
1141 mbox64->xfer_segment_lo = 0;
1142 mbox64->xfer_segment_hi = 0;
1145 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1146 mbox->m_in.poll = 0;
1148 mbox->m_in.numstatus = 0xFF;
1149 mbox->m_in.status = 0xFF;
1150 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1152 while((volatile u8)mbox->m_in.numstatus == 0xFF)
1155 mbox->m_in.numstatus = 0xFF;
1157 while( (volatile u8)mbox->m_in.poll != 0x77 )
1160 mbox->m_in.poll = 0;
1161 mbox->m_in.ack = 0x77;
1163 WRINDOOR(adapter, adapter->mbox_dma | 0x2);
1165 while(RDINDOOR(adapter) & 0x2)
1169 irq_disable(adapter);
1170 issue_command(adapter);
1172 while (!((byte = irq_state(adapter)) & INTR_VALID))
1175 set_irq_state(adapter, byte);
1176 irq_enable(adapter);
1180 return mbox->m_in.status;
1182 bug_blocked_mailbox:
1183 printk(KERN_WARNING "megaraid: Blocked mailbox......!!\n");
1190 * megaraid_isr_iomapped()
1192 * @devp - pointer to our soft state
1195 * Interrupt service routine for io-mapped controllers.
1196 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1197 * and service the completed commands.
1200 megaraid_isr_iomapped(int irq, void *devp, struct pt_regs *regs)
1202 adapter_t *adapter = devp;
1203 unsigned long flags;
1206 u8 completed[MAX_FIRMWARE_STATUS];
1212 * loop till F/W has more commands for us to complete.
1214 spin_lock_irqsave(&adapter->lock, flags);
1217 /* Check if a valid interrupt is pending */
1218 byte = irq_state(adapter);
1219 if( (byte & VALID_INTR_BYTE) == 0 ) {
1221 * No more pending commands
1225 set_irq_state(adapter, byte);
1227 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1230 adapter->mbox->m_in.numstatus = 0xFF;
1232 status = adapter->mbox->m_in.status;
1235 * decrement the pending queue counter
1237 atomic_sub(nstatus, &adapter->pend_cmds);
1239 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1242 /* Acknowledge interrupt */
1245 mega_cmd_done(adapter, completed, nstatus, status);
1247 mega_rundoneq(adapter);
1251 /* Loop through any pending requests */
1252 if(atomic_read(&adapter->quiescent) == 0) {
1253 mega_runpendq(adapter);
1260 spin_unlock_irqrestore(&adapter->lock, flags);
1262 return IRQ_RETVAL(handled);
1267 * megaraid_isr_memmapped()
1269 * @devp - pointer to our soft state
1272 * Interrupt service routine for memory-mapped controllers.
1273 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1274 * and service the completed commands.
1277 megaraid_isr_memmapped(int irq, void *devp, struct pt_regs *regs)
1279 adapter_t *adapter = devp;
1280 unsigned long flags;
1284 u8 completed[MAX_FIRMWARE_STATUS];
1289 * loop till F/W has more commands for us to complete.
1291 spin_lock_irqsave(&adapter->lock, flags);
1294 /* Check if a valid interrupt is pending */
1295 dword = RDOUTDOOR(adapter);
1296 if(dword != 0x10001234) {
1298 * No more pending commands
1302 WROUTDOOR(adapter, 0x10001234);
1304 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1308 adapter->mbox->m_in.numstatus = 0xFF;
1310 status = adapter->mbox->m_in.status;
1313 * decrement the pending queue counter
1315 atomic_sub(nstatus, &adapter->pend_cmds);
1317 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1320 /* Acknowledge interrupt */
1321 WRINDOOR(adapter, 0x2);
1325 while( RDINDOOR(adapter) & 0x02 ) cpu_relax();
1327 mega_cmd_done(adapter, completed, nstatus, status);
1329 mega_rundoneq(adapter);
1331 /* Loop through any pending requests */
1332 if(atomic_read(&adapter->quiescent) == 0) {
1333 mega_runpendq(adapter);
1340 spin_unlock_irqrestore(&adapter->lock, flags);
1342 return IRQ_RETVAL(handled);
1346 * @adapter - pointer to our soft state
1347 * @completed - array of ids of completed commands
1348 * @nstatus - number of completed commands
1349 * @status - status of the last command completed
1351 * Complete the comamnds and call the scsi mid-layer callback hooks.
1354 mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
1356 mega_ext_passthru *epthru = NULL;
1357 struct scatterlist *sgl;
1358 Scsi_Cmnd *cmd = NULL;
1359 mega_passthru *pthru = NULL;
1360 mbox_t *mbox = NULL;
1368 * for all the commands completed, call the mid-layer callback routine
1371 for( i = 0; i < nstatus; i++ ) {
1373 cmdid = completed[i];
1375 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1376 scb = &adapter->int_scb;
1378 mbox = (mbox_t *)scb->raw_mbox;
1381 * Internal command interface do not fire the extended
1382 * passthru or 64-bit passthru
1388 scb = &adapter->scb_list[cmdid];
1391 * Make sure f/w has completed a valid command
1393 if( !(scb->state & SCB_ISSUED) || scb->cmd == NULL ) {
1395 "megaraid: invalid command ");
1396 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1397 cmdid, scb->state, scb->cmd);
1403 * Was a abort issued for this command
1405 if( scb->state & SCB_ABORT ) {
1408 "megaraid: aborted cmd %lx[%x] complete.\n",
1409 scb->cmd->serial_number, scb->idx);
1411 scb->cmd->result = (DID_ABORT << 16);
1413 list_add_tail(SCSI_LIST(scb->cmd),
1414 &adapter->completed_list);
1416 mega_free_scb(adapter, scb);
1422 * Was a reset issued for this command
1424 if( scb->state & SCB_RESET ) {
1427 "megaraid: reset cmd %lx[%x] complete.\n",
1428 scb->cmd->serial_number, scb->idx);
1430 scb->cmd->result = (DID_RESET << 16);
1432 list_add_tail(SCSI_LIST(scb->cmd),
1433 &adapter->completed_list);
1435 mega_free_scb (adapter, scb);
1442 epthru = scb->epthru;
1443 mbox = (mbox_t *)scb->raw_mbox;
1448 int logdrv = mbox->m_out.logdrv;
1450 islogical = adapter->logdrv_chan[cmd->channel];
1452 * Maintain an error counter for the logical drive.
1453 * Some application like SNMP agent need such
1456 if( status && islogical && (cmd->cmnd[0] == READ_6 ||
1457 cmd->cmnd[0] == READ_10 ||
1458 cmd->cmnd[0] == READ_12)) {
1460 * Logical drive number increases by 0x80 when
1461 * a logical drive is deleted
1463 adapter->rd_errors[logdrv%0x80]++;
1466 if( status && islogical && (cmd->cmnd[0] == WRITE_6 ||
1467 cmd->cmnd[0] == WRITE_10 ||
1468 cmd->cmnd[0] == WRITE_12)) {
1470 * Logical drive number increases by 0x80 when
1471 * a logical drive is deleted
1473 adapter->wr_errors[logdrv%0x80]++;
1481 * Do not return the presence of hard disk on the channel so,
1482 * inquiry sent, and returned data==hard disk or removable
1483 * hard disk and not logical, request should return failure! -
1486 islogical = adapter->logdrv_chan[cmd->device->channel];
1487 if( cmd->cmnd[0] == INQUIRY && !islogical ) {
1490 sgl = (struct scatterlist *)
1491 cmd->request_buffer;
1494 c = *(unsigned char *)
1495 page_address((&sgl[0])->page) +
1500 "megaraid: invalid sg.\n");
1505 c = *(u8 *)cmd->request_buffer;
1508 if(IS_RAID_CH(adapter, cmd->device->channel) &&
1509 ((c & 0x1F ) == TYPE_DISK)) {
1514 /* clear result; otherwise, success returns corrupt value */
1517 /* Convert MegaRAID status to Linux error code */
1519 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1520 cmd->result |= (DID_OK << 16);
1523 case 0x02: /* ERROR_ABORTED, i.e.
1524 SCSI_STATUS_CHECK_CONDITION */
1526 /* set sense_buffer and result fields */
1527 if( mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU ||
1528 mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU64 ) {
1530 memcpy(cmd->sense_buffer, pthru->reqsensearea,
1533 cmd->result = (DRIVER_SENSE << 24) |
1535 (CHECK_CONDITION << 1);
1538 if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
1540 memcpy(cmd->sense_buffer,
1541 epthru->reqsensearea, 14);
1543 cmd->result = (DRIVER_SENSE << 24) |
1545 (CHECK_CONDITION << 1);
1547 cmd->sense_buffer[0] = 0x70;
1548 cmd->sense_buffer[2] = ABORTED_COMMAND;
1549 cmd->result |= (CHECK_CONDITION << 1);
1554 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1556 cmd->result |= (DID_BUS_BUSY << 16) | status;
1560 #if MEGA_HAVE_CLUSTERING
1562 * If TEST_UNIT_READY fails, we know
1563 * MEGA_RESERVATION_STATUS failed
1565 if( cmd->cmnd[0] == TEST_UNIT_READY ) {
1566 cmd->result |= (DID_ERROR << 16) |
1567 (RESERVATION_CONFLICT << 1);
1571 * Error code returned is 1 if Reserve or Release
1572 * failed or the input parameter is invalid
1575 (cmd->cmnd[0] == RESERVE ||
1576 cmd->cmnd[0] == RELEASE) ) {
1578 cmd->result |= (DID_ERROR << 16) |
1579 (RESERVATION_CONFLICT << 1);
1583 cmd->result |= (DID_BAD_TARGET << 16)|status;
1587 * Only free SCBs for the commands coming down from the
1588 * mid-layer, not for which were issued internally
1590 * For internal command, restore the status returned by the
1591 * firmware so that user can interpret it.
1593 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1594 cmd->result = status;
1597 * Remove the internal command from the pending list
1599 list_del_init(&scb->list);
1600 scb->state = SCB_FREE;
1603 mega_free_scb(adapter, scb);
1606 /* Add Scsi_Command to end of completed queue */
1607 list_add_tail(SCSI_LIST(cmd), &adapter->completed_list);
1615 * Run through the list of completed requests and finish it
1618 mega_rundoneq (adapter_t *adapter)
1621 struct list_head *pos;
1623 list_for_each(pos, &adapter->completed_list) {
1625 Scsi_Pointer* spos = (Scsi_Pointer *)pos;
1627 cmd = list_entry(spos, Scsi_Cmnd, SCp);
1628 cmd->scsi_done(cmd);
1631 INIT_LIST_HEAD(&adapter->completed_list);
1636 * Free a SCB structure
1637 * Note: We assume the scsi commands associated with this scb is not free yet.
1640 mega_free_scb(adapter_t *adapter, scb_t *scb)
1642 switch( scb->dma_type ) {
1644 case MEGA_DMA_TYPE_NONE:
1647 case MEGA_BULK_DATA:
1648 pci_unmap_page(adapter->dev, scb->dma_h_bulkdata,
1649 scb->cmd->request_bufflen, scb->dma_direction);
1653 pci_unmap_sg(adapter->dev, scb->cmd->request_buffer,
1654 scb->cmd->use_sg, scb->dma_direction);
1662 * Remove from the pending list
1664 list_del_init(&scb->list);
1666 /* Link the scb back into free list */
1667 scb->state = SCB_FREE;
1670 list_add(&scb->list, &adapter->free_list);
1675 * Wait until the controller's mailbox is available
1678 mega_busywait_mbox (adapter_t *adapter)
1680 if (adapter->mbox->m_in.busy)
1681 return __mega_busywait_mbox(adapter);
1686 __mega_busywait_mbox (adapter_t *adapter)
1688 volatile mbox_t *mbox = adapter->mbox;
1691 for (counter = 0; counter < 10000; counter++) {
1692 if (!mbox->m_in.busy)
1694 udelay(100); yield();
1696 return -1; /* give up after 1 second */
1700 * Copies data to SGLIST
1701 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1704 mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len)
1706 struct scatterlist *sgl;
1708 unsigned long offset;
1715 /* Scatter-gather not used */
1716 if( !cmd->use_sg ) {
1718 page = virt_to_page(cmd->request_buffer);
1719 offset = offset_in_page(cmd->request_buffer);
1721 scb->dma_h_bulkdata = pci_map_page(adapter->dev,
1723 cmd->request_bufflen,
1724 scb->dma_direction);
1725 scb->dma_type = MEGA_BULK_DATA;
1728 * We need to handle special 64-bit commands that need a
1731 if( adapter->has_64bit_addr ) {
1732 scb->sgl64[0].address = scb->dma_h_bulkdata;
1733 scb->sgl64[0].length = cmd->request_bufflen;
1734 *buf = (u32)scb->sgl_dma_addr;
1735 *len = (u32)cmd->request_bufflen;
1739 *buf = (u32)scb->dma_h_bulkdata;
1740 *len = (u32)cmd->request_bufflen;
1745 sgl = (struct scatterlist *)cmd->request_buffer;
1748 * Copy Scatter-Gather list info into controller structure.
1750 * The number of sg elements returned must not exceed our limit
1752 sgcnt = pci_map_sg(adapter->dev, sgl, cmd->use_sg,
1753 scb->dma_direction);
1755 scb->dma_type = MEGA_SGLIST;
1757 if( sgcnt > adapter->sglen ) BUG();
1759 for( idx = 0; idx < sgcnt; idx++, sgl++ ) {
1761 if( adapter->has_64bit_addr ) {
1762 scb->sgl64[idx].address = sg_dma_address(sgl);
1763 scb->sgl64[idx].length = sg_dma_len(sgl);
1766 scb->sgl[idx].address = sg_dma_address(sgl);
1767 scb->sgl[idx].length = sg_dma_len(sgl);
1771 /* Reset pointer and length fields */
1772 *buf = scb->sgl_dma_addr;
1775 * For passthru command, dataxferlen must be set, even for commands
1778 *len = (u32)cmd->request_bufflen;
1780 /* Return count of SG requests */
1788 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1789 * Enquiry3 structures for later use
1792 mega_8_to_40ld(mraid_inquiry *inquiry, mega_inquiry3 *enquiry3,
1793 mega_product_info *product_info)
1797 product_info->max_commands = inquiry->adapter_info.max_commands;
1798 enquiry3->rebuild_rate = inquiry->adapter_info.rebuild_rate;
1799 product_info->nchannels = inquiry->adapter_info.nchannels;
1801 for (i = 0; i < 4; i++) {
1802 product_info->fw_version[i] =
1803 inquiry->adapter_info.fw_version[i];
1805 product_info->bios_version[i] =
1806 inquiry->adapter_info.bios_version[i];
1808 enquiry3->cache_flush_interval =
1809 inquiry->adapter_info.cache_flush_interval;
1811 product_info->dram_size = inquiry->adapter_info.dram_size;
1813 enquiry3->num_ldrv = inquiry->logdrv_info.num_ldrv;
1815 for (i = 0; i < MAX_LOGICAL_DRIVES_8LD; i++) {
1816 enquiry3->ldrv_size[i] = inquiry->logdrv_info.ldrv_size[i];
1817 enquiry3->ldrv_prop[i] = inquiry->logdrv_info.ldrv_prop[i];
1818 enquiry3->ldrv_state[i] = inquiry->logdrv_info.ldrv_state[i];
1821 for (i = 0; i < (MAX_PHYSICAL_DRIVES); i++)
1822 enquiry3->pdrv_state[i] = inquiry->pdrv_info.pdrv_state[i];
1826 mega_free_sgl(adapter_t *adapter)
1831 for(i = 0; i < adapter->max_cmds; i++) {
1833 scb = &adapter->scb_list[i];
1836 pci_free_consistent(adapter->dev,
1837 sizeof(mega_sgl64) * adapter->sglen,
1845 pci_free_consistent(adapter->dev, sizeof(mega_passthru),
1846 scb->pthru, scb->pthru_dma_addr);
1852 pci_free_consistent(adapter->dev,
1853 sizeof(mega_ext_passthru),
1854 scb->epthru, scb->epthru_dma_addr);
1864 * Get information about the card/driver
1867 megaraid_info(struct Scsi_Host *host)
1869 static char buffer[512];
1872 adapter = (adapter_t *)host->hostdata;
1875 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1876 adapter->fw_version, adapter->product_info.max_commands,
1877 adapter->host->max_id, adapter->host->max_channel,
1878 adapter->host->max_lun);
1883 * Abort a previous SCSI request. Only commands on the pending list can be
1884 * aborted. All the commands issued to the F/W must complete.
1887 megaraid_abort(Scsi_Cmnd *cmd)
1892 adapter = (adapter_t *)cmd->device->host->hostdata;
1894 rval = megaraid_abort_and_reset(adapter, cmd, SCB_ABORT);
1897 * This is required here to complete any completed requests
1898 * to be communicated over to the mid layer.
1900 mega_rundoneq(adapter);
1907 megaraid_reset(Scsi_Cmnd *cmd)
1913 adapter = (adapter_t *)cmd->device->host->hostdata;
1915 #if MEGA_HAVE_CLUSTERING
1916 mc.cmd = MEGA_CLUSTER_CMD;
1917 mc.opcode = MEGA_RESET_RESERVATIONS;
1919 spin_unlock_irq(&adapter->lock);
1920 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
1922 "megaraid: reservation reset failed.\n");
1925 printk(KERN_INFO "megaraid: reservation reset.\n");
1927 spin_lock_irq(&adapter->lock);
1930 rval = megaraid_abort_and_reset(adapter, cmd, SCB_RESET);
1933 * This is required here to complete any completed requests
1934 * to be communicated over to the mid layer.
1936 mega_rundoneq(adapter);
1944 * megaraid_abort_and_reset()
1945 * @adapter - megaraid soft state
1946 * @cmd - scsi command to be aborted or reset
1947 * @aor - abort or reset flag
1949 * Try to locate the scsi command in the pending queue. If found and is not
1950 * issued to the controller, abort/reset it. Otherwise return failure
1953 megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1955 struct list_head *pos, *next;
1958 printk(KERN_WARNING "megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
1959 (aor == SCB_ABORT)? "ABORTING":"RESET", cmd->serial_number,
1960 cmd->cmnd[0], cmd->device->channel,
1961 cmd->device->id, cmd->device->lun);
1963 if(list_empty(&adapter->pending_list))
1966 list_for_each_safe(pos, next, &adapter->pending_list) {
1968 scb = list_entry(pos, scb_t, list);
1970 if (scb->cmd == cmd) { /* Found command */
1975 * Check if this command has firmare owenership. If
1976 * yes, we cannot reset this command. Whenever, f/w
1977 * completes this command, we will return appropriate
1980 if( scb->state & SCB_ISSUED ) {
1983 "megaraid: %s-%lx[%x], fw owner.\n",
1984 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1985 cmd->serial_number, scb->idx);
1992 * Not yet issued! Remove from the pending
1996 "megaraid: %s-%lx[%x], driver owner.\n",
1997 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1998 cmd->serial_number, scb->idx);
2000 mega_free_scb(adapter, scb);
2002 if( aor == SCB_ABORT ) {
2003 cmd->result = (DID_ABORT << 16);
2006 cmd->result = (DID_RESET << 16);
2009 list_add_tail(SCSI_LIST(cmd),
2010 &adapter->completed_list);
2021 #ifdef CONFIG_PROC_FS
2022 /* Following code handles /proc fs */
2024 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2025 S_IRUSR | S_IFREG, \
2026 controller_proc_dir_entry, \
2030 * mega_create_proc_entry()
2031 * @index - index in soft state array
2032 * @parent - parent node for this /proc entry
2034 * Creates /proc entries for our controllers.
2037 mega_create_proc_entry(int index, struct proc_dir_entry *parent)
2039 struct proc_dir_entry *controller_proc_dir_entry = NULL;
2040 u8 string[64] = { 0 };
2041 adapter_t *adapter = hba_soft_state[index];
2043 sprintf(string, "hba%d", adapter->host->host_no);
2045 controller_proc_dir_entry =
2046 adapter->controller_proc_dir_entry = proc_mkdir(string, parent);
2048 if(!controller_proc_dir_entry) {
2049 printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
2052 adapter->proc_read = CREATE_READ_PROC("config", proc_read_config);
2053 adapter->proc_stat = CREATE_READ_PROC("stat", proc_read_stat);
2054 adapter->proc_mbox = CREATE_READ_PROC("mailbox", proc_read_mbox);
2055 #if MEGA_HAVE_ENH_PROC
2056 adapter->proc_rr = CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate);
2057 adapter->proc_battery = CREATE_READ_PROC("battery-status",
2061 * Display each physical drive on its channel
2063 adapter->proc_pdrvstat[0] = CREATE_READ_PROC("diskdrives-ch0",
2065 adapter->proc_pdrvstat[1] = CREATE_READ_PROC("diskdrives-ch1",
2067 adapter->proc_pdrvstat[2] = CREATE_READ_PROC("diskdrives-ch2",
2069 adapter->proc_pdrvstat[3] = CREATE_READ_PROC("diskdrives-ch3",
2073 * Display a set of up to 10 logical drive through each of following
2076 adapter->proc_rdrvstat[0] = CREATE_READ_PROC("raiddrives-0-9",
2078 adapter->proc_rdrvstat[1] = CREATE_READ_PROC("raiddrives-10-19",
2080 adapter->proc_rdrvstat[2] = CREATE_READ_PROC("raiddrives-20-29",
2082 adapter->proc_rdrvstat[3] = CREATE_READ_PROC("raiddrives-30-39",
2089 * proc_read_config()
2090 * @page - buffer to write the data in
2091 * @start - where the actual data has been written in page
2092 * @offset - same meaning as the read system call
2093 * @count - same meaning as the read system call
2094 * @eof - set if no more data needs to be returned
2095 * @data - pointer to our soft state
2097 * Display configuration information about the controller.
2100 proc_read_config(char *page, char **start, off_t offset, int count, int *eof,
2104 adapter_t *adapter = (adapter_t *)data;
2107 len += sprintf(page+len, "%s", MEGARAID_VERSION);
2109 if(adapter->product_info.product_name[0])
2110 len += sprintf(page+len, "%s\n",
2111 adapter->product_info.product_name);
2113 len += sprintf(page+len, "Controller Type: ");
2115 if( adapter->flag & BOARD_MEMMAP ) {
2116 len += sprintf(page+len,
2117 "438/466/467/471/493/518/520/531/532\n");
2120 len += sprintf(page+len,
2124 if(adapter->flag & BOARD_40LD) {
2125 len += sprintf(page+len,
2126 "Controller Supports 40 Logical Drives\n");
2129 if(adapter->flag & BOARD_64BIT) {
2130 len += sprintf(page+len,
2131 "Controller capable of 64-bit memory addressing\n");
2133 if( adapter->has_64bit_addr ) {
2134 len += sprintf(page+len,
2135 "Controller using 64-bit memory addressing\n");
2138 len += sprintf(page+len,
2139 "Controller is not using 64-bit memory addressing\n");
2142 len += sprintf(page+len, "Base = %08lx, Irq = %d, ", adapter->base,
2143 adapter->host->irq);
2145 len += sprintf(page+len, "Logical Drives = %d, Channels = %d\n",
2146 adapter->numldrv, adapter->product_info.nchannels);
2148 len += sprintf(page+len, "Version =%s:%s, DRAM = %dMb\n",
2149 adapter->fw_version, adapter->bios_version,
2150 adapter->product_info.dram_size);
2152 len += sprintf(page+len,
2153 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2154 adapter->product_info.max_commands, adapter->max_cmds);
2156 len += sprintf(page+len, "support_ext_cdb = %d\n",
2157 adapter->support_ext_cdb);
2158 len += sprintf(page+len, "support_random_del = %d\n",
2159 adapter->support_random_del);
2160 len += sprintf(page+len, "boot_ldrv_enabled = %d\n",
2161 adapter->boot_ldrv_enabled);
2162 len += sprintf(page+len, "boot_ldrv = %d\n",
2163 adapter->boot_ldrv);
2164 len += sprintf(page+len, "boot_pdrv_enabled = %d\n",
2165 adapter->boot_pdrv_enabled);
2166 len += sprintf(page+len, "boot_pdrv_ch = %d\n",
2167 adapter->boot_pdrv_ch);
2168 len += sprintf(page+len, "boot_pdrv_tgt = %d\n",
2169 adapter->boot_pdrv_tgt);
2170 len += sprintf(page+len, "quiescent = %d\n",
2171 atomic_read(&adapter->quiescent));
2172 len += sprintf(page+len, "has_cluster = %d\n",
2173 adapter->has_cluster);
2175 len += sprintf(page+len, "\nModule Parameters:\n");
2176 len += sprintf(page+len, "max_cmd_per_lun = %d\n",
2178 len += sprintf(page+len, "max_sectors_per_io = %d\n",
2179 max_sectors_per_io);
2190 * @page - buffer to write the data in
2191 * @start - where the actual data has been written in page
2192 * @offset - same meaning as the read system call
2193 * @count - same meaning as the read system call
2194 * @eof - set if no more data needs to be returned
2195 * @data - pointer to our soft state
2197 * Diaplay statistical information about the I/O activity.
2200 proc_read_stat(char *page, char **start, off_t offset, int count, int *eof,
2207 i = 0; /* avoid compilation warnings */
2209 adapter = (adapter_t *)data;
2211 len = sprintf(page, "Statistical Information for this controller\n");
2212 len += sprintf(page+len, "pend_cmds = %d\n",
2213 atomic_read(&adapter->pend_cmds));
2215 for(i = 0; i < adapter->numldrv; i++) {
2216 len += sprintf(page+len, "Logical Drive %d:\n", i);
2218 len += sprintf(page+len,
2219 "\tReads Issued = %lu, Writes Issued = %lu\n",
2220 adapter->nreads[i], adapter->nwrites[i]);
2222 len += sprintf(page+len,
2223 "\tSectors Read = %lu, Sectors Written = %lu\n",
2224 adapter->nreadblocks[i], adapter->nwriteblocks[i]);
2226 len += sprintf(page+len,
2227 "\tRead errors = %lu, Write errors = %lu\n\n",
2228 adapter->rd_errors[i], adapter->wr_errors[i]);
2231 len += sprintf(page+len,
2232 "IO and error counters not compiled in driver.\n");
2243 * @page - buffer to write the data in
2244 * @start - where the actual data has been written in page
2245 * @offset - same meaning as the read system call
2246 * @count - same meaning as the read system call
2247 * @eof - set if no more data needs to be returned
2248 * @data - pointer to our soft state
2250 * Display mailbox information for the last command issued. This information
2251 * is good for debugging.
2254 proc_read_mbox(char *page, char **start, off_t offset, int count, int *eof,
2258 adapter_t *adapter = (adapter_t *)data;
2259 volatile mbox_t *mbox = adapter->mbox;
2262 len = sprintf(page, "Contents of Mail Box Structure\n");
2263 len += sprintf(page+len, " Fw Command = 0x%02x\n",
2265 len += sprintf(page+len, " Cmd Sequence = 0x%02x\n",
2267 len += sprintf(page+len, " No of Sectors= %04d\n",
2268 mbox->m_out.numsectors);
2269 len += sprintf(page+len, " LBA = 0x%02x\n",
2271 len += sprintf(page+len, " DTA = 0x%08x\n",
2272 mbox->m_out.xferaddr);
2273 len += sprintf(page+len, " Logical Drive= 0x%02x\n",
2274 mbox->m_out.logdrv);
2275 len += sprintf(page+len, " No of SG Elmt= 0x%02x\n",
2276 mbox->m_out.numsgelements);
2277 len += sprintf(page+len, " Busy = %01x\n",
2279 len += sprintf(page+len, " Status = 0x%02x\n",
2289 * proc_rebuild_rate()
2290 * @page - buffer to write the data in
2291 * @start - where the actual data has been written in page
2292 * @offset - same meaning as the read system call
2293 * @count - same meaning as the read system call
2294 * @eof - set if no more data needs to be returned
2295 * @data - pointer to our soft state
2297 * Display current rebuild rate
2300 proc_rebuild_rate(char *page, char **start, off_t offset, int count, int *eof,
2303 adapter_t *adapter = (adapter_t *)data;
2304 dma_addr_t dma_handle;
2306 struct pci_dev *pdev;
2309 if( make_local_pdev(adapter, &pdev) != 0 ) {
2314 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2315 free_local_pdev(pdev);
2320 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2322 len = sprintf(page, "Adapter inquiry failed.\n");
2324 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2326 mega_free_inquiry(inquiry, dma_handle, pdev);
2328 free_local_pdev(pdev);
2335 if( adapter->flag & BOARD_40LD ) {
2336 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2337 ((mega_inquiry3 *)inquiry)->rebuild_rate);
2340 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2341 ((mraid_ext_inquiry *)
2342 inquiry)->raid_inq.adapter_info.rebuild_rate);
2346 mega_free_inquiry(inquiry, dma_handle, pdev);
2348 free_local_pdev(pdev);
2358 * @page - buffer to write the data in
2359 * @start - where the actual data has been written in page
2360 * @offset - same meaning as the read system call
2361 * @count - same meaning as the read system call
2362 * @eof - set if no more data needs to be returned
2363 * @data - pointer to our soft state
2365 * Display information about the battery module on the controller.
2368 proc_battery(char *page, char **start, off_t offset, int count, int *eof,
2371 adapter_t *adapter = (adapter_t *)data;
2372 dma_addr_t dma_handle;
2374 struct pci_dev *pdev;
2375 u8 battery_status = 0;
2379 if( make_local_pdev(adapter, &pdev) != 0 ) {
2384 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2385 free_local_pdev(pdev);
2390 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2392 len = sprintf(page, "Adapter inquiry failed.\n");
2394 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2396 mega_free_inquiry(inquiry, dma_handle, pdev);
2398 free_local_pdev(pdev);
2405 if( adapter->flag & BOARD_40LD ) {
2406 battery_status = ((mega_inquiry3 *)inquiry)->battery_status;
2409 battery_status = ((mraid_ext_inquiry *)inquiry)->
2410 raid_inq.adapter_info.battery_status;
2414 * Decode the battery status
2416 sprintf(str, "Battery Status:[%d]", battery_status);
2418 if(battery_status == MEGA_BATT_CHARGE_DONE)
2419 strcat(str, " Charge Done");
2421 if(battery_status & MEGA_BATT_MODULE_MISSING)
2422 strcat(str, " Module Missing");
2424 if(battery_status & MEGA_BATT_LOW_VOLTAGE)
2425 strcat(str, " Low Voltage");
2427 if(battery_status & MEGA_BATT_TEMP_HIGH)
2428 strcat(str, " Temperature High");
2430 if(battery_status & MEGA_BATT_PACK_MISSING)
2431 strcat(str, " Pack Missing");
2433 if(battery_status & MEGA_BATT_CHARGE_INPROG)
2434 strcat(str, " Charge In-progress");
2436 if(battery_status & MEGA_BATT_CHARGE_FAIL)
2437 strcat(str, " Charge Fail");
2439 if(battery_status & MEGA_BATT_CYCLES_EXCEEDED)
2440 strcat(str, " Cycles Exceeded");
2442 len = sprintf(page, "%s\n", str);
2445 mega_free_inquiry(inquiry, dma_handle, pdev);
2447 free_local_pdev(pdev);
2457 * @page - buffer to write the data in
2458 * @start - where the actual data has been written in page
2459 * @offset - same meaning as the read system call
2460 * @count - same meaning as the read system call
2461 * @eof - set if no more data needs to be returned
2462 * @data - pointer to our soft state
2464 * Display information about the physical drives on physical channel 0.
2467 proc_pdrv_ch0(char *page, char **start, off_t offset, int count, int *eof,
2470 adapter_t *adapter = (adapter_t *)data;
2474 return (proc_pdrv(adapter, page, 0));
2480 * @page - buffer to write the data in
2481 * @start - where the actual data has been written in page
2482 * @offset - same meaning as the read system call
2483 * @count - same meaning as the read system call
2484 * @eof - set if no more data needs to be returned
2485 * @data - pointer to our soft state
2487 * Display information about the physical drives on physical channel 1.
2490 proc_pdrv_ch1(char *page, char **start, off_t offset, int count, int *eof,
2493 adapter_t *adapter = (adapter_t *)data;
2497 return (proc_pdrv(adapter, page, 1));
2503 * @page - buffer to write the data in
2504 * @start - where the actual data has been written in page
2505 * @offset - same meaning as the read system call
2506 * @count - same meaning as the read system call
2507 * @eof - set if no more data needs to be returned
2508 * @data - pointer to our soft state
2510 * Display information about the physical drives on physical channel 2.
2513 proc_pdrv_ch2(char *page, char **start, off_t offset, int count, int *eof,
2516 adapter_t *adapter = (adapter_t *)data;
2520 return (proc_pdrv(adapter, page, 2));
2526 * @page - buffer to write the data in
2527 * @start - where the actual data has been written in page
2528 * @offset - same meaning as the read system call
2529 * @count - same meaning as the read system call
2530 * @eof - set if no more data needs to be returned
2531 * @data - pointer to our soft state
2533 * Display information about the physical drives on physical channel 3.
2536 proc_pdrv_ch3(char *page, char **start, off_t offset, int count, int *eof,
2539 adapter_t *adapter = (adapter_t *)data;
2543 return (proc_pdrv(adapter, page, 3));
2549 * @page - buffer to write the data in
2550 * @adapter - pointer to our soft state
2552 * Display information about the physical drives.
2555 proc_pdrv(adapter_t *adapter, char *page, int channel)
2557 dma_addr_t dma_handle;
2559 dma_addr_t scsi_inq_dma_handle;
2561 struct pci_dev *pdev;
2570 if( make_local_pdev(adapter, &pdev) != 0 ) {
2574 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2578 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2579 len = sprintf(page, "Adapter inquiry failed.\n");
2581 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2587 scsi_inq = pci_alloc_consistent(pdev, 256, &scsi_inq_dma_handle);
2589 if( scsi_inq == NULL ) {
2590 len = sprintf(page, "memory not available for scsi inq.\n");
2595 if( adapter->flag & BOARD_40LD ) {
2596 pdrv_state = ((mega_inquiry3 *)inquiry)->pdrv_state;
2599 pdrv_state = ((mraid_ext_inquiry *)inquiry)->
2600 raid_inq.pdrv_info.pdrv_state;
2603 max_channels = adapter->product_info.nchannels;
2605 if( channel >= max_channels ) {
2609 for( tgt = 0; tgt <= MAX_TARGET; tgt++ ) {
2611 i = channel*16 + tgt;
2613 state = *(pdrv_state + i);
2615 switch( state & 0x0F ) {
2619 "Channel:%2d Id:%2d State: Online",
2625 "Channel:%2d Id:%2d State: Failed",
2631 "Channel:%2d Id:%2d State: Rebuild",
2637 "Channel:%2d Id:%2d State: Hot spare",
2643 "Channel:%2d Id:%2d State: Un-configured",
2650 * This interface displays inquiries for disk drives
2651 * only. Inquries for logical drives and non-disk
2652 * devices are available through /proc/scsi/scsi
2654 memset(scsi_inq, 0, 256);
2655 if( mega_internal_dev_inquiry(adapter, channel, tgt,
2656 scsi_inq_dma_handle) ||
2657 (scsi_inq[0] & 0x1F) != TYPE_DISK ) {
2662 * Check for overflow. We print less than 240
2663 * characters for inquiry
2665 if( (len + 240) >= PAGE_SIZE ) break;
2667 len += sprintf(page+len, "%s.\n", str);
2669 len += mega_print_inquiry(page+len, scsi_inq);
2673 pci_free_consistent(pdev, 256, scsi_inq, scsi_inq_dma_handle);
2675 mega_free_inquiry(inquiry, dma_handle, pdev);
2677 free_local_pdev(pdev);
2684 * Display scsi inquiry
2687 mega_print_inquiry(char *page, char *scsi_inq)
2692 len = sprintf(page, " Vendor: ");
2693 for( i = 8; i < 16; i++ ) {
2694 len += sprintf(page+len, "%c", scsi_inq[i]);
2697 len += sprintf(page+len, " Model: ");
2699 for( i = 16; i < 32; i++ ) {
2700 len += sprintf(page+len, "%c", scsi_inq[i]);
2703 len += sprintf(page+len, " Rev: ");
2705 for( i = 32; i < 36; i++ ) {
2706 len += sprintf(page+len, "%c", scsi_inq[i]);
2709 len += sprintf(page+len, "\n");
2711 i = scsi_inq[0] & 0x1f;
2713 len += sprintf(page+len, " Type: %s ",
2714 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] :
2717 len += sprintf(page+len,
2718 " ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
2720 if( (scsi_inq[2] & 0x07) == 1 && (scsi_inq[3] & 0x0f) == 1 )
2721 len += sprintf(page+len, " CCS\n");
2723 len += sprintf(page+len, "\n");
2731 * @page - buffer to write the data in
2732 * @start - where the actual data has been written in page
2733 * @offset - same meaning as the read system call
2734 * @count - same meaning as the read system call
2735 * @eof - set if no more data needs to be returned
2736 * @data - pointer to our soft state
2738 * Display real time information about the logical drives 0 through 9.
2741 proc_rdrv_10(char *page, char **start, off_t offset, int count, int *eof,
2744 adapter_t *adapter = (adapter_t *)data;
2748 return (proc_rdrv(adapter, page, 0, 9));
2754 * @page - buffer to write the data in
2755 * @start - where the actual data has been written in page
2756 * @offset - same meaning as the read system call
2757 * @count - same meaning as the read system call
2758 * @eof - set if no more data needs to be returned
2759 * @data - pointer to our soft state
2761 * Display real time information about the logical drives 0 through 9.
2764 proc_rdrv_20(char *page, char **start, off_t offset, int count, int *eof,
2767 adapter_t *adapter = (adapter_t *)data;
2771 return (proc_rdrv(adapter, page, 10, 19));
2777 * @page - buffer to write the data in
2778 * @start - where the actual data has been written in page
2779 * @offset - same meaning as the read system call
2780 * @count - same meaning as the read system call
2781 * @eof - set if no more data needs to be returned
2782 * @data - pointer to our soft state
2784 * Display real time information about the logical drives 0 through 9.
2787 proc_rdrv_30(char *page, char **start, off_t offset, int count, int *eof,
2790 adapter_t *adapter = (adapter_t *)data;
2794 return (proc_rdrv(adapter, page, 20, 29));
2800 * @page - buffer to write the data in
2801 * @start - where the actual data has been written in page
2802 * @offset - same meaning as the read system call
2803 * @count - same meaning as the read system call
2804 * @eof - set if no more data needs to be returned
2805 * @data - pointer to our soft state
2807 * Display real time information about the logical drives 0 through 9.
2810 proc_rdrv_40(char *page, char **start, off_t offset, int count, int *eof,
2813 adapter_t *adapter = (adapter_t *)data;
2817 return (proc_rdrv(adapter, page, 30, 39));
2823 * @page - buffer to write the data in
2824 * @adapter - pointer to our soft state
2825 * @start - starting logical drive to display
2826 * @end - ending logical drive to display
2828 * We do not print the inquiry information since its already available through
2829 * /proc/scsi/scsi interface
2832 proc_rdrv(adapter_t *adapter, char *page, int start, int end )
2834 dma_addr_t dma_handle;
2835 logdrv_param *lparam;
2838 dma_addr_t disk_array_dma_handle;
2840 struct pci_dev *pdev;
2847 if( make_local_pdev(adapter, &pdev) != 0 ) {
2851 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2852 free_local_pdev(pdev);
2856 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2858 len = sprintf(page, "Adapter inquiry failed.\n");
2860 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2862 mega_free_inquiry(inquiry, dma_handle, pdev);
2864 free_local_pdev(pdev);
2869 memset(&mc, 0, sizeof(megacmd_t));
2871 if( adapter->flag & BOARD_40LD ) {
2872 array_sz = sizeof(disk_array_40ld);
2874 rdrv_state = ((mega_inquiry3 *)inquiry)->ldrv_state;
2876 num_ldrv = ((mega_inquiry3 *)inquiry)->num_ldrv;
2879 array_sz = sizeof(disk_array_8ld);
2881 rdrv_state = ((mraid_ext_inquiry *)inquiry)->
2882 raid_inq.logdrv_info.ldrv_state;
2884 num_ldrv = ((mraid_ext_inquiry *)inquiry)->
2885 raid_inq.logdrv_info.num_ldrv;
2888 disk_array = pci_alloc_consistent(pdev, array_sz,
2889 &disk_array_dma_handle);
2891 if( disk_array == NULL ) {
2892 len = sprintf(page, "memory not available.\n");
2894 mega_free_inquiry(inquiry, dma_handle, pdev);
2896 free_local_pdev(pdev);
2901 mc.xferaddr = (u32)disk_array_dma_handle;
2903 if( adapter->flag & BOARD_40LD ) {
2904 mc.cmd = FC_NEW_CONFIG;
2905 mc.opcode = OP_DCMD_READ_CONFIG;
2907 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
2909 len = sprintf(page, "40LD read config failed.\n");
2911 mega_free_inquiry(inquiry, dma_handle, pdev);
2913 pci_free_consistent(pdev, array_sz, disk_array,
2914 disk_array_dma_handle);
2916 free_local_pdev(pdev);
2923 mc.cmd = NEW_READ_CONFIG_8LD;
2925 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
2927 mc.cmd = READ_CONFIG_8LD;
2929 if( mega_internal_command(adapter, LOCK_INT, &mc,
2933 "8LD read config failed.\n");
2935 mega_free_inquiry(inquiry, dma_handle, pdev);
2937 pci_free_consistent(pdev, array_sz,
2939 disk_array_dma_handle);
2941 free_local_pdev(pdev);
2948 for( i = start; i < ( (end+1 < num_ldrv) ? end+1 : num_ldrv ); i++ ) {
2950 if( adapter->flag & BOARD_40LD ) {
2952 &((disk_array_40ld *)disk_array)->ldrv[i].lparam;
2956 &((disk_array_8ld *)disk_array)->ldrv[i].lparam;
2960 * Check for overflow. We print less than 240 characters for
2961 * information about each logical drive.
2963 if( (len + 240) >= PAGE_SIZE ) break;
2965 len += sprintf(page+len, "Logical drive:%2d:, ", i);
2967 switch( rdrv_state[i] & 0x0F ) {
2969 len += sprintf(page+len, "state: offline");
2973 len += sprintf(page+len, "state: degraded");
2977 len += sprintf(page+len, "state: optimal");
2981 len += sprintf(page+len, "state: deleted");
2985 len += sprintf(page+len, "state: unknown");
2990 * Check if check consistency or initialization is going on
2991 * for this logical drive.
2993 if( (rdrv_state[i] & 0xF0) == 0x20 ) {
2994 len += sprintf(page+len,
2995 ", check-consistency in progress");
2997 else if( (rdrv_state[i] & 0xF0) == 0x10 ) {
2998 len += sprintf(page+len,
2999 ", initialization in progress");
3002 len += sprintf(page+len, "\n");
3004 len += sprintf(page+len, "Span depth:%3d, ",
3005 lparam->span_depth);
3007 len += sprintf(page+len, "RAID level:%3d, ",
3010 len += sprintf(page+len, "Stripe size:%3d, ",
3011 lparam->stripe_sz ? lparam->stripe_sz/2: 128);
3013 len += sprintf(page+len, "Row size:%3d\n",
3017 len += sprintf(page+len, "Read Policy: ");
3019 switch(lparam->read_ahead) {
3022 len += sprintf(page+len, "No read ahead, ");
3026 len += sprintf(page+len, "Read ahead, ");
3029 case ADAP_READ_AHEAD:
3030 len += sprintf(page+len, "Adaptive, ");
3035 len += sprintf(page+len, "Write Policy: ");
3037 switch(lparam->write_mode) {
3039 case WRMODE_WRITE_THRU:
3040 len += sprintf(page+len, "Write thru, ");
3043 case WRMODE_WRITE_BACK:
3044 len += sprintf(page+len, "Write back, ");
3048 len += sprintf(page+len, "Cache Policy: ");
3050 switch(lparam->direct_io) {
3053 len += sprintf(page+len, "Cached IO\n\n");
3057 len += sprintf(page+len, "Direct IO\n\n");
3062 mega_free_inquiry(inquiry, dma_handle, pdev);
3064 pci_free_consistent(pdev, array_sz, disk_array,
3065 disk_array_dma_handle);
3067 free_local_pdev(pdev);
3076 * megaraid_biosparam()
3078 * Return the disk geometry for a particular disk
3081 megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
3082 sector_t capacity, int geom[])
3091 /* Get pointer to host config structure */
3092 adapter = (adapter_t *)sdev->host->hostdata;
3094 if (IS_RAID_CH(adapter, sdev->channel)) {
3095 /* Default heads (64) & sectors (32) */
3098 cylinders = (ulong)capacity / (heads * sectors);
3101 * Handle extended translation size for logical drives
3104 if ((ulong)capacity >= 0x200000) {
3107 cylinders = (ulong)capacity / (heads * sectors);
3113 geom[2] = cylinders;
3116 bh = scsi_bios_ptable(bdev);
3119 rval = scsi_partsize(bh, capacity,
3120 &geom[2], &geom[0], &geom[1]);
3127 "megaraid: invalid partition on this disk on channel %d\n",
3130 /* Default heads (64) & sectors (32) */
3133 cylinders = (ulong)capacity / (heads * sectors);
3135 /* Handle extended translation size for logical drives > 1Gb */
3136 if ((ulong)capacity >= 0x200000) {
3139 cylinders = (ulong)capacity / (heads * sectors);
3145 geom[2] = cylinders;
3153 * @adapter - pointer to our soft state
3155 * Allocate memory for the various pointers in the scb structures:
3156 * scatter-gather list pointer, passthru and extended passthru structure
3160 mega_init_scb(adapter_t *adapter)
3165 for( i = 0; i < adapter->max_cmds; i++ ) {
3167 scb = &adapter->scb_list[i];
3175 for( i = 0; i < adapter->max_cmds; i++ ) {
3177 scb = &adapter->scb_list[i];
3181 scb->sgl64 = pci_alloc_consistent(adapter->dev,
3182 sizeof(mega_sgl64) * adapter->sglen,
3183 &scb->sgl_dma_addr);
3185 scb->sgl = (mega_sglist *)scb->sgl64;
3188 printk(KERN_WARNING "RAID: Can't allocate sglist.\n");
3189 mega_free_sgl(adapter);
3193 scb->pthru = pci_alloc_consistent(adapter->dev,
3194 sizeof(mega_passthru),
3195 &scb->pthru_dma_addr);
3198 printk(KERN_WARNING "RAID: Can't allocate passthru.\n");
3199 mega_free_sgl(adapter);
3203 scb->epthru = pci_alloc_consistent(adapter->dev,
3204 sizeof(mega_ext_passthru),
3205 &scb->epthru_dma_addr);
3207 if( !scb->epthru ) {
3209 "Can't allocate extended passthru.\n");
3210 mega_free_sgl(adapter);
3215 scb->dma_type = MEGA_DMA_TYPE_NONE;
3219 * lock not required since we are loading the driver, so no
3220 * commands possible right now.
3222 scb->state = SCB_FREE;
3224 list_add(&scb->list, &adapter->free_list);
3236 * Routines for the character/ioctl interface to the driver. Find out if this
3237 * is a valid open. If yes, increment the module use count so that it cannot
3241 megadev_open (struct inode *inode, struct file *filep)
3244 * Only allow superuser to access private ioctl interface
3246 if( !capable(CAP_SYS_ADMIN) ) return -EACCES;
3254 * @inode - Our device inode
3256 * @cmd - ioctl command
3257 * @arg - user buffer
3259 * ioctl entry point for our private ioctl interface. We move the data in from
3260 * the user space, prepare the command (if necessary, convert the old MIMD
3261 * ioctl to new ioctl command), and issue a synchronous command to the
3265 megadev_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
3272 mega_passthru *upthru; /* user address for passthru */
3273 mega_passthru *pthru; /* copy user passthru here */
3274 dma_addr_t pthru_dma_hndl;
3275 void *data = NULL; /* data to be transferred */
3276 dma_addr_t data_dma_hndl; /* dma handle for data xfer area */
3281 struct pci_dev *pdev;
3283 ustats = NULL; /* avoid compilation warnings */
3287 * Make sure only USCSICMD are issued through this interface.
3288 * MIMD application would still fire different command.
3290 if( (_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD) ) {
3295 * Check and convert a possible MIMD command to NIT command.
3296 * mega_m_to_n() copies the data from the user space, so we do not
3297 * have to do it here.
3298 * NOTE: We will need some user address to copyout the data, therefore
3299 * the inteface layer will also provide us with the required user
3302 memset(&uioc, 0, sizeof(nitioctl_t));
3303 if( (rval = mega_m_to_n( (void *)arg, &uioc)) != 0 )
3307 switch( uioc.opcode ) {
3309 case GET_DRIVER_VER:
3310 if( put_user(driver_ver, (u32 *)uioc.uioc_uaddr) )
3316 if( put_user(hba_count, (u32 *)uioc.uioc_uaddr) )
3320 * Shucks. MIMD interface returns a positive value for number
3321 * of adapters. TODO: Change it to return 0 when there is no
3322 * applicatio using mimd interface.
3331 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3334 if( copy_to_user(uioc.uioc_uaddr, mcontroller+adapno,
3335 sizeof(struct mcontroller)) )
3345 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3348 adapter = hba_soft_state[adapno];
3350 ustats = (megastat_t *)uioc.uioc_uaddr;
3352 if( copy_from_user(&num_ldrv, &ustats->num_ldrv, sizeof(int)) )
3356 * Check for the validity of the logical drive number
3358 if( num_ldrv >= MAX_LOGICAL_DRIVES_40LD ) return -EINVAL;
3360 if( copy_to_user(ustats->nreads, adapter->nreads,
3361 num_ldrv*sizeof(u32)) )
3364 if( copy_to_user(ustats->nreadblocks, adapter->nreadblocks,
3365 num_ldrv*sizeof(u32)) )
3368 if( copy_to_user(ustats->nwrites, adapter->nwrites,
3369 num_ldrv*sizeof(u32)) )
3372 if( copy_to_user(ustats->nwriteblocks, adapter->nwriteblocks,
3373 num_ldrv*sizeof(u32)) )
3376 if( copy_to_user(ustats->rd_errors, adapter->rd_errors,
3377 num_ldrv*sizeof(u32)) )
3380 if( copy_to_user(ustats->wr_errors, adapter->wr_errors,
3381 num_ldrv*sizeof(u32)) )
3392 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3395 adapter = hba_soft_state[adapno];
3398 * Deletion of logical drive is a special case. The adapter
3399 * should be quiescent before this command is issued.
3401 if( uioc.uioc_rmbox[0] == FC_DEL_LOGDRV &&
3402 uioc.uioc_rmbox[2] == OP_DEL_LOGDRV ) {
3405 * Do we support this feature
3407 if( !adapter->support_random_del ) {
3408 printk(KERN_WARNING "megaraid: logdrv ");
3409 printk("delete on non-supporting F/W.\n");
3414 rval = mega_del_logdrv( adapter, uioc.uioc_rmbox[3] );
3417 memset(&mc, 0, sizeof(megacmd_t));
3421 rval = mega_n_to_m((void *)arg, &mc);
3427 * This interface only support the regular passthru commands.
3428 * Reject extended passthru and 64-bit passthru
3430 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU64 ||
3431 uioc.uioc_rmbox[0] == MEGA_MBOXCMD_EXTPTHRU ) {
3433 printk(KERN_WARNING "megaraid: rejected passthru.\n");
3439 * For all internal commands, the buffer must be allocated in
3440 * <4GB address range
3442 if( make_local_pdev(adapter, &pdev) != 0 )
3445 /* Is it a passthru command or a DCMD */
3446 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
3447 /* Passthru commands */
3449 pthru = pci_alloc_consistent(pdev,
3450 sizeof(mega_passthru),
3453 if( pthru == NULL ) {
3454 free_local_pdev(pdev);
3459 * The user passthru structure
3461 upthru = (mega_passthru *)MBOX(uioc)->xferaddr;
3464 * Copy in the user passthru here.
3466 if( copy_from_user(pthru, (char *)upthru,
3467 sizeof(mega_passthru)) ) {
3469 pci_free_consistent(pdev,
3470 sizeof(mega_passthru), pthru,
3473 free_local_pdev(pdev);
3479 * Is there a data transfer
3481 if( pthru->dataxferlen ) {
3482 data = pci_alloc_consistent(pdev,
3486 if( data == NULL ) {
3487 pci_free_consistent(pdev,
3488 sizeof(mega_passthru),
3492 free_local_pdev(pdev);
3498 * Save the user address and point the kernel
3499 * address at just allocated memory
3501 uxferaddr = pthru->dataxferaddr;
3502 pthru->dataxferaddr = data_dma_hndl;
3507 * Is data coming down-stream
3509 if( pthru->dataxferlen && (uioc.flags & UIOC_WR) ) {
3513 if( copy_from_user(data, (char *)uxferaddr,
3514 pthru->dataxferlen) ) {
3516 goto freemem_and_return;
3520 memset(&mc, 0, sizeof(megacmd_t));
3522 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
3523 mc.xferaddr = (u32)pthru_dma_hndl;
3528 mega_internal_command(adapter, LOCK_INT, &mc, pthru);
3530 rval = mega_n_to_m((void *)arg, &mc);
3532 if( rval ) goto freemem_and_return;
3536 * Is data going up-stream
3538 if( pthru->dataxferlen && (uioc.flags & UIOC_RD) ) {
3539 if( copy_to_user((char *)uxferaddr, data,
3540 pthru->dataxferlen) ) {
3546 * Send the request sense data also, irrespective of
3547 * whether the user has asked for it or not.
3549 copy_to_user(upthru->reqsensearea,
3550 pthru->reqsensearea, 14);
3553 if( pthru->dataxferlen ) {
3554 pci_free_consistent(pdev,
3555 pthru->dataxferlen, data,
3559 pci_free_consistent(pdev, sizeof(mega_passthru),
3560 pthru, pthru_dma_hndl);
3562 free_local_pdev(pdev);
3570 * Is there a data transfer
3572 if( uioc.xferlen ) {
3573 data = pci_alloc_consistent(pdev,
3574 uioc.xferlen, &data_dma_hndl);
3576 if( data == NULL ) {
3577 free_local_pdev(pdev);
3581 uxferaddr = MBOX(uioc)->xferaddr;
3585 * Is data coming down-stream
3587 if( uioc.xferlen && (uioc.flags & UIOC_WR) ) {
3591 if( copy_from_user(data, (char *)uxferaddr,
3594 pci_free_consistent(pdev,
3596 data, data_dma_hndl);
3598 free_local_pdev(pdev);
3604 memcpy(&mc, MBOX(uioc), sizeof(megacmd_t));
3606 mc.xferaddr = (u32)data_dma_hndl;
3611 mega_internal_command(adapter, LOCK_INT, &mc, NULL);
3613 rval = mega_n_to_m((void *)arg, &mc);
3616 if( uioc.xferlen ) {
3617 pci_free_consistent(pdev,
3622 free_local_pdev(pdev);
3628 * Is data going up-stream
3630 if( uioc.xferlen && (uioc.flags & UIOC_RD) ) {
3631 if( copy_to_user((char *)uxferaddr, data,
3638 if( uioc.xferlen ) {
3639 pci_free_consistent(pdev,
3644 free_local_pdev(pdev);
3658 * @arg - user address
3659 * @uioc - new ioctl structure
3661 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3664 * Converts the older mimd ioctl structure to newer NIT structure
3667 mega_m_to_n(void *arg, nitioctl_t *uioc)
3669 struct uioctl_t uioc_mimd;
3670 char signature[8] = {0};
3676 * check is the application conforms to NIT. We do not have to do much
3678 * We exploit the fact that the signature is stored in the very
3679 * begining of the structure.
3682 if( copy_from_user(signature, (char *)arg, 7) )
3685 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3688 * NOTE NOTE: The nit ioctl is still under flux because of
3689 * change of mailbox definition, in HPE. No applications yet
3690 * use this interface and let's not have applications use this
3691 * interface till the new specifitions are in place.
3695 if( copy_from_user(uioc, (char *)arg, sizeof(nitioctl_t)) )
3702 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3704 * Get the user ioctl structure
3706 if( copy_from_user(&uioc_mimd, (char *)arg, sizeof(struct uioctl_t)) )
3711 * Get the opcode and subopcode for the commands
3713 opcode = uioc_mimd.ui.fcs.opcode;
3714 subopcode = uioc_mimd.ui.fcs.subopcode;
3719 switch (subopcode) {
3721 case MEGAIOC_QDRVRVER: /* Query driver version */
3722 uioc->opcode = GET_DRIVER_VER;
3723 uioc->uioc_uaddr = uioc_mimd.data;
3726 case MEGAIOC_QNADAP: /* Get # of adapters */
3727 uioc->opcode = GET_N_ADAP;
3728 uioc->uioc_uaddr = uioc_mimd.data;
3731 case MEGAIOC_QADAPINFO: /* Get adapter information */
3732 uioc->opcode = GET_ADAP_INFO;
3733 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3734 uioc->uioc_uaddr = uioc_mimd.data;
3746 uioc->opcode = MBOX_CMD;
3747 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3749 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3751 uioc->xferlen = uioc_mimd.ui.fcs.length;
3753 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3754 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3760 uioc->opcode = MBOX_CMD;
3761 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3763 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3766 * Choose the xferlen bigger of input and output data
3768 uioc->xferlen = uioc_mimd.outlen > uioc_mimd.inlen ?
3769 uioc_mimd.outlen : uioc_mimd.inlen;
3771 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3772 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3786 * @arg - user address
3787 * @mc - mailbox command
3789 * Updates the status information to the application, depending on application
3790 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3793 mega_n_to_m(void *arg, megacmd_t *mc)
3797 mega_passthru *upthru;
3798 struct uioctl_t *uioc_mimd;
3799 char signature[8] = {0};
3802 * check is the application conforms to NIT.
3804 if( copy_from_user(signature, (char *)arg, 7) )
3807 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3809 uiocp = (nitioctl_t *)arg;
3811 if( put_user(mc->status, (u8 *)&MBOX_P(uiocp)->status) )
3814 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3816 umc = MBOX_P(uiocp);
3818 upthru = (mega_passthru *)umc->xferaddr;
3820 if( put_user(mc->status, (u8 *)&upthru->scsistatus) )
3825 uioc_mimd = (struct uioctl_t *)arg;
3827 if( put_user(mc->status, (u8 *)&uioc_mimd->mbox[17]) )
3830 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3832 umc = (megacmd_t *)uioc_mimd->mbox;
3834 upthru = (mega_passthru *)umc->xferaddr;
3836 if( put_user(mc->status, (u8 *)&upthru->scsistatus) )
3846 * MEGARAID 'FW' commands.
3850 * mega_is_bios_enabled()
3851 * @adapter - pointer to our soft state
3853 * issue command to find out if the BIOS is enabled for this controller
3856 mega_is_bios_enabled(adapter_t *adapter)
3858 unsigned char raw_mbox[sizeof(struct mbox_out)];
3862 mbox = (mbox_t *)raw_mbox;
3864 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3866 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3868 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3870 raw_mbox[0] = IS_BIOS_ENABLED;
3871 raw_mbox[2] = GET_BIOS;
3874 ret = issue_scb_block(adapter, raw_mbox);
3876 return *(char *)adapter->mega_buffer;
3881 * mega_enum_raid_scsi()
3882 * @adapter - pointer to our soft state
3884 * Find out what channels are RAID/SCSI. This information is used to
3885 * differentiate the virtual channels and physical channels and to support
3886 * ROMB feature and non-disk devices.
3889 mega_enum_raid_scsi(adapter_t *adapter)
3891 unsigned char raw_mbox[sizeof(struct mbox_out)];
3895 mbox = (mbox_t *)raw_mbox;
3897 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3900 * issue command to find out what channels are raid/scsi
3902 raw_mbox[0] = CHNL_CLASS;
3903 raw_mbox[2] = GET_CHNL_CLASS;
3905 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3907 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3910 * Non-ROMB firware fail this command, so all channels
3911 * must be shown RAID
3913 adapter->mega_ch_class = 0xFF;
3915 if(!issue_scb_block(adapter, raw_mbox)) {
3916 adapter->mega_ch_class = *((char *)adapter->mega_buffer);
3920 for( i = 0; i < adapter->product_info.nchannels; i++ ) {
3921 if( (adapter->mega_ch_class >> i) & 0x01 ) {
3922 printk(KERN_INFO "megaraid: channel[%d] is raid.\n",
3926 printk(KERN_INFO "megaraid: channel[%d] is scsi.\n",
3936 * mega_get_boot_drv()
3937 * @adapter - pointer to our soft state
3939 * Find out which device is the boot device. Note, any logical drive or any
3940 * phyical device (e.g., a CDROM) can be designated as a boot device.
3943 mega_get_boot_drv(adapter_t *adapter)
3945 struct private_bios_data *prv_bios_data;
3946 unsigned char raw_mbox[sizeof(struct mbox_out)];
3953 mbox = (mbox_t *)raw_mbox;
3955 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3957 raw_mbox[0] = BIOS_PVT_DATA;
3958 raw_mbox[2] = GET_BIOS_PVT_DATA;
3960 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3962 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3964 adapter->boot_ldrv_enabled = 0;
3965 adapter->boot_ldrv = 0;
3967 adapter->boot_pdrv_enabled = 0;
3968 adapter->boot_pdrv_ch = 0;
3969 adapter->boot_pdrv_tgt = 0;
3971 if(issue_scb_block(adapter, raw_mbox) == 0) {
3973 (struct private_bios_data *)adapter->mega_buffer;
3976 cksum_p = (char *)prv_bios_data;
3977 for (i = 0; i < 14; i++ ) {
3978 cksum += (u16)(*cksum_p++);
3981 if (prv_bios_data->cksum == (u16)(0-cksum) ) {
3984 * If MSB is set, a physical drive is set as boot
3987 if( prv_bios_data->boot_drv & 0x80 ) {
3988 adapter->boot_pdrv_enabled = 1;
3989 boot_pdrv = prv_bios_data->boot_drv & 0x7F;
3990 adapter->boot_pdrv_ch = boot_pdrv / 16;
3991 adapter->boot_pdrv_tgt = boot_pdrv % 16;
3994 adapter->boot_ldrv_enabled = 1;
3995 adapter->boot_ldrv = prv_bios_data->boot_drv;
4003 * mega_support_random_del()
4004 * @adapter - pointer to our soft state
4006 * Find out if this controller supports random deletion and addition of
4010 mega_support_random_del(adapter_t *adapter)
4012 unsigned char raw_mbox[sizeof(struct mbox_out)];
4016 mbox = (mbox_t *)raw_mbox;
4018 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4023 raw_mbox[0] = FC_DEL_LOGDRV;
4024 raw_mbox[2] = OP_SUP_DEL_LOGDRV;
4026 rval = issue_scb_block(adapter, raw_mbox);
4033 * mega_support_ext_cdb()
4034 * @adapter - pointer to our soft state
4036 * Find out if this firmware support cdblen > 10
4039 mega_support_ext_cdb(adapter_t *adapter)
4041 unsigned char raw_mbox[sizeof(struct mbox_out)];
4045 mbox = (mbox_t *)raw_mbox;
4047 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4049 * issue command to find out if controller supports extended CDBs.
4054 rval = issue_scb_block(adapter, raw_mbox);
4062 * @adapter - pointer to our soft state
4063 * @logdrv - logical drive to be deleted
4065 * Delete the specified logical drive. It is the responsibility of the user
4066 * app to let the OS know about this operation.
4069 mega_del_logdrv(adapter_t *adapter, int logdrv)
4071 unsigned long flags;
4076 * Stop sending commands to the controller, queue them internally.
4077 * When deletion is complete, ISR will flush the queue.
4079 atomic_set(&adapter->quiescent, 1);
4082 * Wait till all the issued commands are complete and there are no
4083 * commands in the pending queue
4085 while( atomic_read(&adapter->pend_cmds) > 0 ||
4086 !list_empty(&adapter->pending_list) ) {
4088 set_current_state(TASK_UNINTERRUPTIBLE);
4089 schedule_timeout(1*HZ ); /* sleep for 1s */
4092 rval = mega_do_del_logdrv(adapter, logdrv);
4094 spin_lock_irqsave(&adapter->lock, flags);
4097 * If delete operation was successful, add 0x80 to the logical drive
4098 * ids for commands in the pending queue.
4100 if (adapter->read_ldidmap) {
4101 struct list_head *pos;
4102 list_for_each(pos, &adapter->pending_list) {
4103 scb = list_entry(pos, scb_t, list);
4104 if (scb->pthru->logdrv < 0x80 )
4105 scb->pthru->logdrv += 0x80;
4109 atomic_set(&adapter->quiescent, 0);
4111 mega_runpendq(adapter);
4113 spin_unlock_irqrestore(&adapter->lock, flags);
4120 mega_do_del_logdrv(adapter_t *adapter, int logdrv)
4125 memset( &mc, 0, sizeof(megacmd_t));
4127 mc.cmd = FC_DEL_LOGDRV;
4128 mc.opcode = OP_DEL_LOGDRV;
4129 mc.subopcode = logdrv;
4131 rval = mega_internal_command(adapter, LOCK_INT, &mc, NULL);
4133 /* log this event */
4135 printk(KERN_WARNING "megaraid: Delete LD-%d failed.", logdrv);
4140 * After deleting first logical drive, the logical drives must be
4141 * addressed by adding 0x80 to the logical drive id.
4143 adapter->read_ldidmap = 1;
4150 * mega_get_max_sgl()
4151 * @adapter - pointer to our soft state
4153 * Find out the maximum number of scatter-gather elements supported by this
4154 * version of the firmware
4157 mega_get_max_sgl(adapter_t *adapter)
4159 unsigned char raw_mbox[sizeof(struct mbox_out)];
4162 mbox = (mbox_t *)raw_mbox;
4164 memset(mbox, 0, sizeof(raw_mbox));
4166 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4168 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4170 raw_mbox[0] = MAIN_MISC_OPCODE;
4171 raw_mbox[2] = GET_MAX_SG_SUPPORT;
4174 if( issue_scb_block(adapter, raw_mbox) ) {
4176 * f/w does not support this command. Choose the default value
4178 adapter->sglen = MIN_SGLIST;
4181 adapter->sglen = *((char *)adapter->mega_buffer);
4184 * Make sure this is not more than the resources we are
4185 * planning to allocate
4187 if ( adapter->sglen > MAX_SGLIST )
4188 adapter->sglen = MAX_SGLIST;
4196 * mega_support_cluster()
4197 * @adapter - pointer to our soft state
4199 * Find out if this firmware support cluster calls.
4202 mega_support_cluster(adapter_t *adapter)
4204 unsigned char raw_mbox[sizeof(struct mbox_out)];
4207 mbox = (mbox_t *)raw_mbox;
4209 memset(mbox, 0, sizeof(raw_mbox));
4211 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4213 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4216 * Try to get the initiator id. This command will succeed iff the
4217 * clustering is available on this HBA.
4219 raw_mbox[0] = MEGA_GET_TARGET_ID;
4221 if( issue_scb_block(adapter, raw_mbox) == 0 ) {
4224 * Cluster support available. Get the initiator target id.
4225 * Tell our id to mid-layer too.
4227 adapter->this_id = *(u32 *)adapter->mega_buffer;
4228 adapter->host->this_id = adapter->this_id;
4239 * mega_get_ldrv_num()
4240 * @adapter - pointer to our soft state
4241 * @cmd - scsi mid layer command
4242 * @channel - channel on the controller
4244 * Calculate the logical drive number based on the information in scsi command
4245 * and the channel number.
4248 mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel)
4253 tgt = cmd->device->id;
4255 if ( tgt > adapter->this_id )
4256 tgt--; /* we do not get inquires for initiator id */
4258 ldrv_num = (channel * 15) + tgt;
4262 * If we have a logical drive with boot enabled, project it first
4264 if( adapter->boot_ldrv_enabled ) {
4265 if( ldrv_num == 0 ) {
4266 ldrv_num = adapter->boot_ldrv;
4269 if( ldrv_num <= adapter->boot_ldrv ) {
4276 * If "delete logical drive" feature is enabled on this controller.
4277 * Do only if at least one delete logical drive operation was done.
4279 * Also, after logical drive deletion, instead of logical drive number,
4280 * the value returned should be 0x80+logical drive id.
4282 * These is valid only for IO commands.
4285 if (adapter->support_random_del && adapter->read_ldidmap )
4286 switch (cmd->cmnd[0]) {
4287 case READ_6: /* fall through */
4288 case WRITE_6: /* fall through */
4289 case READ_10: /* fall through */
4300 * @adapter - pointer to our soft state
4301 * @dma_handle - DMA address of the buffer
4303 * Issue internal comamnds while interrupts are available.
4304 * We only issue direct mailbox commands from within the driver. ioctl()
4305 * interface using these routines can issue passthru commands.
4308 mega_adapinq(adapter_t *adapter, dma_addr_t dma_handle)
4312 memset(&mc, 0, sizeof(megacmd_t));
4314 if( adapter->flag & BOARD_40LD ) {
4315 mc.cmd = FC_NEW_CONFIG;
4316 mc.opcode = NC_SUBOP_ENQUIRY3;
4317 mc.subopcode = ENQ3_GET_SOLICITED_FULL;
4320 mc.cmd = MEGA_MBOXCMD_ADPEXTINQ;
4323 mc.xferaddr = (u32)dma_handle;
4325 if ( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
4334 * mega_allocate_inquiry()
4335 * @dma_handle - handle returned for dma address
4336 * @pdev - handle to pci device
4338 * allocates memory for inquiry structure
4340 static inline caddr_t
4341 mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev)
4343 return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle);
4348 mega_free_inquiry(caddr_t inquiry, dma_addr_t dma_handle, struct pci_dev *pdev)
4350 pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle);
4354 /** mega_internal_dev_inquiry()
4355 * @adapter - pointer to our soft state
4356 * @ch - channel for this device
4357 * @tgt - ID of this device
4358 * @buf_dma_handle - DMA address of the buffer
4360 * Issue the scsi inquiry for the specified device.
4363 mega_internal_dev_inquiry(adapter_t *adapter, u8 ch, u8 tgt,
4364 dma_addr_t buf_dma_handle)
4366 mega_passthru *pthru;
4367 dma_addr_t pthru_dma_handle;
4370 struct pci_dev *pdev;
4374 * For all internal commands, the buffer must be allocated in <4GB
4377 if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
4379 pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
4382 if( pthru == NULL ) {
4383 free_local_pdev(pdev);
4389 pthru->reqsenselen = 14;
4390 pthru->islogical = 0;
4392 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : ch;
4394 pthru->target = (adapter->flag & BOARD_40LD) ? (ch << 4)|tgt : tgt;
4398 pthru->cdb[0] = INQUIRY;
4402 pthru->cdb[4] = 255;
4406 pthru->dataxferaddr = (u32)buf_dma_handle;
4407 pthru->dataxferlen = 256;
4409 memset(&mc, 0, sizeof(megacmd_t));
4411 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
4412 mc.xferaddr = (u32)pthru_dma_handle;
4414 rval = mega_internal_command(adapter, LOCK_INT, &mc, pthru);
4416 pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
4419 free_local_pdev(pdev);
4426 * mega_internal_command()
4427 * @adapter - pointer to our soft state
4428 * @ls - the scope of the exclusion lock.
4429 * @mc - the mailbox command
4430 * @pthru - Passthru structure for DCDB commands
4432 * Issue the internal commands in interrupt mode.
4433 * The last argument is the address of the passthru structure if the command
4434 * to be fired is a passthru command
4436 * lockscope specifies whether the caller has already acquired the lock. Of
4437 * course, the caller must know which lock we are talking about.
4439 * Note: parameter 'pthru' is null for non-passthru commands.
4442 mega_internal_command(adapter_t *adapter, lockscope_t ls, megacmd_t *mc,
4443 mega_passthru *pthru )
4446 struct scsi_device *sdev;
4447 unsigned long flags = 0;
4452 * The internal commands share one command id and hence are
4453 * serialized. This is so because we want to reserve maximum number of
4454 * available command ids for the I/O commands.
4456 down(&adapter->int_mtx);
4458 scb = &adapter->int_scb;
4459 memset(scb, 0, sizeof(scb_t));
4461 scmd = &adapter->int_scmd;
4462 memset(scmd, 0, sizeof(Scsi_Cmnd));
4464 sdev = kmalloc(sizeof(struct scsi_device), GFP_KERNEL);
4465 memset(sdev, 0, sizeof(struct scsi_device));
4466 scmd->device = sdev;
4468 scmd->device->host = adapter->host;
4469 scmd->buffer = (void *)scb;
4470 scmd->cmnd[0] = MEGA_INTERNAL_CMD;
4472 scb->state |= SCB_ACTIVE;
4475 memcpy(scb->raw_mbox, mc, sizeof(megacmd_t));
4478 * Is it a passthru command
4480 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
4485 scb->idx = CMDID_INT_CMDS;
4490 * Get the lock only if the caller has not acquired it already
4492 if( ls == LOCK_INT ) spin_lock_irqsave(&adapter->lock, flags);
4494 megaraid_queue(scmd, mega_internal_done);
4496 if( ls == LOCK_INT ) spin_unlock_irqrestore(&adapter->lock, flags);
4499 * Wait till this command finishes. Do not use
4500 * wait_event_interruptible(). It causes panic if CTRL-C is hit when
4501 * dumping e.g., physical disk information through /proc interface.
4504 wait_event_interruptible(adapter->int_waitq, scmd->state);
4506 wait_event(adapter->int_waitq, scmd->state);
4508 rval = scmd->result;
4509 mc->status = scmd->result;
4513 * Print a debug message for all failed commands. Applications can use
4516 if( scmd->result && trace_level ) {
4517 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4518 mc->cmd, mc->opcode, mc->subopcode, scmd->result);
4521 up(&adapter->int_mtx);
4528 * mega_internal_done()
4529 * @scmd - internal scsi command
4531 * Callback routine for internal commands.
4534 mega_internal_done(Scsi_Cmnd *scmd)
4538 adapter = (adapter_t *)scmd->device->host->hostdata;
4540 scmd->state = 1; /* thread waiting for its command to complete */
4543 * See comment in mega_internal_command() routine for
4544 * wait_event_interruptible()
4547 wake_up_interruptible(&adapter->int_waitq);
4549 wake_up(&adapter->int_waitq);
4555 make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
4557 *pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
4559 if( *pdev == NULL ) return -1;
4561 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
4563 if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) {
4572 free_local_pdev(struct pci_dev *pdev)
4577 static struct scsi_host_template megaraid_template = {
4578 .module = THIS_MODULE,
4580 .proc_name = "megaraid",
4581 .info = megaraid_info,
4582 .queuecommand = megaraid_queue,
4583 .bios_param = megaraid_biosparam,
4584 .max_sectors = MAX_SECTORS_PER_IO,
4585 .can_queue = MAX_COMMANDS,
4586 .this_id = DEFAULT_INITIATOR_ID,
4587 .sg_tablesize = MAX_SGLIST,
4588 .cmd_per_lun = DEF_CMD_PER_LUN,
4589 .use_clustering = ENABLE_CLUSTERING,
4590 .eh_abort_handler = megaraid_abort,
4591 .eh_device_reset_handler = megaraid_reset,
4592 .eh_bus_reset_handler = megaraid_reset,
4593 .eh_host_reset_handler = megaraid_reset,
4596 static int __devinit
4597 megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4599 struct Scsi_Host *host;
4601 unsigned long mega_baseport, tbase, flag = 0;
4602 u16 subsysid, subsysvid;
4603 u8 pci_bus, pci_dev_func;
4605 int error = -ENODEV;
4607 if (pci_enable_device(pdev))
4609 pci_set_master(pdev);
4611 pci_bus = pdev->bus->number;
4612 pci_dev_func = pdev->devfn;
4615 * For these vendor and device ids, signature offsets are not
4616 * valid and 64 bit is implicit
4618 if (id->driver_data & BOARD_64BIT)
4619 flag |= BOARD_64BIT;
4623 pci_read_config_dword(pdev, PCI_CONF_AMISIG64, &magic64);
4624 if (magic64 == HBA_SIGNATURE_64BIT)
4625 flag |= BOARD_64BIT;
4628 subsysvid = pdev->subsystem_vendor;
4629 subsysid = pdev->subsystem_device;
4631 printk(KERN_NOTICE "megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4632 id->vendor, id->device, pci_bus);
4634 printk("slot %d:func %d\n",
4635 PCI_SLOT(pci_dev_func), PCI_FUNC(pci_dev_func));
4637 /* Read the base port and IRQ from PCI */
4638 mega_baseport = pci_resource_start(pdev, 0);
4641 tbase = mega_baseport;
4642 if (pci_resource_flags(pdev, 0) & IORESOURCE_MEM) {
4643 flag |= BOARD_MEMMAP;
4645 if (!request_mem_region(mega_baseport, 128, "megaraid")) {
4646 printk(KERN_WARNING "megaraid: mem region busy!\n");
4647 goto out_disable_device;
4650 mega_baseport = (unsigned long)ioremap(mega_baseport, 128);
4651 if (!mega_baseport) {
4653 "megaraid: could not map hba memory\n");
4654 goto out_release_region;
4657 flag |= BOARD_IOMAP;
4658 mega_baseport += 0x10;
4660 if (!request_region(mega_baseport, 16, "megaraid"))
4661 goto out_disable_device;
4664 /* Initialize SCSI Host structure */
4665 host = scsi_host_alloc(&megaraid_template, sizeof(adapter_t));
4669 adapter = (adapter_t *)host->hostdata;
4670 memset(adapter, 0, sizeof(adapter_t));
4673 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4674 host->host_no, mega_baseport, irq);
4676 adapter->base = mega_baseport;
4678 INIT_LIST_HEAD(&adapter->free_list);
4679 INIT_LIST_HEAD(&adapter->pending_list);
4680 INIT_LIST_HEAD(&adapter->completed_list);
4682 adapter->flag = flag;
4683 spin_lock_init(&adapter->lock);
4684 scsi_assign_lock(host, &adapter->lock);
4686 host->cmd_per_lun = max_cmd_per_lun;
4687 host->max_sectors = max_sectors_per_io;
4689 adapter->dev = pdev;
4690 adapter->host = host;
4692 adapter->host->irq = irq;
4694 if (flag & BOARD_MEMMAP)
4695 adapter->host->base = tbase;
4697 adapter->host->io_port = tbase;
4698 adapter->host->n_io_port = 16;
4701 adapter->host->unique_id = (pci_bus << 8) | pci_dev_func;
4704 * Allocate buffer to issue internal commands.
4706 adapter->mega_buffer = pci_alloc_consistent(adapter->dev,
4707 MEGA_BUFFER_SIZE, &adapter->buf_dma_handle);
4708 if (!adapter->mega_buffer) {
4709 printk(KERN_WARNING "megaraid: out of RAM.\n");
4713 adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
4714 if (!adapter->scb_list) {
4715 printk(KERN_WARNING "megaraid: out of RAM.\n");
4716 goto out_free_cmd_buffer;
4719 if (request_irq(irq, (adapter->flag & BOARD_MEMMAP) ?
4720 megaraid_isr_memmapped : megaraid_isr_iomapped,
4721 SA_SHIRQ, "megaraid", adapter)) {
4723 "megaraid: Couldn't register IRQ %d!\n", irq);
4724 goto out_free_scb_list;
4727 if (mega_setup_mailbox(adapter))
4730 if (mega_query_adapter(adapter))
4734 * Have checks for some buggy f/w
4736 if ((subsysid == 0x1111) && (subsysvid == 0x1111)) {
4740 if (!strcmp(adapter->fw_version, "3.00") ||
4741 !strcmp(adapter->fw_version, "3.01")) {
4743 printk( KERN_WARNING
4744 "megaraid: Your card is a Dell PERC "
4745 "2/SC RAID controller with "
4746 "firmware\nmegaraid: 3.00 or 3.01. "
4747 "This driver is known to have "
4748 "corruption issues\nmegaraid: with "
4749 "those firmware versions on this "
4750 "specific card. In order\nmegaraid: "
4751 "to protect your data, please upgrade "
4752 "your firmware to version\nmegaraid: "
4753 "3.10 or later, available from the "
4754 "Dell Technical Support web\n"
4755 "megaraid: site at\nhttp://support."
4756 "dell.com/us/en/filelib/download/"
4757 "index.asp?fileid=2940\n"
4763 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4764 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4765 * support, since this firmware cannot handle 64 bit
4768 if ((subsysvid == HP_SUBSYS_VID) &&
4769 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) {
4773 if (!strcmp(adapter->fw_version, "H01.07") ||
4774 !strcmp(adapter->fw_version, "H01.08") ||
4775 !strcmp(adapter->fw_version, "H01.09") ) {
4777 "megaraid: Firmware H.01.07, "
4778 "H.01.08, and H.01.09 on 1M/2M "
4780 "megaraid: do not support 64 bit "
4781 "addressing.\nmegaraid: DISABLING "
4782 "64 bit support.\n");
4783 adapter->flag &= ~BOARD_64BIT;
4787 if (mega_is_bios_enabled(adapter))
4788 mega_hbas[hba_count].is_bios_enabled = 1;
4789 mega_hbas[hba_count].hostdata_addr = adapter;
4792 * Find out which channel is raid and which is scsi. This is
4795 mega_enum_raid_scsi(adapter);
4798 * Find out if a logical drive is set as the boot drive. If
4799 * there is one, will make that as the first logical drive.
4800 * ROMB: Do we have to boot from a physical drive. Then all
4801 * the physical drives would appear before the logical disks.
4802 * Else, all the physical drives would be exported to the mid
4803 * layer after logical drives.
4805 mega_get_boot_drv(adapter);
4807 if (adapter->boot_pdrv_enabled) {
4808 j = adapter->product_info.nchannels;
4809 for( i = 0; i < j; i++ )
4810 adapter->logdrv_chan[i] = 0;
4811 for( i = j; i < NVIRT_CHAN + j; i++ )
4812 adapter->logdrv_chan[i] = 1;
4814 for (i = 0; i < NVIRT_CHAN; i++)
4815 adapter->logdrv_chan[i] = 1;
4816 for (i = NVIRT_CHAN; i < MAX_CHANNELS+NVIRT_CHAN; i++)
4817 adapter->logdrv_chan[i] = 0;
4818 adapter->mega_ch_class <<= NVIRT_CHAN;
4822 * Do we support random deletion and addition of logical
4825 adapter->read_ldidmap = 0; /* set it after first logdrv
4827 adapter->support_random_del = mega_support_random_del(adapter);
4829 /* Initialize SCBs */
4830 if (mega_init_scb(adapter))
4834 * Reset the pending commands counter
4836 atomic_set(&adapter->pend_cmds, 0);
4839 * Reset the adapter quiescent flag
4841 atomic_set(&adapter->quiescent, 0);
4843 hba_soft_state[hba_count] = adapter;
4846 * Fill in the structure which needs to be passed back to the
4847 * application when it does an ioctl() for controller related
4852 mcontroller[i].base = mega_baseport;
4853 mcontroller[i].irq = irq;
4854 mcontroller[i].numldrv = adapter->numldrv;
4855 mcontroller[i].pcibus = pci_bus;
4856 mcontroller[i].pcidev = id->device;
4857 mcontroller[i].pcifun = PCI_FUNC (pci_dev_func);
4858 mcontroller[i].pciid = -1;
4859 mcontroller[i].pcivendor = id->vendor;
4860 mcontroller[i].pcislot = PCI_SLOT(pci_dev_func);
4861 mcontroller[i].uid = (pci_bus << 8) | pci_dev_func;
4864 /* Set the Mode of addressing to 64 bit if we can */
4865 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) {
4866 pci_set_dma_mask(pdev, 0xffffffffffffffffULL);
4867 adapter->has_64bit_addr = 1;
4869 pci_set_dma_mask(pdev, 0xffffffff);
4870 adapter->has_64bit_addr = 0;
4873 init_MUTEX(&adapter->int_mtx);
4874 init_waitqueue_head(&adapter->int_waitq);
4876 adapter->this_id = DEFAULT_INITIATOR_ID;
4877 adapter->host->this_id = DEFAULT_INITIATOR_ID;
4879 #if MEGA_HAVE_CLUSTERING
4881 * Is cluster support enabled on this controller
4882 * Note: In a cluster the HBAs ( the initiators ) will have
4883 * different target IDs and we cannot assume it to be 7. Call
4884 * to mega_support_cluster() will get the target ids also if
4885 * the cluster support is available
4887 adapter->has_cluster = mega_support_cluster(adapter);
4888 if (adapter->has_cluster) {
4890 "megaraid: Cluster driver, initiator id:%d\n",
4895 pci_set_drvdata(pdev, host);
4897 mega_create_proc_entry(hba_count, mega_proc_dir_entry);
4899 error = scsi_add_host(host, &pdev->dev);
4903 scsi_scan_host(host);
4908 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
4909 adapter->una_mbox64, adapter->una_mbox64_dma);
4911 free_irq(adapter->host->irq, adapter);
4913 kfree(adapter->scb_list);
4914 out_free_cmd_buffer:
4915 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
4916 adapter->mega_buffer, adapter->buf_dma_handle);
4918 scsi_host_put(host);
4920 if (flag & BOARD_MEMMAP)
4921 iounmap((void *)mega_baseport);
4923 if (flag & BOARD_MEMMAP)
4924 release_mem_region(tbase, 128);
4926 release_region(mega_baseport, 16);
4928 pci_disable_device(pdev);
4934 __megaraid_shutdown(adapter_t *adapter)
4936 u_char raw_mbox[sizeof(struct mbox_out)];
4937 mbox_t *mbox = (mbox_t *)raw_mbox;
4940 /* Flush adapter cache */
4941 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4942 raw_mbox[0] = FLUSH_ADAPTER;
4944 free_irq(adapter->host->irq, adapter);
4946 /* Issue a blocking (interrupts disabled) command to the card */
4947 issue_scb_block(adapter, raw_mbox);
4949 /* Flush disks cache */
4950 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4951 raw_mbox[0] = FLUSH_SYSTEM;
4953 /* Issue a blocking (interrupts disabled) command to the card */
4954 issue_scb_block(adapter, raw_mbox);
4956 if (atomic_read(&adapter->pend_cmds) > 0)
4957 printk(KERN_WARNING "megaraid: pending commands!!\n");
4960 * Have a delibrate delay to make sure all the caches are
4963 for (i = 0; i <= 10; i++)
4968 megaraid_remove_one(struct pci_dev *pdev)
4970 struct Scsi_Host *host = pci_get_drvdata(pdev);
4971 adapter_t *adapter = (adapter_t *)host->hostdata;
4972 char buf[12] = { 0 };
4974 scsi_remove_host(host);
4976 __megaraid_shutdown(adapter);
4978 /* Free our resources */
4979 if (adapter->flag & BOARD_MEMMAP) {
4980 iounmap((void *)adapter->base);
4981 release_mem_region(adapter->host->base, 128);
4983 release_region(adapter->base, 16);
4985 mega_free_sgl(adapter);
4987 #ifdef CONFIG_PROC_FS
4988 if (adapter->controller_proc_dir_entry) {
4989 remove_proc_entry("stat", adapter->controller_proc_dir_entry);
4990 remove_proc_entry("config",
4991 adapter->controller_proc_dir_entry);
4992 remove_proc_entry("mailbox",
4993 adapter->controller_proc_dir_entry);
4994 #if MEGA_HAVE_ENH_PROC
4995 remove_proc_entry("rebuild-rate",
4996 adapter->controller_proc_dir_entry);
4997 remove_proc_entry("battery-status",
4998 adapter->controller_proc_dir_entry);
5000 remove_proc_entry("diskdrives-ch0",
5001 adapter->controller_proc_dir_entry);
5002 remove_proc_entry("diskdrives-ch1",
5003 adapter->controller_proc_dir_entry);
5004 remove_proc_entry("diskdrives-ch2",
5005 adapter->controller_proc_dir_entry);
5006 remove_proc_entry("diskdrives-ch3",
5007 adapter->controller_proc_dir_entry);
5009 remove_proc_entry("raiddrives-0-9",
5010 adapter->controller_proc_dir_entry);
5011 remove_proc_entry("raiddrives-10-19",
5012 adapter->controller_proc_dir_entry);
5013 remove_proc_entry("raiddrives-20-29",
5014 adapter->controller_proc_dir_entry);
5015 remove_proc_entry("raiddrives-30-39",
5016 adapter->controller_proc_dir_entry);
5018 sprintf(buf, "hba%d", adapter->host->host_no);
5019 remove_proc_entry(buf, mega_proc_dir_entry);
5023 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
5024 adapter->mega_buffer, adapter->buf_dma_handle);
5025 kfree(adapter->scb_list);
5026 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
5027 adapter->una_mbox64, adapter->una_mbox64_dma);
5029 scsi_host_put(host);
5030 pci_disable_device(pdev);
5036 megaraid_shutdown(struct device *dev)
5038 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev));
5039 adapter_t *adapter = (adapter_t *)host->hostdata;
5041 __megaraid_shutdown(adapter);
5044 static struct pci_device_id megaraid_pci_tbl[] = {
5045 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DISCOVERY,
5046 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5047 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_PERC4_DI,
5048 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
5049 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_PERC4_QC_VERDE,
5050 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
5051 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID,
5052 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5053 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID2,
5054 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5055 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID3,
5056 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5057 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_AMI_MEGARAID3,
5058 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5059 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_AMI_MEGARAID3,
5060 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5063 MODULE_DEVICE_TABLE(pci, megaraid_pci_tbl);
5065 static struct pci_driver megaraid_pci_driver = {
5067 .id_table = megaraid_pci_tbl,
5068 .probe = megaraid_probe_one,
5069 .remove = __devexit_p(megaraid_remove_one),
5071 .shutdown = megaraid_shutdown,
5075 static int __init megaraid_init(void)
5079 if ((max_cmd_per_lun <= 0) || (max_cmd_per_lun > MAX_CMD_PER_LUN))
5080 max_cmd_per_lun = MAX_CMD_PER_LUN;
5081 if (max_mbox_busy_wait > MBOX_BUSY_WAIT)
5082 max_mbox_busy_wait = MBOX_BUSY_WAIT;
5084 #ifdef CONFIG_PROC_FS
5085 mega_proc_dir_entry = proc_mkdir("megaraid", &proc_root);
5086 if (!mega_proc_dir_entry) {
5088 "megaraid: failed to create megaraid root\n");
5091 error = pci_module_init(&megaraid_pci_driver);
5093 #ifdef CONFIG_PROC_FS
5094 remove_proc_entry("megaraid", &proc_root);
5100 * Register the driver as a character device, for applications
5101 * to access it for ioctls.
5102 * First argument (major) to register_chrdev implies a dynamic
5103 * major number allocation.
5105 major = register_chrdev(0, "megadev", &megadev_fops);
5108 "megaraid: failed to register char device\n");
5114 static void __exit megaraid_exit(void)
5117 * Unregister the character device interface to the driver.
5119 unregister_chrdev(major, "megadev");
5121 #ifdef CONFIG_PROC_FS
5122 remove_proc_entry("megaraid", &proc_root);
5125 pci_unregister_driver(&megaraid_pci_driver);
5128 module_init(megaraid_init);
5129 module_exit(megaraid_exit);
5131 /* vi: set ts=8 sw=8 tw=78: */