1 #ifndef __MEGARAID_H__ 2 #define __MEGARAID_H__ 3 4 #ifndef LINUX_VERSION_CODE 5 #include <linux/version.h> 6 #endif 7 8 /* 9 * For state flag. Do not use LSB(8 bits) which are 10 * reserved for storing info about channels. 11 */ 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 19 20 #define SCB_FREE 0x0 21 #define SCB_ACTIVE 0x1 22 #define SCB_WAITQ 0x2 23 #define SCB_ISSUED 0x3 24 #define SCB_COMPLETE 0x4 25 #define SCB_ABORTED 0x5 26 #define SCB_RESET 0x6 27 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 32 33 #define MEGARAID_VERSION "v1.18k (Release Date: Thu Aug 28 10:05:11 EDT 2003)\n" 34 35 36 #define MEGARAID_IOCTL_VERSION 114 37 38 /* Methods */ 39 #define GET_DRIVER_INFO 0x1 40 41 #define MEGA_CMD_TIMEOUT 10 42 43 /* Feel free to fiddle with these.. max values are: 44 SGLIST 0..26 45 COMMANDS 0..253 46 CMDPERLUN 0..63 47 */ 48 49 #define MAX_SGLIST 0x1A 50 #define MAX_COMMANDS 127 51 #define MAX_CMD_PER_LUN 63 52 #define MAX_FIRMWARE_STATUS 46 53 54 #define MAX_LOGICAL_DRIVES 8 55 #define MAX_CHANNEL 5 56 #define MAX_TARGET 15 57 #define MAX_PHYSICAL_DRIVES MAX_CHANNEL*MAX_TARGET 58 59 #define INQUIRY_DATA_SIZE 0x24 60 #define MAX_CDB_LEN 0x0A 61 #define MAX_REQ_SENSE_LEN 0x20 62 63 #define INTR_VALID 0x40 64 65 /* Direction Macros for MBOX Data direction */ 66 #define TO_DEVICE 0x0 67 #define FROM_DEVICE 0x1 68 #define FROMTO_DEVICE 0x2 69 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 79 80 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 90 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 96 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 104 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 113 114 /* Setup some port macros here */ 115 #define WRITE_MAILBOX(base,offset,value) *(base+offset)=value 116 #define READ_MAILBOX(base,offset) *(base+offset) 117 118 #define WRITE_PORT(base,offset,value) outb_p(value,base+offset) 119 #define READ_PORT(base,offset) inb_p(base+offset) 120 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) 125 126 #ifndef PCI_VENDOR_ID_LSI_LOGIC 127 #define PCI_VENDOR_ID_LSI_LOGIC 0x1000 128 #endif 129 130 /* Define AMI's PCI codes */ 131 #ifndef PCI_VENDOR_ID_AMI 132 #define PCI_VENDOR_ID_AMI 0x101E 133 #endif 134 135 #ifndef PCI_DEVICE_ID_AMI_MEGARAID 136 #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010 137 #endif 138 139 #ifndef PCI_DEVICE_ID_AMI_MEGARAID2 140 #define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060 141 #endif 142 143 #ifndef PCI_DEVICE_ID_AMI_MEGARAID3 144 #define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960 145 #endif 146 147 #define PCI_VENDOR_ID_DISCOVERY 0x1028 148 #define PCI_DEVICE_ID_DISCOVERY 0x000E 149 150 #define PCI_VENDOR_ID_PERC4_DI_YSTONE 0x1028 151 #define PCI_DEVICE_ID_PERC4_DI_YSTONE 0x000F 152 153 #define PCI_VENDOR_ID_PERC4_QC_VERDE 0x1000 154 #define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407 155 156 /* Special Adapter Commands */ 157 #define FW_FIRE_WRITE 0x2C 158 #define FW_FIRE_FLASH 0x2D 159 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 177 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 183 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 188 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 195 196 #define AMI_SIGNATURE 0x3344 197 #define AMI_SIGNATURE_471 0xCCCC 198 #define AMI_64BIT_SIGNATURE 0x0299 199 200 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) /*0x20100 */ 201 #define MEGARAID \ 202 { NULL, /* Next */\ 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 */\ 221 0, /* Present */\ 222 0, /* Default Unchecked ISA DMA */\ 223 ENABLE_CLUSTERING } /* Enable Clustering */ 224 #else 225 #define MEGARAID \ 226 {\ 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 */ \ 245 } 246 #endif 247 248 /*********************************************************************** 249 * Structure Declarations for the Firmware supporting 40 Logical Drives 250 * and 256 Physical Drives. 251 ***********************************************************************/ 252 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 257 258 #define FC_MAX_CHANNELS 16 259 #define FC_MAX_TARGETS_PER_CHANNEL 16 260 #define FC_MAX_PHYSICAL_DEVICES 256 261 262 /******************************************** 263 * PRODUCT_INFO 264 ********************************************/ 265 266 #define SIG_40LOG_32STR_8SPN 0x00282008 267 268 /* 269 * Utilities declare this strcture size as 1024 bytes. So more fields can 270 * be added in future. 271 */ 272 273 struct MRaidProductInfo { 274 u32 DataSize; /* current size in bytes (not including resvd) */ 275 u32 ConfigSignature; 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 */ 283 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 */ 288 289 u32 signature; 290 u16 DramSize; /* In terms of MB */ 291 u16 subSystemID; 292 293 u16 subSystemVendorID; 294 u8 numNotifyCounters; 295 u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */ 296 } __attribute__ ((packed)); 297 typedef struct MRaidProductInfo megaRaidProductInfo; 298 299 /******************************************** 300 * Standard ENQUIRY 301 ********************************************/ 302 struct FC_ADP_INFO { 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 */ 312 u8 BiosVersion[4]; 313 u8 BoardType; 314 u8 sense_alert; 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 */ 318 u8 battery_status; 319 /* 320 BIT 0 : battery module missing 321 BIT 1 : VBAD 322 BIT 2 : temp high 323 BIT 3 : battery pack missing 324 BIT 4,5 : 00 - charge complete 325 01 - fast charge in prog 326 10 - fast charge fail 327 11 - undefined 328 BIt 6 : counter > 1000 329 Bit 7 : undefined 330 */ 331 u8 dec_fault_bus_info; /* was resvd */ 332 } __attribute__ ((packed)); 333 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. */ 340 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)); 345 346 #define PREVSTAT_MASK 0xf0 347 #define CURRSTAT_MASK 0x0f 348 349 struct FC_PDRV_INFO { 350 u8 PDrvState[FC_MAX_PHYSICAL_DEVICES]; /* State of Phys Drvs. */ 351 } __attribute__ ((packed)); 352 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)); 358 359 typedef struct FC_AdapterInq mega_RAIDINQ_FC; 360 361 /******************************************** 362 * NOTIFICATION 363 ********************************************/ 364 365 #define MAX_NOTIFY_SIZE 0x80 366 #define CUR_NOTIFY_SIZE sizeof(struct MegaRAID_Notify) 367 368 /* 369 * Utilities declare this strcture size as ?? bytes. So more fields can 370 * be added in future. 371 */ 372 struct MegaRAID_Notify { 373 u32 globalCounter; /* Any change increments this counter */ 374 375 u8 paramCounter; /* Indicates any params changed */ 376 u8 paramId; /* Param modified - defined below */ 377 u16 paramVal; /* New val of last param modified */ 378 379 u8 writeConfigCounter; /* write config occurred */ 380 u8 writeConfigRsvd[3]; 381 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 */ 386 387 u8 ldrvStateCounter; /* Indicates change of ldrv state */ 388 u8 ldrvStateId; /* ldrv num */ 389 u8 ldrvStateNew; /* New state */ 390 u8 ldrvStateOld; /* old state */ 391 392 u8 pdrvStateCounter; /* Indicates change of ldrv state */ 393 u8 pdrvStateId; /* pdrv id */ 394 u8 pdrvStateNew; /* New state */ 395 u8 pdrvStateOld; /* old state */ 396 397 u8 pdrvFmtCounter; /* Indicates pdrv format started/over */ 398 u8 pdrvFmtId; /* pdrv id */ 399 u8 pdrvFmtVal; /* format started/over */ 400 u8 pdrvFmtRsvd; 401 402 u8 targXferCounter; /* Indicates SCSI-2 Xfer rate change */ 403 u8 targXferId; /* pdrv Id */ 404 u8 targXferVal; /* new Xfer params of last pdrv */ 405 u8 targXferRsvd; 406 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 */ 411 412 u8 fcLoopStateCounter; /* Indicates loop state changed */ 413 u8 fcLoopState0; /* state of fc loop 0 */ 414 u8 fcLoopState1; /* state of fc loop 1 */ 415 u8 fcLoopStateRsvd; 416 } __attribute__ ((packed)); 417 418 /******************************************** 419 * PARAM IDs in Notify struct 420 ********************************************/ 421 #define PARAM_RBLD_RATE 0x01 422 /*-------------------------------------- 423 * Param val = 424 * byte 0: new rbld rate 425 *--------------------------------------*/ 426 #define PARAM_CACHE_FLUSH_INTERVAL 0x02 427 /*-------------------------------------- 428 * Param val = 429 * byte 0: new cache flush interval 430 *--------------------------------------*/ 431 #define PARAM_SENSE_ALERT 0x03 432 /*-------------------------------------- 433 * Param val = 434 * byte 0: last pdrv id causing chkcond 435 *--------------------------------------*/ 436 #define PARAM_DRIVE_INSERTED 0x04 437 /*-------------------------------------- 438 * Param val = 439 * byte 0: last pdrv id inserted 440 *--------------------------------------*/ 441 #define PARAM_BATTERY_STATUS 0x05 442 /*-------------------------------------- 443 * Param val = 444 * byte 0: battery status 445 *--------------------------------------*/ 446 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 453 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 462 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 470 471 /******************************************* 472 * Physical drive states. 473 *******************************************/ 474 #define PDRV_UNCNF 0 475 #define PDRV_ONLINE 3 476 #define PDRV_FAILED 4 477 #define PDRV_RBLD 5 478 479 /******************************************* 480 * Formal val in Notify struct 481 *******************************************/ 482 #define PDRV_FMT_START 0x01 483 #define PDRV_FMT_OVER 0x02 484 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 491 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 499 #endif 500 /******************************************** 501 * ENQUIRY3 502 ********************************************/ 503 /* 504 * Utilities declare this strcture size as 1024 bytes. So more fields can 505 * be added in future. 506 */ 507 struct MegaRAID_Enquiry3 { 508 u32 dataSize; /* current size in bytes (not including resvd) */ 509 510 struct MegaRAID_Notify notify; 511 512 u8 notifyRsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE]; 513 514 u8 rbldRate; /* Rebuild rate (0% - 100%) */ 515 u8 cacheFlushInterval; /* In terms of Seconds */ 516 u8 senseAlert; 517 u8 driveInsertedCount; /* drive insertion count */ 518 519 u8 batteryStatus; 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 */ 523 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]; 529 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; 534 535 /* Structures */ 536 typedef struct _mega_ADP_INFO { 537 u8 MaxConcCmds; 538 u8 RbldRate; 539 u8 MaxTargPerChan; 540 u8 ChanPresent; 541 u8 FwVer[4]; 542 u16 AgeOfFlash; 543 u8 ChipSetValue; 544 u8 DramSize; 545 u8 CacheFlushInterval; 546 u8 BiosVer[4]; 547 u8 resvd[7]; 548 } mega_ADP_INFO; 549 550 typedef struct _mega_LDRV_INFO { 551 u8 NumLDrv; 552 u8 resvd[3]; 553 u32 LDrvSize[MAX_LOGICAL_DRIVES]; 554 u8 LDrvProp[MAX_LOGICAL_DRIVES]; 555 u8 LDrvState[MAX_LOGICAL_DRIVES]; 556 } mega_LDRV_INFO; 557 558 typedef struct _mega_PDRV_INFO { 559 u8 PDrvState[MAX_PHYSICAL_DRIVES]; 560 u8 resvd; 561 } mega_PDRV_INFO; 562 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; 568 } mega_RAIDINQ; 569 570 /* Passthrough command: Mailbox command 0x3*/ 571 typedef struct mega_passthru { 572 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */ 573 u8 ars:1; 574 u8 reserved:3; 575 u8 islogical:1; 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 */ 581 u8 cdb[MAX_CDB_LEN]; 582 u8 cdblen; 583 u8 reqsenselen; 584 u8 reqsensearea[MAX_REQ_SENSE_LEN]; 585 u8 numsgelements; 586 u8 scsistatus; 587 u32 dataxferaddr; 588 u32 dataxferlen; 589 } mega_passthru; 590 591 /* 592 * Extended passthru: support CDB > 10 bytes 593 */ 594 typedef struct { 595 u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */ 596 u8 ars:1; 597 u8 rsvd1:1; 598 u8 cd_rom:1; 599 u8 rsvd2:1; 600 u8 islogical:1; 601 602 u8 logdrv; /* if islogical == 1 */ 603 u8 channel; /* if islogical == 0 */ 604 u8 target; /* if islogical == 0 */ 605 606 u8 queuetag; /* unused */ 607 u8 queueaction; /* unused */ 608 609 u8 cdblen; 610 u8 rsvd3; 611 u8 cdb[16]; 612 613 u8 numsgelements; 614 u8 status; 615 u8 reqsenselen; 616 u8 reqsensearea[MAX_REQ_SENSE_LEN]; 617 u8 rsvd4; 618 619 u32 dataxferaddr; 620 u32 dataxferlen; 621 }mega_ext_passthru; 622 623 struct _mega_mailbox { 624 /* 0x0 */ u8 cmd; 625 /* 0x1 */ u8 cmdid; 626 /* 0x2 */ u16 numsectors; 627 /* 0x4 */ u32 lba; 628 /* 0x8 */ u32 xferaddr; 629 /* 0xC */ u8 logdrv; 630 /* 0xD */ u8 numsgelements; 631 /* 0xE */ u8 resvd; 632 /* 0xF */ u8 busy; 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; 641 642 typedef struct { 643 u32 xferSegment_lo; 644 u32 xferSegment_hi; 645 mega_mailbox mailbox; 646 } mega_mailbox64; 647 648 typedef struct _mega_ioctl_mbox { 649 /* 0x0 */ u8 cmd; 650 /* 0x1 */ u8 cmdid; 651 /* 0x2 */ u8 channel; 652 /* 0x3 */ u8 param; 653 /* 0x4 */ u8 pad[4]; 654 /* 0x8 */ u32 xferaddr; 655 /* 0xC */ u8 logdrv; 656 /* 0xD */ u8 numsgelements; 657 /* 0xE */ u8 resvd; 658 /* 0xF */ u8 busy; 659 /* 0x10 */ u8 numstatus; 660 /* 0x11 */ u8 status; 661 /* 0x12 */ u8 completed[46]; 662 u8 mraid_poll; 663 u8 mraid_ack; 664 u8 malign[16]; 665 } mega_ioctl_mbox; 666 667 typedef struct _mega_64sglist32 { 668 u64 address; 669 u32 length; 670 } __attribute__ ((packed)) mega_64sglist; 671 672 typedef struct _mega_sglist { 673 u32 address; 674 u32 length; 675 } mega_sglist; 676 677 /* Queued command data */ 678 typedef struct _mega_scb mega_scb; 679 680 struct _mega_scb { 681 int idx; 682 u32 state; 683 u32 isrcount; 684 u8 mboxData[16]; 685 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) 686 u32 dma_type; 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 */ 691 u8 sglist_count; 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; 696 u8 *bounce_buffer; 697 #endif 698 699 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) 700 mega_passthru *pthru; 701 mega_ext_passthru *epthru; 702 #else 703 mega_passthru pthru; 704 mega_ext_passthru epthru; 705 #endif 706 707 Scsi_Cmnd *SCpnt; 708 mega_sglist *sgList; 709 mega_64sglist *sg64List; 710 struct semaphore ioctl_sem; 711 void *buff_ptr; 712 u32 iDataSize; 713 mega_scb *next; 714 }; 715 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 720 #define NO_LOCK 2 721 #define INTR_ENB 0 /* do not disable interrupt while manipulating */ 722 #define INTR_DIS 1 /* disable interrupt while manipulating */ 723 724 #define NVIRT_CHAN 4 /* # of virtual channels to represent 60 logical 725 drives */ 726 727 /* Per-controller data */ 728 typedef struct _mega_host_config { 729 u8 numldrv; 730 u32 flag; 731 732 #ifdef __LP64__ 733 u64 base; 734 #else 735 u32 base; 736 #endif 737 738 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) 739 dma_addr_t dma_handle64, adjdmahandle64; 740 struct pci_dev *dev; 741 #endif 742 743 mega_scb *qFreeH; 744 mega_scb *qFreeT; 745 spinlock_t lock_free; 746 747 mega_scb *qPendingH; 748 mega_scb *qPendingT; 749 spinlock_t lock_pend; 750 751 Scsi_Cmnd *qCompletedH; 752 Scsi_Cmnd *qCompletedT; 753 spinlock_t lock_scsicmd; 754 755 u32 qFcnt; 756 u32 qPcnt; 757 u32 qCcnt; 758 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 */ 765 u8 fwVer[7]; 766 u8 biosVer[7]; 767 768 struct Scsi_Host *host; 769 770 volatile mega_mailbox64 *mbox64; /* ptr to beginning of 64-bit mailbox */ 771 volatile mega_mailbox *mbox; /* ptr to beginning of standard mailbox */ 772 773 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) 774 /* ptr to beginning of standard mailbox */ 775 volatile mega_mailbox64 *mailbox64ptr; 776 #else 777 volatile mega_mailbox64 mailbox64; 778 #endif 779 780 volatile u8 mega_buffer[2 * 1024L]; 781 volatile megaRaidProductInfo productInfo; 782 783 u8 max_cmds; 784 mega_scb scbList[MAX_COMMANDS]; 785 786 #define PROCBUFSIZE 4096 787 char procbuf[PROCBUFSIZE]; 788 int procidx; 789 struct proc_dir_entry *controller_proc_dir_entry; 790 struct proc_dir_entry *proc_read, *proc_stat, *proc_status, *proc_mbox; 791 int support_ext_cdb; 792 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 */ 798 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 */ 805 806 mega_scb *int_qh; /* commands are queued in the internal queue */ 807 mega_scb *int_qt; /* while the hba is quiescent */ 808 int int_qlen; 809 char logdrv_chan[MAX_CHANNEL+NVIRT_CHAN]; /* logical drive are on 810 what channels. */ 811 int mega_ch_class; 812 } mega_host_config; 813 814 typedef struct _driver_info { 815 int size; 816 ulong version; 817 } mega_driver_info; 818 819 /* 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. 826 */ 827 #define MEGADEVIOC 0x84 828 829 /* system call imposed limit. Change accordingly */ 830 #define IOCTL_MAX_DATALEN 4096 831 832 #pragma pack(1) 833 struct uioctl_t { 834 u32 inlen; 835 u32 outlen; 836 union { 837 u8 fca[16]; 838 struct { 839 u8 opcode; 840 u8 subopcode; 841 u16 adapno; 842 #if BITS_PER_LONG == 32 843 u8 *buffer; 844 u8 pad[4]; 845 #endif 846 #if BITS_PER_LONG == 64 847 u8 *buffer; 848 #endif 849 u32 length; 850 } fcs; 851 } ui; 852 u8 mbox[18]; /* 16 bytes + 2 status bytes */ 853 mega_passthru pthru; 854 #if BITS_PER_LONG == 32 855 char *data; /* buffer <= 4096 for 0x80 commands */ 856 char pad[4]; 857 #endif 858 #if BITS_PER_LONG == 64 859 char *data; 860 #endif 861 }; 862 #pragma pack() 863 864 /* 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. 870 */ 871 #define MAX_CONTROLLERS 32 872 873 struct mcontroller { 874 u64 base; 875 u8 irq; 876 u8 numldrv; 877 u8 pcibus; 878 u16 pcidev; 879 u8 pcifun; 880 u16 pciid; 881 u16 pcivendor; 882 u8 pcislot; 883 u32 uid; 884 }; 885 886 struct mbox_passthru { 887 u8 cmd; 888 u8 cmdid; 889 u16 pad1; 890 u32 pad2; 891 u32 dataxferaddr; 892 u8 pad3; 893 u8 pad4; 894 u8 rsvd; 895 u8 mboxbusy; 896 u8 nstatus; 897 u8 status; 898 }; 899 900 /* 901 * Defines for Driver IOCTL interface, Op-code:M_RD_DRIVER_IOCTL_INTERFACE 902 */ 903 #define MEGAIOC_MAGIC 'm' 904 905 /* Mega IOCTL command */ 906 #define MEGAIOCCMD _IOWR(MEGAIOC_MAGIC, 0, struct uioctl_t) 907 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 ) 913 914 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) /*0x20300 */ 915 extern struct proc_dir_entry proc_scsi_megaraid; 916 #endif 917 918 /* For Host Re-Ordering */ 919 #define MAX_CONTROLLERS 32 920 921 struct mega_hbas { 922 int is_bios_enabled; 923 mega_host_config *hostdata_addr; 924 }; 925 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 931 #define CH_RAID 0x01 932 #define CH_SCSI 0x00 933 934 935 #define BIOS_PVT_DATA 0x40 936 #define GET_BIOS_PVT_DATA 0x00 937 938 #pragma pack(1) 939 struct private_bios_data { 940 u8 geometry:4; /* 941 * bits 0-3 - BIOS geometry 942 * 0x0001 - 1GB 943 * 0x0010 - 2GB 944 * 0x1000 - 8GB 945 * Others values are invalid 946 */ 947 u8 unused:4; /* bits 4-7 are unused */ 948 u8 boot_drv; /* 949 * logical/physical drive set as boot drive 950 * 0..7 - for 8LD cards 951 * 0..39 - for 40LD cards 952 */ 953 u8 rsvd[12]; 954 u16 cksum; /* 0-(sum of first 13 bytes of this structure) */ 955 }; 956 #pragma pack() 957 958 /* 959 * Command for random deletion of logical drives 960 */ 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 */ 965 966 /*================================================================ 967 * 968 * Function prototypes 969 * 970 *================================================================ 971 */ 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); 982 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); 995 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); 1002 #endif 1003 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); 1015 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 *); 1019 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); 1033 1034 #endif 1035 1036 /* vi: set ts=4: */ 1037