prism54: convert to internal net_device_stats
[safe/jmp/linux-2.6] / drivers / net / hamradio / baycom_epp.c
index 9220de9..bb78c11 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/hdlcdrv.h>
 #include <linux/baycom.h>
 #include <linux/jiffies.h>
+#include <linux/random.h>
 #include <net/ax25.h> 
 #include <asm/uaccess.h>
 
@@ -168,8 +169,9 @@ struct baycom_state {
        int magic;
 
         struct pardevice *pdev;
+       struct net_device *dev;
        unsigned int work_running;
-       struct work_struct run_work;
+       struct delayed_work run_work;
        unsigned int modem;
        unsigned int bitrate;
        unsigned char stat;
@@ -201,7 +203,6 @@ struct baycom_state {
                unsigned char buf[TXBUFFER_SIZE];
         } hdlctx;
 
-        struct net_device_stats stats;
        unsigned int ptt_keyed;
        struct sk_buff *skb;  /* next transmit packet  */
 
@@ -318,13 +319,7 @@ static int eppconfig(struct baycom_state *bc)
        sprintf(portarg, "%ld", bc->pdev->port->base);
        printk(KERN_DEBUG "%s: %s -s -p %s -m %s\n", bc_drvname, eppconfig_path, portarg, modearg);
 
-       return call_usermodehelper(eppconfig_path, argv, envp, 1);
-}
-
-/* ---------------------------------------------------------------------- */
-
-static void epp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
-{
+       return call_usermodehelper(eppconfig_path, argv, envp, UMH_WAIT_PROC);
 }
 
 /* ---------------------------------------------------------------------- */
@@ -427,17 +422,7 @@ static void encode_hdlc(struct baycom_state *bc)
        bc->hdlctx.bufptr = bc->hdlctx.buf;
        bc->hdlctx.bufcnt = wp - bc->hdlctx.buf;
        dev_kfree_skb(skb);
-       bc->stats.tx_packets++;
-}
-
-/* ---------------------------------------------------------------------- */
-
-static unsigned short random_seed;
-
-static inline unsigned short random_num(void)
-{
-       random_seed = 28629 * random_seed + 157;
-       return random_seed;
+       bc->dev->stats.tx_packets++;
 }
 
 /* ---------------------------------------------------------------------- */
@@ -463,7 +448,7 @@ static int transmit(struct baycom_state *bc, int cnt, unsigned char stat)
                        if ((--bc->hdlctx.slotcnt) > 0)
                                return 0;
                        bc->hdlctx.slotcnt = bc->ch_params.slottime;
-                       if ((random_num() % 256) > bc->ch_params.ppersist)
+                       if ((random32() % 256) > bc->ch_params.ppersist)
                                return 0;
                }
        }
@@ -561,7 +546,7 @@ static void do_rxpacket(struct net_device *dev)
        pktlen = bc->hdlcrx.bufcnt-2+1; /* KISS kludge */
        if (!(skb = dev_alloc_skb(pktlen))) {
                printk("%s: memory squeeze, dropping packet\n", dev->name);
-               bc->stats.rx_dropped++;
+               dev->stats.rx_dropped++;
                return;
        }
        cp = skb_put(skb, pktlen);
@@ -569,8 +554,7 @@ static void do_rxpacket(struct net_device *dev)
        memcpy(cp, bc->hdlcrx.buf, pktlen - 1);
        skb->protocol = ax25_type_trans(skb, dev);
        netif_rx(skb);
-       dev->last_rx = jiffies;
-       bc->stats.rx_packets++;
+       dev->stats.rx_packets++;
 }
 
 static int receive(struct net_device *dev, int cnt)
@@ -659,16 +643,18 @@ static int receive(struct net_device *dev, int cnt)
 #define GETTICK(x)
 #endif /* __i386__ */
 
-static void epp_bh(struct net_device *dev)
+static void epp_bh(struct work_struct *work)
 {
+       struct net_device *dev;
        struct baycom_state *bc;
        struct parport *pp;
        unsigned char stat;
        unsigned char tmp[2];
        unsigned int time1 = 0, time2 = 0, time3 = 0;
        int cnt, cnt2;
-       
-       bc = netdev_priv(dev);
+
+       bc = container_of(work, struct baycom_state, run_work.work);
+       dev = bc->dev;
        if (!bc->work_running)
                return;
        baycom_int_freq(bc);
@@ -815,19 +801,6 @@ static int baycom_set_mac_address(struct net_device *dev, void *addr)
 
 /* --------------------------------------------------------------------- */
 
-static struct net_device_stats *baycom_get_stats(struct net_device *dev)
-{
-       struct baycom_state *bc = netdev_priv(dev);
-
-       /* 
-        * Get the current statistics.  This may be called with the
-        * card open or closed. 
-        */
-       return &bc->stats;
-}
-
-/* --------------------------------------------------------------------- */
-
 static void epp_wakeup(void *handle)
 {
         struct net_device *dev = (struct net_device *)handle;
@@ -877,7 +850,7 @@ static int epp_open(struct net_device *dev)
        }
        memset(&bc->modem, 0, sizeof(bc->modem));
         bc->pdev = parport_register_device(pp, dev->name, NULL, epp_wakeup, 
-                                       epp_interrupt, PARPORT_DEV_EXCL, dev);
+                                          NULL, PARPORT_DEV_EXCL, dev);
        parport_put_port(pp);
         if (!bc->pdev) {
                 printk(KERN_ERR "%s: cannot register parport at 0x%lx\n", bc_drvname, pp->base);
@@ -889,7 +862,7 @@ static int epp_open(struct net_device *dev)
                 return -EBUSY;
         }
         dev->irq = /*pp->irq*/ 0;
