en.h 29.7 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 94
#define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD	(128)

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 114
#define MLX5E_TX_CQ_POLL_BUDGET        128
#define MLX5E_UPDATE_STATS_INTERVAL    200 /* msecs */

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

118 119
#define MLX5E_XDP_MIN_INLINE (ETH_HLEN + VLAN_HLEN)
#define MLX5E_XDP_TX_DS_COUNT \
120
	((sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS) + 1 /* SG DS */)
121

122
#define MLX5E_NUM_MAIN_GROUPS 9
123

124 125 126 127 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
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;
	}
}

156 157 158 159 160 161 162 163 164
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;
};
165

166 167 168 169 170 171 172
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;
};

173 174
extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];

175
static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
T
Tariq Toukan 已提交
176
	"rx_cqe_moder",
177
	"rx_cqe_compress",
178 179 180
};

enum mlx5e_priv_flag {
T
Tariq Toukan 已提交
181
	MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0),
182
	MLX5E_PFLAG_RX_CQE_COMPRESS = (1 << 1),
183 184
};

185
#define MLX5E_SET_PFLAG(params, pflag, enable)			\
186 187
	do {							\
		if (enable)					\
188
			(params)->pflags |= (pflag);		\
189
		else						\
190
			(params)->pflags &= ~(pflag);		\
191 192
	} while (0)

193
#define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (pflag)))
194

195 196 197 198
#ifdef CONFIG_MLX5_CORE_EN_DCB
#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
#endif

T
Tariq Toukan 已提交
199 200 201 202 203
struct mlx5e_cq_moder {
	u16 usec;
	u16 pkts;
};

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

H
Huy Nguyen 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
#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 {
246
	enum mlx5_dcbx_oper_mode   mode;
H
Huy Nguyen 已提交
247
	struct mlx5e_cee_config    cee_cfg; /* pending configuration */
248 249 250

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

254 255 256 257 258 259 260 261 262
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;
263 264
	struct ptp_clock          *ptp;
	struct ptp_clock_info      ptp_info;
265
	u8                        *pps_pin_caps;
266 267
};

268
enum {
269
	MLX5E_RQ_STATE_ENABLED,
270
	MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
271
	MLX5E_RQ_STATE_AM,
272 273 274 275 276 277 278
};

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

	/* data path - accessed per napi poll */
279
	u16                        event_ctr;
280 281 282 283
	struct napi_struct        *napi;
	struct mlx5_core_cq        mcq;
	struct mlx5e_channel      *channel;

T
Tariq Toukan 已提交
284 285 286 287 288 289 290
	/* 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;

291
	/* control */
292
	struct mlx5_core_dev      *mdev;
293
	struct mlx5_frag_wq_ctrl   wq_ctrl;
294 295
} ____cacheline_aligned_in_smp;

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
struct mlx5e_tx_wqe_info {
	u32 num_bytes;
	u8  num_wqebbs;
	u8  num_dma;
};

enum mlx5e_dma_map_type {
	MLX5E_DMA_MAP_SINGLE,
	MLX5E_DMA_MAP_PAGE
};

struct mlx5e_sq_dma {
	dma_addr_t              addr;
	u32                     size;
	enum mlx5e_dma_map_type type;
};

enum {
	MLX5E_SQ_STATE_ENABLED,
};

struct mlx5e_sq_wqe_info {
	u8  opcode;
	u8  num_wqebbs;
};
321

S
Saeed Mahameed 已提交
322
struct mlx5e_txqsq {
323 324 325 326 327 328 329 330 331 332 333 334 335
	/* data path */

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

	/* dirtied @xmit */
	u16                        pc ____cacheline_aligned_in_smp;
	u32                        dma_fifo_pc;
	struct mlx5e_sq_stats      stats;

	struct mlx5e_cq            cq;

S
Saeed Mahameed 已提交
336 337 338 339 340
	/* write@xmit, read@completion */
	struct {
		struct sk_buff           **skb;
		struct mlx5e_sq_dma       *dma_fifo;
		struct mlx5e_tx_wqe_info  *wqe_info;
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
	} db;

