Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 27922b4260f65d317aabda37e42bbbff > files > 3033

kernel-2.6.18-238.el5.src.rpm

From: Prarit Bhargava <prarit@redhat.com>
Date: Fri, 28 May 2010 12:42:45 -0400
Subject: [net] r8169: compat header cleanups, part 1
Message-id: <4BFFBA45.1080009@redhat.com>
Patchwork-id: 25891
O-Subject: Re: [RHEL5 PATCH 13/27] compat.h cleanup: r8169 driver changes
Bugzilla: 546740

Clean up r8169 driver compat header usage.

Bugzilla #546740.

Signed-off-by: Jarod Wilson <jarod@redhat.com>

diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 534c667..f6041a3 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -8,7 +8,6 @@
  * See MAINTAINERS file for support contact information.
  */
 
-#include "r8169_compat.h"
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/pci.h>
@@ -513,9 +512,6 @@ struct rtl8169_private {
 	struct rtl8169_counters counters;
 };
 
-/* Include second part of compat layer */
-#include "r8169_compat.h"
-
 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
 module_param(rx_copybreak, int, 0);
@@ -528,9 +524,9 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(RTL8169_VERSION);
 
 static int rtl8169_open(struct net_device *dev);
-static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
-				      struct net_device *dev);
-static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance);
+static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance,
+				     struct pt_regs *pt_regs);
 static int rtl8169_init_ring(struct net_device *dev);
 static void rtl_hw_start(struct net_device *dev);
 static int rtl8169_close(struct net_device *dev);
@@ -542,7 +538,7 @@ static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
 static void rtl8169_down(struct net_device *dev);
 static void rtl8169_rx_clear(struct rtl8169_private *tp);
-static int rtl8169_poll(struct napi_struct *napi, int budget);
+static int rtl8169_poll(struct net_device *dev, int *budget);
 
 static const unsigned int rtl8169_rx_config =
 	(RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
@@ -1247,7 +1243,7 @@ static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
 	}
 }
 
-static const struct ethtool_ops rtl8169_ethtool_ops = {
+static struct ethtool_ops rtl8169_ethtool_ops = {
 	.get_drvinfo		= rtl8169_get_drvinfo,
 	.get_regs_len		= rtl8169_get_regs_len,
 	.get_link		= ethtool_op_get_link,
@@ -2759,7 +2755,7 @@ static void rtl8169_netpoll(struct net_device *dev)
 	struct pci_dev *pdev = tp->pci_dev;
 
 	disable_irq(pdev->irq);
-	rtl8169_interrupt(pdev->irq, dev);
+	rtl8169_interrupt(pdev->irq, dev, NULL);
 	enable_irq(pdev->irq);
 }
 #endif
@@ -2958,26 +2954,6 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
 	}
 }
 
-static const struct net_device_ops rtl8169_netdev_ops = {
-	.ndo_open		= rtl8169_open,
-	.ndo_stop		= rtl8169_close,
-	.ndo_get_stats		= rtl8169_get_stats,
-	.ndo_start_xmit		= rtl8169_start_xmit,
-	.ndo_tx_timeout		= rtl8169_tx_timeout,
-	.ndo_validate_addr	= eth_validate_addr,
-	.ndo_change_mtu		= rtl8169_change_mtu,
-	.ndo_set_mac_address	= rtl_set_mac_address,
-	.ndo_do_ioctl		= rtl8169_ioctl,
-	.ndo_set_multicast_list	= rtl_set_rx_mode,
-#ifdef CONFIG_R8169_VLAN
-	.ndo_vlan_rx_register	= rtl8169_vlan_rx_register,
-#endif
-#ifdef CONFIG_NET_POLL_CONTROLLER
-	.ndo_poll_controller	= rtl8169_netpoll,
-#endif
-
-};
-
 static int __devinit
 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -3004,8 +2980,21 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 
 	SET_NETDEV_DEV(dev, &pdev->dev);
-	/* dev->netdev_ops = &rtl8169_netdev_ops; */
-	dev_netdev_ops(dev, &rtl8169_netdev_ops);
+	dev->open = rtl8169_open;
+	dev->stop = rtl8169_close;
+	dev->hard_start_xmit = rtl8169_start_xmit;
+	dev->set_mac_address = rtl_set_mac_address;
+	dev->get_stats = rtl8169_get_stats;
+	dev->set_multicast_list = rtl_set_rx_mode;
+	dev->change_mtu = rtl8169_change_mtu;
+#ifdef CONFIG_R8169_VLAN
+	dev->vlan_rx_register = rtl8169_vlan_rx_register;
+#endif
+	dev->tx_timeout = rtl8169_tx_timeout;
+	dev->do_ioctl = rtl8169_ioctl;
+#ifdef CONFIG_NET_POLL_CONTROLLER
+	dev->poll_controller = rtl8169_netpoll;
+#endif
 	tp = netdev_priv(dev);
 	tp->dev = dev;
 	tp->pci_dev = pdev;
