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;
26 int phy_addr, phy_num;
29 bus = wriop_get_mdio(priv->dpmac_id);
33 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
34 phy_addr = wriop_get_phy_address(priv->dpmac_id, phy_num);
38 phydev = phy_connect(bus, phy_addr, dev,
39 wriop_get_enet_if(priv->dpmac_id));
41 printf("Failed to connect\n");
45 wriop_set_phy_dev(priv->dpmac_id, phy_num, phydev);
46 ret = phy_config(phydev);
52 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
53 phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
58 wriop_set_phy_dev(priv->dpmac_id, phy_num, NULL);
68 #define DPNI_STATS_PER_PAGE 6
70 static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = {
72 "DPNI_CNT_ING_ALL_FRAMES",
73 "DPNI_CNT_ING_ALL_BYTES",
74 "DPNI_CNT_ING_MCAST_FRAMES",
75 "DPNI_CNT_ING_MCAST_BYTES",
76 "DPNI_CNT_ING_BCAST_FRAMES",
77 "DPNI_CNT_ING_BCAST_BYTES",
79 "DPNI_CNT_EGR_ALL_FRAMES",
80 "DPNI_CNT_EGR_ALL_BYTES",
81 "DPNI_CNT_EGR_MCAST_FRAMES",
82 "DPNI_CNT_EGR_MCAST_BYTES",
83 "DPNI_CNT_EGR_BCAST_FRAMES",
84 "DPNI_CNT_EGR_BCAST_BYTES",
86 "DPNI_CNT_ING_FILTERED_FRAMES",
87 "DPNI_CNT_ING_DISCARDED_FRAMES",
88 "DPNI_CNT_ING_NOBUFFER_DISCARDS",
89 "DPNI_CNT_EGR_DISCARDED_FRAMES",
90 "DPNI_CNT_EGR_CNF_FRAMES",
95 static void print_dpni_stats(const char *strings[],
96 struct dpni_statistics dpni_stats)
101 stat = (uint64_t *)&dpni_stats;
102 for (i = 0; i < DPNI_STATS_PER_PAGE; i++) {
103 if (strcmp(strings[i], "\0") == 0)
105 printf("%s= %llu\n", strings[i], *stat);
110 static void ldpaa_eth_get_dpni_counter(void)
113 unsigned int page = 0;
114 struct dpni_statistics dpni_stats;
116 printf("DPNI counters ..\n");
117 for (page = 0; page < 3; page++) {
118 err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
119 dflt_dpni->dpni_handle, page,
122 printf("dpni_get_statistics: failed:");
123 printf("%d for page[%d]\n", err, page);
126 print_dpni_stats(dpni_statistics[page], dpni_stats);
130 static void ldpaa_eth_get_dpmac_counter(struct eth_device *net_dev)
132 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
136 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
141 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
144 printf("\nDPMAC counters ..\n");
145 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
147 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
149 DPMAC_CNT_ING_FRAME_DISCARD,
152 printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
155 printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
157 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
159 DPMAC_CNT_ING_ALIGN_ERR,
162 printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
165 printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
167 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
172 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
175 printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
177 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
179 DPMAC_CNT_ING_ERR_FRAME,
182 printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
185 printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
187 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
192 printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
195 printf("DPMAC_CNT_EGR_BYTE =%lld\n", value);
197 err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
199 DPMAC_CNT_EGR_ERR_FRAME ,
202 printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
205 printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value);
209 static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
210 const struct dpaa_fd *fd)
215 struct ldpaa_fas *fas;
216 uint32_t status, err;
217 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
219 struct qbman_release_desc releasedesc;
220 struct qbman_swp *swp = dflt_dpio->sw_portal;
222 fd_addr = ldpaa_fd_get_addr(fd);
223 fd_offset = ldpaa_fd_get_offset(fd);
224 fd_length = ldpaa_fd_get_len(fd);
226 debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length);
228 if (fd->simple.frc & LDPAA_FD_FRC_FASV) {
229 /* Read the frame annotation status word and check for errors */
230 fas = (struct ldpaa_fas *)
231 ((uint8_t *)(fd_addr) +
232 dflt_dpni->buf_layout.private_data_size);
233 status = le32_to_cpu(fas->status);
234 if (status & LDPAA_ETH_RX_ERR_MASK) {
235 printf("Rx frame error(s): 0x%08x\n",
236 status & LDPAA_ETH_RX_ERR_MASK);
238 } else if (status & LDPAA_ETH_RX_UNSUPP_MASK) {
239 printf("Unsupported feature in bitmask: 0x%08x\n",
240 status & LDPAA_ETH_RX_UNSUPP_MASK);
245 debug("Rx frame: To Upper layer\n");
246 net_process_received_packet((uint8_t *)(fd_addr) + fd_offset,
250 flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
251 qbman_release_desc_clear(&releasedesc);
252 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
253 time_start = get_timer(0);
255 /* Release buffer into the QBMAN */
256 err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1);
257 } while (get_timer(time_start) < timeo && err == -EBUSY);
260 printf("Rx frame: QBMAN buffer release fails\n");
265 static int ldpaa_eth_pull_dequeue_rx(struct eth_device *dev)
267 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
268 const struct ldpaa_dq *dq;
269 const struct dpaa_fd *fd;
270 int i = 5, err = 0, status;
271 u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
273 static struct qbman_pull_desc pulldesc;
274 struct qbman_swp *swp = dflt_dpio->sw_portal;
277 qbman_pull_desc_clear(&pulldesc);
278 qbman_pull_desc_set_numframes(&pulldesc, 1);
279 qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
281 err = qbman_swp_pull(swp, &pulldesc);
283 printf("Dequeue frames error:0x%08x\n", err);
287 time_start = get_timer(0);
290 dq = qbman_swp_dqrr_next(swp);
291 } while (get_timer(time_start) < timeo && !dq);
294 /* Check for valid frame. If not sent a consume
295 * confirmation to QBMAN otherwise give it to NADK
296 * application and then send consume confirmation to
299 status = (uint8_t)ldpaa_dq_flags(dq);
300 if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) {
301 debug("Dequeue RX frames:");
302 debug("No frame delivered\n");
304 qbman_swp_dqrr_consume(swp, dq);
308 fd = ldpaa_dq_fd(dq);
310 /* Obtain FD and process it */
311 ldpaa_eth_rx(priv, fd);
312 qbman_swp_dqrr_consume(swp, dq);
316 debug("No DQRR entries\n");
324 static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)
326 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
329 int data_offset, err;
330 u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
332 struct qbman_swp *swp = dflt_dpio->sw_portal;
333 struct qbman_eq_desc ed;
334 struct qbman_release_desc releasedesc;
336 /* Setup the FD fields */
337 memset(&fd, 0, sizeof(fd));
339 data_offset = priv->tx_data_offset;
342 err = qbman_swp_acquire(dflt_dpio->sw_portal,
343 dflt_dpbp->dpbp_attr.bpid,
345 } while (err == -EBUSY);
348 printf("qbman_swp_acquire() failed\n");
352 debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start);
354 memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);
356 flush_dcache_range(buffer_start, buffer_start +
357 LDPAA_ETH_RX_BUFFER_SIZE);
359 ldpaa_fd_set_addr(&fd, (u64)buffer_start);
360 ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
361 ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid);
362 ldpaa_fd_set_len(&fd, len);
364 fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA |
367 qbman_eq_desc_clear(&ed);
368 qbman_eq_desc_set_no_orp(&ed, 0);
369 qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0);
371 time_start = get_timer(0);
373 while (get_timer(time_start) < timeo) {
374 err = qbman_swp_enqueue(swp, &ed,
375 (const struct qbman_fd *)(&fd));
381 printf("error enqueueing Tx frame\n");
388 qbman_release_desc_clear(&releasedesc);
389 qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
390 time_start = get_timer(0);
392 /* Release buffer into the QBMAN */
393 err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1);
394 } while (get_timer(time_start) < timeo && err == -EBUSY);
397 printf("TX data: QBMAN buffer release fails\n");
402 static int ldpaa_get_dpmac_state(struct ldpaa_eth_priv *priv,
403 struct dpmac_link_state *state)
405 struct phy_device *phydev = NULL;
406 phy_interface_t enet_if;
407 int phy_num, phys_detected;
410 /* let's start off with maximum capabilities */
411 enet_if = wriop_get_enet_if(priv->dpmac_id);
413 case PHY_INTERFACE_MODE_XGMII:
414 state->rate = SPEED_10000;
417 state->rate = SPEED_1000;
424 state->options |= DPMAC_LINK_OPT_AUTONEG;
426 /* start the phy devices one by one and update the dpmac state */
427 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
428 phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
433 err = phy_startup(phydev);
435 printf("%s: Could not initialize\n", phydev->dev->name);
440 state->rate = min(state->rate, (uint32_t)phydev->speed);
442 state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
443 if (!phydev->autoneg)
444 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
446 /* break out of loop even if one phy is down */
453 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
464 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
466 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
467 struct dpmac_link_state dpmac_link_state = { 0 };
469 struct dpni_link_state link_state;
472 struct dpni_queue d_queue;
474 if (net_dev->state == ETH_STATE_ACTIVE)
477 if (get_mc_boot_status() != 0) {
478 printf("ERROR (MC is not booted)\n");
482 if (get_dpl_apply_status() == 0) {
483 printf("ERROR (DPL is deployed. No device available)\n");
487 /* DPMAC initialization */
488 err = ldpaa_dpmac_setup(priv);
490 goto err_dpmac_setup;
492 err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
496 /* DPMAC binding DPNI */
497 err = ldpaa_dpmac_bind(priv);
501 /* DPNI initialization */
502 err = ldpaa_dpni_setup(priv);
506 err = ldpaa_dpbp_setup();
510 /* DPNI binding DPBP */
511 err = ldpaa_dpni_bind(priv);
515 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
516 dflt_dpni->dpni_handle, net_dev->enetaddr);
518 printf("dpni_add_mac_addr() failed\n");
522 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
524 printf("dpni_enable() failed\n");
528 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
529 priv->dpmac_handle, &dpmac_link_state);
531 printf("dpmac_set_link_state() failed\n");
536 printf("DPMAC link status: %d - ", dpmac_link_state.up);
537 dpmac_link_state.up == 0 ? printf("down\n") :
538 dpmac_link_state.up == 1 ? printf("up\n") : printf("error state\n");
540 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
541 dflt_dpni->dpni_handle, &link_state);
543 printf("dpni_get_link_state() failed\n");
547 printf("DPNI link status: %d - ", link_state.up);
548 link_state.up == 0 ? printf("down\n") :
549 link_state.up == 1 ? printf("up\n") : printf("error state\n");
552 memset(&d_queue, 0, sizeof(struct dpni_queue));
553 err = dpni_get_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
554 dflt_dpni->dpni_handle, DPNI_QUEUE_RX,
557 printf("dpni_get_queue failed\n");
561 priv->rx_dflt_fqid = d_queue.fqid;
563 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
566 printf("dpni_get_qdid() failed\n");
570 return dpmac_link_state.up;
574 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
578 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
581 dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
582 dpmac_destroy(dflt_mc_io,
584 MC_CMD_NO_FLAGS, priv->dpmac_id);
589 static void ldpaa_eth_stop(struct eth_device *net_dev)
591 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
593 struct phy_device *phydev = NULL;
596 if ((net_dev->state == ETH_STATE_PASSIVE) ||
597 (net_dev->state == ETH_STATE_INIT))
601 ldpaa_eth_get_dpni_counter();
602 ldpaa_eth_get_dpmac_counter(net_dev);
605 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
606 dflt_dprc_handle, &dpmac_endpoint);
608 printf("dprc_disconnect() failed dpmac_endpoint\n");
610 err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
612 printf("dpmac_close() failed\n");
614 err = dpmac_destroy(dflt_mc_io,
619 printf("dpmac_destroy() failed\n");
621 /* Stop Tx and Rx traffic */
622 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
624 printf("dpni_disable() failed\n");
627 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
628 phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
630 phy_shutdown(phydev);
634 /* Free DPBP handle and reset. */
637 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
639 printf("dpni_reset() failed\n");
641 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
643 printf("dpni_close() failed\n");
646 static void ldpaa_dpbp_drain_cnt(int count)
648 uint64_t buf_array[7];
655 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
656 dflt_dpbp->dpbp_attr.bpid,
659 printf("qbman_swp_acquire() failed\n");
662 for (i = 0; i < ret; i++) {
663 addr = (void *)buf_array[i];
664 debug("Free: buffer addr =0x%p\n", addr);
670 static void ldpaa_dpbp_drain(void)
673 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
674 ldpaa_dpbp_drain_cnt(7);
677 static int ldpaa_bp_add_7(uint16_t bpid)
679 uint64_t buf_array[7];
682 struct qbman_release_desc rd;
684 for (i = 0; i < 7; i++) {
685 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
687 printf("addr allocation failed\n");
690 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
691 flush_dcache_range((u64)addr,
692 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
694 buf_array[i] = (uint64_t)addr;
695 debug("Release: buffer addr =0x%p\n", addr);
699 /* In case the portal is busy, retry until successful.
700 * This function is guaranteed to succeed in a reasonable amount
706 qbman_release_desc_clear(&rd);
707 qbman_release_desc_set_bpid(&rd, bpid);
708 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
719 static int ldpaa_dpbp_seed(uint16_t bpid)
724 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
725 count = ldpaa_bp_add_7(bpid);
727 printf("Buffer Seed= %d\n", count);
733 static int ldpaa_dpbp_setup(void)
737 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
738 &dflt_dpbp->dpbp_handle);
740 printf("dpbp_open() failed\n");
744 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
746 printf("dpbp_enable() failed\n");
750 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
751 dflt_dpbp->dpbp_handle,
752 &dflt_dpbp->dpbp_attr);
754 printf("dpbp_get_attributes() failed\n");
758 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
761 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
762 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
770 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
772 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
777 static void ldpaa_dpbp_free(void)
780 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
781 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
782 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
785 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
786 struct ldpaa_eth_priv *priv)
789 uint16_t major_ver, minor_ver;
791 error = dpmac_get_api_version(dflt_mc_io, 0,
794 if ((major_ver < DPMAC_VER_MAJOR) ||
795 (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) {
796 printf("DPMAC version mismatch found %u.%u,",
797 major_ver, minor_ver);
798 printf("supported version is %u.%u\n",
799 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
806 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
809 struct dpmac_cfg dpmac_cfg;
811 dpmac_cfg.mac_id = priv->dpmac_id;
813 err = dpmac_create(dflt_mc_io,
815 MC_CMD_NO_FLAGS, &dpmac_cfg,
818 printf("dpmac_create() failed\n");
820 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
822 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
823 goto err_version_check;
826 err = dpmac_open(dflt_mc_io,
829 &priv->dpmac_handle);
831 printf("dpmac_open() failed: %d\n", err);
839 dpmac_destroy(dflt_mc_io,
841 MC_CMD_NO_FLAGS, priv->dpmac_id);
846 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
849 struct dprc_connection_cfg dprc_connection_cfg = {
850 /* If both rates are zero the connection */
851 /* will be configured in "best effort" mode. */
857 struct dprc_endpoint dbg_endpoint;
861 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
862 strcpy(dpmac_endpoint.type, "dpmac");
863 dpmac_endpoint.id = priv->dpmac_id;
865 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
866 strcpy(dpni_endpoint.type, "dpni");
867 dpni_endpoint.id = dflt_dpni->dpni_id;
869 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
873 &dprc_connection_cfg);
875 printf("dprc_connect() failed\n");
878 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
879 dflt_dprc_handle, &dpni_endpoint,
880 &dbg_endpoint, &state);
881 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
882 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
883 printf("%s, DPMAC State= %d\n", __func__, state);
885 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
886 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
887 dflt_dprc_handle, &dpmac_endpoint,
888 &dbg_endpoint, &state);
889 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
890 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
891 printf("%s, DPNI State= %d\n", __func__, state);
896 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
900 /* and get a handle for the DPNI this interface is associate with */
901 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
902 &dflt_dpni->dpni_handle);
904 printf("dpni_open() failed\n");
907 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
908 dflt_dpni->dpni_handle,
909 &dflt_dpni->dpni_attrs);
911 printf("dpni_get_attributes() failed (err=%d)\n", err);
915 /* Configure our buffers' layout */
916 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
917 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
918 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
919 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
920 dflt_dpni->buf_layout.pass_parser_result = true;
921 dflt_dpni->buf_layout.pass_frame_status = true;
922 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
923 /* HW erratum mandates data alignment in multiples of 256 */
924 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
927 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
928 dflt_dpni->dpni_handle,
929 &dflt_dpni->buf_layout, DPNI_QUEUE_RX);
931 printf("dpni_set_buffer_layout() failed");
936 /* remove Rx-only options */
937 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
938 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
939 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
940 dflt_dpni->dpni_handle,
941 &dflt_dpni->buf_layout, DPNI_QUEUE_TX);
943 printf("dpni_set_buffer_layout() failed");
947 /* ... tx-confirm. */
948 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
949 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
950 dflt_dpni->dpni_handle,
951 &dflt_dpni->buf_layout,
952 DPNI_QUEUE_TX_CONFIRM);
954 printf("dpni_set_buffer_layout() failed");
958 /* Now that we've set our tx buffer layout, retrieve the minimum
959 * required tx data offset.
961 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
962 dflt_dpni->dpni_handle,
963 &priv->tx_data_offset);
965 printf("dpni_get_tx_data_offset() failed\n");
966 goto err_data_offset;
969 /* Warn in case TX data offset is not multiple of 64 bytes. */
970 WARN_ON(priv->tx_data_offset % 64);
972 /* Accomodate SWA space. */
973 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
974 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
981 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
986 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
988 struct dpni_pools_cfg pools_params;
989 struct dpni_queue tx_queue;
992 memset(&pools_params, 0, sizeof(pools_params));
993 pools_params.num_dpbp = 1;
994 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
995 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
996 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
997 dflt_dpni->dpni_handle, &pools_params);
999 printf("dpni_set_pools() failed\n");
1003 memset(&tx_queue, 0, sizeof(struct dpni_queue));
1005 err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
1006 dflt_dpni->dpni_handle,
1007 DPNI_QUEUE_TX, 0, 0, &tx_queue);
1010 printf("dpni_set_queue() failed\n");
1014 err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS,
1015 dflt_dpni->dpni_handle,
1018 printf("dpni_set_tx_confirmation_mode() failed\n");
1025 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
1026 phy_interface_t enet_if)
1029 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
1031 snprintf(net_dev->name, ETH_NAME_LEN, "DPMAC%d@%s", priv->dpmac_id,
1032 phy_interface_strings[enet_if]);
1034 net_dev->iobase = 0;
1035 net_dev->init = ldpaa_eth_open;
1036 net_dev->halt = ldpaa_eth_stop;
1037 net_dev->send = ldpaa_eth_tx;
1038 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
1040 #ifdef CONFIG_PHYLIB
1041 err = init_phy(net_dev);
1046 err = eth_register(net_dev);
1048 printf("eth_register() = %d\n", err);
1055 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
1057 struct eth_device *net_dev = NULL;
1058 struct ldpaa_eth_priv *priv = NULL;
1062 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
1064 printf("eth_device malloc() failed\n");
1067 memset(net_dev, 0, sizeof(struct eth_device));
1069 /* alloc the ldpaa ethernet private struct */
1070 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1072 printf("ldpaa_eth_priv malloc() failed\n");
1075 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1077 net_dev->priv = (void *)priv;
1078 priv->net_dev = (struct eth_device *)net_dev;
1079 priv->dpmac_id = dpmac_id;
1080 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1082 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1084 goto err_netdev_init;
1086 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1091 net_dev->priv = NULL;