mlx5_ib.h 19 KB

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