Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 2 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2014-2016 Freescale Semiconductor, Inc. |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 4 | * Copyright 2017 NXP |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __LDPAA_ETH_H |
| 8 | #define __LDPAA_ETH_H |
| 9 | |
| 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> |
| 19 | |
| 20 | |
| 21 | enum ldpaa_eth_type { |
| 22 | LDPAA_ETH_1G_E, |
| 23 | LDPAA_ETH_10G_E, |
| 24 | }; |
| 25 | |
| 26 | /* Arbitrary values for now, but we'll need to tune */ |
Prabhakar Kushwaha | 0c99977 | 2015-12-24 15:33:25 +0530 | [diff] [blame] | 27 | #define LDPAA_ETH_NUM_BUFS (7 * 7) |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 28 | #define LDPAA_ETH_REFILL_THRESH (LDPAA_ETH_NUM_BUFS/2) |
| 29 | #define LDPAA_ETH_RX_BUFFER_SIZE 2048 |
| 30 | |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 31 | /* Hardware requires alignment for buffer address and length: 256-byte |
| 32 | * for ingress, 64-byte for egress. Using 256 for both. |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 33 | */ |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 34 | #define LDPAA_ETH_BUF_ALIGN 256 |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 35 | |
| 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. |
| 38 | */ |
| 39 | #define LDPAA_ETH_SWA_SIZE 64 |
| 40 | |
| 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 |
| 48 | |
| 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 |
| 53 | |
| 54 | /* TODO: we may want to move this and other WRIOP related defines |
| 55 | * to a separate header |
| 56 | */ |
| 57 | /* Frame annotation status */ |
| 58 | struct ldpaa_fas { |
| 59 | u8 reserved; |
| 60 | u8 ppid; |
| 61 | __le16 ifpid; |
| 62 | __le32 status; |
| 63 | } __packed; |
| 64 | |
| 65 | /* Debug frame, otherwise supposed to be discarded */ |
| 66 | #define LDPAA_ETH_FAS_DISC 0x80000000 |
| 67 | /* MACSEC frame */ |
| 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 |
| 89 | /* L3 csum error */ |
| 90 | #define LDPAA_ETH_FAS_L3CE 0x00000004 |
| 91 | /* L4 csum validation performed */ |
| 92 | #define LDPAA_ETH_FAS_L4CV 0x00000002 |
| 93 | /* L4 csum error */ |
| 94 | #define LDPAA_ETH_FAS_L4CE 0x00000001 |
| 95 | /* These bits always signal errors */ |
| 96 | #define LDPAA_ETH_RX_ERR_MASK (LDPAA_ETH_FAS_DISC | \ |
| 97 | LDPAA_ETH_FAS_KSE | \ |
| 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 | \ |
| 109 | LDPAA_ETH_FAS_L4CE) |
| 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 | \ |
| 116 | LDPAA_ETH_FAS_TIDE) |
| 117 | |
Ioana Ciornei | a121fe4 | 2023-05-23 16:47:45 +0300 | [diff] [blame] | 118 | static const char ldpaa_eth_dpni_stat_strings[][ETH_GSTRING_LEN] = { |
| 119 | "[dpni ] rx frames", |
| 120 | "[dpni ] rx bytes", |
| 121 | "[dpni ] rx mcast frames", |
| 122 | "[dpni ] rx mcast bytes", |
| 123 | "[dpni ] rx bcast frames", |
| 124 | "[dpni ] rx bcast bytes", |
| 125 | "[dpni ] tx frames", |
| 126 | "[dpni ] tx bytes", |
| 127 | "[dpni ] tx mcast frames", |
| 128 | "[dpni ] tx mcast bytes", |
| 129 | "[dpni ] tx bcast frames", |
| 130 | "[dpni ] tx bcast bytes", |
| 131 | "[dpni ] rx filtered frames", |
| 132 | "[dpni ] rx discarded frames", |
| 133 | "[dpni ] rx nobuffer discards", |
| 134 | "[dpni ] tx discarded frames", |
| 135 | "[dpni ] tx confirmed frames", |
| 136 | "[dpni ] tx dequeued bytes", |
| 137 | "[dpni ] tx dequeued frames", |
| 138 | "[dpni ] tx rejected bytes", |
| 139 | "[dpni ] tx rejected frames", |
| 140 | "[dpni ] tx pending frames", |
| 141 | }; |
| 142 | |
| 143 | #define LDPAA_ETH_DPNI_NUM_STATS ARRAY_SIZE(ldpaa_eth_dpni_stat_strings) |
| 144 | |
Ioana Ciornei | 98fdaaa | 2023-05-23 16:47:46 +0300 | [diff] [blame] | 145 | static const char ldpaa_eth_dpmac_stat_strings[][ETH_GSTRING_LEN] = { |
| 146 | [DPMAC_CNT_ING_ALL_FRAME] = "[mac] rx all frames", |
| 147 | [DPMAC_CNT_ING_GOOD_FRAME] = "[mac] rx frames ok", |
| 148 | [DPMAC_CNT_ING_ERR_FRAME] = "[mac] rx frame errors", |
| 149 | [DPMAC_CNT_ING_FRAME_DISCARD] = "[mac] rx frame discards", |
| 150 | [DPMAC_CNT_ING_UCAST_FRAME] = "[mac] rx u-cast", |
| 151 | [DPMAC_CNT_ING_BCAST_FRAME] = "[mac] rx b-cast", |
| 152 | [DPMAC_CNT_ING_MCAST_FRAME] = "[mac] rx m-cast", |
| 153 | [DPMAC_CNT_ING_FRAME_64] = "[mac] rx 64 bytes", |
| 154 | [DPMAC_CNT_ING_FRAME_127] = "[mac] rx 65-127 bytes", |
| 155 | [DPMAC_CNT_ING_FRAME_255] = "[mac] rx 128-255 bytes", |
| 156 | [DPMAC_CNT_ING_FRAME_511] = "[mac] rx 256-511 bytes", |
| 157 | [DPMAC_CNT_ING_FRAME_1023] = "[mac] rx 512-1023 bytes", |
| 158 | [DPMAC_CNT_ING_FRAME_1518] = "[mac] rx 1024-1518 bytes", |
| 159 | [DPMAC_CNT_ING_FRAME_1519_MAX] = "[mac] rx 1519-max bytes", |
| 160 | [DPMAC_CNT_ING_FRAG] = "[mac] rx frags", |
| 161 | [DPMAC_CNT_ING_JABBER] = "[mac] rx jabber", |
| 162 | [DPMAC_CNT_ING_ALIGN_ERR] = "[mac] rx align errors", |
| 163 | [DPMAC_CNT_ING_OVERSIZED] = "[mac] rx oversized", |
| 164 | [DPMAC_CNT_ING_VALID_PAUSE_FRAME] = "[mac] rx pause", |
| 165 | [DPMAC_CNT_ING_BYTE] = "[mac] rx bytes", |
| 166 | [DPMAC_CNT_EGR_GOOD_FRAME] = "[mac] tx frames ok", |
| 167 | [DPMAC_CNT_EGR_UCAST_FRAME] = "[mac] tx u-cast", |
| 168 | [DPMAC_CNT_EGR_MCAST_FRAME] = "[mac] tx m-cast", |
| 169 | [DPMAC_CNT_EGR_BCAST_FRAME] = "[mac] tx b-cast", |
| 170 | [DPMAC_CNT_EGR_ERR_FRAME] = "[mac] tx frame errors", |
| 171 | [DPMAC_CNT_EGR_UNDERSIZED] = "[mac] tx undersized", |
| 172 | [DPMAC_CNT_EGR_VALID_PAUSE_FRAME] = "[mac] tx b-pause", |
| 173 | [DPMAC_CNT_EGR_BYTE] = "[mac] tx bytes", |
| 174 | }; |
| 175 | |
| 176 | #define LDPAA_ETH_DPMAC_NUM_STATS ARRAY_SIZE(ldpaa_eth_dpmac_stat_strings) |
| 177 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 178 | struct ldpaa_eth_priv { |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 179 | struct phy_device *phy; |
| 180 | int phy_mode; |
| 181 | bool started; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 182 | uint32_t dpmac_id; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 183 | uint16_t dpmac_handle; |
| 184 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 185 | uint16_t tx_data_offset; |
| 186 | |
| 187 | uint32_t rx_dflt_fqid; |
| 188 | uint16_t tx_qdid; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 189 | uint16_t tx_flow_id; |
| 190 | |
| 191 | enum ldpaa_eth_type type; /* 1G or 10G ethernet */ |
Ioana Ciornei | a121fe4 | 2023-05-23 16:47:45 +0300 | [diff] [blame] | 192 | |
| 193 | /* SW kept statistics */ |
| 194 | u64 dpni_stats[LDPAA_ETH_DPNI_NUM_STATS]; |
Ioana Ciornei | 98fdaaa | 2023-05-23 16:47:46 +0300 | [diff] [blame] | 195 | u64 dpmac_stats[LDPAA_ETH_DPMAC_NUM_STATS]; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 198 | struct dprc_endpoint dpmac_endpoint; |
| 199 | struct dprc_endpoint dpni_endpoint; |
| 200 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 201 | extern struct fsl_mc_io *dflt_mc_io; |
| 202 | extern struct fsl_dpbp_obj *dflt_dpbp; |
| 203 | extern struct fsl_dpio_obj *dflt_dpio; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 204 | extern struct fsl_dpni_obj *dflt_dpni; |
| 205 | extern uint16_t dflt_dprc_handle; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 206 | |
| 207 | static void ldpaa_dpbp_drain_cnt(int count); |
| 208 | static void ldpaa_dpbp_drain(void); |
| 209 | static int ldpaa_dpbp_seed(uint16_t bpid); |
| 210 | static void ldpaa_dpbp_free(void); |
| 211 | static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv); |
| 212 | static int ldpaa_dpbp_setup(void); |
| 213 | static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 214 | static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv); |
| 215 | static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 216 | #endif /* __LDPAA_H */ |