From: Jussi Kivilinna <jussi.kivilinna@iki.fi>
To: linux-wireless@vger.kernel.org
Cc: Chaoming Li <chaoming_li@realsil.com.cn>,
"John W. Linville" <linville@tuxdriver.com>,
Larry Finger <Larry.Finger@lwfinger.net>
Subject: [PATCH 4/4] rtlwifi: usb: add NET_IP_ALIGN padding to RX skb when needed
Date: Sun, 17 Mar 2013 11:59:29 +0200 [thread overview]
Message-ID: <20130317095929.24983.14535.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20130317095831.24983.97107.stgit@localhost6.localdomain6>
Add proper alignment at first packet copy, to avoid extra copies made later
in networking stack.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
---
drivers/net/wireless/rtlwifi/usb.c | 41 +++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index 6cb2940..83915dc 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -569,6 +569,37 @@ static void _rtl_rx_work(unsigned long param)
}
}
+static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr,
+ unsigned int len)
+{
+ unsigned int padding = 0;
+
+ /* make function no-op when possible */
+ if (NET_IP_ALIGN == 0 || len < sizeof(*hdr))
+ return 0;
+
+ /* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */
+ /* TODO: deduplicate common code, define helper function instead? */
+
+ if (ieee80211_is_data_qos(hdr->frame_control)) {
+ u8 *qc = ieee80211_get_qos_ctl(hdr);
+
+ padding ^= NET_IP_ALIGN;
+
+ /* Input might be invalid, avoid accessing memory outside
+ * the buffer.
+ */
+ if ((unsigned long)qc - (unsigned long)hdr < len &&
+ *qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
+ padding ^= NET_IP_ALIGN;
+ }
+
+ if (ieee80211_has_a4(hdr->frame_control))
+ padding ^= NET_IP_ALIGN;
+
+ return padding;
+}
+
#define __RADIO_TAP_SIZE_RSV 32
static void _rtl_rx_completed(struct urb *_urb)
@@ -582,9 +613,11 @@ static void _rtl_rx_completed(struct urb *_urb)
goto free;
if (likely(0 == _urb->status)) {
+ unsigned int padding;
struct sk_buff *skb;
unsigned int qlen;
unsigned int size = _urb->actual_length;
+ struct ieee80211_hdr *hdr;
if (size < RTL_RX_DESC_SIZE + sizeof(struct ieee80211_hdr)) {
RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
@@ -601,7 +634,10 @@ static void _rtl_rx_completed(struct urb *_urb)
goto resubmit;
}
- skb = dev_alloc_skb(size + __RADIO_TAP_SIZE_RSV);
+ hdr = (void *)(_urb->transfer_buffer + RTL_RX_DESC_SIZE);
+ padding = _rtl_rx_get_padding(hdr, size - RTL_RX_DESC_SIZE);
+
+ skb = dev_alloc_skb(size + __RADIO_TAP_SIZE_RSV + padding);
if (!skb) {
RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
"Can't allocate skb for bulk IN!\n");
@@ -610,6 +646,9 @@ static void _rtl_rx_completed(struct urb *_urb)
_rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep);
+ /* Make sure the payload data is 4 byte aligned. */
+ skb_reserve(skb, padding);
+
/* reserve some space for mac80211's radiotap */
skb_reserve(skb, __RADIO_TAP_SIZE_RSV);
next prev parent reply other threads:[~2013-03-17 9:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-17 9:59 [PATCH 0/4] rtlwifi: usb: improve RX performance and lower CPU usage Jussi Kivilinna
2013-03-17 9:59 ` [PATCH 1/4] rtlwifi: usb: use usb_alloc_coherent for RX buffers Jussi Kivilinna
2013-03-17 9:59 ` [PATCH 2/4] rtlwifi: usb: remove extra skb copy on RX path Jussi Kivilinna
2013-03-17 9:59 ` [PATCH 3/4] rtlwifi: usb: defer rx processing to tasklet Jussi Kivilinna
2013-03-17 9:59 ` Jussi Kivilinna [this message]
2013-04-03 17:16 ` [PATCH 0/4] rtlwifi: usb: improve RX performance and lower CPU usage Jussi Kivilinna
2013-04-03 17:32 ` John W. Linville
2013-04-03 19:19 ` Jussi Kivilinna
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130317095929.24983.14535.stgit@localhost6.localdomain6 \
--to=jussi.kivilinna@iki.fi \
--cc=Larry.Finger@lwfinger.net \
--cc=chaoming_li@realsil.com.cn \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).