megaraid.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:29k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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