@@ -3173,7 +3162,9 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	dev->irq = pdev->irq;
 	dev->base_addr = (unsigned long) ioaddr;
 
-	netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
+	dev->weight = R8169_NAPI_WEIGHT;
+	dev->poll = rtl8169_poll;
+	tp->napi.dev = dev;
 
 #ifdef CONFIG_R8169_VLAN
 	dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
@@ -3226,6 +3217,7 @@ out:
 err_out_msi_5:
 	rtl_disable_msi(pdev, tp);
 	iounmap(ioaddr);
+	tp->napi.dev = NULL;
 err_out_free_res_4:
 	pci_release_regions(pdev);
 err_out_mwi_3:
@@ -3313,7 +3305,7 @@ static int rtl8169_open(struct net_device *dev)
 	if (retval < 0)
 		goto err_release_ring_2;
 
-	napi_enable(&tp->napi);
+	netif_poll_enable(dev);
 
 	rtl_hw_start(dev);
 
@@ -3942,7 +3934,7 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
 	if (ret < 0)
 		goto out;
 
-	napi_enable(&tp->napi);
+	netif_poll_enable(dev);
 
 	rtl_hw_start(dev);
 
@@ -4122,8 +4114,8 @@ static void rtl8169_schedule_work(struct net_device *dev, work_func_t task)
 {
 	struct rtl8169_private *tp = netdev_priv(dev);
 
-	PREPARE_DELAYED_WORK(&tp->task, task);
-	schedule_delayed_work(&tp->task, 4);
+	PREPARE_WORK(&tp->task.work, task, &tp->task.work);
+	schedule_delayed_work(&tp->task.work, 4);
 }
 
 static void rtl8169_wait_for_quiescence(struct net_device *dev)
@@ -4134,17 +4126,18 @@ static void rtl8169_wait_for_quiescence(struct net_device *dev)
 	synchronize_irq(dev->irq);
 
 	/* Wait for any pending NAPI task to complete */
-	napi_disable(&tp->napi);
+	netif_poll_disable(dev);
 
 	rtl8169_irq_mask_and_ack(ioaddr);
 
 	tp->intr_mask = 0xffff;
 	RTL_W16(IntrMask, tp->intr_event);
-	napi_enable(&tp->napi);
+	netif_poll_enable(dev);
 }
 
-static void rtl8169_reinit_task(struct work_struct *work)
+static void rtl8169_reinit_task(void *data)
 {
+	struct work_struct *work = data;
 	struct rtl8169_private *tp =
 		container_of(work, struct rtl8169_private, task.work);
 	struct net_device *dev = tp->dev;
@@ -4171,8 +4164,9 @@ out_unlock:
 	rtnl_unlock();
 }
 
-static void rtl8169_reset_task(struct work_struct *work)
+static void rtl8169_reset_task(void *data)
 {
+	struct work_struct *work = data;
 	struct rtl8169_private *tp =
 		container_of(work, struct rtl8169_private, task.work);
 	struct net_device *dev = tp->dev;
@@ -4272,8 +4266,7 @@ static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
-static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
-				      struct net_device *dev)
+static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct rtl8169_private *tp = netdev_priv(dev);
 	unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC;
@@ -4555,6 +4548,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
 			}
 
 			skb_put(skb, pkt_size);
+			skb->dev = dev;
 			skb->protocol = eth_type_trans(skb, dev);
 
 			if (rtl8169_rx_vlan_skb(tp, desc, skb) < 0)
@@ -4594,7 +4588,8 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
 	return count;
 }
 
-static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
+static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance,
+				     struct pt_regs *pt_regs)
 {
 	struct net_device *dev = dev_instance;
 	struct rtl8169_private *tp = netdev_priv(dev);
@@ -4642,8 +4637,8 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 			RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
 			tp->intr_mask = ~tp->napi_event;
 
-			if (likely(napi_schedule_prep(&tp->napi)))
-				__napi_schedule(&tp->napi);
+			if (likely(netif_rx_schedule_prep(dev)))
+				__netif_rx_schedule(dev);
 			else if (netif_msg_intr(tp)) {
 				printk(KERN_INFO "%s: interrupt %04x in poll\n",
 				dev->name, status);
@@ -4663,18 +4658,18 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
 	return IRQ_RETVAL(handled);
 }
 
-static int rtl8169_poll(struct napi_struct *napi, int budget)
+static int rtl8169_poll(struct net_device *dev, int *budget)
 {
-	struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
-	struct net_device *dev = tp->dev;
+	struct rtl8169_private *tp = netdev_priv(dev);
 	void __iomem *ioaddr = tp->mmio_addr;
 	int work_done;
+	u32 can_do = min(*budget, dev->quota);
 
-	work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget);
+	work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, can_do);
 	rtl8169_tx_interrupt(dev, tp, ioaddr);
 
