dpaa2-eth.h 20.4 KB
Newer Older
1
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2
/* Copyright 2014-2016 Freescale Semiconductor Inc.
3
 * Copyright 2016-2020 NXP
4 5 6 7 8
 */

#ifndef __DPAA2_ETH_H
#define __DPAA2_ETH_H

9
#include <linux/dcbnl.h>
10 11
#include <linux/netdevice.h>
#include <linux/if_vlan.h>
12
#include <linux/fsl/mc.h>
13
#include <linux/net_tstamp.h>
14
#include <net/devlink.h>
15

16 17
#include <soc/fsl/dpaa2-io.h>
#include <soc/fsl/dpaa2-fd.h>
18 19 20
#include "dpni.h"
#include "dpni-cmd.h"

21
#include "dpaa2-eth-trace.h"
22
#include "dpaa2-eth-debugfs.h"
23
#include "dpaa2-mac.h"
24

25 26
#define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0)

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#define DPAA2_ETH_STORE_SIZE		16

/* Maximum number of scatter-gather entries in an ingress frame,
 * considering the maximum receive frame size is 64K
 */
#define DPAA2_ETH_MAX_SG_ENTRIES	((64 * 1024) / DPAA2_ETH_RX_BUF_SIZE)

/* Maximum acceptable MTU value. It is in direct relation with the hardware
 * enforced Max Frame Length (currently 10k).
 */
#define DPAA2_ETH_MFL			(10 * 1024)
#define DPAA2_ETH_MAX_MTU		(DPAA2_ETH_MFL - VLAN_ETH_HLEN)
/* Convert L3 MTU to L2 MFL */
#define DPAA2_ETH_L2_MAX_FRM(mtu)	((mtu) + VLAN_ETH_HLEN)

42 43 44
/* Set the taildrop threshold (in bytes) to allow the enqueue of a large
 * enough number of jumbo frames in the Rx queues (length of the current
 * frame is not taken into account when making the taildrop decision)
45
 */
46
#define DPAA2_ETH_FQ_TAILDROP_THRESH	(1024 * 1024)
47

48 49 50
/* Maximum burst size value for Tx shaping */
#define DPAA2_ETH_MAX_BURST_SIZE	0xF7FF

51 52 53 54 55
/* Maximum number of Tx confirmation frames to be processed
 * in a single NAPI call
 */
#define DPAA2_ETH_TXCONF_PER_NAPI	256

56 57 58 59 60
/* Buffer qouta per channel. We want to keep in check number of ingress frames
 * in flight: for small sized frames, congestion group taildrop may kick in
 * first; for large sizes, Rx FQ taildrop threshold will ensure only a
 * reasonable number of frames will be pending at any given time.
 * Ingress frame drop due to buffer pool depletion should be a corner case only
61
 */
62
#define DPAA2_ETH_NUM_BUFS		1280
63 64
#define DPAA2_ETH_REFILL_THRESH \
	(DPAA2_ETH_NUM_BUFS - DPAA2_ETH_BUFS_PER_CMD)
65

66 67 68 69 70 71
/* Congestion group taildrop threshold: number of frames allowed to accumulate
 * at any moment in a group of Rx queues belonging to the same traffic class.
 * Choose value such that we don't risk depleting the buffer pool before the
 * taildrop kicks in
 */
#define DPAA2_ETH_CG_TAILDROP_THRESH(priv)				\
72
	(1024 * dpaa2_eth_queue_count(priv) / dpaa2_eth_tc_count(priv))
73

74 75 76 77 78 79 80 81 82 83 84
/* Congestion group notification threshold: when this many frames accumulate
 * on the Rx queues belonging to the same TC, the MAC is instructed to send
 * PFC frames for that TC.
 * When number of pending frames drops below exit threshold transmission of
 * PFC frames is stopped.
 */
