en.h 28.0 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
32 33
#ifndef __MLX5_EN_H__
#define __MLX5_EN_H__
34 35 36

#include <linux/if_vlan.h>
#include <linux/etherdevice.h>
37 38
#include <linux/timecounter.h>
#include <linux/net_tstamp.h>
39
#include <linux/ptp_clock_kernel.h>
40 41 42
#include <linux/mlx5/driver.h>
#include <linux/mlx5/qp.h>
#include <linux/mlx5/cq.h>
43
#include <linux/mlx5/port.h>
44
#include <linux/mlx5/vport.h>
45
#include <linux/mlx5/transobj.h>
46
#include <linux/rhashtable.h>
47
#include <net/switchdev.h>
48 49
#include "wq.h"
#include "mlx5_core.h"
50
#include "en_stats.h"
51

52 53
#define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)

54 55 56
#define MLX5E_HW2SW_MTU(hwmtu) ((hwmtu) - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))
#define MLX5E_SW2HW_MTU(swmtu) ((swmtu) + (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN))

57 58
#define MLX5E_MAX_NUM_TC	8

59
#define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE                0x6
60 61 62
#define MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE                0xa
#define MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE                0xd

63
#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE                0x1
64 65 66
#define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE                0xa
#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE                0xd

67
#define MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW            0x1
68
#define MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE_MPW            0x3
69 70
#define MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW            0x6

71 72
#define MLX5_RX_HEADROOM NET_SKB_PAD

73 74 75 76 77 78 79
#define MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev) \
	(6 + MLX5_CAP_GEN(mdev, cache_line_128byte)) /* HW restriction */
#define MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, req) \
	max_t(u32, MLX5_MPWRQ_MIN_LOG_STRIDE_SZ(mdev), req)
#define MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev)       MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 6)
#define MLX5_MPWRQ_CQE_CMPRS_LOG_STRIDE_SZ(mdev) MLX5_MPWRQ_LOG_STRIDE_SZ(mdev, 8)

80
#define MLX5_MPWRQ_LOG_WQE_SZ			18
81 82 83 84 85
#define MLX5_MPWRQ_WQE_PAGE_ORDER  (MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT > 0 ? \
				    MLX5_MPWRQ_LOG_WQE_SZ - PAGE_SHIFT : 0)
#define MLX5_MPWRQ_PAGES_PER_WQE		BIT(MLX5_MPWRQ_WQE_PAGE_ORDER)
#define MLX5_MPWRQ_STRIDES_PER_PAGE		(MLX5_MPWRQ_NUM_STRIDES >> \
						 MLX5_MPWRQ_WQE_PAGE_ORDER)
86 87

#define MLX5_MTT_OCTW(npages) (ALIGN(npages, 8) / 2)
T
Tariq Toukan 已提交
88 89 90
#define MLX5E_REQUIRED_MTTS(wqes)		\
	(wqes * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8))
#define MLX5E_VALID_NUM_MTTS(num_mtts) (MLX5_MTT_OCTW(num_mtts) - 1 <= U16_MAX)
91

92
#define MLX5_UMR_ALIGN				(2048)
93
#define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD	(256)
94

A
Achiad Shochat 已提交
95
#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ                 (64 * 1024)
96 97 98
#define MLX5E_DEFAULT_LRO_TIMEOUT                       32
#define MLX5E_LRO_TIMEOUT_ARR_SIZE                      4

99
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC      0x10
T
Tariq Toukan 已提交
100
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
101 102 103 104
#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS      0x20
#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_USEC      0x10
#define MLX5E_PARAMS_DEFAULT_TX_CQ_MODERATION_PKTS      0x20
#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES                0x80
105
#define MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW            0x2
106

107 108
#define MLX5E_LOG_INDIR_RQT_SIZE       0x7
#define MLX5E_INDIR_RQT_SIZE           BIT(MLX5E_LOG_INDIR_RQT_SIZE)
109
#define MLX5E_MIN_NUM_CHANNELS         0x1
110
#define MLX5E_MAX_NUM_CHANNELS         (MLX5E_INDIR_RQT_SIZE >> 1)
111
#define MLX5E_MAX_NUM_SQS              (MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC)
112 113
#define MLX5E_TX_CQ_POLL_BUDGET        128
#define MLX5E_UPDATE_STATS_INTERVAL    200 /* msecs */
114
#define MLX5E_SQ_BF_BUDGET             16
115

116 117 118
#define MLX5E_ICOSQ_MAX_WQEBBS \
	(DIV_ROUND_UP(sizeof(struct mlx5e_umr_wqe), MLX5_SEND_WQE_BB))

119 120 121 122
#define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)
#define MLX5E_XDP_IHS_DS_COUNT \
	DIV_ROUND_UP(MLX5E_XDP_MIN_INLINE - 2, MLX5_SEND_WQE_DS)
#define MLX5E_XDP_TX_DS_COUNT \
123
	((sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) + 1 /* SG DS */)
124 125 126
#define MLX5E_XDP_TX_WQEBBS \
	DIV_ROUND_UP(MLX5E_XDP_TX_DS_COUNT, MLX5_SEND_WQEBB_NUM_DS)

127
#define MLX5E_NUM_MAIN_GROUPS 9
128

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
static inline u16 mlx5_min_rx_wqes(int wq_type, u32 wq_size)
{
	switch (wq_type) {
	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
		return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES_MPW,
			     wq_size / 2);
	default:
		return min_t(u16, MLX5E_PARAMS_DEFAULT_MIN_RX_WQES,
			     wq_size / 2);
	}
}

static inline int mlx5_min_log_rq_size(int wq_type)
{
	switch (wq_type) {
	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
		return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
	default:
		return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE;
	}
}

static inline int mlx5_max_log_rq_size(int wq_type)
{
	switch (wq_type) {
	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
		return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE_MPW;
	default:
		return MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE;
	}
}

161 162 163 164 165 166 167 168 169
struct mlx5e_tx_wqe {
	struct mlx5_wqe_ctrl_seg ctrl;
	struct mlx5_wqe_eth_seg  eth;
};

struct mlx5e_rx_wqe {
	struct mlx5_wqe_srq_next_seg  next;
	struct mlx5_wqe_data_seg      data;
};
170

171 172 173 174 175 176 177
struct mlx5e_umr_wqe {
	struct mlx5_wqe_ctrl_seg       ctrl;
	struct mlx5_wqe_umr_ctrl_seg   uctrl;
	struct mlx5_mkey_seg           mkc;
	struct mlx5_wqe_data_seg       data;
};

178 179
extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];

180
static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
T
Tariq Toukan 已提交
181
	"rx_cqe_moder",
182
	"rx_cqe_compress",
183 184 185
};

enum mlx5e_priv_flag {
T
Tariq Toukan 已提交
186
	MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
187
	MLX5E_PFLAG_RX_CQE_COMPRESS = (1 << 1),
188 189
};

190 191 192 193 194 195
#define MLX5E_SET_PFLAG(priv, pflag, enable)			\
	do {							\
		if (enable)					\
			(priv)->params.pflags |= (pflag);	\
		else						\
			(priv)->params.pflags &= ~(pflag);	\
196 197
	} while (0)

198 199
#define MLX5E_GET_PFLAG(priv, pflag) (!!((priv)->params.pflags & (pflag)))

200 201 202 203
#ifdef CONFIG_MLX5_CORE_EN_DCB
#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
#endif

T
Tariq Toukan 已提交
204 205 206 207 208
struct mlx5e_cq_moder {
	u16 usec;
	u16 pkts;
};

209 210
struct mlx5e_params {
	u8  log_sq_size;
211
	u8  rq_wq_type;
212 213
	u8  mpwqe_log_stride_sz;
	u8  mpwqe_log_num_strides;
214 215 216
	u8  log_rq_size;
	u16 num_channels;
	u8  num_tc;
T
Tariq Toukan 已提交
217
	u8  rx_cq_period_mode;
218
	bool rx_cqe_compress_def;
T
Tariq Toukan 已提交
219 220
	struct mlx5e_cq_moder rx_cq_moderation;
	struct mlx5e_cq_moder tx_cq_moderation;
221 222 223
	u16 min_rx_wqes;
	bool lro_en;
	u32 lro_wqe_sz;
224
	u16 tx_max_inline;
225
	u8  tx_min_inline_mode;
226 227 228
	u8  rss_hfunc;
	u8  toeplitz_hash_key[40];
	u32 indirection_rqt[MLX5E_INDIR_RQT_SIZE];
229
	bool vlan_strip_disable;
230
	bool rx_am_enabled;
231
	u32 lro_timeout;
232
	u32 pflags;
233 234
};

H
Huy Nguyen 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
#ifdef CONFIG_MLX5_CORE_EN_DCB
struct mlx5e_cee_config {
	/* bw pct for priority group */
	u8                         pg_bw_pct[CEE_DCBX_MAX_PGS];
	u8                         prio_to_pg_map[CEE_DCBX_MAX_PRIO];
	bool                       pfc_setting[CEE_DCBX_MAX_PRIO];
	bool                       pfc_enable;
};

enum {
	MLX5_DCB_CHG_RESET,
	MLX5_DCB_NO_CHG,
	MLX5_DCB_CHG_NO_RESET,
};

struct mlx5e_dcbx {
251
	enum mlx5_dcbx_oper_mode   mode;
H
Huy Nguyen 已提交
252
	struct mlx5e_cee_config    cee_cfg; /* pending configuration */
253 254 255

	/* The only setting that cannot be read from FW */
	u8                         tc_tsa[IEEE_8021QAZ_MAX_TCS];
H
Huy Nguyen 已提交
256 257 258
};
#endif

259 260 261 262 263 264 265 266 267
struct mlx5e_tstamp {
	rwlock_t                   lock;
	struct cyclecounter        cycles;
	struct timecounter         clock;
	struct hwtstamp_config     hwtstamp_config;
	u32                        nominal_c_mult;
	unsigned long              overflow_period;
	struct delayed_work        overflow_work;
	struct mlx5_core_dev      *mdev;
268 269
	struct ptp_clock          *ptp;
	struct ptp_clock_info      ptp_info;
270
	u8                        *pps_pin_caps;
271 272
};

273
enum {
274
	MLX5E_RQ_STATE_ENABLED,
275
	MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
276
	MLX5E_RQ_STATE_AM,
277 278 279 280 281 282 283
};

struct mlx5e_cq {
	/* data path - accessed per cqe */
	struct mlx5_cqwq           wq;

	/* data path - accessed per napi poll */
284
	u16                        event_ctr;
285 286 287
	struct napi_struct        *napi;
	struct mlx5_core_cq        mcq;
	struct mlx5e_channel      *channel;
288
	struct mlx5e_priv         *priv;
289

T
Tariq Toukan 已提交
290 291 292 293 294 295 296
	/* cqe decompression */
	struct mlx5_cqe64          title;
	struct mlx5_mini_cqe8      mini_arr[MLX5_MINI_CQE_ARRAY_SIZE];
	u8                         mini_arr_idx;
	u16                        decmprs_left;
	u16                        decmprs_wqe_counter;

297
	/* control */
298
	struct mlx5_frag_wq_ctrl   wq_ctrl;
299 300
} ____cacheline_aligned_in_smp;

301 302 303 304 305 306
struct mlx5e_rq;
typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq *rq,
				       struct mlx5_cqe64 *cqe);
typedef int (*mlx5e_fp_alloc_wqe)(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe,
				  u16 ix);

307 308
typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq *rq, u16 ix);

309 310 311 312 313
struct mlx5e_dma_info {
	struct page	*page;
	dma_addr_t	addr;
};

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
struct mlx5e_rx_am_stats {
	int ppms; /* packets per msec */
	int epms; /* events per msec */
};

struct mlx5e_rx_am_sample {
	ktime_t		time;
	unsigned int	pkt_ctr;
	u16		event_ctr;
};

struct mlx5e_rx_am { /* Adaptive Moderation */
	u8					state;
	struct mlx5e_rx_am_stats		prev_stats;
	struct mlx5e_rx_am_sample		start_sample;
	struct work_struct			work;
	u8					profile_ix;
	u8					mode;
	u8					tune_state;
	u8					steps_right;
	u8					steps_left;
	u8					tired;
};

338 339 340 341 342 343 344 345 346 347 348 349
/* a single cache unit is capable to serve one napi call (for non-striding rq)
 * or a MPWQE (for striding rq).
 */
#define MLX5E_CACHE_UNIT	(MLX5_MPWRQ_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
				 MLX5_MPWRQ_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
#define MLX5E_CACHE_SIZE	(2 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
struct mlx5e_page_cache {
	u32 head;
	u32 tail;
	struct mlx5e_dma_info page_cache[MLX5E_CACHE_SIZE];
};

350 351 352
struct mlx5e_rq {
	/* data path */
	struct mlx5_wq_ll      wq;
353

354 355 356 357 358 359 360
	union {
		struct mlx5e_dma_info *dma_info;
		struct {
			struct mlx5e_mpw_info *info;
			void                  *mtt_no_align;
		} mpwqe;
	};
361 362 363
	struct {
		u8             page_order;
		u32            wqe_sz;    /* wqe data buffer size */
364
		u8             map_dir;   /* dma map direction */
365
	} buff;
366
	__be32                 mkey_be;
367 368 369

