mlx5_ib.h 28 KB

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