134ff6846SIoana Radulescu /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 234ff6846SIoana Radulescu /* Copyright 2014-2016 Freescale Semiconductor Inc. 3*095174daSRobert-Ionut Alexa * Copyright 2016-2022 NXP 434ff6846SIoana Radulescu */ 534ff6846SIoana Radulescu 634ff6846SIoana Radulescu #ifndef __DPAA2_ETH_H 734ff6846SIoana Radulescu #define __DPAA2_ETH_H 834ff6846SIoana Radulescu 9f395b69fSIoana Ciornei #include <linux/dcbnl.h> 1034ff6846SIoana Radulescu #include <linux/netdevice.h> 1134ff6846SIoana Radulescu #include <linux/if_vlan.h> 1234ff6846SIoana Radulescu #include <linux/fsl/mc.h> 131cf773bdSYangbo Lu #include <linux/net_tstamp.h> 14ceeb03adSIoana Ciornei #include <net/devlink.h> 1534ff6846SIoana Radulescu 1634ff6846SIoana Radulescu #include <soc/fsl/dpaa2-io.h> 1734ff6846SIoana Radulescu #include <soc/fsl/dpaa2-fd.h> 1834ff6846SIoana Radulescu #include "dpni.h" 1934ff6846SIoana Radulescu #include "dpni-cmd.h" 2034ff6846SIoana Radulescu 2134ff6846SIoana Radulescu #include "dpaa2-eth-trace.h" 22091a19eaSIoana Radulescu #include "dpaa2-eth-debugfs.h" 2371947923SIoana Ciornei #include "dpaa2-mac.h" 2434ff6846SIoana Radulescu 2534ff6846SIoana Radulescu #define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0) 2634ff6846SIoana Radulescu 2734ff6846SIoana Radulescu #define DPAA2_ETH_STORE_SIZE 16 2834ff6846SIoana Radulescu 2934ff6846SIoana Radulescu /* Maximum number of scatter-gather entries in an ingress frame, 3034ff6846SIoana Radulescu * considering the maximum receive frame size is 64K 3134ff6846SIoana Radulescu */ 3234ff6846SIoana Radulescu #define DPAA2_ETH_MAX_SG_ENTRIES ((64 * 1024) / DPAA2_ETH_RX_BUF_SIZE) 3334ff6846SIoana Radulescu 3434ff6846SIoana Radulescu /* Maximum acceptable MTU value. It is in direct relation with the hardware 3534ff6846SIoana Radulescu * enforced Max Frame Length (currently 10k). 3634ff6846SIoana Radulescu */ 3734ff6846SIoana Radulescu #define DPAA2_ETH_MFL (10 * 1024) 3834ff6846SIoana Radulescu #define DPAA2_ETH_MAX_MTU (DPAA2_ETH_MFL - VLAN_ETH_HLEN) 3934ff6846SIoana Radulescu /* Convert L3 MTU to L2 MFL */ 4034ff6846SIoana Radulescu #define DPAA2_ETH_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN) 4134ff6846SIoana Radulescu 423f8b826dSIoana Radulescu /* Set the taildrop threshold (in bytes) to allow the enqueue of a large 433f8b826dSIoana Radulescu * enough number of jumbo frames in the Rx queues (length of the current 443f8b826dSIoana Radulescu * frame is not taken into account when making the taildrop decision) 4534ff6846SIoana Radulescu */ 463f8b826dSIoana Radulescu #define DPAA2_ETH_FQ_TAILDROP_THRESH (1024 * 1024) 4734ff6846SIoana Radulescu 483657cdafSIoana Ciornei /* Maximum burst size value for Tx shaping */ 493657cdafSIoana Ciornei #define DPAA2_ETH_MAX_BURST_SIZE 0xF7FF 503657cdafSIoana Ciornei 5168049a5fSIoana Ciocoi Radulescu /* Maximum number of Tx confirmation frames to be processed 5268049a5fSIoana Ciocoi Radulescu * in a single NAPI call 5368049a5fSIoana Ciocoi Radulescu */ 5468049a5fSIoana Ciocoi Radulescu #define DPAA2_ETH_TXCONF_PER_NAPI 256 5568049a5fSIoana Ciocoi Radulescu 563f8b826dSIoana Radulescu /* Buffer qouta per channel. We want to keep in check number of ingress frames 573f8b826dSIoana Radulescu * in flight: for small sized frames, congestion group taildrop may kick in 583f8b826dSIoana Radulescu * first; for large sizes, Rx FQ taildrop threshold will ensure only a 593f8b826dSIoana Radulescu * reasonable number of frames will be pending at any given time. 603f8b826dSIoana Radulescu * Ingress frame drop due to buffer pool depletion should be a corner case only 6134ff6846SIoana Radulescu */ 623f8b826dSIoana Radulescu #define DPAA2_ETH_NUM_BUFS 1280 6320fb0572SIoana Ciocoi Radulescu #define DPAA2_ETH_REFILL_THRESH \ 6420fb0572SIoana Ciocoi Radulescu (DPAA2_ETH_NUM_BUFS - DPAA2_ETH_BUFS_PER_CMD) 6534ff6846SIoana Radulescu 662c8d1c8dSIoana Radulescu /* Congestion group taildrop threshold: number of frames allowed to accumulate 672c8d1c8dSIoana Radulescu * at any moment in a group of Rx queues belonging to the same traffic class. 682c8d1c8dSIoana Radulescu * Choose value such that we don't risk depleting the buffer pool before the 692c8d1c8dSIoana Radulescu * taildrop kicks in 702c8d1c8dSIoana Radulescu */ 712c8d1c8dSIoana Radulescu #define DPAA2_ETH_CG_TAILDROP_THRESH(priv) \ 723f8b826dSIoana Radulescu (1024 * dpaa2_eth_queue_count(priv) / dpaa2_eth_tc_count(priv)) 732c8d1c8dSIoana Radulescu 74f395b69fSIoana Ciornei /* Congestion group notification threshold: when this many frames accumulate 75f395b69fSIoana Ciornei * on the Rx queues belonging to the same TC, the MAC is instructed to send 76f395b69fSIoana Ciornei * PFC frames for that TC. 77f395b69fSIoana Ciornei * When number of pending frames drops below exit threshold transmission of 78f395b69fSIoana Ciornei * PFC frames is stopped. 79f395b69fSIoana Ciornei */ 80f395b69fSIoana Ciornei #define DPAA2_ETH_CN_THRESH_ENTRY(priv) \ 81f395b69fSIoana Ciornei (DPAA2_ETH_CG_TAILDROP_THRESH(priv) / 2) 82f395b69fSIoana Ciornei #define DPAA2_ETH_CN_THRESH_EXIT(priv) \ 83f395b69fSIoana Ciornei (DPAA2_ETH_CN_THRESH_ENTRY(priv) * 3 / 4) 84f395b69fSIoana Ciornei 8534ff6846SIoana Radulescu /* Maximum number of buffers that can be acquired/released through a single 8634ff6846SIoana Radulescu * QBMan command 8734ff6846SIoana Radulescu */ 8834ff6846SIoana Radulescu #define DPAA2_ETH_BUFS_PER_CMD 7 8934ff6846SIoana Radulescu 9034ff6846SIoana Radulescu /* Hardware requires alignment for ingress/egress buffer addresses */ 9134ff6846SIoana Radulescu #define DPAA2_ETH_TX_BUF_ALIGN 64 9234ff6846SIoana Radulescu 9327c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_RAW_SIZE PAGE_SIZE 9427c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_TAILROOM \ 9527c87486SIoana Ciocoi Radulescu SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) 9627c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_SIZE \ 9727c87486SIoana Ciocoi Radulescu (DPAA2_ETH_RX_BUF_RAW_SIZE - DPAA2_ETH_RX_BUF_TAILROOM) 9834ff6846SIoana Radulescu 9934ff6846SIoana Radulescu /* Hardware annotation area in RX/TX buffers */ 10034ff6846SIoana Radulescu #define DPAA2_ETH_RX_HWA_SIZE 64 10134ff6846SIoana Radulescu #define DPAA2_ETH_TX_HWA_SIZE 128 10234ff6846SIoana Radulescu 10334ff6846SIoana Radulescu /* PTP nominal frequency 1GHz */ 10434ff6846SIoana Radulescu #define DPAA2_PTP_CLK_PERIOD_NS 1 10534ff6846SIoana Radulescu 10634ff6846SIoana Radulescu /* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned 10734ff6846SIoana Radulescu * to 256B. For newer revisions, the requirement is only for 64B alignment 10834ff6846SIoana Radulescu */ 10934ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN_REV1 256 11034ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN 64 11134ff6846SIoana Radulescu 112*095174daSRobert-Ionut Alexa /* The firmware allows assigning multiple buffer pools to a single DPNI - 113*095174daSRobert-Ionut Alexa * maximum 8 DPBP objects. By default, only the first DPBP (idx 0) is used for 114*095174daSRobert-Ionut Alexa * all queues. Thus, when enabling AF_XDP we must accommodate up to 9 DPBPs 115*095174daSRobert-Ionut Alexa * object: the default and 8 other distinct buffer pools, one for each queue. 116*095174daSRobert-Ionut Alexa */ 117*095174daSRobert-Ionut Alexa #define DPAA2_ETH_DEFAULT_BP_IDX 0 118*095174daSRobert-Ionut Alexa #define DPAA2_ETH_MAX_BPS 9 119*095174daSRobert-Ionut Alexa 12034ff6846SIoana Radulescu /* We are accommodating a skb backpointer and some S/G info 12134ff6846SIoana Radulescu * in the frame's software annotation. The hardware 12234ff6846SIoana Radulescu * options are either 0 or 64, so we choose the latter. 12334ff6846SIoana Radulescu */ 12434ff6846SIoana Radulescu #define DPAA2_ETH_SWA_SIZE 64 12534ff6846SIoana Radulescu 126e3fdf6baSIoana Radulescu /* We store different information in the software annotation area of a Tx frame 127e3fdf6baSIoana Radulescu * based on what type of frame it is 128e3fdf6baSIoana Radulescu */ 129e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type { 130e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SINGLE, 131e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SG, 132d678be1dSIoana Radulescu DPAA2_ETH_SWA_XDP, 1333dc709e0SIoana Ciornei DPAA2_ETH_SWA_SW_TSO, 134e3fdf6baSIoana Radulescu }; 135e3fdf6baSIoana Radulescu 13634ff6846SIoana Radulescu /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */ 13734ff6846SIoana Radulescu struct dpaa2_eth_swa { 138e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type type; 139e3fdf6baSIoana Radulescu union { 140e3fdf6baSIoana Radulescu struct { 141e3fdf6baSIoana Radulescu struct sk_buff *skb; 142d70446eeSIoana Ciornei int sgt_size; 143e3fdf6baSIoana Radulescu } single; 144e3fdf6baSIoana Radulescu struct { 14534ff6846SIoana Radulescu struct sk_buff *skb; 14634ff6846SIoana Radulescu struct scatterlist *scl; 14734ff6846SIoana Radulescu int num_sg; 14834ff6846SIoana Radulescu int sgt_size; 149e3fdf6baSIoana Radulescu } sg; 150d678be1dSIoana Radulescu struct { 151d678be1dSIoana Radulescu int dma_size; 152d678be1dSIoana Radulescu struct xdp_frame *xdpf; 153d678be1dSIoana Radulescu } xdp; 1543dc709e0SIoana Ciornei struct { 1553dc709e0SIoana Ciornei struct sk_buff *skb; 1563dc709e0SIoana Ciornei int num_sg; 1573dc709e0SIoana Ciornei int sgt_size; 1583dc709e0SIoana Ciornei int is_last_fd; 1593dc709e0SIoana Ciornei } tso; 160e3fdf6baSIoana Radulescu }; 16134ff6846SIoana Radulescu }; 16234ff6846SIoana Radulescu 16334ff6846SIoana Radulescu /* Annotation valid bits in FD FRC */ 16434ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASV 0x8000 16534ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAEADV 0x4000 16634ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAPRV 0x2000 16734ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAIADV 0x1000 16834ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASWOV 0x0800 16934ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAICFDV 0x0400 17034ff6846SIoana Radulescu 17134ff6846SIoana Radulescu /* Error bits in FD CTRL */ 17234ff6846SIoana Radulescu #define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR) 17334ff6846SIoana Radulescu #define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \ 17434ff6846SIoana Radulescu FD_CTRL_SBE | \ 17534ff6846SIoana Radulescu FD_CTRL_FSE | \ 17634ff6846SIoana Radulescu FD_CTRL_FAERR) 17734ff6846SIoana Radulescu 17834ff6846SIoana Radulescu /* Annotation bits in FD CTRL */ 17934ff6846SIoana Radulescu #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128B */ 18034ff6846SIoana Radulescu 18134ff6846SIoana Radulescu /* Frame annotation status */ 18234ff6846SIoana Radulescu struct dpaa2_fas { 18334ff6846SIoana Radulescu u8 reserved; 18434ff6846SIoana Radulescu u8 ppid; 18534ff6846SIoana Radulescu __le16 ifpid; 18634ff6846SIoana Radulescu __le32 status; 18734ff6846SIoana Radulescu }; 18834ff6846SIoana Radulescu 18934ff6846SIoana Radulescu /* Frame annotation status word is located in the first 8 bytes 19034ff6846SIoana Radulescu * of the buffer's hardware annoatation area 19134ff6846SIoana Radulescu */ 19234ff6846SIoana Radulescu #define DPAA2_FAS_OFFSET 0 19334ff6846SIoana Radulescu #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas)) 19434ff6846SIoana Radulescu 19534ff6846SIoana Radulescu /* Timestamp is located in the next 8 bytes of the buffer's 19634ff6846SIoana Radulescu * hardware annotation area 19734ff6846SIoana Radulescu */ 19834ff6846SIoana Radulescu #define DPAA2_TS_OFFSET 0x8 19934ff6846SIoana Radulescu 200061d631fSIoana Ciornei /* Frame annotation parse results */ 201061d631fSIoana Ciornei struct dpaa2_fapr { 202061d631fSIoana Ciornei /* 64-bit word 1 */ 203061d631fSIoana Ciornei __le32 faf_lo; 204061d631fSIoana Ciornei __le16 faf_ext; 205061d631fSIoana Ciornei __le16 nxt_hdr; 206061d631fSIoana Ciornei /* 64-bit word 2 */ 207061d631fSIoana Ciornei __le64 faf_hi; 208061d631fSIoana Ciornei /* 64-bit word 3 */ 209061d631fSIoana Ciornei u8 last_ethertype_offset; 210061d631fSIoana Ciornei u8 vlan_tci_offset_n; 211061d631fSIoana Ciornei u8 vlan_tci_offset_1; 212061d631fSIoana Ciornei u8 llc_snap_offset; 213061d631fSIoana Ciornei u8 eth_offset; 214061d631fSIoana Ciornei u8 ip1_pid_offset; 215061d631fSIoana Ciornei u8 shim_offset_2; 216061d631fSIoana Ciornei u8 shim_offset_1; 217061d631fSIoana Ciornei /* 64-bit word 4 */ 218061d631fSIoana Ciornei u8 l5_offset; 219061d631fSIoana Ciornei u8 l4_offset; 220061d631fSIoana Ciornei u8 gre_offset; 221061d631fSIoana Ciornei u8 l3_offset_n; 222061d631fSIoana Ciornei u8 l3_offset_1; 223061d631fSIoana Ciornei u8 mpls_offset_n; 224061d631fSIoana Ciornei u8 mpls_offset_1; 225061d631fSIoana Ciornei u8 pppoe_offset; 226061d631fSIoana Ciornei /* 64-bit word 5 */ 227061d631fSIoana Ciornei __le16 running_sum; 228061d631fSIoana Ciornei __le16 gross_running_sum; 229061d631fSIoana Ciornei u8 ipv6_frag_offset; 230061d631fSIoana Ciornei u8 nxt_hdr_offset; 231061d631fSIoana Ciornei u8 routing_hdr_offset_2; 232061d631fSIoana Ciornei u8 routing_hdr_offset_1; 233061d631fSIoana Ciornei /* 64-bit word 6 */ 234061d631fSIoana Ciornei u8 reserved[5]; /* Soft-parsing context */ 235061d631fSIoana Ciornei u8 ip_proto_offset_n; 236061d631fSIoana Ciornei u8 nxt_hdr_frag_offset; 237061d631fSIoana Ciornei u8 parse_error_code; 238061d631fSIoana Ciornei }; 239061d631fSIoana Ciornei 240061d631fSIoana Ciornei #define DPAA2_FAPR_OFFSET 0x10 241061d631fSIoana Ciornei #define DPAA2_FAPR_SIZE sizeof((struct dpaa2_fapr)) 242061d631fSIoana Ciornei 24334ff6846SIoana Radulescu /* Frame annotation egress action descriptor */ 24434ff6846SIoana Radulescu #define DPAA2_FAEAD_OFFSET 0x58 24534ff6846SIoana Radulescu 24634ff6846SIoana Radulescu struct dpaa2_faead { 24734ff6846SIoana Radulescu __le32 conf_fqid; 24834ff6846SIoana Radulescu __le32 ctrl; 24934ff6846SIoana Radulescu }; 25034ff6846SIoana Radulescu 25134ff6846SIoana Radulescu #define DPAA2_FAEAD_A2V 0x20000000 25299e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_A4V 0x08000000 25334ff6846SIoana Radulescu #define DPAA2_FAEAD_UPDV 0x00001000 25499e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_EBDDV 0x00002000 25534ff6846SIoana Radulescu #define DPAA2_FAEAD_UPD 0x00000010 25634ff6846SIoana Radulescu 257c5521189SYangbo Lu struct ptp_tstamp { 258c5521189SYangbo Lu u16 sec_msb; 259c5521189SYangbo Lu u32 sec_lsb; 260c5521189SYangbo Lu u32 nsec; 261c5521189SYangbo Lu }; 262c5521189SYangbo Lu 263c5521189SYangbo Lu static inline void ns_to_ptp_tstamp(struct ptp_tstamp *tstamp, u64 ns) 264c5521189SYangbo Lu { 265c5521189SYangbo Lu u64 sec, nsec; 266c5521189SYangbo Lu 267c5521189SYangbo Lu sec = ns; 268c5521189SYangbo Lu nsec = do_div(sec, 1000000000); 269c5521189SYangbo Lu 270c5521189SYangbo Lu tstamp->sec_lsb = sec & 0xFFFFFFFF; 271c5521189SYangbo Lu tstamp->sec_msb = (sec >> 32) & 0xFFFF; 272c5521189SYangbo Lu tstamp->nsec = nsec; 273c5521189SYangbo Lu } 274c5521189SYangbo Lu 27534ff6846SIoana Radulescu /* Accessors for the hardware annotation fields that we use */ 27634ff6846SIoana Radulescu static inline void *dpaa2_get_hwa(void *buf_addr, bool swa) 27734ff6846SIoana Radulescu { 27834ff6846SIoana Radulescu return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0); 27934ff6846SIoana Radulescu } 28034ff6846SIoana Radulescu 28134ff6846SIoana Radulescu static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa) 28234ff6846SIoana Radulescu { 28334ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET; 28434ff6846SIoana Radulescu } 28534ff6846SIoana Radulescu 28634ff6846SIoana Radulescu static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa) 28734ff6846SIoana Radulescu { 28834ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET; 28934ff6846SIoana Radulescu } 29034ff6846SIoana Radulescu 291061d631fSIoana Ciornei static inline struct dpaa2_fapr *dpaa2_get_fapr(void *buf_addr, bool swa) 292061d631fSIoana Ciornei { 293061d631fSIoana Ciornei return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAPR_OFFSET; 294061d631fSIoana Ciornei } 295061d631fSIoana Ciornei 29634ff6846SIoana Radulescu static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa) 29734ff6846SIoana Radulescu { 29834ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET; 29934ff6846SIoana Radulescu } 30034ff6846SIoana Radulescu 30134ff6846SIoana Radulescu /* Error and status bits in the frame annotation status word */ 30234ff6846SIoana Radulescu /* Debug frame, otherwise supposed to be discarded */ 30334ff6846SIoana Radulescu #define DPAA2_FAS_DISC 0x80000000 30434ff6846SIoana Radulescu /* MACSEC frame */ 30534ff6846SIoana Radulescu #define DPAA2_FAS_MS 0x40000000 30634ff6846SIoana Radulescu #define DPAA2_FAS_PTP 0x08000000 30734ff6846SIoana Radulescu /* Ethernet multicast frame */ 30834ff6846SIoana Radulescu #define DPAA2_FAS_MC 0x04000000 30934ff6846SIoana Radulescu /* Ethernet broadcast frame */ 31034ff6846SIoana Radulescu #define DPAA2_FAS_BC 0x02000000 31134ff6846SIoana Radulescu #define DPAA2_FAS_KSE 0x00040000 31234ff6846SIoana Radulescu #define DPAA2_FAS_EOFHE 0x00020000 31334ff6846SIoana Radulescu #define DPAA2_FAS_MNLE 0x00010000 31434ff6846SIoana Radulescu #define DPAA2_FAS_TIDE 0x00008000 31534ff6846SIoana Radulescu #define DPAA2_FAS_PIEE 0x00004000 31634ff6846SIoana Radulescu /* Frame length error */ 31734ff6846SIoana Radulescu #define DPAA2_FAS_FLE 0x00002000 31834ff6846SIoana Radulescu /* Frame physical error */ 31934ff6846SIoana Radulescu #define DPAA2_FAS_FPE 0x00001000 32034ff6846SIoana Radulescu #define DPAA2_FAS_PTE 0x00000080 32134ff6846SIoana Radulescu #define DPAA2_FAS_ISP 0x00000040 32234ff6846SIoana Radulescu #define DPAA2_FAS_PHE 0x00000020 32334ff6846SIoana Radulescu #define DPAA2_FAS_BLE 0x00000010 32434ff6846SIoana Radulescu /* L3 csum validation performed */ 32534ff6846SIoana Radulescu #define DPAA2_FAS_L3CV 0x00000008 32634ff6846SIoana Radulescu /* L3 csum error */ 32734ff6846SIoana Radulescu #define DPAA2_FAS_L3CE 0x00000004 32834ff6846SIoana Radulescu /* L4 csum validation performed */ 32934ff6846SIoana Radulescu #define DPAA2_FAS_L4CV 0x00000002 33034ff6846SIoana Radulescu /* L4 csum error */ 33134ff6846SIoana Radulescu #define DPAA2_FAS_L4CE 0x00000001 33234ff6846SIoana Radulescu /* Possible errors on the ingress path */ 33334ff6846SIoana Radulescu #define DPAA2_FAS_RX_ERR_MASK (DPAA2_FAS_KSE | \ 33434ff6846SIoana Radulescu DPAA2_FAS_EOFHE | \ 33534ff6846SIoana Radulescu DPAA2_FAS_MNLE | \ 33634ff6846SIoana Radulescu DPAA2_FAS_TIDE | \ 33734ff6846SIoana Radulescu DPAA2_FAS_PIEE | \ 33834ff6846SIoana Radulescu DPAA2_FAS_FLE | \ 33934ff6846SIoana Radulescu DPAA2_FAS_FPE | \ 34034ff6846SIoana Radulescu DPAA2_FAS_PTE | \ 34134ff6846SIoana Radulescu DPAA2_FAS_ISP | \ 34234ff6846SIoana Radulescu DPAA2_FAS_PHE | \ 34334ff6846SIoana Radulescu DPAA2_FAS_BLE | \ 34434ff6846SIoana Radulescu DPAA2_FAS_L3CE | \ 34534ff6846SIoana Radulescu DPAA2_FAS_L4CE) 34634ff6846SIoana Radulescu 34734ff6846SIoana Radulescu /* Time in milliseconds between link state updates */ 34834ff6846SIoana Radulescu #define DPAA2_ETH_LINK_STATE_REFRESH 1000 34934ff6846SIoana Radulescu 35034ff6846SIoana Radulescu /* Number of times to retry a frame enqueue before giving up. 35134ff6846SIoana Radulescu * Value determined empirically, in order to minimize the number 35234ff6846SIoana Radulescu * of frames dropped on Tx 35334ff6846SIoana Radulescu */ 35434ff6846SIoana Radulescu #define DPAA2_ETH_ENQUEUE_RETRIES 10 35534ff6846SIoana Radulescu 356ef17bd7cSIoana Radulescu /* Number of times to retry DPIO portal operations while waiting 357ef17bd7cSIoana Radulescu * for portal to finish executing current command and become 358ef17bd7cSIoana Radulescu * available. We want to avoid being stuck in a while loop in case 359ef17bd7cSIoana Radulescu * hardware becomes unresponsive, but not give up too easily if 360ef17bd7cSIoana Radulescu * the portal really is busy for valid reasons 361ef17bd7cSIoana Radulescu */ 362ef17bd7cSIoana Radulescu #define DPAA2_ETH_SWP_BUSY_RETRIES 1000 363ef17bd7cSIoana Radulescu 36434ff6846SIoana Radulescu /* Driver statistics, other than those in struct rtnl_link_stats64. 36534ff6846SIoana Radulescu * These are usually collected per-CPU and aggregated by ethtool. 36634ff6846SIoana Radulescu */ 36734ff6846SIoana Radulescu struct dpaa2_eth_drv_stats { 36834ff6846SIoana Radulescu __u64 tx_conf_frames; 36934ff6846SIoana Radulescu __u64 tx_conf_bytes; 37034ff6846SIoana Radulescu __u64 tx_sg_frames; 37134ff6846SIoana Radulescu __u64 tx_sg_bytes; 3723dc709e0SIoana Ciornei __u64 tx_tso_frames; 3733dc709e0SIoana Ciornei __u64 tx_tso_bytes; 37434ff6846SIoana Radulescu __u64 rx_sg_frames; 37534ff6846SIoana Radulescu __u64 rx_sg_bytes; 3764c96c0acSIoana Ciornei /* Linear skbs sent as a S/G FD due to insufficient headroom */ 3774c96c0acSIoana Ciornei __u64 tx_converted_sg_frames; 3784c96c0acSIoana Ciornei __u64 tx_converted_sg_bytes; 37934ff6846SIoana Radulescu /* Enqueues retried due to portal busy */ 38034ff6846SIoana Radulescu __u64 tx_portal_busy; 38134ff6846SIoana Radulescu }; 38234ff6846SIoana Radulescu 38334ff6846SIoana Radulescu /* Per-FQ statistics */ 38434ff6846SIoana Radulescu struct dpaa2_eth_fq_stats { 38534ff6846SIoana Radulescu /* Number of frames received on this queue */ 38634ff6846SIoana Radulescu __u64 frames; 38734ff6846SIoana Radulescu }; 38834ff6846SIoana Radulescu 38934ff6846SIoana Radulescu /* Per-channel statistics */ 39034ff6846SIoana Radulescu struct dpaa2_eth_ch_stats { 39134ff6846SIoana Radulescu /* Volatile dequeues retried due to portal busy */ 39234ff6846SIoana Radulescu __u64 dequeue_portal_busy; 39334ff6846SIoana Radulescu /* Pull errors */ 39434ff6846SIoana Radulescu __u64 pull_err; 3950ff8f0aaSIoana Ciocoi Radulescu /* Number of CDANs; useful to estimate avg NAPI len */ 3960ff8f0aaSIoana Ciocoi Radulescu __u64 cdan; 397a4a7b762SIoana Ciocoi Radulescu /* XDP counters */ 398a4a7b762SIoana Ciocoi Radulescu __u64 xdp_drop; 399a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx; 400a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx_err; 401d678be1dSIoana Radulescu __u64 xdp_redirect; 402460fd830SIoana Ciornei /* Must be last, does not show up in ethtool stats */ 403460fd830SIoana Ciornei __u64 frames; 404fc398becSIoana Ciornei __u64 frames_per_cdan; 405fc398becSIoana Ciornei __u64 bytes_per_cdan; 40634ff6846SIoana Radulescu }; 40734ff6846SIoana Radulescu 408972ce7e3SIoana Ciornei #define DPAA2_ETH_CH_STATS 7 409972ce7e3SIoana Ciornei 41034ff6846SIoana Radulescu /* Maximum number of queues associated with a DPNI */ 41115c87f6bSIoana Radulescu #define DPAA2_ETH_MAX_TCS 8 412685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES_PER_TC 16 413685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES \ 414685e39eaSIoana Radulescu (DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS) 41534ff6846SIoana Radulescu #define DPAA2_ETH_MAX_TX_QUEUES 16 416061d631fSIoana Ciornei #define DPAA2_ETH_MAX_RX_ERR_QUEUES 1 41734ff6846SIoana Radulescu #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \ 418061d631fSIoana Ciornei DPAA2_ETH_MAX_TX_QUEUES + \ 419061d631fSIoana Ciornei DPAA2_ETH_MAX_RX_ERR_QUEUES) 420ab1e6de2SIoana Radulescu #define DPAA2_ETH_MAX_NETDEV_QUEUES \ 421ab1e6de2SIoana Radulescu (DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS) 42234ff6846SIoana Radulescu 42334ff6846SIoana Radulescu #define DPAA2_ETH_MAX_DPCONS 16 42434ff6846SIoana Radulescu 42534ff6846SIoana Radulescu enum dpaa2_eth_fq_type { 42634ff6846SIoana Radulescu DPAA2_RX_FQ = 0, 42734ff6846SIoana Radulescu DPAA2_TX_CONF_FQ, 428061d631fSIoana Ciornei DPAA2_RX_ERR_FQ 42934ff6846SIoana Radulescu }; 43034ff6846SIoana Radulescu 43134ff6846SIoana Radulescu struct dpaa2_eth_priv; 43234ff6846SIoana Radulescu 43338c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds { 43438c440b2SIoana Ciornei struct dpaa2_fd fds[DEV_MAP_BULK_SIZE]; 43538c440b2SIoana Ciornei ssize_t num; 43638c440b2SIoana Ciornei }; 43738c440b2SIoana Ciornei 43834ff6846SIoana Radulescu struct dpaa2_eth_fq { 43934ff6846SIoana Radulescu u32 fqid; 44034ff6846SIoana Radulescu u32 tx_qdbin; 44115c87f6bSIoana Radulescu u32 tx_fqid[DPAA2_ETH_MAX_TCS]; 44234ff6846SIoana Radulescu u16 flowid; 44315c87f6bSIoana Radulescu u8 tc; 44434ff6846SIoana Radulescu int target_cpu; 445569dac6aSIoana Ciocoi Radulescu u32 dq_frames; 446569dac6aSIoana Ciocoi Radulescu u32 dq_bytes; 44734ff6846SIoana Radulescu struct dpaa2_eth_channel *channel; 44834ff6846SIoana Radulescu enum dpaa2_eth_fq_type type; 44934ff6846SIoana Radulescu 45034ff6846SIoana Radulescu void (*consume)(struct dpaa2_eth_priv *priv, 45134ff6846SIoana Radulescu struct dpaa2_eth_channel *ch, 45234ff6846SIoana Radulescu const struct dpaa2_fd *fd, 453dbcdf728SIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq); 45434ff6846SIoana Radulescu struct dpaa2_eth_fq_stats stats; 4558665d978SIoana Ciornei 45638c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_redirect_fds; 45774a1c059SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_tx_fds; 45834ff6846SIoana Radulescu }; 45934ff6846SIoana Radulescu 4607e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp { 4617e273a8eSIoana Ciocoi Radulescu struct bpf_prog *prog; 462d678be1dSIoana Radulescu unsigned int res; 4637e273a8eSIoana Ciocoi Radulescu }; 4647e273a8eSIoana Ciocoi Radulescu 465*095174daSRobert-Ionut Alexa struct dpaa2_eth_bp { 466*095174daSRobert-Ionut Alexa struct fsl_mc_device *dev; 467*095174daSRobert-Ionut Alexa int bpid; 468*095174daSRobert-Ionut Alexa }; 469*095174daSRobert-Ionut Alexa 47034ff6846SIoana Radulescu struct dpaa2_eth_channel { 47134ff6846SIoana Radulescu struct dpaa2_io_notification_ctx nctx; 47234ff6846SIoana Radulescu struct fsl_mc_device *dpcon; 47334ff6846SIoana Radulescu int dpcon_id; 47434ff6846SIoana Radulescu int ch_id; 47534ff6846SIoana Radulescu struct napi_struct napi; 47634ff6846SIoana Radulescu struct dpaa2_io *dpio; 47734ff6846SIoana Radulescu struct dpaa2_io_store *store; 47834ff6846SIoana Radulescu struct dpaa2_eth_priv *priv; 47934ff6846SIoana Radulescu int buf_count; 48034ff6846SIoana Radulescu struct dpaa2_eth_ch_stats stats; 4817e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp xdp; 482d678be1dSIoana Radulescu struct xdp_rxq_info xdp_rxq; 4830a25d92cSIoana Ciornei struct list_head *rx_list; 48428d137ccSIoana Ciornei 48528d137ccSIoana Ciornei /* Buffers to be recycled back in the buffer pool */ 48628d137ccSIoana Ciornei u64 recycled_bufs[DPAA2_ETH_BUFS_PER_CMD]; 48728d137ccSIoana Ciornei int recycled_bufs_cnt; 488*095174daSRobert-Ionut Alexa 489*095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *bp; 49034ff6846SIoana Radulescu }; 49134ff6846SIoana Radulescu 492f76c483aSIoana Radulescu struct dpaa2_eth_dist_fields { 49334ff6846SIoana Radulescu u64 rxnfc_field; 49434ff6846SIoana Radulescu enum net_prot cls_prot; 49534ff6846SIoana Radulescu int cls_field; 49634ff6846SIoana Radulescu int size; 4973a1e6b84SIoana Ciocoi Radulescu u64 id; 49834ff6846SIoana Radulescu }; 49934ff6846SIoana Radulescu 500afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule { 501afb90dbbSIoana Radulescu struct ethtool_rx_flow_spec fs; 502afb90dbbSIoana Radulescu u8 in_use; 503afb90dbbSIoana Radulescu }; 504afb90dbbSIoana Radulescu 505d70446eeSIoana Ciornei #define DPAA2_ETH_SGT_CACHE_SIZE 256 506d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache { 507d70446eeSIoana Ciornei void *buf[DPAA2_ETH_SGT_CACHE_SIZE]; 508d70446eeSIoana Ciornei u16 count; 509d70446eeSIoana Ciornei }; 510d70446eeSIoana Ciornei 511061d631fSIoana Ciornei struct dpaa2_eth_trap_item { 512061d631fSIoana Ciornei void *trap_ctx; 513061d631fSIoana Ciornei }; 514061d631fSIoana Ciornei 515061d631fSIoana Ciornei struct dpaa2_eth_trap_data { 516061d631fSIoana Ciornei struct dpaa2_eth_trap_item *trap_items_arr; 517061d631fSIoana Ciornei struct dpaa2_eth_priv *priv; 518061d631fSIoana Ciornei }; 519061d631fSIoana Ciornei 520a4218aefSIoana Ciornei #define DPAA2_ETH_SG_ENTRIES_MAX (PAGE_SIZE / sizeof(struct scatterlist)) 521a4218aefSIoana Ciornei 52250f82699SIoana Ciornei #define DPAA2_ETH_DEFAULT_COPYBREAK 512 52350f82699SIoana Ciornei 524a4ca448eSIoana Ciornei #define DPAA2_ETH_ENQUEUE_MAX_FDS 200 525a4ca448eSIoana Ciornei struct dpaa2_eth_fds { 526a4ca448eSIoana Ciornei struct dpaa2_fd array[DPAA2_ETH_ENQUEUE_MAX_FDS]; 527a4ca448eSIoana Ciornei }; 528a4ca448eSIoana Ciornei 52934ff6846SIoana Radulescu /* Driver private data */ 53034ff6846SIoana Radulescu struct dpaa2_eth_priv { 53134ff6846SIoana Radulescu struct net_device *net_dev; 53234ff6846SIoana Radulescu 53334ff6846SIoana Radulescu u8 num_fqs; 53434ff6846SIoana Radulescu struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES]; 5351fa0f68cSIoana Ciocoi Radulescu int (*enqueue)(struct dpaa2_eth_priv *priv, 5361fa0f68cSIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq, 53748c0481eSIoana Ciornei struct dpaa2_fd *fd, u8 prio, 5386ff80447SIoana Ciornei u32 num_frames, 53948c0481eSIoana Ciornei int *frames_enqueued); 54034ff6846SIoana Radulescu 54134ff6846SIoana Radulescu u8 num_channels; 54234ff6846SIoana Radulescu struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS]; 543d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache __percpu *sgt_cache; 544c4680c97SRadu Bulie unsigned long features; 54534ff6846SIoana Radulescu struct dpni_attr dpni_attrs; 54634ff6846SIoana Radulescu u16 dpni_ver_major; 54734ff6846SIoana Radulescu u16 dpni_ver_minor; 54834ff6846SIoana Radulescu u16 tx_data_offset; 549c4680c97SRadu Bulie void __iomem *onestep_reg_base; 550c4680c97SRadu Bulie u8 ptp_correction_off; 551c4680c97SRadu Bulie void (*dpaa2_set_onestep_params_cb)(struct dpaa2_eth_priv *priv, 552c4680c97SRadu Bulie u32 offset, u8 udp); 553efa6a7d0SIoana Ciornei u16 rx_buf_size; 55434ff6846SIoana Radulescu struct iommu_domain *iommu_domain; 55534ff6846SIoana Radulescu 5561cf773bdSYangbo Lu enum hwtstamp_tx_types tx_tstamp_type; /* Tx timestamping type */ 55734ff6846SIoana Radulescu bool rx_tstamp; /* Rx timestamping enabled */ 55834ff6846SIoana Radulescu 559*095174daSRobert-Ionut Alexa /* Buffer pool management */ 560*095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *bp[DPAA2_ETH_MAX_BPS]; 561*095174daSRobert-Ionut Alexa int num_bps; 562*095174daSRobert-Ionut Alexa 56334ff6846SIoana Radulescu u16 tx_qdid; 56434ff6846SIoana Radulescu struct fsl_mc_io *mc_io; 56534ff6846SIoana Radulescu /* Cores which have an affine DPIO/DPCON. 56634ff6846SIoana Radulescu * This is the cpu set on which Rx and Tx conf frames are processed 56734ff6846SIoana Radulescu */ 56834ff6846SIoana Radulescu struct cpumask dpio_cpumask; 56934ff6846SIoana Radulescu 57034ff6846SIoana Radulescu /* Standard statistics */ 57134ff6846SIoana Radulescu struct rtnl_link_stats64 __percpu *percpu_stats; 57234ff6846SIoana Radulescu /* Extra stats, in addition to the ones known by the kernel */ 57334ff6846SIoana Radulescu struct dpaa2_eth_drv_stats __percpu *percpu_extras; 57434ff6846SIoana Radulescu 57534ff6846SIoana Radulescu u16 mc_token; 57607beb165SIoana Ciornei u8 rx_fqtd_enabled; 57707beb165SIoana Ciornei u8 rx_cgtd_enabled; 57834ff6846SIoana Radulescu 57934ff6846SIoana Radulescu struct dpni_link_state link_state; 58034ff6846SIoana Radulescu bool do_link_poll; 58134ff6846SIoana Radulescu struct task_struct *poll_thread; 58234ff6846SIoana Radulescu 58334ff6846SIoana Radulescu /* enabled ethtool hashing bits */ 58434ff6846SIoana Radulescu u64 rx_hash_fields; 5852d680237SIoana Ciocoi Radulescu u64 rx_cls_fields; 586afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule *cls_rules; 5874aaaf9b9SIoana Radulescu u8 rx_cls_enabled; 5886aa90fe2SIoana Radulescu u8 vlan_cls_enabled; 58907beb165SIoana Ciornei u8 pfc_enabled; 590f395b69fSIoana Ciornei #ifdef CONFIG_FSL_DPAA2_ETH_DCB 591f395b69fSIoana Ciornei u8 dcbx_mode; 592f395b69fSIoana Ciornei struct ieee_pfc pfc; 593f395b69fSIoana Ciornei #endif 5947e273a8eSIoana Ciocoi Radulescu struct bpf_prog *xdp_prog; 595091a19eaSIoana Radulescu #ifdef CONFIG_DEBUG_FS 596091a19eaSIoana Radulescu struct dpaa2_debugfs dbg; 597091a19eaSIoana Radulescu #endif 59871947923SIoana Ciornei 59971947923SIoana Ciornei struct dpaa2_mac *mac; 600c5521189SYangbo Lu struct workqueue_struct *dpaa2_ptp_wq; 601c5521189SYangbo Lu struct work_struct tx_onestep_tstamp; 602c5521189SYangbo Lu struct sk_buff_head tx_skbs; 603c5521189SYangbo Lu /* The one-step timestamping configuration on hardware 604c5521189SYangbo Lu * registers could only be done when no one-step 605c5521189SYangbo Lu * timestamping frames are in flight. So we use a mutex 606c5521189SYangbo Lu * lock here to make sure the lock is released by last 607c5521189SYangbo Lu * one-step timestamping packet through TX confirmation 608c5521189SYangbo Lu * queue before transmit current packet. 609c5521189SYangbo Lu */ 610c5521189SYangbo Lu struct mutex onestep_tstamp_lock; 611ceeb03adSIoana Ciornei struct devlink *devlink; 612061d631fSIoana Ciornei struct dpaa2_eth_trap_data *trap_data; 613ceeb03adSIoana Ciornei struct devlink_port devlink_port; 6148ed3cefcSIoana Ciornei 6158ed3cefcSIoana Ciornei u32 rx_copybreak; 616a4ca448eSIoana Ciornei 617a4ca448eSIoana Ciornei struct dpaa2_eth_fds __percpu *fd; 618ceeb03adSIoana Ciornei }; 619ceeb03adSIoana Ciornei 620ceeb03adSIoana Ciornei struct dpaa2_eth_devlink_priv { 621ceeb03adSIoana Ciornei struct dpaa2_eth_priv *dpaa2_priv; 62234ff6846SIoana Radulescu }; 62334ff6846SIoana Radulescu 6241cf773bdSYangbo Lu #define TX_TSTAMP 0x1 625c5521189SYangbo Lu #define TX_TSTAMP_ONESTEP_SYNC 0x2 6261cf773bdSYangbo Lu 62734ff6846SIoana Radulescu #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \ 62834ff6846SIoana Radulescu | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \ 62934ff6846SIoana Radulescu | RXH_L4_B_2_3) 63034ff6846SIoana Radulescu 63134ff6846SIoana Radulescu /* default Rx hash options, set during probing */ 63234ff6846SIoana Radulescu #define DPAA2_RXH_DEFAULT (RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \ 63334ff6846SIoana Radulescu RXH_L4_B_0_1 | RXH_L4_B_2_3) 63434ff6846SIoana Radulescu 63534ff6846SIoana Radulescu #define dpaa2_eth_hash_enabled(priv) \ 63634ff6846SIoana Radulescu ((priv)->dpni_attrs.num_queues > 1) 63734ff6846SIoana Radulescu 63834ff6846SIoana Radulescu /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */ 63934ff6846SIoana Radulescu #define DPAA2_CLASSIFIER_DMA_SIZE 256 64034ff6846SIoana Radulescu 64134ff6846SIoana Radulescu extern const struct ethtool_ops dpaa2_ethtool_ops; 64234ff6846SIoana Radulescu extern int dpaa2_phc_index; 643d21c784cSYangbo Lu extern struct ptp_qoriq *dpaa2_ptp; 64434ff6846SIoana Radulescu 64534ff6846SIoana Radulescu static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv, 64634ff6846SIoana Radulescu u16 ver_major, u16 ver_minor) 64734ff6846SIoana Radulescu { 64834ff6846SIoana Radulescu if (priv->dpni_ver_major == ver_major) 64934ff6846SIoana Radulescu return priv->dpni_ver_minor - ver_minor; 65034ff6846SIoana Radulescu return priv->dpni_ver_major - ver_major; 65134ff6846SIoana Radulescu } 65234ff6846SIoana Radulescu 653df85aeb9SIoana Radulescu /* Minimum firmware version that supports a more flexible API 654df85aeb9SIoana Radulescu * for configuring the Rx flow hash key 655df85aeb9SIoana Radulescu */ 656df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MAJOR 7 657df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MINOR 5 658df85aeb9SIoana Radulescu 659df85aeb9SIoana Radulescu #define dpaa2_eth_has_legacy_dist(priv) \ 660df85aeb9SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR, \ 661df85aeb9SIoana Radulescu DPNI_RX_DIST_KEY_VER_MINOR) < 0) 662df85aeb9SIoana Radulescu 66361f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_enabled(priv) \ 66461f9bf00SIoana Ciocoi Radulescu (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS)) 66561f9bf00SIoana Ciocoi Radulescu 66661f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_mask_enabled(priv) \ 66761f9bf00SIoana Ciocoi Radulescu ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING) 66861f9bf00SIoana Ciocoi Radulescu 669afb90dbbSIoana Radulescu #define dpaa2_eth_fs_count(priv) \ 670afb90dbbSIoana Radulescu ((priv)->dpni_attrs.fs_entries) 671afb90dbbSIoana Radulescu 67215c87f6bSIoana Radulescu #define dpaa2_eth_tc_count(priv) \ 67315c87f6bSIoana Radulescu ((priv)->dpni_attrs.num_tcs) 67415c87f6bSIoana Radulescu 675186f21beSIoana Ciornei /* We have exactly one {Rx, Tx conf} queue per channel */ 676186f21beSIoana Ciornei #define dpaa2_eth_queue_count(priv) \ 677186f21beSIoana Ciornei ((priv)->num_channels) 678186f21beSIoana Ciornei 6794aaaf9b9SIoana Radulescu enum dpaa2_eth_rx_dist { 6804aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_HASH, 6814aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_CLS 6824aaaf9b9SIoana Radulescu }; 6834aaaf9b9SIoana Radulescu 6843a1e6b84SIoana Ciocoi Radulescu /* Unique IDs for the supported Rx classification header fields */ 6853a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHDST BIT(0) 6863a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHSRC BIT(1) 6873a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHTYPE BIT(2) 6883a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_VLAN BIT(3) 6893a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPSRC BIT(4) 6903a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPDST BIT(5) 6913a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPPROTO BIT(6) 6923a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4SRC BIT(7) 6933a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4DST BIT(8) 6944ca6dee5SIoana Radulescu #define DPAA2_ETH_DIST_ALL (~0ULL) 6953a1e6b84SIoana Ciocoi Radulescu 696c4680c97SRadu Bulie #define DPNI_PTP_ONESTEP_VER_MAJOR 8 697c4680c97SRadu Bulie #define DPNI_PTP_ONESTEP_VER_MINOR 2 698c4680c97SRadu Bulie #define DPAA2_ETH_FEATURE_ONESTEP_CFG_DIRECT BIT(0) 699c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_STEP_ENABLE BIT(31) 700c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_STEP_CH BIT(7) 701c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_CORRECTION_OFF(v) ((v) << 8) 702c4680c97SRadu Bulie 7038eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MAJOR 7 7048eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MINOR 13 7058eb3cef8SIoana Radulescu #define dpaa2_eth_has_pause_support(priv) \ 7068eb3cef8SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR, \ 7078eb3cef8SIoana Radulescu DPNI_PAUSE_VER_MINOR) >= 0) 7088eb3cef8SIoana Radulescu 709ad054f26SIoana Radulescu static inline bool dpaa2_eth_tx_pause_enabled(u64 link_options) 710ad054f26SIoana Radulescu { 711ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE) ^ 712ad054f26SIoana Radulescu !!(link_options & DPNI_LINK_OPT_ASYM_PAUSE); 713ad054f26SIoana Radulescu } 714ad054f26SIoana Radulescu 715ad054f26SIoana Radulescu static inline bool dpaa2_eth_rx_pause_enabled(u64 link_options) 716ad054f26SIoana Radulescu { 717ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE); 718ad054f26SIoana Radulescu } 719ad054f26SIoana Radulescu 7201cf773bdSYangbo Lu static inline unsigned int dpaa2_eth_needed_headroom(struct sk_buff *skb) 72134ff6846SIoana Radulescu { 72234ff6846SIoana Radulescu unsigned int headroom = DPAA2_ETH_SWA_SIZE; 72334ff6846SIoana Radulescu 724d678be1dSIoana Radulescu /* If we don't have an skb (e.g. XDP buffer), we only need space for 725d678be1dSIoana Radulescu * the software annotation area 726d678be1dSIoana Radulescu */ 727d678be1dSIoana Radulescu if (!skb) 728d678be1dSIoana Radulescu return headroom; 729d678be1dSIoana Radulescu 73034ff6846SIoana Radulescu /* For non-linear skbs we have no headroom requirement, as we build a 73134ff6846SIoana Radulescu * SG frame with a newly allocated SGT buffer 73234ff6846SIoana Radulescu */ 73334ff6846SIoana Radulescu if (skb_is_nonlinear(skb)) 73434ff6846SIoana Radulescu return 0; 73534ff6846SIoana Radulescu 73634ff6846SIoana Radulescu /* If we have Tx timestamping, need 128B hardware annotation */ 737c5521189SYangbo Lu if (skb->cb[0]) 73834ff6846SIoana Radulescu headroom += DPAA2_ETH_TX_HWA_SIZE; 73934ff6846SIoana Radulescu 74034ff6846SIoana Radulescu return headroom; 74134ff6846SIoana Radulescu } 74234ff6846SIoana Radulescu 74334ff6846SIoana Radulescu /* Extra headroom space requested to hardware, in order to make sure there's 74434ff6846SIoana Radulescu * no realloc'ing in forwarding scenarios 74534ff6846SIoana Radulescu */ 74634ff6846SIoana Radulescu static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv) 74734ff6846SIoana Radulescu { 74827c87486SIoana Ciocoi Radulescu return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE; 74934ff6846SIoana Radulescu } 75034ff6846SIoana Radulescu 751d87e6063SIoana Ciornei static inline bool dpaa2_eth_is_type_phy(struct dpaa2_eth_priv *priv) 752d87e6063SIoana Ciornei { 753085f1776SRussell King if (priv->mac && 754085f1776SRussell King (priv->mac->attr.link_type == DPMAC_LINK_TYPE_PHY || 755085f1776SRussell King priv->mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE)) 756d87e6063SIoana Ciornei return true; 757d87e6063SIoana Ciornei 758d87e6063SIoana Ciornei return false; 759d87e6063SIoana Ciornei } 760d87e6063SIoana Ciornei 761d87e6063SIoana Ciornei static inline bool dpaa2_eth_has_mac(struct dpaa2_eth_priv *priv) 762d87e6063SIoana Ciornei { 763d87e6063SIoana Ciornei return priv->mac ? true : false; 764d87e6063SIoana Ciornei } 765d87e6063SIoana Ciornei 766edad8d26SIoana Ciocoi Radulescu int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags); 7672d680237SIoana Ciocoi Radulescu int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key); 7682d680237SIoana Ciocoi Radulescu int dpaa2_eth_cls_key_size(u64 key); 769afb90dbbSIoana Radulescu int dpaa2_eth_cls_fld_off(int prot, int field); 7702d680237SIoana Ciocoi Radulescu void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields); 771edad8d26SIoana Ciocoi Radulescu 77207beb165SIoana Ciornei void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv, 77307beb165SIoana Ciornei bool tx_pause, bool pfc); 77407beb165SIoana Ciornei 775f395b69fSIoana Ciornei extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops; 776f395b69fSIoana Ciornei 777bbb9ae25SLeon Romanovsky int dpaa2_eth_dl_alloc(struct dpaa2_eth_priv *priv); 778bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_free(struct dpaa2_eth_priv *priv); 779bbb9ae25SLeon Romanovsky 780bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv); 781ceeb03adSIoana Ciornei void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv); 782ceeb03adSIoana Ciornei 783ceeb03adSIoana Ciornei int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv); 784ceeb03adSIoana Ciornei void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv); 785ceeb03adSIoana Ciornei 786061d631fSIoana Ciornei int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv); 787061d631fSIoana Ciornei void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv); 788061d631fSIoana Ciornei 789061d631fSIoana Ciornei struct dpaa2_eth_trap_item *dpaa2_eth_dl_get_trap(struct dpaa2_eth_priv *priv, 790061d631fSIoana Ciornei struct dpaa2_fapr *fapr); 791*095174daSRobert-Ionut Alexa 792*095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *dpaa2_eth_allocate_dpbp(struct dpaa2_eth_priv *priv); 793*095174daSRobert-Ionut Alexa void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv, struct dpaa2_eth_bp *bp); 79434ff6846SIoana Radulescu #endif /* __DPAA2_H */ 795