]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/rt2x00/rt2x00usb.c
rt2x00: Replace DRV_NAME with KBUILD_MODNAME
[linux-2.6] / drivers / net / wireless / rt2x00 / rt2x00usb.c
index 73cc726c4046724f01f6e5b9e1b88b5eaf8dc0d2..9b55f7997ca211ede7e482dda8e74306581449c7 100644 (file)
        Abstract: rt2x00 generic usb device routines.
  */
 
-/*
- * Set enviroment defines for rt2x00.h
- */
-#define DRV_NAME "rt2x00usb"
-
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/usb.h>
+#include <linux/bug.h>
 
 #include "rt2x00.h"
 #include "rt2x00usb.h"
@@ -38,7 +34,7 @@
 /*
  * Interfacing with the HW.
  */
-int rt2x00usb_vendor_request(const struct rt2x00_dev *rt2x00dev,
+int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
                             const u8 request, const u8 requesttype,
                             const u16 offset, const u16 value,
                             void *buffer, const u16 buffer_length,
@@ -52,6 +48,7 @@ int rt2x00usb_vendor_request(const struct rt2x00_dev *rt2x00dev,
            (requesttype == USB_VENDOR_REQUEST_IN) ?
            usb_rcvctrlpipe(usb_dev, 0) : usb_sndctrlpipe(usb_dev, 0);
 
+
        for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
                status = usb_control_msg(usb_dev, pipe, request, requesttype,
                                         value, offset, buffer, buffer_length,
@@ -76,13 +73,15 @@ int rt2x00usb_vendor_request(const struct rt2x00_dev *rt2x00dev,
 }
 EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request);
 
-int rt2x00usb_vendor_request_buff(const struct rt2x00_dev *rt2x00dev,
-                                 const u8 request, const u8 requesttype,
-                                 const u16 offset, void *buffer,
-                                 const u16 buffer_length, const int timeout)
+int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
+                                  const u8 request, const u8 requesttype,
+                                  const u16 offset, void *buffer,
+                                  const u16 buffer_length, const int timeout)
 {
        int status;
 
+       BUG_ON(!mutex_is_locked(&rt2x00dev->usb_cache_mutex));
+
        /*
         * Check for Cache availability.
         */
@@ -103,6 +102,25 @@ int rt2x00usb_vendor_request_buff(const struct rt2x00_dev *rt2x00dev,
 
        return status;
 }
+EXPORT_SYMBOL_GPL(rt2x00usb_vendor_req_buff_lock);
+
+int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
+                                 const u8 request, const u8 requesttype,
+                                 const u16 offset, void *buffer,
+                                 const u16 buffer_length, const int timeout)
+{
+       int status;
+
+       mutex_lock(&rt2x00dev->usb_cache_mutex);
+
+       status = rt2x00usb_vendor_req_buff_lock(rt2x00dev, request,
+                                               requesttype, offset, buffer,
+                                               buffer_length, timeout);
+
+       mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       return status;
+}
 EXPORT_SYMBOL_GPL(rt2x00usb_vendor_request_buff);
 
 /*
@@ -113,7 +131,7 @@ static void rt2x00usb_interrupt_txdone(struct urb *urb)
        struct data_entry *entry = (struct data_entry *)urb->context;
        struct data_ring *ring = entry->ring;
        struct rt2x00_dev *rt2x00dev = ring->rt2x00dev;
-       struct data_desc *txd = (struct data_desc *)entry->skb->data;
+       __le32 *txd = (__le32 *)entry->skb->data;
        u32 word;
        int tx_status;
 
@@ -159,7 +177,6 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
            interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
        struct data_entry *entry = rt2x00_get_data_entry(ring);
        int pipe = usb_sndbulkpipe(usb_dev, 1);
-       int max_packet = usb_maxpacket(usb_dev, pipe, 1);
        u32 length;
 
        if (rt2x00_ring_full(ring)) {
@@ -182,7 +199,7 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
        skb_push(skb, ring->desc_size);
        memset(skb->data, 0, ring->desc_size);
 
-       rt2x00lib_write_tx_desc(rt2x00dev, (struct data_desc *)skb->data,
+       rt2x00lib_write_tx_desc(rt2x00dev, (__le32 *)skb->data,
                                (struct ieee80211_hdr *)(skb->data +
                                                         ring->desc_size),
                                skb->len - ring->desc_size, control);
@@ -194,8 +211,7 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
         * length of the data to usb_fill_bulk_urb. Pass the skb
         * to the driver to determine what the length should be.
         */
-       length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev,
-                                                     max_packet, skb);
+       length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, skb);
 
        /*
         * Initialize URB and send the frame to the device.
@@ -223,7 +239,9 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
        struct data_ring *ring = entry->ring;
        struct rt2x00_dev *rt2x00dev = ring->rt2x00dev;
        struct sk_buff *skb;
+       struct ieee80211_hdr *hdr;
        struct rxdata_entry_desc desc;
+       int header_size;
        int frame_size;
 
        if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
@@ -245,19 +263,37 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
         * Allocate a new sk buffer to replace the current one.
         * If allocation fails, we should drop the current frame
         * so we can recycle the existing sk buffer for the new frame.
+        * As alignment we use 2 and not NET_IP_ALIGN because we need
+        * to be sure we have 2 bytes room in the head. (NET_IP_ALIGN
+        * can be 0 on some hardware). We use these 2 bytes for frame
+        * alignment later, we assume that the chance that
+        * header_size % 4 == 2 is bigger then header_size % 2 == 0
+        * and thus optimize alignment by reserving the 2 bytes in
+        * advance.
         */
        frame_size = entry->ring->data_size + entry->ring->desc_size;
-       skb = dev_alloc_skb(frame_size + NET_IP_ALIGN);
+       skb = dev_alloc_skb(frame_size + 2);
        if (!skb)
                goto skip_entry;
 
-       skb_reserve(skb, NET_IP_ALIGN);
+       skb_reserve(skb, 2);
        skb_put(skb, frame_size);
 
        /*
-        * Trim the skb_buffer to only contain the valid
-        * frame data (so ignore the device's descriptor).
+        * The data behind the ieee80211 header must be
+        * aligned on a 4 byte boundary.
+        * After that trim the entire buffer down to only
+        * contain the valid frame data excluding the device
+        * descriptor.
         */
+       hdr = (struct ieee80211_hdr *)entry->skb->data;
+       header_size =
+           ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
+
+       if (header_size % 4 == 0) {
+               skb_push(entry->skb, 2);
+               memmove(entry->skb->data, entry->skb->data + 2, skb->len - 2);
+       }
        skb_trim(entry->skb, desc.size);
 
        /*
@@ -489,6 +525,12 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
        rt2x00dev->dev = usb_intf;
        rt2x00dev->ops = ops;
        rt2x00dev->hw = hw;
+       mutex_init(&rt2x00dev->usb_cache_mutex);
+
+       rt2x00dev->usb_maxpacket =
+           usb_maxpacket(usb_dev, usb_sndbulkpipe(usb_dev, 1), 1);
+       if (!rt2x00dev->usb_maxpacket)
+               rt2x00dev->usb_maxpacket = 1;
 
        retval = rt2x00usb_alloc_reg(rt2x00dev);
        if (retval)