mthca_dev.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. * $Id: mthca_dev.h 1349 2004-12-16 21:09:43Z roland $
  33. */
  34. #ifndef MTHCA_DEV_H
  35. #define MTHCA_DEV_H
  36. #include <linux/spinlock.h>
  37. #include <linux/kernel.h>
  38. #include <linux/pci.h>
  39. #include <linux/dma-mapping.h>
  40. #include <asm/semaphore.h>
  41. #include "mthca_provider.h"
  42. #include "mthca_doorbell.h"
  43. #define DRV_NAME "ib_mthca"
  44. #define PFX DRV_NAME ": "
  45. #define DRV_VERSION "0.06-pre"
  46. #define DRV_RELDATE "November 8, 2004"
  47. /* Types of supported HCA */
  48. enum {
  49. TAVOR, /* MT23108 */
  50. ARBEL_COMPAT, /* MT25208 in Tavor compat mode */
  51. ARBEL_NATIVE /* MT25208 with extended features */
  52. };
  53. enum {
  54. MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
  55. MTHCA_FLAG_SRQ = 1 << 2,
  56. MTHCA_FLAG_MSI = 1 << 3,
  57. MTHCA_FLAG_MSI_X = 1 << 4,
  58. MTHCA_FLAG_NO_LAM = 1 << 5
  59. };
  60. enum {
  61. MTHCA_MAX_PORTS = 2
  62. };
  63. enum {
  64. MTHCA_EQ_CONTEXT_SIZE = 0x40,
  65. MTHCA_CQ_CONTEXT_SIZE = 0x40,
  66. MTHCA_QP_CONTEXT_SIZE = 0x200,
  67. MTHCA_RDB_ENTRY_SIZE = 0x20,
  68. MTHCA_AV_SIZE = 0x20,
  69. MTHCA_MGM_ENTRY_SIZE = 0x40,
  70. /* Arbel FW gives us these, but we need them for Tavor */
  71. MTHCA_MPT_ENTRY_SIZE = 0x40,
  72. MTHCA_MTT_SEG_SIZE = 0x40,
  73. };
  74. enum {
  75. MTHCA_EQ_CMD,
  76. MTHCA_EQ_ASYNC,
  77. MTHCA_EQ_COMP,
  78. MTHCA_NUM_EQ
  79. };
  80. enum {
  81. MTHCA_OPCODE_NOP = 0x00,
  82. MTHCA_OPCODE_RDMA_WRITE = 0x08,
  83. MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,
  84. MTHCA_OPCODE_SEND = 0x0a,
  85. MTHCA_OPCODE_SEND_IMM = 0x0b,
  86. MTHCA_OPCODE_RDMA_READ = 0x10,
  87. MTHCA_OPCODE_ATOMIC_CS = 0x11,
  88. MTHCA_OPCODE_ATOMIC_FA = 0x12,
  89. MTHCA_OPCODE_BIND_MW = 0x18,
  90. MTHCA_OPCODE_INVALID = 0xff
  91. };
  92. struct mthca_cmd {
  93. int use_events;
  94. struct semaphore hcr_sem;
  95. struct semaphore poll_sem;
  96. struct semaphore event_sem;
  97. int max_cmds;
  98. spinlock_t context_lock;
  99. int free_head;
  100. struct mthca_cmd_context *context;
  101. u16 token_mask;
  102. };
  103. struct mthca_limits {
  104. int num_ports;
  105. int vl_cap;
  106. int mtu_cap;
  107. int gid_table_len;
  108. int pkey_table_len;
  109. int local_ca_ack_delay;
  110. int num_uars;
  111. int max_sg;
  112. int num_qps;
  113. int reserved_qps;
  114. int num_srqs;
  115. int reserved_srqs;
  116. int num_eecs;
  117. int reserved_eecs;
  118. int num_cqs;
  119. int reserved_cqs;
  120. int num_eqs;
  121. int reserved_eqs;
  122. int num_mpts;
  123. int num_mtt_segs;
  124. int reserved_mtts;
  125. int reserved_mrws;
  126. int reserved_uars;
  127. int num_mgms;
  128. int num_amgms;
  129. int reserved_mcgs;
  130. int num_pds;
  131. int reserved_pds;
  132. };
  133. struct mthca_alloc {
  134. u32 last;
  135. u32 top;
  136. u32 max;
  137. u32 mask;
  138. spinlock_t lock;
  139. unsigned long *table;
  140. };
  141. struct mthca_array {
  142. struct {
  143. void **page;
  144. int used;
  145. } *page_list;
  146. };
  147. struct mthca_uar_table {
  148. struct mthca_alloc alloc;
  149. u64 uarc_base;
  150. int uarc_size;
  151. };
  152. struct mthca_pd_table {
  153. struct mthca_alloc alloc;
  154. };
  155. struct mthca_mr_table {
  156. struct mthca_alloc mpt_alloc;
  157. int max_mtt_order;
  158. unsigned long **mtt_buddy;
  159. u64 mtt_base;
  160. struct mthca_icm_table *mtt_table;
  161. struct mthca_icm_table *mpt_table;
  162. };
  163. struct mthca_eq_table {
  164. struct mthca_alloc alloc;
  165. void __iomem *clr_int;
  166. u32 clr_mask;
  167. u32 arm_mask;
  168. struct mthca_eq eq[MTHCA_NUM_EQ];
  169. u64 icm_virt;
  170. struct page *icm_page;
  171. dma_addr_t icm_dma;
  172. int have_irq;
  173. u8 inta_pin;
  174. };
  175. struct mthca_cq_table {
  176. struct mthca_alloc alloc;
  177. spinlock_t lock;
  178. struct mthca_array cq;
  179. struct mthca_icm_table *table;
  180. };
  181. struct mthca_qp_table {
  182. struct mthca_alloc alloc;
  183. u32 rdb_base;
  184. int rdb_shift;
  185. int sqp_start;
  186. spinlock_t lock;
  187. struct mthca_array qp;
  188. struct mthca_icm_table *qp_table;
  189. struct mthca_icm_table *eqp_table;
  190. };
  191. struct mthca_av_table {
  192. struct pci_pool *pool;
  193. int num_ddr_avs;
  194. u64 ddr_av_base;
  195. void __iomem *av_map;
  196. struct mthca_alloc alloc;
  197. };
  198. struct mthca_mcg_table {
  199. struct semaphore sem;
  200. struct mthca_alloc alloc;
  201. struct mthca_icm_table *table;
  202. };
  203. struct mthca_dev {
  204. struct ib_device ib_dev;
  205. struct pci_dev *pdev;
  206. int hca_type;
  207. unsigned long mthca_flags;
  208. unsigned long device_cap_flags;
  209. u32 rev_id;
  210. /* firmware info */
  211. u64 fw_ver;
  212. union {
  213. struct {
  214. u64 fw_start;
  215. u64 fw_end;
  216. } tavor;
  217. struct {
  218. u64 clr_int_base;
  219. u64 eq_arm_base;
  220. u64 eq_set_ci_base;
  221. struct mthca_icm *fw_icm;
  222. struct mthca_icm *aux_icm;
  223. u16 fw_pages;
  224. } arbel;
  225. } fw;
  226. u64 ddr_start;
  227. u64 ddr_end;
  228. MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
  229. struct semaphore cap_mask_mutex;
  230. void __iomem *hcr;
  231. void __iomem *kar;
  232. void __iomem *clr_base;
  233. union {
  234. struct {
  235. void __iomem *ecr_base;
  236. } tavor;
  237. struct {
  238. void __iomem *eq_arm;
  239. void __iomem *eq_set_ci_base;
  240. } arbel;
  241. } eq_regs;
  242. struct mthca_cmd cmd;
  243. struct mthca_limits limits;
  244. struct mthca_uar_table uar_table;
  245. struct mthca_pd_table pd_table;
  246. struct mthca_mr_table mr_table;
  247. struct mthca_eq_table eq_table;
  248. struct mthca_cq_table cq_table;
  249. struct mthca_qp_table qp_table;
  250. struct mthca_av_table av_table;
  251. struct mthca_mcg_table mcg_table;
  252. struct mthca_uar driver_uar;
  253. struct mthca_db_table *db_tab;
  254. struct mthca_pd driver_pd;
  255. struct mthca_mr driver_mr;
  256. struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2];
  257. struct ib_ah *sm_ah[MTHCA_MAX_PORTS];
  258. spinlock_t sm_lock;
  259. };
  260. #define mthca_dbg(mdev, format, arg...) \
  261. dev_dbg(&mdev->pdev->dev, format, ## arg)
  262. #define mthca_err(mdev, format, arg...) \
  263. dev_err(&mdev->pdev->dev, format, ## arg)
  264. #define mthca_info(mdev, format, arg...) \
  265. dev_info(&mdev->pdev->dev, format, ## arg)
  266. #define mthca_warn(mdev, format, arg...) \
  267. dev_warn(&mdev->pdev->dev, format, ## arg)
  268. extern void __buggy_use_of_MTHCA_GET(void);
  269. extern void __buggy_use_of_MTHCA_PUT(void);
  270. #define MTHCA_GET(dest, source, offset) \
  271. do { \
  272. void *__p = (char *) (source) + (offset); \
  273. switch (sizeof (dest)) { \
  274. case 1: (dest) = *(u8 *) __p; break; \
  275. case 2: (dest) = be16_to_cpup(__p); break; \
  276. case 4: (dest) = be32_to_cpup(__p); break; \
  277. case 8: (dest) = be64_to_cpup(__p); break; \
  278. default: __buggy_use_of_MTHCA_GET(); \
  279. } \
  280. } while (0)
  281. #define MTHCA_PUT(dest, source, offset) \
  282. do { \
  283. __typeof__(source) *__p = \
  284. (__typeof__(source) *) ((char *) (dest) + (offset)); \
  285. switch (sizeof(source)) { \
  286. case 1: *__p = (source); break; \
  287. case 2: *__p = cpu_to_be16(source); break; \
  288. case 4: *__p = cpu_to_be32(source); break; \
  289. case 8: *__p = cpu_to_be64(source); break; \
  290. default: __buggy_use_of_MTHCA_PUT(); \
  291. } \
  292. } while (0)
  293. int mthca_reset(struct mthca_dev *mdev);
  294. u32 mthca_alloc(struct mthca_alloc *alloc);
  295. void mthca_free(struct mthca_alloc *alloc, u32 obj);
  296. int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
  297. u32 reserved);
  298. void mthca_alloc_cleanup(struct mthca_alloc *alloc);
  299. void *mthca_array_get(struct mthca_array *array, int index);
  300. int mthca_array_set(struct mthca_array *array, int index, void *value);
  301. void mthca_array_clear(struct mthca_array *array, int index);
  302. int mthca_array_init(struct mthca_array *array, int nent);
  303. void mthca_array_cleanup(struct mthca_array *array, int nent);
  304. int mthca_init_uar_table(struct mthca_dev *dev);
  305. int mthca_init_pd_table(struct mthca_dev *dev);
  306. int mthca_init_mr_table(struct mthca_dev *dev);
  307. int mthca_init_eq_table(struct mthca_dev *dev);
  308. int mthca_init_cq_table(struct mthca_dev *dev);
  309. int mthca_init_qp_table(struct mthca_dev *dev);
  310. int mthca_init_av_table(struct mthca_dev *dev);
  311. int mthca_init_mcg_table(struct mthca_dev *dev);
  312. void mthca_cleanup_uar_table(struct mthca_dev *dev);
  313. void mthca_cleanup_pd_table(struct mthca_dev *dev);
  314. void mthca_cleanup_mr_table(struct mthca_dev *dev);
  315. void mthca_cleanup_eq_table(struct mthca_dev *dev);
  316. void mthca_cleanup_cq_table(struct mthca_dev *dev);
  317. void mthca_cleanup_qp_table(struct mthca_dev *dev);
  318. void mthca_cleanup_av_table(struct mthca_dev *dev);
  319. void mthca_cleanup_mcg_table(struct mthca_dev *dev);
  320. int mthca_register_device(struct mthca_dev *dev);
  321. void mthca_unregister_device(struct mthca_dev *dev);
  322. int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
  323. void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
  324. int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd);
  325. void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
  326. int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
  327. u32 access, struct mthca_mr *mr);
  328. int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
  329. u64 *buffer_list, int buffer_size_shift,
  330. int list_len, u64 iova, u64 total_size,
  331. u32 access, struct mthca_mr *mr);
  332. void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr);
  333. int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt);
  334. void mthca_unmap_eq_icm(struct mthca_dev *dev);
  335. int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
  336. struct ib_wc *entry);
  337. int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
  338. int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
  339. int mthca_init_cq(struct mthca_dev *dev, int nent,
  340. struct mthca_cq *cq);
  341. void mthca_free_cq(struct mthca_dev *dev,
  342. struct mthca_cq *cq);
  343. void mthca_cq_event(struct mthca_dev *dev, u32 cqn);
  344. void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn);
  345. void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
  346. enum ib_event_type event_type);
  347. int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask);
  348. int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  349. struct ib_send_wr **bad_wr);
  350. int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  351. struct ib_recv_wr **bad_wr);
  352. int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  353. struct ib_send_wr **bad_wr);
  354. int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  355. struct ib_recv_wr **bad_wr);
  356. int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
  357. int index, int *dbd, u32 *new_wqe);
  358. int mthca_alloc_qp(struct mthca_dev *dev,
  359. struct mthca_pd *pd,
  360. struct mthca_cq *send_cq,
  361. struct mthca_cq *recv_cq,
  362. enum ib_qp_type type,
  363. enum ib_sig_type send_policy,
  364. struct mthca_qp *qp);
  365. int mthca_alloc_sqp(struct mthca_dev *dev,
  366. struct mthca_pd *pd,
  367. struct mthca_cq *send_cq,
  368. struct mthca_cq *recv_cq,
  369. enum ib_sig_type send_policy,
  370. int qpn,
  371. int port,
  372. struct mthca_sqp *sqp);
  373. void mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp);
  374. int mthca_create_ah(struct mthca_dev *dev,
  375. struct mthca_pd *pd,
  376. struct ib_ah_attr *ah_attr,
  377. struct mthca_ah *ah);
  378. int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
  379. int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
  380. struct ib_ud_header *header);
  381. int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
  382. int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
  383. int mthca_process_mad(struct ib_device *ibdev,
  384. int mad_flags,
  385. u8 port_num,
  386. struct ib_wc *in_wc,
  387. struct ib_grh *in_grh,
  388. struct ib_mad *in_mad,
  389. struct ib_mad *out_mad);
  390. int mthca_create_agents(struct mthca_dev *dev);
  391. void mthca_free_agents(struct mthca_dev *dev);
  392. static inline struct mthca_dev *to_mdev(struct ib_device *ibdev)
  393. {
  394. return container_of(ibdev, struct mthca_dev, ib_dev);
  395. }
  396. #endif /* MTHCA_DEV_H */