-       INIT_WORK(&bc->run_work, (void *)(void *)epp_bh, dev);
+       INIT_DELAYED_WORK(&bc->run_work, epp_bh);
        bc->work_running = 1;
        bc->modem = EPP_CONVENTIONAL;
        if (eppconfig(bc))
@@ -971,7 +944,7 @@ static int epp_close(struct net_device *dev)
        unsigned char tmp[1];
 
        bc->work_running = 0;
-       flush_scheduled_work();
+       cancel_delayed_work_sync(&bc->run_work);
        bc->stat = EPP_DCDBIT;
        tmp[0] = 0;
        pp->ops->epp_write_addr(pp, tmp, 1, 0);
@@ -1078,10 +1051,10 @@ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                hi.data.cs.ptt = !!(bc->stat & EPP_PTTBIT);
                hi.data.cs.dcd = !(bc->stat & EPP_DCDBIT);
                hi.data.cs.ptt_keyed = bc->ptt_keyed;
-               hi.data.cs.tx_packets = bc->stats.tx_packets;
-               hi.data.cs.tx_errors = bc->stats.tx_errors;
-               hi.data.cs.rx_packets = bc->stats.rx_packets;
-               hi.data.cs.rx_errors = bc->stats.rx_errors;
+               hi.data.cs.tx_packets = dev->stats.tx_packets;
+               hi.data.cs.tx_errors = dev->stats.tx_errors;
+               hi.data.cs.rx_packets = dev->stats.rx_packets;
+               hi.data.cs.rx_errors = dev->stats.rx_errors;
                break;          
 
        case HDLCDRVCTL_OLDGETSTAT:
@@ -1129,6 +1102,14 @@ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 
 /* --------------------------------------------------------------------- */
 
+static const struct net_device_ops baycom_netdev_ops = {
+       .ndo_open            = epp_open,
+       .ndo_stop            = epp_close,
+       .ndo_do_ioctl        = baycom_ioctl,
+       .ndo_start_xmit      = baycom_send_packet,
+       .ndo_set_mac_address = baycom_set_mac_address,
+};
+
 /*
  * Check for a network adaptor of this type, and return '0' if one exists.
  * If dev->base_addr == 0, probe all likely locations.
@@ -1138,12 +1119,6 @@ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  */
 static void baycom_probe(struct net_device *dev)
 {
-       static char ax25_bcast[AX25_ADDR_LEN] = {
-               'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1
-       };
-       static char ax25_nocall[AX25_ADDR_LEN] = {
-               'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1
-       };
        const struct hdlcdrv_channel_params dflt_ch_params = { 
                20, 2, 10, 40, 0 
        };
@@ -1162,25 +1137,19 @@ static void baycom_probe(struct net_device *dev)
        /*
         * initialize the device struct
         */
-       dev->open = epp_open;
-       dev->stop = epp_close;
-       dev->do_ioctl = baycom_ioctl;
-       dev->hard_start_xmit = baycom_send_packet;
-       dev->get_stats = baycom_get_stats;
 
        /* Fill in the fields of the device structure */
        bc->skb = NULL;
        
-       dev->hard_header = ax25_hard_header;
-       dev->rebuild_header = ax25_rebuild_header;
-       dev->set_mac_address = baycom_set_mac_address;
+       dev->netdev_ops = &baycom_netdev_ops;
+       dev->header_ops = &ax25_header_ops;
        
        dev->type = ARPHRD_AX25;           /* AF_AX25 device */
        dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN;
        dev->mtu = AX25_DEF_PACLEN;        /* eth_mtu is the default */
        dev->addr_len = AX25_ADDR_LEN;     /* sizeof an ax.25 address */
-       memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);
-       memcpy(dev->dev_addr, ax25_nocall, AX25_ADDR_LEN);
+       memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
+       memcpy(dev->dev_addr, &null_ax25_address, AX25_ADDR_LEN);
        dev->tx_queue_len = 16;
 
        /* New style flags */
@@ -1213,6 +1182,7 @@ static void __init baycom_epp_dev_setup(struct net_device *dev)
        /*
         * initialize part of the baycom_state struct
         */
+       bc->dev = dev;
        bc->magic = BAYCOM_MAGIC;
        bc->cfg.fclk = 19666600;
        bc->cfg.bps = 9600;