rt2x00: Cherry picked fixes for 2.6.33.
cover rt2x00: Cherry picked fixes for 2.6.33.
John,
Here is a set of fixes for rt2x00 for 2.6.33. All of these are already present in wireless-next-2.6, and I've cherry-picked them to get rt2800 in a usable state in 2.6.33.
The series can also be pulled from:
git://git.gwingerde.nl/rt2x00-2.6.git
P.S. Once these enter mainline, I'll submit a similar set of patches to stable to fix 2.6.32 as well. Unfortunately these patches don't apply directly on 2.6.32.
Alban Browaeys (2):
rt2x00 : modify padding location.
rt2x00 : trim the skb after having the l2pad removed.
Benoit Papillault (1):
rt2x00: Fix rt2800usb RX frame format and as such L2PAD
Gertjan van Wingerde (5):
rt2x00: Further L2 padding fixes.
rt2x00: Remove SKBDESC_L2_PADDED flag.
rt2x00: Reorganize L2 padding inserting function.
rt2x00: Only remove L2 padding in received frames if there is
payload.
rt2x00: Fix trimming of L2 padded frames.
drivers/net/wireless/rt2x00/rt2800pci.c | 6 +-- drivers/net/wireless/rt2x00/rt2800usb.c | 41 +++++++++----- drivers/net/wireless/rt2x00/rt2800usb.h | 90 ++++++++++++++++++++++------ drivers/net/wireless/rt2x00/rt2x00.h | 6 ++ drivers/net/wireless/rt2x00/rt2x00dev.c | 10 ++- drivers/net/wireless/rt2x00/rt2x00queue.c | 70 ++++++++++------------ drivers/net/wireless/rt2x00/rt2x00queue.h | 5 +- 7 files changed, 142 insertions(+), 86 deletions(-)
PATCH 1/8 rt2x00 : modify padding location.
From: Alban Browaeys <[email protected]>
The padding is to be added between header and payload for the only header need padding case.
--- drivers/net/wireless/rt2x00/rt2x00queue.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/wireless/rt2x00/rt2x00queue.c +1 -1
@@ -197,7 +197,7 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)* the payload is already properly aligned. */ skb_push (skb, header_align); -memmove (skb->data, skb->data + header_align, frame_length); +memmove (skb->data, skb->data + header_align, header_length); skbdesc->flags |=SKBDESC_L2_PADDED ; }else {/*
Signature · 1 line
1.6.6
PATCH 2/8 rt2x00 : trim the skb after having the l2pad removed.
From: Alban Browaeys <[email protected]>
Otherwise we end up truncating the skb before removing the l2pad thus we might have the truncated part become garbage while getting it back in remove_l2pad.
For the same issue: remove the skb_trim from the rt2800 fill_rxdone (it is done after l2pad removal in rt2x00lib_rxdone).
--- drivers/net/wireless/rt2x00/rt2800pci.c | 1 - drivers/net/wireless/rt2x00/rt2800usb.c | 1 - drivers/net/wireless/rt2x00/rt2x00dev.c | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-)
drivers/net/wireless/rt2x00/rt2800pci.c +0 -1
@@ -927,7 +927,6 @@ static void rt2800pci_fill_rxdone(struct queue_entry *entry,* Remove TXWI descriptor from start of buffer. */ skb_pull (entry->skb,RXWI_DESC_SIZE ); -skb_trim (entry->skb, rxdesc->size); }/*
drivers/net/wireless/rt2x00/rt2800usb.c +0 -1
@@ -663,7 +663,6 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,* Remove RXWI descriptor from start of buffer. */ skb_pull (entry->skb, skbdesc->desc_len); -skb_trim (entry->skb, rxdesc->size); }/*
drivers/net/wireless/rt2x00/rt2x00dev.c +3 -3
@@ -385,9 +385,6 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,memset (&rxdesc,0 ,sizeof (rxdesc)); rt2x00dev->ops->lib->fill_rxdone (entry, &rxdesc); -/* Trim buffer to correct size */ -skb_trim (entry->skb, rxdesc.size); -/* * The data behind the ieee80211 header must be * aligned on a 4 byte boundary.
@@ -409,6 +406,9 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,else rt2x00queue_align_payload (entry->skb, header_length); +/* Trim buffer to correct size */ +skb_trim (entry->skb, rxdesc.size); +/* * Check if the frame was received using HT. In that case, * the rate is the MCS index and should be passed to mac80211
Signature · 1 line
1.6.6
PATCH 3/8 rt2x00: Further L2 padding fixes.
Fix a couple of more bugs in the L2 padding code:
1. Compute the amount of L2 padding correctly (in 3 places).
2. Trim the skb correctly when the L2 padding has been applied.
Also introduce a central macro the compute the L2 padding size.
--- drivers/net/wireless/rt2x00/rt2x00.h | 6 ++++++ drivers/net/wireless/rt2x00/rt2x00queue.c | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/net/wireless/rt2x00/rt2x00.h +6 -0
@@ -104,6 +104,12 @@#define GET_DURATION_RES (__size, __rate)(((__size) * 8 * 10) % (__rate))/* +* Determine the number of L2 padding bytes required between the header and +* the payload. +*/ +#define L2PAD_SIZE (__hdrlen) (-(__hdrlen) & 3) + +/* * Determine the alignment requirement, * to make sure the 802.11 payload is padded to a 4-byte boundrary * we must determine the address of the payload and calculate the
drivers/net/wireless/rt2x00/rt2x00queue.c +5 -3
@@ -181,7 +181,7 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)unsigned int frame_length = skb->len;unsigned int header_align =ALIGN_SIZE (skb,0 );unsigned int payload_align =ALIGN_SIZE (skb, header_length); -unsigned int l2pad =4 - (payload_align - header_align); +unsigned int l2pad =L2PAD_SIZE (header_length);if (header_align == payload_align) {/*
@@ -216,6 +216,7 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)memmove (skb->data + header_length + l2pad, skb->data + header_length + l2pad + payload_align, frame_length - header_length); +skb_trim (skb, frame_length + l2pad); skbdesc->flags |=SKBDESC_L2_PADDED ; } }
@@ -223,7 +224,7 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)void rt2x00queue_remove_l2pad (struct sk_buff *skb,unsigned int header_length) {struct skb_frame_desc *skbdesc =get_skb_frame_desc (skb); -unsigned int l2pad =4 - (header_length &3 ); +unsigned int l2pad =L2PAD_SIZE (header_length);if (!l2pad || (skbdesc->flags &SKBDESC_L2_PADDED ))return ;
@@ -346,7 +347,8 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,* Header and alignment information. */ txdesc->header_length =ieee80211_get_hdrlen_from_skb (entry->skb); - txdesc->l2pad =ALIGN_SIZE (entry->skb, txdesc->header_length); +if (test_bit (DRIVER_REQUIRE_L2PAD , &rt2x00dev->flags)) + txdesc->l2pad =L2PAD_SIZE (txdesc->header_length);/* * Check whether this frame is to be acked.
Signature · 1 line
1.6.6
PATCH 4/8 rt2x00: Remove SKBDESC_L2_PADDED flag.
With the improved L2 padding code, this flag is no longer necessary, as the rt2x00queue_remove_l2pad is capable of detecting by itself if L2 padding is applied.
For received frames the RX descriptor flag is still being checked.
--- drivers/net/wireless/rt2x00/rt2800pci.c | 5 +---- drivers/net/wireless/rt2x00/rt2800usb.c | 4 +--- drivers/net/wireless/rt2x00/rt2x00queue.c | 6 +----- drivers/net/wireless/rt2x00/rt2x00queue.h | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-)
drivers/net/wireless/rt2x00/rt2800pci.c +1 -4
@@ -835,7 +835,6 @@ static void rt2800pci_fill_rxdone(struct queue_entry *entry, struct rxdone_entry_desc *rxdesc) {struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; -struct skb_frame_desc *skbdesc =get_skb_frame_desc (entry->skb);struct queue_entry_priv_pci *entry_priv = entry->priv_data;__le32 *rxd = entry_priv->desc;__le32 *rxwi = (__le32 *)entry->skb->data;
@@ -883,10 +882,8 @@ static void rt2800pci_fill_rxdone(struct queue_entry *entry,if (rt2x00_get_field32 (rxd3,RXD_W3_MY_BSS )) rxdesc->dev_flags |=RXDONE_MY_BSS ; -if (rt2x00_get_field32 (rxd3,RXD_W3_L2PAD )) { +if (rt2x00_get_field32 (rxd3,RXD_W3_L2PAD )) rxdesc->dev_flags |=RXDONE_L2PAD ; - skbdesc->flags |=SKBDESC_L2_PADDED ; - }if (rt2x00_get_field32 (rxwi1,RXWI_W1_SHORT_GI )) rxdesc->flags |=RX_FLAG_SHORT_GI ;
drivers/net/wireless/rt2x00/rt2800usb.c +1 -3
@@ -625,10 +625,8 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,if (rt2x00_get_field32 (rxd0,RXINFO_W0_MY_BSS )) rxdesc->dev_flags |=RXDONE_MY_BSS ; -if (rt2x00_get_field32 (rxd0,RXINFO_W0_L2PAD )) { +if (rt2x00_get_field32 (rxd0,RXINFO_W0_L2PAD )) rxdesc->dev_flags |=RXDONE_L2PAD ; - skbdesc->flags |=SKBDESC_L2_PADDED ; - }if (rt2x00_get_field32 (rxwi1,RXWI_W1_SHORT_GI )) rxdesc->flags |=RX_FLAG_SHORT_GI ;
drivers/net/wireless/rt2x00/rt2x00queue.c +1 -5
@@ -177,7 +177,6 @@ void rt2x00queue_align_payload(struct sk_buff *skb, unsigned int header_length)void rt2x00queue_insert_l2pad (struct sk_buff *skb,unsigned int header_length) { -struct skb_frame_desc *skbdesc =get_skb_frame_desc (skb);unsigned int frame_length = skb->len;unsigned int header_align =ALIGN_SIZE (skb,0 );unsigned int payload_align =ALIGN_SIZE (skb, header_length);
@@ -198,7 +197,6 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)*/ skb_push (skb, header_align);memmove (skb->data, skb->data + header_align, header_length); - skbdesc->flags |=SKBDESC_L2_PADDED ; }else {/* *
@@ -217,16 +215,14 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length) skb->data + header_length + l2pad + payload_align, frame_length - header_length);skb_trim (skb, frame_length + l2pad); - skbdesc->flags |=SKBDESC_L2_PADDED ; } }void rt2x00queue_remove_l2pad (struct sk_buff *skb,unsigned int header_length) { -struct skb_frame_desc *skbdesc =get_skb_frame_desc (skb);unsigned int l2pad =L2PAD_SIZE (header_length); -if (!l2pad || (skbdesc->flags &SKBDESC_L2_PADDED )) +if (!l2pad)return ;memmove (skb->data + l2pad, skb->data, header_length);
drivers/net/wireless/rt2x00/rt2x00queue.h +1 -4
@@ -92,8 +92,6 @@ enum data_queue_qid {* @SKBDESC_DMA_MAPPED_TX: &skb_dma field has been mapped for TX * @SKBDESC_IV_STRIPPED: Frame contained a IV/EIV provided by * mac80211 but was stripped for processing by the driver. -* @SKBDESC_L2_PADDED: Payload has been padded for 4-byte alignment, -* the padded bytes are located between header and payload. * @SKBDESC_NOT_MAC80211: Frame didn't originate from mac80211, * don't try to pass it back. */
@@ -101,8 +99,7 @@ enum skb_frame_desc_flags {SKBDESC_DMA_MAPPED_RX =1 <<0 ,SKBDESC_DMA_MAPPED_TX =1 <<1 ,SKBDESC_IV_STRIPPED =1 <<2 , -SKBDESC_L2_PADDED =1 <<3 , - SKBDESC_NOT_MAC80211 = 1 << 4, + SKBDESC_NOT_MAC80211 = 1 << 3, };/**
Signature · 1 line
1.6.6
PATCH 5/8 rt2x00: Reorganize L2 padding inserting function.
Simplify the rt2x00queue_insert_l2pad function by handling the alignment operations one by one. Do not special case special circumstances. Basically first perform header alignment, and then perform payload alignment (if any payload does exist). This results in a properly aligned skb.
The end result is better readable code, with better results, as now L2 padding is inserted only when a payload is actually present in the frame.
--- drivers/net/wireless/rt2x00/rt2x00queue.c | 60 +++++++++++++---------------- 1 files changed, 27 insertions(+), 33 deletions(-)
drivers/net/wireless/rt2x00/rt2x00queue.c +27 -33
@@ -177,45 +177,38 @@ void rt2x00queue_align_payload(struct sk_buff *skb, unsigned int header_length)void rt2x00queue_insert_l2pad (struct sk_buff *skb,unsigned int header_length) { -unsigned int frame_length = skb->len; +unsigned int payload_length = skb->len - header_length;unsigned int header_align =ALIGN_SIZE (skb,0 );unsigned int payload_align =ALIGN_SIZE (skb, header_length);unsigned int l2pad =L2PAD_SIZE (header_length); -if (header_align == payload_align) { -/* -* Both header and payload must be moved the same -* amount of bytes to align them properly. This means -* we don't use the L2 padding but just move the entire -* frame. -*/ -rt2x00queue_align_frame (skb); - }else if (!payload_align) { -/* -* Simple L2 padding, only the header needs to be moved, -* the payload is already properly aligned. -*/ -skb_push (skb, header_align); -memmove (skb->data, skb->data + header_align, header_length); - }else { -/* -* -* Complicated L2 padding, both header and payload need -* to be moved. By default we only move to the start -* of the buffer, so our header alignment needs to be -* increased if there is not enough room for the header -* to be moved. -*/ -if (payload_align > header_align) - header_align +=4 ; +/* +* Adjust the header alignment if the payload needs to be moved more +* than the header. +*/ +if (payload_align > header_align) + header_align +=4 ; + +/* There is nothing to do if no alignment is needed */ +if (!header_align) +return ; -skb_push (skb, header_align); -memmove (skb->data, skb->data + header_align, header_length); +/* Reserve the amount of space needed in front of the frame */ +skb_push (skb, header_align); + +/* +* Move the header. +*/ +memmove (skb->data, skb->data + header_align, header_length); + +/* Move the payload, if present and if required */ +if (payload_length && payload_align)memmove (skb->data + header_length + l2pad, skb->data + header_length + l2pad + payload_align, - frame_length - header_length); -skb_trim (skb, frame_length + l2pad); - } + payload_length); + +/* Trim the skb to the correct size */ +skb_trim (skb, header_length + l2pad + payload_length); }void rt2x00queue_remove_l2pad (struct sk_buff *skb,unsigned int header_length)
@@ -343,7 +336,8 @@ static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry,* Header and alignment information. */ txdesc->header_length =ieee80211_get_hdrlen_from_skb (entry->skb); -if (test_bit (DRIVER_REQUIRE_L2PAD , &rt2x00dev->flags)) +if (test_bit (DRIVER_REQUIRE_L2PAD , &rt2x00dev->flags) && + (entry->skb->len > txdesc->header_length)) txdesc->l2pad =L2PAD_SIZE (txdesc->header_length);/*
Signature · 1 line
1.6.6
PATCH 6/8 rt2x00: Only remove L2 padding in received frames if there is payload.
L2 padding will only be present when there is actual payload present.
--- drivers/net/wireless/rt2x00/rt2x00dev.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/net/wireless/rt2x00/rt2x00dev.c +3 -1
@@ -401,7 +401,9 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev, (rxdesc.flags & RX_FLAG_IV_STRIPPED))rt2x00crypto_rx_insert_iv (entry->skb, header_length, &rxdesc); - else if (rxdesc.dev_flags & RXDONE_L2PAD) + else if (header_length && + (rxdesc.size > header_length) && + (rxdesc.dev_flags & RXDONE_L2PAD)) rt2x00queue_remove_l2pad(entry->skb, header_length); else rt2x00queue_align_payload(entry->skb, header_length);
Signature · 1 line
1.6.6
PATCH 7/8 rt2x00: Fix rt2800usb RX frame format and as such L2PAD
From: Benoit Papillault <[email protected]>
According to Ralink source code, the RX frame format is RXINFO + RXWI + 802.11 frame + RXD, including various padding. Before this patch, we were using RXD + RXWI + 802.11 frame, so RXD was not correct.
Doing this, we fix the L2PAD bit which is now correctly set on received frames.
--- drivers/net/wireless/rt2x00/rt2800usb.c | 38 +++++++++---- drivers/net/wireless/rt2x00/rt2800usb.h | 90 ++++++++++++++++++++++++------- 2 files changed, 97 insertions(+), 31 deletions(-)
drivers/net/wireless/rt2x00/rt2800usb.c +27 -11
@@ -573,41 +573,57 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry, {struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;struct skb_frame_desc *skbdesc =get_skb_frame_desc (entry->skb); -__le32 *rxd = (__le32 *)entry->skb->data; +__le32 *rxi = (__le32 *)entry->skb->data;__le32 *rxwi; -u32 rxd0; +__le32 *rxd; +u32 rxi0;u32 rxwi0;u32 rxwi1;u32 rxwi2;u32 rxwi3; +u32 rxd0; +int rx_pkt_len; + +/* +* RX frame format is : +* | RXINFO | RXWI | header | L2 pad | payload | pad | RXD | USB pad | +* |<------------ rx_pkt_len -------------->| +*/ +rt2x00_desc_read (rxi,0 , &rxi0); + rx_pkt_len =rt2x00_get_field32 (rxi0,RXINFO_W0_USB_DMA_RX_PKT_LEN ); + + rxwi = (__le32 *)(entry->skb->data +RXINFO_DESC_SIZE ); + +/* +* FIXME : we need to check for rx_pkt_len validity +*/ + rxd = (__le32 *)(entry->skb->data +RXINFO_DESC_SIZE + rx_pkt_len);/* * Copy descriptor to the skbdesc->desc buffer, making it safe from * moving of frame data in rt2x00usb. */ -memcpy (skbdesc->desc, rxd, skbdesc->desc_len); - rxd = (__le32 *)skbdesc->desc; - rxwi = &rxd[RXINFO_DESC_SIZE /sizeof (__le32)]; +memcpy (skbdesc->desc, rxi, skbdesc->desc_len);/* * It is now safe to read the descriptor on all architectures. */ -rt2x00_desc_read (rxd,0 , &rxd0);rt2x00_desc_read (rxwi,0 , &rxwi0);rt2x00_desc_read (rxwi,1 , &rxwi1);rt2x00_desc_read (rxwi,2 , &rxwi2);rt2x00_desc_read (rxwi,3 , &rxwi3); +rt2x00_desc_read (rxd,0 , &rxd0); -if (rt2x00_get_field32 (rxd0,RXINFO_W0_CRC_ERROR )) +if (rt2x00_get_field32 (rxd0,RXD_W0_CRC_ERROR )) rxdesc->flags |=RX_FLAG_FAILED_FCS_CRC ;if (test_bit (CONFIG_SUPPORT_HW_CRYPTO , &rt2x00dev->flags)) { rxdesc->cipher =rt2x00_get_field32 (rxwi0,RXWI_W0_UDF ); rxdesc->cipher_status = -rt2x00_get_field32 (rxd0,RXINFO_W0_CIPHER_ERROR ); +rt2x00_get_field32 (rxd0,RXD_W0_CIPHER_ERROR ); } -if (rt2x00_get_field32 (rxd0,RXINFO_W0_DECRYPTED )) { +if (rt2x00_get_field32 (rxd0,RXD_W0_DECRYPTED )) {/* * Hardware has stripped IV/EIV data from 802.11 frame during * decryption. Unfortunately the descriptor doesn't contain
@@ -622,10 +638,10 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry, rxdesc->flags |=RX_FLAG_MMIC_ERROR ; } -if (rt2x00_get_field32 (rxd0,RXINFO_W0_MY_BSS )) +if (rt2x00_get_field32 (rxd0,RXD_W0_MY_BSS )) rxdesc->dev_flags |=RXDONE_MY_BSS ; -if (rt2x00_get_field32 (rxd0,RXINFO_W0_L2PAD )) +if (rt2x00_get_field32 (rxd0,RXD_W0_L2PAD )) rxdesc->dev_flags |=RXDONE_L2PAD ;if (rt2x00_get_field32 (rxwi1,RXWI_W1_SHORT_GI ))
drivers/net/wireless/rt2x00/rt2800usb.h +70 -20
107 lines not on this page · raw message
Signature · 1 line
1.6.6
PATCH 8/8 rt2x00: Fix trimming of L2 padded frames.
Ensure that frames without payload are properly trimmed in rt2x00queue_insert_l2pad.
This should fix the bug reported by Benoit Papillault in:
http://marc.info/?l=linux-wireless&m=125974773006734&w=2
--- drivers/net/wireless/rt2x00/rt2x00queue.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/wireless/rt2x00/rt2x00queue.c +1 -1
@@ -180,7 +180,7 @@ void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)unsigned int payload_length = skb->len - header_length;unsigned int header_align =ALIGN_SIZE (skb,0 );unsigned int payload_align =ALIGN_SIZE (skb, header_length); -unsigned int l2pad =L2PAD_SIZE (header_length); +unsigned int l2pad = payload_length ?L2PAD_SIZE (header_length) :0 ;/* * Adjust the header alignment if the payload needs to be moved more
Signature · 1 line
1.6.6