#define DPAA2_ETH_CN_THRESH_ENTRY(priv) \
	(DPAA2_ETH_CG_TAILDROP_THRESH(priv) / 2)
#define DPAA2_ETH_CN_THRESH_EXIT(priv) \
	(DPAA2_ETH_CN_THRESH_ENTRY(priv) * 3 / 4)

85 86 87 88 89
/* Maximum number of buffers that can be acquired/released through a single
 * QBMan command
 */
#define DPAA2_ETH_BUFS_PER_CMD		7

90
/* Hardware requires alignment for ingress/egress buffer addresses */
91
#define DPAA2_ETH_TX_BUF_ALIGN		64
92

93 94 95 96 97
#define DPAA2_ETH_RX_BUF_RAW_SIZE	PAGE_SIZE
#define DPAA2_ETH_RX_BUF_TAILROOM \
	SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
#define DPAA2_ETH_RX_BUF_SIZE \
	(DPAA2_ETH_RX_BUF_RAW_SIZE - DPAA2_ETH_RX_BUF_TAILROOM)
98

99
/* Hardware annotation area in RX/TX buffers */
100
#define DPAA2_ETH_RX_HWA_SIZE		64
101 102 103 104
#define DPAA2_ETH_TX_HWA_SIZE		128

/* PTP nominal frequency 1GHz */
#define DPAA2_PTP_CLK_PERIOD_NS		1
105

106 107
/* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned
 * to 256B. For newer revisions, the requirement is only for 64B alignment
108
 */
109 110
#define DPAA2_ETH_RX_BUF_ALIGN_REV1	256
#define DPAA2_ETH_RX_BUF_ALIGN		64
111 112 113 114 115 116 117

/* We are accommodating a skb backpointer and some S/G info
 * in the frame's software annotation. The hardware
 * options are either 0 or 64, so we choose the latter.
 */
#define DPAA2_ETH_SWA_SIZE		64

118 119 120 121 122 123
/* We store different information in the software annotation area of a Tx frame
 * based on what type of frame it is
 */
enum dpaa2_eth_swa_type {
	DPAA2_ETH_SWA_SINGLE,
	DPAA2_ETH_SWA_SG,
124
	DPAA2_ETH_SWA_XDP,
125
	DPAA2_ETH_SWA_SW_TSO,
126 127
};

128 129
/* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */
struct dpaa2_eth_swa {
130 131 132 133
	enum dpaa2_eth_swa_type type;
	union {
		struct {
			struct sk_buff *skb;
134
			int sgt_size;
135 136 137 138 139 140 141
		} single;
		struct {
			struct sk_buff *skb;
			struct scatterlist *scl;
			int num_sg;
			int sgt_size;
		} sg;
142 143 144 145
		struct {
			int dma_size;
			struct xdp_frame *xdpf;
		} xdp;
146 147 148 149 150 151
		struct {
			struct sk_buff *skb;
			int num_sg;
			int sgt_size;
			int is_last_fd;
		} tso;
152
	};
153 154 155 156 157 158 159 160 161 162
};

/* Annotation valid bits in FD FRC */
#define DPAA2_FD_FRC_FASV		0x8000
#define DPAA2_FD_FRC_FAEADV		0x4000
#define DPAA2_FD_FRC_FAPRV		0x2000
#define DPAA2_FD_FRC_FAIADV		0x1000
#define DPAA2_FD_FRC_FASWOV		0x0800
#define DPAA2_FD_FRC_FAICFDV		0x0400

163
/* Error bits in FD CTRL */
164 165 166 167 168
#define DPAA2_FD_RX_ERR_MASK		(FD_CTRL_SBE | FD_CTRL_FAERR)
#define DPAA2_FD_TX_ERR_MASK		(FD_CTRL_UFD	| \
					 FD_CTRL_SBE	| \
					 FD_CTRL_FSE	| \
					 FD_CTRL_FAERR)
169

