4 #ifndef LINUX_VERSION_CODE
5 #include <linux/version.h>
9 * For state flag. Do not use LSB(8 bits) which are
10 * reserved for storing info about channels.
12 #define IN_ISR 0x80000000L
13 #define IN_ABORT 0x40000000L
14 #define IN_RESET 0x20000000L
15 #define IN_QUEUE 0x10000000L
16 #define BOARD_QUARTZ 0x08000000L
17 #define BOARD_40LD 0x04000000L
18 #define BOARD_64BIT 0x02000000L
21 #define SCB_ACTIVE 0x1
23 #define SCB_ISSUED 0x3
24 #define SCB_COMPLETE 0x4
25 #define SCB_ABORTED 0x5
28 #define M_RD_CRLFSTR "\n"
29 #define M_RD_IOCTL_CMD 0x80
30 #define M_RD_IOCTL_CMD_NEW 0x81
31 #define M_RD_DRIVER_IOCTL_INTERFACE 0x82
33 #define MEGARAID_VERSION "v1.18k (Release Date: Thu Aug 28 10:05:11 EDT 2003)\n"
36 #define MEGARAID_IOCTL_VERSION 114
39 #define GET_DRIVER_INFO 0x1
41 #define MEGA_CMD_TIMEOUT 10
43 /* Feel free to fiddle with these.. max values are:
49 #define MAX_SGLIST 0x1A
50 #define MAX_COMMANDS 127
51 #define MAX_CMD_PER_LUN 63
52 #define MAX_FIRMWARE_STATUS 46
54 #define MAX_LOGICAL_DRIVES 8
57 #define MAX_PHYSICAL_DRIVES MAX_CHANNEL*MAX_TARGET
59 #define INQUIRY_DATA_SIZE 0x24
60 #define MAX_CDB_LEN 0x0A
61 #define MAX_REQ_SENSE_LEN 0x20
63 #define INTR_VALID 0x40
65 /* Direction Macros for MBOX Data direction */
67 #define FROM_DEVICE 0x1
68 #define FROMTO_DEVICE 0x2
70 /* Mailbox commands */
71 #define MEGA_MBOXCMD_LREAD 0x01
72 #define MEGA_MBOXCMD_LWRITE 0x02
73 #define MEGA_MBOXCMD_LREAD64 0xA7
74 #define MEGA_MBOXCMD_LWRITE64 0xA8
75 #define MEGA_MBOXCMD_PASSTHRU 0x03
76 #define MEGA_MBOXCMD_EXTPASSTHRU 0xE3
77 #define MEGA_MBOXCMD_PASSTHRU64 0xC3
78 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
81 /* Offsets into Mailbox */
82 #define COMMAND_PORT 0x00
83 #define COMMAND_ID_PORT 0x01
84 #define SG_LIST_PORT0 0x08
85 #define SG_LIST_PORT1 0x09
86 #define SG_LIST_PORT2 0x0a
87 #define SG_LIST_PORT3 0x0b
88 #define SG_ELEMENT_PORT 0x0d
89 #define NO_FIRED_PORT 0x0f
91 /* I/O Port offsets */
92 #define I_CMD_PORT 0x00
93 #define I_ACK_PORT 0x00
94 #define I_TOGGLE_PORT 0x01
95 #define INTR_PORT 0x0a
97 #define MAILBOX_SIZE (sizeof(mega_mailbox)-16)
98 #define MBOX_BUSY_PORT 0x00
99 #define MBOX_PORT0 0x04
100 #define MBOX_PORT1 0x05
101 #define MBOX_PORT2 0x06
102 #define MBOX_PORT3 0x07
103 #define ENABLE_MBOX_REGION 0x0B
105 /* I/O Port Values */
106 #define ISSUE_BYTE 0x10
107 #define ACK_BYTE 0x08
108 #define ENABLE_INTR_BYTE 0xc0
109 #define DISABLE_INTR_BYTE 0x00
110 #define VALID_INTR_BYTE 0x40
111 #define MBOX_BUSY_BYTE 0x10
112 #define ENABLE_MBOX_BYTE 0x00
114 /* Setup some port macros here */
115 #define WRITE_MAILBOX(base,offset,value) *(base+offset)=value
116 #define READ_MAILBOX(base,offset) *(base+offset)
118 #define WRITE_PORT(base,offset,value) outb_p(value,base+offset)
119 #define READ_PORT(base,offset) inb_p(base+offset)
121 #define ISSUE_COMMAND(base) WRITE_PORT(base,I_CMD_PORT,ISSUE_BYTE)
122 #define CLEAR_INTR(base) WRITE_PORT(base,I_ACK_PORT,ACK_BYTE)
123 #define ENABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,ENABLE_INTR_BYTE)
124 #define DISABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,DISABLE_INTR_BYTE)
126 #ifndef PCI_VENDOR_ID_LSI_LOGIC
127 #define PCI_VENDOR_ID_LSI_LOGIC 0x1000
130 /* Define AMI's PCI codes */
131 #ifndef PCI_VENDOR_ID_AMI
132 #define PCI_VENDOR_ID_AMI 0x101E
135 #ifndef PCI_DEVICE_ID_AMI_MEGARAID
136 #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
139 #ifndef PCI_DEVICE_ID_AMI_MEGARAID2
140 #define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060
143 #ifndef PCI_DEVICE_ID_AMI_MEGARAID3
144 #define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960
147 #define PCI_VENDOR_ID_DISCOVERY 0x1028
148 #define PCI_DEVICE_ID_DISCOVERY 0x000E
150 #define PCI_VENDOR_ID_PERC4_DI_YSTONE 0x1028
151 #define PCI_DEVICE_ID_PERC4_DI_YSTONE 0x000F
153 #define PCI_VENDOR_ID_PERC4_QC_VERDE 0x1000
154 #define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407
156 /* Special Adapter Commands */
157 #define FW_FIRE_WRITE 0x2C
158 #define FW_FIRE_FLASH 0x2D
160 #define FC_NEW_CONFIG 0xA1
161 #define DCMD_FC_CMD 0xA1
162 #define DCMD_FC_PROCEED 0x02
163 #define DCMD_DELETE_LOGDRV 0x03
164 #define DCMD_FC_READ_NVRAM_CONFIG 0x04
165 #define DCMD_FC_READ_NVRAM_CONFIG_64 0xC0
166 #define DCMD_FC_READ_FINAL_CONFIG 0x05
167 #define DCMD_GET_DISK_CONFIG 0x06
168 #define DCMD_GET_DISK_CONFIG_64 0xC2
169 #define DCMD_CHANGE_LDNO 0x07
170 #define DCMD_COMPACT_CONFIG 0x08
171 #define DCMD_DELETE_DRIVEGROUP 0x09
172 #define DCMD_GET_LOOPID_INFO 0x0A
173 #define DCMD_CHANGE_LOOPID 0x0B
174 #define DCMD_GET_NUM_SCSI_CHANS 0x0C
175 #define DCMD_WRITE_CONFIG 0x0D
176 #define DCMD_WRITE_CONFIG_64 0xC1
178 #define NC_SUBOP_PRODUCT_INFO 0x0E
179 #define NC_SUBOP_ENQUIRY3 0x0F
180 #define ENQ3_GET_SOLICITED_NOTIFY_ONLY 0x01
181 #define ENQ3_GET_SOLICITED_FULL 0x02
182 #define ENQ3_GET_UNSOLICITED 0x03
184 #define PCI_CONF_BASE_ADDR_OFFSET 0x10
185 #define PCI_CONF_IRQ_OFFSET 0x3c
186 #define PCI_CONF_AMISIG 0xa0
187 #define PCI_CONF_AMISIG64 0xa4
189 /* Sub-System Vendor ID sorted on alphabetical order*/
190 #define LSI_SUBSYS_ID 0x1000
191 #define AMI_SUBSYS_ID 0x101E
192 #define DELL_SUBSYS_ID 0x1028
193 #define HP_SUBSYS_ID 0x103C
194 #define INTEL_SUBSYS_ID 0x8086
196 #define AMI_SIGNATURE 0x3344
197 #define AMI_SIGNATURE_471 0xCCCC
198 #define AMI_64BIT_SIGNATURE 0x0299
200 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) /*0x20100 */
203 NULL, /* Usage Count Pointer */\
204 NULL, /* proc Directory Entry */\
205 megaraid_proc_info, /* proc Info Function */\
206 "MegaRAID", /* Driver Name */\
207 megaraid_detect, /* Detect Host Adapter */\
208 megaraid_release, /* Release Host Adapter */\
209 megaraid_info, /* Driver Info Function */\
210 megaraid_command, /* Command Function */\
211 megaraid_queue, /* Queue Command Function */\
212 megaraid_abort, /* Abort Command Function */\
213 megaraid_reset, /* Reset Command Function */\
214 NULL, /* Slave Attach Function */\
215 megaraid_biosparam, /* Disk BIOS Parameters */\
216 MAX_COMMANDS, /* # of cmds that can be\
217 outstanding at any time */\
218 7, /* HBA Target ID */\
219 MAX_SGLIST, /* Scatter/Gather Table Size */\
220 MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
222 0, /* Default Unchecked ISA DMA */\
223 ENABLE_CLUSTERING } /* Enable Clustering */
227 name: "MegaRAID", /* Driver Name */\
228 proc_info: megaraid_proc_info, /* /proc driver info */\
229 detect: megaraid_detect, /* Detect Host Adapter */\
230 release: megaraid_release, /* Release Host Adapter */\
231 info: megaraid_info, /* Driver Info Function */\
232 command: megaraid_command, /* Command Function */\
233 queuecommand: megaraid_queue, /* Queue Command Function */\
234 abort: megaraid_abort, /* Abort Command Function */\
235 reset: megaraid_reset, /* Reset Command Function */\
236 bios_param: megaraid_biosparam, /* Disk BIOS Parameters */\
237 can_queue: MAX_COMMANDS, /* Can Queue */\
238 this_id: 7, /* HBA Target ID */\
239 sg_tablesize: MAX_SGLIST, /* Scatter/Gather Table Size */\
240 cmd_per_lun: MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
241 present: 0, /* Present */\
242 unchecked_isa_dma: 0, /* Default Unchecked ISA DMA */\
243 use_clustering: ENABLE_CLUSTERING, /* Enable Clustering */\
244 highmem_io: 1, /* enable HIGHMEM I/O */ \
248 /***********************************************************************
249 * Structure Declarations for the Firmware supporting 40 Logical Drives
250 * and 256 Physical Drives.
251 ***********************************************************************/
253 #define FC_MAX_LOGICAL_DRIVES 40
254 #define FC_MAX_LOG_DEVICES FC_MAX_LOGICAL_DRIVES
255 #define FC_MAX_SPAN_DEPTH 8
256 #define FC_MAX_ROW_SIZE 32
258 #define FC_MAX_CHANNELS 16
259 #define FC_MAX_TARGETS_PER_CHANNEL 16
260 #define FC_MAX_PHYSICAL_DEVICES 256
262 /********************************************
264 ********************************************/
266 #define SIG_40LOG_32STR_8SPN 0x00282008
269 * Utilities declare this strcture size as 1024 bytes. So more fields can
270 * be added in future.
273 struct MRaidProductInfo {
274 u32 DataSize; /* current size in bytes (not including resvd) */
276 /* Current value is 0x00282008
277 * 0x28=MAX_LOGICAL_DRIVES,
278 * 0x20=Number of stripes and
279 * 0x08=Number of spans */
280 u8 FwVer[16]; /* printable ASCI string */
281 u8 BiosVer[16]; /* printable ASCI string */
282 u8 ProductName[80]; /* printable ASCI string */
284 u8 MaxConcCmds; /* Max. concurrent commands supported */
285 u8 SCSIChanPresent; /* Number of SCSI Channels detected */
286 u8 FCLoopPresent; /* Number of Fibre Loops detected */
287 u8 memType; /* EDO, FPM, SDRAM etc */
290 u16 DramSize; /* In terms of MB */
293 u16 subSystemVendorID;
294 u8 numNotifyCounters;
295 u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */
296 } __attribute__ ((packed));
297 typedef struct MRaidProductInfo megaRaidProductInfo;
299 /********************************************
301 ********************************************/
303 u8 MaxConcCmds; /* Max. concurrent commands supported. */
304 u8 RbldRate; /* Rebuild Rate. Varies from 0%-100% */
305 u8 MaxTargPerChan; /* Max. Targets supported per chan. */
306 u8 ChanPresent; /* No. of Chans present on this adapter. */
307 u8 FwVer[4]; /* Firmware version. */
308 u16 AgeOfFlash; /* No. of times FW has been downloaded. */
309 u8 ChipSetValue; /* Contents of 0xC0000832 */
310 u8 DramSize; /* In terms of MB */
311 u8 CacheFlushInterval; /* In terms of Seconds */
315 u8 write_config_count; /* Increase with evry configuration change */
316 u8 drive_inserted_count;/* Increase with every drive inserted */
317 u8 inserted_drive; /* Channel: Id of inserted drive */
320 BIT 0 : battery module missing
323 BIT 3 : battery pack missing
324 BIT 4,5 : 00 - charge complete
325 01 - fast charge in prog
326 10 - fast charge fail
328 BIt 6 : counter > 1000
331 u8 dec_fault_bus_info; /* was resvd */
332 } __attribute__ ((packed));
334 struct FC_LDRV_INFO {
335 u8 NumLDrv; /* No. of Log. Drvs configured. */
336 u8 recon_state[FC_MAX_LOGICAL_DRIVES / 8];
337 /* bit field for State of reconstruct */
338 u16 LDrvOpStatus[FC_MAX_LOGICAL_DRIVES / 8];
339 /* bit field Status of Long Operations. */
341 u32 LDrvSize[FC_MAX_LOGICAL_DRIVES]; /* Size of each log. Drv. */
342 u8 LDrvProp[FC_MAX_LOGICAL_DRIVES];
343 u8 LDrvState[FC_MAX_LOGICAL_DRIVES]; /* State of Logical Drives. */
344 } __attribute__ ((packed));
346 #define PREVSTAT_MASK 0xf0
347 #define CURRSTAT_MASK 0x0f
349 struct FC_PDRV_INFO {
350 u8 PDrvState[FC_MAX_PHYSICAL_DEVICES]; /* State of Phys Drvs. */
351 } __attribute__ ((packed));
353 struct FC_AdapterInq {
354 struct FC_ADP_INFO AdpInfo;
355 struct FC_LDRV_INFO LogdrvInfo;
356 struct FC_PDRV_INFO PhysdrvInfo;
357 } __attribute__ ((packed));
359 typedef struct FC_AdapterInq mega_RAIDINQ_FC;
361 /********************************************
363 ********************************************/
365 #define MAX_NOTIFY_SIZE 0x80
366 #define CUR_NOTIFY_SIZE sizeof(struct MegaRAID_Notify)
369 * Utilities declare this strcture size as ?? bytes. So more fields can
370 * be added in future.
372 struct MegaRAID_Notify {
373 u32 globalCounter; /* Any change increments this counter */
375 u8 paramCounter; /* Indicates any params changed */
376 u8 paramId; /* Param modified - defined below */
377 u16 paramVal; /* New val of last param modified */
379 u8 writeConfigCounter; /* write config occurred */
380 u8 writeConfigRsvd[3];
382 u8 ldrvOpCounter; /* Indicates ldrv op started/completed */
383 u8 ldrvOpId; /* ldrv num */
384 u8 ldrvOpCmd; /* ldrv operation - defined below */
385 u8 ldrvOpStatus; /* status of the operation */
387 u8 ldrvStateCounter; /* Indicates change of ldrv state */
388 u8 ldrvStateId; /* ldrv num */
389 u8 ldrvStateNew; /* New state */
390 u8 ldrvStateOld; /* old state */
392 u8 pdrvStateCounter; /* Indicates change of ldrv state */
393 u8 pdrvStateId; /* pdrv id */
394 u8 pdrvStateNew; /* New state */
395 u8 pdrvStateOld; /* old state */
397 u8 pdrvFmtCounter; /* Indicates pdrv format started/over */
398 u8 pdrvFmtId; /* pdrv id */
399 u8 pdrvFmtVal; /* format started/over */
402 u8 targXferCounter; /* Indicates SCSI-2 Xfer rate change */
403 u8 targXferId; /* pdrv Id */
404 u8 targXferVal; /* new Xfer params of last pdrv */
407 u8 fcLoopIdChgCounter; /* Indicates loopid changed */
408 u8 fcLoopIdPdrvId; /* pdrv id */
409 u8 fcLoopId0; /* loopid on fc loop 0 */
410 u8 fcLoopId1; /* loopid on fc loop 1 */
412 u8 fcLoopStateCounter; /* Indicates loop state changed */
413 u8 fcLoopState0; /* state of fc loop 0 */
414 u8 fcLoopState1; /* state of fc loop 1 */
416 } __attribute__ ((packed));
418 /********************************************
419 * PARAM IDs in Notify struct
420 ********************************************/
421 #define PARAM_RBLD_RATE 0x01
422 /*--------------------------------------
424 * byte 0: new rbld rate
425 *--------------------------------------*/
426 #define PARAM_CACHE_FLUSH_INTERVAL 0x02
427 /*--------------------------------------
429 * byte 0: new cache flush interval
430 *--------------------------------------*/
431 #define PARAM_SENSE_ALERT 0x03
432 /*--------------------------------------
434 * byte 0: last pdrv id causing chkcond
435 *--------------------------------------*/
436 #define PARAM_DRIVE_INSERTED 0x04
437 /*--------------------------------------
439 * byte 0: last pdrv id inserted
440 *--------------------------------------*/
441 #define PARAM_BATTERY_STATUS 0x05
442 /*--------------------------------------
444 * byte 0: battery status
445 *--------------------------------------*/
447 /********************************************
448 * Ldrv operation cmd in Notify struct
449 ********************************************/
450 #define LDRV_CMD_CHKCONSISTANCY 0x01
451 #define LDRV_CMD_INITIALIZE 0x02
452 #define LDRV_CMD_RECONSTRUCTION 0x03
454 /********************************************
455 * Ldrv operation status in Notify struct
456 ********************************************/
457 #define LDRV_OP_SUCCESS 0x00
458 #define LDRV_OP_FAILED 0x01
459 #define LDRV_OP_ABORTED 0x02
460 #define LDRV_OP_CORRECTED 0x03
461 #define LDRV_OP_STARTED 0x04
463 /********************************************
464 * Raid Logical drive states.
465 ********************************************/
466 #define RDRV_OFFLINE 0
467 #define RDRV_DEGRADED 1
468 #define RDRV_OPTIMAL 2
469 #define RDRV_DELETED 3
471 /*******************************************
472 * Physical drive states.
473 *******************************************/
475 #define PDRV_ONLINE 3
476 #define PDRV_FAILED 4
479 /*******************************************
480 * Formal val in Notify struct
481 *******************************************/
482 #define PDRV_FMT_START 0x01
483 #define PDRV_FMT_OVER 0x02
485 /********************************************
486 * FC Loop State in Notify Struct
487 ********************************************/
488 #define ENQ_FCLOOP_FAILED 0
489 #define ENQ_FCLOOP_ACTIVE 1
490 #define ENQ_FCLOOP_TRANSIENT 2
492 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
493 #define M_RD_DMA_TYPE_NONE 0xFFFF
494 #define M_RD_PTHRU_WITH_BULK_DATA 0x0001
495 #define M_RD_PTHRU_WITH_SGLIST 0x0002
496 #define M_RD_BULK_DATA_ONLY 0x0004
497 #define M_RD_SGLIST_ONLY 0x0008
498 #define M_RD_EPTHRU_WITH_BULK_DATA 0x0010
500 /********************************************
502 ********************************************/
504 * Utilities declare this strcture size as 1024 bytes. So more fields can
505 * be added in future.
507 struct MegaRAID_Enquiry3 {
508 u32 dataSize; /* current size in bytes (not including resvd) */
510 struct MegaRAID_Notify notify;
512 u8 notifyRsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
514 u8 rbldRate; /* Rebuild rate (0% - 100%) */
515 u8 cacheFlushInterval; /* In terms of Seconds */
517 u8 driveInsertedCount; /* drive insertion count */
520 u8 numLDrv; /* No. of Log Drives configured */
521 u8 reconState[FC_MAX_LOGICAL_DRIVES / 8]; /* State of reconstruct */
522 u16 lDrvOpStatus[FC_MAX_LOGICAL_DRIVES / 8]; /* log. Drv Status */
524 u32 lDrvSize[FC_MAX_LOGICAL_DRIVES]; /* Size of each log. Drv */
525 u8 lDrvProp[FC_MAX_LOGICAL_DRIVES];
526 u8 lDrvState[FC_MAX_LOGICAL_DRIVES]; /* State of Logical Drives */
527 u8 pDrvState[FC_MAX_PHYSICAL_DEVICES]; /* State of Phys. Drvs. */
528 u16 physDrvFormat[FC_MAX_PHYSICAL_DEVICES / 16];
530 u8 targXfer[80]; /* phys device transfer rate */
531 u8 pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
532 } __attribute__ ((packed));
533 typedef struct MegaRAID_Enquiry3 mega_Enquiry3;
536 typedef struct _mega_ADP_INFO {
545 u8 CacheFlushInterval;
550 typedef struct _mega_LDRV_INFO {
553 u32 LDrvSize[MAX_LOGICAL_DRIVES];
554 u8 LDrvProp[MAX_LOGICAL_DRIVES];
555 u8 LDrvState[MAX_LOGICAL_DRIVES];
558 typedef struct _mega_PDRV_INFO {
559 u8 PDrvState[MAX_PHYSICAL_DRIVES];
563 /* RAID inquiry: Mailbox command 0x5*/
564 typedef struct _mega_RAIDINQ {
565 mega_ADP_INFO AdpInfo;
566 mega_LDRV_INFO LogdrvInfo;
567 mega_PDRV_INFO PhysdrvInfo;
570 /* Passthrough command: Mailbox command 0x3*/
571 typedef struct mega_passthru {
572 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
576 u8 logdrv; /* if islogical == 1 */
577 u8 channel; /* if islogical == 0 */
578 u8 target; /* if islogical == 0 */
579 u8 queuetag; /* unused */
580 u8 queueaction; /* unused */
584 u8 reqsensearea[MAX_REQ_SENSE_LEN];
592 * Extended passthru: support CDB > 10 bytes
595 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
602 u8 logdrv; /* if islogical == 1 */
603 u8 channel; /* if islogical == 0 */
604 u8 target; /* if islogical == 0 */
606 u8 queuetag; /* unused */
607 u8 queueaction; /* unused */
616 u8 reqsensearea[MAX_REQ_SENSE_LEN];
623 struct _mega_mailbox {
626 /* 0x2 */ u16 numsectors;
628 /* 0x8 */ u32 xferaddr;
630 /* 0xD */ u8 numsgelements;
633 /* 0x10 */ u8 numstatus;
634 /* 0x11 */ u8 status;
635 /* 0x12 */ u8 completed[46];
636 volatile u8 mraid_poll;
637 volatile u8 mraid_ack;
638 u8 pad[16]; /* for alignment purposes */
639 } __attribute__ ((packed));
640 typedef struct _mega_mailbox mega_mailbox;
645 mega_mailbox mailbox;
648 typedef struct _mega_ioctl_mbox {
651 /* 0x2 */ u8 channel;
654 /* 0x8 */ u32 xferaddr;
656 /* 0xD */ u8 numsgelements;
659 /* 0x10 */ u8 numstatus;
660 /* 0x11 */ u8 status;
661 /* 0x12 */ u8 completed[46];
667 typedef struct _mega_64sglist32 {
670 } __attribute__ ((packed)) mega_64sglist;
672 typedef struct _mega_sglist {
677 /* Queued command data */
678 typedef struct _mega_scb mega_scb;
685 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
687 dma_addr_t dma_h_bulkdata; /*Dma handle for bulk data transfter */
688 u32 dma_direction; /*Dma direction */
689 dma_addr_t dma_h_sgdata; /*Dma handle for the sglist structure */
690 dma_addr_t dma_h_sglist[MAX_SGLIST]; /*Dma handle for all SGL elements */
692 dma_addr_t dma_sghandle64;
693 dma_addr_t dma_passthruhandle64;
694 dma_addr_t dma_ext_passthruhandle64;
695 dma_addr_t dma_bounce_buffer;
699 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
700 mega_passthru *pthru;
701 mega_ext_passthru *epthru;
704 mega_ext_passthru epthru;
709 mega_64sglist *sg64List;
710 struct semaphore ioctl_sem;
716 /* internal locking by the queue manipulting routines */
717 #define INTERNAL_LOCK 0
718 /* external locking by the queue manipulting routines */
719 #define EXTERNAL_LOCK 1
721 #define INTR_ENB 0 /* do not disable interrupt while manipulating */
722 #define INTR_DIS 1 /* disable interrupt while manipulating */
724 #define NVIRT_CHAN 4 /* # of virtual channels to represent 60 logical
727 /* Per-controller data */
728 typedef struct _mega_host_config {
738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
739 dma_addr_t dma_handle64, adjdmahandle64;
745 spinlock_t lock_free;
749 spinlock_t lock_pend;
751 Scsi_Cmnd *qCompletedH;
752 Scsi_Cmnd *qCompletedT;
753 spinlock_t lock_scsicmd;
759 unsigned long nReads[FC_MAX_LOGICAL_DRIVES];
760 unsigned long nReadBlocks[FC_MAX_LOGICAL_DRIVES];
761 unsigned long nWrites[FC_MAX_LOGICAL_DRIVES];
762 unsigned long nWriteBlocks[FC_MAX_LOGICAL_DRIVES];
763 unsigned long nInterrupts;
764 /* Host adapter parameters */
768 struct Scsi_Host *host;
770 volatile mega_mailbox64 *mbox64; /* ptr to beginning of 64-bit mailbox */
771 volatile mega_mailbox *mbox; /* ptr to beginning of standard mailbox */
773 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
774 /* ptr to beginning of standard mailbox */
775 volatile mega_mailbox64 *mailbox64ptr;
777 volatile mega_mailbox64 mailbox64;
780 volatile u8 mega_buffer[2 * 1024L];
781 volatile megaRaidProductInfo productInfo;
784 mega_scb scbList[MAX_COMMANDS];
786 #define PROCBUFSIZE 4096
787 char procbuf[PROCBUFSIZE];
789 struct proc_dir_entry *controller_proc_dir_entry;
790 struct proc_dir_entry *proc_read, *proc_stat, *proc_status, *proc_mbox;
793 u8 boot_ldrv_enabled; /* boot from logical drive */
794 u8 boot_ldrv; /* boot logical drive */
795 u8 boot_pdrv_enabled; /* boot from physical drive */
796 u8 boot_pdrv_ch; /* boot physical drive channel */
797 u8 boot_pdrv_tgt; /* boot physical drive target */
799 int support_random_del; /* Do we support random deletion of logdrvs */
800 int read_ldidmap; /* set after logical drive deltion. The logical
801 drive number must be read from the map */
802 int quiescent; /* a stage reached when delete logical drive needs to
803 be done. Stop sending requests to the hba till
804 delete operation is completed */
806 mega_scb *int_qh; /* commands are queued in the internal queue */
807 mega_scb *int_qt; /* while the hba is quiescent */
809 char logdrv_chan[MAX_CHANNEL+NVIRT_CHAN]; /* logical drive are on
814 typedef struct _driver_info {
820 * User ioctl structure.
821 * This structure will be used for Traditional Method ioctl interface
822 * commands (M_RD_IOCTL_CMD),Alternate Buffer Method (M_RD_IOCTL_CMD_NEW)
823 * ioctl commands and the Driver ioctls(M_RD_DRIVER_IOCTL_INTERFACE).
824 * The Driver ioctl interface handles the commands at
825 * the driver level, without being sent to the card.
827 #define MEGADEVIOC 0x84
829 /* system call imposed limit. Change accordingly */
830 #define IOCTL_MAX_DATALEN 4096
842 #if BITS_PER_LONG == 32
846 #if BITS_PER_LONG == 64
852 u8 mbox[18]; /* 16 bytes + 2 status bytes */
854 #if BITS_PER_LONG == 32
855 char *data; /* buffer <= 4096 for 0x80 commands */
858 #if BITS_PER_LONG == 64
865 * struct mcontroller is used to pass information about the controllers in the
866 * system. Its upto the application how to use the information. We are passing
867 * as much info about the cards as possible and useful. Before issuing the
868 * call to find information about the cards, the applicaiton needs to issue a
869 * ioctl first to find out the number of controllers in the system.
871 #define MAX_CONTROLLERS 32
886 struct mbox_passthru {
901 * Defines for Driver IOCTL interface, Op-code:M_RD_DRIVER_IOCTL_INTERFACE
903 #define MEGAIOC_MAGIC 'm'
905 /* Mega IOCTL command */
906 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, struct uioctl_t)
908 #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
909 #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
910 #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
911 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
912 #define GETADAP(mkadap) ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
914 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) /*0x20300 */
915 extern struct proc_dir_entry proc_scsi_megaraid;
918 /* For Host Re-Ordering */
919 #define MAX_CONTROLLERS 32
923 mega_host_config *hostdata_addr;
926 #define IS_BIOS_ENABLED 0x62
927 #define GET_BIOS 0x01
928 #define CHNL_CLASS 0xA9
929 #define GET_CHNL_CLASS 0x00
930 #define SET_CHNL_CLASS 0x01
935 #define BIOS_PVT_DATA 0x40
936 #define GET_BIOS_PVT_DATA 0x00
939 struct private_bios_data {
941 * bits 0-3 - BIOS geometry
945 * Others values are invalid
947 u8 unused:4; /* bits 4-7 are unused */
949 * logical/physical drive set as boot drive
950 * 0..7 - for 8LD cards
951 * 0..39 - for 40LD cards
954 u16 cksum; /* 0-(sum of first 13 bytes of this structure) */
959 * Command for random deletion of logical drives
961 #define FC_DEL_LOGDRV 0xA4 /* f/w command */
962 #define OP_SUP_DEL_LOGDRV 0x2A /* is feature supported */
963 #define OP_GET_LDID_MAP 0x18 /* get logdrv id and logdrv number map */
964 #define OP_DEL_LOGDRV 0x1C /* delete logical drive */
966 /*================================================================
968 * Function prototypes
970 *================================================================
972 const char *megaraid_info (struct Scsi_Host *);
973 int megaraid_detect (Scsi_Host_Template *);
974 int megaraid_release (struct Scsi_Host *);
975 int megaraid_command (Scsi_Cmnd *);
976 int megaraid_abort (Scsi_Cmnd *);
977 int megaraid_reset (Scsi_Cmnd *, unsigned int);
978 int megaraid_queue (Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
979 int megaraid_biosparam (Disk *, kdev_t, int *);
980 int megaraid_proc_info (char *buffer, char **start, off_t offset,
981 int length, int hostno, int inout);
983 static int megaIssueCmd (mega_host_config * megaCfg, u_char * mboxData,
984 mega_scb * scb, int intr);
985 static int mega_build_sglist (mega_host_config * megaCfg, mega_scb * scb,
986 u32 * buffer, u32 * length);
987 static int mega_busyWaitMbox (mega_host_config *);
988 static int mega_runpendq (mega_host_config *);
989 static void mega_rundoneq (mega_host_config *);
990 static void mega_cmd_done (mega_host_config *, mega_scb *, int);
991 static inline void mega_freeSgList (mega_host_config * megaCfg);
992 static void mega_Convert8ldTo40ld (mega_RAIDINQ * inquiry,
993 mega_Enquiry3 * enquiry3,
994 megaRaidProductInfo * productInfo);
996 static int megaraid_reboot_notify (struct notifier_block *,
997 unsigned long, void *);
998 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
999 static mega_scb *mega_ioctl (mega_host_config * megaCfg, Scsi_Cmnd * SCpnt);
1000 static void mega_build_kernel_sg (char *barea, ulong xfersize, mega_scb * pScb,
1001 mega_ioctl_mbox * mbox);
1004 static int megadev_open (struct inode *, struct file *);
1005 static int megadev_ioctl_entry (struct inode *, struct file *,
1006 unsigned int, unsigned long);
1007 static int megadev_ioctl (struct inode *, struct file *,
1008 unsigned int, unsigned long);
1009 static mega_scb *megadev_doioctl (mega_host_config *, Scsi_Cmnd *);
1010 static int megadev_close (struct inode *, struct file *);
1011 static void megadev_ioctl_done (Scsi_Cmnd *);
1012 static int mega_init_scb (mega_host_config *);
1013 static void enq_scb_freelist (mega_host_config *, mega_scb *,
1014 int lock, int intr);
1016 static int mega_is_bios_enabled (mega_host_config *);
1017 static void mega_reorder_hosts (void);
1018 static void mega_swap_hosts (struct Scsi_Host *, struct Scsi_Host *);
1020 static void mega_create_proc_entry (int index, struct proc_dir_entry *);
1021 static int mega_support_ext_cdb(mega_host_config *);
1022 static mega_passthru* mega_prepare_passthru(mega_host_config *, mega_scb *,
1023 Scsi_Cmnd *, int, int);
1024 static mega_ext_passthru* mega_prepare_extpassthru(mega_host_config *,
1025 mega_scb *, Scsi_Cmnd *, int, int);
1026 static void mega_enum_raid_scsi(mega_host_config *);
1027 static int mega_partsize(Disk *, kdev_t, int *);
1028 static void mega_get_boot_drv(mega_host_config *);
1029 static int mega_get_ldrv_num(mega_host_config *, Scsi_Cmnd *, int);
1030 static int mega_support_random_del(mega_host_config *);
1031 static int mega_del_logdrv(mega_host_config *, int);
1032 static int mega_do_del_logdrv(mega_host_config *, int);