[U-Boot] [PATCH 11/28] driver/ldpaa_eth: Update ldpaa ethernet driver

York Sun
2015-03-19T16:45:42Z

From: Prabhakar Kushwaha <prabhakar@freescale.com>

Fix flush_dcache_range() input parameter to use start and end addresses.
Change ethernet interface name to DPNI. Update entry criteria for
ldpaa_eth_stop. Ethernet stack first stop the device before performing
next operation. At the time of Ethernet driver registration,
net_dev->state is set as ETH_STATE_INIT So take care net_dev->state as
ETH_STATE_INIT in ldpaa_eth_stop.

Undef CONFIG_PHYLIB temorarily because ldpaa_eth driver currently does
not support PHYLIB.

Instead of clearing pull descriptor one time, clear it before issuing any
volatile dequeue command.

Volatile command does not return frame immidiately, wait till a frame
is available in DQRR. This frame can be valid or expired.

Flush buffer before releasing to BMan ensure the core does not have any
cachelines that the WRIOP will DMA to.

Signed-off-by: Prabhakar Kushwaha <prabhakar@freescale.com>
Signed-off-by: pankaj chauhan <pankaj.chauhan@freescale.com>
Signed-off-by: Roy Pledge <Roy.Pledge@freescale.com>
---
drivers/net/ldpaa_eth/ldpaa_eth.c | 62 +++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index b79942f..9015e4f 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -15,6 +15,7 @@

#include "ldpaa_eth.h"

+#undef CONFIG_PHYLIB
static int init_phy(struct eth_device *dev)
{
/*TODO for external PHY */
@@ -33,8 +34,6 @@ static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
struct qbman_release_desc releasedesc;
struct qbman_swp *swp = dflt_dpio->sw_portal;

- invalidate_dcache_all();
-
fd_addr = ldpaa_fd_get_addr(fd);
fd_offset = ldpaa_fd_get_offset(fd);
fd_length = ldpaa_fd_get_len(fd);
@@ -62,6 +61,7 @@ static void ldpaa_eth_rx(struct ldpaa_eth_priv *priv,
NetReceive((uint8_t *)(fd_addr) + fd_offset, fd_length);

error:
+ flush_dcache_range(fd_addr, fd_addr + LDPAA_ETH_RX_BUFFER_SIZE);
qbman_release_desc_clear(&releasedesc);
qbman_release_desc_set_bpid(&releasedesc, dflt_dpbp->dpbp_attr.bpid);
do {
@@ -76,22 +76,29 @@ 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;
- int i = 5, err = 0, status;
+ int i = 5, err = 0, status, loop = 20;
static struct qbman_pull_desc pulldesc;
struct qbman_swp *swp = dflt_dpio->sw_portal;

- qbman_pull_desc_clear(&pulldesc);
- qbman_pull_desc_set_numframes(&pulldesc, 1);
- qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
-
while (--i) {
+ qbman_pull_desc_clear(&pulldesc);
+ qbman_pull_desc_set_numframes(&pulldesc, 1);
+ qbman_pull_desc_set_fq(&pulldesc, priv->rx_dflt_fqid);
+
err = qbman_swp_pull(swp, &pulldesc);
if (err < 0) {
printf("Dequeue frames error:0x%08x\n", err);
continue;
}

- dq = qbman_swp_dqrr_next(swp);
+ do {
+ loop--;
+ dq = qbman_swp_dqrr_next(swp);
+
+ if (!loop)
+ break;
+ } while (!dq);
+
if (dq) {
/* Check for valid frame. If not sent a consume
* confirmation to QBMAN otherwise give it to NADK
@@ -128,7 +135,6 @@ static void ldpaa_eth_tx_conf(struct ldpaa_eth_priv *priv,
struct qbman_release_desc releasedesc;
struct qbman_swp *swp = dflt_dpio->sw_portal;

- invalidate_dcache_all();
fd_addr = ldpaa_fd_get_addr(fd);

@@ -159,22 +165,29 @@ static int ldpaa_eth_pull_dequeue_tx_conf(struct ldpaa_eth_priv *priv)
const struct ldpaa_dq *dq;
const struct dpaa_fd *fd;
int err = 0;
- int i = 5, status;
+ int i = 5, status, loop = 20;
static struct qbman_pull_desc pulldesc;
struct qbman_swp *swp = dflt_dpio->sw_portal;

- qbman_pull_desc_clear(&pulldesc);
- qbman_pull_desc_set_numframes(&pulldesc, 1);
- qbman_pull_desc_set_fq(&pulldesc, priv->tx_conf_fqid);
-
while (--i) {
+ qbman_pull_desc_clear(&pulldesc);
+ qbman_pull_desc_set_numframes(&pulldesc, 1);
+ qbman_pull_desc_set_fq(&pulldesc, priv->tx_conf_fqid);
+
err = qbman_swp_pull(swp, &pulldesc);
if (err < 0) {
printf("Dequeue TX conf frames error:0x%08x\n", err);
continue;
}

- dq = qbman_swp_dqrr_next(swp);
+ do {
+ loop--;
+ dq = qbman_swp_dqrr_next(swp);
+
+ if (!loop)
+ break;
+ } while (!dq);
+
if (dq) {
/* Check for valid frame. If not sent a consume
* confirmation to QBMAN otherwise give it to NADK
@@ -229,7 +242,8 @@ static int ldpaa_eth_tx(struct eth_device *net_dev, void *buf, int len)

memcpy(((uint8_t *)(buffer_start) + data_offset), buf, len);

- flush_dcache_range(buffer_start, LDPAA_ETH_RX_BUFFER_SIZE);
+ flush_dcache_range(buffer_start, buffer_start +
+ LDPAA_ETH_RX_BUFFER_SIZE);

ldpaa_fd_set_addr(&fd, (u64)buffer_start);
ldpaa_fd_set_offset(&fd, (uint16_t)(data_offset));
@@ -297,10 +311,10 @@ static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)

#ifdef CONFIG_PHYLIB
/* TODO Check this path */
- ret = phy_startup(priv->phydev);
- if (ret) {
+ err = phy_startup(priv->phydev);
+ if (err) {
printf("%s: Could not initialize\n", priv->phydev->dev->name);
- return ret;
+ return err;
}
#else
priv->phydev->speed = SPEED_1000;
@@ -361,7 +375,8 @@ 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;

- if (net_dev->state == ETH_STATE_PASSIVE)
+ if ((net_dev->state == ETH_STATE_PASSIVE) ||
+ (net_dev->state == ETH_STATE_INIT))
return;
/* Stop Tx and Rx traffic */
err = dpni_disable(dflt_mc_io, priv->dpni_handle);
@@ -422,6 +437,8 @@ static int ldpaa_bp_add_7(uint16_t bpid)
goto err_alloc;
}
memset(addr, 0x00, LDPAA_ETH_RX_BUFFER_SIZE);
+ flush_dcache_range((u64)addr,
+ (u64)(addr + LDPAA_ETH_RX_BUFFER_SIZE));

buf_array[i] = (uint64_t)addr;
debug("Release: buffer addr =0x%p\n", addr);
@@ -623,10 +640,7 @@ static int ldpaa_eth_netdev_init(struct eth_device *net_dev)
int err;
struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;

- if (priv->type == LDPAA_ETH_1G_E)
- sprintf(net_dev->name, "DTSEC%d", priv->dpni_id);
- else
- sprintf(net_dev->name, "TGEC%d", priv->dpni_id);
+ sprintf(net_dev->name, "DPNI%d", priv->dpni_id);

net_dev->iobase = 0;
net_dev->init = ldpaa_eth_open;
--
1.7.9.5