driver/ldpaa_eth: Update ldpaa ethernet driver

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>
Signed-off-by: York Sun <yorksun@freescale.com>
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 3bb9e5e..d4be1ba 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 @@
 	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);
@@ -63,6 +62,7 @@
 				    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 {
@@ -77,22 +77,29 @@
 	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
@@ -129,7 +136,6 @@
 	struct qbman_release_desc releasedesc;
 	struct qbman_swp *swp = dflt_dpio->sw_portal;
 
-	invalidate_dcache_all();
 	fd_addr = ldpaa_fd_get_addr(fd);
 
 
@@ -160,22 +166,29 @@
 	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;
 		}
 
+		do {
+			loop--;
+			dq = qbman_swp_dqrr_next(swp);
+
+			if (!loop)
+				break;
+		} while (!dq);
+
-		dq = qbman_swp_dqrr_next(swp);
 		if (dq) {
 			/* Check for valid frame. If not sent a consume
 			 * confirmation to QBMAN otherwise give it to NADK
@@ -230,7 +243,8 @@
 
 	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));
@@ -298,10 +312,10 @@
 
 #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;
@@ -362,7 +376,8 @@
 	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);
@@ -423,6 +438,8 @@
 			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);
@@ -624,10 +641,7 @@
 	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;