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