134ff6846SIoana Radulescu /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
234ff6846SIoana Radulescu /* Copyright 2014-2016 Freescale Semiconductor Inc.
3095174daSRobert-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>
1592272ec4SJakub Kicinski #include <net/xdp.h>
1634ff6846SIoana Radulescu
1734ff6846SIoana Radulescu #include <soc/fsl/dpaa2-io.h>
1834ff6846SIoana Radulescu #include <soc/fsl/dpaa2-fd.h>
1934ff6846SIoana Radulescu #include "dpni.h"
2034ff6846SIoana Radulescu #include "dpni-cmd.h"
2134ff6846SIoana Radulescu
2234ff6846SIoana Radulescu #include "dpaa2-eth-trace.h"
23091a19eaSIoana Radulescu #include "dpaa2-eth-debugfs.h"
2471947923SIoana Ciornei #include "dpaa2-mac.h"
2534ff6846SIoana Radulescu
2634ff6846SIoana Radulescu #define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0)
2734ff6846SIoana Radulescu
2834ff6846SIoana Radulescu #define DPAA2_ETH_STORE_SIZE 16
2934ff6846SIoana Radulescu
3034ff6846SIoana Radulescu /* Maximum number of scatter-gather entries in an ingress frame,
3134ff6846SIoana Radulescu * considering the maximum receive frame size is 64K
3234ff6846SIoana Radulescu */
3334ff6846SIoana Radulescu #define DPAA2_ETH_MAX_SG_ENTRIES ((64 * 1024) / DPAA2_ETH_RX_BUF_SIZE)
3434ff6846SIoana Radulescu
3534ff6846SIoana Radulescu /* Maximum acceptable MTU value. It is in direct relation with the hardware
3634ff6846SIoana Radulescu * enforced Max Frame Length (currently 10k).
3734ff6846SIoana Radulescu */
3834ff6846SIoana Radulescu #define DPAA2_ETH_MFL (10 * 1024)
3934ff6846SIoana Radulescu #define DPAA2_ETH_MAX_MTU (DPAA2_ETH_MFL - VLAN_ETH_HLEN)
4034ff6846SIoana Radulescu /* Convert L3 MTU to L2 MFL */
4134ff6846SIoana Radulescu #define DPAA2_ETH_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN)
4234ff6846SIoana Radulescu
433f8b826dSIoana Radulescu /* Set the taildrop threshold (in bytes) to allow the enqueue of a large
443f8b826dSIoana Radulescu * enough number of jumbo frames in the Rx queues (length of the current
453f8b826dSIoana Radulescu * frame is not taken into account when making the taildrop decision)
4634ff6846SIoana Radulescu */
473f8b826dSIoana Radulescu #define DPAA2_ETH_FQ_TAILDROP_THRESH (1024 * 1024)
4834ff6846SIoana Radulescu
493657cdafSIoana Ciornei /* Maximum burst size value for Tx shaping */
503657cdafSIoana Ciornei #define DPAA2_ETH_MAX_BURST_SIZE 0xF7FF
513657cdafSIoana Ciornei
5268049a5fSIoana Ciocoi Radulescu /* Maximum number of Tx confirmation frames to be processed
5368049a5fSIoana Ciocoi Radulescu * in a single NAPI call
5468049a5fSIoana Ciocoi Radulescu */
5568049a5fSIoana Ciocoi Radulescu #define DPAA2_ETH_TXCONF_PER_NAPI 256
5668049a5fSIoana Ciocoi Radulescu
574a7f6c5aSRobert-Ionut Alexa /* Maximum number of Tx frames to be processed in a single NAPI
584a7f6c5aSRobert-Ionut Alexa * call when AF_XDP is running. Bind it to DPAA2_ETH_TXCONF_PER_NAPI
594a7f6c5aSRobert-Ionut Alexa * to maximize the throughput.
604a7f6c5aSRobert-Ionut Alexa */
614a7f6c5aSRobert-Ionut Alexa #define DPAA2_ETH_TX_ZC_PER_NAPI DPAA2_ETH_TXCONF_PER_NAPI
624a7f6c5aSRobert-Ionut Alexa
633f8b826dSIoana Radulescu /* Buffer qouta per channel. We want to keep in check number of ingress frames
643f8b826dSIoana Radulescu * in flight: for small sized frames, congestion group taildrop may kick in
653f8b826dSIoana Radulescu * first; for large sizes, Rx FQ taildrop threshold will ensure only a
663f8b826dSIoana Radulescu * reasonable number of frames will be pending at any given time.
673f8b826dSIoana Radulescu * Ingress frame drop due to buffer pool depletion should be a corner case only
6834ff6846SIoana Radulescu */
693f8b826dSIoana Radulescu #define DPAA2_ETH_NUM_BUFS 1280
7020fb0572SIoana Ciocoi Radulescu #define DPAA2_ETH_REFILL_THRESH \
7120fb0572SIoana Ciocoi Radulescu (DPAA2_ETH_NUM_BUFS - DPAA2_ETH_BUFS_PER_CMD)
7234ff6846SIoana Radulescu
732c8d1c8dSIoana Radulescu /* Congestion group taildrop threshold: number of frames allowed to accumulate
742c8d1c8dSIoana Radulescu * at any moment in a group of Rx queues belonging to the same traffic class.
752c8d1c8dSIoana Radulescu * Choose value such that we don't risk depleting the buffer pool before the
762c8d1c8dSIoana Radulescu * taildrop kicks in
772c8d1c8dSIoana Radulescu */
782c8d1c8dSIoana Radulescu #define DPAA2_ETH_CG_TAILDROP_THRESH(priv) \
793f8b826dSIoana Radulescu (1024 * dpaa2_eth_queue_count(priv) / dpaa2_eth_tc_count(priv))
802c8d1c8dSIoana Radulescu
81f395b69fSIoana Ciornei /* Congestion group notification threshold: when this many frames accumulate
82f395b69fSIoana Ciornei * on the Rx queues belonging to the same TC, the MAC is instructed to send
83f395b69fSIoana Ciornei * PFC frames for that TC.
84f395b69fSIoana Ciornei * When number of pending frames drops below exit threshold transmission of
85f395b69fSIoana Ciornei * PFC frames is stopped.
86f395b69fSIoana Ciornei */
87f395b69fSIoana Ciornei #define DPAA2_ETH_CN_THRESH_ENTRY(priv) \
88f395b69fSIoana Ciornei (DPAA2_ETH_CG_TAILDROP_THRESH(priv) / 2)
89f395b69fSIoana Ciornei #define DPAA2_ETH_CN_THRESH_EXIT(priv) \
90f395b69fSIoana Ciornei (DPAA2_ETH_CN_THRESH_ENTRY(priv) * 3 / 4)
91f395b69fSIoana Ciornei
9234ff6846SIoana Radulescu /* Maximum number of buffers that can be acquired/released through a single
9334ff6846SIoana Radulescu * QBMan command
9434ff6846SIoana Radulescu */
9534ff6846SIoana Radulescu #define DPAA2_ETH_BUFS_PER_CMD 7
9634ff6846SIoana Radulescu
9734ff6846SIoana Radulescu /* Hardware requires alignment for ingress/egress buffer addresses */
9834ff6846SIoana Radulescu #define DPAA2_ETH_TX_BUF_ALIGN 64
9934ff6846SIoana Radulescu
10027c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_RAW_SIZE PAGE_SIZE
10127c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_TAILROOM \
10227c87486SIoana Ciocoi Radulescu SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
10327c87486SIoana Ciocoi Radulescu #define DPAA2_ETH_RX_BUF_SIZE \
10427c87486SIoana Ciocoi Radulescu (DPAA2_ETH_RX_BUF_RAW_SIZE - DPAA2_ETH_RX_BUF_TAILROOM)
10534ff6846SIoana Radulescu
10634ff6846SIoana Radulescu /* Hardware annotation area in RX/TX buffers */
10734ff6846SIoana Radulescu #define DPAA2_ETH_RX_HWA_SIZE 64
10834ff6846SIoana Radulescu #define DPAA2_ETH_TX_HWA_SIZE 128
10934ff6846SIoana Radulescu
11034ff6846SIoana Radulescu /* PTP nominal frequency 1GHz */
11134ff6846SIoana Radulescu #define DPAA2_PTP_CLK_PERIOD_NS 1
11234ff6846SIoana Radulescu
11334ff6846SIoana Radulescu /* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned
11434ff6846SIoana Radulescu * to 256B. For newer revisions, the requirement is only for 64B alignment
11534ff6846SIoana Radulescu */
11634ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN_REV1 256
11734ff6846SIoana Radulescu #define DPAA2_ETH_RX_BUF_ALIGN 64
11834ff6846SIoana Radulescu
119095174daSRobert-Ionut Alexa /* The firmware allows assigning multiple buffer pools to a single DPNI -
120095174daSRobert-Ionut Alexa * maximum 8 DPBP objects. By default, only the first DPBP (idx 0) is used for
121095174daSRobert-Ionut Alexa * all queues. Thus, when enabling AF_XDP we must accommodate up to 9 DPBPs
122095174daSRobert-Ionut Alexa * object: the default and 8 other distinct buffer pools, one for each queue.
123095174daSRobert-Ionut Alexa */
124095174daSRobert-Ionut Alexa #define DPAA2_ETH_DEFAULT_BP_IDX 0
125095174daSRobert-Ionut Alexa #define DPAA2_ETH_MAX_BPS 9
126095174daSRobert-Ionut Alexa
12734ff6846SIoana Radulescu /* We are accommodating a skb backpointer and some S/G info
12834ff6846SIoana Radulescu * in the frame's software annotation. The hardware
12934ff6846SIoana Radulescu * options are either 0 or 64, so we choose the latter.
13034ff6846SIoana Radulescu */
13134ff6846SIoana Radulescu #define DPAA2_ETH_SWA_SIZE 64
13234ff6846SIoana Radulescu
133e3fdf6baSIoana Radulescu /* We store different information in the software annotation area of a Tx frame
134e3fdf6baSIoana Radulescu * based on what type of frame it is
135e3fdf6baSIoana Radulescu */
136e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type {
137e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SINGLE,
138e3fdf6baSIoana Radulescu DPAA2_ETH_SWA_SG,
139d678be1dSIoana Radulescu DPAA2_ETH_SWA_XDP,
14048276c08SRobert-Ionut Alexa DPAA2_ETH_SWA_XSK,
1413dc709e0SIoana Ciornei DPAA2_ETH_SWA_SW_TSO,
142e3fdf6baSIoana Radulescu };
143e3fdf6baSIoana Radulescu
14434ff6846SIoana Radulescu /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */
14534ff6846SIoana Radulescu struct dpaa2_eth_swa {
146e3fdf6baSIoana Radulescu enum dpaa2_eth_swa_type type;
147e3fdf6baSIoana Radulescu union {
148e3fdf6baSIoana Radulescu struct {
149e3fdf6baSIoana Radulescu struct sk_buff *skb;
150d70446eeSIoana Ciornei int sgt_size;
151e3fdf6baSIoana Radulescu } single;
152e3fdf6baSIoana Radulescu struct {
15334ff6846SIoana Radulescu struct sk_buff *skb;
15434ff6846SIoana Radulescu struct scatterlist *scl;
15534ff6846SIoana Radulescu int num_sg;
15634ff6846SIoana Radulescu int sgt_size;
157e3fdf6baSIoana Radulescu } sg;
158d678be1dSIoana Radulescu struct {
159d678be1dSIoana Radulescu int dma_size;
160d678be1dSIoana Radulescu struct xdp_frame *xdpf;
161d678be1dSIoana Radulescu } xdp;
1623dc709e0SIoana Ciornei struct {
16348276c08SRobert-Ionut Alexa struct xdp_buff *xdp_buff;
1644a7f6c5aSRobert-Ionut Alexa int sgt_size;
16548276c08SRobert-Ionut Alexa } xsk;
16648276c08SRobert-Ionut Alexa struct {
1673dc709e0SIoana Ciornei struct sk_buff *skb;
1683dc709e0SIoana Ciornei int num_sg;
1693dc709e0SIoana Ciornei int sgt_size;
1703dc709e0SIoana Ciornei int is_last_fd;
1713dc709e0SIoana Ciornei } tso;
172e3fdf6baSIoana Radulescu };
17334ff6846SIoana Radulescu };
17434ff6846SIoana Radulescu
17534ff6846SIoana Radulescu /* Annotation valid bits in FD FRC */
17634ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASV 0x8000
17734ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAEADV 0x4000
17834ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAPRV 0x2000
17934ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAIADV 0x1000
18034ff6846SIoana Radulescu #define DPAA2_FD_FRC_FASWOV 0x0800
18134ff6846SIoana Radulescu #define DPAA2_FD_FRC_FAICFDV 0x0400
18234ff6846SIoana Radulescu
18334ff6846SIoana Radulescu /* Error bits in FD CTRL */
18434ff6846SIoana Radulescu #define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR)
18534ff6846SIoana Radulescu #define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \
18634ff6846SIoana Radulescu FD_CTRL_SBE | \
18734ff6846SIoana Radulescu FD_CTRL_FSE | \
18834ff6846SIoana Radulescu FD_CTRL_FAERR)
18934ff6846SIoana Radulescu
19034ff6846SIoana Radulescu /* Annotation bits in FD CTRL */
19134ff6846SIoana Radulescu #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128B */
19234ff6846SIoana Radulescu
19334ff6846SIoana Radulescu /* Frame annotation status */
19434ff6846SIoana Radulescu struct dpaa2_fas {
19534ff6846SIoana Radulescu u8 reserved;
19634ff6846SIoana Radulescu u8 ppid;
19734ff6846SIoana Radulescu __le16 ifpid;
19834ff6846SIoana Radulescu __le32 status;
19934ff6846SIoana Radulescu };
20034ff6846SIoana Radulescu
20134ff6846SIoana Radulescu /* Frame annotation status word is located in the first 8 bytes
20234ff6846SIoana Radulescu * of the buffer's hardware annoatation area
20334ff6846SIoana Radulescu */
20434ff6846SIoana Radulescu #define DPAA2_FAS_OFFSET 0
20534ff6846SIoana Radulescu #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas))
20634ff6846SIoana Radulescu
20734ff6846SIoana Radulescu /* Timestamp is located in the next 8 bytes of the buffer's
20834ff6846SIoana Radulescu * hardware annotation area
20934ff6846SIoana Radulescu */
21034ff6846SIoana Radulescu #define DPAA2_TS_OFFSET 0x8
21134ff6846SIoana Radulescu
212061d631fSIoana Ciornei /* Frame annotation parse results */
213061d631fSIoana Ciornei struct dpaa2_fapr {
214061d631fSIoana Ciornei /* 64-bit word 1 */
215061d631fSIoana Ciornei __le32 faf_lo;
216061d631fSIoana Ciornei __le16 faf_ext;
217061d631fSIoana Ciornei __le16 nxt_hdr;
218061d631fSIoana Ciornei /* 64-bit word 2 */
219061d631fSIoana Ciornei __le64 faf_hi;
220061d631fSIoana Ciornei /* 64-bit word 3 */
221061d631fSIoana Ciornei u8 last_ethertype_offset;
222061d631fSIoana Ciornei u8 vlan_tci_offset_n;
223061d631fSIoana Ciornei u8 vlan_tci_offset_1;
224061d631fSIoana Ciornei u8 llc_snap_offset;
225061d631fSIoana Ciornei u8 eth_offset;
226061d631fSIoana Ciornei u8 ip1_pid_offset;
227061d631fSIoana Ciornei u8 shim_offset_2;
228061d631fSIoana Ciornei u8 shim_offset_1;
229061d631fSIoana Ciornei /* 64-bit word 4 */
230061d631fSIoana Ciornei u8 l5_offset;
231061d631fSIoana Ciornei u8 l4_offset;
232061d631fSIoana Ciornei u8 gre_offset;
233061d631fSIoana Ciornei u8 l3_offset_n;
234061d631fSIoana Ciornei u8 l3_offset_1;
235061d631fSIoana Ciornei u8 mpls_offset_n;
236061d631fSIoana Ciornei u8 mpls_offset_1;
237061d631fSIoana Ciornei u8 pppoe_offset;
238061d631fSIoana Ciornei /* 64-bit word 5 */
239061d631fSIoana Ciornei __le16 running_sum;
240061d631fSIoana Ciornei __le16 gross_running_sum;
241061d631fSIoana Ciornei u8 ipv6_frag_offset;
242061d631fSIoana Ciornei u8 nxt_hdr_offset;
243061d631fSIoana Ciornei u8 routing_hdr_offset_2;
244061d631fSIoana Ciornei u8 routing_hdr_offset_1;
245061d631fSIoana Ciornei /* 64-bit word 6 */
246061d631fSIoana Ciornei u8 reserved[5]; /* Soft-parsing context */
247061d631fSIoana Ciornei u8 ip_proto_offset_n;
248061d631fSIoana Ciornei u8 nxt_hdr_frag_offset;
249061d631fSIoana Ciornei u8 parse_error_code;
250061d631fSIoana Ciornei };
251061d631fSIoana Ciornei
252061d631fSIoana Ciornei #define DPAA2_FAPR_OFFSET 0x10
253061d631fSIoana Ciornei #define DPAA2_FAPR_SIZE sizeof((struct dpaa2_fapr))
254061d631fSIoana Ciornei
25534ff6846SIoana Radulescu /* Frame annotation egress action descriptor */
25634ff6846SIoana Radulescu #define DPAA2_FAEAD_OFFSET 0x58
25734ff6846SIoana Radulescu
25834ff6846SIoana Radulescu struct dpaa2_faead {
25934ff6846SIoana Radulescu __le32 conf_fqid;
26034ff6846SIoana Radulescu __le32 ctrl;
26134ff6846SIoana Radulescu };
26234ff6846SIoana Radulescu
26334ff6846SIoana Radulescu #define DPAA2_FAEAD_A2V 0x20000000
26499e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_A4V 0x08000000
26534ff6846SIoana Radulescu #define DPAA2_FAEAD_UPDV 0x00001000
26699e43521SIoana Ciocoi Radulescu #define DPAA2_FAEAD_EBDDV 0x00002000
26734ff6846SIoana Radulescu #define DPAA2_FAEAD_UPD 0x00000010
26834ff6846SIoana Radulescu
269c5521189SYangbo Lu struct ptp_tstamp {
270c5521189SYangbo Lu u16 sec_msb;
271c5521189SYangbo Lu u32 sec_lsb;
272c5521189SYangbo Lu u32 nsec;
273c5521189SYangbo Lu };
274c5521189SYangbo Lu
ns_to_ptp_tstamp(struct ptp_tstamp * tstamp,u64 ns)275c5521189SYangbo Lu static inline void ns_to_ptp_tstamp(struct ptp_tstamp *tstamp, u64 ns)
276c5521189SYangbo Lu {
277c5521189SYangbo Lu u64 sec, nsec;
278c5521189SYangbo Lu
279c5521189SYangbo Lu sec = ns;
280c5521189SYangbo Lu nsec = do_div(sec, 1000000000);
281c5521189SYangbo Lu
282c5521189SYangbo Lu tstamp->sec_lsb = sec & 0xFFFFFFFF;
283c5521189SYangbo Lu tstamp->sec_msb = (sec >> 32) & 0xFFFF;
284c5521189SYangbo Lu tstamp->nsec = nsec;
285c5521189SYangbo Lu }
286c5521189SYangbo Lu
28734ff6846SIoana Radulescu /* Accessors for the hardware annotation fields that we use */
dpaa2_get_hwa(void * buf_addr,bool swa)28834ff6846SIoana Radulescu static inline void *dpaa2_get_hwa(void *buf_addr, bool swa)
28934ff6846SIoana Radulescu {
29034ff6846SIoana Radulescu return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0);
29134ff6846SIoana Radulescu }
29234ff6846SIoana Radulescu
dpaa2_get_fas(void * buf_addr,bool swa)29334ff6846SIoana Radulescu static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa)
29434ff6846SIoana Radulescu {
29534ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET;
29634ff6846SIoana Radulescu }
29734ff6846SIoana Radulescu
dpaa2_get_ts(void * buf_addr,bool swa)29834ff6846SIoana Radulescu static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa)
29934ff6846SIoana Radulescu {
30034ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET;
30134ff6846SIoana Radulescu }
30234ff6846SIoana Radulescu
dpaa2_get_fapr(void * buf_addr,bool swa)303061d631fSIoana Ciornei static inline struct dpaa2_fapr *dpaa2_get_fapr(void *buf_addr, bool swa)
304061d631fSIoana Ciornei {
305061d631fSIoana Ciornei return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAPR_OFFSET;
306061d631fSIoana Ciornei }
307061d631fSIoana Ciornei
dpaa2_get_faead(void * buf_addr,bool swa)30834ff6846SIoana Radulescu static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa)
30934ff6846SIoana Radulescu {
31034ff6846SIoana Radulescu return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET;
31134ff6846SIoana Radulescu }
31234ff6846SIoana Radulescu
31334ff6846SIoana Radulescu /* Error and status bits in the frame annotation status word */
31434ff6846SIoana Radulescu /* Debug frame, otherwise supposed to be discarded */
31534ff6846SIoana Radulescu #define DPAA2_FAS_DISC 0x80000000
31634ff6846SIoana Radulescu /* MACSEC frame */
31734ff6846SIoana Radulescu #define DPAA2_FAS_MS 0x40000000
31834ff6846SIoana Radulescu #define DPAA2_FAS_PTP 0x08000000
31934ff6846SIoana Radulescu /* Ethernet multicast frame */
32034ff6846SIoana Radulescu #define DPAA2_FAS_MC 0x04000000
32134ff6846SIoana Radulescu /* Ethernet broadcast frame */
32234ff6846SIoana Radulescu #define DPAA2_FAS_BC 0x02000000
32334ff6846SIoana Radulescu #define DPAA2_FAS_KSE 0x00040000
32434ff6846SIoana Radulescu #define DPAA2_FAS_EOFHE 0x00020000
32534ff6846SIoana Radulescu #define DPAA2_FAS_MNLE 0x00010000
32634ff6846SIoana Radulescu #define DPAA2_FAS_TIDE 0x00008000
32734ff6846SIoana Radulescu #define DPAA2_FAS_PIEE 0x00004000
32834ff6846SIoana Radulescu /* Frame length error */
32934ff6846SIoana Radulescu #define DPAA2_FAS_FLE 0x00002000
33034ff6846SIoana Radulescu /* Frame physical error */
33134ff6846SIoana Radulescu #define DPAA2_FAS_FPE 0x00001000
33234ff6846SIoana Radulescu #define DPAA2_FAS_PTE 0x00000080
33334ff6846SIoana Radulescu #define DPAA2_FAS_ISP 0x00000040
33434ff6846SIoana Radulescu #define DPAA2_FAS_PHE 0x00000020
33534ff6846SIoana Radulescu #define DPAA2_FAS_BLE 0x00000010
33634ff6846SIoana Radulescu /* L3 csum validation performed */
33734ff6846SIoana Radulescu #define DPAA2_FAS_L3CV 0x00000008
33834ff6846SIoana Radulescu /* L3 csum error */
33934ff6846SIoana Radulescu #define DPAA2_FAS_L3CE 0x00000004
34034ff6846SIoana Radulescu /* L4 csum validation performed */
34134ff6846SIoana Radulescu #define DPAA2_FAS_L4CV 0x00000002
34234ff6846SIoana Radulescu /* L4 csum error */
34334ff6846SIoana Radulescu #define DPAA2_FAS_L4CE 0x00000001
34434ff6846SIoana Radulescu /* Possible errors on the ingress path */
34534ff6846SIoana Radulescu #define DPAA2_FAS_RX_ERR_MASK (DPAA2_FAS_KSE | \
34634ff6846SIoana Radulescu DPAA2_FAS_EOFHE | \
34734ff6846SIoana Radulescu DPAA2_FAS_MNLE | \
34834ff6846SIoana Radulescu DPAA2_FAS_TIDE | \
34934ff6846SIoana Radulescu DPAA2_FAS_PIEE | \
35034ff6846SIoana Radulescu DPAA2_FAS_FLE | \
35134ff6846SIoana Radulescu DPAA2_FAS_FPE | \
35234ff6846SIoana Radulescu DPAA2_FAS_PTE | \
35334ff6846SIoana Radulescu DPAA2_FAS_ISP | \
35434ff6846SIoana Radulescu DPAA2_FAS_PHE | \
35534ff6846SIoana Radulescu DPAA2_FAS_BLE | \
35634ff6846SIoana Radulescu DPAA2_FAS_L3CE | \
35734ff6846SIoana Radulescu DPAA2_FAS_L4CE)
35834ff6846SIoana Radulescu
35934ff6846SIoana Radulescu /* Time in milliseconds between link state updates */
36034ff6846SIoana Radulescu #define DPAA2_ETH_LINK_STATE_REFRESH 1000
36134ff6846SIoana Radulescu
36234ff6846SIoana Radulescu /* Number of times to retry a frame enqueue before giving up.
36334ff6846SIoana Radulescu * Value determined empirically, in order to minimize the number
36434ff6846SIoana Radulescu * of frames dropped on Tx
36534ff6846SIoana Radulescu */
36634ff6846SIoana Radulescu #define DPAA2_ETH_ENQUEUE_RETRIES 10
36734ff6846SIoana Radulescu
368ef17bd7cSIoana Radulescu /* Number of times to retry DPIO portal operations while waiting
369ef17bd7cSIoana Radulescu * for portal to finish executing current command and become
370ef17bd7cSIoana Radulescu * available. We want to avoid being stuck in a while loop in case
371ef17bd7cSIoana Radulescu * hardware becomes unresponsive, but not give up too easily if
372ef17bd7cSIoana Radulescu * the portal really is busy for valid reasons
373ef17bd7cSIoana Radulescu */
374ef17bd7cSIoana Radulescu #define DPAA2_ETH_SWP_BUSY_RETRIES 1000
375ef17bd7cSIoana Radulescu
37634ff6846SIoana Radulescu /* Driver statistics, other than those in struct rtnl_link_stats64.
37734ff6846SIoana Radulescu * These are usually collected per-CPU and aggregated by ethtool.
37834ff6846SIoana Radulescu */
37934ff6846SIoana Radulescu struct dpaa2_eth_drv_stats {
38034ff6846SIoana Radulescu __u64 tx_conf_frames;
38134ff6846SIoana Radulescu __u64 tx_conf_bytes;
38234ff6846SIoana Radulescu __u64 tx_sg_frames;
38334ff6846SIoana Radulescu __u64 tx_sg_bytes;
3843dc709e0SIoana Ciornei __u64 tx_tso_frames;
3853dc709e0SIoana Ciornei __u64 tx_tso_bytes;
38634ff6846SIoana Radulescu __u64 rx_sg_frames;
38734ff6846SIoana Radulescu __u64 rx_sg_bytes;
3884c96c0acSIoana Ciornei /* Linear skbs sent as a S/G FD due to insufficient headroom */
3894c96c0acSIoana Ciornei __u64 tx_converted_sg_frames;
3904c96c0acSIoana Ciornei __u64 tx_converted_sg_bytes;
39134ff6846SIoana Radulescu /* Enqueues retried due to portal busy */
39234ff6846SIoana Radulescu __u64 tx_portal_busy;
39334ff6846SIoana Radulescu };
39434ff6846SIoana Radulescu
39534ff6846SIoana Radulescu /* Per-FQ statistics */
39634ff6846SIoana Radulescu struct dpaa2_eth_fq_stats {
39734ff6846SIoana Radulescu /* Number of frames received on this queue */
39834ff6846SIoana Radulescu __u64 frames;
39934ff6846SIoana Radulescu };
40034ff6846SIoana Radulescu
40134ff6846SIoana Radulescu /* Per-channel statistics */
40234ff6846SIoana Radulescu struct dpaa2_eth_ch_stats {
40334ff6846SIoana Radulescu /* Volatile dequeues retried due to portal busy */
40434ff6846SIoana Radulescu __u64 dequeue_portal_busy;
40534ff6846SIoana Radulescu /* Pull errors */
40634ff6846SIoana Radulescu __u64 pull_err;
4070ff8f0aaSIoana Ciocoi Radulescu /* Number of CDANs; useful to estimate avg NAPI len */
4080ff8f0aaSIoana Ciocoi Radulescu __u64 cdan;
409a4a7b762SIoana Ciocoi Radulescu /* XDP counters */
410a4a7b762SIoana Ciocoi Radulescu __u64 xdp_drop;
411a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx;
412a4a7b762SIoana Ciocoi Radulescu __u64 xdp_tx_err;
413d678be1dSIoana Radulescu __u64 xdp_redirect;
414460fd830SIoana Ciornei /* Must be last, does not show up in ethtool stats */
415460fd830SIoana Ciornei __u64 frames;
416fc398becSIoana Ciornei __u64 frames_per_cdan;
417fc398becSIoana Ciornei __u64 bytes_per_cdan;
41834ff6846SIoana Radulescu };
41934ff6846SIoana Radulescu
420972ce7e3SIoana Ciornei #define DPAA2_ETH_CH_STATS 7
421972ce7e3SIoana Ciornei
42234ff6846SIoana Radulescu /* Maximum number of queues associated with a DPNI */
42315c87f6bSIoana Radulescu #define DPAA2_ETH_MAX_TCS 8
424685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES_PER_TC 16
425685e39eaSIoana Radulescu #define DPAA2_ETH_MAX_RX_QUEUES \
426685e39eaSIoana Radulescu (DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS)
42734ff6846SIoana Radulescu #define DPAA2_ETH_MAX_TX_QUEUES 16
428061d631fSIoana Ciornei #define DPAA2_ETH_MAX_RX_ERR_QUEUES 1
42934ff6846SIoana Radulescu #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \
430061d631fSIoana Ciornei DPAA2_ETH_MAX_TX_QUEUES + \
431061d631fSIoana Ciornei DPAA2_ETH_MAX_RX_ERR_QUEUES)
432ab1e6de2SIoana Radulescu #define DPAA2_ETH_MAX_NETDEV_QUEUES \
433ab1e6de2SIoana Radulescu (DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS)
43434ff6846SIoana Radulescu
43534ff6846SIoana Radulescu #define DPAA2_ETH_MAX_DPCONS 16
43634ff6846SIoana Radulescu
43734ff6846SIoana Radulescu enum dpaa2_eth_fq_type {
43834ff6846SIoana Radulescu DPAA2_RX_FQ = 0,
43934ff6846SIoana Radulescu DPAA2_TX_CONF_FQ,
440061d631fSIoana Ciornei DPAA2_RX_ERR_FQ
44134ff6846SIoana Radulescu };
44234ff6846SIoana Radulescu
44334ff6846SIoana Radulescu struct dpaa2_eth_priv;
44448276c08SRobert-Ionut Alexa struct dpaa2_eth_channel;
44548276c08SRobert-Ionut Alexa struct dpaa2_eth_fq;
44634ff6846SIoana Radulescu
44738c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds {
44838c440b2SIoana Ciornei struct dpaa2_fd fds[DEV_MAP_BULK_SIZE];
44938c440b2SIoana Ciornei ssize_t num;
45038c440b2SIoana Ciornei };
45138c440b2SIoana Ciornei
45248276c08SRobert-Ionut Alexa typedef void dpaa2_eth_consume_cb_t(struct dpaa2_eth_priv *priv,
45348276c08SRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
45448276c08SRobert-Ionut Alexa const struct dpaa2_fd *fd,
45548276c08SRobert-Ionut Alexa struct dpaa2_eth_fq *fq);
45648276c08SRobert-Ionut Alexa
45734ff6846SIoana Radulescu struct dpaa2_eth_fq {
45834ff6846SIoana Radulescu u32 fqid;
45934ff6846SIoana Radulescu u32 tx_qdbin;
46015c87f6bSIoana Radulescu u32 tx_fqid[DPAA2_ETH_MAX_TCS];
46134ff6846SIoana Radulescu u16 flowid;
46215c87f6bSIoana Radulescu u8 tc;
46334ff6846SIoana Radulescu int target_cpu;
464569dac6aSIoana Ciocoi Radulescu u32 dq_frames;
465569dac6aSIoana Ciocoi Radulescu u32 dq_bytes;
46634ff6846SIoana Radulescu struct dpaa2_eth_channel *channel;
46734ff6846SIoana Radulescu enum dpaa2_eth_fq_type type;
46834ff6846SIoana Radulescu
46948276c08SRobert-Ionut Alexa dpaa2_eth_consume_cb_t *consume;
47034ff6846SIoana Radulescu struct dpaa2_eth_fq_stats stats;
4718665d978SIoana Ciornei
47238c440b2SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_redirect_fds;
47374a1c059SIoana Ciornei struct dpaa2_eth_xdp_fds xdp_tx_fds;
47434ff6846SIoana Radulescu };
47534ff6846SIoana Radulescu
4767e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp {
4777e273a8eSIoana Ciocoi Radulescu struct bpf_prog *prog;
478d678be1dSIoana Radulescu unsigned int res;
4797e273a8eSIoana Ciocoi Radulescu };
4807e273a8eSIoana Ciocoi Radulescu
481095174daSRobert-Ionut Alexa struct dpaa2_eth_bp {
482095174daSRobert-Ionut Alexa struct fsl_mc_device *dev;
483095174daSRobert-Ionut Alexa int bpid;
484095174daSRobert-Ionut Alexa };
485095174daSRobert-Ionut Alexa
48634ff6846SIoana Radulescu struct dpaa2_eth_channel {
48734ff6846SIoana Radulescu struct dpaa2_io_notification_ctx nctx;
48834ff6846SIoana Radulescu struct fsl_mc_device *dpcon;
48934ff6846SIoana Radulescu int dpcon_id;
49034ff6846SIoana Radulescu int ch_id;
49134ff6846SIoana Radulescu struct napi_struct napi;
49234ff6846SIoana Radulescu struct dpaa2_io *dpio;
49334ff6846SIoana Radulescu struct dpaa2_io_store *store;
49434ff6846SIoana Radulescu struct dpaa2_eth_priv *priv;
49534ff6846SIoana Radulescu int buf_count;
49634ff6846SIoana Radulescu struct dpaa2_eth_ch_stats stats;
4977e273a8eSIoana Ciocoi Radulescu struct dpaa2_eth_ch_xdp xdp;
498d678be1dSIoana Radulescu struct xdp_rxq_info xdp_rxq;
4990a25d92cSIoana Ciornei struct list_head *rx_list;
50028d137ccSIoana Ciornei
50128d137ccSIoana Ciornei /* Buffers to be recycled back in the buffer pool */
50228d137ccSIoana Ciornei u64 recycled_bufs[DPAA2_ETH_BUFS_PER_CMD];
50328d137ccSIoana Ciornei int recycled_bufs_cnt;
504095174daSRobert-Ionut Alexa
50548276c08SRobert-Ionut Alexa bool xsk_zc;
5064a7f6c5aSRobert-Ionut Alexa int xsk_tx_pkts_sent;
50748276c08SRobert-Ionut Alexa struct xsk_buff_pool *xsk_pool;
508095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *bp;
50934ff6846SIoana Radulescu };
51034ff6846SIoana Radulescu
511f76c483aSIoana Radulescu struct dpaa2_eth_dist_fields {
51234ff6846SIoana Radulescu u64 rxnfc_field;
51334ff6846SIoana Radulescu enum net_prot cls_prot;
51434ff6846SIoana Radulescu int cls_field;
51534ff6846SIoana Radulescu int size;
5163a1e6b84SIoana Ciocoi Radulescu u64 id;
51734ff6846SIoana Radulescu };
51834ff6846SIoana Radulescu
519afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule {
520afb90dbbSIoana Radulescu struct ethtool_rx_flow_spec fs;
521afb90dbbSIoana Radulescu u8 in_use;
522afb90dbbSIoana Radulescu };
523afb90dbbSIoana Radulescu
524d70446eeSIoana Ciornei #define DPAA2_ETH_SGT_CACHE_SIZE 256
525d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache {
526d70446eeSIoana Ciornei void *buf[DPAA2_ETH_SGT_CACHE_SIZE];
527d70446eeSIoana Ciornei u16 count;
528d70446eeSIoana Ciornei };
529d70446eeSIoana Ciornei
530061d631fSIoana Ciornei struct dpaa2_eth_trap_item {
531061d631fSIoana Ciornei void *trap_ctx;
532061d631fSIoana Ciornei };
533061d631fSIoana Ciornei
534061d631fSIoana Ciornei struct dpaa2_eth_trap_data {
535061d631fSIoana Ciornei struct dpaa2_eth_trap_item *trap_items_arr;
536061d631fSIoana Ciornei struct dpaa2_eth_priv *priv;
537061d631fSIoana Ciornei };
538061d631fSIoana Ciornei
539a4218aefSIoana Ciornei #define DPAA2_ETH_SG_ENTRIES_MAX (PAGE_SIZE / sizeof(struct scatterlist))
540a4218aefSIoana Ciornei
54150f82699SIoana Ciornei #define DPAA2_ETH_DEFAULT_COPYBREAK 512
54250f82699SIoana Ciornei
5434a7f6c5aSRobert-Ionut Alexa #define DPAA2_ETH_ENQUEUE_MAX_FDS 256
544a4ca448eSIoana Ciornei struct dpaa2_eth_fds {
545a4ca448eSIoana Ciornei struct dpaa2_fd array[DPAA2_ETH_ENQUEUE_MAX_FDS];
546a4ca448eSIoana Ciornei };
547a4ca448eSIoana Ciornei
54834ff6846SIoana Radulescu /* Driver private data */
54934ff6846SIoana Radulescu struct dpaa2_eth_priv {
55034ff6846SIoana Radulescu struct net_device *net_dev;
55134ff6846SIoana Radulescu
55234ff6846SIoana Radulescu u8 num_fqs;
55334ff6846SIoana Radulescu struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES];
5541fa0f68cSIoana Ciocoi Radulescu int (*enqueue)(struct dpaa2_eth_priv *priv,
5551fa0f68cSIoana Ciocoi Radulescu struct dpaa2_eth_fq *fq,
55648c0481eSIoana Ciornei struct dpaa2_fd *fd, u8 prio,
5576ff80447SIoana Ciornei u32 num_frames,
55848c0481eSIoana Ciornei int *frames_enqueued);
55934ff6846SIoana Radulescu
56034ff6846SIoana Radulescu u8 num_channels;
56134ff6846SIoana Radulescu struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS];
562d70446eeSIoana Ciornei struct dpaa2_eth_sgt_cache __percpu *sgt_cache;
563c4680c97SRadu Bulie unsigned long features;
56434ff6846SIoana Radulescu struct dpni_attr dpni_attrs;
56534ff6846SIoana Radulescu u16 dpni_ver_major;
56634ff6846SIoana Radulescu u16 dpni_ver_minor;
56734ff6846SIoana Radulescu u16 tx_data_offset;
568c4680c97SRadu Bulie void __iomem *onestep_reg_base;
569c4680c97SRadu Bulie u8 ptp_correction_off;
570c4680c97SRadu Bulie void (*dpaa2_set_onestep_params_cb)(struct dpaa2_eth_priv *priv,
571c4680c97SRadu Bulie u32 offset, u8 udp);
572efa6a7d0SIoana Ciornei u16 rx_buf_size;
57334ff6846SIoana Radulescu struct iommu_domain *iommu_domain;
57434ff6846SIoana Radulescu
5751cf773bdSYangbo Lu enum hwtstamp_tx_types tx_tstamp_type; /* Tx timestamping type */
57634ff6846SIoana Radulescu bool rx_tstamp; /* Rx timestamping enabled */
57734ff6846SIoana Radulescu
578095174daSRobert-Ionut Alexa /* Buffer pool management */
579095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *bp[DPAA2_ETH_MAX_BPS];
580095174daSRobert-Ionut Alexa int num_bps;
581095174daSRobert-Ionut Alexa
58234ff6846SIoana Radulescu u16 tx_qdid;
58334ff6846SIoana Radulescu struct fsl_mc_io *mc_io;
58434ff6846SIoana Radulescu /* Cores which have an affine DPIO/DPCON.
58534ff6846SIoana Radulescu * This is the cpu set on which Rx and Tx conf frames are processed
58634ff6846SIoana Radulescu */
58734ff6846SIoana Radulescu struct cpumask dpio_cpumask;
58834ff6846SIoana Radulescu
58934ff6846SIoana Radulescu /* Standard statistics */
59034ff6846SIoana Radulescu struct rtnl_link_stats64 __percpu *percpu_stats;
59134ff6846SIoana Radulescu /* Extra stats, in addition to the ones known by the kernel */
59234ff6846SIoana Radulescu struct dpaa2_eth_drv_stats __percpu *percpu_extras;
59334ff6846SIoana Radulescu
59434ff6846SIoana Radulescu u16 mc_token;
59507beb165SIoana Ciornei u8 rx_fqtd_enabled;
59607beb165SIoana Ciornei u8 rx_cgtd_enabled;
59734ff6846SIoana Radulescu
59834ff6846SIoana Radulescu struct dpni_link_state link_state;
59934ff6846SIoana Radulescu bool do_link_poll;
60034ff6846SIoana Radulescu struct task_struct *poll_thread;
60134ff6846SIoana Radulescu
60234ff6846SIoana Radulescu /* enabled ethtool hashing bits */
60334ff6846SIoana Radulescu u64 rx_hash_fields;
6042d680237SIoana Ciocoi Radulescu u64 rx_cls_fields;
605afb90dbbSIoana Radulescu struct dpaa2_eth_cls_rule *cls_rules;
6064aaaf9b9SIoana Radulescu u8 rx_cls_enabled;
6076aa90fe2SIoana Radulescu u8 vlan_cls_enabled;
60807beb165SIoana Ciornei u8 pfc_enabled;
609f395b69fSIoana Ciornei #ifdef CONFIG_FSL_DPAA2_ETH_DCB
610f395b69fSIoana Ciornei u8 dcbx_mode;
611f395b69fSIoana Ciornei struct ieee_pfc pfc;
612f395b69fSIoana Ciornei #endif
6137e273a8eSIoana Ciocoi Radulescu struct bpf_prog *xdp_prog;
614091a19eaSIoana Radulescu #ifdef CONFIG_DEBUG_FS
615091a19eaSIoana Radulescu struct dpaa2_debugfs dbg;
616091a19eaSIoana Radulescu #endif
61771947923SIoana Ciornei
61871947923SIoana Ciornei struct dpaa2_mac *mac;
6192291982eSVladimir Oltean /* Serializes changes to priv->mac */
6202291982eSVladimir Oltean struct mutex mac_lock;
621c5521189SYangbo Lu struct workqueue_struct *dpaa2_ptp_wq;
622c5521189SYangbo Lu struct work_struct tx_onestep_tstamp;
623c5521189SYangbo Lu struct sk_buff_head tx_skbs;
624c5521189SYangbo Lu /* The one-step timestamping configuration on hardware
625c5521189SYangbo Lu * registers could only be done when no one-step
626c5521189SYangbo Lu * timestamping frames are in flight. So we use a mutex
627c5521189SYangbo Lu * lock here to make sure the lock is released by last
628c5521189SYangbo Lu * one-step timestamping packet through TX confirmation
629c5521189SYangbo Lu * queue before transmit current packet.
630c5521189SYangbo Lu */
631c5521189SYangbo Lu struct mutex onestep_tstamp_lock;
632ceeb03adSIoana Ciornei struct devlink *devlink;
633061d631fSIoana Ciornei struct dpaa2_eth_trap_data *trap_data;
634ceeb03adSIoana Ciornei struct devlink_port devlink_port;
6358ed3cefcSIoana Ciornei
6368ed3cefcSIoana Ciornei u32 rx_copybreak;
637a4ca448eSIoana Ciornei
638a4ca448eSIoana Ciornei struct dpaa2_eth_fds __percpu *fd;
639ceeb03adSIoana Ciornei };
640ceeb03adSIoana Ciornei
641ceeb03adSIoana Ciornei struct dpaa2_eth_devlink_priv {
642ceeb03adSIoana Ciornei struct dpaa2_eth_priv *dpaa2_priv;
64334ff6846SIoana Radulescu };
64434ff6846SIoana Radulescu
6451cf773bdSYangbo Lu #define TX_TSTAMP 0x1
646c5521189SYangbo Lu #define TX_TSTAMP_ONESTEP_SYNC 0x2
6471cf773bdSYangbo Lu
64834ff6846SIoana Radulescu #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \
64934ff6846SIoana Radulescu | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \
65034ff6846SIoana Radulescu | RXH_L4_B_2_3)
65134ff6846SIoana Radulescu
65234ff6846SIoana Radulescu /* default Rx hash options, set during probing */
65334ff6846SIoana Radulescu #define DPAA2_RXH_DEFAULT (RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \
65434ff6846SIoana Radulescu RXH_L4_B_0_1 | RXH_L4_B_2_3)
65534ff6846SIoana Radulescu
65634ff6846SIoana Radulescu #define dpaa2_eth_hash_enabled(priv) \
65734ff6846SIoana Radulescu ((priv)->dpni_attrs.num_queues > 1)
65834ff6846SIoana Radulescu
65934ff6846SIoana Radulescu /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */
66034ff6846SIoana Radulescu #define DPAA2_CLASSIFIER_DMA_SIZE 256
66134ff6846SIoana Radulescu
66234ff6846SIoana Radulescu extern const struct ethtool_ops dpaa2_ethtool_ops;
66334ff6846SIoana Radulescu extern int dpaa2_phc_index;
664d21c784cSYangbo Lu extern struct ptp_qoriq *dpaa2_ptp;
66534ff6846SIoana Radulescu
dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv * priv,u16 ver_major,u16 ver_minor)66634ff6846SIoana Radulescu static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv,
66734ff6846SIoana Radulescu u16 ver_major, u16 ver_minor)
66834ff6846SIoana Radulescu {
66934ff6846SIoana Radulescu if (priv->dpni_ver_major == ver_major)
67034ff6846SIoana Radulescu return priv->dpni_ver_minor - ver_minor;
67134ff6846SIoana Radulescu return priv->dpni_ver_major - ver_major;
67234ff6846SIoana Radulescu }
67334ff6846SIoana Radulescu
674df85aeb9SIoana Radulescu /* Minimum firmware version that supports a more flexible API
675df85aeb9SIoana Radulescu * for configuring the Rx flow hash key
676df85aeb9SIoana Radulescu */
677df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MAJOR 7
678df85aeb9SIoana Radulescu #define DPNI_RX_DIST_KEY_VER_MINOR 5
679df85aeb9SIoana Radulescu
680df85aeb9SIoana Radulescu #define dpaa2_eth_has_legacy_dist(priv) \
681df85aeb9SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR, \
682df85aeb9SIoana Radulescu DPNI_RX_DIST_KEY_VER_MINOR) < 0)
683df85aeb9SIoana Radulescu
68461f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_enabled(priv) \
68561f9bf00SIoana Ciocoi Radulescu (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS))
68661f9bf00SIoana Ciocoi Radulescu
68761f9bf00SIoana Ciocoi Radulescu #define dpaa2_eth_fs_mask_enabled(priv) \
68861f9bf00SIoana Ciocoi Radulescu ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING)
68961f9bf00SIoana Ciocoi Radulescu
690afb90dbbSIoana Radulescu #define dpaa2_eth_fs_count(priv) \
691afb90dbbSIoana Radulescu ((priv)->dpni_attrs.fs_entries)
692afb90dbbSIoana Radulescu
69315c87f6bSIoana Radulescu #define dpaa2_eth_tc_count(priv) \
69415c87f6bSIoana Radulescu ((priv)->dpni_attrs.num_tcs)
69515c87f6bSIoana Radulescu
696186f21beSIoana Ciornei /* We have exactly one {Rx, Tx conf} queue per channel */
697186f21beSIoana Ciornei #define dpaa2_eth_queue_count(priv) \
698186f21beSIoana Ciornei ((priv)->num_channels)
699186f21beSIoana Ciornei
7004aaaf9b9SIoana Radulescu enum dpaa2_eth_rx_dist {
7014aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_HASH,
7024aaaf9b9SIoana Radulescu DPAA2_ETH_RX_DIST_CLS
7034aaaf9b9SIoana Radulescu };
7044aaaf9b9SIoana Radulescu
7053a1e6b84SIoana Ciocoi Radulescu /* Unique IDs for the supported Rx classification header fields */
7063a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHDST BIT(0)
7073a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHSRC BIT(1)
7083a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_ETHTYPE BIT(2)
7093a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_VLAN BIT(3)
7103a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPSRC BIT(4)
7113a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPDST BIT(5)
7123a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_IPPROTO BIT(6)
7133a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4SRC BIT(7)
7143a1e6b84SIoana Ciocoi Radulescu #define DPAA2_ETH_DIST_L4DST BIT(8)
7154ca6dee5SIoana Radulescu #define DPAA2_ETH_DIST_ALL (~0ULL)
7163a1e6b84SIoana Ciocoi Radulescu
717c4680c97SRadu Bulie #define DPNI_PTP_ONESTEP_VER_MAJOR 8
718c4680c97SRadu Bulie #define DPNI_PTP_ONESTEP_VER_MINOR 2
719c4680c97SRadu Bulie #define DPAA2_ETH_FEATURE_ONESTEP_CFG_DIRECT BIT(0)
720c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_STEP_ENABLE BIT(31)
721c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_STEP_CH BIT(7)
722c4680c97SRadu Bulie #define DPAA2_PTP_SINGLE_CORRECTION_OFF(v) ((v) << 8)
723c4680c97SRadu Bulie
7248eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MAJOR 7
7258eb3cef8SIoana Radulescu #define DPNI_PAUSE_VER_MINOR 13
7268eb3cef8SIoana Radulescu #define dpaa2_eth_has_pause_support(priv) \
7278eb3cef8SIoana Radulescu (dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR, \
7288eb3cef8SIoana Radulescu DPNI_PAUSE_VER_MINOR) >= 0)
7298eb3cef8SIoana Radulescu
dpaa2_eth_tx_pause_enabled(u64 link_options)730ad054f26SIoana Radulescu static inline bool dpaa2_eth_tx_pause_enabled(u64 link_options)
731ad054f26SIoana Radulescu {
732ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE) ^
733ad054f26SIoana Radulescu !!(link_options & DPNI_LINK_OPT_ASYM_PAUSE);
734ad054f26SIoana Radulescu }
735ad054f26SIoana Radulescu
dpaa2_eth_rx_pause_enabled(u64 link_options)736ad054f26SIoana Radulescu static inline bool dpaa2_eth_rx_pause_enabled(u64 link_options)
737ad054f26SIoana Radulescu {
738ad054f26SIoana Radulescu return !!(link_options & DPNI_LINK_OPT_PAUSE);
739ad054f26SIoana Radulescu }
740ad054f26SIoana Radulescu
dpaa2_eth_needed_headroom(struct sk_buff * skb)7411cf773bdSYangbo Lu static inline unsigned int dpaa2_eth_needed_headroom(struct sk_buff *skb)
74234ff6846SIoana Radulescu {
743*434fad50SIoana Ciornei unsigned int headroom = DPAA2_ETH_SWA_SIZE + DPAA2_ETH_TX_BUF_ALIGN;
74434ff6846SIoana Radulescu
745d678be1dSIoana Radulescu /* If we don't have an skb (e.g. XDP buffer), we only need space for
746d678be1dSIoana Radulescu * the software annotation area
747d678be1dSIoana Radulescu */
748d678be1dSIoana Radulescu if (!skb)
749d678be1dSIoana Radulescu return headroom;
750d678be1dSIoana Radulescu
75134ff6846SIoana Radulescu /* For non-linear skbs we have no headroom requirement, as we build a
75234ff6846SIoana Radulescu * SG frame with a newly allocated SGT buffer
75334ff6846SIoana Radulescu */
75434ff6846SIoana Radulescu if (skb_is_nonlinear(skb))
75534ff6846SIoana Radulescu return 0;
75634ff6846SIoana Radulescu
75734ff6846SIoana Radulescu /* If we have Tx timestamping, need 128B hardware annotation */
758c5521189SYangbo Lu if (skb->cb[0])
75934ff6846SIoana Radulescu headroom += DPAA2_ETH_TX_HWA_SIZE;
76034ff6846SIoana Radulescu
76134ff6846SIoana Radulescu return headroom;
76234ff6846SIoana Radulescu }
76334ff6846SIoana Radulescu
76434ff6846SIoana Radulescu /* Extra headroom space requested to hardware, in order to make sure there's
76534ff6846SIoana Radulescu * no realloc'ing in forwarding scenarios
76634ff6846SIoana Radulescu */
dpaa2_eth_rx_head_room(struct dpaa2_eth_priv * priv)76734ff6846SIoana Radulescu static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv)
76834ff6846SIoana Radulescu {
76927c87486SIoana Ciocoi Radulescu return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE;
77034ff6846SIoana Radulescu }
77134ff6846SIoana Radulescu
dpaa2_eth_is_type_phy(struct dpaa2_eth_priv * priv)772d87e6063SIoana Ciornei static inline bool dpaa2_eth_is_type_phy(struct dpaa2_eth_priv *priv)
773d87e6063SIoana Ciornei {
7742291982eSVladimir Oltean lockdep_assert_held(&priv->mac_lock);
7752291982eSVladimir Oltean
776320fefa9SVladimir Oltean return dpaa2_mac_is_type_phy(priv->mac);
777d87e6063SIoana Ciornei }
778d87e6063SIoana Ciornei
dpaa2_eth_has_mac(struct dpaa2_eth_priv * priv)779d87e6063SIoana Ciornei static inline bool dpaa2_eth_has_mac(struct dpaa2_eth_priv *priv)
780d87e6063SIoana Ciornei {
7812291982eSVladimir Oltean lockdep_assert_held(&priv->mac_lock);
7822291982eSVladimir Oltean
783d87e6063SIoana Ciornei return priv->mac ? true : false;
784d87e6063SIoana Ciornei }
785d87e6063SIoana Ciornei
786edad8d26SIoana Ciocoi Radulescu int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags);
7872d680237SIoana Ciocoi Radulescu int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key);
7882d680237SIoana Ciocoi Radulescu int dpaa2_eth_cls_key_size(u64 key);
789afb90dbbSIoana Radulescu int dpaa2_eth_cls_fld_off(int prot, int field);
7902d680237SIoana Ciocoi Radulescu void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields);
791edad8d26SIoana Ciocoi Radulescu
79207beb165SIoana Ciornei void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv,
79307beb165SIoana Ciornei bool tx_pause, bool pfc);
79407beb165SIoana Ciornei
795f395b69fSIoana Ciornei extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops;
796f395b69fSIoana Ciornei
797bbb9ae25SLeon Romanovsky int dpaa2_eth_dl_alloc(struct dpaa2_eth_priv *priv);
798bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_free(struct dpaa2_eth_priv *priv);
799bbb9ae25SLeon Romanovsky
800bbb9ae25SLeon Romanovsky void dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv);
801ceeb03adSIoana Ciornei void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv);
802ceeb03adSIoana Ciornei
803ceeb03adSIoana Ciornei int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv);
804ceeb03adSIoana Ciornei void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv);
805ceeb03adSIoana Ciornei
806061d631fSIoana Ciornei int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv);
807061d631fSIoana Ciornei void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv);
808061d631fSIoana Ciornei
809061d631fSIoana Ciornei struct dpaa2_eth_trap_item *dpaa2_eth_dl_get_trap(struct dpaa2_eth_priv *priv,
810061d631fSIoana Ciornei struct dpaa2_fapr *fapr);
811095174daSRobert-Ionut Alexa
812095174daSRobert-Ionut Alexa struct dpaa2_eth_bp *dpaa2_eth_allocate_dpbp(struct dpaa2_eth_priv *priv);
813095174daSRobert-Ionut Alexa void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv, struct dpaa2_eth_bp *bp);
814129902a3SRobert-Ionut Alexa
815129902a3SRobert-Ionut Alexa struct sk_buff *dpaa2_eth_alloc_skb(struct dpaa2_eth_priv *priv,
816129902a3SRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
817129902a3SRobert-Ionut Alexa const struct dpaa2_fd *fd, u32 fd_length,
818129902a3SRobert-Ionut Alexa void *fd_vaddr);
819ee2a3bdeSRobert-Ionut Alexa
820ee2a3bdeSRobert-Ionut Alexa void dpaa2_eth_receive_skb(struct dpaa2_eth_priv *priv,
821ee2a3bdeSRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
822ee2a3bdeSRobert-Ionut Alexa const struct dpaa2_fd *fd, void *vaddr,
823ee2a3bdeSRobert-Ionut Alexa struct dpaa2_eth_fq *fq,
824ee2a3bdeSRobert-Ionut Alexa struct rtnl_link_stats64 *percpu_stats,
825ee2a3bdeSRobert-Ionut Alexa struct sk_buff *skb);
826ee2a3bdeSRobert-Ionut Alexa
827ee2a3bdeSRobert-Ionut Alexa void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
828ee2a3bdeSRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
829ee2a3bdeSRobert-Ionut Alexa const struct dpaa2_fd *fd,
830ee2a3bdeSRobert-Ionut Alexa struct dpaa2_eth_fq *fq);
83148276c08SRobert-Ionut Alexa
83248276c08SRobert-Ionut Alexa struct dpaa2_eth_bp *dpaa2_eth_allocate_dpbp(struct dpaa2_eth_priv *priv);
83348276c08SRobert-Ionut Alexa void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv,
83448276c08SRobert-Ionut Alexa struct dpaa2_eth_bp *bp);
83548276c08SRobert-Ionut Alexa
83648276c08SRobert-Ionut Alexa void *dpaa2_iova_to_virt(struct iommu_domain *domain, dma_addr_t iova_addr);
83748276c08SRobert-Ionut Alexa void dpaa2_eth_recycle_buf(struct dpaa2_eth_priv *priv,
83848276c08SRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
83948276c08SRobert-Ionut Alexa dma_addr_t addr);
84048276c08SRobert-Ionut Alexa
84148276c08SRobert-Ionut Alexa void dpaa2_eth_xdp_enqueue(struct dpaa2_eth_priv *priv,
84248276c08SRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
84348276c08SRobert-Ionut Alexa struct dpaa2_fd *fd,
84448276c08SRobert-Ionut Alexa void *buf_start, u16 queue_id);
84548276c08SRobert-Ionut Alexa
84648276c08SRobert-Ionut Alexa int dpaa2_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags);
84748276c08SRobert-Ionut Alexa int dpaa2_xsk_setup_pool(struct net_device *dev, struct xsk_buff_pool *pool, u16 qid);
84848276c08SRobert-Ionut Alexa
8494a7f6c5aSRobert-Ionut Alexa void dpaa2_eth_free_tx_fd(struct dpaa2_eth_priv *priv,
8504a7f6c5aSRobert-Ionut Alexa struct dpaa2_eth_channel *ch,
8514a7f6c5aSRobert-Ionut Alexa struct dpaa2_eth_fq *fq,
8524a7f6c5aSRobert-Ionut Alexa const struct dpaa2_fd *fd, bool in_napi);
8534a7f6c5aSRobert-Ionut Alexa bool dpaa2_xsk_tx(struct dpaa2_eth_priv *priv,
8544a7f6c5aSRobert-Ionut Alexa struct dpaa2_eth_channel *ch);
8554a7f6c5aSRobert-Ionut Alexa
8564a7f6c5aSRobert-Ionut Alexa /* SGT (Scatter-Gather Table) cache management */
8574a7f6c5aSRobert-Ionut Alexa void *dpaa2_eth_sgt_get(struct dpaa2_eth_priv *priv);
8584a7f6c5aSRobert-Ionut Alexa
8594a7f6c5aSRobert-Ionut Alexa void dpaa2_eth_sgt_recycle(struct dpaa2_eth_priv *priv, void *sgt_buf);
8604a7f6c5aSRobert-Ionut Alexa
86134ff6846SIoana Radulescu #endif /* __DPAA2_H */
862