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
;
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
);
46 #define DPNI_STATS_PER_PAGE 6
48 static const char *dpni_statistics
[][DPNI_STATS_PER_PAGE
] = {
50 "DPNI_CNT_ING_ALL_FRAMES",
51 "DPNI_CNT_ING_ALL_BYTES",
52 "DPNI_CNT_ING_MCAST_FRAMES",
53 "DPNI_CNT_ING_MCAST_BYTES",
54 "DPNI_CNT_ING_BCAST_FRAMES",
55 "DPNI_CNT_ING_BCAST_BYTES",
57 "DPNI_CNT_EGR_ALL_FRAMES",
58 "DPNI_CNT_EGR_ALL_BYTES",
59 "DPNI_CNT_EGR_MCAST_FRAMES",
60 "DPNI_CNT_EGR_MCAST_BYTES",
61 "DPNI_CNT_EGR_BCAST_FRAMES",
62 "DPNI_CNT_EGR_BCAST_BYTES",
64 "DPNI_CNT_ING_FILTERED_FRAMES",
65 "DPNI_CNT_ING_DISCARDED_FRAMES",
66 "DPNI_CNT_ING_NOBUFFER_DISCARDS",
67 "DPNI_CNT_EGR_DISCARDED_FRAMES",
68 "DPNI_CNT_EGR_CNF_FRAMES",
73 static void print_dpni_stats(const char *strings
[],
74 struct dpni_statistics dpni_stats
)
79 stat
= (uint64_t *)&dpni_stats
;
80 for (i
= 0; i
< DPNI_STATS_PER_PAGE
; i
++) {
81 if (strcmp(strings
[i
], "\0") == 0)
83 printf("%s= %llu\n", strings
[i
], *stat
);
88 static void ldpaa_eth_get_dpni_counter(void)
91 unsigned int page
= 0;
92 struct dpni_statistics dpni_stats
;
94 printf("DPNI counters ..\n");
95 for (page
= 0; page
< 3; page
++) {
96 err
= dpni_get_statistics(dflt_mc_io
, MC_CMD_NO_FLAGS
,
97 dflt_dpni
->dpni_handle
, page
,
100 printf("dpni_get_statistics: failed:");
101 printf("%d for page[%d]\n", err
, page
);
104 print_dpni_stats(dpni_statistics
[page
], dpni_stats
);
108 static void ldpaa_eth_get_dpmac_counter(struct eth_device
*net_dev
)
110 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)net_dev
->priv
;
114 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
119 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
122 printf("\nDPMAC counters ..\n");
123 printf("DPMAC_CNT_ING_BYTE=%lld\n", value
);
125 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
127 DPMAC_CNT_ING_FRAME_DISCARD
,
130 printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
133 printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value
);
135 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
137 DPMAC_CNT_ING_ALIGN_ERR
,
140 printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
143 printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value
);
145 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
150 printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
153 printf("DPMAC_CNT_ING_BYTE=%lld\n", value
);
155 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
157 DPMAC_CNT_ING_ERR_FRAME
,
160 printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
163 printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value
);
165 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
170 printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
173 printf("DPMAC_CNT_EGR_BYTE =%lld\n", value
);
175 err
= dpmac_get_counter(dflt_mc_io
, MC_CMD_NO_FLAGS
,
177 DPMAC_CNT_EGR_ERR_FRAME
,
180 printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
183 printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value
);
187 static void ldpaa_eth_rx(struct ldpaa_eth_priv
*priv
,
188 const struct dpaa_fd
*fd
)
193 struct ldpaa_fas
*fas
;
194 uint32_t status
, err
;
195 u32 timeo
= (CONFIG_SYS_HZ
* 2) / 1000;
197 struct qbman_release_desc releasedesc
;
198 struct qbman_swp
*swp
= dflt_dpio
->sw_portal
;
200 fd_addr
= ldpaa_fd_get_addr(fd
);
201 fd_offset
= ldpaa_fd_get_offset(fd
);
202 fd_length
= ldpaa_fd_get_len(fd
);
204 debug("Rx frame:data addr=0x%p size=0x%x\n", (u64
*)fd_addr
, fd_length
);
206 if (fd
->simple
.frc
& LDPAA_FD_FRC_FASV
) {
207 /* Read the frame annotation status word and check for errors */
208 fas
= (struct ldpaa_fas
*)
209 ((uint8_t *)(fd_addr
) +
210 dflt_dpni
->buf_layout
.private_data_size
);
211 status
= le32_to_cpu(fas
->status
);
212 if (status
& LDPAA_ETH_RX_ERR_MASK
) {
213 printf("Rx frame error(s): 0x%08x\n",
214 status
& LDPAA_ETH_RX_ERR_MASK
);
216 } else if (status
& LDPAA_ETH_RX_UNSUPP_MASK
) {
217 printf("Unsupported feature in bitmask: 0x%08x\n",
218 status
& LDPAA_ETH_RX_UNSUPP_MASK
);
223 debug("Rx frame: To Upper layer\n");
224 net_process_received_packet((uint8_t *)(fd_addr
) + fd_offset
,
228 flush_dcache_range(fd_addr
, fd_addr
+ LDPAA_ETH_RX_BUFFER_SIZE
);
229 qbman_release_desc_clear(&releasedesc
);
230 qbman_release_desc_set_bpid(&releasedesc
, dflt_dpbp
->dpbp_attr
.bpid
);
231 time_start
= get_timer(0);
233 /* Release buffer into the QBMAN */
234 err
= qbman_swp_release(swp
, &releasedesc
, &fd_addr
, 1);
235 } while (get_timer(time_start
) < timeo
&& err
== -EBUSY
);
238 printf("Rx frame: QBMAN buffer release fails\n");
243 static int ldpaa_eth_pull_dequeue_rx(struct eth_device
*dev
)
245 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)dev
->priv
;
246 const struct ldpaa_dq
*dq
;
247 const struct dpaa_fd
*fd
;
248 int i
= 5, err
= 0, status
;
249 u32 timeo
= (CONFIG_SYS_HZ
* 2) / 1000;
251 static struct qbman_pull_desc pulldesc
;
252 struct qbman_swp
*swp
= dflt_dpio
->sw_portal
;
255 qbman_pull_desc_clear(&pulldesc
);
256 qbman_pull_desc_set_numframes(&pulldesc
, 1);
257 qbman_pull_desc_set_fq(&pulldesc
, priv
->rx_dflt_fqid
);
259 err
= qbman_swp_pull(swp
, &pulldesc
);
261 printf("Dequeue frames error:0x%08x\n", err
);
265 time_start
= get_timer(0);
268 dq
= qbman_swp_dqrr_next(swp
);
269 } while (get_timer(time_start
) < timeo
&& !dq
);
272 /* Check for valid frame. If not sent a consume
273 * confirmation to QBMAN otherwise give it to NADK
274 * application and then send consume confirmation to
277 status
= (uint8_t)ldpaa_dq_flags(dq
);
278 if ((status
& LDPAA_DQ_STAT_VALIDFRAME
) == 0) {
279 debug("Dequeue RX frames:");
280 debug("No frame delivered\n");
282 qbman_swp_dqrr_consume(swp
, dq
);
286 fd
= ldpaa_dq_fd(dq
);
288 /* Obtain FD and process it */
289 ldpaa_eth_rx(priv
, fd
);
290 qbman_swp_dqrr_consume(swp
, dq
);
294 debug("No DQRR entries\n");
302 static int ldpaa_eth_tx(struct eth_device
*net_dev
, void *buf
, int len
)
304 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)net_dev
->priv
;
307 int data_offset
, err
;
308 u32 timeo
= (CONFIG_SYS_HZ
* 10) / 1000;
310 struct qbman_swp
*swp
= dflt_dpio
->sw_portal
;
311 struct qbman_eq_desc ed
;
312 struct qbman_release_desc releasedesc
;
314 /* Setup the FD fields */
315 memset(&fd
, 0, sizeof(fd
));
317 data_offset
= priv
->tx_data_offset
;
320 err
= qbman_swp_acquire(dflt_dpio
->sw_portal
,
321 dflt_dpbp
->dpbp_attr
.bpid
,
323 } while (err
== -EBUSY
);
326 printf("qbman_swp_acquire() failed\n");
330 debug("TX data: malloc buffer start=0x%p\n", (u64
*)buffer_start
);
332 memcpy(((uint8_t *)(buffer_start
) + data_offset
), buf
, len
);
334 flush_dcache_range(buffer_start
, buffer_start
+
335 LDPAA_ETH_RX_BUFFER_SIZE
);
337 ldpaa_fd_set_addr(&fd
, (u64
)buffer_start
);
338 ldpaa_fd_set_offset(&fd
, (uint16_t)(data_offset
));
339 ldpaa_fd_set_bpid(&fd
, dflt_dpbp
->dpbp_attr
.bpid
);
340 ldpaa_fd_set_len(&fd
, len
);
342 fd
.simple
.ctrl
= LDPAA_FD_CTRL_ASAL
| LDPAA_FD_CTRL_PTA
|
345 qbman_eq_desc_clear(&ed
);
346 qbman_eq_desc_set_no_orp(&ed
, 0);
347 qbman_eq_desc_set_qd(&ed
, priv
->tx_qdid
, priv
->tx_flow_id
, 0);
349 time_start
= get_timer(0);
351 while (get_timer(time_start
) < timeo
) {
352 err
= qbman_swp_enqueue(swp
, &ed
,
353 (const struct qbman_fd
*)(&fd
));
359 printf("error enqueueing Tx frame\n");
366 qbman_release_desc_clear(&releasedesc
);
367 qbman_release_desc_set_bpid(&releasedesc
, dflt_dpbp
->dpbp_attr
.bpid
);
368 time_start
= get_timer(0);
370 /* Release buffer into the QBMAN */
371 err
= qbman_swp_release(swp
, &releasedesc
, &buffer_start
, 1);
372 } while (get_timer(time_start
) < timeo
&& err
== -EBUSY
);
375 printf("TX data: QBMAN buffer release fails\n");
380 static int ldpaa_eth_open(struct eth_device
*net_dev
, bd_t
*bd
)
382 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)net_dev
->priv
;
383 struct dpmac_link_state dpmac_link_state
= { 0 };
385 struct dpni_link_state link_state
;
389 phy_interface_t enet_if
;
390 struct dpni_queue d_queue
;
392 if (net_dev
->state
== ETH_STATE_ACTIVE
)
395 if (get_mc_boot_status() != 0) {
396 printf("ERROR (MC is not booted)\n");
400 if (get_dpl_apply_status() == 0) {
401 printf("ERROR (DPL is deployed. No device available)\n");
405 /* DPMAC initialization */
406 err
= ldpaa_dpmac_setup(priv
);
408 goto err_dpmac_setup
;
412 err
= phy_startup(priv
->phydev
);
414 printf("%s: Could not initialize\n",
415 priv
->phydev
->dev
->name
);
420 priv
->phydev
= (struct phy_device
*)malloc(sizeof(struct phy_device
));
421 memset(priv
->phydev
, 0, sizeof(struct phy_device
));
423 priv
->phydev
->speed
= SPEED_1000
;
424 priv
->phydev
->link
= 1;
425 priv
->phydev
->duplex
= DUPLEX_FULL
;
428 bus
= wriop_get_mdio(priv
->dpmac_id
);
429 enet_if
= wriop_get_enet_if(priv
->dpmac_id
);
431 (enet_if
== PHY_INTERFACE_MODE_XGMII
)) {
432 priv
->phydev
= (struct phy_device
*)
433 malloc(sizeof(struct phy_device
));
434 memset(priv
->phydev
, 0, sizeof(struct phy_device
));
436 priv
->phydev
->speed
= SPEED_10000
;
437 priv
->phydev
->link
= 1;
438 priv
->phydev
->duplex
= DUPLEX_FULL
;
441 if (!priv
->phydev
->link
) {
442 printf("%s: No link.\n", priv
->phydev
->dev
->name
);
447 /* DPMAC binding DPNI */
448 err
= ldpaa_dpmac_bind(priv
);
452 /* DPNI initialization */
453 err
= ldpaa_dpni_setup(priv
);
457 err
= ldpaa_dpbp_setup();
461 /* DPNI binding DPBP */
462 err
= ldpaa_dpni_bind(priv
);
466 err
= dpni_add_mac_addr(dflt_mc_io
, MC_CMD_NO_FLAGS
,
467 dflt_dpni
->dpni_handle
, net_dev
->enetaddr
);
469 printf("dpni_add_mac_addr() failed\n");
473 err
= dpni_enable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
475 printf("dpni_enable() failed\n");
479 dpmac_link_state
.rate
= priv
->phydev
->speed
;
481 if (priv
->phydev
->autoneg
== AUTONEG_DISABLE
)
482 dpmac_link_state
.options
&= ~DPMAC_LINK_OPT_AUTONEG
;
484 dpmac_link_state
.options
|= DPMAC_LINK_OPT_AUTONEG
;
486 if (priv
->phydev
->duplex
== DUPLEX_HALF
)
487 dpmac_link_state
.options
|= DPMAC_LINK_OPT_HALF_DUPLEX
;
489 dpmac_link_state
.up
= priv
->phydev
->link
;
491 err
= dpmac_set_link_state(dflt_mc_io
, MC_CMD_NO_FLAGS
,
492 priv
->dpmac_handle
, &dpmac_link_state
);
494 printf("dpmac_set_link_state() failed\n");
499 printf("DPMAC link status: %d - ", dpmac_link_state
.up
);
500 dpmac_link_state
.up
== 0 ? printf("down\n") :
501 dpmac_link_state
.up
== 1 ? printf("up\n") : printf("error state\n");
503 err
= dpni_get_link_state(dflt_mc_io
, MC_CMD_NO_FLAGS
,
504 dflt_dpni
->dpni_handle
, &link_state
);
506 printf("dpni_get_link_state() failed\n");
510 printf("DPNI link status: %d - ", link_state
.up
);
511 link_state
.up
== 0 ? printf("down\n") :
512 link_state
.up
== 1 ? printf("up\n") : printf("error state\n");
515 memset(&d_queue
, 0, sizeof(struct dpni_queue
));
516 err
= dpni_get_queue(dflt_mc_io
, MC_CMD_NO_FLAGS
,
517 dflt_dpni
->dpni_handle
, DPNI_QUEUE_RX
,
520 printf("dpni_get_queue failed\n");
524 priv
->rx_dflt_fqid
= d_queue
.fqid
;
526 err
= dpni_get_qdid(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
,
529 printf("dpni_get_qdid() failed\n");
533 return priv
->phydev
->link
;
537 dpni_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
541 dpni_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
544 dpmac_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, priv
->dpmac_handle
);
545 dpmac_destroy(dflt_mc_io
,
547 MC_CMD_NO_FLAGS
, priv
->dpmac_id
);
552 static void ldpaa_eth_stop(struct eth_device
*net_dev
)
554 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)net_dev
->priv
;
557 struct mii_dev
*bus
= wriop_get_mdio(priv
->dpmac_id
);
560 if ((net_dev
->state
== ETH_STATE_PASSIVE
) ||
561 (net_dev
->state
== ETH_STATE_INIT
))
565 ldpaa_eth_get_dpni_counter();
566 ldpaa_eth_get_dpmac_counter(net_dev
);
569 err
= dprc_disconnect(dflt_mc_io
, MC_CMD_NO_FLAGS
,
570 dflt_dprc_handle
, &dpmac_endpoint
);
572 printf("dprc_disconnect() failed dpmac_endpoint\n");
574 err
= dpmac_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, priv
->dpmac_handle
);
576 printf("dpmac_close() failed\n");
578 err
= dpmac_destroy(dflt_mc_io
,
583 printf("dpmac_destroy() failed\n");
585 /* Stop Tx and Rx traffic */
586 err
= dpni_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
588 printf("dpni_disable() failed\n");
591 if (priv
->phydev
&& bus
!= NULL
)
592 phy_shutdown(priv
->phydev
);
599 /* Free DPBP handle and reset. */
602 dpni_reset(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
604 printf("dpni_reset() failed\n");
606 dpni_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
608 printf("dpni_close() failed\n");
611 static void ldpaa_dpbp_drain_cnt(int count
)
613 uint64_t buf_array
[7];
620 ret
= qbman_swp_acquire(dflt_dpio
->sw_portal
,
621 dflt_dpbp
->dpbp_attr
.bpid
,
624 printf("qbman_swp_acquire() failed\n");
627 for (i
= 0; i
< ret
; i
++) {
628 addr
= (void *)buf_array
[i
];
629 debug("Free: buffer addr =0x%p\n", addr
);
635 static void ldpaa_dpbp_drain(void)
638 for (i
= 0; i
< LDPAA_ETH_NUM_BUFS
; i
+= 7)
639 ldpaa_dpbp_drain_cnt(7);
642 static int ldpaa_bp_add_7(uint16_t bpid
)
644 uint64_t buf_array
[7];
647 struct qbman_release_desc rd
;
649 for (i
= 0; i
< 7; i
++) {
650 addr
= memalign(LDPAA_ETH_BUF_ALIGN
, LDPAA_ETH_RX_BUFFER_SIZE
);
652 printf("addr allocation failed\n");
655 memset(addr
, 0x00, LDPAA_ETH_RX_BUFFER_SIZE
);
656 flush_dcache_range((u64
)addr
,
657 (u64
)(addr
+ LDPAA_ETH_RX_BUFFER_SIZE
));
659 buf_array
[i
] = (uint64_t)addr
;
660 debug("Release: buffer addr =0x%p\n", addr
);
664 /* In case the portal is busy, retry until successful.
665 * This function is guaranteed to succeed in a reasonable amount
671 qbman_release_desc_clear(&rd
);
672 qbman_release_desc_set_bpid(&rd
, bpid
);
673 } while (qbman_swp_release(dflt_dpio
->sw_portal
, &rd
, buf_array
, i
));
684 static int ldpaa_dpbp_seed(uint16_t bpid
)
689 for (i
= 0; i
< LDPAA_ETH_NUM_BUFS
; i
+= 7) {
690 count
= ldpaa_bp_add_7(bpid
);
692 printf("Buffer Seed= %d\n", count
);
698 static int ldpaa_dpbp_setup(void)
702 err
= dpbp_open(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_attr
.id
,
703 &dflt_dpbp
->dpbp_handle
);
705 printf("dpbp_open() failed\n");
709 err
= dpbp_enable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
711 printf("dpbp_enable() failed\n");
715 err
= dpbp_get_attributes(dflt_mc_io
, MC_CMD_NO_FLAGS
,
716 dflt_dpbp
->dpbp_handle
,
717 &dflt_dpbp
->dpbp_attr
);
719 printf("dpbp_get_attributes() failed\n");
723 err
= ldpaa_dpbp_seed(dflt_dpbp
->dpbp_attr
.bpid
);
726 printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
727 dflt_dpbp
->dpbp_attr
.id
, dflt_dpbp
->dpbp_attr
.bpid
);
735 dpbp_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
737 dpbp_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
742 static void ldpaa_dpbp_free(void)
745 dpbp_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
746 dpbp_reset(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
747 dpbp_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
750 static int ldpaa_dpmac_version_check(struct fsl_mc_io
*mc_io
,
751 struct ldpaa_eth_priv
*priv
)
754 uint16_t major_ver
, minor_ver
;
756 error
= dpmac_get_api_version(dflt_mc_io
, 0,
759 if ((major_ver
< DPMAC_VER_MAJOR
) ||
760 (major_ver
== DPMAC_VER_MAJOR
&& minor_ver
< DPMAC_VER_MINOR
)) {
761 printf("DPMAC version mismatch found %u.%u,",
762 major_ver
, minor_ver
);
763 printf("supported version is %u.%u\n",
764 DPMAC_VER_MAJOR
, DPMAC_VER_MINOR
);
771 static int ldpaa_dpmac_setup(struct ldpaa_eth_priv
*priv
)
774 struct dpmac_cfg dpmac_cfg
;
776 dpmac_cfg
.mac_id
= priv
->dpmac_id
;
778 err
= dpmac_create(dflt_mc_io
,
780 MC_CMD_NO_FLAGS
, &dpmac_cfg
,
783 printf("dpmac_create() failed\n");
785 err
= ldpaa_dpmac_version_check(dflt_mc_io
, priv
);
787 printf("ldpaa_dpmac_version_check() failed: %d\n", err
);
788 goto err_version_check
;
791 err
= dpmac_open(dflt_mc_io
,
794 &priv
->dpmac_handle
);
796 printf("dpmac_open() failed: %d\n", err
);
804 dpmac_destroy(dflt_mc_io
,
806 MC_CMD_NO_FLAGS
, priv
->dpmac_id
);
811 static int ldpaa_dpmac_bind(struct ldpaa_eth_priv
*priv
)
814 struct dprc_connection_cfg dprc_connection_cfg
= {
815 /* If both rates are zero the connection */
816 /* will be configured in "best effort" mode. */
822 struct dprc_endpoint dbg_endpoint
;
826 memset(&dpmac_endpoint
, 0, sizeof(struct dprc_endpoint
));
827 strcpy(dpmac_endpoint
.type
, "dpmac");
828 dpmac_endpoint
.id
= priv
->dpmac_id
;
830 memset(&dpni_endpoint
, 0, sizeof(struct dprc_endpoint
));
831 strcpy(dpni_endpoint
.type
, "dpni");
832 dpni_endpoint
.id
= dflt_dpni
->dpni_id
;
834 err
= dprc_connect(dflt_mc_io
, MC_CMD_NO_FLAGS
,
838 &dprc_connection_cfg
);
840 printf("dprc_connect() failed\n");
843 err
= dprc_get_connection(dflt_mc_io
, MC_CMD_NO_FLAGS
,
844 dflt_dprc_handle
, &dpni_endpoint
,
845 &dbg_endpoint
, &state
);
846 printf("%s, DPMAC Type= %s\n", __func__
, dbg_endpoint
.type
);
847 printf("%s, DPMAC ID= %d\n", __func__
, dbg_endpoint
.id
);
848 printf("%s, DPMAC State= %d\n", __func__
, state
);
850 memset(&dbg_endpoint
, 0, sizeof(struct dprc_endpoint
));
851 err
= dprc_get_connection(dflt_mc_io
, MC_CMD_NO_FLAGS
,
852 dflt_dprc_handle
, &dpmac_endpoint
,
853 &dbg_endpoint
, &state
);
854 printf("%s, DPNI Type= %s\n", __func__
, dbg_endpoint
.type
);
855 printf("%s, DPNI ID= %d\n", __func__
, dbg_endpoint
.id
);
856 printf("%s, DPNI State= %d\n", __func__
, state
);
861 static int ldpaa_dpni_setup(struct ldpaa_eth_priv
*priv
)
865 /* and get a handle for the DPNI this interface is associate with */
866 err
= dpni_open(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_id
,
867 &dflt_dpni
->dpni_handle
);
869 printf("dpni_open() failed\n");
872 err
= dpni_get_attributes(dflt_mc_io
, MC_CMD_NO_FLAGS
,
873 dflt_dpni
->dpni_handle
,
874 &dflt_dpni
->dpni_attrs
);
876 printf("dpni_get_attributes() failed (err=%d)\n", err
);
880 /* Configure our buffers' layout */
881 dflt_dpni
->buf_layout
.options
= DPNI_BUF_LAYOUT_OPT_PARSER_RESULT
|
882 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS
|
883 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE
|
884 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN
;
885 dflt_dpni
->buf_layout
.pass_parser_result
= true;
886 dflt_dpni
->buf_layout
.pass_frame_status
= true;
887 dflt_dpni
->buf_layout
.private_data_size
= LDPAA_ETH_SWA_SIZE
;
888 /* HW erratum mandates data alignment in multiples of 256 */
889 dflt_dpni
->buf_layout
.data_align
= LDPAA_ETH_BUF_ALIGN
;
892 err
= dpni_set_buffer_layout(dflt_mc_io
, MC_CMD_NO_FLAGS
,
893 dflt_dpni
->dpni_handle
,
894 &dflt_dpni
->buf_layout
, DPNI_QUEUE_RX
);
896 printf("dpni_set_buffer_layout() failed");
901 /* remove Rx-only options */
902 dflt_dpni
->buf_layout
.options
&= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN
|
903 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT
);
904 err
= dpni_set_buffer_layout(dflt_mc_io
, MC_CMD_NO_FLAGS
,
905 dflt_dpni
->dpni_handle
,
906 &dflt_dpni
->buf_layout
, DPNI_QUEUE_TX
);
908 printf("dpni_set_buffer_layout() failed");
912 /* ... tx-confirm. */
913 dflt_dpni
->buf_layout
.options
&= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE
;
914 err
= dpni_set_buffer_layout(dflt_mc_io
, MC_CMD_NO_FLAGS
,
915 dflt_dpni
->dpni_handle
,
916 &dflt_dpni
->buf_layout
,
917 DPNI_QUEUE_TX_CONFIRM
);
919 printf("dpni_set_buffer_layout() failed");
923 /* Now that we've set our tx buffer layout, retrieve the minimum
924 * required tx data offset.
926 err
= dpni_get_tx_data_offset(dflt_mc_io
, MC_CMD_NO_FLAGS
,
927 dflt_dpni
->dpni_handle
,
928 &priv
->tx_data_offset
);
930 printf("dpni_get_tx_data_offset() failed\n");
931 goto err_data_offset
;
934 /* Warn in case TX data offset is not multiple of 64 bytes. */
935 WARN_ON(priv
->tx_data_offset
% 64);
937 /* Accomodate SWA space. */
938 priv
->tx_data_offset
+= LDPAA_ETH_SWA_SIZE
;
939 debug("priv->tx_data_offset=%d\n", priv
->tx_data_offset
);
946 dpni_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
951 static int ldpaa_dpni_bind(struct ldpaa_eth_priv
*priv
)
953 struct dpni_pools_cfg pools_params
;
954 struct dpni_queue tx_queue
;
957 memset(&pools_params
, 0, sizeof(pools_params
));
958 pools_params
.num_dpbp
= 1;
959 pools_params
.pools
[0].dpbp_id
= (uint16_t)dflt_dpbp
->dpbp_attr
.id
;
960 pools_params
.pools
[0].buffer_size
= LDPAA_ETH_RX_BUFFER_SIZE
;
961 err
= dpni_set_pools(dflt_mc_io
, MC_CMD_NO_FLAGS
,
962 dflt_dpni
->dpni_handle
, &pools_params
);
964 printf("dpni_set_pools() failed\n");
968 memset(&tx_queue
, 0, sizeof(struct dpni_queue
));
970 err
= dpni_set_queue(dflt_mc_io
, MC_CMD_NO_FLAGS
,
971 dflt_dpni
->dpni_handle
,
972 DPNI_QUEUE_TX
, 0, 0, &tx_queue
);
975 printf("dpni_set_queue() failed\n");
979 err
= dpni_set_tx_confirmation_mode(dflt_mc_io
, MC_CMD_NO_FLAGS
,
980 dflt_dpni
->dpni_handle
,
983 printf("dpni_set_tx_confirmation_mode() failed\n");
990 static int ldpaa_eth_netdev_init(struct eth_device
*net_dev
,
991 phy_interface_t enet_if
)
994 struct ldpaa_eth_priv
*priv
= (struct ldpaa_eth_priv
*)net_dev
->priv
;
996 sprintf(net_dev
->name
, "DPMAC%d@%s", priv
->dpmac_id
,
997 phy_interface_strings
[enet_if
]);
1000 net_dev
->init
= ldpaa_eth_open
;
1001 net_dev
->halt
= ldpaa_eth_stop
;
1002 net_dev
->send
= ldpaa_eth_tx
;
1003 net_dev
->recv
= ldpaa_eth_pull_dequeue_rx
;
1005 #ifdef CONFIG_PHYLIB
1006 err
= init_phy(net_dev
);
1011 err
= eth_register(net_dev
);
1013 printf("eth_register() = %d\n", err
);
1020 int ldpaa_eth_init(int dpmac_id
, phy_interface_t enet_if
)
1022 struct eth_device
*net_dev
= NULL
;
1023 struct ldpaa_eth_priv
*priv
= NULL
;
1027 net_dev
= (struct eth_device
*)malloc(sizeof(struct eth_device
));
1029 printf("eth_device malloc() failed\n");
1032 memset(net_dev
, 0, sizeof(struct eth_device
));
1034 /* alloc the ldpaa ethernet private struct */
1035 priv
= (struct ldpaa_eth_priv
*)malloc(sizeof(struct ldpaa_eth_priv
));
1037 printf("ldpaa_eth_priv malloc() failed\n");
1040 memset(priv
, 0, sizeof(struct ldpaa_eth_priv
));
1042 net_dev
->priv
= (void *)priv
;
1043 priv
->net_dev
= (struct eth_device
*)net_dev
;
1044 priv
->dpmac_id
= dpmac_id
;
1045 debug("%s dpmac_id=%d\n", __func__
, dpmac_id
);
1047 err
= ldpaa_eth_netdev_init(net_dev
, enet_if
);
1049 goto err_netdev_init
;
1051 debug("ldpaa ethernet: Probed interface %s\n", net_dev
->name
);
1056 net_dev
->priv
= NULL
;