]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/net/ethernet/mellanox/mlx5/core/en.h
net/mlx5i: Use compilation flag in IPOIB header
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / mellanox / mlx5 / core / en.h
CommitLineData
f62b8bb8 1/*
1afff42c 2 * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
f62b8bb8
AV
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
1afff42c
MF
32#ifndef __MLX5_EN_H__
33#define __MLX5_EN_H__
f62b8bb8
AV
34
35#include <linux/if_vlan.h>
36#include <linux/etherdevice.h>
ef9814de
EBE
37#include <linux/timecounter.h>
38#include <linux/net_tstamp.h>
3d8c38af 39#include <linux/ptp_clock_kernel.h>
48935bbb 40#include <linux/crash_dump.h>
f62b8bb8
AV
41#include <linux/mlx5/driver.h>
42#include <linux/mlx5/qp.h>
43#include <linux/mlx5/cq.h>
ada68c31 44#include <linux/mlx5/port.h>
d18a9470 45#include <linux/mlx5/vport.h>
8d7f9ecb 46#include <linux/mlx5/transobj.h>
1ae1df3a 47#include <linux/mlx5/fs.h>
e8f887ac 48#include <linux/rhashtable.h>
cb67b832 49#include <net/switchdev.h>
0ddf5432 50#include <net/xdp.h>
4c4dbb4a 51#include <linux/net_dim.h>
f62b8bb8 52#include "wq.h"
f62b8bb8 53#include "mlx5_core.h"
9218b44d 54#include "en_stats.h"
f62b8bb8 55
60bbf7ee
JDB
56struct page_pool;
57
bb909416
IL
58#define MLX5E_METADATA_ETHER_TYPE (0x8CE4)
59#define MLX5E_METADATA_ETHER_LEN 8
60
1cabe6b0
MG
61#define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
62
c139dbfd
ES
63#define MLX5E_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
64
472a1e44
TT
65#define MLX5E_HW2SW_MTU(params, hwmtu) ((hwmtu) - ((params)->hard_mtu))
66#define MLX5E_SW2HW_MTU(params, swmtu) ((swmtu) + ((params)->hard_mtu))
d8bec2b2 67
0696d608 68#define MLX5E_MAX_PRIORITY 8
2a5e7a13 69#define MLX5E_MAX_DSCP 64
f62b8bb8
AV
70#define MLX5E_MAX_NUM_TC 8
71
1bfecfca 72#define MLX5_RX_HEADROOM NET_SKB_PAD
78aedd32
TT
73#define MLX5_SKB_FRAG_SZ(len) (SKB_DATA_ALIGN(len) + \
74 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
1bfecfca 75
f32f5bd2
DJ
76#define MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev) \
77 (6 + MLX5_CAP_GEN(mdev, cache_line_128byte)) /* HW restriction */
78#define MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, req) \
79 max_t(u32, MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev), req)
80#define MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev) MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 6)
81#define MLX5_MPWRQ_CQE_CMPRS_LOG_STRIDE_SZ(mdev) MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 8)
696a97cf
EE
82#define MLX5E_MPWQE_STRIDE_SZ(mdev, cqe_cmprs) \
83 (cqe_cmprs ? MLX5_MPWRQ_CQE_CMPRS_LOG_STRIDE_SZ(mdev) : \
84 MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev))
f32f5bd2 85
7e426671 86#define MLX5_MPWRQ_LOG_WQE_SZ 18
461017cb
TT
87#define MLX5_MPWRQ_WQE_PAGE_ORDER (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
88 MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
89#define MLX5_MPWRQ_PAGES_PER_WQE BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
fe4c988b
SM
90
91#define MLX5_MTT_OCTW(npages) (ALIGN(npages, 8) / 2)
73281b78 92#define MLX5E_REQUIRED_WQE_MTTS (ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8))
b8a98a4c 93#define MLX5E_LOG_ALIGNED_MPWQE_PPW (ilog2(MLX5E_REQUIRED_WQE_MTTS))
73281b78
TT
94#define MLX5E_REQUIRED_MTTS(wqes) (wqes * MLX5E_REQUIRED_WQE_MTTS)
95#define MLX5E_MAX_RQ_NUM_MTTS \
96 ((1 << 16) * 2) /* So that MLX5_MTT_OCTW(num_mtts) fits into u16 */
97#define MLX5E_ORDER2_MAX_PACKET_MTU (order_base_2(10 * 1024))
98#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW \
99 (ilog2(MLX5E_MAX_RQ_NUM_MTTS / MLX5E_REQUIRED_WQE_MTTS))
100#define MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW \
101 (MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW + \
102 (MLX5_MPWRQ_LOG_WQE_SZ - MLX5E_ORDER2_MAX_PACKET_MTU))
103
104#define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x6
105#define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE 0xa
106#define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE 0xd
107
108#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE 0x1
109#define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE 0xa
110#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE min_t(u8, 0xd, \
111 MLX5E_LOG_MAX_RQ_NUM_PACKETS_MPW)
112
113#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW 0x2
fe4c988b 114
cbad8cdd 115#define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD (256)
461017cb 116
d9a40271 117#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
2b029556
SM
118#define MLX5E_DEFAULT_LRO_TIMEOUT 32
119#define MLX5E_LRO_TIMEOUT_ARR_SIZE 4
120
f62b8bb8 121#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
9908aa29 122#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
f62b8bb8
AV
123#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
124#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC 0x10
0088cbbc 125#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC_FROM_CQE 0x10
f62b8bb8
AV
126#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS 0x20
127#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES 0x80
461017cb 128#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW 0x2
f62b8bb8 129
936896e9
AS
130#define MLX5E_LOG_INDIR_RQT_SIZE 0x7
131#define MLX5E_INDIR_RQT_SIZE BIT(MLX5E_LOG_INDIR_RQT_SIZE)
b4e029da 132#define MLX5E_MIN_NUM_CHANNELS 0x1
936896e9 133#define MLX5E_MAX_NUM_CHANNELS (MLX5E_INDIR_RQT_SIZE >> 1)
507f0c81 134#define MLX5E_MAX_NUM_SQS (MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC)
f62b8bb8
AV
135#define MLX5E_TX_CQ_POLL_BUDGET 128
136#define MLX5E_UPDATE_STATS_INTERVAL 200 /* msecs */
db75373c 137#define MLX5E_SQ_RECOVER_MIN_INTERVAL 500 /* msecs */
f62b8bb8 138
ea3886ca
TT
139#define MLX5E_UMR_WQE_INLINE_SZ \
140 (sizeof(struct mlx5e_umr_wqe) + \
141 ALIGN(MLX5_MPWRQ_PAGES_PER_WQE * sizeof(struct mlx5_mtt), \
142 MLX5_UMR_MTT_ALIGNMENT))
143#define MLX5E_UMR_WQEBBS \
144 (DIV_ROUND_UP(MLX5E_UMR_WQE_INLINE_SZ, MLX5_SEND_WQE_BB))
145#define MLX5E_ICOSQ_MAX_WQEBBS MLX5E_UMR_WQEBBS
f10b7cc7 146
b5503b99 147#define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)
b5503b99 148#define MLX5E_XDP_TX_DS_COUNT \
b70149dd 149 ((sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) + 1 /* SG DS */)
b5503b99 150
86d722ad 151#define MLX5E_NUM_MAIN_GROUPS 9
2f48af12 152
79c48764
GP
153#define MLX5E_MSG_LEVEL NETIF_MSG_LINK
154
155#define mlx5e_dbg(mlevel, priv, format, ...) \
156do { \
157 if (NETIF_MSG_##mlevel & (priv)->msglevel) \
158 netdev_warn(priv->netdev, format, \
159 ##__VA_ARGS__); \
160} while (0)
161
162
461017cb
TT
163static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
164{
165 switch (wq_type) {
166 case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
167 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
168 wq_size / 2);
169 default:
170 return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
171 wq_size / 2);
172 }
173}
174
48935bbb
SM
175static inline int mlx5e_get_max_num_channels(struct mlx5_core_dev *mdev)
176{
177 return is_kdump_kernel() ?
178 MLX5E_MIN_NUM_CHANNELS :
179 min_t(int, mdev->priv.eq_table.num_comp_vectors,
180 MLX5E_MAX_NUM_CHANNELS);
181}
182
2f48af12
TT
183struct mlx5e_tx_wqe {
184 struct mlx5_wqe_ctrl_seg ctrl;
185 struct mlx5_wqe_eth_seg eth;
043dc78e 186 struct mlx5_wqe_data_seg data[0];
2f48af12
TT
187};
188
189struct mlx5e_rx_wqe {
190 struct mlx5_wqe_srq_next_seg next;
191 struct mlx5_wqe_data_seg data;
192};
86d722ad 193
bc77b240
TT
194struct mlx5e_umr_wqe {
195 struct mlx5_wqe_ctrl_seg ctrl;
196 struct mlx5_wqe_umr_ctrl_seg uctrl;
197 struct mlx5_mkey_seg mkc;
ea3886ca 198 struct mlx5_mtt inline_mtts[0];
bc77b240
TT
199};
200
d605d668
KH
201extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];
202
4e59e288 203static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
9908aa29 204 "rx_cqe_moder",
0088cbbc 205 "tx_cqe_moder",
9bcc8606 206 "rx_cqe_compress",
2ccb0a79 207 "rx_striding_rq",
4e59e288
GP
208};
209
210enum mlx5e_priv_flag {
9908aa29 211 MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
0088cbbc
TG
212 MLX5E_PFLAG_TX_CQE_BASED_MODER = (1 << 1),
213 MLX5E_PFLAG_RX_CQE_COMPRESS = (1 << 2),
2ccb0a79 214 MLX5E_PFLAG_RX_STRIDING_RQ = (1 << 3),
4e59e288
GP
215};
216
6a9764ef 217#define MLX5E_SET_PFLAG(params, pflag, enable) \
59ece1c9
SD
218 do { \
219 if (enable) \
6a9764ef 220 (params)->pflags |= (pflag); \
59ece1c9 221 else \
6a9764ef 222 (params)->pflags &= ~(pflag); \
4e59e288
GP
223 } while (0)
224
6a9764ef 225#define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (pflag)))
59ece1c9 226
08fb1dac
SM
227#ifdef CONFIG_MLX5_CORE_EN_DCB
228#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
08fb1dac
SM
229#endif
230
f62b8bb8
AV
231struct mlx5e_params {
232 u8 log_sq_size;
461017cb 233 u8 rq_wq_type;
73281b78 234 u8 log_rq_mtu_frames;
f62b8bb8 235 u16 num_channels;
f62b8bb8 236 u8 num_tc;
9bcc8606 237 bool rx_cqe_compress_def;
9a317425
AG
238 struct net_dim_cq_moder rx_cq_moderation;
239 struct net_dim_cq_moder tx_cq_moderation;
f62b8bb8
AV
240 bool lro_en;
241 u32 lro_wqe_sz;
cff92d7c 242 u8 tx_min_inline_mode;
2d75b2bc
AS
243 u8 rss_hfunc;
244 u8 toeplitz_hash_key[40];
245 u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
36350114 246 bool vlan_strip_disable;
102722fc 247 bool scatter_fcs_en;
9a317425 248 bool rx_dim_enabled;
cbce4f44 249 bool tx_dim_enabled;
2b029556 250 u32 lro_timeout;
59ece1c9 251 u32 pflags;
6a9764ef 252 struct bpf_prog *xdp_prog;
472a1e44
TT
253 unsigned int sw_mtu;
254 int hard_mtu;
f62b8bb8
AV
255};
256
3a6a931d
HN
257#ifdef CONFIG_MLX5_CORE_EN_DCB
258struct mlx5e_cee_config {
259 /* bw pct for priority group */
260 u8 pg_bw_pct[CEE_DCBX_MAX_PGS];
261 u8 prio_to_pg_map[CEE_DCBX_MAX_PRIO];
262 bool pfc_setting[CEE_DCBX_MAX_PRIO];
263 bool pfc_enable;
264};
265
266enum {
267 MLX5_DCB_CHG_RESET,
268 MLX5_DCB_NO_CHG,
269 MLX5_DCB_CHG_NO_RESET,
270};
271
272struct mlx5e_dcbx {
e207b7e9 273 enum mlx5_dcbx_oper_mode mode;
3a6a931d 274 struct mlx5e_cee_config cee_cfg; /* pending configuration */
2a5e7a13 275 u8 dscp_app_cnt;
820c2c5e
HN
276
277 /* The only setting that cannot be read from FW */
278 u8 tc_tsa[IEEE_8021QAZ_MAX_TCS];
9e10bf1d 279 u8 cap;
0696d608
HN
280
281 /* Buffer configuration */
ecdf2dad 282 bool manual_buffer;
0696d608
HN
283 u32 cable_len;
284 u32 xoff;
3a6a931d 285};
2a5e7a13
HN
286
287struct mlx5e_dcbx_dp {
288 u8 dscp2prio[MLX5E_MAX_DSCP];
289 u8 trust_state;
290};
3a6a931d
HN
291#endif
292
f62b8bb8 293enum {
c0f1147d 294 MLX5E_RQ_STATE_ENABLED,
cb3c7fd4 295 MLX5E_RQ_STATE_AM,
f62b8bb8
AV
296};
297
f62b8bb8
AV
298struct mlx5e_cq {
299 /* data path - accessed per cqe */
300 struct mlx5_cqwq wq;
f62b8bb8
AV
301
302 /* data path - accessed per napi poll */
cb3c7fd4 303 u16 event_ctr;
f62b8bb8
AV
304 struct napi_struct *napi;
305 struct mlx5_core_cq mcq;
306 struct mlx5e_channel *channel;
307
7219ab34
TT
308 /* cqe decompression */
309 struct mlx5_cqe64 title;
310 struct mlx5_mini_cqe8 mini_arr[MLX5_MINI_CQE_ARRAY_SIZE];
311 u8 mini_arr_idx;
312 u16 decmprs_left;
313 u16 decmprs_wqe_counter;
314
f62b8bb8 315 /* control */
a43b25da 316 struct mlx5_core_dev *mdev;
1c1b5228 317 struct mlx5_frag_wq_ctrl wq_ctrl;
f62b8bb8
AV
318} ____cacheline_aligned_in_smp;
319
eba2db2b 320struct mlx5e_tx_wqe_info {
77bdf895 321 struct sk_buff *skb;
eba2db2b
SM
322 u32 num_bytes;
323 u8 num_wqebbs;
324 u8 num_dma;
325};
326
327enum mlx5e_dma_map_type {
328 MLX5E_DMA_MAP_SINGLE,
329 MLX5E_DMA_MAP_PAGE
330};
331
332struct mlx5e_sq_dma {
333 dma_addr_t addr;
334 u32 size;
335 enum mlx5e_dma_map_type type;
336};
337
338enum {
339 MLX5E_SQ_STATE_ENABLED,
db75373c 340 MLX5E_SQ_STATE_RECOVERING,
2ac9cfe7 341 MLX5E_SQ_STATE_IPSEC,
cbce4f44 342 MLX5E_SQ_STATE_AM,
bf239741 343 MLX5E_SQ_STATE_TLS,
eba2db2b
SM
344};
345
346struct mlx5e_sq_wqe_info {
347 u8 opcode;
eba2db2b 348};
2f48af12 349
31391048 350struct mlx5e_txqsq {
eba2db2b
SM
351 /* data path */
352
353 /* dirtied @completion */
354 u16 cc;
355 u32 dma_fifo_cc;
cbce4f44 356 struct net_dim dim; /* Adaptive Moderation */
eba2db2b
SM
357
358 /* dirtied @xmit */
359 u16 pc ____cacheline_aligned_in_smp;
360 u32 dma_fifo_pc;
361 struct mlx5e_sq_stats stats;
362
363 struct mlx5e_cq cq;
364
31391048
SM
365 /* write@xmit, read@completion */
366 struct {
31391048
SM
367 struct mlx5e_sq_dma *dma_fifo;
368 struct mlx5e_tx_wqe_info *wqe_info;
eba2db2b
SM
369 } db;
370
371 /* read only */
372 struct mlx5_wq_cyc wq;
373 u32 dma_fifo_mask;
374 void __iomem *uar_map;
375 struct netdev_queue *txq;
376 u32 sqn;
eba2db2b 377 u8 min_inline_mode;
eba2db2b 378 struct device *pdev;
eba2db2b
SM
379 __be32 mkey_be;
380 unsigned long state;
7c39afb3
FD
381 struct hwtstamp_config *tstamp;
382 struct mlx5_clock *clock;
eba2db2b
SM
383
384 /* control path */
385 struct mlx5_wq_ctrl wq_ctrl;
386 struct mlx5e_channel *channel;
acc6c595 387 int txq_ix;
eba2db2b 388 u32 rate_limit;
db75373c
EBE
389 struct mlx5e_txqsq_recover {
390 struct work_struct recover_work;
391 u64 last_recover;
392 } recover;
31391048
SM
393} ____cacheline_aligned_in_smp;
394
395struct mlx5e_xdpsq {
396 /* data path */
397
398 /* dirtied @rx completion */
399 u16 cc;
400 u16 pc;
401
402 struct mlx5e_cq cq;
403
404 /* write@xmit, read@completion */
405 struct {
406 struct mlx5e_dma_info *di;
407 bool doorbell;
5168d732 408 bool redirect_flush;
31391048
SM
409 } db;
410
411 /* read only */
412 struct mlx5_wq_cyc wq;
413 void __iomem *uar_map;
414 u32 sqn;
415 struct device *pdev;
416 __be32 mkey_be;
417 u8 min_inline_mode;
418 unsigned long state;
419
420 /* control path */
421 struct mlx5_wq_ctrl wq_ctrl;
422 struct mlx5e_channel *channel;
423} ____cacheline_aligned_in_smp;
424
425struct mlx5e_icosq {
426 /* data path */
427
31391048
SM
428 /* dirtied @xmit */
429 u16 pc ____cacheline_aligned_in_smp;
31391048
SM
430
431 struct mlx5e_cq cq;
432
433 /* write@xmit, read@completion */
434 struct {
435 struct mlx5e_sq_wqe_info *ico_wqe;
436 } db;
437
438 /* read only */
439 struct mlx5_wq_cyc wq;
440 void __iomem *uar_map;
441 u32 sqn;
31391048
SM
442 unsigned long state;
443
444 /* control path */
445 struct mlx5_wq_ctrl wq_ctrl;
446 struct mlx5e_channel *channel;
eba2db2b
SM
447} ____cacheline_aligned_in_smp;
448
864b2d71
SM
449static inline bool
450mlx5e_wqc_has_room_for(struct mlx5_wq_cyc *wq, u16 cc, u16 pc, u16 n)
eba2db2b 451{
ddf385e3 452 return (mlx5_wq_cyc_ctr2ix(wq, cc - pc) >= n) || (cc == pc);
eba2db2b 453}
6cd392a0 454
461017cb
TT
455struct mlx5e_dma_info {
456 struct page *page;
457 dma_addr_t addr;
458};
459
accd5883
TT
460struct mlx5e_wqe_frag_info {
461 struct mlx5e_dma_info di;
462 u32 offset;
463};
464
eba2db2b 465struct mlx5e_umr_dma_info {
eba2db2b 466 struct mlx5e_dma_info dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
eba2db2b
SM
467};
468
469struct mlx5e_mpw_info {
470 struct mlx5e_umr_dma_info umr;
471 u16 consumed_strides;
22f45398 472 DECLARE_BITMAP(xdp_xmit_bitmap, MLX5_MPWRQ_PAGES_PER_WQE);
eba2db2b
SM
473};
474
4415a031
TT
475/* a single cache unit is capable to serve one napi call (for non-striding rq)
476 * or a MPWQE (for striding rq).
477 */
478#define MLX5E_CACHE_UNIT (MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
479 MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
29c2849e 480#define MLX5E_CACHE_SIZE (4 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
4415a031
TT
481struct mlx5e_page_cache {
482 u32 head;
483 u32 tail;
484 struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE];
485};
486
eba2db2b
SM
487struct mlx5e_rq;
488typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq*, struct mlx5_cqe64*);
619a8f2a
TT
489typedef struct sk_buff *
490(*mlx5e_fp_skb_from_cqe_mpwrq)(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
491 u16 cqe_bcnt, u32 head_offset, u32 page_idx);
7cc6d77b 492typedef bool (*mlx5e_fp_post_rx_wqes)(struct mlx5e_rq *rq);
eba2db2b
SM
493typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq*, u16);
494
121e8927
TT
495enum mlx5e_rq_flag {
496 MLX5E_RQ_FLAG_XDP_XMIT = BIT(0),
497};
498
f62b8bb8
AV
499struct mlx5e_rq {
500 /* data path */
501 struct mlx5_wq_ll wq;
1bfecfca 502
21c59685 503 union {
accd5883
TT
504 struct {
505 struct mlx5e_wqe_frag_info *frag_info;
506 u32 frag_sz; /* max possible skb frag_sz */
b45d8b50
TT
507 union {
508 bool page_reuse;
b45d8b50 509 };
accd5883 510 } wqe;
21c59685 511 struct {
b8a98a4c 512 struct mlx5e_umr_wqe umr_wqe;
21c59685 513 struct mlx5e_mpw_info *info;
619a8f2a 514 mlx5e_fp_skb_from_cqe_mpwrq skb_from_cqe_mpwrq;
b45d8b50 515 u16 num_strides;
89e89f7a 516 u8 log_stride_sz;
a071cb9f 517 bool umr_in_progress;
21c59685
SM
518 } mpwqe;
519 };
1bfecfca 520 struct {
b45d8b50 521 u16 headroom;
1bfecfca 522 u8 page_order;
b5503b99 523 u8 map_dir; /* dma map direction */
1bfecfca 524 } buff;
f62b8bb8 525
7cc6d77b 526 struct mlx5e_channel *channel;
f62b8bb8
AV
527 struct device *pdev;
528 struct net_device *netdev;
529 struct mlx5e_rq_stats stats;
530 struct mlx5e_cq cq;
4415a031 531 struct mlx5e_page_cache page_cache;
7c39afb3
FD
532 struct hwtstamp_config *tstamp;
533 struct mlx5_clock *clock;
4415a031 534
2f48af12 535 mlx5e_fp_handle_rx_cqe handle_rx_cqe;
7cc6d77b 536 mlx5e_fp_post_rx_wqes post_wqes;
6cd392a0 537 mlx5e_fp_dealloc_wqe dealloc_wqe;
f62b8bb8
AV
538
539 unsigned long state;
540 int ix;
541
9a317425 542 struct net_dim dim; /* Dynamic Interrupt Moderation */
31871f87
SM
543
544 /* XDP */
86994156 545 struct bpf_prog *xdp_prog;
472a1e44 546 unsigned int hw_mtu;
31391048 547 struct mlx5e_xdpsq xdpsq;
121e8927 548 DECLARE_BITMAP(flags, 8);
60bbf7ee 549 struct page_pool *page_pool;
cb3c7fd4 550
f62b8bb8
AV
551 /* control */
552 struct mlx5_wq_ctrl wq_ctrl;
b45d8b50 553 __be32 mkey_be;
461017cb 554 u8 wq_type;
f62b8bb8 555 u32 rqn;
a43b25da 556 struct mlx5_core_dev *mdev;
ec8b9981 557 struct mlx5_core_mkey umr_mkey;
0ddf5432
JDB
558
559 /* XDP read-mostly */
560 struct xdp_rxq_info xdp_rxq;
f62b8bb8
AV
561} ____cacheline_aligned_in_smp;
562
f62b8bb8
AV
563struct mlx5e_channel {
564 /* data path */
565 struct mlx5e_rq rq;
31391048
SM
566 struct mlx5e_txqsq sq[MLX5E_MAX_NUM_TC];
567 struct mlx5e_icosq icosq; /* internal control operations */
b5503b99 568 bool xdp;
f62b8bb8
AV
569 struct napi_struct napi;
570 struct device *pdev;
571 struct net_device *netdev;
572 __be32 mkey_be;
573 u8 num_tc;
f62b8bb8 574
a8c2eb15
TT
575 /* data path - accessed per napi poll */
576 struct irq_desc *irq_desc;
57d689a8 577 struct mlx5e_ch_stats stats;
f62b8bb8
AV
578
579 /* control */
580 struct mlx5e_priv *priv;
a43b25da 581 struct mlx5_core_dev *mdev;
7c39afb3 582 struct hwtstamp_config *tstamp;
f62b8bb8 583 int ix;
231243c8 584 int cpu;
f62b8bb8
AV
585};
586
ff9c852f
SM
587struct mlx5e_channels {
588 struct mlx5e_channel **c;
589 unsigned int num;
6a9764ef 590 struct mlx5e_params params;
ff9c852f
SM
591};
592
f62b8bb8 593enum mlx5e_traffic_types {
5a6f8aef
AS
594 MLX5E_TT_IPV4_TCP,
595 MLX5E_TT_IPV6_TCP,
596 MLX5E_TT_IPV4_UDP,
597 MLX5E_TT_IPV6_UDP,
a741749f
AS
598 MLX5E_TT_IPV4_IPSEC_AH,
599 MLX5E_TT_IPV6_IPSEC_AH,
600 MLX5E_TT_IPV4_IPSEC_ESP,
601 MLX5E_TT_IPV6_IPSEC_ESP,
5a6f8aef
AS
602 MLX5E_TT_IPV4,
603 MLX5E_TT_IPV6,
604 MLX5E_TT_ANY,
605 MLX5E_NUM_TT,
1da36696 606 MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
f62b8bb8
AV
607};
608
7b3722fa
GP
609enum mlx5e_tunnel_types {
610 MLX5E_TT_IPV4_GRE,
611 MLX5E_TT_IPV6_GRE,
612 MLX5E_NUM_TUNNEL_TT,
613};
614
acff797c 615enum {
e0f46eb9 616 MLX5E_STATE_ASYNC_EVENTS_ENABLED,
acff797c
MG
617 MLX5E_STATE_OPENED,
618 MLX5E_STATE_DESTROYING,
619};
620
621struct mlx5e_vxlan_db {
622 spinlock_t lock; /* protect vxlan table */
623 struct radix_tree_root tree;
624};
625
33cfaaa8 626struct mlx5e_l2_rule {
f62b8bb8 627 u8 addr[ETH_ALEN + 2];
74491de9 628 struct mlx5_flow_handle *rule;
f62b8bb8
AV
629};
630
acff797c
MG
631struct mlx5e_flow_table {
632 int num_groups;
633 struct mlx5_flow_table *t;
634 struct mlx5_flow_group **g;
635};
636
33cfaaa8 637#define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
f62b8bb8 638
acff797c
MG
639struct mlx5e_tc_table {
640 struct mlx5_flow_table *t;
641
acff797c 642 struct rhashtable ht;
11c9c548
OG
643
644 DECLARE_HASHTABLE(mod_hdr_tbl, 8);
5c65c564 645 DECLARE_HASHTABLE(hairpin_tbl, 8);
f62b8bb8
AV
646};
647
acff797c
MG
648struct mlx5e_vlan_table {
649 struct mlx5e_flow_table ft;
03eda954 650 DECLARE_BITMAP(active_cvlans, VLAN_N_VID);
7d92d580 651 DECLARE_BITMAP(active_svlans, VLAN_N_VID);
2b52a283 652 struct mlx5_flow_handle *active_cvlans_rule[VLAN_N_VID];
7d92d580 653 struct mlx5_flow_handle *active_svlans_rule[VLAN_N_VID];
74491de9 654 struct mlx5_flow_handle *untagged_rule;
8a271746
MHY
655 struct mlx5_flow_handle *any_cvlan_rule;
656 struct mlx5_flow_handle *any_svlan_rule;
2b52a283 657 bool cvlan_filter_disabled;
f62b8bb8
AV
658};
659
33cfaaa8
MG
660struct mlx5e_l2_table {
661 struct mlx5e_flow_table ft;
662 struct hlist_head netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
663 struct hlist_head netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
664 struct mlx5e_l2_rule broadcast;
665 struct mlx5e_l2_rule allmulti;
666 struct mlx5e_l2_rule promisc;
667 bool broadcast_enabled;
668 bool allmulti_enabled;
669 bool promisc_enabled;
670};
671
672/* L3/L4 traffic type classifier */
673struct mlx5e_ttc_table {
674 struct mlx5e_flow_table ft;
74491de9 675 struct mlx5_flow_handle *rules[MLX5E_NUM_TT];
7b3722fa 676 struct mlx5_flow_handle *tunnel_rules[MLX5E_NUM_TUNNEL_TT];
33cfaaa8
MG
677};
678
18c908e4
MG
679#define ARFS_HASH_SHIFT BITS_PER_BYTE
680#define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
1cabe6b0
MG
681struct arfs_table {
682 struct mlx5e_flow_table ft;
74491de9 683 struct mlx5_flow_handle *default_rule;
18c908e4 684 struct hlist_head rules_hash[ARFS_HASH_SIZE];
1cabe6b0
MG
685};
686
687enum arfs_type {
688 ARFS_IPV4_TCP,
689 ARFS_IPV6_TCP,
690 ARFS_IPV4_UDP,
691 ARFS_IPV6_UDP,
692 ARFS_NUM_TYPES,
693};
694
695struct mlx5e_arfs_tables {
696 struct arfs_table arfs_tables[ARFS_NUM_TYPES];
18c908e4
MG
697 /* Protect aRFS rules list */
698 spinlock_t arfs_lock;
699 struct list_head rules;
700 int last_filter_id;
701 struct workqueue_struct *wq;
1cabe6b0
MG
702};
703
704/* NIC prio FTS */
705enum {
706 MLX5E_VLAN_FT_LEVEL = 0,
707 MLX5E_L2_FT_LEVEL,
708 MLX5E_TTC_FT_LEVEL,
7b3722fa 709 MLX5E_INNER_TTC_FT_LEVEL,
1cabe6b0
MG
710 MLX5E_ARFS_FT_LEVEL
711};
712
3f6d08d1
OG
713enum {
714 MLX5E_TC_FT_LEVEL = 0,
715 MLX5E_TC_TTC_FT_LEVEL,
716};
717
6dc6071c
MG
718struct mlx5e_ethtool_table {
719 struct mlx5_flow_table *ft;
720 int num_rules;
721};
722
1174fce8 723#define ETHTOOL_NUM_L3_L4_FTS 7
6dc6071c
MG
724#define ETHTOOL_NUM_L2_FTS 4
725
726struct mlx5e_ethtool_steering {
1174fce8 727 struct mlx5e_ethtool_table l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
6dc6071c
MG
728 struct mlx5e_ethtool_table l2_ft[ETHTOOL_NUM_L2_FTS];
729 struct list_head rules;
730 int tot_num_rules;
731};
732
acff797c
MG
733struct mlx5e_flow_steering {
734 struct mlx5_flow_namespace *ns;
6dc6071c 735 struct mlx5e_ethtool_steering ethtool;
acff797c
MG
736 struct mlx5e_tc_table tc;
737 struct mlx5e_vlan_table vlan;
33cfaaa8
MG
738 struct mlx5e_l2_table l2;
739 struct mlx5e_ttc_table ttc;
7b3722fa 740 struct mlx5e_ttc_table inner_ttc;
1cabe6b0 741 struct mlx5e_arfs_tables arfs;
f62b8bb8
AV
742};
743
398f3351 744struct mlx5e_rqt {
1da36696 745 u32 rqtn;
398f3351
HHZ
746 bool enabled;
747};
748
749struct mlx5e_tir {
750 u32 tirn;
751 struct mlx5e_rqt rqt;
752 struct list_head list;
1da36696
TT
753};
754
acff797c
MG
755enum {
756 MLX5E_TC_PRIO = 0,
757 MLX5E_NIC_PRIO
758};
759
f62b8bb8
AV
760struct mlx5e_priv {
761 /* priv data path fields - start */
acc6c595
SM
762 struct mlx5e_txqsq *txq2sq[MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC];
763 int channel_tc2txq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
2a5e7a13
HN
764#ifdef CONFIG_MLX5_CORE_EN_DCB
765 struct mlx5e_dcbx_dp dcbx_dp;
766#endif
f62b8bb8
AV
767 /* priv data path fields - end */
768
79c48764 769 u32 msglevel;
f62b8bb8
AV
770 unsigned long state;
771 struct mutex state_lock; /* Protects Interface state */
50cfa25a 772 struct mlx5e_rq drop_rq;
f62b8bb8 773
ff9c852f 774 struct mlx5e_channels channels;
f62b8bb8 775 u32 tisn[MLX5E_MAX_NUM_TC];
398f3351 776 struct mlx5e_rqt indir_rqt;
724b2aa1 777 struct mlx5e_tir indir_tir[MLX5E_NUM_INDIR_TIRS];
7b3722fa 778 struct mlx5e_tir inner_indir_tir[MLX5E_NUM_INDIR_TIRS];
724b2aa1 779 struct mlx5e_tir direct_tir[MLX5E_MAX_NUM_CHANNELS];
507f0c81 780 u32 tx_rates[MLX5E_MAX_NUM_SQS];
f62b8bb8 781
acff797c 782 struct mlx5e_flow_steering fs;
b3f63c3d 783 struct mlx5e_vxlan_db vxlan;
f62b8bb8 784
7bb29755 785 struct workqueue_struct *wq;
f62b8bb8
AV
786 struct work_struct update_carrier_work;
787 struct work_struct set_rx_mode_work;
3947ca18 788 struct work_struct tx_timeout_work;
f62b8bb8
AV
789 struct delayed_work update_stats_work;
790
791 struct mlx5_core_dev *mdev;
792 struct net_device *netdev;
793 struct mlx5e_stats stats;
7c39afb3 794 struct hwtstamp_config tstamp;
7cbaf9a3
MS
795 u16 q_counter;
796 u16 drop_rq_q_counter;
3a6a931d
HN
797#ifdef CONFIG_MLX5_CORE_EN_DCB
798 struct mlx5e_dcbx dcbx;
799#endif
800
6bfd390b 801 const struct mlx5e_profile *profile;
127ea380 802 void *ppriv;
547eede0
IT
803#ifdef CONFIG_MLX5_EN_IPSEC
804 struct mlx5e_ipsec *ipsec;
805#endif
43585a41
IL
806#ifdef CONFIG_MLX5_EN_TLS
807 struct mlx5e_tls *tls;
808#endif
f62b8bb8
AV
809};
810
a43b25da
SM
811struct mlx5e_profile {
812 void (*init)(struct mlx5_core_dev *mdev,
813 struct net_device *netdev,
814 const struct mlx5e_profile *profile, void *ppriv);
815 void (*cleanup)(struct mlx5e_priv *priv);
816 int (*init_rx)(struct mlx5e_priv *priv);
817 void (*cleanup_rx)(struct mlx5e_priv *priv);
818 int (*init_tx)(struct mlx5e_priv *priv);
819 void (*cleanup_tx)(struct mlx5e_priv *priv);
820 void (*enable)(struct mlx5e_priv *priv);
821 void (*disable)(struct mlx5e_priv *priv);
822 void (*update_stats)(struct mlx5e_priv *priv);
7ca42c80 823 void (*update_carrier)(struct mlx5e_priv *priv);
a43b25da 824 int (*max_nch)(struct mlx5_core_dev *mdev);
20fd0c19
SM
825 struct {
826 mlx5e_fp_handle_rx_cqe handle_rx_cqe;
827 mlx5e_fp_handle_rx_cqe handle_rx_cqe_mpwqe;
828 } rx_handlers;
2a5e7a13
HN
829 void (*netdev_registered_init)(struct mlx5e_priv *priv);
830 void (*netdev_registered_remove)(struct mlx5e_priv *priv);
a43b25da
SM
831 int max_tc;
832};
833
665bc539
GP
834void mlx5e_build_ptys2ethtool_map(void);
835
f62b8bb8
AV
836u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
837 void *accel_priv, select_queue_fallback_t fallback);
838netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
bf239741
IL
839netdev_tx_t mlx5e_sq_xmit(struct mlx5e_txqsq *sq, struct sk_buff *skb,
840 struct mlx5e_tx_wqe *wqe, u16 pi);
f62b8bb8
AV
841
842void mlx5e_completion_event(struct mlx5_core_cq *mcq);
843void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
844int mlx5e_napi_poll(struct napi_struct *napi, int budget);
8ec736e5 845bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
44fb6fbb 846int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
1c4bf940 847bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq);
31391048
SM
848void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
849void mlx5e_free_xdpsq_descs(struct mlx5e_xdpsq *sq);
461017cb 850
2ccb0a79
TT
851bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev);
852bool mlx5e_striding_rq_possible(struct mlx5_core_dev *mdev,
853 struct mlx5e_params *params);
854
4415a031
TT
855void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
856 bool recycle);
2f48af12 857void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
461017cb 858void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
f62b8bb8 859bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
7cc6d77b 860bool mlx5e_post_rx_mpwqes(struct mlx5e_rq *rq);
6cd392a0
DJ
861void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
862void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
7e426671 863void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
619a8f2a
TT
864struct sk_buff *
865mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
866 u16 cqe_bcnt, u32 head_offset, u32 page_idx);
867struct sk_buff *
868mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
869 u16 cqe_bcnt, u32 head_offset, u32 page_idx);
f62b8bb8 870
19386177 871void mlx5e_update_stats(struct mlx5e_priv *priv);
f62b8bb8 872
acff797c
MG
873int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
874void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
33cfaaa8 875void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
1cabe6b0 876void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
d605d668
KH
877int mlx5e_self_test_num(struct mlx5e_priv *priv);
878void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
879 u64 *buf);
f913a72a
MG
880int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
881 int location);
882int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
883 struct ethtool_rxnfc *info, u32 *rule_locs);
6dc6071c
MG
884int mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
885 struct ethtool_rx_flow_spec *fs);
886int mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv,
887 int location);
888void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
889void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
f62b8bb8
AV
890void mlx5e_set_rx_mode_work(struct work_struct *work);
891
1170fbd8
FD
892int mlx5e_hwstamp_set(struct mlx5e_priv *priv, struct ifreq *ifr);
893int mlx5e_hwstamp_get(struct mlx5e_priv *priv, struct ifreq *ifr);
be7e87f9 894int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool val);
ef9814de 895
f62b8bb8
AV
896int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
897 u16 vid);
898int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
899 u16 vid);
2b52a283
GP
900void mlx5e_enable_cvlan_filter(struct mlx5e_priv *priv);
901void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
237f258c 902void mlx5e_timestamp_init(struct mlx5e_priv *priv);
f62b8bb8 903
a5f97fee
SM
904struct mlx5e_redirect_rqt_param {
905 bool is_rss;
906 union {
907 u32 rqn; /* Direct RQN (Non-RSS) */
908 struct {
909 u8 hfunc;
910 struct mlx5e_channels *channels;
911 } rss; /* RSS data */
912 };
913};
914
915int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz,
916 struct mlx5e_redirect_rqt_param rrp);
6a9764ef
SM
917void mlx5e_build_indir_tir_ctx_hash(struct mlx5e_params *params,
918 enum mlx5e_traffic_types tt,
7b3722fa 919 void *tirc, bool inner);
2d75b2bc 920
f62b8bb8
AV
921int mlx5e_open_locked(struct net_device *netdev);
922int mlx5e_close_locked(struct net_device *netdev);
55c2503d
SM
923
924int mlx5e_open_channels(struct mlx5e_priv *priv,
925 struct mlx5e_channels *chs);
926void mlx5e_close_channels(struct mlx5e_channels *chs);
2e20a151
SM
927
928/* Function pointer to be used to modify WH settings while
929 * switching channels
930 */
931typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv);
55c2503d 932void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
2e20a151
SM
933 struct mlx5e_channels *new_chs,
934 mlx5e_fp_hw_modify hw_modify);
603f4a45
SM
935void mlx5e_activate_priv_channels(struct mlx5e_priv *priv);
936void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);
55c2503d 937
d4b6c488 938void mlx5e_build_default_indir_rqt(u32 *indirection_rqt, int len,
85082dba 939 int num_channels);
0088cbbc
TG
940void mlx5e_set_tx_cq_mode_params(struct mlx5e_params *params,
941 u8 cq_period_mode);
9908aa29
TT
942void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
943 u8 cq_period_mode);
2ccb0a79 944void mlx5e_set_rq_type(struct mlx5_core_dev *mdev, struct mlx5e_params *params);
696a97cf 945void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev,
2a0f561b 946 struct mlx5e_params *params);
9908aa29 947
7b3722fa
GP
948static inline bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev)
949{
950 return (MLX5_CAP_ETH(mdev, tunnel_stateless_gre) &&
951 MLX5_CAP_FLOWTABLE_NIC_RX(mdev, ft_field_support.inner_ip_version));
952}
953
bf239741
IL
954static inline void mlx5e_sq_fetch_wqe(struct mlx5e_txqsq *sq,
955 struct mlx5e_tx_wqe **wqe,
956 u16 *pi)
957{
ddf385e3 958 struct mlx5_wq_cyc *wq = &sq->wq;
bf239741 959
ddf385e3 960 *pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
bf239741
IL
961 *wqe = mlx5_wq_cyc_get_wqe(wq, *pi);
962 memset(*wqe, 0, sizeof(**wqe));
963}
964
864b2d71
SM
965static inline
966struct mlx5e_tx_wqe *mlx5e_post_nop(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
f62b8bb8 967{
ddf385e3 968 u16 pi = mlx5_wq_cyc_ctr2ix(wq, *pc);
864b2d71
SM
969 struct mlx5e_tx_wqe *wqe = mlx5_wq_cyc_get_wqe(wq, pi);
970 struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl;
971
972 memset(cseg, 0, sizeof(*cseg));
973
974 cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
975 cseg->qpn_ds = cpu_to_be32((sqn << 8) | 0x01);
976
977 (*pc)++;
978
979 return wqe;
980}
981
982static inline
983void mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc,
984 void __iomem *uar_map,
985 struct mlx5_wqe_ctrl_seg *ctrl)
986{
987 ctrl->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
f62b8bb8
AV
988 /* ensure wqe is visible to device before updating doorbell record */
989 dma_wmb();
990
864b2d71 991 *wq->db = cpu_to_be32(pc);
f62b8bb8
AV
992
993 /* ensure doorbell record is visible to device before ringing the
994 * doorbell
995 */
996 wmb();
f62b8bb8 997
864b2d71 998 mlx5_write64((__be32 *)ctrl, uar_map, NULL);
f62b8bb8
AV
999}
1000
1001static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
1002{
1003 struct mlx5_core_cq *mcq;
1004
1005 mcq = &cq->mcq;
5fe9dec0 1006 mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
f62b8bb8
AV
1007}
1008
1009extern const struct ethtool_ops mlx5e_ethtool_ops;
08fb1dac
SM
1010#ifdef CONFIG_MLX5_CORE_EN_DCB
1011extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
1012int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
e207b7e9 1013void mlx5e_dcbnl_initialize(struct mlx5e_priv *priv);
2a5e7a13
HN
1014void mlx5e_dcbnl_init_app(struct mlx5e_priv *priv);
1015void mlx5e_dcbnl_delete_app(struct mlx5e_priv *priv);
08fb1dac
SM
1016#endif
1017
1cabe6b0
MG
1018#ifndef CONFIG_RFS_ACCEL
1019static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
1020{
1021 return 0;
1022}
1023
1024static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
45bf454a
MG
1025
1026static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
1027{
9eb78923 1028 return -EOPNOTSUPP;
45bf454a
MG
1029}
1030
1031static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
1032{
9eb78923 1033 return -EOPNOTSUPP;
45bf454a 1034}
1cabe6b0
MG
1035#else
1036int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
1037void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
45bf454a
MG
1038int mlx5e_arfs_enable(struct mlx5e_priv *priv);
1039int mlx5e_arfs_disable(struct mlx5e_priv *priv);
18c908e4
MG
1040int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1041 u16 rxq_index, u32 flow_id);
1cabe6b0
MG
1042#endif
1043
724b2aa1
HHZ
1044int mlx5e_create_tir(struct mlx5_core_dev *mdev,
1045 struct mlx5e_tir *tir, u32 *in, int inlen);
1046void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
1047 struct mlx5e_tir *tir);
b50d292b
HHZ
1048int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
1049void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
b676f653 1050int mlx5e_refresh_tirs(struct mlx5e_priv *priv, bool enable_uc_lb);
1afff42c 1051
bc81b9d3 1052/* common netdev helpers */
8f493ffd
SM
1053int mlx5e_create_indirect_rqt(struct mlx5e_priv *priv);
1054
1055int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv);
1056void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv);
1057
cb67b832 1058int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
8f493ffd 1059void mlx5e_destroy_direct_rqts(struct mlx5e_priv *priv);
cb67b832
HHZ
1060int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
1061void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
8f493ffd
SM
1062void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
1063
1ae1df3a
OG
1064struct ttc_params {
1065 struct mlx5_flow_table_attr ft_attr;
1066 u32 any_tt_tirn;
1067 u32 indir_tirn[MLX5E_NUM_INDIR_TIRS];
1068 struct mlx5e_ttc_table *inner_ttc;
1069};
1070
1071void mlx5e_set_ttc_basic_params(struct mlx5e_priv *priv, struct ttc_params *ttc_params);
1072void mlx5e_set_ttc_ft_params(struct ttc_params *ttc_params);
1073void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params);
1074
1075int mlx5e_create_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
1076 struct mlx5e_ttc_table *ttc);
1077void mlx5e_destroy_ttc_table(struct mlx5e_priv *priv,
1078 struct mlx5e_ttc_table *ttc);
bc81b9d3 1079
1ae1df3a
OG
1080int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
1081 struct mlx5e_ttc_table *ttc);
1082void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
1083 struct mlx5e_ttc_table *ttc);
458821c7 1084
5426a0b2
SM
1085int mlx5e_create_tis(struct mlx5_core_dev *mdev, int tc,
1086 u32 underlay_qpn, u32 *tisn);
1087void mlx5e_destroy_tis(struct mlx5_core_dev *mdev, u32 tisn);
1088
cb67b832
HHZ
1089int mlx5e_create_tises(struct mlx5e_priv *priv);
1090void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
1091int mlx5e_close(struct net_device *netdev);
1092int mlx5e_open(struct net_device *netdev);
1093void mlx5e_update_stats_work(struct work_struct *work);
cb67b832 1094
3f6d08d1
OG
1095int mlx5e_bits_invert(unsigned long a, int size);
1096
076b0936
ES
1097/* ethtool helpers */
1098void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
1099 struct ethtool_drvinfo *drvinfo);
1100void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv,
1101 uint32_t stringset, uint8_t *data);
1102int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset);
1103void mlx5e_ethtool_get_ethtool_stats(struct mlx5e_priv *priv,
1104 struct ethtool_stats *stats, u64 *data);
1105void mlx5e_ethtool_get_ringparam(struct mlx5e_priv *priv,
1106 struct ethtool_ringparam *param);
1107int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
1108 struct ethtool_ringparam *param);
1109void mlx5e_ethtool_get_channels(struct mlx5e_priv *priv,
1110 struct ethtool_channels *ch);
1111int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
1112 struct ethtool_channels *ch);
1113int mlx5e_ethtool_get_coalesce(struct mlx5e_priv *priv,
1114 struct ethtool_coalesce *coal);
1115int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
1116 struct ethtool_coalesce *coal);
3844b07e
FD
1117int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv,
1118 struct ethtool_ts_info *info);
3ffaabec
OG
1119int mlx5e_ethtool_flash_device(struct mlx5e_priv *priv,
1120 struct ethtool_flash *flash);
076b0936 1121
2c3b5bee
SM
1122/* mlx5e generic netdev management API */
1123struct net_device*
1124mlx5e_create_netdev(struct mlx5_core_dev *mdev, const struct mlx5e_profile *profile,
1125 void *ppriv);
1126int mlx5e_attach_netdev(struct mlx5e_priv *priv);
1127void mlx5e_detach_netdev(struct mlx5e_priv *priv);
1128void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
8f493ffd
SM
1129void mlx5e_build_nic_params(struct mlx5_core_dev *mdev,
1130 struct mlx5e_params *params,
472a1e44 1131 u16 max_channels, u16 mtu);
fbcb127e 1132u8 mlx5e_params_calculate_tx_min_inline(struct mlx5_core_dev *mdev);
9a317425 1133void mlx5e_rx_dim_work(struct work_struct *work);
cbce4f44 1134void mlx5e_tx_dim_work(struct work_struct *work);
1afff42c 1135#endif /* __MLX5_EN_H__ */