mlx5_ib.h 27 KB

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