mlx4.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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, 2006, 2007, 2008 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/mutex.h>
  39. #include <linux/radix-tree.h>
  40. #include <linux/timer.h>
  41. #include <linux/semaphore.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/mlx4/device.h>
  44. #include <linux/mlx4/driver.h>
  45. #include <linux/mlx4/doorbell.h>
  46. #define DRV_NAME "mlx4_core"
  47. #define DRV_VERSION "0.01"
  48. #define DRV_RELDATE "May 1, 2007"
  49. enum {
  50. MLX4_HCR_BASE = 0x80680,
  51. MLX4_HCR_SIZE = 0x0001c,
  52. MLX4_CLR_INT_SIZE = 0x00008
  53. };
  54. enum {
  55. MLX4_MGM_ENTRY_SIZE = 0x100,
  56. MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
  57. MLX4_MTT_ENTRY_PER_SEG = 8
  58. };
  59. enum {
  60. MLX4_NUM_PDS = 1 << 15
  61. };
  62. enum {
  63. MLX4_CMPT_TYPE_QP = 0,
  64. MLX4_CMPT_TYPE_SRQ = 1,
  65. MLX4_CMPT_TYPE_CQ = 2,
  66. MLX4_CMPT_TYPE_EQ = 3,
  67. MLX4_CMPT_NUM_TYPE
  68. };
  69. enum {
  70. MLX4_CMPT_SHIFT = 24,
  71. MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
  72. };
  73. #ifdef CONFIG_MLX4_DEBUG
  74. extern int mlx4_debug_level;
  75. #else /* CONFIG_MLX4_DEBUG */
  76. #define mlx4_debug_level (0)
  77. #endif /* CONFIG_MLX4_DEBUG */
  78. #define mlx4_dbg(mdev, format, arg...) \
  79. do { \
  80. if (mlx4_debug_level) \
  81. dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ##arg); \
  82. } while (0)
  83. #define mlx4_err(mdev, format, arg...) \
  84. dev_err(&mdev->pdev->dev, format, ##arg)
  85. #define mlx4_info(mdev, format, arg...) \
  86. dev_info(&mdev->pdev->dev, format, ##arg)
  87. #define mlx4_warn(mdev, format, arg...) \
  88. dev_warn(&mdev->pdev->dev, format, ##arg)
  89. struct mlx4_bitmap {
  90. u32 last;
  91. u32 top;
  92. u32 max;
  93. u32 reserved_top;
  94. u32 mask;
  95. u32 avail;
  96. spinlock_t lock;
  97. unsigned long *table;
  98. };
  99. struct mlx4_buddy {
  100. unsigned long **bits;
  101. unsigned int *num_free;
  102. int max_order;
  103. spinlock_t lock;
  104. };
  105. struct mlx4_icm;
  106. struct mlx4_icm_table {
  107. u64 virt;
  108. int num_icm;
  109. int num_obj;
  110. int obj_size;
  111. int lowmem;
  112. int coherent;
  113. struct mutex mutex;
  114. struct mlx4_icm **icm;
  115. };
  116. struct mlx4_eq {
  117. struct mlx4_dev *dev;
  118. void __iomem *doorbell;
  119. int eqn;
  120. u32 cons_index;
  121. u16 irq;
  122. u16 have_irq;
  123. int nent;
  124. struct mlx4_buf_list *page_list;
  125. struct mlx4_mtt mtt;
  126. };
  127. struct mlx4_profile {
  128. int num_qp;
  129. int rdmarc_per_qp;
  130. int num_srq;
  131. int num_cq;
  132. int num_mcg;
  133. int num_mpt;
  134. int num_mtt;
  135. };
  136. struct mlx4_fw {
  137. u64 clr_int_base;
  138. u64 catas_offset;
  139. struct mlx4_icm *fw_icm;
  140. struct mlx4_icm *aux_icm;
  141. u32 catas_size;
  142. u16 fw_pages;
  143. u8 clr_int_bar;
  144. u8 catas_bar;
  145. };
  146. #define MGM_QPN_MASK 0x00FFFFFF
  147. #define MGM_BLCK_LB_BIT 30
  148. struct mlx4_promisc_qp {
  149. struct list_head list;
  150. u32 qpn;
  151. };
  152. struct mlx4_steer_index {
  153. struct list_head list;
  154. unsigned int index;
  155. struct list_head duplicates;
  156. };
  157. struct mlx4_mgm {
  158. __be32 next_gid_index;
  159. __be32 members_count;
  160. u32 reserved[2];
  161. u8 gid[16];
  162. __be32 qp[MLX4_QP_PER_MGM];
  163. };
  164. struct mlx4_cmd {
  165. struct pci_pool *pool;
  166. void __iomem *hcr;
  167. struct mutex hcr_mutex;
  168. struct semaphore poll_sem;
  169. struct semaphore event_sem;
  170. int max_cmds;
  171. spinlock_t context_lock;
  172. int free_head;
  173. struct mlx4_cmd_context *context;
  174. u16 token_mask;
  175. u8 use_events;
  176. u8 toggle;
  177. };
  178. struct mlx4_uar_table {
  179. struct mlx4_bitmap bitmap;
  180. };
  181. struct mlx4_mr_table {
  182. struct mlx4_bitmap mpt_bitmap;
  183. struct mlx4_buddy mtt_buddy;
  184. u64 mtt_base;
  185. u64 mpt_base;
  186. struct mlx4_icm_table mtt_table;
  187. struct mlx4_icm_table dmpt_table;
  188. };
  189. struct mlx4_cq_table {
  190. struct mlx4_bitmap bitmap;
  191. spinlock_t lock;
  192. struct radix_tree_root tree;
  193. struct mlx4_icm_table table;
  194. struct mlx4_icm_table cmpt_table;
  195. };
  196. struct mlx4_eq_table {
  197. struct mlx4_bitmap bitmap;
  198. char *irq_names;
  199. void __iomem *clr_int;
  200. void __iomem **uar_map;
  201. u32 clr_mask;
  202. struct mlx4_eq *eq;
  203. struct mlx4_icm_table table;
  204. struct mlx4_icm_table cmpt_table;
  205. int have_irq;
  206. u8 inta_pin;
  207. };
  208. struct mlx4_srq_table {
  209. struct mlx4_bitmap bitmap;
  210. spinlock_t lock;
  211. struct radix_tree_root tree;
  212. struct mlx4_icm_table table;
  213. struct mlx4_icm_table cmpt_table;
  214. };
  215. struct mlx4_qp_table {
  216. struct mlx4_bitmap bitmap;
  217. u32 rdmarc_base;
  218. int rdmarc_shift;
  219. spinlock_t lock;
  220. struct mlx4_icm_table qp_table;
  221. struct mlx4_icm_table auxc_table;
  222. struct mlx4_icm_table altc_table;
  223. struct mlx4_icm_table rdmarc_table;
  224. struct mlx4_icm_table cmpt_table;
  225. };
  226. struct mlx4_mcg_table {
  227. struct mutex mutex;
  228. struct mlx4_bitmap bitmap;
  229. struct mlx4_icm_table table;
  230. };
  231. struct mlx4_catas_err {
  232. u32 __iomem *map;
  233. struct timer_list timer;
  234. struct list_head list;
  235. };
  236. #define MLX4_MAX_MAC_NUM 128
  237. #define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
  238. struct mlx4_mac_table {
  239. __be64 entries[MLX4_MAX_MAC_NUM];
  240. int refs[MLX4_MAX_MAC_NUM];
  241. struct mutex mutex;
  242. int total;
  243. int max;
  244. };
  245. #define MLX4_MAX_VLAN_NUM 128
  246. #define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
  247. struct mlx4_vlan_table {
  248. __be32 entries[MLX4_MAX_VLAN_NUM];
  249. int refs[MLX4_MAX_VLAN_NUM];
  250. struct mutex mutex;
  251. int total;
  252. int max;
  253. };
  254. struct mlx4_mac_entry {
  255. u64 mac;
  256. };
  257. struct mlx4_port_info {
  258. struct mlx4_dev *dev;
  259. int port;
  260. char dev_name[16];
  261. struct device_attribute port_attr;
  262. enum mlx4_port_type tmp_type;
  263. struct mlx4_mac_table mac_table;
  264. struct radix_tree_root mac_tree;
  265. struct mlx4_vlan_table vlan_table;
  266. int base_qpn;
  267. };
  268. struct mlx4_sense {
  269. struct mlx4_dev *dev;
  270. u8 do_sense_port[MLX4_MAX_PORTS + 1];
  271. u8 sense_allowed[MLX4_MAX_PORTS + 1];
  272. struct delayed_work sense_poll;
  273. };
  274. struct mlx4_msix_ctl {
  275. u64 pool_bm;
  276. spinlock_t pool_lock;
  277. };
  278. struct mlx4_steer {
  279. struct list_head promisc_qps[MLX4_NUM_STEERS];
  280. struct list_head steer_entries[MLX4_NUM_STEERS];
  281. struct list_head high_prios;
  282. };
  283. struct mlx4_priv {
  284. struct mlx4_dev dev;
  285. struct list_head dev_list;
  286. struct list_head ctx_list;
  287. spinlock_t ctx_lock;
  288. struct list_head pgdir_list;
  289. struct mutex pgdir_mutex;
  290. struct mlx4_fw fw;
  291. struct mlx4_cmd cmd;
  292. struct mlx4_bitmap pd_bitmap;
  293. struct mlx4_uar_table uar_table;
  294. struct mlx4_mr_table mr_table;
  295. struct mlx4_cq_table cq_table;
  296. struct mlx4_eq_table eq_table;
  297. struct mlx4_srq_table srq_table;
  298. struct mlx4_qp_table qp_table;
  299. struct mlx4_mcg_table mcg_table;
  300. struct mlx4_catas_err catas_err;
  301. void __iomem *clr_base;
  302. struct mlx4_uar driver_uar;
  303. void __iomem *kar;
  304. struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
  305. struct mlx4_sense sense;
  306. struct mutex port_mutex;
  307. struct mlx4_msix_ctl msix_ctl;
  308. struct mlx4_steer *steer;
  309. struct list_head bf_list;
  310. struct mutex bf_mutex;
  311. struct io_mapping *bf_mapping;
  312. };
  313. static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
  314. {
  315. return container_of(dev, struct mlx4_priv, dev);
  316. }
  317. #define MLX4_SENSE_RANGE (HZ * 3)
  318. extern struct workqueue_struct *mlx4_wq;
  319. u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
  320. void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
  321. u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
  322. void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
  323. u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
  324. int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
  325. u32 reserved_bot, u32 resetrved_top);
  326. void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
  327. int mlx4_reset(struct mlx4_dev *dev);
  328. int mlx4_alloc_eq_table(struct mlx4_dev *dev);
  329. void mlx4_free_eq_table(struct mlx4_dev *dev);
  330. int mlx4_init_pd_table(struct mlx4_dev *dev);
  331. int mlx4_init_uar_table(struct mlx4_dev *dev);
  332. int mlx4_init_mr_table(struct mlx4_dev *dev);
  333. int mlx4_init_eq_table(struct mlx4_dev *dev);
  334. int mlx4_init_cq_table(struct mlx4_dev *dev);
  335. int mlx4_init_qp_table(struct mlx4_dev *dev);
  336. int mlx4_init_srq_table(struct mlx4_dev *dev);
  337. int mlx4_init_mcg_table(struct mlx4_dev *dev);
  338. void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
  339. void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
  340. void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
  341. void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
  342. void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
  343. void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
  344. void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
  345. void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
  346. void mlx4_start_catas_poll(struct mlx4_dev *dev);
  347. void mlx4_stop_catas_poll(struct mlx4_dev *dev);
  348. void mlx4_catas_init(void);
  349. int mlx4_restart_one(struct pci_dev *pdev);
  350. int mlx4_register_device(struct mlx4_dev *dev);
  351. void mlx4_unregister_device(struct mlx4_dev *dev);
  352. void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
  353. struct mlx4_dev_cap;
  354. struct mlx4_init_hca_param;
  355. u64 mlx4_make_profile(struct mlx4_dev *dev,
  356. struct mlx4_profile *request,
  357. struct mlx4_dev_cap *dev_cap,
  358. struct mlx4_init_hca_param *init_hca);
  359. int mlx4_cmd_init(struct mlx4_dev *dev);
  360. void mlx4_cmd_cleanup(struct mlx4_dev *dev);
  361. void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
  362. int mlx4_cmd_use_events(struct mlx4_dev *dev);
  363. void mlx4_cmd_use_polling(struct mlx4_dev *dev);
  364. void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
  365. void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
  366. void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
  367. void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
  368. void mlx4_handle_catas_err(struct mlx4_dev *dev);
  369. int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
  370. enum mlx4_port_type *type);
  371. void mlx4_do_sense_ports(struct mlx4_dev *dev,
  372. enum mlx4_port_type *stype,
  373. enum mlx4_port_type *defaults);
  374. void mlx4_start_sense(struct mlx4_dev *dev);
  375. void mlx4_stop_sense(struct mlx4_dev *dev);
  376. void mlx4_sense_init(struct mlx4_dev *dev);
  377. int mlx4_check_port_params(struct mlx4_dev *dev,
  378. enum mlx4_port_type *port_type);
  379. int mlx4_change_port_types(struct mlx4_dev *dev,
  380. enum mlx4_port_type *port_types);
  381. void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
  382. void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
  383. int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
  384. int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
  385. int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  386. enum mlx4_protocol prot, enum mlx4_steer_type steer);
  387. int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  388. int block_mcast_loopback, enum mlx4_protocol prot,
  389. enum mlx4_steer_type steer);
  390. #endif /* MLX4_H */