2 * Copyright (C) 2014-2016 Freescale Semiconductor
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/types.h>
15 #include <linux/compat.h>
16 #include <fsl-mc/fsl_dpmac.h>
18 #include <fsl-mc/ldpaa_wriop.h>
19 #include "ldpaa_eth.h"
22 static int init_phy(struct eth_device *dev)
24 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
25 struct phy_device *phydev = NULL;
28 bus = wriop_get_mdio(priv->dpmac_id);
32 phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
33 dev, wriop_get_enet_if(priv->dpmac_id));
35 printf("Failed to connect\n");
39 priv->phydev = phydev;
41 return phy_config(phydev);
47 #define DPNI_STATS_PER_PAGE 6
49 static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = {
51 "DPNI_CNT_ING_ALL_FRAMES",
52 "DPNI_CNT_ING_ALL_BYTES",
53 "DPNI_CNT_ING_MCAST_FRAMES",
54 "DPNI_CNT_ING_MCAST_BYTES",
55 "DPNI_CNT_ING_BCAST_FRAMES",
56 "DPNI_CNT_ING_BCAST_BYTES",
58 "DPNI_CNT_EGR_ALL_FRAMES",
59 "DPNI_CNT_EGR_ALL_BYTES",
60 "DPNI_CNT_EGR_MCAST_FRAMES",
61 "DPNI_CNT_EGR_MCAST_BYTES",
62 "DPNI_CNT_EGR_BCAST_FRAMES",
63 "DPNI_CNT_EGR_BCAST_BYTES",
65 "DPNI_CNT_ING_FILTERED_FRAMES",
66 "DPNI_CNT_ING_DISCARDED_FRAMES",
67 "DPNI_CNT_ING_NOBUFFER_DISCARDS",
68 "DPNI_CNT_EGR_DISCARDED_FRAMES",
69 "DPNI_CNT_EGR_CNF_FRAMES",
74 static void print_dpni_stats(const char *strings[],
75 struct dpni_statistics dpni_stats)
80 stat = (uint64_t *)&dpni_stats;
81 for (i = 0; i < DPNI_STATS_PER_PAGE; i++) {
82 if (strcmp(strings[i], "\0") == 0)
84 printf("%s= %llu\n", strings[i], *stat);
89 static void ldpaa_eth_get_dpni_counter(void)
92 unsigned int page = 0;
93 struct dpni_statistics dpni_stats;
95 printf("DPNI counters ..\n");
96 for (page = 0; page < 3; page++) {
97 err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
98 dflt_dpni->dpni_handle, page,
101 printf("dpni_get_statistics: failed:");
102 printf("%d for page[%d]\n", err, page);
105 print_dpni_stats(dpni_statistics[page], dpni_stats);
109 static void ldpaa_eth_get_dpmac_counter(struct eth_device *net_dev)
111 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
115 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
120 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
123 printf("\nDPMAC counters ..\n");
124 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
126 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
128 DPMAC_CNT_ING_FRAME_DISCARD,
131 printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
134 printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
136 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
138 DPMAC_CNT_ING_ALIGN_ERR,
141 printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
144 printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
146 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
151 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
154 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
156 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
158 DPMAC_CNT_ING_ERR_FRAME,
161 printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
164 printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
166 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
171 printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
174 printf("DPMAC_CNT_EGR_BYTE =%lld\n", value);
176 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
178 DPMAC_CNT_EGR_ERR_FRAME ,
181 printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
184 printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value);
188 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
189 const struct dpaa_fd *fd)
194 struct ldpaa_fas *fas;
195 uint32_t status, err;
196 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
198 struct qbman_release_desc releasedesc;
199 struct qbman_swp *swp = dflt_dpio->sw_portal;
201 fd_addr = ldpaa_fd_get_addr(fd);
202 fd_offset = ldpaa_fd_get_offset(fd);
203 fd_length = ldpaa_fd_get_len(fd);
205 debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length);
207 if (fd->simple.frc & LDPAA_FD_FRC_FASV) {
208 /* Read the frame annotation status word and check for errors */
209 fas = (struct ldpaa_fas *)
210 ((uint8_t *)(fd_addr) +
211 dflt_dpni->buf_layout.private_data_size);
212 status = le32_to_cpu(fas->status);
213 if (status & LDPAA_ETH_RX_ERR_MASK) {
214 printf("Rx frame error(s): 0x%08x\n",
215 status & LDPAA_ETH_RX_ERR_MASK);
217 } else if (status & LDPAA_ETH_RX_UNSUPP_MASK) {
218 printf("Unsupported feature in bitmask: 0x%08x\n",
219 status & LDPAA_ETH_RX_UNSUPP_MASK);
224 debug("Rx frame: To Upper layer\n");
225 net_process_received_packet((uint8_t *)(fd_addr) + fd_offset,
229 flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
230 qbman_release_desc_clear(&releasedesc);
231 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
232 time_start = get_timer(0);
234 /* Release buffer into the QBMAN */
235 err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1);
236 } while (get_timer(time_start) < timeo && err == -EBUSY);
239 printf("Rx frame: QBMAN buffer release fails\n");
244 static int ldpaa_eth_pull_dequeue_rx(struct eth_device *dev)
246 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
247 const struct ldpaa_dq *dq;
248 const struct dpaa_fd *fd;
249 int i = 5, err = 0, status;
250 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
252 static struct qbman_pull_desc pulldesc;
253 struct qbman_swp *swp = dflt_dpio->sw_portal;
256 qbman_pull_desc_clear(&pulldesc);
257 qbman_pull_desc_set_numframes(&pulldesc, 1);
258 qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
260 err = qbman_swp_pull(swp, &pulldesc);
262 printf("Dequeue frames error:0x%08x\n", err);
266 time_start = get_timer(0);
269 dq = qbman_swp_dqrr_next(swp);
270 } while (get_timer(time_start) < timeo && !dq);
273 /* Check for valid frame. If not sent a consume
274 * confirmation to QBMAN otherwise give it to NADK
275 * application and then send consume confirmation to
278 status = (uint8_t)ldpaa_dq_flags(dq);
279 if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) {
280 debug("Dequeue RX frames:");
281 debug("No frame delivered\n");
283 qbman_swp_dqrr_consume(swp, dq);
287 fd = ldpaa_dq_fd(dq);
289 /* Obtain FD and process it */
290 ldpaa_eth_rx(priv, fd);
291 qbman_swp_dqrr_consume(swp, dq);
295 debug("No DQRR entries\n");
303 static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)
305 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
308 int data_offset, err;
309 u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
311 struct qbman_swp *swp = dflt_dpio->sw_portal;
312 struct qbman_eq_desc ed;
313 struct qbman_release_desc releasedesc;
315 /* Setup the FD fields */
316 memset(&fd, 0, sizeof(fd));
318 data_offset = priv->tx_data_offset;
321 err = qbman_swp_acquire(dflt_dpio->sw_portal,
322 dflt_dpbp->dpbp_attr.bpid,
324 } while (err == -EBUSY);
327 printf("qbman_swp_acquire() failed\n");
331 debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start);
333 memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);
335 flush_dcache_range(buffer_start, buffer_start +
336 LDPAA_ETH_RX_BUFFER_SIZE);
338 ldpaa_fd_set_addr(&fd, (u64)buffer_start);
339 ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
340 ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid);
341 ldpaa_fd_set_len(&fd, len);
343 fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA |
346 qbman_eq_desc_clear(&ed);
347 qbman_eq_desc_set_no_orp(&ed, 0);
348 qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0);
350 time_start = get_timer(0);
352 while (get_timer(time_start) < timeo) {
353 err = qbman_swp_enqueue(swp, &ed,
354 (const struct qbman_fd *)(&fd));
360 printf("error enqueueing Tx frame\n");
367 qbman_release_desc_clear(&releasedesc);
368 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
369 time_start = get_timer(0);
371 /* Release buffer into the QBMAN */
372 err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1);
373 } while (get_timer(time_start) < timeo && err == -EBUSY);
376 printf("TX data: QBMAN buffer release fails\n");
381 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
383 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
384 struct dpmac_link_state dpmac_link_state = { 0 };
386 struct dpni_link_state link_state;
390 phy_interface_t enet_if;
391 struct dpni_queue d_queue;
393 if (net_dev->state == ETH_STATE_ACTIVE)
396 if (get_mc_boot_status() != 0) {
397 printf("ERROR (MC is not booted)\n");
401 if (get_dpl_apply_status() == 0) {
402 printf("ERROR (DPL is deployed. No device available)\n");
406 /* DPMAC initialization */
407 err = ldpaa_dpmac_setup(priv);
409 goto err_dpmac_setup;
413 err = phy_startup(priv->phydev);
415 printf("%s: Could not initialize\n",
416 priv->phydev->dev->name);
421 priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
422 memset(priv->phydev, 0, sizeof(struct phy_device));
424 priv->phydev->speed = SPEED_1000;
425 priv->phydev->link = 1;
426 priv->phydev->duplex = DUPLEX_FULL;
429 bus = wriop_get_mdio(priv->dpmac_id);
430 enet_if = wriop_get_enet_if(priv->dpmac_id);
432 (enet_if == PHY_INTERFACE_MODE_XGMII)) {
433 priv->phydev = (struct phy_device *)
434 malloc(sizeof(struct phy_device));
435 memset(priv->phydev, 0, sizeof(struct phy_device));
437 priv->phydev->speed = SPEED_10000;
438 priv->phydev->link = 1;
439 priv->phydev->duplex = DUPLEX_FULL;
442 if (!priv->phydev->link) {
443 printf("%s: No link.\n", priv->phydev->dev->name);
448 /* DPMAC binding DPNI */
449 err = ldpaa_dpmac_bind(priv);
453 /* DPNI initialization */
454 err = ldpaa_dpni_setup(priv);
458 err = ldpaa_dpbp_setup();
462 /* DPNI binding DPBP */
463 err = ldpaa_dpni_bind(priv);
467 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
468 dflt_dpni->dpni_handle, net_dev->enetaddr);
470 printf("dpni_add_mac_addr() failed\n");
474 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
476 printf("dpni_enable() failed\n");
480 dpmac_link_state.rate = priv->phydev->speed;
482 if (priv->phydev->autoneg == AUTONEG_DISABLE)
483 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
485 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
487 if (priv->phydev->duplex == DUPLEX_HALF)
488 dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
490 dpmac_link_state.up = priv->phydev->link;
492 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
493 priv->dpmac_handle, &dpmac_link_state);
495 printf("dpmac_set_link_state() failed\n");
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");
504 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
505 dflt_dpni->dpni_handle, &link_state);
507 printf("dpni_get_link_state() failed\n");
511 printf("DPNI link status: %d - ", link_state.up);
512 link_state.up == 0 ? printf("down\n") :
513 link_state.up == 1 ? printf("up\n") : printf("error state\n");
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,
521 printf("dpni_get_queue failed\n");
525 priv->rx_dflt_fqid = d_queue.fqid;
527 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
530 printf("dpni_get_qdid() failed\n");
534 return priv->phydev->link;
538 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
542 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
545 dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
546 dpmac_destroy(dflt_mc_io,
548 MC_CMD_NO_FLAGS, priv->dpmac_id);
553 static void ldpaa_eth_stop(struct eth_device *net_dev)
555 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
558 struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
561 if ((net_dev->state == ETH_STATE_PASSIVE) ||
562 (net_dev->state == ETH_STATE_INIT))
566 ldpaa_eth_get_dpni_counter();
567 ldpaa_eth_get_dpmac_counter(net_dev);
570 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
571 dflt_dprc_handle, &dpmac_endpoint);
573 printf("dprc_disconnect() failed dpmac_endpoint\n");
575 err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
577 printf("dpmac_close() failed\n");
579 err = dpmac_destroy(dflt_mc_io,
584 printf("dpmac_destroy() failed\n");
586 /* Stop Tx and Rx traffic */
587 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
589 printf("dpni_disable() failed\n");
592 if (priv->phydev && bus != NULL)
593 phy_shutdown(priv->phydev);
600 /* Free DPBP handle and reset. */
603 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
605 printf("dpni_reset() failed\n");
607 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
609 printf("dpni_close() failed\n");
612 static void ldpaa_dpbp_drain_cnt(int count)
614 uint64_t buf_array[7];
621 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
622 dflt_dpbp->dpbp_attr.bpid,
625 printf("qbman_swp_acquire() failed\n");
628 for (i = 0; i < ret; i++) {
629 addr = (void *)buf_array[i];
630 debug("Free: buffer addr =0x%p\n", addr);
636 static void ldpaa_dpbp_drain(void)
639 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
640 ldpaa_dpbp_drain_cnt(7);
643 static int ldpaa_bp_add_7(uint16_t bpid)
645 uint64_t buf_array[7];
648 struct qbman_release_desc rd;
650 for (i = 0; i < 7; i++) {
651 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
653 printf("addr allocation failed\n");
656 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
657 flush_dcache_range((u64)addr,
658 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
660 buf_array[i] = (uint64_t)addr;
661 debug("Release: buffer addr =0x%p\n", addr);
665 /* In case the portal is busy, retry until successful.
666 * This function is guaranteed to succeed in a reasonable amount
672 qbman_release_desc_clear(&rd);
673 qbman_release_desc_set_bpid(&rd, bpid);
674 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
685 static int ldpaa_dpbp_seed(uint16_t bpid)
690 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
691 count = ldpaa_bp_add_7(bpid);
693 printf("Buffer Seed= %d\n", count);
699 static int ldpaa_dpbp_setup(void)
703 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
704 &dflt_dpbp->dpbp_handle);
706 printf("dpbp_open() failed\n");
710 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
712 printf("dpbp_enable() failed\n");
716 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
717 dflt_dpbp->dpbp_handle,
718 &dflt_dpbp->dpbp_attr);
720 printf("dpbp_get_attributes() failed\n");
724 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
727 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
728 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
736 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
738 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
743 static void ldpaa_dpbp_free(void)
746 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
747 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
748 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
751 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
752 struct ldpaa_eth_priv *priv)
755 uint16_t major_ver, minor_ver;
757 error = dpmac_get_api_version(dflt_mc_io, 0,
760 if ((major_ver < DPMAC_VER_MAJOR) ||
761 (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) {
762 printf("DPMAC version mismatch found %u.%u,",
763 major_ver, minor_ver);
764 printf("supported version is %u.%u\n",
765 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
772 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
775 struct dpmac_cfg dpmac_cfg;
777 dpmac_cfg.mac_id = priv->dpmac_id;
779 err = dpmac_create(dflt_mc_io,
781 MC_CMD_NO_FLAGS, &dpmac_cfg,
784 printf("dpmac_create() failed\n");
786 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
788 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
789 goto err_version_check;
792 err = dpmac_open(dflt_mc_io,
795 &priv->dpmac_handle);
797 printf("dpmac_open() failed: %d\n", err);
805 dpmac_destroy(dflt_mc_io,
807 MC_CMD_NO_FLAGS, priv->dpmac_id);
812 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
815 struct dprc_connection_cfg dprc_connection_cfg = {
816 /* If both rates are zero the connection */
817 /* will be configured in "best effort" mode. */
823 struct dprc_endpoint dbg_endpoint;
827 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
828 strcpy(dpmac_endpoint.type, "dpmac");
829 dpmac_endpoint.id = priv->dpmac_id;
831 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
832 strcpy(dpni_endpoint.type, "dpni");
833 dpni_endpoint.id = dflt_dpni->dpni_id;
835 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
839 &dprc_connection_cfg);
841 printf("dprc_connect() failed\n");
844 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
845 dflt_dprc_handle, &dpni_endpoint,
846 &dbg_endpoint, &state);
847 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
848 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
849 printf("%s, DPMAC State= %d\n", __func__, state);
851 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
852 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
853 dflt_dprc_handle, &dpmac_endpoint,
854 &dbg_endpoint, &state);
855 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
856 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
857 printf("%s, DPNI State= %d\n", __func__, state);
862 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
866 /* and get a handle for the DPNI this interface is associate with */
867 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
868 &dflt_dpni->dpni_handle);
870 printf("dpni_open() failed\n");
873 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
874 dflt_dpni->dpni_handle,
875 &dflt_dpni->dpni_attrs);
877 printf("dpni_get_attributes() failed (err=%d)\n", err);
881 /* Configure our buffers' layout */
882 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
883 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
884 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
885 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
886 dflt_dpni->buf_layout.pass_parser_result = true;
887 dflt_dpni->buf_layout.pass_frame_status = true;
888 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
889 /* HW erratum mandates data alignment in multiples of 256 */
890 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
893 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
894 dflt_dpni->dpni_handle,
895 &dflt_dpni->buf_layout, DPNI_QUEUE_RX);
897 printf("dpni_set_buffer_layout() failed");
902 /* remove Rx-only options */
903 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
904 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
905 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
906 dflt_dpni->dpni_handle,
907 &dflt_dpni->buf_layout, DPNI_QUEUE_TX);
909 printf("dpni_set_buffer_layout() failed");
913 /* ... tx-confirm. */
914 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
915 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
916 dflt_dpni->dpni_handle,
917 &dflt_dpni->buf_layout,
918 DPNI_QUEUE_TX_CONFIRM);
920 printf("dpni_set_buffer_layout() failed");
924 /* Now that we've set our tx buffer layout, retrieve the minimum
925 * required tx data offset.
927 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
928 dflt_dpni->dpni_handle,
929 &priv->tx_data_offset);
931 printf("dpni_get_tx_data_offset() failed\n");
932 goto err_data_offset;
935 /* Warn in case TX data offset is not multiple of 64 bytes. */
936 WARN_ON(priv->tx_data_offset % 64);
938 /* Accomodate SWA space. */
939 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
940 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
947 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
952 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
954 struct dpni_pools_cfg pools_params;
955 struct dpni_queue tx_queue;
958 memset(&pools_params, 0, sizeof(pools_params));
959 pools_params.num_dpbp = 1;
960 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
961 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
962 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
963 dflt_dpni->dpni_handle, &pools_params);
965 printf("dpni_set_pools() failed\n");
969 memset(&tx_queue, 0, sizeof(struct dpni_queue));
971 err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
972 dflt_dpni->dpni_handle,
973 DPNI_QUEUE_TX, 0, 0, &tx_queue);
976 printf("dpni_set_queue() failed\n");
980 err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS,
981 dflt_dpni->dpni_handle,
984 printf("dpni_set_tx_confirmation_mode() failed\n");
991 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
992 phy_interface_t enet_if)
995 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
997 sprintf(net_dev->name, "DPMAC%d@%s", priv->dpmac_id,
998 phy_interface_strings[enet_if]);
1000 net_dev->iobase = 0;
1001 net_dev->init = ldpaa_eth_open;
1002 net_dev->halt = ldpaa_eth_stop;
1003 net_dev->send = ldpaa_eth_tx;
1004 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
1006 #ifdef CONFIG_PHYLIB
1007 err = init_phy(net_dev);
1012 err = eth_register(net_dev);
1014 printf("eth_register() = %d\n", err);
1021 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
1023 struct eth_device *net_dev = NULL;
1024 struct ldpaa_eth_priv *priv = NULL;
1028 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
1030 printf("eth_device malloc() failed\n");
1033 memset(net_dev, 0, sizeof(struct eth_device));
1035 /* alloc the ldpaa ethernet private struct */
1036 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1038 printf("ldpaa_eth_priv malloc() failed\n");
1041 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1043 net_dev->priv = (void *)priv;
1044 priv->net_dev = (struct eth_device *)net_dev;
1045 priv->dpmac_id = dpmac_id;
1046 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1048 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1050 goto err_netdev_init;
1052 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1057 net_dev->priv = NULL;