2 * Copyright (C) 2014 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
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;
27 bus = wriop_get_mdio(priv->dpmac_id);
31 phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
32 dev, wriop_get_enet_if(priv->dpmac_id));
34 printf("Failed to connect\n");
38 priv->phydev = phydev;
40 return phy_config(phydev);
45 static void ldpaa_eth_get_dpni_counter(void)
50 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
51 dflt_dpni->dpni_handle,
55 printf("dpni_get_counter: DPNI_CNT_ING_FRAME failed\n");
58 printf("DPNI_CNT_ING_FRAME=%lld\n", value);
60 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
61 dflt_dpni->dpni_handle,
65 printf("dpni_get_counter: DPNI_CNT_ING_BYTE failed\n");
68 printf("DPNI_CNT_ING_BYTE=%lld\n", value);
70 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
71 dflt_dpni->dpni_handle,
72 DPNI_CNT_ING_FRAME_DROP ,
75 printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DROP failed\n");
78 printf("DPNI_CNT_ING_FRAME_DROP =%lld\n", value);
80 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
81 dflt_dpni->dpni_handle,
82 DPNI_CNT_ING_FRAME_DISCARD,
85 printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DISCARD failed\n");
88 printf("DPNI_CNT_ING_FRAME_DISCARD=%lld\n", value);
90 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
91 dflt_dpni->dpni_handle,
95 printf("dpni_get_counter: DPNI_CNT_EGR_FRAME failed\n");
98 printf("DPNI_CNT_EGR_FRAME=%lld\n", value);
100 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
101 dflt_dpni->dpni_handle,
105 printf("dpni_get_counter: DPNI_CNT_EGR_BYTE failed\n");
108 printf("DPNI_CNT_EGR_BYTE =%lld\n", value);
110 err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
111 dflt_dpni->dpni_handle,
112 DPNI_CNT_EGR_FRAME_DISCARD ,
115 printf("dpni_get_counter: DPNI_CNT_EGR_FRAME_DISCARD failed\n");
118 printf("DPNI_CNT_EGR_FRAME_DISCARD =%lld\n", value);
121 static void ldpaa_eth_get_dpmac_counter(struct eth_device *net_dev)
123 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
127 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
132 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
135 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
137 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
139 DPMAC_CNT_ING_FRAME_DISCARD,
142 printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
145 printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
147 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
149 DPMAC_CNT_ING_ALIGN_ERR,
152 printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
155 printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
157 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
162 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
165 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
167 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
169 DPMAC_CNT_ING_ERR_FRAME,
172 printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
175 printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
177 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
182 printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
185 printf("DPMAC_CNT_EGR_BYTE =%lld\n", value);
187 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
189 DPMAC_CNT_EGR_ERR_FRAME ,
192 printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
195 printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value);
199 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
200 const struct dpaa_fd *fd)
205 struct ldpaa_fas *fas;
206 uint32_t status, err;
207 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
209 struct qbman_release_desc releasedesc;
210 struct qbman_swp *swp = dflt_dpio->sw_portal;
212 fd_addr = ldpaa_fd_get_addr(fd);
213 fd_offset = ldpaa_fd_get_offset(fd);
214 fd_length = ldpaa_fd_get_len(fd);
216 debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length);
218 if (fd->simple.frc & LDPAA_FD_FRC_FASV) {
219 /* Read the frame annotation status word and check for errors */
220 fas = (struct ldpaa_fas *)
221 ((uint8_t *)(fd_addr) +
222 dflt_dpni->buf_layout.private_data_size);
223 status = le32_to_cpu(fas->status);
224 if (status & LDPAA_ETH_RX_ERR_MASK) {
225 printf("Rx frame error(s): 0x%08x\n",
226 status & LDPAA_ETH_RX_ERR_MASK);
228 } else if (status & LDPAA_ETH_RX_UNSUPP_MASK) {
229 printf("Unsupported feature in bitmask: 0x%08x\n",
230 status & LDPAA_ETH_RX_UNSUPP_MASK);
235 debug("Rx frame: To Upper layer\n");
236 net_process_received_packet((uint8_t *)(fd_addr) + fd_offset,
240 flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
241 qbman_release_desc_clear(&releasedesc);
242 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
243 time_start = get_timer(0);
245 /* Release buffer into the QBMAN */
246 err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1);
247 } while (get_timer(time_start) < timeo && err == -EBUSY);
250 printf("Rx frame: QBMAN buffer release fails\n");
255 static int ldpaa_eth_pull_dequeue_rx(struct eth_device *dev)
257 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
258 const struct ldpaa_dq *dq;
259 const struct dpaa_fd *fd;
260 int i = 5, err = 0, status;
261 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
263 static struct qbman_pull_desc pulldesc;
264 struct qbman_swp *swp = dflt_dpio->sw_portal;
267 qbman_pull_desc_clear(&pulldesc);
268 qbman_pull_desc_set_numframes(&pulldesc, 1);
269 qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
271 err = qbman_swp_pull(swp, &pulldesc);
273 printf("Dequeue frames error:0x%08x\n", err);
277 time_start = get_timer(0);
280 dq = qbman_swp_dqrr_next(swp);
281 } while (get_timer(time_start) < timeo && !dq);
284 /* Check for valid frame. If not sent a consume
285 * confirmation to QBMAN otherwise give it to NADK
286 * application and then send consume confirmation to
289 status = (uint8_t)ldpaa_dq_flags(dq);
290 if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) {
291 debug("Dequeue RX frames:");
292 debug("No frame delivered\n");
294 qbman_swp_dqrr_consume(swp, dq);
298 fd = ldpaa_dq_fd(dq);
300 /* Obtain FD and process it */
301 ldpaa_eth_rx(priv, fd);
302 qbman_swp_dqrr_consume(swp, dq);
306 debug("No DQRR entries\n");
314 static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)
316 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
319 int data_offset, err;
320 u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
322 struct qbman_swp *swp = dflt_dpio->sw_portal;
323 struct qbman_eq_desc ed;
324 struct qbman_release_desc releasedesc;
326 /* Setup the FD fields */
327 memset(&fd, 0, sizeof(fd));
329 data_offset = priv->tx_data_offset;
332 err = qbman_swp_acquire(dflt_dpio->sw_portal,
333 dflt_dpbp->dpbp_attr.bpid,
335 } while (err == -EBUSY);
338 printf("qbman_swp_acquire() failed\n");
342 debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start);
344 memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);
346 flush_dcache_range(buffer_start, buffer_start +
347 LDPAA_ETH_RX_BUFFER_SIZE);
349 ldpaa_fd_set_addr(&fd, (u64)buffer_start);
350 ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
351 ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid);
352 ldpaa_fd_set_len(&fd, len);
354 fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA |
357 qbman_eq_desc_clear(&ed);
358 qbman_eq_desc_set_no_orp(&ed, 0);
359 qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0);
361 time_start = get_timer(0);
363 while (get_timer(time_start) < timeo) {
364 err = qbman_swp_enqueue(swp, &ed,
365 (const struct qbman_fd *)(&fd));
371 printf("error enqueueing Tx frame\n");
378 qbman_release_desc_clear(&releasedesc);
379 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
380 time_start = get_timer(0);
382 /* Release buffer into the QBMAN */
383 err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1);
384 } while (get_timer(time_start) < timeo && err == -EBUSY);
387 printf("TX data: QBMAN buffer release fails\n");
392 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
394 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
395 struct dpni_queue_attr rx_queue_attr;
396 struct dpmac_link_state dpmac_link_state = { 0 };
398 struct dpni_link_state link_state;
402 phy_interface_t enet_if;
404 if (net_dev->state == ETH_STATE_ACTIVE)
407 if (get_mc_boot_status() != 0) {
408 printf("ERROR (MC is not booted)\n");
412 if (get_dpl_apply_status() == 0) {
413 printf("ERROR (DPL is deployed. No device available)\n");
417 /* DPMAC initialization */
418 err = ldpaa_dpmac_setup(priv);
420 goto err_dpmac_setup;
424 err = phy_startup(priv->phydev);
426 printf("%s: Could not initialize\n",
427 priv->phydev->dev->name);
431 priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
432 memset(priv->phydev, 0, sizeof(struct phy_device));
434 priv->phydev->speed = SPEED_1000;
435 priv->phydev->link = 1;
436 priv->phydev->duplex = DUPLEX_FULL;
439 bus = wriop_get_mdio(priv->dpmac_id);
440 enet_if = wriop_get_enet_if(priv->dpmac_id);
442 (enet_if == PHY_INTERFACE_MODE_XGMII)) {
443 priv->phydev = (struct phy_device *)
444 malloc(sizeof(struct phy_device));
445 memset(priv->phydev, 0, sizeof(struct phy_device));
447 priv->phydev->speed = SPEED_10000;
448 priv->phydev->link = 1;
449 priv->phydev->duplex = DUPLEX_FULL;
452 if (!priv->phydev->link) {
453 printf("%s: No link.\n", priv->phydev->dev->name);
458 /* DPMAC binding DPNI */
459 err = ldpaa_dpmac_bind(priv);
463 /* DPNI initialization */
464 err = ldpaa_dpni_setup(priv);
468 err = ldpaa_dpbp_setup();
472 /* DPNI binding DPBP */
473 err = ldpaa_dpni_bind(priv);
477 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
478 dflt_dpni->dpni_handle, net_dev->enetaddr);
480 printf("dpni_add_mac_addr() failed\n");
484 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
486 printf("dpni_enable() failed\n");
490 dpmac_link_state.rate = priv->phydev->speed;
492 if (priv->phydev->autoneg == AUTONEG_DISABLE)
493 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
495 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
497 if (priv->phydev->duplex == DUPLEX_HALF)
498 dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
500 dpmac_link_state.up = priv->phydev->link;
502 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
503 priv->dpmac_handle, &dpmac_link_state);
505 printf("dpmac_set_link_state() failed\n");
510 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
511 dflt_dpni->dpni_handle, &link_state);
513 printf("dpni_get_link_state() failed\n");
517 printf("link status: %d - ", link_state.up);
518 link_state.up == 0 ? printf("down\n") :
519 link_state.up == 1 ? printf("up\n") : printf("error state\n");
522 /* TODO: support multiple Rx flows */
523 err = dpni_get_rx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
524 dflt_dpni->dpni_handle, 0, 0, &rx_queue_attr);
526 printf("dpni_get_rx_flow() failed\n");
530 priv->rx_dflt_fqid = rx_queue_attr.fqid;
532 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
535 printf("dpni_get_qdid() failed\n");
539 return priv->phydev->link;
543 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
547 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
550 dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
555 static void ldpaa_eth_stop(struct eth_device *net_dev)
557 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
560 struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
563 if ((net_dev->state == ETH_STATE_PASSIVE) ||
564 (net_dev->state == ETH_STATE_INIT))
568 ldpaa_eth_get_dpni_counter();
569 ldpaa_eth_get_dpmac_counter(net_dev);
572 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
573 dflt_dprc_handle, &dpmac_endpoint);
575 printf("dprc_disconnect() failed dpmac_endpoint\n");
577 err = dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
579 printf("dpmac_destroy() failed\n");
581 /* Stop Tx and Rx traffic */
582 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
584 printf("dpni_disable() failed\n");
587 if (priv->phydev && bus != NULL)
588 phy_shutdown(priv->phydev);
594 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
595 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
598 static void ldpaa_dpbp_drain_cnt(int count)
600 uint64_t buf_array[7];
607 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
608 dflt_dpbp->dpbp_attr.bpid,
611 printf("qbman_swp_acquire() failed\n");
614 for (i = 0; i < ret; i++) {
615 addr = (void *)buf_array[i];
616 debug("Free: buffer addr =0x%p\n", addr);
622 static void ldpaa_dpbp_drain(void)
625 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
626 ldpaa_dpbp_drain_cnt(7);
629 static int ldpaa_bp_add_7(uint16_t bpid)
631 uint64_t buf_array[7];
634 struct qbman_release_desc rd;
636 for (i = 0; i < 7; i++) {
637 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
639 printf("addr allocation failed\n");
642 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
643 flush_dcache_range((u64)addr,
644 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
646 buf_array[i] = (uint64_t)addr;
647 debug("Release: buffer addr =0x%p\n", addr);
651 /* In case the portal is busy, retry until successful.
652 * This function is guaranteed to succeed in a reasonable amount
658 qbman_release_desc_clear(&rd);
659 qbman_release_desc_set_bpid(&rd, bpid);
660 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
671 static int ldpaa_dpbp_seed(uint16_t bpid)
676 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
677 count = ldpaa_bp_add_7(bpid);
679 printf("Buffer Seed= %d\n", count);
685 static int ldpaa_dpbp_setup(void)
689 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
690 &dflt_dpbp->dpbp_handle);
692 printf("dpbp_open() failed\n");
696 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
698 printf("dpbp_enable() failed\n");
702 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
703 dflt_dpbp->dpbp_handle,
704 &dflt_dpbp->dpbp_attr);
706 printf("dpbp_get_attributes() failed\n");
710 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
712 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
713 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
721 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
723 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
728 static void ldpaa_dpbp_free(void)
731 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
732 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
733 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
736 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
737 struct ldpaa_eth_priv *priv)
739 struct dpmac_attr attr;
742 memset(&attr, 0, sizeof(struct dpmac_attr));
743 error = dpmac_get_attributes(mc_io, MC_CMD_NO_FLAGS,
747 if ((attr.version.major != DPMAC_VER_MAJOR) ||
748 (attr.version.minor != DPMAC_VER_MINOR)) {
749 printf("DPMAC version mismatch found %u.%u,",
750 attr.version.major, attr.version.minor);
751 printf("supported version is %u.%u\n",
752 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
759 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
762 struct dpmac_cfg dpmac_cfg;
764 dpmac_cfg.mac_id = priv->dpmac_id;
765 err = dpmac_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpmac_cfg,
766 &priv->dpmac_handle);
768 printf("dpmac_create() failed\n");
770 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
772 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
777 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
780 struct dprc_connection_cfg dprc_connection_cfg = {
781 /* If both rates are zero the connection */
782 /* will be configured in "best effort" mode. */
788 struct dprc_endpoint dbg_endpoint;
792 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
793 strcpy(dpmac_endpoint.type, "dpmac");
794 dpmac_endpoint.id = priv->dpmac_id;
796 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
797 strcpy(dpni_endpoint.type, "dpni");
798 dpni_endpoint.id = dflt_dpni->dpni_id;
800 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
804 &dprc_connection_cfg);
806 printf("dprc_connect() failed\n");
809 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
810 dflt_dprc_handle, &dpni_endpoint,
811 &dbg_endpoint, &state);
812 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
813 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
814 printf("%s, DPMAC State= %d\n", __func__, state);
816 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
817 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
818 dflt_dprc_handle, &dpmac_endpoint,
819 &dbg_endpoint, &state);
820 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
821 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
822 printf("%s, DPNI State= %d\n", __func__, state);
827 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
831 /* and get a handle for the DPNI this interface is associate with */
832 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
833 &dflt_dpni->dpni_handle);
835 printf("dpni_open() failed\n");
839 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
840 dflt_dpni->dpni_handle,
841 &dflt_dpni->dpni_attrs);
843 printf("dpni_get_attributes() failed (err=%d)\n", err);
847 /* Configure our buffers' layout */
848 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
849 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
850 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
851 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
852 dflt_dpni->buf_layout.pass_parser_result = true;
853 dflt_dpni->buf_layout.pass_frame_status = true;
854 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
855 /* HW erratum mandates data alignment in multiples of 256 */
856 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
858 err = dpni_set_rx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
859 dflt_dpni->dpni_handle,
860 &dflt_dpni->buf_layout);
862 printf("dpni_set_rx_buffer_layout() failed");
867 /* remove Rx-only options */
868 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
869 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
870 err = dpni_set_tx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
871 dflt_dpni->dpni_handle,
872 &dflt_dpni->buf_layout);
874 printf("dpni_set_tx_buffer_layout() failed");
878 /* ... tx-confirm. */
879 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
880 err = dpni_set_tx_conf_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
881 dflt_dpni->dpni_handle,
882 &dflt_dpni->buf_layout);
884 printf("dpni_set_tx_conf_buffer_layout() failed");
888 /* Now that we've set our tx buffer layout, retrieve the minimum
889 * required tx data offset.
891 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
892 dflt_dpni->dpni_handle,
893 &priv->tx_data_offset);
895 printf("dpni_get_tx_data_offset() failed\n");
896 goto err_data_offset;
899 /* Warn in case TX data offset is not multiple of 64 bytes. */
900 WARN_ON(priv->tx_data_offset % 64);
902 /* Accomodate SWA space. */
903 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
904 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
911 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
916 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
918 struct dpni_pools_cfg pools_params;
919 struct dpni_tx_flow_cfg dflt_tx_flow;
920 struct dpni_tx_conf_cfg tx_conf_cfg;
923 pools_params.num_dpbp = 1;
924 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
925 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
926 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
927 dflt_dpni->dpni_handle, &pools_params);
929 printf("dpni_set_pools() failed\n");
933 priv->tx_flow_id = DPNI_NEW_FLOW_ID;
934 memset(&dflt_tx_flow, 0, sizeof(dflt_tx_flow));
936 dflt_tx_flow.use_common_tx_conf_queue = 0;
937 err = dpni_set_tx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
938 dflt_dpni->dpni_handle, &priv->tx_flow_id,
941 printf("dpni_set_tx_flow() failed\n");
945 memset(&tx_conf_cfg, 0, sizeof(struct dpni_tx_conf_cfg));
946 tx_conf_cfg.errors_only = true;
947 /*Set tx-conf and error configuration*/
948 err = dpni_set_tx_conf(dflt_mc_io, MC_CMD_NO_FLAGS,
949 dflt_dpni->dpni_handle,
950 priv->tx_flow_id, &tx_conf_cfg);
952 printf("dpni_set_tx_conf() failed\n");
959 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
960 phy_interface_t enet_if)
963 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
965 sprintf(net_dev->name, "DPMAC%d@%s", priv->dpmac_id,
966 phy_interface_strings[enet_if]);
969 net_dev->init = ldpaa_eth_open;
970 net_dev->halt = ldpaa_eth_stop;
971 net_dev->send = ldpaa_eth_tx;
972 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
975 err = init_phy(net_dev);
980 err = eth_register(net_dev);
982 printf("eth_register() = %d\n", err);
989 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
991 struct eth_device *net_dev = NULL;
992 struct ldpaa_eth_priv *priv = NULL;
997 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
999 printf("eth_device malloc() failed\n");
1002 memset(net_dev, 0, sizeof(struct eth_device));
1004 /* alloc the ldpaa ethernet private struct */
1005 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1007 printf("ldpaa_eth_priv malloc() failed\n");
1010 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1012 net_dev->priv = (void *)priv;
1013 priv->net_dev = (struct eth_device *)net_dev;
1014 priv->dpmac_id = dpmac_id;
1015 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1017 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1019 goto err_netdev_init;
1021 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1026 net_dev->priv = NULL;