mlx5_ib.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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. #include <rdma/mlx5-abi.h>
  46. #include <rdma/uverbs_ioctl.h>
  47. #define mlx5_ib_dbg(dev, format, arg...) \
  48. pr_debug("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  49. __LINE__, current->pid, ##arg)
  50. #define mlx5_ib_err(dev, format, arg...) \
  51. pr_err("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  52. __LINE__, current->pid, ##arg)
  53. #define mlx5_ib_warn(dev, format, arg...) \
  54. pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
  55. __LINE__, current->pid, ##arg)
  56. #define field_avail(type, fld, sz) (offsetof(type, fld) + \
  57. sizeof(((type *)0)->fld) <= (sz))
  58. #define MLX5_IB_DEFAULT_UIDX 0xffffff
  59. #define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
  60. #define MLX5_MKEY_PAGE_SHIFT_MASK __mlx5_mask(mkc, log_page_size)
  61. enum {
  62. MLX5_IB_MMAP_CMD_SHIFT = 8,
  63. MLX5_IB_MMAP_CMD_MASK = 0xff,
  64. };
  65. enum {
  66. MLX5_RES_SCAT_DATA32_CQE = 0x1,
  67. MLX5_RES_SCAT_DATA64_CQE = 0x2,
  68. MLX5_REQ_SCAT_DATA32_CQE = 0x11,
  69. MLX5_REQ_SCAT_DATA64_CQE = 0x22,
  70. };
  71. enum mlx5_ib_latency_class {
  72. MLX5_IB_LATENCY_CLASS_LOW,
  73. MLX5_IB_LATENCY_CLASS_MEDIUM,
  74. MLX5_IB_LATENCY_CLASS_HIGH,
  75. };
  76. enum mlx5_ib_mad_ifc_flags {
  77. MLX5_MAD_IFC_IGNORE_MKEY = 1,
  78. MLX5_MAD_IFC_IGNORE_BKEY = 2,
  79. MLX5_MAD_IFC_NET_VIEW = 4,
  80. };
  81. enum {
  82. MLX5_CROSS_CHANNEL_BFREG = 0,
  83. };
  84. enum {
  85. MLX5_CQE_VERSION_V0,
  86. MLX5_CQE_VERSION_V1,
  87. };
  88. enum {
  89. MLX5_TM_MAX_RNDV_MSG_SIZE = 64,
  90. MLX5_TM_MAX_SGE = 1,
  91. };
  92. enum {
  93. MLX5_IB_INVALID_UAR_INDEX = BIT(31),
  94. MLX5_IB_INVALID_BFREG = BIT(31),
  95. };
  96. enum {
  97. MLX5_MAX_MEMIC_PAGES = 0x100,
  98. MLX5_MEMIC_ALLOC_SIZE_MASK = 0x3f,
  99. };
  100. enum {
  101. MLX5_MEMIC_BASE_ALIGN = 6,
  102. MLX5_MEMIC_BASE_SIZE = 1 << MLX5_MEMIC_BASE_ALIGN,
  103. };
  104. struct mlx5_ib_vma_private_data {
  105. struct list_head list;
  106. struct vm_area_struct *vma;
  107. /* protect vma_private_list add/del */
  108. struct mutex *vma_private_list_mutex;
  109. };
  110. struct mlx5_ib_ucontext {
  111. struct ib_ucontext ibucontext;
  112. struct list_head db_page_list;
  113. /* protect doorbell record alloc/free
  114. */
  115. struct mutex db_page_mutex;
  116. struct mlx5_bfreg_info bfregi;
  117. u8 cqe_version;
  118. /* Transport Domain number */
  119. u32 tdn;
  120. struct list_head vma_private_list;
  121. /* protect vma_private_list add/del */
  122. struct mutex vma_private_list_mutex;
  123. u64 lib_caps;
  124. DECLARE_BITMAP(dm_pages, MLX5_MAX_MEMIC_PAGES);
  125. };
  126. static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
  127. {
  128. return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
  129. }
  130. struct mlx5_ib_pd {
  131. struct ib_pd ibpd;
  132. u32 pdn;
  133. };
  134. #define MLX5_IB_FLOW_MCAST_PRIO (MLX5_BY_PASS_NUM_PRIOS - 1)
  135. #define MLX5_IB_FLOW_LAST_PRIO (MLX5_BY_PASS_NUM_REGULAR_PRIOS - 1)
  136. #if (MLX5_IB_FLOW_LAST_PRIO <= 0)
  137. #error "Invalid number of bypass priorities"
  138. #endif
  139. #define MLX5_IB_FLOW_LEFTOVERS_PRIO (MLX5_IB_FLOW_MCAST_PRIO + 1)
  140. #define MLX5_IB_NUM_FLOW_FT (MLX5_IB_FLOW_LEFTOVERS_PRIO + 1)
  141. #define MLX5_IB_NUM_SNIFFER_FTS 2
  142. #define MLX5_IB_NUM_EGRESS_FTS 1
  143. struct mlx5_ib_flow_prio {
  144. struct mlx5_flow_table *flow_table;
  145. unsigned int refcount;
  146. };
  147. struct mlx5_ib_flow_handler {
  148. struct list_head list;
  149. struct ib_flow ibflow;
  150. struct mlx5_ib_flow_prio *prio;
  151. struct mlx5_flow_handle *rule;
  152. };
  153. struct mlx5_ib_flow_db {
  154. struct mlx5_ib_flow_prio prios[MLX5_IB_NUM_FLOW_FT];
  155. struct mlx5_ib_flow_prio sniffer[MLX5_IB_NUM_SNIFFER_FTS];
  156. struct mlx5_ib_flow_prio egress[MLX5_IB_NUM_EGRESS_FTS];
  157. struct mlx5_flow_table *lag_demux_ft;
  158. /* Protect flow steering bypass flow tables
  159. * when add/del flow rules.
  160. * only single add/removal of flow steering rule could be done
  161. * simultaneously.
  162. */
  163. struct mutex lock;
  164. };
  165. /* Use macros here so that don't have to duplicate
  166. * enum ib_send_flags and enum ib_qp_type for low-level driver
  167. */
  168. #define MLX5_IB_SEND_UMR_ENABLE_MR (IB_SEND_RESERVED_START << 0)
  169. #define MLX5_IB_SEND_UMR_DISABLE_MR (IB_SEND_RESERVED_START << 1)
  170. #define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 2)
  171. #define MLX5_IB_SEND_UMR_UPDATE_XLT (IB_SEND_RESERVED_START << 3)
  172. #define MLX5_IB_SEND_UMR_UPDATE_TRANSLATION (IB_SEND_RESERVED_START << 4)
  173. #define MLX5_IB_SEND_UMR_UPDATE_PD_ACCESS IB_SEND_RESERVED_END
  174. #define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
  175. /*
  176. * IB_QPT_GSI creates the software wrapper around GSI, and MLX5_IB_QPT_HW_GSI
  177. * creates the actual hardware QP.
  178. */
  179. #define MLX5_IB_QPT_HW_GSI IB_QPT_RESERVED2
  180. #define MLX5_IB_QPT_DCI IB_QPT_RESERVED3
  181. #define MLX5_IB_QPT_DCT IB_QPT_RESERVED4
  182. #define MLX5_IB_WR_UMR IB_WR_RESERVED1
  183. #define MLX5_IB_UMR_OCTOWORD 16
  184. #define MLX5_IB_UMR_XLT_ALIGNMENT 64
  185. #define MLX5_IB_UPD_XLT_ZAP BIT(0)
  186. #define MLX5_IB_UPD_XLT_ENABLE BIT(1)
  187. #define MLX5_IB_UPD_XLT_ATOMIC BIT(2)
  188. #define MLX5_IB_UPD_XLT_ADDR BIT(3)
  189. #define MLX5_IB_UPD_XLT_PD BIT(4)
  190. #define MLX5_IB_UPD_XLT_ACCESS BIT(5)
  191. #define MLX5_IB_UPD_XLT_INDIRECT BIT(6)
  192. /* Private QP creation flags to be passed in ib_qp_init_attr.create_flags.
  193. *
  194. * These flags are intended for internal use by the mlx5_ib driver, and they
  195. * rely on the range reserved for that use in the ib_qp_create_flags enum.
  196. */
  197. /* Create a UD QP whose source QP number is 1 */
  198. static inline enum ib_qp_create_flags mlx5_ib_create_qp_sqpn_qp1(void)
  199. {
  200. return IB_QP_CREATE_RESERVED_START;
  201. }
  202. struct wr_list {
  203. u16 opcode;
  204. u16 next;
  205. };
  206. enum mlx5_ib_rq_flags {
  207. MLX5_IB_RQ_CVLAN_STRIPPING = 1 << 0,
  208. MLX5_IB_RQ_PCI_WRITE_END_PADDING = 1 << 1,
  209. };
  210. struct mlx5_ib_wq {
  211. u64 *wrid;
  212. u32 *wr_data;
  213. struct wr_list *w_list;
  214. unsigned *wqe_head;
  215. u16 unsig_count;
  216. /* serialize post to the work queue
  217. */
  218. spinlock_t lock;
  219. int wqe_cnt;
  220. int max_post;
  221. int max_gs;
  222. int offset;
  223. int wqe_shift;
  224. unsigned head;
  225. unsigned tail;
  226. u16 cur_post;
  227. u16 last_poll;
  228. void *qend;
  229. };
  230. enum mlx5_ib_wq_flags {
  231. MLX5_IB_WQ_FLAGS_DELAY_DROP = 0x1,
  232. MLX5_IB_WQ_FLAGS_STRIDING_RQ = 0x2,
  233. };
  234. #define MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES 9
  235. #define MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES 16
  236. #define MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES 6
  237. #define MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES 13
  238. struct mlx5_ib_rwq {
  239. struct ib_wq ibwq;
  240. struct mlx5_core_qp core_qp;
  241. u32 rq_num_pas;
  242. u32 log_rq_stride;
  243. u32 log_rq_size;
  244. u32 rq_page_offset;
  245. u32 log_page_size;
  246. u32 log_num_strides;
  247. u32 two_byte_shift_en;
  248. u32 single_stride_log_num_of_bytes;
  249. struct ib_umem *umem;
  250. size_t buf_size;
  251. unsigned int page_shift;
  252. int create_type;
  253. struct mlx5_db db;
  254. u32 user_index;
  255. u32 wqe_count;
  256. u32 wqe_shift;
  257. int wq_sig;
  258. u32 create_flags; /* Use enum mlx5_ib_wq_flags */
  259. };
  260. enum {
  261. MLX5_QP_USER,
  262. MLX5_QP_KERNEL,
  263. MLX5_QP_EMPTY
  264. };
  265. enum {
  266. MLX5_WQ_USER,
  267. MLX5_WQ_KERNEL
  268. };
  269. struct mlx5_ib_rwq_ind_table {
  270. struct ib_rwq_ind_table ib_rwq_ind_tbl;
  271. u32 rqtn;
  272. };
  273. struct mlx5_ib_ubuffer {
  274. struct ib_umem *umem;
  275. int buf_size;
  276. u64 buf_addr;
  277. };
  278. struct mlx5_ib_qp_base {
  279. struct mlx5_ib_qp *container_mibqp;
  280. struct mlx5_core_qp mqp;
  281. struct mlx5_ib_ubuffer ubuffer;
  282. };
  283. struct mlx5_ib_qp_trans {
  284. struct mlx5_ib_qp_base base;
  285. u16 xrcdn;
  286. u8 alt_port;
  287. u8 atomic_rd_en;
  288. u8 resp_depth;
  289. };
  290. struct mlx5_ib_rss_qp {
  291. u32 tirn;
  292. };
  293. struct mlx5_ib_rq {
  294. struct mlx5_ib_qp_base base;
  295. struct mlx5_ib_wq *rq;
  296. struct mlx5_ib_ubuffer ubuffer;
  297. struct mlx5_db *doorbell;
  298. u32 tirn;
  299. u8 state;
  300. u32 flags;
  301. };
  302. struct mlx5_ib_sq {
  303. struct mlx5_ib_qp_base base;
  304. struct mlx5_ib_wq *sq;
  305. struct mlx5_ib_ubuffer ubuffer;
  306. struct mlx5_db *doorbell;
  307. struct mlx5_flow_handle *flow_rule;
  308. u32 tisn;
  309. u8 state;
  310. };
  311. struct mlx5_ib_raw_packet_qp {
  312. struct mlx5_ib_sq sq;
  313. struct mlx5_ib_rq rq;
  314. };
  315. struct mlx5_bf {
  316. int buf_size;
  317. unsigned long offset;
  318. struct mlx5_sq_bfreg *bfreg;
  319. };
  320. struct mlx5_ib_dct {
  321. struct mlx5_core_dct mdct;
  322. u32 *in;
  323. };
  324. struct mlx5_ib_qp {
  325. struct ib_qp ibqp;
  326. union {
  327. struct mlx5_ib_qp_trans trans_qp;
  328. struct mlx5_ib_raw_packet_qp raw_packet_qp;
  329. struct mlx5_ib_rss_qp rss_qp;
  330. struct mlx5_ib_dct dct;
  331. };
  332. struct mlx5_frag_buf buf;
  333. struct mlx5_db db;
  334. struct mlx5_ib_wq rq;
  335. u8 sq_signal_bits;
  336. u8 next_fence;
  337. struct mlx5_ib_wq sq;
  338. /* serialize qp state modifications
  339. */
  340. struct mutex mutex;
  341. u32 flags;
  342. u8 port;
  343. u8 state;
  344. int wq_sig;
  345. int scat_cqe;
  346. int max_inline_data;
  347. struct mlx5_bf bf;
  348. int has_rq;
  349. /* only for user space QPs. For kernel
  350. * we have it from the bf object
  351. */
  352. int bfregn;
  353. int create_type;
  354. /* Store signature errors */
  355. bool signature_en;
  356. struct list_head qps_list;
  357. struct list_head cq_recv_list;
  358. struct list_head cq_send_list;
  359. struct mlx5_rate_limit rl;
  360. u32 underlay_qpn;
  361. bool tunnel_offload_en;
  362. /* storage for qp sub type when core qp type is IB_QPT_DRIVER */
  363. enum ib_qp_type qp_sub_type;
  364. };
  365. struct mlx5_ib_cq_buf {
  366. struct mlx5_frag_buf_ctrl fbc;
  367. struct ib_umem *umem;
  368. int cqe_size;
  369. int nent;
  370. };
  371. enum mlx5_ib_qp_flags {
  372. MLX5_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO,
  373. MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
  374. MLX5_IB_QP_CROSS_CHANNEL = IB_QP_CREATE_CROSS_CHANNEL,
  375. MLX5_IB_QP_MANAGED_SEND = IB_QP_CREATE_MANAGED_SEND,
  376. MLX5_IB_QP_MANAGED_RECV = IB_QP_CREATE_MANAGED_RECV,
  377. MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 5,
  378. /* QP uses 1 as its source QP number */
  379. MLX5_IB_QP_SQPN_QP1 = 1 << 6,
  380. MLX5_IB_QP_CAP_SCATTER_FCS = 1 << 7,
  381. MLX5_IB_QP_RSS = 1 << 8,
  382. MLX5_IB_QP_CVLAN_STRIPPING = 1 << 9,
  383. MLX5_IB_QP_UNDERLAY = 1 << 10,
  384. MLX5_IB_QP_PCI_WRITE_END_PADDING = 1 << 11,
  385. MLX5_IB_QP_TUNNEL_OFFLOAD = 1 << 12,
  386. };
  387. struct mlx5_umr_wr {
  388. struct ib_send_wr wr;
  389. u64 virt_addr;
  390. u64 offset;
  391. struct ib_pd *pd;
  392. unsigned int page_shift;
  393. unsigned int xlt_size;
  394. u64 length;
  395. int access_flags;
  396. u32 mkey;
  397. };
  398. static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
  399. {
  400. return container_of(wr, struct mlx5_umr_wr, wr);
  401. }
  402. struct mlx5_shared_mr_info {
  403. int mr_id;
  404. struct ib_umem *umem;
  405. };
  406. enum mlx5_ib_cq_pr_flags {
  407. MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD = 1 << 0,
  408. };
  409. struct mlx5_ib_cq {
  410. struct ib_cq ibcq;
  411. struct mlx5_core_cq mcq;
  412. struct mlx5_ib_cq_buf buf;
  413. struct mlx5_db db;
  414. /* serialize access to the CQ
  415. */
  416. spinlock_t lock;
  417. /* protect resize cq
  418. */
  419. struct mutex resize_mutex;
  420. struct mlx5_ib_cq_buf *resize_buf;
  421. struct ib_umem *resize_umem;
  422. int cqe_size;
  423. struct list_head list_send_qp;
  424. struct list_head list_recv_qp;
  425. u32 create_flags;
  426. struct list_head wc_list;
  427. enum ib_cq_notify_flags notify_flags;
  428. struct work_struct notify_work;
  429. u16 private_flags; /* Use mlx5_ib_cq_pr_flags */
  430. };
  431. struct mlx5_ib_wc {
  432. struct ib_wc wc;
  433. struct list_head list;
  434. };
  435. struct mlx5_ib_srq {
  436. struct ib_srq ibsrq;
  437. struct mlx5_core_srq msrq;
  438. struct mlx5_frag_buf buf;
  439. struct mlx5_db db;
  440. u64 *wrid;
  441. /* protect SRQ hanlding
  442. */
  443. spinlock_t lock;
  444. int head;
  445. int tail;
  446. u16 wqe_ctr;
  447. struct ib_umem *umem;
  448. /* serialize arming a SRQ
  449. */
  450. struct mutex mutex;
  451. int wq_sig;
  452. };
  453. struct mlx5_ib_xrcd {
  454. struct ib_xrcd ibxrcd;
  455. u32 xrcdn;
  456. };
  457. enum mlx5_ib_mtt_access_flags {
  458. MLX5_IB_MTT_READ = (1 << 0),
  459. MLX5_IB_MTT_WRITE = (1 << 1),
  460. };
  461. struct mlx5_ib_dm {
  462. struct ib_dm ibdm;
  463. phys_addr_t dev_addr;
  464. };
  465. #define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
  466. #define MLX5_IB_DM_ALLOWED_ACCESS (IB_ACCESS_LOCAL_WRITE |\
  467. IB_ACCESS_REMOTE_WRITE |\
  468. IB_ACCESS_REMOTE_READ |\
  469. IB_ACCESS_REMOTE_ATOMIC |\
  470. IB_ZERO_BASED)
  471. struct mlx5_ib_mr {
  472. struct ib_mr ibmr;
  473. void *descs;
  474. dma_addr_t desc_map;
  475. int ndescs;
  476. int max_descs;
  477. int desc_size;
  478. int access_mode;
  479. struct mlx5_core_mkey mmkey;
  480. struct ib_umem *umem;
  481. struct mlx5_shared_mr_info *smr_info;
  482. struct list_head list;
  483. int order;
  484. bool allocated_from_cache;
  485. int npages;
  486. struct mlx5_ib_dev *dev;
  487. u32 out[MLX5_ST_SZ_DW(create_mkey_out)];
  488. struct mlx5_core_sig_ctx *sig;
  489. int live;
  490. void *descs_alloc;
  491. int access_flags; /* Needed for rereg MR */
  492. struct mlx5_ib_mr *parent;
  493. atomic_t num_leaf_free;
  494. wait_queue_head_t q_leaf_free;
  495. };
  496. struct mlx5_ib_mw {
  497. struct ib_mw ibmw;
  498. struct mlx5_core_mkey mmkey;
  499. int ndescs;
  500. };
  501. struct mlx5_ib_umr_context {
  502. struct ib_cqe cqe;
  503. enum ib_wc_status status;
  504. struct completion done;
  505. };
  506. struct umr_common {
  507. struct ib_pd *pd;
  508. struct ib_cq *cq;
  509. struct ib_qp *qp;
  510. /* control access to UMR QP
  511. */
  512. struct semaphore sem;
  513. };
  514. enum {
  515. MLX5_FMR_INVALID,
  516. MLX5_FMR_VALID,
  517. MLX5_FMR_BUSY,
  518. };
  519. struct mlx5_cache_ent {
  520. struct list_head head;
  521. /* sync access to the cahce entry
  522. */
  523. spinlock_t lock;
  524. struct dentry *dir;
  525. char name[4];
  526. u32 order;
  527. u32 xlt;
  528. u32 access_mode;
  529. u32 page;
  530. u32 size;
  531. u32 cur;
  532. u32 miss;
  533. u32 limit;
  534. struct dentry *fsize;
  535. struct dentry *fcur;
  536. struct dentry *fmiss;
  537. struct dentry *flimit;
  538. struct mlx5_ib_dev *dev;
  539. struct work_struct work;
  540. struct delayed_work dwork;
  541. int pending;
  542. struct completion compl;
  543. };
  544. struct mlx5_mr_cache {
  545. struct workqueue_struct *wq;
  546. struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
  547. int stopped;
  548. struct dentry *root;
  549. unsigned long last_add;
  550. };
  551. struct mlx5_ib_gsi_qp;
  552. struct mlx5_ib_port_resources {
  553. struct mlx5_ib_resources *devr;
  554. struct mlx5_ib_gsi_qp *gsi;
  555. struct work_struct pkey_change_work;
  556. };
  557. struct mlx5_ib_resources {
  558. struct ib_cq *c0;
  559. struct ib_xrcd *x0;
  560. struct ib_xrcd *x1;
  561. struct ib_pd *p0;
  562. struct ib_srq *s0;
  563. struct ib_srq *s1;
  564. struct mlx5_ib_port_resources ports[2];
  565. /* Protects changes to the port resources */
  566. struct mutex mutex;
  567. };
  568. struct mlx5_ib_counters {
  569. const char **names;
  570. size_t *offsets;
  571. u32 num_q_counters;
  572. u32 num_cong_counters;
  573. u16 set_id;
  574. bool set_id_valid;
  575. };
  576. struct mlx5_ib_multiport_info;
  577. struct mlx5_ib_multiport {
  578. struct mlx5_ib_multiport_info *mpi;
  579. /* To be held when accessing the multiport info */
  580. spinlock_t mpi_lock;
  581. };
  582. struct mlx5_ib_port {
  583. struct mlx5_ib_counters cnts;
  584. struct mlx5_ib_multiport mp;
  585. struct mlx5_ib_dbg_cc_params *dbg_cc_params;
  586. };
  587. struct mlx5_roce {
  588. /* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
  589. * netdev pointer
  590. */
  591. rwlock_t netdev_lock;
  592. struct net_device *netdev;
  593. struct notifier_block nb;
  594. atomic_t next_port;
  595. enum ib_port_state last_port_state;
  596. struct mlx5_ib_dev *dev;
  597. u8 native_port_num;
  598. };
  599. struct mlx5_ib_dbg_param {
  600. int offset;
  601. struct mlx5_ib_dev *dev;
  602. struct dentry *dentry;
  603. u8 port_num;
  604. };
  605. enum mlx5_ib_dbg_cc_types {
  606. MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE,
  607. MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE_ATI,
  608. MLX5_IB_DBG_CC_RP_TIME_RESET,
  609. MLX5_IB_DBG_CC_RP_BYTE_RESET,
  610. MLX5_IB_DBG_CC_RP_THRESHOLD,
  611. MLX5_IB_DBG_CC_RP_AI_RATE,
  612. MLX5_IB_DBG_CC_RP_HAI_RATE,
  613. MLX5_IB_DBG_CC_RP_MIN_DEC_FAC,
  614. MLX5_IB_DBG_CC_RP_MIN_RATE,
  615. MLX5_IB_DBG_CC_RP_RATE_TO_SET_ON_FIRST_CNP,
  616. MLX5_IB_DBG_CC_RP_DCE_TCP_G,
  617. MLX5_IB_DBG_CC_RP_DCE_TCP_RTT,
  618. MLX5_IB_DBG_CC_RP_RATE_REDUCE_MONITOR_PERIOD,
  619. MLX5_IB_DBG_CC_RP_INITIAL_ALPHA_VALUE,
  620. MLX5_IB_DBG_CC_RP_GD,
  621. MLX5_IB_DBG_CC_NP_CNP_DSCP,
  622. MLX5_IB_DBG_CC_NP_CNP_PRIO_MODE,
  623. MLX5_IB_DBG_CC_NP_CNP_PRIO,
  624. MLX5_IB_DBG_CC_MAX,
  625. };
  626. struct mlx5_ib_dbg_cc_params {
  627. struct dentry *root;
  628. struct mlx5_ib_dbg_param params[MLX5_IB_DBG_CC_MAX];
  629. };
  630. enum {
  631. MLX5_MAX_DELAY_DROP_TIMEOUT_MS = 100,
  632. };
  633. struct mlx5_ib_dbg_delay_drop {
  634. struct dentry *dir_debugfs;
  635. struct dentry *rqs_cnt_debugfs;
  636. struct dentry *events_cnt_debugfs;
  637. struct dentry *timeout_debugfs;
  638. };
  639. struct mlx5_ib_delay_drop {
  640. struct mlx5_ib_dev *dev;
  641. struct work_struct delay_drop_work;
  642. /* serialize setting of delay drop */
  643. struct mutex lock;
  644. u32 timeout;
  645. bool activate;
  646. atomic_t events_cnt;
  647. atomic_t rqs_cnt;
  648. struct mlx5_ib_dbg_delay_drop *dbg;
  649. };
  650. enum mlx5_ib_stages {
  651. MLX5_IB_STAGE_INIT,
  652. MLX5_IB_STAGE_FLOW_DB,
  653. MLX5_IB_STAGE_CAPS,
  654. MLX5_IB_STAGE_NON_DEFAULT_CB,
  655. MLX5_IB_STAGE_ROCE,
  656. MLX5_IB_STAGE_DEVICE_RESOURCES,
  657. MLX5_IB_STAGE_ODP,
  658. MLX5_IB_STAGE_COUNTERS,
  659. MLX5_IB_STAGE_CONG_DEBUGFS,
  660. MLX5_IB_STAGE_UAR,
  661. MLX5_IB_STAGE_BFREG,
  662. MLX5_IB_STAGE_PRE_IB_REG_UMR,
  663. MLX5_IB_STAGE_SPECS,
  664. MLX5_IB_STAGE_IB_REG,
  665. MLX5_IB_STAGE_POST_IB_REG_UMR,
  666. MLX5_IB_STAGE_DELAY_DROP,
  667. MLX5_IB_STAGE_CLASS_ATTR,
  668. MLX5_IB_STAGE_REP_REG,
  669. MLX5_IB_STAGE_MAX,
  670. };
  671. struct mlx5_ib_stage {
  672. int (*init)(struct mlx5_ib_dev *dev);
  673. void (*cleanup)(struct mlx5_ib_dev *dev);
  674. };
  675. #define STAGE_CREATE(_stage, _init, _cleanup) \
  676. .stage[_stage] = {.init = _init, .cleanup = _cleanup}
  677. struct mlx5_ib_profile {
  678. struct mlx5_ib_stage stage[MLX5_IB_STAGE_MAX];
  679. };
  680. struct mlx5_ib_multiport_info {
  681. struct list_head list;
  682. struct mlx5_ib_dev *ibdev;
  683. struct mlx5_core_dev *mdev;
  684. struct completion unref_comp;
  685. u64 sys_image_guid;
  686. u32 mdev_refcnt;
  687. bool is_master;
  688. bool unaffiliate;
  689. };
  690. struct mlx5_ib_flow_action {
  691. struct ib_flow_action ib_action;
  692. union {
  693. struct {
  694. u64 ib_flags;
  695. struct mlx5_accel_esp_xfrm *ctx;
  696. } esp_aes_gcm;
  697. };
  698. };
  699. struct mlx5_memic {
  700. struct mlx5_core_dev *dev;
  701. spinlock_t memic_lock;
  702. DECLARE_BITMAP(memic_alloc_pages, MLX5_MAX_MEMIC_PAGES);
  703. };
  704. struct mlx5_ib_dev {
  705. struct ib_device ib_dev;
  706. struct mlx5_core_dev *mdev;
  707. struct mlx5_roce roce[MLX5_MAX_PORTS];
  708. int num_ports;
  709. /* serialize update of capability mask
  710. */
  711. struct mutex cap_mask_mutex;
  712. bool ib_active;
  713. struct umr_common umrc;
  714. /* sync used page count stats
  715. */
  716. struct mlx5_ib_resources devr;
  717. struct mlx5_mr_cache cache;
  718. struct timer_list delay_timer;
  719. /* Prevents soft lock on massive reg MRs */
  720. struct mutex slow_path_mutex;
  721. int fill_delay;
  722. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  723. struct ib_odp_caps odp_caps;
  724. u64 odp_max_size;
  725. /*
  726. * Sleepable RCU that prevents destruction of MRs while they are still
  727. * being used by a page fault handler.
  728. */
  729. struct srcu_struct mr_srcu;
  730. u32 null_mkey;
  731. #endif
  732. struct mlx5_ib_flow_db *flow_db;
  733. /* protect resources needed as part of reset flow */
  734. spinlock_t reset_flow_resource_lock;
  735. struct list_head qp_list;
  736. /* Array with num_ports elements */
  737. struct mlx5_ib_port *port;
  738. struct mlx5_sq_bfreg bfreg;
  739. struct mlx5_sq_bfreg fp_bfreg;
  740. struct mlx5_ib_delay_drop delay_drop;
  741. const struct mlx5_ib_profile *profile;
  742. struct mlx5_eswitch_rep *rep;
  743. /* protect the user_td */
  744. struct mutex lb_mutex;
  745. u32 user_td;
  746. u8 umr_fence;
  747. struct list_head ib_dev_list;
  748. u64 sys_image_guid;
  749. struct mlx5_memic memic;
  750. };
  751. static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
  752. {
  753. return container_of(mcq, struct mlx5_ib_cq, mcq);
  754. }
  755. static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
  756. {
  757. return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
  758. }
  759. static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
  760. {
  761. return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
  762. }
  763. static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
  764. {
  765. return container_of(ibcq, struct mlx5_ib_cq, ibcq);
  766. }
  767. static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
  768. {
  769. return container_of(mqp, struct mlx5_ib_qp_base, mqp)->container_mibqp;
  770. }
  771. static inline struct mlx5_ib_rwq *to_mibrwq(struct mlx5_core_qp *core_qp)
  772. {
  773. return container_of(core_qp, struct mlx5_ib_rwq, core_qp);
  774. }
  775. static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mkey *mmkey)
  776. {
  777. return container_of(mmkey, struct mlx5_ib_mr, mmkey);
  778. }
  779. static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
  780. {
  781. return container_of(ibpd, struct mlx5_ib_pd, ibpd);
  782. }
  783. static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
  784. {
  785. return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
  786. }
  787. static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
  788. {
  789. return container_of(ibqp, struct mlx5_ib_qp, ibqp);
  790. }
  791. static inline struct mlx5_ib_rwq *to_mrwq(struct ib_wq *ibwq)
  792. {
  793. return container_of(ibwq, struct mlx5_ib_rwq, ibwq);
  794. }
  795. static inline struct mlx5_ib_rwq_ind_table *to_mrwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl)
  796. {
  797. return container_of(ib_rwq_ind_tbl, struct mlx5_ib_rwq_ind_table, ib_rwq_ind_tbl);
  798. }
  799. static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
  800. {
  801. return container_of(msrq, struct mlx5_ib_srq, msrq);
  802. }
  803. static inline struct mlx5_ib_dm *to_mdm(struct ib_dm *ibdm)
  804. {
  805. return container_of(ibdm, struct mlx5_ib_dm, ibdm);
  806. }
  807. static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
  808. {
  809. return container_of(ibmr, struct mlx5_ib_mr, ibmr);
  810. }
  811. static inline struct mlx5_ib_mw *to_mmw(struct ib_mw *ibmw)
  812. {
  813. return container_of(ibmw, struct mlx5_ib_mw, ibmw);
  814. }
  815. static inline struct mlx5_ib_flow_action *
  816. to_mflow_act(struct ib_flow_action *ibact)
  817. {
  818. return container_of(ibact, struct mlx5_ib_flow_action, ib_action);
  819. }
  820. int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
  821. struct mlx5_db *db);
  822. void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
  823. void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  824. void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
  825. void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
  826. int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
  827. u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  828. const void *in_mad, void *response_mad);
  829. struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
  830. struct ib_udata *udata);
  831. int mlx5_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr);
  832. int mlx5_ib_destroy_ah(struct ib_ah *ah);
  833. struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
  834. struct ib_srq_init_attr *init_attr,
  835. struct ib_udata *udata);
  836. int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  837. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
  838. int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
  839. int mlx5_ib_destroy_srq(struct ib_srq *srq);
  840. int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
  841. struct ib_recv_wr **bad_wr);
  842. struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
  843. struct ib_qp_init_attr *init_attr,
  844. struct ib_udata *udata);
  845. int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  846. int attr_mask, struct ib_udata *udata);
  847. int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
  848. struct ib_qp_init_attr *qp_init_attr);
  849. int mlx5_ib_destroy_qp(struct ib_qp *qp);
  850. int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  851. struct ib_send_wr **bad_wr);
  852. int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  853. struct ib_recv_wr **bad_wr);
  854. void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
  855. int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
  856. void *buffer, u32 length,
  857. struct mlx5_ib_qp_base *base);
  858. struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
  859. const struct ib_cq_init_attr *attr,
  860. struct ib_ucontext *context,
  861. struct ib_udata *udata);
  862. int mlx5_ib_destroy_cq(struct ib_cq *cq);
  863. int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  864. int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  865. int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  866. int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
  867. struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
  868. struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  869. u64 virt_addr, int access_flags,
  870. struct ib_udata *udata);
  871. struct ib_mw *mlx5_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
  872. struct ib_udata *udata);
  873. int mlx5_ib_dealloc_mw(struct ib_mw *mw);
  874. int mlx5_ib_update_xlt(struct mlx5_ib_mr *mr, u64 idx, int npages,
  875. int page_shift, int flags);
  876. struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,
  877. int access_flags);
  878. void mlx5_ib_free_implicit_mr(struct mlx5_ib_mr *mr);
  879. int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
  880. u64 length, u64 virt_addr, int access_flags,
  881. struct ib_pd *pd, struct ib_udata *udata);
  882. int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
  883. struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
  884. enum ib_mr_type mr_type,
  885. u32 max_num_sg);
  886. int mlx5_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
  887. unsigned int *sg_offset);
  888. int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  889. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  890. const struct ib_mad_hdr *in, size_t in_mad_size,
  891. struct ib_mad_hdr *out, size_t *out_mad_size,
  892. u16 *out_mad_pkey_index);
  893. struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
  894. struct ib_ucontext *context,
  895. struct ib_udata *udata);
  896. int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  897. int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
  898. int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
  899. int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
  900. struct ib_smp *out_mad);
  901. int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
  902. __be64 *sys_image_guid);
  903. int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
  904. u16 *max_pkeys);
  905. int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
  906. u32 *vendor_id);
  907. int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
  908. int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
  909. int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
  910. u16 *pkey);
  911. int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
  912. union ib_gid *gid);
  913. int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
  914. struct ib_port_attr *props);
  915. int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
  916. struct ib_port_attr *props);
  917. int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
  918. void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
  919. void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
  920. unsigned long max_page_shift,
  921. int *count, int *shift,
  922. int *ncont, int *order);
  923. void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  924. int page_shift, size_t offset, size_t num_pages,
  925. __be64 *pas, int access_flags);
  926. void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
  927. int page_shift, __be64 *pas, int access_flags);
  928. void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
  929. int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
  930. int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
  931. int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
  932. struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, int entry);
  933. void mlx5_mr_cache_free(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr);
  934. int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
  935. struct ib_mr_status *mr_status);
  936. struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd,
  937. struct ib_wq_init_attr *init_attr,
  938. struct ib_udata *udata);
  939. int mlx5_ib_destroy_wq(struct ib_wq *wq);
  940. int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
  941. u32 wq_attr_mask, struct ib_udata *udata);
  942. struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device,
  943. struct ib_rwq_ind_table_init_attr *init_attr,
  944. struct ib_udata *udata);
  945. int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
  946. bool mlx5_ib_dc_atomic_is_supported(struct mlx5_ib_dev *dev);
  947. struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev,
  948. struct ib_ucontext *context,
  949. struct ib_dm_alloc_attr *attr,
  950. struct uverbs_attr_bundle *attrs);
  951. int mlx5_ib_dealloc_dm(struct ib_dm *ibdm);
  952. struct ib_mr *mlx5_ib_reg_dm_mr(struct ib_pd *pd, struct ib_dm *dm,
  953. struct ib_dm_mr_attr *attr,
  954. struct uverbs_attr_bundle *attrs);
  955. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  956. void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
  957. void mlx5_ib_pfault(struct mlx5_core_dev *mdev, void *context,
  958. struct mlx5_pagefault *pfault);
  959. int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
  960. int __init mlx5_ib_odp_init(void);
  961. void mlx5_ib_odp_cleanup(void);
  962. void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
  963. unsigned long end);
  964. void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent);
  965. void mlx5_odp_populate_klm(struct mlx5_klm *pklm, size_t offset,
  966. size_t nentries, struct mlx5_ib_mr *mr, int flags);
  967. #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  968. static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
  969. {
  970. return;
  971. }
  972. static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
  973. static inline int mlx5_ib_odp_init(void) { return 0; }
  974. static inline void mlx5_ib_odp_cleanup(void) {}
  975. static inline void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent) {}
  976. static inline void mlx5_odp_populate_klm(struct mlx5_klm *pklm, size_t offset,
  977. size_t nentries, struct mlx5_ib_mr *mr,
  978. int flags) {}
  979. #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
  980. /* Needed for rep profile */
  981. int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev);
  982. void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev);
  983. int mlx5_ib_stage_rep_flow_db_init(struct mlx5_ib_dev *dev);
  984. int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev);
  985. int mlx5_ib_stage_rep_non_default_cb(struct mlx5_ib_dev *dev);
  986. int mlx5_ib_stage_rep_roce_init(struct mlx5_ib_dev *dev);
  987. void mlx5_ib_stage_rep_roce_cleanup(struct mlx5_ib_dev *dev);
  988. int mlx5_ib_stage_dev_res_init(struct mlx5_ib_dev *dev);
  989. void mlx5_ib_stage_dev_res_cleanup(struct mlx5_ib_dev *dev);
  990. int mlx5_ib_stage_counters_init(struct mlx5_ib_dev *dev);
  991. void mlx5_ib_stage_counters_cleanup(struct mlx5_ib_dev *dev);
  992. int mlx5_ib_stage_bfrag_init(struct mlx5_ib_dev *dev);
  993. void mlx5_ib_stage_bfrag_cleanup(struct mlx5_ib_dev *dev);
  994. void mlx5_ib_stage_pre_ib_reg_umr_cleanup(struct mlx5_ib_dev *dev);
  995. int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev);
  996. void mlx5_ib_stage_ib_reg_cleanup(struct mlx5_ib_dev *dev);
  997. int mlx5_ib_stage_post_ib_reg_umr_init(struct mlx5_ib_dev *dev);
  998. int mlx5_ib_stage_class_attr_init(struct mlx5_ib_dev *dev);
  999. void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
  1000. const struct mlx5_ib_profile *profile,
  1001. int stage);
  1002. void *__mlx5_ib_add(struct mlx5_ib_dev *dev,
  1003. const struct mlx5_ib_profile *profile);
  1004. int mlx5_ib_get_vf_config(struct ib_device *device, int vf,
  1005. u8 port, struct ifla_vf_info *info);
  1006. int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
  1007. u8 port, int state);
  1008. int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
  1009. u8 port, struct ifla_vf_stats *stats);
  1010. int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
  1011. u64 guid, int type);
  1012. __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
  1013. int index);
  1014. int mlx5_get_roce_gid_type(struct mlx5_ib_dev *dev, u8 port_num,
  1015. int index, enum ib_gid_type *gid_type);
  1016. void mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
  1017. int mlx5_ib_init_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
  1018. /* GSI QP helper functions */
  1019. struct ib_qp *mlx5_ib_gsi_create_qp(struct ib_pd *pd,
  1020. struct ib_qp_init_attr *init_attr);
  1021. int mlx5_ib_gsi_destroy_qp(struct ib_qp *qp);
  1022. int mlx5_ib_gsi_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
  1023. int attr_mask);
  1024. int mlx5_ib_gsi_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
  1025. int qp_attr_mask,
  1026. struct ib_qp_init_attr *qp_init_attr);
  1027. int mlx5_ib_gsi_post_send(struct ib_qp *qp, struct ib_send_wr *wr,
  1028. struct ib_send_wr **bad_wr);
  1029. int mlx5_ib_gsi_post_recv(struct ib_qp *qp, struct ib_recv_wr *wr,
  1030. struct ib_recv_wr **bad_wr);
  1031. void mlx5_ib_gsi_pkey_change(struct mlx5_ib_gsi_qp *gsi);
  1032. int mlx5_ib_generate_wc(struct ib_cq *ibcq, struct ib_wc *wc);
  1033. void mlx5_ib_free_bfreg(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi,
  1034. int bfregn);
  1035. struct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi);
  1036. struct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *dev,
  1037. u8 ib_port_num,
  1038. u8 *native_port_num);
  1039. void mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *dev,
  1040. u8 port_num);
  1041. static inline void init_query_mad(struct ib_smp *mad)
  1042. {
  1043. mad->base_version = 1;
  1044. mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  1045. mad->class_version = 1;
  1046. mad->method = IB_MGMT_METHOD_GET;
  1047. }
  1048. static inline u8 convert_access(int acc)
  1049. {
  1050. return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
  1051. (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
  1052. (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
  1053. (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
  1054. MLX5_PERM_LOCAL_READ;
  1055. }
  1056. static inline int is_qp1(enum ib_qp_type qp_type)
  1057. {
  1058. return qp_type == MLX5_IB_QPT_HW_GSI;
  1059. }
  1060. #define MLX5_MAX_UMR_SHIFT 16
  1061. #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
  1062. static inline u32 check_cq_create_flags(u32 flags)
  1063. {
  1064. /*
  1065. * It returns non-zero value for unsupported CQ
  1066. * create flags, otherwise it returns zero.
  1067. */
  1068. return (flags & ~(IB_UVERBS_CQ_FLAGS_IGNORE_OVERRUN |
  1069. IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION));
  1070. }
  1071. static inline int verify_assign_uidx(u8 cqe_version, u32 cmd_uidx,
  1072. u32 *user_index)
  1073. {
  1074. if (cqe_version) {
  1075. if ((cmd_uidx == MLX5_IB_DEFAULT_UIDX) ||
  1076. (cmd_uidx & ~MLX5_USER_ASSIGNED_UIDX_MASK))
  1077. return -EINVAL;
  1078. *user_index = cmd_uidx;
  1079. } else {
  1080. *user_index = MLX5_IB_DEFAULT_UIDX;
  1081. }
  1082. return 0;
  1083. }
  1084. static inline int get_qp_user_index(struct mlx5_ib_ucontext *ucontext,
  1085. struct mlx5_ib_create_qp *ucmd,
  1086. int inlen,
  1087. u32 *user_index)
  1088. {
  1089. u8 cqe_version = ucontext->cqe_version;
  1090. if (field_avail(struct mlx5_ib_create_qp, uidx, inlen) &&
  1091. !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
  1092. return 0;
  1093. if (!!(field_avail(struct mlx5_ib_create_qp, uidx, inlen) !=
  1094. !!cqe_version))
  1095. return -EINVAL;
  1096. return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
  1097. }
  1098. static inline int get_srq_user_index(struct mlx5_ib_ucontext *ucontext,
  1099. struct mlx5_ib_create_srq *ucmd,
  1100. int inlen,
  1101. u32 *user_index)
  1102. {
  1103. u8 cqe_version = ucontext->cqe_version;
  1104. if (field_avail(struct mlx5_ib_create_srq, uidx, inlen) &&
  1105. !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
  1106. return 0;
  1107. if (!!(field_avail(struct mlx5_ib_create_srq, uidx, inlen) !=
  1108. !!cqe_version))
  1109. return -EINVAL;
  1110. return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
  1111. }
  1112. static inline int get_uars_per_sys_page(struct mlx5_ib_dev *dev, bool lib_support)
  1113. {
  1114. return lib_support && MLX5_CAP_GEN(dev->mdev, uar_4k) ?
  1115. MLX5_UARS_IN_PAGE : 1;
  1116. }
  1117. static inline int get_num_static_uars(struct mlx5_ib_dev *dev,
  1118. struct mlx5_bfreg_info *bfregi)
  1119. {
  1120. return get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * bfregi->num_static_sys_pages;
  1121. }
  1122. unsigned long mlx5_ib_get_xlt_emergency_page(void);
  1123. void mlx5_ib_put_xlt_emergency_page(void);
  1124. #endif /* MLX5_IB_H */