384a0be80853f18d4b4355ffcdb39d78807f54c6
[openwrt.git] / package / kernel / mac80211 / patches / 308-rt2x00-do-not-align-payload-on-modern-H-W.patch
1 From: Stanislaw Gruszka <sgruszka@redhat.com>
2 Date: Sun, 2 Nov 2014 13:38:47 +0100
3 Subject: [PATCH] rt2x00: do not align payload on modern H/W
4
5 RT2800 and newer hardware require padding between header and payload if
6 header length is not multiple of 4.
7
8 For historical reasons we also align payload to to 4 bytes boundary, but
9 such alignment is not needed on modern H/W.
10
11 Patch improve performance on embedded CPUs and _possibly_ fixes
12 skb_under_panic problems reported from time to time:
13
14 https://bugzilla.kernel.org/show_bug.cgi?id=84911
15 https://bugzilla.kernel.org/show_bug.cgi?id=72471
16 http://marc.info/?l=linux-wireless&m=139108549530402&w=2
17 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1087591
18
19 But we can not explain or otherwise confirm the patch fixes this panic
20 issue for sure.
21
22 Originally-From: Helmut Schaa <helmut.schaa@googlemail.com>
23 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
24 ---
25
26 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
27 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
28 @@ -158,55 +158,29 @@ void rt2x00queue_align_frame(struct sk_b
29         skb_trim(skb, frame_length);
30  }
31  
32 -void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length)
33 +/*
34 + * H/W needs L2 padding between the header and the paylod if header size
35 + * is not 4 bytes aligned.
36 + */
37 +void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int hdr_len)
38  {
39 -       unsigned int payload_length = skb->len - header_length;
40 -       unsigned int header_align = ALIGN_SIZE(skb, 0);
41 -       unsigned int payload_align = ALIGN_SIZE(skb, header_length);
42 -       unsigned int l2pad = payload_length ? L2PAD_SIZE(header_length) : 0;
43 +       unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
44  
45 -       /*
46 -        * Adjust the header alignment if the payload needs to be moved more
47 -        * than the header.
48 -        */
49 -       if (payload_align > header_align)
50 -               header_align += 4;
51 -
52 -       /* There is nothing to do if no alignment is needed */
53 -       if (!header_align)
54 +       if (!l2pad)
55                 return;
56  
57 -       /* Reserve the amount of space needed in front of the frame */
58 -       skb_push(skb, header_align);
59 -
60 -       /*
61 -        * Move the header.
62 -        */
63 -       memmove(skb->data, skb->data + header_align, header_length);
64 -
65 -       /* Move the payload, if present and if required */
66 -       if (payload_length && payload_align)
67 -               memmove(skb->data + header_length + l2pad,
68 -                       skb->data + header_length + l2pad + payload_align,
69 -                       payload_length);
70 -
71 -       /* Trim the skb to the correct size */
72 -       skb_trim(skb, header_length + l2pad + payload_length);
73 +       skb_push(skb, l2pad);
74 +       memmove(skb->data, skb->data + l2pad, hdr_len);
75  }
76  
77 -void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length)
78 +void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int hdr_len)
79  {
80 -       /*
81 -        * L2 padding is only present if the skb contains more than just the
82 -        * IEEE 802.11 header.
83 -        */
84 -       unsigned int l2pad = (skb->len > header_length) ?
85 -                               L2PAD_SIZE(header_length) : 0;
86 +       unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
87  
88         if (!l2pad)
89                 return;
90  
91 -       memmove(skb->data + l2pad, skb->data, header_length);
92 +       memmove(skb->data + l2pad, skb->data, hdr_len);
93         skb_pull(skb, l2pad);
94  }
95