megaraid.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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. #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: temperature 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 DISABLE */
  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 up to 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 application 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. void __iomem *mmio_base;
  682. /* mbox64 with mbox not aligned on 16-byte boundary */
  683. mbox64_t *una_mbox64;
  684. dma_addr_t una_mbox64_dma;
  685. volatile mbox64_t *mbox64;/* ptr to 64-bit mailbox */
  686. volatile mbox_t *mbox; /* ptr to standard mailbox */
  687. dma_addr_t mbox_dma;
  688. struct pci_dev *dev;
  689. struct list_head free_list;
  690. struct list_head pending_list;
  691. struct list_head completed_list;
  692. struct Scsi_Host *host;
  693. #define MEGA_BUFFER_SIZE (2*1024)
  694. u8 *mega_buffer;
  695. dma_addr_t buf_dma_handle;
  696. mega_product_info product_info;
  697. u8 max_cmds;
  698. scb_t *scb_list;
  699. atomic_t pend_cmds; /* maintain a counter for pending
  700. commands in firmware */
  701. #if MEGA_HAVE_STATS
  702. u32 nreads[MAX_LOGICAL_DRIVES_40LD];
  703. u32 nreadblocks[MAX_LOGICAL_DRIVES_40LD];
  704. u32 nwrites[MAX_LOGICAL_DRIVES_40LD];
  705. u32 nwriteblocks[MAX_LOGICAL_DRIVES_40LD];
  706. u32 rd_errors[MAX_LOGICAL_DRIVES_40LD];
  707. u32 wr_errors[MAX_LOGICAL_DRIVES_40LD];
  708. #endif
  709. /* Host adapter parameters */
  710. u8 numldrv;
  711. u8 fw_version[7];
  712. u8 bios_version[7];
  713. #ifdef CONFIG_PROC_FS
  714. struct proc_dir_entry *controller_proc_dir_entry;
  715. struct proc_dir_entry *proc_read;
  716. struct proc_dir_entry *proc_stat;
  717. struct proc_dir_entry *proc_mbox;
  718. #if MEGA_HAVE_ENH_PROC
  719. struct proc_dir_entry *proc_rr;
  720. struct proc_dir_entry *proc_battery;
  721. #define MAX_PROC_CHANNELS 4
  722. struct proc_dir_entry *proc_pdrvstat[MAX_PROC_CHANNELS];
  723. struct proc_dir_entry *proc_rdrvstat[MAX_PROC_CHANNELS];
  724. #endif
  725. #endif
  726. int has_64bit_addr; /* are we using 64-bit addressing */
  727. int support_ext_cdb;
  728. int boot_ldrv_enabled;
  729. int boot_ldrv;
  730. int boot_pdrv_enabled; /* boot from physical drive */
  731. int boot_pdrv_ch; /* boot physical drive channel */
  732. int boot_pdrv_tgt; /* boot physical drive target */
  733. int support_random_del; /* Do we support random deletion of
  734. logdrvs */
  735. int read_ldidmap; /* set after logical drive deltion. The
  736. logical drive number must be read from the
  737. map */
  738. atomic_t quiescent; /* a stage reached when delete logical
  739. drive needs to be done. Stop
  740. sending requests to the hba till
  741. delete operation is completed */
  742. spinlock_t lock;
  743. u8 logdrv_chan[MAX_CHANNELS+NVIRT_CHAN]; /* logical drive are on
  744. what channels. */
  745. int mega_ch_class;
  746. u8 sglen; /* f/w supported scatter-gather list length */
  747. unsigned char int_cdb[MAX_COMMAND_SIZE];
  748. scb_t int_scb;
  749. struct mutex int_mtx; /* To synchronize the internal
  750. commands */
  751. struct completion int_waitq; /* wait queue for internal
  752. cmds */
  753. int has_cluster; /* cluster support on this HBA */
  754. }adapter_t;
  755. struct mega_hbas {
  756. int is_bios_enabled;
  757. adapter_t *hostdata_addr;
  758. };
  759. /*
  760. * For state flag. Do not use LSB(8 bits) which are
  761. * reserved for storing info about channels.
  762. */
  763. #define IN_ABORT 0x80000000L
  764. #define IN_RESET 0x40000000L
  765. #define BOARD_MEMMAP 0x20000000L
  766. #define BOARD_IOMAP 0x10000000L
  767. #define BOARD_40LD 0x08000000L
  768. #define BOARD_64BIT 0x04000000L
  769. #define INTR_VALID 0x40
  770. #define PCI_CONF_AMISIG 0xa0
  771. #define PCI_CONF_AMISIG64 0xa4
  772. #define MEGA_DMA_TYPE_NONE 0xFFFF
  773. #define MEGA_BULK_DATA 0x0001
  774. #define MEGA_SGLIST 0x0002
  775. /*
  776. * Parameters for the io-mapped controllers
  777. */
  778. /* I/O Port offsets */
  779. #define CMD_PORT 0x00
  780. #define ACK_PORT 0x00
  781. #define TOGGLE_PORT 0x01
  782. #define INTR_PORT 0x0a
  783. #define MBOX_BUSY_PORT 0x00
  784. #define MBOX_PORT0 0x04
  785. #define MBOX_PORT1 0x05
  786. #define MBOX_PORT2 0x06
  787. #define MBOX_PORT3 0x07
  788. #define ENABLE_MBOX_REGION 0x0B
  789. /* I/O Port Values */
  790. #define ISSUE_BYTE 0x10
  791. #define ACK_BYTE 0x08
  792. #define ENABLE_INTR_BYTE 0xc0
  793. #define DISABLE_INTR_BYTE 0x00
  794. #define VALID_INTR_BYTE 0x40
  795. #define MBOX_BUSY_BYTE 0x10
  796. #define ENABLE_MBOX_BYTE 0x00
  797. /* Setup some port macros here */
  798. #define issue_command(adapter) \
  799. outb_p(ISSUE_BYTE, (adapter)->base + CMD_PORT)
  800. #define irq_state(adapter) inb_p((adapter)->base + INTR_PORT)
  801. #define set_irq_state(adapter, value) \
  802. outb_p((value), (adapter)->base + INTR_PORT)
  803. #define irq_ack(adapter) \
  804. outb_p(ACK_BYTE, (adapter)->base + ACK_PORT)
  805. #define irq_enable(adapter) \
  806. outb_p(ENABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
  807. #define irq_disable(adapter) \
  808. outb_p(DISABLE_INTR_BYTE, (adapter)->base + TOGGLE_PORT)
  809. /*
  810. * This is our SYSDEP area. All kernel specific detail should be placed here -
  811. * as much as possible
  812. */
  813. /*
  814. * End of SYSDEP area
  815. */
  816. const char *megaraid_info (struct Scsi_Host *);
  817. static int mega_query_adapter(adapter_t *);
  818. static int issue_scb(adapter_t *, scb_t *);
  819. static int mega_setup_mailbox(adapter_t *);
  820. static int megaraid_queue (struct Scsi_Host *, struct scsi_cmnd *);
  821. static scb_t * mega_build_cmd(adapter_t *, Scsi_Cmnd *, int *);
  822. static void __mega_runpendq(adapter_t *);
  823. static int issue_scb_block(adapter_t *, u_char *);
  824. static irqreturn_t megaraid_isr_memmapped(int, void *);
  825. static irqreturn_t megaraid_isr_iomapped(int, void *);
  826. static void mega_free_scb(adapter_t *, scb_t *);
  827. static int megaraid_abort(Scsi_Cmnd *);
  828. static int megaraid_reset(Scsi_Cmnd *);
  829. static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
  830. static int megaraid_biosparam(struct scsi_device *, struct block_device *,
  831. sector_t, int []);
  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 file *, unsigned int, unsigned long);
  842. static int mega_m_to_n(void __user *, nitioctl_t *);
  843. static int mega_n_to_m(void __user *, megacmd_t *);
  844. static int mega_init_scb (adapter_t *);
  845. static int mega_is_bios_enabled (adapter_t *);
  846. #ifdef CONFIG_PROC_FS
  847. static int mega_print_inquiry(char *, char *);
  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. static int mega_adapinq(adapter_t *, dma_addr_t);
  865. static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
  866. #endif
  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: */