170
/* Annotation bits in FD CTRL */
171
#define DPAA2_FD_CTRL_ASAL		0x00020000	/* ASAL = 128B */
172 173 174 175 176 177 178

/* Frame annotation status */
struct dpaa2_fas {
	u8 reserved;
	u8 ppid;
	__le16 ifpid;
	__le32 status;
179
};
180 181 182 183 184 185 186

/* Frame annotation status word is located in the first 8 bytes
 * of the buffer's hardware annoatation area
 */
#define DPAA2_FAS_OFFSET		0
#define DPAA2_FAS_SIZE			(sizeof(struct dpaa2_fas))

187 188 189 190 191
/* Timestamp is located in the next 8 bytes of the buffer's
 * hardware annotation area
 */
#define DPAA2_TS_OFFSET			0x8

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
/* Frame annotation parse results */
struct dpaa2_fapr {
	/* 64-bit word 1 */
	__le32 faf_lo;
	__le16 faf_ext;
	__le16 nxt_hdr;
	/* 64-bit word 2 */
	__le64 faf_hi;
	/* 64-bit word 3 */
	u8 last_ethertype_offset;
	u8 vlan_tci_offset_n;
	u8 vlan_tci_offset_1;
	u8 llc_snap_offset;
	u8 eth_offset;
	u8 ip1_pid_offset;
	u8 shim_offset_2;
	u8 shim_offset_1;
	/* 64-bit word 4 */
	u8 l5_offset;
	u8 l4_offset;
	u8 gre_offset;
	u8 l3_offset_n;
	u8 l3_offset_1;
	u8 mpls_offset_n;
	u8 mpls_offset_1;
	u8 pppoe_offset;
	/* 64-bit word 5 */
	__le16 running_sum;
	__le16 gross_running_sum;
	u8 ipv6_frag_offset;
	u8 nxt_hdr_offset;
	u8 routing_hdr_offset_2;
	u8 routing_hdr_offset_1;
	/* 64-bit word 6 */
	u8 reserved[5]; /* Soft-parsing context */
	u8 ip_proto_offset_n;
	u8 nxt_hdr_frag_offset;
	u8 parse_error_code;
};

#define DPAA2_FAPR_OFFSET		0x10
#define DPAA2_FAPR_SIZE			sizeof((struct dpaa2_fapr))

235 236 237 238 239 240 241 242 243
/* Frame annotation egress action descriptor */
#define DPAA2_FAEAD_OFFSET		0x58

struct dpaa2_faead {
	__le32 conf_fqid;
	__le32 ctrl;
};

#define DPAA2_FAEAD_A2V			0x20000000
244
#define DPAA2_FAEAD_A4V			0x08000000
245
#define DPAA2_FAEAD_UPDV		0x00001000
246
#define DPAA2_FAEAD_EBDDV		0x00002000
247 248
#define DPAA2_FAEAD_UPD			0x00000010

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
struct ptp_tstamp {
	u16 sec_msb;
	u32 sec_lsb;
	u32 nsec;
};

static inline void ns_to_ptp_tstamp(struct ptp_tstamp *tstamp, u64 ns)
{
	u64 sec, nsec;

	sec = ns;
	nsec = do_div(sec, 1000000000);

	tstamp->sec_lsb = sec & 0xFFFFFFFF;
	tstamp->sec_msb = (sec >> 32) & 0xFFFF;
	tstamp->nsec = nsec;
}

267
/* Accessors for the hardware annotation fields that we use */
268 269 270 271 272 273 274 275 276
static inline void *dpaa2_get_hwa(void *buf_addr, bool swa)
{
	return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0);
}

static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa)
{
	return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET;
}
277

278 279 280 281 282
static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa)
{
	return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET;
}

283 284 285 286 287
static inline struct dpaa2_fapr *dpaa2_get_fapr(void *buf_addr, bool swa)
{
	return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAPR_OFFSET;
}

288 289 290 291 292
static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa)
{
	return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET;
}

