2 * Copyright (C) 2014 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/netdevice.h>
11 #include <fsl-mc/fsl_mc.h>
12 #include <fsl-mc/fsl_dpaa_fd.h>
13 #include <fsl-mc/fsl_dprc.h>
14 #include <fsl-mc/fsl_dpni.h>
15 #include <fsl-mc/fsl_dpbp.h>
16 #include <fsl-mc/fsl_dpio.h>
17 #include <fsl-mc/fsl_qbman_portal.h>
18 #include <fsl-mc/fsl_mc_private.h>
26 /* Arbitrary values for now, but we'll need to tune */
27 #define LDPAA_ETH_NUM_BUFS (2 * 7)
28 #define LDPAA_ETH_REFILL_THRESH (LDPAA_ETH_NUM_BUFS/2)
29 #define LDPAA_ETH_RX_BUFFER_SIZE 2048
31 /* Hardware requires alignment for buffer address and length: 256-byte
32 * for ingress, 64-byte for egress. Using 256 for both.
34 #define LDPAA_ETH_BUF_ALIGN 256
36 /* So far we're only accomodating a skb backpointer in the frame's
37 * software annotation, but the hardware options are either 0 or 64.
39 #define LDPAA_ETH_SWA_SIZE 64
41 /* Annotation valid bits in FD FRC */
42 #define LDPAA_FD_FRC_FASV 0x8000
43 #define LDPAA_FD_FRC_FAEADV 0x4000
44 #define LDPAA_FD_FRC_FAPRV 0x2000
45 #define LDPAA_FD_FRC_FAIADV 0x1000
46 #define LDPAA_FD_FRC_FASWOV 0x0800
47 #define LDPAA_FD_FRC_FAICFDV 0x0400
49 /* Annotation bits in FD CTRL */
50 #define LDPAA_FD_CTRL_ASAL 0x00020000 /* ASAL = 128 */
51 #define LDPAA_FD_CTRL_PTA 0x00800000
52 #define LDPAA_FD_CTRL_PTV1 0x00400000
54 /* TODO: we may want to move this and other WRIOP related defines
55 * to a separate header
57 /* Frame annotation status */
65 /* Debug frame, otherwise supposed to be discarded */
66 #define LDPAA_ETH_FAS_DISC 0x80000000
68 #define LDPAA_ETH_FAS_MS 0x40000000
69 #define LDPAA_ETH_FAS_PTP 0x08000000
70 /* Ethernet multicast frame */
71 #define LDPAA_ETH_FAS_MC 0x04000000
72 /* Ethernet broadcast frame */
73 #define LDPAA_ETH_FAS_BC 0x02000000
74 #define LDPAA_ETH_FAS_KSE 0x00040000
75 #define LDPAA_ETH_FAS_EOFHE 0x00020000
76 #define LDPAA_ETH_FAS_MNLE 0x00010000
77 #define LDPAA_ETH_FAS_TIDE 0x00008000
78 #define LDPAA_ETH_FAS_PIEE 0x00004000
79 /* Frame length error */
80 #define LDPAA_ETH_FAS_FLE 0x00002000
81 /* Frame physical error; our favourite pastime */
82 #define LDPAA_ETH_FAS_FPE 0x00001000
83 #define LDPAA_ETH_FAS_PTE 0x00000080
84 #define LDPAA_ETH_FAS_ISP 0x00000040
85 #define LDPAA_ETH_FAS_PHE 0x00000020
86 #define LDPAA_ETH_FAS_BLE 0x00000010
87 /* L3 csum validation performed */
88 #define LDPAA_ETH_FAS_L3CV 0x00000008
90 #define LDPAA_ETH_FAS_L3CE 0x00000004
91 /* L4 csum validation performed */
92 #define LDPAA_ETH_FAS_L4CV 0x00000002
94 #define LDPAA_ETH_FAS_L4CE 0x00000001
95 /* These bits always signal errors */
96 #define LDPAA_ETH_RX_ERR_MASK (LDPAA_ETH_FAS_DISC | \
98 LDPAA_ETH_FAS_EOFHE | \
99 LDPAA_ETH_FAS_MNLE | \
100 LDPAA_ETH_FAS_TIDE | \
101 LDPAA_ETH_FAS_PIEE | \
102 LDPAA_ETH_FAS_FLE | \
103 LDPAA_ETH_FAS_FPE | \
104 LDPAA_ETH_FAS_PTE | \
105 LDPAA_ETH_FAS_ISP | \
106 LDPAA_ETH_FAS_PHE | \
107 LDPAA_ETH_FAS_BLE | \
108 LDPAA_ETH_FAS_L3CE | \
110 /* Unsupported features in the ingress */
111 #define LDPAA_ETH_RX_UNSUPP_MASK LDPAA_ETH_FAS_MS
112 /* TODO trim down the bitmask; not all of them apply to Tx-confirm */
113 #define LDPAA_ETH_TXCONF_ERR_MASK (LDPAA_ETH_FAS_KSE | \
114 LDPAA_ETH_FAS_EOFHE | \
115 LDPAA_ETH_FAS_MNLE | \
118 struct ldpaa_eth_priv {
119 struct eth_device *net_dev;
121 uint16_t dpmac_handle;
123 uint16_t tx_data_offset;
125 uint32_t rx_dflt_fqid;
129 enum ldpaa_eth_type type; /* 1G or 10G ethernet */
130 struct phy_device *phydev;
133 struct dprc_endpoint dpmac_endpoint;
134 struct dprc_endpoint dpni_endpoint;
136 extern struct fsl_mc_io *dflt_mc_io;
137 extern struct fsl_dpbp_obj *dflt_dpbp;
138 extern struct fsl_dpio_obj *dflt_dpio;
139 extern struct fsl_dpni_obj *dflt_dpni;
140 extern uint16_t dflt_dprc_handle;
142 static void ldpaa_dpbp_drain_cnt(int count);
143 static void ldpaa_dpbp_drain(void);
144 static int ldpaa_dpbp_seed(uint16_t bpid);
145 static void ldpaa_dpbp_free(void);
146 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv);
147 static int ldpaa_dpbp_setup(void);
148 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv);
149 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv);
150 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv);
151 #endif /* __LDPAA_H */