nfsd: minor nfsd_vfs_write cleanup
[safe/jmp/linux-2.6] / drivers / net / irda / ksdazzle-sir.c
index af60f24..64df27f 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
 *
 * Filename:      ksdazzle.c
-* Version:       0.1.1
+* Version:       0.1.2
 * Description:   Irda KingSun Dazzle USB Dongle
 * Status:        Experimental
 * Author:        Alex VillacĂ­s Lasso <a_villacis@palosanto.com>
@@ -82,7 +82,6 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <linux/module.h>
 #include <linux/kref.h>
 #include <linux/usb.h>
 #include <linux/device.h>
@@ -113,6 +112,7 @@ MODULE_DEVICE_TABLE(usb, dongles);
 #define KINGSUN_REQ_SEND 0x09
 
 #define KINGSUN_SND_FIFO_SIZE    2048  /* Max packet we can send */
+#define KINGSUN_RCV_MAX 2048   /* Max transfer we can receive */
 
 struct ksdazzle_speedparams {
        __le32 baudrate;        /* baud rate, little endian */
@@ -140,7 +140,7 @@ struct ksdazzle_cb {
        struct usb_device *usbdev;      /* init: probe_irda */
        struct net_device *netdev;      /* network layer */
        struct irlap_cb *irlap; /* The link layer we are binded to */
-       struct net_device_stats stats;  /* network statistics */
+
        struct qos_info qos;
 
        struct urb *tx_urb;
@@ -150,7 +150,7 @@ struct ksdazzle_cb {
        __u8 tx_payload[8];
 
        struct urb *rx_urb;
-       __u8 rx_payload[8];
+       __u8 *rx_buf;
        iobuff_t rx_unwrap_buff;
 
        struct usb_ctrlrequest *speed_setuprequest;
@@ -278,7 +278,7 @@ static void ksdazzle_send_irq(struct urb *urb)
                                case -EPIPE:
                                        break;
                                default:
-                                       kingsun->stats.tx_errors++;
+                                       netdev->stats.tx_errors++;
                                        netif_start_queue(netdev);
                                }
                        }
@@ -329,12 +329,12 @@ static int ksdazzle_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
                case -EPIPE:
                        break;
                default:
-                       kingsun->stats.tx_errors++;
+                       netdev->stats.tx_errors++;
                        netif_start_queue(netdev);
                }
        } else {
-               kingsun->stats.tx_packets++;
-               kingsun->stats.tx_bytes += skb->len;
+               netdev->stats.tx_packets++;
+               netdev->stats.tx_bytes += skb->len;
 
        }
 
