1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2016 Freescale Semiconductor, Inc.
14 #include <linux/compat.h>
15 #include <fsl-mc/fsl_dpmac.h>
17 #include <fsl-mc/ldpaa_wriop.h>
18 #include "ldpaa_eth.h"
21 static int init_phy(struct eth_device *dev)
23 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
24 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 wriop_set_phy_dev(priv->dpmac_id, phydev);
41 ret = phy_config(phydev);
45 wriop_set_phy_dev(priv->dpmac_id, NULL);
54 #define DPNI_STATS_PER_PAGE 6
56 static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = {
58 "DPNI_CNT_ING_ALL_FRAMES",
59 "DPNI_CNT_ING_ALL_BYTES",
60 "DPNI_CNT_ING_MCAST_FRAMES",
61 "DPNI_CNT_ING_MCAST_BYTES",
62 "DPNI_CNT_ING_BCAST_FRAMES",
63 "DPNI_CNT_ING_BCAST_BYTES",
65 "DPNI_CNT_EGR_ALL_FRAMES",
66 "DPNI_CNT_EGR_ALL_BYTES",
67 "DPNI_CNT_EGR_MCAST_FRAMES",
68 "DPNI_CNT_EGR_MCAST_BYTES",
69 "DPNI_CNT_EGR_BCAST_FRAMES",
70 "DPNI_CNT_EGR_BCAST_BYTES",
72 "DPNI_CNT_ING_FILTERED_FRAMES",
73 "DPNI_CNT_ING_DISCARDED_FRAMES",
74 "DPNI_CNT_ING_NOBUFFER_DISCARDS",
75 "DPNI_CNT_EGR_DISCARDED_FRAMES",
76 "DPNI_CNT_EGR_CNF_FRAMES",
81 static void print_dpni_stats(const char *strings[],
82 struct dpni_statistics dpni_stats)
87 stat = (uint64_t *)&dpni_stats;
88 for (i = 0; i < DPNI_STATS_PER_PAGE; i++) {
89 if (strcmp(strings[i], "\0") == 0)
91 printf("%s= %llu\n", strings[i], *stat);
96 static void ldpaa_eth_get_dpni_counter(void)
99 unsigned int page = 0;
100 struct dpni_statistics dpni_stats;
102 printf("DPNI counters ..\n");
103 for (page = 0; page < 3; page++) {
104 err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
105 dflt_dpni->dpni_handle, page,
108 printf("dpni_get_statistics: failed:");
109 printf("%d for page[%d]\n", err, page);
112 print_dpni_stats(dpni_statistics[page], dpni_stats);
116 static void ldpaa_eth_get_dpmac_counter(struct eth_device *net_dev)
118 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
122 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
127 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
130 printf("\nDPMAC counters ..\n");
131 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
133 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
135 DPMAC_CNT_ING_FRAME_DISCARD,
138 printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
141 printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
143 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
145 DPMAC_CNT_ING_ALIGN_ERR,
148 printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
151 printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
153 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
158 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
161 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
163 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
165 DPMAC_CNT_ING_ERR_FRAME,
168 printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
171 printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
173 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
178 printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
181 printf("DPMAC_CNT_EGR_BYTE =%lld\n", value);
183 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
185 DPMAC_CNT_EGR_ERR_FRAME ,
188 printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
191 printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value);
195 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
196 const struct dpaa_fd *fd)
201 struct ldpaa_fas *fas;
202 uint32_t status, err;
203 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
205 struct qbman_release_desc releasedesc;
206 struct qbman_swp *swp = dflt_dpio->sw_portal;
208 fd_addr = ldpaa_fd_get_addr(fd);
209 fd_offset = ldpaa_fd_get_offset(fd);
210 fd_length = ldpaa_fd_get_len(fd);
212 debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length);
214 if (fd->simple.frc & LDPAA_FD_FRC_FASV) {
215 /* Read the frame annotation status word and check for errors */
216 fas = (struct ldpaa_fas *)
217 ((uint8_t *)(fd_addr) +
218 dflt_dpni->buf_layout.private_data_size);
219 status = le32_to_cpu(fas->status);
220 if (status & LDPAA_ETH_RX_ERR_MASK) {
221 printf("Rx frame error(s): 0x%08x\n",
222 status & LDPAA_ETH_RX_ERR_MASK);
224 } else if (status & LDPAA_ETH_RX_UNSUPP_MASK) {
225 printf("Unsupported feature in bitmask: 0x%08x\n",
226 status & LDPAA_ETH_RX_UNSUPP_MASK);
231 debug("Rx frame: To Upper layer\n");
232 net_process_received_packet((uint8_t *)(fd_addr) + fd_offset,
236 flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
237 qbman_release_desc_clear(&releasedesc);
238 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
239 time_start = get_timer(0);
241 /* Release buffer into the QBMAN */
242 err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1);
243 } while (get_timer(time_start) < timeo && err == -EBUSY);
246 printf("Rx frame: QBMAN buffer release fails\n");
251 static int ldpaa_eth_pull_dequeue_rx(struct eth_device *dev)
253 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
254 const struct ldpaa_dq *dq;
255 const struct dpaa_fd *fd;
256 int i = 5, err = 0, status;
257 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
259 static struct qbman_pull_desc pulldesc;
260 struct qbman_swp *swp = dflt_dpio->sw_portal;
263 qbman_pull_desc_clear(&pulldesc);
264 qbman_pull_desc_set_numframes(&pulldesc, 1);
265 qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
267 err = qbman_swp_pull(swp, &pulldesc);
269 printf("Dequeue frames error:0x%08x\n", err);
273 time_start = get_timer(0);
276 dq = qbman_swp_dqrr_next(swp);
277 } while (get_timer(time_start) < timeo && !dq);
280 /* Check for valid frame. If not sent a consume
281 * confirmation to QBMAN otherwise give it to NADK
282 * application and then send consume confirmation to
285 status = (uint8_t)ldpaa_dq_flags(dq);
286 if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) {
287 debug("Dequeue RX frames:");
288 debug("No frame delivered\n");
290 qbman_swp_dqrr_consume(swp, dq);
294 fd = ldpaa_dq_fd(dq);
296 /* Obtain FD and process it */
297 ldpaa_eth_rx(priv, fd);
298 qbman_swp_dqrr_consume(swp, dq);
302 debug("No DQRR entries\n");
310 static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)
312 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
315 int data_offset, err;
316 u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
318 struct qbman_swp *swp = dflt_dpio->sw_portal;
319 struct qbman_eq_desc ed;
320 struct qbman_release_desc releasedesc;
322 /* Setup the FD fields */
323 memset(&fd, 0, sizeof(fd));
325 data_offset = priv->tx_data_offset;
328 err = qbman_swp_acquire(dflt_dpio->sw_portal,
329 dflt_dpbp->dpbp_attr.bpid,
331 } while (err == -EBUSY);
334 printf("qbman_swp_acquire() failed\n");
338 debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start);
340 memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);
342 flush_dcache_range(buffer_start, buffer_start +
343 LDPAA_ETH_RX_BUFFER_SIZE);
345 ldpaa_fd_set_addr(&fd, (u64)buffer_start);
346 ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
347 ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid);
348 ldpaa_fd_set_len(&fd, len);
350 fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA |
353 qbman_eq_desc_clear(&ed);
354 qbman_eq_desc_set_no_orp(&ed, 0);
355 qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0);
357 time_start = get_timer(0);
359 while (get_timer(time_start) < timeo) {
360 err = qbman_swp_enqueue(swp, &ed,
361 (const struct qbman_fd *)(&fd));
367 printf("error enqueueing Tx frame\n");
374 qbman_release_desc_clear(&releasedesc);
375 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
376 time_start = get_timer(0);
378 /* Release buffer into the QBMAN */
379 err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1);
380 } while (get_timer(time_start) < timeo && err == -EBUSY);
383 printf("TX data: QBMAN buffer release fails\n");
388 static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
389 struct dpmac_link_state *state)
391 struct phy_device *phydev = NULL;
392 phy_interface_t enet_if;
395 /* let's start off with maximum capabilities
397 enet_if = wriop_get_enet_if(priv->dpmac_id);
399 case PHY_INTERFACE_MODE_XGMII:
400 state->rate = SPEED_10000;
403 state->rate = SPEED_1000;
409 state->options |= DPMAC_LINK_OPT_AUTONEG;
411 phydev = wriop_get_phy_dev(priv->dpmac_id);
413 err = phy_startup(phydev);
415 printf("%s: Could not initialize\n", phydev->dev->name);
419 state->rate = min(state->rate, (uint32_t)phydev->speed);
421 state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
422 if (!phydev->autoneg)
423 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
430 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
441 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
443 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
444 struct dpmac_link_state dpmac_link_state = { 0 };
446 struct dpni_link_state link_state;
449 struct dpni_queue d_queue;
451 if (net_dev->state == ETH_STATE_ACTIVE)
454 if (get_mc_boot_status() != 0) {
455 printf("ERROR (MC is not booted)\n");
459 if (get_dpl_apply_status() == 0) {
460 printf("ERROR (DPL is deployed. No device available)\n");
464 /* DPMAC initialization */
465 err = ldpaa_dpmac_setup(priv);
467 goto err_dpmac_setup;
469 err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
473 /* DPMAC binding DPNI */
474 err = ldpaa_dpmac_bind(priv);
478 /* DPNI initialization */
479 err = ldpaa_dpni_setup(priv);
483 err = ldpaa_dpbp_setup();
487 /* DPNI binding DPBP */
488 err = ldpaa_dpni_bind(priv);
492 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
493 dflt_dpni->dpni_handle, net_dev->enetaddr);
495 printf("dpni_add_mac_addr() failed\n");
499 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
501 printf("dpni_enable() failed\n");
505 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
506 priv->dpmac_handle, &dpmac_link_state);
508 printf("dpmac_set_link_state() failed\n");
513 printf("DPMAC link status: %d - ", dpmac_link_state.up);
514 dpmac_link_state.up == 0 ? printf("down\n") :
515 dpmac_link_state.up == 1 ? printf("up\n") : printf("error state\n");
517 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
518 dflt_dpni->dpni_handle, &link_state);
520 printf("dpni_get_link_state() failed\n");
524 printf("DPNI link status: %d - ", link_state.up);
525 link_state.up == 0 ? printf("down\n") :
526 link_state.up == 1 ? printf("up\n") : printf("error state\n");
529 memset(&d_queue, 0, sizeof(struct dpni_queue));
530 err = dpni_get_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
531 dflt_dpni->dpni_handle, DPNI_QUEUE_RX,
534 printf("dpni_get_queue failed\n");
538 priv->rx_dflt_fqid = d_queue.fqid;
540 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
543 printf("dpni_get_qdid() failed\n");
547 return dpmac_link_state.up;
551 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
555 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
558 dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
559 dpmac_destroy(dflt_mc_io,
561 MC_CMD_NO_FLAGS, priv->dpmac_id);
566 static void ldpaa_eth_stop(struct eth_device *net_dev)
568 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
570 struct phy_device *phydev = NULL;
572 if ((net_dev->state == ETH_STATE_PASSIVE) ||
573 (net_dev->state == ETH_STATE_INIT))
577 ldpaa_eth_get_dpni_counter();
578 ldpaa_eth_get_dpmac_counter(net_dev);
581 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
582 dflt_dprc_handle, &dpmac_endpoint);
584 printf("dprc_disconnect() failed dpmac_endpoint\n");
586 err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
588 printf("dpmac_close() failed\n");
590 err = dpmac_destroy(dflt_mc_io,
595 printf("dpmac_destroy() failed\n");
597 /* Stop Tx and Rx traffic */
598 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
600 printf("dpni_disable() failed\n");
603 phydev = wriop_get_phy_dev(priv->dpmac_id);
605 phy_shutdown(phydev);
608 /* Free DPBP handle and reset. */
611 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
613 printf("dpni_reset() failed\n");
615 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
617 printf("dpni_close() failed\n");
620 static void ldpaa_dpbp_drain_cnt(int count)
622 uint64_t buf_array[7];
629 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
630 dflt_dpbp->dpbp_attr.bpid,
633 printf("qbman_swp_acquire() failed\n");
636 for (i = 0; i < ret; i++) {
637 addr = (void *)buf_array[i];
638 debug("Free: buffer addr =0x%p\n", addr);
644 static void ldpaa_dpbp_drain(void)
647 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
648 ldpaa_dpbp_drain_cnt(7);
651 static int ldpaa_bp_add_7(uint16_t bpid)
653 uint64_t buf_array[7];
656 struct qbman_release_desc rd;
658 for (i = 0; i < 7; i++) {
659 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
661 printf("addr allocation failed\n");
664 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
665 flush_dcache_range((u64)addr,
666 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
668 buf_array[i] = (uint64_t)addr;
669 debug("Release: buffer addr =0x%p\n", addr);
673 /* In case the portal is busy, retry until successful.
674 * This function is guaranteed to succeed in a reasonable amount
680 qbman_release_desc_clear(&rd);
681 qbman_release_desc_set_bpid(&rd, bpid);
682 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
693 static int ldpaa_dpbp_seed(uint16_t bpid)
698 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
699 count = ldpaa_bp_add_7(bpid);
701 printf("Buffer Seed= %d\n", count);
707 static int ldpaa_dpbp_setup(void)
711 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
712 &dflt_dpbp->dpbp_handle);
714 printf("dpbp_open() failed\n");
718 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
720 printf("dpbp_enable() failed\n");
724 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
725 dflt_dpbp->dpbp_handle,
726 &dflt_dpbp->dpbp_attr);
728 printf("dpbp_get_attributes() failed\n");
732 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
735 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
736 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
744 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
746 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
751 static void ldpaa_dpbp_free(void)
754 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
755 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
756 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
759 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
760 struct ldpaa_eth_priv *priv)
763 uint16_t major_ver, minor_ver;
765 error = dpmac_get_api_version(dflt_mc_io, 0,
768 if ((major_ver < DPMAC_VER_MAJOR) ||
769 (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) {
770 printf("DPMAC version mismatch found %u.%u,",
771 major_ver, minor_ver);
772 printf("supported version is %u.%u\n",
773 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
780 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
783 struct dpmac_cfg dpmac_cfg;
785 dpmac_cfg.mac_id = priv->dpmac_id;
787 err = dpmac_create(dflt_mc_io,
789 MC_CMD_NO_FLAGS, &dpmac_cfg,
792 printf("dpmac_create() failed\n");
794 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
796 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
797 goto err_version_check;
800 err = dpmac_open(dflt_mc_io,
803 &priv->dpmac_handle);
805 printf("dpmac_open() failed: %d\n", err);
813 dpmac_destroy(dflt_mc_io,
815 MC_CMD_NO_FLAGS, priv->dpmac_id);
820 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
823 struct dprc_connection_cfg dprc_connection_cfg = {
824 /* If both rates are zero the connection */
825 /* will be configured in "best effort" mode. */
831 struct dprc_endpoint dbg_endpoint;
835 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
836 strcpy(dpmac_endpoint.type, "dpmac");
837 dpmac_endpoint.id = priv->dpmac_id;
839 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
840 strcpy(dpni_endpoint.type, "dpni");
841 dpni_endpoint.id = dflt_dpni->dpni_id;
843 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
847 &dprc_connection_cfg);
849 printf("dprc_connect() failed\n");
852 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
853 dflt_dprc_handle, &dpni_endpoint,
854 &dbg_endpoint, &state);
855 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
856 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
857 printf("%s, DPMAC State= %d\n", __func__, state);
859 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
860 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
861 dflt_dprc_handle, &dpmac_endpoint,
862 &dbg_endpoint, &state);
863 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
864 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
865 printf("%s, DPNI State= %d\n", __func__, state);
870 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
874 /* and get a handle for the DPNI this interface is associate with */
875 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
876 &dflt_dpni->dpni_handle);
878 printf("dpni_open() failed\n");
881 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
882 dflt_dpni->dpni_handle,
883 &dflt_dpni->dpni_attrs);
885 printf("dpni_get_attributes() failed (err=%d)\n", err);
889 /* Configure our buffers' layout */
890 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
891 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
892 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
893 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
894 dflt_dpni->buf_layout.pass_parser_result = true;
895 dflt_dpni->buf_layout.pass_frame_status = true;
896 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
897 /* HW erratum mandates data alignment in multiples of 256 */
898 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
901 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
902 dflt_dpni->dpni_handle,
903 &dflt_dpni->buf_layout, DPNI_QUEUE_RX);
905 printf("dpni_set_buffer_layout() failed");
910 /* remove Rx-only options */
911 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
912 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
913 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
914 dflt_dpni->dpni_handle,
915 &dflt_dpni->buf_layout, DPNI_QUEUE_TX);
917 printf("dpni_set_buffer_layout() failed");
921 /* ... tx-confirm. */
922 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
923 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
924 dflt_dpni->dpni_handle,
925 &dflt_dpni->buf_layout,
926 DPNI_QUEUE_TX_CONFIRM);
928 printf("dpni_set_buffer_layout() failed");
932 /* Now that we've set our tx buffer layout, retrieve the minimum
933 * required tx data offset.
935 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
936 dflt_dpni->dpni_handle,
937 &priv->tx_data_offset);
939 printf("dpni_get_tx_data_offset() failed\n");
940 goto err_data_offset;
943 /* Warn in case TX data offset is not multiple of 64 bytes. */
944 WARN_ON(priv->tx_data_offset % 64);
946 /* Accomodate SWA space. */
947 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
948 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
955 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
960 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
962 struct dpni_pools_cfg pools_params;
963 struct dpni_queue tx_queue;
966 memset(&pools_params, 0, sizeof(pools_params));
967 pools_params.num_dpbp = 1;
968 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
969 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
970 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
971 dflt_dpni->dpni_handle, &pools_params);
973 printf("dpni_set_pools() failed\n");
977 memset(&tx_queue, 0, sizeof(struct dpni_queue));
979 err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
980 dflt_dpni->dpni_handle,
981 DPNI_QUEUE_TX, 0, 0, &tx_queue);
984 printf("dpni_set_queue() failed\n");
988 err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS,
989 dflt_dpni->dpni_handle,
992 printf("dpni_set_tx_confirmation_mode() failed\n");
999 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
1000 phy_interface_t enet_if)
1003 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
1005 snprintf(net_dev->name, ETH_NAME_LEN, "DPMAC%d@%s", priv->dpmac_id,
1006 phy_interface_strings[enet_if]);
1008 net_dev->iobase = 0;
1009 net_dev->init = ldpaa_eth_open;
1010 net_dev->halt = ldpaa_eth_stop;
1011 net_dev->send = ldpaa_eth_tx;
1012 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
1014 #ifdef CONFIG_PHYLIB
1015 err = init_phy(net_dev);
1020 err = eth_register(net_dev);
1022 printf("eth_register() = %d\n", err);
1029 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
1031 struct eth_device *net_dev = NULL;
1032 struct ldpaa_eth_priv *priv = NULL;
1036 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
1038 printf("eth_device malloc() failed\n");
1041 memset(net_dev, 0, sizeof(struct eth_device));
1043 /* alloc the ldpaa ethernet private struct */
1044 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1046 printf("ldpaa_eth_priv malloc() failed\n");
1049 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1051 net_dev->priv = (void *)priv;
1052 priv->net_dev = (struct eth_device *)net_dev;
1053 priv->dpmac_id = dpmac_id;
1054 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1056 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1058 goto err_netdev_init;
1060 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1065 net_dev->priv = NULL;