293 294 295 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 321 322 323 324
/* Error and status bits in the frame annotation status word */
/* Debug frame, otherwise supposed to be discarded */
#define DPAA2_FAS_DISC			0x80000000
/* MACSEC frame */
#define DPAA2_FAS_MS			0x40000000
#define DPAA2_FAS_PTP			0x08000000
/* Ethernet multicast frame */
#define DPAA2_FAS_MC			0x04000000
/* Ethernet broadcast frame */
#define DPAA2_FAS_BC			0x02000000
#define DPAA2_FAS_KSE			0x00040000
#define DPAA2_FAS_EOFHE			0x00020000
#define DPAA2_FAS_MNLE			0x00010000
#define DPAA2_FAS_TIDE			0x00008000
#define DPAA2_FAS_PIEE			0x00004000
/* Frame length error */
#define DPAA2_FAS_FLE			0x00002000
/* Frame physical error */
#define DPAA2_FAS_FPE			0x00001000
#define DPAA2_FAS_PTE			0x00000080
#define DPAA2_FAS_ISP			0x00000040
#define DPAA2_FAS_PHE			0x00000020
#define DPAA2_FAS_BLE			0x00000010
/* L3 csum validation performed */
#define DPAA2_FAS_L3CV			0x00000008
/* L3 csum error */
#define DPAA2_FAS_L3CE			0x00000004
/* L4 csum validation performed */
#define DPAA2_FAS_L4CV			0x00000002
/* L4 csum error */
#define DPAA2_FAS_L4CE			0x00000001
/* Possible errors on the ingress path */
325
#define DPAA2_FAS_RX_ERR_MASK		(DPAA2_FAS_KSE		| \
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
					 DPAA2_FAS_EOFHE	| \
					 DPAA2_FAS_MNLE		| \
					 DPAA2_FAS_TIDE		| \
					 DPAA2_FAS_PIEE		| \
					 DPAA2_FAS_FLE		| \
					 DPAA2_FAS_FPE		| \
					 DPAA2_FAS_PTE		| \
					 DPAA2_FAS_ISP		| \
					 DPAA2_FAS_PHE		| \
					 DPAA2_FAS_BLE		| \
					 DPAA2_FAS_L3CE		| \
					 DPAA2_FAS_L4CE)

/* Time in milliseconds between link state updates */
#define DPAA2_ETH_LINK_STATE_REFRESH	1000

/* Number of times to retry a frame enqueue before giving up.
 * Value determined empirically, in order to minimize the number
 * of frames dropped on Tx
 */
#define DPAA2_ETH_ENQUEUE_RETRIES	10

348 349 350 351 352 353 354 355
/* Number of times to retry DPIO portal operations while waiting
 * for portal to finish executing current command and become
 * available. We want to avoid being stuck in a while loop in case
 * hardware becomes unresponsive, but not give up too easily if
 * the portal really is busy for valid reasons
 */
#define DPAA2_ETH_SWP_BUSY_RETRIES	1000

356 357 358 359 360 361 362 363
/* Driver statistics, other than those in struct rtnl_link_stats64.
 * These are usually collected per-CPU and aggregated by ethtool.
 */
struct dpaa2_eth_drv_stats {
	__u64	tx_conf_frames;
	__u64	tx_conf_bytes;
	__u64	tx_sg_frames;
	__u64	tx_sg_bytes;
364 365
	__u64	tx_tso_frames;
	__u64	tx_tso_bytes;
366 367
	__u64	rx_sg_frames;
	__u64	rx_sg_bytes;
368 369 370
	/* Linear skbs sent as a S/G FD due to insufficient headroom */
	__u64	tx_converted_sg_frames;
	__u64	tx_converted_sg_bytes;
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
	/* Enqueues retried due to portal busy */
	__u64	tx_portal_busy;
};

/* Per-FQ statistics */
struct dpaa2_eth_fq_stats {
	/* Number of frames received on this queue */
	__u64 frames;
};

/* Per-channel statistics */
struct dpaa2_eth_ch_stats {
	/* Volatile dequeues retried due to portal busy */
	__u64 dequeue_portal_busy;
	/* Pull errors */
	__u64 pull_err;
387 388
	/* Number of CDANs; useful to estimate avg NAPI len */
	__u64 cdan;
389 390 391 392
	/* XDP counters */
	__u64 xdp_drop;
	__u64 xdp_tx;
	__u64 xdp_tx_err;
393
	__u64 xdp_redirect;
394 395
	/* Must be last, does not show up in ethtool stats */
	__u64 frames;
396 397
	__u64 frames_per_cdan;
	__u64 bytes_per_cdan;
398 399
};

I
Ioana Ciornei 已提交
400 401
#define DPAA2_ETH_CH_STATS	7

402
/* Maximum number of queues associated with a DPNI */
403
#define DPAA2_ETH_MAX_TCS		8
404 405 406
#define DPAA2_ETH_MAX_RX_QUEUES_PER_TC	16
#define DPAA2_ETH_MAX_RX_QUEUES		\
	(DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS)
407
#define DPAA2_ETH_MAX_TX_QUEUES		16
408
#define DPAA2_ETH_MAX_RX_ERR_QUEUES	1
409
#define DPAA2_ETH_MAX_QUEUES		(DPAA2_ETH_MAX_RX_QUEUES + \
410 411
					DPAA2_ETH_MAX_TX_QUEUES + \
					DPAA2_ETH_MAX_RX_ERR_QUEUES)
I
Ioana Radulescu 已提交
412 413
#define DPAA2_ETH_MAX_NETDEV_QUEUES	\
	(DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS)
414

415
#define DPAA2_ETH_MAX_DPCONS		16
416 417 418 419

enum dpaa2_eth_fq_type {
	DPAA2_RX_FQ = 0,
	DPAA2_TX_CONF_FQ,
420
	DPAA2_RX_ERR_FQ
421 422 423 424
};

struct dpaa2_eth_priv;

425 426 427 428 429
struct dpaa2_eth_xdp_fds {
	struct dpaa2_fd fds[DEV_MAP_BULK_SIZE];
	ssize_t num;
};

430 431 432
struct dpaa2_eth_fq {
	u32 fqid;
	u32 tx_qdbin;
433
	u32 tx_fqid[DPAA2_ETH_MAX_TCS];
434
	u16 flowid;
435
	u8 tc;
436
	int target_cpu;
I
Ioana Ciocoi Radulescu 已提交
437 438
	u32 dq_frames;
	u32 dq_bytes;
439 440 441
	struct dpaa2_eth_channel *channel;
	enum dpaa2_eth_fq_type type;

442 443 444
	void (*consume)(struct dpaa2_eth_priv *priv,
			struct dpaa2_eth_channel *ch,
			const struct dpaa2_fd *fd,
445
			struct dpaa2_eth_fq *fq);
446
	struct dpaa2_eth_fq_stats stats;
447

448
	struct dpaa2_eth_xdp_fds xdp_redirect_fds;
I
Ioana Ciornei 已提交
449
	struct dpaa2_eth_xdp_fds xdp_tx_fds;
450 451
};

452 453
struct dpaa2_eth_ch_xdp {
	struct bpf_prog *prog;
454
	unsigned int res;
455 456
};

457 458 459 460 461 462
struct dpaa2_eth_channel {
	struct dpaa2_io_notification_ctx nctx;
	struct fsl_mc_device *dpcon;
	int dpcon_id;
	int ch_id;
	struct napi_struct napi;
463
	struct dpaa2_io *dpio;
464 465 466
	struct dpaa2_io_store *store;
	struct dpaa2_eth_priv *priv;
	int buf_count;
467
	struct dpaa2_eth_ch_stats stats;
468
	struct dpaa2_eth_ch_xdp xdp;
469
	struct xdp_rxq_info xdp_rxq;
470
	struct list_head *rx_list;
471 472 473 474