	/* read only */
	struct mlx5_wq_cyc         wq;
	u32                        dma_fifo_mask;
	void __iomem              *uar_map;
	struct netdev_queue       *txq;
	u32                        sqn;
	u16                        max_inline;
	u8                         min_inline_mode;
	u16                        edge;
	struct device             *pdev;
	struct mlx5e_tstamp       *tstamp;
	__be32                     mkey_be;
	unsigned long              state;

	/* control path */
	struct mlx5_wq_ctrl        wq_ctrl;
	struct mlx5e_channel      *channel;
360
	int                        txq_ix;
361
	u32                        rate_limit;
S
Saeed Mahameed 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
} ____cacheline_aligned_in_smp;

struct mlx5e_xdpsq {
	/* data path */

	/* dirtied @rx completion */
	u16                        cc;
	u16                        pc;

	struct mlx5e_cq            cq;

	/* write@xmit, read@completion */
	struct {
		struct mlx5e_dma_info     *di;
		bool                       doorbell;
	} db;

	/* read only */
	struct mlx5_wq_cyc         wq;
	void __iomem              *uar_map;
	u32                        sqn;
	struct device             *pdev;
	__be32                     mkey_be;
	u8                         min_inline_mode;
	unsigned long              state;

	/* control path */
	struct mlx5_wq_ctrl        wq_ctrl;
	struct mlx5e_channel      *channel;
} ____cacheline_aligned_in_smp;

struct mlx5e_icosq {
	/* data path */

	/* dirtied @completion */
	u16                        cc;

	/* dirtied @xmit */
	u16                        pc ____cacheline_aligned_in_smp;
	u32                        dma_fifo_pc;
	u16                        prev_cc;

	struct mlx5e_cq            cq;

	/* write@xmit, read@completion */
	struct {
		struct mlx5e_sq_wqe_info *ico_wqe;
	} db;

	/* read only */
	struct mlx5_wq_cyc         wq;
	void __iomem              *uar_map;
	u32                        sqn;
	u16                        edge;
	struct device             *pdev;
	__be32                     mkey_be;
	unsigned long              state;

	/* control path */
	struct mlx5_wq_ctrl        wq_ctrl;
	struct mlx5e_channel      *channel;
423 424
} ____cacheline_aligned_in_smp;

425 426
static inline bool
mlx5e_wqc_has_room_for(struct mlx5_wq_cyc *wq, u16 cc, u16 pc, u16 n)
427
{
428
	return (((wq->sz_m1 & (cc - pc)) >= n) || (cc == pc));
429
}
430

431 432 433 434 435
struct mlx5e_dma_info {
	struct page	*page;
	dma_addr_t	addr;
};

436 437 438 439 440 441 442 443 444 445 446 447 448
struct mlx5e_umr_dma_info {
	__be64                *mtt;
	dma_addr_t             mtt_addr;
	struct mlx5e_dma_info  dma_info[MLX5_MPWRQ_PAGES_PER_WQE];
	struct mlx5e_umr_wqe   wqe;
};

struct mlx5e_mpw_info {
	struct mlx5e_umr_dma_info umr;
	u16 consumed_strides;
	u16 skbs_frags[MLX5_MPWRQ_PAGES_PER_WQE];
};

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
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;
};

473 474 475 476 477 478 479 480 481 482 483 484
/* 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];
};

485 486 487 488 489
struct mlx5e_rq;
typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq*, struct mlx5_cqe64*);
typedef int (*mlx5e_fp_alloc_wqe)(struct mlx5e_rq*, struct mlx5e_rx_wqe*, u16);
typedef void (*mlx5e_fp_dealloc_wqe)(struct mlx5e_rq*, u16);

490 491 492
struct mlx5e_rq {
	/* data path */
	struct mlx5_wq_ll      wq;
493

494 495 496 497 498 499 500
	union {
		struct mlx5e_dma_info *dma_info;
		struct {
			struct mlx5e_mpw_info *info;
			void                  *mtt_no_align;
		} mpwqe;
	};
501 502 503
	struct {
		u8             page_order;
		u32            wqe_sz;    /* wqe data buffer size */
504
		u8             map_dir;   /* dma map direction */
505
	} buff;
506
	__be32                 mkey_be;
507 508 509

	struct device         *pdev;
	struct net_device     *netdev;
510
	struct mlx5e_tstamp   *tstamp;
511 512
	struct mlx5e_rq_stats  stats;
	struct mlx5e_cq        cq;
513 514
	struct mlx5e_page_cache page_cache;

515 516
	mlx5e_fp_handle_rx_cqe handle_rx_cqe;
	mlx5e_fp_alloc_wqe     alloc_wqe;
517
	mlx5e_fp_dealloc_wqe   dealloc_wqe;
518 519 520

	unsigned long          state;
	int                    ix;
521
	u16                    rx_headroom;
522

523
	struct mlx5e_rx_am     am; /* Adaptive Moderation */
524 525

	/* XDP */
526
	struct bpf_prog       *xdp_prog;
S
Saeed Mahameed 已提交
527
	struct mlx5e_xdpsq     xdpsq;
528

529 530
	/* control */
	struct mlx5_wq_ctrl    wq_ctrl;
531
	u8                     wq_type;
532 533
	u32                    mpwqe_stride_sz;
	u32                    mpwqe_num_strides;
534 535
	u32                    rqn;
	struct mlx5e_channel  *channel;
536
	struct mlx5_core_dev  *mdev;
T
Tariq Toukan 已提交
537
	struct mlx5_core_mkey  umr_mkey;
538 539 540 541 542 543 544 545 546
} ____cacheline_aligned_in_smp;

enum channel_flags {
	MLX5E_CHANNEL_NAPI_SCHED = 1,
};

struct mlx5e_channel {
	/* data path */
	struct mlx5e_rq            rq;
S
Saeed Mahameed 已提交
547 548
	struct mlx5e_txqsq         sq[MLX5E_MAX_NUM_TC];
	struct mlx5e_icosq         icosq;   /* internal control operations */
549
	bool                       xdp;
550 551 552 553 554 555 556 557 558
	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;
559 560
	struct mlx5_core_dev      *mdev;
	struct mlx5e_tstamp       *tstamp;
561 562 563 564
	int                        ix;
	int                        cpu;
};

565 566 567
struct mlx5e_channels {
	struct mlx5e_channel **c;
	unsigned int           num;
568
	struct mlx5e_params    params;
569 570
};

571
enum mlx5e_traffic_types {
572 573 574 575
	MLX5E_TT_IPV4_TCP,
	MLX5E_TT_IPV6_TCP,
	MLX5E_TT_IPV4_UDP,
	MLX5E_TT_IPV6_UDP,
576 577 578 579
	MLX5E_TT_IPV4_IPSEC_AH,
	MLX5E_TT_IPV6_IPSEC_AH,
	MLX5E_TT_IPV4_IPSEC_ESP,
	MLX5E_TT_IPV6_IPSEC_ESP,
580 581 582 583
	MLX5E_TT_IPV4,
	MLX5E_TT_IPV6,
	MLX5E_TT_ANY,
	MLX5E_NUM_TT,
T
Tariq Toukan 已提交
584
	MLX5E_NUM_INDIR_TIRS = MLX5E_TT_ANY,
585 586
};

587
enum {
588
	MLX5E_STATE_ASYNC_EVENTS_ENABLED,
589 590 591 592 593 594 595 596 597
	MLX5E_STATE_OPENED,
	MLX5E_STATE_DESTROYING,
};

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

598
struct mlx5e_l2_rule {
599
	u8  addr[ETH_ALEN + 2];
M
Mark Bloch 已提交
600
	struct mlx5_flow_handle *rule;
601 602
};

603 604 605 606 607 608
struct mlx5e_flow_table {
	int num_groups;
	struct mlx5_flow_table *t;
	struct mlx5_flow_group **g;
};

609
#define MLX5E_L2_ADDR_HASH_SIZE BIT(BITS_PER_BYTE)
610

611 612 613 614 615
struct mlx5e_tc_table {
	struct mlx5_flow_table		*t;

	struct rhashtable_params        ht_params;
	struct rhashtable               ht;
616 617
};

618 619
struct mlx5e_vlan_table {
	struct mlx5e_flow_table		ft;
620
	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
M
Mark Bloch 已提交
621 622
	struct mlx5_flow_handle	*active_vlans_rule[VLAN_N_VID];
	struct mlx5_flow_handle	*untagged_rule;
623 624 625
	struct mlx5_flow_handle	*any_cvlan_rule;
	struct mlx5_flow_handle	*any_svlan_rule;
	bool			filter_disabled;
626 627
};

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
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 已提交
643
	struct mlx5_flow_handle	 *rules[MLX5E_NUM_TT];
644 645
};

646 647
#define ARFS_HASH_SHIFT BITS_PER_BYTE
#define ARFS_HASH_SIZE BIT(BITS_PER_BYTE)
648 649
struct arfs_table {
	struct mlx5e_flow_table  ft;
M
Mark Bloch 已提交
650
	struct mlx5_flow_handle	 *default_rule;
651
	struct hlist_head	 rules_hash[ARFS_HASH_SIZE];
652 653 654 655 656 657 658 659 660 661 662 663
};

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];
664 665 666 667 668
	/* Protect aRFS rules list */
	spinlock_t                     arfs_lock;
	struct list_head               rules;
	int                            last_filter_id;
	struct workqueue_struct        *wq;
669 670 671 672 673 674 675 676 677 678
};

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

679 680 681 682 683
struct mlx5e_ethtool_table {
	struct mlx5_flow_table *ft;
	int                    num_rules;
};

684
#define ETHTOOL_NUM_L3_L4_FTS 7
685 686 687
#define ETHTOOL_NUM_L2_FTS 4

struct mlx5e_ethtool_steering {
688
	struct mlx5e_ethtool_table      l3_l4_ft[ETHTOOL_NUM_L3_L4_FTS];
689 690 691 692 693
	struct mlx5e_ethtool_table      l2_ft[ETHTOOL_NUM_L2_FTS];
	struct list_head                rules;
	int                             tot_num_rules;
};

694 695
struct mlx5e_flow_steering {
	struct mlx5_flow_namespace      *ns;
696
	struct mlx5e_ethtool_steering   ethtool;
697 698
	struct mlx5e_tc_table           tc;
	struct mlx5e_vlan_table         vlan;
699 700
	struct mlx5e_l2_table           l2;
	struct mlx5e_ttc_table          ttc;
701
	struct mlx5e_arfs_tables        arfs;
702 703
};

704
struct mlx5e_rqt {
T
Tariq Toukan 已提交
705
	u32              rqtn;
706 707 708 709 710 711 712
	bool		 enabled;
};

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

715 716 717 718 719
enum {
	MLX5E_TC_PRIO = 0,
	MLX5E_NIC_PRIO
};

720 721
struct mlx5e_priv {
	/* priv data path fields - start */
722 723
	struct mlx5e_txqsq *txq2sq[MLX5E_MAX_NUM_CHANNELS * MLX5E_MAX_NUM_TC];
	int channel_tc2txq[MLX5E_MAX_NUM_CHANNELS][MLX5E_MAX_NUM_TC];
724 725 726 727
	/* priv data path fields - end */

	unsigned long              state;
	struct mutex               state_lock; /* Protects Interface state */
728
	struct mlx5e_rq            drop_rq;
729

730
	struct mlx5e_channels      channels;
731
	u32                        tisn[MLX5E_MAX_NUM_TC];
732
	struct mlx5e_rqt           indir_rqt;
733 734
	struct mlx5e_tir           indir_tir[MLX5E_NUM_INDIR_TIRS];
	struct mlx5e_tir           direct_tir[MLX5E_MAX_NUM_CHANNELS];
735
	u32                        tx_rates[MLX5E_MAX_NUM_SQS];
736

737
	struct mlx5e_flow_steering fs;
738
	struct mlx5e_vxlan_db      vxlan;
739

740
	struct workqueue_struct    *wq;
741 742
	struct work_struct         update_carrier_work;
	struct work_struct         set_rx_mode_work;
743
	struct work_struct         tx_timeout_work;
744 745 746 747 748
	struct delayed_work        update_stats_work;

	struct mlx5_core_dev      *mdev;
	struct net_device         *netdev;
	struct mlx5e_stats         stats;
749
	struct mlx5e_tstamp        tstamp;
750
	u16 q_counter;
H
Huy Nguyen 已提交
751 752 753 754
#ifdef CONFIG_MLX5_CORE_EN_DCB
	struct mlx5e_dcbx          dcbx;
#endif

755
	const struct mlx5e_profile *profile;
756
	void                      *ppriv;
757 758
};

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
struct mlx5e_profile {
	void	(*init)(struct mlx5_core_dev *mdev,
			struct net_device *netdev,
			const struct mlx5e_profile *profile, void *ppriv);
	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;
};

775 776
void mlx5e_build_ptys2ethtool_map(void);

777 778 779 780 781 782 783
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);
784
bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
E
Eric Dumazet 已提交
785
int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
786
bool mlx5e_poll_xdpsq_cq(struct mlx5e_cq *cq);
S
Saeed Mahameed 已提交
787 788
void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
void mlx5e_free_xdpsq_descs(struct mlx5e_xdpsq *sq);
789

790 791
void mlx5e_page_release(struct mlx5e_rq *rq, struct mlx5e_dma_info *dma_info,
			bool recycle);
792
void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
793
void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
794
bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq);
795
int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe, u16 ix);
796
int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe *wqe,	u16 ix);
797 798
void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix);
void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix);
799 800
void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq);
void mlx5e_free_rx_mpwqe(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi);
801 802
struct mlx5_cqe64 *mlx5e_get_cqe(struct mlx5e_cq *cq);

803 804 805 806
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);

807 808
void mlx5e_update_stats(struct mlx5e_priv *priv);

809 810
int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
811
void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
812
void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
813 814 815
int mlx5e_self_test_num(struct mlx5e_priv *priv);
void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
		     u64 *buf);
816 817 818 819
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);
820 821 822 823 824 825
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);
826 827
void mlx5e_set_rx_mode_work(struct work_struct *work);

828 829 830 831
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);
832 833
void mlx5e_pps_event_handler(struct mlx5e_priv *priv,
			     struct ptp_clock_event *event);
834 835
int mlx5e_hwstamp_set(struct net_device *dev, struct ifreq *ifr);
int mlx5e_hwstamp_get(struct net_device *dev, struct ifreq *ifr);
836
void mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool val);
837

838 839 840 841 842 843 844
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);

845
int mlx5e_modify_channels_vsd(struct mlx5e_channels *chs, bool vsd);
846

847 848 849 850 851 852 853 854 855 856 857 858 859
struct mlx5e_redirect_rqt_param {
	bool is_rss;
	union {
		u32 rqn; /* Direct RQN (Non-RSS) */
		struct {
			u8 hfunc;
			struct mlx5e_channels *channels;
		} rss; /* RSS data */
	};
};

int mlx5e_redirect_rqt(struct mlx5e_priv *priv, u32 rqtn, int sz,
		       struct mlx5e_redirect_rqt_param rrp);