-	if (work_done < budget) {
-		napi_complete(napi);
+	if (work_done < can_do) {
+		napi_complete(&tp->napi);
 
 		/* We need for force the visibility of tp->intr_mask
 		 * for other CPUs, as we can loose an MSI interrupt
@@ -4688,7 +4683,10 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
 		RTL_W16(IntrMask, tp->intr_event);
 	}
 
-	return work_done;
+	*budget -= work_done;
+	dev->quota -= work_done;
+
+	return (work_done < can_do) ? 0 : 1;
 }
 
 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr)
@@ -4712,7 +4710,7 @@ static void rtl8169_down(struct net_device *dev)
 
 	netif_stop_queue(dev);
 
-	napi_disable(&tp->napi);
+	netif_poll_disable(dev);
 
 core_down:
 	spin_lock_irq(&tp->lock);
diff --git a/drivers/net/r8169_compat.h b/drivers/net/r8169_compat.h
deleted file mode 100644
index 7983d36..0000000
--- a/drivers/net/r8169_compat.h
+++ /dev/null
@@ -1,201 +0,0 @@
-#ifndef __R8169_COMPAT_H__
-#define __R8169_COMPAT_H__
-
-#include <linux/etherdevice.h>
-#include <linux/if_vlan.h>
-#include <linux/workqueue.h>
-#include <linux/pci.h>
-
-static inline __be16 backport_eth_type_trans(struct sk_buff *skb,
-					     struct net_device *dev)
-{
-	skb->dev = dev;
-	return eth_type_trans(skb, dev);
-}
-
-#define eth_type_trans backport_eth_type_trans
-
-typedef void (*work_func_t)(struct work_struct *work);
-
-struct delayed_work {
-	struct work_struct work;
-};
-
-static inline void backport_INIT_WORK(struct work_struct *work, void *func)
-{
-	INIT_WORK(work, func, work);
-}
-
-static inline void backport_PREPARE_WORK(struct work_struct *work, void *func)
-{
-	PREPARE_WORK(work, func, work);
-}
-
-static inline int backport_schedule_delayed_work(struct delayed_work *work,
-						 unsigned long delay)
-{
-	if (likely(!delay))
-		return schedule_work(&work->work);
-	else
-		return schedule_delayed_work(&work->work, delay);
-}
-
-
-#undef INIT_WORK
-#define INIT_WORK(_work, _func) backport_INIT_WORK(_work, _func)
-#define INIT_DELAYED_WORK(_work,_func) INIT_WORK(&(_work)->work, _func)
-
-#undef PREPARE_WORK
-#define PREPARE_WORK(_work, _func) backport_PREPARE_WORK(_work, _func)
-#define PREPARE_DELAYED_WORK(_work, _func) PREPARE_WORK(&(_work)->work, _func)
-
-#define schedule_delayed_work backport_schedule_delayed_work
-
-#define PCI_VENDOR_ID_GIGABYTE	0x1458
-
-static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable)
-{
-	if (pci_enable_wake(dev, PCI_D3cold, enable))
-		return pci_enable_wake(dev, PCI_D3hot, enable);
-	return 0;
-}
-
-#undef NETDEV_TX_OK
-#undef NETDEV_TX_BUSY
-#undef NETDEV_TX_LOCKED
-
-enum netdev_tx {
-	NETDEV_TX_OK = 0,
-	NETDEV_TX_BUSY,
-	NETDEV_TX_LOCKED = -1,
-};
-typedef enum netdev_tx netdev_tx_t;
-
-static inline void napi_enable(struct napi_struct *napi)
-{
-	netif_poll_enable(napi->dev);
-}
-
-static inline void napi_disable(struct napi_struct *napi)
-{
-	netif_poll_disable(napi->dev);
-}
-
-static inline void __napi_schedule(struct napi_struct *napi)
-{
-	__netif_rx_schedule(napi->dev);
-}
-
-static inline void napi_schedule(struct napi_struct *napi)
-{
-	netif_rx_schedule(napi->dev);
-}
-
-static inline int napi_schedule_prep(struct napi_struct *napi)
-{
-	return netif_rx_schedule_prep(napi->dev);
-}
-
-static int rtl8169_poll_compat(struct net_device *, int *);
-
-static inline void netif_napi_add(struct net_device *netdev,
-				  struct napi_struct *napi,
-				  int (*poll)(struct napi_struct *, int),
-				  int weight)
-{
-	netdev->weight = weight;
-	netdev->poll = rtl8169_poll_compat;
-
-	napi->dev = netdev;
-	napi->poll = poll;
-}
-
-/*
- * net_device_ops backport
- */
-#define eth_validate_addr NULL
-
-struct net_device_ops {
-	int	(*ndo_init)(struct net_device *dev);
-	void	(*ndo_uninit)(struct net_device *dev);
-	int	(*ndo_open)(struct net_device *dev);
-	int	(*ndo_stop)(struct net_device *dev);
-	int	(*ndo_start_xmit) (struct sk_buff *skb, struct net_device *dev);
-	u16	(*ndo_select_queue)(struct net_device *dev,
-				    struct sk_buff *skb);
-	void	(*ndo_change_rx_flags)(struct net_device *dev, int flags);
-	void	(*ndo_set_rx_mode)(struct net_device *dev);
-	void	(*ndo_set_multicast_list)(struct net_device *dev);
-	int	(*ndo_set_mac_address)(struct net_device *dev, void *addr);
-	int	(*ndo_validate_addr)(struct net_device *dev);
-	int	(*ndo_do_ioctl)(struct net_device *dev,
-				struct ifreq *ifr, int cmd);
-	int	(*ndo_set_config)(struct net_device *dev, struct ifmap *map);
-	int	(*ndo_change_mtu)(struct net_device *dev, int new_mtu);
-	int	(*ndo_neigh_setup)(struct net_device *dev,
-				   struct neigh_parms *);
-	void	(*ndo_tx_timeout) (struct net_device *dev);
-
-	struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
-
-	void	(*ndo_vlan_rx_register)(struct net_device *dev,
-				struct vlan_group *grp);
-	void	(*ndo_vlan_rx_add_vid)(struct net_device *dev,
-			       unsigned short vid);
-	void	(*ndo_vlan_rx_kill_vid)(struct net_device *dev,
-				unsigned short vid);
-#ifdef CONFIG_NET_POLL_CONTROLLER
-	void	(*ndo_poll_controller)(struct net_device *dev);
-#endif
-};
-
-static void dev_netdev_ops(struct net_device *netdev,
-			   const struct net_device_ops *ops)
-{
-	netdev->open = ops->ndo_open;
-	netdev->stop = ops->ndo_stop;
-	netdev->hard_start_xmit = ops->ndo_start_xmit;
-	netdev->set_mac_address = ops->ndo_set_mac_address;
-	netdev->get_stats = ops->ndo_get_stats;
-	netdev->set_multicast_list = ops->ndo_set_multicast_list;
-	netdev->change_mtu = ops->ndo_change_mtu;
-	netdev->vlan_rx_register = ops->ndo_vlan_rx_register;
-	netdev->vlan_rx_add_vid = ops->ndo_vlan_rx_add_vid;
-	netdev->tx_timeout = ops->ndo_tx_timeout;
-	netdev->do_ioctl = ops->ndo_do_ioctl;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-	netdev->poll_controller = ops->ndo_poll_controller;
-#endif
-}
-
-static inline int backport_request_irq(unsigned int irq,
-				       irqreturn_t (*h)(int, void *),
-				       unsigned long flags,
-				       const char *dev_name, void *dev_id)
-{
-	return request_irq(irq,
-			   (irqreturn_t (*)(int, void *, struct pt_regs *))h,
-			   flags, dev_name, dev_id);
-}
-#define request_irq backport_request_irq
-
-#define ETH_FCS_LEN	4
-
-#elif !defined(__R8169_COMPAT2_H__)
-#define __R8169_COMPAT2_H__
-
-static int rtl8169_poll_compat(struct net_device *netdev, int *budget)
-{
-	struct rtl8169_private *tp = netdev_priv(netdev);
-	u32 work_done, can_do;
-
-	can_do = min(*budget, netdev->quota);
-	work_done = tp->napi.poll(&tp->napi, can_do);
-	*budget -= work_done;
-	netdev->quota -= work_done;
-
-	return (work_done < can_do) ? 0 : 1;
-}
-
-#define ETH_FCS_LEN 4
-#endif