mlx5_ib.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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. #include <linux/mlx5/transobj.h>
  44. #include <rdma/ib_user_verbs.h>
  45. #define mlx5_ib_dbg(dev, format, arg...) \
  46. pr_debug("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  47. __LINE__, current->pid, ##arg)
  48. #define mlx5_ib_err(dev, format, arg...) \
  49. pr_err("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  50. __LINE__, current->pid, ##arg)
  51. #define mlx5_ib_warn(dev, format, arg...) \
  52. pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  53. __LINE__, current->pid, ##arg)
  54. #define field_avail(type, fld, sz) (offsetof(type, fld) + \
  55. sizeof(((type *)0)->fld) <= (sz))
  56. #define MLX5_IB_DEFAULT_UIDX 0xffffff
  57. #define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
  58. enum {
  59. MLX5_IB_MMAP_CMD_SHIFT = 8,
  60. MLX5_IB_MMAP_CMD_MASK = 0xff,
  61. };
  62. enum mlx5_ib_mmap_cmd {
  63. MLX5_IB_MMAP_REGULAR_PAGE = 0,
  64. MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1,
  65. /* 5 is chosen in order to be compatible with old versions of libmlx5 */
  66. MLX5_IB_MMAP_CORE_CLOCK = 5,
  67. };
  68. enum {
  69. MLX5_RES_SCAT_DATA32_CQE = 0x1,
  70. MLX5_RES_SCAT_DATA64_CQE = 0x2,
  71. MLX5_REQ_SCAT_DATA32_CQE = 0x11,
  72. MLX5_REQ_SCAT_DATA64_CQE = 0x22,
  73. };
  74. enum mlx5_ib_latency_class {
  75. MLX5_IB_LATENCY_CLASS_LOW,
  76. MLX5_IB_LATENCY_CLASS_MEDIUM,
  77. MLX5_IB_LATENCY_CLASS_HIGH,
  78. MLX5_IB_LATENCY_CLASS_FAST_PATH
  79. };
  80. enum mlx5_ib_mad_ifc_flags {
  81. MLX5_MAD_IFC_IGNORE_MKEY = 1,
  82. MLX5_MAD_IFC_IGNORE_BKEY = 2,
  83. MLX5_MAD_IFC_NET_VIEW = 4,
  84. };
  85. enum {
  86. MLX5_CROSS_CHANNEL_UUAR = 0,
  87. };
  88. enum {
  89. MLX5_CQE_VERSION_V0,
  90. MLX5_CQE_VERSION_V1,
  91. };
  92. struct mlx5_ib_ucontext {
  93. struct ib_ucontext ibucontext;
  94. struct list_head db_page_list;
  95. /* protect doorbell record alloc/free
  96. */
  97. struct mutex db_page_mutex;
  98. struct mlx5_uuar_info uuari;
  99. u8 cqe_version;
  100. /* Transport Domain number */
  101. u32 tdn;
  102. };
  103. static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
  104. {
  105. return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
  106. }
  107. struct mlx5_ib_pd {
  108. struct ib_pd ibpd;
  109. u32 pdn;
  110. };
  111. #define MLX5_IB_FLOW_MCAST_PRIO (MLX5_BY_PASS_NUM_PRIOS - 1)
  112. #define MLX5_IB_FLOW_LAST_PRIO (MLX5_BY_PASS_NUM_REGULAR_PRIOS - 1)
  113. #if (MLX5_IB_FLOW_LAST_PRIO <= 0)
  114. #error "Invalid number of bypass priorities"
  115. #endif
  116. #define MLX5_IB_FLOW_LEFTOVERS_PRIO (MLX5_IB_FLOW_MCAST_PRIO + 1)
  117. #define MLX5_IB_NUM_FLOW_FT (MLX5_IB_FLOW_LEFTOVERS_PRIO + 1)
  118. struct mlx5_ib_flow_prio {
  119. struct mlx5_flow_table *flow_table;
  120. unsigned int refcount;
  121. };
  122. struct mlx5_ib_flow_handler {
  123. struct list_head list;
  124. struct ib_flow ibflow;
  125. unsigned int prio;
  126. struct mlx5_flow_rule *rule;
  127. };
  128. struct mlx5_ib_flow_db {
  129. struct mlx5_ib_flow_prio prios[MLX5_IB_NUM_FLOW_FT];
  130. /* Protect flow steering bypass flow tables
  131. * when add/del flow rules.
  132. * only single add/removal of flow steering rule could be done
  133. * simultaneously.
  134. */
  135. struct mutex lock;
  136. };
  137. /* Use macros here so that don't have to duplicate
  138. * enum ib_send_flags and enum ib_qp_type for low-level driver
  139. */
  140. #define MLX5_IB_SEND_UMR_UNREG IB_SEND_RESERVED_START
  141. #define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
  142. #define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
  143. #define MLX5_IB_SEND_UMR_UPDATE_TRANSLATION (IB_SEND_RESERVED_START << 3)
  144. #define MLX5_IB_SEND_UMR_UPDATE_PD (IB_SEND_RESERVED_START << 4)
  145. #define MLX5_IB_SEND_UMR_UPDATE_ACCESS IB_SEND_RESERVED_END
  146. #define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
  147. /*
  148. * IB_QPT_GSI creates the software wrapper around GSI, and MLX5_IB_QPT_HW_GSI
  149. * creates the actual hardware QP.
  150. */
  151. #define MLX5_IB_QPT_HW_GSI IB_QPT_RESERVED2
  152. #define MLX5_IB_WR_UMR IB_WR_RESERVED1
  153. /* Private QP creation flags to be passed in ib_qp_init_attr.create_flags.
  154. *
  155. * These flags are intended for internal use by the mlx5_ib driver, and they
  156. * rely on the range reserved for that use in the ib_qp_create_flags enum.
  157. */
  158. /* Create a UD QP whose source QP number is 1 */
  159. static inline enum ib_qp_create_flags mlx5_ib_create_qp_sqpn_qp1(void)
  160. {
  161. return IB_QP_CREATE_RESERVED_START;
  162. }
  163. struct wr_list {
  164. u16 opcode;
  165. u16 next;
  166. };
  167. struct mlx5_ib_wq {
  168. u64 *wrid;
  169. u32 *wr_data;
  170. struct wr_list *w_list;
  171. unsigned *wqe_head;
  172. u16 unsig_count;
  173. /* serialize post to the work queue
  174. */
  175. spinlock_t lock;
  176. int wqe_cnt;
  177. int max_post;
  178. int max_gs;
  179. int offset;
  180. int wqe_shift;
  181. unsigned head;
  182. unsigned tail;
  183. u16 cur_post;
  184. u16 last_poll;
  185. void *qend;
  186. };
  187. enum {
  188. MLX5_QP_USER,
  189. MLX5_QP_KERNEL,
  190. MLX5_QP_EMPTY
  191. };
  192. /*
  193. * Connect-IB can trigger up to four concurrent pagefaults
  194. * per-QP.
  195. */
  196. enum mlx5_ib_pagefault_context {
  197. MLX5_IB_PAGEFAULT_RESPONDER_READ,
  198. MLX5_IB_PAGEFAULT_REQUESTOR_READ,
  199. MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
  200. MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
  201. MLX5_IB_PAGEFAULT_CONTEXTS
  202. };
  203. static inline enum mlx5_ib_pagefault_context
  204. mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
  205. {
  206. return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
  207. }
  208. struct mlx5_ib_pfault {
  209. struct work_struct work;
  210. struct mlx5_pagefault mpfault;
  211. };
  212. struct mlx5_ib_ubuffer {
  213. struct ib_umem *umem;
  214. int buf_size;
  215. u64 buf_addr;
  216. };
  217. struct mlx5_ib_qp_base {
  218. struct mlx5_ib_qp *container_mibqp;
  219. struct mlx5_core_qp mqp;
  220. struct mlx5_ib_ubuffer ubuffer;
  221. };
  222. struct mlx5_ib_qp_trans {
  223. struct mlx5_ib_qp_base base;
  224. u16 xrcdn;
  225. u8 alt_port;
  226. u8 atomic_rd_en;
  227. u8 resp_depth;
  228. };
  229. struct mlx5_ib_rq {
  230. struct mlx5_ib_qp_base base;
  231. struct mlx5_ib_wq *rq;
  232. struct mlx5_ib_ubuffer ubuffer;
  233. struct mlx5_db *doorbell;
  234. u32 tirn;
  235. u8 state;
  236. };
  237. struct mlx5_ib_sq {
  238. struct mlx5_ib_qp_base base;
  239. struct mlx5_ib_wq *sq;
  240. struct mlx5_ib_ubuffer ubuffer;
  241. struct mlx5_db *doorbell;
  242. u32 tisn;
  243. u8 state;
  244. };
  245. struct mlx5_ib_raw_packet_qp {
  246. struct mlx5_ib_sq sq;
  247. struct mlx5_ib_rq rq;
  248. };
  249. struct mlx5_ib_qp {
  250. struct ib_qp ibqp;
  251. union {
  252. struct mlx5_ib_qp_trans trans_qp;
  253. struct mlx5_ib_raw_packet_qp raw_packet_qp;
  254. };
  255. struct mlx5_buf buf;
  256. struct mlx5_db db;
  257. struct mlx5_ib_wq rq;
  258. u8 sq_signal_bits;
  259. u8 fm_cache;
  260. struct mlx5_ib_wq sq;
  261. /* serialize qp state modifications
  262. */
  263. struct mutex mutex;
  264. u32 flags;
  265. u8 port;
  266. u8 state;
  267. int wq_sig;
  268. int scat_cqe;
  269. int max_inline_data;
  270. struct mlx5_bf *bf;
  271. int has_rq;
  272. /* only for user space QPs. For kernel
  273. * we have it from the bf object
  274. */
  275. int uuarn;
  276. int create_type;
  277. /* Store signature errors */
  278. bool signature_en;
  279. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  280. /*
  281. * A flag that is true for QP's that are in a state that doesn't
  282. * allow page faults, and shouldn't schedule any more faults.
  283. */
  284. int disable_page_faults;
  285. /*
  286. * The disable_page_faults_lock protects a QP's disable_page_faults
  287. * field, allowing for a thread to atomically check whether the QP
  288. * allows page faults, and if so schedule a page fault.
  289. */
  290. spinlock_t disable_page_faults_lock;
  291. struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
  292. #endif
  293. };
  294. struct mlx5_ib_cq_buf {
  295. struct mlx5_buf buf;
  296. struct ib_umem *umem;
  297. int cqe_size;
  298. int nent;
  299. };
  300. enum mlx5_ib_qp_flags {
  301. MLX5_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO,
  302. MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
  303. MLX5_IB_QP_CROSS_CHANNEL = IB_QP_CREATE_CROSS_CHANNEL,
  304. MLX5_IB_QP_MANAGED_SEND = IB_QP_CREATE_MANAGED_SEND,
  305. MLX5_IB_QP_MANAGED_RECV = IB_QP_CREATE_MANAGED_RECV,
  306. MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 5,
  307. /* QP uses 1 as its source QP number */
  308. MLX5_IB_QP_SQPN_QP1 = 1 << 6,
  309. };
  310. struct mlx5_umr_wr {
  311. struct ib_send_wr wr;
  312. union {
  313. u64 virt_addr;
  314. u64 offset;
  315. } target;
  316. struct ib_pd *pd;
  317. unsigned int page_shift;
  318. unsigned int npages;
  319. u32 length;
  320. int access_flags;
  321. u32 mkey;
  322. };
  323. static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
  324. {
  325. return container_of(wr, struct mlx5_umr_wr, wr);
  326. }
  327. struct mlx5_shared_mr_info {
  328. int mr_id;
  329. struct ib_umem *umem;
  330. };
  331. struct mlx5_ib_cq {
  332. struct ib_cq ibcq;
  333. struct mlx5_core_cq mcq;
  334. struct mlx5_ib_cq_buf buf;
  335. struct mlx5_db db;
  336. /* serialize access to the CQ
  337. */
  338. spinlock_t lock;
  339. /* protect resize cq
  340. */
  341. struct mutex resize_mutex;
  342. struct mlx5_ib_cq_buf *resize_buf;
  343. struct ib_umem *resize_umem;
  344. int cqe_size;
  345. u32 create_flags;
  346. struct list_head wc_list;
  347. enum ib_cq_notify_flags notify_flags;
  348. struct work_struct notify_work;
  349. };
  350. struct mlx5_ib_wc {
  351. struct ib_wc wc;
  352. struct list_head list;
  353. };
  354. struct mlx5_ib_srq {
  355. struct ib_srq ibsrq;
  356. struct mlx5_core_srq msrq;
  357. struct mlx5_buf buf;
  358. struct mlx5_db db;
  359. u64 *wrid;
  360. /* protect SRQ hanlding
  361. */
  362. spinlock_t lock;
  363. int head;
  364. int tail;
  365. u16 wqe_ctr;
  366. struct ib_umem *umem;
  367. /* serialize arming a SRQ
  368. */
  369. struct mutex mutex;
  370. int wq_sig;
  371. };
  372. struct mlx5_ib_xrcd {
  373. struct ib_xrcd ibxrcd;
  374. u32 xrcdn;
  375. };
  376. enum mlx5_ib_mtt_access_flags {
  377. MLX5_IB_MTT_READ = (1 << 0),
  378. MLX5_IB_MTT_WRITE = (1 << 1),
  379. };
  380. #define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
  381. struct mlx5_ib_mr {
  382. struct ib_mr ibmr;
  383. void *descs;
  384. dma_addr_t desc_map;
  385. int ndescs;
  386. int max_descs;
  387. int desc_size;
  388. int access_mode;
  389. struct mlx5_core_mkey mmkey;
  390. struct ib_umem *umem;
  391. struct mlx5_shared_mr_info *smr_info;
  392. struct list_head list;
  393. int order;
  394. int umred;
  395. int npages;
  396. struct mlx5_ib_dev *dev;
  397. struct mlx5_create_mkey_mbox_out out;
  398. struct mlx5_core_sig_ctx *sig;
  399. int live;
  400. void *descs_alloc;
  401. int access_flags; /* Needed for rereg MR */
  402. };
  403. struct mlx5_ib_mw {
  404. struct ib_mw ibmw;
  405. struct mlx5_core_mkey mmkey;
  406. };
  407. struct mlx5_ib_umr_context {
  408. struct ib_cqe cqe;
  409. enum ib_wc_status status;
  410. struct completion done;
  411. };
  412. struct umr_common {
  413. struct ib_pd *pd;
  414. struct ib_cq *cq;
  415. struct ib_qp *qp;
  416. /* control access to UMR QP
  417. */
  418. struct semaphore sem;
  419. };
  420. enum {
  421. MLX5_FMR_INVALID,
  422. MLX5_FMR_VALID,
  423. MLX5_FMR_BUSY,
  424. };
  425. struct mlx5_cache_ent {
  426. struct list_head head;
  427. /* sync access to the cahce entry
  428. */
  429. spinlock_t lock;
  430. struct dentry *dir;
  431. char name[4];
  432. u32 order;
  433. u32 size;
  434. u32 cur;
  435. u32 miss;
  436. u32 limit;
  437. struct dentry *fsize;
  438. struct dentry *fcur;
  439. struct dentry *fmiss;
  440. struct dentry *flimit;
  441. struct mlx5_ib_dev *dev;
  442. struct work_struct work;
  443. struct delayed_work dwork;
  444. int pending;
  445. };
  446. struct mlx5_mr_cache {
  447. struct workqueue_struct *wq;
  448. struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
  449. int stopped;
  450. struct dentry *root;
  451. unsigned long last_add;
  452. };
  453. struct mlx5_ib_gsi_qp;
  454. struct mlx5_ib_port_resources {
  455. struct mlx5_ib_resources *devr;
  456. struct mlx5_ib_gsi_qp *gsi;
  457. struct work_struct pkey_change_work;
  458. };
  459. struct mlx5_ib_resources {
  460. struct ib_cq *c0;
  461. struct ib_xrcd *x0;
  462. struct ib_xrcd *x1;
  463. struct ib_pd *p0;
  464. struct ib_srq *s0;
  465. struct ib_srq *s1;
  466. struct mlx5_ib_port_resources ports[2];
  467. /* Protects changes to the port resources */
  468. struct mutex mutex;
  469. };
  470. struct mlx5_roce {
  471. /* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
  472. * netdev pointer
  473. */
  474. rwlock_t netdev_lock;
  475. struct net_device *netdev;
  476. struct notifier_block nb;
  477. };
  478. struct mlx5_ib_dev {
  479. struct ib_device ib_dev;
  480. struct mlx5_core_dev *mdev;
  481. struct mlx5_roce roce;
  482. MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
  483. int num_ports;
  484. /* serialize update of capability mask
  485. */
  486. struct mutex cap_mask_mutex;
  487. bool ib_active;
  488. struct umr_common umrc;
  489. /* sync used page count stats
  490. */
  491. struct mlx5_ib_resources devr;
  492. struct mlx5_mr_cache cache;
  493. struct timer_list delay_timer;
  494. int fill_delay;
  495. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  496. struct ib_odp_caps odp_caps;
  497. /*
  498. * Sleepable RCU that prevents destruction of MRs while they are still
  499. * being used by a page fault handler.
  500. */
  501. struct srcu_struct mr_srcu;
  502. #endif
  503. struct mlx5_ib_flow_db flow_db;
  504. };
  505. static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
  506. {
  507. return container_of(mcq, struct mlx5_ib_cq, mcq);
  508. }
  509. static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
  510. {
  511. return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
  512. }
  513. static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
  514. {
  515. return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
  516. }
  517. static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
  518. {
  519. return container_of(ibcq, struct mlx5_ib_cq, ibcq);
  520. }
  521. static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
  522. {
  523. return container_of(mqp, struct mlx5_ib_qp_base, mqp)->container_mibqp;
  524. }
  525. static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mkey *mmkey)
  526. {
  527. return container_of(mmkey, struct mlx5_ib_mr, mmkey);
  528. }
  529. static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
  530. {
  531. return container_of(ibpd, struct mlx5_ib_pd, ibpd);
  532. }
  533. static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
  534. {
  535. return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
  536. }
  537. static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
  538. {
  539. return container_of(ibqp, struct mlx5_ib_qp, ibqp);
  540. }
  541. static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
  542. {
  543. return container_of(msrq, struct mlx5_ib_srq, msrq);
  544. }
  545. static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
  546. {
  547. return container_of(ibmr, struct mlx5_ib_mr, ibmr);
  548. }
  549. static inline struct mlx5_ib_mw *to_mmw(struct ib_mw *ibmw)
  550. {
  551. return container_of(ibmw, struct mlx5_ib_mw, ibmw);
  552. }
  553. struct mlx5_ib_ah {
  554. struct ib_ah ibah;
  555. struct mlx5_av av;
  556. };
  557. static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
  558. {
  559. return container_of(ibah, struct mlx5_ib_ah, ibah);
  560. }
  561. int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
  562. struct mlx5_db *db);
  563. void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
  564. void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  565. void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  566. void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
  567. int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
  568. u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  569. const void *in_mad, void *response_mad);
  570. struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  571. int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
  572. int mlx5_ib_destroy_ah(struct ib_ah *ah);
  573. struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
  574. struct ib_srq_init_attr *init_attr,
  575. struct ib_udata *udata);
  576. int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  577. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
  578. int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
  579. int mlx5_ib_destroy_srq(struct ib_srq *srq);
  580. int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
  581. struct ib_recv_wr **bad_wr);
  582. struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
  583. struct ib_qp_init_attr *init_attr,
  584. struct ib_udata *udata);
  585. int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  586. int attr_mask, struct ib_udata *udata);
  587. int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
  588. struct ib_qp_init_attr *qp_init_attr);
  589. int mlx5_ib_destroy_qp(struct ib_qp *qp);
  590. int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  591. struct ib_send_wr **bad_wr);
  592. int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  593. struct ib_recv_wr **bad_wr);
  594. void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
  595. int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
  596. void *buffer, u32 length,
  597. struct mlx5_ib_qp_base *base);
  598. struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
  599. const struct ib_cq_init_attr *attr,
  600. struct ib_ucontext *context,
  601. struct ib_udata *udata);
  602. int mlx5_ib_destroy_cq(struct ib_cq *cq);
  603. int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  604. int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  605. int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  606. int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
  607. struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
  608. struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  609. u64 virt_addr, int access_flags,
  610. struct ib_udata *udata);
  611. struct ib_mw *mlx5_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
  612. struct ib_udata *udata);
  613. int mlx5_ib_dealloc_mw(struct ib_mw *mw);
  614. int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
  615. int npages, int zap);
  616. int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
  617. u64 length, u64 virt_addr, int access_flags,
  618. struct ib_pd *pd, struct ib_udata *udata);
  619. int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
  620. struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
  621. enum ib_mr_type mr_type,
  622. u32 max_num_sg);
  623. int mlx5_ib_map_mr_sg(struct ib_mr *ibmr,
  624. struct scatterlist *sg,
  625. int sg_nents);
  626. int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  627. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  628. const struct ib_mad_hdr *in, size_t in_mad_size,
  629. struct ib_mad_hdr *out, size_t *out_mad_size,
  630. u16 *out_mad_pkey_index);
  631. struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
  632. struct ib_ucontext *context,
  633. struct ib_udata *udata);
  634. int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  635. int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
  636. int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
  637. int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
  638. struct ib_smp *out_mad);
  639. int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
  640. __be64 *sys_image_guid);
  641. int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
  642. u16 *max_pkeys);
  643. int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
  644. u32 *vendor_id);
  645. int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
  646. int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
  647. int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
  648. u16 *pkey);
  649. int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
  650. union ib_gid *gid);
  651. int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
  652. struct ib_port_attr *props);
  653. int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
  654. struct ib_port_attr *props);
  655. int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
  656. void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
  657. void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
  658. int *ncont, int *order);
  659. void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  660. int page_shift, size_t offset, size_t num_pages,
  661. __be64 *pas, int access_flags);
  662. void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  663. int page_shift, __be64 *pas, int access_flags);
  664. void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
  665. int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
  666. int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
  667. int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
  668. int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
  669. int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
  670. struct ib_mr_status *mr_status);
  671. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  672. extern struct workqueue_struct *mlx5_ib_page_fault_wq;
  673. void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
  674. void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
  675. struct mlx5_ib_pfault *pfault);
  676. void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
  677. int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
  678. void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
  679. int __init mlx5_ib_odp_init(void);
  680. void mlx5_ib_odp_cleanup(void);
  681. void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
  682. void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
  683. void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
  684. unsigned long end);
  685. int mlx5_ib_get_vf_config(struct ib_device *device, int vf,
  686. u8 port, struct ifla_vf_info *info);
  687. int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
  688. u8 port, int state);
  689. int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
  690. u8 port, struct ifla_vf_stats *stats);
  691. int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
  692. u64 guid, int type);
  693. #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  694. static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
  695. {
  696. return;
  697. }
  698. static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
  699. static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
  700. static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
  701. static inline int mlx5_ib_odp_init(void) { return 0; }
  702. static inline void mlx5_ib_odp_cleanup(void) {}
  703. static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
  704. static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
  705. #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  706. __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
  707. int index);
  708. /* GSI QP helper functions */
  709. struct ib_qp *mlx5_ib_gsi_create_qp(struct ib_pd *pd,
  710. struct ib_qp_init_attr *init_attr);
  711. int mlx5_ib_gsi_destroy_qp(struct ib_qp *qp);
  712. int mlx5_ib_gsi_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
  713. int attr_mask);
  714. int mlx5_ib_gsi_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
  715. int qp_attr_mask,
  716. struct ib_qp_init_attr *qp_init_attr);
  717. int mlx5_ib_gsi_post_send(struct ib_qp *qp, struct ib_send_wr *wr,
  718. struct ib_send_wr **bad_wr);
  719. int mlx5_ib_gsi_post_recv(struct ib_qp *qp, struct ib_recv_wr *wr,
  720. struct ib_recv_wr **bad_wr);
  721. void mlx5_ib_gsi_pkey_change(struct mlx5_ib_gsi_qp *gsi);
  722. int mlx5_ib_generate_wc(struct ib_cq *ibcq, struct ib_wc *wc);
  723. static inline void init_query_mad(struct ib_smp *mad)
  724. {
  725. mad->base_version = 1;
  726. mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  727. mad->class_version = 1;
  728. mad->method = IB_MGMT_METHOD_GET;
  729. }
  730. static inline u8 convert_access(int acc)
  731. {
  732. return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
  733. (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
  734. (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
  735. (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
  736. MLX5_PERM_LOCAL_READ;
  737. }
  738. static inline int is_qp1(enum ib_qp_type qp_type)
  739. {
  740. return qp_type == MLX5_IB_QPT_HW_GSI;
  741. }
  742. #define MLX5_MAX_UMR_SHIFT 16
  743. #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
  744. static inline u32 check_cq_create_flags(u32 flags)
  745. {
  746. /*
  747. * It returns non-zero value for unsupported CQ
  748. * create flags, otherwise it returns zero.
  749. */
  750. return (flags & ~(IB_CQ_FLAGS_IGNORE_OVERRUN |
  751. IB_CQ_FLAGS_TIMESTAMP_COMPLETION));
  752. }
  753. static inline int verify_assign_uidx(u8 cqe_version, u32 cmd_uidx,
  754. u32 *user_index)
  755. {
  756. if (cqe_version) {
  757. if ((cmd_uidx == MLX5_IB_DEFAULT_UIDX) ||
  758. (cmd_uidx & ~MLX5_USER_ASSIGNED_UIDX_MASK))
  759. return -EINVAL;
  760. *user_index = cmd_uidx;
  761. } else {
  762. *user_index = MLX5_IB_DEFAULT_UIDX;
  763. }
  764. return 0;
  765. }
  766. #endif /* MLX5_IB_H */