megaraid.h 27 KB

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