1dc7e38acSHans Petter Selasky /*-
240218d73SHans Petter Selasky * Copyright (c) 2013-2019, Mellanox Technologies, Ltd. All rights reserved.
3aa7bbdabSHans Petter Selasky * Copyright (c) 2022 NVIDIA corporation & affiliates.
4dc7e38acSHans Petter Selasky *
5dc7e38acSHans Petter Selasky * Redistribution and use in source and binary forms, with or without
6dc7e38acSHans Petter Selasky * modification, are permitted provided that the following conditions
7dc7e38acSHans Petter Selasky * are met:
8dc7e38acSHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
9dc7e38acSHans Petter Selasky * notice, this list of conditions and the following disclaimer.
10dc7e38acSHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
11dc7e38acSHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
12dc7e38acSHans Petter Selasky * documentation and/or other materials provided with the distribution.
13dc7e38acSHans Petter Selasky *
14dc7e38acSHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
15dc7e38acSHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16dc7e38acSHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17dc7e38acSHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18dc7e38acSHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19dc7e38acSHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20dc7e38acSHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21dc7e38acSHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22dc7e38acSHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23dc7e38acSHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24dc7e38acSHans Petter Selasky * SUCH DAMAGE.
25dc7e38acSHans Petter Selasky */
26dc7e38acSHans Petter Selasky
27dc7e38acSHans Petter Selasky #ifndef MLX5_DRIVER_H
28dc7e38acSHans Petter Selasky #define MLX5_DRIVER_H
29dc7e38acSHans Petter Selasky
3038535d6cSHans Petter Selasky #include "opt_ratelimit.h"
3138535d6cSHans Petter Selasky
32dc7e38acSHans Petter Selasky #include <linux/kernel.h>
33dc7e38acSHans Petter Selasky #include <linux/completion.h>
34dc7e38acSHans Petter Selasky #include <linux/pci.h>
35dc7e38acSHans Petter Selasky #include <linux/cache.h>
36dc7e38acSHans Petter Selasky #include <linux/rbtree.h>
3776a5241fSHans Petter Selasky #include <linux/if_ether.h>
38dc7e38acSHans Petter Selasky #include <linux/semaphore.h>
39dc7e38acSHans Petter Selasky #include <linux/slab.h>
40dc7e38acSHans Petter Selasky #include <linux/vmalloc.h>
41dc7e38acSHans Petter Selasky #include <linux/radix-tree.h>
42e9dcd831SSlava Shwartsman #include <linux/idr.h>
437eefcb5eSHans Petter Selasky #include <linux/wait.h>
44dc7e38acSHans Petter Selasky
45dc7e38acSHans Petter Selasky #include <dev/mlx5/device.h>
46dc7e38acSHans Petter Selasky #include <dev/mlx5/doorbell.h>
47788333d9SHans Petter Selasky #include <dev/mlx5/srq.h>
48dc7e38acSHans Petter Selasky
49cb4e4a6eSHans Petter Selasky #define MLX5_QCOUNTER_SETS_NETDEV 64
5044a03e91SHans Petter Selasky #define MLX5_MAX_NUMBER_OF_VFS 128
51cb4e4a6eSHans Petter Selasky
52266c81aaSHans Petter Selasky #define MLX5_INVALID_QUEUE_HANDLE 0xffffffff
5335bbcf09SRaed Salem #define MLX5_ST_SZ_BYTES(typ) (sizeof(struct mlx5_ifc_##typ##_bits) / 8)
54266c81aaSHans Petter Selasky
55dc7e38acSHans Petter Selasky enum {
56dc7e38acSHans Petter Selasky MLX5_BOARD_ID_LEN = 64,
57dc7e38acSHans Petter Selasky MLX5_MAX_NAME_LEN = 16,
58dc7e38acSHans Petter Selasky };
59dc7e38acSHans Petter Selasky
60dc7e38acSHans Petter Selasky enum {
614f227510SHans Petter Selasky MLX5_CMD_TIMEOUT_MSEC = 60 * 1000,
62dc7e38acSHans Petter Selasky };
63dc7e38acSHans Petter Selasky
64dc7e38acSHans Petter Selasky enum {
65dc7e38acSHans Petter Selasky CMD_OWNER_SW = 0x0,
66dc7e38acSHans Petter Selasky CMD_OWNER_HW = 0x1,
67dc7e38acSHans Petter Selasky CMD_STATUS_SUCCESS = 0,
68dc7e38acSHans Petter Selasky };
69dc7e38acSHans Petter Selasky
70dc7e38acSHans Petter Selasky enum mlx5_sqp_t {
71dc7e38acSHans Petter Selasky MLX5_SQP_SMI = 0,
72dc7e38acSHans Petter Selasky MLX5_SQP_GSI = 1,
73dc7e38acSHans Petter Selasky MLX5_SQP_IEEE_1588 = 2,
74dc7e38acSHans Petter Selasky MLX5_SQP_SNIFFER = 3,
75dc7e38acSHans Petter Selasky MLX5_SQP_SYNC_UMR = 4,
76dc7e38acSHans Petter Selasky };
77dc7e38acSHans Petter Selasky
78dc7e38acSHans Petter Selasky enum {
79dc7e38acSHans Petter Selasky MLX5_MAX_PORTS = 2,
80dc7e38acSHans Petter Selasky };
81dc7e38acSHans Petter Selasky
82dc7e38acSHans Petter Selasky enum {
83dc7e38acSHans Petter Selasky MLX5_EQ_VEC_PAGES = 0,
84dc7e38acSHans Petter Selasky MLX5_EQ_VEC_CMD = 1,
85dc7e38acSHans Petter Selasky MLX5_EQ_VEC_ASYNC = 2,
86dc7e38acSHans Petter Selasky MLX5_EQ_VEC_COMP_BASE,
87dc7e38acSHans Petter Selasky };
88dc7e38acSHans Petter Selasky
89dc7e38acSHans Petter Selasky enum {
90cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_OFF = 16,
91cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_NONE = 0 << MLX5_ATOMIC_MODE_OFF,
92cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_IB_COMP = 1 << MLX5_ATOMIC_MODE_OFF,
93cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_CX = 2 << MLX5_ATOMIC_MODE_OFF,
94cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_8B = 3 << MLX5_ATOMIC_MODE_OFF,
95cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_16B = 4 << MLX5_ATOMIC_MODE_OFF,
96cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_32B = 5 << MLX5_ATOMIC_MODE_OFF,
97cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_64B = 6 << MLX5_ATOMIC_MODE_OFF,
98cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_128B = 7 << MLX5_ATOMIC_MODE_OFF,
99cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_256B = 8 << MLX5_ATOMIC_MODE_OFF,
100cb4e4a6eSHans Petter Selasky };
101cb4e4a6eSHans Petter Selasky
102cb4e4a6eSHans Petter Selasky enum {
103cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_OFF = 20,
104cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_NONE = 0 << MLX5_ATOMIC_MODE_DCT_OFF,
105cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_IB_COMP = 1 << MLX5_ATOMIC_MODE_DCT_OFF,
106cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_CX = 2 << MLX5_ATOMIC_MODE_DCT_OFF,
107cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_8B = 3 << MLX5_ATOMIC_MODE_DCT_OFF,
108cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_16B = 4 << MLX5_ATOMIC_MODE_DCT_OFF,
109cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_32B = 5 << MLX5_ATOMIC_MODE_DCT_OFF,
110cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_64B = 6 << MLX5_ATOMIC_MODE_DCT_OFF,
111cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_128B = 7 << MLX5_ATOMIC_MODE_DCT_OFF,
112cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_MODE_DCT_256B = 8 << MLX5_ATOMIC_MODE_DCT_OFF,
113cb4e4a6eSHans Petter Selasky };
114cb4e4a6eSHans Petter Selasky
115cb4e4a6eSHans Petter Selasky enum {
116cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
117cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
118cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_OPS_MASKED_CMP_SWAP = 1 << 2,
119cb4e4a6eSHans Petter Selasky MLX5_ATOMIC_OPS_MASKED_FETCH_ADD = 1 << 3,
120dc7e38acSHans Petter Selasky };
121dc7e38acSHans Petter Selasky
122dc7e38acSHans Petter Selasky enum {
123ed0cee0bSHans Petter Selasky MLX5_REG_QPTS = 0x4002,
124dc7e38acSHans Petter Selasky MLX5_REG_QETCR = 0x4005,
125dc7e38acSHans Petter Selasky MLX5_REG_QPDP = 0x4007,
126dc7e38acSHans Petter Selasky MLX5_REG_QTCT = 0x400A,
127ed0cee0bSHans Petter Selasky MLX5_REG_QPDPM = 0x4013,
128cb022443SHans Petter Selasky MLX5_REG_QHLL = 0x4016,
129ed0cee0bSHans Petter Selasky MLX5_REG_QCAM = 0x4019,
130cb4e4a6eSHans Petter Selasky MLX5_REG_DCBX_PARAM = 0x4020,
131cb4e4a6eSHans Petter Selasky MLX5_REG_DCBX_APP = 0x4021,
132e9dcd831SSlava Shwartsman MLX5_REG_FPGA_CAP = 0x4022,
133e9dcd831SSlava Shwartsman MLX5_REG_FPGA_CTRL = 0x4023,
134e9dcd831SSlava Shwartsman MLX5_REG_FPGA_ACCESS_REG = 0x4024,
135e9dcd831SSlava Shwartsman MLX5_REG_FPGA_SHELL_CNTR = 0x4025,
1368ae1c36fSHans Petter Selasky MLX5_REG_PCAP = 0x5001,
1378ae1c36fSHans Petter Selasky MLX5_REG_PMLP = 0x5002,
138dc7e38acSHans Petter Selasky MLX5_REG_PMTU = 0x5003,
139dc7e38acSHans Petter Selasky MLX5_REG_PTYS = 0x5004,
140dc7e38acSHans Petter Selasky MLX5_REG_PAOS = 0x5006,
141dc7e38acSHans Petter Selasky MLX5_REG_PFCC = 0x5007,
142dc7e38acSHans Petter Selasky MLX5_REG_PPCNT = 0x5008,
143dc7e38acSHans Petter Selasky MLX5_REG_PUDE = 0x5009,
144dc7e38acSHans Petter Selasky MLX5_REG_PPTB = 0x500B,
145dc7e38acSHans Petter Selasky MLX5_REG_PBMC = 0x500C,
1468ae1c36fSHans Petter Selasky MLX5_REG_PELC = 0x500E,
1478ae1c36fSHans Petter Selasky MLX5_REG_PVLC = 0x500F,
148dc7e38acSHans Petter Selasky MLX5_REG_PMPE = 0x5010,
1498ae1c36fSHans Petter Selasky MLX5_REG_PMAOS = 0x5012,
15096425f44SHans Petter Selasky MLX5_REG_PPLM = 0x5023,
151e088db5eSKonstantin Belousov MLX5_REG_PDDR = 0x5031,
152207ff00eSHans Petter Selasky MLX5_REG_PBSR = 0x5038,
153ae73b041SHans Petter Selasky MLX5_REG_PCAM = 0x507f,
154dc7e38acSHans Petter Selasky MLX5_REG_NODE_DESC = 0x6001,
155dc7e38acSHans Petter Selasky MLX5_REG_HOST_ENDIANNESS = 0x7004,
156085b35bbSSlava Shwartsman MLX5_REG_MTMP = 0x900a,
157dc7e38acSHans Petter Selasky MLX5_REG_MCIA = 0x9014,
158939c79a2SHans Petter Selasky MLX5_REG_MFRL = 0x9028,
159cb4e4a6eSHans Petter Selasky MLX5_REG_MPCNT = 0x9051,
160d5d52dd7SHans Petter Selasky MLX5_REG_MCQI = 0x9061,
161d5d52dd7SHans Petter Selasky MLX5_REG_MCC = 0x9062,
162d5d52dd7SHans Petter Selasky MLX5_REG_MCDA = 0x9063,
163ae73b041SHans Petter Selasky MLX5_REG_MCAM = 0x907f,
164dc7e38acSHans Petter Selasky };
165dc7e38acSHans Petter Selasky
166dc7e38acSHans Petter Selasky enum dbg_rsc_type {
167dc7e38acSHans Petter Selasky MLX5_DBG_RSC_QP,
168dc7e38acSHans Petter Selasky MLX5_DBG_RSC_EQ,
169dc7e38acSHans Petter Selasky MLX5_DBG_RSC_CQ,
170dc7e38acSHans Petter Selasky };
171dc7e38acSHans Petter Selasky
172cb4e4a6eSHans Petter Selasky enum {
173cb4e4a6eSHans Petter Selasky MLX5_INTERFACE_PROTOCOL_IB = 0,
174cb4e4a6eSHans Petter Selasky MLX5_INTERFACE_PROTOCOL_ETH = 1,
175cb4e4a6eSHans Petter Selasky MLX5_INTERFACE_NUMBER = 2,
176cb4e4a6eSHans Petter Selasky };
177cb4e4a6eSHans Petter Selasky
178dc7e38acSHans Petter Selasky struct mlx5_field_desc {
179dc7e38acSHans Petter Selasky int i;
180dc7e38acSHans Petter Selasky };
181dc7e38acSHans Petter Selasky
182dc7e38acSHans Petter Selasky struct mlx5_rsc_debug {
183dc7e38acSHans Petter Selasky struct mlx5_core_dev *dev;
184dc7e38acSHans Petter Selasky void *object;
185dc7e38acSHans Petter Selasky enum dbg_rsc_type type;
186dc7e38acSHans Petter Selasky struct mlx5_field_desc fields[0];
187dc7e38acSHans Petter Selasky };
188dc7e38acSHans Petter Selasky
189dc7e38acSHans Petter Selasky enum mlx5_dev_event {
190dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_SYS_ERROR,
191dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_PORT_UP,
192dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_PORT_DOWN,
193dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_PORT_INITIALIZED,
194dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_LID_CHANGE,
195dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_PKEY_CHANGE,
196dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_GUID_CHANGE,
197dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_CLIENT_REREG,
198dc7e38acSHans Petter Selasky MLX5_DEV_EVENT_VPORT_CHANGE,
199cb4e4a6eSHans Petter Selasky MLX5_DEV_EVENT_ERROR_STATE_DCBX,
200cb4e4a6eSHans Petter Selasky MLX5_DEV_EVENT_REMOTE_CONFIG_CHANGE,
201cb4e4a6eSHans Petter Selasky MLX5_DEV_EVENT_LOCAL_OPER_CHANGE,
202cb4e4a6eSHans Petter Selasky MLX5_DEV_EVENT_REMOTE_CONFIG_APPLICATION_PRIORITY_CHANGE,
203dc7e38acSHans Petter Selasky };
204dc7e38acSHans Petter Selasky
205dc7e38acSHans Petter Selasky enum mlx5_port_status {
206dc7e38acSHans Petter Selasky MLX5_PORT_UP = 1 << 0,
207dc7e38acSHans Petter Selasky MLX5_PORT_DOWN = 1 << 1,
208dc7e38acSHans Petter Selasky };
209dc7e38acSHans Petter Selasky
2104b95c665SHans Petter Selasky enum {
2114b95c665SHans Petter Selasky MLX5_VSC_SPACE_SUPPORTED = 0x1,
2124b95c665SHans Petter Selasky MLX5_VSC_SPACE_OFFSET = 0x4,
2134b95c665SHans Petter Selasky MLX5_VSC_COUNTER_OFFSET = 0x8,
2144b95c665SHans Petter Selasky MLX5_VSC_SEMA_OFFSET = 0xC,
2154b95c665SHans Petter Selasky MLX5_VSC_ADDR_OFFSET = 0x10,
2164b95c665SHans Petter Selasky MLX5_VSC_DATA_OFFSET = 0x14,
2174b95c665SHans Petter Selasky MLX5_VSC_MAX_RETRIES = 0x1000,
2184b95c665SHans Petter Selasky };
2194b95c665SHans Petter Selasky
220dc7e38acSHans Petter Selasky #define MLX5_PROT_MASK(link_mode) (1 << link_mode)
221dc7e38acSHans Petter Selasky
222dc7e38acSHans Petter Selasky struct mlx5_cmd_first {
223dc7e38acSHans Petter Selasky __be32 data[4];
224dc7e38acSHans Petter Selasky };
225dc7e38acSHans Petter Selasky
2261c807f67SHans Petter Selasky struct cache_ent;
2271c807f67SHans Petter Selasky struct mlx5_fw_page {
2281c807f67SHans Petter Selasky union {
2291c807f67SHans Petter Selasky struct rb_node rb_node;
230dc7e38acSHans Petter Selasky struct list_head list;
231dc7e38acSHans Petter Selasky };
2321c807f67SHans Petter Selasky struct mlx5_cmd_first first;
2331c807f67SHans Petter Selasky struct mlx5_core_dev *dev;
2341c807f67SHans Petter Selasky bus_dmamap_t dma_map;
2351c807f67SHans Petter Selasky bus_addr_t dma_addr;
2361c807f67SHans Petter Selasky void *virt_addr;
2371c807f67SHans Petter Selasky struct cache_ent *cache;
2381c807f67SHans Petter Selasky u32 numpages;
2391c807f67SHans Petter Selasky u16 load_done;
2401c807f67SHans Petter Selasky #define MLX5_LOAD_ST_NONE 0
2411c807f67SHans Petter Selasky #define MLX5_LOAD_ST_SUCCESS 1
2421c807f67SHans Petter Selasky #define MLX5_LOAD_ST_FAILURE 2
2431c807f67SHans Petter Selasky u16 func_id;
2441c807f67SHans Petter Selasky };
2451c807f67SHans Petter Selasky #define mlx5_cmd_msg mlx5_fw_page
246dc7e38acSHans Petter Selasky
247dc7e38acSHans Petter Selasky struct mlx5_cmd_debug {
248dc7e38acSHans Petter Selasky void *in_msg;
249dc7e38acSHans Petter Selasky void *out_msg;
250dc7e38acSHans Petter Selasky u8 status;
251dc7e38acSHans Petter Selasky u16 inlen;
252dc7e38acSHans Petter Selasky u16 outlen;
253dc7e38acSHans Petter Selasky };
254dc7e38acSHans Petter Selasky
255dc7e38acSHans Petter Selasky struct cache_ent {
256dc7e38acSHans Petter Selasky /* protect block chain allocations
257dc7e38acSHans Petter Selasky */
258dc7e38acSHans Petter Selasky spinlock_t lock;
259dc7e38acSHans Petter Selasky struct list_head head;
260dc7e38acSHans Petter Selasky };
261dc7e38acSHans Petter Selasky
262dc7e38acSHans Petter Selasky struct cmd_msg_cache {
263dc7e38acSHans Petter Selasky struct cache_ent large;
264dc7e38acSHans Petter Selasky struct cache_ent med;
265dc7e38acSHans Petter Selasky
266dc7e38acSHans Petter Selasky };
267dc7e38acSHans Petter Selasky
2684b109912SHans Petter Selasky struct mlx5_traffic_counter {
2694b109912SHans Petter Selasky u64 packets;
2704b109912SHans Petter Selasky u64 octets;
2714b109912SHans Petter Selasky };
2724b109912SHans Petter Selasky
27335bbcf09SRaed Salem struct mlx5_fc_pool {
27435bbcf09SRaed Salem struct mlx5_core_dev *dev;
27535bbcf09SRaed Salem struct mutex pool_lock; /* protects pool lists */
27635bbcf09SRaed Salem struct list_head fully_used;
27735bbcf09SRaed Salem struct list_head partially_used;
27835bbcf09SRaed Salem struct list_head unused;
27935bbcf09SRaed Salem int available_fcs;
28035bbcf09SRaed Salem int used_fcs;
28135bbcf09SRaed Salem int threshold;
28235bbcf09SRaed Salem };
28335bbcf09SRaed Salem
28435bbcf09SRaed Salem struct mlx5_fc_stats {
28535bbcf09SRaed Salem spinlock_t counters_idr_lock; /* protects counters_idr */
28635bbcf09SRaed Salem struct idr counters_idr;
28735bbcf09SRaed Salem struct list_head counters;
28835bbcf09SRaed Salem struct llist_head addlist;
28935bbcf09SRaed Salem struct llist_head dellist;
29035bbcf09SRaed Salem
29135bbcf09SRaed Salem struct workqueue_struct *wq;
29235bbcf09SRaed Salem struct delayed_work work;
29335bbcf09SRaed Salem unsigned long next_query;
29435bbcf09SRaed Salem unsigned long sampling_interval; /* jiffies */
29535bbcf09SRaed Salem u32 *bulk_query_out;
29635bbcf09SRaed Salem int bulk_query_len;
29735bbcf09SRaed Salem size_t num_counters;
29835bbcf09SRaed Salem bool bulk_query_alloc_failed;
29935bbcf09SRaed Salem unsigned long next_bulk_query_alloc;
30035bbcf09SRaed Salem struct mlx5_fc_pool fc_pool;
30135bbcf09SRaed Salem };
30235bbcf09SRaed Salem
303721a1a6aSSlava Shwartsman enum mlx5_cmd_mode {
304721a1a6aSSlava Shwartsman MLX5_CMD_MODE_POLLING,
305721a1a6aSSlava Shwartsman MLX5_CMD_MODE_EVENTS
306721a1a6aSSlava Shwartsman };
307721a1a6aSSlava Shwartsman
308dc7e38acSHans Petter Selasky struct mlx5_cmd_stats {
309dc7e38acSHans Petter Selasky u64 sum;
310dc7e38acSHans Petter Selasky u64 n;
311dc7e38acSHans Petter Selasky /* protect command average calculations */
312dc7e38acSHans Petter Selasky spinlock_t lock;
313dc7e38acSHans Petter Selasky };
314dc7e38acSHans Petter Selasky
315dc7e38acSHans Petter Selasky struct mlx5_cmd {
3161c807f67SHans Petter Selasky struct mlx5_fw_page *cmd_page;
3171c807f67SHans Petter Selasky bus_dma_tag_t dma_tag;
3181c807f67SHans Petter Selasky struct sx dma_sx;
3191c807f67SHans Petter Selasky struct mtx dma_mtx;
3201c807f67SHans Petter Selasky #define MLX5_DMA_OWNED(dev) mtx_owned(&(dev)->cmd.dma_mtx)
3211c807f67SHans Petter Selasky #define MLX5_DMA_LOCK(dev) mtx_lock(&(dev)->cmd.dma_mtx)
3221c807f67SHans Petter Selasky #define MLX5_DMA_UNLOCK(dev) mtx_unlock(&(dev)->cmd.dma_mtx)
3231c807f67SHans Petter Selasky struct cv dma_cv;
3241c807f67SHans Petter Selasky #define MLX5_DMA_DONE(dev) cv_broadcast(&(dev)->cmd.dma_cv)
3251c807f67SHans Petter Selasky #define MLX5_DMA_WAIT(dev) cv_wait(&(dev)->cmd.dma_cv, &(dev)->cmd.dma_mtx)
326dc7e38acSHans Petter Selasky void *cmd_buf;
327dc7e38acSHans Petter Selasky dma_addr_t dma;
328dc7e38acSHans Petter Selasky u16 cmdif_rev;
329dc7e38acSHans Petter Selasky u8 log_sz;
330dc7e38acSHans Petter Selasky u8 log_stride;
331dc7e38acSHans Petter Selasky int max_reg_cmds;
332dc7e38acSHans Petter Selasky int events;
333dc7e38acSHans Petter Selasky u32 __iomem *vector;
334dc7e38acSHans Petter Selasky
335dc7e38acSHans Petter Selasky /* protect command queue allocations
336dc7e38acSHans Petter Selasky */
337dc7e38acSHans Petter Selasky spinlock_t alloc_lock;
338dc7e38acSHans Petter Selasky
339dc7e38acSHans Petter Selasky /* protect token allocations
340dc7e38acSHans Petter Selasky */
341dc7e38acSHans Petter Selasky spinlock_t token_lock;
342dc7e38acSHans Petter Selasky u8 token;
343dc7e38acSHans Petter Selasky unsigned long bitmask;
344dc7e38acSHans Petter Selasky struct semaphore sem;
345dc7e38acSHans Petter Selasky struct semaphore pages_sem;
346721a1a6aSSlava Shwartsman enum mlx5_cmd_mode mode;
347721a1a6aSSlava Shwartsman struct mlx5_cmd_work_ent * volatile ent_arr[MLX5_MAX_COMMANDS];
348721a1a6aSSlava Shwartsman volatile enum mlx5_cmd_mode ent_mode[MLX5_MAX_COMMANDS];
349dc7e38acSHans Petter Selasky struct mlx5_cmd_debug dbg;
350dc7e38acSHans Petter Selasky struct cmd_msg_cache cache;
351dc7e38acSHans Petter Selasky int checksum_disabled;
352dc7e38acSHans Petter Selasky struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
353dc7e38acSHans Petter Selasky };
354dc7e38acSHans Petter Selasky
355dc7e38acSHans Petter Selasky struct mlx5_port_caps {
356dc7e38acSHans Petter Selasky int gid_table_len;
357dc7e38acSHans Petter Selasky int pkey_table_len;
358dc7e38acSHans Petter Selasky u8 ext_port_cap;
359dc7e38acSHans Petter Selasky };
360dc7e38acSHans Petter Selasky
361dc7e38acSHans Petter Selasky struct mlx5_buf {
3621c807f67SHans Petter Selasky bus_dma_tag_t dma_tag;
3631c807f67SHans Petter Selasky bus_dmamap_t dma_map;
3641c807f67SHans Petter Selasky struct mlx5_core_dev *dev;
3651c807f67SHans Petter Selasky struct {
3661c807f67SHans Petter Selasky void *buf;
3671c807f67SHans Petter Selasky } direct;
3681c807f67SHans Petter Selasky u64 *page_list;
369dc7e38acSHans Petter Selasky int npages;
370dc7e38acSHans Petter Selasky int size;
371dc7e38acSHans Petter Selasky u8 page_shift;
3721c807f67SHans Petter Selasky u8 load_done;
373dc7e38acSHans Petter Selasky };
374dc7e38acSHans Petter Selasky
375e9dcd831SSlava Shwartsman struct mlx5_frag_buf {
376e9dcd831SSlava Shwartsman struct mlx5_buf_list *frags;
377e9dcd831SSlava Shwartsman int npages;
378e9dcd831SSlava Shwartsman int size;
379e9dcd831SSlava Shwartsman u8 page_shift;
380e9dcd831SSlava Shwartsman };
381e9dcd831SSlava Shwartsman
382dc7e38acSHans Petter Selasky struct mlx5_eq {
383dc7e38acSHans Petter Selasky struct mlx5_core_dev *dev;
384dc7e38acSHans Petter Selasky __be32 __iomem *doorbell;
385dc7e38acSHans Petter Selasky u32 cons_index;
386dc7e38acSHans Petter Selasky struct mlx5_buf buf;
387dc7e38acSHans Petter Selasky int size;
388dc7e38acSHans Petter Selasky u8 irqn;
389dc7e38acSHans Petter Selasky u8 eqn;
390dc7e38acSHans Petter Selasky int nent;
391dc7e38acSHans Petter Selasky u64 mask;
392dc7e38acSHans Petter Selasky struct list_head list;
393dc7e38acSHans Petter Selasky int index;
394dc7e38acSHans Petter Selasky struct mlx5_rsc_debug *dbg;
395dc7e38acSHans Petter Selasky };
396dc7e38acSHans Petter Selasky
397dc7e38acSHans Petter Selasky struct mlx5_core_psv {
398dc7e38acSHans Petter Selasky u32 psv_idx;
399dc7e38acSHans Petter Selasky struct psv_layout {
400dc7e38acSHans Petter Selasky u32 pd;
401dc7e38acSHans Petter Selasky u16 syndrome;
402dc7e38acSHans Petter Selasky u16 reserved;
403dc7e38acSHans Petter Selasky u16 bg;
404dc7e38acSHans Petter Selasky u16 app_tag;
405dc7e38acSHans Petter Selasky u32 ref_tag;
406dc7e38acSHans Petter Selasky } psv;
407dc7e38acSHans Petter Selasky };
408dc7e38acSHans Petter Selasky
409dc7e38acSHans Petter Selasky struct mlx5_core_sig_ctx {
410dc7e38acSHans Petter Selasky struct mlx5_core_psv psv_memory;
411dc7e38acSHans Petter Selasky struct mlx5_core_psv psv_wire;
412dc7e38acSHans Petter Selasky struct ib_sig_err err_item;
413dc7e38acSHans Petter Selasky bool sig_status_checked;
414dc7e38acSHans Petter Selasky bool sig_err_exists;
415dc7e38acSHans Petter Selasky u32 sigerr_count;
416dc7e38acSHans Petter Selasky };
417dc7e38acSHans Petter Selasky
418e9dcd831SSlava Shwartsman enum {
419e9dcd831SSlava Shwartsman MLX5_MKEY_MR = 1,
420e9dcd831SSlava Shwartsman MLX5_MKEY_MW,
421b633e08cSHans Petter Selasky MLX5_MKEY_INDIRECT_DEVX,
422e9dcd831SSlava Shwartsman };
423e9dcd831SSlava Shwartsman
424e9dcd831SSlava Shwartsman struct mlx5_core_mkey {
425e9dcd831SSlava Shwartsman u64 iova;
426e9dcd831SSlava Shwartsman u64 size;
427e9dcd831SSlava Shwartsman u32 key;
428e9dcd831SSlava Shwartsman u32 pd;
429e9dcd831SSlava Shwartsman u32 type;
430e9dcd831SSlava Shwartsman };
431e9dcd831SSlava Shwartsman
432dc7e38acSHans Petter Selasky enum mlx5_res_type {
433cb4e4a6eSHans Petter Selasky MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
434cb4e4a6eSHans Petter Selasky MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
435cb4e4a6eSHans Petter Selasky MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
436cb4e4a6eSHans Petter Selasky MLX5_RES_SRQ = 3,
437cb4e4a6eSHans Petter Selasky MLX5_RES_XSRQ = 4,
438b633e08cSHans Petter Selasky MLX5_RES_XRQ = 5,
439b633e08cSHans Petter Selasky MLX5_RES_DCT = MLX5_EVENT_QUEUE_TYPE_DCT,
440dc7e38acSHans Petter Selasky };
441dc7e38acSHans Petter Selasky
442dc7e38acSHans Petter Selasky struct mlx5_core_rsc_common {
443dc7e38acSHans Petter Selasky enum mlx5_res_type res;
444dc7e38acSHans Petter Selasky atomic_t refcount;
445dc7e38acSHans Petter Selasky struct completion free;
446dc7e38acSHans Petter Selasky };
447dc7e38acSHans Petter Selasky
448f8f5b459SHans Petter Selasky struct mlx5_uars_page {
449f8f5b459SHans Petter Selasky void __iomem *map;
450f8f5b459SHans Petter Selasky bool wc;
451f8f5b459SHans Petter Selasky u32 index;
452f8f5b459SHans Petter Selasky struct list_head list;
453f8f5b459SHans Petter Selasky unsigned int bfregs;
454f8f5b459SHans Petter Selasky unsigned long *reg_bitmap; /* for non fast path bf regs */
455f8f5b459SHans Petter Selasky unsigned long *fp_bitmap;
456f8f5b459SHans Petter Selasky unsigned int reg_avail;
457f8f5b459SHans Petter Selasky unsigned int fp_avail;
458f8f5b459SHans Petter Selasky struct kref ref_count;
459f8f5b459SHans Petter Selasky struct mlx5_core_dev *mdev;
460f8f5b459SHans Petter Selasky };
461f8f5b459SHans Petter Selasky
462f8f5b459SHans Petter Selasky struct mlx5_bfreg_head {
463f8f5b459SHans Petter Selasky /* protect blue flame registers allocations */
464f8f5b459SHans Petter Selasky struct mutex lock;
465f8f5b459SHans Petter Selasky struct list_head list;
466f8f5b459SHans Petter Selasky };
467f8f5b459SHans Petter Selasky
468f8f5b459SHans Petter Selasky struct mlx5_bfreg_data {
469f8f5b459SHans Petter Selasky struct mlx5_bfreg_head reg_head;
470f8f5b459SHans Petter Selasky struct mlx5_bfreg_head wc_head;
471f8f5b459SHans Petter Selasky };
472f8f5b459SHans Petter Selasky
473f8f5b459SHans Petter Selasky struct mlx5_sq_bfreg {
474f8f5b459SHans Petter Selasky void __iomem *map;
475f8f5b459SHans Petter Selasky struct mlx5_uars_page *up;
476f8f5b459SHans Petter Selasky bool wc;
477f8f5b459SHans Petter Selasky u32 index;
478f8f5b459SHans Petter Selasky unsigned int offset;
479f8f5b459SHans Petter Selasky };
480f8f5b459SHans Petter Selasky
481dc7e38acSHans Petter Selasky struct mlx5_core_srq {
482dc7e38acSHans Petter Selasky struct mlx5_core_rsc_common common; /* must be first */
483dc7e38acSHans Petter Selasky u32 srqn;
484dc7e38acSHans Petter Selasky int max;
485abb28d28SSlava Shwartsman size_t max_gs;
486abb28d28SSlava Shwartsman size_t max_avail_gather;
487dc7e38acSHans Petter Selasky int wqe_shift;
488dc7e38acSHans Petter Selasky void (*event)(struct mlx5_core_srq *, int);
489dc7e38acSHans Petter Selasky atomic_t refcount;
490dc7e38acSHans Petter Selasky struct completion free;
491dc7e38acSHans Petter Selasky };
492dc7e38acSHans Petter Selasky
493b633e08cSHans Petter Selasky struct mlx5_ib_dev;
494dc7e38acSHans Petter Selasky struct mlx5_eq_table {
495dc7e38acSHans Petter Selasky void __iomem *update_ci;
496dc7e38acSHans Petter Selasky void __iomem *update_arm_ci;
497dc7e38acSHans Petter Selasky struct list_head comp_eqs_list;
498dc7e38acSHans Petter Selasky struct mlx5_eq pages_eq;
499dc7e38acSHans Petter Selasky struct mlx5_eq async_eq;
500dc7e38acSHans Petter Selasky struct mlx5_eq cmd_eq;
501dc7e38acSHans Petter Selasky int num_comp_vectors;
502b633e08cSHans Petter Selasky spinlock_t lock; /* protect EQs list */
503b633e08cSHans Petter Selasky struct mlx5_ib_dev *dev; /* for devx event notifier */
504b633e08cSHans Petter Selasky bool (*cb)(struct mlx5_core_dev *mdev,
505b633e08cSHans Petter Selasky uint8_t event_type, void *data);
506dc7e38acSHans Petter Selasky };
507dc7e38acSHans Petter Selasky
508dc7e38acSHans Petter Selasky struct mlx5_core_health {
509dc7e38acSHans Petter Selasky struct mlx5_health_buffer __iomem *health;
510dc7e38acSHans Petter Selasky __be32 __iomem *health_counter;
511dc7e38acSHans Petter Selasky struct timer_list timer;
512dc7e38acSHans Petter Selasky u32 prev;
513dc7e38acSHans Petter Selasky int miss_counter;
5141900b6f8SHans Petter Selasky u32 fatal_error;
51540218d73SHans Petter Selasky struct workqueue_struct *wq_watchdog;
516adb6fd50SHans Petter Selasky struct work_struct work_watchdog;
517ca551594SHans Petter Selasky /* wq spinlock to synchronize draining */
518ca551594SHans Petter Selasky spinlock_t wq_lock;
519a2485fe5SHans Petter Selasky struct workqueue_struct *wq;
520ca551594SHans Petter Selasky unsigned long flags;
521a2485fe5SHans Petter Selasky struct work_struct work;
5224bb7662bSHans Petter Selasky struct delayed_work recover_work;
5235169fb81SHans Petter Selasky unsigned int last_reset_req;
524a0a4fd77SHans Petter Selasky struct work_struct work_cmd_completion;
5258d1eeedbSHans Petter Selasky struct workqueue_struct *wq_cmd;
526dc7e38acSHans Petter Selasky };
527dc7e38acSHans Petter Selasky
528dc7e38acSHans Petter Selasky #define MLX5_CQ_LINEAR_ARRAY_SIZE 1024
529dc7e38acSHans Petter Selasky
530dc7e38acSHans Petter Selasky struct mlx5_cq_linear_array_entry {
531dc7e38acSHans Petter Selasky struct mlx5_core_cq * volatile cq;
532dc7e38acSHans Petter Selasky };
533dc7e38acSHans Petter Selasky
534dc7e38acSHans Petter Selasky struct mlx5_cq_table {
535dc7e38acSHans Petter Selasky /* protect radix tree
536dc7e38acSHans Petter Selasky */
537e4881300SHans Petter Selasky spinlock_t writerlock;
538e4881300SHans Petter Selasky atomic_t writercount;
539dc7e38acSHans Petter Selasky struct radix_tree_root tree;
540dc7e38acSHans Petter Selasky struct mlx5_cq_linear_array_entry linear_array[MLX5_CQ_LINEAR_ARRAY_SIZE];
541dc7e38acSHans Petter Selasky };
542dc7e38acSHans Petter Selasky
543dc7e38acSHans Petter Selasky struct mlx5_qp_table {
544dc7e38acSHans Petter Selasky /* protect radix tree
545dc7e38acSHans Petter Selasky */
546dc7e38acSHans Petter Selasky spinlock_t lock;
547dc7e38acSHans Petter Selasky struct radix_tree_root tree;
548dc7e38acSHans Petter Selasky };
549dc7e38acSHans Petter Selasky
550dc7e38acSHans Petter Selasky struct mlx5_srq_table {
551dc7e38acSHans Petter Selasky /* protect radix tree
552dc7e38acSHans Petter Selasky */
553dc7e38acSHans Petter Selasky spinlock_t lock;
554dc7e38acSHans Petter Selasky struct radix_tree_root tree;
555dc7e38acSHans Petter Selasky };
556dc7e38acSHans Petter Selasky
557dc7e38acSHans Petter Selasky struct mlx5_mr_table {
558dc7e38acSHans Petter Selasky /* protect radix tree
559dc7e38acSHans Petter Selasky */
560cb4e4a6eSHans Petter Selasky spinlock_t lock;
561dc7e38acSHans Petter Selasky struct radix_tree_root tree;
562dc7e38acSHans Petter Selasky };
563dc7e38acSHans Petter Selasky
56438535d6cSHans Petter Selasky #ifdef RATELIMIT
56538535d6cSHans Petter Selasky struct mlx5_rl_entry {
56638535d6cSHans Petter Selasky u32 rate;
56738535d6cSHans Petter Selasky u16 burst;
56838535d6cSHans Petter Selasky u16 index;
569266c81aaSHans Petter Selasky u32 qos_handle; /* schedule queue handle */
57038535d6cSHans Petter Selasky u32 refcount;
57138535d6cSHans Petter Selasky };
57238535d6cSHans Petter Selasky
57338535d6cSHans Petter Selasky struct mlx5_rl_table {
57438535d6cSHans Petter Selasky struct mutex rl_lock;
57538535d6cSHans Petter Selasky u16 max_size;
57638535d6cSHans Petter Selasky u32 max_rate;
57738535d6cSHans Petter Selasky u32 min_rate;
57838535d6cSHans Petter Selasky struct mlx5_rl_entry *rl_entry;
57938535d6cSHans Petter Selasky };
58038535d6cSHans Petter Selasky #endif
58138535d6cSHans Petter Selasky
582111b57c3SHans Petter Selasky struct mlx5_pme_stats {
583111b57c3SHans Petter Selasky u64 status_counters[MLX5_MODULE_STATUS_NUM];
584111b57c3SHans Petter Selasky u64 error_counters[MLX5_MODULE_EVENT_ERROR_NUM];
585111b57c3SHans Petter Selasky };
586111b57c3SHans Petter Selasky
587dc7e38acSHans Petter Selasky struct mlx5_priv {
588dc7e38acSHans Petter Selasky char name[MLX5_MAX_NAME_LEN];
589dc7e38acSHans Petter Selasky struct mlx5_eq_table eq_table;
590dc7e38acSHans Petter Selasky struct msix_entry *msix_arr;
591dc7e38acSHans Petter Selasky MLX5_DECLARE_DOORBELL_LOCK(cq_uar_lock);
592192fc18dSHans Petter Selasky int disable_irqs;
593dc7e38acSHans Petter Selasky
594dc7e38acSHans Petter Selasky /* pages stuff */
595dc7e38acSHans Petter Selasky struct workqueue_struct *pg_wq;
596dc7e38acSHans Petter Selasky struct rb_root page_root;
597115bc9b1SHans Petter Selasky s64 fw_pages;
598cb4e4a6eSHans Petter Selasky atomic_t reg_pages;
59944a03e91SHans Petter Selasky s64 pages_per_func[MLX5_MAX_NUMBER_OF_VFS];
600dc7e38acSHans Petter Selasky struct mlx5_core_health health;
601dc7e38acSHans Petter Selasky
602dc7e38acSHans Petter Selasky struct mlx5_srq_table srq_table;
603dc7e38acSHans Petter Selasky
604dc7e38acSHans Petter Selasky /* start: qp staff */
605dc7e38acSHans Petter Selasky struct mlx5_qp_table qp_table;
60680b4ef6dSHans Petter Selasky
607dc7e38acSHans Petter Selasky /* end: qp staff */
608dc7e38acSHans Petter Selasky
609dc7e38acSHans Petter Selasky /* start: cq staff */
610dc7e38acSHans Petter Selasky struct mlx5_cq_table cq_table;
611dc7e38acSHans Petter Selasky /* end: cq staff */
612dc7e38acSHans Petter Selasky
613dc7e38acSHans Petter Selasky /* start: mr staff */
614dc7e38acSHans Petter Selasky struct mlx5_mr_table mr_table;
615dc7e38acSHans Petter Selasky /* end: mr staff */
616dc7e38acSHans Petter Selasky
617dc7e38acSHans Petter Selasky /* start: alloc staff */
618dc7e38acSHans Petter Selasky int numa_node;
619dc7e38acSHans Petter Selasky
620dc7e38acSHans Petter Selasky struct mutex pgdir_mutex;
621dc7e38acSHans Petter Selasky struct list_head pgdir_list;
622dc7e38acSHans Petter Selasky /* end: alloc staff */
623dc7e38acSHans Petter Selasky
624dc7e38acSHans Petter Selasky /* protect mkey key part */
625dc7e38acSHans Petter Selasky spinlock_t mkey_lock;
626dc7e38acSHans Petter Selasky u8 mkey_key;
627dc7e38acSHans Petter Selasky
628dc7e38acSHans Petter Selasky struct list_head dev_list;
629dc7e38acSHans Petter Selasky struct list_head ctx_list;
630dc7e38acSHans Petter Selasky spinlock_t ctx_lock;
631cb4e4a6eSHans Petter Selasky unsigned long pci_dev_data;
63238535d6cSHans Petter Selasky #ifdef RATELIMIT
63338535d6cSHans Petter Selasky struct mlx5_rl_table rl_table;
63438535d6cSHans Petter Selasky #endif
635111b57c3SHans Petter Selasky struct mlx5_pme_stats pme_stats;
63691ad1bd9SKonstantin Belousov
637e23731dbSKonstantin Belousov struct mlx5_flow_steering *steering;
63891ad1bd9SKonstantin Belousov struct mlx5_eswitch *eswitch;
639f8f5b459SHans Petter Selasky
640f8f5b459SHans Petter Selasky struct mlx5_bfreg_data bfregs;
641f8f5b459SHans Petter Selasky struct mlx5_uars_page *uar;
64235bbcf09SRaed Salem struct mlx5_fc_stats fc_stats;
643e23731dbSKonstantin Belousov struct mlx5_ft_pool *ft_pool;
644cb4e4a6eSHans Petter Selasky };
645cb4e4a6eSHans Petter Selasky
646cb4e4a6eSHans Petter Selasky enum mlx5_device_state {
647cb4e4a6eSHans Petter Selasky MLX5_DEVICE_STATE_UP,
648cb4e4a6eSHans Petter Selasky MLX5_DEVICE_STATE_INTERNAL_ERROR,
649dc7e38acSHans Petter Selasky };
650dc7e38acSHans Petter Selasky
651a2485fe5SHans Petter Selasky enum mlx5_interface_state {
6520cf6ff0aSKonstantin Belousov MLX5_INTERFACE_STATE_UP = 0x1,
6530cf6ff0aSKonstantin Belousov MLX5_INTERFACE_STATE_TEARDOWN = 0x2,
654a2485fe5SHans Petter Selasky };
655a2485fe5SHans Petter Selasky
656a2485fe5SHans Petter Selasky enum mlx5_pci_status {
657a2485fe5SHans Petter Selasky MLX5_PCI_STATUS_DISABLED,
658a2485fe5SHans Petter Selasky MLX5_PCI_STATUS_ENABLED,
659a2485fe5SHans Petter Selasky };
660a2485fe5SHans Petter Selasky
661e9dcd831SSlava Shwartsman #define MLX5_MAX_RESERVED_GIDS 8
662e9dcd831SSlava Shwartsman
663e9dcd831SSlava Shwartsman struct mlx5_rsvd_gids {
664e9dcd831SSlava Shwartsman unsigned int start;
665e9dcd831SSlava Shwartsman unsigned int count;
666e9dcd831SSlava Shwartsman struct ida ida;
667e9dcd831SSlava Shwartsman };
668e9dcd831SSlava Shwartsman
669dc7e38acSHans Petter Selasky struct mlx5_special_contexts {
670dc7e38acSHans Petter Selasky int resd_lkey;
671dc7e38acSHans Petter Selasky };
672dc7e38acSHans Petter Selasky
673aa7bbdabSHans Petter Selasky struct mlx5_diag_cnt_id {
674aa7bbdabSHans Petter Selasky u16 id;
675aa7bbdabSHans Petter Selasky bool enabled;
676aa7bbdabSHans Petter Selasky };
677aa7bbdabSHans Petter Selasky
678aa7bbdabSHans Petter Selasky struct mlx5_diag_cnt {
679aa7bbdabSHans Petter Selasky #define DIAG_LOCK(dc) mutex_lock(&(dc)->lock)
680aa7bbdabSHans Petter Selasky #define DIAG_UNLOCK(dc) mutex_unlock(&(dc)->lock)
681aa7bbdabSHans Petter Selasky struct mutex lock;
682aa7bbdabSHans Petter Selasky struct sysctl_ctx_list sysctl_ctx;
683aa7bbdabSHans Petter Selasky struct mlx5_diag_cnt_id *cnt_id;
684aa7bbdabSHans Petter Selasky u16 num_of_samples;
685aa7bbdabSHans Petter Selasky u16 sample_index;
686aa7bbdabSHans Petter Selasky u8 num_cnt_id;
687aa7bbdabSHans Petter Selasky u8 log_num_of_samples;
688aa7bbdabSHans Petter Selasky u8 log_sample_period;
689aa7bbdabSHans Petter Selasky u8 flag;
690aa7bbdabSHans Petter Selasky u8 ready;
691aa7bbdabSHans Petter Selasky };
692aa7bbdabSHans Petter Selasky
6935a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace;
694dc7e38acSHans Petter Selasky struct mlx5_core_dev {
695dc7e38acSHans Petter Selasky struct pci_dev *pdev;
696a2485fe5SHans Petter Selasky /* sync pci state */
697a2485fe5SHans Petter Selasky struct mutex pci_status_mutex;
698a2485fe5SHans Petter Selasky enum mlx5_pci_status pci_status;
699dc7e38acSHans Petter Selasky char board_id[MLX5_BOARD_ID_LEN];
700dc7e38acSHans Petter Selasky struct mlx5_cmd cmd;
701dc7e38acSHans Petter Selasky struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
702dc7e38acSHans Petter Selasky u32 hca_caps_cur[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
703dc7e38acSHans Petter Selasky u32 hca_caps_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
704ed0cee0bSHans Petter Selasky struct {
7055a8145f6SHans Petter Selasky u32 pcam[MLX5_ST_SZ_DW(pcam_reg)];
7065a8145f6SHans Petter Selasky u32 mcam[MLX5_ST_SZ_DW(mcam_reg)];
707ed0cee0bSHans Petter Selasky u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
708e9dcd831SSlava Shwartsman u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
709ed0cee0bSHans Petter Selasky } caps;
710b35a986dSHans Petter Selasky phys_addr_t iseg_base;
711dc7e38acSHans Petter Selasky struct mlx5_init_seg __iomem *iseg;
712cb4e4a6eSHans Petter Selasky enum mlx5_device_state state;
713a2485fe5SHans Petter Selasky /* sync interface state */
714a2485fe5SHans Petter Selasky struct mutex intf_state_mutex;
715a2485fe5SHans Petter Selasky unsigned long intf_state;
716dc7e38acSHans Petter Selasky void (*event) (struct mlx5_core_dev *dev,
717dc7e38acSHans Petter Selasky enum mlx5_dev_event event,
718dc7e38acSHans Petter Selasky unsigned long param);
719dc7e38acSHans Petter Selasky struct mlx5_priv priv;
720dc7e38acSHans Petter Selasky struct mlx5_profile *profile;
721dc7e38acSHans Petter Selasky atomic_t num_qps;
722aa7bbdabSHans Petter Selasky struct mlx5_diag_cnt diag_cnt;
7234b95c665SHans Petter Selasky u32 vsc_addr;
724dc7e38acSHans Petter Selasky u32 issi;
725dc7e38acSHans Petter Selasky struct mlx5_special_contexts special_contexts;
726*253a1fa1SAriel Ehrenberg unsigned int module_status;
727*253a1fa1SAriel Ehrenberg unsigned int module_num;
7285a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *root_ns;
7295a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *fdb_root_ns;
7305a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *esw_egress_root_ns;
7315a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *esw_ingress_root_ns;
7325a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *sniffer_rx_root_ns;
7335a93b4cdSHans Petter Selasky struct mlx5_flow_root_namespace *sniffer_tx_root_ns;
734e23731dbSKonstantin Belousov struct mlx5_flow_root_namespace *nic_tx_root_ns;
735e23731dbSKonstantin Belousov struct mlx5_flow_root_namespace *rdma_tx_root_ns;
736e23731dbSKonstantin Belousov struct mlx5_flow_root_namespace *rdma_rx_root_ns;
737e23731dbSKonstantin Belousov
738cb4e4a6eSHans Petter Selasky u32 num_q_counter_allocated[MLX5_INTERFACE_NUMBER];
73947458190SHans Petter Selasky struct mlx5_crspace_regmap *dump_rege;
740cf551f95SHans Petter Selasky uint32_t *dump_data;
741cf551f95SHans Petter Selasky unsigned dump_size;
742cf551f95SHans Petter Selasky bool dump_valid;
743cf551f95SHans Petter Selasky bool dump_copyout;
744cf551f95SHans Petter Selasky struct mtx dump_lock;
7456ed134c4SHans Petter Selasky
746987446faSKonstantin Belousov bool iov_pf;
747987446faSKonstantin Belousov
7486ed134c4SHans Petter Selasky struct sysctl_ctx_list sysctl_ctx;
7496ed134c4SHans Petter Selasky int msix_eqvec;
750adb6fd50SHans Petter Selasky int pwr_status;
751adb6fd50SHans Petter Selasky int pwr_value;
752e9dcd831SSlava Shwartsman
753e9dcd831SSlava Shwartsman struct {
754e9dcd831SSlava Shwartsman struct mlx5_rsvd_gids reserved_gids;
755e9dcd831SSlava Shwartsman atomic_t roce_en;
756e9dcd831SSlava Shwartsman } roce;
75766b38bfeSHans Petter Selasky
75866b38bfeSHans Petter Selasky struct {
75966b38bfeSHans Petter Selasky spinlock_t spinlock;
76066b38bfeSHans Petter Selasky #define MLX5_MPFS_TABLE_MAX 32
76166b38bfeSHans Petter Selasky long bitmap[BITS_TO_LONGS(MLX5_MPFS_TABLE_MAX)];
76266b38bfeSHans Petter Selasky } mpfs;
763e9dcd831SSlava Shwartsman #ifdef CONFIG_MLX5_FPGA
764e9dcd831SSlava Shwartsman struct mlx5_fpga_device *fpga;
765e9dcd831SSlava Shwartsman #endif
766e23731dbSKonstantin Belousov struct xarray ipsec_sadb;
767dc7e38acSHans Petter Selasky };
768dc7e38acSHans Petter Selasky
769dc7e38acSHans Petter Selasky enum {
770dc7e38acSHans Petter Selasky MLX5_WOL_DISABLE = 0,
771dc7e38acSHans Petter Selasky MLX5_WOL_SECURED_MAGIC = 1 << 1,
772dc7e38acSHans Petter Selasky MLX5_WOL_MAGIC = 1 << 2,
773dc7e38acSHans Petter Selasky MLX5_WOL_ARP = 1 << 3,
774dc7e38acSHans Petter Selasky MLX5_WOL_BROADCAST = 1 << 4,
775dc7e38acSHans Petter Selasky MLX5_WOL_MULTICAST = 1 << 5,
776dc7e38acSHans Petter Selasky MLX5_WOL_UNICAST = 1 << 6,
777dc7e38acSHans Petter Selasky MLX5_WOL_PHY_ACTIVITY = 1 << 7,
778dc7e38acSHans Petter Selasky };
779dc7e38acSHans Petter Selasky
780dc7e38acSHans Petter Selasky struct mlx5_db {
781dc7e38acSHans Petter Selasky __be32 *db;
782dc7e38acSHans Petter Selasky union {
783dc7e38acSHans Petter Selasky struct mlx5_db_pgdir *pgdir;
784dc7e38acSHans Petter Selasky struct mlx5_ib_user_db_page *user_page;
785dc7e38acSHans Petter Selasky } u;
786dc7e38acSHans Petter Selasky dma_addr_t dma;
787dc7e38acSHans Petter Selasky int index;
788dc7e38acSHans Petter Selasky };
789dc7e38acSHans Petter Selasky
790dc7e38acSHans Petter Selasky struct mlx5_net_counters {
791dc7e38acSHans Petter Selasky u64 packets;
792dc7e38acSHans Petter Selasky u64 octets;
793dc7e38acSHans Petter Selasky };
794dc7e38acSHans Petter Selasky
795dc7e38acSHans Petter Selasky struct mlx5_ptys_reg {
796cb4e4a6eSHans Petter Selasky u8 an_dis_admin;
797cb4e4a6eSHans Petter Selasky u8 an_dis_ap;
798dc7e38acSHans Petter Selasky u8 local_port;
799dc7e38acSHans Petter Selasky u8 proto_mask;
800dc7e38acSHans Petter Selasky u32 eth_proto_cap;
801dc7e38acSHans Petter Selasky u16 ib_link_width_cap;
802dc7e38acSHans Petter Selasky u16 ib_proto_cap;
803dc7e38acSHans Petter Selasky u32 eth_proto_admin;
804dc7e38acSHans Petter Selasky u16 ib_link_width_admin;
805dc7e38acSHans Petter Selasky u16 ib_proto_admin;
806dc7e38acSHans Petter Selasky u32 eth_proto_oper;
807dc7e38acSHans Petter Selasky u16 ib_link_width_oper;
808dc7e38acSHans Petter Selasky u16 ib_proto_oper;
809dc7e38acSHans Petter Selasky u32 eth_proto_lp_advertise;
810dc7e38acSHans Petter Selasky };
811dc7e38acSHans Petter Selasky
812dc7e38acSHans Petter Selasky struct mlx5_pvlc_reg {
813dc7e38acSHans Petter Selasky u8 local_port;
814dc7e38acSHans Petter Selasky u8 vl_hw_cap;
815dc7e38acSHans Petter Selasky u8 vl_admin;
816dc7e38acSHans Petter Selasky u8 vl_operational;
817dc7e38acSHans Petter Selasky };
818dc7e38acSHans Petter Selasky
819dc7e38acSHans Petter Selasky struct mlx5_pmtu_reg {
820dc7e38acSHans Petter Selasky u8 local_port;
821dc7e38acSHans Petter Selasky u16 max_mtu;
822dc7e38acSHans Petter Selasky u16 admin_mtu;
823dc7e38acSHans Petter Selasky u16 oper_mtu;
824dc7e38acSHans Petter Selasky };
825dc7e38acSHans Petter Selasky
826dc7e38acSHans Petter Selasky struct mlx5_vport_counters {
827dc7e38acSHans Petter Selasky struct mlx5_net_counters received_errors;
828dc7e38acSHans Petter Selasky struct mlx5_net_counters transmit_errors;
829dc7e38acSHans Petter Selasky struct mlx5_net_counters received_ib_unicast;
830dc7e38acSHans Petter Selasky struct mlx5_net_counters transmitted_ib_unicast;
831dc7e38acSHans Petter Selasky struct mlx5_net_counters received_ib_multicast;
832dc7e38acSHans Petter Selasky struct mlx5_net_counters transmitted_ib_multicast;
833dc7e38acSHans Petter Selasky struct mlx5_net_counters received_eth_broadcast;
834dc7e38acSHans Petter Selasky struct mlx5_net_counters transmitted_eth_broadcast;
835dc7e38acSHans Petter Selasky struct mlx5_net_counters received_eth_unicast;
836dc7e38acSHans Petter Selasky struct mlx5_net_counters transmitted_eth_unicast;
837dc7e38acSHans Petter Selasky struct mlx5_net_counters received_eth_multicast;
838dc7e38acSHans Petter Selasky struct mlx5_net_counters transmitted_eth_multicast;
839dc7e38acSHans Petter Selasky };
840dc7e38acSHans Petter Selasky
841dc7e38acSHans Petter Selasky enum {
8421c807f67SHans Petter Selasky MLX5_DB_PER_PAGE = MLX5_ADAPTER_PAGE_SIZE / L1_CACHE_BYTES,
843dc7e38acSHans Petter Selasky };
844dc7e38acSHans Petter Selasky
845cb4e4a6eSHans Petter Selasky struct mlx5_core_dct {
846cb4e4a6eSHans Petter Selasky struct mlx5_core_rsc_common common; /* must be first */
847cb4e4a6eSHans Petter Selasky void (*event)(struct mlx5_core_dct *, int);
848cb4e4a6eSHans Petter Selasky int dctn;
849cb4e4a6eSHans Petter Selasky struct completion drained;
850cb4e4a6eSHans Petter Selasky struct mlx5_rsc_debug *dbg;
851cb4e4a6eSHans Petter Selasky int pid;
852cbf6911eSHans Petter Selasky u16 uid;
853cb4e4a6eSHans Petter Selasky };
854cb4e4a6eSHans Petter Selasky
855dc7e38acSHans Petter Selasky enum {
856dc7e38acSHans Petter Selasky MLX5_PTYS_IB = 1 << 0,
857dc7e38acSHans Petter Selasky MLX5_PTYS_EN = 1 << 2,
858dc7e38acSHans Petter Selasky };
859dc7e38acSHans Petter Selasky
860dc7e38acSHans Petter Selasky struct mlx5_db_pgdir {
861dc7e38acSHans Petter Selasky struct list_head list;
862dc7e38acSHans Petter Selasky DECLARE_BITMAP(bitmap, MLX5_DB_PER_PAGE);
8631c807f67SHans Petter Selasky struct mlx5_fw_page *fw_page;
864dc7e38acSHans Petter Selasky __be32 *db_page;
865dc7e38acSHans Petter Selasky dma_addr_t db_dma;
866dc7e38acSHans Petter Selasky };
867dc7e38acSHans Petter Selasky
868dc7e38acSHans Petter Selasky typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
869dc7e38acSHans Petter Selasky
870dc7e38acSHans Petter Selasky struct mlx5_cmd_work_ent {
871dc7e38acSHans Petter Selasky struct mlx5_cmd_msg *in;
872dc7e38acSHans Petter Selasky struct mlx5_cmd_msg *out;
8731c807f67SHans Petter Selasky int uin_size;
874dc7e38acSHans Petter Selasky void *uout;
875dc7e38acSHans Petter Selasky int uout_size;
876dc7e38acSHans Petter Selasky mlx5_cmd_cbk_t callback;
87711546d06SHans Petter Selasky struct delayed_work cb_timeout_work;
878dc7e38acSHans Petter Selasky void *context;
879dc7e38acSHans Petter Selasky int idx;
880dc7e38acSHans Petter Selasky struct completion done;
881dc7e38acSHans Petter Selasky struct mlx5_cmd *cmd;
882dc7e38acSHans Petter Selasky struct work_struct work;
883dc7e38acSHans Petter Selasky struct mlx5_cmd_layout *lay;
884dc7e38acSHans Petter Selasky int ret;
885dc7e38acSHans Petter Selasky int page_queue;
886dc7e38acSHans Petter Selasky u8 status;
887dc7e38acSHans Petter Selasky u8 token;
888dc7e38acSHans Petter Selasky u64 ts1;
889dc7e38acSHans Petter Selasky u64 ts2;
890dc7e38acSHans Petter Selasky u16 op;
89130dfc051SHans Petter Selasky u8 busy;
892c0902569SHans Petter Selasky bool polling;
893dc7e38acSHans Petter Selasky };
894dc7e38acSHans Petter Selasky
895dc7e38acSHans Petter Selasky struct mlx5_pas {
896dc7e38acSHans Petter Selasky u64 pa;
897dc7e38acSHans Petter Selasky u8 log_sz;
898dc7e38acSHans Petter Selasky };
899dc7e38acSHans Petter Selasky
9004b109912SHans Petter Selasky enum port_state_policy {
9014b109912SHans Petter Selasky MLX5_POLICY_DOWN = 0,
9024b109912SHans Petter Selasky MLX5_POLICY_UP = 1,
9034b109912SHans Petter Selasky MLX5_POLICY_FOLLOW = 2,
9044b109912SHans Petter Selasky MLX5_POLICY_INVALID = 0xffffffff
9054b109912SHans Petter Selasky };
9064b109912SHans Petter Selasky
9071c807f67SHans Petter Selasky static inline void *
mlx5_buf_offset(struct mlx5_buf * buf,int offset)9081c807f67SHans Petter Selasky mlx5_buf_offset(struct mlx5_buf *buf, int offset)
909dc7e38acSHans Petter Selasky {
9101c807f67SHans Petter Selasky return ((char *)buf->direct.buf + offset);
911dc7e38acSHans Petter Selasky }
912dc7e38acSHans Petter Selasky
913dc7e38acSHans Petter Selasky
914dc7e38acSHans Petter Selasky extern struct workqueue_struct *mlx5_core_wq;
915dc7e38acSHans Petter Selasky
916dc7e38acSHans Petter Selasky #define STRUCT_FIELD(header, field) \
917dc7e38acSHans Petter Selasky .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
918dc7e38acSHans Petter Selasky .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
919dc7e38acSHans Petter Selasky
pci2mlx5_core_dev(struct pci_dev * pdev)920dc7e38acSHans Petter Selasky static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
921dc7e38acSHans Petter Selasky {
922dc7e38acSHans Petter Selasky return pci_get_drvdata(pdev);
923dc7e38acSHans Petter Selasky }
924dc7e38acSHans Petter Selasky
fw_rev_maj(struct mlx5_core_dev * dev)925dc7e38acSHans Petter Selasky static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
926dc7e38acSHans Petter Selasky {
927dc7e38acSHans Petter Selasky return ioread32be(&dev->iseg->fw_rev) & 0xffff;
928dc7e38acSHans Petter Selasky }
929dc7e38acSHans Petter Selasky
fw_rev_min(struct mlx5_core_dev * dev)930dc7e38acSHans Petter Selasky static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
931dc7e38acSHans Petter Selasky {
932dc7e38acSHans Petter Selasky return ioread32be(&dev->iseg->fw_rev) >> 16;
933dc7e38acSHans Petter Selasky }
934dc7e38acSHans Petter Selasky
fw_rev_sub(struct mlx5_core_dev * dev)935dc7e38acSHans Petter Selasky static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
936dc7e38acSHans Petter Selasky {
937dc7e38acSHans Petter Selasky return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
938dc7e38acSHans Petter Selasky }
939dc7e38acSHans Petter Selasky
cmdif_rev_get(struct mlx5_core_dev * dev)940dc7e38acSHans Petter Selasky static inline u16 cmdif_rev_get(struct mlx5_core_dev *dev)
941dc7e38acSHans Petter Selasky {
942dc7e38acSHans Petter Selasky return ioread32be(&dev->iseg->cmdif_rev_fw_sub) >> 16;
943dc7e38acSHans Petter Selasky }
944dc7e38acSHans Petter Selasky
mlx5_get_gid_table_len(u16 param)945dc7e38acSHans Petter Selasky static inline int mlx5_get_gid_table_len(u16 param)
946dc7e38acSHans Petter Selasky {
947dc7e38acSHans Petter Selasky if (param > 4) {
948dc7e38acSHans Petter Selasky printf("M4_CORE_DRV_NAME: WARN: ""gid table length is zero\n");
949dc7e38acSHans Petter Selasky return 0;
950dc7e38acSHans Petter Selasky }
951dc7e38acSHans Petter Selasky
952dc7e38acSHans Petter Selasky return 8 * (1 << param);
953dc7e38acSHans Petter Selasky }
954dc7e38acSHans Petter Selasky
mlx5_vzalloc(unsigned long size)955dc7e38acSHans Petter Selasky static inline void *mlx5_vzalloc(unsigned long size)
956dc7e38acSHans Petter Selasky {
957dc7e38acSHans Petter Selasky void *rtn;
958dc7e38acSHans Petter Selasky
959dc7e38acSHans Petter Selasky rtn = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
960dc7e38acSHans Petter Selasky return rtn;
961dc7e38acSHans Petter Selasky }
962dc7e38acSHans Petter Selasky
mlx5_vmalloc(unsigned long size)963cb4e4a6eSHans Petter Selasky static inline void *mlx5_vmalloc(unsigned long size)
964dc7e38acSHans Petter Selasky {
965cb4e4a6eSHans Petter Selasky void *rtn;
966cb4e4a6eSHans Petter Selasky
967cb4e4a6eSHans Petter Selasky rtn = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
968cb4e4a6eSHans Petter Selasky if (!rtn)
969cb4e4a6eSHans Petter Selasky rtn = vmalloc(size);
970cb4e4a6eSHans Petter Selasky return rtn;
971dc7e38acSHans Petter Selasky }
972dc7e38acSHans Petter Selasky
mlx5_base_mkey(const u32 key)9734b109912SHans Petter Selasky static inline u32 mlx5_base_mkey(const u32 key)
9744b109912SHans Petter Selasky {
9754b109912SHans Petter Selasky return key & 0xffffff00u;
9764b109912SHans Petter Selasky }
9774b109912SHans Petter Selasky
978dc7e38acSHans Petter Selasky int mlx5_cmd_init(struct mlx5_core_dev *dev);
979dc7e38acSHans Petter Selasky void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
980dc7e38acSHans Petter Selasky void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
981dc7e38acSHans Petter Selasky void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
982788333d9SHans Petter Selasky void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
983788333d9SHans Petter Selasky int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
9847eefcb5eSHans Petter Selasky
9857eefcb5eSHans Petter Selasky struct mlx5_async_ctx {
9867eefcb5eSHans Petter Selasky struct mlx5_core_dev *dev;
9877eefcb5eSHans Petter Selasky atomic_t num_inflight;
9887eefcb5eSHans Petter Selasky struct wait_queue_head wait;
9897eefcb5eSHans Petter Selasky };
9907eefcb5eSHans Petter Selasky
9917eefcb5eSHans Petter Selasky struct mlx5_async_work;
9927eefcb5eSHans Petter Selasky
9937eefcb5eSHans Petter Selasky typedef void (*mlx5_async_cbk_t)(int status, struct mlx5_async_work *context);
9947eefcb5eSHans Petter Selasky
9957eefcb5eSHans Petter Selasky struct mlx5_async_work {
9967eefcb5eSHans Petter Selasky struct mlx5_async_ctx *ctx;
9977eefcb5eSHans Petter Selasky mlx5_async_cbk_t user_callback;
9987eefcb5eSHans Petter Selasky };
9997eefcb5eSHans Petter Selasky
10007eefcb5eSHans Petter Selasky void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
10017eefcb5eSHans Petter Selasky struct mlx5_async_ctx *ctx);
10027eefcb5eSHans Petter Selasky void mlx5_cmd_cleanup_async_ctx(struct mlx5_async_ctx *ctx);
10037eefcb5eSHans Petter Selasky int mlx5_cmd_exec_cb(struct mlx5_async_ctx *ctx, void *in, int in_size,
10047eefcb5eSHans Petter Selasky void *out, int out_size, mlx5_async_cbk_t callback,
10057eefcb5eSHans Petter Selasky struct mlx5_async_work *work);
1006dc7e38acSHans Petter Selasky int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
1007dc7e38acSHans Petter Selasky int out_size);
100835bbcf09SRaed Salem #define mlx5_cmd_exec_inout(dev, ifc_cmd, in, out) \
100935bbcf09SRaed Salem ({ \
101035bbcf09SRaed Salem mlx5_cmd_exec(dev, in, MLX5_ST_SZ_BYTES(ifc_cmd##_in), out, \
101135bbcf09SRaed Salem MLX5_ST_SZ_BYTES(ifc_cmd##_out)); \
101235bbcf09SRaed Salem })
101335bbcf09SRaed Salem
101435bbcf09SRaed Salem #define mlx5_cmd_exec_in(dev, ifc_cmd, in) \
101535bbcf09SRaed Salem ({ \
101635bbcf09SRaed Salem u32 _out[MLX5_ST_SZ_DW(ifc_cmd##_out)] = {}; \
101735bbcf09SRaed Salem mlx5_cmd_exec_inout(dev, ifc_cmd, in, _out); \
101835bbcf09SRaed Salem })
1019c0902569SHans Petter Selasky int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
1020c0902569SHans Petter Selasky void *out, int out_size);
1021dc7e38acSHans Petter Selasky int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
1022dc7e38acSHans Petter Selasky int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
1023f8f5b459SHans Petter Selasky int mlx5_alloc_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg,
1024f8f5b459SHans Petter Selasky bool map_wc, bool fast_path);
1025f8f5b459SHans Petter Selasky void mlx5_free_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg);
1026f8f5b459SHans Petter Selasky struct mlx5_uars_page *mlx5_get_uars_page(struct mlx5_core_dev *mdev);
1027f8f5b459SHans Petter Selasky void mlx5_put_uars_page(struct mlx5_core_dev *mdev, struct mlx5_uars_page *up);
1028a2485fe5SHans Petter Selasky void mlx5_health_cleanup(struct mlx5_core_dev *dev);
1029a2485fe5SHans Petter Selasky int mlx5_health_init(struct mlx5_core_dev *dev);
1030dc7e38acSHans Petter Selasky void mlx5_start_health_poll(struct mlx5_core_dev *dev);
10312119f825SSlava Shwartsman void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);
1032ca551594SHans Petter Selasky void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
1033519774eaSHans Petter Selasky void mlx5_drain_health_recovery(struct mlx5_core_dev *dev);
10344bb7662bSHans Petter Selasky void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
1035adb6fd50SHans Petter Selasky void mlx5_trigger_health_watchdog(struct mlx5_core_dev *dev);
10361c807f67SHans Petter Selasky
1037dc7e38acSHans Petter Selasky int mlx5_buf_alloc(struct mlx5_core_dev *dev, int size, int max_direct,
1038dc7e38acSHans Petter Selasky struct mlx5_buf *buf);
1039dc7e38acSHans Petter Selasky void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf);
1040dc7e38acSHans Petter Selasky int mlx5_core_create_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1041788333d9SHans Petter Selasky struct mlx5_srq_attr *in);
1042dc7e38acSHans Petter Selasky int mlx5_core_destroy_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq);
1043dc7e38acSHans Petter Selasky int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1044788333d9SHans Petter Selasky struct mlx5_srq_attr *out);
1045dc7e38acSHans Petter Selasky int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
1046dc7e38acSHans Petter Selasky int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
1047dc7e38acSHans Petter Selasky u16 lwm, int is_srq);
1048dc7e38acSHans Petter Selasky void mlx5_init_mr_table(struct mlx5_core_dev *dev);
1049dc7e38acSHans Petter Selasky void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev);
1050788333d9SHans Petter Selasky int mlx5_core_create_mkey_cb(struct mlx5_core_dev *dev,
1051b633e08cSHans Petter Selasky struct mlx5_core_mkey *mkey,
10527eefcb5eSHans Petter Selasky struct mlx5_async_ctx *async_ctx, u32 *in,
10537eefcb5eSHans Petter Selasky int inlen, u32 *out, int outlen,
10547eefcb5eSHans Petter Selasky mlx5_async_cbk_t callback,
10557eefcb5eSHans Petter Selasky struct mlx5_async_work *context);
1056788333d9SHans Petter Selasky int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
1057b633e08cSHans Petter Selasky struct mlx5_core_mkey *mr,
1058788333d9SHans Petter Selasky u32 *in, int inlen);
1059b633e08cSHans Petter Selasky int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey);
1060b633e08cSHans Petter Selasky int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey,
1061788333d9SHans Petter Selasky u32 *out, int outlen);
1062b633e08cSHans Petter Selasky int mlx5_core_dump_fill_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mr,
1063dc7e38acSHans Petter Selasky u32 *mkey);
1064b633e08cSHans Petter Selasky int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn, u16 uid);
1065b633e08cSHans Petter Selasky int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn, u16 uid);
1066500d0c40SHans Petter Selasky int mlx5_core_mad_ifc(struct mlx5_core_dev *dev, const void *inb, void *outb,
1067dc7e38acSHans Petter Selasky u16 opmod, u8 port);
10681c807f67SHans Petter Selasky void mlx5_fwp_flush(struct mlx5_fw_page *fwp);
10691c807f67SHans Petter Selasky void mlx5_fwp_invalidate(struct mlx5_fw_page *fwp);
10701c807f67SHans Petter Selasky struct mlx5_fw_page *mlx5_fwp_alloc(struct mlx5_core_dev *dev, gfp_t flags, unsigned num);
10711c807f67SHans Petter Selasky void mlx5_fwp_free(struct mlx5_fw_page *fwp);
10721c807f67SHans Petter Selasky u64 mlx5_fwp_get_dma(struct mlx5_fw_page *fwp, size_t offset);
10731c807f67SHans Petter Selasky void *mlx5_fwp_get_virt(struct mlx5_fw_page *fwp, size_t offset);
1074dc7e38acSHans Petter Selasky void mlx5_pagealloc_init(struct mlx5_core_dev *dev);
1075dc7e38acSHans Petter Selasky void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
1076dc7e38acSHans Petter Selasky int mlx5_pagealloc_start(struct mlx5_core_dev *dev);
1077dc7e38acSHans Petter Selasky void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
1078dc7e38acSHans Petter Selasky void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
1079dc7e38acSHans Petter Selasky s32 npages);
1080dc7e38acSHans Petter Selasky int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
1081dc7e38acSHans Petter Selasky int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
108244a03e91SHans Petter Selasky s64 mlx5_wait_for_reclaim_vfs_pages(struct mlx5_core_dev *dev);
1083dc7e38acSHans Petter Selasky void mlx5_register_debugfs(void);
1084dc7e38acSHans Petter Selasky void mlx5_unregister_debugfs(void);
1085dc7e38acSHans Petter Selasky int mlx5_eq_init(struct mlx5_core_dev *dev);
1086dc7e38acSHans Petter Selasky void mlx5_eq_cleanup(struct mlx5_core_dev *dev);
1087dc7e38acSHans Petter Selasky void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas);
1088f34f0a65SHans Petter Selasky void mlx5_cq_completion(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe);
1089dc7e38acSHans Petter Selasky void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
1090dc7e38acSHans Petter Selasky void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
1091dc7e38acSHans Petter Selasky struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);
1092721a1a6aSSlava Shwartsman void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vector, enum mlx5_cmd_mode mode);
1093dc7e38acSHans Petter Selasky void mlx5_cq_event(struct mlx5_core_dev *dev, u32 cqn, int event_type);
1094dc7e38acSHans Petter Selasky int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
1095f8f5b459SHans Petter Selasky int nent, u64 mask);
1096dc7e38acSHans Petter Selasky int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1097dc7e38acSHans Petter Selasky int mlx5_start_eqs(struct mlx5_core_dev *dev);
1098dc7e38acSHans Petter Selasky int mlx5_stop_eqs(struct mlx5_core_dev *dev);
1099dc7e38acSHans Petter Selasky int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn, int *irqn);
1100dc7e38acSHans Petter Selasky int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
1101dc7e38acSHans Petter Selasky int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
1102cb4e4a6eSHans Petter Selasky int mlx5_core_set_dc_cnak_trace(struct mlx5_core_dev *dev, int enable,
1103cb4e4a6eSHans Petter Selasky u64 addr);
1104dc7e38acSHans Petter Selasky
1105dc7e38acSHans Petter Selasky int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
1106dc7e38acSHans Petter Selasky void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
1107dc7e38acSHans Petter Selasky int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
1108dc7e38acSHans Petter Selasky int size_in, void *data_out, int size_out,
1109dc7e38acSHans Petter Selasky u16 reg_num, int arg, int write);
1110dc7e38acSHans Petter Selasky
1111cb4e4a6eSHans Petter Selasky void mlx5_toggle_port_link(struct mlx5_core_dev *dev);
1112dc7e38acSHans Petter Selasky
1113dc7e38acSHans Petter Selasky int mlx5_debug_eq_add(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1114dc7e38acSHans Petter Selasky void mlx5_debug_eq_remove(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
1115dc7e38acSHans Petter Selasky int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
1116788333d9SHans Petter Selasky u32 *out, int outlen);
1117dc7e38acSHans Petter Selasky int mlx5_eq_debugfs_init(struct mlx5_core_dev *dev);
1118dc7e38acSHans Petter Selasky void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev);
1119dc7e38acSHans Petter Selasky int mlx5_cq_debugfs_init(struct mlx5_core_dev *dev);
1120dc7e38acSHans Petter Selasky void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev);
1121dc7e38acSHans Petter Selasky int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
1122dc7e38acSHans Petter Selasky void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
1123dc7e38acSHans Petter Selasky
11247c3eff94SHans Petter Selasky static inline struct domainset *
mlx5_dev_domainset(struct mlx5_core_dev * mdev)11257c3eff94SHans Petter Selasky mlx5_dev_domainset(struct mlx5_core_dev *mdev)
11267c3eff94SHans Petter Selasky {
11277c3eff94SHans Petter Selasky return (linux_get_vm_domain_set(mdev->priv.numa_node));
11287c3eff94SHans Petter Selasky }
11297c3eff94SHans Petter Selasky
1130dc7e38acSHans Petter Selasky const char *mlx5_command_str(int command);
1131dc7e38acSHans Petter Selasky int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
1132dc7e38acSHans Petter Selasky void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
1133dc7e38acSHans Petter Selasky int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
1134dc7e38acSHans Petter Selasky int npsvs, u32 *sig_index);
1135dc7e38acSHans Petter Selasky int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
1136dc7e38acSHans Petter Selasky void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
1137dc7e38acSHans Petter Selasky u8 mlx5_is_wol_supported(struct mlx5_core_dev *dev);
1138dc7e38acSHans Petter Selasky int mlx5_set_wol(struct mlx5_core_dev *dev, u8 wol_mode);
113927c29bc4SHans Petter Selasky int mlx5_set_dropless_mode(struct mlx5_core_dev *dev, u16 timeout);
114027c29bc4SHans Petter Selasky int mlx5_query_dropless_mode(struct mlx5_core_dev *dev, u16 *timeout);
1141dc7e38acSHans Petter Selasky int mlx5_query_wol(struct mlx5_core_dev *dev, u8 *wol_mode);
1142dc7e38acSHans Petter Selasky int mlx5_core_access_pvlc(struct mlx5_core_dev *dev,
1143dc7e38acSHans Petter Selasky struct mlx5_pvlc_reg *pvlc, int write);
1144dc7e38acSHans Petter Selasky int mlx5_core_access_ptys(struct mlx5_core_dev *dev,
1145dc7e38acSHans Petter Selasky struct mlx5_ptys_reg *ptys, int write);
1146dc7e38acSHans Petter Selasky int mlx5_core_access_pmtu(struct mlx5_core_dev *dev,
1147dc7e38acSHans Petter Selasky struct mlx5_pmtu_reg *pmtu, int write);
1148dc7e38acSHans Petter Selasky int mlx5_vxlan_udp_port_add(struct mlx5_core_dev *dev, u16 port);
1149dc7e38acSHans Petter Selasky int mlx5_vxlan_udp_port_delete(struct mlx5_core_dev *dev, u16 port);
1150dc7e38acSHans Petter Selasky int mlx5_query_port_cong_status(struct mlx5_core_dev *mdev, int protocol,
1151dc7e38acSHans Petter Selasky int priority, int *is_enable);
1152dc7e38acSHans Petter Selasky int mlx5_modify_port_cong_status(struct mlx5_core_dev *mdev, int protocol,
1153dc7e38acSHans Petter Selasky int priority, int enable);
1154dc7e38acSHans Petter Selasky int mlx5_query_port_cong_params(struct mlx5_core_dev *mdev, int protocol,
1155dc7e38acSHans Petter Selasky void *out, int out_size);
1156dc7e38acSHans Petter Selasky int mlx5_modify_port_cong_params(struct mlx5_core_dev *mdev,
1157dc7e38acSHans Petter Selasky void *in, int in_size);
1158dc7e38acSHans Petter Selasky int mlx5_query_port_cong_statistics(struct mlx5_core_dev *mdev, int clear,
1159dc7e38acSHans Petter Selasky void *out, int out_size);
1160cb022443SHans Petter Selasky int mlx5_set_diagnostic_params(struct mlx5_core_dev *mdev, void *in,
1161cb022443SHans Petter Selasky int in_size);
1162cb022443SHans Petter Selasky int mlx5_query_diagnostic_counters(struct mlx5_core_dev *mdev,
1163cb022443SHans Petter Selasky u8 num_of_samples, u16 sample_index,
1164cb022443SHans Petter Selasky void *out, int out_size);
11654b95c665SHans Petter Selasky int mlx5_vsc_find_cap(struct mlx5_core_dev *mdev);
11664b95c665SHans Petter Selasky int mlx5_vsc_lock(struct mlx5_core_dev *mdev);
11674b95c665SHans Petter Selasky void mlx5_vsc_unlock(struct mlx5_core_dev *mdev);
11684b95c665SHans Petter Selasky int mlx5_vsc_set_space(struct mlx5_core_dev *mdev, u16 space);
1169e456deccSHans Petter Selasky int mlx5_vsc_wait_on_flag(struct mlx5_core_dev *mdev, u32 expected);
1170b575d8c8SHans Petter Selasky int mlx5_vsc_write(struct mlx5_core_dev *mdev, u32 addr, const u32 *data);
11714b95c665SHans Petter Selasky int mlx5_vsc_read(struct mlx5_core_dev *mdev, u32 addr, u32 *data);
1172b575d8c8SHans Petter Selasky int mlx5_vsc_lock_addr_space(struct mlx5_core_dev *mdev, u32 addr);
1173b575d8c8SHans Petter Selasky int mlx5_vsc_unlock_addr_space(struct mlx5_core_dev *mdev, u32 addr);
1174adb6fd50SHans Petter Selasky int mlx5_pci_read_power_status(struct mlx5_core_dev *mdev,
1175adb6fd50SHans Petter Selasky u16 *p_power, u8 *p_status);
1176b575d8c8SHans Petter Selasky
mlx5_mkey_to_idx(u32 mkey)1177dc7e38acSHans Petter Selasky static inline u32 mlx5_mkey_to_idx(u32 mkey)
1178dc7e38acSHans Petter Selasky {
1179dc7e38acSHans Petter Selasky return mkey >> 8;
1180dc7e38acSHans Petter Selasky }
1181dc7e38acSHans Petter Selasky
mlx5_idx_to_mkey(u32 mkey_idx)1182dc7e38acSHans Petter Selasky static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
1183dc7e38acSHans Petter Selasky {
1184dc7e38acSHans Petter Selasky return mkey_idx << 8;
1185dc7e38acSHans Petter Selasky }
1186dc7e38acSHans Petter Selasky
mlx5_mkey_variant(u32 mkey)1187dc7e38acSHans Petter Selasky static inline u8 mlx5_mkey_variant(u32 mkey)
1188dc7e38acSHans Petter Selasky {
1189dc7e38acSHans Petter Selasky return mkey & 0xff;
1190dc7e38acSHans Petter Selasky }
1191dc7e38acSHans Petter Selasky
1192dc7e38acSHans Petter Selasky enum {
1193dc7e38acSHans Petter Selasky MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
1194dc7e38acSHans Petter Selasky MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
1195dc7e38acSHans Petter Selasky };
1196dc7e38acSHans Petter Selasky
1197dc7e38acSHans Petter Selasky enum {
1198cb4e4a6eSHans Petter Selasky MAX_MR_CACHE_ENTRIES = 15,
1199dc7e38acSHans Petter Selasky };
1200dc7e38acSHans Petter Selasky
1201dc7e38acSHans Petter Selasky struct mlx5_interface {
1202dc7e38acSHans Petter Selasky void * (*add)(struct mlx5_core_dev *dev);
1203dc7e38acSHans Petter Selasky void (*remove)(struct mlx5_core_dev *dev, void *context);
1204dc7e38acSHans Petter Selasky void (*event)(struct mlx5_core_dev *dev, void *context,
1205dc7e38acSHans Petter Selasky enum mlx5_dev_event event, unsigned long param);
1206dc7e38acSHans Petter Selasky void * (*get_dev)(void *context);
1207dc7e38acSHans Petter Selasky int protocol;
1208dc7e38acSHans Petter Selasky struct list_head list;
1209dc7e38acSHans Petter Selasky };
1210dc7e38acSHans Petter Selasky
1211dc7e38acSHans Petter Selasky void *mlx5_get_protocol_dev(struct mlx5_core_dev *mdev, int protocol);
1212dc7e38acSHans Petter Selasky int mlx5_register_interface(struct mlx5_interface *intf);
1213dc7e38acSHans Petter Selasky void mlx5_unregister_interface(struct mlx5_interface *intf);
1214dc7e38acSHans Petter Selasky
1215e9dcd831SSlava Shwartsman unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
1216e9dcd831SSlava Shwartsman int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
1217e9dcd831SSlava Shwartsman u8 roce_version, u8 roce_l3_type, const u8 *gid,
1218e9dcd831SSlava Shwartsman const u8 *mac, bool vlan, u16 vlan_id);
1219e9dcd831SSlava Shwartsman
1220dc7e38acSHans Petter Selasky struct mlx5_profile {
1221dc7e38acSHans Petter Selasky u64 mask;
1222dc7e38acSHans Petter Selasky u8 log_max_qp;
1223dc7e38acSHans Petter Selasky struct {
1224dc7e38acSHans Petter Selasky int size;
1225dc7e38acSHans Petter Selasky int limit;
1226dc7e38acSHans Petter Selasky } mr_cache[MAX_MR_CACHE_ENTRIES];
1227dc7e38acSHans Petter Selasky };
1228dc7e38acSHans Petter Selasky
1229cb4e4a6eSHans Petter Selasky enum {
1230cb4e4a6eSHans Petter Selasky MLX5_PCI_DEV_IS_VF = 1 << 0,
1231cb4e4a6eSHans Petter Selasky };
1232cb4e4a6eSHans Petter Selasky
1233a2485fe5SHans Petter Selasky enum {
1234a2485fe5SHans Petter Selasky MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
1235a2485fe5SHans Petter Selasky };
1236a2485fe5SHans Petter Selasky
mlx5_core_is_pf(struct mlx5_core_dev * dev)1237cb4e4a6eSHans Petter Selasky static inline int mlx5_core_is_pf(struct mlx5_core_dev *dev)
1238cb4e4a6eSHans Petter Selasky {
1239cb4e4a6eSHans Petter Selasky return !(dev->priv.pci_dev_data & MLX5_PCI_DEV_IS_VF);
1240cb4e4a6eSHans Petter Selasky }
124138535d6cSHans Petter Selasky #ifdef RATELIMIT
124238535d6cSHans Petter Selasky int mlx5_init_rl_table(struct mlx5_core_dev *dev);
124338535d6cSHans Petter Selasky void mlx5_cleanup_rl_table(struct mlx5_core_dev *dev);
124438535d6cSHans Petter Selasky int mlx5_rl_add_rate(struct mlx5_core_dev *dev, u32 rate, u32 burst, u16 *index);
124538535d6cSHans Petter Selasky void mlx5_rl_remove_rate(struct mlx5_core_dev *dev, u32 rate, u32 burst);
124638535d6cSHans Petter Selasky bool mlx5_rl_is_in_range(const struct mlx5_core_dev *dev, u32 rate, u32 burst);
1247266c81aaSHans Petter Selasky int mlx5e_query_rate_limit_cmd(struct mlx5_core_dev *dev, u16 index, u32 *scq_handle);
1248266c81aaSHans Petter Selasky
mlx5_rl_get_scq_handle(struct mlx5_core_dev * dev,uint16_t index)1249266c81aaSHans Petter Selasky static inline u32 mlx5_rl_get_scq_handle(struct mlx5_core_dev *dev, uint16_t index)
1250266c81aaSHans Petter Selasky {
1251266c81aaSHans Petter Selasky KASSERT(index > 0,
1252266c81aaSHans Petter Selasky ("invalid rate index for sq remap, failed retrieving SCQ handle"));
1253266c81aaSHans Petter Selasky
1254266c81aaSHans Petter Selasky return (dev->priv.rl_table.rl_entry[index - 1].qos_handle);
1255266c81aaSHans Petter Selasky }
125638535d6cSHans Petter Selasky
mlx5_rl_is_supported(struct mlx5_core_dev * dev)125738535d6cSHans Petter Selasky static inline bool mlx5_rl_is_supported(struct mlx5_core_dev *dev)
125838535d6cSHans Petter Selasky {
125938535d6cSHans Petter Selasky return !!(dev->priv.rl_table.max_size);
126038535d6cSHans Petter Selasky }
126138535d6cSHans Petter Selasky #endif
1262dc7e38acSHans Petter Selasky
1263f14d8498SHans Petter Selasky void mlx5_disable_interrupts(struct mlx5_core_dev *);
1264f14d8498SHans Petter Selasky void mlx5_poll_interrupts(struct mlx5_core_dev *);
1265f14d8498SHans Petter Selasky
mlx5_get_qp_default_ts(struct mlx5_core_dev * dev)12664fb0a74eSHans Petter Selasky static inline int mlx5_get_qp_default_ts(struct mlx5_core_dev *dev)
12674fb0a74eSHans Petter Selasky {
12684fb0a74eSHans Petter Selasky return !MLX5_CAP_ROCE(dev, qp_ts_format) ?
12694fb0a74eSHans Petter Selasky MLX5_QPC_TIMESTAMP_FORMAT_FREE_RUNNING :
12704fb0a74eSHans Petter Selasky MLX5_QPC_TIMESTAMP_FORMAT_DEFAULT;
12714fb0a74eSHans Petter Selasky }
12724fb0a74eSHans Petter Selasky
mlx5_get_rq_default_ts(struct mlx5_core_dev * dev)12734fb0a74eSHans Petter Selasky static inline int mlx5_get_rq_default_ts(struct mlx5_core_dev *dev)
12744fb0a74eSHans Petter Selasky {
12754fb0a74eSHans Petter Selasky return !MLX5_CAP_GEN(dev, rq_ts_format) ?
12764fb0a74eSHans Petter Selasky MLX5_RQC_TIMESTAMP_FORMAT_FREE_RUNNING :
12774fb0a74eSHans Petter Selasky MLX5_RQC_TIMESTAMP_FORMAT_DEFAULT;
12784fb0a74eSHans Petter Selasky }
12794fb0a74eSHans Petter Selasky
mlx5_get_sq_default_ts(struct mlx5_core_dev * dev)12804fb0a74eSHans Petter Selasky static inline int mlx5_get_sq_default_ts(struct mlx5_core_dev *dev)
12814fb0a74eSHans Petter Selasky {
12824fb0a74eSHans Petter Selasky return !MLX5_CAP_GEN(dev, sq_ts_format) ?
12834fb0a74eSHans Petter Selasky MLX5_SQC_TIMESTAMP_FORMAT_FREE_RUNNING :
12844fb0a74eSHans Petter Selasky MLX5_SQC_TIMESTAMP_FORMAT_DEFAULT;
12854fb0a74eSHans Petter Selasky }
12864fb0a74eSHans Petter Selasky
1287dc7e38acSHans Petter Selasky #endif /* MLX5_DRIVER_H */
1288