mvumi.h 12 KB

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