diff options
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/wan/cycx_x25.c | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c index aeea321e4a9d..5fa52923efa8 100644 --- a/drivers/net/wan/cycx_x25.c +++ b/drivers/net/wan/cycx_x25.c | |||
@@ -199,6 +199,8 @@ static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev, | |||
199 | static struct net_device * | 199 | static struct net_device * |
200 | cycx_x25_get_dev_by_dte_addr(struct wan_device *wandev, char *dte); | 200 | cycx_x25_get_dev_by_dte_addr(struct wan_device *wandev, char *dte); |
201 | 201 | ||
202 | static void cycx_x25_chan_setup(struct net_device *dev); | ||
203 | |||
202 | #ifdef CYCLOMX_X25_DEBUG | 204 | #ifdef CYCLOMX_X25_DEBUG |
203 | static void hex_dump(char *msg, unsigned char *p, int len); | 205 | static void hex_dump(char *msg, unsigned char *p, int len); |
204 | static void cycx_x25_dump_config(struct cycx_x25_config *conf); | 206 | static void cycx_x25_dump_config(struct cycx_x25_config *conf); |
@@ -353,6 +355,12 @@ static int cycx_wan_update(struct wan_device *wandev) | |||
353 | return 0; | 355 | return 0; |
354 | } | 356 | } |
355 | 357 | ||
358 | /* callback to initialize device */ | ||
359 | static void cycx_x25_chan_setup(struct net_device *dev) | ||
360 | { | ||
361 | dev->init = cycx_netdevice_init; | ||
362 | } | ||
363 | |||
356 | /* Create new logical channel. | 364 | /* Create new logical channel. |
357 | * This routine is called by the router when ROUTER_IFNEW IOCTL is being | 365 | * This routine is called by the router when ROUTER_IFNEW IOCTL is being |
358 | * handled. | 366 | * handled. |
@@ -376,11 +384,12 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, | |||
376 | return -EINVAL; | 384 | return -EINVAL; |
377 | } | 385 | } |
378 | 386 | ||
379 | /* allocate and initialize private data */ | 387 | dev = alloc_netdev(sizeof(struct cycx_x25_channel), conf->name, |
380 | chan = kzalloc(sizeof(struct cycx_x25_channel), GFP_KERNEL); | 388 | cycx_x25_chan_setup); |
381 | if (!chan) | 389 | if (!dev) |
382 | return -ENOMEM; | 390 | return -ENOMEM; |
383 | 391 | ||
392 | chan = netdev_priv(dev); | ||
384 | strcpy(chan->name, conf->name); | 393 | strcpy(chan->name, conf->name); |
385 | chan->card = card; | 394 | chan->card = card; |
386 | chan->link = conf->port; | 395 | chan->link = conf->port; |
@@ -396,14 +405,14 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, | |||
396 | if (len > WAN_ADDRESS_SZ) { | 405 | if (len > WAN_ADDRESS_SZ) { |
397 | printk(KERN_ERR "%s: %s local addr too long!\n", | 406 | printk(KERN_ERR "%s: %s local addr too long!\n", |
398 | wandev->name, chan->name); | 407 | wandev->name, chan->name); |
399 | kfree(chan); | 408 | err = -EINVAL; |
400 | return -EINVAL; | 409 | goto error; |
401 | } else { | 410 | } else { |
402 | chan->local_addr = kmalloc(len + 1, GFP_KERNEL); | 411 | chan->local_addr = kmalloc(len + 1, GFP_KERNEL); |
403 | 412 | ||
404 | if (!chan->local_addr) { | 413 | if (!chan->local_addr) { |
405 | kfree(chan); | 414 | err = -ENOMEM; |
406 | return -ENOMEM; | 415 | goto error; |
407 | } | 416 | } |
408 | } | 417 | } |
409 | 418 | ||
@@ -429,41 +438,31 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, | |||
429 | "%s: PVC %u is out of range on interface %s!\n", | 438 | "%s: PVC %u is out of range on interface %s!\n", |
430 | wandev->name, lcn, chan->name); | 439 | wandev->name, lcn, chan->name); |
431 | err = -EINVAL; | 440 | err = -EINVAL; |
441 | goto error; | ||
432 | } | 442 | } |
433 | } else { | 443 | } else { |
434 | printk(KERN_ERR "%s: invalid media address on interface %s!\n", | 444 | printk(KERN_ERR "%s: invalid media address on interface %s!\n", |
435 | wandev->name, chan->name); | 445 | wandev->name, chan->name); |
436 | err = -EINVAL; | 446 | err = -EINVAL; |
447 | goto error; | ||
437 | } | 448 | } |
438 | 449 | ||
439 | if (err) { | ||
440 | kfree(chan->local_addr); | ||
441 | kfree(chan); | ||
442 | return err; | ||
443 | } | ||
444 | |||
445 | /* prepare network device data space for registration */ | ||
446 | strcpy(dev->name, chan->name); | ||
447 | dev->init = cycx_netdevice_init; | ||
448 | dev->priv = chan; | ||
449 | |||
450 | return 0; | 450 | return 0; |
451 | |||
452 | error: | ||
453 | free_netdev(dev); | ||
454 | return err; | ||
451 | } | 455 | } |
452 | 456 | ||
453 | /* Delete logical channel. */ | 457 | /* Delete logical channel. */ |
454 | static int cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev) | 458 | static int cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev) |
455 | { | 459 | { |
456 | if (dev->priv) { | 460 | struct cycx_x25_channel *chan = netdev_priv(dev); |
457 | struct cycx_x25_channel *chan = dev->priv; | ||
458 | 461 | ||
459 | if (chan->svc) { | 462 | if (chan->svc) { |
460 | kfree(chan->local_addr); | 463 | kfree(chan->local_addr); |
461 | if (chan->state == WAN_CONNECTED) | 464 | if (chan->state == WAN_CONNECTED) |
462 | del_timer(&chan->timer); | 465 | del_timer(&chan->timer); |
463 | } | ||
464 | |||
465 | kfree(chan); | ||
466 | dev->priv = NULL; | ||
467 | } | 466 | } |
468 | 467 | ||
469 | return 0; | 468 | return 0; |
@@ -484,7 +483,7 @@ static const struct header_ops cycx_header_ops = { | |||
484 | * registration. */ | 483 | * registration. */ |
485 | static int cycx_netdevice_init(struct net_device *dev) | 484 | static int cycx_netdevice_init(struct net_device *dev) |
486 | { | 485 | { |
487 | struct cycx_x25_channel *chan = dev->priv; | 486 | struct cycx_x25_channel *chan = netdev_priv(dev); |
488 | struct cycx_device *card = chan->card; | 487 | struct cycx_device *card = chan->card; |
489 | struct wan_device *wandev = &card->wandev; | 488 | struct wan_device *wandev = &card->wandev; |
490 | 489 | ||
@@ -542,7 +541,7 @@ static int cycx_netdevice_open(struct net_device *dev) | |||
542 | * o if there's no more open channels then disconnect physical link. */ | 541 | * o if there's no more open channels then disconnect physical link. */ |
543 | static int cycx_netdevice_stop(struct net_device *dev) | 542 | static int cycx_netdevice_stop(struct net_device *dev) |
544 | { | 543 | { |
545 | struct cycx_x25_channel *chan = dev->priv; | 544 | struct cycx_x25_channel *chan = netdev_priv(dev); |
546 | 545 | ||
547 | netif_stop_queue(dev); | 546 | netif_stop_queue(dev); |
548 | 547 | ||
@@ -596,7 +595,7 @@ static int cycx_netdevice_rebuild_header(struct sk_buff *skb) | |||
596 | static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb, | 595 | static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb, |
597 | struct net_device *dev) | 596 | struct net_device *dev) |
598 | { | 597 | { |
599 | struct cycx_x25_channel *chan = dev->priv; | 598 | struct cycx_x25_channel *chan = netdev_priv(dev); |
600 | struct cycx_device *card = chan->card; | 599 | struct cycx_device *card = chan->card; |
601 | 600 | ||
602 | if (!chan->svc) | 601 | if (!chan->svc) |
@@ -670,7 +669,7 @@ free_packet: | |||
670 | * Return a pointer to struct net_device_stats */ | 669 | * Return a pointer to struct net_device_stats */ |
671 | static struct net_device_stats *cycx_netdevice_get_stats(struct net_device *dev) | 670 | static struct net_device_stats *cycx_netdevice_get_stats(struct net_device *dev) |
672 | { | 671 | { |
673 | struct cycx_x25_channel *chan = dev->priv; | 672 | struct cycx_x25_channel *chan = netdev_priv(dev); |
674 | 673 | ||
675 | return chan ? &chan->ifstats : NULL; | 674 | return chan ? &chan->ifstats : NULL; |
676 | } | 675 | } |
@@ -783,7 +782,7 @@ static void cycx_x25_irq_rx(struct cycx_device *card, struct cycx_x25_cmd *cmd) | |||
783 | return; | 782 | return; |
784 | } | 783 | } |
785 | 784 | ||
786 | chan = dev->priv; | 785 | chan = netdev_priv(dev); |
787 | reset_timer(dev); | 786 | reset_timer(dev); |
788 | 787 | ||
789 | if (chan->drop_sequence) { | 788 | if (chan->drop_sequence) { |
@@ -883,7 +882,7 @@ static void cycx_x25_irq_connect(struct cycx_device *card, | |||
883 | return; | 882 | return; |
884 | } | 883 | } |
885 | 884 | ||
886 | chan = dev->priv; | 885 | chan = netdev_priv(dev); |
887 | chan->lcn = lcn; | 886 | chan->lcn = lcn; |
888 | cycx_x25_connect_response(card, chan); | 887 | cycx_x25_connect_response(card, chan); |
889 | cycx_x25_set_chan_state(dev, WAN_CONNECTED); | 888 | cycx_x25_set_chan_state(dev, WAN_CONNECTED); |
@@ -913,7 +912,7 @@ static void cycx_x25_irq_connect_confirm(struct cycx_device *card, | |||
913 | } | 912 | } |
914 | 913 | ||
915 | clear_bit(--key, (void*)&card->u.x.connection_keys); | 914 | clear_bit(--key, (void*)&card->u.x.connection_keys); |
916 | chan = dev->priv; | 915 | chan = netdev_priv(dev); |
917 | chan->lcn = lcn; | 916 | chan->lcn = lcn; |
918 | cycx_x25_set_chan_state(dev, WAN_CONNECTED); | 917 | cycx_x25_set_chan_state(dev, WAN_CONNECTED); |
919 | } | 918 | } |
@@ -953,7 +952,7 @@ static void cycx_x25_irq_disconnect(struct cycx_device *card, | |||
953 | 952 | ||
954 | dev = cycx_x25_get_dev_by_lcn(wandev, lcn); | 953 | dev = cycx_x25_get_dev_by_lcn(wandev, lcn); |
955 | if (dev) { | 954 | if (dev) { |
956 | struct cycx_x25_channel *chan = dev->priv; | 955 | struct cycx_x25_channel *chan = netdev_priv(dev); |
957 | 956 | ||
958 | cycx_x25_disconnect_response(card, chan->link, lcn); | 957 | cycx_x25_disconnect_response(card, chan->link, lcn); |
959 | cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); | 958 | cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); |
@@ -1301,7 +1300,7 @@ static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev, | |||
1301 | struct cycx_x25_channel *chan; | 1300 | struct cycx_x25_channel *chan; |
1302 | 1301 | ||
1303 | while (dev) { | 1302 | while (dev) { |
1304 | chan = (struct cycx_x25_channel*)dev->priv; | 1303 | chan = netdev_priv(dev); |
1305 | 1304 | ||
1306 | if (chan->lcn == lcn) | 1305 | if (chan->lcn == lcn) |
1307 | break; | 1306 | break; |
@@ -1318,7 +1317,7 @@ static struct net_device * | |||
1318 | struct cycx_x25_channel *chan; | 1317 | struct cycx_x25_channel *chan; |
1319 | 1318 | ||
1320 | while (dev) { | 1319 | while (dev) { |
1321 | chan = (struct cycx_x25_channel*)dev->priv; | 1320 | chan = netdev_priv(dev); |
1322 | 1321 | ||
1323 | if (!strcmp(chan->addr, dte)) | 1322 | if (!strcmp(chan->addr, dte)) |
1324 | break; | 1323 | break; |
@@ -1336,7 +1335,7 @@ static struct net_device * | |||
1336 | * <0 failure */ | 1335 | * <0 failure */ |
1337 | static int cycx_x25_chan_connect(struct net_device *dev) | 1336 | static int cycx_x25_chan_connect(struct net_device *dev) |
1338 | { | 1337 | { |
1339 | struct cycx_x25_channel *chan = dev->priv; | 1338 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1340 | struct cycx_device *card = chan->card; | 1339 | struct cycx_device *card = chan->card; |
1341 | 1340 | ||
1342 | if (chan->svc) { | 1341 | if (chan->svc) { |
@@ -1361,7 +1360,7 @@ static int cycx_x25_chan_connect(struct net_device *dev) | |||
1361 | * o if SVC then clear X.25 call */ | 1360 | * o if SVC then clear X.25 call */ |
1362 | static void cycx_x25_chan_disconnect(struct net_device *dev) | 1361 | static void cycx_x25_chan_disconnect(struct net_device *dev) |
1363 | { | 1362 | { |
1364 | struct cycx_x25_channel *chan = dev->priv; | 1363 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1365 | 1364 | ||
1366 | if (chan->svc) { | 1365 | if (chan->svc) { |
1367 | x25_clear_call(chan->card, chan->link, chan->lcn, 0, 0); | 1366 | x25_clear_call(chan->card, chan->link, chan->lcn, 0, 0); |
@@ -1374,7 +1373,7 @@ static void cycx_x25_chan_disconnect(struct net_device *dev) | |||
1374 | static void cycx_x25_chan_timer(unsigned long d) | 1373 | static void cycx_x25_chan_timer(unsigned long d) |
1375 | { | 1374 | { |
1376 | struct net_device *dev = (struct net_device *)d; | 1375 | struct net_device *dev = (struct net_device *)d; |
1377 | struct cycx_x25_channel *chan = dev->priv; | 1376 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1378 | 1377 | ||
1379 | if (chan->state == WAN_CONNECTED) | 1378 | if (chan->state == WAN_CONNECTED) |
1380 | cycx_x25_chan_disconnect(dev); | 1379 | cycx_x25_chan_disconnect(dev); |
@@ -1386,7 +1385,7 @@ static void cycx_x25_chan_timer(unsigned long d) | |||
1386 | /* Set logical channel state. */ | 1385 | /* Set logical channel state. */ |
1387 | static void cycx_x25_set_chan_state(struct net_device *dev, u8 state) | 1386 | static void cycx_x25_set_chan_state(struct net_device *dev, u8 state) |
1388 | { | 1387 | { |
1389 | struct cycx_x25_channel *chan = dev->priv; | 1388 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1390 | struct cycx_device *card = chan->card; | 1389 | struct cycx_device *card = chan->card; |
1391 | unsigned long flags; | 1390 | unsigned long flags; |
1392 | char *string_state = NULL; | 1391 | char *string_state = NULL; |
@@ -1452,7 +1451,7 @@ static void cycx_x25_set_chan_state(struct net_device *dev, u8 state) | |||
1452 | * to the router. */ | 1451 | * to the router. */ |
1453 | static int cycx_x25_chan_send(struct net_device *dev, struct sk_buff *skb) | 1452 | static int cycx_x25_chan_send(struct net_device *dev, struct sk_buff *skb) |
1454 | { | 1453 | { |
1455 | struct cycx_x25_channel *chan = dev->priv; | 1454 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1456 | struct cycx_device *card = chan->card; | 1455 | struct cycx_device *card = chan->card; |
1457 | int bitm = 0; /* final packet */ | 1456 | int bitm = 0; /* final packet */ |
1458 | unsigned len = skb->len; | 1457 | unsigned len = skb->len; |
@@ -1545,7 +1544,7 @@ static unsigned dec_to_uint(u8 *str, int len) | |||
1545 | 1544 | ||
1546 | static void reset_timer(struct net_device *dev) | 1545 | static void reset_timer(struct net_device *dev) |
1547 | { | 1546 | { |
1548 | struct cycx_x25_channel *chan = dev->priv; | 1547 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1549 | 1548 | ||
1550 | if (chan->svc) | 1549 | if (chan->svc) |
1551 | mod_timer(&chan->timer, jiffies+chan->idle_tmout*HZ); | 1550 | mod_timer(&chan->timer, jiffies+chan->idle_tmout*HZ); |
@@ -1598,7 +1597,7 @@ static void cycx_x25_dump_devs(struct wan_device *wandev) | |||
1598 | printk(KERN_INFO "---------------------------------------\n"); | 1597 | printk(KERN_INFO "---------------------------------------\n"); |
1599 | 1598 | ||
1600 | while(dev) { | 1599 | while(dev) { |
1601 | struct cycx_x25_channel *chan = dev->priv; | 1600 | struct cycx_x25_channel *chan = netdev_priv(dev); |
1602 | 1601 | ||
1603 | printk(KERN_INFO "%-5.5s %-15.15s %d ETH_P_%s\n", | 1602 | printk(KERN_INFO "%-5.5s %-15.15s %d ETH_P_%s\n", |
1604 | chan->name, chan->addr, netif_queue_stopped(dev), | 1603 | chan->name, chan->addr, netif_queue_stopped(dev), |