netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe
@ 2010-06-11 12:47 Jonas Bonn
  2010-06-11 12:47 ` [PATCH 2/7] ethoc: Write bus addresses to registers Jonas Bonn
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

This moves the calculation of the number of transmission buffers to
ethoc_probe where it more logically fits with the rest of the memory
allocation code.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 6ed2df1..68093cf 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -658,8 +658,6 @@ static int ethoc_mdio_probe(struct net_device *dev)
 static int ethoc_open(struct net_device *dev)
 {
 	struct ethoc *priv = netdev_priv(dev);
-	unsigned int min_tx = 2;
-	unsigned int num_bd;
 	int ret;
 
 	ret = request_irq(dev->irq, ethoc_interrupt, IRQF_SHARED,
@@ -667,11 +665,6 @@ static int ethoc_open(struct net_device *dev)
 	if (ret)
 		return ret;
 
-	/* calculate the number of TX/RX buffers, maximum 128 supported */
-	num_bd = min_t(unsigned int,
-		128, (dev->mem_end - dev->mem_start + 1) / ETHOC_BUFSIZ);
-	priv->num_tx = max(min_tx, num_bd / 4);
-	priv->num_rx = num_bd - priv->num_tx;
 	ethoc_write(priv, TX_BD_NUM, priv->num_tx);
 
 	ethoc_init_ring(priv);
@@ -884,6 +877,7 @@ static int ethoc_probe(struct platform_device *pdev)
 	struct resource *mem = NULL;
 	struct ethoc *priv = NULL;
 	unsigned int phy;
+	int num_bd;
 	int ret = 0;
 
 	/* allocate networking device */
@@ -978,6 +972,12 @@ static int ethoc_probe(struct platform_device *pdev)
 		priv->dma_alloc = buffer_size;
 	}
 
+	/* calculate the number of TX/RX buffers, maximum 128 supported */
+	num_bd = min_t(unsigned int,
+		128, (netdev->mem_end - netdev->mem_start + 1) / ETHOC_BUFSIZ);
+	priv->num_tx = max(2, num_bd / 4);
+	priv->num_rx = num_bd - priv->num_tx;
+
 	/* Allow the platform setup code to pass in a MAC address. */
 	if (pdev->dev.platform_data) {
 		struct ethoc_platform_data *pdata =
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] ethoc: Write bus addresses to registers
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 12:47 ` [PATCH 3/7] ethoc: write number of TX buffers in init_ring Jonas Bonn
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

The ethoc driver should be writing bus addresses to the ethoc registers, not
virtual addresses.  This patch adds an array to store the virtual addresses
in and references that array when manipulating the contents of the buffer
descriptors.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 68093cf..5904ad2 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -180,6 +180,7 @@ MODULE_PARM_DESC(buffer_size, "DMA buffer allocation size");
  * @dty_tx:	last buffer actually sent
  * @num_rx:	number of receive buffers
  * @cur_rx:	current receive buffer
+ * @vma:        pointer to array of virtual memory addresses for buffers
  * @netdev:	pointer to network device structure
  * @napi:	NAPI structure
  * @stats:	network device statistics
@@ -203,6 +204,8 @@ struct ethoc {
 	unsigned int num_rx;
 	unsigned int cur_rx;
 
+	void** vma;
+
 	struct net_device *netdev;
 	struct napi_struct napi;
 	struct net_device_stats stats;
@@ -285,18 +288,20 @@ static inline void ethoc_disable_rx_and_tx(struct ethoc *dev)
 	ethoc_write(dev, MODER, mode);
 }
 