	/* Buffers to be recycled back in the buffer pool */
	u64 recycled_bufs[DPAA2_ETH_BUFS_PER_CMD];
	int recycled_bufs_cnt;
475 476
};

I
Ioana Radulescu 已提交
477
struct dpaa2_eth_dist_fields {
478 479 480 481
	u64 rxnfc_field;
	enum net_prot cls_prot;
	int cls_field;
	int size;
482
	u64 id;
483 484
};

485 486 487 488 489
struct dpaa2_eth_cls_rule {
	struct ethtool_rx_flow_spec fs;
	u8 in_use;
};

490 491 492 493 494 495
#define DPAA2_ETH_SGT_CACHE_SIZE	256
struct dpaa2_eth_sgt_cache {
	void *buf[DPAA2_ETH_SGT_CACHE_SIZE];
	u16 count;
};

496 497 498 499 500 501 502 503 504
struct dpaa2_eth_trap_item {
	void *trap_ctx;
};

struct dpaa2_eth_trap_data {
	struct dpaa2_eth_trap_item *trap_items_arr;
	struct dpaa2_eth_priv *priv;
};

505 506
#define DPAA2_ETH_SG_ENTRIES_MAX	(PAGE_SIZE / sizeof(struct scatterlist))

507 508
#define DPAA2_ETH_DEFAULT_COPYBREAK	512

509 510 511 512 513
#define DPAA2_ETH_ENQUEUE_MAX_FDS	200
struct dpaa2_eth_fds {
	struct dpaa2_fd array[DPAA2_ETH_ENQUEUE_MAX_FDS];
};

514 515 516 517 518 519
/* Driver private data */
struct dpaa2_eth_priv {
	struct net_device *net_dev;

	u8 num_fqs;
	struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES];
520 521
	int (*enqueue)(struct dpaa2_eth_priv *priv,
		       struct dpaa2_eth_fq *fq,
522
		       struct dpaa2_fd *fd, u8 prio,
523
		       u32 num_frames,
524
		       int *frames_enqueued);
525 526 527

	u8 num_channels;
	struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS];
528
	struct dpaa2_eth_sgt_cache __percpu *sgt_cache;
529 530

	struct dpni_attr dpni_attrs;
531 532
	u16 dpni_ver_major;
	u16 dpni_ver_minor;
533 534 535
	u16 tx_data_offset;

	struct fsl_mc_device *dpbp_dev;
536
	u16 rx_buf_size;
537
	u16 bpid;
538
	struct iommu_domain *iommu_domain;
539

540 541
	enum hwtstamp_tx_types tx_tstamp_type;	/* Tx timestamping type */
	bool rx_tstamp;				/* Rx timestamping enabled */
542

543 544 545 546 547 548 549 550 551
	u16 tx_qdid;
	struct fsl_mc_io *mc_io;
	/* Cores which have an affine DPIO/DPCON.
	 * This is the cpu set on which Rx and Tx conf frames are processed
	 */
	struct cpumask dpio_cpumask;

	/* Standard statistics */
	struct rtnl_link_stats64 __percpu *percpu_stats;
552 553
	/* Extra stats, in addition to the ones known by the kernel */
	struct dpaa2_eth_drv_stats __percpu *percpu_extras;
554 555

	u16 mc_token;
556 557
	u8 rx_fqtd_enabled;
	u8 rx_cgtd_enabled;
558 559 560 561

	struct dpni_link_state link_state;
	bool do_link_poll;
	struct task_struct *poll_thread;
562 563 564

	/* enabled ethtool hashing bits */
	u64 rx_hash_fields;
565
	u64 rx_cls_fields;
566
	struct dpaa2_eth_cls_rule *cls_rules;
