megaraid.h 27 KB

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