@@ -348,9 +348,10 @@ static int ksdazzle_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
 static void ksdazzle_rcv_irq(struct urb *urb)
 {
        struct ksdazzle_cb *kingsun = urb->context;
+       struct net_device *netdev = kingsun->netdev;
 
        /* in process of stopping, just drop data */
-       if (!netif_running(kingsun->netdev)) {
+       if (!netif_running(netdev)) {
                kingsun->receiving = 0;
                return;
        }
@@ -368,10 +369,9 @@ static void ksdazzle_rcv_irq(struct urb *urb)
                unsigned int i;
 
                for (i = 0; i < urb->actual_length; i++) {
-                       async_unwrap_char(kingsun->netdev, &kingsun->stats,
+                       async_unwrap_char(netdev, &netdev->stats,
                                          &kingsun->rx_unwrap_buff, bytes[i]);
                }
-               kingsun->netdev->last_rx = jiffies;
                kingsun->receiving =
                    (kingsun->rx_unwrap_buff.state != OUTSIDE_FRAME) ? 1 : 0;
        }
@@ -440,7 +440,8 @@ static int ksdazzle_net_open(struct net_device *netdev)
        /* Start reception. */
        usb_fill_int_urb(kingsun->rx_urb, kingsun->usbdev,
                         usb_rcvintpipe(kingsun->usbdev, kingsun->ep_in),
-                        kingsun->rx_payload, 8, ksdazzle_rcv_irq, kingsun, 1);
+                        kingsun->rx_buf, KINGSUN_RCV_MAX, ksdazzle_rcv_irq,
+                        kingsun, 1);
        kingsun->rx_urb->status = 0;
        err = usb_submit_urb(kingsun->rx_urb, GFP_KERNEL);
        if (err) {
@@ -561,15 +562,12 @@ static int ksdazzle_net_ioctl(struct net_device *netdev, struct ifreq *rq,
        return ret;
 }
 
-/*
- * Get device stats (for /proc/net/dev and ifconfig)
- */
-static struct net_device_stats *ksdazzle_net_get_stats(struct net_device
-                                                      *netdev)
-{
-       struct ksdazzle_cb *kingsun = netdev_priv(netdev);
-       return &kingsun->stats;
-}
+static const struct net_device_ops ksdazzle_ops = {
+       .ndo_start_xmit = ksdazzle_hard_xmit,
+       .ndo_open       = ksdazzle_net_open,
+       .ndo_stop       = ksdazzle_net_close,
+       .ndo_do_ioctl   = ksdazzle_net_ioctl,
+};
 
 /*
  * This routine is called by the USB subsystem for each new device
@@ -641,6 +639,7 @@ static int ksdazzle_probe(struct usb_interface *intf,
        kingsun->tx_buf_clear_sent = 0;
 
        kingsun->rx_urb = NULL;
+       kingsun->rx_buf = NULL;
        kingsun->rx_unwrap_buff.in_frame = FALSE;
        kingsun->rx_unwrap_buff.state = OUTSIDE_FRAME;
        kingsun->rx_unwrap_buff.skb = NULL;
@@ -651,6 +650,11 @@ static int ksdazzle_probe(struct usb_interface *intf,
        kingsun->speed_urb = NULL;
        kingsun->speedparams.baudrate = 0;
 
+       /* Allocate input buffer */
+       kingsun->rx_buf = kmalloc(KINGSUN_RCV_MAX, GFP_KERNEL);
+       if (!kingsun->rx_buf)
+               goto free_mem;
+
        /* Allocate output buffer */
        kingsun->tx_buf_clear = kmalloc(KINGSUN_SND_FIFO_SIZE, GFP_KERNEL);
        if (!kingsun->tx_buf_clear)
@@ -687,17 +691,14 @@ static int ksdazzle_probe(struct usb_interface *intf,
        irda_qos_bits_to_value(&kingsun->qos);
 
        /* Override the network functions we need to use */
-       net->hard_start_xmit = ksdazzle_hard_xmit;
-       net->open = ksdazzle_net_open;
-       net->stop = ksdazzle_net_close;
-       net->get_stats = ksdazzle_net_get_stats;
-       net->do_ioctl = ksdazzle_net_ioctl;
+       net->netdev_ops = &ksdazzle_ops;
 
        ret = register_netdev(net);
        if (ret != 0)
                goto free_mem;
 
-       info("IrDA: Registered KingSun/Dazzle device %s", net->name);
+       dev_info(&net->dev, "IrDA: Registered KingSun/Dazzle device %s\n",
+                net->name);
 
        usb_set_intfdata(intf, kingsun);
 
@@ -714,6 +715,7 @@ static int ksdazzle_probe(struct usb_interface *intf,
       free_mem:
        kfree(kingsun->speed_setuprequest);
        kfree(kingsun->tx_buf_clear);
+       kfree(kingsun->rx_buf);
        free_netdev(net);
       err_out1:
        return ret;
@@ -746,6 +748,7 @@ static void ksdazzle_disconnect(struct usb_interface *intf)
 
        kfree(kingsun->speed_setuprequest);
        kfree(kingsun->tx_buf_clear);
+       kfree(kingsun->rx_buf);
        free_netdev(kingsun->netdev);
 
        usb_set_intfdata(intf, NULL);