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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. From: Janusz Dziedzic <[email protected]>
  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 <[email protected]>
  16. ---
  17. Index: backports-v4.18-rc7/include/net/mac80211.h
  18. ===================================================================
  19. --- backports-v4.18-rc7.orig/include/net/mac80211.h
  20. +++ backports-v4.18-rc7/include/net/mac80211.h
  21. @@ -2084,6 +2084,9 @@ struct ieee80211_txq {
  22. * @IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP: The driver (or firmware) doesn't
  23. * support QoS NDP for AP probing - that's most likely a driver bug.
  24. *
  25. + * @IEEE80211_HW_NEEDS_ALIGNED4_SKBS: Driver need aligned skbs to four-byte.
  26. + * Padding will be added after ieee80211_hdr, before IV/LLC.
  27. + *
  28. * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  29. */
  30. enum ieee80211_hw_flags {
  31. @@ -2129,6 +2132,7 @@ enum ieee80211_hw_flags {
  32. IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA,
  33. IEEE80211_HW_DEAUTH_NEED_MGD_TX_PREP,
  34. IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP,
  35. + IEEE80211_HW_NEEDS_ALIGNED4_SKBS,
  36. /* keep last, obviously */
  37. NUM_IEEE80211_HW_FLAGS
  38. Index: backports-v4.18-rc7/net/mac80211/debugfs.c
  39. ===================================================================
  40. --- backports-v4.18-rc7.orig/net/mac80211/debugfs.c
  41. +++ backports-v4.18-rc7/net/mac80211/debugfs.c
  42. @@ -214,6 +214,7 @@ static const char *hw_flag_names[] = {
  43. FLAG(SUPPORTS_TDLS_BUFFER_STA),
  44. FLAG(DEAUTH_NEED_MGD_TX_PREP),
  45. FLAG(DOESNT_SUPPORT_QOS_NDP),
  46. + FLAG(NEEDS_ALIGNED4_SKBS),
  47. #undef FLAG
  48. };
  49. Index: backports-v4.18-rc7/net/mac80211/ieee80211_i.h
  50. ===================================================================
  51. --- backports-v4.18-rc7.orig/net/mac80211/ieee80211_i.h
  52. +++ backports-v4.18-rc7/net/mac80211/ieee80211_i.h
  53. @@ -1550,6 +1550,29 @@ ieee80211_vif_get_num_mcast_if(struct ie
  54. return -1;
  55. }
  56. +static inline unsigned int
  57. +ieee80211_hdr_padsize(struct ieee80211_hw *hw, unsigned int hdrlen)
  58. +{
  59. + /*
  60. + * While hdrlen is already aligned to two-byte boundaries,
  61. + * simple check with & 2 will return correct padsize.
  62. + */
  63. + if (ieee80211_hw_check(hw, NEEDS_ALIGNED4_SKBS))
  64. + return hdrlen & 2;
  65. + return 0;
  66. +}
  67. +
  68. +static inline unsigned int
  69. +ieee80211_padded_hdrlen(struct ieee80211_hw *hw, __le16 fc)
  70. +{
  71. + unsigned int hdrlen;
  72. +
  73. + hdrlen = ieee80211_hdrlen(fc);
  74. + hdrlen += ieee80211_hdr_padsize(hw, hdrlen);
  75. +
  76. + return hdrlen;
  77. +}
  78. +
  79. u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
  80. struct ieee80211_rx_status *status,
  81. unsigned int mpdu_len,
  82. Index: backports-v4.18-rc7/net/mac80211/sta_info.h
  83. ===================================================================
  84. --- backports-v4.18-rc7.orig/net/mac80211/sta_info.h
  85. +++ backports-v4.18-rc7/net/mac80211/sta_info.h
  86. @@ -301,7 +301,7 @@ struct ieee80211_fast_tx {
  87. u8 hdr_len;
  88. u8 sa_offs, da_offs, pn_offs;
  89. u8 band;
  90. - u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  91. + u8 hdr[30 + 2 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  92. sizeof(rfc1042_header)] __aligned(2);
  93. struct rcu_head rcu_head;
  94. Index: backports-v4.18-rc7/net/mac80211/status.c
  95. ===================================================================
  96. --- backports-v4.18-rc7.orig/net/mac80211/status.c
  97. +++ backports-v4.18-rc7/net/mac80211/status.c
  98. @@ -653,9 +653,22 @@ void ieee80211_tx_monitor(struct ieee802
  99. struct sk_buff *skb2;
  100. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  101. struct ieee80211_sub_if_data *sdata;
  102. + struct ieee80211_hdr *hdr = (void *)skb->data;
  103. struct net_device *prev_dev = NULL;
  104. + unsigned int hdrlen, padsize;
  105. int rtap_len;
  106. + /* Remove padding if was added */
  107. + if (ieee80211_hw_check(&local->hw, NEEDS_ALIGNED4_SKBS)) {
  108. + hdrlen = ieee80211_hdrlen(hdr->frame_control);
  109. + padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
  110. +
  111. + if (padsize && skb->len > hdrlen + padsize) {
  112. + memmove(skb->data + padsize, skb->data, hdrlen);
  113. + skb_pull(skb, padsize);
  114. + }
  115. + }
  116. +
  117. /* send frame to monitor interfaces now */
  118. rtap_len = ieee80211_tx_radiotap_len(info);
  119. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  120. Index: backports-v4.18-rc7/net/mac80211/tkip.c
  121. ===================================================================
  122. --- backports-v4.18-rc7.orig/net/mac80211/tkip.c
  123. +++ backports-v4.18-rc7/net/mac80211/tkip.c
  124. @@ -201,10 +201,12 @@ void ieee80211_get_tkip_p2k(struct ieee8
  125. {
  126. struct ieee80211_key *key = (struct ieee80211_key *)
  127. container_of(keyconf, struct ieee80211_key, conf);
  128. + struct ieee80211_hw *hw = &key->local->hw;
  129. const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
  130. struct tkip_ctx *ctx = &key->u.tkip.tx;
  131. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  132. - const u8 *data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
  133. + const u8 *data = (u8 *)hdr + ieee80211_padded_hdrlen(hw,
  134. + hdr->frame_control);
  135. u32 iv32 = get_unaligned_le32(&data[4]);
  136. u16 iv16 = data[2] | (data[0] << 8);
  137. Index: backports-v4.18-rc7/net/mac80211/tx.c
  138. ===================================================================
  139. --- backports-v4.18-rc7.orig/net/mac80211/tx.c
  140. +++ backports-v4.18-rc7/net/mac80211/tx.c
  141. @@ -1169,8 +1169,7 @@ ieee80211_tx_prepare(struct ieee80211_su
  142. info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  143. hdr = (struct ieee80211_hdr *) skb->data;
  144. -
  145. - tx->hdrlen = ieee80211_hdrlen(hdr->frame_control);
  146. + tx->hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  147. if (likely(sta)) {
  148. if (!IS_ERR(sta))
  149. @@ -2200,7 +2199,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
  150. goto fail;
  151. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  152. - hdrlen = ieee80211_hdrlen(hdr->frame_control);
  153. + hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  154. if (skb->len < len_rthdr + hdrlen)
  155. goto fail;
  156. @@ -2418,7 +2417,7 @@ static struct sk_buff *ieee80211_build_h
  157. struct ieee80211_chanctx_conf *chanctx_conf;
  158. struct ieee80211_sub_if_data *ap_sdata;
  159. enum nl80211_band band;
  160. - int ret;
  161. + int padsize, ret;
  162. if (IS_ERR(sta))
  163. sta = NULL;
  164. @@ -2638,6 +2637,9 @@ static struct sk_buff *ieee80211_build_h
  165. hdrlen += 2;
  166. }
  167. + /* Check aligned4 skb required */
  168. + padsize = ieee80211_hdr_padsize(&sdata->local->hw, hdrlen);
  169. +
  170. /*
  171. * Drop unicast frames to unauthorised stations unless they are
  172. * EAPOL frames from the local station.
  173. @@ -2718,6 +2720,7 @@ static struct sk_buff *ieee80211_build_h
  174. skb_pull(skb, skip_header_bytes);
  175. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  176. + head_need += padsize;
  177. /*
  178. * So we need to modify the skb header and hence need a copy of
  179. @@ -2750,6 +2753,9 @@ static struct sk_buff *ieee80211_build_h
  180. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  181. #endif
  182. + if (padsize)
  183. + memset(skb_push(skb, padsize), 0, padsize);
  184. +
  185. if (ieee80211_is_data_qos(fc)) {
  186. __le16 *qos_control;
  187. @@ -2925,6 +2931,9 @@ void ieee80211_check_fast_xmit(struct st
  188. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  189. }
  190. + /* Check aligned4 skb required */
  191. + build.hdr_len += ieee80211_hdr_padsize(&local->hw, build.hdr_len);
  192. +
  193. /* We store the key here so there's no point in using rcu_dereference()
  194. * but that's fine because the code that changes the pointers will call
  195. * this function after doing so. For a single CPU that would be enough,
  196. @@ -3513,7 +3522,7 @@ begin:
  197. if (tx.key &&
  198. (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  199. - pn_offs = ieee80211_hdrlen(hdr->frame_control);
  200. + pn_offs = tx.hdrlen;
  201. ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
  202. tx.key, skb);
  203. Index: backports-v4.18-rc7/net/mac80211/util.c
  204. ===================================================================
  205. --- backports-v4.18-rc7.orig/net/mac80211/util.c
  206. +++ backports-v4.18-rc7/net/mac80211/util.c
  207. @@ -1274,6 +1274,7 @@ void ieee80211_send_auth(struct ieee8021
  208. u32 tx_flags)
  209. {
  210. struct ieee80211_local *local = sdata->local;
  211. + struct ieee80211_hw *hw = &local->hw;
  212. struct sk_buff *skb;
  213. struct ieee80211_mgmt *mgmt;
  214. unsigned int hdrlen;
  215. @@ -1300,7 +1301,7 @@ void ieee80211_send_auth(struct ieee8021
  216. skb_put_data(skb, extra, extra_len);
  217. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  218. - hdrlen = ieee80211_hdrlen(mgmt->frame_control);
  219. + hdrlen = ieee80211_padded_hdrlen(hw, mgmt->frame_control);
  220. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  221. err = ieee80211_wep_encrypt(local, skb, hdrlen, key,
  222. key_len, key_idx);