860 861 862
void mlx5e_build_indir_tir_ctx_hash(struct mlx5e_params *params,
				    enum mlx5e_traffic_types tt,
				    void *tirc);
863

864 865
int mlx5e_open_locked(struct net_device *netdev);
int mlx5e_close_locked(struct net_device *netdev);
866 867 868 869 870 871 872

int mlx5e_open_channels(struct mlx5e_priv *priv,
			struct mlx5e_channels *chs);
void mlx5e_close_channels(struct mlx5e_channels *chs);
void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
				struct mlx5e_channels *new_chs);

873 874
void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
				   u32 *indirection_rqt, int len,
875
				   int num_channels);
876
int mlx5e_get_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
877

T
Tariq Toukan 已提交
878 879
void mlx5e_set_rx_cq_mode_params(struct mlx5e_params *params,
				 u8 cq_period_mode);
880 881
void mlx5e_set_rq_type_params(struct mlx5_core_dev *mdev,
			      struct mlx5e_params *params, u8 rq_type);
T
Tariq Toukan 已提交
882

883 884
static inline
struct mlx5e_tx_wqe *mlx5e_post_nop(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
885
{
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
	u16                         pi   = *pc & wq->sz_m1;
	struct mlx5e_tx_wqe        *wqe  = mlx5_wq_cyc_get_wqe(wq, pi);
	struct mlx5_wqe_ctrl_seg   *cseg = &wqe->ctrl;

	memset(cseg, 0, sizeof(*cseg));

	cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
	cseg->qpn_ds           = cpu_to_be32((sqn << 8) | 0x01);

	(*pc)++;

	return wqe;
}

static inline
void mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc,
		     void __iomem *uar_map,
		     struct mlx5_wqe_ctrl_seg *ctrl)
{
	ctrl->fm_ce_se = MLX5_WQE_CTRL_CQ_UPDATE;
906 907 908
	/* ensure wqe is visible to device before updating doorbell record */
	dma_wmb();

909
	*wq->db = cpu_to_be32(pc);
910 911 912 913 914 915

	/* ensure doorbell record is visible to device before ringing the
	 * doorbell
	 */
	wmb();

916
	mlx5_write64((__be32 *)ctrl, uar_map, NULL);
917 918 919 920 921 922 923
}

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

	mcq = &cq->mcq;
924
	mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
925 926
}

927 928
static inline u32 mlx5e_get_wqe_mtt_offset(struct mlx5e_rq *rq, u16 wqe_ix)
{
T
Tariq Toukan 已提交
929
	return wqe_ix * ALIGN(MLX5_MPWRQ_PAGES_PER_WQE, 8);
930 931
}

932
extern const struct ethtool_ops mlx5e_ethtool_ops;
933 934 935
#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);
936
void mlx5e_dcbnl_initialize(struct mlx5e_priv *priv);
937 938
#endif

939 940 941 942 943 944 945
#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) {}
946 947 948

static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
{
949
	return -EOPNOTSUPP;
950 951 952 953
}

static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
{
954
	return -EOPNOTSUPP;
955
}
956 957 958
#else
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
959 960
int mlx5e_arfs_enable(struct mlx5e_priv *priv);
int mlx5e_arfs_disable(struct mlx5e_priv *priv);
961 962
int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
			u16 rxq_index, u32 flow_id);
963 964
#endif

965
u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
966 967 968 969
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);
970 971
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
972
int mlx5e_refresh_tirs(struct mlx5e_priv *priv, bool enable_uc_lb);
973

974 975 976 977 978 979 980 981 982 983 984
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);
985
void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe);
986
void mlx5e_update_hw_rep_counters(struct mlx5e_priv *priv);
987 988 989 990 991 992 993 994 995 996

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);
997 998 999
struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
				       const struct mlx5e_profile *profile,
				       void *ppriv);
1000
void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
1001 1002
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);
1003
u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
1004

1005 1006 1007 1008 1009 1010
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);
1011
#endif /* __MLX5_EN_H__ */