2015-03-19 16:20:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freescale Semiconductor
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/types.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <hwconfig.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <linux/compat.h>
|
2015-11-04 06:56:00 +00:00
|
|
|
#include <fsl-mc/fsl_dpmac.h>
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
#include <fsl-mc/ldpaa_wriop.h>
|
2015-03-19 16:20:46 +00:00
|
|
|
#include "ldpaa_eth.h"
|
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
2015-03-19 16:20:46 +00:00
|
|
|
static int init_phy(struct eth_device *dev)
|
|
|
|
{
|
2016-02-24 11:32:11 +00:00
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
|
|
|
|
struct phy_device *phydev = NULL;
|
|
|
|
struct mii_dev *bus;
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
bus = wriop_get_mdio(priv->dpmac_id);
|
|
|
|
if (bus == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
phydev = phy_connect(bus, wriop_get_phy_address(priv->dpmac_id),
|
|
|
|
dev, wriop_get_enet_if(priv->dpmac_id));
|
|
|
|
if (!phydev) {
|
|
|
|
printf("Failed to connect\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->phydev = phydev;
|
|
|
|
|
|
|
|
return phy_config(phydev);
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
2016-02-24 11:32:11 +00:00
|
|
|
#endif
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2015-11-04 06:56:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
static void ldpaa_eth_get_dpni_counter(void)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u64 value;
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_ING_FRAME,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_ING_FRAME failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_ING_FRAME=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_ING_BYTE,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_ING_BYTE failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_ING_BYTE=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_ING_FRAME_DROP ,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DROP failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_ING_FRAME_DROP =%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_ING_FRAME_DISCARD,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_ING_FRAME_DISCARD failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_ING_FRAME_DISCARD=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_EGR_FRAME,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_EGR_FRAME failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_EGR_FRAME=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_EGR_BYTE ,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_EGR_BYTE failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_EGR_BYTE =%lld\n", value);
|
|
|
|
|
|
|
|
err = dpni_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
DPNI_CNT_EGR_FRAME_DISCARD ,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_counter: DPNI_CNT_EGR_FRAME_DISCARD failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPNI_CNT_EGR_FRAME_DISCARD =%lld\n", value);
|
|
|
|
}
|
2015-12-24 10:03:37 +00:00
|
|
|
|
|
|
|
static void ldpaa_eth_get_dpmac_counter(struct eth_device *net_dev)
|
|
|
|
{
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
|
|
|
|
int err = 0;
|
|
|
|
u64 value;
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_ING_BYTE,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_ING_FRAME_DISCARD,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_ING_ALIGN_ERR,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_ING_BYTE,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_ING_ERR_FRAME,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_EGR_BYTE ,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_EGR_BYTE =%lld\n", value);
|
|
|
|
|
|
|
|
err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
DPMAC_CNT_EGR_ERR_FRAME ,
|
|
|
|
&value);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_get_counter: DPMAC_CNT_EGR_ERR_FRAME failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("DPMAC_CNT_EGR_ERR_FRAME =%lld\n", value);
|
|
|
|
}
|
2015-11-04 06:56:01 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
|
|
|
|
const struct dpaa_fd *fd)
|
|
|
|
{
|
|
|
|
u64 fd_addr;
|
|
|
|
uint16_t fd_offset;
|
|
|
|
uint32_t fd_length;
|
|
|
|
struct ldpaa_fas *fas;
|
|
|
|
uint32_t status, err;
|
2015-07-02 05:59:08 +00:00
|
|
|
u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
|
|
|
|
u32 time_start;
|
2015-03-19 16:20:46 +00:00
|
|
|
struct qbman_release_desc releasedesc;
|
|
|
|
struct qbman_swp *swp = dflt_dpio->sw_portal;
|
|
|
|
|
|
|
|
fd_addr = ldpaa_fd_get_addr(fd);
|
|
|
|
fd_offset = ldpaa_fd_get_offset(fd);
|
|
|
|
fd_length = ldpaa_fd_get_len(fd);
|
|
|
|
|
|
|
|
debug("Rx frame:data addr=0x%p size=0x%x\n", (u64 *)fd_addr, fd_length);
|
|
|
|
|
|
|
|
if (fd->simple.frc & LDPAA_FD_FRC_FASV) {
|
|
|
|
/* Read the frame annotation status word and check for errors */
|
|
|
|
fas = (struct ldpaa_fas *)
|
|
|
|
((uint8_t *)(fd_addr) +
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->buf_layout.private_data_size);
|
2015-03-19 16:20:46 +00:00
|
|
|
status = le32_to_cpu(fas->status);
|
|
|
|
if (status & LDPAA_ETH_RX_ERR_MASK) {
|
|
|
|
printf("Rx frame error(s): 0x%08x\n",
|
|
|
|
status & LDPAA_ETH_RX_ERR_MASK);
|
|
|
|
goto error;
|
|
|
|
} else if (status & LDPAA_ETH_RX_UNSUPP_MASK) {
|
|
|
|
printf("Unsupported feature in bitmask: 0x%08x\n",
|
|
|
|
status & LDPAA_ETH_RX_UNSUPP_MASK);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Rx frame: To Upper layer\n");
|
|
|
|
net_process_received_packet((uint8_t *)(fd_addr) + fd_offset,
|
|
|
|
fd_length);
|
|
|
|
|
|
|
|
error:
|
2015-03-21 02:28:15 +00:00
|
|
|
flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
|
2015-03-19 16:20:46 +00:00
|
|
|
qbman_release_desc_clear(&releasedesc);
|
|
|
|
qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
|
2015-07-02 05:59:08 +00:00
|
|
|
time_start = get_timer(0);
|
2015-03-19 16:20:46 +00:00
|
|
|
do {
|
|
|
|
/* Release buffer into the QBMAN */
|
|
|
|
err = qbman_swp_release(swp, &releasedesc, &fd_addr, 1);
|
2015-07-02 05:59:08 +00:00
|
|
|
} while (get_timer(time_start) < timeo && err == -EBUSY);
|
|
|
|
|
|
|
|
if (err == -EBUSY)
|
|
|
|
printf("Rx frame: QBMAN buffer release fails\n");
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_eth_pull_dequeue_rx(struct eth_device *dev)
|
|
|
|
{
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)dev->priv;
|
|
|
|
const struct ldpaa_dq *dq;
|
|
|
|
const struct dpaa_fd *fd;
|
2015-07-02 05:59:06 +00:00
|
|
|
int i = 5, err = 0, status;
|
|
|
|
u32 timeo = (CONFIG_SYS_HZ * 2) / 1000;
|
|
|
|
u32 time_start;
|
2015-03-19 16:20:46 +00:00
|
|
|
static struct qbman_pull_desc pulldesc;
|
|
|
|
struct qbman_swp *swp = dflt_dpio->sw_portal;
|
|
|
|
|
|
|
|
while (--i) {
|
2015-03-21 02:28:15 +00:00
|
|
|
qbman_pull_desc_clear(&pulldesc);
|
|
|
|
qbman_pull_desc_set_numframes(&pulldesc, 1);
|
|
|
|
qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
err = qbman_swp_pull(swp, &pulldesc);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("Dequeue frames error:0x%08x\n", err);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:59:06 +00:00
|
|
|
time_start = get_timer(0);
|
2015-03-21 02:28:15 +00:00
|
|
|
|
2015-07-02 05:59:06 +00:00
|
|
|
do {
|
|
|
|
dq = qbman_swp_dqrr_next(swp);
|
|
|
|
} while (get_timer(time_start) < timeo && !dq);
|
2015-03-21 02:28:15 +00:00
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
if (dq) {
|
|
|
|
/* Check for valid frame. If not sent a consume
|
|
|
|
* confirmation to QBMAN otherwise give it to NADK
|
|
|
|
* application and then send consume confirmation to
|
|
|
|
* QBMAN.
|
|
|
|
*/
|
|
|
|
status = (uint8_t)ldpaa_dq_flags(dq);
|
|
|
|
if ((status & LDPAA_DQ_STAT_VALIDFRAME) == 0) {
|
|
|
|
debug("Dequeue RX frames:");
|
|
|
|
debug("No frame delivered\n");
|
|
|
|
|
|
|
|
qbman_swp_dqrr_consume(swp, dq);
|
2015-07-02 05:59:07 +00:00
|
|
|
continue;
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fd = ldpaa_dq_fd(dq);
|
|
|
|
|
|
|
|
/* Obtain FD and process it */
|
|
|
|
ldpaa_eth_rx(priv, fd);
|
|
|
|
qbman_swp_dqrr_consume(swp, dq);
|
|
|
|
break;
|
2015-07-02 05:59:06 +00:00
|
|
|
} else {
|
|
|
|
err = -ENODATA;
|
|
|
|
debug("No DQRR entries\n");
|
|
|
|
break;
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)
|
|
|
|
{
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
|
|
|
|
struct dpaa_fd fd;
|
|
|
|
u64 buffer_start;
|
|
|
|
int data_offset, err;
|
2015-07-02 05:59:05 +00:00
|
|
|
u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
|
|
|
|
u32 time_start;
|
2015-03-19 16:20:46 +00:00
|
|
|
struct qbman_swp *swp = dflt_dpio->sw_portal;
|
|
|
|
struct qbman_eq_desc ed;
|
2015-07-02 05:59:05 +00:00
|
|
|
struct qbman_release_desc releasedesc;
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
/* Setup the FD fields */
|
|
|
|
memset(&fd, 0, sizeof(fd));
|
|
|
|
|
|
|
|
data_offset = priv->tx_data_offset;
|
|
|
|
|
|
|
|
do {
|
|
|
|
err = qbman_swp_acquire(dflt_dpio->sw_portal,
|
|
|
|
dflt_dpbp->dpbp_attr.bpid,
|
|
|
|
&buffer_start, 1);
|
|
|
|
} while (err == -EBUSY);
|
|
|
|
|
2017-10-26 10:33:22 +00:00
|
|
|
if (err <= 0) {
|
2015-03-19 16:20:46 +00:00
|
|
|
printf("qbman_swp_acquire() failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("TX data: malloc buffer start=0x%p\n", (u64 *)buffer_start);
|
|
|
|
|
|
|
|
memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);
|
|
|
|
|
2015-03-21 02:28:15 +00:00
|
|
|
flush_dcache_range(buffer_start, buffer_start +
|
|
|
|
LDPAA_ETH_RX_BUFFER_SIZE);
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
ldpaa_fd_set_addr(&fd, (u64)buffer_start);
|
|
|
|
ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
|
|
|
|
ldpaa_fd_set_bpid(&fd, dflt_dpbp->dpbp_attr.bpid);
|
|
|
|
ldpaa_fd_set_len(&fd, len);
|
|
|
|
|
|
|
|
fd.simple.ctrl = LDPAA_FD_CTRL_ASAL | LDPAA_FD_CTRL_PTA |
|
|
|
|
LDPAA_FD_CTRL_PTV1;
|
|
|
|
|
|
|
|
qbman_eq_desc_clear(&ed);
|
|
|
|
qbman_eq_desc_set_no_orp(&ed, 0);
|
|
|
|
qbman_eq_desc_set_qd(&ed, priv->tx_qdid, priv->tx_flow_id, 0);
|
2015-07-02 05:59:05 +00:00
|
|
|
|
|
|
|
time_start = get_timer(0);
|
|
|
|
|
|
|
|
while (get_timer(time_start) < timeo) {
|
|
|
|
err = qbman_swp_enqueue(swp, &ed,
|
|
|
|
(const struct qbman_fd *)(&fd));
|
|
|
|
if (err != -EBUSY)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err < 0) {
|
2015-03-19 16:20:46 +00:00
|
|
|
printf("error enqueueing Tx frame\n");
|
2015-07-02 05:59:05 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
return err;
|
2015-07-02 05:59:05 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
qbman_release_desc_clear(&releasedesc);
|
|
|
|
qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
|
|
|
|
time_start = get_timer(0);
|
|
|
|
do {
|
|
|
|
/* Release buffer into the QBMAN */
|
|
|
|
err = qbman_swp_release(swp, &releasedesc, &buffer_start, 1);
|
|
|
|
} while (get_timer(time_start) < timeo && err == -EBUSY);
|
|
|
|
|
|
|
|
if (err == -EBUSY)
|
|
|
|
printf("TX data: QBMAN buffer release fails\n");
|
|
|
|
|
|
|
|
return err;
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
|
|
|
|
{
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
|
|
|
|
struct dpni_queue_attr rx_queue_attr;
|
2015-11-04 06:56:00 +00:00
|
|
|
struct dpmac_link_state dpmac_link_state = { 0 };
|
2015-11-04 06:56:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
struct dpni_link_state link_state;
|
|
|
|
#endif
|
2016-02-24 11:32:11 +00:00
|
|
|
int err = 0;
|
|
|
|
struct mii_dev *bus;
|
|
|
|
phy_interface_t enet_if;
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
if (net_dev->state == ETH_STATE_ACTIVE)
|
|
|
|
return 0;
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
if (get_mc_boot_status() != 0) {
|
|
|
|
printf("ERROR (MC is not booted)\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_dpl_apply_status() == 0) {
|
|
|
|
printf("ERROR (DPL is deployed. No device available)\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2016-02-24 11:32:11 +00:00
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
/* DPMAC initialization */
|
|
|
|
err = ldpaa_dpmac_setup(priv);
|
|
|
|
if (err < 0)
|
|
|
|
goto err_dpmac_setup;
|
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
2016-11-03 12:35:09 +00:00
|
|
|
if (priv->phydev) {
|
2016-02-24 11:32:11 +00:00
|
|
|
err = phy_startup(priv->phydev);
|
|
|
|
if (err) {
|
|
|
|
printf("%s: Could not initialize\n",
|
|
|
|
priv->phydev->dev->name);
|
|
|
|
goto err_dpamc_bind;
|
|
|
|
}
|
2016-11-03 12:35:09 +00:00
|
|
|
}
|
2016-02-24 11:32:11 +00:00
|
|
|
#else
|
|
|
|
priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
|
|
|
|
memset(priv->phydev, 0, sizeof(struct phy_device));
|
|
|
|
|
|
|
|
priv->phydev->speed = SPEED_1000;
|
|
|
|
priv->phydev->link = 1;
|
|
|
|
priv->phydev->duplex = DUPLEX_FULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bus = wriop_get_mdio(priv->dpmac_id);
|
|
|
|
enet_if = wriop_get_enet_if(priv->dpmac_id);
|
|
|
|
if ((bus == NULL) &&
|
|
|
|
(enet_if == PHY_INTERFACE_MODE_XGMII)) {
|
|
|
|
priv->phydev = (struct phy_device *)
|
|
|
|
malloc(sizeof(struct phy_device));
|
|
|
|
memset(priv->phydev, 0, sizeof(struct phy_device));
|
|
|
|
|
|
|
|
priv->phydev->speed = SPEED_10000;
|
|
|
|
priv->phydev->link = 1;
|
|
|
|
priv->phydev->duplex = DUPLEX_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->phydev->link) {
|
|
|
|
printf("%s: No link.\n", priv->phydev->dev->name);
|
|
|
|
err = -1;
|
|
|
|
goto err_dpamc_bind;
|
|
|
|
}
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
/* DPMAC binding DPNI */
|
|
|
|
err = ldpaa_dpmac_bind(priv);
|
|
|
|
if (err)
|
|
|
|
goto err_dpamc_bind;
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
/* DPNI initialization */
|
|
|
|
err = ldpaa_dpni_setup(priv);
|
|
|
|
if (err < 0)
|
|
|
|
goto err_dpni_setup;
|
|
|
|
|
|
|
|
err = ldpaa_dpbp_setup();
|
|
|
|
if (err < 0)
|
|
|
|
goto err_dpbp_setup;
|
|
|
|
|
|
|
|
/* DPNI binding DPBP */
|
|
|
|
err = ldpaa_dpni_bind(priv);
|
|
|
|
if (err)
|
2015-11-04 06:56:00 +00:00
|
|
|
goto err_dpni_bind;
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2015-10-07 10:59:58 +00:00
|
|
|
err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle, net_dev->enetaddr);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
2015-10-07 10:59:58 +00:00
|
|
|
printf("dpni_add_mac_addr() failed\n");
|
2015-03-19 16:20:46 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_enable() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
dpmac_link_state.rate = priv->phydev->speed;
|
|
|
|
|
|
|
|
if (priv->phydev->autoneg == AUTONEG_DISABLE)
|
|
|
|
dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
|
|
|
|
else
|
|
|
|
dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;
|
|
|
|
|
|
|
|
if (priv->phydev->duplex == DUPLEX_HALF)
|
|
|
|
dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
|
|
|
|
|
|
|
|
dpmac_link_state.up = priv->phydev->link;
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle, &dpmac_link_state);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpmac_set_link_state() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
2015-11-04 06:56:01 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle, &link_state);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("dpni_get_link_state() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("link status: %d - ", link_state.up);
|
|
|
|
link_state.up == 0 ? printf("down\n") :
|
|
|
|
link_state.up == 1 ? printf("up\n") : printf("error state\n");
|
|
|
|
#endif
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
/* TODO: support multiple Rx flows */
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_get_rx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle, 0, 0, &rx_queue_attr);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_get_rx_flow() failed\n");
|
|
|
|
goto err_rx_flow;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->rx_dflt_fqid = rx_queue_attr.fqid;
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
|
2015-07-07 10:10:06 +00:00
|
|
|
&priv->tx_qdid);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_get_qdid() failed\n");
|
|
|
|
goto err_qdid;
|
|
|
|
}
|
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
return priv->phydev->link;
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
err_qdid:
|
|
|
|
err_rx_flow:
|
2015-11-04 06:56:00 +00:00
|
|
|
dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
|
|
|
err_dpni_bind:
|
2015-03-19 16:20:46 +00:00
|
|
|
ldpaa_dpbp_free();
|
|
|
|
err_dpbp_setup:
|
2015-11-04 06:56:00 +00:00
|
|
|
dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
err_dpni_setup:
|
2016-02-24 11:32:11 +00:00
|
|
|
err_dpamc_bind:
|
|
|
|
dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
|
2015-11-04 06:56:00 +00:00
|
|
|
err_dpmac_setup:
|
2015-03-19 16:20:46 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ldpaa_eth_stop(struct eth_device *net_dev)
|
|
|
|
{
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
|
|
|
|
int err = 0;
|
2016-02-24 11:32:11 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
|
|
|
struct mii_dev *bus = wriop_get_mdio(priv->dpmac_id);
|
|
|
|
#endif
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2015-03-21 02:28:15 +00:00
|
|
|
if ((net_dev->state == ETH_STATE_PASSIVE) ||
|
|
|
|
(net_dev->state == ETH_STATE_INIT))
|
2015-03-19 16:20:46 +00:00
|
|
|
return;
|
2015-11-04 06:56:00 +00:00
|
|
|
|
2015-11-04 06:56:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
ldpaa_eth_get_dpni_counter();
|
2015-12-24 10:03:37 +00:00
|
|
|
ldpaa_eth_get_dpmac_counter(net_dev);
|
2015-11-04 06:56:01 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dprc_handle, &dpmac_endpoint);
|
|
|
|
if (err < 0)
|
|
|
|
printf("dprc_disconnect() failed dpmac_endpoint\n");
|
|
|
|
|
|
|
|
err = dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
|
|
|
|
if (err < 0)
|
|
|
|
printf("dpmac_destroy() failed\n");
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
/* Stop Tx and Rx traffic */
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err < 0)
|
|
|
|
printf("dpni_disable() failed\n");
|
|
|
|
|
|
|
|
#ifdef CONFIG_PHYLIB
|
2016-02-24 11:32:11 +00:00
|
|
|
if (priv->phydev && bus != NULL)
|
|
|
|
phy_shutdown(priv->phydev);
|
2017-02-15 15:26:03 +00:00
|
|
|
else {
|
2016-02-24 11:32:11 +00:00
|
|
|
free(priv->phydev);
|
2017-02-15 15:26:03 +00:00
|
|
|
priv->phydev = NULL;
|
|
|
|
}
|
2015-03-19 16:20:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ldpaa_dpbp_free();
|
2015-11-04 06:56:00 +00:00
|
|
|
dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
|
|
|
dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ldpaa_dpbp_drain_cnt(int count)
|
|
|
|
{
|
|
|
|
uint64_t buf_array[7];
|
|
|
|
void *addr;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
BUG_ON(count > 7);
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = qbman_swp_acquire(dflt_dpio->sw_portal,
|
|
|
|
dflt_dpbp->dpbp_attr.bpid,
|
|
|
|
buf_array, count);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("qbman_swp_acquire() failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ret; i++) {
|
|
|
|
addr = (void *)buf_array[i];
|
|
|
|
debug("Free: buffer addr =0x%p\n", addr);
|
|
|
|
free(addr);
|
|
|
|
}
|
|
|
|
} while (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ldpaa_dpbp_drain(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7)
|
|
|
|
ldpaa_dpbp_drain_cnt(7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_bp_add_7(uint16_t bpid)
|
|
|
|
{
|
|
|
|
uint64_t buf_array[7];
|
|
|
|
u8 *addr;
|
|
|
|
int i;
|
|
|
|
struct qbman_release_desc rd;
|
|
|
|
|
|
|
|
for (i = 0; i < 7; i++) {
|
2015-11-04 06:56:02 +00:00
|
|
|
addr = memalign(LDPAA_ETH_BUF_ALIGN, LDPAA_ETH_RX_BUFFER_SIZE);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (!addr) {
|
|
|
|
printf("addr allocation failed\n");
|
|
|
|
goto err_alloc;
|
|
|
|
}
|
|
|
|
memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
|
2015-03-21 02:28:15 +00:00
|
|
|
flush_dcache_range((u64)addr,
|
|
|
|
(u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
buf_array[i] = (uint64_t)addr;
|
|
|
|
debug("Release: buffer addr =0x%p\n", addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
release_bufs:
|
|
|
|
/* In case the portal is busy, retry until successful.
|
|
|
|
* This function is guaranteed to succeed in a reasonable amount
|
|
|
|
* of time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
do {
|
|
|
|
mdelay(1);
|
|
|
|
qbman_release_desc_clear(&rd);
|
|
|
|
qbman_release_desc_set_bpid(&rd, bpid);
|
|
|
|
} while (qbman_swp_release(dflt_dpio->sw_portal, &rd, buf_array, i));
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
if (i)
|
|
|
|
goto release_bufs;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_dpbp_seed(uint16_t bpid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
for (i = 0; i < LDPAA_ETH_NUM_BUFS; i += 7) {
|
|
|
|
count = ldpaa_bp_add_7(bpid);
|
|
|
|
if (count < 7)
|
|
|
|
printf("Buffer Seed= %d\n", count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_dpbp_setup(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
|
2015-03-19 16:20:46 +00:00
|
|
|
&dflt_dpbp->dpbp_handle);
|
|
|
|
if (err) {
|
|
|
|
printf("dpbp_open() failed\n");
|
|
|
|
goto err_open;
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpbp_enable() failed\n");
|
|
|
|
goto err_enable;
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpbp->dpbp_handle,
|
2015-03-19 16:20:46 +00:00
|
|
|
&dflt_dpbp->dpbp_attr);
|
|
|
|
if (err) {
|
|
|
|
printf("dpbp_get_attributes() failed\n");
|
|
|
|
goto err_get_attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid);
|
|
|
|
if (err) {
|
|
|
|
printf("Buffer seeding failed for DPBP %d (bpid=%d)\n",
|
|
|
|
dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid);
|
|
|
|
goto err_seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_seed:
|
|
|
|
err_get_attr:
|
2015-07-07 10:10:06 +00:00
|
|
|
dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
err_enable:
|
2015-07-07 10:10:06 +00:00
|
|
|
dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
err_open:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ldpaa_dpbp_free(void)
|
|
|
|
{
|
|
|
|
ldpaa_dpbp_drain();
|
2015-07-07 10:10:06 +00:00
|
|
|
dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
|
|
|
dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
|
|
|
dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 10:02:37 +00:00
|
|
|
static int ldpaa_dpmac_version_check(struct fsl_mc_io *mc_io,
|
|
|
|
struct ldpaa_eth_priv *priv)
|
|
|
|
{
|
|
|
|
struct dpmac_attr attr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
memset(&attr, 0, sizeof(struct dpmac_attr));
|
|
|
|
error = dpmac_get_attributes(mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
priv->dpmac_handle,
|
|
|
|
&attr);
|
|
|
|
if (error == 0) {
|
|
|
|
if ((attr.version.major != DPMAC_VER_MAJOR) ||
|
|
|
|
(attr.version.minor != DPMAC_VER_MINOR)) {
|
|
|
|
printf("DPMAC version mismatch found %u.%u,",
|
|
|
|
attr.version.major, attr.version.minor);
|
|
|
|
printf("supported version is %u.%u\n",
|
|
|
|
DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct dpmac_cfg dpmac_cfg;
|
|
|
|
|
|
|
|
dpmac_cfg.mac_id = priv->dpmac_id;
|
|
|
|
err = dpmac_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpmac_cfg,
|
|
|
|
&priv->dpmac_handle);
|
|
|
|
if (err)
|
|
|
|
printf("dpmac_create() failed\n");
|
2015-12-24 10:02:37 +00:00
|
|
|
|
|
|
|
err = ldpaa_dpmac_version_check(dflt_mc_io, priv);
|
|
|
|
if (err < 0)
|
|
|
|
printf("ldpaa_dpmac_version_check() failed: %d\n", err);
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct dprc_connection_cfg dprc_connection_cfg = {
|
|
|
|
/* If both rates are zero the connection */
|
|
|
|
/* will be configured in "best effort" mode. */
|
|
|
|
.committed_rate = 0,
|
|
|
|
.max_rate = 0
|
|
|
|
};
|
|
|
|
|
2015-11-04 06:56:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
struct dprc_endpoint dbg_endpoint;
|
|
|
|
int state = 0;
|
|
|
|
#endif
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(dpmac_endpoint.type, "dpmac");
|
2015-11-04 06:56:00 +00:00
|
|
|
dpmac_endpoint.id = priv->dpmac_id;
|
|
|
|
|
|
|
|
memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(dpni_endpoint.type, "dpni");
|
2015-11-04 06:56:00 +00:00
|
|
|
dpni_endpoint.id = dflt_dpni->dpni_id;
|
|
|
|
|
|
|
|
err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dprc_handle,
|
|
|
|
&dpmac_endpoint,
|
|
|
|
&dpni_endpoint,
|
|
|
|
&dprc_connection_cfg);
|
2015-11-04 06:56:01 +00:00
|
|
|
if (err)
|
|
|
|
printf("dprc_connect() failed\n");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dprc_handle, &dpni_endpoint,
|
|
|
|
&dbg_endpoint, &state);
|
|
|
|
printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
|
|
|
|
printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
|
|
|
|
printf("%s, DPMAC State= %d\n", __func__, state);
|
|
|
|
|
|
|
|
memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
|
|
|
|
err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dprc_handle, &dpmac_endpoint,
|
|
|
|
&dbg_endpoint, &state);
|
|
|
|
printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
|
|
|
|
printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
|
|
|
|
printf("%s, DPNI State= %d\n", __func__, state);
|
|
|
|
#endif
|
2015-11-04 06:56:00 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* and get a handle for the DPNI this interface is associate with */
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
|
|
|
|
&dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_open() failed\n");
|
|
|
|
goto err_open;
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
&dflt_dpni->dpni_attrs);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_get_attributes() failed (err=%d)\n", err);
|
|
|
|
goto err_get_attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure our buffers' layout */
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
|
2015-03-19 16:20:46 +00:00
|
|
|
DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
|
2015-11-04 06:56:02 +00:00
|
|
|
DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
|
|
|
|
DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->buf_layout.pass_parser_result = true;
|
|
|
|
dflt_dpni->buf_layout.pass_frame_status = true;
|
|
|
|
dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
|
2015-11-04 06:56:02 +00:00
|
|
|
/* HW erratum mandates data alignment in multiples of 256 */
|
|
|
|
dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
|
2015-03-19 16:20:46 +00:00
|
|
|
/* ...rx, ... */
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpni_set_rx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
&dflt_dpni->buf_layout);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_rx_buffer_layout() failed");
|
|
|
|
goto err_buf_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... tx, ... */
|
2015-11-04 06:56:02 +00:00
|
|
|
/* remove Rx-only options */
|
|
|
|
dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
|
|
|
|
DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpni_set_tx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
&dflt_dpni->buf_layout);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_tx_buffer_layout() failed");
|
|
|
|
goto err_buf_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... tx-confirm. */
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpni_set_tx_conf_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
&dflt_dpni->buf_layout);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_tx_conf_buffer_layout() failed");
|
|
|
|
goto err_buf_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now that we've set our tx buffer layout, retrieve the minimum
|
|
|
|
* required tx data offset.
|
|
|
|
*/
|
2015-07-07 10:10:06 +00:00
|
|
|
err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
|
2015-11-04 06:56:00 +00:00
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
&priv->tx_data_offset);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_get_tx_data_offset() failed\n");
|
|
|
|
goto err_data_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Warn in case TX data offset is not multiple of 64 bytes. */
|
|
|
|
WARN_ON(priv->tx_data_offset % 64);
|
|
|
|
|
|
|
|
/* Accomodate SWA space. */
|
|
|
|
priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
|
|
|
|
debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_data_offset:
|
|
|
|
err_buf_layout:
|
|
|
|
err_get_attr:
|
2015-11-04 06:56:00 +00:00
|
|
|
dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
|
2015-03-19 16:20:46 +00:00
|
|
|
err_open:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv)
|
|
|
|
{
|
|
|
|
struct dpni_pools_cfg pools_params;
|
|
|
|
struct dpni_tx_flow_cfg dflt_tx_flow;
|
2015-12-24 10:03:13 +00:00
|
|
|
struct dpni_tx_conf_cfg tx_conf_cfg;
|
2015-03-19 16:20:46 +00:00
|
|
|
int err = 0;
|
|
|
|
|
2016-03-28 08:41:05 +00:00
|
|
|
memset(&pools_params, 0, sizeof(pools_params));
|
2015-03-19 16:20:46 +00:00
|
|
|
pools_params.num_dpbp = 1;
|
|
|
|
pools_params.pools[0].dpbp_id = (uint16_t)dflt_dpbp->dpbp_attr.id;
|
|
|
|
pools_params.pools[0].buffer_size = LDPAA_ETH_RX_BUFFER_SIZE;
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_set_pools(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle, &pools_params);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_pools() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->tx_flow_id = DPNI_NEW_FLOW_ID;
|
|
|
|
memset(&dflt_tx_flow, 0, sizeof(dflt_tx_flow));
|
|
|
|
|
2015-12-24 10:02:49 +00:00
|
|
|
dflt_tx_flow.use_common_tx_conf_queue = 0;
|
2015-11-04 06:56:00 +00:00
|
|
|
err = dpni_set_tx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle, &priv->tx_flow_id,
|
|
|
|
&dflt_tx_flow);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_tx_flow() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-12-24 10:03:13 +00:00
|
|
|
memset(&tx_conf_cfg, 0, sizeof(struct dpni_tx_conf_cfg));
|
|
|
|
tx_conf_cfg.errors_only = true;
|
|
|
|
/*Set tx-conf and error configuration*/
|
|
|
|
err = dpni_set_tx_conf(dflt_mc_io, MC_CMD_NO_FLAGS,
|
|
|
|
dflt_dpni->dpni_handle,
|
|
|
|
priv->tx_flow_id, &tx_conf_cfg);
|
|
|
|
if (err) {
|
|
|
|
printf("dpni_set_tx_conf() failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-03-19 16:20:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
static int ldpaa_eth_netdev_init(struct eth_device *net_dev,
|
|
|
|
phy_interface_t enet_if)
|
2015-03-19 16:20:46 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
sprintf(net_dev->name, "DPMAC%d@%s", priv->dpmac_id,
|
|
|
|
phy_interface_strings[enet_if]);
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
net_dev->iobase = 0;
|
|
|
|
net_dev->init = ldpaa_eth_open;
|
|
|
|
net_dev->halt = ldpaa_eth_stop;
|
|
|
|
net_dev->send = ldpaa_eth_tx;
|
|
|
|
net_dev->recv = ldpaa_eth_pull_dequeue_rx;
|
|
|
|
|
2016-02-24 11:32:11 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
|
|
|
err = init_phy(net_dev);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
#endif
|
2015-03-19 16:20:46 +00:00
|
|
|
|
|
|
|
err = eth_register(net_dev);
|
|
|
|
if (err < 0) {
|
|
|
|
printf("eth_register() = %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
int ldpaa_eth_init(int dpmac_id, phy_interface_t enet_if)
|
2015-03-19 16:20:46 +00:00
|
|
|
{
|
|
|
|
struct eth_device *net_dev = NULL;
|
|
|
|
struct ldpaa_eth_priv *priv = NULL;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Net device */
|
|
|
|
net_dev = (struct eth_device *)malloc(sizeof(struct eth_device));
|
|
|
|
if (!net_dev) {
|
|
|
|
printf("eth_device malloc() failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memset(net_dev, 0, sizeof(struct eth_device));
|
|
|
|
|
|
|
|
/* alloc the ldpaa ethernet private struct */
|
|
|
|
priv = (struct ldpaa_eth_priv *)malloc(sizeof(struct ldpaa_eth_priv));
|
|
|
|
if (!priv) {
|
|
|
|
printf("ldpaa_eth_priv malloc() failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memset(priv, 0, sizeof(struct ldpaa_eth_priv));
|
|
|
|
|
|
|
|
net_dev->priv = (void *)priv;
|
|
|
|
priv->net_dev = (struct eth_device *)net_dev;
|
2015-11-04 06:56:00 +00:00
|
|
|
priv->dpmac_id = dpmac_id;
|
|
|
|
debug("%s dpmac_id=%d\n", __func__, dpmac_id);
|
2015-03-19 16:20:46 +00:00
|
|
|
|
2015-11-04 06:56:00 +00:00
|
|
|
err = ldpaa_eth_netdev_init(net_dev, enet_if);
|
2015-03-19 16:20:46 +00:00
|
|
|
if (err)
|
|
|
|
goto err_netdev_init;
|
|
|
|
|
|
|
|
debug("ldpaa ethernet: Probed interface %s\n", net_dev->name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_netdev_init:
|
|
|
|
free(priv);
|
|
|
|
net_dev->priv = NULL;
|
|
|
|
free(net_dev);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|