	struct device         *pdev;
	struct net_device     *netdev;
370
	struct mlx5e_tstamp   *tstamp;
371 372
	struct mlx5e_rq_stats  stats;
	struct mlx5e_cq        cq;
373 374
	struct mlx5e_page_cache page_cache;

375 376
	mlx5e_fp_handle_rx_cqe handle_rx_cqe;
	mlx5e_fp_alloc_wqe     alloc_wqe;
377
	mlx5e_fp_dealloc_wqe   dealloc_wqe;
378 379 380

	unsigned long          state;
	int                    ix;
381
	u16                    rx_headroom;
382

383
	struct mlx5e_rx_am     am; /* Adaptive Moderation */
384
	struct bpf_prog       *xdp_prog;
385

386 387
	/* control */
	struct mlx5_wq_ctrl    wq_ctrl;
388
	u8                     wq_type;
389 390
	u32                    mpwqe_stride_sz;
	u32                    mpwqe_num_strides;
391 392
	u32                    rqn;
	struct mlx5e_channel  *channel;
393
	struct mlx5e_priv     *priv;
T
Tariq Toukan 已提交
394
	struct mlx5_core_mkey  umr_mkey;
395 396
} ____cacheline_aligned_in_smp;

397 398 399
struct mlx5e_umr_dma_info {
	__be64                *mtt;
	dma_addr_t             mtt_addr;
400 401
	struct mlx5e_dma_info  dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
	struct mlx5e_umr_wqe   wqe;
402 403 404
};

struct mlx5e_mpw_info {
405
	struct mlx5e_umr_dma_info umr;
406 407 408 409
	u16 consumed_strides;
	u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
};

410
struct mlx5e_tx_wqe_info {
411 412 413 414 415
	u32 num_bytes;
	u8  num_wqebbs;
	u8  num_dma;
};

416 417 418 419 420
enum mlx5e_dma_map_type {
	MLX5E_DMA_MAP_SINGLE,
	MLX5E_DMA_MAP_PAGE
};

421
struct mlx5e_sq_dma {
422 423 424
	dma_addr_t              addr;
	u32                     size;
	enum mlx5e_dma_map_type type;
425 426 427
};

enum {
428
	MLX5E_SQ_STATE_ENABLED,
M
Moshe Lazer 已提交
429
	MLX5E_SQ_STATE_BF_ENABLE,
430 431
};

432
struct mlx5e_sq_wqe_info {
T
Tariq Toukan 已提交
433 434 435 436
	u8  opcode;
	u8  num_wqebbs;
};

437 438
enum mlx5e_sq_type {
	MLX5E_SQ_TXQ,
439 440
	MLX5E_SQ_ICO,
	MLX5E_SQ_XDP
441 442
};

443 444 445 446 447 448 449 450 451 452
struct mlx5e_sq {
	/* data path */

	/* dirtied @completion */
	u16                        cc;
	u32                        dma_fifo_cc;

	/* dirtied @xmit */
	u16                        pc ____cacheline_aligned_in_smp;
	u32                        dma_fifo_pc;
453 454 455
	u16                        bf_offset;
	u16                        prev_cc;
	u8                         bf_budget;
456 457 458 459
	struct mlx5e_sq_stats      stats;

	struct mlx5e_cq            cq;

460 461 462 463 464 465 466
	/* pointers to per tx element info: write@xmit, read@completion */
	union {
		struct {
			struct sk_buff           **skb;
			struct mlx5e_sq_dma       *dma_fifo;
			struct mlx5e_tx_wqe_info  *wqe_info;
		} txq;
467 468 469 470
		struct mlx5e_sq_wqe_info *ico_wqe;
		struct {
			struct mlx5e_sq_wqe_info  *wqe_info;
			struct mlx5e_dma_info     *di;
S
Saeed Mahameed 已提交
471
			bool                       doorbell;
472
		} xdp;
473
	} db;
474 475 476 477

	/* read only */
	struct mlx5_wq_cyc         wq;
	u32                        dma_fifo_mask;
478
	void __iomem              *uar_map;
479 480
	struct netdev_queue       *txq;
	u32                        sqn;
481
	u16                        bf_buf_size;
S
Saeed Mahameed 已提交
482
	u16                        max_inline;
483
	u8                         min_inline_mode;
S
Saeed Mahameed 已提交
484
	u16                        edge;
485
	struct device             *pdev;
486
	struct mlx5e_tstamp       *tstamp;
487 488 489 490 491
	__be32                     mkey_be;
	unsigned long              state;

