netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH 32/42] hysdn: convert to net_device_ops and other updates
Date: Tue, 06 Jan 2009 16:33:48 -0800	[thread overview]
Message-ID: <20090107003348.948135773@vyatta.com> (raw)
In-Reply-To: 20090107003316.784424362@vyatta.com

[-- Attachment #1: hysdn.patch --]
[-- Type: text/plain, Size: 5847 bytes --]

Several API problems fixed:
  * use proper allocation
  * handle renames
  * convert to net_device_ops
  * use internal net_device_stats

This driver is putrid (as in old and rotten), so I doubt any one uses it.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>


---
 drivers/isdn/hysdn/hysdn_net.c |   77 ++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 46 deletions(-)

--- a/drivers/isdn/hysdn/hysdn_net.c	2009-01-03 21:48:10.166764790 -0800
+++ b/drivers/isdn/hysdn/hysdn_net.c	2009-01-03 22:03:32.319014167 -0800
@@ -38,16 +38,12 @@ char *hysdn_net_revision = "$Revision: 1
 /* inside the definition.                                                   */
 /****************************************************************************/
 struct net_local {
-	struct net_device netdev;	/* the network device */
-	struct net_device_stats stats;
-	/* additional vars may be added here */
-	char dev_name[9];	/* our own device name */
-
 	/* Tx control lock.  This protects the transmit buffer ring
 	 * state along with the "tx full" state of the driver.  This
 	 * means all netif_queue flow control actions are protected
 	 * by this lock as well.
 	 */
+	struct net_device *dev;
 	spinlock_t lock;
 	struct sk_buff *skbs[MAX_SKB_BUFFERS];	/* pointers to tx-skbs */
 	int in_idx, out_idx;	/* indexes to buffer ring */
@@ -55,15 +51,6 @@ struct net_local {
 };				/* net_local */
 
 
-/*****************************************************/
-/* Get the current statistics for this card.         */
-/* This may be called with the card open or closed ! */
-/*****************************************************/
-static struct net_device_stats *
-net_get_stats(struct net_device *dev)
-{
-	return (&((struct net_local *) dev)->stats);
-}				/* net_device_stats */
 
 /*********************************************************************/
 /* Open/initialize the board. This is called (in the current kernel) */
@@ -182,8 +169,8 @@ hysdn_tx_netack(hysdn_card * card)
 	if (!lp->sk_count)
 		return;		/* error condition */
 
-	lp->stats.tx_packets++;
-	lp->stats.tx_bytes += lp->skbs[lp->out_idx]->len;
+	lp->dev->stats.tx_packets++;
+	lp->dev->stats.tx_bytes += lp->skbs[lp->out_idx]->len;
 
 	dev_kfree_skb(lp->skbs[lp->out_idx++]);		/* free skb */
 	if (lp->out_idx >= MAX_SKB_BUFFERS)
@@ -200,29 +187,30 @@ void
 hysdn_rx_netpkt(hysdn_card * card, unsigned char *buf, unsigned short len)
 {
 	struct net_local *lp = card->netif;
+	struct net_device *dev = lp->dev;
 	struct sk_buff *skb;
 
 	if (!lp)
 		return;		/* non existing device */
 
-	lp->stats.rx_bytes += len;
+	dev->stats.rx_bytes += len;
 
 	skb = dev_alloc_skb(len);
 	if (skb == NULL) {
 		printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n",
-		       lp->netdev.name);
-		lp->stats.rx_dropped++;
+		       dev->name);
+		dev->stats.rx_dropped++;
 		return;
 	}
 	/* copy the data */
 	memcpy(skb_put(skb, len), buf, len);
 
 	/* determine the used protocol */
-	skb->protocol = eth_type_trans(skb, &lp->netdev);
+	skb->protocol = eth_type_trans(skb, dev);
 
-	netif_rx(skb);
-	lp->stats.rx_packets++;	/* adjust packet count */
+	dev->stats.rx_packets++;	/* adjust packet count */
 
+	netif_rx(skb);
 }				/* hysdn_rx_netpkt */
 
 /*****************************************************/
@@ -242,24 +230,15 @@ hysdn_tx_netget(hysdn_card * card)
 	return (lp->skbs[lp->out_idx]);		/* next packet to send */
 }				/* hysdn_tx_netget */
 
+static const struct net_device_ops hysdn_netdev_ops = {
+	.ndo_open 		= net_open,
+	.ndo_stop		= net_close,
+	.ndo_start_xmit		= net_send_packet,
+	.ndo_change_mtu		= eth_change_mtu,
+	.ndo_set_mac_address 	= eth_mac_addr,
+	.ndo_validate_addr	= eth_validate_addr,
+};
 
