megaraid.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. #ifndef __MEGARAID_H__
  2. #define __MEGARAID_H__
  3. #include <linux/spinlock.h>
  4. #define MEGARAID_VERSION \
  5. "v2.00.3 (Release Date: Wed Feb 19 08:51:30 EST 2003)\n"
  6. /*
  7. * Driver features - change the values to enable or disable features in the
  8. * driver.
  9. */
  10. /*
  11. * Comand coalescing - This feature allows the driver to be able to combine
  12. * two or more commands and issue as one command in order to boost I/O
  13. * performance. Useful if the nature of the I/O is sequential. It is not very
  14. * useful for random natured I/Os.
  15. */
  16. #define MEGA_HAVE_COALESCING 0
  17. /*
  18. * Clustering support - Set this flag if you are planning to use the
  19. * clustering services provided by the megaraid controllers and planning to
  20. * setup a cluster
  21. */
  22. #define MEGA_HAVE_CLUSTERING 1
  23. /*
  24. * Driver statistics - Set this flag if you are interested in statics about
  25. * number of I/O completed on each logical drive and how many interrupts
  26. * generated. If enabled, this information is available through /proc
  27. * interface and through the private ioctl. Setting this flag has a
  28. * performance penalty.
  29. */
  30. #define MEGA_HAVE_STATS 0
  31. /*
  32. * Enhanced /proc interface - This feature will allow you to have a more
  33. * detailed /proc interface for megaraid driver. E.g., a real time update of
  34. * the status of the logical drives, battery status, physical drives etc.
  35. */
  36. #define MEGA_HAVE_ENH_PROC 1
  37. #define MAX_DEV_TYPE 32
  38. #ifndef PCI_VENDOR_ID_LSI_LOGIC
  39. #define PCI_VENDOR_ID_LSI_LOGIC 0x1000
  40. #endif
  41. #ifndef PCI_VENDOR_ID_AMI
  42. #define PCI_VENDOR_ID_AMI 0x101E
  43. #endif
  44. #ifndef PCI_VENDOR_ID_DELL
  45. #define PCI_VENDOR_ID_DELL 0x1028
  46. #endif
  47. #ifndef PCI_VENDOR_ID_INTEL
  48. #define PCI_VENDOR_ID_INTEL 0x8086
  49. #endif
  50. #ifndef PCI_DEVICE_ID_AMI_MEGARAID
  51. #define PCI_DEVICE_ID_AMI_MEGARAID 0x9010
  52. #endif
  53. #ifndef PCI_DEVICE_ID_AMI_MEGARAID2
  54. #define PCI_DEVICE_ID_AMI_MEGARAID2 0x9060
  55. #endif
  56. #ifndef PCI_DEVICE_ID_AMI_MEGARAID3
  57. #define PCI_DEVICE_ID_AMI_MEGARAID3 0x1960
  58. #endif
  59. #define PCI_DEVICE_ID_DISCOVERY 0x000E
  60. #define PCI_DEVICE_ID_PERC4_DI 0x000F
  61. #define PCI_DEVICE_ID_PERC4_QC_VERDE 0x0407
  62. /* Sub-System Vendor IDs */
  63. #define AMI_SUBSYS_VID 0x101E
  64. #define DELL_SUBSYS_VID 0x1028
  65. #define HP_SUBSYS_VID 0x103C
  66. #define LSI_SUBSYS_VID 0x1000
  67. #define INTEL_SUBSYS_VID 0x8086
  68. #define HBA_SIGNATURE 0x3344
  69. #define HBA_SIGNATURE_471 0xCCCC
  70. #define HBA_SIGNATURE_64BIT 0x0299
  71. #define MBOX_BUSY_WAIT 10 /* wait for up to 10 usec for
  72. mailbox to be free */
  73. #define DEFAULT_INITIATOR_ID 7
  74. #define MAX_SGLIST 64 /* max supported in f/w */
  75. #define MIN_SGLIST 26 /* guaranteed to support these many */
  76. #define MAX_COMMANDS 126
  77. #define CMDID_INT_CMDS MAX_COMMANDS+1 /* make sure CMDID_INT_CMDS
  78. is less than max commands
  79. supported by any f/w */
  80. #define MAX_CDB_LEN 10
  81. #define MAX_EXT_CDB_LEN 16 /* we support cdb length up to 16 */
  82. #define DEF_CMD_PER_LUN 63
  83. #define MAX_CMD_PER_LUN MAX_COMMANDS
  84. #define MAX_FIRMWARE_STATUS 46
  85. #define MAX_XFER_PER_CMD (64*1024)
  86. #define MAX_SECTORS_PER_IO 128
  87. #define MAX_LOGICAL_DRIVES_40LD 40
  88. #define FC_MAX_PHYSICAL_DEVICES 256
  89. #define MAX_LOGICAL_DRIVES_8LD 8
  90. #define MAX_CHANNELS 5
  91. #define MAX_TARGET 15
  92. #define MAX_PHYSICAL_DRIVES MAX_CHANNELS*MAX_TARGET
  93. #define MAX_ROW_SIZE_40LD 32
  94. #define MAX_ROW_SIZE_8LD 8
  95. #define MAX_SPAN_DEPTH 8
  96. #define NVIRT_CHAN 4 /* # of virtual channels to represent
  97. up to 60 logical drives */
  98. struct mbox_out {
  99. /* 0x0 */ u8 cmd;
  100. /* 0x1 */ u8 cmdid;
  101. /* 0x2 */ u16 numsectors;
  102. /* 0x4 */ u32 lba;
  103. /* 0x8 */ u32 xferaddr;
  104. /* 0xC */ u8 logdrv;
  105. /* 0xD */ u8 numsgelements;
  106. /* 0xE */ u8 resvd;
  107. } __attribute__ ((packed));
  108. struct mbox_in {
  109. /* 0xF */ volatile u8 busy;
  110. /* 0x10 */ volatile u8 numstatus;
  111. /* 0x11 */ volatile u8 status;
  112. /* 0x12 */ volatile u8 completed[MAX_FIRMWARE_STATUS];
  113. volatile u8 poll;
  114. volatile u8 ack;
  115. } __attribute__ ((packed));
  116. typedef struct {
  117. struct mbox_out m_out;
  118. struct mbox_in m_in;
  119. } __attribute__ ((packed)) mbox_t;
  120. typedef struct {
  121. u32 xfer_segment_lo;
  122. u32 xfer_segment_hi;
  123. mbox_t mbox;
  124. } __attribute__ ((packed)) mbox64_t;
  125. /*
  126. * Passthru definitions
  127. */
  128. #define MAX_REQ_SENSE_LEN 0x20
  129. typedef struct {
  130. u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
  131. u8 ars:1;
  132. u8 reserved:3;
  133. u8 islogical:1;
  134. u8 logdrv; /* if islogical == 1 */
  135. u8 channel; /* if islogical == 0 */
  136. u8 target; /* if islogical == 0 */
  137. u8 queuetag; /* unused */
  138. u8 queueaction; /* unused */
  139. u8 cdb[MAX_CDB_LEN];
  140. u8 cdblen;
  141. u8 reqsenselen;
  142. u8 reqsensearea[MAX_REQ_SENSE_LEN];
  143. u8 numsgelements;
  144. u8 scsistatus;
  145. u32 dataxferaddr;
  146. u32 dataxferlen;
  147. } __attribute__ ((packed)) mega_passthru;
  148. /*
  149. * Extended passthru: support CDB > 10 bytes
  150. */
  151. typedef struct {
  152. u8 timeout:3; /* 0=6sec/1=60sec/2=10min/3=3hrs */
  153. u8 ars:1;
  154. u8 rsvd1:1;
  155. u8 cd_rom:1;
  156. u8 rsvd2:1;
  157. u8 islogical:1;
  158. u8 logdrv; /* if islogical == 1 */
  159. u8 channel; /* if islogical == 0 */
  160. u8 target; /* if islogical == 0 */
  161. u8 queuetag; /* unused */
  162. u8 queueaction; /* unused */
  163. u8 cdblen;
  164. u8 rsvd3;
  165. u8 cdb[MAX_EXT_CDB_LEN];
  166. u8 numsgelements;
  167. u8 status;
  168. u8 reqsenselen;
  169. u8 reqsensearea[MAX_REQ_SENSE_LEN];
  170. u8 rsvd4;
  171. u32 dataxferaddr;
  172. u32 dataxferlen;
  173. } __attribute__ ((packed)) mega_ext_passthru;
  174. typedef struct {
  175. u64 address;
  176. u32 length;
  177. } __attribute__ ((packed)) mega_sgl64;
  178. typedef struct {
  179. u32 address;
  180. u32 length;
  181. } __attribute__ ((packed)) mega_sglist;
  182. /* Queued command data */
  183. typedef struct {
  184. int idx;
  185. u32 state;
  186. struct list_head list;
  187. u8 raw_mbox[66];
  188. u32 dma_type;
  189. u32 dma_direction;
  190. Scsi_Cmnd *cmd;
  191. dma_addr_t dma_h_bulkdata;
  192. dma_addr_t dma_h_sgdata;
  193. mega_sglist *sgl;
  194. mega_sgl64 *sgl64;
  195. dma_addr_t sgl_dma_addr;
  196. mega_passthru *pthru;
  197. dma_addr_t pthru_dma_addr;
  198. mega_ext_passthru *epthru;
  199. dma_addr_t epthru_dma_addr;
  200. } scb_t;
  201. /*
  202. * Flags to follow the scb as it transitions between various stages
  203. */
  204. #define SCB_FREE 0x0000 /* on the free list */
  205. #define SCB_ACTIVE 0x0001 /* off the free list */
  206. #define SCB_PENDQ 0x0002 /* on the pending queue */
  207. #define SCB_ISSUED 0x0004 /* issued - owner f/w */
  208. #define SCB_ABORT 0x0008 /* Got an abort for this one */
  209. #define SCB_RESET 0x0010 /* Got a reset for this one */
  210. /*
  211. * Utilities declare this strcture size as 1024 bytes. So more fields can
  212. * be added in future.
  213. */
  214. typedef struct {
  215. u32 data_size; /* current size in bytes (not including resvd) */
  216. u32 config_signature;
  217. /* Current value is 0x00282008
  218. * 0x28=MAX_LOGICAL_DRIVES,
  219. * 0x20=Number of stripes and
  220. * 0x08=Number of spans */
  221. u8 fw_version[16]; /* printable ASCI string */
  222. u8 bios_version[16]; /* printable ASCI string */
  223. u8 product_name[80]; /* printable ASCI string */
  224. u8 max_commands; /* Max. concurrent commands supported */
  225. u8 nchannels; /* Number of SCSI Channels detected */
  226. u8 fc_loop_present; /* Number of Fibre Loops detected */
  227. u8 mem_type; /* EDO, FPM, SDRAM etc */
  228. u32 signature;
  229. u16 dram_size; /* In terms of MB */
  230. u16 subsysid;
  231. u16 subsysvid;
  232. u8 notify_counters;
  233. u8 pad1k[889]; /* 135 + 889 resvd = 1024 total size */
  234. } __attribute__ ((packed)) mega_product_info;
  235. struct notify {
  236. u32 global_counter; /* Any change increments this counter */
  237. u8 param_counter; /* Indicates any params changed */
  238. u8 param_id; /* Param modified - defined below */
  239. u16 param_val; /* New val of last param modified */
  240. u8 write_config_counter; /* write config occurred */
  241. u8 write_config_rsvd[3];
  242. u8 ldrv_op_counter; /* Indicates ldrv op started/completed */
  243. u8 ldrv_opid; /* ldrv num */
  244. u8 ldrv_opcmd; /* ldrv operation - defined below */
  245. u8 ldrv_opstatus; /* status of the operation */
  246. u8 ldrv_state_counter; /* Indicates change of ldrv state */
  247. u8 ldrv_state_id; /* ldrv num */
  248. u8 ldrv_state_new; /* New state */
  249. u8 ldrv_state_old; /* old state */
  250. u8 pdrv_state_counter; /* Indicates change of ldrv state */
  251. u8 pdrv_state_id; /* pdrv id */
  252. u8 pdrv_state_new; /* New state */
  253. u8 pdrv_state_old; /* old state */
  254. u8 pdrv_fmt_counter; /* Indicates pdrv format started/over */
  255. u8 pdrv_fmt_id; /* pdrv id */
  256. u8 pdrv_fmt_val; /* format started/over */
  257. u8 pdrv_fmt_rsvd;
  258. u8 targ_xfer_counter; /* Indicates SCSI-2 Xfer rate change */
  259. u8 targ_xfer_id; /* pdrv Id */
  260. u8 targ_xfer_val; /* new Xfer params of last pdrv */
  261. u8 targ_xfer_rsvd;
  262. u8 fcloop_id_chg_counter; /* Indicates loopid changed */
  263. u8 fcloopid_pdrvid; /* pdrv id */
  264. u8 fcloop_id0; /* loopid on fc loop 0 */
  265. u8 fcloop_id1; /* loopid on fc loop 1 */
  266. u8 fcloop_state_counter; /* Indicates loop state changed */
  267. u8 fcloop_state0; /* state of fc loop 0 */
  268. u8 fcloop_state1; /* state of fc loop 1 */
  269. u8 fcloop_state_rsvd;
  270. } __attribute__ ((packed));
  271. #define MAX_NOTIFY_SIZE 0x80
  272. #define CUR_NOTIFY_SIZE sizeof(struct notify)
  273. typedef struct {
  274. u32 data_size; /* current size in bytes (not including resvd) */
  275. struct notify notify;
  276. u8 notify_rsvd[MAX_NOTIFY_SIZE - CUR_NOTIFY_SIZE];
  277. u8 rebuild_rate; /* Rebuild rate (0% - 100%) */
  278. u8 cache_flush_interval; /* In terms of Seconds */
  279. u8 sense_alert;
  280. u8 drive_insert_count; /* drive insertion count */
  281. u8 battery_status;
  282. u8 num_ldrv; /* No. of Log Drives configured */
  283. u8 recon_state[MAX_LOGICAL_DRIVES_40LD / 8]; /* State of
  284. reconstruct */
  285. u16 ldrv_op_status[MAX_LOGICAL_DRIVES_40LD / 8]; /* logdrv
  286. Status */
  287. u32 ldrv_size[MAX_LOGICAL_DRIVES_40LD];/* Size of each log drv */
  288. u8 ldrv_prop[MAX_LOGICAL_DRIVES_40LD];
  289. u8 ldrv_state[MAX_LOGICAL_DRIVES_40LD];/* State of log drives */
  290. u8 pdrv_state[FC_MAX_PHYSICAL_DEVICES];/* State of phys drvs. */
  291. u16 pdrv_format[FC_MAX_PHYSICAL_DEVICES / 16];
  292. u8 targ_xfer[80]; /* phys device transfer rate */
  293. u8 pad1k[263]; /* 761 + 263reserved = 1024 bytes total size */
  294. } __attribute__ ((packed)) mega_inquiry3;
  295. /* Structures */
  296. typedef struct {
  297. u8 max_commands; /* Max concurrent commands supported */
  298. u8 rebuild_rate; /* Rebuild rate - 0% thru 100% */
  299. u8 max_targ_per_chan; /* Max targ per channel */
  300. u8 nchannels; /* Number of channels on HBA */
  301. u8 fw_version[4]; /* Firmware version */
  302. u16 age_of_flash; /* Number of times FW has been flashed */
  303. u8 chip_set_value; /* Contents of 0xC0000832 */
  304. u8 dram_size; /* In MB */
  305. u8 cache_flush_interval; /* in seconds */
  306. u8 bios_version[4];
  307. u8 board_type;
  308. u8 sense_alert;
  309. u8 write_config_count; /* Increase with every configuration
  310. change */
  311. u8 drive_inserted_count; /* Increase with every drive inserted
  312. */
  313. u8 inserted_drive; /* Channel:Id of inserted drive */
  314. u8 battery_status; /*
  315. * BIT 0: battery module missing
  316. * BIT 1: VBAD
  317. * BIT 2: temprature high
  318. * BIT 3: battery pack missing
  319. * BIT 4,5:
  320. * 00 - charge complete
  321. * 01 - fast charge in progress
  322. * 10 - fast charge fail
  323. * 11 - undefined
  324. * Bit 6: counter > 1000
  325. * Bit 7: Undefined
  326. */
  327. u8 dec_fault_bus_info;
  328. } __attribute__ ((packed)) mega_adp_info;
  329. typedef struct {
  330. u8 num_ldrv; /* Number of logical drives configured */
  331. u8 rsvd[3];
  332. u32 ldrv_size[MAX_LOGICAL_DRIVES_8LD];
  333. u8 ldrv_prop[MAX_LOGICAL_DRIVES_8LD];
  334. u8 ldrv_state[MAX_LOGICAL_DRIVES_8LD];
  335. } __attribute__ ((packed)) mega_ldrv_info;
  336. typedef struct {
  337. u8 pdrv_state[MAX_PHYSICAL_DRIVES];
  338. u8 rsvd;
  339. } __attribute__ ((packed)) mega_pdrv_info;
  340. /* RAID inquiry: Mailbox command 0x05*/
  341. typedef struct {
  342. mega_adp_info adapter_info;
  343. mega_ldrv_info logdrv_info;
  344. mega_pdrv_info pdrv_info;
  345. } __attribute__ ((packed)) mraid_inquiry;
  346. /* RAID extended inquiry: Mailbox command 0x04*/
  347. typedef struct {
  348. mraid_inquiry raid_inq;
  349. u16 phys_drv_format[MAX_CHANNELS];
  350. u8 stack_attn;
  351. u8 modem_status;
  352. u8 rsvd[2];
  353. } __attribute__ ((packed)) mraid_ext_inquiry;
  354. typedef struct {
  355. u8 channel;
  356. u8 target;
  357. }__attribute__ ((packed)) adp_device;
  358. typedef struct {
  359. u32 start_blk; /* starting block */
  360. u32 num_blks; /* # of blocks */
  361. adp_device device[MAX_ROW_SIZE_40LD];
  362. }__attribute__ ((packed)) adp_span_40ld;
  363. typedef struct {
  364. u32 start_blk; /* starting block */
  365. u32 num_blks; /* # of blocks */
  366. adp_device device[MAX_ROW_SIZE_8LD];
  367. }__attribute__ ((packed)) adp_span_8ld;
  368. typedef struct {
  369. u8 span_depth; /* Total # of spans */
  370. u8 level; /* RAID level */
  371. u8 read_ahead; /* read ahead, no read ahead, adaptive read
  372. ahead */
  373. u8 stripe_sz; /* Encoded stripe size */
  374. u8 status; /* Status of the logical drive */
  375. u8 write_mode; /* write mode, write_through/write_back */
  376. u8 direct_io; /* direct io or through cache */
  377. u8 row_size; /* Number of stripes in a row */
  378. } __attribute__ ((packed)) logdrv_param;
  379. typedef struct {
  380. logdrv_param lparam;
  381. adp_span_40ld span[MAX_SPAN_DEPTH];
  382. }__attribute__ ((packed)) logdrv_40ld;
  383. typedef struct {
  384. logdrv_param lparam;
  385. adp_span_8ld span[MAX_SPAN_DEPTH];
  386. }__attribute__ ((packed)) logdrv_8ld;
  387. typedef struct {
  388. u8 type; /* Type of the device */
  389. u8 cur_status; /* current status of the device */
  390. u8 tag_depth; /* Level of tagging */
  391. u8 sync_neg; /* sync negotiation - ENABLE or DISBALE */
  392. u32 size; /* configurable size in terms of 512 byte
  393. blocks */
  394. }__attribute__ ((packed)) phys_drv;
  395. typedef struct {
  396. u8 nlog_drives; /* number of logical drives */
  397. u8 resvd[3];
  398. logdrv_40ld ldrv[MAX_LOGICAL_DRIVES_40LD];
  399. phys_drv pdrv[MAX_PHYSICAL_DRIVES];
  400. }__attribute__ ((packed)) disk_array_40ld;
  401. typedef struct {
  402. u8 nlog_drives; /* number of logical drives */
  403. u8 resvd[3];
  404. logdrv_8ld ldrv[MAX_LOGICAL_DRIVES_8LD];
  405. phys_drv pdrv[MAX_PHYSICAL_DRIVES];
  406. }__attribute__ ((packed)) disk_array_8ld;
  407. /*
  408. * User ioctl structure.
  409. * This structure will be used for Traditional Method ioctl interface
  410. * commands (0x80),Alternate Buffer Method (0x81) ioctl commands and the
  411. * Driver ioctls.
  412. * The Driver ioctl interface handles the commands at the driver level,
  413. * without being sent to the card.
  414. */
  415. /* system call imposed limit. Change accordingly */
  416. #define IOCTL_MAX_DATALEN 4096
  417. struct uioctl_t {
  418. u32 inlen;
  419. u32 outlen;
  420. union {
  421. u8 fca[16];
  422. struct {
  423. u8 opcode;
  424. u8 subopcode;
  425. u16 adapno;
  426. #if BITS_PER_LONG == 32
  427. u8 *buffer;
  428. u8 pad[4];
  429. #endif
  430. #if BITS_PER_LONG == 64
  431. u8 *buffer;
  432. #endif
  433. u32 length;
  434. } __attribute__ ((packed)) fcs;
  435. } __attribute__ ((packed)) ui;
  436. u8 mbox[18]; /* 16 bytes + 2 status bytes */
  437. mega_passthru pthru;
  438. #if BITS_PER_LONG == 32
  439. char __user *data; /* buffer <= 4096 for 0x80 commands */
  440. char pad[4];
  441. #endif
  442. #if BITS_PER_LONG == 64
  443. char __user *data;
  444. #endif
  445. } __attribute__ ((packed));
  446. /*
  447. * struct mcontroller is used to pass information about the controllers in the
  448. * system. Its upto the application how to use the information. We are passing
  449. * as much info about the cards as possible and useful. Before issuing the
  450. * call to find information about the cards, the applicaiton needs to issue a
  451. * ioctl first to find out the number of controllers in the system.
  452. */
  453. #define MAX_CONTROLLERS 32
  454. struct mcontroller {
  455. u64 base;
  456. u8 irq;
  457. u8 numldrv;
  458. u8 pcibus;
  459. u16 pcidev;
  460. u8 pcifun;
  461. u16 pciid;
  462. u16 pcivendor;
  463. u8 pcislot;
  464. u32 uid;
  465. };
  466. /*
  467. * mailbox structure used for internal commands
  468. */
  469. typedef struct {
  470. u8 cmd;
  471. u8 cmdid;
  472. u8 opcode;
  473. u8 subopcode;
  474. u32 lba;
  475. u32 xferaddr;
  476. u8 logdrv;
  477. u8 rsvd[3];
  478. u8 numstatus;
  479. u8 status;
  480. } __attribute__ ((packed)) megacmd_t;
  481. /*
  482. * Defines for Driver IOCTL interface
  483. */
  484. #define MEGAIOC_MAGIC 'm'
  485. #define MEGAIOC_QNADAP 'm' /* Query # of adapters */
  486. #define MEGAIOC_QDRVRVER 'e' /* Query driver version */
  487. #define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
  488. #define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
  489. #define GETADAP(mkadap) ( (mkadap) ^ MEGAIOC_MAGIC << 8 )
  490. /*
  491. * Definition for the new ioctl interface (NIT)
  492. */
  493. /*
  494. * Vendor specific Group-7 commands
  495. */
  496. #define VENDOR_SPECIFIC_COMMANDS 0xE0
  497. #define MEGA_INTERNAL_CMD VENDOR_SPECIFIC_COMMANDS + 0x01
  498. /*
  499. * The ioctl command. No other command shall be used for this interface
  500. */
  501. #define USCSICMD VENDOR_SPECIFIC_COMMANDS
  502. /*
  503. * Data direction flags
  504. */
  505. #define UIOC_RD 0x00001
  506. #define UIOC_WR 0x00002
  507. /*
  508. * ioctl opcodes
  509. */
  510. #define MBOX_CMD 0x00000 /* DCMD or passthru command */
  511. #define GET_DRIVER_VER 0x10000 /* Get driver version */
  512. #define GET_N_ADAP 0x20000 /* Get number of adapters */
  513. #define GET_ADAP_INFO 0x30000 /* Get information about a adapter */
  514. #define GET_CAP 0x40000 /* Get ioctl capabilities */
  515. #define GET_STATS 0x50000 /* Get statistics, including error info */
  516. /*
  517. * The ioctl structure.
  518. * MBOX macro converts a nitioctl_t structure to megacmd_t pointer and
  519. * MBOX_P macro converts a nitioctl_t pointer to megacmd_t pointer.
  520. */
  521. typedef struct {
  522. char signature[8]; /* Must contain "MEGANIT" */
  523. u32 opcode; /* opcode for the command */
  524. u32 adapno; /* adapter number */
  525. union {
  526. u8 __raw_mbox[18];
  527. void __user *__uaddr; /* xferaddr for non-mbox cmds */
  528. }__ua;
  529. #define uioc_rmbox __ua.__raw_mbox
  530. #define MBOX(uioc) ((megacmd_t *)&((uioc).__ua.__raw_mbox[0]))
  531. #define MBOX_P(uioc) ((megacmd_t __user *)&((uioc)->__ua.__raw_mbox[0]))
  532. #define uioc_uaddr __ua.__uaddr
  533. u32 xferlen; /* xferlen for DCMD and non-mbox
  534. commands */
  535. u32 flags; /* data direction flags */
  536. }nitioctl_t;
  537. /*
  538. * I/O statistics for some applications like SNMP agent. The caller must
  539. * provide the number of logical drives for which status should be reported.
  540. */
  541. typedef struct {
  542. int num_ldrv; /* Number for logical drives for which the
  543. status should be reported. */
  544. u32 nreads[MAX_LOGICAL_DRIVES_40LD]; /* number of reads for
  545. each logical drive */
  546. u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
  547. read for each logical
  548. drive */
  549. u32 nwrites[MAX_LOGICAL_DRIVES_40LD]; /* number of writes
  550. for each logical
  551. drive */
  552. u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD]; /* number of blocks
  553. writes for each
  554. logical drive */
  555. u32 rd_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of read
  556. errors for each
  557. logical drive */
  558. u32 wr_errors[MAX_LOGICAL_DRIVES_40LD]; /* number of write
  559. errors for each
  560. logical drive */
  561. }megastat_t;
  562. struct private_bios_data {
  563. u8 geometry:4; /*
  564. * bits 0-3 - BIOS geometry
  565. * 0x0001 - 1GB
  566. * 0x0010 - 2GB
  567. * 0x1000 - 8GB
  568. * Others values are invalid
  569. */
  570. u8 unused:4; /* bits 4-7 are unused */
  571. u8 boot_drv; /*
  572. * logical drive set as boot drive
  573. * 0..7 - for 8LD cards
  574. * 0..39 - for 40LD cards
  575. */
  576. u8 rsvd[12];
  577. u16 cksum; /* 0-(sum of first 13 bytes of this structure) */
  578. } __attribute__ ((packed));
  579. /*
  580. * Mailbox and firmware commands and subopcodes used in this driver.
  581. */
  582. #define MEGA_MBOXCMD_LREAD 0x01
  583. #define MEGA_MBOXCMD_LWRITE 0x02
  584. #define MEGA_MBOXCMD_PASSTHRU 0x03
  585. #define MEGA_MBOXCMD_ADPEXTINQ 0x04
  586. #define MEGA_MBOXCMD_ADAPTERINQ 0x05
  587. #define MEGA_MBOXCMD_LREAD64 0xA7
  588. #define MEGA_MBOXCMD_LWRITE64 0xA8
  589. #define MEGA_MBOXCMD_PASSTHRU64 0xC3
  590. #define MEGA_MBOXCMD_EXTPTHRU 0xE3
  591. #define MAIN_MISC_OPCODE 0xA4 /* f/w misc opcode */
  592. #define GET_MAX_SG_SUPPORT 0x01 /* get max sg len supported by f/w */
  593. #define FC_NEW_CONFIG 0xA1
  594. #define NC_SUBOP_PRODUCT_INFO 0x0E
  595. #define NC_SUBOP_ENQUIRY3 0x0F
  596. #define ENQ3_GET_SOLICITED_FULL 0x02
  597. #define OP_DCMD_READ_CONFIG 0x04
  598. #define NEW_READ_CONFIG_8LD 0x67
  599. #define READ_CONFIG_8LD 0x07
  600. #define FLUSH_ADAPTER 0x0A
  601. #define FLUSH_SYSTEM 0xFE
  602. /*
  603. * Command for random deletion of logical drives
  604. */
  605. #define FC_DEL_LOGDRV 0xA4 /* f/w command */
  606. #define OP_SUP_DEL_LOGDRV 0x2A /* is feature supported */
  607. #define OP_GET_LDID_MAP 0x18 /* get ldid and logdrv number map */
  608. #define OP_DEL_LOGDRV 0x1C /* delete logical drive */
  609. /*
  610. * BIOS commands
  611. */
  612. #define IS_BIOS_ENABLED 0x62
  613. #define GET_BIOS 0x01
  614. #define CHNL_CLASS 0xA9
  615. #define GET_CHNL_CLASS 0x00
  616. #define SET_CHNL_CLASS 0x01
  617. #define CH_RAID 0x01
  618. #define CH_SCSI 0x00
  619. #define BIOS_PVT_DATA 0x40
  620. #define GET_BIOS_PVT_DATA 0x00
  621. /*
  622. * Commands to support clustering
  623. */
  624. #define MEGA_GET_TARGET_ID 0x7D
  625. #define MEGA_CLUSTER_OP 0x70
  626. #define MEGA_GET_CLUSTER_MODE 0x02
  627. #define MEGA_CLUSTER_CMD 0x6E
  628. #define MEGA_RESERVE_LD 0x01
  629. #define MEGA_RELEASE_LD 0x02
  630. #define MEGA_RESET_RESERVATIONS 0x03
  631. #define MEGA_RESERVATION_STATUS 0x04
  632. #define MEGA_RESERVE_PD 0x05
  633. #define MEGA_RELEASE_PD 0x06
  634. /*
  635. * Module battery status
  636. */
  637. #define MEGA_BATT_MODULE_MISSING 0x01
  638. #define MEGA_BATT_LOW_VOLTAGE 0x02
  639. #define MEGA_BATT_TEMP_HIGH 0x04
  640. #define MEGA_BATT_PACK_MISSING 0x08
  641. #define MEGA_BATT_CHARGE_MASK 0x30
  642. #define MEGA_BATT_CHARGE_DONE 0x00
  643. #define MEGA_BATT_CHARGE_INPROG 0x10
  644. #define MEGA_BATT_CHARGE_FAIL 0x20
  645. #define MEGA_BATT_CYCLES_EXCEEDED 0x40
  646. /*
  647. * Physical drive states.
  648. */
  649. #define PDRV_UNCNF 0
  650. #define PDRV_ONLINE 3
  651. #define PDRV_FAILED 4
  652. #define PDRV_RBLD 5
  653. #define PDRV_HOTSPARE 6
  654. /*
  655. * Raid logical drive states.
  656. */
  657. #define RDRV_OFFLINE 0
  658. #define RDRV_DEGRADED 1
  659. #define RDRV_OPTIMAL 2
  660. #define RDRV_DELETED 3
  661. /*
  662. * Read, write and cache policies
  663. */
  664. #define NO_READ_AHEAD 0
  665. #define READ_AHEAD 1
  666. #define ADAP_READ_AHEAD 2
  667. #define WRMODE_WRITE_THRU 0
  668. #define WRMODE_WRITE_BACK 1
  669. #define CACHED_IO 0
  670. #define DIRECT_IO 1
  671. #define SCSI_LIST(scp) ((struct list_head *)(&(scp)->SCp))
  672. /*
  673. * Each controller's soft state
  674. */
  675. typedef struct {
  676. int this_id; /* our id, may set to different than 7 if
  677. clustering is available */
  678. u32 flag;
  679. unsigned long base;
  680. /* mbox64 with mbox not aligned on 16-byte boundry */
  681. mbox64_t *una_mbox64;
  682. dma_addr_t una_mbox64_dma;
  683. volatile mbox64_t *mbox64;/* ptr to 64-bit mailbox */
  684. volatile mbox_t *mbox; /* ptr to standard mailbox */
  685. dma_addr_t mbox_dma;
  686. struct pci_dev *dev;
  687. struct list_head free_list;
  688. struct list_head pending_list;
  689. struct list_head completed_list;
  690. struct Scsi_Host *host;
  691. #define MEGA_BUFFER_SIZE (2*1024)
  692. u8 *mega_buffer;
  693. dma_addr_t buf_dma_handle;
  694. mega_product_info product_info;
  695. u8 max_cmds;
  696. scb_t *scb_list;
  697. atomic_t pend_cmds; /* maintain a counter for pending
  698. commands in firmware */
  699. #if MEGA_HAVE_STATS
  700. u32 nreads[MAX_LOGICAL_DRIVES_40LD];
  701. u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];
  702. u32 nwrites[MAX_LOGICAL_DRIVES_40LD];
  703. u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
  704. u32 rd_errors[MAX_LOGICAL_DRIVES_40LD];
  705. u32 wr_errors[MAX_LOGICAL_DRIVES_40LD];
  706. #endif
  707. /* Host adapter parameters */
  708. u8 numldrv;
  709. u8 fw_version[7];
  710. u8 bios_version[7];
  711. #ifdef CONFIG_PROC_FS
  712. struct proc_dir_entry *controller_proc_dir_entry;
  713. struct proc_dir_entry *proc_read;
  714. struct proc_dir_entry *proc_stat;
  715. struct proc_dir_entry *proc_mbox;
  716. #if MEGA_HAVE_ENH_PROC
  717. struct proc_dir_entry *proc_rr;
  718. struct proc_dir_entry *proc_battery;
  719. #define MAX_PROC_CHANNELS 4
  720. struct proc_dir_entry *proc_pdrvstat[MAX_PROC_CHANNELS];
  721. struct proc_dir_entry *proc_rdrvstat[MAX_PROC_CHANNELS];
  722. #endif
  723. #endif
  724. int has_64bit_addr; /* are we using 64-bit addressing */
  725. int support_ext_cdb;
  726. int boot_ldrv_enabled;
  727. int boot_ldrv;
  728. int boot_pdrv_enabled; /* boot from physical drive */
  729. int boot_pdrv_ch; /* boot physical drive channel */
  730. int boot_pdrv_tgt; /* boot physical drive target */
  731. int support_random_del; /* Do we support random deletion of
  732. logdrvs */
  733. int read_ldidmap; /* set after logical drive deltion. The
  734. logical drive number must be read from the
  735. map */
  736. atomic_t quiescent; /* a stage reached when delete logical
  737. drive needs to be done. Stop
  738. sending requests to the hba till
  739. delete operation is completed */
  740. spinlock_t lock;
  741. u8 logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
  742. what channels. */
  743. int mega_ch_class;
  744. u8 sglen; /* f/w supported scatter-gather list length */
  745. scb_t int_scb;
  746. Scsi_Cmnd int_scmd;
  747. struct semaphore int_mtx; /* To synchronize the internal
  748. commands */
  749. struct completion int_waitq; /* wait queue for internal
  750. cmds */
  751. int has_cluster; /* cluster support on this HBA */
  752. }adapter_t;
  753. struct mega_hbas {
  754. int is_bios_enabled;
  755. adapter_t *hostdata_addr;
  756. };
  757. /*
  758. * For state flag. Do not use LSB(8 bits) which are
  759. * reserved for storing info about channels.
  760. */
  761. #define IN_ABORT 0x80000000L
  762. #define IN_RESET 0x40000000L
  763. #define BOARD_MEMMAP 0x20000000L
  764. #define BOARD_IOMAP 0x10000000L
  765. #define BOARD_40LD 0x08000000L
  766. #define BOARD_64BIT 0x04000000L
  767. #define INTR_VALID 0x40
  768. #define PCI_CONF_AMISIG 0xa0
  769. #define PCI_CONF_AMISIG64 0xa4
  770. #define MEGA_DMA_TYPE_NONE 0xFFFF
  771. #define MEGA_BULK_DATA 0x0001
  772. #define MEGA_SGLIST 0x0002
  773. /*
  774. * lockscope definitions, callers can specify the lock scope with this data
  775. * type. LOCK_INT would mean the caller has not acquired the lock before
  776. * making the call and LOCK_EXT would mean otherwise.
  777. */
  778. typedef enum { LOCK_INT, LOCK_EXT } lockscope_t;
  779. /*
  780. * Parameters for the io-mapped controllers
  781. */
  782. /* I/O Port offsets */
  783. #define CMD_PORT 0x00
  784. #define ACK_PORT 0x00
  785. #define TOGGLE_PORT 0x01
  786. #define INTR_PORT 0x0a
  787. #define MBOX_BUSY_PORT 0x00
  788. #define MBOX_PORT0 0x04
  789. #define MBOX_PORT1 0x05
  790. #define MBOX_PORT2 0x06
  791. #define MBOX_PORT3 0x07
  792. #define ENABLE_MBOX_REGION 0x0B
  793. /* I/O Port Values */
  794. #define ISSUE_BYTE 0x10
  795. #define ACK_BYTE 0x08
  796. #define ENABLE_INTR_BYTE 0xc0
  797. #define DISABLE_INTR_BYTE 0x00
  798. #define VALID_INTR_BYTE 0x40
  799. #define MBOX_BUSY_BYTE 0x10
  800. #define ENABLE_MBOX_BYTE 0x00
  801. /* Setup some port macros here */
  802. #define issue_command(adapter) \
  803. outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
  804. #define irq_state(adapter) inb_p((adapter)->base + INTR_PORT)
  805. #define set_irq_state(adapter, value) \
  806. outb_p((value), (adapter)->base + INTR_PORT)
  807. #define irq_ack(adapter) \
  808. outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
  809. #define irq_enable(adapter) \
  810. outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
  811. #define irq_disable(adapter) \
  812. outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
  813. /*
  814. * This is our SYSDEP area. All kernel specific detail should be placed here -
  815. * as much as possible
  816. */
  817. /*
  818. * End of SYSDEP area
  819. */
  820. const char *megaraid_info (struct Scsi_Host *);
  821. static int mega_query_adapter(adapter_t *);
  822. static int issue_scb(adapter_t *, scb_t *);
  823. static int mega_setup_mailbox(adapter_t *);
  824. static int megaraid_queue (Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
  825. static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
  826. static void __mega_runpendq(adapter_t *);
  827. static int issue_scb_block(adapter_t *, u_char *);
  828. static irqreturn_t megaraid_isr_memmapped(int, void *, struct pt_regs *);
  829. static irqreturn_t megaraid_isr_iomapped(int, void *, struct pt_regs *);
  830. static void mega_free_scb(adapter_t *, scb_t *);
  831. static int megaraid_abort(Scsi_Cmnd *);
  832. static int megaraid_reset(Scsi_Cmnd *);
  833. static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
  834. static int megaraid_biosparam(struct scsi_device *, struct block_device *,
  835. sector_t, int []);
  836. static int mega_print_inquiry(char *, char *);
  837. static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
  838. u32 *buffer, u32 *length);
  839. static int __mega_busywait_mbox (adapter_t *);
  840. static void mega_rundoneq (adapter_t *);
  841. static void mega_cmd_done(adapter_t *, u8 [], int, int);
  842. static inline void mega_free_sgl (adapter_t *adapter);
  843. static void mega_8_to_40ld (mraid_inquiry *inquiry,
  844. mega_inquiry3 *enquiry3, mega_product_info *);
  845. static int megadev_open (struct inode *, struct file *);
  846. static int megadev_ioctl (struct inode *, struct file *, unsigned int,
  847. unsigned long);
  848. static int mega_m_to_n(void __user *, nitioctl_t *);
  849. static int mega_n_to_m(void __user *, megacmd_t *);
  850. static int mega_init_scb (adapter_t *);
  851. static int mega_is_bios_enabled (adapter_t *);
  852. #ifdef CONFIG_PROC_FS
  853. static void mega_create_proc_entry(int, struct proc_dir_entry *);
  854. static int proc_read_config(char *, char **, off_t, int, int *, void *);
  855. static int proc_read_stat(char *, char **, off_t, int, int *, void *);
  856. static int proc_read_mbox(char *, char **, off_t, int, int *, void *);
  857. static int proc_rebuild_rate(char *, char **, off_t, int, int *, void *);
  858. static int proc_battery(char *, char **, off_t, int, int *, void *);
  859. static int proc_pdrv_ch0(char *, char **, off_t, int, int *, void *);
  860. static int proc_pdrv_ch1(char *, char **, off_t, int, int *, void *);
  861. static int proc_pdrv_ch2(char *, char **, off_t, int, int *, void *);
  862. static int proc_pdrv_ch3(char *, char **, off_t, int, int *, void *);
  863. static int proc_pdrv(adapter_t *, char *, int);
  864. static int proc_rdrv_10(char *, char **, off_t, int, int *, void *);
  865. static int proc_rdrv_20(char *, char **, off_t, int, int *, void *);
  866. static int proc_rdrv_30(char *, char **, off_t, int, int *, void *);
  867. static int proc_rdrv_40(char *, char **, off_t, int, int *, void *);
  868. static int proc_rdrv(adapter_t *, char *, int, int);
  869. #endif
  870. static int mega_adapinq(adapter_t *, dma_addr_t);
  871. static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
  872. static int mega_support_ext_cdb(adapter_t *);
  873. static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
  874. Scsi_Cmnd *, int, int);
  875. static mega_ext_passthru* mega_prepare_extpassthru(adapter_t *,
  876. scb_t *, Scsi_Cmnd *, int, int);
  877. static void mega_enum_raid_scsi(adapter_t *);
  878. static void mega_get_boot_drv(adapter_t *);
  879. static int mega_support_random_del(adapter_t *);
  880. static int mega_del_logdrv(adapter_t *, int);
  881. static int mega_do_del_logdrv(adapter_t *, int);
  882. static void mega_get_max_sgl(adapter_t *);
  883. static int mega_internal_command(adapter_t *, lockscope_t, megacmd_t *,
  884. mega_passthru *);
  885. static void mega_internal_done(Scsi_Cmnd *);
  886. static int mega_support_cluster(adapter_t *);
  887. #endif
  888. /* vi: set ts=8 sw=8 tw=78: */