megaraid.h 27 KB

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