Path: blob/main/sys/contrib/dev/broadcom/brcm80211/brcmsmac/rate.h
178665 views
/*1* Copyright (c) 2010 Broadcom Corporation2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY10* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION12* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN13* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*/1516#ifndef _BRCM_RATE_H_17#define _BRCM_RATE_H_1819#include "types.h"20#include "d11.h"21#include "phy_hal.h"2223extern const u8 rate_info[];24extern const struct brcms_c_rateset cck_ofdm_mimo_rates;25extern const struct brcms_c_rateset ofdm_mimo_rates;26extern const struct brcms_c_rateset cck_ofdm_rates;27extern const struct brcms_c_rateset ofdm_rates;28extern const struct brcms_c_rateset cck_rates;29extern const struct brcms_c_rateset gphy_legacy_rates;30extern const struct brcms_c_rateset rate_limit_1_2;3132struct brcms_mcs_info {33/* phy rate in kbps [20Mhz] */34u32 phy_rate_20;35/* phy rate in kbps [40Mhz] */36u32 phy_rate_40;37/* phy rate in kbps [20Mhz] with SGI */38u32 phy_rate_20_sgi;39/* phy rate in kbps [40Mhz] with SGI */40u32 phy_rate_40_sgi;41/* phy ctl byte 3, code rate, modulation type, # of streams */42u8 tx_phy_ctl3;43/* matching legacy ofdm rate in 500bkps */44u8 leg_ofdm;45};4647#define BRCMS_MAXMCS 32 /* max valid mcs index */48#define MCS_TABLE_SIZE 33 /* Number of mcs entries in the table */49extern const struct brcms_mcs_info mcs_table[];5051#define MCS_TXS_MASK 0xc0 /* num tx streams - 1 bit mask */52#define MCS_TXS_SHIFT 6 /* num tx streams - 1 bit shift */5354/* returns num tx streams - 1 */55static inline u8 mcs_2_txstreams(u8 mcs)56{57return (mcs_table[mcs].tx_phy_ctl3 & MCS_TXS_MASK) >> MCS_TXS_SHIFT;58}5960static inline uint mcs_2_rate(u8 mcs, bool is40, bool sgi)61{62if (sgi) {63if (is40)64return mcs_table[mcs].phy_rate_40_sgi;65return mcs_table[mcs].phy_rate_20_sgi;66}67if (is40)68return mcs_table[mcs].phy_rate_40;6970return mcs_table[mcs].phy_rate_20;71}7273/* Macro to use the rate_info table */74#define BRCMS_RATE_MASK_FULL 0xff /* Rate value mask with basic rate flag */7576/*77* rate spec : holds rate and mode specific information required to generate a78* tx frame. Legacy CCK and OFDM information is held in the same manner as was79* done in the past (in the lower byte) the upper 3 bytes primarily hold MIMO80* specific information81*/8283/* rate spec bit fields */8485/* Either 500Kbps units or MIMO MCS idx */86#define RSPEC_RATE_MASK 0x0000007F87/* mimo MCS is stored in RSPEC_RATE_MASK */88#define RSPEC_MIMORATE 0x0800000089/* mimo bw mask */90#define RSPEC_BW_MASK 0x0000070091/* mimo bw shift */92#define RSPEC_BW_SHIFT 893/* mimo Space/Time/Frequency mode mask */94#define RSPEC_STF_MASK 0x0000380095/* mimo Space/Time/Frequency mode shift */96#define RSPEC_STF_SHIFT 1197/* mimo coding type mask */98#define RSPEC_CT_MASK 0x0000C00099/* mimo coding type shift */100#define RSPEC_CT_SHIFT 14101/* mimo num STC streams per PLCP defn. */102#define RSPEC_STC_MASK 0x00300000103/* mimo num STC streams per PLCP defn. */104#define RSPEC_STC_SHIFT 20105/* mimo bit indicates adv coding in use */106#define RSPEC_LDPC_CODING 0x00400000107/* mimo bit indicates short GI in use */108#define RSPEC_SHORT_GI 0x00800000109/* bit indicates override both rate & mode */110#define RSPEC_OVERRIDE 0x80000000111/* bit indicates override rate only */112#define RSPEC_OVERRIDE_MCS_ONLY 0x40000000113114static inline bool rspec_active(u32 rspec)115{116return rspec & (RSPEC_RATE_MASK | RSPEC_MIMORATE);117}118119static inline u8 rspec_phytxbyte2(u32 rspec)120{121return (rspec & 0xff00) >> 8;122}123124static inline u32 rspec_get_bw(u32 rspec)125{126return (rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT;127}128129static inline bool rspec_issgi(u32 rspec)130{131return (rspec & RSPEC_SHORT_GI) == RSPEC_SHORT_GI;132}133134static inline bool rspec_is40mhz(u32 rspec)135{136u32 bw = rspec_get_bw(rspec);137138return bw == PHY_TXC1_BW_40MHZ || bw == PHY_TXC1_BW_40MHZ_DUP;139}140141static inline uint rspec2rate(u32 rspec)142{143if (rspec & RSPEC_MIMORATE)144return mcs_2_rate(rspec & RSPEC_RATE_MASK, rspec_is40mhz(rspec),145rspec_issgi(rspec));146return rspec & RSPEC_RATE_MASK;147}148149static inline u8 rspec_mimoplcp3(u32 rspec)150{151return (rspec & 0xf00000) >> 16;152}153154static inline bool plcp3_issgi(u8 plcp)155{156return (plcp & (RSPEC_SHORT_GI >> 16)) != 0;157}158159static inline uint rspec_stc(u32 rspec)160{161return (rspec & RSPEC_STC_MASK) >> RSPEC_STC_SHIFT;162}163164static inline uint rspec_stf(u32 rspec)165{166return (rspec & RSPEC_STF_MASK) >> RSPEC_STF_SHIFT;167}168169static inline bool is_mcs_rate(u32 ratespec)170{171return (ratespec & RSPEC_MIMORATE) != 0;172}173174static inline bool is_ofdm_rate(u32 ratespec)175{176return !is_mcs_rate(ratespec) &&177(rate_info[ratespec & RSPEC_RATE_MASK] & BRCMS_RATE_FLAG);178}179180static inline bool is_cck_rate(u32 ratespec)181{182u32 rate = (ratespec & BRCMS_RATE_MASK);183184return !is_mcs_rate(ratespec) && (185rate == BRCM_RATE_1M || rate == BRCM_RATE_2M ||186rate == BRCM_RATE_5M5 || rate == BRCM_RATE_11M);187}188189static inline bool is_single_stream(u8 mcs)190{191return mcs <= HIGHEST_SINGLE_STREAM_MCS || mcs == 32;192}193194static inline u8 cck_rspec(u8 cck)195{196return cck & RSPEC_RATE_MASK;197}198199/* Convert encoded rate value in plcp header to numerical rates in 500 KHz200* increments */201static inline u8 ofdm_phy2mac_rate(u8 rlpt)202{203return wlc_phy_get_ofdm_rate_lookup()[rlpt & 0x7];204}205206static inline u8 cck_phy2mac_rate(u8 signal)207{208return signal/5;209}210211/* Rates specified in brcms_c_rateset_filter() */212#define BRCMS_RATES_CCK_OFDM 0213#define BRCMS_RATES_CCK 1214#define BRCMS_RATES_OFDM 2215216/* sanitize, and sort a rateset with the basic bit(s) preserved, validate217* rateset */218bool brcms_c_rate_hwrs_filter_sort_validate(struct brcms_c_rateset *rs,219const struct brcms_c_rateset *hw_rs,220bool check_brate, u8 txstreams);221/* copy rateset src to dst as-is (no masking or sorting) */222void brcms_c_rateset_copy(const struct brcms_c_rateset *src,223struct brcms_c_rateset *dst);224225/* would be nice to have these documented ... */226u32 brcms_c_compute_rspec(struct d11rxhdr *rxh, u8 *plcp);227228void brcms_c_rateset_filter(struct brcms_c_rateset *src,229struct brcms_c_rateset *dst, bool basic_only,230u8 rates, uint xmask, bool mcsallow);231232void brcms_c_rateset_default(struct brcms_c_rateset *rs_tgt,233const struct brcms_c_rateset *rs_hw, uint phy_type,234int bandtype, bool cck_only, uint rate_mask,235bool mcsallow, u8 bw, u8 txstreams);236237s16 brcms_c_rate_legacy_phyctl(uint rate);238239void brcms_c_rateset_mcs_upd(struct brcms_c_rateset *rs, u8 txstreams);240void brcms_c_rateset_mcs_clear(struct brcms_c_rateset *rateset);241void brcms_c_rateset_mcs_build(struct brcms_c_rateset *rateset, u8 txstreams);242void brcms_c_rateset_bw_mcs_filter(struct brcms_c_rateset *rateset, u8 bw);243244#endif /* _BRCM_RATE_H_ */245246247