xref: /freebsd/sys/dev/mlx5/driver.h (revision d15f2551b25f79ddcbe289faa95e655100b952da)
1 /*-
2  * Copyright (c) 2013-2019, Mellanox Technologies, Ltd.  All rights reserved.
3  * Copyright (c) 2022 NVIDIA corporation & affiliates.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef MLX5_DRIVER_H
28 #define MLX5_DRIVER_H
29 
30 #include "opt_ratelimit.h"
31 
32 #include <linux/kernel.h>
33 #include <linux/completion.h>
34 #include <linux/pci.h>
35 #include <linux/cache.h>
36 #include <linux/rbtree.h>
37 #include <linux/if_ether.h>
38 #include <linux/semaphore.h>
39 #include <linux/slab.h>
40 #include <linux/vmalloc.h>
41 #include <linux/radix-tree.h>
42 #include <linux/idr.h>
43 #include <linux/wait.h>
44 
45 #include <dev/mlx5/device.h>
46 #include <dev/mlx5/doorbell.h>
47 #include <dev/mlx5/srq.h>
48 
49 #define MLX5_QCOUNTER_SETS_NETDEV 64
50 #define MLX5_MAX_NUMBER_OF_VFS 128
51 
52 #define MLX5_INVALID_QUEUE_HANDLE 0xffffffff
53 #define MLX5_ST_SZ_BYTES(typ) (sizeof(struct mlx5_ifc_##typ##_bits) / 8)
54 
55 enum {
56 	MLX5_BOARD_ID_LEN = 64,
57 	MLX5_MAX_NAME_LEN = 16,
58 };
59 
60 enum {
61 	MLX5_CMD_TIMEOUT_MSEC	= 60 * 1000,
62 };
63 
64 enum {
65 	CMD_OWNER_SW		= 0x0,
66 	CMD_OWNER_HW		= 0x1,
67 	CMD_STATUS_SUCCESS	= 0,
68 };
69 
70 enum mlx5_sqp_t {
71 	MLX5_SQP_SMI		= 0,
72 	MLX5_SQP_GSI		= 1,
73 	MLX5_SQP_IEEE_1588	= 2,
74 	MLX5_SQP_SNIFFER	= 3,
75 	MLX5_SQP_SYNC_UMR	= 4,
76 };
77 
78 enum {
79 	MLX5_MAX_PORTS	= 2,
80 };
81 
82 enum {
83 	MLX5_EQ_VEC_PAGES	 = 0,
84 	MLX5_EQ_VEC_CMD		 = 1,
85 	MLX5_EQ_VEC_ASYNC	 = 2,
86 	MLX5_EQ_VEC_COMP_BASE,
87 };
88 
89 enum {
90 	MLX5_ATOMIC_MODE_OFF		= 16,
91 	MLX5_ATOMIC_MODE_NONE		= 0 << MLX5_ATOMIC_MODE_OFF,
92 	MLX5_ATOMIC_MODE_IB_COMP	= 1 << MLX5_ATOMIC_MODE_OFF,
93 	MLX5_ATOMIC_MODE_CX		= 2 << MLX5_ATOMIC_MODE_OFF,
94 	MLX5_ATOMIC_MODE_8B		= 3 << MLX5_ATOMIC_MODE_OFF,
95 	MLX5_ATOMIC_MODE_16B		= 4 << MLX5_ATOMIC_MODE_OFF,
96 	MLX5_ATOMIC_MODE_32B		= 5 << MLX5_ATOMIC_MODE_OFF,
97 	MLX5_ATOMIC_MODE_64B		= 6 << MLX5_ATOMIC_MODE_OFF,
98 	MLX5_ATOMIC_MODE_128B		= 7 << MLX5_ATOMIC_MODE_OFF,
99 	MLX5_ATOMIC_MODE_256B		= 8 << MLX5_ATOMIC_MODE_OFF,
100 };
101 
102 enum {
103 	MLX5_ATOMIC_MODE_DCT_OFF	= 20,
104 	MLX5_ATOMIC_MODE_DCT_NONE	= 0 << MLX5_ATOMIC_MODE_DCT_OFF,
105 	MLX5_ATOMIC_MODE_DCT_IB_COMP	= 1 << MLX5_ATOMIC_MODE_DCT_OFF,
106 	MLX5_ATOMIC_MODE_DCT_CX		= 2 << MLX5_ATOMIC_MODE_DCT_OFF,
107 	MLX5_ATOMIC_MODE_DCT_8B		= 3 << MLX5_ATOMIC_MODE_DCT_OFF,
108 	MLX5_ATOMIC_MODE_DCT_16B	= 4 << MLX5_ATOMIC_MODE_DCT_OFF,
109 	MLX5_ATOMIC_MODE_DCT_32B	= 5 << MLX5_ATOMIC_MODE_DCT_OFF,
110 	MLX5_ATOMIC_MODE_DCT_64B	= 6 << MLX5_ATOMIC_MODE_DCT_OFF,
111 	MLX5_ATOMIC_MODE_DCT_128B	= 7 << MLX5_ATOMIC_MODE_DCT_OFF,
112 	MLX5_ATOMIC_MODE_DCT_256B	= 8 << MLX5_ATOMIC_MODE_DCT_OFF,
113 };
114 
115 enum {
116 	MLX5_ATOMIC_OPS_CMP_SWAP		= 1 << 0,
117 	MLX5_ATOMIC_OPS_FETCH_ADD		= 1 << 1,
118 	MLX5_ATOMIC_OPS_MASKED_CMP_SWAP		= 1 << 2,
119 	MLX5_ATOMIC_OPS_MASKED_FETCH_ADD	= 1 << 3,
120 };
121 
122 enum {
123 	MLX5_REG_QPTS		 = 0x4002,
124 	MLX5_REG_QETCR		 = 0x4005,
125 	MLX5_REG_QPDP		 = 0x4007,
126 	MLX5_REG_QTCT		 = 0x400A,
127 	MLX5_REG_QPDPM		 = 0x4013,
128 	MLX5_REG_QHLL		 = 0x4016,
129 	MLX5_REG_QCAM		 = 0x4019,
130 	MLX5_REG_DCBX_PARAM	 = 0x4020,
131 	MLX5_REG_DCBX_APP	 = 0x4021,
132 	MLX5_REG_FPGA_CAP	 = 0x4022,
133 	MLX5_REG_FPGA_CTRL	 = 0x4023,
134 	MLX5_REG_FPGA_ACCESS_REG = 0x4024,
135 	MLX5_REG_FPGA_SHELL_CNTR = 0x4025,
136 	MLX5_REG_PCAP		 = 0x5001,
137 	MLX5_REG_PMLP		 = 0x5002,
138 	MLX5_REG_PMTU		 = 0x5003,
139 	MLX5_REG_PTYS		 = 0x5004,
140 	MLX5_REG_PAOS		 = 0x5006,
141 	MLX5_REG_PFCC		 = 0x5007,
142 	MLX5_REG_PPCNT		 = 0x5008,
143 	MLX5_REG_PUDE		 = 0x5009,
144 	MLX5_REG_PPTB		 = 0x500B,
145 	MLX5_REG_PBMC		 = 0x500C,
146 	MLX5_REG_PELC		 = 0x500E,
147 	MLX5_REG_PVLC		 = 0x500F,
148 	MLX5_REG_PMPE		 = 0x5010,
149 	MLX5_REG_PMAOS		 = 0x5012,
150 	MLX5_REG_PPLM		 = 0x5023,
151 	MLX5_REG_PDDR		 = 0x5031,
152 	MLX5_REG_PBSR		 = 0x5038,
153 	MLX5_REG_PCAM		 = 0x507f,
154 	MLX5_REG_NODE_DESC	 = 0x6001,
155 	MLX5_REG_HOST_ENDIANNESS = 0x7004,
156 	MLX5_REG_MTMP		 = 0x900a,
157 	MLX5_REG_MCIA		 = 0x9014,
158 	MLX5_REG_MFRL		 = 0x9028,
159 	MLX5_REG_MPCNT		 = 0x9051,
160 	MLX5_REG_MCQI		 = 0x9061,
161 	MLX5_REG_MCC		 = 0x9062,
162 	MLX5_REG_MCDA		 = 0x9063,
163 	MLX5_REG_MCAM		 = 0x907f,
164 };
165 
166 enum dbg_rsc_type {
167 	MLX5_DBG_RSC_QP,
168 	MLX5_DBG_RSC_EQ,
169 	MLX5_DBG_RSC_CQ,
170 };
171 
172 enum {
173 	MLX5_INTERFACE_PROTOCOL_IB  = 0,
174 	MLX5_INTERFACE_PROTOCOL_ETH = 1,
175 	MLX5_INTERFACE_NUMBER       = 2,
176 };
177 
178 struct mlx5_field_desc {
179 	int			i;
180 };
181 
182 struct mlx5_rsc_debug {
183 	struct mlx5_core_dev   *dev;
184 	void		       *object;
185 	enum dbg_rsc_type	type;
186 	struct mlx5_field_desc	fields[0];
187 };
188 
189 enum mlx5_dev_event {
190 	MLX5_DEV_EVENT_SYS_ERROR,
191 	MLX5_DEV_EVENT_PORT_UP,
192 	MLX5_DEV_EVENT_PORT_DOWN,
193 	MLX5_DEV_EVENT_PORT_INITIALIZED,
194 	MLX5_DEV_EVENT_LID_CHANGE,
195 	MLX5_DEV_EVENT_PKEY_CHANGE,
196 	MLX5_DEV_EVENT_GUID_CHANGE,
197 	MLX5_DEV_EVENT_CLIENT_REREG,
198 	MLX5_DEV_EVENT_VPORT_CHANGE,
199 	MLX5_DEV_EVENT_ERROR_STATE_DCBX,
200 	MLX5_DEV_EVENT_REMOTE_CONFIG_CHANGE,
201 	MLX5_DEV_EVENT_LOCAL_OPER_CHANGE,
202 	MLX5_DEV_EVENT_REMOTE_CONFIG_APPLICATION_PRIORITY_CHANGE,
203 };
204 
205 enum mlx5_port_status {
206 	MLX5_PORT_UP        = 1 << 0,
207 	MLX5_PORT_DOWN      = 1 << 1,
208 };
209 
210 enum {
211 	MLX5_VSC_SPACE_SUPPORTED = 0x1,
212 	MLX5_VSC_SPACE_OFFSET	 = 0x4,
213 	MLX5_VSC_COUNTER_OFFSET	 = 0x8,
214 	MLX5_VSC_SEMA_OFFSET	 = 0xC,
215 	MLX5_VSC_ADDR_OFFSET	 = 0x10,
216 	MLX5_VSC_DATA_OFFSET	 = 0x14,
217 	MLX5_VSC_MAX_RETRIES	 = 0x1000,
218 };
219 
220 #define MLX5_PROT_MASK(link_mode) (1 << link_mode)
221 
222 struct mlx5_cmd_first {
223 	__be32		data[4];
224 };
225 
226 struct cache_ent;
227 struct mlx5_fw_page {
228 	union {
229 		struct rb_node rb_node;
230 		struct list_head list;
231 	};
232 	struct mlx5_cmd_first first;
233 	struct mlx5_core_dev *dev;
234 	bus_dmamap_t dma_map;
235 	bus_addr_t dma_addr;
236 	void *virt_addr;
237 	struct cache_ent *cache;
238 	u32 numpages;
239 	u16 load_done;
240 #define	MLX5_LOAD_ST_NONE 0
241 #define	MLX5_LOAD_ST_SUCCESS 1
242 #define	MLX5_LOAD_ST_FAILURE 2
243 	u16 func_id;
244 };
245 #define	mlx5_cmd_msg mlx5_fw_page
246 
247 struct mlx5_cmd_debug {
248 	void		       *in_msg;
249 	void		       *out_msg;
250 	u8			status;
251 	u16			inlen;
252 	u16			outlen;
253 };
254 
255 struct cache_ent {
256 	/* protect block chain allocations
257 	 */
258 	spinlock_t		lock;
259 	struct list_head	head;
260 };
261 
262 struct cmd_msg_cache {
263 	struct cache_ent	large;
264 	struct cache_ent	med;
265 
266 };
267 
268 struct mlx5_traffic_counter {
269 	u64         packets;
270 	u64         octets;
271 };
272 
273 struct mlx5_fc_pool {
274 	struct mlx5_core_dev *dev;
275 	struct mutex pool_lock; /* protects pool lists */
276 	struct list_head fully_used;
277 	struct list_head partially_used;
278 	struct list_head unused;
279 	int available_fcs;
280 	int used_fcs;
281 	int threshold;
282 };
283 
284 struct mlx5_fc_stats {
285 	spinlock_t counters_idr_lock; /* protects counters_idr */
286 	struct idr counters_idr;
287 	struct list_head counters;
288 	struct llist_head addlist;
289 	struct llist_head dellist;
290 
291 	struct workqueue_struct *wq;
292 	struct delayed_work work;
293 	unsigned long next_query;
294 	unsigned long sampling_interval; /* jiffies */
295 	u32 *bulk_query_out;
296 	int bulk_query_len;
297 	size_t num_counters;
298 	bool bulk_query_alloc_failed;
299 	unsigned long next_bulk_query_alloc;
300 	struct mlx5_fc_pool fc_pool;
301 };
302 
303 enum mlx5_cmd_mode {
304 	MLX5_CMD_MODE_POLLING,
305 	MLX5_CMD_MODE_EVENTS
306 };
307 
308 struct mlx5_cmd_stats {
309 	u64		sum;
310 	u64		n;
311 	/* protect command average calculations */
312 	spinlock_t	lock;
313 };
314 
315 struct mlx5_cmd {
316 	struct mlx5_fw_page *cmd_page;
317 	bus_dma_tag_t dma_tag;
318 	struct sx dma_sx;
319 	struct mtx dma_mtx;
320 #define	MLX5_DMA_OWNED(dev) mtx_owned(&(dev)->cmd.dma_mtx)
321 #define	MLX5_DMA_LOCK(dev) mtx_lock(&(dev)->cmd.dma_mtx)
322 #define	MLX5_DMA_UNLOCK(dev) mtx_unlock(&(dev)->cmd.dma_mtx)
323 	struct cv dma_cv;
324 #define	MLX5_DMA_DONE(dev) cv_broadcast(&(dev)->cmd.dma_cv)
325 #define	MLX5_DMA_WAIT(dev) cv_wait(&(dev)->cmd.dma_cv, &(dev)->cmd.dma_mtx)
326 	void	       *cmd_buf;
327 	dma_addr_t	dma;
328 	u16		cmdif_rev;
329 	u8		log_sz;
330 	u8		log_stride;
331 	int		max_reg_cmds;
332 	int		events;
333 	u32 __iomem    *vector;
334 
335 	/* protect command queue allocations
336 	 */
337 	spinlock_t	alloc_lock;
338 
339 	/* protect token allocations
340 	 */
341 	spinlock_t	token_lock;
342 	u8		token;
343 	unsigned long	bitmask;
344 	struct semaphore sem;
345 	struct semaphore pages_sem;
346 	enum mlx5_cmd_mode mode;
347 	struct mlx5_cmd_work_ent * volatile ent_arr[MLX5_MAX_COMMANDS];
348 	volatile enum mlx5_cmd_mode ent_mode[MLX5_MAX_COMMANDS];
349 	struct mlx5_cmd_debug dbg;
350 	struct cmd_msg_cache cache;
351 	int checksum_disabled;
352 	struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
353 };
354 
355 struct mlx5_port_caps {
356 	int	gid_table_len;
357 	int	pkey_table_len;
358 	u8	ext_port_cap;
359 };
360 
361 struct mlx5_buf {
362 	bus_dma_tag_t		dma_tag;
363 	bus_dmamap_t		dma_map;
364 	struct mlx5_core_dev   *dev;
365 	struct {
366 		void	       *buf;
367 	} direct;
368 	u64		       *page_list;
369 	int			npages;
370 	int			size;
371 	u8			page_shift;
372 	u8			load_done;
373 };
374 
375 struct mlx5_frag_buf {
376 	struct mlx5_buf_list	*frags;
377 	int			npages;
378 	int			size;
379 	u8			page_shift;
380 };
381 
382 struct mlx5_eq {
383 	struct mlx5_core_dev   *dev;
384 	__be32 __iomem	       *doorbell;
385 	u32			cons_index;
386 	struct mlx5_buf		buf;
387 	int			size;
388 	u8			irqn;
389 	u8			eqn;
390 	int			nent;
391 	u64			mask;
392 	struct list_head	list;
393 	int			index;
394 	struct mlx5_rsc_debug	*dbg;
395 };
396 
397 struct mlx5_core_psv {
398 	u32	psv_idx;
399 	struct psv_layout {
400 		u32	pd;
401 		u16	syndrome;
402 		u16	reserved;
403 		u16	bg;
404 		u16	app_tag;
405 		u32	ref_tag;
406 	} psv;
407 };
408 
409 struct mlx5_core_sig_ctx {
410 	struct mlx5_core_psv	psv_memory;
411 	struct mlx5_core_psv	psv_wire;
412 	struct ib_sig_err       err_item;
413 	bool			sig_status_checked;
414 	bool			sig_err_exists;
415 	u32			sigerr_count;
416 };
417 
418 enum {
419 	MLX5_MKEY_MR = 1,
420 	MLX5_MKEY_MW,
421 	MLX5_MKEY_INDIRECT_DEVX,
422 };
423 
424 struct mlx5_core_mkey {
425 	u64			iova;
426 	u64			size;
427 	u32			key;
428 	u32			pd;
429 	u32			type;
430 };
431 
432 enum mlx5_res_type {
433 	MLX5_RES_QP	= MLX5_EVENT_QUEUE_TYPE_QP,
434 	MLX5_RES_RQ	= MLX5_EVENT_QUEUE_TYPE_RQ,
435 	MLX5_RES_SQ	= MLX5_EVENT_QUEUE_TYPE_SQ,
436 	MLX5_RES_SRQ	= 3,
437 	MLX5_RES_XSRQ	= 4,
438 	MLX5_RES_XRQ	= 5,
439 	MLX5_RES_DCT	= MLX5_EVENT_QUEUE_TYPE_DCT,
440 };
441 
442 struct mlx5_core_rsc_common {
443 	enum mlx5_res_type	res;
444 	atomic_t		refcount;
445 	struct completion	free;
446 };
447 
448 struct mlx5_uars_page {
449 	void __iomem	       *map;
450 	bool			wc;
451 	u32			index;
452 	struct list_head	list;
453 	unsigned int		bfregs;
454 	unsigned long	       *reg_bitmap; /* for non fast path bf regs */
455 	unsigned long	       *fp_bitmap;
456 	unsigned int		reg_avail;
457 	unsigned int		fp_avail;
458 	struct kref		ref_count;
459 	struct mlx5_core_dev   *mdev;
460 };
461 
462 struct mlx5_bfreg_head {
463 	/* protect blue flame registers allocations */
464 	struct mutex		lock;
465 	struct list_head	list;
466 };
467 
468 struct mlx5_bfreg_data {
469 	struct mlx5_bfreg_head	reg_head;
470 	struct mlx5_bfreg_head	wc_head;
471 };
472 
473 struct mlx5_sq_bfreg {
474 	void __iomem	       *map;
475 	struct mlx5_uars_page  *up;
476 	bool			wc;
477 	u32			index;
478 	unsigned int		offset;
479 };
480 
481 struct mlx5_core_srq {
482 	struct mlx5_core_rsc_common	common; /* must be first */
483 	u32				srqn;
484 	u16				uid;
485 	int				max;
486 	size_t				max_gs;
487 	size_t				max_avail_gather;
488 	int				wqe_shift;
489 	void				(*event)(struct mlx5_core_srq *, int);
490 	atomic_t			refcount;
491 	struct completion		free;
492 };
493 
494 struct mlx5_ib_dev;
495 struct mlx5_eq_table {
496 	void __iomem	       *update_ci;
497 	void __iomem	       *update_arm_ci;
498 	struct list_head	comp_eqs_list;
499 	struct mlx5_eq		pages_eq;
500 	struct mlx5_eq		async_eq;
501 	struct mlx5_eq		cmd_eq;
502 	int			num_comp_vectors;
503 	spinlock_t		lock;	/* protect EQs list */
504 	struct mlx5_ib_dev	*dev;	/* for devx event notifier */
505 	bool (*cb)(struct mlx5_core_dev *mdev,
506 		   uint8_t event_type, void *data);
507 };
508 
509 struct mlx5_core_health {
510 	struct mlx5_health_buffer __iomem	*health;
511 	__be32 __iomem		       *health_counter;
512 	struct timer_list		timer;
513 	u32				prev;
514 	int				miss_counter;
515 	u32				fatal_error;
516 	struct workqueue_struct	       *wq_watchdog;
517 	struct work_struct		work_watchdog;
518 	/* wq spinlock to synchronize draining */
519 	spinlock_t			wq_lock;
520 	struct workqueue_struct	       *wq;
521 	unsigned long			flags;
522 	struct work_struct		work;
523 	struct delayed_work		recover_work;
524 	unsigned int			last_reset_req;
525 	struct work_struct		work_cmd_completion;
526 	struct workqueue_struct	       *wq_cmd;
527 };
528 
529 #define	MLX5_CQ_LINEAR_ARRAY_SIZE	1024
530 
531 struct mlx5_cq_linear_array_entry {
532 	struct mlx5_core_cq * volatile cq;
533 };
534 
535 struct mlx5_cq_table {
536 	/* protect radix tree
537 	 */
538 	spinlock_t		writerlock;
539 	atomic_t		writercount;
540 	struct radix_tree_root	tree;
541 	struct mlx5_cq_linear_array_entry linear_array[MLX5_CQ_LINEAR_ARRAY_SIZE];
542 };
543 
544 struct mlx5_qp_table {
545 	/* protect radix tree
546 	 */
547 	spinlock_t		lock;
548 	struct radix_tree_root	tree;
549 };
550 
551 struct mlx5_srq_table {
552 	/* protect radix tree
553 	 */
554 	spinlock_t		lock;
555 	struct radix_tree_root	tree;
556 };
557 
558 struct mlx5_mr_table {
559 	/* protect radix tree
560 	 */
561 	spinlock_t		lock;
562 	struct radix_tree_root	tree;
563 };
564 
565 #ifdef RATELIMIT
566 struct mlx5_rl_entry {
567 	u32			rate;
568 	u16			burst;
569 	u16			index;
570 	u32			qos_handle; /* schedule queue handle */
571 	u32			refcount;
572 };
573 
574 struct mlx5_rl_table {
575 	struct mutex		rl_lock;
576 	u16			max_size;
577 	u32			max_rate;
578 	u32			min_rate;
579 	struct mlx5_rl_entry   *rl_entry;
580 };
581 #endif
582 
583 struct mlx5_pme_stats {
584 	u64			status_counters[MLX5_MODULE_STATUS_NUM];
585 	u64			error_counters[MLX5_MODULE_EVENT_ERROR_NUM];
586 };
587 
588 struct mlx5_priv {
589 	char			name[MLX5_MAX_NAME_LEN];
590 	struct mlx5_eq_table	eq_table;
591 	struct msix_entry	*msix_arr;
592 	MLX5_DECLARE_DOORBELL_LOCK(cq_uar_lock);
593 	int			disable_irqs;
594 
595 	/* pages stuff */
596 	struct workqueue_struct *pg_wq;
597 	struct rb_root		page_root;
598 	s64			fw_pages;
599 	atomic_t		reg_pages;
600 	s64			pages_per_func[MLX5_MAX_NUMBER_OF_VFS];
601 	struct mlx5_core_health health;
602 
603 	struct mlx5_srq_table	srq_table;
604 
605 	/* start: qp staff */
606 	struct mlx5_qp_table	qp_table;
607 
608 	/* end: qp staff */
609 
610 	/* start: cq staff */
611 	struct mlx5_cq_table	cq_table;
612 	/* end: cq staff */
613 
614 	/* start: mr staff */
615 	struct mlx5_mr_table	mr_table;
616 	/* end: mr staff */
617 
618 	/* start: alloc staff */
619 	int			numa_node;
620 
621 	struct mutex   pgdir_mutex;
622 	struct list_head        pgdir_list;
623 	/* end: alloc staff */
624 
625 	/* protect mkey key part */
626 	spinlock_t		mkey_lock;
627 	u8			mkey_key;
628 
629 	struct list_head        dev_list;
630 	struct list_head        ctx_list;
631 	spinlock_t              ctx_lock;
632 	unsigned long		pci_dev_data;
633 #ifdef RATELIMIT
634 	struct mlx5_rl_table	rl_table;
635 #endif
636 	struct mlx5_pme_stats pme_stats;
637 
638 	struct mlx5_flow_steering *steering;
639 	struct mlx5_eswitch	*eswitch;
640 
641 	struct mlx5_bfreg_data		bfregs;
642 	struct mlx5_uars_page	       *uar;
643 	struct mlx5_fc_stats		fc_stats;
644 	struct mlx5_ft_pool             *ft_pool;
645 };
646 
647 enum mlx5_device_state {
648 	MLX5_DEVICE_STATE_UP,
649 	MLX5_DEVICE_STATE_INTERNAL_ERROR,
650 };
651 
652 enum mlx5_interface_state {
653 	MLX5_INTERFACE_STATE_UP = 0x1,
654 	MLX5_INTERFACE_STATE_TEARDOWN = 0x2,
655 };
656 
657 enum mlx5_pci_status {
658 	MLX5_PCI_STATUS_DISABLED,
659 	MLX5_PCI_STATUS_ENABLED,
660 };
661 
662 #define	MLX5_MAX_RESERVED_GIDS	8
663 
664 struct mlx5_rsvd_gids {
665 	unsigned int start;
666 	unsigned int count;
667 	struct ida ida;
668 };
669 
670 struct mlx5_special_contexts {
671 	int resd_lkey;
672 };
673 
674 struct mlx5_diag_cnt_id {
675 	u16	id;
676 	bool	enabled;
677 };
678 
679 struct mlx5_diag_cnt {
680 #define	DIAG_LOCK(dc) mutex_lock(&(dc)->lock)
681 #define	DIAG_UNLOCK(dc) mutex_unlock(&(dc)->lock)
682 	struct mutex lock;
683 	struct sysctl_ctx_list sysctl_ctx;
684 	struct mlx5_diag_cnt_id *cnt_id;
685 	u16	num_of_samples;
686 	u16	sample_index;
687 	u8	num_cnt_id;
688 	u8	log_num_of_samples;
689 	u8	log_sample_period;
690 	u8	flag;
691 	u8	ready;
692 };
693 
694 struct mlx5_flow_root_namespace;
695 struct mlx5_core_dev {
696 	struct pci_dev	       *pdev;
697 	/* sync pci state */
698 	struct mutex		pci_status_mutex;
699 	enum mlx5_pci_status	pci_status;
700 	char			board_id[MLX5_BOARD_ID_LEN];
701 	struct mlx5_cmd		cmd;
702 	struct mlx5_port_caps	port_caps[MLX5_MAX_PORTS];
703 	u32 hca_caps_cur[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
704 	u32 hca_caps_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
705 	struct {
706 		u32 pcam[MLX5_ST_SZ_DW(pcam_reg)];
707 		u32 mcam[MLX5_ST_SZ_DW(mcam_reg)];
708 		u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
709 		u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
710 	} caps;
711 	phys_addr_t		iseg_base;
712 	struct mlx5_init_seg __iomem *iseg;
713 	enum mlx5_device_state	state;
714 	/* sync interface state */
715 	struct mutex		intf_state_mutex;
716 	unsigned long		intf_state;
717 	void			(*event) (struct mlx5_core_dev *dev,
718 					  enum mlx5_dev_event event,
719 					  unsigned long param);
720 	struct mlx5_priv	priv;
721 	struct mlx5_profile	*profile;
722 	atomic_t		num_qps;
723 	struct mlx5_diag_cnt	diag_cnt;
724 	u32			vsc_addr;
725 	u32			issi;
726 	struct mlx5_special_contexts special_contexts;
727 	unsigned int module_status;
728 	unsigned int module_num;
729 	struct mlx5_flow_root_namespace *root_ns;
730 	struct mlx5_flow_root_namespace *fdb_root_ns;
731 	struct mlx5_flow_root_namespace *esw_egress_root_ns;
732 	struct mlx5_flow_root_namespace *esw_ingress_root_ns;
733 	struct mlx5_flow_root_namespace *sniffer_rx_root_ns;
734 	struct mlx5_flow_root_namespace *sniffer_tx_root_ns;
735 	struct mlx5_flow_root_namespace *nic_tx_root_ns;
736 	struct mlx5_flow_root_namespace *rdma_tx_root_ns;
737 	struct mlx5_flow_root_namespace *rdma_rx_root_ns;
738 
739 	u32 num_q_counter_allocated[MLX5_INTERFACE_NUMBER];
740 	struct mlx5_crspace_regmap *dump_rege;
741 	uint32_t *dump_data;
742 	unsigned dump_size;
743 	bool dump_valid;
744 	bool dump_copyout;
745 	struct mtx dump_lock;
746 
747 	bool			iov_pf;
748 
749 	struct sysctl_ctx_list	sysctl_ctx;
750 	int			msix_eqvec;
751 	int			pwr_status;
752 	int			pwr_value;
753 
754 	struct {
755 		struct mlx5_rsvd_gids	reserved_gids;
756 		atomic_t		roce_en;
757 	} roce;
758 
759 	struct {
760 		spinlock_t	spinlock;
761 #define	MLX5_MPFS_TABLE_MAX 32
762 		long		bitmap[BITS_TO_LONGS(MLX5_MPFS_TABLE_MAX)];
763 	} mpfs;
764 #ifdef CONFIG_MLX5_FPGA
765 	struct mlx5_fpga_device	*fpga;
766 #endif
767 	struct xarray ipsec_sadb;
768 };
769 
770 enum {
771 	MLX5_WOL_DISABLE       = 0,
772 	MLX5_WOL_SECURED_MAGIC = 1 << 1,
773 	MLX5_WOL_MAGIC         = 1 << 2,
774 	MLX5_WOL_ARP           = 1 << 3,
775 	MLX5_WOL_BROADCAST     = 1 << 4,
776 	MLX5_WOL_MULTICAST     = 1 << 5,
777 	MLX5_WOL_UNICAST       = 1 << 6,
778 	MLX5_WOL_PHY_ACTIVITY  = 1 << 7,
779 };
780 
781 struct mlx5_db {
782 	__be32			*db;
783 	union {
784 		struct mlx5_db_pgdir		*pgdir;
785 		struct mlx5_ib_user_db_page	*user_page;
786 	}			u;
787 	dma_addr_t		dma;
788 	int			index;
789 };
790 
791 struct mlx5_net_counters {
792 	u64	packets;
793 	u64	octets;
794 };
795 
796 struct mlx5_ptys_reg {
797 	u8	an_dis_admin;
798 	u8	an_dis_ap;
799 	u8	local_port;
800 	u8	proto_mask;
801 	u32	eth_proto_cap;
802 	u16	ib_link_width_cap;
803 	u16	ib_proto_cap;
804 	u32	eth_proto_admin;
805 	u16	ib_link_width_admin;
806 	u16	ib_proto_admin;
807 	u32	eth_proto_oper;
808 	u16	ib_link_width_oper;
809 	u16	ib_proto_oper;
810 	u32	eth_proto_lp_advertise;
811 };
812 
813 struct mlx5_pvlc_reg {
814 	u8	local_port;
815 	u8	vl_hw_cap;
816 	u8	vl_admin;
817 	u8	vl_operational;
818 };
819 
820 struct mlx5_pmtu_reg {
821 	u8	local_port;
822 	u16	max_mtu;
823 	u16	admin_mtu;
824 	u16	oper_mtu;
825 };
826 
827 struct mlx5_vport_counters {
828 	struct mlx5_net_counters	received_errors;
829 	struct mlx5_net_counters	transmit_errors;
830 	struct mlx5_net_counters	received_ib_unicast;
831 	struct mlx5_net_counters	transmitted_ib_unicast;
832 	struct mlx5_net_counters	received_ib_multicast;
833 	struct mlx5_net_counters	transmitted_ib_multicast;
834 	struct mlx5_net_counters	received_eth_broadcast;
835 	struct mlx5_net_counters	transmitted_eth_broadcast;
836 	struct mlx5_net_counters	received_eth_unicast;
837 	struct mlx5_net_counters	transmitted_eth_unicast;
838 	struct mlx5_net_counters	received_eth_multicast;
839 	struct mlx5_net_counters	transmitted_eth_multicast;
840 };
841 
842 enum {
843 	MLX5_DB_PER_PAGE = MLX5_ADAPTER_PAGE_SIZE / L1_CACHE_BYTES,
844 };
845 
846 struct mlx5_core_dct {
847 	struct mlx5_core_rsc_common	common; /* must be first */
848 	void (*event)(struct mlx5_core_dct *, int);
849 	int			dctn;
850 	struct completion	drained;
851 	struct mlx5_rsc_debug	*dbg;
852 	int			pid;
853 	u16			uid;
854 };
855 
856 enum {
857 	MLX5_PTYS_IB = 1 << 0,
858 	MLX5_PTYS_EN = 1 << 2,
859 };
860 
861 struct mlx5_db_pgdir {
862 	struct list_head	list;
863 	DECLARE_BITMAP(bitmap, MLX5_DB_PER_PAGE);
864 	struct mlx5_fw_page    *fw_page;
865 	__be32		       *db_page;
866 	dma_addr_t		db_dma;
867 };
868 
869 typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
870 
871 struct mlx5_cmd_work_ent {
872 	struct mlx5_cmd_msg    *in;
873 	struct mlx5_cmd_msg    *out;
874 	int			uin_size;
875 	void		       *uout;
876 	int			uout_size;
877 	mlx5_cmd_cbk_t		callback;
878         struct delayed_work     cb_timeout_work;
879 	void		       *context;
880 	int			idx;
881 	struct completion	done;
882 	struct mlx5_cmd        *cmd;
883 	struct work_struct	work;
884 	struct mlx5_cmd_layout *lay;
885 	int			ret;
886 	int			page_queue;
887 	u8			status;
888 	u8			token;
889 	u64			ts1;
890 	u64			ts2;
891 	u16			op;
892 	u8			busy;
893 	bool			polling;
894 	struct work_struct	freew;
895 };
896 
897 struct mlx5_pas {
898 	u64	pa;
899 	u8	log_sz;
900 };
901 
902 enum port_state_policy {
903 	MLX5_POLICY_DOWN        = 0,
904 	MLX5_POLICY_UP          = 1,
905 	MLX5_POLICY_FOLLOW      = 2,
906 	MLX5_POLICY_INVALID     = 0xffffffff
907 };
908 
909 static inline void *
910 mlx5_buf_offset(struct mlx5_buf *buf, int offset)
911 {
912 	return ((char *)buf->direct.buf + offset);
913 }
914 
915 
916 extern struct workqueue_struct *mlx5_core_wq;
917 
918 #define STRUCT_FIELD(header, field) \
919 	.struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field),      \
920 	.struct_size_bytes   = sizeof((struct ib_unpacked_ ## header *)0)->field
921 
922 static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
923 {
924 	return pci_get_drvdata(pdev);
925 }
926 
927 static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
928 {
929 	return ioread32be(&dev->iseg->fw_rev) & 0xffff;
930 }
931 
932 static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
933 {
934 	return ioread32be(&dev->iseg->fw_rev) >> 16;
935 }
936 
937 static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
938 {
939 	return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
940 }
941 
942 static inline u16 cmdif_rev_get(struct mlx5_core_dev *dev)
943 {
944 	return ioread32be(&dev->iseg->cmdif_rev_fw_sub) >> 16;
945 }
946 
947 static inline int mlx5_get_gid_table_len(u16 param)
948 {
949 	if (param > 4) {
950 		printf("M4_CORE_DRV_NAME: WARN: ""gid table length is zero\n");
951 		return 0;
952 	}
953 
954 	return 8 * (1 << param);
955 }
956 
957 static inline void *mlx5_vzalloc(unsigned long size)
958 {
959 	void *rtn;
960 
961 	rtn = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
962 	return rtn;
963 }
964 
965 static inline void *mlx5_vmalloc(unsigned long size)
966 {
967 	void *rtn;
968 
969 	rtn = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
970 	if (!rtn)
971 		rtn = vmalloc(size);
972 	return rtn;
973 }
974 
975 static inline u32 mlx5_base_mkey(const u32 key)
976 {
977 	return key & 0xffffff00u;
978 }
979 
980 int mlx5_cmd_init(struct mlx5_core_dev *dev);
981 void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
982 void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
983 void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
984 void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
985 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
986 
987 struct mlx5_async_ctx {
988 	struct mlx5_core_dev *dev;
989 	atomic_t num_inflight;
990 	struct wait_queue_head wait;
991 };
992 
993 struct mlx5_async_work;
994 
995 typedef void (*mlx5_async_cbk_t)(int status, struct mlx5_async_work *context);
996 
997 struct mlx5_async_work {
998 	struct mlx5_async_ctx *ctx;
999 	mlx5_async_cbk_t user_callback;
1000 };
1001 
1002 void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
1003 			     struct mlx5_async_ctx *ctx);
1004 void mlx5_cmd_cleanup_async_ctx(struct mlx5_async_ctx *ctx);
1005 int mlx5_cmd_exec_cb(struct mlx5_async_ctx *ctx, void *in, int in_size,
1006 		     void *out, int out_size, mlx5_async_cbk_t callback,
1007 		     struct mlx5_async_work *work);
1008 int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1009 		  int out_size);
1010 #define mlx5_cmd_exec_inout(dev, ifc_cmd, in, out)                             \
1011 	({                                                                     \
1012 		mlx5_cmd_exec(dev, in, MLX5_ST_SZ_BYTES(ifc_cmd##_in), out,    \
1013 			      MLX5_ST_SZ_BYTES(ifc_cmd##_out));                \
1014 	})
1015 
1016 #define mlx5_cmd_exec_in(dev, ifc_cmd, in)                                     \
1017 	({                                                                     \
1018 		u32 _out[MLX5_ST_SZ_DW(ifc_cmd##_out)] = {};                   \
1019 		mlx5_cmd_exec_inout(dev, ifc_cmd, in, _out);                   \
1020 	})
1021 int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
1022 			  void *out, int out_size);
1023 int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
1024 int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
1025 int mlx5_alloc_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg,
1026 		     bool map_wc, bool fast_path);
1027 void mlx5_free_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg);
1028 struct mlx5_uars_page *mlx5_get_uars_page(struct mlx5_core_dev *mdev);
1029 void mlx5_put_uars_page(struct mlx5_core_dev *mdev, struct mlx5_uars_page *up);
1030 void mlx5_health_cleanup(struct mlx5_core_dev *dev);
1031 int mlx5_health_init(struct mlx5_core_dev *dev);
1032 void mlx5_start_health_poll(struct mlx5_core_dev *dev);
1033 void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);
1034 void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
1035 void mlx5_drain_health_recovery(struct mlx5_core_dev *dev);
1036 void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
1037 void mlx5_trigger_health_watchdog(struct mlx5_core_dev *dev);
1038 
1039 int mlx5_buf_alloc(struct mlx5_core_dev *dev, int size, int max_direct,
1040 		   struct mlx5_buf *buf);
1041 void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf);
1042 int mlx5_core_create_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1043 			 struct mlx5_srq_attr *in);
1044 int mlx5_core_destroy_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq);
1045 int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1046 			struct mlx5_srq_attr *out);
1047 int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
1048 int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1049 		      u16 lwm, int is_srq);
1050 void mlx5_init_mr_table(struct mlx5_core_dev *dev);
1051 void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev);
1052 int mlx5_core_create_mkey_cb(struct mlx5_core_dev *dev,
1053 			     struct mlx5_core_mkey *mkey,
1054 			     struct mlx5_async_ctx *async_ctx, u32 *in,
1055 			     int inlen, u32 *out, int outlen,
1056 			     mlx5_async_cbk_t callback,
1057 			     struct mlx5_async_work *context);
1058 int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
1059 			  struct mlx5_core_mkey *mr,
1060 			  u32 *in, int inlen);
1061 int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey);
1062 int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey,
1063 			 u32 *out, int outlen);
1064 int mlx5_core_dump_fill_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mr,
1065 			     u32 *mkey);
1066 int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn, u16 uid);
1067 int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn, u16 uid);
1068 int mlx5_core_mad_ifc(struct mlx5_core_dev *dev, const void *inb, void *outb,
1069 		      u16 opmod, u8 port);
1070 void mlx5_fwp_flush(struct mlx5_fw_page *fwp);
1071 void mlx5_fwp_invalidate(struct mlx5_fw_page *fwp);
1072 struct mlx5_fw_page *mlx5_fwp_alloc(struct mlx5_core_dev *dev, gfp_t flags, unsigned num);
1073 void mlx5_fwp_free(struct mlx5_fw_page *fwp);
1074 u64 mlx5_fwp_get_dma(struct mlx5_fw_page *fwp, size_t offset);
1075 void *mlx5_fwp_get_virt(struct mlx5_fw_page *fwp, size_t offset);
1076 void mlx5_pagealloc_init(struct mlx5_core_dev *dev);
1077 void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
1078 int mlx5_pagealloc_start(struct mlx5_core_dev *dev);
1079 void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
1080 void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
1081 				 s32 npages);
1082 int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
1083 int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
1084 s64 mlx5_wait_for_reclaim_vfs_pages(struct mlx5_core_dev *dev);
1085 void mlx5_register_debugfs(void);
1086 void mlx5_unregister_debugfs(void);
1087 int mlx5_eq_init(struct mlx5_core_dev *dev);
1088 void mlx5_eq_cleanup(struct mlx5_core_dev *dev);
1089 void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas);
1090 void mlx5_cq_completion(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe);
1091 void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
1092 void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
1093 struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);
1094 void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vector, enum mlx5_cmd_mode mode);
1095 void mlx5_cq_event(struct mlx5_core_dev *dev, u32 cqn, int event_type);
1096 int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
1097 		       int nent, u64 mask);
1098 int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1099 int mlx5_start_eqs(struct mlx5_core_dev *dev);
1100 int mlx5_stop_eqs(struct mlx5_core_dev *dev);
1101 int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn, int *irqn);
1102 int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
1103 int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
1104 int mlx5_core_set_dc_cnak_trace(struct mlx5_core_dev *dev, int enable,
1105 				u64 addr);
1106 
1107 int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
1108 void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
1109 int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
1110 			 int size_in, void *data_out, int size_out,
1111 			 u16 reg_num, int arg, int write);
1112 
1113 void mlx5_toggle_port_link(struct mlx5_core_dev *dev);
1114 
1115 int mlx5_debug_eq_add(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1116 void mlx5_debug_eq_remove(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1117 int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
1118 		       u32 *out, int outlen);
1119 int mlx5_eq_debugfs_init(struct mlx5_core_dev *dev);
1120 void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev);
1121 int mlx5_cq_debugfs_init(struct mlx5_core_dev *dev);
1122 void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev);
1123 int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
1124 void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
1125 
1126 static inline struct domainset *
1127 mlx5_dev_domainset(struct mlx5_core_dev *mdev)
1128 {
1129 	return (linux_get_vm_domain_set(mdev->priv.numa_node));
1130 }
1131 
1132 const char *mlx5_command_str(int command);
1133 int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
1134 void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
1135 int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
1136 			 int npsvs, u32 *sig_index);
1137 int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
1138 void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
1139 u8 mlx5_is_wol_supported(struct mlx5_core_dev *dev);
1140 int mlx5_set_wol(struct mlx5_core_dev *dev, u8 wol_mode);
1141 int mlx5_set_dropless_mode(struct mlx5_core_dev *dev, u16 timeout);
1142 int mlx5_query_dropless_mode(struct mlx5_core_dev *dev, u16 *timeout);
1143 int mlx5_query_wol(struct mlx5_core_dev *dev, u8 *wol_mode);
1144 int mlx5_core_access_pvlc(struct mlx5_core_dev *dev,
1145 			  struct mlx5_pvlc_reg *pvlc, int write);
1146 int mlx5_core_access_ptys(struct mlx5_core_dev *dev,
1147 			  struct mlx5_ptys_reg *ptys, int write);
1148 int mlx5_core_access_pmtu(struct mlx5_core_dev *dev,
1149 			  struct mlx5_pmtu_reg *pmtu, int write);
1150 int mlx5_vxlan_udp_port_add(struct mlx5_core_dev *dev, u16 port);
1151 int mlx5_vxlan_udp_port_delete(struct mlx5_core_dev *dev, u16 port);
1152 int mlx5_query_port_cong_status(struct mlx5_core_dev *mdev, int protocol,
1153 				int priority, int *is_enable);
1154 int mlx5_modify_port_cong_status(struct mlx5_core_dev *mdev, int protocol,
1155 				 int priority, int enable);
1156 int mlx5_query_port_cong_params(struct mlx5_core_dev *mdev, int protocol,
1157 				void *out, int out_size);
1158 int mlx5_modify_port_cong_params(struct mlx5_core_dev *mdev,
1159 				 void *in, int in_size);
1160 int mlx5_query_port_cong_statistics(struct mlx5_core_dev *mdev, int clear,
1161 				    void *out, int out_size);
1162 int mlx5_set_diagnostic_params(struct mlx5_core_dev *mdev, void *in,
1163 			       int in_size);
1164 int mlx5_query_diagnostic_counters(struct mlx5_core_dev *mdev,
1165 				   u8 num_of_samples, u16 sample_index,
1166 				   void *out, int out_size);
1167 int mlx5_vsc_find_cap(struct mlx5_core_dev *mdev);
1168 int mlx5_vsc_lock(struct mlx5_core_dev *mdev);
1169 void mlx5_vsc_unlock(struct mlx5_core_dev *mdev);
1170 int mlx5_vsc_set_space(struct mlx5_core_dev *mdev, u16 space);
1171 int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *mdev, u32 expected);
1172 int mlx5_vsc_write(struct mlx5_core_dev *mdev, u32 addr, const u32 *data);
1173 int mlx5_vsc_read(struct mlx5_core_dev *mdev, u32 addr, u32 *data);
1174 int mlx5_vsc_lock_addr_space(struct mlx5_core_dev *mdev, u32 addr);
1175 int mlx5_vsc_unlock_addr_space(struct mlx5_core_dev *mdev, u32 addr);
1176 int mlx5_pci_read_power_status(struct mlx5_core_dev *mdev,
1177 			       u16 *p_power, u8 *p_status);
1178 
1179 static inline u32 mlx5_mkey_to_idx(u32 mkey)
1180 {
1181 	return mkey >> 8;
1182 }
1183 
1184 static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
1185 {
1186 	return mkey_idx << 8;
1187 }
1188 
1189 static inline u8 mlx5_mkey_variant(u32 mkey)
1190 {
1191 	return mkey & 0xff;
1192 }
1193 
1194 enum {
1195 	MLX5_PROF_MASK_QP_SIZE		= (u64)1 << 0,
1196 	MLX5_PROF_MASK_MR_CACHE		= (u64)1 << 1,
1197 };
1198 
1199 enum {
1200 	MAX_MR_CACHE_ENTRIES    = 15,
1201 };
1202 
1203 struct mlx5_interface {
1204 	void *			(*add)(struct mlx5_core_dev *dev);
1205 	void			(*remove)(struct mlx5_core_dev *dev, void *context);
1206 	void			(*event)(struct mlx5_core_dev *dev, void *context,
1207 					 enum mlx5_dev_event event, unsigned long param);
1208 	void *                  (*get_dev)(void *context);
1209 	int			protocol;
1210 	struct list_head	list;
1211 };
1212 
1213 void *mlx5_get_protocol_dev(struct mlx5_core_dev *mdev, int protocol);
1214 int mlx5_register_interface(struct mlx5_interface *intf);
1215 void mlx5_unregister_interface(struct mlx5_interface *intf);
1216 
1217 unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
1218 int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
1219     u8 roce_version, u8 roce_l3_type, const u8 *gid,
1220     const u8 *mac, bool vlan, u16 vlan_id);
1221 
1222 struct mlx5_profile {
1223 	u64	mask;
1224 	u8	log_max_qp;
1225 	struct {
1226 		int	size;
1227 		int	limit;
1228 	} mr_cache[MAX_MR_CACHE_ENTRIES];
1229 };
1230 
1231 enum {
1232 	MLX5_PCI_DEV_IS_VF		= 1 << 0,
1233 };
1234 
1235 enum {
1236 	MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
1237 };
1238 
1239 static inline int mlx5_core_is_pf(struct mlx5_core_dev *dev)
1240 {
1241 	return !(dev->priv.pci_dev_data & MLX5_PCI_DEV_IS_VF);
1242 }
1243 #ifdef RATELIMIT
1244 int mlx5_init_rl_table(struct mlx5_core_dev *dev);
1245 void mlx5_cleanup_rl_table(struct mlx5_core_dev *dev);
1246 int mlx5_rl_add_rate(struct mlx5_core_dev *dev, u32 rate, u32 burst, u16 *index);
1247 void mlx5_rl_remove_rate(struct mlx5_core_dev *dev, u32 rate, u32 burst);
1248 bool mlx5_rl_is_in_range(const struct mlx5_core_dev *dev, u32 rate, u32 burst);
1249 int mlx5e_query_rate_limit_cmd(struct mlx5_core_dev *dev, u16 index, u32 *scq_handle);
1250 
1251 static inline u32 mlx5_rl_get_scq_handle(struct mlx5_core_dev *dev, uint16_t index)
1252 {
1253 	KASSERT(index > 0,
1254 	    ("invalid rate index for sq remap, failed retrieving SCQ handle"));
1255 
1256         return (dev->priv.rl_table.rl_entry[index - 1].qos_handle);
1257 }
1258 
1259 static inline bool mlx5_rl_is_supported(struct mlx5_core_dev *dev)
1260 {
1261 	return !!(dev->priv.rl_table.max_size);
1262 }
1263 #endif
1264 
1265 void mlx5_disable_interrupts(struct mlx5_core_dev *);
1266 void mlx5_poll_interrupts(struct mlx5_core_dev *);
1267 
1268 static inline int mlx5_get_qp_default_ts(struct mlx5_core_dev *dev)
1269 {
1270         return !MLX5_CAP_ROCE(dev, qp_ts_format) ?
1271                        MLX5_QPC_TIMESTAMP_FORMAT_FREE_RUNNING :
1272                        MLX5_QPC_TIMESTAMP_FORMAT_DEFAULT;
1273 }
1274 
1275 static inline int mlx5_get_rq_default_ts(struct mlx5_core_dev *dev)
1276 {
1277         return !MLX5_CAP_GEN(dev, rq_ts_format) ?
1278                        MLX5_RQC_TIMESTAMP_FORMAT_FREE_RUNNING :
1279                        MLX5_RQC_TIMESTAMP_FORMAT_DEFAULT;
1280 }
1281 
1282 static inline int mlx5_get_sq_default_ts(struct mlx5_core_dev *dev)
1283 {
1284         return !MLX5_CAP_GEN(dev, sq_ts_format) ?
1285                        MLX5_SQC_TIMESTAMP_FORMAT_FREE_RUNNING :
1286                        MLX5_SQC_TIMESTAMP_FORMAT_DEFAULT;
1287 }
1288 
1289 #endif /* MLX5_DRIVER_H */
1290