megaraid.h 29 KB

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