netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/0] cpmac: update to the net subsystem changes
@ 2007-10-24  2:42 Eugene Konev
       [not found] ` <5070e5ddd7ae0681b14e712980d830225a2103aa.1193191283.git.ejka@imfi.kspu.ru>
  0 siblings, 1 reply; 5+ messages in thread
From: Eugene Konev @ 2007-10-24  2:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Matteo Croce, netdev

This patchset includes cpmac updates for changed net subsystem interfaces.
Please accept the following patches for cpmac driver:
  1. cpmac: use print_mac() instead of MAC_FMT
  2. cpmac: convert to napi_struct interface
  3. cpmac: update to new fixed phy driver interface

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

* [PATCH 1/3] cpmac: use print_mac() instead of MAC_FMT
       [not found] ` <5070e5ddd7ae0681b14e712980d830225a2103aa.1193191283.git.ejka@imfi.kspu.ru>
@ 2007-10-24  2:42   ` Eugene Konev
  2007-10-25  7:32     ` Jeff Garzik
       [not found]   ` <ad70799b9f985de8e07528f3d9fd65081416efca.1193191283.git.ejka@imfi.kspu.ru>
       [not found]   ` <6a2c62ba4fb9c80b4a4a957168183fbe35775740.1193191283.git.ejka@imfi.kspu.ru>
  2 siblings, 1 reply; 5+ messages in thread
From: Eugene Konev @ 2007-10-24  2:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Matteo Croce, netdev, Eugene Konev

Switch to using DECLARE_MAC_BUF/print_mac() added by commit
0795af5729b18218767fab27c44b1384f72dc9ad [NET]: Introduce and use print_mac()
and DECLARE_MAC_BUF().


Signed-off-by: Eugene Konev <ejka@imfi.kspu.ru>
---
 drivers/net/cpmac.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 57541d2..0598d4d 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -53,12 +53,6 @@ MODULE_PARM_DESC(debug_level, "Number of NETIF_MSG bits to enable");
 MODULE_PARM_DESC(dumb_switch, "Assume switch is not connected to MDIO bus");
 
 #define CPMAC_VERSION "0.5.0"
-/* stolen from net/ieee80211.h */
-#ifndef MAC_FMT
-#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
-#define MAC_ARG(x) ((u8*)(x))[0], ((u8*)(x))[1], ((u8*)(x))[2], \
-		   ((u8*)(x))[3], ((u8*)(x))[4], ((u8*)(x))[5]
-#endif
 /* frame size + 802.1q tag */
 #define CPMAC_SKB_SIZE		(ETH_FRAME_LEN + 4)
 #define CPMAC_QUEUES	8
@@ -1006,6 +1000,7 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
 	struct cpmac_priv *priv;
 	struct net_device *dev;
 	struct plat_cpmac_data *pdata;
+	DECLARE_MAC_BUF(mac);
 
 	pdata = pdev->dev.platform_data;
 
@@ -1077,9 +1072,9 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
 
 	if (netif_msg_probe(priv)) {
 		printk(KERN_INFO
-		       "cpmac: device %s (regs: %p, irq: %d, phy: %s, mac: "
-		       MAC_FMT ")\n", dev->name, (void *)mem->start, dev->irq,
-		       priv->phy_name, MAC_ARG(dev->dev_addr));
+		       "cpmac: device %s (regs: %p, irq: %d, phy: %s, "
+		       "mac: %s)\n", dev->name, (void *)mem->start, dev->irq,
+		       priv->phy_name, print_mac(mac, dev->dev_addr));
 	}
 	return 0;
 
-- 
1.5.3.4


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

* [PATCH 2/3] cpmac: convert to napi_struct interface
       [not found]   ` <ad70799b9f985de8e07528f3d9fd65081416efca.1193191283.git.ejka@imfi.kspu.ru>
@ 2007-10-24  2:42     ` Eugene Konev
  0 siblings, 0 replies; 5+ messages in thread
From: Eugene Konev @ 2007-10-24  2:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Matteo Croce, netdev, Eugene Konev