-static int ethoc_init_ring(struct ethoc *dev)
+static int ethoc_init_ring(struct ethoc *dev, void* mem_start)
 {
 	struct ethoc_bd bd;
 	int i;
+	void* vma;
 
 	dev->cur_tx = 0;
 	dev->dty_tx = 0;
 	dev->cur_rx = 0;
 
 	/* setup transmission buffers */
-	bd.addr = virt_to_phys(dev->membase);
+	bd.addr = mem_start;
 	bd.stat = TX_BD_IRQ | TX_BD_CRC;
+	vma = dev->membase;
 
 	for (i = 0; i < dev->num_tx; i++) {
 		if (i == dev->num_tx - 1)
@@ -304,6 +309,9 @@ static int ethoc_init_ring(struct ethoc *dev)
 
 		ethoc_write_bd(dev, i, &bd);
 		bd.addr += ETHOC_BUFSIZ;
+
+		dev->vma[i] = vma;
+		vma += ETHOC_BUFSIZ;
 	}
 
 	bd.stat = RX_BD_EMPTY | RX_BD_IRQ;
@@ -314,6 +322,9 @@ static int ethoc_init_ring(struct ethoc *dev)
 
 		ethoc_write_bd(dev, dev->num_tx + i, &bd);
 		bd.addr += ETHOC_BUFSIZ;
+
+		dev->vma[dev->num_tx + i] = vma;
+		vma += ETHOC_BUFSIZ;
 	}
 
 	return 0;
@@ -415,7 +426,7 @@ static int ethoc_rx(struct net_device *dev, int limit)
 			skb = netdev_alloc_skb_ip_align(dev, size);
 
 			if (likely(skb)) {
-				void *src = phys_to_virt(bd.addr);
+				void *src = priv->vma[entry];
 				memcpy_fromio(skb_put(skb, size), src, size);
 				skb->protocol = eth_type_trans(skb, dev);
 				priv->stats.rx_packets++;
@@ -667,7 +678,7 @@ static int ethoc_open(struct net_device *dev)
 
 	ethoc_write(priv, TX_BD_NUM, priv->num_tx);
 
-	ethoc_init_ring(priv);
+	ethoc_init_ring(priv, (void*)dev->mem_start);
 	ethoc_reset(priv);
 
 	if (netif_queue_stopped(dev)) {
@@ -831,7 +842,7 @@ static netdev_tx_t ethoc_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	else
 		bd.stat &= ~TX_BD_PAD;
 
-	dest = phys_to_virt(bd.addr);
+	dest = priv->vma[entry];
 	memcpy_toio(dest, skb->data, skb->len);
 
 	bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK);
@@ -978,6 +989,12 @@ static int ethoc_probe(struct platform_device *pdev)
 	priv->num_tx = max(2, num_bd / 4);
 	priv->num_rx = num_bd - priv->num_tx;
 
+	priv->vma = devm_kzalloc(&pdev->dev, num_bd*sizeof(void*), GFP_KERNEL);
+	if (!priv->vma) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
 	/* Allow the platform setup code to pass in a MAC address. */
 	if (pdev->dev.platform_data) {
 		struct ethoc_platform_data *pdata =
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] ethoc: write number of TX buffers in init_ring
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
  2010-06-11 12:47 ` [PATCH 2/7] ethoc: Write bus addresses to registers Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 12:47 ` [PATCH 4/7] ethoc: Clean up PHY probing Jonas Bonn
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

This moves the write of the TX_BD_NUM to init_ring together with the
rest of the code setting up the transmission buffers.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 5904ad2..afeb993 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -298,6 +298,8 @@ static int ethoc_init_ring(struct ethoc *dev, void* mem_start)
 	dev->dty_tx = 0;
 	dev->cur_rx = 0;
 
+	ethoc_write(dev, TX_BD_NUM, dev->num_tx);
+
 	/* setup transmission buffers */
 	bd.addr = mem_start;
 	bd.stat = TX_BD_IRQ | TX_BD_CRC;
@@ -676,8 +678,6 @@ static int ethoc_open(struct net_device *dev)
 	if (ret)
 		return ret;
 
-	ethoc_write(priv, TX_BD_NUM, priv->num_tx);
-
 	ethoc_init_ring(priv, (void*)dev->mem_start);
 	ethoc_reset(priv);
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] ethoc: Clean up PHY probing
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
  2010-06-11 12:47 ` [PATCH 2/7] ethoc: Write bus addresses to registers Jonas Bonn
  2010-06-11 12:47 ` [PATCH 3/7] ethoc: write number of TX buffers in init_ring Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 12:47 ` [PATCH 5/7] Remove unused variable Jonas Bonn
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

- No need to iterate over all possible addresses on bus
- Use helper function phy_find_first
- Use phy_connect_direct as we already have the relevant structure

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |   24 ++++++++----------------
 1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index afeb993..1ee9947 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -635,21 +635,13 @@ static int ethoc_mdio_probe(struct net_device *dev)
 {
 	struct ethoc *priv = netdev_priv(dev);
 	struct phy_device *phy;
+	int err;
 	int i;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++) {
-		phy = priv->mdio->phy_map[i];
-		if (phy) {
-			if (priv->phy_id != -1) {
-				/* attach to specified PHY */
-				if (priv->phy_id == phy->addr)
-					break;
-			} else {
-				/* autoselect PHY if none was specified */
-				if (phy->addr != 0)
-					break;
-			}
-		}
+	if (priv->phy_id != -1) {
+		phy = priv->mdio->phy_map[priv->phy_id];
+	} else {
+		phy = phy_find_first(priv->mdio);
 	}
 
 	if (!phy) {
@@ -657,11 +649,11 @@ static int ethoc_mdio_probe(struct net_device *dev)
 		return -ENXIO;
 	}
 
-	phy = phy_connect(dev, dev_name(&phy->dev), ethoc_mdio_poll, 0,
+	err = phy_connect_direct(dev, phy, ethoc_mdio_poll, 0,
 			PHY_INTERFACE_MODE_GMII);
-	if (IS_ERR(phy)) {
+	if (err) {
 		dev_err(&dev->dev, "could not attach to PHY\n");
-		return PTR_ERR(phy);
+		return err;
 	}
 
 	priv->phy = phy;
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] Remove unused variable
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
                   ` (2 preceding siblings ...)
  2010-06-11 12:47 ` [PATCH 4/7] ethoc: Clean up PHY probing Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 12:47 ` [PATCH 6/7] ethoc: Clear command buffer after write Jonas Bonn
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn


Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 1ee9947..e5c2f5b 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -636,7 +636,6 @@ static int ethoc_mdio_probe(struct net_device *dev)
 	struct ethoc *priv = netdev_priv(dev);
 	struct phy_device *phy;
 	int err;
