aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00usb.c
diff options
context:
space:
mode:
authorGertjan van Wingerde <gwingerde@kpnplanet.nl>2008-06-06 16:54:12 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-06-14 12:17:57 -0400
commit239c249d06b0c68ae06b10d9d6ad1f8e7f39452b (patch)
tree6d59d08b738406c525f084d043b9dfd91e711fb1 /drivers/net/wireless/rt2x00/rt2x00usb.c
parentd56d453a1dd85aff08fe6965f395049725fdb04e (diff)
rt2x00: Centralize RX packet alignment handling in rt2x00lib.
When rt2x00pci will be switched over to dynamically mapped skb's instead of statically allocated DMA buffers, it no longer can handle alignment of RX packets in a copy step, and needs to implement the same scheme as rt2x00usb does. In order to make the patch on dynamically mapped skb's smaller, already centralize the alignment handling into rt2x00lib. This allows us to move more code in rt2x00lib, and thus remove code duplication between rt2x00usb and rt2x00pci. Signed-off-by: Gertjan van Wingerde <gwingerde@kpnplanet.nl> Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2x00usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c63
1 files changed, 3 insertions, 60 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 797023cad94..33833bc6d66 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -260,44 +260,6 @@ EXPORT_SYMBOL_GPL(rt2x00usb_kick_tx_queue);
260/* 260/*
261 * RX data handlers. 261 * RX data handlers.
262 */ 262 */
263static struct sk_buff* rt2x00usb_alloc_rxskb(struct data_queue *queue)
264{
265 struct sk_buff *skb;
266 unsigned int frame_size;
267 unsigned int reserved_size;
268
269 /*
270 * The frame size includes descriptor size, because the
271 * hardware directly receive the frame into the skbuffer.
272 */
273 frame_size = queue->data_size + queue->desc_size;
274
275 /*
276 * For the allocation we should keep a few things in mind:
277 * 1) 4byte alignment of 802.11 payload
278 *
279 * For (1) we need at most 4 bytes to guarentee the correct
280 * alignment. We are going to optimize the fact that the chance
281 * that the 802.11 header_size % 4 == 2 is much bigger then
282 * anything else. However since we need to move the frame up
283 * to 3 bytes to the front, which means we need to preallocate
284 * 6 bytes.
285 */
286 reserved_size = 6;
287
288 /*
289 * Allocate skbuffer.
290 */
291 skb = dev_alloc_skb(frame_size + reserved_size);
292 if (!skb)
293 return NULL;
294
295 skb_reserve(skb, reserved_size);
296 skb_put(skb, frame_size);
297
298 return skb;
299}
300
301static void rt2x00usb_interrupt_rxdone(struct urb *urb) 263static void rt2x00usb_interrupt_rxdone(struct urb *urb)
302{ 264{
303 struct queue_entry *entry = (struct queue_entry *)urb->context; 265 struct queue_entry *entry = (struct queue_entry *)urb->context;
@@ -305,8 +267,6 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
305 struct sk_buff *skb; 267 struct sk_buff *skb;
306 struct skb_frame_desc *skbdesc; 268 struct skb_frame_desc *skbdesc;
307 struct rxdone_entry_desc rxdesc; 269 struct rxdone_entry_desc rxdesc;
308 unsigned int header_size;
309 unsigned int align;
310 270
311 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) || 271 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
312 !test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) 272 !test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
@@ -330,26 +290,9 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
330 memset(&rxdesc, 0, sizeof(rxdesc)); 290 memset(&rxdesc, 0, sizeof(rxdesc));
331 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc); 291 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
332 292
333 header_size = ieee80211_get_hdrlen_from_skb(entry->skb);
334
335 /* 293 /*
336 * The data behind the ieee80211 header must be 294 * Trim the skb to the correct size.
337 * aligned on a 4 byte boundary. We already reserved
338 * 2 bytes for header_size % 4 == 2 optimization.
339 * To determine the number of bytes which the data
340 * should be moved to the left, we must add these
341 * 2 bytes to the header_size.
342 */ 295 */
343 align = (header_size + 2) % 4;
344
345 if (align) {
346 skb_push(entry->skb, align);
347 /* Move entire frame in 1 command */
348 memmove(entry->skb->data, entry->skb->data + align,
349 rxdesc.size);
350 }
351
352 /* Update data pointers, trim buffer to correct size */
353 skb_trim(entry->skb, rxdesc.size); 296 skb_trim(entry->skb, rxdesc.size);
354 297
355 /* 298 /*
@@ -357,7 +300,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
357 * If allocation fails, we should drop the current frame 300 * If allocation fails, we should drop the current frame
358 * so we can recycle the existing sk buffer for the new frame. 301 * so we can recycle the existing sk buffer for the new frame.
359 */ 302 */
360 skb = rt2x00usb_alloc_rxskb(entry->queue); 303 skb = rt2x00queue_alloc_rxskb(entry->queue);
361 if (!skb) 304 if (!skb)
362 goto skip_entry; 305 goto skip_entry;
363 306
@@ -529,7 +472,7 @@ int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev)
529 */ 472 */
530 entry_size = rt2x00dev->rx->data_size + rt2x00dev->rx->desc_size; 473 entry_size = rt2x00dev->rx->data_size + rt2x00dev->rx->desc_size;
531 for (i = 0; i < rt2x00dev->rx->limit; i++) { 474 for (i = 0; i < rt2x00dev->rx->limit; i++) {
532 skb = rt2x00usb_alloc_rxskb(rt2x00dev->rx); 475 skb = rt2x00queue_alloc_rxskb(rt2x00dev->rx);
533 if (!skb) 476 if (!skb)
534 goto exit; 477 goto exit;
535 478