File: /usr/src/linux/drivers/scsi/megaraid.h
1 #ifndef __MEGARAID_H__
2 #define __MEGARAID_H__
3
4 #ifndef LINUX_VERSION_CODE
5 #include <linux/version.h>
6 #endif
7
8 #define IN_ISR 0x80000000L
9 #define IN_ABORT 0x40000000L
10 #define IN_RESET 0x20000000L
11 #define IN_QUEUE 0x10000000L
12
13 #define BOARD_QUARTZ 0x08000000L
14 #define BOARD_40LD 0x04000000L
15 #define BOARD_64BIT 0x02000000L
16
17 #define SCB_FREE 0x0
18 #define SCB_ACTIVE 0x1
19 #define SCB_WAITQ 0x2
20 #define SCB_ISSUED 0x3
21 #define SCB_COMPLETE 0x4
22 #define SCB_ABORTED 0x5
23 #define SCB_RESET 0x6
24
25 #define M_RD_CRLFSTR "\n"
26 #define M_RD_IOCTL_CMD 0x80
27 #define M_RD_IOCTL_CMD_NEW 0x81
28 #define M_RD_DRIVER_IOCTL_INTERFACE 0x82
29
30 #define MEGARAID_VERSION "v1.17a (Release Date: Fri Jul 13 18:44:01 EDT 2001)"
31
32 #define MEGARAID_IOCTL_VERSION 114
33
34 /* Methods */
35 #define GET_DRIVER_INFO 0x1
36
37 #define MEGA_CMD_TIMEOUT 10
38
39 /* Feel free to fiddle with these.. max values are:
40 SGLIST 0..26
41 COMMANDS 0..253
42 CMDPERLUN 0..63
43 */
44
45 #define MAX_SGLIST 0x1A
46 #define MAX_COMMANDS 127
47 #define MAX_CMD_PER_LUN 63
48 #define MAX_FIRMWARE_STATUS 46
49
50 #define MAX_LOGICAL_DRIVES 8
51 #define MAX_CHANNEL 5
52 #define MAX_TARGET 15
53 #define MAX_PHYSICAL_DRIVES MAX_CHANNEL*MAX_TARGET
54
55 #define INQUIRY_DATA_SIZE 0x24
56 #define MAX_CDB_LEN 0x0A
57 #define MAX_REQ_SENSE_LEN 0x20
58
59 #define INTR_VALID 0x40
60
61 /* Direction Macros for MBOX Data direction */
62 #define TO_DEVICE 0x0
63 #define FROM_DEVICE 0x1
64 #define FROMTO_DEVICE 0x2
65
66 /* Mailbox commands */
67 #define MEGA_MBOXCMD_LREAD 0x01
68 #define MEGA_MBOXCMD_LWRITE 0x02
69 #define MEGA_MBOXCMD_LREAD64 0xA7
70 #define MEGA_MBOXCMD_LWRITE64 0xA8
71 #define MEGA_MBOXCMD_PASSTHRU 0x03
72 #define MEGA_MBOXCMD_EXTPASSTHRU 0xE3
73 #define MEGA_MBOXCMD_ADAPTERINQ 0x05
74
75
76 /* Offsets into Mailbox */
77 #define COMMAND_PORT 0x00
78 #define COMMAND_ID_PORT 0x01
79 #define SG_LIST_PORT0 0x08
80 #define SG_LIST_PORT1 0x09
81 #define SG_LIST_PORT2 0x0a
82 #define SG_LIST_PORT3 0x0b
83 #define SG_ELEMENT_PORT 0x0d
84 #define NO_FIRED_PORT 0x0f
85
86 /* I/O Port offsets */
87 #define I_CMD_PORT 0x00
88 #define I_ACK_PORT 0x00
89 #define I_TOGGLE_PORT 0x01
90 #define INTR_PORT 0x0a
91
92 #define MAILBOX_SIZE (sizeof(mega_mailbox)-16)
93 #define MBOX_BUSY_PORT 0x00
94 #define MBOX_PORT0 0x04
95 #define MBOX_PORT1 0x05
96 #define MBOX_PORT2 0x06
97 #define MBOX_PORT3 0x07
98 #define ENABLE_MBOX_REGION 0x0B
99
100 /* I/O Port Values */
101 #define ISSUE_BYTE 0x10
102 #define ACK_BYTE 0x08
103 #define ENABLE_INTR_BYTE 0xc0
104 #define DISABLE_INTR_BYTE 0x00
105 #define VALID_INTR_BYTE 0x40
106 #define MBOX_BUSY_BYTE 0x10
107 #define ENABLE_MBOX_BYTE 0x00
108
109 /* Setup some port macros here */
110 #define WRITE_MAILBOX(base,offset,value) *(base+offset)=value
111 #define READ_MAILBOX(base,offset) *(base+offset)
112
113 #define WRITE_PORT(base,offset,value) outb_p(value,base+offset)
114 #define READ_PORT(base,offset) inb_p(base+offset)
115
116 #define ISSUE_COMMAND(base) WRITE_PORT(base,I_CMD_PORT,ISSUE_BYTE)
117 #define CLEAR_INTR(base) WRITE_PORT(base,I_ACK_PORT,ACK_BYTE)
118 #define ENABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,ENABLE_INTR_BYTE)
119 #define DISABLE_INTR(base) WRITE_PORT(base,I_TOGGLE_PORT,DISABLE_INTR_BYTE)
120
121 /* Define AMI's PCI codes */
122 #ifndef PCI_VENDOR_ID_AMI
123 #define PCI_VENDOR_ID_AMI 0x101E
124 #endif
125
126 #ifndef PCI_DEVICE_ID_AMI_MEGARAID
127 #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
128 #endif
129
130 #ifndef PCI_DEVICE_ID_AMI_MEGARAID2
131 #define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060
132 #endif
133
134 #ifndef PCI_DEVICE_ID_AMI_MEGARAID3
135 #define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960
136 #endif
137
138 /* Special Adapter Commands */
139 #define FW_FIRE_WRITE 0x2C
140 #define FW_FIRE_FLASH 0x2D
141
142 #define FC_NEW_CONFIG 0xA1
143 #define DCMD_FC_CMD 0xA1
144 #define DCMD_FC_PROCEED 0x02
145 #define DCMD_DELETE_LOGDRV 0x03
146 #define DCMD_FC_READ_NVRAM_CONFIG 0x04
147 #define DCMD_FC_READ_NVRAM_CONFIG_64 0xC0
148 #define DCMD_FC_READ_FINAL_CONFIG 0x05
149 #define DCMD_GET_DISK_CONFIG 0x06
150 #define DCMD_GET_DISK_CONFIG_64 0xC2
151 #define DCMD_CHANGE_LDNO 0x07
152 #define DCMD_COMPACT_CONFIG 0x08
153 #define DCMD_DELETE_DRIVEGROUP 0x09
154 #define DCMD_GET_LOOPID_INFO 0x0A
155 #define DCMD_CHANGE_LOOPID 0x0B
156 #define DCMD_GET_NUM_SCSI_CHANS 0x0C
157 #define DCMD_WRITE_CONFIG 0x0D
158 #define DCMD_WRITE_CONFIG_64 0xC1
159
160 #define NC_SUBOP_PRODUCT_INFO 0x0E
161 #define NC_SUBOP_ENQUIRY3 0x0F
162 #define ENQ3_GET_SOLICITED_NOTIFY_ONLY 0x01
163 #define ENQ3_GET_SOLICITED_FULL 0x02
164 #define ENQ3_GET_UNSOLICITED 0x03
165
166 #define PCI_CONF_BASE_ADDR_OFFSET 0x10
167 #define PCI_CONF_IRQ_OFFSET 0x3c
168 #define PCI_CONF_AMISIG 0xa0
169 #define PCI_CONF_AMISIG64 0xa4
170
171 /* Sub-System Vendor ID sorted on alphabetical order*/
172 #define AMI_SUBSYS_ID 0x101E
173 #define DELL_SUBSYS_ID 0x1028
174 #define HP_SUBSYS_ID 0x103C
175
176 #define AMI_SIGNATURE 0x3344
177 #define AMI_SIGNATURE_471 0xCCCC
178 #define AMI_64BIT_SIGNATURE 0x0299
179
180 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) /*0x20100 */
181 #define MEGARAID \
182 { NULL, /* Next */\
183 NULL, /* Usage Count Pointer */\
184 NULL, /* proc Directory Entry */\
185 megaraid_proc_info, /* proc Info Function */\
186 "MegaRAID", /* Driver Name */\
187 megaraid_detect, /* Detect Host Adapter */\
188 megaraid_release, /* Release Host Adapter */\
189 megaraid_info, /* Driver Info Function */\
190 megaraid_command, /* Command Function */\
191 megaraid_queue, /* Queue Command Function */\
192 megaraid_abort, /* Abort Command Function */\
193 megaraid_reset, /* Reset Command Function */\
194 NULL, /* Slave Attach Function */\
195 megaraid_biosparam, /* Disk BIOS Parameters */\
196 MAX_COMMANDS, /* # of cmds that can be\
197 outstanding at any time */\
198 7, /* HBA Target ID */\
199 MAX_SGLIST, /* Scatter/Gather Table Size */\
200 MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
201 0, /* Present */\
202 0, /* Default Unchecked ISA DMA */\
203 ENABLE_CLUSTERING } /* Enable Clustering */
204 #else
205 #define MEGARAID \
206 {\
207 name: "MegaRAID", /* Driver Name */\
208 proc_info: megaraid_proc_info, /* /proc driver info */\
209 detect: megaraid_detect, /* Detect Host Adapter */\
210 release: megaraid_release, /* Release Host Adapter */\
211 info: megaraid_info, /* Driver Info Function */\
212 command: megaraid_command, /* Command Function */\
213 queuecommand: megaraid_queue, /* Queue Command Function */\
214 abort: megaraid_abort, /* Abort Command Function */\
215 reset: megaraid_reset, /* Reset Command Function */\
216 bios_param: megaraid_biosparam, /* Disk BIOS Parameters */\
217 can_queue: MAX_COMMANDS, /* Can Queue */\
218 this_id: 7, /* HBA Target ID */\
219 sg_tablesize: MAX_SGLIST, /* Scatter/Gather Table Size */\
220 cmd_per_lun: MAX_CMD_PER_LUN, /* SCSI Commands per LUN */\
221 present: 0, /* Present */\
222 unchecked_isa_dma: 0, /* Default Unchecked ISA DMA */\
223 use_clustering: ENABLE_CLUSTERING /* Enable Clustering */\
224 }
225 #endif
226
227 /***********************************************************************
228 * Structure Declarations for the Firmware supporting 40 Logical Drives
229 * and 256 Physical Drives.
230 ***********************************************************************/
231
232 #define FC_MAX_LOGICAL_DRIVES 40
233 #define FC_MAX_LOG_DEVICES FC_MAX_LOGICAL_DRIVES
234 #define FC_MAX_SPAN_DEPTH 8
235 #define FC_MAX_ROW_SIZE 32
236
237 #define FC_MAX_CHANNELS 16
238 #define FC_MAX_TARGETS_PER_CHANNEL 16
239 #define FC_MAX_PHYSICAL_DEVICES 256
240
241 /********************************************
242 * PRODUCT_INFO
243 ********************************************/
244
245 #define SIG_40LOG_32STR_8SPN 0x00282008
246
247 /*
248 * Utilities declare this strcture size as 1024 bytes. So more fields can
249 * be added in future.
250 */
251
252 struct MRaidProductInfo {
253 u32 DataSize; /* current size in bytes (not including resvd) */
254 u32 ConfigSignature;
255 /* Current value is 0x00282008
256 * 0x28=MAX_LOGICAL_DRIVES,
257 * 0x20=Number of stripes and
258 * 0x08=Number of spans */
259 u8 FwVer[16]; /* printable ASCI string */
260 u8 BiosVer[16]; /* printable ASCI string */
261 u8 ProductName[80]; /* printable ASCI string */
262
263 u8 MaxConcCmds; /* Max. concurrent commands supported */
264 u8 SCSIChanPresent; /* Number of SCSI Channels detected */
265 u8 FCLoopPresent; /* Number of Fibre Loops detected */
266 u8 memType; /* EDO, FPM, SDRAM etc */
267
268 u32 signature;
269 u16 DramSize; /* In terms of MB */
270 u16 subSystemID;
271
272 u16 subSystemVendorID;
273 u8 numNotifyCounters;
274 u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */
275 } __attribute__ ((packed));
276 typedef struct MRaidProductInfo megaRaidProductInfo;
277
278 /********************************************
279 * Standard ENQUIRY
280 ********************************************/
281 struct FC_ADP_INFO {
282 u8 MaxConcCmds; /* Max. concurrent commands supported. */
283 u8 RbldRate; /* Rebuild Rate. Varies from 0%-100% */
284 u8 MaxTargPerChan; /* Max. Targets supported per chan. */
285 u8 ChanPresent; /* No. of Chans present on this adapter. */
286 u8 FwVer[4]; /* Firmware version. */
287 u16 AgeOfFlash; /* No. of times FW has been downloaded. */
288 u8 ChipSetValue; /* Contents of 0xC0000832 */
289 u8 DramSize; /* In terms of MB */
290 u8 CacheFlushInterval; /* In terms of Seconds */
291 u8 BiosVersion[4];
292 u8 BoardType;
293 u8 sense_alert;
294 u8 write_config_count; /* Increase with evry configuration change */
295 u8 drive_inserted_count;/* Increase with every drive inserted */
296 u8 inserted_drive; /* Channel: Id of inserted drive */
297 u8 battery_status;
298 /*
299 BIT 0 : battery module missing
300 BIT 1 : VBAD
301 BIT 2 : temp high
302 BIT 3 : battery pack missing
303 BIT 4,5 : 00 - charge complete
304 01 - fast charge in prog
305 10 - fast charge fail
306 11 - undefined
307 BIt 6 : counter > 1000
308 Bit 7 : undefined
309 */
310 u8 dec_fault_bus_info; /* was resvd */
311 } __attribute__ ((packed));
312
313 struct FC_LDRV_INFO {
314 u8 NumLDrv; /* No. of Log. Drvs configured. */
315 u8 recon_state[FC_MAX_LOGICAL_DRIVES / 8];
316 /* bit field for State of reconstruct */
317 u16 LDrvOpStatus[FC_MAX_LOGICAL_DRIVES / 8];
318 /* bit field Status of Long Operations. */
319
320 u32 LDrvSize[FC_MAX_LOGICAL_DRIVES]; /* Size of each log. Drv. */
321 u8 LDrvProp[FC_MAX_LOGICAL_DRIVES];
322 u8 LDrvState[FC_MAX_LOGICAL_DRIVES]; /* State of Logical Drives. */
323 } __attribute__ ((packed));
324
325 #define PREVSTAT_MASK 0xf0
326 #define CURRSTAT_MASK 0x0f
327
328 struct FC_PDRV_INFO {
329 u8 PDrvState[FC_MAX_PHYSICAL_DEVICES]; /* State of Phys Drvs. */
330 } __attribute__ ((packed));
331
332 struct FC_AdapterInq {
333 struct FC_ADP_INFO AdpInfo;
334 struct FC_LDRV_INFO LogdrvInfo;
335 struct FC_PDRV_INFO PhysdrvInfo;
336 } __attribute__ ((packed));
337
338 typedef struct FC_AdapterInq mega_RAIDINQ_FC;
339
340 /********************************************
341 * NOTIFICATION
342 ********************************************/
343
344 #define MAX_NOTIFY_SIZE 0x80
345 #define CUR_NOTIFY_SIZE sizeof(struct MegaRAID_Notify)
346
347 /*
348 * Utilities declare this strcture size as ?? bytes. So more fields can
349 * be added in future.
350 */
351 struct MegaRAID_Notify {
352 u32 globalCounter; /* Any change increments this counter */
353
354 u8 paramCounter; /* Indicates any params changed */
355 u8 paramId; /* Param modified - defined below */
356 u16 paramVal; /* New val of last param modified */
357
358 u8 writeConfigCounter; /* write config occurred */
359 u8 writeConfigRsvd[3];
360
361 u8 ldrvOpCounter; /* Indicates ldrv op started/completed */
362 u8 ldrvOpId; /* ldrv num */
363 u8 ldrvOpCmd; /* ldrv operation - defined below */
364 u8 ldrvOpStatus; /* status of the operation */
365
366 u8 ldrvStateCounter; /* Indicates change of ldrv state */
367 u8 ldrvStateId; /* ldrv num */
368 u8 ldrvStateNew; /* New state */
369 u8 ldrvStateOld; /* old state */
370
371 u8 pdrvStateCounter; /* Indicates change of ldrv state */
372 u8 pdrvStateId; /* pdrv id */
373 u8 pdrvStateNew; /* New state */
374 u8 pdrvStateOld; /* old state */
375
376 u8 pdrvFmtCounter; /* Indicates pdrv format started/over */
377 u8 pdrvFmtId; /* pdrv id */
378 u8 pdrvFmtVal; /* format started/over */
379 u8 pdrvFmtRsvd;
380
381 u8 targXferCounter; /* Indicates SCSI-2 Xfer rate change */
382 u8 targXferId; /* pdrv Id */
383 u8 targXferVal; /* new Xfer params of last pdrv */
384 u8 targXferRsvd;
385
386 u8 fcLoopIdChgCounter; /* Indicates loopid changed */
387 u8 fcLoopIdPdrvId; /* pdrv id */
388 u8 fcLoopId0; /* loopid on fc loop 0 */
389 u8 fcLoopId1; /* loopid on fc loop 1 */
390
391 u8 fcLoopStateCounter; /* Indicates loop state changed */
392 u8 fcLoopState0; /* state of fc loop 0 */
393 u8 fcLoopState1; /* state of fc loop 1 */
394 u8 fcLoopStateRsvd;
395 } __attribute__ ((packed));
396
397 /********************************************
398 * PARAM IDs in Notify struct
399 ********************************************/
400 #define PARAM_RBLD_RATE 0x01
401 /*--------------------------------------
402 * Param val =
403 * byte 0: new rbld rate
404 *--------------------------------------*/
405 #define PARAM_CACHE_FLUSH_INTERVAL 0x02
406 /*--------------------------------------
407 * Param val =
408 * byte 0: new cache flush interval
409 *--------------------------------------*/
410 #define PARAM_SENSE_ALERT 0x03
411 /*--------------------------------------
412 * Param val =
413 * byte 0: last pdrv id causing chkcond
414 *--------------------------------------*/
415 #define PARAM_DRIVE_INSERTED 0x04
416 /*--------------------------------------
417 * Param val =
418 * byte 0: last pdrv id inserted
419 *--------------------------------------*/
420 #define PARAM_BATTERY_STATUS 0x05
421 /*--------------------------------------
422 * Param val =
423 * byte 0: battery status
424 *--------------------------------------*/
425
426 /********************************************
427 * Ldrv operation cmd in Notify struct
428 ********************************************/
429 #define LDRV_CMD_CHKCONSISTANCY 0x01
430 #define LDRV_CMD_INITIALIZE 0x02
431 #define LDRV_CMD_RECONSTRUCTION 0x03
432
433 /********************************************
434 * Ldrv operation status in Notify struct
435 ********************************************/
436 #define LDRV_OP_SUCCESS 0x00
437 #define LDRV_OP_FAILED 0x01
438 #define LDRV_OP_ABORTED 0x02
439 #define LDRV_OP_CORRECTED 0x03
440 #define LDRV_OP_STARTED 0x04
441
442 /********************************************
443 * Raid Logical drive states.
444 ********************************************/
445 #define RDRV_OFFLINE 0
446 #define RDRV_DEGRADED 1
447 #define RDRV_OPTIMAL 2
448 #define RDRV_DELETED 3
449
450 /*******************************************
451 * Physical drive states.
452 *******************************************/
453 #define PDRV_UNCNF 0
454 #define PDRV_ONLINE 3
455 #define PDRV_FAILED 4
456 #define PDRV_RBLD 5
457
458 /*******************************************
459 * Formal val in Notify struct
460 *******************************************/
461 #define PDRV_FMT_START 0x01
462 #define PDRV_FMT_OVER 0x02
463
464 /********************************************
465 * FC Loop State in Notify Struct
466 ********************************************/
467 #define ENQ_FCLOOP_FAILED 0
468 #define ENQ_FCLOOP_ACTIVE 1
469 #define ENQ_FCLOOP_TRANSIENT 2
470
471 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
472 #define M_RD_DMA_TYPE_NONE 0xFFFF
473 #define M_RD_PTHRU_WITH_BULK_DATA 0x0001
474 #define M_RD_PTHRU_WITH_SGLIST 0x0002
475 #define M_RD_BULK_DATA_ONLY 0x0004
476 #define M_RD_SGLIST_ONLY 0x0008
477 #define M_RD_EPTHRU_WITH_BULK_DATA 0x0010
478 #endif
479 /********************************************
480 * ENQUIRY3
481 ********************************************/
482 /*
483 * Utilities declare this strcture size as 1024 bytes. So more fields can
484 * be added in future.
485 */
486 struct MegaRAID_Enquiry3 {
487 u32 dataSize; /* current size in bytes (not including resvd) */
488
489 struct MegaRAID_Notify notify;
490
491 u8 notifyRsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
492
493 u8 rbldRate; /* Rebuild rate (0% - 100%) */
494 u8 cacheFlushInterval; /* In terms of Seconds */
495 u8 senseAlert;
496 u8 driveInsertedCount; /* drive insertion count */
497
498 u8 batteryStatus;
499 u8 numLDrv; /* No. of Log Drives configured */
500 u8 reconState[FC_MAX_LOGICAL_DRIVES / 8]; /* State of reconstruct */
501 u16 lDrvOpStatus[FC_MAX_LOGICAL_DRIVES / 8]; /* log. Drv Status */
502
503 u32 lDrvSize[FC_MAX_LOGICAL_DRIVES]; /* Size of each log. Drv */
504 u8 lDrvProp[FC_MAX_LOGICAL_DRIVES];
505 u8 lDrvState[FC_MAX_LOGICAL_DRIVES]; /* State of Logical Drives */
506 u8 pDrvState[FC_MAX_PHYSICAL_DEVICES]; /* State of Phys. Drvs. */
507 u16 physDrvFormat[FC_MAX_PHYSICAL_DEVICES / 16];
508
509 u8 targXfer[80]; /* phys device transfer rate */
510 u8 pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
511 } __attribute__ ((packed));
512 typedef struct MegaRAID_Enquiry3 mega_Enquiry3;
513
514 /* Structures */
515 typedef struct _mega_ADP_INFO {
516 u8 MaxConcCmds;
517 u8 RbldRate;
518 u8 MaxTargPerChan;
519 u8 ChanPresent;
520 u8 FwVer[4];
521 u16 AgeOfFlash;
522 u8 ChipSetValue;
523 u8 DramSize;
524 u8 CacheFlushInterval;
525 u8 BiosVer[4];
526 u8 resvd[7];
527 } mega_ADP_INFO;
528
529 typedef struct _mega_LDRV_INFO {
530 u8 NumLDrv;
531 u8 resvd[3];
532 u32 LDrvSize[MAX_LOGICAL_DRIVES];
533 u8 LDrvProp[MAX_LOGICAL_DRIVES];
534 u8 LDrvState[MAX_LOGICAL_DRIVES];
535 } mega_LDRV_INFO;
536
537 typedef struct _mega_PDRV_INFO {
538 u8 PDrvState[MAX_PHYSICAL_DRIVES];
539 u8 resvd;
540 } mega_PDRV_INFO;
541
542 /* RAID inquiry: Mailbox command 0x5*/
543 typedef struct _mega_RAIDINQ {
544 mega_ADP_INFO AdpInfo;
545 mega_LDRV_INFO LogdrvInfo;
546 mega_PDRV_INFO PhysdrvInfo;
547 } mega_RAIDINQ;
548
549 /* Passthrough command: Mailbox command 0x3*/
550 typedef struct mega_passthru {
551 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
552 u8 ars:1;
553 u8 reserved:3;
554 u8 islogical:1;
555 u8 logdrv; /* if islogical == 1 */
556 u8 channel; /* if islogical == 0 */
557 u8 target; /* if islogical == 0 */
558 u8 queuetag; /* unused */
559 u8 queueaction; /* unused */
560 u8 cdb[MAX_CDB_LEN];
561 u8 cdblen;
562 u8 reqsenselen;
563 u8 reqsensearea[MAX_REQ_SENSE_LEN];
564 u8 numsgelements;
565 u8 scsistatus;
566 u32 dataxferaddr;
567 u32 dataxferlen;
568 } mega_passthru;
569
570 /*
571 * Extended passthru: support CDB > 10 bytes
572 */
573 typedef struct {
574 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
575 u8 ars:1;
576 u8 rsvd1:1;
577 u8 cd_rom:1;
578 u8 rsvd2:1;
579 u8 islogical:1;
580
581 u8 logdrv; /* if islogical == 1 */
582 u8 channel; /* if islogical == 0 */
583 u8 target; /* if islogical == 0 */
584
585 u8 queuetag; /* unused */
586 u8 queueaction; /* unused */
587
588 u8 cdblen;
589 u8 rsvd3;
590 u8 cdb[16];
591
592 u8 numsgelements;
593 u8 status;
594 u8 reqsenselen;
595 u8 reqsensearea[MAX_REQ_SENSE_LEN];
596 u8 rsvd4;
597
598 u32 dataxferaddr;
599 u32 dataxferlen;
600 }mega_ext_passthru;
601
602 struct _mega_mailbox {
603 /* 0x0 */ u8 cmd;
604 /* 0x1 */ u8 cmdid;
605 /* 0x2 */ u16 numsectors;
606 /* 0x4 */ u32 lba;
607 /* 0x8 */ u32 xferaddr;
608 /* 0xC */ u8 logdrv;
609 /* 0xD */ u8 numsgelements;
610 /* 0xE */ u8 resvd;
611 /* 0xF */ u8 busy;
612 /* 0x10 */ u8 numstatus;
613 /* 0x11 */ u8 status;
614 /* 0x12 */ u8 completed[46];
615 volatile u8 mraid_poll;
616 volatile u8 mraid_ack;
617 u8 pad[16]; /* for alignment purposes */
618 } __attribute__ ((packed));
619 typedef struct _mega_mailbox mega_mailbox;
620
621 typedef struct {
622 u32 xferSegment_lo;
623 u32 xferSegment_hi;
624 mega_mailbox mailbox;
625 } mega_mailbox64;
626
627 typedef struct _mega_ioctl_mbox {
628 /* 0x0 */ u8 cmd;
629 /* 0x1 */ u8 cmdid;
630 /* 0x2 */ u8 channel;
631 /* 0x3 */ u8 param;
632 /* 0x4 */ u8 pad[4];
633 /* 0x8 */ u32 xferaddr;
634 /* 0xC */ u8 logdrv;
635 /* 0xD */ u8 numsgelements;
636 /* 0xE */ u8 resvd;
637 /* 0xF */ u8 busy;
638 /* 0x10 */ u8 numstatus;
639 /* 0x11 */ u8 status;
640 /* 0x12 */ u8 completed[46];
641 u8 mraid_poll;
642 u8 mraid_ack;
643 u8 malign[16];
644 } mega_ioctl_mbox;
645
646 typedef struct _mega_64sglist32 {
647 u64 address;
648 u32 length;
649 } __attribute__ ((packed)) mega_64sglist;
650
651 typedef struct _mega_sglist {
652 u32 address;
653 u32 length;
654 } mega_sglist;
655
656 /* Queued command data */
657 typedef struct _mega_scb mega_scb;
658
659 struct _mega_scb {
660 int idx;
661 u32 state;
662 u32 isrcount;
663 u8 mboxData[16];
664 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
665 u32 dma_type;
666 dma_addr_t dma_h_bulkdata; /*Dma handle for bulk data transfter */
667 u32 dma_direction; /*Dma direction */
668 dma_addr_t dma_h_sgdata; /*Dma handle for the sglist structure */
669 dma_addr_t dma_h_sglist[MAX_SGLIST]; /*Dma handle for all SGL elements */
670 u8 sglist_count;
671 dma_addr_t dma_sghandle64;
672 dma_addr_t dma_passthruhandle64;
673 dma_addr_t dma_ext_passthruhandle64;
674 dma_addr_t dma_bounce_buffer;
675 u8 *bounce_buffer;
676 #endif
677
678 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
679 mega_passthru *pthru;
680 mega_ext_passthru *epthru;
681 #else
682 mega_passthru pthru;
683 mega_ext_passthru epthru;
684 #endif
685
686 Scsi_Cmnd *SCpnt;
687 mega_sglist *sgList;
688 mega_64sglist *sg64List;
689 struct semaphore ioctl_sem;
690 void *buff_ptr;
691 u32 iDataSize;
692 mega_scb *next;
693 };
694
695 /* internal locking by the queue manipulting routines */
696 #define INTERNAL_LOCK 0
697 /* external locking by the queue manipulting routines */
698 #define EXTERNAL_LOCK 1
699 #define NO_LOCK 2
700 #define INTR_ENB 0 /* do not disable interrupt while manipulating */
701 #define INTR_DIS 1 /* disable interrupt while manipulating */
702
703 /* Per-controller data */
704 typedef struct _mega_host_config {
705 u8 numldrv;
706 u32 flag;
707
708 #ifdef __LP64__
709 u64 base;
710 #else
711 u32 base;
712 #endif
713
714 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
715 dma_addr_t dma_handle64, adjdmahandle64;
716 struct pci_dev *dev;
717 #endif
718
719 mega_scb *qFreeH;
720 mega_scb *qFreeT;
721 spinlock_t lock_free;
722
723 mega_scb *qPendingH;
724 mega_scb *qPendingT;
725 spinlock_t lock_pend;
726
727 Scsi_Cmnd *qCompletedH;
728 Scsi_Cmnd *qCompletedT;
729 spinlock_t lock_scsicmd;
730
731 u32 qFcnt;
732 u32 qPcnt;
733 u32 qCcnt;
734
735 unsigned long nReads[FC_MAX_LOGICAL_DRIVES];
736 unsigned long nReadBlocks[FC_MAX_LOGICAL_DRIVES];
737 unsigned long nWrites[FC_MAX_LOGICAL_DRIVES];
738 unsigned long nWriteBlocks[FC_MAX_LOGICAL_DRIVES];
739 unsigned long nInterrupts;
740 /* Host adapter parameters */
741 u8 fwVer[7];
742 u8 biosVer[7];
743
744 struct Scsi_Host *host;
745
746 volatile mega_mailbox64 *mbox64; /* ptr to beginning of 64-bit mailbox */
747 volatile mega_mailbox *mbox; /* ptr to beginning of standard mailbox */
748
749 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
750 /* ptr to beginning of standard mailbox */
751 volatile mega_mailbox64 *mailbox64ptr;
752 #else
753 volatile mega_mailbox64 mailbox64;
754 #endif
755
756 volatile u8 mega_buffer[2 * 1024L];
757 volatile megaRaidProductInfo productInfo;
758
759 u8 max_cmds;
760 mega_scb scbList[MAX_COMMANDS];
761
762 #define PROCBUFSIZE 4096
763 char procbuf[PROCBUFSIZE];
764 int procidx;
765 struct proc_dir_entry *controller_proc_dir_entry;
766 struct proc_dir_entry *proc_read, *proc_stat, *proc_status, *proc_mbox;
767 int support_ext_cdb;
768 int boot_ldrv_enabled;
769 int boot_ldrv;
770 } mega_host_config;
771
772 typedef struct _driver_info {
773 int size;
774 ulong version;
775 } mega_driver_info;
776
777 /*
778 * User ioctl structure.
779 * This structure will be used for Traditional Method ioctl interface
780 * commands (M_RD_IOCTL_CMD),Alternate Buffer Method (M_RD_IOCTL_CMD_NEW)
781 * ioctl commands and the Driver ioctls(M_RD_DRIVER_IOCTL_INTERFACE).
782 * The Driver ioctl interface handles the commands at
783 * the driver level, without being sent to the card.
784 */
785 #define MEGADEVIOC 0x84
786
787 /* system call imposed limit. Change accordingly */
788 #define IOCTL_MAX_DATALEN 4096
789
790 #pragma pack(1)
791 struct uioctl_t {
792 u32 inlen;
793 u32 outlen;
794 union {
795 u8 fca[16];
796 struct {
797 u8 opcode;
798 u8 subopcode;
799 u16 adapno;
800 #if BITS_PER_LONG == 32
801 u8 *buffer;
802 u8 pad[4];
803 #endif
804 #if BITS_PER_LONG == 64
805 u8 *buffer;
806 #endif
807 u32 length;
808 } fcs;
809 } ui;
810 u8 mbox[18]; /* 16 bytes + 2 status bytes */
811 mega_passthru pthru;
812 #if BITS_PER_LONG == 32
813 char *data; /* buffer <= 4096 for 0x80 commands */
814 char pad[4];
815 #endif
816 #if BITS_PER_LONG == 64
817 char *data;
818 #endif
819 };
820 #pragma pack()
821
822 /*
823 * struct mcontroller is used to pass information about the controllers in the
824 * system. Its upto the application how to use the information. We are passing
825 * as much info about the cards as possible and useful. Before issuing the
826 * call to find information about the cards, the applicaiton needs to issue a
827 * ioctl first to find out the number of controllers in the system.
828 */
829 #define MAX_CONTROLLERS 32
830
831 struct mcontroller {
832 u64 base;
833 u8 irq;
834 u8 numldrv;
835 u8 pcibus;
836 u16 pcidev;
837 u8 pcifun;
838 u16 pciid;
839 u16 pcivendor;
840 u8 pcislot;
841 u32 uid;
842 };
843
844 struct mbox_passthru {
845 u8 cmd;
846 u8 cmdid;
847 u16 pad1;
848 u32 pad2;
849 u32 dataxferaddr;
850 u8 pad3;
851 u8 pad4;
852 u8 rsvd;
853 u8 mboxbusy;
854 u8 nstatus;
855 u8 status;
856 };
857
858 /*
859 * Defines for Driver IOCTL interface, Op-code:M_RD_DRIVER_IOCTL_INTERFACE
860 */
861 #define MEGAIOC_MAGIC 'm'
862 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0) /* Mega IOCTL command */
863
864 #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
865 #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
866 #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
867 #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
868 #define GETADAP(mkadap) ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
869
870 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) /*0x20300 */
871 extern struct proc_dir_entry proc_scsi_megaraid;
872 #endif
873
874 /* For Host Re-Ordering */
875 #define MAX_CONTROLLERS 32
876
877 struct mega_hbas {
878 int is_bios_enabled;
879 mega_host_config *hostdata_addr;
880 };
881
882 #define IS_BIOS_ENABLED 0x62
883 #define GET_BIOS 0x01
884 #define CHNL_CLASS 0xA9
885 #define GET_CHNL_CLASS 0x00
886 #define SET_CHNL_CLASS 0x01
887 #define CH_RAID 0x01
888 #define CH_SCSI 0x00
889
890
891 #define BIOS_PVT_DATA 0x40
892 #define GET_BIOS_PVT_DATA 0x00
893
894 #pragma pack(1)
895 struct private_bios_data {
896 u8 geometry:4; /*
897 * bits 0-3 - BIOS geometry
898 * 0x0001 - 1GB
899 * 0x0010 - 2GB
900 * 0x1000 - 8GB
901 * Others values are invalid
902 */
903 u8 unused:4; /* bits 4-7 are unused */
904 u8 boot_ldrv; /*
905 * logical drive set as boot drive
906 * 0..7 - for 8LD cards
907 * 0..39 - for 40LD cards
908 */
909 u8 rsvd[12];
910 u16 cksum; /* 0-(sum of first 13 bytes of this structure) */
911 };
912 #pragma pack()
913
914
915 /*================================================================
916 *
917 * Function prototypes
918 *
919 *================================================================
920 */
921 const char *megaraid_info (struct Scsi_Host *);
922 int megaraid_detect (Scsi_Host_Template *);
923 int megaraid_release (struct Scsi_Host *);
924 int megaraid_command (Scsi_Cmnd *);
925 int megaraid_abort (Scsi_Cmnd *);
926 int megaraid_reset (Scsi_Cmnd *, unsigned int);
927 int megaraid_queue (Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
928 int megaraid_biosparam (Disk *, kdev_t, int *);
929 int megaraid_proc_info (char *buffer, char **start, off_t offset,
930 int length, int hostno, int inout);
931
932 static int megaIssueCmd (mega_host_config * megaCfg, u_char * mboxData,
933 mega_scb * scb, int intr);
934 static int mega_build_sglist (mega_host_config * megaCfg, mega_scb * scb,
935 u32 * buffer, u32 * length);
936 static int mega_busyWaitMbox (mega_host_config *);
937 static int mega_runpendq (mega_host_config *);
938 static void mega_rundoneq (mega_host_config *);
939 static void mega_cmd_done (mega_host_config *, mega_scb *, int);
940 static inline void mega_freeSgList (mega_host_config * megaCfg);
941 static void mega_Convert8ldTo40ld (mega_RAIDINQ * inquiry,
942 mega_Enquiry3 * enquiry3,
943 megaRaidProductInfo * productInfo);
944
945 static int megaraid_reboot_notify (struct notifier_block *,
946 unsigned long, void *);
947 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
948 static mega_scb *mega_ioctl (mega_host_config * megaCfg, Scsi_Cmnd * SCpnt);
949 static void mega_build_kernel_sg (char *barea, ulong xfersize, mega_scb * pScb,
950 mega_ioctl_mbox * mbox);
951 #endif
952
953 static int megadev_open (struct inode *, struct file *);
954 static int megadev_ioctl_entry (struct inode *, struct file *,
955 unsigned int, unsigned long);
956 static int megadev_ioctl (struct inode *, struct file *,
957 unsigned int, unsigned long);
958 static mega_scb *megadev_doioctl (mega_host_config *, Scsi_Cmnd *);
959 static int megadev_close (struct inode *, struct file *);
960 static void megadev_ioctl_done (Scsi_Cmnd *);
961 static int mega_init_scb (mega_host_config *);
962 static void enq_scb_freelist (mega_host_config *, mega_scb *,
963 int lock, int intr);
964
965 static int mega_is_bios_enabled (mega_host_config *);
966 static void mega_reorder_hosts (void);
967 static void mega_swap_hosts (struct Scsi_Host *, struct Scsi_Host *);
968
969 static void mega_create_proc_entry (int index, struct proc_dir_entry *);
970 static int mega_support_ext_cdb(mega_host_config *);
971 static mega_passthru* mega_prepare_passthru(mega_host_config *, mega_scb *,
972 Scsi_Cmnd *);
973 static mega_ext_passthru* mega_prepare_extpassthru(mega_host_config *,
974 mega_scb *, Scsi_Cmnd *);
975 static void mega_enum_raid_scsi(mega_host_config *);
976 static int mega_partsize(Disk *, kdev_t, int *);
977 static void mega_get_boot_ldrv(mega_host_config *);
978
979 #endif
980
981 /* vi: set ts=4: */
982