-	int i;
 
 	if (priv->phy_id != -1) {
 		phy = priv->mdio->phy_map[priv->phy_id];
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] ethoc: Clear command buffer after write
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
                   ` (3 preceding siblings ...)
  2010-06-11 12:47 ` [PATCH 5/7] Remove unused variable Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 12:47 ` [PATCH 7/7] ethoc: use devres resource management Jonas Bonn
  2010-06-11 20:29 ` [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

This matches what ethoc_mdio_read does and makes the functions
symmetric.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index e5c2f5b..1681f08 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -613,8 +613,11 @@ static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
 
 	while (time_before(jiffies, timeout)) {
 		u32 stat = ethoc_read(priv, MIISTATUS);
-		if (!(stat & MIISTATUS_BUSY))
+		if (!(stat & MIISTATUS_BUSY)) {
+			/* reset MII command register */
+			ethoc_write(priv, MIICOMMAND, 0);
 			return 0;
+		}
 
 		schedule();
 	}
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] ethoc: use devres resource management
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
                   ` (4 preceding siblings ...)
  2010-06-11 12:47 ` [PATCH 6/7] ethoc: Clear command buffer after write Jonas Bonn
@ 2010-06-11 12:47 ` Jonas Bonn
  2010-06-11 20:29 ` [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2010-06-11 12:47 UTC (permalink / raw)
  To: netdev; +Cc: Jonas Bonn

The point of using the devres resource management routines is that they
simplify the driver by taking care of releasing resources on failure and
release.  A recent commit added a bunch of error handling that is unnecessary
in this context.

This patch removes this redundant error handling, as well as using
dmam_alloc_coherent in place of dma_alloc_coherent in order to use this
framework consistenly throughout the driver.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
---
 drivers/net/ethoc.c |   28 +---------------------------
 1 files changed, 1 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index 1681f08..37ce8ac 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -964,7 +964,7 @@ static int ethoc_probe(struct platform_device *pdev)
 		}
 	} else {
 		/* Allocate buffer memory */
-		priv->membase = dma_alloc_coherent(NULL,
+		priv->membase = dmam_alloc_coherent(&pdev->dev,
 			buffer_size, (void *)&netdev->mem_start,
 			GFP_KERNEL);
 		if (!priv->membase) {
@@ -1074,21 +1074,6 @@ free_mdio:
 	kfree(priv->mdio->irq);
 	mdiobus_free(priv->mdio);
 free:
-	if (priv) {
-		if (priv->dma_alloc)
-			dma_free_coherent(NULL, priv->dma_alloc, priv->membase,
-					  netdev->mem_start);
-		else if (priv->membase)
-			devm_iounmap(&pdev->dev, priv->membase);
-		if (priv->iobase)
-			devm_iounmap(&pdev->dev, priv->iobase);
-	}
-	if (mem)
-		devm_release_mem_region(&pdev->dev, mem->start,
-					mem->end - mem->start + 1);
-	if (mmio)
-		devm_release_mem_region(&pdev->dev, mmio->start,
-					mmio->end - mmio->start + 1);
 	free_netdev(netdev);
 out:
 	return ret;
@@ -1115,17 +1100,6 @@ static int ethoc_remove(struct platform_device *pdev)
 			kfree(priv->mdio->irq);
 			mdiobus_free(priv->mdio);
 		}
-		if (priv->dma_alloc)
-			dma_free_coherent(NULL, priv->dma_alloc, priv->membase,
-				netdev->mem_start);
-		else {
-			devm_iounmap(&pdev->dev, priv->membase);
-			devm_release_mem_region(&pdev->dev, netdev->mem_start,
-				netdev->mem_end - netdev->mem_start + 1);
-		}
-		devm_iounmap(&pdev->dev, priv->iobase);
-		devm_release_mem_region(&pdev->dev, netdev->base_addr,
-			priv->io_region_size);
 		unregister_netdev(netdev);
 		free_netdev(netdev);
 	}
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe
  2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
                   ` (5 preceding siblings ...)
  2010-06-11 12:47 ` [PATCH 7/7] ethoc: use devres resource management Jonas Bonn
@ 2010-06-11 20:29 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2010-06-11 20:29 UTC (permalink / raw)
  To: jonas; +Cc: netdev


I've applied all 7 patches to net-next-2.6, thanks Jonas.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-06-11 20:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-11 12:47 [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe Jonas Bonn
2010-06-11 12:47 ` [PATCH 2/7] ethoc: Write bus addresses to registers Jonas Bonn
2010-06-11 12:47 ` [PATCH 3/7] ethoc: write number of TX buffers in init_ring Jonas Bonn
2010-06-11 12:47 ` [PATCH 4/7] ethoc: Clean up PHY probing Jonas Bonn
2010-06-11 12:47 ` [PATCH 5/7] Remove unused variable Jonas Bonn
2010-06-11 12:47 ` [PATCH 6/7] ethoc: Clear command buffer after write Jonas Bonn
2010-06-11 12:47 ` [PATCH 7/7] ethoc: use devres resource management Jonas Bonn
2010-06-11 20:29 ` [PATCH 1/7] ethoc: calculate number of buffers in ethoc_probe David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).