Convert cpmac to new napi_struct API introduced by
bea3348eef27e6044b6161fd04c3152215f96411 [NET]: Make NAPI polling independent
of struct net_device objects.
Only disable rx interrupts if napi actually has been scheduled.

Signed-off-by: Eugene Konev <ejka@imfi.kspu.ru>
---
 drivers/net/cpmac.c |   68 +++++++++++++++++++++++++++-----------------------
 1 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 0598d4d..486c82b 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -205,6 +205,7 @@ struct cpmac_priv {
 	struct net_device *dev;
 	struct work_struct reset_work;
 	struct platform_device *pdev;
+	struct napi_struct napi;
 };
 
 static irqreturn_t cpmac_irq(int, void *);
@@ -356,47 +357,48 @@ static void cpmac_set_multicast_list(struct net_device *dev)
 	}
 }
 
-static struct sk_buff *cpmac_rx_one(struct net_device *dev,
-				    struct cpmac_priv *priv,
+static struct sk_buff *cpmac_rx_one(struct cpmac_priv *priv,
 				    struct cpmac_desc *desc)
 {
 	struct sk_buff *skb, *result = NULL;
 
 	if (unlikely(netif_msg_hw(priv)))
-		cpmac_dump_desc(dev, desc);
+		cpmac_dump_desc(priv->dev, desc);
 	cpmac_write(priv->regs, CPMAC_RX_ACK(0), (u32)desc->mapping);
 	if (unlikely(!desc->datalen)) {
 		if (netif_msg_rx_err(priv) && net_ratelimit())
 			printk(KERN_WARNING "%s: rx: spurious interrupt\n",
-			       dev->name);
+			       priv->dev->name);
 		return NULL;
 	}
 
-	skb = netdev_alloc_skb(dev, CPMAC_SKB_SIZE);
+	skb = netdev_alloc_skb(priv->dev, CPMAC_SKB_SIZE);
 	if (likely(skb)) {
 		skb_reserve(skb, 2);
 		skb_put(desc->skb, desc->datalen);
-		desc->skb->protocol = eth_type_trans(desc->skb, dev);
+		desc->skb->protocol = eth_type_trans(desc->skb, priv->dev);
 		desc->skb->ip_summed = CHECKSUM_NONE;
-		dev->stats.rx_packets++;
-		dev->stats.rx_bytes += desc->datalen;
+		priv->dev->stats.rx_packets++;
+		priv->dev->stats.rx_bytes += desc->datalen;
 		result = desc->skb;
-		dma_unmap_single(&dev->dev, desc->data_mapping, CPMAC_SKB_SIZE,
-				 DMA_FROM_DEVICE);
+		dma_unmap_single(&priv->dev->dev, desc->data_mapping,
+				 CPMAC_SKB_SIZE, DMA_FROM_DEVICE);
 		desc->skb = skb;
-		desc->data_mapping = dma_map_single(&dev->dev, skb->data,
+		desc->data_mapping = dma_map_single(&priv->dev->dev, skb->data,
 						    CPMAC_SKB_SIZE,
 						    DMA_FROM_DEVICE);
 		desc->hw_data = (u32)desc->data_mapping;
 		if (unlikely(netif_msg_pktdata(priv))) {
-			printk(KERN_DEBUG "%s: received packet:\n", dev->name);
-			cpmac_dump_skb(dev, result);
+			printk(KERN_DEBUG "%s: received packet:\n",
+			       priv->dev->name);
+			cpmac_dump_skb(priv->dev, result);
 		}
 	} else {
 		if (netif_msg_rx_err(priv) && net_ratelimit())
 			printk(KERN_WARNING
-			       "%s: low on skbs, dropping packet\n", dev->name);
-		dev->stats.rx_dropped++;
+			       "%s: low on skbs, dropping packet\n",
+			       priv->dev->name);
+		priv->dev->stats.rx_dropped++;
 	}
 
 	desc->buflen = CPMAC_SKB_SIZE;
@@ -405,25 +407,25 @@ static struct sk_buff *cpmac_rx_one(struct net_device *dev,
 	return result;
 }
 
-static int cpmac_poll(struct net_device *dev, int *budget)
+static int cpmac_poll(struct napi_struct *napi, int budget)
 {
 	struct sk_buff *skb;
 	struct cpmac_desc *desc;
-	int received = 0, quota = min(dev->quota, *budget);
-	struct cpmac_priv *priv = netdev_priv(dev);
+	int received = 0;
+	struct cpmac_priv *priv = container_of(napi, struct cpmac_priv, napi);
 
 	spin_lock(&priv->rx_lock);
 	if (unlikely(!priv->rx_head)) {
 		if (netif_msg_rx_err(priv) && net_ratelimit())
 			printk(KERN_WARNING "%s: rx: polling, but no queue\n",
-			       dev->name);
-		netif_rx_complete(dev);
+			       priv->dev->name);
+		netif_rx_complete(priv->dev, napi);
 		return 0;
 	}
 
 	desc = priv->rx_head;
-	while ((received < quota) && ((desc->dataflags & CPMAC_OWN) == 0)) {
-		skb = cpmac_rx_one(dev, priv, desc);
+	while (((desc->dataflags & CPMAC_OWN) == 0) && (received < budget)) {
+		skb = cpmac_rx_one(priv, desc);
 		if (likely(skb)) {
 			netif_receive_skb(skb);
 			received++;
@@ -433,13 +435,11 @@ static int cpmac_poll(struct net_device *dev, int *budget)
 
 	priv->rx_head = desc;
 	spin_unlock(&priv->rx_lock);
-	*budget -= received;
-	dev->quota -= received;
 	if (unlikely(netif_msg_rx_status(priv)))
-		printk(KERN_DEBUG "%s: poll processed %d packets\n", dev->name,
-		       received);
+		printk(KERN_DEBUG "%s: poll processed %d packets\n",
+		       priv->dev->name, received);
 	if (desc->dataflags & CPMAC_OWN) {
-		netif_rx_complete(dev);
+		netif_rx_complete(priv->dev, napi);
 		cpmac_write(priv->regs, CPMAC_RX_PTR(0), (u32)desc->mapping);
 		cpmac_write(priv->regs, CPMAC_RX_INT_ENABLE, 1);
 		return 0;
@@ -649,6 +649,7 @@ static void cpmac_hw_error(struct work_struct *work)
 	spin_unlock(&priv->rx_lock);
 	cpmac_clear_tx(priv->dev);
 	cpmac_hw_start(priv->dev);
+	napi_enable(&priv->napi);
 	netif_start_queue(priv->dev);
 }
 
@@ -675,8 +676,10 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id)
 
 	if (status & MAC_INT_RX) {
 		queue = (status >> 8) & 7;
-		netif_rx_schedule(dev);
-		cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue);
+		if (netif_rx_schedule_prep(dev, &priv->napi)) {
+			cpmac_write(priv->regs, CPMAC_RX_INT_CLEAR, 1 << queue);
+			__netif_rx_schedule(dev, &priv->napi);
+		}
 	}
 
 	cpmac_write(priv->regs, CPMAC_MAC_EOI_VECTOR, 0);
@@ -686,6 +689,7 @@ static irqreturn_t cpmac_irq(int irq, void *dev_id)
 			printk(KERN_ERR "%s: hw error, resetting...\n",
 			       dev->name);
 		netif_stop_queue(dev);
+		napi_disable(&priv->napi);
 		cpmac_hw_stop(dev);
 		schedule_work(&priv->reset_work);
 		if (unlikely(netif_msg_hw(priv)))
@@ -921,6 +925,7 @@ static int cpmac_open(struct net_device *dev)
 	INIT_WORK(&priv->reset_work, cpmac_hw_error);
 	cpmac_hw_start(dev);
 
+	napi_enable(&priv->napi);
 	priv->phy->state = PHY_CHANGELINK;
 	phy_start(priv->phy);
 
@@ -959,6 +964,7 @@ static int cpmac_stop(struct net_device *dev)
 	netif_stop_queue(dev);
 
 	cancel_work_sync(&priv->reset_work);
+	napi_disable(&priv->napi);
 	phy_stop(priv->phy);
 	phy_disconnect(priv->phy);
 	priv->phy = NULL;
@@ -1048,10 +1054,10 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
 	dev->set_multicast_list = cpmac_set_multicast_list;
 	dev->tx_timeout         = cpmac_tx_timeout;
 	dev->ethtool_ops        = &cpmac_ethtool_ops;
-	dev->poll = cpmac_poll;
-	dev->weight = 64;
 	dev->features |= NETIF_F_MULTI_QUEUE;
 
+	netif_napi_add(dev, &priv->napi, cpmac_poll, 64);
+
 	spin_lock_init(&priv->lock);
 	spin_lock_init(&priv->rx_lock);
 	priv->dev = dev;
-- 
1.5.3.4


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

* [PATCH 3/3] cpmac: update to new fixed phy driver interface
       [not found]   ` <6a2c62ba4fb9c80b4a4a957168183fbe35775740.1193191283.git.ejka@imfi.kspu.ru>
@ 2007-10-24  2:42     ` Eugene Konev
  0 siblings, 0 replies; 5+ messages in thread
From: Eugene Konev @ 2007-10-24  2:42 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Matteo Croce, netdev, Eugene Konev

Use fixed_mdio_get_phydev for obtaining fixed phy instances and adopt to
changed fixed phy device naming.

Signed-off-by: Eugene Konev <ejka@imfi.kspu.ru>
---
 drivers/net/cpmac.c |   64 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 486c82b..6fd95a2 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -34,6 +34,7 @@
 #include <linux/skbuff.h>
 #include <linux/mii.h>
 #include <linux/phy.h>
+#include <linux/phy_fixed.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <asm/gpio.h>
@@ -847,6 +848,15 @@ static void cpmac_adjust_link(struct net_device *dev)
 	spin_unlock(&priv->lock);
 }
 
+static int cpmac_link_update(struct net_device *dev,
+			     struct fixed_phy_status *status)
+{
+	status->link = 1;
+	status->speed = 100;
+	status->duplex = 1;
+	return 0;
+}
+
 static int cpmac_open(struct net_device *dev)
 {
 	int i, size, res;
@@ -855,15 +865,6 @@ static int cpmac_open(struct net_device *dev)
 	struct cpmac_desc *desc;
 	struct sk_buff *skb;
 
-	priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link,
-				0, PHY_INTERFACE_MODE_MII);
-	if (IS_ERR(priv->phy)) {
-		if (netif_msg_drv(priv))
-			printk(KERN_ERR "%s: Could not attach to PHY\n",
-			       dev->name);
-		return PTR_ERR(priv->phy);
-	}
-
 	mem = platform_get_resource_byname(priv->pdev, IORESOURCE_MEM, "regs");
 	if (!request_mem_region(mem->start, mem->end - mem->start, dev->name)) {
 		if (netif_msg_drv(priv))
@@ -950,8 +951,6 @@ fail_remap:
 	release_mem_region(mem->start, mem->end - mem->start);
 
 fail_reserve:
-	phy_disconnect(priv->phy);
-
 	return res;
 }
 
@@ -966,8 +965,6 @@ static int cpmac_stop(struct net_device *dev)
 	cancel_work_sync(&priv->reset_work);
 	napi_disable(&priv->napi);
 	phy_stop(priv->phy);
-	phy_disconnect(priv->phy);
-	priv->phy = NULL;
 
 	cpmac_hw_stop(dev);
 
@@ -1001,11 +998,12 @@ static int external_switch;
 
 static int __devinit cpmac_probe(struct platform_device *pdev)
 {
-	int rc, phy_id;
+	int rc, phy_id, i;
 	struct resource *mem;
 	struct cpmac_priv *priv;
 	struct net_device *dev;
 	struct plat_cpmac_data *pdata;
+	struct fixed_info *fixed_phy;
 	DECLARE_MAC_BUF(mac);
 
 	pdata = pdev->dev.platform_data;
@@ -1064,11 +1062,41 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
 	priv->ring_size = 64;
 	priv->msg_enable = netif_msg_init(debug_level, 0xff);
 	memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
+
 	if (phy_id == 31) {
-		snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT,
-			 cpmac_mii.id, phy_id);
-	} else
-		snprintf(priv->phy_name, BUS_ID_SIZE, "fixed@%d:%d", 100, 1);
+		snprintf(priv->phy_name, BUS_ID_SIZE, PHY_ID_FMT, cpmac_mii.id,
+			 phy_id);
+	} else {
+		/* Let's try to get a free fixed phy... */
+		for (i = 0; i < MAX_PHY_AMNT; i++) {
+			fixed_phy = fixed_mdio_get_phydev(i);
+			if (!fixed_phy)
+				continue;
+			if (!fixed_phy->phydev->attached_dev) {
+				strncpy(priv->phy_name,
+					fixed_phy->phydev->dev.bus_id,
+					BUS_ID_SIZE);
+				fixed_mdio_set_link_update(fixed_phy->phydev,
+							   &cpmac_link_update);
+				goto phy_found;
+			}
+		}
+		if (netif_msg_drv(priv))
+			printk(KERN_ERR "%s: Could not find fixed PHY\n",
+			       dev->name);
+		rc = -ENODEV;
+		goto fail;
+	}
+
+phy_found:
+	priv->phy = phy_connect(dev, priv->phy_name, &cpmac_adjust_link, 0,
+				PHY_INTERFACE_MODE_MII);
+	if (IS_ERR(priv->phy)) {
+		if (netif_msg_drv(priv))
+			printk(KERN_ERR "%s: Could not attach to PHY\n",
+			       dev->name);
+		return PTR_ERR(priv->phy);
+	}
 
 	if ((rc = register_netdev(dev))) {
 		printk(KERN_ERR "cpmac: error %i registering device %s\n", rc,
-- 
1.5.3.4


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

* Re: [PATCH 1/3] cpmac: use print_mac() instead of MAC_FMT
  2007-10-24  2:42   ` [PATCH 1/3] cpmac: use print_mac() instead of MAC_FMT Eugene Konev
@ 2007-10-25  7:32     ` Jeff Garzik
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Garzik @ 2007-10-25  7:32 UTC (permalink / raw)
  To: Eugene Konev; +Cc: Matteo Croce, netdev

Eugene Konev wrote:
> Switch to using DECLARE_MAC_BUF/print_mac() added by commit
> 0795af5729b18218767fab27c44b1384f72dc9ad [NET]: Introduce and use print_mac()
> and DECLARE_MAC_BUF().
> 
> 
> Signed-off-by: Eugene Konev <ejka@imfi.kspu.ru>

applied 1-3



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

end of thread, other threads:[~2007-10-25  7:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-24  2:42 [PATCH 0/0] cpmac: update to the net subsystem changes Eugene Konev
     [not found] ` <5070e5ddd7ae0681b14e712980d830225a2103aa.1193191283.git.ejka@imfi.kspu.ru>
2007-10-24  2:42   ` [PATCH 1/3] cpmac: use print_mac() instead of MAC_FMT Eugene Konev
2007-10-25  7:32     ` Jeff Garzik
     [not found]   ` <ad70799b9f985de8e07528f3d9fd65081416efca.1193191283.git.ejka@imfi.kspu.ru>
2007-10-24  2:42     ` [PATCH 2/3] cpmac: convert to napi_struct interface Eugene Konev
     [not found]   ` <6a2c62ba4fb9c80b4a4a957168183fbe35775740.1193191283.git.ejka@imfi.kspu.ru>
2007-10-24  2:42     ` [PATCH 3/3] cpmac: update to new fixed phy driver interface Eugene Konev

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).