mlx5_ib.h 38 KB

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