mlx5_ib.h 37 KB

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