567
	u8 rx_cls_enabled;
568
	u8 vlan_cls_enabled;
569
	u8 pfc_enabled;
570 571 572 573
#ifdef CONFIG_FSL_DPAA2_ETH_DCB
	u8 dcbx_mode;
	struct ieee_pfc pfc;
#endif
574
	struct bpf_prog *xdp_prog;
575 576 577
#ifdef CONFIG_DEBUG_FS
	struct dpaa2_debugfs dbg;
#endif
578 579

	struct dpaa2_mac *mac;
580 581 582 583 584 585 586 587 588 589 590
	struct workqueue_struct	*dpaa2_ptp_wq;
	struct work_struct	tx_onestep_tstamp;
	struct sk_buff_head	tx_skbs;
	/* The one-step timestamping configuration on hardware
	 * registers could only be done when no one-step
	 * timestamping frames are in flight. So we use a mutex
	 * lock here to make sure the lock is released by last
	 * one-step timestamping packet through TX confirmation
	 * queue before transmit current packet.
	 */
	struct mutex		onestep_tstamp_lock;
591
	struct devlink *devlink;
592
	struct dpaa2_eth_trap_data *trap_data;
593
	struct devlink_port devlink_port;
594 595

	u32 rx_copybreak;
596 597

	struct dpaa2_eth_fds __percpu *fd;
598 599 600 601
};

struct dpaa2_eth_devlink_priv {
	struct dpaa2_eth_priv *dpaa2_priv;
602 603
};

604
#define TX_TSTAMP		0x1
605
#define TX_TSTAMP_ONESTEP_SYNC	0x2
606

607 608 609 610
#define DPAA2_RXH_SUPPORTED	(RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \
				| RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \
				| RXH_L4_B_2_3)

611 612 613 614
/* default Rx hash options, set during probing */
#define DPAA2_RXH_DEFAULT	(RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \
				 RXH_L4_B_0_1 | RXH_L4_B_2_3)

615 616 617 618 619 620
#define dpaa2_eth_hash_enabled(priv)	\
	((priv)->dpni_attrs.num_queues > 1)

/* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */
#define DPAA2_CLASSIFIER_DMA_SIZE 256

621
extern const struct ethtool_ops dpaa2_ethtool_ops;
622
extern int dpaa2_phc_index;
623
extern struct ptp_qoriq *dpaa2_ptp;
624

625 626 627 628 629 630 631 632
static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv,
					 u16 ver_major, u16 ver_minor)
{
	if (priv->dpni_ver_major == ver_major)
		return priv->dpni_ver_minor - ver_minor;
	return priv->dpni_ver_major - ver_major;
}

633 634 635 636 637 638 639 640 641 642
/* Minimum firmware version that supports a more flexible API
 * for configuring the Rx flow hash key
 */
#define DPNI_RX_DIST_KEY_VER_MAJOR	7
#define DPNI_RX_DIST_KEY_VER_MINOR	5

#define dpaa2_eth_has_legacy_dist(priv)					\
	(dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR,	\
				DPNI_RX_DIST_KEY_VER_MINOR) < 0)

643 644 645 646 647 648
#define dpaa2_eth_fs_enabled(priv)	\
	(!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS))

