aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/hysdn
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2009-01-07 21:03:43 -0500
committerDavid S. Miller <davem@davemloft.net>2009-01-07 21:03:43 -0500
commit0e2445fbdd2bfc7055f6e9ab83842bebcaf4868f (patch)
treea1c9f4963d25dbf001c751368c73d52173410188 /drivers/isdn/hysdn
parentfb875333c80942455551f690f306a899ceeee5df (diff)
hysdn: convert to net_device_ops and other updates
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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn/hysdn')
-rw-r--r--drivers/isdn/hysdn/hysdn_net.c77
1 files changed, 31 insertions, 46 deletions
diff --git a/drivers/isdn/hysdn/hysdn_net.c b/drivers/isdn/hysdn/hysdn_net.c
index 7ee5bd9f2bb4..579974cf4c9a 100644
--- a/drivers/isdn/hysdn/hysdn_net.c
+++ b/drivers/isdn/hysdn/hysdn_net.c
@@ -38,16 +38,12 @@ char *hysdn_net_revision = "$Revision: 1.8.6.4 $";
38/* inside the definition. */ 38/* inside the definition. */
39/****************************************************************************/ 39/****************************************************************************/
40struct net_local { 40struct net_local {
41 struct net_device netdev; /* the network device */
42 struct net_device_stats stats;
43 /* additional vars may be added here */
44 char dev_name[9]; /* our own device name */
45
46 /* Tx control lock. This protects the transmit buffer ring 41 /* Tx control lock. This protects the transmit buffer ring
47 * state along with the "tx full" state of the driver. This 42 * state along with the "tx full" state of the driver. This
48 * means all netif_queue flow control actions are protected 43 * means all netif_queue flow control actions are protected
49 * by this lock as well. 44 * by this lock as well.
50 */ 45 */
46 struct net_device *dev;
51 spinlock_t lock; 47 spinlock_t lock;
52 struct sk_buff *skbs[MAX_SKB_BUFFERS]; /* pointers to tx-skbs */ 48 struct sk_buff *skbs[MAX_SKB_BUFFERS]; /* pointers to tx-skbs */
53 int in_idx, out_idx; /* indexes to buffer ring */ 49 int in_idx, out_idx; /* indexes to buffer ring */
@@ -55,15 +51,6 @@ struct net_local {
55}; /* net_local */ 51}; /* net_local */
56 52
57 53
58/*****************************************************/
59/* Get the current statistics for this card. */
60/* This may be called with the card open or closed ! */
61/*****************************************************/
62static struct net_device_stats *
63net_get_stats(struct net_device *dev)
64{
65 return (&((struct net_local *) dev)->stats);
66} /* net_device_stats */
67 54
68/*********************************************************************/ 55/*********************************************************************/
69/* Open/initialize the board. This is called (in the current kernel) */ 56/* Open/initialize the board. This is called (in the current kernel) */
@@ -182,8 +169,8 @@ hysdn_tx_netack(hysdn_card * card)
182 if (!lp->sk_count) 169 if (!lp->sk_count)
183 return; /* error condition */ 170 return; /* error condition */
184 171
185 lp->stats.tx_packets++; 172 lp->dev->stats.tx_packets++;
186 lp->stats.tx_bytes += lp->skbs[lp->out_idx]->len; 173 lp->dev->stats.tx_bytes += lp->skbs[lp->out_idx]->len;
187 174
188 dev_kfree_skb(lp->skbs[lp->out_idx++]); /* free skb */ 175 dev_kfree_skb(lp->skbs[lp->out_idx++]); /* free skb */
189 if (lp->out_idx >= MAX_SKB_BUFFERS) 176 if (lp->out_idx >= MAX_SKB_BUFFERS)
@@ -200,29 +187,30 @@ void
200hysdn_rx_netpkt(hysdn_card * card, unsigned char *buf, unsigned short len) 187hysdn_rx_netpkt(hysdn_card * card, unsigned char *buf, unsigned short len)
201{ 188{
202 struct net_local *lp = card->netif; 189 struct net_local *lp = card->netif;
190 struct net_device *dev = lp->dev;
203 struct sk_buff *skb; 191 struct sk_buff *skb;
204 192
205 if (!lp) 193 if (!lp)
206 return; /* non existing device */ 194 return; /* non existing device */
207 195
208 lp->stats.rx_bytes += len; 196 dev->stats.rx_bytes += len;
209 197
210 skb = dev_alloc_skb(len); 198 skb = dev_alloc_skb(len);
211 if (skb == NULL) { 199 if (skb == NULL) {
212 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", 200 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n",
213 lp->netdev.name); 201 dev->name);
214 lp->stats.rx_dropped++; 202 dev->stats.rx_dropped++;
215 return; 203 return;
216 } 204 }
217 /* copy the data */ 205 /* copy the data */
218 memcpy(skb_put(skb, len), buf, len); 206 memcpy(skb_put(skb, len), buf, len);
219 207
220 /* determine the used protocol */ 208 /* determine the used protocol */
221 skb->protocol = eth_type_trans(skb, &lp->netdev); 209 skb->protocol = eth_type_trans(skb, dev);
222 210
223 netif_rx(skb); 211 dev->stats.rx_packets++; /* adjust packet count */
224 lp->stats.rx_packets++; /* adjust packet count */
225 212
213 netif_rx(skb);
226} /* hysdn_rx_netpkt */ 214} /* hysdn_rx_netpkt */
227 215
228/*****************************************************/ 216/*****************************************************/
@@ -242,24 +230,15 @@ hysdn_tx_netget(hysdn_card * card)
242 return (lp->skbs[lp->out_idx]); /* next packet to send */ 230 return (lp->skbs[lp->out_idx]); /* next packet to send */
243} /* hysdn_tx_netget */ 231} /* hysdn_tx_netget */
244 232
233static const struct net_device_ops hysdn_netdev_ops = {
234 .ndo_open = net_open,
235 .ndo_stop = net_close,
236 .ndo_start_xmit = net_send_packet,
237 .ndo_change_mtu = eth_change_mtu,
238 .ndo_set_mac_address = eth_mac_addr,
239 .ndo_validate_addr = eth_validate_addr,
240};
245 241
246/*******************************************/
247/* init function called by register device */
248/*******************************************/
249static int
250net_init(struct net_device *dev)
251{
252 /* setup the function table */
253 dev->open = net_open;
254 dev->stop = net_close;
255 dev->hard_start_xmit = net_send_packet;
256 dev->get_stats = net_get_stats;
257
258 /* Fill in the fields of the device structure with ethernet values. */
259 ether_setup(dev);
260
261 return (0); /* success */
262} /* net_init */
263 242
264/*****************************************************************************/ 243/*****************************************************************************/
265/* hysdn_net_create creates a new net device for the given card. If a device */ 244/* 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)
271{ 250{
272 struct net_device *dev; 251 struct net_device *dev;
273 int i; 252 int i;
253 struct net_local *lp;
254
274 if(!card) { 255 if(!card) {
275 printk(KERN_WARNING "No card-pt in hysdn_net_create!\n"); 256 printk(KERN_WARNING "No card-pt in hysdn_net_create!\n");
276 return (-ENOMEM); 257 return (-ENOMEM);
277 } 258 }
278 hysdn_net_release(card); /* release an existing net device */ 259 hysdn_net_release(card); /* release an existing net device */
279 if ((dev = kzalloc(sizeof(struct net_local), GFP_KERNEL)) == NULL) { 260
261 dev = alloc_etherdev(sizeof(struct net_local));
262 if (!dev) {
280 printk(KERN_WARNING "HYSDN: unable to allocate mem\n"); 263 printk(KERN_WARNING "HYSDN: unable to allocate mem\n");
281 return (-ENOMEM); 264 return (-ENOMEM);
282 } 265 }
283 266
267 lp = netdev_priv(dev);
268 lp->dev = dev;
269
270 dev->netdev_ops = &hysdn_netdev_ops;
284 spin_lock_init(&((struct net_local *) dev)->lock); 271 spin_lock_init(&((struct net_local *) dev)->lock);
285 272
286 /* initialise necessary or informing fields */ 273 /* initialise necessary or informing fields */
287 dev->base_addr = card->iobase; /* IO address */ 274 dev->base_addr = card->iobase; /* IO address */
288 dev->irq = card->irq; /* irq */ 275 dev->irq = card->irq; /* irq */
289 dev->init = net_init; /* the init function of the device */ 276
290 if(dev->name) { 277 dev->netdev_ops = &hysdn_netdev_ops;
291 strcpy(dev->name, ((struct net_local *) dev)->dev_name);
292 }
293 if ((i = register_netdev(dev))) { 278 if ((i = register_netdev(dev))) {
294 printk(KERN_WARNING "HYSDN: unable to create network device\n"); 279 printk(KERN_WARNING "HYSDN: unable to create network device\n");
295 kfree(dev); 280 free_netdev(dev);
296 return (i); 281 return (i);
297 } 282 }
298 dev->ml_priv = card; /* remember pointer to own data structure */ 283 dev->ml_priv = card; /* remember pointer to own data structure */
@@ -316,7 +301,7 @@ hysdn_net_release(hysdn_card * card)
316 return (0); /* non existing */ 301 return (0); /* non existing */
317 302
318 card->netif = NULL; /* clear out pointer */ 303 card->netif = NULL; /* clear out pointer */
319 dev->stop(dev); /* close the device */ 304 net_close(dev);
320 305
321 flush_tx_buffers((struct net_local *) dev); /* empty buffers */ 306 flush_tx_buffers((struct net_local *) dev); /* empty buffers */
322 307