28 #include <linux/slab.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
38 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
41 unsigned int frame_size;
42 unsigned int head_size = 0;
49 frame_size = entry->queue->data_size + entry->queue->desc_size;
71 skb = __dev_alloc_skb(frame_size + head_size + tail_size, gfp);
79 skb_reserve(skb, head_size);
85 skbdesc = get_skb_frame_desc(skb);
86 memset(skbdesc, 0,
sizeof(*skbdesc));
102 struct device *
dev = entry->queue->rt2x00dev->dev;
113 struct device *
dev = entry->queue->rt2x00dev->dev;
154 unsigned int header_align =
ALIGN_SIZE(skb, 0);
155 unsigned int payload_align =
ALIGN_SIZE(skb, header_length);
156 unsigned int l2pad = payload_length ?
L2PAD_SIZE(header_length) : 0;
162 if (payload_align > header_align)
178 if (payload_length && payload_align)
180 skb->
data + header_length + l2pad + payload_align,
184 skb_trim(skb, header_length + l2pad + payload_length);
203 static void rt2x00queue_create_tx_descriptor_seq(
struct rt2x00_dev *rt2x00dev,
251 static void rt2x00queue_create_tx_descriptor_plcp(
struct rt2x00_dev *rt2x00dev,
273 data_length = skb->
len + 4;
281 txdesc->
u.
plcp.service = 0x04;
284 txdesc->
u.
plcp.length_high = (data_length >> 6) & 0x3f;
285 txdesc->
u.
plcp.length_low = data_length & 0x3f;
299 if (hwrate->
bitrate == 110 && residual <= 30)
300 txdesc->
u.
plcp.service |= 0x80;
303 txdesc->
u.
plcp.length_high = (duration >> 8) & 0xff;
304 txdesc->
u.
plcp.length_low = duration & 0xff;
311 txdesc->
u.
plcp.signal |= 0x08;
315 static void rt2x00queue_create_tx_descriptor_ht(
struct rt2x00_dev *rt2x00dev,
327 txdesc->
u.
ht.mpdu_density =
328 sta->
ht_cap.ampdu_density;
339 txdesc->
u.
ht.mcs = txrate->
idx;
345 if (sta && txdesc->
u.
ht.mcs > 7 &&
352 txdesc->
u.
ht.mcs = rt2x00_get_rate_mcs(hwrate->
mcs);
354 txdesc->
u.
ht.mcs |= 0x08;
367 txdesc->
u.
ht.ba_size = 7;
373 txdesc->
u.
ht.stbc = 1;
411 static void rt2x00queue_create_tx_descriptor(
struct rt2x00_dev *rt2x00dev,
422 memset(txdesc, 0,
sizeof(*txdesc));
446 if (tx_info->
control.rts_cts_rate_idx >= 0)
448 ieee80211_get_rts_cts_rate(rt2x00dev->
hw, tx_info);
492 rate = ieee80211_get_tx_rate(rt2x00dev->
hw, tx_info);
493 hwrate = rt2x00_get_rate(
rate->hw_value);
504 rt2x00queue_create_tx_descriptor_seq(rt2x00dev, skb, txdesc);
507 rt2x00queue_create_tx_descriptor_ht(rt2x00dev, skb, txdesc,
510 rt2x00queue_create_tx_descriptor_plcp(rt2x00dev, skb, txdesc,
514 static int rt2x00queue_write_tx_data(
struct queue_entry *
entry,
517 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
524 if (
unlikely(rt2x00dev->
ops->lib->get_entry_state &&
525 rt2x00dev->
ops->lib->get_entry_state(entry))) {
527 "Corrupt queue %d, accessing entry which is not ours.\n"
528 "Please file bug report to %s.\n",
536 skb_push(entry->skb, rt2x00dev->
ops->extra_tx_headroom);
537 memset(entry->skb->data, 0, rt2x00dev->
ops->extra_tx_headroom);
542 if (rt2x00dev->
ops->lib->write_tx_data)
543 rt2x00dev->
ops->lib->write_tx_data(entry, txdesc);
554 static void rt2x00queue_write_tx_descriptor(
struct queue_entry *entry,
559 queue->
rt2x00dev->ops->lib->write_tx_desc(entry, txdesc);
568 static void rt2x00queue_kick_tx_queue(
struct data_queue *queue,
580 if (rt2x00queue_threshold(queue) ||
582 queue->
rt2x00dev->ops->lib->kick_queue(queue);
589 struct queue_entry *
entry;
592 u8 rate_idx, rate_flags;
600 rt2x00queue_create_tx_descriptor(queue->
rt2x00dev, skb, &txdesc,
NULL);
607 tx_info = IEEE80211_SKB_CB(skb);
608 rate_idx = tx_info->
control.rates[0].idx;
609 rate_flags = tx_info->
control.rates[0].flags;
610 skbdesc = get_skb_frame_desc(skb);
611 memset(skbdesc, 0,
sizeof(*skbdesc));
649 if (
unlikely(rt2x00queue_full(queue))) {
651 "Dropping frame due to full tx queue %d.\n", queue->
qid);
661 "Arrived at non-free entry in the non-full queue %d.\n"
662 "Please file bug report to %s.\n",
676 if (
unlikely(rt2x00queue_write_tx_data(entry, &txdesc))) {
686 rt2x00queue_write_tx_descriptor(entry, &txdesc);
687 rt2x00queue_kick_tx_queue(queue, &txdesc);
713 if (rt2x00dev->
ops->lib->clear_beacon)
714 rt2x00dev->
ops->lib->clear_beacon(intf->
beacon);
736 intf->
beacon->skb = ieee80211_beacon_get(rt2x00dev->
hw, vif);
745 rt2x00queue_create_tx_descriptor(rt2x00dev, intf->
beacon->skb, &txdesc,
NULL);
750 skbdesc = get_skb_frame_desc(intf->
beacon->skb);
751 memset(skbdesc, 0,
sizeof(*skbdesc));
757 rt2x00dev->
ops->lib->write_beacon(intf->
beacon, &txdesc);
779 bool (*
fn)(
struct queue_entry *entry))
781 unsigned long irqflags;
782 unsigned int index_start;
783 unsigned int index_end;
788 "Entry requested from invalid index range (%d - %d)\n",
802 spin_unlock_irqrestore(&queue->
index_lock, irqflags);
808 if (index_start < index_end) {
809 for (i = index_start; i < index_end; i++) {
814 for (i = index_start; i < queue->
limit; i++) {
819 for (i = 0; i < index_end; i++) {
832 struct queue_entry *
entry;
833 unsigned long irqflags;
837 "Entry requested from invalid index type (%d)\n", index);
845 spin_unlock_irqrestore(&queue->
index_lock, irqflags);
854 unsigned long irqflags;
858 "Index change on invalid index type (%d)\n", index);
877 spin_unlock_irqrestore(&queue->
index_lock, irqflags);
887 switch (queue->
qid) {
911 switch (queue->
qid) {
927 queue->
rt2x00dev->ops->lib->kick_queue(queue);
946 queue->
rt2x00dev->ops->lib->start_queue(queue);
965 queue->
rt2x00dev->ops->lib->stop_queue(queue);
1002 if (!drop && tx_queue)
1003 queue->
rt2x00dev->ops->lib->kick_queue(queue);
1012 queue->
rt2x00dev->ops->lib->flush_queue(queue, drop);
1017 if (
unlikely(!rt2x00queue_empty(queue)))
1075 static void rt2x00queue_reset(
struct data_queue *queue)
1077 unsigned long irqflags;
1086 queue->
index[i] = 0;
1088 spin_unlock_irqrestore(&queue->
index_lock, irqflags);
1097 rt2x00queue_reset(queue);
1099 for (i = 0; i < queue->
limit; i++)
1100 rt2x00dev->
ops->lib->clear_entry(&queue->
entries[i]);
1104 static int rt2x00queue_alloc_entries(
struct data_queue *queue,
1108 unsigned int entry_size;
1111 rt2x00queue_reset(queue);
1121 entry_size =
sizeof(*entries) + qdesc->
priv_size;
1126 #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \
1127 (((char *)(__base)) + ((__limit) * (__esize)) + \
1128 ((__index) * (__psize)))
1130 for (i = 0; i < queue->
limit; i++) {
1131 entries[
i].flags = 0;
1132 entries[
i].queue = queue;
1133 entries[
i].skb =
NULL;
1134 entries[
i].entry_idx =
i;
1135 entries[
i].priv_data =
1140 #undef QUEUE_ENTRY_PRIV_OFFSET
1147 static void rt2x00queue_free_skbs(
struct data_queue *queue)
1154 for (i = 0; i < queue->
limit; i++) {
1159 static int rt2x00queue_alloc_rxskbs(
struct data_queue *queue)
1164 for (i = 0; i < queue->
limit; i++) {
1179 status = rt2x00queue_alloc_entries(rt2x00dev->
rx, rt2x00dev->
ops->rx);
1184 status = rt2x00queue_alloc_entries(queue, rt2x00dev->
ops->tx);
1189 status = rt2x00queue_alloc_entries(rt2x00dev->
bcn, rt2x00dev->
ops->bcn);
1194 status = rt2x00queue_alloc_entries(rt2x00dev->
atim,
1195 rt2x00dev->
ops->atim);
1200 status = rt2x00queue_alloc_rxskbs(rt2x00dev->
rx);
1207 ERROR(rt2x00dev,
"Queue entries allocation failed.\n");
1218 rt2x00queue_free_skbs(rt2x00dev->
rx);
1226 static void rt2x00queue_init(
struct rt2x00_dev *rt2x00dev,
1245 unsigned int req_atim =
1255 rt2x00dev->
data_queues = 2 + rt2x00dev->
ops->tx_queues + req_atim;
1259 ERROR(rt2x00dev,
"Queue allocation failed.\n");
1266 rt2x00dev->
rx = queue;
1267 rt2x00dev->
tx = &queue[1];
1268 rt2x00dev->
bcn = &queue[1 + rt2x00dev->
ops->tx_queues];
1269 rt2x00dev->
atim = req_atim ? &queue[2 + rt2x00dev->
ops->tx_queues] :
NULL;
1280 rt2x00queue_init(rt2x00dev, rt2x00dev->
rx,
QID_RX);
1284 rt2x00queue_init(rt2x00dev, queue, qid++);
1288 rt2x00queue_init(rt2x00dev, rt2x00dev->
atim,
QID_ATIM);