	/* control path */
	struct mlx5_wq_ctrl        wq_ctrl;
E
Eli Cohen 已提交
492
	struct mlx5_sq_bfreg	   bfreg;
493 494
	struct mlx5e_channel      *channel;
	int                        tc;
495
	u32                        rate_limit;
496
	u8                         type;
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
} ____cacheline_aligned_in_smp;

static inline bool mlx5e_sq_has_room_for(struct mlx5e_sq *sq, u16 n)
{
	return (((sq->wq.sz_m1 & (sq->cc - sq->pc)) >= n) ||
		(sq->cc  == sq->pc));
}

enum channel_flags {
	MLX5E_CHANNEL_NAPI_SCHED = 1,
};

struct mlx5e_channel {
	/* data path */
	struct mlx5e_rq            rq;
512
	struct mlx5e_sq            xdp_sq;
513
	struct mlx5e_sq            sq[MLX5E_MAX_NUM_TC];
T
Tariq Toukan 已提交
514
	struct mlx5e_sq            icosq;   /* internal control operations */
515
	bool                       xdp;
516 517 518 519 520 521 522 523 524 525 526 527 528 529
	struct napi_struct         napi;
	struct device             *pdev;
	struct net_device         *netdev;
	__be32                     mkey_be;
	u8                         num_tc;
	unsigned long              flags;

	/* control */
	struct mlx5e_priv         *priv;
	int                        ix;
	int                        cpu;
};

enum mlx5e_traffic_types {
530 531 532 533
	MLX5E_TT_IPV4_TCP,
	MLX5E_TT_IPV6_TCP,
	MLX5E_TT_IPV4_UDP,
	MLX5E_TT_IPV6_UDP,
534 535 536 537
	MLX5E_TT_IPV4_IPSEC_AH,
	MLX5E_TT_IPV6_IPSEC_AH,
	MLX5E_TT_IPV4_IPSEC_ESP,
	MLX5E_TT_IPV6_IPSEC_ESP,
538 539 540 541
	MLX5E_TT_IPV4,
	MLX5E_TT_IPV6,
	MLX5E_TT_ANY,
	MLX5E_NUM_TT,
T
Tariq Toukan 已提交
542
	MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
543 544
};

545
enum {
546
	MLX5E_STATE_ASYNC_EVENTS_ENABLED,
547 548 549 550 551 552 553 554 555
	MLX5E_STATE_OPENED,
	MLX5E_STATE_DESTROYING,
};

struct mlx5e_vxlan_db {
	spinlock_t			lock; /* protect vxlan table */
	struct radix_tree_root		tree;
};

556
struct mlx5e_l2_rule {
557
	u8  addr[ETH_ALEN + 2];
M
Mark Bloch 已提交
558
	struct mlx5_flow_handle *rule;
559 560
};

561 562 563 564 565 566
struct mlx5e_flow_table {
	int num_groups;
	struct mlx5_flow_table *t;
	struct mlx5_flow_group **g;
};

567
#define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
568

569 570 571 572 573
struct mlx5e_tc_table {
	struct mlx5_flow_table		*t;

	struct rhashtable_params        ht_params;
	struct rhashtable               ht;
574 575
};

576 577
struct mlx5e_vlan_table {
	struct mlx5e_flow_table		ft;
578
	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
M
Mark Bloch 已提交
579 580
	struct mlx5_flow_handle	*active_vlans_rule[VLAN_N_VID];
	struct mlx5_flow_handle	*untagged_rule;
581 582 583
	struct mlx5_flow_handle	*any_cvlan_rule;
	struct mlx5_flow_handle	*any_svlan_rule;
	bool			filter_disabled;
584 585
};

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
struct mlx5e_l2_table {
	struct mlx5e_flow_table    ft;
	struct hlist_head          netdev_uc[MLX5E_L2_ADDR_HASH_SIZE];
	struct hlist_head          netdev_mc[MLX5E_L2_ADDR_HASH_SIZE];
	struct mlx5e_l2_rule	   broadcast;
	struct mlx5e_l2_rule	   allmulti;
	struct mlx5e_l2_rule	   promisc;
	bool                       broadcast_enabled;
	bool                       allmulti_enabled;
	bool                       promisc_enabled;
};

