hptiop.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * HighPoint RR3xxx/4xxx controller driver for Linux
  3. * Copyright (C) 2006-2009 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. #define MVIOP_MU_QUEUE_ADDR_HOST_MASK (~(0x1full))
  71. #define MVIOP_MU_QUEUE_ADDR_HOST_BIT 4
  72. #define MVIOP_MU_QUEUE_ADDR_IOP_HIGH32 0xffffffff
  73. #define MVIOP_MU_QUEUE_REQUEST_RESULT_BIT 1
  74. #define MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT 2
  75. #define MVIOP_MU_INBOUND_INT_MSG 1
  76. #define MVIOP_MU_INBOUND_INT_POSTQUEUE 2
  77. #define MVIOP_MU_OUTBOUND_INT_MSG 1
  78. #define MVIOP_MU_OUTBOUND_INT_POSTQUEUE 2
  79. enum hpt_iopmu_message {
  80. /* host-to-iop messages */
  81. IOPMU_INBOUND_MSG0_NOP = 0,
  82. IOPMU_INBOUND_MSG0_RESET,
  83. IOPMU_INBOUND_MSG0_FLUSH,
  84. IOPMU_INBOUND_MSG0_SHUTDOWN,
  85. IOPMU_INBOUND_MSG0_STOP_BACKGROUND_TASK,
  86. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK,
  87. IOPMU_INBOUND_MSG0_MAX = 0xff,
  88. /* iop-to-host messages */
  89. IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_0 = 0x100,
  90. IOPMU_OUTBOUND_MSG0_REGISTER_DEVICE_MAX = 0x1ff,
  91. IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_0 = 0x200,
  92. IOPMU_OUTBOUND_MSG0_UNREGISTER_DEVICE_MAX = 0x2ff,
  93. IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_0 = 0x300,
  94. IOPMU_OUTBOUND_MSG0_REVALIDATE_DEVICE_MAX = 0x3ff,
  95. };
  96. struct hpt_iop_request_header {
  97. __le32 size;
  98. __le32 type;
  99. __le32 flags;
  100. __le32 result;
  101. __le32 context; /* host context */
  102. __le32 context_hi32;
  103. };
  104. #define IOP_REQUEST_FLAG_SYNC_REQUEST 1
  105. #define IOP_REQUEST_FLAG_BIST_REQUEST 2
  106. #define IOP_REQUEST_FLAG_REMAPPED 4
  107. #define IOP_REQUEST_FLAG_OUTPUT_CONTEXT 8
  108. enum hpt_iop_request_type {
  109. IOP_REQUEST_TYPE_GET_CONFIG = 0,
  110. IOP_REQUEST_TYPE_SET_CONFIG,
  111. IOP_REQUEST_TYPE_BLOCK_COMMAND,
  112. IOP_REQUEST_TYPE_SCSI_COMMAND,
  113. IOP_REQUEST_TYPE_IOCTL_COMMAND,
  114. IOP_REQUEST_TYPE_MAX
  115. };
  116. enum hpt_iop_result_type {
  117. IOP_RESULT_PENDING = 0,
  118. IOP_RESULT_SUCCESS,
  119. IOP_RESULT_FAIL,
  120. IOP_RESULT_BUSY,
  121. IOP_RESULT_RESET,
  122. IOP_RESULT_INVALID_REQUEST,
  123. IOP_RESULT_BAD_TARGET,
  124. IOP_RESULT_CHECK_CONDITION,
  125. };
  126. struct hpt_iop_request_get_config {
  127. struct hpt_iop_request_header header;
  128. __le32 interface_version;
  129. __le32 firmware_version;
  130. __le32 max_requests;
  131. __le32 request_size;
  132. __le32 max_sg_count;
  133. __le32 data_transfer_length;
  134. __le32 alignment_mask;
  135. __le32 max_devices;
  136. __le32 sdram_size;
  137. };
  138. struct hpt_iop_request_set_config {
  139. struct hpt_iop_request_header header;
  140. __le32 iop_id;
  141. __le16 vbus_id;
  142. __le16 max_host_request_size;
  143. __le32 reserve[6];
  144. };
  145. struct hpt_iopsg {
  146. __le32 size;
  147. __le32 eot; /* non-zero: end of table */
  148. __le64 pci_address;
  149. };
  150. struct hpt_iop_request_block_command {
  151. struct hpt_iop_request_header header;
  152. u8 channel;
  153. u8 target;
  154. u8 lun;
  155. u8 pad1;
  156. __le16 command; /* IOP_BLOCK_COMMAND_{READ,WRITE} */
  157. __le16 sectors;
  158. __le64 lba;
  159. struct hpt_iopsg sg_list[1];
  160. };
  161. #define IOP_BLOCK_COMMAND_READ 1
  162. #define IOP_BLOCK_COMMAND_WRITE 2
  163. #define IOP_BLOCK_COMMAND_VERIFY 3
  164. #define IOP_BLOCK_COMMAND_FLUSH 4
  165. #define IOP_BLOCK_COMMAND_SHUTDOWN 5
  166. struct hpt_iop_request_scsi_command {
  167. struct hpt_iop_request_header header;
  168. u8 channel;
  169. u8 target;
  170. u8 lun;
  171. u8 pad1;
  172. u8 cdb[16];
  173. __le32 dataxfer_length;
  174. struct hpt_iopsg sg_list[1];
  175. };
  176. struct hpt_iop_request_ioctl_command {
  177. struct hpt_iop_request_header header;
  178. __le32 ioctl_code;
  179. __le32 inbuf_size;
  180. __le32 outbuf_size;
  181. __le32 bytes_returned;
  182. u8 buf[1];
  183. /* out data should be put at buf[(inbuf_size+3)&~3] */
  184. };
  185. #define HPTIOP_MAX_REQUESTS 256u
  186. struct hptiop_request {
  187. struct hptiop_request *next;
  188. void *req_virt;
  189. u32 req_shifted_phy;
  190. struct scsi_cmnd *scp;
  191. int index;
  192. };
  193. struct hpt_scsi_pointer {
  194. int mapped;
  195. int sgcnt;
  196. dma_addr_t dma_handle;
  197. };
  198. #define HPT_SCP(scp) ((struct hpt_scsi_pointer *)&(scp)->SCp)
  199. struct hptiop_hba {
  200. struct hptiop_adapter_ops *ops;
  201. union {
  202. struct {
  203. struct hpt_iopmu_itl __iomem *iop;
  204. void __iomem *plx;
  205. } itl;
  206. struct {
  207. struct hpt_iopmv_regs *regs;
  208. struct hpt_iopmu_mv __iomem *mu;
  209. void *internal_req;
  210. dma_addr_t internal_req_phy;
  211. } mv;
  212. } u;
  213. struct Scsi_Host *host;
  214. struct pci_dev *pcidev;
  215. /* IOP config info */
  216. u32 interface_version;
  217. u32 firmware_version;
  218. u32 sdram_size;
  219. u32 max_devices;
  220. u32 max_requests;
  221. u32 max_request_size;
  222. u32 max_sg_descriptors;
  223. u32 req_size; /* host-allocated request buffer size */
  224. u32 iopintf_v2: 1;
  225. u32 initialized: 1;
  226. u32 msg_done: 1;
  227. struct hptiop_request * req_list;
  228. struct hptiop_request reqs[HPTIOP_MAX_REQUESTS];
  229. /* used to free allocated dma area */
  230. void *dma_coherent;
  231. dma_addr_t dma_coherent_handle;
  232. atomic_t reset_count;
  233. atomic_t resetting;
  234. wait_queue_head_t reset_wq;
  235. wait_queue_head_t ioctl_wq;
  236. };
  237. struct hpt_ioctl_k {
  238. struct hptiop_hba * hba;
  239. u32 ioctl_code;
  240. u32 inbuf_size;
  241. u32 outbuf_size;
  242. void *inbuf;
  243. void *outbuf;
  244. u32 *bytes_returned;
  245. void (*done)(struct hpt_ioctl_k *);
  246. int result; /* HPT_IOCTL_RESULT_ */
  247. };
  248. struct hptiop_adapter_ops {
  249. int (*iop_wait_ready)(struct hptiop_hba *hba, u32 millisec);
  250. int (*internal_memalloc)(struct hptiop_hba *hba);
  251. int (*internal_memfree)(struct hptiop_hba *hba);
  252. int (*map_pci_bar)(struct hptiop_hba *hba);
  253. void (*unmap_pci_bar)(struct hptiop_hba *hba);
  254. void (*enable_intr)(struct hptiop_hba *hba);
  255. void (*disable_intr)(struct hptiop_hba *hba);
  256. int (*get_config)(struct hptiop_hba *hba,
  257. struct hpt_iop_request_get_config *config);
  258. int (*set_config)(struct hptiop_hba *hba,
  259. struct hpt_iop_request_set_config *config);
  260. int (*iop_intr)(struct hptiop_hba *hba);
  261. void (*post_msg)(struct hptiop_hba *hba, u32 msg);
  262. void (*post_req)(struct hptiop_hba *hba, struct hptiop_request *_req);
  263. };
  264. #define HPT_IOCTL_RESULT_OK 0
  265. #define HPT_IOCTL_RESULT_FAILED (-1)
  266. #if 0
  267. #define dprintk(fmt, args...) do { printk(fmt, ##args); } while(0)
  268. #else
  269. #define dprintk(fmt, args...)
  270. #endif
  271. #endif