[DRIVER MODEL] Convert platform drivers to use struct platform_driver
[safe/jmp/linux-2.6] / drivers / usb / gadget / ether.c
index 3830a0a..8f402f8 100644 (file)
@@ -91,12 +91,12 @@ static const char driver_desc [] = DRIVER_DESC;
 
 #define RX_EXTRA       20              /* guard against rx overflows */
 
-#ifdef CONFIG_USB_ETH_RNDIS
 #include "rndis.h"
-#else
-#define rndis_init()   0
-#define rndis_uninit(x)        do{}while(0)
-#define rndis_exit()   do{}while(0)
+
+#ifndef        CONFIG_USB_ETH_RNDIS
+#define rndis_uninit(x)                do{}while(0)
+#define rndis_deregister(c)    do{}while(0)
+#define rndis_exit()           do{}while(0)
 #endif
 
 /* CDC and RNDIS support the same host-chosen outgoing packet filters. */
@@ -945,15 +945,16 @@ config_buf (enum usb_device_speed speed,
 
 /*-------------------------------------------------------------------------*/
 
-static void eth_start (struct eth_dev *dev, int gfp_flags);
-static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags);
+static void eth_start (struct eth_dev *dev, gfp_t gfp_flags);
+static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags);
 
 static int
-set_ether_config (struct eth_dev *dev, int gfp_flags)
+set_ether_config (struct eth_dev *dev, gfp_t gfp_flags)
 {
        int                                     result = 0;
        struct usb_gadget                       *gadget = dev->gadget;
 
+#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
        /* status endpoint used for RNDIS and (optionally) CDC */
        if (!subset_active(dev) && dev->status_ep) {
                dev->status = ep_desc (gadget, &hs_status_desc,
@@ -967,6 +968,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags)
                        goto done;
                }
        }
+#endif
 
        dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc);
        dev->in_ep->driver_data = dev;
@@ -1079,7 +1081,7 @@ static void eth_reset_config (struct eth_dev *dev)
  * that returns config descriptors, and altsetting code.
  */
 static int
-eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
+eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags)
 {
        int                     result = 0;
        struct usb_gadget       *gadget = dev->gadget;
@@ -1133,9 +1135,9 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags)
                dev->config = number;
                INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n",
                                speed, number, power, driver_desc,
-                               dev->rndis
+                               rndis_active(dev)
                                        ? "RNDIS"
-                                       : (dev->cdc
+                                       : (cdc_active(dev)
                                                ? "CDC Ethernet"
                                                : "CDC Ethernet Subset"));
        }
@@ -1277,9 +1279,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
        struct eth_dev          *dev = get_gadget_data (gadget);
        struct usb_request      *req = dev->req;
        int                     value = -EOPNOTSUPP;
-       u16                     wIndex = (__force u16) ctrl->wIndex;
-       u16                     wValue = (__force u16) ctrl->wValue;
-       u16                     wLength = (__force u16) ctrl->wLength;
+       u16                     wIndex = le16_to_cpu(ctrl->wIndex);
+       u16                     wValue = le16_to_cpu(ctrl->wValue);
+       u16                     wLength = le16_to_cpu(ctrl->wLength);
 
        /* descriptors just go into the pre-allocated ep0 buffer,
         * while config change events may enable network traffic.
@@ -1350,7 +1352,7 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                                || !dev->config
                                || wIndex > 1)
                        break;
-               if (!dev->cdc && wIndex != 0)
+               if (!cdc_active(dev) && wIndex != 0)
                        break;
                spin_lock (&dev->lock);
 
@@ -1420,11 +1422,11 @@ done_set_intf:
                                || !dev->config
                                || wIndex > 1)
                        break;
-               if (!(dev->cdc || dev->rndis) && wIndex != 0)
+               if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0)
                        break;
 
                /* for CDC, iff carrier is on, data interface is active. */
-               if (dev->rndis || wIndex != 1)
+               if (rndis_active(dev) || wIndex != 1)
                        *(u8 *)req->buf = 0;
                else
                        *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0;
@@ -1437,8 +1439,7 @@ done_set_intf:
                 * wValue = packet filter bitmap
                 */
                if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
-                               || !dev->cdc
-                               || dev->rndis
+                               || !cdc_active(dev)
                                || wLength != 0
                                || wIndex > 1)
                        break;
@@ -1462,7 +1463,7 @@ done_set_intf:
         */
        case USB_CDC_SEND_ENCAPSULATED_COMMAND:
                if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE)
