3 * Linux MegaRAID device driver
5 * Copyright © 2002 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
14 * - speed-ups (list handling fixes, issued_list, optimizations.)
17 * Copyright (c) 2003 Christoph Hellwig <hch@lst.de>
18 * - new-style, hotplug-aware pci probing and scsi registration
20 * Version : v2.00.3 (Feb 19, 2003) - Atul Mukker <Atul.Mukker@lsil.com>
22 * Description: Linux device driver for LSI Logic MegaRAID controller
24 * Supported controllers: MegaRAID 418, 428, 438, 466, 762, 467, 471, 490, 493
27 * This driver is supported by LSI Logic, with assistance from Red Hat, Dell,
28 * and others. Please send updates to the mailing list
29 * linux-scsi@vger.kernel.org .
35 #include <linux/blkdev.h>
36 #include <asm/uaccess.h>
38 #include <linux/delay.h>
39 #include <linux/proc_fs.h>
40 #include <linux/reboot.h>
41 #include <linux/module.h>
42 #include <linux/list.h>
43 #include <linux/interrupt.h>
44 #include <linux/pci.h>
45 #include <linux/init.h>
46 #include <scsi/scsicam.h>
49 #include <scsi/scsi_host.h>
53 #define MEGARAID_MODULE_VERSION "2.00.3"
55 MODULE_AUTHOR ("LSI Logic Corporation");
56 MODULE_DESCRIPTION ("LSI Logic MegaRAID driver");
57 MODULE_LICENSE ("GPL");
58 MODULE_VERSION(MEGARAID_MODULE_VERSION);
60 static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
61 MODULE_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");
340 * @adapter - pointer to our soft state
342 * Runs through the list of pending requests.
345 mega_runpendq(adapter_t *adapter)
347 if(!list_empty(&adapter->pending_list))
348 __mega_runpendq(adapter);
353 * @scmd - Issue this scsi command
354 * @done - the callback hook into the scsi mid-layer
356 * The command queuing entry point for the mid-layer.
359 megaraid_queue(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
365 adapter = (adapter_t *)scmd->device->host->hostdata;
367 scmd->scsi_done = done;
371 * Allocate and build a SCB request
372 * busy flag will be set if mega_build_cmd() command could not
373 * allocate scb. We will return non-zero status in that case.
374 * NOTE: scb can be null even though certain commands completed
375 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
376 * return 0 in that case.
379 scb = mega_build_cmd(adapter, scmd, &busy);
382 scb->state |= SCB_PENDQ;
383 list_add_tail(&scb->list, &adapter->pending_list);
386 * Check if the HBA is in quiescent state, e.g., during a
387 * delete logical drive opertion. If it is, don't run
390 if(atomic_read(&adapter->quiescent) == 0) {
391 mega_runpendq(adapter);
400 * mega_allocate_scb()
401 * @adapter - pointer to our soft state
402 * @cmd - scsi command from the mid-layer
404 * Allocate a SCB structure. This is the central structure for controller
407 static inline scb_t *
408 mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd)
410 struct list_head *head = &adapter->free_list;
413 /* Unlink command from Free List */
414 if( !list_empty(head) ) {
416 scb = list_entry(head->next, scb_t, list);
418 list_del_init(head->next);
420 scb->state = SCB_ACTIVE;
422 scb->dma_type = MEGA_DMA_TYPE_NONE;
431 * mega_get_ldrv_num()
432 * @adapter - pointer to our soft state
433 * @cmd - scsi mid layer command
434 * @channel - channel on the controller
436 * Calculate the logical drive number based on the information in scsi command
437 * and the channel number.
440 mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel)
445 tgt = cmd->device->id;
447 if ( tgt > adapter->this_id )
448 tgt--; /* we do not get inquires for initiator id */
450 ldrv_num = (channel * 15) + tgt;
454 * If we have a logical drive with boot enabled, project it first
456 if( adapter->boot_ldrv_enabled ) {
457 if( ldrv_num == 0 ) {
458 ldrv_num = adapter->boot_ldrv;
461 if( ldrv_num <= adapter->boot_ldrv ) {
468 * If "delete logical drive" feature is enabled on this controller.
469 * Do only if at least one delete logical drive operation was done.
471 * Also, after logical drive deletion, instead of logical drive number,
472 * the value returned should be 0x80+logical drive id.
474 * These is valid only for IO commands.
477 if (adapter->support_random_del && adapter->read_ldidmap )
478 switch (cmd->cmnd[0]) {
479 case READ_6: /* fall through */
480 case WRITE_6: /* fall through */
481 case READ_10: /* fall through */
491 * @adapter - pointer to our soft state
492 * @cmd - Prepare using this scsi command
493 * @busy - busy flag if no resources
495 * Prepares a command and scatter gather list for the controller. This routine
496 * also finds out if the commands is intended for a logical drive or a
497 * physical device and prepares the controller command accordingly.
499 * We also re-order the logical drives and physical devices based on their
503 mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy)
505 mega_ext_passthru *epthru;
506 mega_passthru *pthru;
514 int ldrv_num = 0; /* logical drive number */
518 * filter the internal and ioctl commands
520 if((cmd->cmnd[0] == MEGA_INTERNAL_CMD)) {
526 * We know what channels our logical drives are on - mega_find_card()
528 islogical = adapter->logdrv_chan[cmd->device->channel];
531 * The theory: If physical drive is chosen for boot, all the physical
532 * devices are exported before the logical drives, otherwise physical
533 * devices are pushed after logical drives, in which case - Kernel sees
534 * the physical devices on virtual channel which is obviously converted
535 * to actual channel on the HBA.
537 if( adapter->boot_pdrv_enabled ) {
539 /* logical channel */
540 channel = cmd->device->channel -
541 adapter->product_info.nchannels;
544 /* this is physical channel */
545 channel = cmd->device->channel;
546 target = cmd->device->id;
549 * boot from a physical disk, that disk needs to be
550 * exposed first IF both the channels are SCSI, then
551 * booting from the second channel is not allowed.
554 target = adapter->boot_pdrv_tgt;
556 else if( target == adapter->boot_pdrv_tgt ) {
563 /* this is the logical channel */
564 channel = cmd->device->channel;
567 /* physical channel */
568 channel = cmd->device->channel - NVIRT_CHAN;
569 target = cmd->device->id;
576 /* have just LUN 0 for each target on virtual channels */
577 if (cmd->device->lun) {
578 cmd->result = (DID_BAD_TARGET << 16);
583 ldrv_num = mega_get_ldrv_num(adapter, cmd, channel);
586 max_ldrv_num = (adapter->flag & BOARD_40LD) ?
587 MAX_LOGICAL_DRIVES_40LD : MAX_LOGICAL_DRIVES_8LD;
590 * max_ldrv_num increases by 0x80 if some logical drive was
593 if(adapter->read_ldidmap)
594 max_ldrv_num += 0x80;
596 if(ldrv_num > max_ldrv_num ) {
597 cmd->result = (DID_BAD_TARGET << 16);
604 if( cmd->device->lun > 7) {
606 * Do not support lun >7 for physically accessed
609 cmd->result = (DID_BAD_TARGET << 16);
617 * Logical drive commands
621 switch (cmd->cmnd[0]) {
622 case TEST_UNIT_READY:
623 memset(cmd->request_buffer, 0, cmd->request_bufflen);
625 #if MEGA_HAVE_CLUSTERING
627 * Do we support clustering and is the support enabled
628 * If no, return success always
630 if( !adapter->has_cluster ) {
631 cmd->result = (DID_OK << 16);
636 if(!(scb = mega_allocate_scb(adapter, cmd))) {
638 cmd->result = (DID_ERROR << 16);
645 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
646 scb->raw_mbox[2] = MEGA_RESERVATION_STATUS;
647 scb->raw_mbox[3] = ldrv_num;
649 scb->dma_direction = PCI_DMA_NONE;
653 cmd->result = (DID_OK << 16);
659 memset(cmd->request_buffer, 0, cmd->cmnd[4]);
660 cmd->result = (DID_OK << 16);
667 if(!(adapter->flag & (1L << cmd->device->channel))) {
670 "scsi%d: scanning scsi channel %d ",
671 adapter->host->host_no,
672 cmd->device->channel);
673 printk("for logical drives.\n");
675 adapter->flag |= (1L << cmd->device->channel);
678 /* Allocate a SCB and initialize passthru */
679 if(!(scb = mega_allocate_scb(adapter, cmd))) {
681 cmd->result = (DID_ERROR << 16);
689 mbox = (mbox_t *)scb->raw_mbox;
690 memset(mbox, 0, sizeof(scb->raw_mbox));
691 memset(pthru, 0, sizeof(mega_passthru));
695 pthru->reqsenselen = 14;
696 pthru->islogical = 1;
697 pthru->logdrv = ldrv_num;
698 pthru->cdblen = cmd->cmd_len;
699 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
701 if( adapter->has_64bit_addr ) {
702 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
705 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
708 scb->dma_direction = PCI_DMA_FROMDEVICE;
710 pthru->numsgelements = mega_build_sglist(adapter, scb,
711 &pthru->dataxferaddr, &pthru->dataxferlen);
713 mbox->m_out.xferaddr = scb->pthru_dma_addr;
724 /* Allocate a SCB and initialize mailbox */
725 if(!(scb = mega_allocate_scb(adapter, cmd))) {
727 cmd->result = (DID_ERROR << 16);
733 mbox = (mbox_t *)scb->raw_mbox;
735 memset(mbox, 0, sizeof(scb->raw_mbox));
736 mbox->m_out.logdrv = ldrv_num;
739 * A little hack: 2nd bit is zero for all scsi read
740 * commands and is set for all scsi write commands
742 if( adapter->has_64bit_addr ) {
743 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
744 MEGA_MBOXCMD_LWRITE64:
745 MEGA_MBOXCMD_LREAD64 ;
748 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
754 * 6-byte READ(0x08) or WRITE(0x0A) cdb
756 if( cmd->cmd_len == 6 ) {
757 mbox->m_out.numsectors = (u32) cmd->cmnd[4];
759 ((u32)cmd->cmnd[1] << 16) |
760 ((u32)cmd->cmnd[2] << 8) |
763 mbox->m_out.lba &= 0x1FFFFF;
767 * Take modulo 0x80, since the logical drive
768 * number increases by 0x80 when a logical
771 if (*cmd->cmnd == READ_6) {
772 adapter->nreads[ldrv_num%0x80]++;
773 adapter->nreadblocks[ldrv_num%0x80] +=
774 mbox->m_out.numsectors;
776 adapter->nwrites[ldrv_num%0x80]++;
777 adapter->nwriteblocks[ldrv_num%0x80] +=
778 mbox->m_out.numsectors;
784 * 10-byte READ(0x28) or WRITE(0x2A) cdb
786 if( cmd->cmd_len == 10 ) {
787 mbox->m_out.numsectors =
789 ((u32)cmd->cmnd[7] << 8);
791 ((u32)cmd->cmnd[2] << 24) |
792 ((u32)cmd->cmnd[3] << 16) |
793 ((u32)cmd->cmnd[4] << 8) |
797 if (*cmd->cmnd == READ_10) {
798 adapter->nreads[ldrv_num%0x80]++;
799 adapter->nreadblocks[ldrv_num%0x80] +=
800 mbox->m_out.numsectors;
802 adapter->nwrites[ldrv_num%0x80]++;
803 adapter->nwriteblocks[ldrv_num%0x80] +=
804 mbox->m_out.numsectors;
810 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
812 if( cmd->cmd_len == 12 ) {
814 ((u32)cmd->cmnd[2] << 24) |
815 ((u32)cmd->cmnd[3] << 16) |
816 ((u32)cmd->cmnd[4] << 8) |
819 mbox->m_out.numsectors =
820 ((u32)cmd->cmnd[6] << 24) |
821 ((u32)cmd->cmnd[7] << 16) |
822 ((u32)cmd->cmnd[8] << 8) |
826 if (*cmd->cmnd == READ_12) {
827 adapter->nreads[ldrv_num%0x80]++;
828 adapter->nreadblocks[ldrv_num%0x80] +=
829 mbox->m_out.numsectors;
831 adapter->nwrites[ldrv_num%0x80]++;
832 adapter->nwriteblocks[ldrv_num%0x80] +=
833 mbox->m_out.numsectors;
839 * If it is a read command
841 if( (*cmd->cmnd & 0x0F) == 0x08 ) {
842 scb->dma_direction = PCI_DMA_FROMDEVICE;
845 scb->dma_direction = PCI_DMA_TODEVICE;
848 /* Calculate Scatter-Gather info */
849 mbox->m_out.numsgelements = mega_build_sglist(adapter, scb,
850 (u32 *)&mbox->m_out.xferaddr, (u32 *)&seg);
854 #if MEGA_HAVE_CLUSTERING
855 case RESERVE: /* Fall through */
859 * Do we support clustering and is the support enabled
861 if( ! adapter->has_cluster ) {
863 cmd->result = (DID_BAD_TARGET << 16);
868 /* Allocate a SCB and initialize mailbox */
869 if(!(scb = mega_allocate_scb(adapter, cmd))) {
871 cmd->result = (DID_ERROR << 16);
878 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
879 scb->raw_mbox[2] = ( *cmd->cmnd == RESERVE ) ?
880 MEGA_RESERVE_LD : MEGA_RELEASE_LD;
882 scb->raw_mbox[3] = ldrv_num;
884 scb->dma_direction = PCI_DMA_NONE;
890 cmd->result = (DID_BAD_TARGET << 16);
897 * Passthru drive commands
900 /* Allocate a SCB and initialize passthru */
901 if(!(scb = mega_allocate_scb(adapter, cmd))) {
903 cmd->result = (DID_ERROR << 16);
910 mbox = (mbox_t *)scb->raw_mbox;
911 memset(mbox, 0, sizeof(scb->raw_mbox));
913 if( adapter->support_ext_cdb ) {
915 epthru = mega_prepare_extpassthru(adapter, scb, cmd,
918 mbox->m_out.cmd = MEGA_MBOXCMD_EXTPTHRU;
920 mbox->m_out.xferaddr = scb->epthru_dma_addr;
925 pthru = mega_prepare_passthru(adapter, scb, cmd,
928 /* Initialize mailbox */
929 if( adapter->has_64bit_addr ) {
930 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
933 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
936 mbox->m_out.xferaddr = scb->pthru_dma_addr;
946 * mega_prepare_passthru()
947 * @adapter - pointer to our soft state
948 * @scb - our scsi control block
949 * @cmd - scsi command from the mid-layer
950 * @channel - actual channel on the controller
951 * @target - actual id on the controller.
953 * prepare a command for the scsi physical devices.
955 static mega_passthru *
956 mega_prepare_passthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
957 int channel, int target)
959 mega_passthru *pthru;
962 memset(pthru, 0, sizeof (mega_passthru));
964 /* 0=6sec/1=60sec/2=10min/3=3hrs */
968 pthru->reqsenselen = 14;
969 pthru->islogical = 0;
971 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
973 pthru->target = (adapter->flag & BOARD_40LD) ?
974 (channel << 4) | target : target;
976 pthru->cdblen = cmd->cmd_len;
977 pthru->logdrv = cmd->device->lun;
979 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
981 /* Not sure about the direction */
982 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
984 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
985 switch (cmd->cmnd[0]) {
988 if(!(adapter->flag & (1L << cmd->device->channel))) {
991 "scsi%d: scanning scsi channel %d [P%d] ",
992 adapter->host->host_no,
993 cmd->device->channel, channel);
994 printk("for physical devices.\n");
996 adapter->flag |= (1L << cmd->device->channel);
1000 pthru->numsgelements = mega_build_sglist(adapter, scb,
1001 &pthru->dataxferaddr, &pthru->dataxferlen);
1009 * mega_prepare_extpassthru()
1010 * @adapter - pointer to our soft state
1011 * @scb - our scsi control block
1012 * @cmd - scsi command from the mid-layer
1013 * @channel - actual channel on the controller
1014 * @target - actual id on the controller.
1016 * prepare a command for the scsi physical devices. This rountine prepares
1017 * commands for devices which can take extended CDBs (>10 bytes)
1019 static mega_ext_passthru *
1020 mega_prepare_extpassthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
1021 int channel, int target)
1023 mega_ext_passthru *epthru;
1025 epthru = scb->epthru;
1026 memset(epthru, 0, sizeof(mega_ext_passthru));
1028 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1029 epthru->timeout = 2;
1032 epthru->reqsenselen = 14;
1033 epthru->islogical = 0;
1035 epthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
1036 epthru->target = (adapter->flag & BOARD_40LD) ?
1037 (channel << 4) | target : target;
1039 epthru->cdblen = cmd->cmd_len;
1040 epthru->logdrv = cmd->device->lun;
1042 memcpy(epthru->cdb, cmd->cmnd, cmd->cmd_len);
1044 /* Not sure about the direction */
1045 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
1047 switch(cmd->cmnd[0]) {
1050 if(!(adapter->flag & (1L << cmd->device->channel))) {
1053 "scsi%d: scanning scsi channel %d [P%d] ",
1054 adapter->host->host_no,
1055 cmd->device->channel, channel);
1056 printk("for physical devices.\n");
1058 adapter->flag |= (1L << cmd->device->channel);
1062 epthru->numsgelements = mega_build_sglist(adapter, scb,
1063 &epthru->dataxferaddr, &epthru->dataxferlen);
1071 __mega_runpendq(adapter_t *adapter)
1074 struct list_head *pos, *next;
1076 /* Issue any pending commands to the card */
1077 list_for_each_safe(pos, next, &adapter->pending_list) {
1079 scb = list_entry(pos, scb_t, list);
1081 if( !(scb->state & SCB_ISSUED) ) {
1083 if( issue_scb(adapter, scb) != 0 )
1094 * @adapter - pointer to our soft state
1095 * @scb - scsi control block
1097 * Post a command to the card if the mailbox is available, otherwise return
1098 * busy. We also take the scb from the pending list if the mailbox is
1102 issue_scb(adapter_t *adapter, scb_t *scb)
1104 volatile mbox64_t *mbox64 = adapter->mbox64;
1105 volatile mbox_t *mbox = adapter->mbox;
1108 if(unlikely(mbox->m_in.busy)) {
1112 } while( mbox->m_in.busy && (i < max_mbox_busy_wait) );
1114 if(mbox->m_in.busy) return -1;
1117 /* Copy mailbox data into host structure */
1118 memcpy((char *)&mbox->m_out, (char *)scb->raw_mbox,
1119 sizeof(struct mbox_out));
1121 mbox->m_out.cmdid = scb->idx; /* Set cmdid */
1122 mbox->m_in.busy = 1; /* Set busy */
1126 * Increment the pending queue counter
1128 atomic_inc(&adapter->pend_cmds);
1130 switch (mbox->m_out.cmd) {
1131 case MEGA_MBOXCMD_LREAD64:
1132 case MEGA_MBOXCMD_LWRITE64:
1133 case MEGA_MBOXCMD_PASSTHRU64:
1134 case MEGA_MBOXCMD_EXTPTHRU:
1135 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1136 mbox64->xfer_segment_hi = 0;
1137 mbox->m_out.xferaddr = 0xFFFFFFFF;
1140 mbox64->xfer_segment_lo = 0;
1141 mbox64->xfer_segment_hi = 0;
1147 scb->state |= SCB_ISSUED;
1149 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1150 mbox->m_in.poll = 0;
1152 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1155 irq_enable(adapter);
1156 issue_command(adapter);
1163 * Wait until the controller's mailbox is available
1166 mega_busywait_mbox (adapter_t *adapter)
1168 if (adapter->mbox->m_in.busy)
1169 return __mega_busywait_mbox(adapter);
1175 * @adapter - pointer to our soft state
1176 * @raw_mbox - the mailbox
1178 * Issue a scb in synchronous and non-interrupt mode
1181 issue_scb_block(adapter_t *adapter, u_char *raw_mbox)
1183 volatile mbox64_t *mbox64 = adapter->mbox64;
1184 volatile mbox_t *mbox = adapter->mbox;
1187 /* Wait until mailbox is free */
1188 if(mega_busywait_mbox (adapter))
1189 goto bug_blocked_mailbox;
1191 /* Copy mailbox data into host structure */
1192 memcpy((char *) mbox, raw_mbox, sizeof(struct mbox_out));
1193 mbox->m_out.cmdid = 0xFE;
1194 mbox->m_in.busy = 1;
1196 switch (raw_mbox[0]) {
1197 case MEGA_MBOXCMD_LREAD64:
1198 case MEGA_MBOXCMD_LWRITE64:
1199 case MEGA_MBOXCMD_PASSTHRU64:
1200 case MEGA_MBOXCMD_EXTPTHRU:
1201 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1202 mbox64->xfer_segment_hi = 0;
1203 mbox->m_out.xferaddr = 0xFFFFFFFF;
1206 mbox64->xfer_segment_lo = 0;
1207 mbox64->xfer_segment_hi = 0;
1210 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1211 mbox->m_in.poll = 0;
1213 mbox->m_in.numstatus = 0xFF;
1214 mbox->m_in.status = 0xFF;
1215 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1217 while((volatile u8)mbox->m_in.numstatus == 0xFF)
1220 mbox->m_in.numstatus = 0xFF;
1222 while( (volatile u8)mbox->m_in.poll != 0x77 )
1225 mbox->m_in.poll = 0;
1226 mbox->m_in.ack = 0x77;
1228 WRINDOOR(adapter, adapter->mbox_dma | 0x2);
1230 while(RDINDOOR(adapter) & 0x2)
1234 irq_disable(adapter);
1235 issue_command(adapter);
1237 while (!((byte = irq_state(adapter)) & INTR_VALID))
1240 set_irq_state(adapter, byte);
1241 irq_enable(adapter);
1245 return mbox->m_in.status;
1247 bug_blocked_mailbox:
1248 printk(KERN_WARNING "megaraid: Blocked mailbox......!!\n");
1255 * megaraid_isr_iomapped()
1257 * @devp - pointer to our soft state
1260 * Interrupt service routine for io-mapped controllers.
1261 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1262 * and service the completed commands.
1265 megaraid_isr_iomapped(int irq, void *devp, struct pt_regs *regs)
1267 adapter_t *adapter = devp;
1268 unsigned long flags;
1271 u8 completed[MAX_FIRMWARE_STATUS];
1277 * loop till F/W has more commands for us to complete.
1279 spin_lock_irqsave(&adapter->lock, flags);
1282 /* Check if a valid interrupt is pending */
1283 byte = irq_state(adapter);
1284 if( (byte & VALID_INTR_BYTE) == 0 ) {
1286 * No more pending commands
1290 set_irq_state(adapter, byte);
1292 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1295 adapter->mbox->m_in.numstatus = 0xFF;
1297 status = adapter->mbox->m_in.status;
1300 * decrement the pending queue counter
1302 atomic_sub(nstatus, &adapter->pend_cmds);
1304 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1307 /* Acknowledge interrupt */
1310 mega_cmd_done(adapter, completed, nstatus, status);
1312 mega_rundoneq(adapter);
1316 /* Loop through any pending requests */
1317 if(atomic_read(&adapter->quiescent) == 0) {
1318 mega_runpendq(adapter);
1325 spin_unlock_irqrestore(&adapter->lock, flags);
1327 return IRQ_RETVAL(handled);
1332 * megaraid_isr_memmapped()
1334 * @devp - pointer to our soft state
1337 * Interrupt service routine for memory-mapped controllers.
1338 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1339 * and service the completed commands.
1342 megaraid_isr_memmapped(int irq, void *devp, struct pt_regs *regs)
1344 adapter_t *adapter = devp;
1345 unsigned long flags;
1349 u8 completed[MAX_FIRMWARE_STATUS];
1354 * loop till F/W has more commands for us to complete.
1356 spin_lock_irqsave(&adapter->lock, flags);
1359 /* Check if a valid interrupt is pending */
1360 dword = RDOUTDOOR(adapter);
1361 if(dword != 0x10001234) {
1363 * No more pending commands
1367 WROUTDOOR(adapter, 0x10001234);
1369 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1373 adapter->mbox->m_in.numstatus = 0xFF;
1375 status = adapter->mbox->m_in.status;
1378 * decrement the pending queue counter
1380 atomic_sub(nstatus, &adapter->pend_cmds);
1382 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1385 /* Acknowledge interrupt */
1386 WRINDOOR(adapter, 0x2);
1390 while( RDINDOOR(adapter) & 0x02 ) cpu_relax();
1392 mega_cmd_done(adapter, completed, nstatus, status);
1394 mega_rundoneq(adapter);
1396 /* Loop through any pending requests */
1397 if(atomic_read(&adapter->quiescent) == 0) {
1398 mega_runpendq(adapter);
1405 spin_unlock_irqrestore(&adapter->lock, flags);
1407 return IRQ_RETVAL(handled);
1411 * @adapter - pointer to our soft state
1412 * @completed - array of ids of completed commands
1413 * @nstatus - number of completed commands
1414 * @status - status of the last command completed
1416 * Complete the comamnds and call the scsi mid-layer callback hooks.
1419 mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
1421 mega_ext_passthru *epthru = NULL;
1422 struct scatterlist *sgl;
1423 Scsi_Cmnd *cmd = NULL;
1424 mega_passthru *pthru = NULL;
1425 mbox_t *mbox = NULL;
1433 * for all the commands completed, call the mid-layer callback routine
1436 for( i = 0; i < nstatus; i++ ) {
1438 cmdid = completed[i];
1440 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1441 scb = &adapter->int_scb;
1443 mbox = (mbox_t *)scb->raw_mbox;
1446 * Internal command interface do not fire the extended
1447 * passthru or 64-bit passthru
1453 scb = &adapter->scb_list[cmdid];
1456 * Make sure f/w has completed a valid command
1458 if( !(scb->state & SCB_ISSUED) || scb->cmd == NULL ) {
1460 "megaraid: invalid command ");
1461 printk("Id %d, scb->state:%x, scsi cmd:%p\n",
1462 cmdid, scb->state, scb->cmd);
1468 * Was a abort issued for this command
1470 if( scb->state & SCB_ABORT ) {
1473 "megaraid: aborted cmd %lx[%x] complete.\n",
1474 scb->cmd->serial_number, scb->idx);
1476 scb->cmd->result = (DID_ABORT << 16);
1478 list_add_tail(SCSI_LIST(scb->cmd),
1479 &adapter->completed_list);
1481 mega_free_scb(adapter, scb);
1487 * Was a reset issued for this command
1489 if( scb->state & SCB_RESET ) {
1492 "megaraid: reset cmd %lx[%x] complete.\n",
1493 scb->cmd->serial_number, scb->idx);
1495 scb->cmd->result = (DID_RESET << 16);
1497 list_add_tail(SCSI_LIST(scb->cmd),
1498 &adapter->completed_list);
1500 mega_free_scb (adapter, scb);
1507 epthru = scb->epthru;
1508 mbox = (mbox_t *)scb->raw_mbox;
1513 int logdrv = mbox->m_out.logdrv;
1515 islogical = adapter->logdrv_chan[cmd->channel];
1517 * Maintain an error counter for the logical drive.
1518 * Some application like SNMP agent need such
1521 if( status && islogical && (cmd->cmnd[0] == READ_6 ||
1522 cmd->cmnd[0] == READ_10 ||
1523 cmd->cmnd[0] == READ_12)) {
1525 * Logical drive number increases by 0x80 when
1526 * a logical drive is deleted
1528 adapter->rd_errors[logdrv%0x80]++;
1531 if( status && islogical && (cmd->cmnd[0] == WRITE_6 ||
1532 cmd->cmnd[0] == WRITE_10 ||
1533 cmd->cmnd[0] == WRITE_12)) {
1535 * Logical drive number increases by 0x80 when
1536 * a logical drive is deleted
1538 adapter->wr_errors[logdrv%0x80]++;
1546 * Do not return the presence of hard disk on the channel so,
1547 * inquiry sent, and returned data==hard disk or removable
1548 * hard disk and not logical, request should return failure! -
1551 islogical = adapter->logdrv_chan[cmd->device->channel];
1552 if( cmd->cmnd[0] == INQUIRY && !islogical ) {
1555 sgl = (struct scatterlist *)
1556 cmd->request_buffer;
1559 c = *(unsigned char *)
1560 page_address((&sgl[0])->page) +
1565 "megaraid: invalid sg.\n");
1570 c = *(u8 *)cmd->request_buffer;
1573 if(IS_RAID_CH(adapter, cmd->device->channel) &&
1574 ((c & 0x1F ) == TYPE_DISK)) {
1579 /* clear result; otherwise, success returns corrupt value */
1582 /* Convert MegaRAID status to Linux error code */
1584 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1585 cmd->result |= (DID_OK << 16);
1588 case 0x02: /* ERROR_ABORTED, i.e.
1589 SCSI_STATUS_CHECK_CONDITION */
1591 /* set sense_buffer and result fields */
1592 if( mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU ||
1593 mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU64 ) {
1595 memcpy(cmd->sense_buffer, pthru->reqsensearea,
1598 cmd->result = (DRIVER_SENSE << 24) |
1600 (CHECK_CONDITION << 1);
1603 if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
1605 memcpy(cmd->sense_buffer,
1606 epthru->reqsensearea, 14);
1608 cmd->result = (DRIVER_SENSE << 24) |
1610 (CHECK_CONDITION << 1);
1612 cmd->sense_buffer[0] = 0x70;
1613 cmd->sense_buffer[2] = ABORTED_COMMAND;
1614 cmd->result |= (CHECK_CONDITION << 1);
1619 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1621 cmd->result |= (DID_BUS_BUSY << 16) | status;
1625 #if MEGA_HAVE_CLUSTERING
1627 * If TEST_UNIT_READY fails, we know
1628 * MEGA_RESERVATION_STATUS failed
1630 if( cmd->cmnd[0] == TEST_UNIT_READY ) {
1631 cmd->result |= (DID_ERROR << 16) |
1632 (RESERVATION_CONFLICT << 1);
1636 * Error code returned is 1 if Reserve or Release
1637 * failed or the input parameter is invalid
1640 (cmd->cmnd[0] == RESERVE ||
1641 cmd->cmnd[0] == RELEASE) ) {
1643 cmd->result |= (DID_ERROR << 16) |
1644 (RESERVATION_CONFLICT << 1);
1648 cmd->result |= (DID_BAD_TARGET << 16)|status;
1652 * Only free SCBs for the commands coming down from the
1653 * mid-layer, not for which were issued internally
1655 * For internal command, restore the status returned by the
1656 * firmware so that user can interpret it.
1658 if( cmdid == CMDID_INT_CMDS ) { /* internal command */
1659 cmd->result = status;
1662 * Remove the internal command from the pending list
1664 list_del_init(&scb->list);
1665 scb->state = SCB_FREE;
1668 mega_free_scb(adapter, scb);
1671 /* Add Scsi_Command to end of completed queue */
1672 list_add_tail(SCSI_LIST(cmd), &adapter->completed_list);
1680 * Run through the list of completed requests and finish it
1683 mega_rundoneq (adapter_t *adapter)
1686 struct list_head *pos;
1688 list_for_each(pos, &adapter->completed_list) {
1690 Scsi_Pointer* spos = (Scsi_Pointer *)pos;
1692 cmd = list_entry(spos, Scsi_Cmnd, SCp);
1693 cmd->scsi_done(cmd);
1696 INIT_LIST_HEAD(&adapter->completed_list);
1701 * Free a SCB structure
1702 * Note: We assume the scsi commands associated with this scb is not free yet.
1705 mega_free_scb(adapter_t *adapter, scb_t *scb)
1707 switch( scb->dma_type ) {
1709 case MEGA_DMA_TYPE_NONE:
1712 case MEGA_BULK_DATA:
1713 pci_unmap_page(adapter->dev, scb->dma_h_bulkdata,
1714 scb->cmd->request_bufflen, scb->dma_direction);
1718 pci_unmap_sg(adapter->dev, scb->cmd->request_buffer,
1719 scb->cmd->use_sg, scb->dma_direction);
1727 * Remove from the pending list
1729 list_del_init(&scb->list);
1731 /* Link the scb back into free list */
1732 scb->state = SCB_FREE;
1735 list_add(&scb->list, &adapter->free_list);
1740 __mega_busywait_mbox (adapter_t *adapter)
1742 volatile mbox_t *mbox = adapter->mbox;
1745 for (counter = 0; counter < 10000; counter++) {
1746 if (!mbox->m_in.busy)
1748 udelay(100); yield();
1750 return -1; /* give up after 1 second */
1754 * Copies data to SGLIST
1755 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1758 mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len)
1760 struct scatterlist *sgl;
1762 unsigned long offset;
1769 /* Scatter-gather not used */
1770 if( !cmd->use_sg ) {
1772 page = virt_to_page(cmd->request_buffer);
1773 offset = offset_in_page(cmd->request_buffer);
1775 scb->dma_h_bulkdata = pci_map_page(adapter->dev,
1777 cmd->request_bufflen,
1778 scb->dma_direction);
1779 scb->dma_type = MEGA_BULK_DATA;
1782 * We need to handle special 64-bit commands that need a
1785 if( adapter->has_64bit_addr ) {
1786 scb->sgl64[0].address = scb->dma_h_bulkdata;
1787 scb->sgl64[0].length = cmd->request_bufflen;
1788 *buf = (u32)scb->sgl_dma_addr;
1789 *len = (u32)cmd->request_bufflen;
1793 *buf = (u32)scb->dma_h_bulkdata;
1794 *len = (u32)cmd->request_bufflen;
1799 sgl = (struct scatterlist *)cmd->request_buffer;
1802 * Copy Scatter-Gather list info into controller structure.
1804 * The number of sg elements returned must not exceed our limit
1806 sgcnt = pci_map_sg(adapter->dev, sgl, cmd->use_sg,
1807 scb->dma_direction);
1809 scb->dma_type = MEGA_SGLIST;
1811 if( sgcnt > adapter->sglen ) BUG();
1813 for( idx = 0; idx < sgcnt; idx++, sgl++ ) {
1815 if( adapter->has_64bit_addr ) {
1816 scb->sgl64[idx].address = sg_dma_address(sgl);
1817 scb->sgl64[idx].length = sg_dma_len(sgl);
1820 scb->sgl[idx].address = sg_dma_address(sgl);
1821 scb->sgl[idx].length = sg_dma_len(sgl);
1825 /* Reset pointer and length fields */
1826 *buf = scb->sgl_dma_addr;
1829 * For passthru command, dataxferlen must be set, even for commands
1832 *len = (u32)cmd->request_bufflen;
1834 /* Return count of SG requests */
1842 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1843 * Enquiry3 structures for later use
1846 mega_8_to_40ld(mraid_inquiry *inquiry, mega_inquiry3 *enquiry3,
1847 mega_product_info *product_info)
1851 product_info->max_commands = inquiry->adapter_info.max_commands;
1852 enquiry3->rebuild_rate = inquiry->adapter_info.rebuild_rate;
1853 product_info->nchannels = inquiry->adapter_info.nchannels;
1855 for (i = 0; i < 4; i++) {
1856 product_info->fw_version[i] =
1857 inquiry->adapter_info.fw_version[i];
1859 product_info->bios_version[i] =
1860 inquiry->adapter_info.bios_version[i];
1862 enquiry3->cache_flush_interval =
1863 inquiry->adapter_info.cache_flush_interval;
1865 product_info->dram_size = inquiry->adapter_info.dram_size;
1867 enquiry3->num_ldrv = inquiry->logdrv_info.num_ldrv;
1869 for (i = 0; i < MAX_LOGICAL_DRIVES_8LD; i++) {
1870 enquiry3->ldrv_size[i] = inquiry->logdrv_info.ldrv_size[i];
1871 enquiry3->ldrv_prop[i] = inquiry->logdrv_info.ldrv_prop[i];
1872 enquiry3->ldrv_state[i] = inquiry->logdrv_info.ldrv_state[i];
1875 for (i = 0; i < (MAX_PHYSICAL_DRIVES); i++)
1876 enquiry3->pdrv_state[i] = inquiry->pdrv_info.pdrv_state[i];
1880 mega_free_sgl(adapter_t *adapter)
1885 for(i = 0; i < adapter->max_cmds; i++) {
1887 scb = &adapter->scb_list[i];
1890 pci_free_consistent(adapter->dev,
1891 sizeof(mega_sgl64) * adapter->sglen,
1899 pci_free_consistent(adapter->dev, sizeof(mega_passthru),
1900 scb->pthru, scb->pthru_dma_addr);
1906 pci_free_consistent(adapter->dev,
1907 sizeof(mega_ext_passthru),
1908 scb->epthru, scb->epthru_dma_addr);
1918 * Get information about the card/driver
1921 megaraid_info(struct Scsi_Host *host)
1923 static char buffer[512];
1926 adapter = (adapter_t *)host->hostdata;
1929 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1930 adapter->fw_version, adapter->product_info.max_commands,
1931 adapter->host->max_id, adapter->host->max_channel,
1932 adapter->host->max_lun);
1937 * Abort a previous SCSI request. Only commands on the pending list can be
1938 * aborted. All the commands issued to the F/W must complete.
1941 megaraid_abort(Scsi_Cmnd *cmd)
1946 adapter = (adapter_t *)cmd->device->host->hostdata;
1948 rval = megaraid_abort_and_reset(adapter, cmd, SCB_ABORT);
1951 * This is required here to complete any completed requests
1952 * to be communicated over to the mid layer.
1954 mega_rundoneq(adapter);
1961 megaraid_reset(Scsi_Cmnd *cmd)
1967 adapter = (adapter_t *)cmd->device->host->hostdata;
1969 #if MEGA_HAVE_CLUSTERING
1970 mc.cmd = MEGA_CLUSTER_CMD;
1971 mc.opcode = MEGA_RESET_RESERVATIONS;
1973 spin_unlock_irq(&adapter->lock);
1974 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
1976 "megaraid: reservation reset failed.\n");
1979 printk(KERN_INFO "megaraid: reservation reset.\n");
1981 spin_lock_irq(&adapter->lock);
1984 rval = megaraid_abort_and_reset(adapter, cmd, SCB_RESET);
1987 * This is required here to complete any completed requests
1988 * to be communicated over to the mid layer.
1990 mega_rundoneq(adapter);
1998 * megaraid_abort_and_reset()
1999 * @adapter - megaraid soft state
2000 * @cmd - scsi command to be aborted or reset
2001 * @aor - abort or reset flag
2003 * Try to locate the scsi command in the pending queue. If found and is not
2004 * issued to the controller, abort/reset it. Otherwise return failure
2007 megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
2009 struct list_head *pos, *next;
2012 printk(KERN_WARNING "megaraid: %s-%lx cmd=%x <c=%d t=%d l=%d>\n",
2013 (aor == SCB_ABORT)? "ABORTING":"RESET", cmd->serial_number,
2014 cmd->cmnd[0], cmd->device->channel,
2015 cmd->device->id, cmd->device->lun);
2017 if(list_empty(&adapter->pending_list))
2020 list_for_each_safe(pos, next, &adapter->pending_list) {
2022 scb = list_entry(pos, scb_t, list);
2024 if (scb->cmd == cmd) { /* Found command */
2029 * Check if this command has firmare owenership. If
2030 * yes, we cannot reset this command. Whenever, f/w
2031 * completes this command, we will return appropriate
2034 if( scb->state & SCB_ISSUED ) {
2037 "megaraid: %s-%lx[%x], fw owner.\n",
2038 (aor==SCB_ABORT) ? "ABORTING":"RESET",
2039 cmd->serial_number, scb->idx);
2046 * Not yet issued! Remove from the pending
2050 "megaraid: %s-%lx[%x], driver owner.\n",
2051 (aor==SCB_ABORT) ? "ABORTING":"RESET",
2052 cmd->serial_number, scb->idx);
2054 mega_free_scb(adapter, scb);
2056 if( aor == SCB_ABORT ) {
2057 cmd->result = (DID_ABORT << 16);
2060 cmd->result = (DID_RESET << 16);
2063 list_add_tail(SCSI_LIST(cmd),
2064 &adapter->completed_list);
2075 make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
2077 *pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
2079 if( *pdev == NULL ) return -1;
2081 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
2083 if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) {
2092 free_local_pdev(struct pci_dev *pdev)
2098 * mega_allocate_inquiry()
2099 * @dma_handle - handle returned for dma address
2100 * @pdev - handle to pci device
2102 * allocates memory for inquiry structure
2104 static inline void *
2105 mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev)
2107 return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle);
2112 mega_free_inquiry(void *inquiry, dma_addr_t dma_handle, struct pci_dev *pdev)
2114 pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle);
2118 #ifdef CONFIG_PROC_FS
2119 /* Following code handles /proc fs */
2121 #define CREATE_READ_PROC(string, func) create_proc_read_entry(string, \
2122 S_IRUSR | S_IFREG, \
2123 controller_proc_dir_entry, \
2127 * mega_create_proc_entry()
2128 * @index - index in soft state array
2129 * @parent - parent node for this /proc entry
2131 * Creates /proc entries for our controllers.
2134 mega_create_proc_entry(int index, struct proc_dir_entry *parent)
2136 struct proc_dir_entry *controller_proc_dir_entry = NULL;
2137 u8 string[64] = { 0 };
2138 adapter_t *adapter = hba_soft_state[index];
2140 sprintf(string, "hba%d", adapter->host->host_no);
2142 controller_proc_dir_entry =
2143 adapter->controller_proc_dir_entry = proc_mkdir(string, parent);
2145 if(!controller_proc_dir_entry) {
2146 printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
2149 adapter->proc_read = CREATE_READ_PROC("config", proc_read_config);
2150 adapter->proc_stat = CREATE_READ_PROC("stat", proc_read_stat);
2151 adapter->proc_mbox = CREATE_READ_PROC("mailbox", proc_read_mbox);
2152 #if MEGA_HAVE_ENH_PROC
2153 adapter->proc_rr = CREATE_READ_PROC("rebuild-rate", proc_rebuild_rate);
2154 adapter->proc_battery = CREATE_READ_PROC("battery-status",
2158 * Display each physical drive on its channel
2160 adapter->proc_pdrvstat[0] = CREATE_READ_PROC("diskdrives-ch0",
2162 adapter->proc_pdrvstat[1] = CREATE_READ_PROC("diskdrives-ch1",
2164 adapter->proc_pdrvstat[2] = CREATE_READ_PROC("diskdrives-ch2",
2166 adapter->proc_pdrvstat[3] = CREATE_READ_PROC("diskdrives-ch3",
2170 * Display a set of up to 10 logical drive through each of following
2173 adapter->proc_rdrvstat[0] = CREATE_READ_PROC("raiddrives-0-9",
2175 adapter->proc_rdrvstat[1] = CREATE_READ_PROC("raiddrives-10-19",
2177 adapter->proc_rdrvstat[2] = CREATE_READ_PROC("raiddrives-20-29",
2179 adapter->proc_rdrvstat[3] = CREATE_READ_PROC("raiddrives-30-39",
2186 * proc_read_config()
2187 * @page - buffer to write the data in
2188 * @start - where the actual data has been written in page
2189 * @offset - same meaning as the read system call
2190 * @count - same meaning as the read system call
2191 * @eof - set if no more data needs to be returned
2192 * @data - pointer to our soft state
2194 * Display configuration information about the controller.
2197 proc_read_config(char *page, char **start, off_t offset, int count, int *eof,
2201 adapter_t *adapter = (adapter_t *)data;
2204 len += sprintf(page+len, "%s", MEGARAID_VERSION);
2206 if(adapter->product_info.product_name[0])
2207 len += sprintf(page+len, "%s\n",
2208 adapter->product_info.product_name);
2210 len += sprintf(page+len, "Controller Type: ");
2212 if( adapter->flag & BOARD_MEMMAP ) {
2213 len += sprintf(page+len,
2214 "438/466/467/471/493/518/520/531/532\n");
2217 len += sprintf(page+len,
2221 if(adapter->flag & BOARD_40LD) {
2222 len += sprintf(page+len,
2223 "Controller Supports 40 Logical Drives\n");
2226 if(adapter->flag & BOARD_64BIT) {
2227 len += sprintf(page+len,
2228 "Controller capable of 64-bit memory addressing\n");
2230 if( adapter->has_64bit_addr ) {
2231 len += sprintf(page+len,
2232 "Controller using 64-bit memory addressing\n");
2235 len += sprintf(page+len,
2236 "Controller is not using 64-bit memory addressing\n");
2239 len += sprintf(page+len, "Base = %08lx, Irq = %d, ", adapter->base,
2240 adapter->host->irq);
2242 len += sprintf(page+len, "Logical Drives = %d, Channels = %d\n",
2243 adapter->numldrv, adapter->product_info.nchannels);
2245 len += sprintf(page+len, "Version =%s:%s, DRAM = %dMb\n",
2246 adapter->fw_version, adapter->bios_version,
2247 adapter->product_info.dram_size);
2249 len += sprintf(page+len,
2250 "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2251 adapter->product_info.max_commands, adapter->max_cmds);
2253 len += sprintf(page+len, "support_ext_cdb = %d\n",
2254 adapter->support_ext_cdb);
2255 len += sprintf(page+len, "support_random_del = %d\n",
2256 adapter->support_random_del);
2257 len += sprintf(page+len, "boot_ldrv_enabled = %d\n",
2258 adapter->boot_ldrv_enabled);
2259 len += sprintf(page+len, "boot_ldrv = %d\n",
2260 adapter->boot_ldrv);
2261 len += sprintf(page+len, "boot_pdrv_enabled = %d\n",
2262 adapter->boot_pdrv_enabled);
2263 len += sprintf(page+len, "boot_pdrv_ch = %d\n",
2264 adapter->boot_pdrv_ch);
2265 len += sprintf(page+len, "boot_pdrv_tgt = %d\n",
2266 adapter->boot_pdrv_tgt);
2267 len += sprintf(page+len, "quiescent = %d\n",
2268 atomic_read(&adapter->quiescent));
2269 len += sprintf(page+len, "has_cluster = %d\n",
2270 adapter->has_cluster);
2272 len += sprintf(page+len, "\nModule Parameters:\n");
2273 len += sprintf(page+len, "max_cmd_per_lun = %d\n",
2275 len += sprintf(page+len, "max_sectors_per_io = %d\n",
2276 max_sectors_per_io);
2287 * @page - buffer to write the data in
2288 * @start - where the actual data has been written in page
2289 * @offset - same meaning as the read system call
2290 * @count - same meaning as the read system call
2291 * @eof - set if no more data needs to be returned
2292 * @data - pointer to our soft state
2294 * Diaplay statistical information about the I/O activity.
2297 proc_read_stat(char *page, char **start, off_t offset, int count, int *eof,
2304 i = 0; /* avoid compilation warnings */
2306 adapter = (adapter_t *)data;
2308 len = sprintf(page, "Statistical Information for this controller\n");
2309 len += sprintf(page+len, "pend_cmds = %d\n",
2310 atomic_read(&adapter->pend_cmds));
2312 for(i = 0; i < adapter->numldrv; i++) {
2313 len += sprintf(page+len, "Logical Drive %d:\n", i);
2315 len += sprintf(page+len,
2316 "\tReads Issued = %lu, Writes Issued = %lu\n",
2317 adapter->nreads[i], adapter->nwrites[i]);
2319 len += sprintf(page+len,
2320 "\tSectors Read = %lu, Sectors Written = %lu\n",
2321 adapter->nreadblocks[i], adapter->nwriteblocks[i]);
2323 len += sprintf(page+len,
2324 "\tRead errors = %lu, Write errors = %lu\n\n",
2325 adapter->rd_errors[i], adapter->wr_errors[i]);
2328 len += sprintf(page+len,
2329 "IO and error counters not compiled in driver.\n");
2340 * @page - buffer to write the data in
2341 * @start - where the actual data has been written in page
2342 * @offset - same meaning as the read system call
2343 * @count - same meaning as the read system call
2344 * @eof - set if no more data needs to be returned
2345 * @data - pointer to our soft state
2347 * Display mailbox information for the last command issued. This information
2348 * is good for debugging.
2351 proc_read_mbox(char *page, char **start, off_t offset, int count, int *eof,
2355 adapter_t *adapter = (adapter_t *)data;
2356 volatile mbox_t *mbox = adapter->mbox;
2359 len = sprintf(page, "Contents of Mail Box Structure\n");
2360 len += sprintf(page+len, " Fw Command = 0x%02x\n",
2362 len += sprintf(page+len, " Cmd Sequence = 0x%02x\n",
2364 len += sprintf(page+len, " No of Sectors= %04d\n",
2365 mbox->m_out.numsectors);
2366 len += sprintf(page+len, " LBA = 0x%02x\n",
2368 len += sprintf(page+len, " DTA = 0x%08x\n",
2369 mbox->m_out.xferaddr);
2370 len += sprintf(page+len, " Logical Drive= 0x%02x\n",
2371 mbox->m_out.logdrv);
2372 len += sprintf(page+len, " No of SG Elmt= 0x%02x\n",
2373 mbox->m_out.numsgelements);
2374 len += sprintf(page+len, " Busy = %01x\n",
2376 len += sprintf(page+len, " Status = 0x%02x\n",
2386 * proc_rebuild_rate()
2387 * @page - buffer to write the data in
2388 * @start - where the actual data has been written in page
2389 * @offset - same meaning as the read system call
2390 * @count - same meaning as the read system call
2391 * @eof - set if no more data needs to be returned
2392 * @data - pointer to our soft state
2394 * Display current rebuild rate
2397 proc_rebuild_rate(char *page, char **start, off_t offset, int count, int *eof,
2400 adapter_t *adapter = (adapter_t *)data;
2401 dma_addr_t dma_handle;
2403 struct pci_dev *pdev;
2406 if( make_local_pdev(adapter, &pdev) != 0 ) {
2411 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2412 free_local_pdev(pdev);
2417 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2419 len = sprintf(page, "Adapter inquiry failed.\n");
2421 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2423 mega_free_inquiry(inquiry, dma_handle, pdev);
2425 free_local_pdev(pdev);
2432 if( adapter->flag & BOARD_40LD ) {
2433 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2434 ((mega_inquiry3 *)inquiry)->rebuild_rate);
2437 len = sprintf(page, "Rebuild Rate: [%d%%]\n",
2438 ((mraid_ext_inquiry *)
2439 inquiry)->raid_inq.adapter_info.rebuild_rate);
2443 mega_free_inquiry(inquiry, dma_handle, pdev);
2445 free_local_pdev(pdev);
2455 * @page - buffer to write the data in
2456 * @start - where the actual data has been written in page
2457 * @offset - same meaning as the read system call
2458 * @count - same meaning as the read system call
2459 * @eof - set if no more data needs to be returned
2460 * @data - pointer to our soft state
2462 * Display information about the battery module on the controller.
2465 proc_battery(char *page, char **start, off_t offset, int count, int *eof,
2468 adapter_t *adapter = (adapter_t *)data;
2469 dma_addr_t dma_handle;
2471 struct pci_dev *pdev;
2472 u8 battery_status = 0;
2476 if( make_local_pdev(adapter, &pdev) != 0 ) {
2481 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2482 free_local_pdev(pdev);
2487 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2489 len = sprintf(page, "Adapter inquiry failed.\n");
2491 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2493 mega_free_inquiry(inquiry, dma_handle, pdev);
2495 free_local_pdev(pdev);
2502 if( adapter->flag & BOARD_40LD ) {
2503 battery_status = ((mega_inquiry3 *)inquiry)->battery_status;
2506 battery_status = ((mraid_ext_inquiry *)inquiry)->
2507 raid_inq.adapter_info.battery_status;
2511 * Decode the battery status
2513 sprintf(str, "Battery Status:[%d]", battery_status);
2515 if(battery_status == MEGA_BATT_CHARGE_DONE)
2516 strcat(str, " Charge Done");
2518 if(battery_status & MEGA_BATT_MODULE_MISSING)
2519 strcat(str, " Module Missing");
2521 if(battery_status & MEGA_BATT_LOW_VOLTAGE)
2522 strcat(str, " Low Voltage");
2524 if(battery_status & MEGA_BATT_TEMP_HIGH)
2525 strcat(str, " Temperature High");
2527 if(battery_status & MEGA_BATT_PACK_MISSING)
2528 strcat(str, " Pack Missing");
2530 if(battery_status & MEGA_BATT_CHARGE_INPROG)
2531 strcat(str, " Charge In-progress");
2533 if(battery_status & MEGA_BATT_CHARGE_FAIL)
2534 strcat(str, " Charge Fail");
2536 if(battery_status & MEGA_BATT_CYCLES_EXCEEDED)
2537 strcat(str, " Cycles Exceeded");
2539 len = sprintf(page, "%s\n", str);
2542 mega_free_inquiry(inquiry, dma_handle, pdev);
2544 free_local_pdev(pdev);
2554 * @page - buffer to write the data in
2555 * @start - where the actual data has been written in page
2556 * @offset - same meaning as the read system call
2557 * @count - same meaning as the read system call
2558 * @eof - set if no more data needs to be returned
2559 * @data - pointer to our soft state
2561 * Display information about the physical drives on physical channel 0.
2564 proc_pdrv_ch0(char *page, char **start, off_t offset, int count, int *eof,
2567 adapter_t *adapter = (adapter_t *)data;
2571 return (proc_pdrv(adapter, page, 0));
2577 * @page - buffer to write the data in
2578 * @start - where the actual data has been written in page
2579 * @offset - same meaning as the read system call
2580 * @count - same meaning as the read system call
2581 * @eof - set if no more data needs to be returned
2582 * @data - pointer to our soft state
2584 * Display information about the physical drives on physical channel 1.
2587 proc_pdrv_ch1(char *page, char **start, off_t offset, int count, int *eof,
2590 adapter_t *adapter = (adapter_t *)data;
2594 return (proc_pdrv(adapter, page, 1));
2600 * @page - buffer to write the data in
2601 * @start - where the actual data has been written in page
2602 * @offset - same meaning as the read system call
2603 * @count - same meaning as the read system call
2604 * @eof - set if no more data needs to be returned
2605 * @data - pointer to our soft state
2607 * Display information about the physical drives on physical channel 2.
2610 proc_pdrv_ch2(char *page, char **start, off_t offset, int count, int *eof,
2613 adapter_t *adapter = (adapter_t *)data;
2617 return (proc_pdrv(adapter, page, 2));
2623 * @page - buffer to write the data in
2624 * @start - where the actual data has been written in page
2625 * @offset - same meaning as the read system call
2626 * @count - same meaning as the read system call
2627 * @eof - set if no more data needs to be returned
2628 * @data - pointer to our soft state
2630 * Display information about the physical drives on physical channel 3.
2633 proc_pdrv_ch3(char *page, char **start, off_t offset, int count, int *eof,
2636 adapter_t *adapter = (adapter_t *)data;
2640 return (proc_pdrv(adapter, page, 3));
2646 * @page - buffer to write the data in
2647 * @adapter - pointer to our soft state
2649 * Display information about the physical drives.
2652 proc_pdrv(adapter_t *adapter, char *page, int channel)
2654 dma_addr_t dma_handle;
2656 dma_addr_t scsi_inq_dma_handle;
2658 struct pci_dev *pdev;
2667 if( make_local_pdev(adapter, &pdev) != 0 ) {
2671 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2675 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2676 len = sprintf(page, "Adapter inquiry failed.\n");
2678 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2684 scsi_inq = pci_alloc_consistent(pdev, 256, &scsi_inq_dma_handle);
2686 if( scsi_inq == NULL ) {
2687 len = sprintf(page, "memory not available for scsi inq.\n");
2692 if( adapter->flag & BOARD_40LD ) {
2693 pdrv_state = ((mega_inquiry3 *)inquiry)->pdrv_state;
2696 pdrv_state = ((mraid_ext_inquiry *)inquiry)->
2697 raid_inq.pdrv_info.pdrv_state;
2700 max_channels = adapter->product_info.nchannels;
2702 if( channel >= max_channels ) {
2706 for( tgt = 0; tgt <= MAX_TARGET; tgt++ ) {
2708 i = channel*16 + tgt;
2710 state = *(pdrv_state + i);
2712 switch( state & 0x0F ) {
2716 "Channel:%2d Id:%2d State: Online",
2722 "Channel:%2d Id:%2d State: Failed",
2728 "Channel:%2d Id:%2d State: Rebuild",
2734 "Channel:%2d Id:%2d State: Hot spare",
2740 "Channel:%2d Id:%2d State: Un-configured",
2747 * This interface displays inquiries for disk drives
2748 * only. Inquries for logical drives and non-disk
2749 * devices are available through /proc/scsi/scsi
2751 memset(scsi_inq, 0, 256);
2752 if( mega_internal_dev_inquiry(adapter, channel, tgt,
2753 scsi_inq_dma_handle) ||
2754 (scsi_inq[0] & 0x1F) != TYPE_DISK ) {
2759 * Check for overflow. We print less than 240
2760 * characters for inquiry
2762 if( (len + 240) >= PAGE_SIZE ) break;
2764 len += sprintf(page+len, "%s.\n", str);
2766 len += mega_print_inquiry(page+len, scsi_inq);
2770 pci_free_consistent(pdev, 256, scsi_inq, scsi_inq_dma_handle);
2772 mega_free_inquiry(inquiry, dma_handle, pdev);
2774 free_local_pdev(pdev);
2781 * Display scsi inquiry
2784 mega_print_inquiry(char *page, char *scsi_inq)
2789 len = sprintf(page, " Vendor: ");
2790 for( i = 8; i < 16; i++ ) {
2791 len += sprintf(page+len, "%c", scsi_inq[i]);
2794 len += sprintf(page+len, " Model: ");
2796 for( i = 16; i < 32; i++ ) {
2797 len += sprintf(page+len, "%c", scsi_inq[i]);
2800 len += sprintf(page+len, " Rev: ");
2802 for( i = 32; i < 36; i++ ) {
2803 len += sprintf(page+len, "%c", scsi_inq[i]);
2806 len += sprintf(page+len, "\n");
2808 i = scsi_inq[0] & 0x1f;
2810 len += sprintf(page+len, " Type: %s ",
2811 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] :
2814 len += sprintf(page+len,
2815 " ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
2817 if( (scsi_inq[2] & 0x07) == 1 && (scsi_inq[3] & 0x0f) == 1 )
2818 len += sprintf(page+len, " CCS\n");
2820 len += sprintf(page+len, "\n");
2828 * @page - buffer to write the data in
2829 * @start - where the actual data has been written in page
2830 * @offset - same meaning as the read system call
2831 * @count - same meaning as the read system call
2832 * @eof - set if no more data needs to be returned
2833 * @data - pointer to our soft state
2835 * Display real time information about the logical drives 0 through 9.
2838 proc_rdrv_10(char *page, char **start, off_t offset, int count, int *eof,
2841 adapter_t *adapter = (adapter_t *)data;
2845 return (proc_rdrv(adapter, page, 0, 9));
2851 * @page - buffer to write the data in
2852 * @start - where the actual data has been written in page
2853 * @offset - same meaning as the read system call
2854 * @count - same meaning as the read system call
2855 * @eof - set if no more data needs to be returned
2856 * @data - pointer to our soft state
2858 * Display real time information about the logical drives 0 through 9.
2861 proc_rdrv_20(char *page, char **start, off_t offset, int count, int *eof,
2864 adapter_t *adapter = (adapter_t *)data;
2868 return (proc_rdrv(adapter, page, 10, 19));
2874 * @page - buffer to write the data in
2875 * @start - where the actual data has been written in page
2876 * @offset - same meaning as the read system call
2877 * @count - same meaning as the read system call
2878 * @eof - set if no more data needs to be returned
2879 * @data - pointer to our soft state
2881 * Display real time information about the logical drives 0 through 9.
2884 proc_rdrv_30(char *page, char **start, off_t offset, int count, int *eof,
2887 adapter_t *adapter = (adapter_t *)data;
2891 return (proc_rdrv(adapter, page, 20, 29));
2897 * @page - buffer to write the data in
2898 * @start - where the actual data has been written in page
2899 * @offset - same meaning as the read system call
2900 * @count - same meaning as the read system call
2901 * @eof - set if no more data needs to be returned
2902 * @data - pointer to our soft state
2904 * Display real time information about the logical drives 0 through 9.
2907 proc_rdrv_40(char *page, char **start, off_t offset, int count, int *eof,
2910 adapter_t *adapter = (adapter_t *)data;
2914 return (proc_rdrv(adapter, page, 30, 39));
2920 * @page - buffer to write the data in
2921 * @adapter - pointer to our soft state
2922 * @start - starting logical drive to display
2923 * @end - ending logical drive to display
2925 * We do not print the inquiry information since its already available through
2926 * /proc/scsi/scsi interface
2929 proc_rdrv(adapter_t *adapter, char *page, int start, int end )
2931 dma_addr_t dma_handle;
2932 logdrv_param *lparam;
2935 dma_addr_t disk_array_dma_handle;
2937 struct pci_dev *pdev;
2944 if( make_local_pdev(adapter, &pdev) != 0 ) {
2948 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
2949 free_local_pdev(pdev);
2953 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2955 len = sprintf(page, "Adapter inquiry failed.\n");
2957 printk(KERN_WARNING "megaraid: inquiry failed.\n");
2959 mega_free_inquiry(inquiry, dma_handle, pdev);
2961 free_local_pdev(pdev);
2966 memset(&mc, 0, sizeof(megacmd_t));
2968 if( adapter->flag & BOARD_40LD ) {
2969 array_sz = sizeof(disk_array_40ld);
2971 rdrv_state = ((mega_inquiry3 *)inquiry)->ldrv_state;
2973 num_ldrv = ((mega_inquiry3 *)inquiry)->num_ldrv;
2976 array_sz = sizeof(disk_array_8ld);
2978 rdrv_state = ((mraid_ext_inquiry *)inquiry)->
2979 raid_inq.logdrv_info.ldrv_state;
2981 num_ldrv = ((mraid_ext_inquiry *)inquiry)->
2982 raid_inq.logdrv_info.num_ldrv;
2985 disk_array = pci_alloc_consistent(pdev, array_sz,
2986 &disk_array_dma_handle);
2988 if( disk_array == NULL ) {
2989 len = sprintf(page, "memory not available.\n");
2991 mega_free_inquiry(inquiry, dma_handle, pdev);
2993 free_local_pdev(pdev);
2998 mc.xferaddr = (u32)disk_array_dma_handle;
3000 if( adapter->flag & BOARD_40LD ) {
3001 mc.cmd = FC_NEW_CONFIG;
3002 mc.opcode = OP_DCMD_READ_CONFIG;
3004 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
3006 len = sprintf(page, "40LD read config failed.\n");
3008 mega_free_inquiry(inquiry, dma_handle, pdev);
3010 pci_free_consistent(pdev, array_sz, disk_array,
3011 disk_array_dma_handle);
3013 free_local_pdev(pdev);
3020 mc.cmd = NEW_READ_CONFIG_8LD;
3022 if( mega_internal_command(adapter, LOCK_INT, &mc, NULL) ) {
3024 mc.cmd = READ_CONFIG_8LD;
3026 if( mega_internal_command(adapter, LOCK_INT, &mc,
3030 "8LD read config failed.\n");
3032 mega_free_inquiry(inquiry, dma_handle, pdev);
3034 pci_free_consistent(pdev, array_sz,
3036 disk_array_dma_handle);
3038 free_local_pdev(pdev);
3045 for( i = start; i < ( (end+1 < num_ldrv) ? end+1 : num_ldrv ); i++ ) {
3047 if( adapter->flag & BOARD_40LD ) {
3049 &((disk_array_40ld *)disk_array)->ldrv[i].lparam;
3053 &((disk_array_8ld *)disk_array)->ldrv[i].lparam;
3057 * Check for overflow. We print less than 240 characters for
3058 * information about each logical drive.
3060 if( (len + 240) >= PAGE_SIZE ) break;
3062 len += sprintf(page+len, "Logical drive:%2d:, ", i);
3064 switch( rdrv_state[i] & 0x0F ) {
3066 len += sprintf(page+len, "state: offline");
3070 len += sprintf(page+len, "state: degraded");
3074 len += sprintf(page+len, "state: optimal");
3078 len += sprintf(page+len, "state: deleted");
3082 len += sprintf(page+len, "state: unknown");
3087 * Check if check consistency or initialization is going on
3088 * for this logical drive.
3090 if( (rdrv_state[i] & 0xF0) == 0x20 ) {
3091 len += sprintf(page+len,
3092 ", check-consistency in progress");
3094 else if( (rdrv_state[i] & 0xF0) == 0x10 ) {
3095 len += sprintf(page+len,
3096 ", initialization in progress");
3099 len += sprintf(page+len, "\n");
3101 len += sprintf(page+len, "Span depth:%3d, ",
3102 lparam->span_depth);
3104 len += sprintf(page+len, "RAID level:%3d, ",
3107 len += sprintf(page+len, "Stripe size:%3d, ",
3108 lparam->stripe_sz ? lparam->stripe_sz/2: 128);
3110 len += sprintf(page+len, "Row size:%3d\n",
3114 len += sprintf(page+len, "Read Policy: ");
3116 switch(lparam->read_ahead) {
3119 len += sprintf(page+len, "No read ahead, ");
3123 len += sprintf(page+len, "Read ahead, ");
3126 case ADAP_READ_AHEAD:
3127 len += sprintf(page+len, "Adaptive, ");
3132 len += sprintf(page+len, "Write Policy: ");
3134 switch(lparam->write_mode) {
3136 case WRMODE_WRITE_THRU:
3137 len += sprintf(page+len, "Write thru, ");
3140 case WRMODE_WRITE_BACK:
3141 len += sprintf(page+len, "Write back, ");
3145 len += sprintf(page+len, "Cache Policy: ");
3147 switch(lparam->direct_io) {
3150 len += sprintf(page+len, "Cached IO\n\n");
3154 len += sprintf(page+len, "Direct IO\n\n");
3159 mega_free_inquiry(inquiry, dma_handle, pdev);
3161 pci_free_consistent(pdev, array_sz, disk_array,
3162 disk_array_dma_handle);
3164 free_local_pdev(pdev);
3173 * megaraid_biosparam()
3175 * Return the disk geometry for a particular disk
3178 megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
3179 sector_t capacity, int geom[])
3188 /* Get pointer to host config structure */
3189 adapter = (adapter_t *)sdev->host->hostdata;
3191 if (IS_RAID_CH(adapter, sdev->channel)) {
3192 /* Default heads (64) & sectors (32) */
3195 cylinders = (ulong)capacity / (heads * sectors);
3198 * Handle extended translation size for logical drives
3201 if ((ulong)capacity >= 0x200000) {
3204 cylinders = (ulong)capacity / (heads * sectors);
3210 geom[2] = cylinders;
3213 bh = scsi_bios_ptable(bdev);
3216 rval = scsi_partsize(bh, capacity,
3217 &geom[2], &geom[0], &geom[1]);
3224 "megaraid: invalid partition on this disk on channel %d\n",
3227 /* Default heads (64) & sectors (32) */
3230 cylinders = (ulong)capacity / (heads * sectors);
3232 /* Handle extended translation size for logical drives > 1Gb */
3233 if ((ulong)capacity >= 0x200000) {
3236 cylinders = (ulong)capacity / (heads * sectors);
3242 geom[2] = cylinders;
3250 * @adapter - pointer to our soft state
3252 * Allocate memory for the various pointers in the scb structures:
3253 * scatter-gather list pointer, passthru and extended passthru structure
3257 mega_init_scb(adapter_t *adapter)
3262 for( i = 0; i < adapter->max_cmds; i++ ) {
3264 scb = &adapter->scb_list[i];
3272 for( i = 0; i < adapter->max_cmds; i++ ) {
3274 scb = &adapter->scb_list[i];
3278 scb->sgl64 = pci_alloc_consistent(adapter->dev,
3279 sizeof(mega_sgl64) * adapter->sglen,
3280 &scb->sgl_dma_addr);
3282 scb->sgl = (mega_sglist *)scb->sgl64;
3285 printk(KERN_WARNING "RAID: Can't allocate sglist.\n");
3286 mega_free_sgl(adapter);
3290 scb->pthru = pci_alloc_consistent(adapter->dev,
3291 sizeof(mega_passthru),
3292 &scb->pthru_dma_addr);
3295 printk(KERN_WARNING "RAID: Can't allocate passthru.\n");
3296 mega_free_sgl(adapter);
3300 scb->epthru = pci_alloc_consistent(adapter->dev,
3301 sizeof(mega_ext_passthru),
3302 &scb->epthru_dma_addr);
3304 if( !scb->epthru ) {
3306 "Can't allocate extended passthru.\n");
3307 mega_free_sgl(adapter);
3312 scb->dma_type = MEGA_DMA_TYPE_NONE;
3316 * lock not required since we are loading the driver, so no
3317 * commands possible right now.
3319 scb->state = SCB_FREE;
3321 list_add(&scb->list, &adapter->free_list);
3333 * Routines for the character/ioctl interface to the driver. Find out if this
3334 * is a valid open. If yes, increment the module use count so that it cannot
3338 megadev_open (struct inode *inode, struct file *filep)
3341 * Only allow superuser to access private ioctl interface
3343 if( !capable(CAP_SYS_ADMIN) ) return -EACCES;
3351 * @inode - Our device inode
3353 * @cmd - ioctl command
3354 * @arg - user buffer
3356 * ioctl entry point for our private ioctl interface. We move the data in from
3357 * the user space, prepare the command (if necessary, convert the old MIMD
3358 * ioctl to new ioctl command), and issue a synchronous command to the
3362 megadev_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
3369 mega_passthru __user *upthru; /* user address for passthru */
3370 mega_passthru *pthru; /* copy user passthru here */
3371 dma_addr_t pthru_dma_hndl;
3372 void *data = NULL; /* data to be transferred */
3373 dma_addr_t data_dma_hndl; /* dma handle for data xfer area */
3375 megastat_t __user *ustats;
3378 struct pci_dev *pdev;
3380 ustats = NULL; /* avoid compilation warnings */
3384 * Make sure only USCSICMD are issued through this interface.
3385 * MIMD application would still fire different command.
3387 if( (_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD) ) {
3392 * Check and convert a possible MIMD command to NIT command.
3393 * mega_m_to_n() copies the data from the user space, so we do not
3394 * have to do it here.
3395 * NOTE: We will need some user address to copyout the data, therefore
3396 * the inteface layer will also provide us with the required user
3399 memset(&uioc, 0, sizeof(nitioctl_t));
3400 if( (rval = mega_m_to_n( (void __user *)arg, &uioc)) != 0 )
3404 switch( uioc.opcode ) {
3406 case GET_DRIVER_VER:
3407 if( put_user(driver_ver, (u32 __user *)uioc.uioc_uaddr) )
3413 if( put_user(hba_count, (u32 __user *)uioc.uioc_uaddr) )
3417 * Shucks. MIMD interface returns a positive value for number
3418 * of adapters. TODO: Change it to return 0 when there is no
3419 * applicatio using mimd interface.
3428 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3431 if( copy_to_user(uioc.uioc_uaddr, mcontroller+adapno,
3432 sizeof(struct mcontroller)) )
3442 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3445 adapter = hba_soft_state[adapno];
3447 ustats = uioc.uioc_uaddr;
3449 if( copy_from_user(&num_ldrv, &ustats->num_ldrv, sizeof(int)) )
3453 * Check for the validity of the logical drive number
3455 if( num_ldrv >= MAX_LOGICAL_DRIVES_40LD ) return -EINVAL;
3457 if( copy_to_user(ustats->nreads, adapter->nreads,
3458 num_ldrv*sizeof(u32)) )
3461 if( copy_to_user(ustats->nreadblocks, adapter->nreadblocks,
3462 num_ldrv*sizeof(u32)) )
3465 if( copy_to_user(ustats->nwrites, adapter->nwrites,
3466 num_ldrv*sizeof(u32)) )
3469 if( copy_to_user(ustats->nwriteblocks, adapter->nwriteblocks,
3470 num_ldrv*sizeof(u32)) )
3473 if( copy_to_user(ustats->rd_errors, adapter->rd_errors,
3474 num_ldrv*sizeof(u32)) )
3477 if( copy_to_user(ustats->wr_errors, adapter->wr_errors,
3478 num_ldrv*sizeof(u32)) )
3489 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3492 adapter = hba_soft_state[adapno];
3495 * Deletion of logical drive is a special case. The adapter
3496 * should be quiescent before this command is issued.
3498 if( uioc.uioc_rmbox[0] == FC_DEL_LOGDRV &&
3499 uioc.uioc_rmbox[2] == OP_DEL_LOGDRV ) {
3502 * Do we support this feature
3504 if( !adapter->support_random_del ) {
3505 printk(KERN_WARNING "megaraid: logdrv ");
3506 printk("delete on non-supporting F/W.\n");
3511 rval = mega_del_logdrv( adapter, uioc.uioc_rmbox[3] );
3514 memset(&mc, 0, sizeof(megacmd_t));
3518 rval = mega_n_to_m((void __user *)arg, &mc);
3524 * This interface only support the regular passthru commands.
3525 * Reject extended passthru and 64-bit passthru
3527 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU64 ||
3528 uioc.uioc_rmbox[0] == MEGA_MBOXCMD_EXTPTHRU ) {
3530 printk(KERN_WARNING "megaraid: rejected passthru.\n");
3536 * For all internal commands, the buffer must be allocated in
3537 * <4GB address range
3539 if( make_local_pdev(adapter, &pdev) != 0 )
3542 /* Is it a passthru command or a DCMD */
3543 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
3544 /* Passthru commands */
3546 pthru = pci_alloc_consistent(pdev,
3547 sizeof(mega_passthru),
3550 if( pthru == NULL ) {
3551 free_local_pdev(pdev);
3556 * The user passthru structure
3558 upthru = (mega_passthru __user *)MBOX(uioc)->xferaddr;
3561 * Copy in the user passthru here.
3563 if( copy_from_user(pthru, upthru,
3564 sizeof(mega_passthru)) ) {
3566 pci_free_consistent(pdev,
3567 sizeof(mega_passthru), pthru,
3570 free_local_pdev(pdev);
3576 * Is there a data transfer
3578 if( pthru->dataxferlen ) {
3579 data = pci_alloc_consistent(pdev,
3583 if( data == NULL ) {
3584 pci_free_consistent(pdev,
3585 sizeof(mega_passthru),
3589 free_local_pdev(pdev);
3595 * Save the user address and point the kernel
3596 * address at just allocated memory
3598 uxferaddr = pthru->dataxferaddr;
3599 pthru->dataxferaddr = data_dma_hndl;
3604 * Is data coming down-stream
3606 if( pthru->dataxferlen && (uioc.flags & UIOC_WR) ) {
3610 if( copy_from_user(data, (char __user *)uxferaddr,
3611 pthru->dataxferlen) ) {
3613 goto freemem_and_return;
3617 memset(&mc, 0, sizeof(megacmd_t));
3619 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
3620 mc.xferaddr = (u32)pthru_dma_hndl;
3625 mega_internal_command(adapter, LOCK_INT, &mc, pthru);
3627 rval = mega_n_to_m((void __user *)arg, &mc);
3629 if( rval ) goto freemem_and_return;
3633 * Is data going up-stream
3635 if( pthru->dataxferlen && (uioc.flags & UIOC_RD) ) {
3636 if( copy_to_user((char __user *)uxferaddr, data,
3637 pthru->dataxferlen) ) {
3643 * Send the request sense data also, irrespective of
3644 * whether the user has asked for it or not.
3646 copy_to_user(upthru->reqsensearea,
3647 pthru->reqsensearea, 14);
3650 if( pthru->dataxferlen ) {
3651 pci_free_consistent(pdev,
3652 pthru->dataxferlen, data,
3656 pci_free_consistent(pdev, sizeof(mega_passthru),
3657 pthru, pthru_dma_hndl);
3659 free_local_pdev(pdev);
3667 * Is there a data transfer
3669 if( uioc.xferlen ) {
3670 data = pci_alloc_consistent(pdev,
3671 uioc.xferlen, &data_dma_hndl);
3673 if( data == NULL ) {
3674 free_local_pdev(pdev);
3678 uxferaddr = MBOX(uioc)->xferaddr;
3682 * Is data coming down-stream
3684 if( uioc.xferlen && (uioc.flags & UIOC_WR) ) {
3688 if( copy_from_user(data, (char __user *)uxferaddr,
3691 pci_free_consistent(pdev,
3693 data, data_dma_hndl);
3695 free_local_pdev(pdev);
3701 memcpy(&mc, MBOX(uioc), sizeof(megacmd_t));
3703 mc.xferaddr = (u32)data_dma_hndl;
3708 mega_internal_command(adapter, LOCK_INT, &mc, NULL);
3710 rval = mega_n_to_m((void __user *)arg, &mc);
3713 if( uioc.xferlen ) {
3714 pci_free_consistent(pdev,
3719 free_local_pdev(pdev);
3725 * Is data going up-stream
3727 if( uioc.xferlen && (uioc.flags & UIOC_RD) ) {
3728 if( copy_to_user((char __user *)uxferaddr, data,
3735 if( uioc.xferlen ) {
3736 pci_free_consistent(pdev,
3741 free_local_pdev(pdev);
3755 * @arg - user address
3756 * @uioc - new ioctl structure
3758 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3761 * Converts the older mimd ioctl structure to newer NIT structure
3764 mega_m_to_n(void __user *arg, nitioctl_t *uioc)
3766 struct uioctl_t uioc_mimd;
3767 char signature[8] = {0};
3773 * check is the application conforms to NIT. We do not have to do much
3775 * We exploit the fact that the signature is stored in the very
3776 * begining of the structure.
3779 if( copy_from_user(signature, arg, 7) )
3782 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3785 * NOTE NOTE: The nit ioctl is still under flux because of
3786 * change of mailbox definition, in HPE. No applications yet
3787 * use this interface and let's not have applications use this
3788 * interface till the new specifitions are in place.
3792 if( copy_from_user(uioc, arg, sizeof(nitioctl_t)) )
3799 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3801 * Get the user ioctl structure
3803 if( copy_from_user(&uioc_mimd, arg, sizeof(struct uioctl_t)) )
3808 * Get the opcode and subopcode for the commands
3810 opcode = uioc_mimd.ui.fcs.opcode;
3811 subopcode = uioc_mimd.ui.fcs.subopcode;
3816 switch (subopcode) {
3818 case MEGAIOC_QDRVRVER: /* Query driver version */
3819 uioc->opcode = GET_DRIVER_VER;
3820 uioc->uioc_uaddr = uioc_mimd.data;
3823 case MEGAIOC_QNADAP: /* Get # of adapters */
3824 uioc->opcode = GET_N_ADAP;
3825 uioc->uioc_uaddr = uioc_mimd.data;
3828 case MEGAIOC_QADAPINFO: /* Get adapter information */
3829 uioc->opcode = GET_ADAP_INFO;
3830 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3831 uioc->uioc_uaddr = uioc_mimd.data;
3843 uioc->opcode = MBOX_CMD;
3844 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3846 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3848 uioc->xferlen = uioc_mimd.ui.fcs.length;
3850 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3851 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3857 uioc->opcode = MBOX_CMD;
3858 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3860 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3863 * Choose the xferlen bigger of input and output data
3865 uioc->xferlen = uioc_mimd.outlen > uioc_mimd.inlen ?
3866 uioc_mimd.outlen : uioc_mimd.inlen;
3868 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3869 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3883 * @arg - user address
3884 * @mc - mailbox command
3886 * Updates the status information to the application, depending on application
3887 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3890 mega_n_to_m(void __user *arg, megacmd_t *mc)
3892 nitioctl_t __user *uiocp;
3893 megacmd_t __user *umc;
3894 mega_passthru __user *upthru;
3895 struct uioctl_t __user *uioc_mimd;
3896 char signature[8] = {0};
3899 * check is the application conforms to NIT.
3901 if( copy_from_user(signature, arg, 7) )
3904 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3908 if( put_user(mc->status, (u8 __user *)&MBOX_P(uiocp)->status) )
3911 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3913 umc = MBOX_P(uiocp);
3915 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3918 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus))
3925 if( put_user(mc->status, (u8 __user *)&uioc_mimd->mbox[17]) )
3928 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3930 umc = (megacmd_t __user *)uioc_mimd->mbox;
3932 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3935 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus) )
3945 * MEGARAID 'FW' commands.
3949 * mega_is_bios_enabled()
3950 * @adapter - pointer to our soft state
3952 * issue command to find out if the BIOS is enabled for this controller
3955 mega_is_bios_enabled(adapter_t *adapter)
3957 unsigned char raw_mbox[sizeof(struct mbox_out)];
3961 mbox = (mbox_t *)raw_mbox;
3963 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3965 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3967 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3969 raw_mbox[0] = IS_BIOS_ENABLED;
3970 raw_mbox[2] = GET_BIOS;
3973 ret = issue_scb_block(adapter, raw_mbox);
3975 return *(char *)adapter->mega_buffer;
3980 * mega_enum_raid_scsi()
3981 * @adapter - pointer to our soft state
3983 * Find out what channels are RAID/SCSI. This information is used to
3984 * differentiate the virtual channels and physical channels and to support
3985 * ROMB feature and non-disk devices.
3988 mega_enum_raid_scsi(adapter_t *adapter)
3990 unsigned char raw_mbox[sizeof(struct mbox_out)];
3994 mbox = (mbox_t *)raw_mbox;
3996 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3999 * issue command to find out what channels are raid/scsi
4001 raw_mbox[0] = CHNL_CLASS;
4002 raw_mbox[2] = GET_CHNL_CLASS;
4004 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4006 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4009 * Non-ROMB firware fail this command, so all channels
4010 * must be shown RAID
4012 adapter->mega_ch_class = 0xFF;
4014 if(!issue_scb_block(adapter, raw_mbox)) {
4015 adapter->mega_ch_class = *((char *)adapter->mega_buffer);
4019 for( i = 0; i < adapter->product_info.nchannels; i++ ) {
4020 if( (adapter->mega_ch_class >> i) & 0x01 ) {
4021 printk(KERN_INFO "megaraid: channel[%d] is raid.\n",
4025 printk(KERN_INFO "megaraid: channel[%d] is scsi.\n",
4035 * mega_get_boot_drv()
4036 * @adapter - pointer to our soft state
4038 * Find out which device is the boot device. Note, any logical drive or any
4039 * phyical device (e.g., a CDROM) can be designated as a boot device.
4042 mega_get_boot_drv(adapter_t *adapter)
4044 struct private_bios_data *prv_bios_data;
4045 unsigned char raw_mbox[sizeof(struct mbox_out)];
4052 mbox = (mbox_t *)raw_mbox;
4054 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4056 raw_mbox[0] = BIOS_PVT_DATA;
4057 raw_mbox[2] = GET_BIOS_PVT_DATA;
4059 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4061 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4063 adapter->boot_ldrv_enabled = 0;
4064 adapter->boot_ldrv = 0;
4066 adapter->boot_pdrv_enabled = 0;
4067 adapter->boot_pdrv_ch = 0;
4068 adapter->boot_pdrv_tgt = 0;
4070 if(issue_scb_block(adapter, raw_mbox) == 0) {
4072 (struct private_bios_data *)adapter->mega_buffer;
4075 cksum_p = (char *)prv_bios_data;
4076 for (i = 0; i < 14; i++ ) {
4077 cksum += (u16)(*cksum_p++);
4080 if (prv_bios_data->cksum == (u16)(0-cksum) ) {
4083 * If MSB is set, a physical drive is set as boot
4086 if( prv_bios_data->boot_drv & 0x80 ) {
4087 adapter->boot_pdrv_enabled = 1;
4088 boot_pdrv = prv_bios_data->boot_drv & 0x7F;
4089 adapter->boot_pdrv_ch = boot_pdrv / 16;
4090 adapter->boot_pdrv_tgt = boot_pdrv % 16;
4093 adapter->boot_ldrv_enabled = 1;
4094 adapter->boot_ldrv = prv_bios_data->boot_drv;
4102 * mega_support_random_del()
4103 * @adapter - pointer to our soft state
4105 * Find out if this controller supports random deletion and addition of
4109 mega_support_random_del(adapter_t *adapter)
4111 unsigned char raw_mbox[sizeof(struct mbox_out)];
4115 mbox = (mbox_t *)raw_mbox;
4117 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4122 raw_mbox[0] = FC_DEL_LOGDRV;
4123 raw_mbox[2] = OP_SUP_DEL_LOGDRV;
4125 rval = issue_scb_block(adapter, raw_mbox);
4132 * mega_support_ext_cdb()
4133 * @adapter - pointer to our soft state
4135 * Find out if this firmware support cdblen > 10
4138 mega_support_ext_cdb(adapter_t *adapter)
4140 unsigned char raw_mbox[sizeof(struct mbox_out)];
4144 mbox = (mbox_t *)raw_mbox;
4146 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4148 * issue command to find out if controller supports extended CDBs.
4153 rval = issue_scb_block(adapter, raw_mbox);
4161 * @adapter - pointer to our soft state
4162 * @logdrv - logical drive to be deleted
4164 * Delete the specified logical drive. It is the responsibility of the user
4165 * app to let the OS know about this operation.
4168 mega_del_logdrv(adapter_t *adapter, int logdrv)
4170 unsigned long flags;
4175 * Stop sending commands to the controller, queue them internally.
4176 * When deletion is complete, ISR will flush the queue.
4178 atomic_set(&adapter->quiescent, 1);
4181 * Wait till all the issued commands are complete and there are no
4182 * commands in the pending queue
4184 while (atomic_read(&adapter->pend_cmds) > 0 ||
4185 !list_empty(&adapter->pending_list))
4186 msleep(1000); /* sleep for 1s */
4188 rval = mega_do_del_logdrv(adapter, logdrv);
4190 spin_lock_irqsave(&adapter->lock, flags);
4193 * If delete operation was successful, add 0x80 to the logical drive
4194 * ids for commands in the pending queue.
4196 if (adapter->read_ldidmap) {
4197 struct list_head *pos;
4198 list_for_each(pos, &adapter->pending_list) {
4199 scb = list_entry(pos, scb_t, list);
4200 if (scb->pthru->logdrv < 0x80 )
4201 scb->pthru->logdrv += 0x80;
4205 atomic_set(&adapter->quiescent, 0);
4207 mega_runpendq(adapter);
4209 spin_unlock_irqrestore(&adapter->lock, flags);
4216 mega_do_del_logdrv(adapter_t *adapter, int logdrv)
4221 memset( &mc, 0, sizeof(megacmd_t));
4223 mc.cmd = FC_DEL_LOGDRV;
4224 mc.opcode = OP_DEL_LOGDRV;
4225 mc.subopcode = logdrv;
4227 rval = mega_internal_command(adapter, LOCK_INT, &mc, NULL);
4229 /* log this event */
4231 printk(KERN_WARNING "megaraid: Delete LD-%d failed.", logdrv);
4236 * After deleting first logical drive, the logical drives must be
4237 * addressed by adding 0x80 to the logical drive id.
4239 adapter->read_ldidmap = 1;
4246 * mega_get_max_sgl()
4247 * @adapter - pointer to our soft state
4249 * Find out the maximum number of scatter-gather elements supported by this
4250 * version of the firmware
4253 mega_get_max_sgl(adapter_t *adapter)
4255 unsigned char raw_mbox[sizeof(struct mbox_out)];
4258 mbox = (mbox_t *)raw_mbox;
4260 memset(mbox, 0, sizeof(raw_mbox));
4262 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4264 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4266 raw_mbox[0] = MAIN_MISC_OPCODE;
4267 raw_mbox[2] = GET_MAX_SG_SUPPORT;
4270 if( issue_scb_block(adapter, raw_mbox) ) {
4272 * f/w does not support this command. Choose the default value
4274 adapter->sglen = MIN_SGLIST;
4277 adapter->sglen = *((char *)adapter->mega_buffer);
4280 * Make sure this is not more than the resources we are
4281 * planning to allocate
4283 if ( adapter->sglen > MAX_SGLIST )
4284 adapter->sglen = MAX_SGLIST;
4292 * mega_support_cluster()
4293 * @adapter - pointer to our soft state
4295 * Find out if this firmware support cluster calls.
4298 mega_support_cluster(adapter_t *adapter)
4300 unsigned char raw_mbox[sizeof(struct mbox_out)];
4303 mbox = (mbox_t *)raw_mbox;
4305 memset(mbox, 0, sizeof(raw_mbox));
4307 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
4309 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
4312 * Try to get the initiator id. This command will succeed iff the
4313 * clustering is available on this HBA.
4315 raw_mbox[0] = MEGA_GET_TARGET_ID;
4317 if( issue_scb_block(adapter, raw_mbox) == 0 ) {
4320 * Cluster support available. Get the initiator target id.
4321 * Tell our id to mid-layer too.
4323 adapter->this_id = *(u32 *)adapter->mega_buffer;
4324 adapter->host->this_id = adapter->this_id;
4335 * @adapter - pointer to our soft state
4336 * @dma_handle - DMA address of the buffer
4338 * Issue internal comamnds while interrupts are available.
4339 * We only issue direct mailbox commands from within the driver. ioctl()
4340 * interface using these routines can issue passthru commands.
4343 mega_adapinq(adapter_t *adapter, dma_addr_t dma_handle)
4347 memset(&mc, 0, sizeof(megacmd_t));
4349 if( adapter->flag & BOARD_40LD ) {
4350 mc.cmd = FC_NEW_CONFIG;
4351 mc.opcode = NC_SUBOP_ENQUIRY3;
4352 mc.subopcode = ENQ3_GET_SOLICITED_FULL;
4355 mc.cmd = MEGA_MBOXCMD_ADPEXTINQ;
4358 mc.xferaddr = (u32)dma_handle;
4360 if ( mega_internal_command(adapter, LOCK_INT, &mc, NULL) != 0 ) {
4368 /** mega_internal_dev_inquiry()
4369 * @adapter - pointer to our soft state
4370 * @ch - channel for this device
4371 * @tgt - ID of this device
4372 * @buf_dma_handle - DMA address of the buffer
4374 * Issue the scsi inquiry for the specified device.
4377 mega_internal_dev_inquiry(adapter_t *adapter, u8 ch, u8 tgt,
4378 dma_addr_t buf_dma_handle)
4380 mega_passthru *pthru;
4381 dma_addr_t pthru_dma_handle;
4384 struct pci_dev *pdev;
4388 * For all internal commands, the buffer must be allocated in <4GB
4391 if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
4393 pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
4396 if( pthru == NULL ) {
4397 free_local_pdev(pdev);
4403 pthru->reqsenselen = 14;
4404 pthru->islogical = 0;
4406 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : ch;
4408 pthru->target = (adapter->flag & BOARD_40LD) ? (ch << 4)|tgt : tgt;
4412 pthru->cdb[0] = INQUIRY;
4416 pthru->cdb[4] = 255;
4420 pthru->dataxferaddr = (u32)buf_dma_handle;
4421 pthru->dataxferlen = 256;
4423 memset(&mc, 0, sizeof(megacmd_t));
4425 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
4426 mc.xferaddr = (u32)pthru_dma_handle;
4428 rval = mega_internal_command(adapter, LOCK_INT, &mc, pthru);
4430 pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
4433 free_local_pdev(pdev);
4440 * mega_internal_command()
4441 * @adapter - pointer to our soft state
4442 * @ls - the scope of the exclusion lock.
4443 * @mc - the mailbox command
4444 * @pthru - Passthru structure for DCDB commands
4446 * Issue the internal commands in interrupt mode.
4447 * The last argument is the address of the passthru structure if the command
4448 * to be fired is a passthru command
4450 * lockscope specifies whether the caller has already acquired the lock. Of
4451 * course, the caller must know which lock we are talking about.
4453 * Note: parameter 'pthru' is null for non-passthru commands.
4456 mega_internal_command(adapter_t *adapter, lockscope_t ls, megacmd_t *mc,
4457 mega_passthru *pthru )
4460 struct scsi_device *sdev;
4461 unsigned long flags = 0;
4466 * The internal commands share one command id and hence are
4467 * serialized. This is so because we want to reserve maximum number of
4468 * available command ids for the I/O commands.
4470 down(&adapter->int_mtx);
4472 scb = &adapter->int_scb;
4473 memset(scb, 0, sizeof(scb_t));
4475 scmd = &adapter->int_scmd;
4476 memset(scmd, 0, sizeof(Scsi_Cmnd));
4478 sdev = kmalloc(sizeof(struct scsi_device), GFP_KERNEL);
4479 memset(sdev, 0, sizeof(struct scsi_device));
4480 scmd->device = sdev;
4482 scmd->device->host = adapter->host;
4483 scmd->buffer = (void *)scb;
4484 scmd->cmnd[0] = MEGA_INTERNAL_CMD;
4486 scb->state |= SCB_ACTIVE;
4489 memcpy(scb->raw_mbox, mc, sizeof(megacmd_t));
4492 * Is it a passthru command
4494 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
4499 scb->idx = CMDID_INT_CMDS;
4504 * Get the lock only if the caller has not acquired it already
4506 if( ls == LOCK_INT ) spin_lock_irqsave(&adapter->lock, flags);
4508 megaraid_queue(scmd, mega_internal_done);
4510 if( ls == LOCK_INT ) spin_unlock_irqrestore(&adapter->lock, flags);
4513 * Wait till this command finishes. Do not use
4514 * wait_event_interruptible(). It causes panic if CTRL-C is hit when
4515 * dumping e.g., physical disk information through /proc interface.
4518 wait_event_interruptible(adapter->int_waitq, scmd->state);
4520 wait_event(adapter->int_waitq, scmd->state);
4522 rval = scmd->result;
4523 mc->status = scmd->result;
4527 * Print a debug message for all failed commands. Applications can use
4530 if( scmd->result && trace_level ) {
4531 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n",
4532 mc->cmd, mc->opcode, mc->subopcode, scmd->result);
4535 up(&adapter->int_mtx);
4542 * mega_internal_done()
4543 * @scmd - internal scsi command
4545 * Callback routine for internal commands.
4548 mega_internal_done(Scsi_Cmnd *scmd)
4552 adapter = (adapter_t *)scmd->device->host->hostdata;
4554 scmd->state = 1; /* thread waiting for its command to complete */
4557 * See comment in mega_internal_command() routine for
4558 * wait_event_interruptible()
4561 wake_up_interruptible(&adapter->int_waitq);
4563 wake_up(&adapter->int_waitq);
4568 static struct scsi_host_template megaraid_template = {
4569 .module = THIS_MODULE,
4571 .proc_name = "megaraid",
4572 .info = megaraid_info,
4573 .queuecommand = megaraid_queue,
4574 .bios_param = megaraid_biosparam,
4575 .max_sectors = MAX_SECTORS_PER_IO,
4576 .can_queue = MAX_COMMANDS,
4577 .this_id = DEFAULT_INITIATOR_ID,
4578 .sg_tablesize = MAX_SGLIST,
4579 .cmd_per_lun = DEF_CMD_PER_LUN,
4580 .use_clustering = ENABLE_CLUSTERING,
4581 .eh_abort_handler = megaraid_abort,
4582 .eh_device_reset_handler = megaraid_reset,
4583 .eh_bus_reset_handler = megaraid_reset,
4584 .eh_host_reset_handler = megaraid_reset,
4587 static int __devinit
4588 megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4590 struct Scsi_Host *host;
4592 unsigned long mega_baseport, tbase, flag = 0;
4593 u16 subsysid, subsysvid;
4594 u8 pci_bus, pci_dev_func;
4596 int error = -ENODEV;
4598 if (pci_enable_device(pdev))
4600 pci_set_master(pdev);
4602 pci_bus = pdev->bus->number;
4603 pci_dev_func = pdev->devfn;
4606 * The megaraid3 stuff reports the ID of the Intel part which is not
4607 * remotely specific to the megaraid
4609 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
4612 * Don't fall over the Compaq management cards using the same
4615 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ &&
4616 pdev->subsystem_device == 0xC000)
4618 /* Now check the magic signature byte */
4619 pci_read_config_word(pdev, PCI_CONF_AMISIG, &magic);
4620 if (magic != HBA_SIGNATURE_471 && magic != HBA_SIGNATURE)
4622 /* Ok it is probably a megaraid */
4626 * For these vendor and device ids, signature offsets are not
4627 * valid and 64 bit is implicit
4629 if (id->driver_data & BOARD_64BIT)
4630 flag |= BOARD_64BIT;
4634 pci_read_config_dword(pdev, PCI_CONF_AMISIG64, &magic64);
4635 if (magic64 == HBA_SIGNATURE_64BIT)
4636 flag |= BOARD_64BIT;
4639 subsysvid = pdev->subsystem_vendor;
4640 subsysid = pdev->subsystem_device;
4642 printk(KERN_NOTICE "megaraid: found 0x%4.04x:0x%4.04x:bus %d:",
4643 id->vendor, id->device, pci_bus);
4645 printk("slot %d:func %d\n",
4646 PCI_SLOT(pci_dev_func), PCI_FUNC(pci_dev_func));
4648 /* Read the base port and IRQ from PCI */
4649 mega_baseport = pci_resource_start(pdev, 0);
4652 tbase = mega_baseport;
4653 if (pci_resource_flags(pdev, 0) & IORESOURCE_MEM) {
4654 flag |= BOARD_MEMMAP;
4656 if (!request_mem_region(mega_baseport, 128, "megaraid")) {
4657 printk(KERN_WARNING "megaraid: mem region busy!\n");
4658 goto out_disable_device;
4661 mega_baseport = (unsigned long)ioremap(mega_baseport, 128);
4662 if (!mega_baseport) {
4664 "megaraid: could not map hba memory\n");
4665 goto out_release_region;
4668 flag |= BOARD_IOMAP;
4669 mega_baseport += 0x10;
4671 if (!request_region(mega_baseport, 16, "megaraid"))
4672 goto out_disable_device;
4675 /* Initialize SCSI Host structure */
4676 host = scsi_host_alloc(&megaraid_template, sizeof(adapter_t));
4680 adapter = (adapter_t *)host->hostdata;
4681 memset(adapter, 0, sizeof(adapter_t));
4684 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4685 host->host_no, mega_baseport, irq);
4687 adapter->base = mega_baseport;
4689 INIT_LIST_HEAD(&adapter->free_list);
4690 INIT_LIST_HEAD(&adapter->pending_list);
4691 INIT_LIST_HEAD(&adapter->completed_list);
4693 adapter->flag = flag;
4694 spin_lock_init(&adapter->lock);
4695 scsi_assign_lock(host, &adapter->lock);
4697 host->cmd_per_lun = max_cmd_per_lun;
4698 host->max_sectors = max_sectors_per_io;
4700 adapter->dev = pdev;
4701 adapter->host = host;
4703 adapter->host->irq = irq;
4705 if (flag & BOARD_MEMMAP)
4706 adapter->host->base = tbase;
4708 adapter->host->io_port = tbase;
4709 adapter->host->n_io_port = 16;
4712 adapter->host->unique_id = (pci_bus << 8) | pci_dev_func;
4715 * Allocate buffer to issue internal commands.
4717 adapter->mega_buffer = pci_alloc_consistent(adapter->dev,
4718 MEGA_BUFFER_SIZE, &adapter->buf_dma_handle);
4719 if (!adapter->mega_buffer) {
4720 printk(KERN_WARNING "megaraid: out of RAM.\n");
4724 adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
4725 if (!adapter->scb_list) {
4726 printk(KERN_WARNING "megaraid: out of RAM.\n");
4727 goto out_free_cmd_buffer;
4730 if (request_irq(irq, (adapter->flag & BOARD_MEMMAP) ?
4731 megaraid_isr_memmapped : megaraid_isr_iomapped,
4732 SA_SHIRQ, "megaraid", adapter)) {
4734 "megaraid: Couldn't register IRQ %d!\n", irq);
4735 goto out_free_scb_list;
4738 if (mega_setup_mailbox(adapter))
4741 if (mega_query_adapter(adapter))
4745 * Have checks for some buggy f/w
4747 if ((subsysid == 0x1111) && (subsysvid == 0x1111)) {
4751 if (!strcmp(adapter->fw_version, "3.00") ||
4752 !strcmp(adapter->fw_version, "3.01")) {
4754 printk( KERN_WARNING
4755 "megaraid: Your card is a Dell PERC "
4756 "2/SC RAID controller with "
4757 "firmware\nmegaraid: 3.00 or 3.01. "
4758 "This driver is known to have "
4759 "corruption issues\nmegaraid: with "
4760 "those firmware versions on this "
4761 "specific card. In order\nmegaraid: "
4762 "to protect your data, please upgrade "
4763 "your firmware to version\nmegaraid: "
4764 "3.10 or later, available from the "
4765 "Dell Technical Support web\n"
4766 "megaraid: site at\nhttp://support."
4767 "dell.com/us/en/filelib/download/"
4768 "index.asp?fileid=2940\n"
4774 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4775 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4776 * support, since this firmware cannot handle 64 bit
4779 if ((subsysvid == HP_SUBSYS_VID) &&
4780 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) {
4784 if (!strcmp(adapter->fw_version, "H01.07") ||
4785 !strcmp(adapter->fw_version, "H01.08") ||
4786 !strcmp(adapter->fw_version, "H01.09") ) {
4788 "megaraid: Firmware H.01.07, "
4789 "H.01.08, and H.01.09 on 1M/2M "
4791 "megaraid: do not support 64 bit "
4792 "addressing.\nmegaraid: DISABLING "
4793 "64 bit support.\n");
4794 adapter->flag &= ~BOARD_64BIT;
4798 if (mega_is_bios_enabled(adapter))
4799 mega_hbas[hba_count].is_bios_enabled = 1;
4800 mega_hbas[hba_count].hostdata_addr = adapter;
4803 * Find out which channel is raid and which is scsi. This is
4806 mega_enum_raid_scsi(adapter);
4809 * Find out if a logical drive is set as the boot drive. If
4810 * there is one, will make that as the first logical drive.
4811 * ROMB: Do we have to boot from a physical drive. Then all
4812 * the physical drives would appear before the logical disks.
4813 * Else, all the physical drives would be exported to the mid
4814 * layer after logical drives.
4816 mega_get_boot_drv(adapter);
4818 if (adapter->boot_pdrv_enabled) {
4819 j = adapter->product_info.nchannels;
4820 for( i = 0; i < j; i++ )
4821 adapter->logdrv_chan[i] = 0;
4822 for( i = j; i < NVIRT_CHAN + j; i++ )
4823 adapter->logdrv_chan[i] = 1;
4825 for (i = 0; i < NVIRT_CHAN; i++)
4826 adapter->logdrv_chan[i] = 1;
4827 for (i = NVIRT_CHAN; i < MAX_CHANNELS+NVIRT_CHAN; i++)
4828 adapter->logdrv_chan[i] = 0;
4829 adapter->mega_ch_class <<= NVIRT_CHAN;
4833 * Do we support random deletion and addition of logical
4836 adapter->read_ldidmap = 0; /* set it after first logdrv
4838 adapter->support_random_del = mega_support_random_del(adapter);
4840 /* Initialize SCBs */
4841 if (mega_init_scb(adapter))
4845 * Reset the pending commands counter
4847 atomic_set(&adapter->pend_cmds, 0);
4850 * Reset the adapter quiescent flag
4852 atomic_set(&adapter->quiescent, 0);
4854 hba_soft_state[hba_count] = adapter;
4857 * Fill in the structure which needs to be passed back to the
4858 * application when it does an ioctl() for controller related
4863 mcontroller[i].base = mega_baseport;
4864 mcontroller[i].irq = irq;
4865 mcontroller[i].numldrv = adapter->numldrv;
4866 mcontroller[i].pcibus = pci_bus;
4867 mcontroller[i].pcidev = id->device;
4868 mcontroller[i].pcifun = PCI_FUNC (pci_dev_func);
4869 mcontroller[i].pciid = -1;
4870 mcontroller[i].pcivendor = id->vendor;
4871 mcontroller[i].pcislot = PCI_SLOT(pci_dev_func);
4872 mcontroller[i].uid = (pci_bus << 8) | pci_dev_func;
4875 /* Set the Mode of addressing to 64 bit if we can */
4876 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) {
4877 pci_set_dma_mask(pdev, 0xffffffffffffffffULL);
4878 adapter->has_64bit_addr = 1;
4880 pci_set_dma_mask(pdev, 0xffffffff);
4881 adapter->has_64bit_addr = 0;
4884 init_MUTEX(&adapter->int_mtx);
4885 init_waitqueue_head(&adapter->int_waitq);
4887 adapter->this_id = DEFAULT_INITIATOR_ID;
4888 adapter->host->this_id = DEFAULT_INITIATOR_ID;
4890 #if MEGA_HAVE_CLUSTERING
4892 * Is cluster support enabled on this controller
4893 * Note: In a cluster the HBAs ( the initiators ) will have
4894 * different target IDs and we cannot assume it to be 7. Call
4895 * to mega_support_cluster() will get the target ids also if
4896 * the cluster support is available
4898 adapter->has_cluster = mega_support_cluster(adapter);
4899 if (adapter->has_cluster) {
4901 "megaraid: Cluster driver, initiator id:%d\n",
4906 pci_set_drvdata(pdev, host);
4908 mega_create_proc_entry(hba_count, mega_proc_dir_entry);
4910 error = scsi_add_host(host, &pdev->dev);
4914 scsi_scan_host(host);
4919 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
4920 adapter->una_mbox64, adapter->una_mbox64_dma);
4922 free_irq(adapter->host->irq, adapter);
4924 kfree(adapter->scb_list);
4925 out_free_cmd_buffer:
4926 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
4927 adapter->mega_buffer, adapter->buf_dma_handle);
4929 scsi_host_put(host);
4931 if (flag & BOARD_MEMMAP)
4932 iounmap((void *)mega_baseport);
4934 if (flag & BOARD_MEMMAP)
4935 release_mem_region(tbase, 128);
4937 release_region(mega_baseport, 16);
4939 pci_disable_device(pdev);
4945 __megaraid_shutdown(adapter_t *adapter)
4947 u_char raw_mbox[sizeof(struct mbox_out)];
4948 mbox_t *mbox = (mbox_t *)raw_mbox;
4951 /* Flush adapter cache */
4952 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4953 raw_mbox[0] = FLUSH_ADAPTER;
4955 free_irq(adapter->host->irq, adapter);
4957 /* Issue a blocking (interrupts disabled) command to the card */
4958 issue_scb_block(adapter, raw_mbox);
4960 /* Flush disks cache */
4961 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4962 raw_mbox[0] = FLUSH_SYSTEM;
4964 /* Issue a blocking (interrupts disabled) command to the card */
4965 issue_scb_block(adapter, raw_mbox);
4967 if (atomic_read(&adapter->pend_cmds) > 0)
4968 printk(KERN_WARNING "megaraid: pending commands!!\n");
4971 * Have a delibrate delay to make sure all the caches are
4974 for (i = 0; i <= 10; i++)
4979 megaraid_remove_one(struct pci_dev *pdev)
4981 struct Scsi_Host *host = pci_get_drvdata(pdev);
4982 adapter_t *adapter = (adapter_t *)host->hostdata;
4983 char buf[12] = { 0 };
4985 scsi_remove_host(host);
4987 __megaraid_shutdown(adapter);
4989 /* Free our resources */
4990 if (adapter->flag & BOARD_MEMMAP) {
4991 iounmap((void *)adapter->base);
4992 release_mem_region(adapter->host->base, 128);
4994 release_region(adapter->base, 16);
4996 mega_free_sgl(adapter);
4998 #ifdef CONFIG_PROC_FS
4999 if (adapter->controller_proc_dir_entry) {
5000 remove_proc_entry("stat", adapter->controller_proc_dir_entry);
5001 remove_proc_entry("config",
5002 adapter->controller_proc_dir_entry);
5003 remove_proc_entry("mailbox",
5004 adapter->controller_proc_dir_entry);
5005 #if MEGA_HAVE_ENH_PROC
5006 remove_proc_entry("rebuild-rate",
5007 adapter->controller_proc_dir_entry);
5008 remove_proc_entry("battery-status",
5009 adapter->controller_proc_dir_entry);
5011 remove_proc_entry("diskdrives-ch0",
5012 adapter->controller_proc_dir_entry);
5013 remove_proc_entry("diskdrives-ch1",
5014 adapter->controller_proc_dir_entry);
5015 remove_proc_entry("diskdrives-ch2",
5016 adapter->controller_proc_dir_entry);
5017 remove_proc_entry("diskdrives-ch3",
5018 adapter->controller_proc_dir_entry);
5020 remove_proc_entry("raiddrives-0-9",
5021 adapter->controller_proc_dir_entry);
5022 remove_proc_entry("raiddrives-10-19",
5023 adapter->controller_proc_dir_entry);
5024 remove_proc_entry("raiddrives-20-29",
5025 adapter->controller_proc_dir_entry);
5026 remove_proc_entry("raiddrives-30-39",
5027 adapter->controller_proc_dir_entry);
5029 sprintf(buf, "hba%d", adapter->host->host_no);
5030 remove_proc_entry(buf, mega_proc_dir_entry);
5034 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
5035 adapter->mega_buffer, adapter->buf_dma_handle);
5036 kfree(adapter->scb_list);
5037 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
5038 adapter->una_mbox64, adapter->una_mbox64_dma);
5040 scsi_host_put(host);
5041 pci_disable_device(pdev);
5047 megaraid_shutdown(struct device *dev)
5049 struct Scsi_Host *host = pci_get_drvdata(to_pci_dev(dev));
5050 adapter_t *adapter = (adapter_t *)host->hostdata;
5052 __megaraid_shutdown(adapter);
5055 static struct pci_device_id megaraid_pci_tbl[] = {
5056 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DISCOVERY,
5057 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5058 {PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_PERC4_DI,
5059 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
5060 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_PERC4_QC_VERDE,
5061 PCI_ANY_ID, PCI_ANY_ID, 0, 0, BOARD_64BIT},
5062 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID,
5063 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5064 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID2,
5065 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5066 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID3,
5067 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5068 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_AMI_MEGARAID3,
5069 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5070 {PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_AMI_MEGARAID3,
5071 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
5074 MODULE_DEVICE_TABLE(pci, megaraid_pci_tbl);
5076 static struct pci_driver megaraid_pci_driver = {
5078 .id_table = megaraid_pci_tbl,
5079 .probe = megaraid_probe_one,
5080 .remove = __devexit_p(megaraid_remove_one),
5082 .shutdown = megaraid_shutdown,
5086 static int __init megaraid_init(void)
5090 if ((max_cmd_per_lun <= 0) || (max_cmd_per_lun > MAX_CMD_PER_LUN))
5091 max_cmd_per_lun = MAX_CMD_PER_LUN;
5092 if (max_mbox_busy_wait > MBOX_BUSY_WAIT)
5093 max_mbox_busy_wait = MBOX_BUSY_WAIT;
5095 #ifdef CONFIG_PROC_FS
5096 mega_proc_dir_entry = proc_mkdir("megaraid", &proc_root);
5097 if (!mega_proc_dir_entry) {
5099 "megaraid: failed to create megaraid root\n");
5102 error = pci_module_init(&megaraid_pci_driver);
5104 #ifdef CONFIG_PROC_FS
5105 remove_proc_entry("megaraid", &proc_root);
5111 * Register the driver as a character device, for applications
5112 * to access it for ioctls.
5113 * First argument (major) to register_chrdev implies a dynamic
5114 * major number allocation.
5116 major = register_chrdev(0, "megadev", &megadev_fops);
5119 "megaraid: failed to register char device\n");
5125 static void __exit megaraid_exit(void)
5128 * Unregister the character device interface to the driver.
5130 unregister_chrdev(major, "megadev");
5132 #ifdef CONFIG_PROC_FS
5133 remove_proc_entry("megaraid", &proc_root);
5136 pci_unregister_driver(&megaraid_pci_driver);
5139 module_init(megaraid_init);
5140 module_exit(megaraid_exit);
5142 /* vi: set ts=8 sw=8 tw=78: */