/* L3/L4 traffic type classifier */
struct mlx5e_ttc_table {
	struct mlx5e_flow_table  ft;
M
Mark Bloch 已提交
601
	struct mlx5_flow_handle	 *rules[MLX5E_NUM_TT];
602 603
};

604 605
#define ARFS_HASH_SHIFT BITS_PER_BYTE
#define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
606 607
struct arfs_table {
	struct mlx5e_flow_table  ft;
M
Mark Bloch 已提交
608
	struct mlx5_flow_handle	 *default_rule;
609
	struct hlist_head	 rules_hash[ARFS_HASH_SIZE];
610 611 612 613 614 615 616 617 618 619 620 621
};

enum  arfs_type {
	ARFS_IPV4_TCP,
	ARFS_IPV6_TCP,
	ARFS_IPV4_UDP,
	ARFS_IPV6_UDP,
	ARFS_NUM_TYPES,
};

struct mlx5e_arfs_tables {
	struct arfs_table arfs_tables[ARFS_NUM_TYPES];
622 623 624 625 626
	/* Protect aRFS rules list */
	spinlock_t                     arfs_lock;
	struct list_head               rules;
	int                            last_filter_id;
	struct workqueue_struct        *wq;
627 628 629 630 631 632 633 634 635 636
};

/* NIC prio FTS */
enum {
	MLX5E_VLAN_FT_LEVEL = 0,
	MLX5E_L2_FT_LEVEL,
	MLX5E_TTC_FT_LEVEL,
	MLX5E_ARFS_FT_LEVEL
};

637 638 639 640 641
struct mlx5e_ethtool_table {
	struct mlx5_flow_table *ft;
	int                    num_rules;
};

642
#define ETHTOOL_NUM_L3_L4_FTS 7
643 644 645
#define ETHTOOL_NUM_L2_FTS 4

struct mlx5e_ethtool_steering {
646
	struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
647 648 649 650 651
	struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
	struct list_head                rules;
	int                             tot_num_rules;
};

652 653
struct mlx5e_flow_steering {
	struct mlx5_flow_namespace      *ns;
654
	struct mlx5e_ethtool_steering   ethtool;
655 656
	struct mlx5e_tc_table           tc;
	struct mlx5e_vlan_table         vlan;
657 658
	struct mlx5e_l2_table           l2;
	struct mlx5e_ttc_table          ttc;
659
	struct mlx5e_arfs_tables        arfs;
660 661
};

662
struct mlx5e_rqt {
T
Tariq Toukan 已提交
663
	u32              rqtn;
664 665 666 667 668 669 670
	bool		 enabled;
};

struct mlx5e_tir {
	u32		  tirn;
	struct mlx5e_rqt  rqt;
	struct list_head  list;
T
Tariq Toukan 已提交
671 672
};

673 674 675 676 677
enum {
	MLX5E_TC_PRIO = 0,
	MLX5E_NIC_PRIO
};

678 679 680
struct mlx5e_profile {
	void	(*init)(struct mlx5_core_dev *mdev,
			struct net_device *netdev,
681
			const struct mlx5e_profile *profile, void *ppriv);
682 683 684 685 686 687 688 689 690 691 692 693
	void	(*cleanup)(struct mlx5e_priv *priv);
	int	(*init_rx)(struct mlx5e_priv *priv);
	void	(*cleanup_rx)(struct mlx5e_priv *priv);
	int	(*init_tx)(struct mlx5e_priv *priv);
	void	(*cleanup_tx)(struct mlx5e_priv *priv);
	void	(*enable)(struct mlx5e_priv *priv);
	void	(*disable)(struct mlx5e_priv *priv);
	void	(*update_stats)(struct mlx5e_priv *priv);
	int	(*max_nch)(struct mlx5_core_dev *mdev);
	int	max_tc;
};

694 695
struct mlx5e_priv {
	/* priv data path fields - start */
696
	struct mlx5e_sq            **txq_to_sq_map;
697
	int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
698
	struct bpf_prog *xdp_prog;
699 700 701 702
	/* priv data path fields - end */

	unsigned long              state;
	struct mutex               state_lock; /* Protects Interface state */
703
	struct mlx5e_rq            drop_rq;
704 705 706

	struct mlx5e_channel     **channel;
	u32                        tisn[MLX5E_MAX_NUM_TC];
707
	struct mlx5e_rqt           indir_rqt;
708 709
	struct mlx5e_tir           indir_tir[MLX5E_NUM_INDIR_TIRS];
	struct mlx5e_tir           direct_tir[MLX5E_MAX_NUM_CHANNELS];
710
	u32                        tx_rates[MLX5E_MAX_NUM_SQS];
711

712
	struct mlx5e_flow_steering fs;
713
	struct mlx5e_vxlan_db      vxlan;
714 715