-                               || !dev->rndis
+                               || !rndis_active(dev)
                                || wLength > USB_BUFSIZ
                                || wValue
                                || rndis_control_intf.bInterfaceNumber
@@ -1477,7 +1478,7 @@ done_set_intf:
        case USB_CDC_GET_ENCAPSULATED_RESPONSE:
                if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)
                                        == ctrl->bRequestType
-                               && dev->rndis
+                               && rndis_active(dev)
                                // && wLength >= 0x0400
                                && !wValue
                                && rndis_control_intf.bInterfaceNumber
@@ -1597,7 +1598,7 @@ static void defer_kevent (struct eth_dev *dev, int flag)
 static void rx_complete (struct usb_ep *ep, struct usb_request *req);
 
 static int
-rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags)
+rx_submit (struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
 {
        struct sk_buff          *skb;
        int                     retval = -ENOMEM;
@@ -1661,11 +1662,9 @@ static void rx_complete (struct usb_ep *ep, struct usb_request *req)
        /* normal completion */
        case 0:
                skb_put (skb, req->actual);
-#ifdef CONFIG_USB_ETH_RNDIS
                /* we know MaxPacketsPerTransfer == 1 here */
-               if (dev->rndis)
+               if (rndis_active(dev))
                        status = rndis_rm_hdr (skb);
-#endif
                if (status < 0
                                || ETH_HLEN > skb->len
                                || skb->len > ETH_FRAME_LEN) {
@@ -1725,7 +1724,7 @@ clean:
 }
 
 static int prealloc (struct list_head *list, struct usb_ep *ep,
-                       unsigned n, int gfp_flags)
+                       unsigned n, gfp_t gfp_flags)
 {
        unsigned                i;
        struct usb_request      *req;
@@ -1764,7 +1763,7 @@ extra:
        return 0;
 }
 
-static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags)
+static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
 {
        int status;
 
@@ -1780,7 +1779,7 @@ fail:
        return status;
 }
 
-static void rx_fill (struct eth_dev *dev, int gfp_flags)
+static void rx_fill (struct eth_dev *dev, gfp_t gfp_flags)
 {
        struct usb_request      *req;
        unsigned long           flags;
@@ -1893,8 +1892,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
         * or the hardware can't use skb buffers.
         * or there's not enough space for any RNDIS headers we need
         */
-#ifdef CONFIG_USB_ETH_RNDIS
-       if (dev->rndis) {
+       if (rndis_active(dev)) {
                struct sk_buff  *skb_rndis;
 
                skb_rndis = skb_realloc_headroom (skb,
@@ -1907,7 +1905,6 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
                rndis_add_hdr (skb);
                length = skb->len;
        }
-#endif
        req->buf = skb->data;
        req->context = skb;
        req->complete = tx_complete;
@@ -1940,9 +1937,7 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
        }
 
        if (retval) {
-#ifdef CONFIG_USB_ETH_RNDIS
 drop:
-#endif
                dev->stats.tx_dropped++;
                dev_kfree_skb_any (skb);
                spin_lock_irqsave (&dev->lock, flags);
@@ -1967,7 +1962,7 @@ drop:
  * normally just one notification will be queued.
  */
 
-static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned);
+static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, gfp_t);
 static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
 
 static void
@@ -2023,9 +2018,13 @@ static int rndis_control_ack (struct net_device *net)
        return 0;
 }
 
+#else
+
+#define        rndis_control_ack       NULL
+
 #endif /* RNDIS */
 
-static void eth_start (struct eth_dev *dev, int gfp_flags)
+static void eth_start (struct eth_dev *dev, gfp_t gfp_flags)
 {
        DEBUG (dev, "%s\n", __FUNCTION__);
 
@@ -2035,14 +2034,12 @@ static void eth_start (struct eth_dev *dev, int gfp_flags)
        /* and open the tx floodgates */ 
        atomic_set (&dev->tx_qlen, 0);
        netif_wake_queue (dev->net);
-#ifdef CONFIG_USB_ETH_RNDIS
-       if (dev->rndis) {
+       if (rndis_active(dev)) {
                rndis_set_param_medium (dev->rndis_config,
                                        NDIS_MEDIUM_802_3,
                                        BITRATE(dev->gadget)/100);
                (void) rndis_signal_connect (dev->rndis_config);
        }
-#endif 
 }
 
 static int eth_open (struct net_device *net)
@@ -2083,13 +2080,11 @@ static int eth_stop (struct net_device *net)
                }
        }
        
