319-wifi-mac80211-mesh-fast-xmit-support.patch 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Sun, 26 Feb 2023 13:53:08 +0100
  3. Subject: [PATCH] wifi: mac80211: mesh fast xmit support
  4. Previously, fast xmit only worked on interface types where initially a
  5. sta lookup is performed, and a cached header can be attached to the sta,
  6. requiring only some fields to be updated at runtime.
  7. This technique is not directly applicable for a mesh device type due
  8. to the dynamic nature of the topology and protocol. There are more
  9. addresses that need to be filled, and there is an extra header with a
  10. dynamic length based on the addressing mode.
  11. Change the code to cache entries contain a copy of the mesh subframe header +
  12. bridge tunnel header, as well as an embedded struct ieee80211_fast_tx, which
  13. contains the information for building the 802.11 header.
  14. Add a mesh specific early fast xmit call, which looks up a cached entry and
  15. adds only the mesh subframe header, before passing it over to the generic
  16. fast xmit code.
  17. To ensure the changes in network are reflected in these cached headers,
  18. flush affected cached entries on path changes, as well as other conditions
  19. that currently trigger a fast xmit check in other modes (key changes etc.)
  20. This code is loosely based on a previous implementation by:
  21. Sriram R <quic_srirrama@quicinc.com>
  22. Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
  23. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  24. ---
  25. --- a/net/mac80211/ieee80211_i.h
  26. +++ b/net/mac80211/ieee80211_i.h
  27. @@ -37,6 +37,7 @@
  28. extern const struct cfg80211_ops mac80211_config_ops;
  29. struct ieee80211_local;
  30. +struct ieee80211_mesh_fast_tx;
  31. /* Maximum number of broadcast/multicast frames to buffer when some of the
  32. * associated stations are using power saving. */
  33. @@ -656,6 +657,19 @@ struct mesh_table {
  34. atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
  35. };
  36. +/**
  37. + * struct mesh_tx_cache - mesh fast xmit header cache
  38. + *
  39. + * @rht: hash table containing struct ieee80211_mesh_fast_tx, using skb DA as key
  40. + * @walk_head: linked list containing all ieee80211_mesh_fast_tx objects
  41. + * @walk_lock: lock protecting walk_head and rht
  42. + */
  43. +struct mesh_tx_cache {
  44. + struct rhashtable rht;
  45. + struct hlist_head walk_head;
  46. + spinlock_t walk_lock;
  47. +};
  48. +
  49. struct ieee80211_if_mesh {
  50. struct timer_list housekeeping_timer;
  51. struct timer_list mesh_path_timer;
  52. @@ -734,6 +748,7 @@ struct ieee80211_if_mesh {
  53. struct mesh_table mpp_paths; /* Store paths for MPP&MAP */
  54. int mesh_paths_generation;
  55. int mpp_paths_generation;
  56. + struct mesh_tx_cache tx_cache;
  57. };
  58. #ifdef CPTCFG_MAC80211_MESH
  59. @@ -2002,6 +2017,11 @@ int ieee80211_tx_control_port(struct wip
  60. int link_id, u64 *cookie);
  61. int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
  62. const u8 *buf, size_t len);
  63. +void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
  64. + struct sta_info *sta,
  65. + struct ieee80211_fast_tx *fast_tx,
  66. + struct sk_buff *skb, bool ampdu,
  67. + const u8 *da, const u8 *sa);
  68. /* HT */
  69. void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
  70. --- a/net/mac80211/mesh.c
  71. +++ b/net/mac80211/mesh.c
  72. @@ -10,6 +10,7 @@
  73. #include <asm/unaligned.h>
  74. #include "ieee80211_i.h"
  75. #include "mesh.h"
  76. +#include "wme.h"
  77. #include "driver-ops.h"
  78. static int mesh_allocated;
  79. @@ -698,6 +699,95 @@ ieee80211_mesh_update_bss_params(struct
  80. __le32_to_cpu(he_oper->he_oper_params);
  81. }
  82. +bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
  83. + struct sk_buff *skb, u32 ctrl_flags)
  84. +{
  85. + struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  86. + struct ieee80211_mesh_fast_tx *entry;
  87. + struct ieee80211s_hdr *meshhdr;
  88. + u8 sa[ETH_ALEN] __aligned(2);
  89. + struct tid_ampdu_tx *tid_tx;
  90. + struct sta_info *sta;
  91. + bool copy_sa = false;
  92. + u16 ethertype;
  93. + u8 tid;
  94. +
  95. + if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
  96. + return false;
  97. +
  98. + if (ifmsh->mshcfg.dot11MeshNolearn)
  99. + return false;
  100. +
  101. + /* Add support for these cases later */
  102. + if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep)
  103. + return false;
  104. +
  105. + if (is_multicast_ether_addr(skb->data))
  106. + return false;
  107. +
  108. + ethertype = (skb->data[12] << 8) | skb->data[13];
  109. + if (ethertype < ETH_P_802_3_MIN)
  110. + return false;
  111. +
  112. + if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
  113. + return false;
  114. +
  115. + if (skb->ip_summed == CHECKSUM_PARTIAL) {
  116. + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
  117. + if (skb_checksum_help(skb))
  118. + return false;
  119. + }
  120. +
  121. + entry = mesh_fast_tx_get(sdata, skb->data);
  122. + if (!entry)
  123. + return false;
  124. +
  125. + if (skb_headroom(skb) < entry->hdrlen + entry->fast_tx.hdr_len)
  126. + return false;
  127. +
  128. + sta = rcu_dereference(entry->mpath->next_hop);
  129. + if (!sta)
  130. + return false;
  131. +
  132. + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  133. + tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  134. + if (tid_tx) {
  135. + if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
  136. + return false;
  137. + if (tid_tx->timeout)
  138. + tid_tx->last_tx = jiffies;
  139. + }
  140. +
  141. + skb = skb_share_check(skb, GFP_ATOMIC);
  142. + if (!skb)
  143. + return true;
  144. +
  145. + skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
  146. +
  147. + meshhdr = (struct ieee80211s_hdr *)entry->hdr;
  148. + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
  149. + /* preserve SA from eth header for 6-addr frames */
  150. + ether_addr_copy(sa, skb->data + ETH_ALEN);
  151. + copy_sa = true;
  152. + }
  153. +
  154. + memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr,
  155. + entry->hdrlen);
  156. +
  157. + meshhdr = (struct ieee80211s_hdr *)skb->data;
  158. + put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
  159. + &meshhdr->seqnum);
  160. + meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  161. + if (copy_sa)
  162. + ether_addr_copy(meshhdr->eaddr2, sa);
  163. +
  164. + skb_push(skb, 2 * ETH_ALEN);
  165. + __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
  166. + entry->mpath->dst, sdata->vif.addr);
  167. +
  168. + return true;
  169. +}
  170. +
  171. /**
  172. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  173. * @hdr: 802.11 frame header
  174. @@ -780,6 +870,8 @@ static void ieee80211_mesh_housekeeping(
  175. changed = mesh_accept_plinks_update(sdata);
  176. ieee80211_mbss_info_change_notify(sdata, changed);
  177. + mesh_fast_tx_gc(sdata);
  178. +
  179. mod_timer(&ifmsh->housekeeping_timer,
  180. round_jiffies(jiffies +
  181. IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  182. --- a/net/mac80211/mesh.h
  183. +++ b/net/mac80211/mesh.h
  184. @@ -122,11 +122,41 @@ struct mesh_path {
  185. u8 rann_snd_addr[ETH_ALEN];
  186. u32 rann_metric;
  187. unsigned long last_preq_to_root;
  188. + unsigned long fast_tx_check;
  189. bool is_root;
  190. bool is_gate;
  191. u32 path_change_count;
  192. };
  193. +#define MESH_FAST_TX_CACHE_MAX_SIZE 512
  194. +#define MESH_FAST_TX_CACHE_THRESHOLD_SIZE 384
  195. +#define MESH_FAST_TX_CACHE_TIMEOUT 8000 /* msecs */
  196. +
  197. +/**
  198. + * struct ieee80211_mesh_fast_tx - cached mesh fast tx entry
  199. + * @rhash: rhashtable pointer
  200. + * @addr_key: The Ethernet DA which is the key for this entry
  201. + * @fast_tx: base fast_tx data
  202. + * @hdr: cached mesh and rfc1042 headers
  203. + * @hdrlen: length of mesh + rfc1042
  204. + * @walk_list: list containing all the fast tx entries
  205. + * @mpath: mesh path corresponding to the Mesh DA
  206. + * @mppath: MPP entry corresponding to this DA
  207. + * @timestamp: Last used time of this entry
  208. + */
  209. +struct ieee80211_mesh_fast_tx {
  210. + struct rhash_head rhash;
  211. + u8 addr_key[ETH_ALEN] __aligned(2);
  212. +
  213. + struct ieee80211_fast_tx fast_tx;
  214. + u8 hdr[sizeof(struct ieee80211s_hdr) + sizeof(rfc1042_header)];
  215. + u16 hdrlen;
  216. +
  217. + struct mesh_path *mpath, *mppath;
  218. + struct hlist_node walk_list;
  219. + unsigned long timestamp;
  220. +};
  221. +
  222. /* Recent multicast cache */
  223. /* RMC_BUCKETS must be a power of 2, maximum 256 */
  224. #define RMC_BUCKETS 256
  225. @@ -298,6 +328,20 @@ void mesh_path_discard_frame(struct ieee
  226. void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);
  227. bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
  228. +struct ieee80211_mesh_fast_tx *
  229. +mesh_fast_tx_get(struct ieee80211_sub_if_data *sdata, const u8 *addr);
  230. +bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
  231. + struct sk_buff *skb, u32 ctrl_flags);
  232. +void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
  233. + struct sk_buff *skb, struct mesh_path *mpath);
  234. +void mesh_fast_tx_gc(struct ieee80211_sub_if_data *sdata);
  235. +void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata,
  236. + const u8 *addr);
  237. +void mesh_fast_tx_flush_mpath(struct mesh_path *mpath);
  238. +void mesh_fast_tx_flush_sta(struct ieee80211_sub_if_data *sdata,
  239. + struct sta_info *sta);
  240. +void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
  241. + struct mesh_path *mpath, const u8 *addr);
  242. #ifdef CPTCFG_MAC80211_MESH
  243. static inline
  244. --- a/net/mac80211/mesh_hwmp.c
  245. +++ b/net/mac80211/mesh_hwmp.c
  246. @@ -394,6 +394,7 @@ static u32 hwmp_route_info_get(struct ie
  247. u32 orig_sn, orig_metric;
  248. unsigned long orig_lifetime, exp_time;
  249. u32 last_hop_metric, new_metric;
  250. + bool flush_mpath = false;
  251. bool process = true;
  252. u8 hopcount;
  253. @@ -491,8 +492,10 @@ static u32 hwmp_route_info_get(struct ie
  254. }
  255. if (fresh_info) {
  256. - if (rcu_access_pointer(mpath->next_hop) != sta)
  257. + if (rcu_access_pointer(mpath->next_hop) != sta) {
  258. mpath->path_change_count++;
  259. + flush_mpath = true;
  260. + }
  261. mesh_path_assign_nexthop(mpath, sta);
  262. mpath->flags |= MESH_PATH_SN_VALID;
  263. mpath->metric = new_metric;
  264. @@ -502,6 +505,8 @@ static u32 hwmp_route_info_get(struct ie
  265. mpath->hop_count = hopcount;
  266. mesh_path_activate(mpath);
  267. spin_unlock_bh(&mpath->state_lock);
  268. + if (flush_mpath)
  269. + mesh_fast_tx_flush_mpath(mpath);
  270. ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
  271. /* init it at a low value - 0 start is tricky */
  272. ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
  273. @@ -539,8 +544,10 @@ static u32 hwmp_route_info_get(struct ie
  274. }
  275. if (fresh_info) {
  276. - if (rcu_access_pointer(mpath->next_hop) != sta)
  277. + if (rcu_access_pointer(mpath->next_hop) != sta) {
  278. mpath->path_change_count++;
  279. + flush_mpath = true;
  280. + }
  281. mesh_path_assign_nexthop(mpath, sta);
  282. mpath->metric = last_hop_metric;
  283. mpath->exp_time = time_after(mpath->exp_time, exp_time)
  284. @@ -548,6 +555,8 @@ static u32 hwmp_route_info_get(struct ie
  285. mpath->hop_count = 1;
  286. mesh_path_activate(mpath);
  287. spin_unlock_bh(&mpath->state_lock);
  288. + if (flush_mpath)
  289. + mesh_fast_tx_flush_mpath(mpath);
  290. ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
  291. /* init it at a low value - 0 start is tricky */
  292. ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
  293. @@ -1215,6 +1224,20 @@ static int mesh_nexthop_lookup_nolearn(s
  294. return 0;
  295. }
  296. +void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
  297. + struct mesh_path *mpath, const u8 *addr)
  298. +{
  299. + if (mpath->flags & (MESH_PATH_REQ_QUEUED | MESH_PATH_FIXED |
  300. + MESH_PATH_RESOLVING))
  301. + return;
  302. +
  303. + if (time_after(jiffies,
  304. + mpath->exp_time -
  305. + msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
  306. + (!addr || ether_addr_equal(sdata->vif.addr, addr)))
  307. + mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
  308. +}
  309. +
  310. /**
  311. * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling
  312. * this function is considered "using" the associated mpath, so preempt a path
  313. @@ -1242,19 +1265,15 @@ int mesh_nexthop_lookup(struct ieee80211
  314. if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
  315. return -ENOENT;
  316. - if (time_after(jiffies,
  317. - mpath->exp_time -
  318. - msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
  319. - ether_addr_equal(sdata->vif.addr, hdr->addr4) &&
  320. - !(mpath->flags & MESH_PATH_RESOLVING) &&
  321. - !(mpath->flags & MESH_PATH_FIXED))
  322. - mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
  323. + mesh_path_refresh(sdata, mpath, hdr->addr4);
  324. next_hop = rcu_dereference(mpath->next_hop);
  325. if (next_hop) {
  326. memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
  327. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  328. ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
  329. + if (ieee80211_hw_check(&sdata->local->hw, SUPPORT_FAST_XMIT))
  330. + mesh_fast_tx_cache(sdata, skb, mpath);
  331. return 0;
  332. }
  333. --- a/net/mac80211/mesh_pathtbl.c
  334. +++ b/net/mac80211/mesh_pathtbl.c
  335. @@ -14,6 +14,7 @@
  336. #include "wme.h"
  337. #include "ieee80211_i.h"
  338. #include "mesh.h"
  339. +#include <linux/rhashtable.h>
  340. static void mesh_path_free_rcu(struct mesh_table *tbl, struct mesh_path *mpath);
  341. @@ -32,6 +33,41 @@ static const struct rhashtable_params me
  342. .hashfn = mesh_table_hash,
  343. };
  344. +static const struct rhashtable_params fast_tx_rht_params = {
  345. + .nelem_hint = 10,
  346. + .automatic_shrinking = true,
  347. + .key_len = ETH_ALEN,
  348. + .key_offset = offsetof(struct ieee80211_mesh_fast_tx, addr_key),
  349. + .head_offset = offsetof(struct ieee80211_mesh_fast_tx, rhash),
  350. + .hashfn = mesh_table_hash,
  351. +};
  352. +
  353. +static void __mesh_fast_tx_entry_free(void *ptr, void *tblptr)
  354. +{
  355. + struct ieee80211_mesh_fast_tx *entry = ptr;
  356. +
  357. + kfree_rcu(entry, fast_tx.rcu_head);
  358. +}
  359. +
  360. +static void mesh_fast_tx_deinit(struct ieee80211_sub_if_data *sdata)
  361. +{
  362. + struct mesh_tx_cache *cache;
  363. +
  364. + cache = &sdata->u.mesh.tx_cache;
  365. + rhashtable_free_and_destroy(&cache->rht,
  366. + __mesh_fast_tx_entry_free, NULL);
  367. +}
  368. +
  369. +static void mesh_fast_tx_init(struct ieee80211_sub_if_data *sdata)
  370. +{
  371. + struct mesh_tx_cache *cache;
  372. +
  373. + cache = &sdata->u.mesh.tx_cache;
  374. + rhashtable_init(&cache->rht, &fast_tx_rht_params);
  375. + INIT_HLIST_HEAD(&cache->walk_head);
  376. + spin_lock_init(&cache->walk_lock);
  377. +}
  378. +
  379. static inline bool mpath_expired(struct mesh_path *mpath)
  380. {
  381. return (mpath->flags & MESH_PATH_ACTIVE) &&
  382. @@ -381,6 +417,243 @@ struct mesh_path *mesh_path_new(struct i
  383. return new_mpath;
  384. }
  385. +static void mesh_fast_tx_entry_free(struct mesh_tx_cache *cache,
  386. + struct ieee80211_mesh_fast_tx *entry)
  387. +{
  388. + hlist_del_rcu(&entry->walk_list);
  389. + rhashtable_remove_fast(&cache->rht, &entry->rhash, fast_tx_rht_params);
  390. + kfree_rcu(entry, fast_tx.rcu_head);
  391. +}
  392. +
  393. +struct ieee80211_mesh_fast_tx *
  394. +mesh_fast_tx_get(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  395. +{
  396. + struct ieee80211_mesh_fast_tx *entry;
  397. + struct mesh_tx_cache *cache;
  398. +
  399. + cache = &sdata->u.mesh.tx_cache;
  400. + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
  401. + if (!entry)
  402. + return NULL;
  403. +
  404. + if (!(entry->mpath->flags & MESH_PATH_ACTIVE) ||
  405. + mpath_expired(entry->mpath)) {
  406. + spin_lock_bh(&cache->walk_lock);
  407. + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
  408. + if (entry)
  409. + mesh_fast_tx_entry_free(cache, entry);
  410. + spin_unlock_bh(&cache->walk_lock);
  411. + return NULL;
  412. + }
  413. +
  414. + mesh_path_refresh(sdata, entry->mpath, NULL);
  415. + if (entry->mppath)
  416. + entry->mppath->exp_time = jiffies;
  417. + entry->timestamp = jiffies;
  418. +
  419. + return entry;
  420. +}
  421. +
  422. +void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
  423. + struct sk_buff *skb, struct mesh_path *mpath)
  424. +{
  425. + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  426. + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  427. + struct ieee80211_mesh_fast_tx *entry, *prev;
  428. + struct ieee80211_mesh_fast_tx build = {};
  429. + struct ieee80211s_hdr *meshhdr;
  430. + struct mesh_tx_cache *cache;
  431. + struct ieee80211_key *key;
  432. + struct mesh_path *mppath;
  433. + struct sta_info *sta;
  434. + u8 *qc;
  435. +
  436. + if (sdata->noack_map ||
  437. + !ieee80211_is_data_qos(hdr->frame_control))
  438. + return;
  439. +
  440. + build.fast_tx.hdr_len = ieee80211_hdrlen(hdr->frame_control);
  441. + meshhdr = (struct ieee80211s_hdr *)(skb->data + build.fast_tx.hdr_len);
  442. + build.hdrlen = ieee80211_get_mesh_hdrlen(meshhdr);
  443. +
  444. + cache = &sdata->u.mesh.tx_cache;
  445. + if (atomic_read(&cache->rht.nelems) >= MESH_FAST_TX_CACHE_MAX_SIZE)
  446. + return;
  447. +
  448. + sta = rcu_dereference(mpath->next_hop);
  449. + if (!sta)
  450. + return;
  451. +
  452. + if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
  453. + /* This is required to keep the mppath alive */
  454. + mppath = mpp_path_lookup(sdata, meshhdr->eaddr1);
  455. + if (!mppath)
  456. + return;
  457. + build.mppath = mppath;
  458. + } else if (ieee80211_has_a4(hdr->frame_control)) {
  459. + mppath = mpath;
  460. + } else {
  461. + return;
  462. + }
  463. +
  464. + /* rate limit, in case fast xmit can't be enabled */
  465. + if (mppath->fast_tx_check == jiffies)
  466. + return;
  467. +
  468. + mppath->fast_tx_check = jiffies;
  469. +
  470. + /*
  471. + * Same use of the sta lock as in ieee80211_check_fast_xmit, in order
  472. + * to protect against concurrent sta key updates.
  473. + */
  474. + spin_lock_bh(&sta->lock);
  475. + key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
  476. + if (!key)
  477. + key = rcu_access_pointer(sdata->default_unicast_key);
  478. + build.fast_tx.key = key;
  479. +
  480. + if (key) {
  481. + bool gen_iv, iv_spc;
  482. +
  483. + gen_iv = key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
  484. + iv_spc = key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  485. +
  486. + if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
  487. + (key->flags & KEY_FLAG_TAINTED))
  488. + goto unlock_sta;
  489. +
  490. + switch (key->conf.cipher) {
  491. + case WLAN_CIPHER_SUITE_CCMP:
  492. + case WLAN_CIPHER_SUITE_CCMP_256:
  493. + if (gen_iv)
  494. + build.fast_tx.pn_offs = build.fast_tx.hdr_len;
  495. + if (gen_iv || iv_spc)
  496. + build.fast_tx.hdr_len += IEEE80211_CCMP_HDR_LEN;
  497. + break;
  498. + case WLAN_CIPHER_SUITE_GCMP:
  499. + case WLAN_CIPHER_SUITE_GCMP_256:
  500. + if (gen_iv)
  501. + build.fast_tx.pn_offs = build.fast_tx.hdr_len;
  502. + if (gen_iv || iv_spc)
  503. + build.fast_tx.hdr_len += IEEE80211_GCMP_HDR_LEN;
  504. + break;
  505. + default:
  506. + goto unlock_sta;
  507. + }
  508. + }
  509. +
  510. + memcpy(build.addr_key, mppath->dst, ETH_ALEN);
  511. + build.timestamp = jiffies;
  512. + build.fast_tx.band = info->band;
  513. + build.fast_tx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  514. + build.fast_tx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  515. + build.mpath = mpath;
  516. + memcpy(build.hdr, meshhdr, build.hdrlen);
  517. + memcpy(build.hdr + build.hdrlen, rfc1042_header, sizeof(rfc1042_header));
  518. + build.hdrlen += sizeof(rfc1042_header);
  519. + memcpy(build.fast_tx.hdr, hdr, build.fast_tx.hdr_len);
  520. +
  521. + hdr = (struct ieee80211_hdr *)build.fast_tx.hdr;
  522. + if (build.fast_tx.key)
  523. + hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  524. +
  525. + qc = ieee80211_get_qos_ctl(hdr);
  526. + qc[1] |= IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8;
  527. +
  528. + entry = kmemdup(&build, sizeof(build), GFP_ATOMIC);
  529. + if (!entry)
  530. + goto unlock_sta;
  531. +
  532. + spin_lock(&cache->walk_lock);
  533. + prev = rhashtable_lookup_get_insert_fast(&cache->rht,
  534. + &entry->rhash,
  535. + fast_tx_rht_params);
  536. + if (unlikely(IS_ERR(prev))) {
  537. + kfree(entry);
  538. + goto unlock_cache;
  539. + }
  540. +
  541. + /*
  542. + * replace any previous entry in the hash table, in case we're
  543. + * replacing it with a different type (e.g. mpath -> mpp)
  544. + */
  545. + if (unlikely(prev)) {
  546. + rhashtable_replace_fast(&cache->rht, &prev->rhash,
  547. + &entry->rhash, fast_tx_rht_params);
  548. + hlist_del_rcu(&prev->walk_list);
  549. + kfree_rcu(prev, fast_tx.rcu_head);
  550. + }
  551. +
  552. + hlist_add_head(&entry->walk_list, &cache->walk_head);
  553. +
  554. +unlock_cache:
  555. + spin_unlock(&cache->walk_lock);
  556. +unlock_sta:
  557. + spin_unlock_bh(&sta->lock);
  558. +}
  559. +
  560. +void mesh_fast_tx_gc(struct ieee80211_sub_if_data *sdata)
  561. +{
  562. + unsigned long timeout = msecs_to_jiffies(MESH_FAST_TX_CACHE_TIMEOUT);
  563. + struct mesh_tx_cache *cache;
  564. + struct ieee80211_mesh_fast_tx *entry;
  565. + struct hlist_node *n;
  566. +
  567. + cache = &sdata->u.mesh.tx_cache;
  568. + if (atomic_read(&cache->rht.nelems) < MESH_FAST_TX_CACHE_THRESHOLD_SIZE)
  569. + return;
  570. +
  571. + spin_lock_bh(&cache->walk_lock);
  572. + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
  573. + if (!time_is_after_jiffies(entry->timestamp + timeout))
  574. + mesh_fast_tx_entry_free(cache, entry);
  575. + spin_unlock_bh(&cache->walk_lock);
  576. +}
  577. +
  578. +void mesh_fast_tx_flush_mpath(struct mesh_path *mpath)
  579. +{
  580. + struct ieee80211_sub_if_data *sdata = mpath->sdata;
  581. + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
  582. + struct ieee80211_mesh_fast_tx *entry;
  583. + struct hlist_node *n;
  584. +
  585. + cache = &sdata->u.mesh.tx_cache;
  586. + spin_lock_bh(&cache->walk_lock);
  587. + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
  588. + if (entry->mpath == mpath)
  589. + mesh_fast_tx_entry_free(cache, entry);
  590. + spin_unlock_bh(&cache->walk_lock);
  591. +}
  592. +
  593. +void mesh_fast_tx_flush_sta(struct ieee80211_sub_if_data *sdata,
  594. + struct sta_info *sta)
  595. +{
  596. + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
  597. + struct ieee80211_mesh_fast_tx *entry;
  598. + struct hlist_node *n;
  599. +
  600. + cache = &sdata->u.mesh.tx_cache;
  601. + spin_lock_bh(&cache->walk_lock);
  602. + hlist_for_each_entry_safe(entry, n, &cache->walk_head, walk_list)
  603. + if (rcu_access_pointer(entry->mpath->next_hop) == sta)
  604. + mesh_fast_tx_entry_free(cache, entry);
  605. + spin_unlock_bh(&cache->walk_lock);
  606. +}
  607. +
  608. +void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata,
  609. + const u8 *addr)
  610. +{
  611. + struct mesh_tx_cache *cache = &sdata->u.mesh.tx_cache;
  612. + struct ieee80211_mesh_fast_tx *entry;
  613. +
  614. + cache = &sdata->u.mesh.tx_cache;
  615. + spin_lock_bh(&cache->walk_lock);
  616. + entry = rhashtable_lookup(&cache->rht, addr, fast_tx_rht_params);
  617. + if (entry)
  618. + mesh_fast_tx_entry_free(cache, entry);
  619. + spin_unlock_bh(&cache->walk_lock);
  620. +}
  621. +
  622. /**
  623. * mesh_path_add - allocate and add a new path to the mesh path table
  624. * @dst: destination address of the path (ETH_ALEN length)
  625. @@ -464,6 +737,8 @@ int mpp_path_add(struct ieee80211_sub_if
  626. if (ret)
  627. kfree(new_mpath);
  628. + else
  629. + mesh_fast_tx_flush_addr(sdata, dst);
  630. sdata->u.mesh.mpp_paths_generation++;
  631. return ret;
  632. @@ -523,6 +798,10 @@ static void __mesh_path_del(struct mesh_
  633. {
  634. hlist_del_rcu(&mpath->walk_list);
  635. rhashtable_remove_fast(&tbl->rhead, &mpath->rhash, mesh_rht_params);
  636. + if (tbl == &mpath->sdata->u.mesh.mpp_paths)
  637. + mesh_fast_tx_flush_addr(mpath->sdata, mpath->dst);
  638. + else
  639. + mesh_fast_tx_flush_mpath(mpath);
  640. mesh_path_free_rcu(tbl, mpath);
  641. }
  642. @@ -747,6 +1026,7 @@ void mesh_path_fix_nexthop(struct mesh_p
  643. mpath->exp_time = 0;
  644. mpath->flags = MESH_PATH_FIXED | MESH_PATH_SN_VALID;
  645. mesh_path_activate(mpath);
  646. + mesh_fast_tx_flush_mpath(mpath);
  647. spin_unlock_bh(&mpath->state_lock);
  648. ewma_mesh_fail_avg_init(&next_hop->mesh->fail_avg);
  649. /* init it at a low value - 0 start is tricky */
  650. @@ -758,6 +1038,7 @@ void mesh_pathtbl_init(struct ieee80211_
  651. {
  652. mesh_table_init(&sdata->u.mesh.mesh_paths);
  653. mesh_table_init(&sdata->u.mesh.mpp_paths);
  654. + mesh_fast_tx_init(sdata);
  655. }
  656. static
  657. @@ -785,6 +1066,7 @@ void mesh_path_expire(struct ieee80211_s
  658. void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata)
  659. {
  660. + mesh_fast_tx_deinit(sdata);
  661. mesh_table_free(&sdata->u.mesh.mesh_paths);
  662. mesh_table_free(&sdata->u.mesh.mpp_paths);
  663. }
  664. --- a/net/mac80211/rx.c
  665. +++ b/net/mac80211/rx.c
  666. @@ -2791,6 +2791,7 @@ ieee80211_rx_mesh_data(struct ieee80211_
  667. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  668. struct mesh_path *mppath;
  669. char *proxied_addr;
  670. + bool update = false;
  671. if (multicast)
  672. proxied_addr = mesh_hdr->eaddr1;
  673. @@ -2806,11 +2807,18 @@ ieee80211_rx_mesh_data(struct ieee80211_
  674. mpp_path_add(sdata, proxied_addr, eth->h_source);
  675. } else {
  676. spin_lock_bh(&mppath->state_lock);
  677. - if (!ether_addr_equal(mppath->mpp, eth->h_source))
  678. + if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
  679. memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
  680. + update = true;
  681. + }
  682. mppath->exp_time = jiffies;
  683. spin_unlock_bh(&mppath->state_lock);
  684. }
  685. +
  686. + /* flush fast xmit cache if the address path changed */
  687. + if (update)
  688. + mesh_fast_tx_flush_addr(sdata, proxied_addr);
  689. +
  690. rcu_read_unlock();
  691. }
  692. --- a/net/mac80211/tx.c
  693. +++ b/net/mac80211/tx.c
  694. @@ -3022,6 +3022,9 @@ void ieee80211_check_fast_xmit(struct st
  695. if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
  696. return;
  697. + if (ieee80211_vif_is_mesh(&sdata->vif))
  698. + mesh_fast_tx_flush_sta(sdata, sta);
  699. +
  700. /* Locking here protects both the pointer itself, and against concurrent
  701. * invocations winning data access races to, e.g., the key pointer that
  702. * is used.
  703. @@ -3403,6 +3406,9 @@ static bool ieee80211_amsdu_aggregate(st
  704. if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
  705. return false;
  706. + if (ieee80211_vif_is_mesh(&sdata->vif))
  707. + return false;
  708. +
  709. if (skb_is_gso(skb))
  710. return false;
  711. @@ -3635,10 +3641,11 @@ free:
  712. return NULL;
  713. }
  714. -static void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
  715. - struct sta_info *sta,
  716. - struct ieee80211_fast_tx *fast_tx,
  717. - struct sk_buff *skb, u8 tid, bool ampdu)
  718. +void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
  719. + struct sta_info *sta,
  720. + struct ieee80211_fast_tx *fast_tx,
  721. + struct sk_buff *skb, bool ampdu,
  722. + const u8 *da, const u8 *sa)
  723. {
  724. struct ieee80211_local *local = sdata->local;
  725. struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
  726. @@ -3647,7 +3654,6 @@ static void __ieee80211_xmit_fast(struct
  727. ieee80211_tx_result r;
  728. int hw_headroom = sdata->local->hw.extra_tx_headroom;
  729. int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
  730. - struct ethhdr eth;
  731. skb = skb_share_check(skb, GFP_ATOMIC);
  732. if (unlikely(!skb))
  733. @@ -3667,11 +3673,10 @@ static void __ieee80211_xmit_fast(struct
  734. ENCRYPT_NO)))
  735. goto free;
  736. - memcpy(&eth, skb->data, ETH_HLEN - 2);
  737. hdr = skb_push(skb, extra_head);
  738. memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
  739. - memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
  740. - memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
  741. + memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN);
  742. + memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN);
  743. info = IEEE80211_SKB_CB(skb);
  744. memset(info, 0, sizeof(*info));
  745. @@ -3690,7 +3695,8 @@ static void __ieee80211_xmit_fast(struct
  746. #endif
  747. if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  748. - tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  749. + u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  750. +
  751. *ieee80211_get_qos_ctl(hdr) = tid;
  752. }
  753. @@ -3733,6 +3739,7 @@ static bool ieee80211_xmit_fast(struct i
  754. struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
  755. struct tid_ampdu_tx *tid_tx = NULL;
  756. struct sk_buff *next;
  757. + struct ethhdr eth;
  758. u8 tid = IEEE80211_NUM_TIDS;
  759. /* control port protocol needs a lot of special handling */
  760. @@ -3758,6 +3765,8 @@ static bool ieee80211_xmit_fast(struct i
  761. }
  762. }
  763. + memcpy(&eth, skb->data, ETH_HLEN - 2);
  764. +
  765. /* after this point (skb is modified) we cannot return false */
  766. skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
  767. if (!skb)
  768. @@ -3765,7 +3774,8 @@ static bool ieee80211_xmit_fast(struct i
  769. skb_list_walk_safe(skb, skb, next) {
  770. skb_mark_not_on_list(skb);
  771. - __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid, tid_tx);
  772. + __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx,
  773. + eth.h_dest, eth.h_source);
  774. }
  775. return true;
  776. @@ -4252,8 +4262,15 @@ void __ieee80211_subif_start_xmit(struct
  777. return;
  778. }
  779. + sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
  780. +
  781. rcu_read_lock();
  782. + if (ieee80211_vif_is_mesh(&sdata->vif) &&
  783. + ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) &&
  784. + ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
  785. + goto out;
  786. +
  787. if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
  788. goto out_free;
  789. @@ -4263,8 +4280,6 @@ void __ieee80211_subif_start_xmit(struct
  790. skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
  791. ieee80211_aggr_check(sdata, sta, skb);
  792. - sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
  793. -
  794. if (sta) {
  795. struct ieee80211_fast_tx *fast_tx;