	struct mlx5e_params        params;
716
	struct workqueue_struct    *wq;
717 718
	struct work_struct         update_carrier_work;
	struct work_struct         set_rx_mode_work;
719
	struct work_struct         tx_timeout_work;
720 721 722 723 724
	struct delayed_work        update_stats_work;

	struct mlx5_core_dev      *mdev;
	struct net_device         *netdev;
	struct mlx5e_stats         stats;
725
	struct mlx5e_tstamp        tstamp;
726
	u16 q_counter;
H
Huy Nguyen 已提交
727 728 729 730
#ifdef CONFIG_MLX5_CORE_EN_DCB
	struct mlx5e_dcbx          dcbx;
#endif

731
	const struct mlx5e_profile *profile;
732
	void                      *ppriv;
733 734
};

735 736
void mlx5e_build_ptys2ethtool_map(void);

S
Saeed Mahameed 已提交
737
void mlx5e_send_nop(struct mlx5e_sq *sq, bool notify_hw);
738 739 740 741 742 743 744
u16 mlx5e_select_queue(struct net_device *dev, struct sk_buff *skb,
		       void *accel_priv, select_queue_fallback_t fallback);
netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);

void mlx5e_completion_event(struct mlx5_core_cq *mcq);
void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
int mlx5e_napi_poll(struct napi_struct *napi, int budget);
745
bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
E
Eric Dumazet 已提交
746
int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
747
void mlx5e_free_sq_descs(struct mlx5e_sq *sq);
748

749 750
void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
			bool recycle);
751
void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
752
void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
753
bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
754
int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
755
int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe,	u16 ix);
756 757
void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
758 759
void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq);
void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
760 761
struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);

762 763 764 765
void mlx5e_rx_am(struct mlx5e_rq *rq);
void mlx5e_rx_am_work(struct work_struct *work);
struct mlx5e_cq_moder mlx5e_am_get_def_profile(u8 rx_cq_period_mode);

766 767
void mlx5e_update_stats(struct mlx5e_priv *priv);

768 769
int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
770
void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
771
void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
772 773 774
int mlx5e_self_test_num(struct mlx5e_priv *priv);
void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
		     u64 *buf);
775 776 777 778
int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
			   int location);
int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,
				struct ethtool_rxnfc *info, u32 *rule_locs);
779 780 781 782 783 784
int mlx5e_ethtool_flow_replace(struct mlx5e_priv *priv,
			       struct ethtool_rx_flow_spec *fs);
int mlx5e_ethtool_flow_remove(struct mlx5e_priv *priv,
			      int location);
void mlx5e_ethtool_init_steering(struct mlx5e_priv *priv);
void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv);
785 786
void mlx5e_set_rx_mode_work(struct work_struct *work);

787 788 789 790
void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
			struct skb_shared_hwtstamps *hwts);
void mlx5e_timestamp_init(struct mlx5e_priv *priv);
void mlx5e_timestamp_cleanup(struct mlx5e_priv *priv);
791 792
void mlx5e_pps_event_handler(struct mlx5e_priv *priv,
			     struct ptp_clock_event *event);
793 794
int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
795
void mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool val);
796

797 798 799 800 801 802 803
int mlx5e_vlan_rx_add_vid(struct net_device *dev, __always_unused __be16 proto,
			  u16 vid);
int mlx5e_vlan_rx_kill_vid(struct net_device *dev, __always_unused __be16 proto,
			   u16 vid);
void mlx5e_enable_vlan_filter(struct mlx5e_priv *priv);
void mlx5e_disable_vlan_filter(struct mlx5e_priv *priv);

804 805
int mlx5e_modify_rqs_vsd(struct mlx5e_priv *priv, bool vsd);

T
Tariq Toukan 已提交
806
int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz, int ix);
807 808
void mlx5e_build_indir_tir_ctx_hash(struct mlx5e_priv *priv, void *tirc,
				    enum mlx5e_traffic_types tt);
809

810 811
int mlx5e_open_locked(struct net_device *netdev);
int mlx5e_close_locked(struct net_device *netdev);
812 813
void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
				   u32 *indirection_rqt, int len,
814
				   int num_channels);
815
int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
816

