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_eth_open(struct eth_device *net_dev, bd_t *bd)
390 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
391 struct dpmac_link_state dpmac_link_state = { 0 };
393 struct dpni_link_state link_state;
397 phy_interface_t enet_if;
398 struct dpni_queue d_queue;
399 struct phy_device *phydev = NULL;
401 if (net_dev->state == ETH_STATE_ACTIVE)
404 if (get_mc_boot_status() != 0) {
405 printf("ERROR (MC is not booted)\n");
409 if (get_dpl_apply_status() == 0) {
410 printf("ERROR (DPL is deployed. No device available)\n");
414 /* DPMAC initialization */
415 err = ldpaa_dpmac_setup(priv);
417 goto err_dpmac_setup;
420 phydev = wriop_get_phy_dev(priv->dpmac_id);
422 err = phy_startup(phydev);
424 printf("%s: Could not initialize\n",
430 phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
431 memset(phydev, 0, sizeof(struct phy_device));
432 wriop_set_phy_dev(priv->dpmac_id, phydev);
434 phydev->speed = SPEED_1000;
436 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 phydev = (struct phy_device *)
444 malloc(sizeof(struct phy_device));
445 memset(phydev, 0, sizeof(struct phy_device));
446 wriop_set_phy_dev(priv->dpmac_id, phydev);
448 phydev->speed = SPEED_10000;
450 phydev->duplex = DUPLEX_FULL;
454 printf("%s: No link.\n", phydev->dev->name);
459 /* DPMAC binding DPNI */
460 err = ldpaa_dpmac_bind(priv);
464 /* DPNI initialization */
465 err = ldpaa_dpni_setup(priv);
469 err = ldpaa_dpbp_setup();
473 /* DPNI binding DPBP */
474 err = ldpaa_dpni_bind(priv);
478 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
479 dflt_dpni->dpni_handle, net_dev->enetaddr);
481 printf("dpni_add_mac_addr() failed\n");
485 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
487 printf("dpni_enable() failed\n");
491 dpmac_link_state.rate = phydev->speed;
493 if (phydev->autoneg == AUTONEG_DISABLE)
494 dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
496 dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
498 if (phydev->duplex == DUPLEX_HALF)
499 dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
501 dpmac_link_state.up = phydev->link;
503 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
504 priv->dpmac_handle, &dpmac_link_state);
506 printf("dpmac_set_link_state() failed\n");
511 printf("DPMAC link status: %d - ", dpmac_link_state.up);
512 dpmac_link_state.up == 0 ? printf("down\n") :
513 dpmac_link_state.up == 1 ? printf("up\n") : printf("error state\n");
515 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
516 dflt_dpni->dpni_handle, &link_state);
518 printf("dpni_get_link_state() failed\n");
522 printf("DPNI link status: %d - ", link_state.up);
523 link_state.up == 0 ? printf("down\n") :
524 link_state.up == 1 ? printf("up\n") : printf("error state\n");
527 memset(&d_queue, 0, sizeof(struct dpni_queue));
528 err = dpni_get_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
529 dflt_dpni->dpni_handle, DPNI_QUEUE_RX,
532 printf("dpni_get_queue failed\n");
536 priv->rx_dflt_fqid = d_queue.fqid;
538 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
541 printf("dpni_get_qdid() failed\n");
549 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
553 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
556 dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
557 dpmac_destroy(dflt_mc_io,
559 MC_CMD_NO_FLAGS, priv->dpmac_id);
564 static void ldpaa_eth_stop(struct eth_device *net_dev)
566 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
569 struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
571 struct phy_device *phydev = NULL;
573 if ((net_dev->state == ETH_STATE_PASSIVE) ||
574 (net_dev->state == ETH_STATE_INIT))
578 ldpaa_eth_get_dpni_counter();
579 ldpaa_eth_get_dpmac_counter(net_dev);
582 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
583 dflt_dprc_handle, &dpmac_endpoint);
585 printf("dprc_disconnect() failed dpmac_endpoint\n");
587 err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
589 printf("dpmac_close() failed\n");
591 err = dpmac_destroy(dflt_mc_io,
596 printf("dpmac_destroy() failed\n");
598 /* Stop Tx and Rx traffic */
599 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
601 printf("dpni_disable() failed\n");
604 phydev = wriop_get_phy_dev(priv->dpmac_id);
606 phy_shutdown(phydev);
609 wriop_set_phy_dev(priv->dpmac_id, NULL);
613 /* Free DPBP handle and reset. */
616 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
618 printf("dpni_reset() failed\n");
620 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
622 printf("dpni_close() failed\n");
625 static void ldpaa_dpbp_drain_cnt(int count)
627 uint64_t buf_array[7];
634 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
635 dflt_dpbp->dpbp_attr.bpid,
638 printf("qbman_swp_acquire() failed\n");
641 for (i = 0; i < ret; i++) {
642 addr = (void *)buf_array[i];
643 debug("Free: buffer addr =0x%p\n", addr);
649 static void ldpaa_dpbp_drain(void)
652 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
653 ldpaa_dpbp_drain_cnt(7);
656 static int ldpaa_bp_add_7(uint16_t bpid)
658 uint64_t buf_array[7];
661 struct qbman_release_desc rd;
663 for (i = 0; i < 7; i++) {
664 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
666 printf("addr allocation failed\n");
669 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
670 flush_dcache_range((u64)addr,
671 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
673 buf_array[i] = (uint64_t)addr;
674 debug("Release: buffer addr =0x%p\n", addr);
678 /* In case the portal is busy, retry until successful.
679 * This function is guaranteed to succeed in a reasonable amount
685 qbman_release_desc_clear(&rd);
686 qbman_release_desc_set_bpid(&rd, bpid);
687 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
698 static int ldpaa_dpbp_seed(uint16_t bpid)
703 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
704 count = ldpaa_bp_add_7(bpid);
706 printf("Buffer Seed= %d\n", count);
712 static int ldpaa_dpbp_setup(void)
716 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
717 &dflt_dpbp->dpbp_handle);
719 printf("dpbp_open() failed\n");
723 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
725 printf("dpbp_enable() failed\n");
729 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
730 dflt_dpbp->dpbp_handle,
731 &dflt_dpbp->dpbp_attr);
733 printf("dpbp_get_attributes() failed\n");
737 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
740 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
741 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
749 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
751 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
756 static void ldpaa_dpbp_free(void)
759 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
760 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
761 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
764 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
765 struct ldpaa_eth_priv *priv)
768 uint16_t major_ver, minor_ver;
770 error = dpmac_get_api_version(dflt_mc_io, 0,
773 if ((major_ver < DPMAC_VER_MAJOR) ||
774 (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) {
775 printf("DPMAC version mismatch found %u.%u,",
776 major_ver, minor_ver);
777 printf("supported version is %u.%u\n",
778 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
785 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
788 struct dpmac_cfg dpmac_cfg;
790 dpmac_cfg.mac_id = priv->dpmac_id;
792 err = dpmac_create(dflt_mc_io,
794 MC_CMD_NO_FLAGS, &dpmac_cfg,
797 printf("dpmac_create() failed\n");
799 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
801 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
802 goto err_version_check;
805 err = dpmac_open(dflt_mc_io,
808 &priv->dpmac_handle);
810 printf("dpmac_open() failed: %d\n", err);
818 dpmac_destroy(dflt_mc_io,
820 MC_CMD_NO_FLAGS, priv->dpmac_id);
825 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
828 struct dprc_connection_cfg dprc_connection_cfg = {
829 /* If both rates are zero the connection */
830 /* will be configured in "best effort" mode. */
836 struct dprc_endpoint dbg_endpoint;
840 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
841 strcpy(dpmac_endpoint.type, "dpmac");
842 dpmac_endpoint.id = priv->dpmac_id;
844 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
845 strcpy(dpni_endpoint.type, "dpni");
846 dpni_endpoint.id = dflt_dpni->dpni_id;
848 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
852 &dprc_connection_cfg);
854 printf("dprc_connect() failed\n");
857 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
858 dflt_dprc_handle, &dpni_endpoint,
859 &dbg_endpoint, &state);
860 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
861 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
862 printf("%s, DPMAC State= %d\n", __func__, state);
864 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
865 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
866 dflt_dprc_handle, &dpmac_endpoint,
867 &dbg_endpoint, &state);
868 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
869 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
870 printf("%s, DPNI State= %d\n", __func__, state);
875 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
879 /* and get a handle for the DPNI this interface is associate with */
880 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
881 &dflt_dpni->dpni_handle);
883 printf("dpni_open() failed\n");
886 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
887 dflt_dpni->dpni_handle,
888 &dflt_dpni->dpni_attrs);
890 printf("dpni_get_attributes() failed (err=%d)\n", err);
894 /* Configure our buffers' layout */
895 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
896 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
897 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
898 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
899 dflt_dpni->buf_layout.pass_parser_result = true;
900 dflt_dpni->buf_layout.pass_frame_status = true;
901 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
902 /* HW erratum mandates data alignment in multiples of 256 */
903 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
906 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
907 dflt_dpni->dpni_handle,
908 &dflt_dpni->buf_layout, DPNI_QUEUE_RX);
910 printf("dpni_set_buffer_layout() failed");
915 /* remove Rx-only options */
916 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
917 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
918 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
919 dflt_dpni->dpni_handle,
920 &dflt_dpni->buf_layout, DPNI_QUEUE_TX);
922 printf("dpni_set_buffer_layout() failed");
926 /* ... tx-confirm. */
927 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
928 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
929 dflt_dpni->dpni_handle,
930 &dflt_dpni->buf_layout,
931 DPNI_QUEUE_TX_CONFIRM);
933 printf("dpni_set_buffer_layout() failed");
937 /* Now that we've set our tx buffer layout, retrieve the minimum
938 * required tx data offset.
940 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
941 dflt_dpni->dpni_handle,
942 &priv->tx_data_offset);
944 printf("dpni_get_tx_data_offset() failed\n");
945 goto err_data_offset;
948 /* Warn in case TX data offset is not multiple of 64 bytes. */
949 WARN_ON(priv->tx_data_offset % 64);
951 /* Accomodate SWA space. */
952 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
953 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
960 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
965 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
967 struct dpni_pools_cfg pools_params;
968 struct dpni_queue tx_queue;
971 memset(&pools_params, 0, sizeof(pools_params));
972 pools_params.num_dpbp = 1;
973 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
974 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
975 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
976 dflt_dpni->dpni_handle, &pools_params);
978 printf("dpni_set_pools() failed\n");
982 memset(&tx_queue, 0, sizeof(struct dpni_queue));
984 err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
985 dflt_dpni->dpni_handle,
986 DPNI_QUEUE_TX, 0, 0, &tx_queue);
989 printf("dpni_set_queue() failed\n");
993 err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS,
994 dflt_dpni->dpni_handle,
997 printf("dpni_set_tx_confirmation_mode() failed\n");
1004 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
1005 phy_interface_t enet_if)
1008 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
1010 snprintf(net_dev->name, ETH_NAME_LEN, "DPMAC%d@%s", priv->dpmac_id,
1011 phy_interface_strings[enet_if]);
1013 net_dev->iobase = 0;
1014 net_dev->init = ldpaa_eth_open;
1015 net_dev->halt = ldpaa_eth_stop;
1016 net_dev->send = ldpaa_eth_tx;
1017 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
1019 #ifdef CONFIG_PHYLIB
1020 err = init_phy(net_dev);
1025 err = eth_register(net_dev);
1027 printf("eth_register() = %d\n", err);
1034 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
1036 struct eth_device *net_dev = NULL;
1037 struct ldpaa_eth_priv *priv = NULL;
1041 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
1043 printf("eth_device malloc() failed\n");
1046 memset(net_dev, 0, sizeof(struct eth_device));
1048 /* alloc the ldpaa ethernet private struct */
1049 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1051 printf("ldpaa_eth_priv malloc() failed\n");
1054 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1056 net_dev->priv = (void *)priv;
1057 priv->net_dev = (struct eth_device *)net_dev;
1058 priv->dpmac_id = dpmac_id;
1059 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1061 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1063 goto err_netdev_init;
1065 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1070 net_dev->priv = NULL;