134ff6846SIoana Radulescu /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 234ff6846SIoana Radulescu /* Copyright 2014-2016 Freescale Semiconductor Inc. 348c0481eSIoana Ciornei * Copyright 2016-2020 NXP 434ff6846SIoana Radulescu */ 534ff6846SIoana Radulescu 634ff6846SIoana Radulescu #ifndef __DPAA2_ETH_H 734ff6846SIoana Radulescu #define __DPAA2_ETH_H 834ff6846SIoana Radulescu 934ff6846SIoana Radulescu #include <linux/netdevice.h> 1034ff6846SIoana Radulescu #include <linux/if_vlan.h> 1134ff6846SIoana Radulescu #include <linux/fsl/mc.h> 1234ff6846SIoana Radulescu 1334ff6846SIoana Radulescu #include <soc/fsl/dpaa2-io.h> 1434ff6846SIoana Radulescu #include <soc/fsl/dpaa2-fd.h> 1534ff6846SIoana Radulescu #include "dpni.h" 1634ff6846SIoana Radulescu #include "dpni-cmd.h" 1734ff6846SIoana Radulescu 1834ff6846SIoana Radulescu #include "dpaa2-eth-trace.h" 19091a19eaSIoana Radulescu #include "dpaa2-eth-debugfs.h" 2071947923SIoana Ciornei #include "dpaa2-mac.h" 2134ff6846SIoana Radulescu 2234ff6846SIoana Radulescu #define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0) 2334ff6846SIoana Radulescu 2434ff6846SIoana Radulescu #define DPAA2_ETH_STORE_SIZE 16 2534ff6846SIoana Radulescu 2634ff6846SIoana Radulescu /* Maximum number of scatter-gather entries in an ingress frame, 2734ff6846SIoana Radulescu * considering the maximum receive frame size is 64K 2834ff6846SIoana Radulescu */ 2934ff6846SIoana Radulescu #define DPAA2_ETH_MAX_SG_ENTRIES ((64 * 1024) / DPAA2_ETH_RX_BUF_SIZE) 3034ff6846SIoana Radulescu 3134ff6846SIoana Radulescu /* Maximum acceptable MTU value. It is in direct relation with the hardware 3234ff6846SIoana Radulescu * enforced Max Frame Length (currently 10k). 3334ff6846SIoana Radulescu */ 3434ff6846SIoana Radulescu #define DPAA2_ETH_MFL (10 * 1024) 3534ff6846SIoana Radulescu #define DPAA2_ETH_MAX_MTU (DPAA2_ETH_MFL - VLAN_ETH_HLEN) 3634ff6846SIoana Radulescu /* Convert L3 MTU to L2 MFL */ 3734ff6846SIoana Radulescu #define DPAA2_ETH_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN) 3834ff6846SIoana Radulescu 3934ff6846SIoana Radulescu /* Set the taildrop threshold (in bytes) to allow the enqueue of several jumbo 4034ff6846SIoana Radulescu * frames in the Rx queues (length of the current frame is not 4134ff6846SIoana Radulescu * taken into account when making the taildrop decision) 4234ff6846SIoana Radulescu */ 4334ff6846SIoana Radulescu #define DPAA2_ETH_TAILDROP_THRESH (64 * 1024) 4434ff6846SIoana Radulescu 4568049a5fSIoana Ciocoi Radulescu /* Maximum number of Tx confirmation frames to be processed 4668049a5fSIoana Ciocoi Radulescu * in a single NAPI call 4768049a5fSIoana Ciocoi Radulescu */ 4868049a5fSIoana Ciocoi Radulescu #define DPAA2_ETH_TXCONF_PER_NAPI 256 4968049a5fSIoana Ciocoi Radulescu 5034ff6846SIoana Radulescu /* Buffer quota per queue. Must be large enough such that for minimum sized 5134ff6846SIoana Radulescu * frames taildrop kicks in before the bpool gets depleted, so we compute 5234ff6846SIoana Radulescu * how many 64B frames fit inside the taildrop threshold and add a margin 5334ff6846SIoana Radulescu * to accommodate the buffer refill delay. 5434ff6846SIoana Radulescu */ 5534ff6846SIoana Radulescu #define DPAA2_ETH_MAX_FRAMES_PER_QUEUE (DPAA2_ETH_TAILDROP_THRESH / 64) 5634ff6846SIoana Radulescu #define DPAA2_ETH_NUM_BUFS (DPAA2_ETH_MAX_FRAMES_PER_QUEUE + 256) 5720fb0572SIoana Ciocoi Radulescu #define DPAA2_ETH_REFILL_THRESH \ 5820fb0572SIoana Ciocoi Radulescu (DPAA2_ETH_NUM_BUFS - DPAA2_ETH_BUFS_PER_CMD) 5934ff6846SIoana Radulescu 6034ff6846SIoana Radulescu /* Maximum number of buffers that can be acquired/released through a single 6134ff6846SIoana Radulescu * QBMan command 6234ff6846SIoana Radulescu */ 6334ff6846SIoana Radulescu #define DPAA2_ETH_BUFS_PER_CMD 7 6434ff6846SIoana Radulescu 6534ff6846SIoana Radulescu /* Hardware requires alignment for ingress/egress buffer addresses */ 6634ff6846SIoana Radulescu #define DPAA2_ETH_TX_BUF_ALIGN 64 6734ff6846SIoana Radulescu 6827c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_RAW_SIZE PAGE_SIZE 6927c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_TAILROOM \ 7027c87486SIoana Ciocoi Radulescu SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) 7127c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_SIZE \ 7227c87486SIoana Ciocoi Radulescu (DPAA2_ETH_RX_BUF_RAW_SIZE - DPAA2_ETH_RX_BUF_TAILROOM) 7334ff6846SIoana Radulescu 7434ff6846SIoana Radulescu /* Hardware annotation area in RX/TX buffers */ 7534ff6846SIoana Radulescu #define DPAA2_ETH_RX_HWA_SIZE 64 7634ff6846SIoana Radulescu #define DPAA2_ETH_TX_HWA_SIZE 128 7734ff6846SIoana Radulescu 7834ff6846SIoana Radulescu /* PTP nominal frequency 1GHz */ 7934ff6846SIoana Radulescu #define DPAA2_PTP_CLK_PERIOD_NS 1 8034ff6846SIoana Radulescu 8134ff6846SIoana Radulescu /* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned 8234ff6846SIoana Radulescu * to 256B. For newer revisions, the requirement is only for 64B alignment 8334ff6846SIoana Radulescu */ 8434ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN_REV1 256 8534ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN 64 8634ff6846SIoana Radulescu 8734ff6846SIoana Radulescu /* We are accommodating a skb backpointer and some S/G info 8834ff6846SIoana Radulescu * in the frame's software annotation. The hardware 8934ff6846SIoana Radulescu * options are either 0 or 64, so we choose the latter. 9034ff6846SIoana Radulescu */ 9134ff6846SIoana Radulescu #define DPAA2_ETH_SWA_SIZE 64 9234ff6846SIoana Radulescu 93e3fdf6baSIoana Radulescu /* We store different information in the software annotation area of a Tx frame 94e3fdf6baSIoana Radulescu * based on what type of frame it is 95e3fdf6baSIoana Radulescu */ 96e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type { 97e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SINGLE, 98e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SG, 99d678be1dSIoana Radulescu DPAA2_ETH_SWA_XDP, 100e3fdf6baSIoana Radulescu }; 101e3fdf6baSIoana Radulescu 10234ff6846SIoana Radulescu /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */ 10334ff6846SIoana Radulescu struct dpaa2_eth_swa { 104e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type type; 105e3fdf6baSIoana Radulescu union { 106e3fdf6baSIoana Radulescu struct { 107e3fdf6baSIoana Radulescu struct sk_buff *skb; 108e3fdf6baSIoana Radulescu } single; 109e3fdf6baSIoana Radulescu struct { 11034ff6846SIoana Radulescu struct sk_buff *skb; 11134ff6846SIoana Radulescu struct scatterlist *scl; 11234ff6846SIoana Radulescu int num_sg; 11334ff6846SIoana Radulescu int sgt_size; 114e3fdf6baSIoana Radulescu } sg; 115d678be1dSIoana Radulescu struct { 116d678be1dSIoana Radulescu int dma_size; 117d678be1dSIoana Radulescu struct xdp_frame *xdpf; 118d678be1dSIoana Radulescu } xdp; 119e3fdf6baSIoana Radulescu }; 12034ff6846SIoana Radulescu }; 12134ff6846SIoana Radulescu 12234ff6846SIoana Radulescu /* Annotation valid bits in FD FRC */ 12334ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASV 0x8000 12434ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAEADV 0x4000 12534ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAPRV 0x2000 12634ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAIADV 0x1000 12734ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASWOV 0x0800 12834ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAICFDV 0x0400 12934ff6846SIoana Radulescu 13034ff6846SIoana Radulescu /* Error bits in FD CTRL */ 13134ff6846SIoana Radulescu #define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR) 13234ff6846SIoana Radulescu #define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \ 13334ff6846SIoana Radulescu FD_CTRL_SBE | \ 13434ff6846SIoana Radulescu FD_CTRL_FSE | \ 13534ff6846SIoana Radulescu FD_CTRL_FAERR) 13634ff6846SIoana Radulescu 13734ff6846SIoana Radulescu /* Annotation bits in FD CTRL */ 13834ff6846SIoana Radulescu #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128B */ 13934ff6846SIoana Radulescu 14034ff6846SIoana Radulescu /* Frame annotation status */ 14134ff6846SIoana Radulescu struct dpaa2_fas { 14234ff6846SIoana Radulescu u8 reserved; 14334ff6846SIoana Radulescu u8 ppid; 14434ff6846SIoana Radulescu __le16 ifpid; 14534ff6846SIoana Radulescu __le32 status; 14634ff6846SIoana Radulescu }; 14734ff6846SIoana Radulescu 14834ff6846SIoana Radulescu /* Frame annotation status word is located in the first 8 bytes 14934ff6846SIoana Radulescu * of the buffer's hardware annoatation area 15034ff6846SIoana Radulescu */ 15134ff6846SIoana Radulescu #define DPAA2_FAS_OFFSET 0 15234ff6846SIoana Radulescu #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas)) 15334ff6846SIoana Radulescu 15434ff6846SIoana Radulescu /* Timestamp is located in the next 8 bytes of the buffer's 15534ff6846SIoana Radulescu * hardware annotation area 15634ff6846SIoana Radulescu */ 15734ff6846SIoana Radulescu #define DPAA2_TS_OFFSET 0x8 15834ff6846SIoana Radulescu 15934ff6846SIoana Radulescu /* Frame annotation egress action descriptor */ 16034ff6846SIoana Radulescu #define DPAA2_FAEAD_OFFSET 0x58 16134ff6846SIoana Radulescu 16234ff6846SIoana Radulescu struct dpaa2_faead { 16334ff6846SIoana Radulescu __le32 conf_fqid; 16434ff6846SIoana Radulescu __le32 ctrl; 16534ff6846SIoana Radulescu }; 16634ff6846SIoana Radulescu 16734ff6846SIoana Radulescu #define DPAA2_FAEAD_A2V 0x20000000 16899e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_A4V 0x08000000 16934ff6846SIoana Radulescu #define DPAA2_FAEAD_UPDV 0x00001000 17099e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_EBDDV 0x00002000 17134ff6846SIoana Radulescu #define DPAA2_FAEAD_UPD 0x00000010 17234ff6846SIoana Radulescu 17334ff6846SIoana Radulescu /* Accessors for the hardware annotation fields that we use */ 17434ff6846SIoana Radulescu static inline void *dpaa2_get_hwa(void *buf_addr, bool swa) 17534ff6846SIoana Radulescu { 17634ff6846SIoana Radulescu return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0); 17734ff6846SIoana Radulescu } 17834ff6846SIoana Radulescu 17934ff6846SIoana Radulescu static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa) 18034ff6846SIoana Radulescu { 18134ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET; 18234ff6846SIoana Radulescu } 18334ff6846SIoana Radulescu 18434ff6846SIoana Radulescu static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa) 18534ff6846SIoana Radulescu { 18634ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET; 18734ff6846SIoana Radulescu } 18834ff6846SIoana Radulescu 18934ff6846SIoana Radulescu static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa) 19034ff6846SIoana Radulescu { 19134ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET; 19234ff6846SIoana Radulescu } 19334ff6846SIoana Radulescu 19434ff6846SIoana Radulescu /* Error and status bits in the frame annotation status word */ 19534ff6846SIoana Radulescu /* Debug frame, otherwise supposed to be discarded */ 19634ff6846SIoana Radulescu #define DPAA2_FAS_DISC 0x80000000 19734ff6846SIoana Radulescu /* MACSEC frame */ 19834ff6846SIoana Radulescu #define DPAA2_FAS_MS 0x40000000 19934ff6846SIoana Radulescu #define DPAA2_FAS_PTP 0x08000000 20034ff6846SIoana Radulescu /* Ethernet multicast frame */ 20134ff6846SIoana Radulescu #define DPAA2_FAS_MC 0x04000000 20234ff6846SIoana Radulescu /* Ethernet broadcast frame */ 20334ff6846SIoana Radulescu #define DPAA2_FAS_BC 0x02000000 20434ff6846SIoana Radulescu #define DPAA2_FAS_KSE 0x00040000 20534ff6846SIoana Radulescu #define DPAA2_FAS_EOFHE 0x00020000 20634ff6846SIoana Radulescu #define DPAA2_FAS_MNLE 0x00010000 20734ff6846SIoana Radulescu #define DPAA2_FAS_TIDE 0x00008000 20834ff6846SIoana Radulescu #define DPAA2_FAS_PIEE 0x00004000 20934ff6846SIoana Radulescu /* Frame length error */ 21034ff6846SIoana Radulescu #define DPAA2_FAS_FLE 0x00002000 21134ff6846SIoana Radulescu /* Frame physical error */ 21234ff6846SIoana Radulescu #define DPAA2_FAS_FPE 0x00001000 21334ff6846SIoana Radulescu #define DPAA2_FAS_PTE 0x00000080 21434ff6846SIoana Radulescu #define DPAA2_FAS_ISP 0x00000040 21534ff6846SIoana Radulescu #define DPAA2_FAS_PHE 0x00000020 21634ff6846SIoana Radulescu #define DPAA2_FAS_BLE 0x00000010 21734ff6846SIoana Radulescu /* L3 csum validation performed */ 21834ff6846SIoana Radulescu #define DPAA2_FAS_L3CV 0x00000008 21934ff6846SIoana Radulescu /* L3 csum error */ 22034ff6846SIoana Radulescu #define DPAA2_FAS_L3CE 0x00000004 22134ff6846SIoana Radulescu /* L4 csum validation performed */ 22234ff6846SIoana Radulescu #define DPAA2_FAS_L4CV 0x00000002 22334ff6846SIoana Radulescu /* L4 csum error */ 22434ff6846SIoana Radulescu #define DPAA2_FAS_L4CE 0x00000001 22534ff6846SIoana Radulescu /* Possible errors on the ingress path */ 22634ff6846SIoana Radulescu #define DPAA2_FAS_RX_ERR_MASK (DPAA2_FAS_KSE | \ 22734ff6846SIoana Radulescu DPAA2_FAS_EOFHE | \ 22834ff6846SIoana Radulescu DPAA2_FAS_MNLE | \ 22934ff6846SIoana Radulescu DPAA2_FAS_TIDE | \ 23034ff6846SIoana Radulescu DPAA2_FAS_PIEE | \ 23134ff6846SIoana Radulescu DPAA2_FAS_FLE | \ 23234ff6846SIoana Radulescu DPAA2_FAS_FPE | \ 23334ff6846SIoana Radulescu DPAA2_FAS_PTE | \ 23434ff6846SIoana Radulescu DPAA2_FAS_ISP | \ 23534ff6846SIoana Radulescu DPAA2_FAS_PHE | \ 23634ff6846SIoana Radulescu DPAA2_FAS_BLE | \ 23734ff6846SIoana Radulescu DPAA2_FAS_L3CE | \ 23834ff6846SIoana Radulescu DPAA2_FAS_L4CE) 23934ff6846SIoana Radulescu 24034ff6846SIoana Radulescu /* Time in milliseconds between link state updates */ 24134ff6846SIoana Radulescu #define DPAA2_ETH_LINK_STATE_REFRESH 1000 24234ff6846SIoana Radulescu 24334ff6846SIoana Radulescu /* Number of times to retry a frame enqueue before giving up. 24434ff6846SIoana Radulescu * Value determined empirically, in order to minimize the number 24534ff6846SIoana Radulescu * of frames dropped on Tx 24634ff6846SIoana Radulescu */ 24734ff6846SIoana Radulescu #define DPAA2_ETH_ENQUEUE_RETRIES 10 24834ff6846SIoana Radulescu 249ef17bd7cSIoana Radulescu /* Number of times to retry DPIO portal operations while waiting 250ef17bd7cSIoana Radulescu * for portal to finish executing current command and become 251ef17bd7cSIoana Radulescu * available. We want to avoid being stuck in a while loop in case 252ef17bd7cSIoana Radulescu * hardware becomes unresponsive, but not give up too easily if 253ef17bd7cSIoana Radulescu * the portal really is busy for valid reasons 254ef17bd7cSIoana Radulescu */ 255ef17bd7cSIoana Radulescu #define DPAA2_ETH_SWP_BUSY_RETRIES 1000 256ef17bd7cSIoana Radulescu 25734ff6846SIoana Radulescu /* Driver statistics, other than those in struct rtnl_link_stats64. 25834ff6846SIoana Radulescu * These are usually collected per-CPU and aggregated by ethtool. 25934ff6846SIoana Radulescu */ 26034ff6846SIoana Radulescu struct dpaa2_eth_drv_stats { 26134ff6846SIoana Radulescu __u64 tx_conf_frames; 26234ff6846SIoana Radulescu __u64 tx_conf_bytes; 26334ff6846SIoana Radulescu __u64 tx_sg_frames; 26434ff6846SIoana Radulescu __u64 tx_sg_bytes; 26534ff6846SIoana Radulescu __u64 tx_reallocs; 26634ff6846SIoana Radulescu __u64 rx_sg_frames; 26734ff6846SIoana Radulescu __u64 rx_sg_bytes; 26834ff6846SIoana Radulescu /* Enqueues retried due to portal busy */ 26934ff6846SIoana Radulescu __u64 tx_portal_busy; 27034ff6846SIoana Radulescu }; 27134ff6846SIoana Radulescu 27234ff6846SIoana Radulescu /* Per-FQ statistics */ 27334ff6846SIoana Radulescu struct dpaa2_eth_fq_stats { 27434ff6846SIoana Radulescu /* Number of frames received on this queue */ 27534ff6846SIoana Radulescu __u64 frames; 27634ff6846SIoana Radulescu }; 27734ff6846SIoana Radulescu 27834ff6846SIoana Radulescu /* Per-channel statistics */ 27934ff6846SIoana Radulescu struct dpaa2_eth_ch_stats { 28034ff6846SIoana Radulescu /* Volatile dequeues retried due to portal busy */ 28134ff6846SIoana Radulescu __u64 dequeue_portal_busy; 28234ff6846SIoana Radulescu /* Pull errors */ 28334ff6846SIoana Radulescu __u64 pull_err; 2840ff8f0aaSIoana Ciocoi Radulescu /* Number of CDANs; useful to estimate avg NAPI len */ 2850ff8f0aaSIoana Ciocoi Radulescu __u64 cdan; 286a4a7b762SIoana Ciocoi Radulescu /* XDP counters */ 287a4a7b762SIoana Ciocoi Radulescu __u64 xdp_drop; 288a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx; 289a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx_err; 290d678be1dSIoana Radulescu __u64 xdp_redirect; 291460fd830SIoana Ciornei /* Must be last, does not show up in ethtool stats */ 292460fd830SIoana Ciornei __u64 frames; 29334ff6846SIoana Radulescu }; 29434ff6846SIoana Radulescu 29534ff6846SIoana Radulescu /* Maximum number of queues associated with a DPNI */ 29615c87f6bSIoana Radulescu #define DPAA2_ETH_MAX_TCS 8 297*685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES_PER_TC 16 298*685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES \ 299*685e39eaSIoana Radulescu (DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS) 30034ff6846SIoana Radulescu #define DPAA2_ETH_MAX_TX_QUEUES 16 30134ff6846SIoana Radulescu #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \ 30234ff6846SIoana Radulescu DPAA2_ETH_MAX_TX_QUEUES) 303ab1e6de2SIoana Radulescu #define DPAA2_ETH_MAX_NETDEV_QUEUES \ 304ab1e6de2SIoana Radulescu (DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS) 30534ff6846SIoana Radulescu 30634ff6846SIoana Radulescu #define DPAA2_ETH_MAX_DPCONS 16 30734ff6846SIoana Radulescu 30834ff6846SIoana Radulescu enum dpaa2_eth_fq_type { 30934ff6846SIoana Radulescu DPAA2_RX_FQ = 0, 31034ff6846SIoana Radulescu DPAA2_TX_CONF_FQ, 31134ff6846SIoana Radulescu }; 31234ff6846SIoana Radulescu 31334ff6846SIoana Radulescu struct dpaa2_eth_priv; 31434ff6846SIoana Radulescu 31538c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds { 31638c440b2SIoana Ciornei struct dpaa2_fd fds[DEV_MAP_BULK_SIZE]; 31738c440b2SIoana Ciornei ssize_t num; 31838c440b2SIoana Ciornei }; 31938c440b2SIoana Ciornei 32034ff6846SIoana Radulescu struct dpaa2_eth_fq { 32134ff6846SIoana Radulescu u32 fqid; 32234ff6846SIoana Radulescu u32 tx_qdbin; 32315c87f6bSIoana Radulescu u32 tx_fqid[DPAA2_ETH_MAX_TCS]; 32434ff6846SIoana Radulescu u16 flowid; 32515c87f6bSIoana Radulescu u8 tc; 32634ff6846SIoana Radulescu int target_cpu; 327569dac6aSIoana Ciocoi Radulescu u32 dq_frames; 328569dac6aSIoana Ciocoi Radulescu u32 dq_bytes; 32934ff6846SIoana Radulescu struct dpaa2_eth_channel *channel; 33034ff6846SIoana Radulescu enum dpaa2_eth_fq_type type; 33134ff6846SIoana Radulescu 33234ff6846SIoana Radulescu void (*consume)(struct dpaa2_eth_priv *priv, 33334ff6846SIoana Radulescu struct dpaa2_eth_channel *ch, 33434ff6846SIoana Radulescu const struct dpaa2_fd *fd, 335dbcdf728SIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq); 33634ff6846SIoana Radulescu struct dpaa2_eth_fq_stats stats; 3378665d978SIoana Ciornei 33838c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_redirect_fds; 33974a1c059SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_tx_fds; 34034ff6846SIoana Radulescu }; 34134ff6846SIoana Radulescu 3427e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp { 3437e273a8eSIoana Ciocoi Radulescu struct bpf_prog *prog; 3445d39dc21SIoana Ciocoi Radulescu u64 drop_bufs[DPAA2_ETH_BUFS_PER_CMD]; 3455d39dc21SIoana Ciocoi Radulescu int drop_cnt; 346d678be1dSIoana Radulescu unsigned int res; 3477e273a8eSIoana Ciocoi Radulescu }; 3487e273a8eSIoana Ciocoi Radulescu 34934ff6846SIoana Radulescu struct dpaa2_eth_channel { 35034ff6846SIoana Radulescu struct dpaa2_io_notification_ctx nctx; 35134ff6846SIoana Radulescu struct fsl_mc_device *dpcon; 35234ff6846SIoana Radulescu int dpcon_id; 35334ff6846SIoana Radulescu int ch_id; 35434ff6846SIoana Radulescu struct napi_struct napi; 35534ff6846SIoana Radulescu struct dpaa2_io *dpio; 35634ff6846SIoana Radulescu struct dpaa2_io_store *store; 35734ff6846SIoana Radulescu struct dpaa2_eth_priv *priv; 35834ff6846SIoana Radulescu int buf_count; 35934ff6846SIoana Radulescu struct dpaa2_eth_ch_stats stats; 3607e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp xdp; 361d678be1dSIoana Radulescu struct xdp_rxq_info xdp_rxq; 3620a25d92cSIoana Ciornei struct list_head *rx_list; 36334ff6846SIoana Radulescu }; 36434ff6846SIoana Radulescu 365f76c483aSIoana Radulescu struct dpaa2_eth_dist_fields { 36634ff6846SIoana Radulescu u64 rxnfc_field; 36734ff6846SIoana Radulescu enum net_prot cls_prot; 36834ff6846SIoana Radulescu int cls_field; 36934ff6846SIoana Radulescu int size; 3703a1e6b84SIoana Ciocoi Radulescu u64 id; 37134ff6846SIoana Radulescu }; 37234ff6846SIoana Radulescu 373afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule { 374afb90dbbSIoana Radulescu struct ethtool_rx_flow_spec fs; 375afb90dbbSIoana Radulescu u8 in_use; 376afb90dbbSIoana Radulescu }; 377afb90dbbSIoana Radulescu 37834ff6846SIoana Radulescu /* Driver private data */ 37934ff6846SIoana Radulescu struct dpaa2_eth_priv { 38034ff6846SIoana Radulescu struct net_device *net_dev; 38134ff6846SIoana Radulescu 38234ff6846SIoana Radulescu u8 num_fqs; 38334ff6846SIoana Radulescu struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES]; 3841fa0f68cSIoana Ciocoi Radulescu int (*enqueue)(struct dpaa2_eth_priv *priv, 3851fa0f68cSIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq, 38648c0481eSIoana Ciornei struct dpaa2_fd *fd, u8 prio, 3876ff80447SIoana Ciornei u32 num_frames, 38848c0481eSIoana Ciornei int *frames_enqueued); 38934ff6846SIoana Radulescu 39034ff6846SIoana Radulescu u8 num_channels; 39134ff6846SIoana Radulescu struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS]; 39234ff6846SIoana Radulescu 39334ff6846SIoana Radulescu struct dpni_attr dpni_attrs; 39434ff6846SIoana Radulescu u16 dpni_ver_major; 39534ff6846SIoana Radulescu u16 dpni_ver_minor; 39634ff6846SIoana Radulescu u16 tx_data_offset; 39734ff6846SIoana Radulescu 39834ff6846SIoana Radulescu struct fsl_mc_device *dpbp_dev; 399efa6a7d0SIoana Ciornei u16 rx_buf_size; 40034ff6846SIoana Radulescu u16 bpid; 40134ff6846SIoana Radulescu struct iommu_domain *iommu_domain; 40234ff6846SIoana Radulescu 40334ff6846SIoana Radulescu bool tx_tstamp; /* Tx timestamping enabled */ 40434ff6846SIoana Radulescu bool rx_tstamp; /* Rx timestamping enabled */ 40534ff6846SIoana Radulescu 40634ff6846SIoana Radulescu u16 tx_qdid; 40734ff6846SIoana Radulescu struct fsl_mc_io *mc_io; 40834ff6846SIoana Radulescu /* Cores which have an affine DPIO/DPCON. 40934ff6846SIoana Radulescu * This is the cpu set on which Rx and Tx conf frames are processed 41034ff6846SIoana Radulescu */ 41134ff6846SIoana Radulescu struct cpumask dpio_cpumask; 41234ff6846SIoana Radulescu 41334ff6846SIoana Radulescu /* Standard statistics */ 41434ff6846SIoana Radulescu struct rtnl_link_stats64 __percpu *percpu_stats; 41534ff6846SIoana Radulescu /* Extra stats, in addition to the ones known by the kernel */ 41634ff6846SIoana Radulescu struct dpaa2_eth_drv_stats __percpu *percpu_extras; 41734ff6846SIoana Radulescu 41834ff6846SIoana Radulescu u16 mc_token; 4198eb3cef8SIoana Radulescu u8 rx_td_enabled; 42034ff6846SIoana Radulescu 42134ff6846SIoana Radulescu struct dpni_link_state link_state; 42234ff6846SIoana Radulescu bool do_link_poll; 42334ff6846SIoana Radulescu struct task_struct *poll_thread; 42434ff6846SIoana Radulescu 42534ff6846SIoana Radulescu /* enabled ethtool hashing bits */ 42634ff6846SIoana Radulescu u64 rx_hash_fields; 4272d680237SIoana Ciocoi Radulescu u64 rx_cls_fields; 428afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule *cls_rules; 4294aaaf9b9SIoana Radulescu u8 rx_cls_enabled; 4307e273a8eSIoana Ciocoi Radulescu struct bpf_prog *xdp_prog; 431091a19eaSIoana Radulescu #ifdef CONFIG_DEBUG_FS 432091a19eaSIoana Radulescu struct dpaa2_debugfs dbg; 433091a19eaSIoana Radulescu #endif 43471947923SIoana Ciornei 43571947923SIoana Ciornei struct dpaa2_mac *mac; 43634ff6846SIoana Radulescu }; 43734ff6846SIoana Radulescu 43834ff6846SIoana Radulescu #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \ 43934ff6846SIoana Radulescu | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \ 44034ff6846SIoana Radulescu | RXH_L4_B_2_3) 44134ff6846SIoana Radulescu 44234ff6846SIoana Radulescu /* default Rx hash options, set during probing */ 44334ff6846SIoana Radulescu #define DPAA2_RXH_DEFAULT (RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \ 44434ff6846SIoana Radulescu RXH_L4_B_0_1 | RXH_L4_B_2_3) 44534ff6846SIoana Radulescu 44634ff6846SIoana Radulescu #define dpaa2_eth_hash_enabled(priv) \ 44734ff6846SIoana Radulescu ((priv)->dpni_attrs.num_queues > 1) 44834ff6846SIoana Radulescu 44934ff6846SIoana Radulescu /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */ 45034ff6846SIoana Radulescu #define DPAA2_CLASSIFIER_DMA_SIZE 256 45134ff6846SIoana Radulescu 45234ff6846SIoana Radulescu extern const struct ethtool_ops dpaa2_ethtool_ops; 45334ff6846SIoana Radulescu extern int dpaa2_phc_index; 45434ff6846SIoana Radulescu 45534ff6846SIoana Radulescu static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv, 45634ff6846SIoana Radulescu u16 ver_major, u16 ver_minor) 45734ff6846SIoana Radulescu { 45834ff6846SIoana Radulescu if (priv->dpni_ver_major == ver_major) 45934ff6846SIoana Radulescu return priv->dpni_ver_minor - ver_minor; 46034ff6846SIoana Radulescu return priv->dpni_ver_major - ver_major; 46134ff6846SIoana Radulescu } 46234ff6846SIoana Radulescu 463df85aeb9SIoana Radulescu /* Minimum firmware version that supports a more flexible API 464df85aeb9SIoana Radulescu * for configuring the Rx flow hash key 465df85aeb9SIoana Radulescu */ 466df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MAJOR 7 467df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MINOR 5 468df85aeb9SIoana Radulescu 469df85aeb9SIoana Radulescu #define dpaa2_eth_has_legacy_dist(priv) \ 470df85aeb9SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR, \ 471df85aeb9SIoana Radulescu DPNI_RX_DIST_KEY_VER_MINOR) < 0) 472df85aeb9SIoana Radulescu 47361f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_enabled(priv) \ 47461f9bf00SIoana Ciocoi Radulescu (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS)) 47561f9bf00SIoana Ciocoi Radulescu 47661f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_mask_enabled(priv) \ 47761f9bf00SIoana Ciocoi Radulescu ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING) 47861f9bf00SIoana Ciocoi Radulescu 479afb90dbbSIoana Radulescu #define dpaa2_eth_fs_count(priv) \ 480afb90dbbSIoana Radulescu ((priv)->dpni_attrs.fs_entries) 481afb90dbbSIoana Radulescu 48215c87f6bSIoana Radulescu #define dpaa2_eth_tc_count(priv) \ 48315c87f6bSIoana Radulescu ((priv)->dpni_attrs.num_tcs) 48415c87f6bSIoana Radulescu 485186f21beSIoana Ciornei /* We have exactly one {Rx, Tx conf} queue per channel */ 486186f21beSIoana Ciornei #define dpaa2_eth_queue_count(priv) \ 487186f21beSIoana Ciornei ((priv)->num_channels) 488186f21beSIoana Ciornei 4894aaaf9b9SIoana Radulescu enum dpaa2_eth_rx_dist { 4904aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_HASH, 4914aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_CLS 4924aaaf9b9SIoana Radulescu }; 4934aaaf9b9SIoana Radulescu 4943a1e6b84SIoana Ciocoi Radulescu /* Unique IDs for the supported Rx classification header fields */ 4953a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHDST BIT(0) 4963a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHSRC BIT(1) 4973a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHTYPE BIT(2) 4983a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_VLAN BIT(3) 4993a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPSRC BIT(4) 5003a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPDST BIT(5) 5013a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPPROTO BIT(6) 5023a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4SRC BIT(7) 5033a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4DST BIT(8) 5044ca6dee5SIoana Radulescu #define DPAA2_ETH_DIST_ALL (~0ULL) 5053a1e6b84SIoana Ciocoi Radulescu 5068eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MAJOR 7 5078eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MINOR 13 5088eb3cef8SIoana Radulescu #define dpaa2_eth_has_pause_support(priv) \ 5098eb3cef8SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR, \ 5108eb3cef8SIoana Radulescu DPNI_PAUSE_VER_MINOR) >= 0) 5118eb3cef8SIoana Radulescu 51234ff6846SIoana Radulescu static inline 51334ff6846SIoana Radulescu unsigned int dpaa2_eth_needed_headroom(struct dpaa2_eth_priv *priv, 51434ff6846SIoana Radulescu struct sk_buff *skb) 51534ff6846SIoana Radulescu { 51634ff6846SIoana Radulescu unsigned int headroom = DPAA2_ETH_SWA_SIZE; 51734ff6846SIoana Radulescu 518d678be1dSIoana Radulescu /* If we don't have an skb (e.g. XDP buffer), we only need space for 519d678be1dSIoana Radulescu * the software annotation area 520d678be1dSIoana Radulescu */ 521d678be1dSIoana Radulescu if (!skb) 522d678be1dSIoana Radulescu return headroom; 523d678be1dSIoana Radulescu 52434ff6846SIoana Radulescu /* For non-linear skbs we have no headroom requirement, as we build a 52534ff6846SIoana Radulescu * SG frame with a newly allocated SGT buffer 52634ff6846SIoana Radulescu */ 52734ff6846SIoana Radulescu if (skb_is_nonlinear(skb)) 52834ff6846SIoana Radulescu return 0; 52934ff6846SIoana Radulescu 53034ff6846SIoana Radulescu /* If we have Tx timestamping, need 128B hardware annotation */ 53134ff6846SIoana Radulescu if (priv->tx_tstamp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) 53234ff6846SIoana Radulescu headroom += DPAA2_ETH_TX_HWA_SIZE; 53334ff6846SIoana Radulescu 53434ff6846SIoana Radulescu return headroom; 53534ff6846SIoana Radulescu } 53634ff6846SIoana Radulescu 53734ff6846SIoana Radulescu /* Extra headroom space requested to hardware, in order to make sure there's 53834ff6846SIoana Radulescu * no realloc'ing in forwarding scenarios 53934ff6846SIoana Radulescu */ 54034ff6846SIoana Radulescu static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv) 54134ff6846SIoana Radulescu { 54227c87486SIoana Ciocoi Radulescu return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE; 54334ff6846SIoana Radulescu } 54434ff6846SIoana Radulescu 545edad8d26SIoana Ciocoi Radulescu int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags); 5462d680237SIoana Ciocoi Radulescu int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key); 5472d680237SIoana Ciocoi Radulescu int dpaa2_eth_cls_key_size(u64 key); 548afb90dbbSIoana Radulescu int dpaa2_eth_cls_fld_off(int prot, int field); 5492d680237SIoana Ciocoi Radulescu void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields); 550edad8d26SIoana Ciocoi Radulescu 55134ff6846SIoana Radulescu #endif /* __DPAA2_H */ 552