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 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 11234ff6846SIoana Radulescu /* We are accommodating a skb backpointer and some S/G info 11334ff6846SIoana Radulescu * in the frame's software annotation. The hardware 11434ff6846SIoana Radulescu * options are either 0 or 64, so we choose the latter. 11534ff6846SIoana Radulescu */ 11634ff6846SIoana Radulescu #define DPAA2_ETH_SWA_SIZE 64 11734ff6846SIoana Radulescu 118e3fdf6baSIoana Radulescu /* We store different information in the software annotation area of a Tx frame 119e3fdf6baSIoana Radulescu * based on what type of frame it is 120e3fdf6baSIoana Radulescu */ 121e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type { 122e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SINGLE, 123e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SG, 124d678be1dSIoana Radulescu DPAA2_ETH_SWA_XDP, 125e3fdf6baSIoana Radulescu }; 126e3fdf6baSIoana Radulescu 12734ff6846SIoana Radulescu /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */ 12834ff6846SIoana Radulescu struct dpaa2_eth_swa { 129e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type type; 130e3fdf6baSIoana Radulescu union { 131e3fdf6baSIoana Radulescu struct { 132e3fdf6baSIoana Radulescu struct sk_buff *skb; 133d70446eeSIoana Ciornei int sgt_size; 134e3fdf6baSIoana Radulescu } single; 135e3fdf6baSIoana Radulescu struct { 13634ff6846SIoana Radulescu struct sk_buff *skb; 13734ff6846SIoana Radulescu struct scatterlist *scl; 13834ff6846SIoana Radulescu int num_sg; 13934ff6846SIoana Radulescu int sgt_size; 140e3fdf6baSIoana Radulescu } sg; 141d678be1dSIoana Radulescu struct { 142d678be1dSIoana Radulescu int dma_size; 143d678be1dSIoana Radulescu struct xdp_frame *xdpf; 144d678be1dSIoana Radulescu } xdp; 145e3fdf6baSIoana Radulescu }; 14634ff6846SIoana Radulescu }; 14734ff6846SIoana Radulescu 14834ff6846SIoana Radulescu /* Annotation valid bits in FD FRC */ 14934ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASV 0x8000 15034ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAEADV 0x4000 15134ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAPRV 0x2000 15234ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAIADV 0x1000 15334ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASWOV 0x0800 15434ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAICFDV 0x0400 15534ff6846SIoana Radulescu 15634ff6846SIoana Radulescu /* Error bits in FD CTRL */ 15734ff6846SIoana Radulescu #define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR) 15834ff6846SIoana Radulescu #define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \ 15934ff6846SIoana Radulescu FD_CTRL_SBE | \ 16034ff6846SIoana Radulescu FD_CTRL_FSE | \ 16134ff6846SIoana Radulescu FD_CTRL_FAERR) 16234ff6846SIoana Radulescu 16334ff6846SIoana Radulescu /* Annotation bits in FD CTRL */ 16434ff6846SIoana Radulescu #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128B */ 16534ff6846SIoana Radulescu 16634ff6846SIoana Radulescu /* Frame annotation status */ 16734ff6846SIoana Radulescu struct dpaa2_fas { 16834ff6846SIoana Radulescu u8 reserved; 16934ff6846SIoana Radulescu u8 ppid; 17034ff6846SIoana Radulescu __le16 ifpid; 17134ff6846SIoana Radulescu __le32 status; 17234ff6846SIoana Radulescu }; 17334ff6846SIoana Radulescu 17434ff6846SIoana Radulescu /* Frame annotation status word is located in the first 8 bytes 17534ff6846SIoana Radulescu * of the buffer's hardware annoatation area 17634ff6846SIoana Radulescu */ 17734ff6846SIoana Radulescu #define DPAA2_FAS_OFFSET 0 17834ff6846SIoana Radulescu #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas)) 17934ff6846SIoana Radulescu 18034ff6846SIoana Radulescu /* Timestamp is located in the next 8 bytes of the buffer's 18134ff6846SIoana Radulescu * hardware annotation area 18234ff6846SIoana Radulescu */ 18334ff6846SIoana Radulescu #define DPAA2_TS_OFFSET 0x8 18434ff6846SIoana Radulescu 185061d631fSIoana Ciornei /* Frame annotation parse results */ 186061d631fSIoana Ciornei struct dpaa2_fapr { 187061d631fSIoana Ciornei /* 64-bit word 1 */ 188061d631fSIoana Ciornei __le32 faf_lo; 189061d631fSIoana Ciornei __le16 faf_ext; 190061d631fSIoana Ciornei __le16 nxt_hdr; 191061d631fSIoana Ciornei /* 64-bit word 2 */ 192061d631fSIoana Ciornei __le64 faf_hi; 193061d631fSIoana Ciornei /* 64-bit word 3 */ 194061d631fSIoana Ciornei u8 last_ethertype_offset; 195061d631fSIoana Ciornei u8 vlan_tci_offset_n; 196061d631fSIoana Ciornei u8 vlan_tci_offset_1; 197061d631fSIoana Ciornei u8 llc_snap_offset; 198061d631fSIoana Ciornei u8 eth_offset; 199061d631fSIoana Ciornei u8 ip1_pid_offset; 200061d631fSIoana Ciornei u8 shim_offset_2; 201061d631fSIoana Ciornei u8 shim_offset_1; 202061d631fSIoana Ciornei /* 64-bit word 4 */ 203061d631fSIoana Ciornei u8 l5_offset; 204061d631fSIoana Ciornei u8 l4_offset; 205061d631fSIoana Ciornei u8 gre_offset; 206061d631fSIoana Ciornei u8 l3_offset_n; 207061d631fSIoana Ciornei u8 l3_offset_1; 208061d631fSIoana Ciornei u8 mpls_offset_n; 209061d631fSIoana Ciornei u8 mpls_offset_1; 210061d631fSIoana Ciornei u8 pppoe_offset; 211061d631fSIoana Ciornei /* 64-bit word 5 */ 212061d631fSIoana Ciornei __le16 running_sum; 213061d631fSIoana Ciornei __le16 gross_running_sum; 214061d631fSIoana Ciornei u8 ipv6_frag_offset; 215061d631fSIoana Ciornei u8 nxt_hdr_offset; 216061d631fSIoana Ciornei u8 routing_hdr_offset_2; 217061d631fSIoana Ciornei u8 routing_hdr_offset_1; 218061d631fSIoana Ciornei /* 64-bit word 6 */ 219061d631fSIoana Ciornei u8 reserved[5]; /* Soft-parsing context */ 220061d631fSIoana Ciornei u8 ip_proto_offset_n; 221061d631fSIoana Ciornei u8 nxt_hdr_frag_offset; 222061d631fSIoana Ciornei u8 parse_error_code; 223061d631fSIoana Ciornei }; 224061d631fSIoana Ciornei 225061d631fSIoana Ciornei #define DPAA2_FAPR_OFFSET 0x10 226061d631fSIoana Ciornei #define DPAA2_FAPR_SIZE sizeof((struct dpaa2_fapr)) 227061d631fSIoana Ciornei 22834ff6846SIoana Radulescu /* Frame annotation egress action descriptor */ 22934ff6846SIoana Radulescu #define DPAA2_FAEAD_OFFSET 0x58 23034ff6846SIoana Radulescu 23134ff6846SIoana Radulescu struct dpaa2_faead { 23234ff6846SIoana Radulescu __le32 conf_fqid; 23334ff6846SIoana Radulescu __le32 ctrl; 23434ff6846SIoana Radulescu }; 23534ff6846SIoana Radulescu 23634ff6846SIoana Radulescu #define DPAA2_FAEAD_A2V 0x20000000 23799e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_A4V 0x08000000 23834ff6846SIoana Radulescu #define DPAA2_FAEAD_UPDV 0x00001000 23999e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_EBDDV 0x00002000 24034ff6846SIoana Radulescu #define DPAA2_FAEAD_UPD 0x00000010 24134ff6846SIoana Radulescu 242c5521189SYangbo Lu struct ptp_tstamp { 243c5521189SYangbo Lu u16 sec_msb; 244c5521189SYangbo Lu u32 sec_lsb; 245c5521189SYangbo Lu u32 nsec; 246c5521189SYangbo Lu }; 247c5521189SYangbo Lu 248c5521189SYangbo Lu static inline void ns_to_ptp_tstamp(struct ptp_tstamp *tstamp, u64 ns) 249c5521189SYangbo Lu { 250c5521189SYangbo Lu u64 sec, nsec; 251c5521189SYangbo Lu 252c5521189SYangbo Lu sec = ns; 253c5521189SYangbo Lu nsec = do_div(sec, 1000000000); 254c5521189SYangbo Lu 255c5521189SYangbo Lu tstamp->sec_lsb = sec & 0xFFFFFFFF; 256c5521189SYangbo Lu tstamp->sec_msb = (sec >> 32) & 0xFFFF; 257c5521189SYangbo Lu tstamp->nsec = nsec; 258c5521189SYangbo Lu } 259c5521189SYangbo Lu 26034ff6846SIoana Radulescu /* Accessors for the hardware annotation fields that we use */ 26134ff6846SIoana Radulescu static inline void *dpaa2_get_hwa(void *buf_addr, bool swa) 26234ff6846SIoana Radulescu { 26334ff6846SIoana Radulescu return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0); 26434ff6846SIoana Radulescu } 26534ff6846SIoana Radulescu 26634ff6846SIoana Radulescu static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa) 26734ff6846SIoana Radulescu { 26834ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET; 26934ff6846SIoana Radulescu } 27034ff6846SIoana Radulescu 27134ff6846SIoana Radulescu static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa) 27234ff6846SIoana Radulescu { 27334ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET; 27434ff6846SIoana Radulescu } 27534ff6846SIoana Radulescu 276061d631fSIoana Ciornei static inline struct dpaa2_fapr *dpaa2_get_fapr(void *buf_addr, bool swa) 277061d631fSIoana Ciornei { 278061d631fSIoana Ciornei return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAPR_OFFSET; 279061d631fSIoana Ciornei } 280061d631fSIoana Ciornei 28134ff6846SIoana Radulescu static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa) 28234ff6846SIoana Radulescu { 28334ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET; 28434ff6846SIoana Radulescu } 28534ff6846SIoana Radulescu 28634ff6846SIoana Radulescu /* Error and status bits in the frame annotation status word */ 28734ff6846SIoana Radulescu /* Debug frame, otherwise supposed to be discarded */ 28834ff6846SIoana Radulescu #define DPAA2_FAS_DISC 0x80000000 28934ff6846SIoana Radulescu /* MACSEC frame */ 29034ff6846SIoana Radulescu #define DPAA2_FAS_MS 0x40000000 29134ff6846SIoana Radulescu #define DPAA2_FAS_PTP 0x08000000 29234ff6846SIoana Radulescu /* Ethernet multicast frame */ 29334ff6846SIoana Radulescu #define DPAA2_FAS_MC 0x04000000 29434ff6846SIoana Radulescu /* Ethernet broadcast frame */ 29534ff6846SIoana Radulescu #define DPAA2_FAS_BC 0x02000000 29634ff6846SIoana Radulescu #define DPAA2_FAS_KSE 0x00040000 29734ff6846SIoana Radulescu #define DPAA2_FAS_EOFHE 0x00020000 29834ff6846SIoana Radulescu #define DPAA2_FAS_MNLE 0x00010000 29934ff6846SIoana Radulescu #define DPAA2_FAS_TIDE 0x00008000 30034ff6846SIoana Radulescu #define DPAA2_FAS_PIEE 0x00004000 30134ff6846SIoana Radulescu /* Frame length error */ 30234ff6846SIoana Radulescu #define DPAA2_FAS_FLE 0x00002000 30334ff6846SIoana Radulescu /* Frame physical error */ 30434ff6846SIoana Radulescu #define DPAA2_FAS_FPE 0x00001000 30534ff6846SIoana Radulescu #define DPAA2_FAS_PTE 0x00000080 30634ff6846SIoana Radulescu #define DPAA2_FAS_ISP 0x00000040 30734ff6846SIoana Radulescu #define DPAA2_FAS_PHE 0x00000020 30834ff6846SIoana Radulescu #define DPAA2_FAS_BLE 0x00000010 30934ff6846SIoana Radulescu /* L3 csum validation performed */ 31034ff6846SIoana Radulescu #define DPAA2_FAS_L3CV 0x00000008 31134ff6846SIoana Radulescu /* L3 csum error */ 31234ff6846SIoana Radulescu #define DPAA2_FAS_L3CE 0x00000004 31334ff6846SIoana Radulescu /* L4 csum validation performed */ 31434ff6846SIoana Radulescu #define DPAA2_FAS_L4CV 0x00000002 31534ff6846SIoana Radulescu /* L4 csum error */ 31634ff6846SIoana Radulescu #define DPAA2_FAS_L4CE 0x00000001 31734ff6846SIoana Radulescu /* Possible errors on the ingress path */ 31834ff6846SIoana Radulescu #define DPAA2_FAS_RX_ERR_MASK (DPAA2_FAS_KSE | \ 31934ff6846SIoana Radulescu DPAA2_FAS_EOFHE | \ 32034ff6846SIoana Radulescu DPAA2_FAS_MNLE | \ 32134ff6846SIoana Radulescu DPAA2_FAS_TIDE | \ 32234ff6846SIoana Radulescu DPAA2_FAS_PIEE | \ 32334ff6846SIoana Radulescu DPAA2_FAS_FLE | \ 32434ff6846SIoana Radulescu DPAA2_FAS_FPE | \ 32534ff6846SIoana Radulescu DPAA2_FAS_PTE | \ 32634ff6846SIoana Radulescu DPAA2_FAS_ISP | \ 32734ff6846SIoana Radulescu DPAA2_FAS_PHE | \ 32834ff6846SIoana Radulescu DPAA2_FAS_BLE | \ 32934ff6846SIoana Radulescu DPAA2_FAS_L3CE | \ 33034ff6846SIoana Radulescu DPAA2_FAS_L4CE) 33134ff6846SIoana Radulescu 33234ff6846SIoana Radulescu /* Time in milliseconds between link state updates */ 33334ff6846SIoana Radulescu #define DPAA2_ETH_LINK_STATE_REFRESH 1000 33434ff6846SIoana Radulescu 33534ff6846SIoana Radulescu /* Number of times to retry a frame enqueue before giving up. 33634ff6846SIoana Radulescu * Value determined empirically, in order to minimize the number 33734ff6846SIoana Radulescu * of frames dropped on Tx 33834ff6846SIoana Radulescu */ 33934ff6846SIoana Radulescu #define DPAA2_ETH_ENQUEUE_RETRIES 10 34034ff6846SIoana Radulescu 341ef17bd7cSIoana Radulescu /* Number of times to retry DPIO portal operations while waiting 342ef17bd7cSIoana Radulescu * for portal to finish executing current command and become 343ef17bd7cSIoana Radulescu * available. We want to avoid being stuck in a while loop in case 344ef17bd7cSIoana Radulescu * hardware becomes unresponsive, but not give up too easily if 345ef17bd7cSIoana Radulescu * the portal really is busy for valid reasons 346ef17bd7cSIoana Radulescu */ 347ef17bd7cSIoana Radulescu #define DPAA2_ETH_SWP_BUSY_RETRIES 1000 348ef17bd7cSIoana Radulescu 34934ff6846SIoana Radulescu /* Driver statistics, other than those in struct rtnl_link_stats64. 35034ff6846SIoana Radulescu * These are usually collected per-CPU and aggregated by ethtool. 35134ff6846SIoana Radulescu */ 35234ff6846SIoana Radulescu struct dpaa2_eth_drv_stats { 35334ff6846SIoana Radulescu __u64 tx_conf_frames; 35434ff6846SIoana Radulescu __u64 tx_conf_bytes; 35534ff6846SIoana Radulescu __u64 tx_sg_frames; 35634ff6846SIoana Radulescu __u64 tx_sg_bytes; 35734ff6846SIoana Radulescu __u64 rx_sg_frames; 35834ff6846SIoana Radulescu __u64 rx_sg_bytes; 3594c96c0acSIoana Ciornei /* Linear skbs sent as a S/G FD due to insufficient headroom */ 3604c96c0acSIoana Ciornei __u64 tx_converted_sg_frames; 3614c96c0acSIoana Ciornei __u64 tx_converted_sg_bytes; 36234ff6846SIoana Radulescu /* Enqueues retried due to portal busy */ 36334ff6846SIoana Radulescu __u64 tx_portal_busy; 36434ff6846SIoana Radulescu }; 36534ff6846SIoana Radulescu 36634ff6846SIoana Radulescu /* Per-FQ statistics */ 36734ff6846SIoana Radulescu struct dpaa2_eth_fq_stats { 36834ff6846SIoana Radulescu /* Number of frames received on this queue */ 36934ff6846SIoana Radulescu __u64 frames; 37034ff6846SIoana Radulescu }; 37134ff6846SIoana Radulescu 37234ff6846SIoana Radulescu /* Per-channel statistics */ 37334ff6846SIoana Radulescu struct dpaa2_eth_ch_stats { 37434ff6846SIoana Radulescu /* Volatile dequeues retried due to portal busy */ 37534ff6846SIoana Radulescu __u64 dequeue_portal_busy; 37634ff6846SIoana Radulescu /* Pull errors */ 37734ff6846SIoana Radulescu __u64 pull_err; 3780ff8f0aaSIoana Ciocoi Radulescu /* Number of CDANs; useful to estimate avg NAPI len */ 3790ff8f0aaSIoana Ciocoi Radulescu __u64 cdan; 380a4a7b762SIoana Ciocoi Radulescu /* XDP counters */ 381a4a7b762SIoana Ciocoi Radulescu __u64 xdp_drop; 382a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx; 383a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx_err; 384d678be1dSIoana Radulescu __u64 xdp_redirect; 385460fd830SIoana Ciornei /* Must be last, does not show up in ethtool stats */ 386460fd830SIoana Ciornei __u64 frames; 387fc398becSIoana Ciornei __u64 frames_per_cdan; 388fc398becSIoana Ciornei __u64 bytes_per_cdan; 38934ff6846SIoana Radulescu }; 39034ff6846SIoana Radulescu 391972ce7e3SIoana Ciornei #define DPAA2_ETH_CH_STATS 7 392972ce7e3SIoana Ciornei 39334ff6846SIoana Radulescu /* Maximum number of queues associated with a DPNI */ 39415c87f6bSIoana Radulescu #define DPAA2_ETH_MAX_TCS 8 395685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES_PER_TC 16 396685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES \ 397685e39eaSIoana Radulescu (DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS) 39834ff6846SIoana Radulescu #define DPAA2_ETH_MAX_TX_QUEUES 16 399061d631fSIoana Ciornei #define DPAA2_ETH_MAX_RX_ERR_QUEUES 1 40034ff6846SIoana Radulescu #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \ 401061d631fSIoana Ciornei DPAA2_ETH_MAX_TX_QUEUES + \ 402061d631fSIoana Ciornei DPAA2_ETH_MAX_RX_ERR_QUEUES) 403ab1e6de2SIoana Radulescu #define DPAA2_ETH_MAX_NETDEV_QUEUES \ 404ab1e6de2SIoana Radulescu (DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS) 40534ff6846SIoana Radulescu 40634ff6846SIoana Radulescu #define DPAA2_ETH_MAX_DPCONS 16 40734ff6846SIoana Radulescu 40834ff6846SIoana Radulescu enum dpaa2_eth_fq_type { 40934ff6846SIoana Radulescu DPAA2_RX_FQ = 0, 41034ff6846SIoana Radulescu DPAA2_TX_CONF_FQ, 411061d631fSIoana Ciornei DPAA2_RX_ERR_FQ 41234ff6846SIoana Radulescu }; 41334ff6846SIoana Radulescu 41434ff6846SIoana Radulescu struct dpaa2_eth_priv; 41534ff6846SIoana Radulescu 41638c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds { 41738c440b2SIoana Ciornei struct dpaa2_fd fds[DEV_MAP_BULK_SIZE]; 41838c440b2SIoana Ciornei ssize_t num; 41938c440b2SIoana Ciornei }; 42038c440b2SIoana Ciornei 42134ff6846SIoana Radulescu struct dpaa2_eth_fq { 42234ff6846SIoana Radulescu u32 fqid; 42334ff6846SIoana Radulescu u32 tx_qdbin; 42415c87f6bSIoana Radulescu u32 tx_fqid[DPAA2_ETH_MAX_TCS]; 42534ff6846SIoana Radulescu u16 flowid; 42615c87f6bSIoana Radulescu u8 tc; 42734ff6846SIoana Radulescu int target_cpu; 428569dac6aSIoana Ciocoi Radulescu u32 dq_frames; 429569dac6aSIoana Ciocoi Radulescu u32 dq_bytes; 43034ff6846SIoana Radulescu struct dpaa2_eth_channel *channel; 43134ff6846SIoana Radulescu enum dpaa2_eth_fq_type type; 43234ff6846SIoana Radulescu 43334ff6846SIoana Radulescu void (*consume)(struct dpaa2_eth_priv *priv, 43434ff6846SIoana Radulescu struct dpaa2_eth_channel *ch, 43534ff6846SIoana Radulescu const struct dpaa2_fd *fd, 436dbcdf728SIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq); 43734ff6846SIoana Radulescu struct dpaa2_eth_fq_stats stats; 4388665d978SIoana Ciornei 43938c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_redirect_fds; 44074a1c059SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_tx_fds; 44134ff6846SIoana Radulescu }; 44234ff6846SIoana Radulescu 4437e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp { 4447e273a8eSIoana Ciocoi Radulescu struct bpf_prog *prog; 445d678be1dSIoana Radulescu unsigned int res; 4467e273a8eSIoana Ciocoi Radulescu }; 4477e273a8eSIoana Ciocoi Radulescu 44834ff6846SIoana Radulescu struct dpaa2_eth_channel { 44934ff6846SIoana Radulescu struct dpaa2_io_notification_ctx nctx; 45034ff6846SIoana Radulescu struct fsl_mc_device *dpcon; 45134ff6846SIoana Radulescu int dpcon_id; 45234ff6846SIoana Radulescu int ch_id; 45334ff6846SIoana Radulescu struct napi_struct napi; 45434ff6846SIoana Radulescu struct dpaa2_io *dpio; 45534ff6846SIoana Radulescu struct dpaa2_io_store *store; 45634ff6846SIoana Radulescu struct dpaa2_eth_priv *priv; 45734ff6846SIoana Radulescu int buf_count; 45834ff6846SIoana Radulescu struct dpaa2_eth_ch_stats stats; 4597e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp xdp; 460d678be1dSIoana Radulescu struct xdp_rxq_info xdp_rxq; 4610a25d92cSIoana Ciornei struct list_head *rx_list; 46228d137ccSIoana Ciornei 46328d137ccSIoana Ciornei /* Buffers to be recycled back in the buffer pool */ 46428d137ccSIoana Ciornei u64 recycled_bufs[DPAA2_ETH_BUFS_PER_CMD]; 46528d137ccSIoana Ciornei int recycled_bufs_cnt; 46634ff6846SIoana Radulescu }; 46734ff6846SIoana Radulescu 468f76c483aSIoana Radulescu struct dpaa2_eth_dist_fields { 46934ff6846SIoana Radulescu u64 rxnfc_field; 47034ff6846SIoana Radulescu enum net_prot cls_prot; 47134ff6846SIoana Radulescu int cls_field; 47234ff6846SIoana Radulescu int size; 4733a1e6b84SIoana Ciocoi Radulescu u64 id; 47434ff6846SIoana Radulescu }; 47534ff6846SIoana Radulescu 476afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule { 477afb90dbbSIoana Radulescu struct ethtool_rx_flow_spec fs; 478afb90dbbSIoana Radulescu u8 in_use; 479afb90dbbSIoana Radulescu }; 480afb90dbbSIoana Radulescu 481d70446eeSIoana Ciornei #define DPAA2_ETH_SGT_CACHE_SIZE 256 482d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache { 483d70446eeSIoana Ciornei void *buf[DPAA2_ETH_SGT_CACHE_SIZE]; 484d70446eeSIoana Ciornei u16 count; 485d70446eeSIoana Ciornei }; 486d70446eeSIoana Ciornei 487061d631fSIoana Ciornei struct dpaa2_eth_trap_item { 488061d631fSIoana Ciornei void *trap_ctx; 489061d631fSIoana Ciornei }; 490061d631fSIoana Ciornei 491061d631fSIoana Ciornei struct dpaa2_eth_trap_data { 492061d631fSIoana Ciornei struct dpaa2_eth_trap_item *trap_items_arr; 493061d631fSIoana Ciornei struct dpaa2_eth_priv *priv; 494061d631fSIoana Ciornei }; 495061d631fSIoana Ciornei 496*a4218aefSIoana Ciornei #define DPAA2_ETH_SG_ENTRIES_MAX (PAGE_SIZE / sizeof(struct scatterlist)) 497*a4218aefSIoana Ciornei 49850f82699SIoana Ciornei #define DPAA2_ETH_DEFAULT_COPYBREAK 512 49950f82699SIoana Ciornei 50034ff6846SIoana Radulescu /* Driver private data */ 50134ff6846SIoana Radulescu struct dpaa2_eth_priv { 50234ff6846SIoana Radulescu struct net_device *net_dev; 50334ff6846SIoana Radulescu 50434ff6846SIoana Radulescu u8 num_fqs; 50534ff6846SIoana Radulescu struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES]; 5061fa0f68cSIoana Ciocoi Radulescu int (*enqueue)(struct dpaa2_eth_priv *priv, 5071fa0f68cSIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq, 50848c0481eSIoana Ciornei struct dpaa2_fd *fd, u8 prio, 5096ff80447SIoana Ciornei u32 num_frames, 51048c0481eSIoana Ciornei int *frames_enqueued); 51134ff6846SIoana Radulescu 51234ff6846SIoana Radulescu u8 num_channels; 51334ff6846SIoana Radulescu struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS]; 514d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache __percpu *sgt_cache; 51534ff6846SIoana Radulescu 51634ff6846SIoana Radulescu struct dpni_attr dpni_attrs; 51734ff6846SIoana Radulescu u16 dpni_ver_major; 51834ff6846SIoana Radulescu u16 dpni_ver_minor; 51934ff6846SIoana Radulescu u16 tx_data_offset; 52034ff6846SIoana Radulescu 52134ff6846SIoana Radulescu struct fsl_mc_device *dpbp_dev; 522efa6a7d0SIoana Ciornei u16 rx_buf_size; 52334ff6846SIoana Radulescu u16 bpid; 52434ff6846SIoana Radulescu struct iommu_domain *iommu_domain; 52534ff6846SIoana Radulescu 5261cf773bdSYangbo Lu enum hwtstamp_tx_types tx_tstamp_type; /* Tx timestamping type */ 52734ff6846SIoana Radulescu bool rx_tstamp; /* Rx timestamping enabled */ 52834ff6846SIoana Radulescu 52934ff6846SIoana Radulescu u16 tx_qdid; 53034ff6846SIoana Radulescu struct fsl_mc_io *mc_io; 53134ff6846SIoana Radulescu /* Cores which have an affine DPIO/DPCON. 53234ff6846SIoana Radulescu * This is the cpu set on which Rx and Tx conf frames are processed 53334ff6846SIoana Radulescu */ 53434ff6846SIoana Radulescu struct cpumask dpio_cpumask; 53534ff6846SIoana Radulescu 53634ff6846SIoana Radulescu /* Standard statistics */ 53734ff6846SIoana Radulescu struct rtnl_link_stats64 __percpu *percpu_stats; 53834ff6846SIoana Radulescu /* Extra stats, in addition to the ones known by the kernel */ 53934ff6846SIoana Radulescu struct dpaa2_eth_drv_stats __percpu *percpu_extras; 54034ff6846SIoana Radulescu 54134ff6846SIoana Radulescu u16 mc_token; 54207beb165SIoana Ciornei u8 rx_fqtd_enabled; 54307beb165SIoana Ciornei u8 rx_cgtd_enabled; 54434ff6846SIoana Radulescu 54534ff6846SIoana Radulescu struct dpni_link_state link_state; 54634ff6846SIoana Radulescu bool do_link_poll; 54734ff6846SIoana Radulescu struct task_struct *poll_thread; 54834ff6846SIoana Radulescu 54934ff6846SIoana Radulescu /* enabled ethtool hashing bits */ 55034ff6846SIoana Radulescu u64 rx_hash_fields; 5512d680237SIoana Ciocoi Radulescu u64 rx_cls_fields; 552afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule *cls_rules; 5534aaaf9b9SIoana Radulescu u8 rx_cls_enabled; 5546aa90fe2SIoana Radulescu u8 vlan_cls_enabled; 55507beb165SIoana Ciornei u8 pfc_enabled; 556f395b69fSIoana Ciornei #ifdef CONFIG_FSL_DPAA2_ETH_DCB 557f395b69fSIoana Ciornei u8 dcbx_mode; 558f395b69fSIoana Ciornei struct ieee_pfc pfc; 559f395b69fSIoana Ciornei #endif 5607e273a8eSIoana Ciocoi Radulescu struct bpf_prog *xdp_prog; 561091a19eaSIoana Radulescu #ifdef CONFIG_DEBUG_FS 562091a19eaSIoana Radulescu struct dpaa2_debugfs dbg; 563091a19eaSIoana Radulescu #endif 56471947923SIoana Ciornei 56571947923SIoana Ciornei struct dpaa2_mac *mac; 566c5521189SYangbo Lu struct workqueue_struct *dpaa2_ptp_wq; 567c5521189SYangbo Lu struct work_struct tx_onestep_tstamp; 568c5521189SYangbo Lu struct sk_buff_head tx_skbs; 569c5521189SYangbo Lu /* The one-step timestamping configuration on hardware 570c5521189SYangbo Lu * registers could only be done when no one-step 571c5521189SYangbo Lu * timestamping frames are in flight. So we use a mutex 572c5521189SYangbo Lu * lock here to make sure the lock is released by last 573c5521189SYangbo Lu * one-step timestamping packet through TX confirmation 574c5521189SYangbo Lu * queue before transmit current packet. 575c5521189SYangbo Lu */ 576c5521189SYangbo Lu struct mutex onestep_tstamp_lock; 577ceeb03adSIoana Ciornei struct devlink *devlink; 578061d631fSIoana Ciornei struct dpaa2_eth_trap_data *trap_data; 579ceeb03adSIoana Ciornei struct devlink_port devlink_port; 5808ed3cefcSIoana Ciornei 5818ed3cefcSIoana Ciornei u32 rx_copybreak; 582ceeb03adSIoana Ciornei }; 583ceeb03adSIoana Ciornei 584ceeb03adSIoana Ciornei struct dpaa2_eth_devlink_priv { 585ceeb03adSIoana Ciornei struct dpaa2_eth_priv *dpaa2_priv; 58634ff6846SIoana Radulescu }; 58734ff6846SIoana Radulescu 5881cf773bdSYangbo Lu #define TX_TSTAMP 0x1 589c5521189SYangbo Lu #define TX_TSTAMP_ONESTEP_SYNC 0x2 5901cf773bdSYangbo Lu 59134ff6846SIoana Radulescu #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \ 59234ff6846SIoana Radulescu | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \ 59334ff6846SIoana Radulescu | RXH_L4_B_2_3) 59434ff6846SIoana Radulescu 59534ff6846SIoana Radulescu /* default Rx hash options, set during probing */ 59634ff6846SIoana Radulescu #define DPAA2_RXH_DEFAULT (RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \ 59734ff6846SIoana Radulescu RXH_L4_B_0_1 | RXH_L4_B_2_3) 59834ff6846SIoana Radulescu 59934ff6846SIoana Radulescu #define dpaa2_eth_hash_enabled(priv) \ 60034ff6846SIoana Radulescu ((priv)->dpni_attrs.num_queues > 1) 60134ff6846SIoana Radulescu 60234ff6846SIoana Radulescu /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */ 60334ff6846SIoana Radulescu #define DPAA2_CLASSIFIER_DMA_SIZE 256 60434ff6846SIoana Radulescu 60534ff6846SIoana Radulescu extern const struct ethtool_ops dpaa2_ethtool_ops; 60634ff6846SIoana Radulescu extern int dpaa2_phc_index; 607d21c784cSYangbo Lu extern struct ptp_qoriq *dpaa2_ptp; 60834ff6846SIoana Radulescu 60934ff6846SIoana Radulescu static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv, 61034ff6846SIoana Radulescu u16 ver_major, u16 ver_minor) 61134ff6846SIoana Radulescu { 61234ff6846SIoana Radulescu if (priv->dpni_ver_major == ver_major) 61334ff6846SIoana Radulescu return priv->dpni_ver_minor - ver_minor; 61434ff6846SIoana Radulescu return priv->dpni_ver_major - ver_major; 61534ff6846SIoana Radulescu } 61634ff6846SIoana Radulescu 617df85aeb9SIoana Radulescu /* Minimum firmware version that supports a more flexible API 618df85aeb9SIoana Radulescu * for configuring the Rx flow hash key 619df85aeb9SIoana Radulescu */ 620df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MAJOR 7 621df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MINOR 5 622df85aeb9SIoana Radulescu 623df85aeb9SIoana Radulescu #define dpaa2_eth_has_legacy_dist(priv) \ 624df85aeb9SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR, \ 625df85aeb9SIoana Radulescu DPNI_RX_DIST_KEY_VER_MINOR) < 0) 626df85aeb9SIoana Radulescu 62761f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_enabled(priv) \ 62861f9bf00SIoana Ciocoi Radulescu (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS)) 62961f9bf00SIoana Ciocoi Radulescu 63061f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_mask_enabled(priv) \ 63161f9bf00SIoana Ciocoi Radulescu ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING) 63261f9bf00SIoana Ciocoi Radulescu 633afb90dbbSIoana Radulescu #define dpaa2_eth_fs_count(priv) \ 634afb90dbbSIoana Radulescu ((priv)->dpni_attrs.fs_entries) 635afb90dbbSIoana Radulescu 63615c87f6bSIoana Radulescu #define dpaa2_eth_tc_count(priv) \ 63715c87f6bSIoana Radulescu ((priv)->dpni_attrs.num_tcs) 63815c87f6bSIoana Radulescu 639186f21beSIoana Ciornei /* We have exactly one {Rx, Tx conf} queue per channel */ 640186f21beSIoana Ciornei #define dpaa2_eth_queue_count(priv) \ 641186f21beSIoana Ciornei ((priv)->num_channels) 642186f21beSIoana Ciornei 6434aaaf9b9SIoana Radulescu enum dpaa2_eth_rx_dist { 6444aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_HASH, 6454aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_CLS 6464aaaf9b9SIoana Radulescu }; 6474aaaf9b9SIoana Radulescu 6483a1e6b84SIoana Ciocoi Radulescu /* Unique IDs for the supported Rx classification header fields */ 6493a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHDST BIT(0) 6503a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHSRC BIT(1) 6513a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHTYPE BIT(2) 6523a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_VLAN BIT(3) 6533a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPSRC BIT(4) 6543a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPDST BIT(5) 6553a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPPROTO BIT(6) 6563a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4SRC BIT(7) 6573a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4DST BIT(8) 6584ca6dee5SIoana Radulescu #define DPAA2_ETH_DIST_ALL (~0ULL) 6593a1e6b84SIoana Ciocoi Radulescu 6608eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MAJOR 7 6618eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MINOR 13 6628eb3cef8SIoana Radulescu #define dpaa2_eth_has_pause_support(priv) \ 6638eb3cef8SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR, \ 6648eb3cef8SIoana Radulescu DPNI_PAUSE_VER_MINOR) >= 0) 6658eb3cef8SIoana Radulescu 666ad054f26SIoana Radulescu static inline bool dpaa2_eth_tx_pause_enabled(u64 link_options) 667ad054f26SIoana Radulescu { 668ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE) ^ 669ad054f26SIoana Radulescu !!(link_options & DPNI_LINK_OPT_ASYM_PAUSE); 670ad054f26SIoana Radulescu } 671ad054f26SIoana Radulescu 672ad054f26SIoana Radulescu static inline bool dpaa2_eth_rx_pause_enabled(u64 link_options) 673ad054f26SIoana Radulescu { 674ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE); 675ad054f26SIoana Radulescu } 676ad054f26SIoana Radulescu 6771cf773bdSYangbo Lu static inline unsigned int dpaa2_eth_needed_headroom(struct sk_buff *skb) 67834ff6846SIoana Radulescu { 67934ff6846SIoana Radulescu unsigned int headroom = DPAA2_ETH_SWA_SIZE; 68034ff6846SIoana Radulescu 681d678be1dSIoana Radulescu /* If we don't have an skb (e.g. XDP buffer), we only need space for 682d678be1dSIoana Radulescu * the software annotation area 683d678be1dSIoana Radulescu */ 684d678be1dSIoana Radulescu if (!skb) 685d678be1dSIoana Radulescu return headroom; 686d678be1dSIoana Radulescu 68734ff6846SIoana Radulescu /* For non-linear skbs we have no headroom requirement, as we build a 68834ff6846SIoana Radulescu * SG frame with a newly allocated SGT buffer 68934ff6846SIoana Radulescu */ 69034ff6846SIoana Radulescu if (skb_is_nonlinear(skb)) 69134ff6846SIoana Radulescu return 0; 69234ff6846SIoana Radulescu 69334ff6846SIoana Radulescu /* If we have Tx timestamping, need 128B hardware annotation */ 694c5521189SYangbo Lu if (skb->cb[0]) 69534ff6846SIoana Radulescu headroom += DPAA2_ETH_TX_HWA_SIZE; 69634ff6846SIoana Radulescu 69734ff6846SIoana Radulescu return headroom; 69834ff6846SIoana Radulescu } 69934ff6846SIoana Radulescu 70034ff6846SIoana Radulescu /* Extra headroom space requested to hardware, in order to make sure there's 70134ff6846SIoana Radulescu * no realloc'ing in forwarding scenarios 70234ff6846SIoana Radulescu */ 70334ff6846SIoana Radulescu static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv) 70434ff6846SIoana Radulescu { 70527c87486SIoana Ciocoi Radulescu return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE; 70634ff6846SIoana Radulescu } 70734ff6846SIoana Radulescu 708d87e6063SIoana Ciornei static inline bool dpaa2_eth_is_type_phy(struct dpaa2_eth_priv *priv) 709d87e6063SIoana Ciornei { 710085f1776SRussell King if (priv->mac && 711085f1776SRussell King (priv->mac->attr.link_type == DPMAC_LINK_TYPE_PHY || 712085f1776SRussell King priv->mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE)) 713d87e6063SIoana Ciornei return true; 714d87e6063SIoana Ciornei 715d87e6063SIoana Ciornei return false; 716d87e6063SIoana Ciornei } 717d87e6063SIoana Ciornei 718d87e6063SIoana Ciornei static inline bool dpaa2_eth_has_mac(struct dpaa2_eth_priv *priv) 719d87e6063SIoana Ciornei { 720d87e6063SIoana Ciornei return priv->mac ? true : false; 721d87e6063SIoana Ciornei } 722d87e6063SIoana Ciornei 723edad8d26SIoana Ciocoi Radulescu int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags); 7242d680237SIoana Ciocoi Radulescu int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key); 7252d680237SIoana Ciocoi Radulescu int dpaa2_eth_cls_key_size(u64 key); 726afb90dbbSIoana Radulescu int dpaa2_eth_cls_fld_off(int prot, int field); 7272d680237SIoana Ciocoi Radulescu void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields); 728edad8d26SIoana Ciocoi Radulescu 72907beb165SIoana Ciornei void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv, 73007beb165SIoana Ciornei bool tx_pause, bool pfc); 73107beb165SIoana Ciornei 732f395b69fSIoana Ciornei extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops; 733f395b69fSIoana Ciornei 734bbb9ae25SLeon Romanovsky int dpaa2_eth_dl_alloc(struct dpaa2_eth_priv *priv); 735bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_free(struct dpaa2_eth_priv *priv); 736bbb9ae25SLeon Romanovsky 737bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv); 738ceeb03adSIoana Ciornei void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv); 739ceeb03adSIoana Ciornei 740ceeb03adSIoana Ciornei int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv); 741ceeb03adSIoana Ciornei void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv); 742ceeb03adSIoana Ciornei 743061d631fSIoana Ciornei int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv); 744061d631fSIoana Ciornei void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv); 745061d631fSIoana Ciornei 746061d631fSIoana Ciornei struct dpaa2_eth_trap_item *dpaa2_eth_dl_get_trap(struct dpaa2_eth_priv *priv, 747061d631fSIoana Ciornei struct dpaa2_fapr *fapr); 74834ff6846SIoana Radulescu #endif /* __DPAA2_H */ 749