#define dpaa2_eth_fs_mask_enabled(priv)	\
	((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING)

649 650 651
#define dpaa2_eth_fs_count(priv)        \
	((priv)->dpni_attrs.fs_entries)

652 653 654
#define dpaa2_eth_tc_count(priv)	\
	((priv)->dpni_attrs.num_tcs)

655 656 657 658
/* We have exactly one {Rx, Tx conf} queue per channel */
#define dpaa2_eth_queue_count(priv)     \
	((priv)->num_channels)

659 660 661 662 663
enum dpaa2_eth_rx_dist {
	DPAA2_ETH_RX_DIST_HASH,
	DPAA2_ETH_RX_DIST_CLS
};

664 665 666 667 668 669 670 671 672 673
/* Unique IDs for the supported Rx classification header fields */
#define DPAA2_ETH_DIST_ETHDST		BIT(0)
#define DPAA2_ETH_DIST_ETHSRC		BIT(1)
#define DPAA2_ETH_DIST_ETHTYPE		BIT(2)
#define DPAA2_ETH_DIST_VLAN		BIT(3)
#define DPAA2_ETH_DIST_IPSRC		BIT(4)
#define DPAA2_ETH_DIST_IPDST		BIT(5)
#define DPAA2_ETH_DIST_IPPROTO		BIT(6)
#define DPAA2_ETH_DIST_L4SRC		BIT(7)
#define DPAA2_ETH_DIST_L4DST		BIT(8)
674
#define DPAA2_ETH_DIST_ALL		(~0ULL)
675

676 677 678 679 680 681
#define DPNI_PAUSE_VER_MAJOR		7
#define DPNI_PAUSE_VER_MINOR		13
#define dpaa2_eth_has_pause_support(priv)			\
	(dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR,	\
				DPNI_PAUSE_VER_MINOR) >= 0)

682 683 684 685 686 687 688 689 690 691 692
static inline bool dpaa2_eth_tx_pause_enabled(u64 link_options)
{
	return !!(link_options & DPNI_LINK_OPT_PAUSE) ^
	       !!(link_options & DPNI_LINK_OPT_ASYM_PAUSE);
}

static inline bool dpaa2_eth_rx_pause_enabled(u64 link_options)
{
	return !!(link_options & DPNI_LINK_OPT_PAUSE);
}

693
static inline unsigned int dpaa2_eth_needed_headroom(struct sk_buff *skb)
694
{
695 696
	unsigned int headroom = DPAA2_ETH_SWA_SIZE;

697 698 699 700 701 702
	/* If we don't have an skb (e.g. XDP buffer), we only need space for
	 * the software annotation area
	 */
	if (!skb)
		return headroom;

703 704 705
	/* For non-linear skbs we have no headroom requirement, as we build a
	 * SG frame with a newly allocated SGT buffer
	 */
706 707 708
	if (skb_is_nonlinear(skb))
		return 0;

709
	/* If we have Tx timestamping, need 128B hardware annotation */
710
	if (skb->cb[0])
711 712 713
		headroom += DPAA2_ETH_TX_HWA_SIZE;

	return headroom;
714 715 716 717 718 719 720
}

/* Extra headroom space requested to hardware, in order to make sure there's
 * no realloc'ing in forwarding scenarios
 */
static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv)
{
721
	return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE;
722 723
}

724 725
static inline bool dpaa2_eth_is_type_phy(struct dpaa2_eth_priv *priv)
{
726 727 728
	if (priv->mac &&
	    (priv->mac->attr.link_type == DPMAC_LINK_TYPE_PHY ||
	     priv->mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE))
729 730 731 732 733 734 735 736 737 738
		return true;

	return false;
}

static inline bool dpaa2_eth_has_mac(struct dpaa2_eth_priv *priv)
{
	return priv->mac ? true : false;
}

739
int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags);
740 741
int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key);
int dpaa2_eth_cls_key_size(u64 key);
742
int dpaa2_eth_cls_fld_off(int prot, int field);
743
void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields);
744

745 746 747
void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv,
			       bool tx_pause, bool pfc);

748 749
extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops;

750 751 752 753
int dpaa2_eth_dl_alloc(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_free(struct dpaa2_eth_priv *priv);

void dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv);
754 755 756 757 758
void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv);

int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv);

759 760 761 762 763
int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv);
void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv);

struct dpaa2_eth_trap_item *dpaa2_eth_dl_get_trap(struct dpaa2_eth_priv *priv,
						  struct dpaa2_fapr *fapr);
764
#endif	/* __DPAA2_H */