4 #ifndef LINUX_VERSION_CODE
5 #include <linux/version.h>
8 #define IN_ISR 0x80000000L
9 #define IN_ABORT 0x40000000L
10 #define IN_RESET 0x20000000L
11 #define IN_QUEUE 0x10000000L
12 #define BOARD_QUARTZ 0x08000000L
13 #define BOARD_40LD 0x04000000L
17 #define SCB_ACTIVE 0x1
19 #define SCB_ISSUED 0x3
20 #define SCB_COMPLETE 0x4
21 #define SCB_ABORTED 0x5
25 #define MEGA_CMD_TIMEOUT 10
27 /* Feel free to fiddle with these.. max values are:
32 #define MAX_SGLIST 0x1A
33 #define MAX_COMMANDS 127
34 #define MAX_CMD_PER_LUN 63
35 #define MAX_FIRMWARE_STATUS 46
37 #define MAX_LOGICAL_DRIVES 8
40 #define MAX_PHYSICAL_DRIVES MAX_CHANNEL*MAX_TARGET
42 #define INQUIRY_DATA_SIZE 0x24
43 #define MAX_CDB_LEN 0x0A
44 #define MAX_REQ_SENSE_LEN 0x20
46 #define INTR_VALID 0x40
48 /* Mailbox commands */
49 #define MEGA_MBOXCMD_LREAD 0x01
50 #define MEGA_MBOXCMD_LWRITE 0x02
51 #define MEGA_MBOXCMD_PASSTHRU 0x03
52 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
54 /* Offsets into Mailbox */
55 #define COMMAND_PORT 0x00
56 #define COMMAND_ID_PORT 0x01
57 #define SG_LIST_PORT0 0x08
58 #define SG_LIST_PORT1 0x09
59 #define SG_LIST_PORT2 0x0a
60 #define SG_LIST_PORT3 0x0b
61 #define SG_ELEMENT_PORT 0x0d
62 #define NO_FIRED_PORT 0x0f
64 /* I/O Port offsets */
65 #define I_CMD_PORT 0x00
66 #define I_ACK_PORT 0x00
67 #define I_TOGGLE_PORT 0x01
68 #define INTR_PORT 0x0a
70 #define MAILBOX_SIZE (sizeof(mega_mailbox)-16)
71 #define MBOX_BUSY_PORT 0x00
72 #define MBOX_PORT0 0x04
73 #define MBOX_PORT1 0x05
74 #define MBOX_PORT2 0x06
75 #define MBOX_PORT3 0x07
76 #define ENABLE_MBOX_REGION 0x0B
79 #define ISSUE_BYTE 0x10
81 #define ENABLE_INTR_BYTE 0xc0
82 #define DISABLE_INTR_BYTE 0x00
83 #define VALID_INTR_BYTE 0x40
84 #define MBOX_BUSY_BYTE 0x10
85 #define ENABLE_MBOX_BYTE 0x00
87 /* Setup some port macros here */
88 #define WRITE_MAILBOX(base,offset,value) *(base+offset)=value
89 #define READ_MAILBOX(base,offset) *(base+offset)
91 #define WRITE_PORT(base,offset,value) outb_p(value,base+offset)
92 #define READ_PORT(base,offset) inb_p(base+offset)
94 #define ISSUE_COMMAND(base) WRITE_PORT(base,I_CMD_PORT,ISSUE_BYTE)
95 #define CLEAR_INTR(base) WRITE_PORT(base,I_ACK_PORT,ACK_BYTE)
96 #define ENABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,ENABLE_INTR_BYTE)
97 #define DISABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,DISABLE_INTR_BYTE)
99 /* Define AMI's PCI codes */
100 #undef PCI_VENDOR_ID_AMI
101 #undef PCI_DEVICE_ID_AMI_MEGARAID
103 #ifndef PCI_VENDOR_ID_AMI
104 #define PCI_VENDOR_ID_AMI 0x101E
105 #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
108 #define PCI_CONF_BASE_ADDR_OFFSET 0x10
109 #define PCI_CONF_IRQ_OFFSET 0x3c
110 #define PCI_CONF_AMISIG 0xa0
111 #define AMI_SIGNATURE 0x3344
113 #if LINUX_VERSION_CODE < 0x20100
116 NULL, /* Usage Count Pointer */\
117 NULL, /* /proc Directory Entry */\
118 megaraid_proc_info, /* /proc Info Function */\
119 "MegaRAID", /* Driver Name */\
120 megaraid_detect, /* Detect Host Adapter */\
121 megaraid_release, /* Release Host Adapter */\
122 megaraid_info, /* Driver Info Function */\
123 megaraid_command, /* Command Function */\
124 megaraid_queue, /* Queue Command Function */\
125 megaraid_abort, /* Abort Command Function */\
126 megaraid_reset, /* Reset Command Function */\
127 NULL, /* Slave Attach Function */\
128 megaraid_biosparam, /* Disk BIOS Parameters */\
129 MAX_COMMANDS, /* # of cmds that can be\
130 outstanding at any time */\
131 7, /* HBA Target ID */\
132 MAX_SGLIST, /* Scatter/Gather Table Size */\
133 MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
135 0, /* Default Unchecked ISA DMA */\
136 ENABLE_CLUSTERING } /* Enable Clustering */
140 name: "MegaRAID", /* Driver Name */\
141 proc_info: megaraid_proc_info, /* /proc driver info */\
142 detect: megaraid_detect, /* Detect Host Adapter */\
143 release: megaraid_release, /* Release Host Adapter */\
144 info: megaraid_info, /* Driver Info Function */\
145 command: megaraid_command, /* Command Function */\
146 queuecommand: megaraid_queue, /* Queue Command Function */\
147 abort: megaraid_abort, /* Abort Command Function */\
148 reset: megaraid_reset, /* Reset Command Function */\
149 bios_param: megaraid_biosparam, /* Disk BIOS Parameters */\
150 can_queue: MAX_COMMANDS, /* Can Queue */\
151 this_id: 7, /* HBA Target ID */\
152 sg_tablesize: MAX_SGLIST, /* Scatter/Gather Table Size */\
153 cmd_per_lun: MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
154 present: 0, /* Present */\
155 unchecked_isa_dma:1, /* Default Unchecked ISA DMA */\
156 use_clustering: ENABLE_CLUSTERING /* Enable Clustering */\
161 /***********************************************************************
162 * Structure Declarations for the Firmware supporting 40 Logical Drives
163 * and 256 Physical Drives.
164 ***********************************************************************/
166 #define FC_MAX_LOGICAL_DRIVES 40
167 #define FC_MAX_LOG_DEVICES FC_MAX_LOGICAL_DRIVES
168 #define FC_MAX_SPAN_DEPTH 8
169 #define FC_MAX_ROW_SIZE 32
171 #define FC_MAX_CHANNELS 16
172 #define FC_MAX_TARGETS_PER_CHANNEL 16
173 #define FC_MAX_PHYSICAL_DEVICES 256
175 #define FC_NEW_CONFIG 0xA1
176 #define DCMD_FC_CMD 0xA1
177 #define NC_SUBOP_PRODUCT_INFO 0x0E
178 #define NC_SUBOP_ENQUIRY3 0x0F
179 #define ENQ3_GET_SOLICITED_NOTIFY_ONLY 0x01
180 #define ENQ3_GET_SOLICITED_FULL 0x02
181 #define ENQ3_GET_UNSOLICITED 0x03
184 /********************************************
185 * PRODUCT_INFO Strucure
186 ********************************************/
188 #define SIG_40LOG_32STR_8SPN 0x00282008
191 * Utilities declare this strcture size as 1024 bytes. So more fields can
192 * be added in future.
195 struct MRaidProductInfo
197 u32 DataSize
; /* current size in bytes (not including resvd) */
199 /* Current value is 0x00282008
200 * 0x28=MAX_LOGICAL_DRIVES,
201 * 0x20=Number of stripes and
202 * 0x08=Number of spans */
203 u8 FwVer
[16]; /* printable ASCI string */
204 u8 BiosVer
[16]; /* printable ASCI string */
205 u8 ProductName
[80]; /* printable ASCI string */
207 u8 MaxConcCmds
; /* Max. concurrent commands supported */
208 u8 SCSIChanPresent
; /* Number of SCSI Channels detected */
209 u8 FCLoopPresent
; /* Number of Fibre Loops detected */
210 u8 memType
; /* EDO, FPM, SDRAM etc */
213 u16 DramSize
; /* In terms of MB */
216 u16 subSystemVendorID
;
217 u8 numNotifyCounters
;
218 u8 pad1k
[889]; /* 135 + 889 resvd = 1024 total size */
219 }__attribute__((packed
));
220 typedef struct MRaidProductInfo megaRaidProductInfo
;
222 /********************************************
223 * Standard ENQUIRY Strucure
224 ********************************************/
227 u8 MaxConcCmds
; /* Max. concurrent commands supported. */
228 u8 RbldRate
; /* Rebuild Rate. Varies from 0%-100% */
229 u8 MaxTargPerChan
; /* Max. Targets supported per chan. */
230 u8 ChanPresent
; /* No. of Chans present on this adapter. */
231 u8 FwVer
[4]; /* Firmware version. */
232 u16 AgeOfFlash
; /* No. of times FW has been downloaded. */
233 u8 ChipSetValue
; /* Contents of 0xC0000832 */
234 u8 DramSize
; /* In terms of MB */
235 u8 CacheFlushInterval
; /* In terms of Seconds */
239 u8 write_config_count
; /* Increase with evry configuration change */
240 u8 drive_inserted_count
; /* Increase with every drive inserted */
241 u8 inserted_drive
; /* Channel: Id of inserted drive */
244 BIT 0 : battery module missing
247 BIT 3 : battery pack missing
248 BIT 4,5 : 00 - charge complete
249 01 - fast charge in prog
250 10 - fast charge fail
252 BIt 6 : counter > 1000
255 u8 dec_fault_bus_info
; /* was resvd */
256 }__attribute__((packed
));
260 u8 NumLDrv
; /* No. of Log. Drvs configured. */
261 u8 recon_state
[FC_MAX_LOGICAL_DRIVES
/8];
262 /* bit field for State of reconstruct */
263 u16 LDrvOpStatus
[FC_MAX_LOGICAL_DRIVES
/8];
264 /* bit field Status of Long Operations. */
266 u32 LDrvSize
[FC_MAX_LOGICAL_DRIVES
]; /* Size of each log. Drv. */
267 u8 LDrvProp
[FC_MAX_LOGICAL_DRIVES
];
268 u8 LDrvState
[FC_MAX_LOGICAL_DRIVES
]; /* State of Logical Drives. */
269 }__attribute__((packed
));
271 #define PREVSTAT_MASK 0xf0
272 #define CURRSTAT_MASK 0x0f
276 u8 PDrvState
[FC_MAX_PHYSICAL_DEVICES
]; /* State of Phys Drvs. */
277 }__attribute__((packed
));
282 struct FC_ADP_INFO AdpInfo
;
283 struct FC_LDRV_INFO LogdrvInfo
;
284 struct FC_PDRV_INFO PhysdrvInfo
;
285 }__attribute__((packed
));
288 typedef struct FC_AdapterInq mega_RAIDINQ_FC
;
290 /********************************************
291 * NOTIFICATION Strucure
292 ********************************************/
294 #define MAX_NOTIFY_SIZE 0x80
295 #define CUR_NOTIFY_SIZE sizeof(struct MegaRAID_Notify)
298 * Utilities declare this strcture size as ?? bytes. So more fields can
299 * be added in future.
301 struct MegaRAID_Notify
303 u32 globalCounter
; /* Any change increments this counter */
305 u8 paramCounter
; /* Indicates any params changed */
306 u8 paramId
; /* Param modified - defined below */
307 u16 paramVal
; /* New val of last param modified */
309 u8 writeConfigCounter
; /* write config occurred */
310 u8 writeConfigRsvd
[3];
312 u8 ldrvOpCounter
; /* Indicates ldrv op started/completed */
313 u8 ldrvOpId
; /* ldrv num */
314 u8 ldrvOpCmd
; /* ldrv operation - defined below */
315 u8 ldrvOpStatus
; /* status of the operation */
317 u8 ldrvStateCounter
; /* Indicates change of ldrv state */
318 u8 ldrvStateId
; /* ldrv num */
319 u8 ldrvStateNew
; /* New state */
320 u8 ldrvStateOld
; /* old state */
322 u8 pdrvStateCounter
; /* Indicates change of ldrv state */
323 u8 pdrvStateId
; /* pdrv id */
324 u8 pdrvStateNew
; /* New state */
325 u8 pdrvStateOld
; /* old state */
327 u8 pdrvFmtCounter
; /* Indicates pdrv format started/over */
328 u8 pdrvFmtId
; /* pdrv id */
329 u8 pdrvFmtVal
; /* format started/over */
332 u8 targXferCounter
; /* Indicates SCSI-2 Xfer rate change */
333 u8 targXferId
; /* pdrv Id */
334 u8 targXferVal
; /* new Xfer params of last pdrv */
337 u8 fcLoopIdChgCounter
; /* Indicates loopid changed */
338 u8 fcLoopIdPdrvId
; /* pdrv id */
339 u8 fcLoopId0
; /* loopid on fc loop 0 */
340 u8 fcLoopId1
; /* loopid on fc loop 1 */
342 u8 fcLoopStateCounter
; /* Indicates loop state changed */
343 u8 fcLoopState0
; /* state of fc loop 0 */
344 u8 fcLoopState1
; /* state of fc loop 1 */
346 }__attribute__((packed
));
349 /********************************************
350 * PARAM IDs in Notify struct
351 ********************************************/
352 #define PARAM_RBLD_RATE 0x01
353 /*--------------------------------------
355 * byte 0: new rbld rate
356 *--------------------------------------*/
357 #define PARAM_CACHE_FLUSH_INTERVAL 0x02
358 /*--------------------------------------
360 * byte 0: new cache flush interval
361 *--------------------------------------*/
362 #define PARAM_SENSE_ALERT 0x03
363 /*--------------------------------------
365 * byte 0: last pdrv id causing chkcond
366 *--------------------------------------*/
367 #define PARAM_DRIVE_INSERTED 0x04
368 /*--------------------------------------
370 * byte 0: last pdrv id inserted
371 *--------------------------------------*/
372 #define PARAM_BATTERY_STATUS 0x05
373 /*--------------------------------------
375 * byte 0: battery status
376 *--------------------------------------*/
378 /********************************************
379 * Ldrv operation cmd in Notify struct
380 ********************************************/
381 #define LDRV_CMD_CHKCONSISTANCY 0x01
382 #define LDRV_CMD_INITIALIZE 0x02
383 #define LDRV_CMD_RECONSTRUCTION 0x03
385 /********************************************
386 * Ldrv operation status in Notify struct
387 ********************************************/
388 #define LDRV_OP_SUCCESS 0x00
389 #define LDRV_OP_FAILED 0x01
390 #define LDRV_OP_ABORTED 0x02
391 #define LDRV_OP_CORRECTED 0x03
392 #define LDRV_OP_STARTED 0x04
395 /********************************************
396 * Raid Logical drive states.
397 ********************************************/
398 #define RDRV_OFFLINE 0
399 #define RDRV_DEGRADED 1
400 #define RDRV_OPTIMAL 2
401 #define RDRV_DELETED 3
403 /*******************************************
404 * Physical drive states.
405 *******************************************/
407 #define PDRV_ONLINE 3
408 #define PDRV_FAILED 4
410 /* #define PDRV_HOTSPARE 6 */
412 /*******************************************
413 * Formal val in Notify struct
414 *******************************************/
415 #define PDRV_FMT_START 0x01
416 #define PDRV_FMT_OVER 0x02
418 /********************************************
419 * FC Loop State in Notify Struct
420 ********************************************/
421 #define ENQ_FCLOOP_FAILED 0
422 #define ENQ_FCLOOP_ACTIVE 1
423 #define ENQ_FCLOOP_TRANSIENT 2
425 /********************************************
427 ********************************************/
429 * Utilities declare this strcture size as 1024 bytes. So more fields can
430 * be added in future.
432 struct MegaRAID_Enquiry3
434 u32 dataSize
; /* current size in bytes (not including resvd) */
436 struct MegaRAID_Notify notify
;
438 u8 notifyRsvd
[MAX_NOTIFY_SIZE
- CUR_NOTIFY_SIZE
];
440 u8 rbldRate
; /* Rebuild rate (0% - 100%) */
441 u8 cacheFlushInterval
; /* In terms of Seconds */
443 u8 driveInsertedCount
; /* drive insertion count */
446 u8 numLDrv
; /* No. of Log Drives configured */
447 u8 reconState
[FC_MAX_LOGICAL_DRIVES
/8]; /* State of reconstruct */
448 u16 lDrvOpStatus
[FC_MAX_LOGICAL_DRIVES
/8]; /* log. Drv Status */
450 u32 lDrvSize
[FC_MAX_LOGICAL_DRIVES
]; /* Size of each log. Drv */
451 u8 lDrvProp
[FC_MAX_LOGICAL_DRIVES
];
452 u8 lDrvState
[FC_MAX_LOGICAL_DRIVES
]; /* State of Logical Drives */
453 u8 pDrvState
[FC_MAX_PHYSICAL_DEVICES
]; /* State of Phys. Drvs. */
454 u16 physDrvFormat
[FC_MAX_PHYSICAL_DEVICES
/16];
456 u8 targXfer
[80]; /* phys device transfer rate */
457 u8 pad1k
[263]; /* 761 + 263reserved = 1024 bytes total size */
458 }__attribute__((packed
));
459 typedef struct MegaRAID_Enquiry3 mega_Enquiry3
;
462 typedef struct _mega_ADP_INFO
{
471 u8 CacheFlushInterval
;
476 typedef struct _mega_LDRV_INFO
{
479 u32 LDrvSize
[MAX_LOGICAL_DRIVES
];
480 u8 LDrvProp
[MAX_LOGICAL_DRIVES
];
481 u8 LDrvState
[MAX_LOGICAL_DRIVES
];
484 typedef struct _mega_PDRV_INFO
{
485 u8 PDrvState
[MAX_PHYSICAL_DRIVES
];
489 // RAID inquiry: Mailbox command 0x5
490 typedef struct _mega_RAIDINQ
{
491 mega_ADP_INFO AdpInfo
;
492 mega_LDRV_INFO LogdrvInfo
;
493 mega_PDRV_INFO PhysdrvInfo
;
496 // Passthrough command: Mailbox command 0x3
497 typedef struct mega_passthru
{
498 u8 timeout
:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
502 u8 logdrv
; /* if islogical == 1 */
503 u8 channel
; /* if islogical == 0 */
504 u8 target
; /* if islogical == 0 */
505 u8 queuetag
; /* unused */
506 u8 queueaction
; /* unused */
510 u8 reqsensearea
[MAX_REQ_SENSE_LEN
];
517 struct _mega_mailbox
{
520 /* 0x2 */ u16 numsectors
;
522 /* 0x8 */ u32 xferaddr
;
524 /* 0xD */ u8 numsgelements
;
527 /* 0x10 */ u8 numstatus
;
528 /* 0x11 */ u8 status
;
529 /* 0x12 */ u8 completed
[46];
532 u8 pad
[16]; /* for alignment purposes */
533 }__attribute__((packed
));
534 typedef struct _mega_mailbox mega_mailbox
;
537 u32 xferSegment
; /* for 64-bit controllers */
538 mega_mailbox mailbox
;
541 typedef struct _mega_ioctl_mbox
{
544 /* 0x2 */ u8 channel
;
547 /* 0x8 */ u32 xferaddr
;
549 /* 0xD */ u8 numsgelements
;
552 /* 0x10 */ u8 numstatus
;
553 /* 0x11 */ u8 status
;
554 /* 0x12 */ u8 completed
[46];
560 typedef struct _mega_sglist
{
565 /* Queued command data */
566 typedef struct _mega_scb mega_scb
;
576 char *kern_area
; /* Only used for large ioctl xfers */
577 struct wait_queue
*ioctl_wait
;
578 struct semaphore sem
;
582 /* Per-controller data */
583 typedef struct _mega_host_config
{
593 Scsi_Cmnd
*qCompletedH
;
594 Scsi_Cmnd
*qCompletedT
;
599 u32 nReads
[FC_MAX_LOGICAL_DRIVES
];
600 u32 nWrites
[FC_MAX_LOGICAL_DRIVES
];
602 /* Host adapter parameters */
606 struct Scsi_Host
*host
;
608 volatile mega_mailbox64
*mbox64
; /* ptr to beginning of 64-bit mailbox */
609 volatile mega_mailbox
*mbox
; /* ptr to beginning of standard mailbox */
610 volatile mega_mailbox64 mailbox64
;
613 u8 generic_buffer
[2 * 1024L];
614 mega_RAIDINQ adapterInfoData
;
615 mega_Enquiry3 enquiry3Data
;
618 volatile u8 mega_buffer
[2*1024L];
620 volatile megaRaidProductInfo productInfo
;
623 mega_scb scbList
[MAX_COMMANDS
];
626 const char *megaraid_info(struct Scsi_Host
*);
627 int megaraid_detect(Scsi_Host_Template
*);
628 int megaraid_release(struct Scsi_Host
*);
629 int megaraid_command(Scsi_Cmnd
*);
630 int megaraid_abort(Scsi_Cmnd
*);
631 int megaraid_reset(Scsi_Cmnd
*, unsigned int);
632 int megaraid_queue(Scsi_Cmnd
*, void (*done
) (Scsi_Cmnd
*));
633 int megaraid_biosparam(Disk
*, kdev_t
, int *);
634 int megaraid_proc_info(char *buffer
, char **start
, off_t offset
,
635 int length
, int hostno
, int inout
);