mlx4.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
  5. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  6. * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
  7. *
  8. * This software is available to you under a choice of one of two
  9. * licenses. You may choose to be licensed under the terms of the GNU
  10. * General Public License (GPL) Version 2, available from the file
  11. * COPYING in the main directory of this source tree, or the
  12. * OpenIB.org BSD license below:
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials
  25. * provided with the distribution.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  31. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  32. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34. * SOFTWARE.
  35. */
  36. #ifndef MLX4_H
  37. #define MLX4_H
  38. #include <linux/radix-tree.h>
  39. #include <linux/mlx4/device.h>
  40. #include <linux/mlx4/doorbell.h>
  41. #define DRV_NAME "mlx4_core"
  42. #define PFX DRV_NAME ": "
  43. #define DRV_VERSION "0.01"
  44. #define DRV_RELDATE "May 1, 2007"
  45. enum {
  46. MLX4_HCR_BASE = 0x80680,
  47. MLX4_HCR_SIZE = 0x0001c,
  48. MLX4_CLR_INT_SIZE = 0x00008
  49. };
  50. enum {
  51. MLX4_BOARD_ID_LEN = 64
  52. };
  53. enum {
  54. MLX4_MGM_ENTRY_SIZE = 0x40,
  55. MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
  56. MLX4_MTT_ENTRY_PER_SEG = 8
  57. };
  58. enum {
  59. MLX4_EQ_ASYNC,
  60. MLX4_EQ_COMP,
  61. MLX4_EQ_CATAS,
  62. MLX4_NUM_EQ
  63. };
  64. enum {
  65. MLX4_NUM_PDS = 1 << 15
  66. };
  67. enum {
  68. MLX4_CMPT_TYPE_QP = 0,
  69. MLX4_CMPT_TYPE_SRQ = 1,
  70. MLX4_CMPT_TYPE_CQ = 2,
  71. MLX4_CMPT_TYPE_EQ = 3,
  72. MLX4_CMPT_NUM_TYPE
  73. };
  74. enum {
  75. MLX4_CMPT_SHIFT = 24,
  76. MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
  77. };
  78. #ifdef CONFIG_MLX4_DEBUG
  79. extern int mlx4_debug_level;
  80. #define mlx4_dbg(mdev, format, arg...) \
  81. do { \
  82. if (mlx4_debug_level) \
  83. dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
  84. } while (0)
  85. #else /* CONFIG_MLX4_DEBUG */
  86. #define mlx4_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
  87. #endif /* CONFIG_MLX4_DEBUG */
  88. #define mlx4_err(mdev, format, arg...) \
  89. dev_err(&mdev->pdev->dev, format, ## arg)
  90. #define mlx4_info(mdev, format, arg...) \
  91. dev_info(&mdev->pdev->dev, format, ## arg)
  92. #define mlx4_warn(mdev, format, arg...) \
  93. dev_warn(&mdev->pdev->dev, format, ## arg)
  94. struct mlx4_bitmap {
  95. u32 last;
  96. u32 top;
  97. u32 max;
  98. u32 mask;
  99. spinlock_t lock;
  100. unsigned long *table;
  101. };
  102. struct mlx4_buddy {
  103. unsigned long **bits;
  104. int max_order;
  105. spinlock_t lock;
  106. };
  107. struct mlx4_icm;
  108. struct mlx4_icm_table {
  109. u64 virt;
  110. int num_icm;
  111. int num_obj;
  112. int obj_size;
  113. int lowmem;
  114. struct mutex mutex;
  115. struct mlx4_icm **icm;
  116. };
  117. struct mlx4_eq {
  118. struct mlx4_dev *dev;
  119. void __iomem *doorbell;
  120. int eqn;
  121. u32 cons_index;
  122. u16 irq;
  123. u16 have_irq;
  124. int nent;
  125. struct mlx4_buf_list *page_list;
  126. struct mlx4_mtt mtt;
  127. };
  128. struct mlx4_profile {
  129. int num_qp;
  130. int rdmarc_per_qp;
  131. int num_srq;
  132. int num_cq;
  133. int num_mcg;
  134. int num_mpt;
  135. int num_mtt;
  136. };
  137. struct mlx4_fw {
  138. u64 clr_int_base;
  139. u64 catas_offset;
  140. struct mlx4_icm *fw_icm;
  141. struct mlx4_icm *aux_icm;
  142. u32 catas_size;
  143. u16 fw_pages;
  144. u8 clr_int_bar;
  145. u8 catas_bar;
  146. };
  147. struct mlx4_cmd {
  148. struct pci_pool *pool;
  149. void __iomem *hcr;
  150. struct mutex hcr_mutex;
  151. struct semaphore poll_sem;
  152. struct semaphore event_sem;
  153. int max_cmds;
  154. spinlock_t context_lock;
  155. int free_head;
  156. struct mlx4_cmd_context *context;
  157. u16 token_mask;
  158. u8 use_events;
  159. u8 toggle;
  160. };
  161. struct mlx4_uar_table {
  162. struct mlx4_bitmap bitmap;
  163. };
  164. struct mlx4_mr_table {
  165. struct mlx4_bitmap mpt_bitmap;
  166. struct mlx4_buddy mtt_buddy;
  167. u64 mtt_base;
  168. u64 mpt_base;
  169. struct mlx4_icm_table mtt_table;
  170. struct mlx4_icm_table dmpt_table;
  171. };
  172. struct mlx4_cq_table {
  173. struct mlx4_bitmap bitmap;
  174. spinlock_t lock;
  175. struct radix_tree_root tree;
  176. struct mlx4_icm_table table;
  177. struct mlx4_icm_table cmpt_table;
  178. };
  179. struct mlx4_eq_table {
  180. struct mlx4_bitmap bitmap;
  181. void __iomem *clr_int;
  182. void __iomem *uar_map[(MLX4_NUM_EQ + 6) / 4];
  183. u32 clr_mask;
  184. struct mlx4_eq eq[MLX4_NUM_EQ];
  185. u64 icm_virt;
  186. struct page *icm_page;
  187. dma_addr_t icm_dma;
  188. struct mlx4_icm_table cmpt_table;
  189. int have_irq;
  190. u8 inta_pin;
  191. };
  192. struct mlx4_srq_table {
  193. struct mlx4_bitmap bitmap;
  194. spinlock_t lock;
  195. struct radix_tree_root tree;
  196. struct mlx4_icm_table table;
  197. struct mlx4_icm_table cmpt_table;
  198. };
  199. struct mlx4_qp_table {
  200. struct mlx4_bitmap bitmap;
  201. u32 rdmarc_base;
  202. int rdmarc_shift;
  203. spinlock_t lock;
  204. struct mlx4_icm_table qp_table;
  205. struct mlx4_icm_table auxc_table;
  206. struct mlx4_icm_table altc_table;
  207. struct mlx4_icm_table rdmarc_table;
  208. struct mlx4_icm_table cmpt_table;
  209. };
  210. struct mlx4_mcg_table {
  211. struct mutex mutex;
  212. struct mlx4_bitmap bitmap;
  213. struct mlx4_icm_table table;
  214. };
  215. struct mlx4_catas_err {
  216. u32 __iomem *map;
  217. int size;
  218. };
  219. struct mlx4_priv {
  220. struct mlx4_dev dev;
  221. struct list_head dev_list;
  222. struct list_head ctx_list;
  223. spinlock_t ctx_lock;
  224. struct mlx4_fw fw;
  225. struct mlx4_cmd cmd;
  226. struct mlx4_bitmap pd_bitmap;
  227. struct mlx4_uar_table uar_table;
  228. struct mlx4_mr_table mr_table;
  229. struct mlx4_cq_table cq_table;
  230. struct mlx4_eq_table eq_table;
  231. struct mlx4_srq_table srq_table;
  232. struct mlx4_qp_table qp_table;
  233. struct mlx4_mcg_table mcg_table;
  234. struct mlx4_catas_err catas_err;
  235. void __iomem *clr_base;
  236. struct mlx4_uar driver_uar;
  237. void __iomem *kar;
  238. u32 rev_id;
  239. char board_id[MLX4_BOARD_ID_LEN];
  240. };
  241. static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
  242. {
  243. return container_of(dev, struct mlx4_priv, dev);
  244. }
  245. u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
  246. void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
  247. int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved);
  248. void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
  249. int mlx4_reset(struct mlx4_dev *dev);
  250. int mlx4_init_pd_table(struct mlx4_dev *dev);
  251. int mlx4_init_uar_table(struct mlx4_dev *dev);
  252. int mlx4_init_mr_table(struct mlx4_dev *dev);
  253. int mlx4_init_eq_table(struct mlx4_dev *dev);
  254. int mlx4_init_cq_table(struct mlx4_dev *dev);
  255. int mlx4_init_qp_table(struct mlx4_dev *dev);
  256. int mlx4_init_srq_table(struct mlx4_dev *dev);
  257. int mlx4_init_mcg_table(struct mlx4_dev *dev);
  258. void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
  259. void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
  260. void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
  261. void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
  262. void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
  263. void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
  264. void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
  265. void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
  266. void mlx4_map_catas_buf(struct mlx4_dev *dev);
  267. void mlx4_unmap_catas_buf(struct mlx4_dev *dev);
  268. int mlx4_register_device(struct mlx4_dev *dev);
  269. void mlx4_unregister_device(struct mlx4_dev *dev);
  270. void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_event type,
  271. int subtype, int port);
  272. struct mlx4_dev_cap;
  273. struct mlx4_init_hca_param;
  274. u64 mlx4_make_profile(struct mlx4_dev *dev,
  275. struct mlx4_profile *request,
  276. struct mlx4_dev_cap *dev_cap,
  277. struct mlx4_init_hca_param *init_hca);
  278. int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt);
  279. void mlx4_unmap_eq_icm(struct mlx4_dev *dev);
  280. int mlx4_cmd_init(struct mlx4_dev *dev);
  281. void mlx4_cmd_cleanup(struct mlx4_dev *dev);
  282. void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
  283. int mlx4_cmd_use_events(struct mlx4_dev *dev);
  284. void mlx4_cmd_use_polling(struct mlx4_dev *dev);
  285. void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
  286. void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
  287. void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
  288. void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
  289. void mlx4_handle_catas_err(struct mlx4_dev *dev);
  290. #endif /* MLX4_H */