Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[pandora-kernel.git] / drivers / net / usb / rndis_host.c
index 800c9d0..e1177cc 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
-// #define     DEBUG                   // error path messages, extra info
-// #define     VERBOSE                 // more; success messages
-
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/netdevice.h>
@@ -29,9 +25,8 @@
 #include <linux/mii.h>
 #include <linux/usb.h>
 #include <linux/usb/cdc.h>
-
-#include "usbnet.h"
-#include "rndis_host.h"
+#include <linux/usb/usbnet.h>
+#include <linux/usb/rndis_host.h>
 
 
 /*
@@ -199,7 +194,7 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf)
                        dev_dbg(&info->control->dev,
                                "rndis response error, code %d\n", retval);
                }
-               msleep(2);
+               msleep(20);
        }
        dev_dbg(&info->control->dev, "rndis response timeout\n");
        return -ETIMEDOUT;
@@ -223,7 +218,7 @@ EXPORT_SYMBOL_GPL(rndis_command);
  * ActiveSync 4.1 Windows driver.
  */
 static int rndis_query(struct usbnet *dev, struct usb_interface *intf,
-               void *buf, u32 oid, u32 in_len,
+               void *buf, __le32 oid, u32 in_len,
                void **reply, int *reply_len)
 {
        int retval;
@@ -271,7 +266,8 @@ response_error:
        return -EDOM;
 }
 
-int generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf)
+int
+generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags)
 {
        int                     retval;
        struct net_device       *net = dev->net;
@@ -287,7 +283,8 @@ int generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf)
                struct rndis_set_c      *set_c;
                struct rndis_halt       *halt;
        } u;
-       u32                     tmp;
+       u32                     tmp, phym_unspec;
+       __le32                  *phym;
        int                     reply_len;
        unsigned char           *bp;
 
@@ -318,6 +315,14 @@ int generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf)
        net->hard_header_len += sizeof (struct rndis_data_hdr);
        dev->hard_mtu = net->mtu + net->hard_header_len;
 
+       dev->maxpacket = usb_maxpacket(dev->udev, dev->out, 1);
+       if (dev->maxpacket == 0) {
+               if (netif_msg_probe(dev))
+                       dev_dbg(&intf->dev, "dev->maxpacket can't be 0\n");
+               retval = -EINVAL;
+               goto fail_and_release;
+       }
+
        dev->rx_urb_size = dev->hard_mtu + (dev->maxpacket + 1);
        dev->rx_urb_size &= ~(dev->maxpacket - 1);
        u.init->max_transfer_size = cpu_to_le32(dev->rx_urb_size);
@@ -358,6 +363,33 @@ int generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf)
                        dev->driver_info->early_init(dev) != 0)
                goto halt_fail_and_release;
 
+       /* Check physical medium */
+       phym = NULL;
+       reply_len = sizeof *phym;
+       retval = rndis_query(dev, intf, u.buf, OID_GEN_PHYSICAL_MEDIUM,
+                       0, (void **) &phym, &reply_len);
+       if (retval != 0 || !phym) {
+               /* OID is optional so don't fail here. */
+               phym_unspec = RNDIS_PHYSICAL_MEDIUM_UNSPECIFIED;
+               phym = &phym_unspec;
+       }
+       if ((flags & FLAG_RNDIS_PHYM_WIRELESS) &&
+                       *phym != RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
+               if (netif_msg_probe(dev))
+                       dev_dbg(&intf->dev, "driver requires wireless "
+                               "physical medium, but device is not.\n");
+               retval = -ENODEV;
+               goto halt_fail_and_release;
+       }
+       if ((flags & FLAG_RNDIS_PHYM_NOT_WIRELESS) &&
+                       *phym == RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
+               if (netif_msg_probe(dev))
+                       dev_dbg(&intf->dev, "driver requires non-wireless "
+                               "physical medium, but device is wireless.\n");
+               retval = -ENODEV;
+               goto halt_fail_and_release;
+       }
+
        /* Get designated host ethernet address */
        reply_len = ETH_ALEN;
        retval = rndis_query(dev, intf, u.buf, OID_802_3_PERMANENT_ADDRESS,
@@ -403,6 +435,11 @@ fail:
 }
 EXPORT_SYMBOL_GPL(generic_rndis_bind);
 
+static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+       return generic_rndis_bind(dev, intf, FLAG_RNDIS_PHYM_NOT_WIRELESS);
+}
+
 void rndis_unbind(struct usbnet *dev, struct usb_interface *intf)
 {
        struct rndis_halt       *halt;
@@ -518,7 +555,7 @@ EXPORT_SYMBOL_GPL(rndis_tx_fixup);
 static const struct driver_info        rndis_info = {
        .description =  "RNDIS device",
        .flags =        FLAG_ETHER | FLAG_FRAMING_RN | FLAG_NO_SETINT,
-       .bind =         generic_rndis_bind,
+       .bind =         rndis_bind,
        .unbind =       rndis_unbind,
        .status =       rndis_status,
        .rx_fixup =     rndis_rx_fixup,