358-mac80211-add-NEED_ALIGNED4_SKBS-hw-flag.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. From: Janusz Dziedzic <janusz.dziedzic@tieto.com>
  2. Date: Fri, 19 Feb 2016 11:01:50 +0100
  3. Subject: [PATCH] mac80211: add NEED_ALIGNED4_SKBS hw flag
  4. HW/driver should set NEED_ALIGNED4_SKBS flag in case
  5. require aligned skbs to four-byte boundaries.
  6. This affect only TX direction.
  7. Padding is added after ieee80211_hdr, before IV/LLC.
  8. Before we have to do memmove(hdrlen) twice in the
  9. dirver. Once before we pass this to HW and next
  10. in tx completion (to be sure monitor will report
  11. this tx frame correctly).
  12. With this patch we can skip this memmove() and save CPU.
  13. Currently this was tested with ath9k, both hw/sw crypt for
  14. wep/tkip/ccmp.
  15. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
  16. ---
  17. --- a/include/net/mac80211.h
  18. +++ b/include/net/mac80211.h
  19. @@ -2127,6 +2127,9 @@ struct ieee80211_txq {
  20. * @IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP: The driver (or firmware) doesn't
  21. * support QoS NDP for AP probing - that's most likely a driver bug.
  22. *
  23. + * @IEEE80211_HW_NEEDS_ALIGNED4_SKBS: Driver need aligned skbs to four-byte.
  24. + * Padding will be added after ieee80211_hdr, before IV/LLC.
  25. + *
  26. * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  27. */
  28. enum ieee80211_hw_flags {
  29. @@ -2172,6 +2175,7 @@ enum ieee80211_hw_flags {
  30. IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA,
  31. IEEE80211_HW_DEAUTH_NEED_MGD_TX_PREP,
  32. IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP,
  33. + IEEE80211_HW_NEEDS_ALIGNED4_SKBS,
  34. /* keep last, obviously */
  35. NUM_IEEE80211_HW_FLAGS
  36. --- a/net/mac80211/debugfs.c
  37. +++ b/net/mac80211/debugfs.c
  38. @@ -214,6 +214,7 @@ static const char *hw_flag_names[] = {
  39. FLAG(SUPPORTS_TDLS_BUFFER_STA),
  40. FLAG(DEAUTH_NEED_MGD_TX_PREP),
  41. FLAG(DOESNT_SUPPORT_QOS_NDP),
  42. + FLAG(NEEDS_ALIGNED4_SKBS),
  43. #undef FLAG
  44. };
  45. --- a/net/mac80211/ieee80211_i.h
  46. +++ b/net/mac80211/ieee80211_i.h
  47. @@ -1557,6 +1557,29 @@ ieee80211_vif_get_num_mcast_if(struct ie
  48. return -1;
  49. }
  50. +static inline unsigned int
  51. +ieee80211_hdr_padsize(struct ieee80211_hw *hw, unsigned int hdrlen)
  52. +{
  53. + /*
  54. + * While hdrlen is already aligned to two-byte boundaries,
  55. + * simple check with & 2 will return correct padsize.
  56. + */
  57. + if (ieee80211_hw_check(hw, NEEDS_ALIGNED4_SKBS))
  58. + return hdrlen & 2;
  59. + return 0;
  60. +}
  61. +
  62. +static inline unsigned int
  63. +ieee80211_padded_hdrlen(struct ieee80211_hw *hw, __le16 fc)
  64. +{
  65. + unsigned int hdrlen;
  66. +
  67. + hdrlen = ieee80211_hdrlen(fc);
  68. + hdrlen += ieee80211_hdr_padsize(hw, hdrlen);
  69. +
  70. + return hdrlen;
  71. +}
  72. +
  73. u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
  74. struct ieee80211_rx_status *status,
  75. unsigned int mpdu_len,
  76. --- a/net/mac80211/sta_info.h
  77. +++ b/net/mac80211/sta_info.h
  78. @@ -301,7 +301,7 @@ struct ieee80211_fast_tx {
  79. u8 hdr_len;
  80. u8 sa_offs, da_offs, pn_offs;
  81. u8 band;
  82. - u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  83. + u8 hdr[30 + 2 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  84. sizeof(rfc1042_header)] __aligned(2);
  85. struct rcu_head rcu_head;
  86. --- a/net/mac80211/status.c
  87. +++ b/net/mac80211/status.c
  88. @@ -655,9 +655,22 @@ void ieee80211_tx_monitor(struct ieee802
  89. struct sk_buff *skb2;
  90. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  91. struct ieee80211_sub_if_data *sdata;
  92. + struct ieee80211_hdr *hdr = (void *)skb->data;
  93. struct net_device *prev_dev = NULL;
  94. + unsigned int hdrlen, padsize;
  95. int rtap_len;
  96. + /* Remove padding if was added */
  97. + if (ieee80211_hw_check(&local->hw, NEEDS_ALIGNED4_SKBS)) {
  98. + hdrlen = ieee80211_hdrlen(hdr->frame_control);
  99. + padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
  100. +
  101. + if (padsize && skb->len > hdrlen + padsize) {
  102. + memmove(skb->data + padsize, skb->data, hdrlen);
  103. + skb_pull(skb, padsize);
  104. + }
  105. + }
  106. +
  107. /* send frame to monitor interfaces now */
  108. rtap_len = ieee80211_tx_radiotap_len(info);
  109. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  110. --- a/net/mac80211/tkip.c
  111. +++ b/net/mac80211/tkip.c
  112. @@ -201,10 +201,12 @@ void ieee80211_get_tkip_p2k(struct ieee8
  113. {
  114. struct ieee80211_key *key = (struct ieee80211_key *)
  115. container_of(keyconf, struct ieee80211_key, conf);
  116. + struct ieee80211_hw *hw = &key->local->hw;
  117. const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
  118. struct tkip_ctx *ctx = &key->u.tkip.tx;
  119. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  120. - const u8 *data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
  121. + const u8 *data = (u8 *)hdr + ieee80211_padded_hdrlen(hw,
  122. + hdr->frame_control);
  123. u32 iv32 = get_unaligned_le32(&data[4]);
  124. u16 iv16 = data[2] | (data[0] << 8);
  125. --- a/net/mac80211/tx.c
  126. +++ b/net/mac80211/tx.c
  127. @@ -1175,8 +1175,7 @@ ieee80211_tx_prepare(struct ieee80211_su
  128. info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  129. hdr = (struct ieee80211_hdr *) skb->data;
  130. -
  131. - tx->hdrlen = ieee80211_hdrlen(hdr->frame_control);
  132. + tx->hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  133. if (likely(sta)) {
  134. if (!IS_ERR(sta))
  135. @@ -2209,7 +2208,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
  136. goto fail;
  137. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  138. - hdrlen = ieee80211_hdrlen(hdr->frame_control);
  139. + hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  140. if (skb->len < len_rthdr + hdrlen)
  141. goto fail;
  142. @@ -2427,7 +2426,7 @@ static struct sk_buff *ieee80211_build_h
  143. struct ieee80211_chanctx_conf *chanctx_conf;
  144. struct ieee80211_sub_if_data *ap_sdata;
  145. enum nl80211_band band;
  146. - int ret;
  147. + int padsize, ret;
  148. if (IS_ERR(sta))
  149. sta = NULL;
  150. @@ -2647,6 +2646,9 @@ static struct sk_buff *ieee80211_build_h
  151. hdrlen += 2;
  152. }
  153. + /* Check aligned4 skb required */
  154. + padsize = ieee80211_hdr_padsize(&sdata->local->hw, hdrlen);
  155. +
  156. /*
  157. * Drop unicast frames to unauthorised stations unless they are
  158. * EAPOL frames from the local station.
  159. @@ -2727,6 +2729,7 @@ static struct sk_buff *ieee80211_build_h
  160. skb_pull(skb, skip_header_bytes);
  161. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  162. + head_need += padsize;
  163. /*
  164. * So we need to modify the skb header and hence need a copy of
  165. @@ -2759,6 +2762,9 @@ static struct sk_buff *ieee80211_build_h
  166. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  167. #endif
  168. + if (padsize)
  169. + memset(skb_push(skb, padsize), 0, padsize);
  170. +
  171. if (ieee80211_is_data_qos(fc)) {
  172. __le16 *qos_control;
  173. @@ -2934,6 +2940,9 @@ void ieee80211_check_fast_xmit(struct st
  174. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  175. }
  176. + /* Check aligned4 skb required */
  177. + build.hdr_len += ieee80211_hdr_padsize(&local->hw, build.hdr_len);
  178. +
  179. /* We store the key here so there's no point in using rcu_dereference()
  180. * but that's fine because the code that changes the pointers will call
  181. * this function after doing so. For a single CPU that would be enough,
  182. @@ -3528,7 +3537,7 @@ begin:
  183. if (tx.key &&
  184. (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  185. - pn_offs = ieee80211_hdrlen(hdr->frame_control);
  186. + pn_offs = tx.hdrlen;
  187. ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
  188. tx.key, skb);
  189. --- a/net/mac80211/util.c
  190. +++ b/net/mac80211/util.c
  191. @@ -1288,6 +1288,7 @@ void ieee80211_send_auth(struct ieee8021
  192. u32 tx_flags)
  193. {
  194. struct ieee80211_local *local = sdata->local;
  195. + struct ieee80211_hw *hw = &local->hw;
  196. struct sk_buff *skb;
  197. struct ieee80211_mgmt *mgmt;
  198. unsigned int hdrlen;
  199. @@ -1314,7 +1315,7 @@ void ieee80211_send_auth(struct ieee8021
  200. skb_put_data(skb, extra, extra_len);
  201. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  202. - hdrlen = ieee80211_hdrlen(mgmt->frame_control);
  203. + hdrlen = ieee80211_padded_hdrlen(hw, mgmt->frame_control);
  204. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  205. err = ieee80211_wep_encrypt(local, skb, hdrlen, key,
  206. key_len, key_idx);