mlx5_ib.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. union {
  214. u64 virt_addr;
  215. u64 offset;
  216. } target;
  217. struct ib_pd *pd;
  218. unsigned int page_shift;
  219. unsigned int npages;
  220. u32 length;
  221. int access_flags;
  222. u32 mkey;
  223. };
  224. struct mlx5_shared_mr_info {
  225. int mr_id;
  226. struct ib_umem *umem;
  227. };
  228. struct mlx5_ib_cq {
  229. struct ib_cq ibcq;
  230. struct mlx5_core_cq mcq;
  231. struct mlx5_ib_cq_buf buf;
  232. struct mlx5_db db;
  233. /* serialize access to the CQ
  234. */
  235. spinlock_t lock;
  236. /* protect resize cq
  237. */
  238. struct mutex resize_mutex;
  239. struct mlx5_ib_cq_buf *resize_buf;
  240. struct ib_umem *resize_umem;
  241. int cqe_size;
  242. };
  243. struct mlx5_ib_srq {
  244. struct ib_srq ibsrq;
  245. struct mlx5_core_srq msrq;
  246. struct mlx5_buf buf;
  247. struct mlx5_db db;
  248. u64 *wrid;
  249. /* protect SRQ hanlding
  250. */
  251. spinlock_t lock;
  252. int head;
  253. int tail;
  254. u16 wqe_ctr;
  255. struct ib_umem *umem;
  256. /* serialize arming a SRQ
  257. */
  258. struct mutex mutex;
  259. int wq_sig;
  260. };
  261. struct mlx5_ib_xrcd {
  262. struct ib_xrcd ibxrcd;
  263. u32 xrcdn;
  264. };
  265. enum mlx5_ib_mtt_access_flags {
  266. MLX5_IB_MTT_READ = (1 << 0),
  267. MLX5_IB_MTT_WRITE = (1 << 1),
  268. };
  269. #define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
  270. struct mlx5_ib_mr {
  271. struct ib_mr ibmr;
  272. struct mlx5_core_mr mmr;
  273. struct ib_umem *umem;
  274. struct mlx5_shared_mr_info *smr_info;
  275. struct list_head list;
  276. int order;
  277. int umred;
  278. int npages;
  279. struct mlx5_ib_dev *dev;
  280. struct mlx5_create_mkey_mbox_out out;
  281. struct mlx5_core_sig_ctx *sig;
  282. int live;
  283. };
  284. struct mlx5_ib_fast_reg_page_list {
  285. struct ib_fast_reg_page_list ibfrpl;
  286. __be64 *mapped_page_list;
  287. dma_addr_t map;
  288. };
  289. struct mlx5_ib_umr_context {
  290. enum ib_wc_status status;
  291. struct completion done;
  292. };
  293. static inline void mlx5_ib_init_umr_context(struct mlx5_ib_umr_context *context)
  294. {
  295. context->status = -1;
  296. init_completion(&context->done);
  297. }
  298. struct umr_common {
  299. struct ib_pd *pd;
  300. struct ib_cq *cq;
  301. struct ib_qp *qp;
  302. /* control access to UMR QP
  303. */
  304. struct semaphore sem;
  305. };
  306. enum {
  307. MLX5_FMR_INVALID,
  308. MLX5_FMR_VALID,
  309. MLX5_FMR_BUSY,
  310. };
  311. struct mlx5_ib_fmr {
  312. struct ib_fmr ibfmr;
  313. struct mlx5_core_mr mr;
  314. int access_flags;
  315. int state;
  316. /* protect fmr state
  317. */
  318. spinlock_t lock;
  319. u64 wrid;
  320. struct ib_send_wr wr[2];
  321. u8 page_shift;
  322. struct ib_fast_reg_page_list page_list;
  323. };
  324. struct mlx5_cache_ent {
  325. struct list_head head;
  326. /* sync access to the cahce entry
  327. */
  328. spinlock_t lock;
  329. struct dentry *dir;
  330. char name[4];
  331. u32 order;
  332. u32 size;
  333. u32 cur;
  334. u32 miss;
  335. u32 limit;
  336. struct dentry *fsize;
  337. struct dentry *fcur;
  338. struct dentry *fmiss;
  339. struct dentry *flimit;
  340. struct mlx5_ib_dev *dev;
  341. struct work_struct work;
  342. struct delayed_work dwork;
  343. int pending;
  344. };
  345. struct mlx5_mr_cache {
  346. struct workqueue_struct *wq;
  347. struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
  348. int stopped;
  349. struct dentry *root;
  350. unsigned long last_add;
  351. };
  352. struct mlx5_ib_resources {
  353. struct ib_cq *c0;
  354. struct ib_xrcd *x0;
  355. struct ib_xrcd *x1;
  356. struct ib_pd *p0;
  357. struct ib_srq *s0;
  358. struct ib_srq *s1;
  359. };
  360. struct mlx5_ib_dev {
  361. struct ib_device ib_dev;
  362. struct mlx5_core_dev *mdev;
  363. MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
  364. int num_ports;
  365. /* serialize update of capability mask
  366. */
  367. struct mutex cap_mask_mutex;
  368. bool ib_active;
  369. struct umr_common umrc;
  370. /* sync used page count stats
  371. */
  372. struct mlx5_ib_resources devr;
  373. struct mlx5_mr_cache cache;
  374. struct timer_list delay_timer;
  375. int fill_delay;
  376. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  377. struct ib_odp_caps odp_caps;
  378. /*
  379. * Sleepable RCU that prevents destruction of MRs while they are still
  380. * being used by a page fault handler.
  381. */
  382. struct srcu_struct mr_srcu;
  383. #endif
  384. };
  385. static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
  386. {
  387. return container_of(mcq, struct mlx5_ib_cq, mcq);
  388. }
  389. static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
  390. {
  391. return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
  392. }
  393. static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
  394. {
  395. return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
  396. }
  397. static inline struct mlx5_ib_fmr *to_mfmr(struct ib_fmr *ibfmr)
  398. {
  399. return container_of(ibfmr, struct mlx5_ib_fmr, ibfmr);
  400. }
  401. static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
  402. {
  403. return container_of(ibcq, struct mlx5_ib_cq, ibcq);
  404. }
  405. static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
  406. {
  407. return container_of(mqp, struct mlx5_ib_qp, mqp);
  408. }
  409. static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mr *mmr)
  410. {
  411. return container_of(mmr, struct mlx5_ib_mr, mmr);
  412. }
  413. static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
  414. {
  415. return container_of(ibpd, struct mlx5_ib_pd, ibpd);
  416. }
  417. static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
  418. {
  419. return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
  420. }
  421. static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
  422. {
  423. return container_of(ibqp, struct mlx5_ib_qp, ibqp);
  424. }
  425. static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
  426. {
  427. return container_of(msrq, struct mlx5_ib_srq, msrq);
  428. }
  429. static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
  430. {
  431. return container_of(ibmr, struct mlx5_ib_mr, ibmr);
  432. }
  433. static inline struct mlx5_ib_fast_reg_page_list *to_mfrpl(struct ib_fast_reg_page_list *ibfrpl)
  434. {
  435. return container_of(ibfrpl, struct mlx5_ib_fast_reg_page_list, ibfrpl);
  436. }
  437. struct mlx5_ib_ah {
  438. struct ib_ah ibah;
  439. struct mlx5_av av;
  440. };
  441. static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
  442. {
  443. return container_of(ibah, struct mlx5_ib_ah, ibah);
  444. }
  445. int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
  446. struct mlx5_db *db);
  447. void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
  448. void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  449. void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  450. void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
  451. int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
  452. u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  453. const void *in_mad, void *response_mad);
  454. struct ib_ah *create_ib_ah(struct ib_ah_attr *ah_attr,
  455. struct mlx5_ib_ah *ah);
  456. struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  457. int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
  458. int mlx5_ib_destroy_ah(struct ib_ah *ah);
  459. struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
  460. struct ib_srq_init_attr *init_attr,
  461. struct ib_udata *udata);
  462. int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  463. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
  464. int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
  465. int mlx5_ib_destroy_srq(struct ib_srq *srq);
  466. int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
  467. struct ib_recv_wr **bad_wr);
  468. struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
  469. struct ib_qp_init_attr *init_attr,
  470. struct ib_udata *udata);
  471. int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  472. int attr_mask, struct ib_udata *udata);
  473. int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
  474. struct ib_qp_init_attr *qp_init_attr);
  475. int mlx5_ib_destroy_qp(struct ib_qp *qp);
  476. int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  477. struct ib_send_wr **bad_wr);
  478. int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  479. struct ib_recv_wr **bad_wr);
  480. void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
  481. int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
  482. void *buffer, u32 length);
  483. struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
  484. const struct ib_cq_init_attr *attr,
  485. struct ib_ucontext *context,
  486. struct ib_udata *udata);
  487. int mlx5_ib_destroy_cq(struct ib_cq *cq);
  488. int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  489. int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  490. int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  491. int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
  492. struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
  493. struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  494. u64 virt_addr, int access_flags,
  495. struct ib_udata *udata);
  496. int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
  497. int npages, int zap);
  498. int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
  499. struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
  500. enum ib_mr_type mr_type,
  501. u32 max_num_sg);
  502. struct ib_fast_reg_page_list *mlx5_ib_alloc_fast_reg_page_list(struct ib_device *ibdev,
  503. int page_list_len);
  504. void mlx5_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
  505. struct ib_fmr *mlx5_ib_fmr_alloc(struct ib_pd *pd, int acc,
  506. struct ib_fmr_attr *fmr_attr);
  507. int mlx5_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
  508. int npages, u64 iova);
  509. int mlx5_ib_unmap_fmr(struct list_head *fmr_list);
  510. int mlx5_ib_fmr_dealloc(struct ib_fmr *ibfmr);
  511. int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  512. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  513. const struct ib_mad_hdr *in, size_t in_mad_size,
  514. struct ib_mad_hdr *out, size_t *out_mad_size,
  515. u16 *out_mad_pkey_index);
  516. struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
  517. struct ib_ucontext *context,
  518. struct ib_udata *udata);
  519. int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  520. int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
  521. int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
  522. int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
  523. struct ib_smp *out_mad);
  524. int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
  525. __be64 *sys_image_guid);
  526. int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
  527. u16 *max_pkeys);
  528. int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
  529. u32 *vendor_id);
  530. int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
  531. int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
  532. int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
  533. u16 *pkey);
  534. int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
  535. union ib_gid *gid);
  536. int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
  537. struct ib_port_attr *props);
  538. int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
  539. struct ib_port_attr *props);
  540. int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
  541. void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
  542. void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
  543. int *ncont, int *order);
  544. void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  545. int page_shift, size_t offset, size_t num_pages,
  546. __be64 *pas, int access_flags);
  547. void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  548. int page_shift, __be64 *pas, int access_flags);
  549. void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
  550. int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
  551. int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
  552. int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
  553. int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
  554. void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context);
  555. int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
  556. struct ib_mr_status *mr_status);
  557. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  558. extern struct workqueue_struct *mlx5_ib_page_fault_wq;
  559. void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
  560. void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
  561. struct mlx5_ib_pfault *pfault);
  562. void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
  563. int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
  564. void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
  565. int __init mlx5_ib_odp_init(void);
  566. void mlx5_ib_odp_cleanup(void);
  567. void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
  568. void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
  569. void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
  570. unsigned long end);
  571. #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  572. static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
  573. {
  574. return;
  575. }
  576. static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
  577. static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
  578. static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
  579. static inline int mlx5_ib_odp_init(void) { return 0; }
  580. static inline void mlx5_ib_odp_cleanup(void) {}
  581. static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
  582. static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
  583. #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  584. static inline void init_query_mad(struct ib_smp *mad)
  585. {
  586. mad->base_version = 1;
  587. mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  588. mad->class_version = 1;
  589. mad->method = IB_MGMT_METHOD_GET;
  590. }
  591. static inline u8 convert_access(int acc)
  592. {
  593. return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
  594. (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
  595. (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
  596. (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
  597. MLX5_PERM_LOCAL_READ;
  598. }
  599. static inline int is_qp1(enum ib_qp_type qp_type)
  600. {
  601. return qp_type == IB_QPT_GSI;
  602. }
  603. #define MLX5_MAX_UMR_SHIFT 16
  604. #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
  605. #endif /* MLX5_IB_H */