T
Tariq Toukan 已提交
817 818
void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
				 u8 cq_period_mode);
819
void mlx5e_set_rq_type_params(struct mlx5e_priv *priv, u8 rq_type);
T
Tariq Toukan 已提交
820

821
static inline void mlx5e_tx_notify_hw(struct mlx5e_sq *sq,
822
				      struct mlx5_wqe_ctrl_seg *ctrl, int bf_sz)
823
{
E
Eli Cohen 已提交
824
	u16 ofst = sq->bf_offset;
825

826 827 828 829 830 831 832 833 834
	/* ensure wqe is visible to device before updating doorbell record */
	dma_wmb();

	*sq->wq.db = cpu_to_be32(sq->pc);

	/* ensure doorbell record is visible to device before ringing the
	 * doorbell
	 */
	wmb();
M
Moshe Lazer 已提交
835
	if (bf_sz)
836
		__iowrite64_copy(sq->uar_map + ofst, ctrl, bf_sz);
M
Moshe Lazer 已提交
837
	else
838
		mlx5_write64((__be32 *)ctrl, sq->uar_map + ofst, NULL);
M
Moshe Lazer 已提交
839 840
	/* flush the write-combining mapped buffer */
	wmb();
841 842 843 844 845 846 847 848 849

	sq->bf_offset ^= sq->bf_buf_size;
}

static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
{
	struct mlx5_core_cq *mcq;

	mcq = &cq->mcq;
850
	mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
851 852
}

853 854
static inline u32 mlx5e_get_wqe_mtt_offset(struct mlx5e_rq *rq, u16 wqe_ix)
{
T
Tariq Toukan 已提交
855
	return wqe_ix * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8);
856 857
}

858
extern const struct ethtool_ops mlx5e_ethtool_ops;
859 860 861
#ifdef CONFIG_MLX5_CORE_EN_DCB
extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
862
void mlx5e_dcbnl_initialize(struct mlx5e_priv *priv);
863 864
#endif

865 866 867 868 869 870 871
#ifndef CONFIG_RFS_ACCEL
static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
{
	return 0;
}

static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
872 873 874

static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
{
875
	return -EOPNOTSUPP;
876 877 878 879
}

static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
{
880
	return -EOPNOTSUPP;
881
}
882 883 884
#else
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
885 886
int mlx5e_arfs_enable(struct mlx5e_priv *priv);
int mlx5e_arfs_disable(struct mlx5e_priv *priv);
887 888
int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
			u16 rxq_index, u32 flow_id);
889 890
#endif

891
u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
892 893 894 895
int mlx5e_create_tir(struct mlx5_core_dev *mdev,
		     struct mlx5e_tir *tir, u32 *in, int inlen);
void mlx5e_destroy_tir(struct mlx5_core_dev *mdev,
		       struct mlx5e_tir *tir);
896 897
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
898 899
int mlx5e_refresh_tirs_self_loopback(struct mlx5_core_dev *mdev,
				     bool enable_uc_lb);
900

901 902 903 904 905 906 907 908 909 910 911
struct mlx5_eswitch_rep;
int mlx5e_vport_rep_load(struct mlx5_eswitch *esw,
			 struct mlx5_eswitch_rep *rep);
void mlx5e_vport_rep_unload(struct mlx5_eswitch *esw,
			    struct mlx5_eswitch_rep *rep);
int mlx5e_nic_rep_load(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep);
void mlx5e_nic_rep_unload(struct mlx5_eswitch *esw,
			  struct mlx5_eswitch_rep *rep);
int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
912
void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
913
void mlx5e_update_hw_rep_counters(struct mlx5e_priv *priv);
914 915 916 917 918 919 920 921 922 923

int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
int mlx5e_create_tises(struct mlx5e_priv *priv);
void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
int mlx5e_close(struct net_device *netdev);
int mlx5e_open(struct net_device *netdev);
void mlx5e_update_stats_work(struct work_struct *work);
924 925 926
struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
				       const struct mlx5e_profile *profile,
				       void *ppriv);
927
void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
928 929
int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
930
u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
931

932 933 934 935 936 937
int mlx5e_get_offload_stats(int attr_id, const struct net_device *dev,
			    void *sp);
bool mlx5e_has_offload_stats(const struct net_device *dev, int attr_id);

bool mlx5e_is_uplink_rep(struct mlx5e_priv *priv);
bool mlx5e_is_vf_vport_rep(struct mlx5e_priv *priv);
938
#endif /* __MLX5_EN_H__ */