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 | #include <common.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Sean Anderson | eba9951 | 2020-10-04 21:39:46 -0400 | [diff] [blame] | 9 | #include <dm/device_compat.h> |
| 10 | #include <fsl-mc/fsl_dpmac.h> |
| 11 | #include <fsl-mc/ldpaa_wriop.h> |
| 12 | #include <hwconfig.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Sean Anderson | eba9951 | 2020-10-04 21:39:46 -0400 | [diff] [blame] | 15 | #include <miiphy.h> |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 16 | #include <net.h> |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 17 | #include <phy.h> |
Sean Anderson | eba9951 | 2020-10-04 21:39:46 -0400 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/types.h> |
Simon Glass | c06c1be | 2020-05-10 11:40:08 -0600 | [diff] [blame] | 20 | #include <linux/bug.h> |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 21 | #include <linux/compat.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 22 | #include <linux/delay.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 24 | #include "ldpaa_eth.h" |
| 25 | |
Prabhakar Kushwaha | ef9329a | 2016-02-24 17:02:11 +0530 | [diff] [blame] | 26 | #ifdef CONFIG_PHYLIB |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 27 | static void init_phy(struct udevice *dev) |
| 28 | { |
| 29 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
| 30 | |
| 31 | priv->phy = dm_eth_phy_connect(dev); |
| 32 | |
| 33 | if (!priv->phy) |
| 34 | return; |
| 35 | |
| 36 | phy_config(priv->phy); |
| 37 | } |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 38 | #endif |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 39 | |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 40 | #ifdef DEBUG |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 41 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 42 | #define DPNI_STATS_PER_PAGE 6 |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 43 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 44 | static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = { |
| 45 | { |
| 46 | "DPNI_CNT_ING_ALL_FRAMES", |
| 47 | "DPNI_CNT_ING_ALL_BYTES", |
| 48 | "DPNI_CNT_ING_MCAST_FRAMES", |
| 49 | "DPNI_CNT_ING_MCAST_BYTES", |
| 50 | "DPNI_CNT_ING_BCAST_FRAMES", |
| 51 | "DPNI_CNT_ING_BCAST_BYTES", |
| 52 | }, { |
| 53 | "DPNI_CNT_EGR_ALL_FRAMES", |
| 54 | "DPNI_CNT_EGR_ALL_BYTES", |
| 55 | "DPNI_CNT_EGR_MCAST_FRAMES", |
| 56 | "DPNI_CNT_EGR_MCAST_BYTES", |
| 57 | "DPNI_CNT_EGR_BCAST_FRAMES", |
| 58 | "DPNI_CNT_EGR_BCAST_BYTES", |
| 59 | }, { |
| 60 | "DPNI_CNT_ING_FILTERED_FRAMES", |
| 61 | "DPNI_CNT_ING_DISCARDED_FRAMES", |
| 62 | "DPNI_CNT_ING_NOBUFFER_DISCARDS", |
| 63 | "DPNI_CNT_EGR_DISCARDED_FRAMES", |
| 64 | "DPNI_CNT_EGR_CNF_FRAMES", |
| 65 | "" |
| 66 | }, |
| 67 | }; |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 68 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 69 | static void print_dpni_stats(const char *strings[], |
| 70 | struct dpni_statistics dpni_stats) |
| 71 | { |
| 72 | uint64_t *stat; |
| 73 | int i; |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 74 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 75 | stat = (uint64_t *)&dpni_stats; |
| 76 | for (i = 0; i < DPNI_STATS_PER_PAGE; i++) { |
| 77 | if (strcmp(strings[i], "\0") == 0) |
| 78 | break; |
| 79 | printf("%s= %llu\n", strings[i], *stat); |
| 80 | stat++; |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 81 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 82 | } |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 83 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 84 | static void ldpaa_eth_get_dpni_counter(void) |
| 85 | { |
| 86 | int err = 0; |
| 87 | unsigned int page = 0; |
| 88 | struct dpni_statistics dpni_stats; |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 89 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 90 | printf("DPNI counters ..\n"); |
| 91 | for (page = 0; page < 3; page++) { |
| 92 | err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 93 | dflt_dpni->dpni_handle, page, |
| 94 | &dpni_stats); |
| 95 | if (err < 0) { |
| 96 | printf("dpni_get_statistics: failed:"); |
| 97 | printf("%d for page[%d]\n", err, page); |
| 98 | return; |
| 99 | } |
| 100 | print_dpni_stats(dpni_statistics[page], dpni_stats); |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 101 | } |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 102 | } |
Prabhakar Kushwaha | 314aa55 | 2015-12-24 15:33:37 +0530 | [diff] [blame] | 103 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 104 | static void ldpaa_eth_get_dpmac_counter(struct udevice *dev) |
| 105 | { |
| 106 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Prabhakar Kushwaha | 314aa55 | 2015-12-24 15:33:37 +0530 | [diff] [blame] | 107 | int err = 0; |
| 108 | u64 value; |
| 109 | |
| 110 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 111 | priv->dpmac_handle, |
| 112 | DPMAC_CNT_ING_BYTE, |
| 113 | &value); |
| 114 | if (err < 0) { |
| 115 | printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n"); |
| 116 | return; |
| 117 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 118 | printf("\nDPMAC counters ..\n"); |
Prabhakar Kushwaha | 314aa55 | 2015-12-24 15:33:37 +0530 | [diff] [blame] | 119 | printf("DPMAC_CNT_ING_BYTE=%lld\n", value); |
| 120 | |
| 121 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 122 | priv->dpmac_handle, |
| 123 | DPMAC_CNT_ING_FRAME_DISCARD, |
| 124 | &value); |
| 125 | if (err < 0) { |
| 126 | printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n"); |
| 127 | return; |
| 128 | } |
| 129 | printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value); |
| 130 | |
| 131 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 132 | priv->dpmac_handle, |
| 133 | DPMAC_CNT_ING_ALIGN_ERR, |
| 134 | &value); |
| 135 | if (err < 0) { |
| 136 | printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n"); |
| 137 | return; |
| 138 | } |
| 139 | printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value); |
| 140 | |
| 141 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 142 | priv->dpmac_handle, |
| 143 | DPMAC_CNT_ING_BYTE, |
| 144 | &value); |
| 145 | if (err < 0) { |
| 146 | printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n"); |
| 147 | return; |
| 148 | } |
| 149 | printf("DPMAC_CNT_ING_BYTE=%lld\n", value); |
| 150 | |
| 151 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 152 | priv->dpmac_handle, |
| 153 | DPMAC_CNT_ING_ERR_FRAME, |
| 154 | &value); |
| 155 | if (err < 0) { |
| 156 | printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n"); |
| 157 | return; |
| 158 | } |
| 159 | printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value); |
| 160 | |
| 161 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 162 | priv->dpmac_handle, |
| 163 | DPMAC_CNT_EGR_BYTE , |
| 164 | &value); |
| 165 | if (err < 0) { |
| 166 | printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n"); |
| 167 | return; |
| 168 | } |
| 169 | printf("DPMAC_CNT_EGR_BYTE =%lld\n", value); |
| 170 | |
| 171 | err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 172 | priv->dpmac_handle, |
| 173 | DPMAC_CNT_EGR_ERR_FRAME , |
| 174 | &value); |
| 175 | if (err < 0) { |
| 176 | printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n"); |
| 177 | return; |
| 178 | } |
| 179 | printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value); |
| 180 | } |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 181 | #endif |
| 182 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 183 | static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv, |
| 184 | const struct dpaa_fd *fd) |
| 185 | { |
| 186 | u64 fd_addr; |
| 187 | uint16_t fd_offset; |
| 188 | uint32_t fd_length; |
| 189 | struct ldpaa_fas *fas; |
| 190 | uint32_t status, err; |
Prabhakar Kushwaha | c7d10d8 | 2015-07-02 11:29:08 +0530 | [diff] [blame] | 191 | u32 timeo = (CONFIG_SYS_HZ * 2) / 1000; |
| 192 | u32 time_start; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 193 | struct qbman_release_desc releasedesc; |
| 194 | struct qbman_swp *swp = dflt_dpio->sw_portal; |
| 195 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 196 | fd_addr = ldpaa_fd_get_addr(fd); |
| 197 | fd_offset = ldpaa_fd_get_offset(fd); |
| 198 | fd_length = ldpaa_fd_get_len(fd); |
| 199 | |
| 200 | debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length); |
| 201 | |
| 202 | if (fd->simple.frc & LDPAA_FD_FRC_FASV) { |
| 203 | /* Read the frame annotation status word and check for errors */ |
| 204 | fas = (struct ldpaa_fas *) |
| 205 | ((uint8_t *)(fd_addr) + |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 206 | dflt_dpni->buf_layout.private_data_size); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 207 | status = le32_to_cpu(fas->status); |
| 208 | if (status & LDPAA_ETH_RX_ERR_MASK) { |
| 209 | printf("Rx frame error(s): 0x%08x\n", |
| 210 | status & LDPAA_ETH_RX_ERR_MASK); |
| 211 | goto error; |
| 212 | } else if (status & LDPAA_ETH_RX_UNSUPP_MASK) { |
| 213 | printf("Unsupported feature in bitmask: 0x%08x\n", |
| 214 | status & LDPAA_ETH_RX_UNSUPP_MASK); |
| 215 | goto error; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | debug("Rx frame: To Upper layer\n"); |
| 220 | net_process_received_packet((uint8_t *)(fd_addr) + fd_offset, |
| 221 | fd_length); |
| 222 | |
| 223 | error: |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 224 | flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 225 | qbman_release_desc_clear(&releasedesc); |
| 226 | qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid); |
Prabhakar Kushwaha | c7d10d8 | 2015-07-02 11:29:08 +0530 | [diff] [blame] | 227 | time_start = get_timer(0); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 228 | do { |
| 229 | /* Release buffer into the QBMAN */ |
| 230 | err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1); |
Prabhakar Kushwaha | c7d10d8 | 2015-07-02 11:29:08 +0530 | [diff] [blame] | 231 | } while (get_timer(time_start) < timeo && err == -EBUSY); |
| 232 | |
| 233 | if (err == -EBUSY) |
| 234 | printf("Rx frame: QBMAN buffer release fails\n"); |
| 235 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 239 | static int ldpaa_eth_pull_dequeue_rx(struct udevice *dev, |
| 240 | int flags, uchar **packetp) |
| 241 | { |
| 242 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 243 | const struct ldpaa_dq *dq; |
| 244 | const struct dpaa_fd *fd; |
Prabhakar Kushwaha | be0c955 | 2015-07-02 11:29:06 +0530 | [diff] [blame] | 245 | int i = 5, err = 0, status; |
| 246 | u32 timeo = (CONFIG_SYS_HZ * 2) / 1000; |
| 247 | u32 time_start; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 248 | static struct qbman_pull_desc pulldesc; |
| 249 | struct qbman_swp *swp = dflt_dpio->sw_portal; |
| 250 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 251 | while (--i) { |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 252 | qbman_pull_desc_clear(&pulldesc); |
| 253 | qbman_pull_desc_set_numframes(&pulldesc, 1); |
| 254 | qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid); |
| 255 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 256 | err = qbman_swp_pull(swp, &pulldesc); |
| 257 | if (err < 0) { |
| 258 | printf("Dequeue frames error:0x%08x\n", err); |
| 259 | continue; |
| 260 | } |
| 261 | |
Prabhakar Kushwaha | be0c955 | 2015-07-02 11:29:06 +0530 | [diff] [blame] | 262 | time_start = get_timer(0); |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 263 | |
Prabhakar Kushwaha | be0c955 | 2015-07-02 11:29:06 +0530 | [diff] [blame] | 264 | do { |
| 265 | dq = qbman_swp_dqrr_next(swp); |
| 266 | } while (get_timer(time_start) < timeo && !dq); |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 267 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 268 | if (dq) { |
| 269 | /* Check for valid frame. If not sent a consume |
| 270 | * confirmation to QBMAN otherwise give it to NADK |
| 271 | * application and then send consume confirmation to |
| 272 | * QBMAN. |
| 273 | */ |
| 274 | status = (uint8_t)ldpaa_dq_flags(dq); |
| 275 | if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) { |
| 276 | debug("Dequeue RX frames:"); |
| 277 | debug("No frame delivered\n"); |
| 278 | |
| 279 | qbman_swp_dqrr_consume(swp, dq); |
Prabhakar Kushwaha | 37ed1a6 | 2015-07-02 11:29:07 +0530 | [diff] [blame] | 280 | continue; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | fd = ldpaa_dq_fd(dq); |
| 284 | |
| 285 | /* Obtain FD and process it */ |
| 286 | ldpaa_eth_rx(priv, fd); |
| 287 | qbman_swp_dqrr_consume(swp, dq); |
| 288 | break; |
Prabhakar Kushwaha | be0c955 | 2015-07-02 11:29:06 +0530 | [diff] [blame] | 289 | } else { |
| 290 | err = -ENODATA; |
| 291 | debug("No DQRR entries\n"); |
| 292 | break; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | return err; |
| 297 | } |
| 298 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 299 | static int ldpaa_eth_tx(struct udevice *dev, void *buf, int len) |
| 300 | { |
| 301 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 302 | struct dpaa_fd fd; |
| 303 | u64 buffer_start; |
| 304 | int data_offset, err; |
Prabhakar Kushwaha | 20c3010 | 2015-07-02 11:29:05 +0530 | [diff] [blame] | 305 | u32 timeo = (CONFIG_SYS_HZ * 10) / 1000; |
| 306 | u32 time_start; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 307 | struct qbman_swp *swp = dflt_dpio->sw_portal; |
| 308 | struct qbman_eq_desc ed; |
Prabhakar Kushwaha | 20c3010 | 2015-07-02 11:29:05 +0530 | [diff] [blame] | 309 | struct qbman_release_desc releasedesc; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 310 | |
| 311 | /* Setup the FD fields */ |
| 312 | memset(&fd, 0, sizeof(fd)); |
| 313 | |
| 314 | data_offset = priv->tx_data_offset; |
| 315 | |
| 316 | do { |
| 317 | err = qbman_swp_acquire(dflt_dpio->sw_portal, |
| 318 | dflt_dpbp->dpbp_attr.bpid, |
| 319 | &buffer_start, 1); |
| 320 | } while (err == -EBUSY); |
| 321 | |
Ashish Kumar | 34f080c | 2017-10-26 16:03:22 +0530 | [diff] [blame] | 322 | if (err <= 0) { |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 323 | printf("qbman_swp_acquire() failed\n"); |
| 324 | return -ENOMEM; |
| 325 | } |
| 326 | |
| 327 | debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start); |
| 328 | |
| 329 | memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len); |
| 330 | |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 331 | flush_dcache_range(buffer_start, buffer_start + |
| 332 | LDPAA_ETH_RX_BUFFER_SIZE); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 333 | |
| 334 | ldpaa_fd_set_addr(&fd, (u64)buffer_start); |
| 335 | ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset)); |
| 336 | ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid); |
| 337 | ldpaa_fd_set_len(&fd, len); |
| 338 | |
| 339 | fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA | |
| 340 | LDPAA_FD_CTRL_PTV1; |
| 341 | |
| 342 | qbman_eq_desc_clear(&ed); |
| 343 | qbman_eq_desc_set_no_orp(&ed, 0); |
| 344 | qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0); |
Prabhakar Kushwaha | 20c3010 | 2015-07-02 11:29:05 +0530 | [diff] [blame] | 345 | |
| 346 | time_start = get_timer(0); |
| 347 | |
| 348 | while (get_timer(time_start) < timeo) { |
| 349 | err = qbman_swp_enqueue(swp, &ed, |
| 350 | (const struct qbman_fd *)(&fd)); |
| 351 | if (err != -EBUSY) |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | if (err < 0) { |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 356 | printf("error enqueueing Tx frame\n"); |
Prabhakar Kushwaha | 20c3010 | 2015-07-02 11:29:05 +0530 | [diff] [blame] | 357 | goto error; |
| 358 | } |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 359 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 360 | return err; |
Prabhakar Kushwaha | 20c3010 | 2015-07-02 11:29:05 +0530 | [diff] [blame] | 361 | |
| 362 | error: |
| 363 | qbman_release_desc_clear(&releasedesc); |
| 364 | qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid); |
| 365 | time_start = get_timer(0); |
| 366 | do { |
| 367 | /* Release buffer into the QBMAN */ |
| 368 | err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1); |
| 369 | } while (get_timer(time_start) < timeo && err == -EBUSY); |
| 370 | |
| 371 | if (err == -EBUSY) |
| 372 | printf("TX data: QBMAN buffer release fails\n"); |
| 373 | |
| 374 | return err; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 377 | static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv, |
| 378 | struct dpmac_link_state *state) |
| 379 | { |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 380 | phy_interface_t enet_if; |
Tom Rini | 13da625 | 2018-10-11 20:07:48 -0400 | [diff] [blame] | 381 | struct phy_device *phydev = NULL; |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 382 | int err; |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 383 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 384 | /* let's start off with maximum capabilities */ |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 385 | enet_if = wriop_get_enet_if(priv->dpmac_id); |
| 386 | switch (enet_if) { |
| 387 | case PHY_INTERFACE_MODE_XGMII: |
| 388 | state->rate = SPEED_10000; |
| 389 | break; |
| 390 | default: |
| 391 | state->rate = SPEED_1000; |
| 392 | break; |
| 393 | } |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 394 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 395 | state->up = 1; |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 396 | state->options |= DPMAC_LINK_OPT_AUTONEG; |
Tom Rini | e83c201 | 2022-11-27 10:25:14 -0500 | [diff] [blame] | 397 | phydev = priv->phy; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 398 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 399 | if (phydev) { |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 400 | err = phy_startup(phydev); |
| 401 | if (err) { |
| 402 | printf("%s: Could not initialize\n", phydev->dev->name); |
| 403 | state->up = 0; |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 404 | } else if (phydev->link) { |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 405 | state->rate = min(state->rate, (uint32_t)phydev->speed); |
| 406 | if (!phydev->duplex) |
| 407 | state->options |= DPMAC_LINK_OPT_HALF_DUPLEX; |
| 408 | if (!phydev->autoneg) |
| 409 | state->options &= ~DPMAC_LINK_OPT_AUTONEG; |
| 410 | } else { |
| 411 | state->up = 0; |
| 412 | } |
| 413 | } |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 414 | |
| 415 | if (!phydev) |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 416 | state->options &= ~DPMAC_LINK_OPT_AUTONEG; |
| 417 | |
| 418 | if (!state->up) { |
| 419 | state->rate = 0; |
| 420 | state->options = 0; |
| 421 | return -ENOLINK; |
| 422 | } |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 427 | static int ldpaa_eth_open(struct udevice *dev) |
| 428 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 429 | struct eth_pdata *plat = dev_get_plat(dev); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 430 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 431 | struct dpmac_link_state dpmac_link_state = { 0 }; |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 432 | #ifdef DEBUG |
| 433 | struct dpni_link_state link_state; |
| 434 | #endif |
Prabhakar Kushwaha | ef9329a | 2016-02-24 17:02:11 +0530 | [diff] [blame] | 435 | int err = 0; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 436 | struct dpni_queue d_queue; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 437 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 438 | if (eth_is_active(dev)) |
| 439 | return 0; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 440 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 441 | if (get_mc_boot_status() != 0) { |
| 442 | printf("ERROR (MC is not booted)\n"); |
| 443 | return -ENODEV; |
| 444 | } |
| 445 | |
| 446 | if (get_dpl_apply_status() == 0) { |
| 447 | printf("ERROR (DPL is deployed. No device available)\n"); |
| 448 | return -ENODEV; |
| 449 | } |
Prabhakar Kushwaha | ef9329a | 2016-02-24 17:02:11 +0530 | [diff] [blame] | 450 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 451 | /* DPMAC initialization */ |
| 452 | err = ldpaa_dpmac_setup(priv); |
| 453 | if (err < 0) |
| 454 | goto err_dpmac_setup; |
| 455 | |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 456 | err = ldpaa_get_dpmac_state(priv, &dpmac_link_state); |
| 457 | if (err < 0) |
Pankaj Bansal | d24b128 | 2018-10-10 14:08:29 +0530 | [diff] [blame] | 458 | goto err_dpmac_bind; |
Prabhakar Kushwaha | ef9329a | 2016-02-24 17:02:11 +0530 | [diff] [blame] | 459 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 460 | /* DPMAC binding DPNI */ |
| 461 | err = ldpaa_dpmac_bind(priv); |
| 462 | if (err) |
Pankaj Bansal | d24b128 | 2018-10-10 14:08:29 +0530 | [diff] [blame] | 463 | goto err_dpmac_bind; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 464 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 465 | /* DPNI initialization */ |
| 466 | err = ldpaa_dpni_setup(priv); |
| 467 | if (err < 0) |
| 468 | goto err_dpni_setup; |
| 469 | |
| 470 | err = ldpaa_dpbp_setup(); |
| 471 | if (err < 0) |
| 472 | goto err_dpbp_setup; |
| 473 | |
| 474 | /* DPNI binding DPBP */ |
| 475 | err = ldpaa_dpni_bind(priv); |
| 476 | if (err) |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 477 | goto err_dpni_bind; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 478 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 479 | err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 480 | dflt_dpni->dpni_handle, plat->enetaddr); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 481 | if (err) { |
Prabhakar Kushwaha | d2c20a3 | 2015-10-07 16:29:58 +0530 | [diff] [blame] | 482 | printf("dpni_add_mac_addr() failed\n"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 483 | return err; |
| 484 | } |
| 485 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 486 | err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 487 | if (err < 0) { |
| 488 | printf("dpni_enable() failed\n"); |
| 489 | return err; |
| 490 | } |
| 491 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 492 | err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 493 | priv->dpmac_handle, &dpmac_link_state); |
| 494 | if (err < 0) { |
| 495 | printf("dpmac_set_link_state() failed\n"); |
| 496 | return err; |
| 497 | } |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 498 | |
| 499 | #ifdef DEBUG |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 500 | printf("DPMAC link status: %d - ", dpmac_link_state.up); |
| 501 | dpmac_link_state.up == 0 ? printf("down\n") : |
| 502 | dpmac_link_state.up == 1 ? printf("up\n") : printf("error state\n"); |
| 503 | |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 504 | err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 505 | dflt_dpni->dpni_handle, &link_state); |
| 506 | if (err < 0) { |
| 507 | printf("dpni_get_link_state() failed\n"); |
| 508 | return err; |
| 509 | } |
| 510 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 511 | printf("DPNI link status: %d - ", link_state.up); |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 512 | link_state.up == 0 ? printf("down\n") : |
| 513 | link_state.up == 1 ? printf("up\n") : printf("error state\n"); |
| 514 | #endif |
| 515 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 516 | memset(&d_queue, 0, sizeof(struct dpni_queue)); |
| 517 | err = dpni_get_queue(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 518 | dflt_dpni->dpni_handle, DPNI_QUEUE_RX, |
| 519 | 0, 0, &d_queue); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 520 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 521 | printf("dpni_get_queue failed\n"); |
| 522 | goto err_get_queue; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 525 | priv->rx_dflt_fqid = d_queue.fqid; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 526 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 527 | err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle, |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 528 | &priv->tx_qdid); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 529 | if (err) { |
| 530 | printf("dpni_get_qdid() failed\n"); |
| 531 | goto err_qdid; |
| 532 | } |
| 533 | |
Pankaj Bansal | e031d26 | 2018-10-10 14:08:32 +0530 | [diff] [blame] | 534 | return dpmac_link_state.up; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 535 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 536 | err_qdid: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 537 | err_get_queue: |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 538 | dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 539 | err_dpni_bind: |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 540 | ldpaa_dpbp_free(); |
| 541 | err_dpbp_setup: |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 542 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 543 | err_dpni_setup: |
Pankaj Bansal | d24b128 | 2018-10-10 14:08:29 +0530 | [diff] [blame] | 544 | err_dpmac_bind: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 545 | dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle); |
| 546 | dpmac_destroy(dflt_mc_io, |
| 547 | dflt_dprc_handle, |
| 548 | MC_CMD_NO_FLAGS, priv->dpmac_id); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 549 | err_dpmac_setup: |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 550 | return err; |
| 551 | } |
| 552 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 553 | static void ldpaa_eth_stop(struct udevice *dev) |
| 554 | { |
| 555 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 556 | struct phy_device *phydev = NULL; |
| 557 | int err = 0; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 558 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 559 | if (!eth_is_active(dev)) |
| 560 | return; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 561 | |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 562 | #ifdef DEBUG |
| 563 | ldpaa_eth_get_dpni_counter(); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 564 | ldpaa_eth_get_dpmac_counter(dev); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 565 | #endif |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 566 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 567 | err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 568 | dflt_dprc_handle, &dpmac_endpoint); |
| 569 | if (err < 0) |
| 570 | printf("dprc_disconnect() failed dpmac_endpoint\n"); |
| 571 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 572 | err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle); |
| 573 | if (err < 0) |
| 574 | printf("dpmac_close() failed\n"); |
| 575 | |
| 576 | err = dpmac_destroy(dflt_mc_io, |
| 577 | dflt_dprc_handle, |
| 578 | MC_CMD_NO_FLAGS, |
| 579 | priv->dpmac_id); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 580 | if (err < 0) |
| 581 | printf("dpmac_destroy() failed\n"); |
| 582 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 583 | /* Stop Tx and Rx traffic */ |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 584 | err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 585 | if (err < 0) |
| 586 | printf("dpni_disable() failed\n"); |
| 587 | |
Tom Rini | e83c201 | 2022-11-27 10:25:14 -0500 | [diff] [blame] | 588 | phydev = priv->phy; |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 589 | if (phydev) |
| 590 | phy_shutdown(phydev); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 591 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 592 | /* Free DPBP handle and reset. */ |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 593 | ldpaa_dpbp_free(); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 594 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 595 | dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 596 | if (err < 0) |
| 597 | printf("dpni_reset() failed\n"); |
| 598 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 599 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 600 | if (err < 0) |
| 601 | printf("dpni_close() failed\n"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void ldpaa_dpbp_drain_cnt(int count) |
| 605 | { |
| 606 | uint64_t buf_array[7]; |
| 607 | void *addr; |
| 608 | int ret, i; |
| 609 | |
| 610 | BUG_ON(count > 7); |
| 611 | |
| 612 | do { |
| 613 | ret = qbman_swp_acquire(dflt_dpio->sw_portal, |
| 614 | dflt_dpbp->dpbp_attr.bpid, |
| 615 | buf_array, count); |
| 616 | if (ret < 0) { |
| 617 | printf("qbman_swp_acquire() failed\n"); |
| 618 | return; |
| 619 | } |
| 620 | for (i = 0; i < ret; i++) { |
| 621 | addr = (void *)buf_array[i]; |
| 622 | debug("Free: buffer addr =0x%p\n", addr); |
| 623 | free(addr); |
| 624 | } |
| 625 | } while (ret); |
| 626 | } |
| 627 | |
| 628 | static void ldpaa_dpbp_drain(void) |
| 629 | { |
| 630 | int i; |
| 631 | for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) |
| 632 | ldpaa_dpbp_drain_cnt(7); |
| 633 | } |
| 634 | |
| 635 | static int ldpaa_bp_add_7(uint16_t bpid) |
| 636 | { |
| 637 | uint64_t buf_array[7]; |
| 638 | u8 *addr; |
| 639 | int i; |
| 640 | struct qbman_release_desc rd; |
| 641 | |
| 642 | for (i = 0; i < 7; i++) { |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 643 | addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 644 | if (!addr) { |
| 645 | printf("addr allocation failed\n"); |
| 646 | goto err_alloc; |
| 647 | } |
| 648 | memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE); |
Prabhakar Kushwaha | dbe0f2a | 2015-03-20 19:28:15 -0700 | [diff] [blame] | 649 | flush_dcache_range((u64)addr, |
| 650 | (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE)); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 651 | |
| 652 | buf_array[i] = (uint64_t)addr; |
| 653 | debug("Release: buffer addr =0x%p\n", addr); |
| 654 | } |
| 655 | |
| 656 | release_bufs: |
| 657 | /* In case the portal is busy, retry until successful. |
| 658 | * This function is guaranteed to succeed in a reasonable amount |
| 659 | * of time. |
| 660 | */ |
| 661 | |
| 662 | do { |
| 663 | mdelay(1); |
| 664 | qbman_release_desc_clear(&rd); |
| 665 | qbman_release_desc_set_bpid(&rd, bpid); |
| 666 | } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i)); |
| 667 | |
| 668 | return i; |
| 669 | |
| 670 | err_alloc: |
| 671 | if (i) |
| 672 | goto release_bufs; |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static int ldpaa_dpbp_seed(uint16_t bpid) |
| 678 | { |
| 679 | int i; |
| 680 | int count; |
| 681 | |
| 682 | for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) { |
| 683 | count = ldpaa_bp_add_7(bpid); |
| 684 | if (count < 7) |
| 685 | printf("Buffer Seed= %d\n", count); |
| 686 | } |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static int ldpaa_dpbp_setup(void) |
| 692 | { |
| 693 | int err; |
| 694 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 695 | err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id, |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 696 | &dflt_dpbp->dpbp_handle); |
| 697 | if (err) { |
| 698 | printf("dpbp_open() failed\n"); |
| 699 | goto err_open; |
| 700 | } |
| 701 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 702 | err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 703 | if (err) { |
| 704 | printf("dpbp_enable() failed\n"); |
| 705 | goto err_enable; |
| 706 | } |
| 707 | |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 708 | err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 709 | dflt_dpbp->dpbp_handle, |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 710 | &dflt_dpbp->dpbp_attr); |
| 711 | if (err) { |
| 712 | printf("dpbp_get_attributes() failed\n"); |
| 713 | goto err_get_attr; |
| 714 | } |
| 715 | |
| 716 | err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 717 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 718 | if (err) { |
| 719 | printf("Buffer seeding failed for DPBP %d (bpid=%d)\n", |
| 720 | dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid); |
| 721 | goto err_seed; |
| 722 | } |
| 723 | |
| 724 | return 0; |
| 725 | |
| 726 | err_seed: |
| 727 | err_get_attr: |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 728 | dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 729 | err_enable: |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 730 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 731 | err_open: |
| 732 | return err; |
| 733 | } |
| 734 | |
| 735 | static void ldpaa_dpbp_free(void) |
| 736 | { |
| 737 | ldpaa_dpbp_drain(); |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 738 | dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 739 | dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 740 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 743 | static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io, |
| 744 | struct ldpaa_eth_priv *priv) |
| 745 | { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 746 | int error; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 747 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 748 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 749 | error = dpmac_get_api_version(dflt_mc_io, 0, |
| 750 | &major_ver, |
| 751 | &minor_ver); |
| 752 | if ((major_ver < DPMAC_VER_MAJOR) || |
| 753 | (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) { |
| 754 | printf("DPMAC version mismatch found %u.%u,", |
| 755 | major_ver, minor_ver); |
| 756 | printf("supported version is %u.%u\n", |
| 757 | DPMAC_VER_MAJOR, DPMAC_VER_MINOR); |
| 758 | return error; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | return error; |
| 762 | } |
| 763 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 764 | static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv) |
| 765 | { |
| 766 | int err = 0; |
| 767 | struct dpmac_cfg dpmac_cfg; |
| 768 | |
| 769 | dpmac_cfg.mac_id = priv->dpmac_id; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 770 | |
| 771 | err = dpmac_create(dflt_mc_io, |
| 772 | dflt_dprc_handle, |
| 773 | MC_CMD_NO_FLAGS, &dpmac_cfg, |
| 774 | &priv->dpmac_id); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 775 | if (err) |
| 776 | printf("dpmac_create() failed\n"); |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 777 | |
| 778 | err = ldpaa_dpmac_version_check(dflt_mc_io, priv); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 779 | if (err < 0) { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 780 | printf("ldpaa_dpmac_version_check() failed: %d\n", err); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 781 | goto err_version_check; |
| 782 | } |
| 783 | |
| 784 | err = dpmac_open(dflt_mc_io, |
| 785 | MC_CMD_NO_FLAGS, |
| 786 | priv->dpmac_id, |
| 787 | &priv->dpmac_handle); |
| 788 | if (err < 0) { |
| 789 | printf("dpmac_open() failed: %d\n", err); |
| 790 | goto err_open; |
| 791 | } |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 792 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 793 | return err; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 794 | |
| 795 | err_open: |
| 796 | err_version_check: |
| 797 | dpmac_destroy(dflt_mc_io, |
| 798 | dflt_dprc_handle, |
| 799 | MC_CMD_NO_FLAGS, priv->dpmac_id); |
| 800 | |
| 801 | return err; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv) |
| 805 | { |
| 806 | int err = 0; |
| 807 | struct dprc_connection_cfg dprc_connection_cfg = { |
| 808 | /* If both rates are zero the connection */ |
| 809 | /* will be configured in "best effort" mode. */ |
| 810 | .committed_rate = 0, |
| 811 | .max_rate = 0 |
| 812 | }; |
| 813 | |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 814 | #ifdef DEBUG |
| 815 | struct dprc_endpoint dbg_endpoint; |
| 816 | int state = 0; |
| 817 | #endif |
| 818 | |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 819 | memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint)); |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 820 | strcpy(dpmac_endpoint.type, "dpmac"); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 821 | dpmac_endpoint.id = priv->dpmac_id; |
| 822 | |
| 823 | memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint)); |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 824 | strcpy(dpni_endpoint.type, "dpni"); |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 825 | dpni_endpoint.id = dflt_dpni->dpni_id; |
| 826 | |
| 827 | err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 828 | dflt_dprc_handle, |
| 829 | &dpmac_endpoint, |
| 830 | &dpni_endpoint, |
| 831 | &dprc_connection_cfg); |
Prabhakar Kushwaha | b4af96f | 2015-11-04 12:26:01 +0530 | [diff] [blame] | 832 | if (err) |
| 833 | printf("dprc_connect() failed\n"); |
| 834 | |
| 835 | #ifdef DEBUG |
| 836 | err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 837 | dflt_dprc_handle, &dpni_endpoint, |
| 838 | &dbg_endpoint, &state); |
| 839 | printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type); |
| 840 | printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id); |
| 841 | printf("%s, DPMAC State= %d\n", __func__, state); |
| 842 | |
| 843 | memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint)); |
| 844 | err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 845 | dflt_dprc_handle, &dpmac_endpoint, |
| 846 | &dbg_endpoint, &state); |
| 847 | printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type); |
| 848 | printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id); |
| 849 | printf("%s, DPNI State= %d\n", __func__, state); |
| 850 | #endif |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 851 | return err; |
| 852 | } |
| 853 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 854 | static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv) |
| 855 | { |
| 856 | int err; |
| 857 | |
| 858 | /* and get a handle for the DPNI this interface is associate with */ |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 859 | err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id, |
| 860 | &dflt_dpni->dpni_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 861 | if (err) { |
| 862 | printf("dpni_open() failed\n"); |
| 863 | goto err_open; |
| 864 | } |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 865 | err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 866 | dflt_dpni->dpni_handle, |
| 867 | &dflt_dpni->dpni_attrs); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 868 | if (err) { |
| 869 | printf("dpni_get_attributes() failed (err=%d)\n", err); |
| 870 | goto err_get_attr; |
| 871 | } |
| 872 | |
| 873 | /* Configure our buffers' layout */ |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 874 | dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 875 | DPNI_BUF_LAYOUT_OPT_FRAME_STATUS | |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 876 | DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE | |
| 877 | DPNI_BUF_LAYOUT_OPT_DATA_ALIGN; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 878 | dflt_dpni->buf_layout.pass_parser_result = true; |
| 879 | dflt_dpni->buf_layout.pass_frame_status = true; |
| 880 | dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE; |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 881 | /* HW erratum mandates data alignment in multiples of 256 */ |
| 882 | dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 883 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 884 | /* ...rx, ... */ |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 885 | err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 886 | dflt_dpni->dpni_handle, |
| 887 | &dflt_dpni->buf_layout, DPNI_QUEUE_RX); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 888 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 889 | printf("dpni_set_buffer_layout() failed"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 890 | goto err_buf_layout; |
| 891 | } |
| 892 | |
| 893 | /* ... tx, ... */ |
Prabhakar Kushwaha | 9a93480 | 2015-11-04 12:26:02 +0530 | [diff] [blame] | 894 | /* remove Rx-only options */ |
| 895 | dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN | |
| 896 | DPNI_BUF_LAYOUT_OPT_PARSER_RESULT); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 897 | err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 898 | dflt_dpni->dpni_handle, |
| 899 | &dflt_dpni->buf_layout, DPNI_QUEUE_TX); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 900 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 901 | printf("dpni_set_buffer_layout() failed"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 902 | goto err_buf_layout; |
| 903 | } |
| 904 | |
| 905 | /* ... tx-confirm. */ |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 906 | dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 907 | err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 908 | dflt_dpni->dpni_handle, |
| 909 | &dflt_dpni->buf_layout, |
| 910 | DPNI_QUEUE_TX_CONFIRM); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 911 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 912 | printf("dpni_set_buffer_layout() failed"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 913 | goto err_buf_layout; |
| 914 | } |
| 915 | |
| 916 | /* Now that we've set our tx buffer layout, retrieve the minimum |
| 917 | * required tx data offset. |
| 918 | */ |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 919 | err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 920 | dflt_dpni->dpni_handle, |
| 921 | &priv->tx_data_offset); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 922 | if (err) { |
| 923 | printf("dpni_get_tx_data_offset() failed\n"); |
| 924 | goto err_data_offset; |
| 925 | } |
| 926 | |
| 927 | /* Warn in case TX data offset is not multiple of 64 bytes. */ |
| 928 | WARN_ON(priv->tx_data_offset % 64); |
| 929 | |
| 930 | /* Accomodate SWA space. */ |
| 931 | priv->tx_data_offset += LDPAA_ETH_SWA_SIZE; |
| 932 | debug("priv->tx_data_offset=%d\n", priv->tx_data_offset); |
| 933 | |
| 934 | return 0; |
| 935 | |
| 936 | err_data_offset: |
| 937 | err_buf_layout: |
| 938 | err_get_attr: |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 939 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 940 | err_open: |
| 941 | return err; |
| 942 | } |
| 943 | |
| 944 | static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv) |
| 945 | { |
| 946 | struct dpni_pools_cfg pools_params; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 947 | struct dpni_queue tx_queue; |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 948 | int err = 0; |
| 949 | |
Prabhakar Kushwaha | a799232 | 2016-03-28 14:11:05 +0530 | [diff] [blame] | 950 | memset(&pools_params, 0, sizeof(pools_params)); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 951 | pools_params.num_dpbp = 1; |
| 952 | pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id; |
| 953 | pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE; |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 954 | err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 955 | dflt_dpni->dpni_handle, &pools_params); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 956 | if (err) { |
| 957 | printf("dpni_set_pools() failed\n"); |
| 958 | return err; |
| 959 | } |
| 960 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 961 | memset(&tx_queue, 0, sizeof(struct dpni_queue)); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 962 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 963 | err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 964 | dflt_dpni->dpni_handle, |
| 965 | DPNI_QUEUE_TX, 0, 0, &tx_queue); |
| 966 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 967 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 968 | printf("dpni_set_queue() failed\n"); |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 969 | return err; |
| 970 | } |
| 971 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 972 | err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 973 | dflt_dpni->dpni_handle, |
| 974 | DPNI_CONF_DISABLE); |
Prabhakar Kushwaha | b0efba7 | 2015-12-24 15:33:13 +0530 | [diff] [blame] | 975 | if (err) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 976 | printf("dpni_set_tx_confirmation_mode() failed\n"); |
Prabhakar Kushwaha | b0efba7 | 2015-12-24 15:33:13 +0530 | [diff] [blame] | 977 | return err; |
| 978 | } |
| 979 | |
Prabhakar Kushwaha | 5350b99 | 2015-03-19 09:20:46 -0700 | [diff] [blame] | 980 | return 0; |
| 981 | } |
| 982 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 983 | static int ldpaa_eth_probe(struct udevice *dev) |
| 984 | { |
| 985 | struct ofnode_phandle_args phandle; |
| 986 | |
| 987 | /* Nothing to do if there is no "phy-handle" in the DTS node */ |
| 988 | if (dev_read_phandle_with_args(dev, "phy-handle", NULL, |
| 989 | 0, 0, &phandle)) { |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | init_phy(dev); |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | static uint32_t ldpaa_eth_get_dpmac_id(struct udevice *dev) |
| 999 | { |
| 1000 | int port_node = dev_of_offset(dev); |
| 1001 | |
| 1002 | return fdtdec_get_uint(gd->fdt_blob, port_node, "reg", -1); |
| 1003 | } |
| 1004 | |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1005 | static int ldpaa_eth_bind(struct udevice *dev) |
| 1006 | { |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1007 | uint32_t dpmac_id; |
| 1008 | char eth_name[16]; |
| 1009 | int phy_mode = -1; |
| 1010 | |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1011 | phy_mode = dev_read_phy_mode(dev); |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 1012 | if (phy_mode == PHY_INTERFACE_MODE_NA) { |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1013 | dev_err(dev, "incorrect phy mode\n"); |
| 1014 | return -EINVAL; |
| 1015 | } |
| 1016 | |
| 1017 | dpmac_id = ldpaa_eth_get_dpmac_id(dev); |
| 1018 | if (dpmac_id == -1) { |
| 1019 | dev_err(dev, "missing reg field from the dpmac node\n"); |
| 1020 | return -EINVAL; |
| 1021 | } |
| 1022 | |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1023 | sprintf(eth_name, "DPMAC%d@%s", dpmac_id, |
| 1024 | phy_string_for_interface(phy_mode)); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1025 | device_set_name(dev, eth_name); |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1030 | static int ldpaa_eth_of_to_plat(struct udevice *dev) |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1031 | { |
| 1032 | struct ldpaa_eth_priv *priv = dev_get_priv(dev); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1033 | |
| 1034 | priv->dpmac_id = ldpaa_eth_get_dpmac_id(dev); |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1035 | priv->phy_mode = dev_read_phy_mode(dev); |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1036 | |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | static const struct eth_ops ldpaa_eth_ops = { |
| 1041 | .start = ldpaa_eth_open, |
| 1042 | .send = ldpaa_eth_tx, |
| 1043 | .recv = ldpaa_eth_pull_dequeue_rx, |
| 1044 | .stop = ldpaa_eth_stop, |
| 1045 | }; |
| 1046 | |
| 1047 | static const struct udevice_id ldpaa_eth_of_ids[] = { |
| 1048 | { .compatible = "fsl,qoriq-mc-dpmac" }, |
| 1049 | }; |
| 1050 | |
| 1051 | U_BOOT_DRIVER(ldpaa_eth) = { |
| 1052 | .name = "ldpaa_eth", |
| 1053 | .id = UCLASS_ETH, |
| 1054 | .of_match = ldpaa_eth_of_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1055 | .of_to_plat = ldpaa_eth_of_to_plat, |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1056 | .bind = ldpaa_eth_bind, |
| 1057 | .probe = ldpaa_eth_probe, |
| 1058 | .ops = &ldpaa_eth_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1059 | .priv_auto = sizeof(struct ldpaa_eth_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1060 | .plat_auto = sizeof(struct eth_pdata), |
Ioana Ciornei | 872004f | 2020-03-18 16:47:37 +0200 | [diff] [blame] | 1061 | }; |