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 phy_interface_t enet_if;
408 struct phy_device *phydev = NULL;
412 /* let's start off with maximum capabilities */
413 enet_if = wriop_get_enet_if(priv->dpmac_id);
415 case PHY_INTERFACE_MODE_XGMII:
416 state->rate = SPEED_10000;
419 state->rate = SPEED_1000;
426 state->options |= DPMAC_LINK_OPT_AUTONEG;
428 /* start the phy devices one by one and update the dpmac state */
429 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
430 phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
435 err = phy_startup(phydev);
437 printf("%s: Could not initialize\n", phydev->dev->name);
442 state->rate = min(state->rate, (uint32_t)phydev->speed);
444 state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
445 if (!phydev->autoneg)
446 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
448 /* break out of loop even if one phy is down */
455 state->options &= ~DPMAC_LINK_OPT_AUTONEG;
466 static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
468 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
469 struct dpmac_link_state dpmac_link_state = { 0 };
471 struct dpni_link_state link_state;
474 struct dpni_queue d_queue;
476 if (net_dev->state == ETH_STATE_ACTIVE)
479 if (get_mc_boot_status() != 0) {
480 printf("ERROR (MC is not booted)\n");
484 if (get_dpl_apply_status() == 0) {
485 printf("ERROR (DPL is deployed. No device available)\n");
489 /* DPMAC initialization */
490 err = ldpaa_dpmac_setup(priv);
492 goto err_dpmac_setup;
494 err = ldpaa_get_dpmac_state(priv, &dpmac_link_state);
498 /* DPMAC binding DPNI */
499 err = ldpaa_dpmac_bind(priv);
503 /* DPNI initialization */
504 err = ldpaa_dpni_setup(priv);
508 err = ldpaa_dpbp_setup();
512 /* DPNI binding DPBP */
513 err = ldpaa_dpni_bind(priv);
517 err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
518 dflt_dpni->dpni_handle, net_dev->enetaddr);
520 printf("dpni_add_mac_addr() failed\n");
524 err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
526 printf("dpni_enable() failed\n");
530 err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
531 priv->dpmac_handle, &dpmac_link_state);
533 printf("dpmac_set_link_state() failed\n");
538 printf("DPMAC link status: %d - ", dpmac_link_state.up);
539 dpmac_link_state.up == 0 ? printf("down\n") :
540 dpmac_link_state.up == 1 ? printf("up\n") : printf("error state\n");
542 err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
543 dflt_dpni->dpni_handle, &link_state);
545 printf("dpni_get_link_state() failed\n");
549 printf("DPNI link status: %d - ", link_state.up);
550 link_state.up == 0 ? printf("down\n") :
551 link_state.up == 1 ? printf("up\n") : printf("error state\n");
554 memset(&d_queue, 0, sizeof(struct dpni_queue));
555 err = dpni_get_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
556 dflt_dpni->dpni_handle, DPNI_QUEUE_RX,
559 printf("dpni_get_queue failed\n");
563 priv->rx_dflt_fqid = d_queue.fqid;
565 err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
568 printf("dpni_get_qdid() failed\n");
572 return dpmac_link_state.up;
576 dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
580 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
583 dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
584 dpmac_destroy(dflt_mc_io,
586 MC_CMD_NO_FLAGS, priv->dpmac_id);
591 static void ldpaa_eth_stop(struct eth_device *net_dev)
593 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
596 struct phy_device *phydev = NULL;
600 if ((net_dev->state == ETH_STATE_PASSIVE) ||
601 (net_dev->state == ETH_STATE_INIT))
605 ldpaa_eth_get_dpni_counter();
606 ldpaa_eth_get_dpmac_counter(net_dev);
609 err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
610 dflt_dprc_handle, &dpmac_endpoint);
612 printf("dprc_disconnect() failed dpmac_endpoint\n");
614 err = dpmac_close(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
616 printf("dpmac_close() failed\n");
618 err = dpmac_destroy(dflt_mc_io,
623 printf("dpmac_destroy() failed\n");
625 /* Stop Tx and Rx traffic */
626 err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
628 printf("dpni_disable() failed\n");
631 for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
632 phydev = wriop_get_phy_dev(priv->dpmac_id, phy_num);
634 phy_shutdown(phydev);
638 /* Free DPBP handle and reset. */
641 dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
643 printf("dpni_reset() failed\n");
645 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
647 printf("dpni_close() failed\n");
650 static void ldpaa_dpbp_drain_cnt(int count)
652 uint64_t buf_array[7];
659 ret = qbman_swp_acquire(dflt_dpio->sw_portal,
660 dflt_dpbp->dpbp_attr.bpid,
663 printf("qbman_swp_acquire() failed\n");
666 for (i = 0; i < ret; i++) {
667 addr = (void *)buf_array[i];
668 debug("Free: buffer addr =0x%p\n", addr);
674 static void ldpaa_dpbp_drain(void)
677 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
678 ldpaa_dpbp_drain_cnt(7);
681 static int ldpaa_bp_add_7(uint16_t bpid)
683 uint64_t buf_array[7];
686 struct qbman_release_desc rd;
688 for (i = 0; i < 7; i++) {
689 addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
691 printf("addr allocation failed\n");
694 memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
695 flush_dcache_range((u64)addr,
696 (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
698 buf_array[i] = (uint64_t)addr;
699 debug("Release: buffer addr =0x%p\n", addr);
703 /* In case the portal is busy, retry until successful.
704 * This function is guaranteed to succeed in a reasonable amount
710 qbman_release_desc_clear(&rd);
711 qbman_release_desc_set_bpid(&rd, bpid);
712 } while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
723 static int ldpaa_dpbp_seed(uint16_t bpid)
728 for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
729 count = ldpaa_bp_add_7(bpid);
731 printf("Buffer Seed= %d\n", count);
737 static int ldpaa_dpbp_setup(void)
741 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
742 &dflt_dpbp->dpbp_handle);
744 printf("dpbp_open() failed\n");
748 err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
750 printf("dpbp_enable() failed\n");
754 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
755 dflt_dpbp->dpbp_handle,
756 &dflt_dpbp->dpbp_attr);
758 printf("dpbp_get_attributes() failed\n");
762 err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
765 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
766 dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
774 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
776 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
781 static void ldpaa_dpbp_free(void)
784 dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
785 dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
786 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
789 static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
790 struct ldpaa_eth_priv *priv)
793 uint16_t major_ver, minor_ver;
795 error = dpmac_get_api_version(dflt_mc_io, 0,
798 if ((major_ver < DPMAC_VER_MAJOR) ||
799 (major_ver == DPMAC_VER_MAJOR && minor_ver < DPMAC_VER_MINOR)) {
800 printf("DPMAC version mismatch found %u.%u,",
801 major_ver, minor_ver);
802 printf("supported version is %u.%u\n",
803 DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
810 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
813 struct dpmac_cfg dpmac_cfg;
815 dpmac_cfg.mac_id = priv->dpmac_id;
817 err = dpmac_create(dflt_mc_io,
819 MC_CMD_NO_FLAGS, &dpmac_cfg,
822 printf("dpmac_create() failed\n");
824 err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
826 printf("ldpaa_dpmac_version_check() failed: %d\n", err);
827 goto err_version_check;
830 err = dpmac_open(dflt_mc_io,
833 &priv->dpmac_handle);
835 printf("dpmac_open() failed: %d\n", err);
843 dpmac_destroy(dflt_mc_io,
845 MC_CMD_NO_FLAGS, priv->dpmac_id);
850 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
853 struct dprc_connection_cfg dprc_connection_cfg = {
854 /* If both rates are zero the connection */
855 /* will be configured in "best effort" mode. */
861 struct dprc_endpoint dbg_endpoint;
865 memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
866 strcpy(dpmac_endpoint.type, "dpmac");
867 dpmac_endpoint.id = priv->dpmac_id;
869 memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
870 strcpy(dpni_endpoint.type, "dpni");
871 dpni_endpoint.id = dflt_dpni->dpni_id;
873 err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
877 &dprc_connection_cfg);
879 printf("dprc_connect() failed\n");
882 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
883 dflt_dprc_handle, &dpni_endpoint,
884 &dbg_endpoint, &state);
885 printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
886 printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
887 printf("%s, DPMAC State= %d\n", __func__, state);
889 memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
890 err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
891 dflt_dprc_handle, &dpmac_endpoint,
892 &dbg_endpoint, &state);
893 printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
894 printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
895 printf("%s, DPNI State= %d\n", __func__, state);
900 static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
904 /* and get a handle for the DPNI this interface is associate with */
905 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
906 &dflt_dpni->dpni_handle);
908 printf("dpni_open() failed\n");
911 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
912 dflt_dpni->dpni_handle,
913 &dflt_dpni->dpni_attrs);
915 printf("dpni_get_attributes() failed (err=%d)\n", err);
919 /* Configure our buffers' layout */
920 dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
921 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
922 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
923 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
924 dflt_dpni->buf_layout.pass_parser_result = true;
925 dflt_dpni->buf_layout.pass_frame_status = true;
926 dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
927 /* HW erratum mandates data alignment in multiples of 256 */
928 dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
931 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
932 dflt_dpni->dpni_handle,
933 &dflt_dpni->buf_layout, DPNI_QUEUE_RX);
935 printf("dpni_set_buffer_layout() failed");
940 /* remove Rx-only options */
941 dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
942 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
943 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
944 dflt_dpni->dpni_handle,
945 &dflt_dpni->buf_layout, DPNI_QUEUE_TX);
947 printf("dpni_set_buffer_layout() failed");
951 /* ... tx-confirm. */
952 dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
953 err = dpni_set_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
954 dflt_dpni->dpni_handle,
955 &dflt_dpni->buf_layout,
956 DPNI_QUEUE_TX_CONFIRM);
958 printf("dpni_set_buffer_layout() failed");
962 /* Now that we've set our tx buffer layout, retrieve the minimum
963 * required tx data offset.
965 err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
966 dflt_dpni->dpni_handle,
967 &priv->tx_data_offset);
969 printf("dpni_get_tx_data_offset() failed\n");
970 goto err_data_offset;
973 /* Warn in case TX data offset is not multiple of 64 bytes. */
974 WARN_ON(priv->tx_data_offset % 64);
976 /* Accomodate SWA space. */
977 priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
978 debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
985 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
990 static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
992 struct dpni_pools_cfg pools_params;
993 struct dpni_queue tx_queue;
996 memset(&pools_params, 0, sizeof(pools_params));
997 pools_params.num_dpbp = 1;
998 pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
999 pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
1000 err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
1001 dflt_dpni->dpni_handle, &pools_params);
1003 printf("dpni_set_pools() failed\n");
1007 memset(&tx_queue, 0, sizeof(struct dpni_queue));
1009 err = dpni_set_queue(dflt_mc_io, MC_CMD_NO_FLAGS,
1010 dflt_dpni->dpni_handle,
1011 DPNI_QUEUE_TX, 0, 0, &tx_queue);
1014 printf("dpni_set_queue() failed\n");
1018 err = dpni_set_tx_confirmation_mode(dflt_mc_io, MC_CMD_NO_FLAGS,
1019 dflt_dpni->dpni_handle,
1022 printf("dpni_set_tx_confirmation_mode() failed\n");
1029 static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
1030 phy_interface_t enet_if)
1033 struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
1035 snprintf(net_dev->name, ETH_NAME_LEN, "DPMAC%d@%s", priv->dpmac_id,
1036 phy_interface_strings[enet_if]);
1038 net_dev->iobase = 0;
1039 net_dev->init = ldpaa_eth_open;
1040 net_dev->halt = ldpaa_eth_stop;
1041 net_dev->send = ldpaa_eth_tx;
1042 net_dev->recv = ldpaa_eth_pull_dequeue_rx;
1044 #ifdef CONFIG_PHYLIB
1045 err = init_phy(net_dev);
1050 err = eth_register(net_dev);
1052 printf("eth_register() = %d\n", err);
1059 int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
1061 struct eth_device *net_dev = NULL;
1062 struct ldpaa_eth_priv *priv = NULL;
1066 net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
1068 printf("eth_device malloc() failed\n");
1071 memset(net_dev, 0, sizeof(struct eth_device));
1073 /* alloc the ldpaa ethernet private struct */
1074 priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
1076 printf("ldpaa_eth_priv malloc() failed\n");
1079 memset(priv, 0, sizeof(struct ldpaa_eth_priv));
1081 net_dev->priv = (void *)priv;
1082 priv->net_dev = (struct eth_device *)net_dev;
1083 priv->dpmac_id = dpmac_id;
1084 debug("%s dpmac_id=%d\n", __func__, dpmac_id);
1086 err = ldpaa_eth_netdev_init(net_dev, enet_if);
1088 goto err_netdev_init;
1090 debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
1095 net_dev->priv = NULL;