-#ifdef CONFIG_USB_ETH_RNDIS
-       if (dev->rndis) {
+       if (rndis_active(dev)) {
                rndis_set_param_medium (dev->rndis_config,
                                        NDIS_MEDIUM_802_3, 0);
                (void) rndis_signal_disconnect (dev->rndis_config);
        }
-#endif
 
        return 0;
 }
@@ -2097,7 +2092,7 @@ static int eth_stop (struct net_device *net)
 /*-------------------------------------------------------------------------*/
 
 static struct usb_request *
-eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags)
+eth_req_alloc (struct usb_ep *ep, unsigned size, gfp_t gfp_flags)
 {
        struct usb_request      *req;
 
@@ -2127,10 +2122,8 @@ eth_unbind (struct usb_gadget *gadget)
        struct eth_dev          *dev = get_gadget_data (gadget);
 
        DEBUG (dev, "unbind\n");
-#ifdef CONFIG_USB_ETH_RNDIS
        rndis_deregister (dev->rndis_config);
        rndis_exit ();
-#endif
 
        /* we've already been disconnected ... no i/o is active */
        if (dev->req) {
@@ -2188,6 +2181,7 @@ eth_bind (struct usb_gadget *gadget)
        u8                      cdc = 1, zlp = 1, rndis = 1;
        struct usb_ep           *in_ep, *out_ep, *status_ep = NULL;
        int                     status = -ENOMEM;
+       int                     gcnum;
 
        /* these flags are only ever cleared; compiler take note */
 #ifndef        DEV_CONFIG_CDC
@@ -2201,44 +2195,26 @@ eth_bind (struct usb_gadget *gadget)
         * standard protocol is _strongly_ preferred for interop purposes.
         * (By everyone except Microsoft.)
         */
-       if (gadget_is_net2280 (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
-       } else if (gadget_is_dummy (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0202);
-       } else if (gadget_is_pxa (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0203);
+       if (gadget_is_pxa (gadget)) {
                /* pxa doesn't support altsettings */
                cdc = 0;
        } else if (gadget_is_sh(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0204);
                /* sh doesn't support multiple interfaces or configs */
                cdc = 0;
                rndis = 0;
        } else if (gadget_is_sa1100 (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0205);
                /* hardware can't write zlps */
                zlp = 0;
                /* sa1100 CAN do CDC, without status endpoint ... we use
                 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth".
                 */
                cdc = 0;
-       } else if (gadget_is_goku (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0206);
-       } else if (gadget_is_mq11xx (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0207);
-       } else if (gadget_is_omap (gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0208);
-       } else if (gadget_is_lh7a40x(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0209);
-       } else if (gadget_is_n9604(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0210);
-       } else if (gadget_is_pxa27x(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0211);
-       } else if (gadget_is_s3c2410(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0212);
-       } else if (gadget_is_at91(gadget)) {
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x0213);
-       } else {
+       }
+
+       gcnum = usb_gadget_controller_number (gadget);
+       if (gcnum >= 0)
+               device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum);
+       else {
                /* can't assume CDC works.  don't want to default to
                 * anything less functional on CDC-capable hardware,
                 * so we fail in this case.
@@ -2437,6 +2413,7 @@ autoconf_fail:
        dev->req->complete = eth_setup_complete;
 
        /* ... and maybe likewise for status transfer */
+#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
        if (dev->status_ep) {
                dev->stat_req = eth_req_alloc (dev->status_ep,
                                        STATUS_BYTECOUNT, GFP_KERNEL);
@@ -2446,6 +2423,7 @@ autoconf_fail:
                }
                dev->stat_req->context = NULL;
        }
+#endif
 
        /* finish hookup to lower layer ... */
        dev->gadget = gadget;
@@ -2481,7 +2459,6 @@ autoconf_fail:
                        dev->host_mac [2], dev->host_mac [3],
                        dev->host_mac [4], dev->host_mac [5]);
 
-#ifdef CONFIG_USB_ETH_RNDIS
        if (rndis) {
                u32     vendorID = 0;
 
@@ -2509,7 +2486,6 @@ fail0:
                        goto fail0;
                INFO (dev, "RNDIS ready\n");
        }
-#endif 
 
        return status;
 
@@ -2557,6 +2533,7 @@ static struct usb_gadget_driver eth_driver = {
 
        .driver         = {
                .name           = (char *) shortname,
+               .owner          = THIS_MODULE,
                // .shutdown = ...
                // .suspend = ...
                // .resume = ...