351-mac80211-add-TX_NEEDS_ALIGNED4_SKBS-hw-flag.patch 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. From: Janusz Dziedzic <janusz.dziedzic@tieto.com>
  2. Date: Sun, 10 Mar 2019 17:22:08 +0100
  3. Subject: [PATCH] mac80211: add TX_NEEDS_ALIGNED4_SKBS hw flag
  4. The driver should set this flag if the hardware requires tx skb data
  5. (starting with the LLC header) to be aligned to 4 bytes.
  6. Padding is added after ieee80211_hdr, before IV/LLC.
  7. Before this patch, we have to do memmove(hdrlen) twice in the driver:
  8. Once before we pass this to HW and once again in tx completion
  9. (to fix up the skb for monitor mode).
  10. With this patch we can skip this memmove() and thus reduce CPU cycles in
  11. the data path.
  12. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
  13. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  14. ---
  15. --- a/include/net/mac80211.h
  16. +++ b/include/net/mac80211.h
  17. @@ -2140,6 +2140,9 @@ struct ieee80211_txq {
  18. * @IEEE80211_HW_TX_STATUS_NO_AMPDU_LEN: Driver does not report accurate A-MPDU
  19. * length in tx status information
  20. *
  21. + * @IEEE80211_HW_TX_NEEDS_ALIGNED4_SKBS: Driver need aligned skbs to four-byte.
  22. + * Padding will be added after ieee80211_hdr, before IV/LLC.
  23. + *
  24. * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  25. */
  26. enum ieee80211_hw_flags {
  27. @@ -2186,6 +2189,7 @@ enum ieee80211_hw_flags {
  28. IEEE80211_HW_DEAUTH_NEED_MGD_TX_PREP,
  29. IEEE80211_HW_DOESNT_SUPPORT_QOS_NDP,
  30. IEEE80211_HW_TX_STATUS_NO_AMPDU_LEN,
  31. + IEEE80211_HW_TX_NEEDS_ALIGNED4_SKBS,
  32. /* keep last, obviously */
  33. NUM_IEEE80211_HW_FLAGS
  34. @@ -2472,6 +2476,40 @@ ieee80211_get_alt_retry_rate(const struc
  35. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb);
  36. /**
  37. + * ieee80211_hdr_padsize - get size of padding between 802.11 header and LLC
  38. + * @hw: the hardware
  39. + * @hdrlen: 802.11 header length
  40. + */
  41. +static inline unsigned int
  42. +ieee80211_hdr_padsize(struct ieee80211_hw *hw, unsigned int hdrlen)
  43. +{
  44. + /*
  45. + * While hdrlen is already aligned to two-byte boundaries,
  46. + * simple check with & 2 will return correct padsize.
  47. + */
  48. + if (ieee80211_hw_check(hw, TX_NEEDS_ALIGNED4_SKBS))
  49. + return hdrlen & 2;
  50. + return 0;
  51. +}
  52. +
  53. +/**
  54. + * ieee80211_padded_hdrlen - get padded 802.11 header size
  55. + * @hw: the hardware
  56. + * @fc: frame control field in little-endian format
  57. + */
  58. +static inline unsigned int
  59. +ieee80211_padded_hdrlen(struct ieee80211_hw *hw, __le16 fc)
  60. +{
  61. + unsigned int hdrlen;
  62. +
  63. + hdrlen = ieee80211_hdrlen(fc);
  64. + hdrlen += ieee80211_hdr_padsize(hw, hdrlen);
  65. +
  66. + return hdrlen;
  67. +}
  68. +
  69. +
  70. +/**
  71. * DOC: Hardware crypto acceleration
  72. *
  73. * mac80211 is capable of taking advantage of many hardware
  74. --- a/net/mac80211/iface.c
  75. +++ b/net/mac80211/iface.c
  76. @@ -1871,6 +1871,10 @@ int ieee80211_if_add(struct ieee80211_lo
  77. + 8 /* rfc1042/bridge tunnel */
  78. - ETH_HLEN /* ethernet hard_header_len */
  79. + IEEE80211_ENCRYPT_HEADROOM;
  80. +
  81. + if (ieee80211_hw_check(&local->hw, TX_NEEDS_ALIGNED4_SKBS))
  82. + ndev->needed_headroom += 2; /* padding */
  83. +
  84. ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
  85. ret = dev_alloc_name(ndev, ndev->name);
  86. --- a/net/mac80211/mesh_pathtbl.c
  87. +++ b/net/mac80211/mesh_pathtbl.c
  88. @@ -105,13 +105,15 @@ void mesh_path_assign_nexthop(struct mes
  89. static void prepare_for_gate(struct sk_buff *skb, char *dst_addr,
  90. struct mesh_path *gate_mpath)
  91. {
  92. + struct ieee80211_sub_if_data *sdata = gate_mpath->sdata;
  93. + struct ieee80211_hw *hw = &sdata->local->hw;
  94. struct ieee80211_hdr *hdr;
  95. struct ieee80211s_hdr *mshdr;
  96. int mesh_hdrlen, hdrlen;
  97. char *next_hop;
  98. hdr = (struct ieee80211_hdr *) skb->data;
  99. - hdrlen = ieee80211_hdrlen(hdr->frame_control);
  100. + hdrlen = ieee80211_padded_hdrlen(hw, hdr->frame_control);
  101. mshdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  102. if (!(mshdr->flags & MESH_FLAGS_AE)) {
  103. --- a/net/mac80211/rx.c
  104. +++ b/net/mac80211/rx.c
  105. @@ -2597,7 +2597,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
  106. struct ieee80211_local *local = rx->local;
  107. struct ieee80211_sub_if_data *sdata = rx->sdata;
  108. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  109. - u16 ac, q, hdrlen;
  110. + u16 ac, q, hdrlen, padsize;
  111. int tailroom = 0;
  112. hdr = (struct ieee80211_hdr *) skb->data;
  113. @@ -2690,7 +2690,9 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
  114. if (sdata->crypto_tx_tailroom_needed_cnt)
  115. tailroom = IEEE80211_ENCRYPT_TAILROOM;
  116. - fwd_skb = skb_copy_expand(skb, local->tx_headroom +
  117. + padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
  118. +
  119. + fwd_skb = skb_copy_expand(skb, local->tx_headroom + padsize +
  120. sdata->encrypt_headroom,
  121. tailroom, GFP_ATOMIC);
  122. if (!fwd_skb)
  123. @@ -2722,6 +2724,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
  124. return RX_DROP_MONITOR;
  125. }
  126. + if (padsize) {
  127. + skb_push(fwd_skb, padsize);
  128. + memmove(fwd_skb->data, skb->data + padsize, hdrlen);
  129. + memset(fwd_skb->data + hdrlen, 0, padsize);
  130. + }
  131. +
  132. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  133. ieee80211_add_pending_skb(local, fwd_skb);
  134. out:
  135. --- a/net/mac80211/sta_info.h
  136. +++ b/net/mac80211/sta_info.h
  137. @@ -311,7 +311,7 @@ struct ieee80211_fast_tx {
  138. u8 hdr_len;
  139. u8 sa_offs, da_offs, pn_offs;
  140. u8 band;
  141. - u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  142. + u8 hdr[30 + 2 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
  143. sizeof(rfc1042_header)] __aligned(2);
  144. struct rcu_head rcu_head;
  145. --- a/net/mac80211/status.c
  146. +++ b/net/mac80211/status.c
  147. @@ -515,6 +515,7 @@ static void ieee80211_report_used_skb(st
  148. {
  149. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  150. struct ieee80211_hdr *hdr = (void *)skb->data;
  151. + struct ieee80211_hw *hw = &local->hw;
  152. bool acked = info->flags & IEEE80211_TX_STAT_ACK;
  153. if (dropped)
  154. @@ -531,7 +532,7 @@ static void ieee80211_report_used_skb(st
  155. skb->dev = NULL;
  156. } else {
  157. unsigned int hdr_size =
  158. - ieee80211_hdrlen(hdr->frame_control);
  159. + ieee80211_padded_hdrlen(hw, hdr->frame_control);
  160. /* Check to see if packet is a TDLS teardown packet */
  161. if (ieee80211_is_data(hdr->frame_control) &&
  162. @@ -655,9 +656,22 @@ void ieee80211_tx_monitor(struct ieee802
  163. struct sk_buff *skb2;
  164. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  165. struct ieee80211_sub_if_data *sdata;
  166. + struct ieee80211_hdr *hdr = (void *)skb->data;
  167. struct net_device *prev_dev = NULL;
  168. + unsigned int hdrlen, padsize;
  169. int rtap_len;
  170. + /* Remove padding if was added */
  171. + if (ieee80211_hw_check(&local->hw, TX_NEEDS_ALIGNED4_SKBS)) {
  172. + hdrlen = ieee80211_hdrlen(hdr->frame_control);
  173. + padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
  174. +
  175. + if (padsize && skb->len > hdrlen + padsize) {
  176. + memmove(skb->data + padsize, skb->data, hdrlen);
  177. + skb_pull(skb, padsize);
  178. + }
  179. + }
  180. +
  181. /* send frame to monitor interfaces now */
  182. rtap_len = ieee80211_tx_radiotap_len(info);
  183. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  184. --- a/net/mac80211/tkip.c
  185. +++ b/net/mac80211/tkip.c
  186. @@ -201,10 +201,12 @@ void ieee80211_get_tkip_p2k(struct ieee8
  187. {
  188. struct ieee80211_key *key = (struct ieee80211_key *)
  189. container_of(keyconf, struct ieee80211_key, conf);
  190. + struct ieee80211_hw *hw = &key->local->hw;
  191. const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
  192. struct tkip_ctx *ctx = &key->u.tkip.tx;
  193. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  194. - const u8 *data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
  195. + const u8 *data = (u8 *)hdr + ieee80211_padded_hdrlen(hw,
  196. + hdr->frame_control);
  197. u32 iv32 = get_unaligned_le32(&data[4]);
  198. u16 iv16 = data[2] | (data[0] << 8);
  199. --- a/net/mac80211/tx.c
  200. +++ b/net/mac80211/tx.c
  201. @@ -1175,8 +1175,7 @@ ieee80211_tx_prepare(struct ieee80211_su
  202. info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  203. hdr = (struct ieee80211_hdr *) skb->data;
  204. -
  205. - tx->hdrlen = ieee80211_hdrlen(hdr->frame_control);
  206. + tx->hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  207. if (likely(sta)) {
  208. if (!IS_ERR(sta))
  209. @@ -2222,7 +2221,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
  210. goto fail;
  211. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  212. - hdrlen = ieee80211_hdrlen(hdr->frame_control);
  213. + hdrlen = ieee80211_padded_hdrlen(&local->hw, hdr->frame_control);
  214. if (skb->len < len_rthdr + hdrlen)
  215. goto fail;
  216. @@ -2441,7 +2440,7 @@ static struct sk_buff *ieee80211_build_h
  217. struct ieee80211_chanctx_conf *chanctx_conf;
  218. struct ieee80211_sub_if_data *ap_sdata;
  219. enum nl80211_band band;
  220. - int ret;
  221. + int padsize, ret;
  222. if (IS_ERR(sta))
  223. sta = NULL;
  224. @@ -2740,7 +2739,9 @@ static struct sk_buff *ieee80211_build_h
  225. }
  226. skb_pull(skb, skip_header_bytes);
  227. + padsize = ieee80211_hdr_padsize(&local->hw, hdrlen);
  228. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  229. + head_need += padsize;
  230. /*
  231. * So we need to modify the skb header and hence need a copy of
  232. @@ -2773,6 +2774,9 @@ static struct sk_buff *ieee80211_build_h
  233. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  234. #endif
  235. + if (padsize)
  236. + memset(skb_push(skb, padsize), 0, padsize);
  237. +
  238. if (ieee80211_is_data_qos(fc)) {
  239. __le16 *qos_control;
  240. @@ -2949,6 +2953,8 @@ void ieee80211_check_fast_xmit(struct st
  241. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  242. }
  243. + build.hdr_len += ieee80211_hdr_padsize(&local->hw, build.hdr_len);
  244. +
  245. /* We store the key here so there's no point in using rcu_dereference()
  246. * but that's fine because the code that changes the pointers will call
  247. * this function after doing so. For a single CPU that would be enough,
  248. @@ -3525,7 +3531,7 @@ begin:
  249. tx.local = local;
  250. tx.skb = skb;
  251. tx.sdata = vif_to_sdata(info->control.vif);
  252. - tx.hdrlen = ieee80211_hdrlen(hdr->frame_control);
  253. + tx.hdrlen = ieee80211_padded_hdrlen(hw, hdr->frame_control);
  254. if (txq->sta) {
  255. tx.sta = container_of(txq->sta, struct sta_info, sta);
  256. @@ -4029,7 +4035,7 @@ ieee80211_build_data_template(struct iee
  257. hdr = (void *)skb->data;
  258. tx.sta = sta_info_get(sdata, hdr->addr1);
  259. tx.skb = skb;
  260. - tx.hdrlen = ieee80211_hdrlen(hdr->frame_control);
  261. + tx.hdrlen = ieee80211_padded_hdrlen(&tx.local->hw, hdr->frame_control);
  262. if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
  263. rcu_read_unlock();
  264. --- a/net/mac80211/debugfs.c
  265. +++ b/net/mac80211/debugfs.c
  266. @@ -215,6 +215,7 @@ static const char *hw_flag_names[] = {
  267. FLAG(DEAUTH_NEED_MGD_TX_PREP),
  268. FLAG(DOESNT_SUPPORT_QOS_NDP),
  269. FLAG(TX_STATUS_NO_AMPDU_LEN),
  270. + FLAG(TX_NEEDS_ALIGNED4_SKBS),
  271. #undef FLAG
  272. };