mlx5_ib.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (c) 2013-2015, Mellanox Technologies. 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. #ifndef MLX5_IB_H
  33. #define MLX5_IB_H
  34. #include <linux/kernel.h>
  35. #include <linux/sched.h>
  36. #include <rdma/ib_verbs.h>
  37. #include <rdma/ib_smi.h>
  38. #include <linux/mlx5/driver.h>
  39. #include <linux/mlx5/cq.h>
  40. #include <linux/mlx5/qp.h>
  41. #include <linux/mlx5/srq.h>
  42. #include <linux/types.h>
  43. #define mlx5_ib_dbg(dev, format, arg...) \
  44. pr_debug("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  45. __LINE__, current->pid, ##arg)
  46. #define mlx5_ib_err(dev, format, arg...) \
  47. pr_err("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  48. __LINE__, current->pid, ##arg)
  49. #define mlx5_ib_warn(dev, format, arg...) \
  50. pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  51. __LINE__, current->pid, ##arg)
  52. enum {
  53. MLX5_IB_MMAP_CMD_SHIFT = 8,
  54. MLX5_IB_MMAP_CMD_MASK = 0xff,
  55. };
  56. enum mlx5_ib_mmap_cmd {
  57. MLX5_IB_MMAP_REGULAR_PAGE = 0,
  58. MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1, /* always last */
  59. };
  60. enum {
  61. MLX5_RES_SCAT_DATA32_CQE = 0x1,
  62. MLX5_RES_SCAT_DATA64_CQE = 0x2,
  63. MLX5_REQ_SCAT_DATA32_CQE = 0x11,
  64. MLX5_REQ_SCAT_DATA64_CQE = 0x22,
  65. };
  66. enum mlx5_ib_latency_class {
  67. MLX5_IB_LATENCY_CLASS_LOW,
  68. MLX5_IB_LATENCY_CLASS_MEDIUM,
  69. MLX5_IB_LATENCY_CLASS_HIGH,
  70. MLX5_IB_LATENCY_CLASS_FAST_PATH
  71. };
  72. enum mlx5_ib_mad_ifc_flags {
  73. MLX5_MAD_IFC_IGNORE_MKEY = 1,
  74. MLX5_MAD_IFC_IGNORE_BKEY = 2,
  75. MLX5_MAD_IFC_NET_VIEW = 4,
  76. };
  77. struct mlx5_ib_ucontext {
  78. struct ib_ucontext ibucontext;
  79. struct list_head db_page_list;
  80. /* protect doorbell record alloc/free
  81. */
  82. struct mutex db_page_mutex;
  83. struct mlx5_uuar_info uuari;
  84. };
  85. static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
  86. {
  87. return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
  88. }
  89. struct mlx5_ib_pd {
  90. struct ib_pd ibpd;
  91. u32 pdn;
  92. };
  93. /* Use macros here so that don't have to duplicate
  94. * enum ib_send_flags and enum ib_qp_type for low-level driver
  95. */
  96. #define MLX5_IB_SEND_UMR_UNREG IB_SEND_RESERVED_START
  97. #define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
  98. #define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
  99. #define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
  100. #define MLX5_IB_WR_UMR IB_WR_RESERVED1
  101. struct wr_list {
  102. u16 opcode;
  103. u16 next;
  104. };
  105. struct mlx5_ib_wq {
  106. u64 *wrid;
  107. u32 *wr_data;
  108. struct wr_list *w_list;
  109. unsigned *wqe_head;
  110. u16 unsig_count;
  111. /* serialize post to the work queue
  112. */
  113. spinlock_t lock;
  114. int wqe_cnt;
  115. int max_post;
  116. int max_gs;
  117. int offset;
  118. int wqe_shift;
  119. unsigned head;
  120. unsigned tail;
  121. u16 cur_post;
  122. u16 last_poll;
  123. void *qend;
  124. };
  125. enum {
  126. MLX5_QP_USER,
  127. MLX5_QP_KERNEL,
  128. MLX5_QP_EMPTY
  129. };
  130. /*
  131. * Connect-IB can trigger up to four concurrent pagefaults
  132. * per-QP.
  133. */
  134. enum mlx5_ib_pagefault_context {
  135. MLX5_IB_PAGEFAULT_RESPONDER_READ,
  136. MLX5_IB_PAGEFAULT_REQUESTOR_READ,
  137. MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
  138. MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
  139. MLX5_IB_PAGEFAULT_CONTEXTS
  140. };
  141. static inline enum mlx5_ib_pagefault_context
  142. mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
  143. {
  144. return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
  145. }
  146. struct mlx5_ib_pfault {
  147. struct work_struct work;
  148. struct mlx5_pagefault mpfault;
  149. };
  150. struct mlx5_ib_qp {
  151. struct ib_qp ibqp;
  152. struct mlx5_core_qp mqp;
  153. struct mlx5_buf buf;
  154. struct mlx5_db db;
  155. struct mlx5_ib_wq rq;
  156. u32 doorbell_qpn;
  157. u8 sq_signal_bits;
  158. u8 fm_cache;
  159. int sq_max_wqes_per_wr;
  160. int sq_spare_wqes;
  161. struct mlx5_ib_wq sq;
  162. struct ib_umem *umem;
  163. int buf_size;
  164. /* serialize qp state modifications
  165. */
  166. struct mutex mutex;
  167. u16 xrcdn;
  168. u32 flags;
  169. u8 port;
  170. u8 alt_port;
  171. u8 atomic_rd_en;
  172. u8 resp_depth;
  173. u8 state;
  174. int mlx_type;
  175. int wq_sig;
  176. int scat_cqe;
  177. int max_inline_data;
  178. struct mlx5_bf *bf;
  179. int has_rq;
  180. /* only for user space QPs. For kernel
  181. * we have it from the bf object
  182. */
  183. int uuarn;
  184. int create_type;
  185. /* Store signature errors */
  186. bool signature_en;
  187. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  188. /*
  189. * A flag that is true for QP's that are in a state that doesn't
  190. * allow page faults, and shouldn't schedule any more faults.
  191. */
  192. int disable_page_faults;
  193. /*
  194. * The disable_page_faults_lock protects a QP's disable_page_faults
  195. * field, allowing for a thread to atomically check whether the QP
  196. * allows page faults, and if so schedule a page fault.
  197. */
  198. spinlock_t disable_page_faults_lock;
  199. struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
  200. #endif
  201. };
  202. struct mlx5_ib_cq_buf {
  203. struct mlx5_buf buf;
  204. struct ib_umem *umem;
  205. int cqe_size;
  206. int nent;
  207. };
  208. enum mlx5_ib_qp_flags {
  209. MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0,
  210. MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1,
  211. };
  212. struct mlx5_umr_wr {
  213. struct ib_send_wr wr;
  214. union {
  215. u64 virt_addr;
  216. u64 offset;
  217. } target;
  218. struct ib_pd *pd;
  219. unsigned int page_shift;
  220. unsigned int npages;
  221. u32 length;
  222. int access_flags;
  223. u32 mkey;
  224. };
  225. static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
  226. {
  227. return container_of(wr, struct mlx5_umr_wr, wr);
  228. }
  229. struct mlx5_shared_mr_info {
  230. int mr_id;
  231. struct ib_umem *umem;
  232. };
  233. struct mlx5_ib_cq {
  234. struct ib_cq ibcq;
  235. struct mlx5_core_cq mcq;
  236. struct mlx5_ib_cq_buf buf;
  237. struct mlx5_db db;
  238. /* serialize access to the CQ
  239. */
  240. spinlock_t lock;
  241. /* protect resize cq
  242. */
  243. struct mutex resize_mutex;
  244. struct mlx5_ib_cq_buf *resize_buf;
  245. struct ib_umem *resize_umem;
  246. int cqe_size;
  247. };
  248. struct mlx5_ib_srq {
  249. struct ib_srq ibsrq;
  250. struct mlx5_core_srq msrq;
  251. struct mlx5_buf buf;
  252. struct mlx5_db db;
  253. u64 *wrid;
  254. /* protect SRQ hanlding
  255. */
  256. spinlock_t lock;
  257. int head;
  258. int tail;
  259. u16 wqe_ctr;
  260. struct ib_umem *umem;
  261. /* serialize arming a SRQ
  262. */
  263. struct mutex mutex;
  264. int wq_sig;
  265. };
  266. struct mlx5_ib_xrcd {
  267. struct ib_xrcd ibxrcd;
  268. u32 xrcdn;
  269. };
  270. enum mlx5_ib_mtt_access_flags {
  271. MLX5_IB_MTT_READ = (1 << 0),
  272. MLX5_IB_MTT_WRITE = (1 << 1),
  273. };
  274. #define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
  275. struct mlx5_ib_mr {
  276. struct ib_mr ibmr;
  277. void *descs;
  278. dma_addr_t desc_map;
  279. int ndescs;
  280. int max_descs;
  281. int desc_size;
  282. struct mlx5_core_mr mmr;
  283. struct ib_umem *umem;
  284. struct mlx5_shared_mr_info *smr_info;
  285. struct list_head list;
  286. int order;
  287. int umred;
  288. int npages;
  289. struct mlx5_ib_dev *dev;
  290. struct mlx5_create_mkey_mbox_out out;
  291. struct mlx5_core_sig_ctx *sig;
  292. int live;
  293. void *descs_alloc;
  294. };
  295. struct mlx5_ib_umr_context {
  296. enum ib_wc_status status;
  297. struct completion done;
  298. };
  299. static inline void mlx5_ib_init_umr_context(struct mlx5_ib_umr_context *context)
  300. {
  301. context->status = -1;
  302. init_completion(&context->done);
  303. }
  304. struct umr_common {
  305. struct ib_pd *pd;
  306. struct ib_cq *cq;
  307. struct ib_qp *qp;
  308. /* control access to UMR QP
  309. */
  310. struct semaphore sem;
  311. };
  312. enum {
  313. MLX5_FMR_INVALID,
  314. MLX5_FMR_VALID,
  315. MLX5_FMR_BUSY,
  316. };
  317. struct mlx5_cache_ent {
  318. struct list_head head;
  319. /* sync access to the cahce entry
  320. */
  321. spinlock_t lock;
  322. struct dentry *dir;
  323. char name[4];
  324. u32 order;
  325. u32 size;
  326. u32 cur;
  327. u32 miss;
  328. u32 limit;
  329. struct dentry *fsize;
  330. struct dentry *fcur;
  331. struct dentry *fmiss;
  332. struct dentry *flimit;
  333. struct mlx5_ib_dev *dev;
  334. struct work_struct work;
  335. struct delayed_work dwork;
  336. int pending;
  337. };
  338. struct mlx5_mr_cache {
  339. struct workqueue_struct *wq;
  340. struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
  341. int stopped;
  342. struct dentry *root;
  343. unsigned long last_add;
  344. };
  345. struct mlx5_ib_resources {
  346. struct ib_cq *c0;
  347. struct ib_xrcd *x0;
  348. struct ib_xrcd *x1;
  349. struct ib_pd *p0;
  350. struct ib_srq *s0;
  351. struct ib_srq *s1;
  352. };
  353. struct mlx5_ib_dev {
  354. struct ib_device ib_dev;
  355. struct mlx5_core_dev *mdev;
  356. MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
  357. int num_ports;
  358. /* serialize update of capability mask
  359. */
  360. struct mutex cap_mask_mutex;
  361. bool ib_active;
  362. struct umr_common umrc;
  363. /* sync used page count stats
  364. */
  365. struct mlx5_ib_resources devr;
  366. struct mlx5_mr_cache cache;
  367. struct timer_list delay_timer;
  368. int fill_delay;
  369. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  370. struct ib_odp_caps odp_caps;
  371. /*
  372. * Sleepable RCU that prevents destruction of MRs while they are still
  373. * being used by a page fault handler.
  374. */
  375. struct srcu_struct mr_srcu;
  376. #endif
  377. };
  378. static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
  379. {
  380. return container_of(mcq, struct mlx5_ib_cq, mcq);
  381. }
  382. static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
  383. {
  384. return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
  385. }
  386. static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
  387. {
  388. return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
  389. }
  390. static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
  391. {
  392. return container_of(ibcq, struct mlx5_ib_cq, ibcq);
  393. }
  394. static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
  395. {
  396. return container_of(mqp, struct mlx5_ib_qp, mqp);
  397. }
  398. static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mr *mmr)
  399. {
  400. return container_of(mmr, struct mlx5_ib_mr, mmr);
  401. }
  402. static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
  403. {
  404. return container_of(ibpd, struct mlx5_ib_pd, ibpd);
  405. }
  406. static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
  407. {
  408. return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
  409. }
  410. static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
  411. {
  412. return container_of(ibqp, struct mlx5_ib_qp, ibqp);
  413. }
  414. static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
  415. {
  416. return container_of(msrq, struct mlx5_ib_srq, msrq);
  417. }
  418. static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
  419. {
  420. return container_of(ibmr, struct mlx5_ib_mr, ibmr);
  421. }
  422. struct mlx5_ib_ah {
  423. struct ib_ah ibah;
  424. struct mlx5_av av;
  425. };
  426. static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
  427. {
  428. return container_of(ibah, struct mlx5_ib_ah, ibah);
  429. }
  430. int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
  431. struct mlx5_db *db);
  432. void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
  433. void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  434. void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  435. void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
  436. int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
  437. u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  438. const void *in_mad, void *response_mad);
  439. struct ib_ah *create_ib_ah(struct ib_ah_attr *ah_attr,
  440. struct mlx5_ib_ah *ah);
  441. struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  442. int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
  443. int mlx5_ib_destroy_ah(struct ib_ah *ah);
  444. struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
  445. struct ib_srq_init_attr *init_attr,
  446. struct ib_udata *udata);
  447. int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  448. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
  449. int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
  450. int mlx5_ib_destroy_srq(struct ib_srq *srq);
  451. int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
  452. struct ib_recv_wr **bad_wr);
  453. struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
  454. struct ib_qp_init_attr *init_attr,
  455. struct ib_udata *udata);
  456. int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  457. int attr_mask, struct ib_udata *udata);
  458. int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
  459. struct ib_qp_init_attr *qp_init_attr);
  460. int mlx5_ib_destroy_qp(struct ib_qp *qp);
  461. int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  462. struct ib_send_wr **bad_wr);
  463. int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  464. struct ib_recv_wr **bad_wr);
  465. void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
  466. int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
  467. void *buffer, u32 length);
  468. struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
  469. const struct ib_cq_init_attr *attr,
  470. struct ib_ucontext *context,
  471. struct ib_udata *udata);
  472. int mlx5_ib_destroy_cq(struct ib_cq *cq);
  473. int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  474. int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  475. int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  476. int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
  477. struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
  478. struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  479. u64 virt_addr, int access_flags,
  480. struct ib_udata *udata);
  481. int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
  482. int npages, int zap);
  483. int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
  484. struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
  485. enum ib_mr_type mr_type,
  486. u32 max_num_sg);
  487. int mlx5_ib_map_mr_sg(struct ib_mr *ibmr,
  488. struct scatterlist *sg,
  489. int sg_nents);
  490. int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  491. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  492. const struct ib_mad_hdr *in, size_t in_mad_size,
  493. struct ib_mad_hdr *out, size_t *out_mad_size,
  494. u16 *out_mad_pkey_index);
  495. struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
  496. struct ib_ucontext *context,
  497. struct ib_udata *udata);
  498. int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  499. int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
  500. int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
  501. int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
  502. struct ib_smp *out_mad);
  503. int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
  504. __be64 *sys_image_guid);
  505. int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
  506. u16 *max_pkeys);
  507. int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
  508. u32 *vendor_id);
  509. int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
  510. int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
  511. int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
  512. u16 *pkey);
  513. int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
  514. union ib_gid *gid);
  515. int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
  516. struct ib_port_attr *props);
  517. int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
  518. struct ib_port_attr *props);
  519. int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
  520. void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
  521. void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
  522. int *ncont, int *order);
  523. void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  524. int page_shift, size_t offset, size_t num_pages,
  525. __be64 *pas, int access_flags);
  526. void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  527. int page_shift, __be64 *pas, int access_flags);
  528. void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
  529. int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
  530. int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
  531. int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
  532. int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
  533. void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context);
  534. int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
  535. struct ib_mr_status *mr_status);
  536. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  537. extern struct workqueue_struct *mlx5_ib_page_fault_wq;
  538. void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
  539. void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
  540. struct mlx5_ib_pfault *pfault);
  541. void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
  542. int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
  543. void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
  544. int __init mlx5_ib_odp_init(void);
  545. void mlx5_ib_odp_cleanup(void);
  546. void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
  547. void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
  548. void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
  549. unsigned long end);
  550. #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  551. static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
  552. {
  553. return;
  554. }
  555. static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
  556. static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
  557. static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
  558. static inline int mlx5_ib_odp_init(void) { return 0; }
  559. static inline void mlx5_ib_odp_cleanup(void) {}
  560. static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
  561. static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
  562. #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  563. static inline void init_query_mad(struct ib_smp *mad)
  564. {
  565. mad->base_version = 1;
  566. mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  567. mad->class_version = 1;
  568. mad->method = IB_MGMT_METHOD_GET;
  569. }
  570. static inline u8 convert_access(int acc)
  571. {
  572. return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
  573. (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
  574. (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
  575. (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
  576. MLX5_PERM_LOCAL_READ;
  577. }
  578. static inline int is_qp1(enum ib_qp_type qp_type)
  579. {
  580. return qp_type == IB_QPT_GSI;
  581. }
  582. #define MLX5_MAX_UMR_SHIFT 16
  583. #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
  584. #endif /* MLX5_IB_H */