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