mvumi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Marvell UMI head file
  3. *
  4. * Copyright 2011 Marvell. <jyli@marvell.com>
  5. *
  6. * This file is licensed under GPLv2.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; version 2 of the
  11. * License.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. * USA
  22. */
  23. #ifndef MVUMI_H
  24. #define MVUMI_H
  25. #define MAX_BASE_ADDRESS 6
  26. #define VER_MAJOR 1
  27. #define VER_MINOR 1
  28. #define VER_OEM 0
  29. #define VER_BUILD 1500
  30. #define MV_DRIVER_NAME "mvumi"
  31. #define PCI_DEVICE_ID_MARVELL_MV9143 0x9143
  32. #define PCI_DEVICE_ID_MARVELL_MV9580 0x9580
  33. #define MVUMI_INTERNAL_CMD_WAIT_TIME 45
  34. #define MVUMI_INQUIRY_LENGTH 44
  35. #define MVUMI_INQUIRY_UUID_OFF 36
  36. #define MVUMI_INQUIRY_UUID_LEN 8
  37. #define IS_DMA64 (sizeof(dma_addr_t) == 8)
  38. enum mvumi_qc_result {
  39. MV_QUEUE_COMMAND_RESULT_SENT = 0,
  40. MV_QUEUE_COMMAND_RESULT_NO_RESOURCE,
  41. };
  42. struct mvumi_hw_regs {
  43. /* For CPU */
  44. void *main_int_cause_reg;
  45. void *enpointa_mask_reg;
  46. void *enpointb_mask_reg;
  47. void *rstoutn_en_reg;
  48. void *ctrl_sts_reg;
  49. void *rstoutn_mask_reg;
  50. void *sys_soft_rst_reg;
  51. /* For Doorbell */
  52. void *pciea_to_arm_drbl_reg;
  53. void *arm_to_pciea_drbl_reg;
  54. void *arm_to_pciea_mask_reg;
  55. void *pciea_to_arm_msg0;
  56. void *pciea_to_arm_msg1;
  57. void *arm_to_pciea_msg0;
  58. void *arm_to_pciea_msg1;
  59. /* reset register */
  60. void *reset_request;
  61. void *reset_enable;
  62. /* For Message Unit */
  63. void *inb_list_basel;
  64. void *inb_list_baseh;
  65. void *inb_aval_count_basel;
  66. void *inb_aval_count_baseh;
  67. void *inb_write_pointer;
  68. void *inb_read_pointer;
  69. void *outb_list_basel;
  70. void *outb_list_baseh;
  71. void *outb_copy_basel;
  72. void *outb_copy_baseh;
  73. void *outb_copy_pointer;
  74. void *outb_read_pointer;
  75. void *inb_isr_cause;
  76. void *outb_isr_cause;
  77. void *outb_coal_cfg;
  78. void *outb_coal_timeout;
  79. /* Bit setting for HW */
  80. u32 int_comaout;
  81. u32 int_comaerr;
  82. u32 int_dl_cpu2pciea;
  83. u32 int_mu;
  84. u32 int_drbl_int_mask;
  85. u32 int_main_int_mask;
  86. u32 cl_pointer_toggle;
  87. u32 cl_slot_num_mask;
  88. u32 clic_irq;
  89. u32 clic_in_err;
  90. u32 clic_out_err;
  91. };
  92. struct mvumi_dyn_list_entry {
  93. u32 src_low_addr;
  94. u32 src_high_addr;
  95. u32 if_length;
  96. u32 reserve;
  97. };
  98. #define SCSI_CMD_MARVELL_SPECIFIC 0xE1
  99. #define CDB_CORE_MODULE 0x1
  100. #define CDB_CORE_SHUTDOWN 0xB
  101. enum {
  102. DRBL_HANDSHAKE = 1 << 0,
  103. DRBL_SOFT_RESET = 1 << 1,
  104. DRBL_BUS_CHANGE = 1 << 2,
  105. DRBL_EVENT_NOTIFY = 1 << 3,
  106. DRBL_MU_RESET = 1 << 4,
  107. DRBL_HANDSHAKE_ISR = DRBL_HANDSHAKE,
  108. /*
  109. * Command flag is the flag for the CDB command itself
  110. */
  111. /* 1-non data; 0-data command */
  112. CMD_FLAG_NON_DATA = 1 << 0,
  113. CMD_FLAG_DMA = 1 << 1,
  114. CMD_FLAG_PIO = 1 << 2,
  115. /* 1-host read data */
  116. CMD_FLAG_DATA_IN = 1 << 3,
  117. /* 1-host write data */
  118. CMD_FLAG_DATA_OUT = 1 << 4,
  119. CMD_FLAG_PRDT_IN_HOST = 1 << 5,
  120. };
  121. #define APICDB0_EVENT 0xF4
  122. #define APICDB1_EVENT_GETEVENT 0
  123. #define APICDB1_HOST_GETEVENT 1
  124. #define MAX_EVENTS_RETURNED 6
  125. #define DEVICE_OFFLINE 0
  126. #define DEVICE_ONLINE 1
  127. struct mvumi_hotplug_event {
  128. u16 size;
  129. u8 dummy[2];
  130. u8 bitmap[0];
  131. };
  132. struct mvumi_driver_event {
  133. u32 time_stamp;
  134. u32 sequence_no;
  135. u32 event_id;
  136. u8 severity;
  137. u8 param_count;
  138. u16 device_id;
  139. u32 params[4];
  140. u8 sense_data_length;
  141. u8 Reserved1;
  142. u8 sense_data[30];
  143. };
  144. struct mvumi_event_req {
  145. unsigned char count;
  146. unsigned char reserved[3];
  147. struct mvumi_driver_event events[MAX_EVENTS_RETURNED];
  148. };
  149. struct mvumi_events_wq {
  150. struct work_struct work_q;
  151. struct mvumi_hba *mhba;
  152. unsigned int event;
  153. void *param;
  154. };
  155. #define HS_CAPABILITY_SUPPORT_COMPACT_SG (1U << 4)
  156. #define HS_CAPABILITY_SUPPORT_PRD_HOST (1U << 5)
  157. #define HS_CAPABILITY_SUPPORT_DYN_SRC (1U << 6)
  158. #define HS_CAPABILITY_NEW_PAGE_IO_DEPTH_DEF (1U << 14)
  159. #define MVUMI_MAX_SG_ENTRY 32
  160. #define SGD_EOT (1L << 27)
  161. #define SGD_EOT_CP (1L << 22)
  162. struct mvumi_sgl {
  163. u32 baseaddr_l;
  164. u32 baseaddr_h;
  165. u32 flags;
  166. u32 size;
  167. };
  168. struct mvumi_compact_sgl {
  169. u32 baseaddr_l;
  170. u32 baseaddr_h;
  171. u32 flags;
  172. };
  173. #define GET_COMPACT_SGD_SIZE(sgd) \
  174. ((((struct mvumi_compact_sgl *)(sgd))->flags) & 0x3FFFFFL)
  175. #define SET_COMPACT_SGD_SIZE(sgd, sz) do { \
  176. (((struct mvumi_compact_sgl *)(sgd))->flags) &= ~0x3FFFFFL; \
  177. (((struct mvumi_compact_sgl *)(sgd))->flags) |= (sz); \
  178. } while (0)
  179. #define sgd_getsz(_mhba, sgd, sz) do { \
  180. if (_mhba->hba_capability & HS_CAPABILITY_SUPPORT_COMPACT_SG) \
  181. (sz) = GET_COMPACT_SGD_SIZE(sgd); \
  182. else \
  183. (sz) = (sgd)->size; \
  184. } while (0)
  185. #define sgd_setsz(_mhba, sgd, sz) do { \
  186. if (_mhba->hba_capability & HS_CAPABILITY_SUPPORT_COMPACT_SG) \
  187. SET_COMPACT_SGD_SIZE(sgd, sz); \
  188. else \
  189. (sgd)->size = (sz); \
  190. } while (0)
  191. #define sgd_inc(_mhba, sgd) do { \
  192. if (_mhba->hba_capability & HS_CAPABILITY_SUPPORT_COMPACT_SG) \
  193. sgd = (struct mvumi_sgl *)(((unsigned char *) (sgd)) + 12); \
  194. else \
  195. sgd = (struct mvumi_sgl *)(((unsigned char *) (sgd)) + 16); \
  196. } while (0)
  197. struct mvumi_res {
  198. struct list_head entry;
  199. dma_addr_t bus_addr;
  200. void *virt_addr;
  201. unsigned int size;
  202. unsigned short type; /* enum Resource_Type */
  203. };
  204. /* Resource type */
  205. enum resource_type {
  206. RESOURCE_CACHED_MEMORY = 0,
  207. RESOURCE_UNCACHED_MEMORY
  208. };
  209. struct mvumi_sense_data {
  210. u8 error_code:7;
  211. u8 valid:1;
  212. u8 segment_number;
  213. u8 sense_key:4;
  214. u8 reserved:1;
  215. u8 incorrect_length:1;
  216. u8 end_of_media:1;
  217. u8 file_mark:1;
  218. u8 information[4];
  219. u8 additional_sense_length;
  220. u8 command_specific_information[4];
  221. u8 additional_sense_code;
  222. u8 additional_sense_code_qualifier;
  223. u8 field_replaceable_unit_code;
  224. u8 sense_key_specific[3];
  225. };
  226. /* Request initiator must set the status to REQ_STATUS_PENDING. */
  227. #define REQ_STATUS_PENDING 0x80
  228. struct mvumi_cmd {
  229. struct list_head queue_pointer;
  230. struct mvumi_msg_frame *frame;
  231. dma_addr_t frame_phys;
  232. struct scsi_cmnd *scmd;
  233. atomic_t sync_cmd;
  234. void *data_buf;
  235. unsigned short request_id;
  236. unsigned char cmd_status;
  237. };
  238. /*
  239. * the function type of the in bound frame
  240. */
  241. #define CL_FUN_SCSI_CMD 0x1
  242. struct mvumi_msg_frame {
  243. u16 device_id;
  244. u16 tag;
  245. u8 cmd_flag;
  246. u8 req_function;
  247. u8 cdb_length;
  248. u8 sg_counts;
  249. u32 data_transfer_length;
  250. u16 request_id;
  251. u16 reserved1;
  252. u8 cdb[MAX_COMMAND_SIZE];
  253. u32 payload[1];
  254. };
  255. /*
  256. * the respond flag for data_payload of the out bound frame
  257. */
  258. #define CL_RSP_FLAG_NODATA 0x0
  259. #define CL_RSP_FLAG_SENSEDATA 0x1
  260. struct mvumi_rsp_frame {
  261. u16 device_id;
  262. u16 tag;
  263. u8 req_status;
  264. u8 rsp_flag; /* Indicates the type of Data_Payload.*/
  265. u16 request_id;
  266. u32 payload[1];
  267. };
  268. struct mvumi_ob_data {
  269. struct list_head list;
  270. unsigned char data[0];
  271. };
  272. struct version_info {
  273. u32 ver_major;
  274. u32 ver_minor;
  275. u32 ver_oem;
  276. u32 ver_build;
  277. };
  278. #define FW_MAX_DELAY 30
  279. #define MVUMI_FW_BUSY (1U << 0)
  280. #define MVUMI_FW_ATTACH (1U << 1)
  281. #define MVUMI_FW_ALLOC (1U << 2)
  282. /*
  283. * State is the state of the MU
  284. */
  285. #define FW_STATE_IDLE 0
  286. #define FW_STATE_STARTING 1
  287. #define FW_STATE_HANDSHAKING 2
  288. #define FW_STATE_STARTED 3
  289. #define FW_STATE_ABORT 4
  290. #define HANDSHAKE_SIGNATURE 0x5A5A5A5AL
  291. #define HANDSHAKE_READYSTATE 0x55AA5AA5L
  292. #define HANDSHAKE_DONESTATE 0x55AAA55AL
  293. /* HandShake Status definition */
  294. #define HS_STATUS_OK 1
  295. #define HS_STATUS_ERR 2
  296. #define HS_STATUS_INVALID 3
  297. /* HandShake State/Cmd definition */
  298. #define HS_S_START 1
  299. #define HS_S_RESET 2
  300. #define HS_S_PAGE_ADDR 3
  301. #define HS_S_QUERY_PAGE 4
  302. #define HS_S_SEND_PAGE 5
  303. #define HS_S_END 6
  304. #define HS_S_ABORT 7
  305. #define HS_PAGE_VERIFY_SIZE 128
  306. #define HS_GET_STATE(a) (a & 0xFFFF)
  307. #define HS_GET_STATUS(a) ((a & 0xFFFF0000) >> 16)
  308. #define HS_SET_STATE(a, b) (a |= (b & 0xFFFF))
  309. #define HS_SET_STATUS(a, b) (a |= ((b & 0xFFFF) << 16))
  310. /* handshake frame */
  311. struct mvumi_hs_frame {
  312. u16 size;
  313. /* host information */
  314. u8 host_type;
  315. u8 reserved_1[1];
  316. struct version_info host_ver; /* bios or driver version */
  317. /* controller information */
  318. u32 system_io_bus;
  319. u32 slot_number;
  320. u32 intr_level;
  321. u32 intr_vector;
  322. /* communication list configuration */
  323. u32 ib_baseaddr_l;
  324. u32 ib_baseaddr_h;
  325. u32 ob_baseaddr_l;
  326. u32 ob_baseaddr_h;
  327. u8 ib_entry_size;
  328. u8 ob_entry_size;
  329. u8 ob_depth;
  330. u8 ib_depth;
  331. /* system time */
  332. u64 seconds_since1970;
  333. };
  334. struct mvumi_hs_header {
  335. u8 page_code;
  336. u8 checksum;
  337. u16 frame_length;
  338. u32 frame_content[1];
  339. };
  340. /*
  341. * the page code type of the handshake header
  342. */
  343. #define HS_PAGE_FIRM_CAP 0x1
  344. #define HS_PAGE_HOST_INFO 0x2
  345. #define HS_PAGE_FIRM_CTL 0x3
  346. #define HS_PAGE_CL_INFO 0x4
  347. #define HS_PAGE_TOTAL 0x5
  348. #define HSP_SIZE(i) sizeof(struct mvumi_hs_page##i)
  349. #define HSP_MAX_SIZE ({ \
  350. int size, m1, m2; \
  351. m1 = max(HSP_SIZE(1), HSP_SIZE(3)); \
  352. m2 = max(HSP_SIZE(2), HSP_SIZE(4)); \
  353. size = max(m1, m2); \
  354. size; \
  355. })
  356. /* The format of the page code for Firmware capability */
  357. struct mvumi_hs_page1 {
  358. u8 pagecode;
  359. u8 checksum;
  360. u16 frame_length;
  361. u16 number_of_ports;
  362. u16 max_devices_support;
  363. u16 max_io_support;
  364. u16 umi_ver;
  365. u32 max_transfer_size;
  366. struct version_info fw_ver;
  367. u8 cl_in_max_entry_size;
  368. u8 cl_out_max_entry_size;
  369. u8 cl_inout_list_depth;
  370. u8 total_pages;
  371. u16 capability;
  372. u16 reserved1;
  373. };
  374. /* The format of the page code for Host information */
  375. struct mvumi_hs_page2 {
  376. u8 pagecode;
  377. u8 checksum;
  378. u16 frame_length;
  379. u8 host_type;
  380. u8 host_cap;
  381. u8 reserved[2];
  382. struct version_info host_ver;
  383. u32 system_io_bus;
  384. u32 slot_number;
  385. u32 intr_level;
  386. u32 intr_vector;
  387. u64 seconds_since1970;
  388. };
  389. /* The format of the page code for firmware control */
  390. struct mvumi_hs_page3 {
  391. u8 pagecode;
  392. u8 checksum;
  393. u16 frame_length;
  394. u16 control;
  395. u8 reserved[2];
  396. u32 host_bufferaddr_l;
  397. u32 host_bufferaddr_h;
  398. u32 host_eventaddr_l;
  399. u32 host_eventaddr_h;
  400. };
  401. struct mvumi_hs_page4 {
  402. u8 pagecode;
  403. u8 checksum;
  404. u16 frame_length;
  405. u32 ib_baseaddr_l;
  406. u32 ib_baseaddr_h;
  407. u32 ob_baseaddr_l;
  408. u32 ob_baseaddr_h;
  409. u8 ib_entry_size;
  410. u8 ob_entry_size;
  411. u8 ob_depth;
  412. u8 ib_depth;
  413. };
  414. struct mvumi_tag {
  415. unsigned short *stack;
  416. unsigned short top;
  417. unsigned short size;
  418. };
  419. struct mvumi_device {
  420. struct list_head list;
  421. struct scsi_device *sdev;
  422. u64 wwid;
  423. u8 dev_type;
  424. int id;
  425. };
  426. struct mvumi_hba {
  427. void *base_addr[MAX_BASE_ADDRESS];
  428. u32 pci_base[MAX_BASE_ADDRESS];
  429. void *mmio;
  430. struct list_head cmd_pool;
  431. struct Scsi_Host *shost;
  432. wait_queue_head_t int_cmd_wait_q;
  433. struct pci_dev *pdev;
  434. unsigned int unique_id;
  435. atomic_t fw_outstanding;
  436. struct mvumi_instance_template *instancet;
  437. void *ib_list;
  438. dma_addr_t ib_list_phys;
  439. void *ib_frame;
  440. dma_addr_t ib_frame_phys;
  441. void *ob_list;
  442. dma_addr_t ob_list_phys;
  443. void *ib_shadow;
  444. dma_addr_t ib_shadow_phys;
  445. void *ob_shadow;
  446. dma_addr_t ob_shadow_phys;
  447. void *handshake_page;
  448. dma_addr_t handshake_page_phys;
  449. unsigned int global_isr;
  450. unsigned int isr_status;
  451. unsigned short max_sge;
  452. unsigned short max_target_id;
  453. unsigned char *target_map;
  454. unsigned int max_io;
  455. unsigned int list_num_io;
  456. unsigned int ib_max_size;
  457. unsigned int ob_max_size;
  458. unsigned int ib_max_size_setting;
  459. unsigned int ob_max_size_setting;
  460. unsigned int max_transfer_size;
  461. unsigned char hba_total_pages;
  462. unsigned char fw_flag;
  463. unsigned char request_id_enabled;
  464. unsigned char eot_flag;
  465. unsigned short hba_capability;
  466. unsigned short io_seq;
  467. unsigned int ib_cur_slot;
  468. unsigned int ob_cur_slot;
  469. unsigned int fw_state;
  470. struct mutex sas_discovery_mutex;
  471. struct list_head ob_data_list;
  472. struct list_head free_ob_list;
  473. struct list_head res_list;
  474. struct list_head waiting_req_list;
  475. struct mvumi_tag tag_pool;
  476. struct mvumi_cmd **tag_cmd;
  477. struct mvumi_hw_regs *regs;
  478. struct mutex device_lock;
  479. struct list_head mhba_dev_list;
  480. struct list_head shost_dev_list;
  481. struct task_struct *dm_thread;
  482. atomic_t pnp_count;
  483. };
  484. struct mvumi_instance_template {
  485. void (*fire_cmd) (struct mvumi_hba *, struct mvumi_cmd *);
  486. void (*enable_intr) (struct mvumi_hba *);
  487. void (*disable_intr) (struct mvumi_hba *);
  488. int (*clear_intr) (void *);
  489. unsigned int (*read_fw_status_reg) (struct mvumi_hba *);
  490. unsigned int (*check_ib_list) (struct mvumi_hba *);
  491. int (*check_ob_list) (struct mvumi_hba *, unsigned int *,
  492. unsigned int *);
  493. int (*reset_host) (struct mvumi_hba *);
  494. };
  495. extern struct timezone sys_tz;
  496. #endif