mlx5_ib.h 28 KB

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