-/*******************************************/
-/* init function called by register device */
-/*******************************************/
-static int
-net_init(struct net_device *dev)
-{
-	/* setup the function table */
-	dev->open = net_open;
-	dev->stop = net_close;
-	dev->hard_start_xmit = net_send_packet;
-	dev->get_stats = net_get_stats;
-
-	/* Fill in the fields of the device structure with ethernet values. */
-	ether_setup(dev);
-
-	return (0);		/* success */
-}				/* net_init */
 
 /*****************************************************************************/
 /* hysdn_net_create creates a new net device for the given card. If a device */
@@ -271,28 +250,34 @@ hysdn_net_create(hysdn_card * card)
 {
 	struct net_device *dev;
 	int i;
+	struct net_local *lp;
+
 	if(!card) {
 		printk(KERN_WARNING "No card-pt in hysdn_net_create!\n");
 		return (-ENOMEM);
 	}
 	hysdn_net_release(card);	/* release an existing net device */
-	if ((dev = kzalloc(sizeof(struct net_local), GFP_KERNEL)) == NULL) {
+
+	dev = alloc_etherdev(sizeof(struct net_local));
+	if (!dev) {
 		printk(KERN_WARNING "HYSDN: unable to allocate mem\n");
 		return (-ENOMEM);
 	}
 
+	lp = netdev_priv(dev);
+	lp->dev = dev;
+
+	dev->netdev_ops = &hysdn_netdev_ops;
 	spin_lock_init(&((struct net_local *) dev)->lock);
 
 	/* initialise necessary or informing fields */
 	dev->base_addr = card->iobase;	/* IO address */
 	dev->irq = card->irq;	/* irq */
-	dev->init = net_init;	/* the init function of the device */
-	if(dev->name) {
-		strcpy(dev->name, ((struct net_local *) dev)->dev_name);
-	} 
+
+	dev->netdev_ops = &hysdn_netdev_ops;
 	if ((i = register_netdev(dev))) {
 		printk(KERN_WARNING "HYSDN: unable to create network device\n");
-		kfree(dev);
+		free_netdev(dev);
 		return (i);
 	}
 	dev->ml_priv = card;	/* remember pointer to own data structure */
@@ -316,7 +301,7 @@ hysdn_net_release(hysdn_card * card)
 		return (0);	/* non existing */
 
 	card->netif = NULL;	/* clear out pointer */
-	dev->stop(dev);		/* close the device */
+	net_close(dev);
 
 	flush_tx_buffers((struct net_local *) dev);	/* empty buffers */
 

-- 


  parent reply	other threads:[~2009-01-07  0:54 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-07  0:33 [PATCH 00/42] Still more net_device API updates Stephen Hemminger
2009-01-07  0:33 ` [PATCH 01/42] appletalk: convert aarp to net_device_ops Stephen Hemminger
2009-01-08  1:21   ` David Miller
2009-01-08  3:09     ` Joe Perches
2009-01-08  4:39       ` David Miller
2009-01-07  0:33 ` [PATCH 02/42] appletalk: convert ipddp " Stephen Hemminger
2009-01-08  1:22   ` David Miller
2009-01-07  0:33 ` [PATCH 03/42] bluetooth: driver API update Stephen Hemminger
     [not found]   ` <20090107003345.753201945-ZtmgI6mnKB3QT0dZR+AlfA@public.gmane.org>
2009-01-07  1:53     ` Marcel Holtmann
2009-01-08  1:23       ` David Miller
2009-01-07  0:33 ` [PATCH 05/42] cassini: update to net_device_ops Stephen Hemminger
2009-01-08  1:25   ` David Miller
2009-01-07  0:33 ` [PATCH 06/42] ipg: " Stephen Hemminger
2009-01-07  7:59   ` Pekka Enberg
2009-01-08  1:26     ` David Miller
2009-01-07  0:33 ` [PATCH 07/42] plip: " Stephen Hemminger
2009-01-08  1:26   ` David Miller
2009-01-07  0:33 ` [PATCH 08/42] tlan: " Stephen Hemminger
2009-01-08  1:27   ` David Miller
2009-01-07  0:33 ` [PATCH 09/42] epic100: " Stephen Hemminger
2009-01-08  1:27   ` David Miller
2009-01-07  0:33 ` [PATCH 10/42] sunhme: " Stephen Hemminger
2009-01-08  1:28   ` David Miller
2009-01-07  0:33 ` [PATCH 11/42] sungem: " Stephen Hemminger
2009-01-08  1:29   ` David Miller
2009-01-07  0:33 ` [PATCH 12/42] pcnet32: " Stephen Hemminger
2009-01-08  1:29   ` David Miller
2009-01-07  0:33 ` [PATCH 13/42] typhoon: " Stephen Hemminger
2009-01-08  1:29   ` David Miller
2009-01-07  0:33 ` [PATCH 14/42] enc28j60: " Stephen Hemminger
2009-01-08  1:30   ` David Miller
2009-01-07  0:33 ` [PATCH 16/42] de600: " Stephen Hemminger
2009-01-08  1:35   ` David Miller
2009-01-08  1:48     ` [PATCH 15/42] hp100: " Stephen Hemminger
2009-01-08  2:13       ` David Miller
2009-01-07  0:33 ` [PATCH 17/42] sis190: " Stephen Hemminger
2009-01-08  1:35   ` David Miller
2009-01-07  0:33 ` [PATCH 18/42] ns83820: fix net_device_ops support Stephen Hemminger
2009-01-08  1:36   ` David Miller
2009-01-07  0:33 ` [PATCH 19/42] sb1000: update to net_device_ops Stephen Hemminger
2009-01-08  1:57   ` David Miller
2009-01-07  0:33 ` [PATCH 20/42] natsemi: " Stephen Hemminger
2009-01-08  1:57   ` David Miller
2009-01-07  0:33 ` [PATCH 21/42] fealnx: " Stephen Hemminger
2009-01-08  1:57   ` David Miller
2009-01-07  0:33 ` [PATCH 22/42] starfire: " Stephen Hemminger
2009-01-08  1:58   ` David Miller
2009-01-07  0:33 ` [PATCH 23/42] sundance: " Stephen Hemminger
2009-01-08  1:58   ` David Miller
2009-01-07  0:33 ` [PATCH 24/42] tulip: convert devices to new API Stephen Hemminger
2009-01-07  7:49   ` Grant Grundler
2009-01-08  1:59     ` David Miller
2009-01-07  0:33 ` [PATCH 25/42] de2104x: convert to net_device_ops Stephen Hemminger
2009-01-07  7:50   ` Grant Grundler
2009-01-08  1:59   ` David Miller
2009-01-07  0:33 ` [PATCH 26/42] de4x5: " Stephen Hemminger
2009-01-08  2:00   ` David Miller
2009-01-07  0:33 ` [PATCH 27/42] xircom: convert devices to new API Stephen Hemminger
2009-01-08  2:01   ` David Miller
2009-01-07  0:33 ` [PATCH 28/42] dmfe: convert " Stephen Hemminger
2009-01-08 21:16   ` Grant Grundler
2009-01-08 21:32     ` David Miller
2009-01-07  0:33 ` [PATCH 29/42] uli526x: convert devices " Stephen Hemminger
2009-01-08  2:01   ` David Miller
2009-01-07  0:33 ` [PATCH 30/42] windbond: " Stephen Hemminger
2009-01-08  2:02   ` David Miller
2009-01-07  0:33 ` [PATCH 31/42] dvb: update network device to current API Stephen Hemminger
2009-01-08  2:02   ` David Miller
2009-01-07  0:33 ` Stephen Hemminger [this message]
2009-01-08  2:03   ` [PATCH 32/42] hysdn: convert to net_device_ops and other updates David Miller
2009-01-07  0:33 ` [PATCH 33/42] I4l: convert to net_device_ops Stephen Hemminger
2009-01-07  0:33 ` [PATCH 34/42] fusion: convert devices to new API Stephen Hemminger
2009-01-08  2:04   ` David Miller
2009-01-07  0:33 ` [PATCH 35/42] xpnet: " Stephen Hemminger
2009-01-08  2:05   ` David Miller
2009-01-07  0:33 ` [PATCH 36/42] gadget: " Stephen Hemminger
2009-01-08  2:05   ` David Miller
2009-01-07  0:33 ` [PATCH 37/42] synclink: " Stephen Hemminger
2009-01-07 23:48   ` [PATCH 37/42] synclink: convert devices to new API (rev2) Stephen Hemminger
2009-01-08  2:08     ` David Miller
2009-01-08 22:49       ` Krzysztof Halasa
2009-01-08 22:55         ` Krzysztof Halasa
2009-01-13  0:18         ` David Miller
2009-01-07  0:33 ` [PATCH 38/42] uwb: convert devices to net_device_ops Stephen Hemminger
2009-01-07 10:38   ` David Vrabel
2009-01-08  2:09     ` David Miller
2009-01-07  0:33 ` [PATCH 39/42] slip: convert " Stephen Hemminger
2009-01-08  2:09   ` David Miller
2009-01-07  0:33 ` [PATCH 40/42] amd8111e: " Stephen Hemminger
2009-01-08  2:10   ` David Miller
2009-01-07  0:33 ` [PATCH 41/42] atp: " Stephen Hemminger
2009-01-08  2:10   ` David Miller
2009-01-07  0:33 ` [PATCH 42/42] b44: " Stephen Hemminger
2009-01-08  2:10   ` David Miller
     [not found] ` <20090107003345.872219054@vyatta.com>
2009-01-08  1:25   ` [PATCH 04/42] phonet: update " David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090107003348.948135773@vyatta.com \
    --to=shemminger@vyatta.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).