mlx5_ib.h 39 KB

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