Skip to content

Commit

Permalink
wifi: mac80211: mesh fast xmit support
Browse files Browse the repository at this point in the history
Previously, fast xmit only worked on interface types where initially a
sta lookup is performed, and a cached header can be attached to the sta,
requiring only some fields to be updated at runtime.

This technique is not directly applicable for a mesh device type due
to the dynamic nature of the topology and protocol. There are more
addresses that need to be filled, and there is an extra header with a
dynamic length based on the addressing mode.

Change the code to cache entries contain a copy of the mesh subframe header +
bridge tunnel header, as well as an embedded struct ieee80211_fast_tx, which
contains the information for building the 802.11 header.

Add a mesh specific early fast xmit call, which looks up a cached entry and
adds only the mesh subframe header, before passing it over to the generic
fast xmit code.

To ensure the changes in network are reflected in these cached headers,
flush affected cached entries on path changes, as well as other conditions
that currently trigger a fast xmit check in other modes (key changes etc.)

This code is loosely based on a previous implementation by:
Sriram R <quic_srirrama@quicinc.com>

Cc: Sriram R <quic_srirrama@quicinc.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Link: https://lore.kernel.org/r/20230314095956.62085-4-nbd@nbd.name
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Felix Fietkau authored and Johannes Berg committed Mar 22, 2023
1 parent e626dad commit d5edb9a
Show file tree
Hide file tree
Showing 7 changed files with 507 additions and 25 deletions.
20 changes: 20 additions & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
extern const struct cfg80211_ops mac80211_config_ops;

struct ieee80211_local;
struct ieee80211_mesh_fast_tx;

/* Maximum number of broadcast/multicast frames to buffer when some of the
* associated stations are using power saving. */
Expand Down Expand Up @@ -656,6 +657,19 @@ struct mesh_table {
atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
};

/**
* struct mesh_tx_cache - mesh fast xmit header cache
*
* @rht: hash table containing struct ieee80211_mesh_fast_tx, using skb DA as key
* @walk_head: linked list containing all ieee80211_mesh_fast_tx objects
* @walk_lock: lock protecting walk_head and rht
*/
struct mesh_tx_cache {
struct rhashtable rht;
struct hlist_head walk_head;
spinlock_t walk_lock;
};

struct ieee80211_if_mesh {
struct timer_list housekeeping_timer;
struct timer_list mesh_path_timer;
Expand Down Expand Up @@ -734,6 +748,7 @@ struct ieee80211_if_mesh {
struct mesh_table mpp_paths; /* Store paths for MPP&MAP */
int mesh_paths_generation;
int mpp_paths_generation;
struct mesh_tx_cache tx_cache;
};

#ifdef CONFIG_MAC80211_MESH
Expand Down Expand Up @@ -2018,6 +2033,11 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
int link_id, u64 *cookie);
int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
const u8 *buf, size_t len);
void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta,
struct ieee80211_fast_tx *fast_tx,
struct sk_buff *skb, bool ampdu,
const u8 *da, const u8 *sa);

/* HT */
void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
Expand Down
92 changes: 92 additions & 0 deletions net/mac80211/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <asm/unaligned.h>
#include "ieee80211_i.h"
#include "mesh.h"
#include "wme.h"
#include "driver-ops.h"

static int mesh_allocated;
Expand Down Expand Up @@ -698,6 +699,95 @@ ieee80211_mesh_update_bss_params(struct ieee80211_sub_if_data *sdata,
__le32_to_cpu(he_oper->he_oper_params);
}

bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
struct sk_buff *skb, u32 ctrl_flags)
{
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
struct ieee80211_mesh_fast_tx *entry;
struct ieee80211s_hdr *meshhdr;
u8 sa[ETH_ALEN] __aligned(2);
struct tid_ampdu_tx *tid_tx;
struct sta_info *sta;
bool copy_sa = false;
u16 ethertype;
u8 tid;

if (ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
return false;

if (ifmsh->mshcfg.dot11MeshNolearn)
return false;

/* Add support for these cases later */
if (ifmsh->ps_peers_light_sleep || ifmsh->ps_peers_deep_sleep)
return false;

if (is_multicast_ether_addr(skb->data))
return false;

ethertype = (skb->data[12] << 8) | skb->data[13];
if (ethertype < ETH_P_802_3_MIN)
return false;

if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
return false;

if (skb->ip_summed == CHECKSUM_PARTIAL) {
skb_set_transport_header(skb, skb_checksum_start_offset(skb));
if (skb_checksum_help(skb))
return false;
}

entry = mesh_fast_tx_get(sdata, skb->data);
if (!entry)
return false;

if (skb_headroom(skb) < entry->hdrlen + entry->fast_tx.hdr_len)
return false;

sta = rcu_dereference(entry->mpath->next_hop);
if (!sta)
return false;

tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
if (tid_tx) {
if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
return false;
if (tid_tx->timeout)
tid_tx->last_tx = jiffies;
}

skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
return true;

skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));

meshhdr = (struct ieee80211s_hdr *)entry->hdr;
if ((meshhdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6) {
/* preserve SA from eth header for 6-addr frames */
ether_addr_copy(sa, skb->data + ETH_ALEN);
copy_sa = true;
}

memcpy(skb_push(skb, entry->hdrlen - 2 * ETH_ALEN), entry->hdr,
entry->hdrlen);

meshhdr = (struct ieee80211s_hdr *)skb->data;
put_unaligned_le32(atomic_inc_return(&sdata->u.mesh.mesh_seqnum),
&meshhdr->seqnum);
meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
if (copy_sa)
ether_addr_copy(meshhdr->eaddr2, sa);

skb_push(skb, 2 * ETH_ALEN);
__ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
entry->mpath->dst, sdata->vif.addr);

return true;
}

/**
* ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
* @hdr: 802.11 frame header
Expand Down Expand Up @@ -780,6 +870,8 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)
changed = mesh_accept_plinks_update(sdata);
ieee80211_mbss_info_change_notify(sdata, changed);

mesh_fast_tx_gc(sdata);

mod_timer(&ifmsh->housekeeping_timer,
round_jiffies(jiffies +
IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
Expand Down
44 changes: 44 additions & 0 deletions net/mac80211/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,41 @@ struct mesh_path {
u8 rann_snd_addr[ETH_ALEN];
u32 rann_metric;
unsigned long last_preq_to_root;
unsigned long fast_tx_check;
bool is_root;
bool is_gate;
u32 path_change_count;
};

#define MESH_FAST_TX_CACHE_MAX_SIZE 512
#define MESH_FAST_TX_CACHE_THRESHOLD_SIZE 384
#define MESH_FAST_TX_CACHE_TIMEOUT 8000 /* msecs */

/**
* struct ieee80211_mesh_fast_tx - cached mesh fast tx entry
* @rhash: rhashtable pointer
* @addr_key: The Ethernet DA which is the key for this entry
* @fast_tx: base fast_tx data
* @hdr: cached mesh and rfc1042 headers
* @hdrlen: length of mesh + rfc1042
* @walk_list: list containing all the fast tx entries
* @mpath: mesh path corresponding to the Mesh DA
* @mppath: MPP entry corresponding to this DA
* @timestamp: Last used time of this entry
*/
struct ieee80211_mesh_fast_tx {
struct rhash_head rhash;
u8 addr_key[ETH_ALEN] __aligned(2);

struct ieee80211_fast_tx fast_tx;
u8 hdr[sizeof(struct ieee80211s_hdr) + sizeof(rfc1042_header)];
u16 hdrlen;

struct mesh_path *mpath, *mppath;
struct hlist_node walk_list;
unsigned long timestamp;
};

/* Recent multicast cache */
/* RMC_BUCKETS must be a power of 2, maximum 256 */
#define RMC_BUCKETS 256
Expand Down Expand Up @@ -298,6 +328,20 @@ void mesh_path_discard_frame(struct ieee80211_sub_if_data *sdata,
void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata);

bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt);
struct ieee80211_mesh_fast_tx *
mesh_fast_tx_get(struct ieee80211_sub_if_data *sdata, const u8 *addr);
bool ieee80211_mesh_xmit_fast(struct ieee80211_sub_if_data *sdata,
struct sk_buff *skb, u32 ctrl_flags);
void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
struct sk_buff *skb, struct mesh_path *mpath);
void mesh_fast_tx_gc(struct ieee80211_sub_if_data *sdata);
void mesh_fast_tx_flush_addr(struct ieee80211_sub_if_data *sdata,
const u8 *addr);
void mesh_fast_tx_flush_mpath(struct mesh_path *mpath);
void mesh_fast_tx_flush_sta(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta);
void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
struct mesh_path *mpath, const u8 *addr);

#ifdef CONFIG_MAC80211_MESH
static inline
Expand Down
37 changes: 28 additions & 9 deletions net/mac80211/mesh_hwmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
u32 orig_sn, orig_metric;
unsigned long orig_lifetime, exp_time;
u32 last_hop_metric, new_metric;
bool flush_mpath = false;
bool process = true;
u8 hopcount;

Expand Down Expand Up @@ -491,8 +492,10 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
}

if (fresh_info) {
if (rcu_access_pointer(mpath->next_hop) != sta)
if (rcu_access_pointer(mpath->next_hop) != sta) {
mpath->path_change_count++;
flush_mpath = true;
}
mesh_path_assign_nexthop(mpath, sta);
mpath->flags |= MESH_PATH_SN_VALID;
mpath->metric = new_metric;
Expand All @@ -502,6 +505,8 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
mpath->hop_count = hopcount;
mesh_path_activate(mpath);
spin_unlock_bh(&mpath->state_lock);
if (flush_mpath)
mesh_fast_tx_flush_mpath(mpath);
ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
/* init it at a low value - 0 start is tricky */
ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
Expand Down Expand Up @@ -539,15 +544,19 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
}

if (fresh_info) {
if (rcu_access_pointer(mpath->next_hop) != sta)
if (rcu_access_pointer(mpath->next_hop) != sta) {
mpath->path_change_count++;
flush_mpath = true;
}
mesh_path_assign_nexthop(mpath, sta);
mpath->metric = last_hop_metric;
mpath->exp_time = time_after(mpath->exp_time, exp_time)
? mpath->exp_time : exp_time;
mpath->hop_count = 1;
mesh_path_activate(mpath);
spin_unlock_bh(&mpath->state_lock);
if (flush_mpath)
mesh_fast_tx_flush_mpath(mpath);
ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
/* init it at a low value - 0 start is tricky */
ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
Expand Down Expand Up @@ -1215,6 +1224,20 @@ static int mesh_nexthop_lookup_nolearn(struct ieee80211_sub_if_data *sdata,
return 0;
}

void mesh_path_refresh(struct ieee80211_sub_if_data *sdata,
struct mesh_path *mpath, const u8 *addr)
{
if (mpath->flags & (MESH_PATH_REQ_QUEUED | MESH_PATH_FIXED |
MESH_PATH_RESOLVING))
return;

if (time_after(jiffies,
mpath->exp_time -
msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
(!addr || ether_addr_equal(sdata->vif.addr, addr)))
mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
}

/**
* mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling
* this function is considered "using" the associated mpath, so preempt a path
Expand Down Expand Up @@ -1242,19 +1265,15 @@ int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
return -ENOENT;

if (time_after(jiffies,
mpath->exp_time -
msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
ether_addr_equal(sdata->vif.addr, hdr->addr4) &&
!(mpath->flags & MESH_PATH_RESOLVING) &&
!(mpath->flags & MESH_PATH_FIXED))
mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
mesh_path_refresh(sdata, mpath, hdr->addr4);

next_hop = rcu_dereference(mpath->next_hop);
if (next_hop) {
memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
if (ieee80211_hw_check(&sdata->local->hw, SUPPORT_FAST_XMIT))
mesh_fast_tx_cache(sdata, skb, mpath);
return 0;
}

Expand Down
Loading

0 comments on commit d5edb9a

Please sign in to comment.