hptiop.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * HighPoint RR3xxx/4xxx controller driver for Linux
  3. * Copyright (C) 2006-2015 HighPoint Technologies, Inc. All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * Please report bugs/comments/suggestions to linux@highpoint-tech.com
  15. *
  16. * For more information, visit http://www.highpoint-tech.com
  17. */
  18. #ifndef _HPTIOP_H_
  19. #define _HPTIOP_H_
  20. struct hpt_iopmu_itl {
  21. __le32 resrved0[4];
  22. __le32 inbound_msgaddr0;
  23. __le32 inbound_msgaddr1;
  24. __le32 outbound_msgaddr0;
  25. __le32 outbound_msgaddr1;
  26. __le32 inbound_doorbell;
  27. __le32 inbound_intstatus;
  28. __le32 inbound_intmask;
  29. __le32 outbound_doorbell;
  30. __le32 outbound_intstatus;
  31. __le32 outbound_intmask;
  32. __le32 reserved1[2];
  33. __le32 inbound_queue;
  34. __le32 outbound_queue;
  35. };
  36. #define IOPMU_QUEUE_EMPTY 0xffffffff
  37. #define IOPMU_QUEUE_MASK_HOST_BITS 0xf0000000
  38. #define IOPMU_QUEUE_ADDR_HOST_BIT 0x80000000
  39. #define IOPMU_QUEUE_REQUEST_SIZE_BIT 0x40000000
  40. #define IOPMU_QUEUE_REQUEST_RESULT_BIT 0x40000000
  41. #define IOPMU_OUTBOUND_INT_MSG0 1
  42. #define IOPMU_OUTBOUND_INT_MSG1 2
  43. #define IOPMU_OUTBOUND_INT_DOORBELL 4
  44. #define IOPMU_OUTBOUND_INT_POSTQUEUE 8
  45. #define IOPMU_OUTBOUND_INT_PCI 0x10
  46. #define IOPMU_INBOUND_INT_MSG0 1
  47. #define IOPMU_INBOUND_INT_MSG1 2
  48. #define IOPMU_INBOUND_INT_DOORBELL 4
  49. #define IOPMU_INBOUND_INT_ERROR 8
  50. #define IOPMU_INBOUND_INT_POSTQUEUE 0x10
  51. #define MVIOP_QUEUE_LEN 512
  52. struct hpt_iopmu_mv {
  53. __le32 inbound_head;
  54. __le32 inbound_tail;
  55. __le32 outbound_head;
  56. __le32 outbound_tail;
  57. __le32 inbound_msg;
  58. __le32 outbound_msg;
  59. __le32 reserve[10];
  60. __le64 inbound_q[MVIOP_QUEUE_LEN];
  61. __le64 outbound_q[MVIOP_QUEUE_LEN];
  62. };
  63. struct hpt_iopmv_regs {
  64. __le32 reserved[0x20400 / 4];
  65. __le32 inbound_doorbell;
  66. __le32 inbound_intmask;
  67. __le32 outbound_doorbell;
  68. __le32 outbound_intmask;
  69. };
  70. #pragma pack(1)
  71. struct hpt_iopmu_mvfrey {
  72. __le32 reserved0[(0x4000 - 0) / 4];
  73. __le32 inbound_base;
  74. __le32 inbound_base_high;
  75. __le32 reserved1[(0x4018 - 0x4008) / 4];
  76. __le32 inbound_write_ptr;
  77. __le32 reserved2[(0x402c - 0x401c) / 4];
  78. __le32 inbound_conf_ctl;
  79. __le32 reserved3[(0x4050 - 0x4030) / 4];
  80. __le32 outbound_base;
  81. __le32 outbound_base_high;
  82. __le32 outbound_shadow_base;
  83. __le32 outbound_shadow_base_high;
  84. __le32 reserved4[(0x4088 - 0x4060) / 4];
  85. __le32 isr_cause;
  86. __le32 isr_enable;
  87. __le32 reserved5[(0x1020c - 0x4090) / 4];
  88. __le32 pcie_f0_int_enable;
  89. __le32 reserved6[(0x10400 - 0x10210) / 4];
  90. __le32 f0_to_cpu_msg_a;
  91. __le32 reserved7[(0x10420 - 0x10404) / 4];
  92. __le32 cpu_to_f0_msg_a;
  93. __le32 reserved8[(0x10480 - 0x10424) / 4];
  94. __le32 f0_doorbell;
  95. __le32 f0_doorbell_enable;
  96. };
  97. struct mvfrey_inlist_entry {
  98. dma_addr_t addr;
  99. __le32 intrfc_len;
  100. __le32 reserved;
  101. };
  102. struct mvfrey_outlist_entry {
  103. __le32 val;
  104. };
  105. #pragma pack()
  106. #define MVIOP_MU_QUEUE_ADDR_HOST_MASK (~(0x1full))
  107. #define MVIOP_MU_QUEUE_ADDR_HOST_BIT 4
  108. #define MVIOP_MU_QUEUE_ADDR_IOP_HIGH32 0xffffffff
  109. #define MVIOP_MU_QUEUE_REQUEST_RESULT_BIT 1
  110. #define MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT 2
  111. #define MVIOP_MU_INBOUND_INT_MSG 1
  112. #define MVIOP_MU_INBOUND_INT_POSTQUEUE 2
  113. #define MVIOP_MU_OUTBOUND_INT_MSG 1
  114. #define MVIOP_MU_OUTBOUND_INT_POSTQUEUE 2
  115. #define CL_POINTER_TOGGLE 0x00004000
  116. #define CPU_TO_F0_DRBL_MSG_BIT 0x02000000
  117. enum hpt_iopmu_message {
  118. /* host-to-iop messages */
  119. IOPMU_INBOUND_MSG0_NOP = 0,
  120. IOPMU_INBOUND_MSG0_RESET,
  121. IOPMU_INBOUND_MSG0_FLUSH,
  122. IOPMU_INBOUND_MSG0_SHUTDOWN,
  123. IOPMU_INBOUND_MSG0_STOP_BACKGROUND_TASK,
  124. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK,
  125. IOPMU_INBOUND_MSG0_RESET_COMM,
  126. IOPMU_INBOUND_MSG0_MAX = 0xff,
  127. /* iop-to-host messages */
  128. IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_0 = 0x100,
  129. IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_MAX = 0x1ff,
  130. IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_0 = 0x200,
  131. IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_MAX = 0x2ff,
  132. IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_0 = 0x300,
  133. IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_MAX = 0x3ff,
  134. };
  135. struct hpt_iop_request_header {
  136. __le32 size;
  137. __le32 type;
  138. __le32 flags;
  139. __le32 result;
  140. __le32 context; /* host context */
  141. __le32 context_hi32;
  142. };
  143. #define IOP_REQUEST_FLAG_SYNC_REQUEST 1
  144. #define IOP_REQUEST_FLAG_BIST_REQUEST 2
  145. #define IOP_REQUEST_FLAG_REMAPPED 4
  146. #define IOP_REQUEST_FLAG_OUTPUT_CONTEXT 8
  147. #define IOP_REQUEST_FLAG_ADDR_BITS 0x40 /* flags[31:16] is phy_addr[47:32] */
  148. enum hpt_iop_request_type {
  149. IOP_REQUEST_TYPE_GET_CONFIG = 0,
  150. IOP_REQUEST_TYPE_SET_CONFIG,
  151. IOP_REQUEST_TYPE_BLOCK_COMMAND,
  152. IOP_REQUEST_TYPE_SCSI_COMMAND,
  153. IOP_REQUEST_TYPE_IOCTL_COMMAND,
  154. IOP_REQUEST_TYPE_MAX
  155. };
  156. enum hpt_iop_result_type {
  157. IOP_RESULT_PENDING = 0,
  158. IOP_RESULT_SUCCESS,
  159. IOP_RESULT_FAIL,
  160. IOP_RESULT_BUSY,
  161. IOP_RESULT_RESET,
  162. IOP_RESULT_INVALID_REQUEST,
  163. IOP_RESULT_BAD_TARGET,
  164. IOP_RESULT_CHECK_CONDITION,
  165. };
  166. struct hpt_iop_request_get_config {
  167. struct hpt_iop_request_header header;
  168. __le32 interface_version;
  169. __le32 firmware_version;
  170. __le32 max_requests;
  171. __le32 request_size;
  172. __le32 max_sg_count;
  173. __le32 data_transfer_length;
  174. __le32 alignment_mask;
  175. __le32 max_devices;
  176. __le32 sdram_size;
  177. };
  178. struct hpt_iop_request_set_config {
  179. struct hpt_iop_request_header header;
  180. __le32 iop_id;
  181. __le16 vbus_id;
  182. __le16 max_host_request_size;
  183. __le32 reserve[6];
  184. };
  185. struct hpt_iopsg {
  186. __le32 size;
  187. __le32 eot; /* non-zero: end of table */
  188. __le64 pci_address;
  189. };
  190. struct hpt_iop_request_block_command {
  191. struct hpt_iop_request_header header;
  192. u8 channel;
  193. u8 target;
  194. u8 lun;
  195. u8 pad1;
  196. __le16 command; /* IOP_BLOCK_COMMAND_{READ,WRITE} */
  197. __le16 sectors;
  198. __le64 lba;
  199. struct hpt_iopsg sg_list[1];
  200. };
  201. #define IOP_BLOCK_COMMAND_READ 1
  202. #define IOP_BLOCK_COMMAND_WRITE 2
  203. #define IOP_BLOCK_COMMAND_VERIFY 3
  204. #define IOP_BLOCK_COMMAND_FLUSH 4
  205. #define IOP_BLOCK_COMMAND_SHUTDOWN 5
  206. struct hpt_iop_request_scsi_command {
  207. struct hpt_iop_request_header header;
  208. u8 channel;
  209. u8 target;
  210. u8 lun;
  211. u8 pad1;
  212. u8 cdb[16];
  213. __le32 dataxfer_length;
  214. struct hpt_iopsg sg_list[1];
  215. };
  216. struct hpt_iop_request_ioctl_command {
  217. struct hpt_iop_request_header header;
  218. __le32 ioctl_code;
  219. __le32 inbuf_size;
  220. __le32 outbuf_size;
  221. __le32 bytes_returned;
  222. u8 buf[1];
  223. /* out data should be put at buf[(inbuf_size+3)&~3] */
  224. };
  225. #define HPTIOP_MAX_REQUESTS 256u
  226. struct hptiop_request {
  227. struct hptiop_request *next;
  228. void *req_virt;
  229. u32 req_shifted_phy;
  230. struct scsi_cmnd *scp;
  231. int index;
  232. };
  233. struct hpt_scsi_pointer {
  234. int mapped;
  235. int sgcnt;
  236. dma_addr_t dma_handle;
  237. };
  238. #define HPT_SCP(scp) ((struct hpt_scsi_pointer *)&(scp)->SCp)
  239. enum hptiop_family {
  240. UNKNOWN_BASED_IOP,
  241. INTEL_BASED_IOP,
  242. MV_BASED_IOP,
  243. MVFREY_BASED_IOP
  244. } ;
  245. struct hptiop_hba {
  246. struct hptiop_adapter_ops *ops;
  247. union {
  248. struct {
  249. struct hpt_iopmu_itl __iomem *iop;
  250. void __iomem *plx;
  251. } itl;
  252. struct {
  253. struct hpt_iopmv_regs *regs;
  254. struct hpt_iopmu_mv __iomem *mu;
  255. void *internal_req;
  256. dma_addr_t internal_req_phy;
  257. } mv;
  258. struct {
  259. struct hpt_iop_request_get_config __iomem *config;
  260. struct hpt_iopmu_mvfrey __iomem *mu;
  261. int internal_mem_size;
  262. struct hptiop_request internal_req;
  263. int list_count;
  264. struct mvfrey_inlist_entry *inlist;
  265. dma_addr_t inlist_phy;
  266. __le32 inlist_wptr;
  267. struct mvfrey_outlist_entry *outlist;
  268. dma_addr_t outlist_phy;
  269. __le32 *outlist_cptr; /* copy pointer shadow */
  270. dma_addr_t outlist_cptr_phy;
  271. __le32 outlist_rptr;
  272. } mvfrey;
  273. } u;
  274. struct Scsi_Host *host;
  275. struct pci_dev *pcidev;
  276. /* IOP config info */
  277. u32 interface_version;
  278. u32 firmware_version;
  279. u32 sdram_size;
  280. u32 max_devices;
  281. u32 max_requests;
  282. u32 max_request_size;
  283. u32 max_sg_descriptors;
  284. u32 req_size; /* host-allocated request buffer size */
  285. u32 iopintf_v2: 1;
  286. u32 initialized: 1;
  287. u32 msg_done: 1;
  288. struct hptiop_request * req_list;
  289. struct hptiop_request reqs[HPTIOP_MAX_REQUESTS];
  290. /* used to free allocated dma area */
  291. void *dma_coherent[HPTIOP_MAX_REQUESTS];
  292. dma_addr_t dma_coherent_handle[HPTIOP_MAX_REQUESTS];
  293. atomic_t reset_count;
  294. atomic_t resetting;
  295. wait_queue_head_t reset_wq;
  296. wait_queue_head_t ioctl_wq;
  297. };
  298. struct hpt_ioctl_k {
  299. struct hptiop_hba * hba;
  300. u32 ioctl_code;
  301. u32 inbuf_size;
  302. u32 outbuf_size;
  303. void *inbuf;
  304. void *outbuf;
  305. u32 *bytes_returned;
  306. void (*done)(struct hpt_ioctl_k *);
  307. int result; /* HPT_IOCTL_RESULT_ */
  308. };
  309. struct hptiop_adapter_ops {
  310. enum hptiop_family family;
  311. int (*iop_wait_ready)(struct hptiop_hba *hba, u32 millisec);
  312. int (*internal_memalloc)(struct hptiop_hba *hba);
  313. int (*internal_memfree)(struct hptiop_hba *hba);
  314. int (*map_pci_bar)(struct hptiop_hba *hba);
  315. void (*unmap_pci_bar)(struct hptiop_hba *hba);
  316. void (*enable_intr)(struct hptiop_hba *hba);
  317. void (*disable_intr)(struct hptiop_hba *hba);
  318. int (*get_config)(struct hptiop_hba *hba,
  319. struct hpt_iop_request_get_config *config);
  320. int (*set_config)(struct hptiop_hba *hba,
  321. struct hpt_iop_request_set_config *config);
  322. int (*iop_intr)(struct hptiop_hba *hba);
  323. void (*post_msg)(struct hptiop_hba *hba, u32 msg);
  324. void (*post_req)(struct hptiop_hba *hba, struct hptiop_request *_req);
  325. int hw_dma_bit_mask;
  326. int (*reset_comm)(struct hptiop_hba *hba);
  327. __le64 host_phy_flag;
  328. };
  329. #define HPT_IOCTL_RESULT_OK 0
  330. #define HPT_IOCTL_RESULT_FAILED (-1)
  331. #if 0
  332. #define dprintk(fmt, args...) do { printk(fmt, ##args); } while(0)
  333. #else
  334. #define dprintk(fmt, args...)
  335. #endif
  336. #endif