3 * Linux MegaRAID device driver
5 * Copyright (c) 2002 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
14 * - speed-ups (list handling fixes, issued_list, optimizations.)
17 * Copyright (c) 2003 Christoph Hellwig <hch@lst.de>
18 * - new-style, hotplug-aware pci probing and scsi registration
20 * Version : v2.00.4 Mon Nov 14 14:02:43 EST 2005 - Seokmann Ju
21 * <Seokmann.Ju@lsil.com>
23 * Description: Linux device driver for LSI Logic MegaRAID controller
25 * Supported controllers: MegaRAID 418, 428, 438, 466, 762, 467, 471, 490, 493
28 * This driver is supported by LSI Logic, with assistance from Red Hat, Dell,
29 * and others. Please send updates to the mailing list
30 * linux-scsi@vger.kernel.org .
36 #include <linux/blkdev.h>
37 #include <asm/uaccess.h>
39 #include <linux/completion.h>
40 #include <linux/delay.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/reboot.h>
44 #include <linux/module.h>
45 #include <linux/list.h>
46 #include <linux/interrupt.h>
47 #include <linux/pci.h>
48 #include <linux/init.h>
49 #include <linux/dma-mapping.h>
50 #include <linux/mutex.h>
51 #include <linux/slab.h>
52 #include <scsi/scsicam.h>
55 #include <scsi/scsi_host.h>
59 #define MEGARAID_MODULE_VERSION "2.00.4"
61 MODULE_AUTHOR ("sju@lsil.com");
62 MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
63 MODULE_LICENSE ("GPL");
64 MODULE_VERSION(MEGARAID_MODULE_VERSION);
66 static DEFINE_MUTEX(megadev_mutex);
67 static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
68 module_param(max_cmd_per_lun, uint, 0);
69 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)");
71 static unsigned short int max_sectors_per_io = MAX_SECTORS_PER_IO;
72 module_param(max_sectors_per_io, ushort, 0);
73 MODULE_PARM_DESC(max_sectors_per_io, "Maximum number of sectors per I/O request (default=MAX_SECTORS_PER_IO=128)");
76 static unsigned short int max_mbox_busy_wait = MBOX_BUSY_WAIT;
77 module_param(max_mbox_busy_wait, ushort, 0);
78 MODULE_PARM_DESC(max_mbox_busy_wait, "Maximum wait for mailbox in microseconds if busy (default=MBOX_BUSY_WAIT=10)");
80 #define RDINDOOR(adapter) readl((adapter)->mmio_base + 0x20)
81 #define RDOUTDOOR(adapter) readl((adapter)->mmio_base + 0x2C)
82 #define WRINDOOR(adapter,value) writel(value, (adapter)->mmio_base + 0x20)
83 #define WROUTDOOR(adapter,value) writel(value, (adapter)->mmio_base + 0x2C)
90 static adapter_t *hba_soft_state[MAX_CONTROLLERS];
91 static struct proc_dir_entry *mega_proc_dir_entry;
93 /* For controller re-ordering */
94 static struct mega_hbas mega_hbas[MAX_CONTROLLERS];
97 megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
100 * The File Operations structure for the serial/ioctl interface of the driver
102 static const struct file_operations megadev_fops = {
103 .owner = THIS_MODULE,
104 .unlocked_ioctl = megadev_unlocked_ioctl,
105 .open = megadev_open,
106 .llseek = noop_llseek,
110 * Array to structures for storing the information about the controllers. This
111 * information is sent to the user level applications, when they do an ioctl
112 * for this information.
114 static struct mcontroller mcontroller[MAX_CONTROLLERS];
116 /* The current driver version */
117 static u32 driver_ver = 0x02000000;
119 /* major number used by the device for character interface */
122 #define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
126 * Debug variable to print some diagnostic messages
128 static int trace_level;
131 * mega_setup_mailbox()
132 * @adapter - pointer to our soft state
134 * Allocates a 8 byte aligned memory for the handshake mailbox.
137 mega_setup_mailbox(adapter_t *adapter)
141 adapter->una_mbox64 = pci_alloc_consistent(adapter->dev,
142 sizeof(mbox64_t), &adapter->una_mbox64_dma);
144 if( !adapter->una_mbox64 ) return -1;
146 adapter->mbox = &adapter->una_mbox64->mbox;
148 adapter->mbox = (mbox_t *)((((unsigned long) adapter->mbox) + 15) &
151 adapter->mbox64 = (mbox64_t *)(((unsigned long)adapter->mbox) - 8);
153 align = ((void *)adapter->mbox) - ((void *)&adapter->una_mbox64->mbox);
155 adapter->mbox_dma = adapter->una_mbox64_dma + 8 + align;
158 * Register the mailbox if the controller is an io-mapped controller
160 if( adapter->flag & BOARD_IOMAP ) {
162 outb(adapter->mbox_dma & 0xFF,
163 adapter->host->io_port + MBOX_PORT0);
165 outb((adapter->mbox_dma >> 8) & 0xFF,
166 adapter->host->io_port + MBOX_PORT1);
168 outb((adapter->mbox_dma >> 16) & 0xFF,
169 adapter->host->io_port + MBOX_PORT2);
171 outb((adapter->mbox_dma >> 24) & 0xFF,
172 adapter->host->io_port + MBOX_PORT3);
174 outb(ENABLE_MBOX_BYTE,
175 adapter->host->io_port + ENABLE_MBOX_REGION);
187 * mega_query_adapter()
188 * @adapter - pointer to our soft state
190 * Issue the adapter inquiry commands to the controller and find out
191 * information and parameter about the devices attached
194 mega_query_adapter(adapter_t *adapter)
196 dma_addr_t prod_info_dma_handle;
197 mega_inquiry3 *inquiry3;
198 u8 raw_mbox[sizeof(struct mbox_out)];
202 /* Initialize adapter inquiry mailbox */
204 mbox = (mbox_t *)raw_mbox;
206 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
207 memset(&mbox->m_out, 0, sizeof(raw_mbox));
210 * Try to issue Inquiry3 command
211 * if not succeeded, then issue MEGA_MBOXCMD_ADAPTERINQ command and
212 * update enquiry3 structure
214 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
216 inquiry3 = (mega_inquiry3 *)adapter->mega_buffer;
218 raw_mbox[0] = FC_NEW_CONFIG; /* i.e. mbox->cmd=0xA1 */
219 raw_mbox[2] = NC_SUBOP_ENQUIRY3; /* i.e. 0x0F */
220 raw_mbox[3] = ENQ3_GET_SOLICITED_FULL; /* i.e. 0x02 */
222 /* Issue a blocking command to the card */
223 if ((retval = issue_scb_block(adapter, raw_mbox))) {
224 /* the adapter does not support 40ld */
226 mraid_ext_inquiry *ext_inq;
228 dma_addr_t dma_handle;
230 ext_inq = pci_alloc_consistent(adapter->dev,
231 sizeof(mraid_ext_inquiry), &dma_handle);
233 if( ext_inq == NULL ) return -1;
235 inq = &ext_inq->raid_inq;
237 mbox->m_out.xferaddr = (u32)dma_handle;
239 /*issue old 0x04 command to adapter */
240 mbox->m_out.cmd = MEGA_MBOXCMD_ADPEXTINQ;
242 issue_scb_block(adapter, raw_mbox);
245 * update Enquiry3 and ProductInfo structures with
246 * mraid_inquiry structure
248 mega_8_to_40ld(inq, inquiry3,
249 (mega_product_info *)&adapter->product_info);
251 pci_free_consistent(adapter->dev, sizeof(mraid_ext_inquiry),
252 ext_inq, dma_handle);
254 } else { /*adapter supports 40ld */
255 adapter->flag |= BOARD_40LD;
258 * get product_info, which is static information and will be
261 prod_info_dma_handle = pci_map_single(adapter->dev, (void *)
262 &adapter->product_info,
263 sizeof(mega_product_info), PCI_DMA_FROMDEVICE);
265 mbox->m_out.xferaddr = prod_info_dma_handle;
267 raw_mbox[0] = FC_NEW_CONFIG; /* i.e. mbox->cmd=0xA1 */
268 raw_mbox[2] = NC_SUBOP_PRODUCT_INFO; /* i.e. 0x0E */
270 if ((retval = issue_scb_block(adapter, raw_mbox)))
271 dev_warn(&adapter->dev->dev,
272 "Product_info cmd failed with error: %d\n",
275 pci_unmap_single(adapter->dev, prod_info_dma_handle,
276 sizeof(mega_product_info), PCI_DMA_FROMDEVICE);
281 * kernel scans the channels from 0 to <= max_channel
283 adapter->host->max_channel =
284 adapter->product_info.nchannels + NVIRT_CHAN -1;
286 adapter->host->max_id = 16; /* max targets per channel */
288 adapter->host->max_lun = 7; /* Up to 7 luns for non disk devices */
290 adapter->host->cmd_per_lun = max_cmd_per_lun;
292 adapter->numldrv = inquiry3->num_ldrv;
294 adapter->max_cmds = adapter->product_info.max_commands;
296 if(adapter->max_cmds > MAX_COMMANDS)
297 adapter->max_cmds = MAX_COMMANDS;
299 adapter->host->can_queue = adapter->max_cmds - 1;
302 * Get the maximum number of scatter-gather elements supported by this
305 mega_get_max_sgl(adapter);
307 adapter->host->sg_tablesize = adapter->sglen;
309 /* use HP firmware and bios version encoding
310 Note: fw_version[0|1] and bios_version[0|1] were originally shifted
311 right 8 bits making them zero. This 0 value was hardcoded to fix
313 if (adapter->product_info.subsysvid == PCI_VENDOR_ID_HP) {
314 sprintf (adapter->fw_version, "%c%d%d.%d%d",
315 adapter->product_info.fw_version[2],
317 adapter->product_info.fw_version[1] & 0x0f,
319 adapter->product_info.fw_version[0] & 0x0f);
320 sprintf (adapter->bios_version, "%c%d%d.%d%d",
321 adapter->product_info.bios_version[2],
323 adapter->product_info.bios_version[1] & 0x0f,
325 adapter->product_info.bios_version[0] & 0x0f);
327 memcpy(adapter->fw_version,
328 (char *)adapter->product_info.fw_version, 4);
329 adapter->fw_version[4] = 0;
331 memcpy(adapter->bios_version,
332 (char *)adapter->product_info.bios_version, 4);
334 adapter->bios_version[4] = 0;
337 dev_notice(&adapter->dev->dev, "[%s:%s] detected %d logical drives\n",
338 adapter->fw_version, adapter->bios_version, adapter->numldrv);
341 * Do we support extended (>10 bytes) cdbs
343 adapter->support_ext_cdb = mega_support_ext_cdb(adapter);
344 if (adapter->support_ext_cdb)
345 dev_notice(&adapter->dev->dev, "supports extended CDBs\n");
353 * @adapter - pointer to our soft state
355 * Runs through the list of pending requests.
358 mega_runpendq(adapter_t *adapter)
360 if(!list_empty(&adapter->pending_list))
361 __mega_runpendq(adapter);
366 * @scmd - Issue this scsi command
367 * @done - the callback hook into the scsi mid-layer
369 * The command queuing entry point for the mid-layer.
372 megaraid_queue_lck(Scsi_Cmnd *scmd, void (*done)(Scsi_Cmnd *))
379 adapter = (adapter_t *)scmd->device->host->hostdata;
381 scmd->scsi_done = done;
385 * Allocate and build a SCB request
386 * busy flag will be set if mega_build_cmd() command could not
387 * allocate scb. We will return non-zero status in that case.
388 * NOTE: scb can be null even though certain commands completed
389 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, we would
390 * return 0 in that case.
393 spin_lock_irqsave(&adapter->lock, flags);
394 scb = mega_build_cmd(adapter, scmd, &busy);
398 scb->state |= SCB_PENDQ;
399 list_add_tail(&scb->list, &adapter->pending_list);
402 * Check if the HBA is in quiescent state, e.g., during a
403 * delete logical drive opertion. If it is, don't run
406 if (atomic_read(&adapter->quiescent) == 0)
407 mega_runpendq(adapter);
411 spin_unlock_irqrestore(&adapter->lock, flags);
415 static DEF_SCSI_QCMD(megaraid_queue)
418 * mega_allocate_scb()
419 * @adapter - pointer to our soft state
420 * @cmd - scsi command from the mid-layer
422 * Allocate a SCB structure. This is the central structure for controller
425 static inline scb_t *
426 mega_allocate_scb(adapter_t *adapter, Scsi_Cmnd *cmd)
428 struct list_head *head = &adapter->free_list;
431 /* Unlink command from Free List */
432 if( !list_empty(head) ) {
434 scb = list_entry(head->next, scb_t, list);
436 list_del_init(head->next);
438 scb->state = SCB_ACTIVE;
440 scb->dma_type = MEGA_DMA_TYPE_NONE;
449 * mega_get_ldrv_num()
450 * @adapter - pointer to our soft state
451 * @cmd - scsi mid layer command
452 * @channel - channel on the controller
454 * Calculate the logical drive number based on the information in scsi command
455 * and the channel number.
458 mega_get_ldrv_num(adapter_t *adapter, Scsi_Cmnd *cmd, int channel)
463 tgt = cmd->device->id;
465 if ( tgt > adapter->this_id )
466 tgt--; /* we do not get inquires for initiator id */
468 ldrv_num = (channel * 15) + tgt;
472 * If we have a logical drive with boot enabled, project it first
474 if( adapter->boot_ldrv_enabled ) {
475 if( ldrv_num == 0 ) {
476 ldrv_num = adapter->boot_ldrv;
479 if( ldrv_num <= adapter->boot_ldrv ) {
486 * If "delete logical drive" feature is enabled on this controller.
487 * Do only if at least one delete logical drive operation was done.
489 * Also, after logical drive deletion, instead of logical drive number,
490 * the value returned should be 0x80+logical drive id.
492 * These is valid only for IO commands.
495 if (adapter->support_random_del && adapter->read_ldidmap )
496 switch (cmd->cmnd[0]) {
497 case READ_6: /* fall through */
498 case WRITE_6: /* fall through */
499 case READ_10: /* fall through */
509 * @adapter - pointer to our soft state
510 * @cmd - Prepare using this scsi command
511 * @busy - busy flag if no resources
513 * Prepares a command and scatter gather list for the controller. This routine
514 * also finds out if the commands is intended for a logical drive or a
515 * physical device and prepares the controller command accordingly.
517 * We also re-order the logical drives and physical devices based on their
521 mega_build_cmd(adapter_t *adapter, Scsi_Cmnd *cmd, int *busy)
523 mega_ext_passthru *epthru;
524 mega_passthru *pthru;
532 int ldrv_num = 0; /* logical drive number */
535 * We know what channels our logical drives are on - mega_find_card()
537 islogical = adapter->logdrv_chan[cmd->device->channel];
540 * The theory: If physical drive is chosen for boot, all the physical
541 * devices are exported before the logical drives, otherwise physical
542 * devices are pushed after logical drives, in which case - Kernel sees
543 * the physical devices on virtual channel which is obviously converted
544 * to actual channel on the HBA.
546 if( adapter->boot_pdrv_enabled ) {
548 /* logical channel */
549 channel = cmd->device->channel -
550 adapter->product_info.nchannels;
553 /* this is physical channel */
554 channel = cmd->device->channel;
555 target = cmd->device->id;
558 * boot from a physical disk, that disk needs to be
559 * exposed first IF both the channels are SCSI, then
560 * booting from the second channel is not allowed.
563 target = adapter->boot_pdrv_tgt;
565 else if( target == adapter->boot_pdrv_tgt ) {
572 /* this is the logical channel */
573 channel = cmd->device->channel;
576 /* physical channel */
577 channel = cmd->device->channel - NVIRT_CHAN;
578 target = cmd->device->id;
585 /* have just LUN 0 for each target on virtual channels */
586 if (cmd->device->lun) {
587 cmd->result = (DID_BAD_TARGET << 16);
592 ldrv_num = mega_get_ldrv_num(adapter, cmd, channel);
595 max_ldrv_num = (adapter->flag & BOARD_40LD) ?
596 MAX_LOGICAL_DRIVES_40LD : MAX_LOGICAL_DRIVES_8LD;
599 * max_ldrv_num increases by 0x80 if some logical drive was
602 if(adapter->read_ldidmap)
603 max_ldrv_num += 0x80;
605 if(ldrv_num > max_ldrv_num ) {
606 cmd->result = (DID_BAD_TARGET << 16);
613 if( cmd->device->lun > 7) {
615 * Do not support lun >7 for physically accessed
618 cmd->result = (DID_BAD_TARGET << 16);
626 * Logical drive commands
630 switch (cmd->cmnd[0]) {
631 case TEST_UNIT_READY:
632 #if MEGA_HAVE_CLUSTERING
634 * Do we support clustering and is the support enabled
635 * If no, return success always
637 if( !adapter->has_cluster ) {
638 cmd->result = (DID_OK << 16);
643 if(!(scb = mega_allocate_scb(adapter, cmd))) {
648 scb->raw_mbox[0] = MEGA_CLUSTER_CMD;
649 scb->raw_mbox[2] = MEGA_RESERVATION_STATUS;
650 scb->raw_mbox[3] = ldrv_num;
652 scb->dma_direction = PCI_DMA_NONE;
656 cmd->result = (DID_OK << 16);
663 struct scatterlist *sg;
665 sg = scsi_sglist(cmd);
666 buf = kmap_atomic(sg_page(sg)) + sg->offset;
668 memset(buf, 0, cmd->cmnd[4]);
669 kunmap_atomic(buf - sg->offset);
671 cmd->result = (DID_OK << 16);
679 if(!(adapter->flag & (1L << cmd->device->channel))) {
681 dev_notice(&adapter->dev->dev,
682 "scsi%d: scanning scsi channel %d "
683 "for logical drives\n",
684 adapter->host->host_no,
685 cmd->device->channel);
687 adapter->flag |= (1L << cmd->device->channel);
690 /* Allocate a SCB and initialize passthru */
691 if(!(scb = mega_allocate_scb(adapter, cmd))) {
697 mbox = (mbox_t *)scb->raw_mbox;
698 memset(mbox, 0, sizeof(scb->raw_mbox));
699 memset(pthru, 0, sizeof(mega_passthru));
703 pthru->reqsenselen = 14;
704 pthru->islogical = 1;
705 pthru->logdrv = ldrv_num;
706 pthru->cdblen = cmd->cmd_len;
707 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
709 if( adapter->has_64bit_addr ) {
710 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
713 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
716 scb->dma_direction = PCI_DMA_FROMDEVICE;
718 pthru->numsgelements = mega_build_sglist(adapter, scb,
719 &pthru->dataxferaddr, &pthru->dataxferlen);
721 mbox->m_out.xferaddr = scb->pthru_dma_addr;
732 /* Allocate a SCB and initialize mailbox */
733 if(!(scb = mega_allocate_scb(adapter, cmd))) {
737 mbox = (mbox_t *)scb->raw_mbox;
739 memset(mbox, 0, sizeof(scb->raw_mbox));
740 mbox->m_out.logdrv = ldrv_num;
743 * A little hack: 2nd bit is zero for all scsi read
744 * commands and is set for all scsi write commands
746 if( adapter->has_64bit_addr ) {
747 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
748 MEGA_MBOXCMD_LWRITE64:
749 MEGA_MBOXCMD_LREAD64 ;
752 mbox->m_out.cmd = (*cmd->cmnd & 0x02) ?
758 * 6-byte READ(0x08) or WRITE(0x0A) cdb
760 if( cmd->cmd_len == 6 ) {
761 mbox->m_out.numsectors = (u32) cmd->cmnd[4];
763 ((u32)cmd->cmnd[1] << 16) |
764 ((u32)cmd->cmnd[2] << 8) |
767 mbox->m_out.lba &= 0x1FFFFF;
771 * Take modulo 0x80, since the logical drive
772 * number increases by 0x80 when a logical
775 if (*cmd->cmnd == READ_6) {
776 adapter->nreads[ldrv_num%0x80]++;
777 adapter->nreadblocks[ldrv_num%0x80] +=
778 mbox->m_out.numsectors;
780 adapter->nwrites[ldrv_num%0x80]++;
781 adapter->nwriteblocks[ldrv_num%0x80] +=
782 mbox->m_out.numsectors;
788 * 10-byte READ(0x28) or WRITE(0x2A) cdb
790 if( cmd->cmd_len == 10 ) {
791 mbox->m_out.numsectors =
793 ((u32)cmd->cmnd[7] << 8);
795 ((u32)cmd->cmnd[2] << 24) |
796 ((u32)cmd->cmnd[3] << 16) |
797 ((u32)cmd->cmnd[4] << 8) |
801 if (*cmd->cmnd == READ_10) {
802 adapter->nreads[ldrv_num%0x80]++;
803 adapter->nreadblocks[ldrv_num%0x80] +=
804 mbox->m_out.numsectors;
806 adapter->nwrites[ldrv_num%0x80]++;
807 adapter->nwriteblocks[ldrv_num%0x80] +=
808 mbox->m_out.numsectors;
814 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
816 if( cmd->cmd_len == 12 ) {
818 ((u32)cmd->cmnd[2] << 24) |
819 ((u32)cmd->cmnd[3] << 16) |
820 ((u32)cmd->cmnd[4] << 8) |
823 mbox->m_out.numsectors =
824 ((u32)cmd->cmnd[6] << 24) |
825 ((u32)cmd->cmnd[7] << 16) |
826 ((u32)cmd->cmnd[8] << 8) |
830 if (*cmd->cmnd == READ_12) {
831 adapter->nreads[ldrv_num%0x80]++;
832 adapter->nreadblocks[ldrv_num%0x80] +=
833 mbox->m_out.numsectors;
835 adapter->nwrites[ldrv_num%0x80]++;
836 adapter->nwriteblocks[ldrv_num%0x80] +=
837 mbox->m_out.numsectors;
843 * If it is a read command
845 if( (*cmd->cmnd & 0x0F) == 0x08 ) {
846 scb->dma_direction = PCI_DMA_FROMDEVICE;
849 scb->dma_direction = PCI_DMA_TODEVICE;
852 /* Calculate Scatter-Gather info */
853 mbox->m_out.numsgelements = mega_build_sglist(adapter, scb,
854 (u32 *)&mbox->m_out.xferaddr, &seg);
858 #if MEGA_HAVE_CLUSTERING
859 case RESERVE: /* Fall through */
863 * Do we support clustering and is the support enabled
865 if( ! adapter->has_cluster ) {
867 cmd->result = (DID_BAD_TARGET << 16);
872 /* Allocate a SCB and initialize mailbox */
873 if(!(scb = mega_allocate_scb(adapter, cmd))) {
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))) {
906 mbox = (mbox_t *)scb->raw_mbox;
907 memset(mbox, 0, sizeof(scb->raw_mbox));
909 if( adapter->support_ext_cdb ) {
911 epthru = mega_prepare_extpassthru(adapter, scb, cmd,
914 mbox->m_out.cmd = MEGA_MBOXCMD_EXTPTHRU;
916 mbox->m_out.xferaddr = scb->epthru_dma_addr;
921 pthru = mega_prepare_passthru(adapter, scb, cmd,
924 /* Initialize mailbox */
925 if( adapter->has_64bit_addr ) {
926 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU64;
929 mbox->m_out.cmd = MEGA_MBOXCMD_PASSTHRU;
932 mbox->m_out.xferaddr = scb->pthru_dma_addr;
942 * mega_prepare_passthru()
943 * @adapter - pointer to our soft state
944 * @scb - our scsi control block
945 * @cmd - scsi command from the mid-layer
946 * @channel - actual channel on the controller
947 * @target - actual id on the controller.
949 * prepare a command for the scsi physical devices.
951 static mega_passthru *
952 mega_prepare_passthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
953 int channel, int target)
955 mega_passthru *pthru;
958 memset(pthru, 0, sizeof (mega_passthru));
960 /* 0=6sec/1=60sec/2=10min/3=3hrs */
964 pthru->reqsenselen = 14;
965 pthru->islogical = 0;
967 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
969 pthru->target = (adapter->flag & BOARD_40LD) ?
970 (channel << 4) | target : target;
972 pthru->cdblen = cmd->cmd_len;
973 pthru->logdrv = cmd->device->lun;
975 memcpy(pthru->cdb, cmd->cmnd, cmd->cmd_len);
977 /* Not sure about the direction */
978 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
980 /* Special Code for Handling READ_CAPA/ INQ using bounce buffers */
981 switch (cmd->cmnd[0]) {
984 if(!(adapter->flag & (1L << cmd->device->channel))) {
986 dev_notice(&adapter->dev->dev,
987 "scsi%d: scanning scsi channel %d [P%d] "
988 "for physical devices\n",
989 adapter->host->host_no,
990 cmd->device->channel, channel);
992 adapter->flag |= (1L << cmd->device->channel);
996 pthru->numsgelements = mega_build_sglist(adapter, scb,
997 &pthru->dataxferaddr, &pthru->dataxferlen);
1005 * mega_prepare_extpassthru()
1006 * @adapter - pointer to our soft state
1007 * @scb - our scsi control block
1008 * @cmd - scsi command from the mid-layer
1009 * @channel - actual channel on the controller
1010 * @target - actual id on the controller.
1012 * prepare a command for the scsi physical devices. This rountine prepares
1013 * commands for devices which can take extended CDBs (>10 bytes)
1015 static mega_ext_passthru *
1016 mega_prepare_extpassthru(adapter_t *adapter, scb_t *scb, Scsi_Cmnd *cmd,
1017 int channel, int target)
1019 mega_ext_passthru *epthru;
1021 epthru = scb->epthru;
1022 memset(epthru, 0, sizeof(mega_ext_passthru));
1024 /* 0=6sec/1=60sec/2=10min/3=3hrs */
1025 epthru->timeout = 2;
1028 epthru->reqsenselen = 14;
1029 epthru->islogical = 0;
1031 epthru->channel = (adapter->flag & BOARD_40LD) ? 0 : channel;
1032 epthru->target = (adapter->flag & BOARD_40LD) ?
1033 (channel << 4) | target : target;
1035 epthru->cdblen = cmd->cmd_len;
1036 epthru->logdrv = cmd->device->lun;
1038 memcpy(epthru->cdb, cmd->cmnd, cmd->cmd_len);
1040 /* Not sure about the direction */
1041 scb->dma_direction = PCI_DMA_BIDIRECTIONAL;
1043 switch(cmd->cmnd[0]) {
1046 if(!(adapter->flag & (1L << cmd->device->channel))) {
1048 dev_notice(&adapter->dev->dev,
1049 "scsi%d: scanning scsi channel %d [P%d] "
1050 "for physical devices\n",
1051 adapter->host->host_no,
1052 cmd->device->channel, channel);
1054 adapter->flag |= (1L << cmd->device->channel);
1058 epthru->numsgelements = mega_build_sglist(adapter, scb,
1059 &epthru->dataxferaddr, &epthru->dataxferlen);
1067 __mega_runpendq(adapter_t *adapter)
1070 struct list_head *pos, *next;
1072 /* Issue any pending commands to the card */
1073 list_for_each_safe(pos, next, &adapter->pending_list) {
1075 scb = list_entry(pos, scb_t, list);
1077 if( !(scb->state & SCB_ISSUED) ) {
1079 if( issue_scb(adapter, scb) != 0 )
1090 * @adapter - pointer to our soft state
1091 * @scb - scsi control block
1093 * Post a command to the card if the mailbox is available, otherwise return
1094 * busy. We also take the scb from the pending list if the mailbox is
1098 issue_scb(adapter_t *adapter, scb_t *scb)
1100 volatile mbox64_t *mbox64 = adapter->mbox64;
1101 volatile mbox_t *mbox = adapter->mbox;
1104 if(unlikely(mbox->m_in.busy)) {
1108 } while( mbox->m_in.busy && (i < max_mbox_busy_wait) );
1110 if(mbox->m_in.busy) return -1;
1113 /* Copy mailbox data into host structure */
1114 memcpy((char *)&mbox->m_out, (char *)scb->raw_mbox,
1115 sizeof(struct mbox_out));
1117 mbox->m_out.cmdid = scb->idx; /* Set cmdid */
1118 mbox->m_in.busy = 1; /* Set busy */
1122 * Increment the pending queue counter
1124 atomic_inc(&adapter->pend_cmds);
1126 switch (mbox->m_out.cmd) {
1127 case MEGA_MBOXCMD_LREAD64:
1128 case MEGA_MBOXCMD_LWRITE64:
1129 case MEGA_MBOXCMD_PASSTHRU64:
1130 case MEGA_MBOXCMD_EXTPTHRU:
1131 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1132 mbox64->xfer_segment_hi = 0;
1133 mbox->m_out.xferaddr = 0xFFFFFFFF;
1136 mbox64->xfer_segment_lo = 0;
1137 mbox64->xfer_segment_hi = 0;
1143 scb->state |= SCB_ISSUED;
1145 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1146 mbox->m_in.poll = 0;
1148 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1151 irq_enable(adapter);
1152 issue_command(adapter);
1159 * Wait until the controller's mailbox is available
1162 mega_busywait_mbox (adapter_t *adapter)
1164 if (adapter->mbox->m_in.busy)
1165 return __mega_busywait_mbox(adapter);
1171 * @adapter - pointer to our soft state
1172 * @raw_mbox - the mailbox
1174 * Issue a scb in synchronous and non-interrupt mode
1177 issue_scb_block(adapter_t *adapter, u_char *raw_mbox)
1179 volatile mbox64_t *mbox64 = adapter->mbox64;
1180 volatile mbox_t *mbox = adapter->mbox;
1183 /* Wait until mailbox is free */
1184 if(mega_busywait_mbox (adapter))
1185 goto bug_blocked_mailbox;
1187 /* Copy mailbox data into host structure */
1188 memcpy((char *) mbox, raw_mbox, sizeof(struct mbox_out));
1189 mbox->m_out.cmdid = 0xFE;
1190 mbox->m_in.busy = 1;
1192 switch (raw_mbox[0]) {
1193 case MEGA_MBOXCMD_LREAD64:
1194 case MEGA_MBOXCMD_LWRITE64:
1195 case MEGA_MBOXCMD_PASSTHRU64:
1196 case MEGA_MBOXCMD_EXTPTHRU:
1197 mbox64->xfer_segment_lo = mbox->m_out.xferaddr;
1198 mbox64->xfer_segment_hi = 0;
1199 mbox->m_out.xferaddr = 0xFFFFFFFF;
1202 mbox64->xfer_segment_lo = 0;
1203 mbox64->xfer_segment_hi = 0;
1206 if( likely(adapter->flag & BOARD_MEMMAP) ) {
1207 mbox->m_in.poll = 0;
1209 mbox->m_in.numstatus = 0xFF;
1210 mbox->m_in.status = 0xFF;
1211 WRINDOOR(adapter, adapter->mbox_dma | 0x1);
1213 while((volatile u8)mbox->m_in.numstatus == 0xFF)
1216 mbox->m_in.numstatus = 0xFF;
1218 while( (volatile u8)mbox->m_in.poll != 0x77 )
1221 mbox->m_in.poll = 0;
1222 mbox->m_in.ack = 0x77;
1224 WRINDOOR(adapter, adapter->mbox_dma | 0x2);
1226 while(RDINDOOR(adapter) & 0x2)
1230 irq_disable(adapter);
1231 issue_command(adapter);
1233 while (!((byte = irq_state(adapter)) & INTR_VALID))
1236 set_irq_state(adapter, byte);
1237 irq_enable(adapter);
1241 return mbox->m_in.status;
1243 bug_blocked_mailbox:
1244 dev_warn(&adapter->dev->dev, "Blocked mailbox......!!\n");
1251 * megaraid_isr_iomapped()
1253 * @devp - pointer to our soft state
1255 * Interrupt service routine for io-mapped controllers.
1256 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1257 * and service the completed commands.
1260 megaraid_isr_iomapped(int irq, void *devp)
1262 adapter_t *adapter = devp;
1263 unsigned long flags;
1266 u8 completed[MAX_FIRMWARE_STATUS];
1272 * loop till F/W has more commands for us to complete.
1274 spin_lock_irqsave(&adapter->lock, flags);
1277 /* Check if a valid interrupt is pending */
1278 byte = irq_state(adapter);
1279 if( (byte & VALID_INTR_BYTE) == 0 ) {
1281 * No more pending commands
1285 set_irq_state(adapter, byte);
1287 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1290 adapter->mbox->m_in.numstatus = 0xFF;
1292 status = adapter->mbox->m_in.status;
1295 * decrement the pending queue counter
1297 atomic_sub(nstatus, &adapter->pend_cmds);
1299 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1302 /* Acknowledge interrupt */
1305 mega_cmd_done(adapter, completed, nstatus, status);
1307 mega_rundoneq(adapter);
1311 /* Loop through any pending requests */
1312 if(atomic_read(&adapter->quiescent) == 0) {
1313 mega_runpendq(adapter);
1320 spin_unlock_irqrestore(&adapter->lock, flags);
1322 return IRQ_RETVAL(handled);
1327 * megaraid_isr_memmapped()
1329 * @devp - pointer to our soft state
1331 * Interrupt service routine for memory-mapped controllers.
1332 * Find out if our device is interrupting. If yes, acknowledge the interrupt
1333 * and service the completed commands.
1336 megaraid_isr_memmapped(int irq, void *devp)
1338 adapter_t *adapter = devp;
1339 unsigned long flags;
1343 u8 completed[MAX_FIRMWARE_STATUS];
1348 * loop till F/W has more commands for us to complete.
1350 spin_lock_irqsave(&adapter->lock, flags);
1353 /* Check if a valid interrupt is pending */
1354 dword = RDOUTDOOR(adapter);
1355 if(dword != 0x10001234) {
1357 * No more pending commands
1361 WROUTDOOR(adapter, 0x10001234);
1363 while((nstatus = (volatile u8)adapter->mbox->m_in.numstatus)
1367 adapter->mbox->m_in.numstatus = 0xFF;
1369 status = adapter->mbox->m_in.status;
1372 * decrement the pending queue counter
1374 atomic_sub(nstatus, &adapter->pend_cmds);
1376 memcpy(completed, (void *)adapter->mbox->m_in.completed,
1379 /* Acknowledge interrupt */
1380 WRINDOOR(adapter, 0x2);
1384 while( RDINDOOR(adapter) & 0x02 )
1387 mega_cmd_done(adapter, completed, nstatus, status);
1389 mega_rundoneq(adapter);
1391 /* Loop through any pending requests */
1392 if(atomic_read(&adapter->quiescent) == 0) {
1393 mega_runpendq(adapter);
1400 spin_unlock_irqrestore(&adapter->lock, flags);
1402 return IRQ_RETVAL(handled);
1406 * @adapter - pointer to our soft state
1407 * @completed - array of ids of completed commands
1408 * @nstatus - number of completed commands
1409 * @status - status of the last command completed
1411 * Complete the commands and call the scsi mid-layer callback hooks.
1414 mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
1416 mega_ext_passthru *epthru = NULL;
1417 struct scatterlist *sgl;
1418 Scsi_Cmnd *cmd = NULL;
1419 mega_passthru *pthru = NULL;
1420 mbox_t *mbox = NULL;
1428 * for all the commands completed, call the mid-layer callback routine
1431 for( i = 0; i < nstatus; i++ ) {
1433 cmdid = completed[i];
1436 * Only free SCBs for the commands coming down from the
1437 * mid-layer, not for which were issued internally
1439 * For internal command, restore the status returned by the
1440 * firmware so that user can interpret it.
1442 if (cmdid == CMDID_INT_CMDS) {
1443 scb = &adapter->int_scb;
1445 list_del_init(&scb->list);
1446 scb->state = SCB_FREE;
1448 adapter->int_status = status;
1449 complete(&adapter->int_waitq);
1451 scb = &adapter->scb_list[cmdid];
1454 * Make sure f/w has completed a valid command
1456 if( !(scb->state & SCB_ISSUED) || scb->cmd == NULL ) {
1457 dev_crit(&adapter->dev->dev, "invalid command "
1458 "Id %d, scb->state:%x, scsi cmd:%p\n",
1459 cmdid, scb->state, scb->cmd);
1465 * Was a abort issued for this command
1467 if( scb->state & SCB_ABORT ) {
1469 dev_warn(&adapter->dev->dev,
1470 "aborted cmd [%x] complete\n",
1473 scb->cmd->result = (DID_ABORT << 16);
1475 list_add_tail(SCSI_LIST(scb->cmd),
1476 &adapter->completed_list);
1478 mega_free_scb(adapter, scb);
1484 * Was a reset issued for this command
1486 if( scb->state & SCB_RESET ) {
1488 dev_warn(&adapter->dev->dev,
1489 "reset cmd [%x] complete\n",
1492 scb->cmd->result = (DID_RESET << 16);
1494 list_add_tail(SCSI_LIST(scb->cmd),
1495 &adapter->completed_list);
1497 mega_free_scb (adapter, scb);
1504 epthru = scb->epthru;
1505 mbox = (mbox_t *)scb->raw_mbox;
1510 int logdrv = mbox->m_out.logdrv;
1512 islogical = adapter->logdrv_chan[cmd->channel];
1514 * Maintain an error counter for the logical drive.
1515 * Some application like SNMP agent need such
1518 if( status && islogical && (cmd->cmnd[0] == READ_6 ||
1519 cmd->cmnd[0] == READ_10 ||
1520 cmd->cmnd[0] == READ_12)) {
1522 * Logical drive number increases by 0x80 when
1523 * a logical drive is deleted
1525 adapter->rd_errors[logdrv%0x80]++;
1528 if( status && islogical && (cmd->cmnd[0] == WRITE_6 ||
1529 cmd->cmnd[0] == WRITE_10 ||
1530 cmd->cmnd[0] == WRITE_12)) {
1532 * Logical drive number increases by 0x80 when
1533 * a logical drive is deleted
1535 adapter->wr_errors[logdrv%0x80]++;
1543 * Do not return the presence of hard disk on the channel so,
1544 * inquiry sent, and returned data==hard disk or removable
1545 * hard disk and not logical, request should return failure! -
1548 islogical = adapter->logdrv_chan[cmd->device->channel];
1549 if( cmd->cmnd[0] == INQUIRY && !islogical ) {
1551 sgl = scsi_sglist(cmd);
1552 if( sg_page(sgl) ) {
1553 c = *(unsigned char *) sg_virt(&sgl[0]);
1555 dev_warn(&adapter->dev->dev, "invalid sg\n");
1559 if(IS_RAID_CH(adapter, cmd->device->channel) &&
1560 ((c & 0x1F ) == TYPE_DISK)) {
1565 /* clear result; otherwise, success returns corrupt value */
1568 /* Convert MegaRAID status to Linux error code */
1570 case 0x00: /* SUCCESS , i.e. SCSI_STATUS_GOOD */
1571 cmd->result |= (DID_OK << 16);
1574 case 0x02: /* ERROR_ABORTED, i.e.
1575 SCSI_STATUS_CHECK_CONDITION */
1577 /* set sense_buffer and result fields */
1578 if( mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU ||
1579 mbox->m_out.cmd == MEGA_MBOXCMD_PASSTHRU64 ) {
1581 memcpy(cmd->sense_buffer, pthru->reqsensearea,
1584 cmd->result = (DRIVER_SENSE << 24) |
1586 (CHECK_CONDITION << 1);
1589 if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
1591 memcpy(cmd->sense_buffer,
1592 epthru->reqsensearea, 14);
1594 cmd->result = (DRIVER_SENSE << 24) |
1596 (CHECK_CONDITION << 1);
1598 cmd->sense_buffer[0] = 0x70;
1599 cmd->sense_buffer[2] = ABORTED_COMMAND;
1600 cmd->result |= (CHECK_CONDITION << 1);
1605 case 0x08: /* ERR_DEST_DRIVE_FAILED, i.e.
1607 cmd->result |= (DID_BUS_BUSY << 16) | status;
1611 #if MEGA_HAVE_CLUSTERING
1613 * If TEST_UNIT_READY fails, we know
1614 * MEGA_RESERVATION_STATUS failed
1616 if( cmd->cmnd[0] == TEST_UNIT_READY ) {
1617 cmd->result |= (DID_ERROR << 16) |
1618 (RESERVATION_CONFLICT << 1);
1622 * Error code returned is 1 if Reserve or Release
1623 * failed or the input parameter is invalid
1626 (cmd->cmnd[0] == RESERVE ||
1627 cmd->cmnd[0] == RELEASE) ) {
1629 cmd->result |= (DID_ERROR << 16) |
1630 (RESERVATION_CONFLICT << 1);
1634 cmd->result |= (DID_BAD_TARGET << 16)|status;
1637 mega_free_scb(adapter, scb);
1639 /* Add Scsi_Command to end of completed queue */
1640 list_add_tail(SCSI_LIST(cmd), &adapter->completed_list);
1648 * Run through the list of completed requests and finish it
1651 mega_rundoneq (adapter_t *adapter)
1654 struct list_head *pos;
1656 list_for_each(pos, &adapter->completed_list) {
1658 struct scsi_pointer* spos = (struct scsi_pointer *)pos;
1660 cmd = list_entry(spos, Scsi_Cmnd, SCp);
1661 cmd->scsi_done(cmd);
1664 INIT_LIST_HEAD(&adapter->completed_list);
1669 * Free a SCB structure
1670 * Note: We assume the scsi commands associated with this scb is not free yet.
1673 mega_free_scb(adapter_t *adapter, scb_t *scb)
1675 switch( scb->dma_type ) {
1677 case MEGA_DMA_TYPE_NONE:
1681 scsi_dma_unmap(scb->cmd);
1688 * Remove from the pending list
1690 list_del_init(&scb->list);
1692 /* Link the scb back into free list */
1693 scb->state = SCB_FREE;
1696 list_add(&scb->list, &adapter->free_list);
1701 __mega_busywait_mbox (adapter_t *adapter)
1703 volatile mbox_t *mbox = adapter->mbox;
1706 for (counter = 0; counter < 10000; counter++) {
1707 if (!mbox->m_in.busy)
1712 return -1; /* give up after 1 second */
1716 * Copies data to SGLIST
1717 * Note: For 64 bit cards, we need a minimum of one SG element for read/write
1720 mega_build_sglist(adapter_t *adapter, scb_t *scb, u32 *buf, u32 *len)
1722 struct scatterlist *sg;
1730 * Copy Scatter-Gather list info into controller structure.
1732 * The number of sg elements returned must not exceed our limit
1734 sgcnt = scsi_dma_map(cmd);
1736 scb->dma_type = MEGA_SGLIST;
1738 BUG_ON(sgcnt > adapter->sglen || sgcnt < 0);
1742 if (scsi_sg_count(cmd) == 1 && !adapter->has_64bit_addr) {
1743 sg = scsi_sglist(cmd);
1744 scb->dma_h_bulkdata = sg_dma_address(sg);
1745 *buf = (u32)scb->dma_h_bulkdata;
1746 *len = sg_dma_len(sg);
1750 scsi_for_each_sg(cmd, sg, sgcnt, idx) {
1751 if (adapter->has_64bit_addr) {
1752 scb->sgl64[idx].address = sg_dma_address(sg);
1753 *len += scb->sgl64[idx].length = sg_dma_len(sg);
1755 scb->sgl[idx].address = sg_dma_address(sg);
1756 *len += scb->sgl[idx].length = sg_dma_len(sg);
1760 /* Reset pointer and length fields */
1761 *buf = scb->sgl_dma_addr;
1763 /* Return count of SG requests */
1771 * takes all info in AdapterInquiry structure and puts it into ProductInfo and
1772 * Enquiry3 structures for later use
1775 mega_8_to_40ld(mraid_inquiry *inquiry, mega_inquiry3 *enquiry3,
1776 mega_product_info *product_info)
1780 product_info->max_commands = inquiry->adapter_info.max_commands;
1781 enquiry3->rebuild_rate = inquiry->adapter_info.rebuild_rate;
1782 product_info->nchannels = inquiry->adapter_info.nchannels;
1784 for (i = 0; i < 4; i++) {
1785 product_info->fw_version[i] =
1786 inquiry->adapter_info.fw_version[i];
1788 product_info->bios_version[i] =
1789 inquiry->adapter_info.bios_version[i];
1791 enquiry3->cache_flush_interval =
1792 inquiry->adapter_info.cache_flush_interval;
1794 product_info->dram_size = inquiry->adapter_info.dram_size;
1796 enquiry3->num_ldrv = inquiry->logdrv_info.num_ldrv;
1798 for (i = 0; i < MAX_LOGICAL_DRIVES_8LD; i++) {
1799 enquiry3->ldrv_size[i] = inquiry->logdrv_info.ldrv_size[i];
1800 enquiry3->ldrv_prop[i] = inquiry->logdrv_info.ldrv_prop[i];
1801 enquiry3->ldrv_state[i] = inquiry->logdrv_info.ldrv_state[i];
1804 for (i = 0; i < (MAX_PHYSICAL_DRIVES); i++)
1805 enquiry3->pdrv_state[i] = inquiry->pdrv_info.pdrv_state[i];
1809 mega_free_sgl(adapter_t *adapter)
1814 for(i = 0; i < adapter->max_cmds; i++) {
1816 scb = &adapter->scb_list[i];
1819 pci_free_consistent(adapter->dev,
1820 sizeof(mega_sgl64) * adapter->sglen,
1828 pci_free_consistent(adapter->dev, sizeof(mega_passthru),
1829 scb->pthru, scb->pthru_dma_addr);
1835 pci_free_consistent(adapter->dev,
1836 sizeof(mega_ext_passthru),
1837 scb->epthru, scb->epthru_dma_addr);
1847 * Get information about the card/driver
1850 megaraid_info(struct Scsi_Host *host)
1852 static char buffer[512];
1855 adapter = (adapter_t *)host->hostdata;
1858 "LSI Logic MegaRAID %s %d commands %d targs %d chans %d luns",
1859 adapter->fw_version, adapter->product_info.max_commands,
1860 adapter->host->max_id, adapter->host->max_channel,
1861 (u32)adapter->host->max_lun);
1866 * Abort a previous SCSI request. Only commands on the pending list can be
1867 * aborted. All the commands issued to the F/W must complete.
1870 megaraid_abort(Scsi_Cmnd *cmd)
1875 adapter = (adapter_t *)cmd->device->host->hostdata;
1877 rval = megaraid_abort_and_reset(adapter, cmd, SCB_ABORT);
1880 * This is required here to complete any completed requests
1881 * to be communicated over to the mid layer.
1883 mega_rundoneq(adapter);
1890 megaraid_reset(struct scsi_cmnd *cmd)
1896 adapter = (adapter_t *)cmd->device->host->hostdata;
1898 #if MEGA_HAVE_CLUSTERING
1899 mc.cmd = MEGA_CLUSTER_CMD;
1900 mc.opcode = MEGA_RESET_RESERVATIONS;
1902 if( mega_internal_command(adapter, &mc, NULL) != 0 ) {
1903 dev_warn(&adapter->dev->dev, "reservation reset failed\n");
1906 dev_info(&adapter->dev->dev, "reservation reset\n");
1910 spin_lock_irq(&adapter->lock);
1912 rval = megaraid_abort_and_reset(adapter, cmd, SCB_RESET);
1915 * This is required here to complete any completed requests
1916 * to be communicated over to the mid layer.
1918 mega_rundoneq(adapter);
1919 spin_unlock_irq(&adapter->lock);
1925 * megaraid_abort_and_reset()
1926 * @adapter - megaraid soft state
1927 * @cmd - scsi command to be aborted or reset
1928 * @aor - abort or reset flag
1930 * Try to locate the scsi command in the pending queue. If found and is not
1931 * issued to the controller, abort/reset it. Otherwise return failure
1934 megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1936 struct list_head *pos, *next;
1939 dev_warn(&adapter->dev->dev, "%s cmd=%x <c=%d t=%d l=%d>\n",
1940 (aor == SCB_ABORT)? "ABORTING":"RESET",
1941 cmd->cmnd[0], cmd->device->channel,
1942 cmd->device->id, (u32)cmd->device->lun);
1944 if(list_empty(&adapter->pending_list))
1947 list_for_each_safe(pos, next, &adapter->pending_list) {
1949 scb = list_entry(pos, scb_t, list);
1951 if (scb->cmd == cmd) { /* Found command */
1956 * Check if this command has firmware ownership. If
1957 * yes, we cannot reset this command. Whenever f/w
1958 * completes this command, we will return appropriate
1961 if( scb->state & SCB_ISSUED ) {
1963 dev_warn(&adapter->dev->dev,
1964 "%s[%x], fw owner\n",
1965 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1973 * Not yet issued! Remove from the pending
1976 dev_warn(&adapter->dev->dev,
1977 "%s-[%x], driver owner\n",
1978 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1981 mega_free_scb(adapter, scb);
1983 if( aor == SCB_ABORT ) {
1984 cmd->result = (DID_ABORT << 16);
1987 cmd->result = (DID_RESET << 16);
1990 list_add_tail(SCSI_LIST(cmd),
1991 &adapter->completed_list);
2002 make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
2004 *pdev = pci_alloc_dev(NULL);
2006 if( *pdev == NULL ) return -1;
2008 memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
2010 if( pci_set_dma_mask(*pdev, DMA_BIT_MASK(32)) != 0 ) {
2019 free_local_pdev(struct pci_dev *pdev)
2025 * mega_allocate_inquiry()
2026 * @dma_handle - handle returned for dma address
2027 * @pdev - handle to pci device
2029 * allocates memory for inquiry structure
2031 static inline void *
2032 mega_allocate_inquiry(dma_addr_t *dma_handle, struct pci_dev *pdev)
2034 return pci_alloc_consistent(pdev, sizeof(mega_inquiry3), dma_handle);
2039 mega_free_inquiry(void *inquiry, dma_addr_t dma_handle, struct pci_dev *pdev)
2041 pci_free_consistent(pdev, sizeof(mega_inquiry3), inquiry, dma_handle);
2045 #ifdef CONFIG_PROC_FS
2046 /* Following code handles /proc fs */
2049 * proc_show_config()
2050 * @m - Synthetic file construction data
2051 * @v - File iterator
2053 * Display configuration information about the controller.
2056 proc_show_config(struct seq_file *m, void *v)
2059 adapter_t *adapter = m->private;
2061 seq_puts(m, MEGARAID_VERSION);
2062 if(adapter->product_info.product_name[0])
2063 seq_printf(m, "%s\n", adapter->product_info.product_name);
2065 seq_puts(m, "Controller Type: ");
2067 if( adapter->flag & BOARD_MEMMAP )
2068 seq_puts(m, "438/466/467/471/493/518/520/531/532\n");
2070 seq_puts(m, "418/428/434\n");
2072 if(adapter->flag & BOARD_40LD)
2073 seq_puts(m, "Controller Supports 40 Logical Drives\n");
2075 if(adapter->flag & BOARD_64BIT)
2076 seq_puts(m, "Controller capable of 64-bit memory addressing\n");
2077 if( adapter->has_64bit_addr )
2078 seq_puts(m, "Controller using 64-bit memory addressing\n");
2080 seq_puts(m, "Controller is not using 64-bit memory addressing\n");
2082 seq_printf(m, "Base = %08lx, Irq = %d, ",
2083 adapter->base, adapter->host->irq);
2085 seq_printf(m, "Logical Drives = %d, Channels = %d\n",
2086 adapter->numldrv, adapter->product_info.nchannels);
2088 seq_printf(m, "Version =%s:%s, DRAM = %dMb\n",
2089 adapter->fw_version, adapter->bios_version,
2090 adapter->product_info.dram_size);
2092 seq_printf(m, "Controller Queue Depth = %d, Driver Queue Depth = %d\n",
2093 adapter->product_info.max_commands, adapter->max_cmds);
2095 seq_printf(m, "support_ext_cdb = %d\n", adapter->support_ext_cdb);
2096 seq_printf(m, "support_random_del = %d\n", adapter->support_random_del);
2097 seq_printf(m, "boot_ldrv_enabled = %d\n", adapter->boot_ldrv_enabled);
2098 seq_printf(m, "boot_ldrv = %d\n", adapter->boot_ldrv);
2099 seq_printf(m, "boot_pdrv_enabled = %d\n", adapter->boot_pdrv_enabled);
2100 seq_printf(m, "boot_pdrv_ch = %d\n", adapter->boot_pdrv_ch);
2101 seq_printf(m, "boot_pdrv_tgt = %d\n", adapter->boot_pdrv_tgt);
2102 seq_printf(m, "quiescent = %d\n",
2103 atomic_read(&adapter->quiescent));
2104 seq_printf(m, "has_cluster = %d\n", adapter->has_cluster);
2106 seq_puts(m, "\nModule Parameters:\n");
2107 seq_printf(m, "max_cmd_per_lun = %d\n", max_cmd_per_lun);
2108 seq_printf(m, "max_sectors_per_io = %d\n", max_sectors_per_io);
2114 * @m - Synthetic file construction data
2115 * @v - File iterator
2117 * Display statistical information about the I/O activity.
2120 proc_show_stat(struct seq_file *m, void *v)
2122 adapter_t *adapter = m->private;
2127 seq_puts(m, "Statistical Information for this controller\n");
2128 seq_printf(m, "pend_cmds = %d\n", atomic_read(&adapter->pend_cmds));
2130 for(i = 0; i < adapter->numldrv; i++) {
2131 seq_printf(m, "Logical Drive %d:\n", i);
2132 seq_printf(m, "\tReads Issued = %lu, Writes Issued = %lu\n",
2133 adapter->nreads[i], adapter->nwrites[i]);
2134 seq_printf(m, "\tSectors Read = %lu, Sectors Written = %lu\n",
2135 adapter->nreadblocks[i], adapter->nwriteblocks[i]);
2136 seq_printf(m, "\tRead errors = %lu, Write errors = %lu\n\n",
2137 adapter->rd_errors[i], adapter->wr_errors[i]);
2140 seq_puts(m, "IO and error counters not compiled in driver.\n");
2148 * @m - Synthetic file construction data
2149 * @v - File iterator
2151 * Display mailbox information for the last command issued. This information
2152 * is good for debugging.
2155 proc_show_mbox(struct seq_file *m, void *v)
2157 adapter_t *adapter = m->private;
2158 volatile mbox_t *mbox = adapter->mbox;
2160 seq_puts(m, "Contents of Mail Box Structure\n");
2161 seq_printf(m, " Fw Command = 0x%02x\n", mbox->m_out.cmd);
2162 seq_printf(m, " Cmd Sequence = 0x%02x\n", mbox->m_out.cmdid);
2163 seq_printf(m, " No of Sectors= %04d\n", mbox->m_out.numsectors);
2164 seq_printf(m, " LBA = 0x%02x\n", mbox->m_out.lba);
2165 seq_printf(m, " DTA = 0x%08x\n", mbox->m_out.xferaddr);
2166 seq_printf(m, " Logical Drive= 0x%02x\n", mbox->m_out.logdrv);
2167 seq_printf(m, " No of SG Elmt= 0x%02x\n", mbox->m_out.numsgelements);
2168 seq_printf(m, " Busy = %01x\n", mbox->m_in.busy);
2169 seq_printf(m, " Status = 0x%02x\n", mbox->m_in.status);
2175 * proc_show_rebuild_rate()
2176 * @m - Synthetic file construction data
2177 * @v - File iterator
2179 * Display current rebuild rate
2182 proc_show_rebuild_rate(struct seq_file *m, void *v)
2184 adapter_t *adapter = m->private;
2185 dma_addr_t dma_handle;
2187 struct pci_dev *pdev;
2189 if( make_local_pdev(adapter, &pdev) != 0 )
2192 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL )
2195 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2196 seq_puts(m, "Adapter inquiry failed.\n");
2197 dev_warn(&adapter->dev->dev, "inquiry failed\n");
2201 if( adapter->flag & BOARD_40LD )
2202 seq_printf(m, "Rebuild Rate: [%d%%]\n",
2203 ((mega_inquiry3 *)inquiry)->rebuild_rate);
2205 seq_printf(m, "Rebuild Rate: [%d%%]\n",
2206 ((mraid_ext_inquiry *)
2207 inquiry)->raid_inq.adapter_info.rebuild_rate);
2210 mega_free_inquiry(inquiry, dma_handle, pdev);
2212 free_local_pdev(pdev);
2218 * proc_show_battery()
2219 * @m - Synthetic file construction data
2220 * @v - File iterator
2222 * Display information about the battery module on the controller.
2225 proc_show_battery(struct seq_file *m, void *v)
2227 adapter_t *adapter = m->private;
2228 dma_addr_t dma_handle;
2230 struct pci_dev *pdev;
2233 if( make_local_pdev(adapter, &pdev) != 0 )
2236 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL )
2239 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2240 seq_puts(m, "Adapter inquiry failed.\n");
2241 dev_warn(&adapter->dev->dev, "inquiry failed\n");
2245 if( adapter->flag & BOARD_40LD ) {
2246 battery_status = ((mega_inquiry3 *)inquiry)->battery_status;
2249 battery_status = ((mraid_ext_inquiry *)inquiry)->
2250 raid_inq.adapter_info.battery_status;
2254 * Decode the battery status
2256 seq_printf(m, "Battery Status:[%d]", battery_status);
2258 if(battery_status == MEGA_BATT_CHARGE_DONE)
2259 seq_puts(m, " Charge Done");
2261 if(battery_status & MEGA_BATT_MODULE_MISSING)
2262 seq_puts(m, " Module Missing");
2264 if(battery_status & MEGA_BATT_LOW_VOLTAGE)
2265 seq_puts(m, " Low Voltage");
2267 if(battery_status & MEGA_BATT_TEMP_HIGH)
2268 seq_puts(m, " Temperature High");
2270 if(battery_status & MEGA_BATT_PACK_MISSING)
2271 seq_puts(m, " Pack Missing");
2273 if(battery_status & MEGA_BATT_CHARGE_INPROG)
2274 seq_puts(m, " Charge In-progress");
2276 if(battery_status & MEGA_BATT_CHARGE_FAIL)
2277 seq_puts(m, " Charge Fail");
2279 if(battery_status & MEGA_BATT_CYCLES_EXCEEDED)
2280 seq_puts(m, " Cycles Exceeded");
2285 mega_free_inquiry(inquiry, dma_handle, pdev);
2287 free_local_pdev(pdev);
2293 * Display scsi inquiry
2296 mega_print_inquiry(struct seq_file *m, char *scsi_inq)
2300 seq_puts(m, " Vendor: ");
2301 seq_write(m, scsi_inq + 8, 8);
2302 seq_puts(m, " Model: ");
2303 seq_write(m, scsi_inq + 16, 16);
2304 seq_puts(m, " Rev: ");
2305 seq_write(m, scsi_inq + 32, 4);
2308 i = scsi_inq[0] & 0x1f;
2309 seq_printf(m, " Type: %s ", scsi_device_type(i));
2311 seq_printf(m, " ANSI SCSI revision: %02x",
2312 scsi_inq[2] & 0x07);
2314 if( (scsi_inq[2] & 0x07) == 1 && (scsi_inq[3] & 0x0f) == 1 )
2315 seq_puts(m, " CCS\n");
2322 * @m - Synthetic file construction data
2323 * @page - buffer to write the data in
2324 * @adapter - pointer to our soft state
2326 * Display information about the physical drives.
2329 proc_show_pdrv(struct seq_file *m, adapter_t *adapter, int channel)
2331 dma_addr_t dma_handle;
2333 dma_addr_t scsi_inq_dma_handle;
2335 struct pci_dev *pdev;
2342 if( make_local_pdev(adapter, &pdev) != 0 )
2345 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL )
2348 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2349 seq_puts(m, "Adapter inquiry failed.\n");
2350 dev_warn(&adapter->dev->dev, "inquiry failed\n");
2355 scsi_inq = pci_alloc_consistent(pdev, 256, &scsi_inq_dma_handle);
2356 if( scsi_inq == NULL ) {
2357 seq_puts(m, "memory not available for scsi inq.\n");
2361 if( adapter->flag & BOARD_40LD ) {
2362 pdrv_state = ((mega_inquiry3 *)inquiry)->pdrv_state;
2365 pdrv_state = ((mraid_ext_inquiry *)inquiry)->
2366 raid_inq.pdrv_info.pdrv_state;
2369 max_channels = adapter->product_info.nchannels;
2371 if( channel >= max_channels ) {
2375 for( tgt = 0; tgt <= MAX_TARGET; tgt++ ) {
2377 i = channel*16 + tgt;
2379 state = *(pdrv_state + i);
2380 switch( state & 0x0F ) {
2382 seq_printf(m, "Channel:%2d Id:%2d State: Online",
2387 seq_printf(m, "Channel:%2d Id:%2d State: Failed",
2392 seq_printf(m, "Channel:%2d Id:%2d State: Rebuild",
2397 seq_printf(m, "Channel:%2d Id:%2d State: Hot spare",
2402 seq_printf(m, "Channel:%2d Id:%2d State: Un-configured",
2408 * This interface displays inquiries for disk drives
2409 * only. Inquries for logical drives and non-disk
2410 * devices are available through /proc/scsi/scsi
2412 memset(scsi_inq, 0, 256);
2413 if( mega_internal_dev_inquiry(adapter, channel, tgt,
2414 scsi_inq_dma_handle) ||
2415 (scsi_inq[0] & 0x1F) != TYPE_DISK ) {
2420 * Check for overflow. We print less than 240
2421 * characters for inquiry
2424 mega_print_inquiry(m, scsi_inq);
2428 pci_free_consistent(pdev, 256, scsi_inq, scsi_inq_dma_handle);
2430 mega_free_inquiry(inquiry, dma_handle, pdev);
2432 free_local_pdev(pdev);
2437 * proc_show_pdrv_ch0()
2438 * @m - Synthetic file construction data
2439 * @v - File iterator
2441 * Display information about the physical drives on physical channel 0.
2444 proc_show_pdrv_ch0(struct seq_file *m, void *v)
2446 return proc_show_pdrv(m, m->private, 0);
2451 * proc_show_pdrv_ch1()
2452 * @m - Synthetic file construction data
2453 * @v - File iterator
2455 * Display information about the physical drives on physical channel 1.
2458 proc_show_pdrv_ch1(struct seq_file *m, void *v)
2460 return proc_show_pdrv(m, m->private, 1);
2465 * proc_show_pdrv_ch2()
2466 * @m - Synthetic file construction data
2467 * @v - File iterator
2469 * Display information about the physical drives on physical channel 2.
2472 proc_show_pdrv_ch2(struct seq_file *m, void *v)
2474 return proc_show_pdrv(m, m->private, 2);
2479 * proc_show_pdrv_ch3()
2480 * @m - Synthetic file construction data
2481 * @v - File iterator
2483 * Display information about the physical drives on physical channel 3.
2486 proc_show_pdrv_ch3(struct seq_file *m, void *v)
2488 return proc_show_pdrv(m, m->private, 3);
2494 * @m - Synthetic file construction data
2495 * @adapter - pointer to our soft state
2496 * @start - starting logical drive to display
2497 * @end - ending logical drive to display
2499 * We do not print the inquiry information since its already available through
2500 * /proc/scsi/scsi interface
2503 proc_show_rdrv(struct seq_file *m, adapter_t *adapter, int start, int end )
2505 dma_addr_t dma_handle;
2506 logdrv_param *lparam;
2509 dma_addr_t disk_array_dma_handle;
2511 struct pci_dev *pdev;
2517 if( make_local_pdev(adapter, &pdev) != 0 )
2520 if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL )
2523 if( mega_adapinq(adapter, dma_handle) != 0 ) {
2524 seq_puts(m, "Adapter inquiry failed.\n");
2525 dev_warn(&adapter->dev->dev, "inquiry failed\n");
2529 memset(&mc, 0, sizeof(megacmd_t));
2531 if( adapter->flag & BOARD_40LD ) {
2532 array_sz = sizeof(disk_array_40ld);
2534 rdrv_state = ((mega_inquiry3 *)inquiry)->ldrv_state;
2536 num_ldrv = ((mega_inquiry3 *)inquiry)->num_ldrv;
2539 array_sz = sizeof(disk_array_8ld);
2541 rdrv_state = ((mraid_ext_inquiry *)inquiry)->
2542 raid_inq.logdrv_info.ldrv_state;
2544 num_ldrv = ((mraid_ext_inquiry *)inquiry)->
2545 raid_inq.logdrv_info.num_ldrv;
2548 disk_array = pci_alloc_consistent(pdev, array_sz,
2549 &disk_array_dma_handle);
2551 if( disk_array == NULL ) {
2552 seq_puts(m, "memory not available.\n");
2556 mc.xferaddr = (u32)disk_array_dma_handle;
2558 if( adapter->flag & BOARD_40LD ) {
2559 mc.cmd = FC_NEW_CONFIG;
2560 mc.opcode = OP_DCMD_READ_CONFIG;
2562 if( mega_internal_command(adapter, &mc, NULL) ) {
2563 seq_puts(m, "40LD read config failed.\n");
2569 mc.cmd = NEW_READ_CONFIG_8LD;
2571 if( mega_internal_command(adapter, &mc, NULL) ) {
2572 mc.cmd = READ_CONFIG_8LD;
2573 if( mega_internal_command(adapter, &mc, NULL) ) {
2574 seq_puts(m, "8LD read config failed.\n");
2580 for( i = start; i < ( (end+1 < num_ldrv) ? end+1 : num_ldrv ); i++ ) {
2582 if( adapter->flag & BOARD_40LD ) {
2584 &((disk_array_40ld *)disk_array)->ldrv[i].lparam;
2588 &((disk_array_8ld *)disk_array)->ldrv[i].lparam;
2592 * Check for overflow. We print less than 240 characters for
2593 * information about each logical drive.
2595 seq_printf(m, "Logical drive:%2d:, ", i);
2597 switch( rdrv_state[i] & 0x0F ) {
2599 seq_puts(m, "state: offline");
2602 seq_puts(m, "state: degraded");
2605 seq_puts(m, "state: optimal");
2608 seq_puts(m, "state: deleted");
2611 seq_puts(m, "state: unknown");
2616 * Check if check consistency or initialization is going on
2617 * for this logical drive.
2619 if( (rdrv_state[i] & 0xF0) == 0x20 )
2620 seq_puts(m, ", check-consistency in progress");
2621 else if( (rdrv_state[i] & 0xF0) == 0x10 )
2622 seq_puts(m, ", initialization in progress");
2626 seq_printf(m, "Span depth:%3d, ", lparam->span_depth);
2627 seq_printf(m, "RAID level:%3d, ", lparam->level);
2628 seq_printf(m, "Stripe size:%3d, ",
2629 lparam->stripe_sz ? lparam->stripe_sz/2: 128);
2630 seq_printf(m, "Row size:%3d\n", lparam->row_size);
2632 seq_puts(m, "Read Policy: ");
2633 switch(lparam->read_ahead) {
2635 seq_puts(m, "No read ahead, ");
2638 seq_puts(m, "Read ahead, ");
2640 case ADAP_READ_AHEAD:
2641 seq_puts(m, "Adaptive, ");
2646 seq_puts(m, "Write Policy: ");
2647 switch(lparam->write_mode) {
2648 case WRMODE_WRITE_THRU:
2649 seq_puts(m, "Write thru, ");
2651 case WRMODE_WRITE_BACK:
2652 seq_puts(m, "Write back, ");
2656 seq_puts(m, "Cache Policy: ");
2657 switch(lparam->direct_io) {
2659 seq_puts(m, "Cached IO\n\n");
2662 seq_puts(m, "Direct IO\n\n");
2668 pci_free_consistent(pdev, array_sz, disk_array,
2669 disk_array_dma_handle);
2671 mega_free_inquiry(inquiry, dma_handle, pdev);
2673 free_local_pdev(pdev);
2678 * proc_show_rdrv_10()
2679 * @m - Synthetic file construction data
2680 * @v - File iterator
2682 * Display real time information about the logical drives 0 through 9.
2685 proc_show_rdrv_10(struct seq_file *m, void *v)
2687 return proc_show_rdrv(m, m->private, 0, 9);
2692 * proc_show_rdrv_20()
2693 * @m - Synthetic file construction data
2694 * @v - File iterator
2696 * Display real time information about the logical drives 0 through 9.
2699 proc_show_rdrv_20(struct seq_file *m, void *v)
2701 return proc_show_rdrv(m, m->private, 10, 19);
2706 * proc_show_rdrv_30()
2707 * @m - Synthetic file construction data
2708 * @v - File iterator
2710 * Display real time information about the logical drives 0 through 9.
2713 proc_show_rdrv_30(struct seq_file *m, void *v)
2715 return proc_show_rdrv(m, m->private, 20, 29);
2720 * proc_show_rdrv_40()
2721 * @m - Synthetic file construction data
2722 * @v - File iterator
2724 * Display real time information about the logical drives 0 through 9.
2727 proc_show_rdrv_40(struct seq_file *m, void *v)
2729 return proc_show_rdrv(m, m->private, 30, 39);
2734 * seq_file wrappers for procfile show routines.
2736 static int mega_proc_open(struct inode *inode, struct file *file)
2738 adapter_t *adapter = proc_get_parent_data(inode);
2739 int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
2741 return single_open(file, show, adapter);
2744 static const struct file_operations mega_proc_fops = {
2745 .open = mega_proc_open,
2747 .llseek = seq_lseek,
2748 .release = single_release,
2752 * Table of proc files we need to create.
2754 struct mega_proc_file {
2756 unsigned short ptr_offset;
2757 int (*show) (struct seq_file *m, void *v);
2760 static const struct mega_proc_file mega_proc_files[] = {
2761 { "config", offsetof(adapter_t, proc_read), proc_show_config },
2762 { "stat", offsetof(adapter_t, proc_stat), proc_show_stat },
2763 { "mailbox", offsetof(adapter_t, proc_mbox), proc_show_mbox },
2764 #if MEGA_HAVE_ENH_PROC
2765 { "rebuild-rate", offsetof(adapter_t, proc_rr), proc_show_rebuild_rate },
2766 { "battery-status", offsetof(adapter_t, proc_battery), proc_show_battery },
2767 { "diskdrives-ch0", offsetof(adapter_t, proc_pdrvstat[0]), proc_show_pdrv_ch0 },
2768 { "diskdrives-ch1", offsetof(adapter_t, proc_pdrvstat[1]), proc_show_pdrv_ch1 },
2769 { "diskdrives-ch2", offsetof(adapter_t, proc_pdrvstat[2]), proc_show_pdrv_ch2 },
2770 { "diskdrives-ch3", offsetof(adapter_t, proc_pdrvstat[3]), proc_show_pdrv_ch3 },
2771 { "raiddrives-0-9", offsetof(adapter_t, proc_rdrvstat[0]), proc_show_rdrv_10 },
2772 { "raiddrives-10-19", offsetof(adapter_t, proc_rdrvstat[1]), proc_show_rdrv_20 },
2773 { "raiddrives-20-29", offsetof(adapter_t, proc_rdrvstat[2]), proc_show_rdrv_30 },
2774 { "raiddrives-30-39", offsetof(adapter_t, proc_rdrvstat[3]), proc_show_rdrv_40 },
2780 * mega_create_proc_entry()
2781 * @index - index in soft state array
2782 * @parent - parent node for this /proc entry
2784 * Creates /proc entries for our controllers.
2787 mega_create_proc_entry(int index, struct proc_dir_entry *parent)
2789 const struct mega_proc_file *f;
2790 adapter_t *adapter = hba_soft_state[index];
2791 struct proc_dir_entry *dir, *de, **ppde;
2794 sprintf(string, "hba%d", adapter->host->host_no);
2796 dir = adapter->controller_proc_dir_entry =
2797 proc_mkdir_data(string, 0, parent, adapter);
2799 dev_warn(&adapter->dev->dev, "proc_mkdir failed\n");
2803 for (f = mega_proc_files; f->name; f++) {
2804 de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops,
2807 dev_warn(&adapter->dev->dev, "proc_create failed\n");
2811 ppde = (void *)adapter + f->ptr_offset;
2817 static inline void mega_create_proc_entry(int index, struct proc_dir_entry *parent)
2824 * megaraid_biosparam()
2826 * Return the disk geometry for a particular disk
2829 megaraid_biosparam(struct scsi_device *sdev, struct block_device *bdev,
2830 sector_t capacity, int geom[])
2839 /* Get pointer to host config structure */
2840 adapter = (adapter_t *)sdev->host->hostdata;
2842 if (IS_RAID_CH(adapter, sdev->channel)) {
2843 /* Default heads (64) & sectors (32) */
2846 cylinders = (ulong)capacity / (heads * sectors);
2849 * Handle extended translation size for logical drives
2852 if ((ulong)capacity >= 0x200000) {
2855 cylinders = (ulong)capacity / (heads * sectors);
2861 geom[2] = cylinders;
2864 bh = scsi_bios_ptable(bdev);
2867 rval = scsi_partsize(bh, capacity,
2868 &geom[2], &geom[0], &geom[1]);
2874 dev_info(&adapter->dev->dev,
2875 "invalid partition on this disk on channel %d\n",
2878 /* Default heads (64) & sectors (32) */
2881 cylinders = (ulong)capacity / (heads * sectors);
2883 /* Handle extended translation size for logical drives > 1Gb */
2884 if ((ulong)capacity >= 0x200000) {
2887 cylinders = (ulong)capacity / (heads * sectors);
2893 geom[2] = cylinders;
2901 * @adapter - pointer to our soft state
2903 * Allocate memory for the various pointers in the scb structures:
2904 * scatter-gather list pointer, passthru and extended passthru structure
2908 mega_init_scb(adapter_t *adapter)
2913 for( i = 0; i < adapter->max_cmds; i++ ) {
2915 scb = &adapter->scb_list[i];
2923 for( i = 0; i < adapter->max_cmds; i++ ) {
2925 scb = &adapter->scb_list[i];
2929 scb->sgl64 = pci_alloc_consistent(adapter->dev,
2930 sizeof(mega_sgl64) * adapter->sglen,
2931 &scb->sgl_dma_addr);
2933 scb->sgl = (mega_sglist *)scb->sgl64;
2936 dev_warn(&adapter->dev->dev, "RAID: Can't allocate sglist\n");
2937 mega_free_sgl(adapter);
2941 scb->pthru = pci_alloc_consistent(adapter->dev,
2942 sizeof(mega_passthru),
2943 &scb->pthru_dma_addr);
2946 dev_warn(&adapter->dev->dev, "RAID: Can't allocate passthru\n");
2947 mega_free_sgl(adapter);
2951 scb->epthru = pci_alloc_consistent(adapter->dev,
2952 sizeof(mega_ext_passthru),
2953 &scb->epthru_dma_addr);
2955 if( !scb->epthru ) {
2956 dev_warn(&adapter->dev->dev,
2957 "Can't allocate extended passthru\n");
2958 mega_free_sgl(adapter);
2963 scb->dma_type = MEGA_DMA_TYPE_NONE;
2967 * lock not required since we are loading the driver, so no
2968 * commands possible right now.
2970 scb->state = SCB_FREE;
2972 list_add(&scb->list, &adapter->free_list);
2984 * Routines for the character/ioctl interface to the driver. Find out if this
2988 megadev_open (struct inode *inode, struct file *filep)
2991 * Only allow superuser to access private ioctl interface
2993 if( !capable(CAP_SYS_ADMIN) ) return -EACCES;
3001 * @inode - Our device inode
3003 * @cmd - ioctl command
3004 * @arg - user buffer
3006 * ioctl entry point for our private ioctl interface. We move the data in from
3007 * the user space, prepare the command (if necessary, convert the old MIMD
3008 * ioctl to new ioctl command), and issue a synchronous command to the
3012 megadev_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
3018 mega_passthru __user *upthru; /* user address for passthru */
3019 mega_passthru *pthru; /* copy user passthru here */
3020 dma_addr_t pthru_dma_hndl;
3021 void *data = NULL; /* data to be transferred */
3022 dma_addr_t data_dma_hndl; /* dma handle for data xfer area */
3024 megastat_t __user *ustats;
3027 struct pci_dev *pdev;
3029 ustats = NULL; /* avoid compilation warnings */
3033 * Make sure only USCSICMD are issued through this interface.
3034 * MIMD application would still fire different command.
3036 if( (_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD) ) {
3041 * Check and convert a possible MIMD command to NIT command.
3042 * mega_m_to_n() copies the data from the user space, so we do not
3043 * have to do it here.
3044 * NOTE: We will need some user address to copyout the data, therefore
3045 * the inteface layer will also provide us with the required user
3048 memset(&uioc, 0, sizeof(nitioctl_t));
3049 if( (rval = mega_m_to_n( (void __user *)arg, &uioc)) != 0 )
3053 switch( uioc.opcode ) {
3055 case GET_DRIVER_VER:
3056 if( put_user(driver_ver, (u32 __user *)uioc.uioc_uaddr) )
3062 if( put_user(hba_count, (u32 __user *)uioc.uioc_uaddr) )
3066 * Shucks. MIMD interface returns a positive value for number
3067 * of adapters. TODO: Change it to return 0 when there is no
3068 * applicatio using mimd interface.
3077 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3080 if( copy_to_user(uioc.uioc_uaddr, mcontroller+adapno,
3081 sizeof(struct mcontroller)) )
3091 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3094 adapter = hba_soft_state[adapno];
3096 ustats = uioc.uioc_uaddr;
3098 if( copy_from_user(&num_ldrv, &ustats->num_ldrv, sizeof(int)) )
3102 * Check for the validity of the logical drive number
3104 if( num_ldrv >= MAX_LOGICAL_DRIVES_40LD ) return -EINVAL;
3106 if( copy_to_user(ustats->nreads, adapter->nreads,
3107 num_ldrv*sizeof(u32)) )
3110 if( copy_to_user(ustats->nreadblocks, adapter->nreadblocks,
3111 num_ldrv*sizeof(u32)) )
3114 if( copy_to_user(ustats->nwrites, adapter->nwrites,
3115 num_ldrv*sizeof(u32)) )
3118 if( copy_to_user(ustats->nwriteblocks, adapter->nwriteblocks,
3119 num_ldrv*sizeof(u32)) )
3122 if( copy_to_user(ustats->rd_errors, adapter->rd_errors,
3123 num_ldrv*sizeof(u32)) )
3126 if( copy_to_user(ustats->wr_errors, adapter->wr_errors,
3127 num_ldrv*sizeof(u32)) )
3138 if( (adapno = GETADAP(uioc.adapno)) >= hba_count )
3141 adapter = hba_soft_state[adapno];
3144 * Deletion of logical drive is a special case. The adapter
3145 * should be quiescent before this command is issued.
3147 if( uioc.uioc_rmbox[0] == FC_DEL_LOGDRV &&
3148 uioc.uioc_rmbox[2] == OP_DEL_LOGDRV ) {
3151 * Do we support this feature
3153 if( !adapter->support_random_del ) {
3154 dev_warn(&adapter->dev->dev, "logdrv "
3155 "delete on non-supporting F/W\n");
3160 rval = mega_del_logdrv( adapter, uioc.uioc_rmbox[3] );
3163 memset(&mc, 0, sizeof(megacmd_t));
3167 rval = mega_n_to_m((void __user *)arg, &mc);
3173 * This interface only support the regular passthru commands.
3174 * Reject extended passthru and 64-bit passthru
3176 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU64 ||
3177 uioc.uioc_rmbox[0] == MEGA_MBOXCMD_EXTPTHRU ) {
3179 dev_warn(&adapter->dev->dev, "rejected passthru\n");
3185 * For all internal commands, the buffer must be allocated in
3186 * <4GB address range
3188 if( make_local_pdev(adapter, &pdev) != 0 )
3191 /* Is it a passthru command or a DCMD */
3192 if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
3193 /* Passthru commands */
3195 pthru = pci_alloc_consistent(pdev,
3196 sizeof(mega_passthru),
3199 if( pthru == NULL ) {
3200 free_local_pdev(pdev);
3205 * The user passthru structure
3207 upthru = (mega_passthru __user *)(unsigned long)MBOX(uioc)->xferaddr;
3210 * Copy in the user passthru here.
3212 if( copy_from_user(pthru, upthru,
3213 sizeof(mega_passthru)) ) {
3215 pci_free_consistent(pdev,
3216 sizeof(mega_passthru), pthru,
3219 free_local_pdev(pdev);
3225 * Is there a data transfer
3227 if( pthru->dataxferlen ) {
3228 data = pci_alloc_consistent(pdev,
3232 if( data == NULL ) {
3233 pci_free_consistent(pdev,
3234 sizeof(mega_passthru),
3238 free_local_pdev(pdev);
3244 * Save the user address and point the kernel
3245 * address at just allocated memory
3247 uxferaddr = pthru->dataxferaddr;
3248 pthru->dataxferaddr = data_dma_hndl;
3253 * Is data coming down-stream
3255 if( pthru->dataxferlen && (uioc.flags & UIOC_WR) ) {
3259 if( copy_from_user(data, (char __user *)(unsigned long) uxferaddr,
3260 pthru->dataxferlen) ) {
3262 goto freemem_and_return;
3266 memset(&mc, 0, sizeof(megacmd_t));
3268 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
3269 mc.xferaddr = (u32)pthru_dma_hndl;
3274 mega_internal_command(adapter, &mc, pthru);
3276 rval = mega_n_to_m((void __user *)arg, &mc);
3278 if( rval ) goto freemem_and_return;
3282 * Is data going up-stream
3284 if( pthru->dataxferlen && (uioc.flags & UIOC_RD) ) {
3285 if( copy_to_user((char __user *)(unsigned long) uxferaddr, data,
3286 pthru->dataxferlen) ) {
3292 * Send the request sense data also, irrespective of
3293 * whether the user has asked for it or not.
3295 if (copy_to_user(upthru->reqsensearea,
3296 pthru->reqsensearea, 14))
3300 if( pthru->dataxferlen ) {
3301 pci_free_consistent(pdev,
3302 pthru->dataxferlen, data,
3306 pci_free_consistent(pdev, sizeof(mega_passthru),
3307 pthru, pthru_dma_hndl);
3309 free_local_pdev(pdev);
3317 * Is there a data transfer
3319 if( uioc.xferlen ) {
3320 data = pci_alloc_consistent(pdev,
3321 uioc.xferlen, &data_dma_hndl);
3323 if( data == NULL ) {
3324 free_local_pdev(pdev);
3328 uxferaddr = MBOX(uioc)->xferaddr;
3332 * Is data coming down-stream
3334 if( uioc.xferlen && (uioc.flags & UIOC_WR) ) {
3338 if( copy_from_user(data, (char __user *)(unsigned long) uxferaddr,
3341 pci_free_consistent(pdev,
3343 data, data_dma_hndl);
3345 free_local_pdev(pdev);
3351 memcpy(&mc, MBOX(uioc), sizeof(megacmd_t));
3353 mc.xferaddr = (u32)data_dma_hndl;
3358 mega_internal_command(adapter, &mc, NULL);
3360 rval = mega_n_to_m((void __user *)arg, &mc);
3363 if( uioc.xferlen ) {
3364 pci_free_consistent(pdev,
3369 free_local_pdev(pdev);
3375 * Is data going up-stream
3377 if( uioc.xferlen && (uioc.flags & UIOC_RD) ) {
3378 if( copy_to_user((char __user *)(unsigned long) uxferaddr, data,
3385 if( uioc.xferlen ) {
3386 pci_free_consistent(pdev,
3391 free_local_pdev(pdev);
3404 megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
3408 mutex_lock(&megadev_mutex);
3409 ret = megadev_ioctl(filep, cmd, arg);
3410 mutex_unlock(&megadev_mutex);
3417 * @arg - user address
3418 * @uioc - new ioctl structure
3420 * A thin layer to convert older mimd interface ioctl structure to NIT ioctl
3423 * Converts the older mimd ioctl structure to newer NIT structure
3426 mega_m_to_n(void __user *arg, nitioctl_t *uioc)
3428 struct uioctl_t uioc_mimd;
3429 char signature[8] = {0};
3435 * check is the application conforms to NIT. We do not have to do much
3437 * We exploit the fact that the signature is stored in the very
3438 * beginning of the structure.
3441 if( copy_from_user(signature, arg, 7) )
3444 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3447 * NOTE NOTE: The nit ioctl is still under flux because of
3448 * change of mailbox definition, in HPE. No applications yet
3449 * use this interface and let's not have applications use this
3450 * interface till the new specifitions are in place.
3454 if( copy_from_user(uioc, arg, sizeof(nitioctl_t)) )
3461 * Else assume we have mimd uioctl_t as arg. Convert to nitioctl_t
3463 * Get the user ioctl structure
3465 if( copy_from_user(&uioc_mimd, arg, sizeof(struct uioctl_t)) )
3470 * Get the opcode and subopcode for the commands
3472 opcode = uioc_mimd.ui.fcs.opcode;
3473 subopcode = uioc_mimd.ui.fcs.subopcode;
3478 switch (subopcode) {
3480 case MEGAIOC_QDRVRVER: /* Query driver version */
3481 uioc->opcode = GET_DRIVER_VER;
3482 uioc->uioc_uaddr = uioc_mimd.data;
3485 case MEGAIOC_QNADAP: /* Get # of adapters */
3486 uioc->opcode = GET_N_ADAP;
3487 uioc->uioc_uaddr = uioc_mimd.data;
3490 case MEGAIOC_QADAPINFO: /* Get adapter information */
3491 uioc->opcode = GET_ADAP_INFO;
3492 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3493 uioc->uioc_uaddr = uioc_mimd.data;
3505 uioc->opcode = MBOX_CMD;
3506 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3508 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3510 uioc->xferlen = uioc_mimd.ui.fcs.length;
3512 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3513 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3519 uioc->opcode = MBOX_CMD;
3520 uioc->adapno = uioc_mimd.ui.fcs.adapno;
3522 memcpy(uioc->uioc_rmbox, uioc_mimd.mbox, 18);
3525 * Choose the xferlen bigger of input and output data
3527 uioc->xferlen = uioc_mimd.outlen > uioc_mimd.inlen ?
3528 uioc_mimd.outlen : uioc_mimd.inlen;
3530 if( uioc_mimd.outlen ) uioc->flags = UIOC_RD;
3531 if( uioc_mimd.inlen ) uioc->flags |= UIOC_WR;
3545 * @arg - user address
3546 * @mc - mailbox command
3548 * Updates the status information to the application, depending on application
3549 * conforms to older mimd ioctl interface or newer NIT ioctl interface
3552 mega_n_to_m(void __user *arg, megacmd_t *mc)
3554 nitioctl_t __user *uiocp;
3555 megacmd_t __user *umc;
3556 mega_passthru __user *upthru;
3557 struct uioctl_t __user *uioc_mimd;
3558 char signature[8] = {0};
3561 * check is the application conforms to NIT.
3563 if( copy_from_user(signature, arg, 7) )
3566 if( memcmp(signature, "MEGANIT", 7) == 0 ) {
3570 if( put_user(mc->status, (u8 __user *)&MBOX_P(uiocp)->status) )
3573 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3575 umc = MBOX_P(uiocp);
3577 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3580 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus))
3587 if( put_user(mc->status, (u8 __user *)&uioc_mimd->mbox[17]) )
3590 if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) {
3592 umc = (megacmd_t __user *)uioc_mimd->mbox;
3594 if (get_user(upthru, (mega_passthru __user * __user *)&umc->xferaddr))
3597 if( put_user(mc->status, (u8 __user *)&upthru->scsistatus) )
3607 * MEGARAID 'FW' commands.
3611 * mega_is_bios_enabled()
3612 * @adapter - pointer to our soft state
3614 * issue command to find out if the BIOS is enabled for this controller
3617 mega_is_bios_enabled(adapter_t *adapter)
3619 unsigned char raw_mbox[sizeof(struct mbox_out)];
3623 mbox = (mbox_t *)raw_mbox;
3625 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3627 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3629 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3631 raw_mbox[0] = IS_BIOS_ENABLED;
3632 raw_mbox[2] = GET_BIOS;
3635 ret = issue_scb_block(adapter, raw_mbox);
3637 return *(char *)adapter->mega_buffer;
3642 * mega_enum_raid_scsi()
3643 * @adapter - pointer to our soft state
3645 * Find out what channels are RAID/SCSI. This information is used to
3646 * differentiate the virtual channels and physical channels and to support
3647 * ROMB feature and non-disk devices.
3650 mega_enum_raid_scsi(adapter_t *adapter)
3652 unsigned char raw_mbox[sizeof(struct mbox_out)];
3656 mbox = (mbox_t *)raw_mbox;
3658 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3661 * issue command to find out what channels are raid/scsi
3663 raw_mbox[0] = CHNL_CLASS;
3664 raw_mbox[2] = GET_CHNL_CLASS;
3666 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3668 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3671 * Non-ROMB firmware fail this command, so all channels
3672 * must be shown RAID
3674 adapter->mega_ch_class = 0xFF;
3676 if(!issue_scb_block(adapter, raw_mbox)) {
3677 adapter->mega_ch_class = *((char *)adapter->mega_buffer);
3681 for( i = 0; i < adapter->product_info.nchannels; i++ ) {
3682 if( (adapter->mega_ch_class >> i) & 0x01 ) {
3683 dev_info(&adapter->dev->dev, "channel[%d] is raid\n",
3687 dev_info(&adapter->dev->dev, "channel[%d] is scsi\n",
3697 * mega_get_boot_drv()
3698 * @adapter - pointer to our soft state
3700 * Find out which device is the boot device. Note, any logical drive or any
3701 * phyical device (e.g., a CDROM) can be designated as a boot device.
3704 mega_get_boot_drv(adapter_t *adapter)
3706 struct private_bios_data *prv_bios_data;
3707 unsigned char raw_mbox[sizeof(struct mbox_out)];
3714 mbox = (mbox_t *)raw_mbox;
3716 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3718 raw_mbox[0] = BIOS_PVT_DATA;
3719 raw_mbox[2] = GET_BIOS_PVT_DATA;
3721 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3723 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3725 adapter->boot_ldrv_enabled = 0;
3726 adapter->boot_ldrv = 0;
3728 adapter->boot_pdrv_enabled = 0;
3729 adapter->boot_pdrv_ch = 0;
3730 adapter->boot_pdrv_tgt = 0;
3732 if(issue_scb_block(adapter, raw_mbox) == 0) {
3734 (struct private_bios_data *)adapter->mega_buffer;
3737 cksum_p = (char *)prv_bios_data;
3738 for (i = 0; i < 14; i++ ) {
3739 cksum += (u16)(*cksum_p++);
3742 if (prv_bios_data->cksum == (u16)(0-cksum) ) {
3745 * If MSB is set, a physical drive is set as boot
3748 if( prv_bios_data->boot_drv & 0x80 ) {
3749 adapter->boot_pdrv_enabled = 1;
3750 boot_pdrv = prv_bios_data->boot_drv & 0x7F;
3751 adapter->boot_pdrv_ch = boot_pdrv / 16;
3752 adapter->boot_pdrv_tgt = boot_pdrv % 16;
3755 adapter->boot_ldrv_enabled = 1;
3756 adapter->boot_ldrv = prv_bios_data->boot_drv;
3764 * mega_support_random_del()
3765 * @adapter - pointer to our soft state
3767 * Find out if this controller supports random deletion and addition of
3771 mega_support_random_del(adapter_t *adapter)
3773 unsigned char raw_mbox[sizeof(struct mbox_out)];
3777 mbox = (mbox_t *)raw_mbox;
3779 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3784 raw_mbox[0] = FC_DEL_LOGDRV;
3785 raw_mbox[2] = OP_SUP_DEL_LOGDRV;
3787 rval = issue_scb_block(adapter, raw_mbox);
3794 * mega_support_ext_cdb()
3795 * @adapter - pointer to our soft state
3797 * Find out if this firmware support cdblen > 10
3800 mega_support_ext_cdb(adapter_t *adapter)
3802 unsigned char raw_mbox[sizeof(struct mbox_out)];
3806 mbox = (mbox_t *)raw_mbox;
3808 memset(&mbox->m_out, 0, sizeof(raw_mbox));
3810 * issue command to find out if controller supports extended CDBs.
3815 rval = issue_scb_block(adapter, raw_mbox);
3823 * @adapter - pointer to our soft state
3824 * @logdrv - logical drive to be deleted
3826 * Delete the specified logical drive. It is the responsibility of the user
3827 * app to let the OS know about this operation.
3830 mega_del_logdrv(adapter_t *adapter, int logdrv)
3832 unsigned long flags;
3837 * Stop sending commands to the controller, queue them internally.
3838 * When deletion is complete, ISR will flush the queue.
3840 atomic_set(&adapter->quiescent, 1);
3843 * Wait till all the issued commands are complete and there are no
3844 * commands in the pending queue
3846 while (atomic_read(&adapter->pend_cmds) > 0 ||
3847 !list_empty(&adapter->pending_list))
3848 msleep(1000); /* sleep for 1s */
3850 rval = mega_do_del_logdrv(adapter, logdrv);
3852 spin_lock_irqsave(&adapter->lock, flags);
3855 * If delete operation was successful, add 0x80 to the logical drive
3856 * ids for commands in the pending queue.
3858 if (adapter->read_ldidmap) {
3859 struct list_head *pos;
3860 list_for_each(pos, &adapter->pending_list) {
3861 scb = list_entry(pos, scb_t, list);
3862 if (scb->pthru->logdrv < 0x80 )
3863 scb->pthru->logdrv += 0x80;
3867 atomic_set(&adapter->quiescent, 0);
3869 mega_runpendq(adapter);
3871 spin_unlock_irqrestore(&adapter->lock, flags);
3878 mega_do_del_logdrv(adapter_t *adapter, int logdrv)
3883 memset( &mc, 0, sizeof(megacmd_t));
3885 mc.cmd = FC_DEL_LOGDRV;
3886 mc.opcode = OP_DEL_LOGDRV;
3887 mc.subopcode = logdrv;
3889 rval = mega_internal_command(adapter, &mc, NULL);
3891 /* log this event */
3893 dev_warn(&adapter->dev->dev, "Delete LD-%d failed", logdrv);
3898 * After deleting first logical drive, the logical drives must be
3899 * addressed by adding 0x80 to the logical drive id.
3901 adapter->read_ldidmap = 1;
3908 * mega_get_max_sgl()
3909 * @adapter - pointer to our soft state
3911 * Find out the maximum number of scatter-gather elements supported by this
3912 * version of the firmware
3915 mega_get_max_sgl(adapter_t *adapter)
3917 unsigned char raw_mbox[sizeof(struct mbox_out)];
3920 mbox = (mbox_t *)raw_mbox;
3922 memset(mbox, 0, sizeof(raw_mbox));
3924 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3926 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3928 raw_mbox[0] = MAIN_MISC_OPCODE;
3929 raw_mbox[2] = GET_MAX_SG_SUPPORT;
3932 if( issue_scb_block(adapter, raw_mbox) ) {
3934 * f/w does not support this command. Choose the default value
3936 adapter->sglen = MIN_SGLIST;
3939 adapter->sglen = *((char *)adapter->mega_buffer);
3942 * Make sure this is not more than the resources we are
3943 * planning to allocate
3945 if ( adapter->sglen > MAX_SGLIST )
3946 adapter->sglen = MAX_SGLIST;
3954 * mega_support_cluster()
3955 * @adapter - pointer to our soft state
3957 * Find out if this firmware support cluster calls.
3960 mega_support_cluster(adapter_t *adapter)
3962 unsigned char raw_mbox[sizeof(struct mbox_out)];
3965 mbox = (mbox_t *)raw_mbox;
3967 memset(mbox, 0, sizeof(raw_mbox));
3969 memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
3971 mbox->m_out.xferaddr = (u32)adapter->buf_dma_handle;
3974 * Try to get the initiator id. This command will succeed iff the
3975 * clustering is available on this HBA.
3977 raw_mbox[0] = MEGA_GET_TARGET_ID;
3979 if( issue_scb_block(adapter, raw_mbox) == 0 ) {
3982 * Cluster support available. Get the initiator target id.
3983 * Tell our id to mid-layer too.
3985 adapter->this_id = *(u32 *)adapter->mega_buffer;
3986 adapter->host->this_id = adapter->this_id;
3994 #ifdef CONFIG_PROC_FS
3997 * @adapter - pointer to our soft state
3998 * @dma_handle - DMA address of the buffer
4000 * Issue internal commands while interrupts are available.
4001 * We only issue direct mailbox commands from within the driver. ioctl()
4002 * interface using these routines can issue passthru commands.
4005 mega_adapinq(adapter_t *adapter, dma_addr_t dma_handle)
4009 memset(&mc, 0, sizeof(megacmd_t));
4011 if( adapter->flag & BOARD_40LD ) {
4012 mc.cmd = FC_NEW_CONFIG;
4013 mc.opcode = NC_SUBOP_ENQUIRY3;
4014 mc.subopcode = ENQ3_GET_SOLICITED_FULL;
4017 mc.cmd = MEGA_MBOXCMD_ADPEXTINQ;
4020 mc.xferaddr = (u32)dma_handle;
4022 if ( mega_internal_command(adapter, &mc, NULL) != 0 ) {
4030 /** mega_internal_dev_inquiry()
4031 * @adapter - pointer to our soft state
4032 * @ch - channel for this device
4033 * @tgt - ID of this device
4034 * @buf_dma_handle - DMA address of the buffer
4036 * Issue the scsi inquiry for the specified device.
4039 mega_internal_dev_inquiry(adapter_t *adapter, u8 ch, u8 tgt,
4040 dma_addr_t buf_dma_handle)
4042 mega_passthru *pthru;
4043 dma_addr_t pthru_dma_handle;
4046 struct pci_dev *pdev;
4050 * For all internal commands, the buffer must be allocated in <4GB
4053 if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
4055 pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
4058 if( pthru == NULL ) {
4059 free_local_pdev(pdev);
4065 pthru->reqsenselen = 14;
4066 pthru->islogical = 0;
4068 pthru->channel = (adapter->flag & BOARD_40LD) ? 0 : ch;
4070 pthru->target = (adapter->flag & BOARD_40LD) ? (ch << 4)|tgt : tgt;
4074 pthru->cdb[0] = INQUIRY;
4078 pthru->cdb[4] = 255;
4082 pthru->dataxferaddr = (u32)buf_dma_handle;
4083 pthru->dataxferlen = 256;
4085 memset(&mc, 0, sizeof(megacmd_t));
4087 mc.cmd = MEGA_MBOXCMD_PASSTHRU;
4088 mc.xferaddr = (u32)pthru_dma_handle;
4090 rval = mega_internal_command(adapter, &mc, pthru);
4092 pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
4095 free_local_pdev(pdev);
4102 * mega_internal_command()
4103 * @adapter - pointer to our soft state
4104 * @mc - the mailbox command
4105 * @pthru - Passthru structure for DCDB commands
4107 * Issue the internal commands in interrupt mode.
4108 * The last argument is the address of the passthru structure if the command
4109 * to be fired is a passthru command
4111 * Note: parameter 'pthru' is null for non-passthru commands.
4114 mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru)
4116 unsigned long flags;
4121 * The internal commands share one command id and hence are
4122 * serialized. This is so because we want to reserve maximum number of
4123 * available command ids for the I/O commands.
4125 mutex_lock(&adapter->int_mtx);
4127 scb = &adapter->int_scb;
4128 memset(scb, 0, sizeof(scb_t));
4130 scb->idx = CMDID_INT_CMDS;
4131 scb->state |= SCB_ACTIVE | SCB_PENDQ;
4133 memcpy(scb->raw_mbox, mc, sizeof(megacmd_t));
4136 * Is it a passthru command
4138 if (mc->cmd == MEGA_MBOXCMD_PASSTHRU)
4141 spin_lock_irqsave(&adapter->lock, flags);
4142 list_add_tail(&scb->list, &adapter->pending_list);
4144 * Check if the HBA is in quiescent state, e.g., during a
4145 * delete logical drive opertion. If it is, don't run
4148 if (atomic_read(&adapter->quiescent) == 0)
4149 mega_runpendq(adapter);
4150 spin_unlock_irqrestore(&adapter->lock, flags);
4152 wait_for_completion(&adapter->int_waitq);
4154 mc->status = rval = adapter->int_status;
4157 * Print a debug message for all failed commands. Applications can use
4160 if (rval && trace_level) {
4161 dev_info(&adapter->dev->dev, "cmd [%x, %x, %x] status:[%x]\n",
4162 mc->cmd, mc->opcode, mc->subopcode, rval);
4165 mutex_unlock(&adapter->int_mtx);
4169 static struct scsi_host_template megaraid_template = {
4170 .module = THIS_MODULE,
4172 .proc_name = "megaraid_legacy",
4173 .info = megaraid_info,
4174 .queuecommand = megaraid_queue,
4175 .bios_param = megaraid_biosparam,
4176 .max_sectors = MAX_SECTORS_PER_IO,
4177 .can_queue = MAX_COMMANDS,
4178 .this_id = DEFAULT_INITIATOR_ID,
4179 .sg_tablesize = MAX_SGLIST,
4180 .cmd_per_lun = DEF_CMD_PER_LUN,
4181 .use_clustering = ENABLE_CLUSTERING,
4182 .eh_abort_handler = megaraid_abort,
4183 .eh_device_reset_handler = megaraid_reset,
4184 .eh_bus_reset_handler = megaraid_reset,
4185 .eh_host_reset_handler = megaraid_reset,
4190 megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4192 struct Scsi_Host *host;
4194 unsigned long mega_baseport, tbase, flag = 0;
4195 u16 subsysid, subsysvid;
4196 u8 pci_bus, pci_dev_func;
4198 int error = -ENODEV;
4200 if (pci_enable_device(pdev))
4202 pci_set_master(pdev);
4204 pci_bus = pdev->bus->number;
4205 pci_dev_func = pdev->devfn;
4208 * The megaraid3 stuff reports the ID of the Intel part which is not
4209 * remotely specific to the megaraid
4211 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
4214 * Don't fall over the Compaq management cards using the same
4217 if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ &&
4218 pdev->subsystem_device == 0xC000)
4220 /* Now check the magic signature byte */
4221 pci_read_config_word(pdev, PCI_CONF_AMISIG, &magic);
4222 if (magic != HBA_SIGNATURE_471 && magic != HBA_SIGNATURE)
4224 /* Ok it is probably a megaraid */
4228 * For these vendor and device ids, signature offsets are not
4229 * valid and 64 bit is implicit
4231 if (id->driver_data & BOARD_64BIT)
4232 flag |= BOARD_64BIT;
4236 pci_read_config_dword(pdev, PCI_CONF_AMISIG64, &magic64);
4237 if (magic64 == HBA_SIGNATURE_64BIT)
4238 flag |= BOARD_64BIT;
4241 subsysvid = pdev->subsystem_vendor;
4242 subsysid = pdev->subsystem_device;
4244 dev_notice(&pdev->dev, "found 0x%4.04x:0x%4.04x\n",
4245 id->vendor, id->device);
4247 /* Read the base port and IRQ from PCI */
4248 mega_baseport = pci_resource_start(pdev, 0);
4251 tbase = mega_baseport;
4252 if (pci_resource_flags(pdev, 0) & IORESOURCE_MEM) {
4253 flag |= BOARD_MEMMAP;
4255 if (!request_mem_region(mega_baseport, 128, "megaraid")) {
4256 dev_warn(&pdev->dev, "mem region busy!\n");
4257 goto out_disable_device;
4260 mega_baseport = (unsigned long)ioremap(mega_baseport, 128);
4261 if (!mega_baseport) {
4262 dev_warn(&pdev->dev, "could not map hba memory\n");
4263 goto out_release_region;
4266 flag |= BOARD_IOMAP;
4267 mega_baseport += 0x10;
4269 if (!request_region(mega_baseport, 16, "megaraid"))
4270 goto out_disable_device;
4273 /* Initialize SCSI Host structure */
4274 host = scsi_host_alloc(&megaraid_template, sizeof(adapter_t));
4278 adapter = (adapter_t *)host->hostdata;
4279 memset(adapter, 0, sizeof(adapter_t));
4281 dev_notice(&pdev->dev,
4282 "scsi%d:Found MegaRAID controller at 0x%lx, IRQ:%d\n",
4283 host->host_no, mega_baseport, irq);
4285 adapter->base = mega_baseport;
4286 if (flag & BOARD_MEMMAP)
4287 adapter->mmio_base = (void __iomem *) mega_baseport;
4289 INIT_LIST_HEAD(&adapter->free_list);
4290 INIT_LIST_HEAD(&adapter->pending_list);
4291 INIT_LIST_HEAD(&adapter->completed_list);
4293 adapter->flag = flag;
4294 spin_lock_init(&adapter->lock);
4296 host->cmd_per_lun = max_cmd_per_lun;
4297 host->max_sectors = max_sectors_per_io;
4299 adapter->dev = pdev;
4300 adapter->host = host;
4302 adapter->host->irq = irq;
4304 if (flag & BOARD_MEMMAP)
4305 adapter->host->base = tbase;
4307 adapter->host->io_port = tbase;
4308 adapter->host->n_io_port = 16;
4311 adapter->host->unique_id = (pci_bus << 8) | pci_dev_func;
4314 * Allocate buffer to issue internal commands.
4316 adapter->mega_buffer = pci_alloc_consistent(adapter->dev,
4317 MEGA_BUFFER_SIZE, &adapter->buf_dma_handle);
4318 if (!adapter->mega_buffer) {
4319 dev_warn(&pdev->dev, "out of RAM\n");
4323 adapter->scb_list = kmalloc(sizeof(scb_t) * MAX_COMMANDS, GFP_KERNEL);
4324 if (!adapter->scb_list) {
4325 dev_warn(&pdev->dev, "out of RAM\n");
4326 goto out_free_cmd_buffer;
4329 if (request_irq(irq, (adapter->flag & BOARD_MEMMAP) ?
4330 megaraid_isr_memmapped : megaraid_isr_iomapped,
4331 IRQF_SHARED, "megaraid", adapter)) {
4332 dev_warn(&pdev->dev, "Couldn't register IRQ %d!\n", irq);
4333 goto out_free_scb_list;
4336 if (mega_setup_mailbox(adapter))
4339 if (mega_query_adapter(adapter))
4343 * Have checks for some buggy f/w
4345 if ((subsysid == 0x1111) && (subsysvid == 0x1111)) {
4349 if (!strcmp(adapter->fw_version, "3.00") ||
4350 !strcmp(adapter->fw_version, "3.01")) {
4352 dev_warn(&pdev->dev,
4353 "Your card is a Dell PERC "
4354 "2/SC RAID controller with "
4355 "firmware\nmegaraid: 3.00 or 3.01. "
4356 "This driver is known to have "
4357 "corruption issues\nmegaraid: with "
4358 "those firmware versions on this "
4359 "specific card. In order\nmegaraid: "
4360 "to protect your data, please upgrade "
4361 "your firmware to version\nmegaraid: "
4362 "3.10 or later, available from the "
4363 "Dell Technical Support web\n"
4364 "megaraid: site at\nhttp://support."
4365 "dell.com/us/en/filelib/download/"
4366 "index.asp?fileid=2940\n"
4372 * If we have a HP 1M(0x60E7)/2M(0x60E8) controller with
4373 * firmware H.01.07, H.01.08, and H.01.09 disable 64 bit
4374 * support, since this firmware cannot handle 64 bit
4377 if ((subsysvid == PCI_VENDOR_ID_HP) &&
4378 ((subsysid == 0x60E7) || (subsysid == 0x60E8))) {
4382 if (!strcmp(adapter->fw_version, "H01.07") ||
4383 !strcmp(adapter->fw_version, "H01.08") ||
4384 !strcmp(adapter->fw_version, "H01.09") ) {
4385 dev_warn(&pdev->dev,
4386 "Firmware H.01.07, "
4387 "H.01.08, and H.01.09 on 1M/2M "
4389 "do not support 64 bit "
4390 "addressing.\nDISABLING "
4391 "64 bit support.\n");
4392 adapter->flag &= ~BOARD_64BIT;
4396 if (mega_is_bios_enabled(adapter))
4397 mega_hbas[hba_count].is_bios_enabled = 1;
4398 mega_hbas[hba_count].hostdata_addr = adapter;
4401 * Find out which channel is raid and which is scsi. This is
4404 mega_enum_raid_scsi(adapter);
4407 * Find out if a logical drive is set as the boot drive. If
4408 * there is one, will make that as the first logical drive.
4409 * ROMB: Do we have to boot from a physical drive. Then all
4410 * the physical drives would appear before the logical disks.
4411 * Else, all the physical drives would be exported to the mid
4412 * layer after logical drives.
4414 mega_get_boot_drv(adapter);
4416 if (adapter->boot_pdrv_enabled) {
4417 j = adapter->product_info.nchannels;
4418 for( i = 0; i < j; i++ )
4419 adapter->logdrv_chan[i] = 0;
4420 for( i = j; i < NVIRT_CHAN + j; i++ )
4421 adapter->logdrv_chan[i] = 1;
4423 for (i = 0; i < NVIRT_CHAN; i++)
4424 adapter->logdrv_chan[i] = 1;
4425 for (i = NVIRT_CHAN; i < MAX_CHANNELS+NVIRT_CHAN; i++)
4426 adapter->logdrv_chan[i] = 0;
4427 adapter->mega_ch_class <<= NVIRT_CHAN;
4431 * Do we support random deletion and addition of logical
4434 adapter->read_ldidmap = 0; /* set it after first logdrv
4436 adapter->support_random_del = mega_support_random_del(adapter);
4438 /* Initialize SCBs */
4439 if (mega_init_scb(adapter))
4443 * Reset the pending commands counter
4445 atomic_set(&adapter->pend_cmds, 0);
4448 * Reset the adapter quiescent flag
4450 atomic_set(&adapter->quiescent, 0);
4452 hba_soft_state[hba_count] = adapter;
4455 * Fill in the structure which needs to be passed back to the
4456 * application when it does an ioctl() for controller related
4461 mcontroller[i].base = mega_baseport;
4462 mcontroller[i].irq = irq;
4463 mcontroller[i].numldrv = adapter->numldrv;
4464 mcontroller[i].pcibus = pci_bus;
4465 mcontroller[i].pcidev = id->device;
4466 mcontroller[i].pcifun = PCI_FUNC (pci_dev_func);
4467 mcontroller[i].pciid = -1;
4468 mcontroller[i].pcivendor = id->vendor;
4469 mcontroller[i].pcislot = PCI_SLOT(pci_dev_func);
4470 mcontroller[i].uid = (pci_bus << 8) | pci_dev_func;
4473 /* Set the Mode of addressing to 64 bit if we can */
4474 if ((adapter->flag & BOARD_64BIT) && (sizeof(dma_addr_t) == 8)) {
4475 pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
4476 adapter->has_64bit_addr = 1;
4478 pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4479 adapter->has_64bit_addr = 0;
4482 mutex_init(&adapter->int_mtx);
4483 init_completion(&adapter->int_waitq);
4485 adapter->this_id = DEFAULT_INITIATOR_ID;
4486 adapter->host->this_id = DEFAULT_INITIATOR_ID;
4488 #if MEGA_HAVE_CLUSTERING
4490 * Is cluster support enabled on this controller
4491 * Note: In a cluster the HBAs ( the initiators ) will have
4492 * different target IDs and we cannot assume it to be 7. Call
4493 * to mega_support_cluster() will get the target ids also if
4494 * the cluster support is available
4496 adapter->has_cluster = mega_support_cluster(adapter);
4497 if (adapter->has_cluster) {
4498 dev_notice(&pdev->dev,
4499 "Cluster driver, initiator id:%d\n",
4504 pci_set_drvdata(pdev, host);
4506 mega_create_proc_entry(hba_count, mega_proc_dir_entry);
4508 error = scsi_add_host(host, &pdev->dev);
4512 scsi_scan_host(host);
4517 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
4518 adapter->una_mbox64, adapter->una_mbox64_dma);
4520 free_irq(adapter->host->irq, adapter);
4522 kfree(adapter->scb_list);
4523 out_free_cmd_buffer:
4524 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
4525 adapter->mega_buffer, adapter->buf_dma_handle);
4527 scsi_host_put(host);
4529 if (flag & BOARD_MEMMAP)
4530 iounmap((void *)mega_baseport);
4532 if (flag & BOARD_MEMMAP)
4533 release_mem_region(tbase, 128);
4535 release_region(mega_baseport, 16);
4537 pci_disable_device(pdev);
4543 __megaraid_shutdown(adapter_t *adapter)
4545 u_char raw_mbox[sizeof(struct mbox_out)];
4546 mbox_t *mbox = (mbox_t *)raw_mbox;
4549 /* Flush adapter cache */
4550 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4551 raw_mbox[0] = FLUSH_ADAPTER;
4553 free_irq(adapter->host->irq, adapter);
4555 /* Issue a blocking (interrupts disabled) command to the card */
4556 issue_scb_block(adapter, raw_mbox);
4558 /* Flush disks cache */
4559 memset(&mbox->m_out, 0, sizeof(raw_mbox));
4560 raw_mbox[0] = FLUSH_SYSTEM;
4562 /* Issue a blocking (interrupts disabled) command to the card */
4563 issue_scb_block(adapter, raw_mbox);
4565 if (atomic_read(&adapter->pend_cmds) > 0)
4566 dev_warn(&adapter->dev->dev, "pending commands!!\n");
4569 * Have a delibrate delay to make sure all the caches are
4572 for (i = 0; i <= 10; i++)
4577 megaraid_remove_one(struct pci_dev *pdev)
4579 struct Scsi_Host *host = pci_get_drvdata(pdev);
4580 adapter_t *adapter = (adapter_t *)host->hostdata;
4582 scsi_remove_host(host);
4584 __megaraid_shutdown(adapter);
4586 /* Free our resources */
4587 if (adapter->flag & BOARD_MEMMAP) {
4588 iounmap((void *)adapter->base);
4589 release_mem_region(adapter->host->base, 128);
4591 release_region(adapter->base, 16);
4593 mega_free_sgl(adapter);
4595 #ifdef CONFIG_PROC_FS
4596 if (adapter->controller_proc_dir_entry) {
4597 remove_proc_entry("stat", adapter->controller_proc_dir_entry);
4598 remove_proc_entry("config",
4599 adapter->controller_proc_dir_entry);
4600 remove_proc_entry("mailbox",
4601 adapter->controller_proc_dir_entry);
4602 #if MEGA_HAVE_ENH_PROC
4603 remove_proc_entry("rebuild-rate",
4604 adapter->controller_proc_dir_entry);
4605 remove_proc_entry("battery-status",
4606 adapter->controller_proc_dir_entry);
4608 remove_proc_entry("diskdrives-ch0",
4609 adapter->controller_proc_dir_entry);
4610 remove_proc_entry("diskdrives-ch1",
4611 adapter->controller_proc_dir_entry);
4612 remove_proc_entry("diskdrives-ch2",
4613 adapter->controller_proc_dir_entry);
4614 remove_proc_entry("diskdrives-ch3",
4615 adapter->controller_proc_dir_entry);
4617 remove_proc_entry("raiddrives-0-9",
4618 adapter->controller_proc_dir_entry);
4619 remove_proc_entry("raiddrives-10-19",
4620 adapter->controller_proc_dir_entry);
4621 remove_proc_entry("raiddrives-20-29",
4622 adapter->controller_proc_dir_entry);
4623 remove_proc_entry("raiddrives-30-39",
4624 adapter->controller_proc_dir_entry);
4627 char buf[12] = { 0 };
4628 sprintf(buf, "hba%d", adapter->host->host_no);
4629 remove_proc_entry(buf, mega_proc_dir_entry);
4634 pci_free_consistent(adapter->dev, MEGA_BUFFER_SIZE,
4635 adapter->mega_buffer, adapter->buf_dma_handle);
4636 kfree(adapter->scb_list);
4637 pci_free_consistent(adapter->dev, sizeof(mbox64_t),
4638 adapter->una_mbox64, adapter->una_mbox64_dma);
4640 scsi_host_put(host);
4641 pci_disable_device(pdev);
4647 megaraid_shutdown(struct pci_dev *pdev)
4649 struct Scsi_Host *host = pci_get_drvdata(pdev);
4650 adapter_t *adapter = (adapter_t *)host->hostdata;
4652 __megaraid_shutdown(adapter);
4655 static struct pci_device_id megaraid_pci_tbl[] = {
4656 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID,
4657 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4658 {PCI_VENDOR_ID_AMI, PCI_DEVICE_ID_AMI_MEGARAID2,
4659 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4660 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_AMI_MEGARAID3,
4661 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4664 MODULE_DEVICE_TABLE(pci, megaraid_pci_tbl);
4666 static struct pci_driver megaraid_pci_driver = {
4667 .name = "megaraid_legacy",
4668 .id_table = megaraid_pci_tbl,
4669 .probe = megaraid_probe_one,
4670 .remove = megaraid_remove_one,
4671 .shutdown = megaraid_shutdown,
4674 static int __init megaraid_init(void)
4678 if ((max_cmd_per_lun <= 0) || (max_cmd_per_lun > MAX_CMD_PER_LUN))
4679 max_cmd_per_lun = MAX_CMD_PER_LUN;
4680 if (max_mbox_busy_wait > MBOX_BUSY_WAIT)
4681 max_mbox_busy_wait = MBOX_BUSY_WAIT;
4683 #ifdef CONFIG_PROC_FS
4684 mega_proc_dir_entry = proc_mkdir("megaraid", NULL);
4685 if (!mega_proc_dir_entry) {
4687 "megaraid: failed to create megaraid root\n");
4690 error = pci_register_driver(&megaraid_pci_driver);
4692 #ifdef CONFIG_PROC_FS
4693 remove_proc_entry("megaraid", NULL);
4699 * Register the driver as a character device, for applications
4700 * to access it for ioctls.
4701 * First argument (major) to register_chrdev implies a dynamic
4702 * major number allocation.
4704 major = register_chrdev(0, "megadev_legacy", &megadev_fops);
4707 "megaraid: failed to register char device\n");
4713 static void __exit megaraid_exit(void)
4716 * Unregister the character device interface to the driver.
4718 unregister_chrdev(major, "megadev_legacy");
4720 pci_unregister_driver(&megaraid_pci_driver);
4722 #ifdef CONFIG_PROC_FS
4723 remove_proc_entry("megaraid", NULL);
4727 module_init(megaraid_init);
4728 module_exit(megaraid_exit);
4730 /* vi: set ts=8 sw=8 tw=78: */