Commit 30caa6e3 authored by Gertjan van Wingerde's avatar Gertjan van Wingerde Committed by John W. Linville

rt2x00: Centralize allocation of RX skbs.

In preparation of replacing the statically allocated DMA buffers with
dynamically mapped skbs, centralize the allocation of RX skbs to rt2x00queue.c
and let rt2x00pci already use them.
Signed-off-by: default avatarGertjan van Wingerde <gwingerde@kpnplanet.nl>
Signed-off-by: default avatarIvo van Doorn <IvDoorn@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 14a3bf89
...@@ -899,10 +899,16 @@ static inline u16 get_duration_res(const unsigned int size, const u8 rate) ...@@ -899,10 +899,16 @@ static inline u16 get_duration_res(const unsigned int size, const u8 rate)
} }
/** /**
* rt2x00queue_alloc_rxskb - allocate a skb for RX purposes. * rt2x00queue_alloc_skb - allocate a skb.
* @queue: The queue for which the skb will be applicable. * @queue: The queue for which the skb will be applicable.
*/ */
struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue); struct sk_buff *rt2x00queue_alloc_skb(struct data_queue *queue);
/**
* rt2x00queue_free_skb - free a skb
* @skb: The skb to free.
*/
void rt2x00queue_free_skb(struct sk_buff *skb);
/** /**
* rt2x00queue_create_tx_descriptor - Create TX descriptor from mac80211 input * rt2x00queue_create_tx_descriptor - Create TX descriptor from mac80211 input
......
...@@ -74,13 +74,59 @@ EXPORT_SYMBOL_GPL(rt2x00pci_write_tx_data); ...@@ -74,13 +74,59 @@ EXPORT_SYMBOL_GPL(rt2x00pci_write_tx_data);
/* /*
* TX/RX data handlers. * TX/RX data handlers.
*/ */
static void rt2x00pci_rxdone_entry(struct rt2x00_dev *rt2x00dev,
struct queue_entry *entry)
{
struct sk_buff *skb;
struct skb_frame_desc *skbdesc;
struct rxdone_entry_desc rxdesc;
struct queue_entry_priv_pci *entry_priv = entry->priv_data;
/*
* Allocate a new sk_buffer. If no new buffer available, drop the
* received frame and reuse the existing buffer.
*/
skb = rt2x00queue_alloc_skb(entry->queue);
if (!skb)
return;
/*
* Extract the RXD details.
*/
memset(&rxdesc, 0, sizeof(rxdesc));
rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
/*
* Copy the received data to the entries' skb.
*/
memcpy(entry->skb->data, entry_priv->data, rxdesc.size);
skb_trim(entry->skb, rxdesc.size);
/*
* Fill in skb descriptor
*/
skbdesc = get_skb_frame_desc(entry->skb);
memset(skbdesc, 0, sizeof(*skbdesc));
skbdesc->desc = entry_priv->desc;
skbdesc->desc_len = entry->queue->desc_size;
skbdesc->entry = entry;
/*
* Send the frame to rt2x00lib for further processing.
*/
rt2x00lib_rxdone(entry, &rxdesc);
/*
* Replace the entries' skb with the newly allocated one.
*/
entry->skb = skb;
}
void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev) void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
{ {
struct data_queue *queue = rt2x00dev->rx; struct data_queue *queue = rt2x00dev->rx;
struct queue_entry *entry; struct queue_entry *entry;
struct queue_entry_priv_pci *entry_priv; struct queue_entry_priv_pci *entry_priv;
struct skb_frame_desc *skbdesc;
struct rxdone_entry_desc rxdesc;
u32 word; u32 word;
while (1) { while (1) {
...@@ -91,32 +137,7 @@ void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev) ...@@ -91,32 +137,7 @@ void rt2x00pci_rxdone(struct rt2x00_dev *rt2x00dev)
if (rt2x00_get_field32(word, RXD_ENTRY_OWNER_NIC)) if (rt2x00_get_field32(word, RXD_ENTRY_OWNER_NIC))
break; break;
memset(&rxdesc, 0, sizeof(rxdesc)); rt2x00pci_rxdone_entry(rt2x00dev, entry);
rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
/*
* Allocate the sk_buffer and copy all data into it.
*/
entry->skb = rt2x00queue_alloc_rxskb(queue);
if (!entry->skb)
return;
memcpy(entry->skb->data, entry_priv->data, rxdesc.size);
skb_trim(entry->skb, rxdesc.size);
/*
* Fill in skb descriptor
*/
skbdesc = get_skb_frame_desc(entry->skb);
memset(skbdesc, 0, sizeof(*skbdesc));
skbdesc->desc = entry_priv->desc;
skbdesc->desc_len = queue->desc_size;
skbdesc->entry = entry;
/*
* Send the frame to rt2x00lib for further processing.
*/
rt2x00lib_rxdone(entry, &rxdesc);
if (test_bit(DEVICE_ENABLED_RADIO, &queue->rt2x00dev->flags)) { if (test_bit(DEVICE_ENABLED_RADIO, &queue->rt2x00dev->flags)) {
rt2x00_set_field32(&word, RXD_ENTRY_OWNER_NIC, 1); rt2x00_set_field32(&word, RXD_ENTRY_OWNER_NIC, 1);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "rt2x00.h" #include "rt2x00.h"
#include "rt2x00lib.h" #include "rt2x00lib.h"
struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue) struct sk_buff *rt2x00queue_alloc_skb(struct data_queue *queue)
{ {
struct sk_buff *skb; struct sk_buff *skb;
unsigned int frame_size; unsigned int frame_size;
...@@ -42,17 +42,10 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue) ...@@ -42,17 +42,10 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue)
frame_size = queue->data_size + queue->desc_size; frame_size = queue->data_size + queue->desc_size;
/* /*
* For the allocation we should keep a few things in mind: * Reserve a few bytes extra headroom to allow drivers some moving
* 1) 4byte alignment of 802.11 payload * space (e.g. for alignment), while keeping the skb aligned.
*
* For (1) we need at most 4 bytes to guarentee the correct
* alignment. We are going to optimize the fact that the chance
* that the 802.11 header_size % 4 == 2 is much bigger then
* anything else. However since we need to move the frame up
* to 3 bytes to the front, which means we need to preallocate
* 6 bytes.
*/ */
reserved_size = 6; reserved_size = 8;
/* /*
* Allocate skbuffer. * Allocate skbuffer.
...@@ -66,7 +59,13 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue) ...@@ -66,7 +59,13 @@ struct sk_buff *rt2x00queue_alloc_rxskb(struct data_queue *queue)
return skb; return skb;
} }
EXPORT_SYMBOL_GPL(rt2x00queue_alloc_rxskb); EXPORT_SYMBOL_GPL(rt2x00queue_alloc_skb);
void rt2x00queue_free_skb(struct sk_buff *skb)
{
dev_kfree_skb_any(skb);
}
EXPORT_SYMBOL_GPL(rt2x00queue_free_skb);
void rt2x00queue_create_tx_descriptor(struct queue_entry *entry, void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,
struct txentry_desc *txdesc) struct txentry_desc *txdesc)
...@@ -422,12 +421,45 @@ static int rt2x00queue_alloc_entries(struct data_queue *queue, ...@@ -422,12 +421,45 @@ static int rt2x00queue_alloc_entries(struct data_queue *queue,
return 0; return 0;
} }
static void rt2x00queue_free_skbs(struct data_queue *queue)
{
unsigned int i;
if (!queue->entries)
return;
for (i = 0; i < queue->limit; i++) {
if (queue->entries[i].skb)
rt2x00queue_free_skb(queue->entries[i].skb);
}
}
static int rt2x00queue_alloc_skbs(struct data_queue *queue)
{
unsigned int i;
struct sk_buff *skb;
for (i = 0; i < queue->limit; i++) {
skb = rt2x00queue_alloc_skb(queue);
if (!skb)
goto exit;
queue->entries[i].skb = skb;
}
return 0;
exit:
rt2x00queue_free_skbs(queue);
return -ENOMEM;
}
int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev) int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
{ {
struct data_queue *queue; struct data_queue *queue;
int status; int status;
status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx); status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx);
if (status) if (status)
goto exit; goto exit;
...@@ -442,11 +474,14 @@ int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev) ...@@ -442,11 +474,14 @@ int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev)
if (status) if (status)
goto exit; goto exit;
if (!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags)) if (test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags)) {
return 0; status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1],
rt2x00dev->ops->atim);
if (status)
goto exit;
}
status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1], status = rt2x00queue_alloc_skbs(rt2x00dev->rx);
rt2x00dev->ops->atim);
if (status) if (status)
goto exit; goto exit;
...@@ -464,6 +499,8 @@ void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev) ...@@ -464,6 +499,8 @@ void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev)
{ {
struct data_queue *queue; struct data_queue *queue;
rt2x00queue_free_skbs(rt2x00dev->rx);
queue_for_each(rt2x00dev, queue) { queue_for_each(rt2x00dev, queue) {
kfree(queue->entries); kfree(queue->entries);
queue->entries = NULL; queue->entries = NULL;
......
...@@ -300,7 +300,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb) ...@@ -300,7 +300,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
* If allocation fails, we should drop the current frame * If allocation fails, we should drop the current frame
* so we can recycle the existing sk buffer for the new frame. * so we can recycle the existing sk buffer for the new frame.
*/ */
skb = rt2x00queue_alloc_rxskb(entry->queue); skb = rt2x00queue_alloc_skb(entry->queue);
if (!skb) if (!skb)
goto skip_entry; goto skip_entry;
...@@ -434,8 +434,6 @@ static void rt2x00usb_free_urb(struct rt2x00_dev *rt2x00dev, ...@@ -434,8 +434,6 @@ static void rt2x00usb_free_urb(struct rt2x00_dev *rt2x00dev,
entry_priv = queue->entries[i].priv_data; entry_priv = queue->entries[i].priv_data;
usb_kill_urb(entry_priv->urb); usb_kill_urb(entry_priv->urb);
usb_free_urb(entry_priv->urb); usb_free_urb(entry_priv->urb);
if (queue->entries[i].skb)
kfree_skb(queue->entries[i].skb);
} }
/* /*
...@@ -457,10 +455,7 @@ static void rt2x00usb_free_urb(struct rt2x00_dev *rt2x00dev, ...@@ -457,10 +455,7 @@ static void rt2x00usb_free_urb(struct rt2x00_dev *rt2x00dev,
int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev) int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev)
{ {
struct data_queue *queue; struct data_queue *queue;
struct sk_buff *skb; int status;
unsigned int entry_size;
unsigned int i;
int uninitialized_var(status);
/* /*
* Allocate DMA * Allocate DMA
...@@ -471,18 +466,6 @@ int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev) ...@@ -471,18 +466,6 @@ int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev)
goto exit; goto exit;
} }
/*
* For the RX queue, skb's should be allocated.
*/
entry_size = rt2x00dev->rx->data_size + rt2x00dev->rx->desc_size;
for (i = 0; i < rt2x00dev->rx->limit; i++) {
skb = rt2x00queue_alloc_rxskb(rt2x00dev->rx);
if (!skb)
goto exit;
rt2x00dev->rx->entries[i].skb = skb;
}
return 0; return 0;
exit: exit:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment