4 #include <linux/version.h>
5 #include <linux/spinlock.h>
8 #define MEGARAID_VERSION \
9 "v2.10.10.1 (Release Date: Thu Jan 27 16:19:44 EDT 2005)\n"
12 * Driver features - change the values to enable or disable features in the
17 * Comand coalescing - This feature allows the driver to be able to combine
18 * two or more commands and issue as one command in order to boost I/O
19 * performance. Useful if the nature of the I/O is sequential. It is not very
20 * useful for random natured I/Os.
22 #define MEGA_HAVE_COALESCING 0
25 * Clustering support - Set this flag if you are planning to use the
26 * clustering services provided by the megaraid controllers and planning to
29 #define MEGA_HAVE_CLUSTERING 1
32 * Driver statistics - Set this flag if you are interested in statics about
33 * number of I/O completed on each logical drive and how many interrupts
34 * generated. If enabled, this information is available through /proc
35 * interface and through the private ioctl. Setting this flag has a
36 * performance penalty.
38 #define MEGA_HAVE_STATS 0
41 * Enhanced /proc interface - This feature will allow you to have a more
42 * detailed /proc interface for megaraid driver. E.g., a real time update of
43 * the status of the logical drives, battery status, physical drives etc.
45 #define MEGA_HAVE_ENH_PROC 1
47 #ifndef PCI_VENDOR_ID_AMI
48 #define PCI_VENDOR_ID_AMI 0x101E
51 #ifndef PCI_VENDOR_ID_DELL
52 #define PCI_VENDOR_ID_DELL 0x1028
55 #ifndef PCI_VENDOR_ID_INTEL
56 #define PCI_VENDOR_ID_INTEL 0x8086
59 #ifndef PCI_DEVICE_ID_AMI_MEGARAID
60 #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
63 #ifndef PCI_DEVICE_ID_AMI_MEGARAID2
64 #define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060
67 #ifndef PCI_DEVICE_ID_AMI_MEGARAID3
68 #define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960
71 #define PCI_DEVICE_ID_DISCOVERY 0x000E
72 #define PCI_DEVICE_ID_PERC4_DI 0x000F
73 #define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407
74 #define PCI_DEVICE_ID_PERC4E_SI_DI 0x0013
75 #define PCI_DEVICE_ID_PERC4E_DC_SC 0x0408
76 #define PCI_DEVICE_ID_LSI_SATA_PCIX 0x0409
78 /* Sub-System Vendor IDs */
79 #define AMI_SUBSYS_VID 0x101E
80 #define DELL_SUBSYS_VID 0x1028
81 #define HP_SUBSYS_VID 0x103C
82 #define LSI_SUBSYS_VID 0x1000
83 #define INTEL_SUBSYS_VID 0x8086
84 #define FSC_SUBSYS_VID 0x1734
85 #define ACER_SUBSYS_VID 0x1025
86 #define NEC_SUBSYS_VID 0x1033
88 #define HBA_SIGNATURE 0x3344
89 #define HBA_SIGNATURE_471 0xCCCC
90 #define HBA_SIGNATURE_64BIT 0x0299
92 #define MBOX_BUSY_WAIT 10 /* wait for up to 10 usec for
94 #define DEFAULT_INITIATOR_ID 7
96 #define MAX_SGLIST 64 /* max supported in f/w */
97 #define MIN_SGLIST 26 /* guaranteed to support these many */
98 #define MAX_COMMANDS 126
99 #define CMDID_INT_CMDS MAX_COMMANDS+1 /* make sure CMDID_INT_CMDS
100 is less than max commands
101 supported by any f/w */
103 #define MAX_CDB_LEN 10
104 #define MAX_EXT_CDB_LEN 16 /* we support cdb length up to 16 */
106 #define DEF_CMD_PER_LUN 63
107 #define MAX_CMD_PER_LUN MAX_COMMANDS
108 #define MAX_FIRMWARE_STATUS 46
109 #define MAX_XFER_PER_CMD (64*1024)
110 #define MAX_SECTORS_PER_IO 128
112 #define MAX_LOGICAL_DRIVES_40LD 40
113 #define FC_MAX_PHYSICAL_DEVICES 256
114 #define MAX_LOGICAL_DRIVES_8LD 8
115 #define MAX_CHANNELS 5
116 #define MAX_TARGET 15
117 #define MAX_PHYSICAL_DRIVES MAX_CHANNELS*MAX_TARGET
118 #define MAX_ROW_SIZE_40LD 32
119 #define MAX_ROW_SIZE_8LD 8
120 #define MAX_SPAN_DEPTH 8
122 #define NVIRT_CHAN 4 /* # of virtual channels to represent
123 up to 60 logical drives */
127 .name = "MegaRAID", \
128 .proc_name = "megaraid", \
129 .detect = megaraid_detect, \
130 .release = megaraid_release, \
131 .info = megaraid_info, \
132 .command = megaraid_command, \
133 .queuecommand = megaraid_queue, \
134 .max_sectors = MAX_SECTORS_PER_IO, \
135 .can_queue = MAX_COMMANDS, \
136 .this_id = DEFAULT_INITIATOR_ID, \
137 .sg_tablesize = MAX_SGLIST, \
138 .cmd_per_lun = DEF_CMD_PER_LUN, \
140 .unchecked_isa_dma = 0, \
141 .use_clustering = ENABLE_CLUSTERING, \
142 .use_new_eh_code = 1, \
143 .eh_abort_handler = megaraid_abort, \
144 .eh_device_reset_handler = megaraid_reset, \
145 .eh_bus_reset_handler = megaraid_reset, \
146 .eh_host_reset_handler = megaraid_reset, \
155 /* 0x2 */ u16 numsectors;
157 /* 0x8 */ u32 xferaddr;
159 /* 0xD */ u8 numsgelements;
161 /* 0xF */ volatile u8 busy;
162 /* 0x10 */ volatile u8 numstatus;
163 /* 0x11 */ volatile u8 status;
164 /* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
167 } __attribute__ ((packed)) mbox_t;
173 } __attribute__ ((packed)) mbox64_t;
177 * Passthru definitions
179 #define MAX_REQ_SENSE_LEN 0x20
182 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
186 u8 logdrv; /* if islogical == 1 */
187 u8 channel; /* if islogical == 0 */
188 u8 target; /* if islogical == 0 */
189 u8 queuetag; /* unused */
190 u8 queueaction; /* unused */
194 u8 reqsensearea[MAX_REQ_SENSE_LEN];
199 } __attribute__ ((packed)) mega_passthru;
203 * Extended passthru: support CDB > 10 bytes
206 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
212 u8 logdrv; /* if islogical == 1 */
213 u8 channel; /* if islogical == 0 */
214 u8 target; /* if islogical == 0 */
215 u8 queuetag; /* unused */
216 u8 queueaction; /* unused */
219 u8 cdb[MAX_EXT_CDB_LEN];
223 u8 reqsensearea[MAX_REQ_SENSE_LEN];
227 } __attribute__ ((packed)) mega_ext_passthru;
232 } __attribute__ ((packed)) mega_sgl64;
237 } __attribute__ ((packed)) mega_sglist;
240 /* Queued command data */
244 struct list_head list;
250 dma_addr_t dma_h_bulkdata;
251 dma_addr_t dma_h_sgdata;
255 dma_addr_t sgl_dma_addr;
257 mega_passthru *pthru;
258 dma_addr_t pthru_dma_addr;
259 mega_ext_passthru *epthru;
260 dma_addr_t epthru_dma_addr;
264 * Flags to follow the scb as it transitions between various stages
266 #define SCB_FREE 0x0000 /* on the free list */
267 #define SCB_ACTIVE 0x0001 /* off the free list */
268 #define SCB_PENDQ 0x0002 /* on the pending queue */
269 #define SCB_ISSUED 0x0004 /* issued - owner f/w */
270 #define SCB_ABORT 0x0008 /* Got an abort for this one */
271 #define SCB_RESET 0x0010 /* Got a reset for this one */
274 * Utilities declare this strcture size as 1024 bytes. So more fields can
275 * be added in future.
278 u32 data_size; /* current size in bytes (not including resvd) */
280 u32 config_signature;
281 /* Current value is 0x00282008
282 * 0x28=MAX_LOGICAL_DRIVES,
283 * 0x20=Number of stripes and
284 * 0x08=Number of spans */
286 u8 fw_version[16]; /* printable ASCI string */
287 u8 bios_version[16]; /* printable ASCI string */
288 u8 product_name[80]; /* printable ASCI string */
290 u8 max_commands; /* Max. concurrent commands supported */
291 u8 nchannels; /* Number of SCSI Channels detected */
292 u8 fc_loop_present; /* Number of Fibre Loops detected */
293 u8 mem_type; /* EDO, FPM, SDRAM etc */
296 u16 dram_size; /* In terms of MB */
301 u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */
302 } __attribute__ ((packed)) mega_product_info;
305 u32 global_counter; /* Any change increments this counter */
307 u8 param_counter; /* Indicates any params changed */
308 u8 param_id; /* Param modified - defined below */
309 u16 param_val; /* New val of last param modified */
311 u8 write_config_counter; /* write config occurred */
312 u8 write_config_rsvd[3];
314 u8 ldrv_op_counter; /* Indicates ldrv op started/completed */
315 u8 ldrv_opid; /* ldrv num */
316 u8 ldrv_opcmd; /* ldrv operation - defined below */
317 u8 ldrv_opstatus; /* status of the operation */
319 u8 ldrv_state_counter; /* Indicates change of ldrv state */
320 u8 ldrv_state_id; /* ldrv num */
321 u8 ldrv_state_new; /* New state */
322 u8 ldrv_state_old; /* old state */
324 u8 pdrv_state_counter; /* Indicates change of ldrv state */
325 u8 pdrv_state_id; /* pdrv id */
326 u8 pdrv_state_new; /* New state */
327 u8 pdrv_state_old; /* old state */
329 u8 pdrv_fmt_counter; /* Indicates pdrv format started/over */
330 u8 pdrv_fmt_id; /* pdrv id */
331 u8 pdrv_fmt_val; /* format started/over */
334 u8 targ_xfer_counter; /* Indicates SCSI-2 Xfer rate change */
335 u8 targ_xfer_id; /* pdrv Id */
336 u8 targ_xfer_val; /* new Xfer params of last pdrv */
339 u8 fcloop_id_chg_counter; /* Indicates loopid changed */
340 u8 fcloopid_pdrvid; /* pdrv id */
341 u8 fcloop_id0; /* loopid on fc loop 0 */
342 u8 fcloop_id1; /* loopid on fc loop 1 */
344 u8 fcloop_state_counter; /* Indicates loop state changed */
345 u8 fcloop_state0; /* state of fc loop 0 */
346 u8 fcloop_state1; /* state of fc loop 1 */
347 u8 fcloop_state_rsvd;
348 } __attribute__ ((packed));
350 #define MAX_NOTIFY_SIZE 0x80
351 #define CUR_NOTIFY_SIZE sizeof(struct notify)
354 u32 data_size; /* current size in bytes (not including resvd) */
356 struct notify notify;
358 u8 notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
360 u8 rebuild_rate; /* Rebuild rate (0% - 100%) */
361 u8 cache_flush_interval; /* In terms of Seconds */
363 u8 drive_insert_count; /* drive insertion count */
366 u8 num_ldrv; /* No. of Log Drives configured */
367 u8 recon_state[MAX_LOGICAL_DRIVES_40LD / 8]; /* State of
369 u16 ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
372 u32 ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
373 u8 ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
374 u8 ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
375 u8 pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
376 u16 pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
378 u8 targ_xfer[80]; /* phys device transfer rate */
379 u8 pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
380 } __attribute__ ((packed)) mega_inquiry3;
385 u8 max_commands; /* Max concurrent commands supported */
386 u8 rebuild_rate; /* Rebuild rate - 0% thru 100% */
387 u8 max_targ_per_chan; /* Max targ per channel */
388 u8 nchannels; /* Number of channels on HBA */
389 u8 fw_version[4]; /* Firmware version */
390 u16 age_of_flash; /* Number of times FW has been flashed */
391 u8 chip_set_value; /* Contents of 0xC0000832 */
392 u8 dram_size; /* In MB */
393 u8 cache_flush_interval; /* in seconds */
397 u8 write_config_count; /* Increase with every configuration
399 u8 drive_inserted_count; /* Increase with every drive inserted
401 u8 inserted_drive; /* Channel:Id of inserted drive */
402 u8 battery_status; /*
403 * BIT 0: battery module missing
405 * BIT 2: temprature high
406 * BIT 3: battery pack missing
408 * 00 - charge complete
409 * 01 - fast charge in progress
410 * 10 - fast charge fail
412 * Bit 6: counter > 1000
415 u8 dec_fault_bus_info;
416 } __attribute__ ((packed)) mega_adp_info;
420 u8 num_ldrv; /* Number of logical drives configured */
422 u32 ldrv_size[MAX_LOGICAL_DRIVES_8LD];
423 u8 ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
424 u8 ldrv_state[MAX_LOGICAL_DRIVES_8LD];
425 } __attribute__ ((packed)) mega_ldrv_info;
428 u8 pdrv_state[MAX_PHYSICAL_DRIVES];
430 } __attribute__ ((packed)) mega_pdrv_info;
432 /* RAID inquiry: Mailbox command 0x05*/
434 mega_adp_info adapter_info;
435 mega_ldrv_info logdrv_info;
436 mega_pdrv_info pdrv_info;
437 } __attribute__ ((packed)) mraid_inquiry;
440 /* RAID extended inquiry: Mailbox command 0x04*/
442 mraid_inquiry raid_inq;
443 u16 phys_drv_format[MAX_CHANNELS];
447 } __attribute__ ((packed)) mraid_ext_inquiry;
453 }__attribute__ ((packed)) adp_device;
456 u32 start_blk; /* starting block */
457 u32 num_blks; /* # of blocks */
458 adp_device device[MAX_ROW_SIZE_40LD];
459 }__attribute__ ((packed)) adp_span_40ld;
462 u32 start_blk; /* starting block */
463 u32 num_blks; /* # of blocks */
464 adp_device device[MAX_ROW_SIZE_8LD];
465 }__attribute__ ((packed)) adp_span_8ld;
468 u8 span_depth; /* Total # of spans */
469 u8 level; /* RAID level */
470 u8 read_ahead; /* read ahead, no read ahead, adaptive read
472 u8 stripe_sz; /* Encoded stripe size */
473 u8 status; /* Status of the logical drive */
474 u8 write_mode; /* write mode, write_through/write_back */
475 u8 direct_io; /* direct io or through cache */
476 u8 row_size; /* Number of stripes in a row */
477 } __attribute__ ((packed)) logdrv_param;
481 adp_span_40ld span[MAX_SPAN_DEPTH];
482 }__attribute__ ((packed)) logdrv_40ld;
486 adp_span_8ld span[MAX_SPAN_DEPTH];
487 }__attribute__ ((packed)) logdrv_8ld;
490 u8 type; /* Type of the device */
491 u8 cur_status; /* current status of the device */
492 u8 tag_depth; /* Level of tagging */
493 u8 sync_neg; /* sync negotiation - ENABLE or DISBALE */
494 u32 size; /* configurable size in terms of 512 byte
496 }__attribute__ ((packed)) phys_drv;
499 u8 nlog_drives; /* number of logical drives */
501 logdrv_40ld ldrv[MAX_LOGICAL_DRIVES_40LD];
502 phys_drv pdrv[MAX_PHYSICAL_DRIVES];
503 }__attribute__ ((packed)) disk_array_40ld;
506 u8 nlog_drives; /* number of logical drives */
508 logdrv_8ld ldrv[MAX_LOGICAL_DRIVES_8LD];
509 phys_drv pdrv[MAX_PHYSICAL_DRIVES];
510 }__attribute__ ((packed)) disk_array_8ld;
513 * FW Definitions & Data Structures for 8LD 4-Span and 8-Span Controllers
515 #define MAX_STRIPES 8
516 #define SPAN4_DEPTH 4
517 #define SPAN8_DEPTH 8
518 #define MAX_PHYDRVS 5 * 16 /* 5 Channels * 16 Targets */
521 unsigned char channel;
522 unsigned char target;
523 }__attribute__ ((packed)) device_t;
526 unsigned long start_blk;
527 unsigned long total_blks;
528 device_t device[ MAX_STRIPES ];
529 }__attribute__ ((packed)) span_t;
533 unsigned char curr_status;
534 unsigned char tag_depth;
535 unsigned char resvd1;
537 }__attribute__ ((packed)) phydrv_t;
540 unsigned char span_depth;
542 unsigned char read_ahead; /* 0=No rdahead,1=RDAHEAD,2=adaptive */
543 unsigned char stripe_sz;
544 unsigned char status;
545 unsigned char write_policy; /* 0=wrthru,1=wrbak */
546 unsigned char direct_io; /* 1=directio,0=cached */
547 unsigned char no_stripes;
548 span_t span[ SPAN4_DEPTH ];
549 }__attribute__ ((packed)) ld_span4_t;
552 unsigned char span_depth;
554 unsigned char read_ahead; /* 0=No rdahead,1=RDAHEAD,2=adaptive */
555 unsigned char stripe_sz;
556 unsigned char status;
557 unsigned char write_policy; /* 0=wrthru,1=wrbak */
558 unsigned char direct_io; /* 1=directio,0=cached */
559 unsigned char no_stripes;
560 span_t span[ SPAN8_DEPTH ];
561 }__attribute__ ((packed)) ld_span8_t;
564 unsigned char no_log_drives;
565 unsigned char pad[3];
566 ld_span4_t log_drv[ MAX_LOGICAL_DRIVES_8LD ];
567 phydrv_t phys_drv[ MAX_PHYDRVS ];
568 }__attribute__ ((packed)) diskarray_span4_t;
571 unsigned char no_log_drives;
572 unsigned char pad[3];
573 ld_span8_t log_drv[ MAX_LOGICAL_DRIVES_8LD ];
574 phydrv_t phys_drv[ MAX_PHYDRVS ];
575 }__attribute__ ((packed)) diskarray_span8_t;
578 * User ioctl structure.
579 * This structure will be used for Traditional Method ioctl interface
580 * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
582 * The Driver ioctl interface handles the commands at the driver level,
583 * without being sent to the card.
585 /* system call imposed limit. Change accordingly */
586 #define IOCTL_MAX_DATALEN 4096
597 #if BITS_PER_LONG == 32
601 #if BITS_PER_LONG == 64
605 } __attribute__ ((packed)) fcs;
606 } __attribute__ ((packed)) ui;
607 u8 mbox[18]; /* 16 bytes + 2 status bytes */
609 #if BITS_PER_LONG == 32
610 char *data; /* buffer <= 4096 for 0x80 commands */
613 #if BITS_PER_LONG == 64
616 } __attribute__ ((packed));
619 * struct mcontroller is used to pass information about the controllers in the
620 * system. Its upto the application how to use the information. We are passing
621 * as much info about the cards as possible and useful. Before issuing the
622 * call to find information about the cards, the applicaiton needs to issue a
623 * ioctl first to find out the number of controllers in the system.
625 #define MAX_CONTROLLERS 32
641 * mailbox structure used for internal commands
654 } __attribute__ ((packed)) megacmd_t;
657 * Defines for Driver IOCTL interface
659 #define MEGAIOC_MAGIC 'm'
661 /* Mega IOCTL command */
662 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, struct uioctl_t)
664 #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
665 #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
666 #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
667 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
668 #define GETADAP(mkadap) ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
671 * Definition for the new ioctl interface (NIT)
675 * Vendor specific Group-7 commands
677 #define VENDOR_SPECIFIC_COMMANDS 0xE0
678 #define MEGA_INTERNAL_CMD VENDOR_SPECIFIC_COMMANDS + 0x01
681 * The ioctl command. No other command shall be used for this interface
683 #define USCSICMD VENDOR_SPECIFIC_COMMANDS
686 * Data direction flags
688 #define UIOC_RD 0x00001
689 #define UIOC_WR 0x00002
694 #define MBOX_CMD 0x00000 /* DCMD or passthru command */
695 #define GET_DRIVER_VER 0x10000 /* Get driver version */
696 #define GET_N_ADAP 0x20000 /* Get number of adapters */
697 #define GET_ADAP_INFO 0x30000 /* Get information about a adapter */
698 #define GET_CAP 0x40000 /* Get ioctl capabilities */
699 #define GET_STATS 0x50000 /* Get statistics, including error info */
703 * The ioctl structure.
704 * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
705 * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
708 char signature[8]; /* Must contain "MEGANIT" */
709 u32 opcode; /* opcode for the command */
710 u32 adapno; /* adapter number */
711 mbox_t u_mbox; /* user mailbox */
712 caddr_t u_dataaddr; /* xferaddr for DCMD and non-mbox
716 #define RMBOX(uioc) ((u8 *)&(uioc).u_mbox)
717 #define MBOX(uioc) ((megacmd_t *)&(uioc).u_mbox)
718 #define MBOX_P(uioc) ((megacmd_t *)&(uioc)->u_mbox)
721 u32 xferlen; /* xferlen for DCMD and non-mbox
723 u32 flags; /* data direction flags */
728 * I/O statistics for some applications like SNMP agent. The caller must
729 * provide the number of logical drives for which status should be reported.
732 int num_ldrv; /* Number for logical drives for which the
733 status should be reported. */
734 u32 nreads[MAX_LOGICAL_DRIVES_40LD]; /* number of reads for
735 each logical drive */
736 u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
737 read for each logical
739 u32 nwrites[MAX_LOGICAL_DRIVES_40LD]; /* number of writes
742 u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
745 u32 rd_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of read
748 u32 wr_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of write
754 struct private_bios_data {
756 * bits 0-3 - BIOS geometry
760 * Others values are invalid
762 u8 unused:4; /* bits 4-7 are unused */
764 * logical drive set as boot drive
765 * 0..7 - for 8LD cards
766 * 0..39 - for 40LD cards
769 u16 cksum; /* 0-(sum of first 13 bytes of this structure) */
770 } __attribute__ ((packed));
776 * Mailbox and firmware commands and subopcodes used in this driver.
779 #define MEGA_MBOXCMD_LREAD 0x01
780 #define MEGA_MBOXCMD_LWRITE 0x02
781 #define MEGA_MBOXCMD_PASSTHRU 0x03
782 #define MEGA_MBOXCMD_ADPEXTINQ 0x04
783 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
784 #define MEGA_MBOXCMD_LREAD64 0xA7
785 #define MEGA_MBOXCMD_LWRITE64 0xA8
786 #define MEGA_MBOXCMD_PASSTHRU64 0xC3
787 #define MEGA_MBOXCMD_EXTPTHRU 0xE3
789 #define MAIN_MISC_OPCODE 0xA4 /* f/w misc opcode */
790 #define GET_MAX_SG_SUPPORT 0x01 /* get max sg len supported by f/w */
792 #define FC_NEW_CONFIG 0xA1
793 #define NC_SUBOP_PRODUCT_INFO 0x0E
794 #define NC_SUBOP_ENQUIRY3 0x0F
795 #define ENQ3_GET_SOLICITED_FULL 0x02
796 #define OP_DCMD_READ_CONFIG 0x04
797 #define NEW_READ_CONFIG_8LD 0x67
798 #define READ_CONFIG_8LD 0x07
799 #define FLUSH_ADAPTER 0x0A
800 #define FLUSH_SYSTEM 0xFE
803 * Command for random deletion of logical drives
805 #define FC_DEL_LOGDRV 0xA4 /* f/w command */
806 #define OP_SUP_DEL_LOGDRV 0x2A /* is feature supported */
807 #define OP_GET_LDID_MAP 0x18 /* get ldid and logdrv number map */
808 #define OP_DEL_LOGDRV 0x1C /* delete logical drive */
813 #define IS_BIOS_ENABLED 0x62
814 #define GET_BIOS 0x01
815 #define CHNL_CLASS 0xA9
816 #define GET_CHNL_CLASS 0x00
817 #define SET_CHNL_CLASS 0x01
820 #define BIOS_PVT_DATA 0x40
821 #define GET_BIOS_PVT_DATA 0x00
825 * Commands to support clustering
827 #define MEGA_GET_TARGET_ID 0x7D
828 #define MEGA_CLUSTER_OP 0x70
829 #define MEGA_GET_CLUSTER_MODE 0x02
830 #define MEGA_CLUSTER_CMD 0x6E
831 #define MEGA_RESERVE_LD 0x01
832 #define MEGA_RELEASE_LD 0x02
833 #define MEGA_RESET_RESERVATIONS 0x03
834 #define MEGA_RESERVATION_STATUS 0x04
835 #define MEGA_RESERVE_PD 0x05
836 #define MEGA_RELEASE_PD 0x06
840 * Module battery status
842 #define MEGA_BATT_MODULE_MISSING 0x01
843 #define MEGA_BATT_LOW_VOLTAGE 0x02
844 #define MEGA_BATT_TEMP_HIGH 0x04
845 #define MEGA_BATT_PACK_MISSING 0x08
846 #define MEGA_BATT_CHARGE_MASK 0x30
847 #define MEGA_BATT_CHARGE_DONE 0x00
848 #define MEGA_BATT_CHARGE_INPROG 0x10
849 #define MEGA_BATT_CHARGE_FAIL 0x20
850 #define MEGA_BATT_CYCLES_EXCEEDED 0x40
853 * Physical drive states.
856 #define PDRV_ONLINE 3
857 #define PDRV_FAILED 4
859 #define PDRV_HOTSPARE 6
863 * Raid logical drive states.
865 #define RDRV_OFFLINE 0
866 #define RDRV_DEGRADED 1
867 #define RDRV_OPTIMAL 2
868 #define RDRV_DELETED 3
871 * Read, write and cache policies
873 #define NO_READ_AHEAD 0
875 #define ADAP_READ_AHEAD 2
876 #define WRMODE_WRITE_THRU 0
877 #define WRMODE_WRITE_BACK 1
883 * Each controller's soft state
886 int this_id; /* our id, may set to different than 7 if
887 clustering is available */
892 /* mbox64 with mbox not aligned on 16-byte boundry */
893 mbox64_t *una_mbox64;
894 dma_addr_t una_mbox64_dma;
896 volatile mbox64_t *mbox64;/* ptr to 64-bit mailbox */
897 volatile mbox_t *mbox; /* ptr to standard mailbox */
901 struct list_head free_list;
902 struct list_head pending_list;
904 struct Scsi_Host *host;
906 #define MEGA_BUFFER_SIZE (2*1024)
908 dma_addr_t buf_dma_handle;
910 mega_product_info product_info;
915 atomic_t pend_cmds; /* maintain a counter for
916 pending commands in firmware */
919 u32 nreads[MAX_LOGICAL_DRIVES_40LD];
920 u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];
921 u32 nwrites[MAX_LOGICAL_DRIVES_40LD];
922 u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
923 u32 rd_errors[MAX_LOGICAL_DRIVES_40LD];
924 u32 wr_errors[MAX_LOGICAL_DRIVES_40LD];
927 /* Host adapter parameters */
932 #ifdef CONFIG_PROC_FS
933 struct proc_dir_entry *controller_proc_dir_entry;
934 struct proc_dir_entry *proc_read;
935 struct proc_dir_entry *proc_stat;
936 struct proc_dir_entry *proc_mbox;
938 #if MEGA_HAVE_ENH_PROC
939 struct proc_dir_entry *proc_rr;
940 struct proc_dir_entry *proc_battery;
941 #define MAX_PROC_CHANNELS 4
942 struct proc_dir_entry *proc_pdrvstat[MAX_PROC_CHANNELS];
943 struct proc_dir_entry *proc_rdrvstat[MAX_PROC_CHANNELS];
948 int has_64bit_addr; /* are we using 64-bit addressing */
950 int boot_ldrv_enabled;
952 int boot_pdrv_enabled; /* boot from physical drive */
953 int boot_pdrv_ch; /* boot physical drive channel */
954 int boot_pdrv_tgt; /* boot physical drive target */
957 int support_random_del; /* Do we support random deletion of
959 int read_ldidmap; /* set after logical drive deltion. The
960 logical drive number must be read from the
962 atomic_t quiescent; /* a stage reached when delete logical
963 drive needs to be done. Stop
964 sending requests to the hba till
965 delete operation is completed */
967 spinlock_t *host_lock; // pointer to appropriate lock
969 u8 logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
973 u8 sglen; /* f/w supported scatter-gather list length */
977 struct semaphore int_mtx; /* To synchronize the internal
979 wait_queue_head_t int_waitq; /* wait queue for internal
982 int has_cluster; /* cluster support on this HBA */
984 #define INT_MEMBLK_SZ (28*1024)
985 mega_passthru *int_pthru; /*internal pthru*/
986 dma_addr_t int_pthru_dma_hndl;
987 caddr_t int_data; /*internal data*/
988 dma_addr_t int_data_dma_hndl;
997 adapter_t *hostdata_addr;
1002 * For state flag. Do not use LSB(8 bits) which are
1003 * reserved for storing info about channels.
1005 #define IN_ABORT 0x80000000L
1006 #define IN_RESET 0x40000000L
1007 #define BOARD_MEMMAP 0x20000000L
1008 #define BOARD_IOMAP 0x10000000L
1009 #define BOARD_40LD 0x08000000L
1010 #define BOARD_64BIT 0x04000000L
1012 #define INTR_VALID 0x40
1014 #define PCI_CONF_AMISIG 0xa0
1015 #define PCI_CONF_AMISIG64 0xa4
1018 #define MEGA_DMA_TYPE_NONE 0xFFFF
1019 #define MEGA_BULK_DATA 0x0001
1020 #define MEGA_SGLIST 0x0002
1023 * lockscope definitions, callers can specify the lock scope with this data
1024 * type. LOCK_INT would mean the caller has not acquired the lock before
1025 * making the call and LOCK_EXT would mean otherwise.
1027 typedef enum { LOCK_INT, LOCK_EXT } lockscope_t;
1030 * Parameters for the io-mapped controllers
1033 /* I/O Port offsets */
1034 #define CMD_PORT 0x00
1035 #define ACK_PORT 0x00
1036 #define TOGGLE_PORT 0x01
1037 #define INTR_PORT 0x0a
1039 #define MBOX_BUSY_PORT 0x00
1040 #define MBOX_PORT0 0x04
1041 #define MBOX_PORT1 0x05
1042 #define MBOX_PORT2 0x06
1043 #define MBOX_PORT3 0x07
1044 #define ENABLE_MBOX_REGION 0x0B
1046 /* I/O Port Values */
1047 #define ISSUE_BYTE 0x10
1048 #define ACK_BYTE 0x08
1049 #define ENABLE_INTR_BYTE 0xc0
1050 #define DISABLE_INTR_BYTE 0x00
1051 #define VALID_INTR_BYTE 0x40
1052 #define MBOX_BUSY_BYTE 0x10
1053 #define ENABLE_MBOX_BYTE 0x00
1056 /* Setup some port macros here */
1057 #define issue_command(adapter) \
1058 outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
1060 #define irq_state(adapter) inb_p((adapter)->base + INTR_PORT)
1062 #define set_irq_state(adapter, value) \
1063 outb_p((value), (adapter)->base + INTR_PORT)
1065 #define irq_ack(adapter) \
1066 outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
1068 #define irq_enable(adapter) \
1069 outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
1071 #define irq_disable(adapter) \
1072 outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
1076 * This is our SYSDEP area. All kernel specific detail should be placed here -
1077 * as much as possible
1081 * End of SYSDEP area
1085 * ASSERT macro for megaraid. This should panic but printk should do for now
1088 #define ASSERT( expression ) \
1089 if( !(expression) ) { \
1090 panic("assertion failed: %s, file: %s, line: %d\n", \
1091 #expression, __FILE__, __LINE__); \
1094 #define ASSERT(expression)
1097 #define MBOX_ABORT_SLEEP 60
1098 #define MBOX_RESET_SLEEP 30
1099 #define MBOX_RESET_WAIT 180
1101 const char *megaraid_info (struct Scsi_Host *);
1103 static int megaraid_detect(Scsi_Host_Template *);
1104 static void mega_find_card(Scsi_Host_Template *, u16, u16);
1105 static int mega_query_adapter(adapter_t *);
1106 static inline int issue_scb(adapter_t *, scb_t *);
1107 static int mega_setup_mailbox(adapter_t *);
1109 static int megaraid_queue (Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
1110 static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
1111 static inline scb_t *mega_allocate_scb(adapter_t *, Scsi_Cmnd *);
1112 static void __mega_runpendq(adapter_t *);
1113 static inline void mega_runpendq(adapter_t *);
1114 static int issue_scb_block(adapter_t *, u_char *);
1116 static void megaraid_isr_memmapped(int, void *, struct pt_regs *);
1117 static inline void megaraid_memmbox_ack_sequence(adapter_t *);
1118 static void megaraid_isr_iomapped(int, void *, struct pt_regs *);
1119 static inline void megaraid_iombox_ack_sequence(adapter_t *);
1121 static void mega_free_scb(adapter_t *, scb_t *);
1123 static int megaraid_release (struct Scsi_Host *);
1124 static int megaraid_command (Scsi_Cmnd *);
1125 static int megaraid_abort(Scsi_Cmnd *);
1126 static int megaraid_reset(Scsi_Cmnd *);
1128 static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
1129 u32 *buffer, u32 *length);
1130 static inline int mega_busywait_mbox (adapter_t *);
1131 static int __mega_busywait_mbox (adapter_t *);
1132 static inline void mega_cmd_done(adapter_t *, u8 [], int, int);
1133 static inline void mega_free_sgl (adapter_t *adapter);
1134 static void mega_8_to_40ld (mraid_inquiry *inquiry,
1135 mega_inquiry3 *enquiry3, mega_product_info *);
1137 static int megaraid_reboot_notify (struct notifier_block *,
1138 unsigned long, void *);
1139 static int megadev_open (struct inode *, struct file *);
1141 #if defined( __x86_64__) || defined(IA32_EMULATION)
1143 #define LSI_CONFIG_COMPAT
1148 #ifdef LSI_CONFIG_COMPAT
1149 static int megadev_compat_ioctl(unsigned int, unsigned int, unsigned long,
1153 static int megadev_ioctl_entry (struct inode *, struct file *, unsigned int,
1155 static int megadev_ioctl (struct inode *, struct file *, unsigned int,
1157 static int mega_m_to_n(void *, nitioctl_t *);
1158 static int mega_n_to_m(void *, megacmd_t *);
1159 static int megadev_close (struct inode *, struct file *);
1161 static int mega_init_scb (adapter_t *);
1163 static int mega_is_bios_enabled (adapter_t *);
1164 static void mega_reorder_hosts (void);
1165 static void mega_swap_hosts (struct Scsi_Host *, struct Scsi_Host *);
1167 #ifdef CONFIG_PROC_FS
1168 static void mega_create_proc_entry(int, struct proc_dir_entry *);
1169 static int proc_read_config(char *, char **, off_t, int, int *, void *);
1170 static int proc_read_stat(char *, char **, off_t, int, int *, void *);
1171 static int proc_read_mbox(char *, char **, off_t, int, int *, void *);
1172 static int proc_rebuild_rate(char *, char **, off_t, int, int *, void *);
1173 static int proc_battery(char *, char **, off_t, int, int *, void *);
1174 static int proc_pdrv_ch0(char *, char **, off_t, int, int *, void *);
1175 static int proc_pdrv_ch1(char *, char **, off_t, int, int *, void *);
1176 static int proc_pdrv_ch2(char *, char **, off_t, int, int *, void *);
1177 static int proc_pdrv_ch3(char *, char **, off_t, int, int *, void *);
1178 static int proc_pdrv(adapter_t *, char *, int);
1179 static int proc_rdrv_10(char *, char **, off_t, int, int *, void *);
1180 static int proc_rdrv_20(char *, char **, off_t, int, int *, void *);
1181 static int proc_rdrv_30(char *, char **, off_t, int, int *, void *);
1182 static int proc_rdrv_40(char *, char **, off_t, int, int *, void *);
1183 static int proc_rdrv(adapter_t *, char *, int, int);
1185 static int mega_adapinq(adapter_t *, dma_addr_t);
1186 static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
1187 static inline caddr_t mega_allocate_inquiry(dma_addr_t *, struct pci_dev *);
1188 static inline void mega_free_inquiry(caddr_t, dma_addr_t, struct pci_dev *);
1189 static int mega_print_inquiry(char *, char *);
1192 static int mega_support_ext_cdb(adapter_t *);
1193 static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
1194 Scsi_Cmnd *, int, int);
1195 static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
1196 scb_t *, Scsi_Cmnd *, int, int);
1197 static void mega_enum_raid_scsi(adapter_t *);
1198 static void mega_get_boot_drv(adapter_t *);
1199 static inline int mega_get_ldrv_num(adapter_t *, Scsi_Cmnd *, int);
1200 static int mega_support_random_del(adapter_t *);
1201 static int mega_del_logdrv(adapter_t *, int);
1202 static int mega_do_del_logdrv(adapter_t *, int);
1203 static void mega_get_max_sgl(adapter_t *);
1204 static int mega_internal_command(adapter_t *, lockscope_t, megacmd_t *,
1206 static void mega_internal_done(Scsi_Cmnd *);
1207 static int mega_support_cluster(adapter_t *);
1210 /* vi: set ts=8 sw=8 tw=78: */