| 1 | /*	$OpenBSD: ieee80211_ra_vht.h,v 1.1 2022/03/19 10:25:09 stsp Exp $	*/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2021 Christian Ehrhardt <ehrhardt@genua.de> |
| 5 | * Copyright (c) 2021, 2022 Stefan Sperling <stsp@openbsd.org> |
| 6 | * |
| 7 | * Permission to use, copy, modify, and distribute this software for any |
| 8 | * purpose with or without fee is hereby granted, provided that the above |
| 9 | * copyright notice and this permission notice appear in all copies. |
| 10 | * |
| 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Goodput statistics struct. Measures the effective data rate of a rate. |
| 22 | * All uint64_t numbers in this struct use fixed-point arithmetic. |
| 23 | */ |
| 24 | struct ieee80211_ra_vht_goodput_stats { |
| 25 | 	uint64_t measured;	/* Most recently measured goodput. */ |
| 26 | 	uint64_t average;	/* Average measured goodput. */ |
| 27 | 	uint64_t stddeviation;	/* Goodput standard deviation. */ |
| 28 | 	uint64_t loss;		/* This rate's loss percentage SFER. */ |
| 29 | 	uint32_t nprobe_pkts;	/* Number of packets in current probe. */ |
| 30 | 	uint32_t nprobe_fail;	/* Number of failed packets. */ |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * Rate adaptation state. |
| 35 | * |
| 36 | * Drivers should not modify any fields of this structure directly. |
| 37 | * Use ieee80211_ra_vht_init() and ieee80211_ra_vht_add_stats() only. |
| 38 | */ |
| 39 | struct ieee80211_ra_vht_node { |
| 40 | 	/* Bitmaps for MCS 0-9 for a given number of spatial streams. */ |
| 41 | 	uint16_t valid_probes[IEEE80211_VHT_NUM_SS]; |
| 42 | 	uint16_t valid_rates[IEEE80211_VHT_NUM_SS]; |
| 43 | 	uint16_t candidate_rates[IEEE80211_VHT_NUM_SS]; |
| 44 | 	uint16_t probed_rates[IEEE80211_VHT_NUM_SS]; |
| 45 | |
| 46 | 	/* Maximum usable MCS per given number of spatial streams. */ |
| 47 | 	int max_mcs[IEEE80211_VHT_NUM_SS]; |
| 48 | |
| 49 | 	/* Probing state. */ |
| 50 | 	int probing; |
| 51 | #define IEEE80211_RA_NOT_PROBING	0x0 |
| 52 | #define IEEE80211_RA_PROBING_DOWN	0x1 |
| 53 | #define IEEE80211_RA_PROBING_UP		0x2 |
| 54 | #define IEEE80211_RA_PROBING_INTER	0x4 /* combined with UP or DOWN */ |
| 55 | |
| 56 | 	/* The current best MCS,NSS found by probing. */ |
| 57 | 	int best_mcs; |
| 58 | 	int best_nss; |
| 59 | |
| 60 | 	/* Goodput statistics for each rate. */ |
| 61 | 	struct ieee80211_ra_vht_goodput_stats |
| 62 | 	 g[IEEE80211_VHT_NUM_RATESETS][IEEE80211_VHT_RATESET_MAX_NRATES]; |
| 63 | }; |
| 64 | |
| 65 | /* Initialize rate adaptation state. */ |
| 66 | void	ieee80211_ra_vht_node_init(struct ieee80211_ra_vht_node *); |
| 67 | |
| 68 | /* |
| 69 | * Drivers report information about 802.11ac/VHT Tx attempts here. |
| 70 | * mcs: The VHT MCS used during this Tx attempt. |
| 71 | * nss: The number of spatial streams used during this Tx attempt. |
| 72 | * total: How many Tx attempts (initial attempt + any retries) were made? |
| 73 | * fail: How many of these Tx attempts failed? |
| 74 | */ |
| 75 | void	ieee80211_ra_vht_add_stats(struct ieee80211_ra_vht_node *, |
| 76 | 	 struct ieee80211com *, struct ieee80211_node *, |
| 77 | 	 int mcs, int nss, unsigned int total, unsigned int fail); |
| 78 | |
| 79 | /* Drivers call this function to update ni->ni_txmcs and ni->ni_vht_ss. */ |
| 80 | void	ieee80211_ra_vht_choose(struct ieee80211_ra_vht_node *, |
| 81 | 	 struct ieee80211com *, struct ieee80211_node *); |
| 82 | |
| 83 | /* |
| 84 | * Get the VHT rateset for a particular VHT MCS, NSS, with 40MHz, 80MHz, |
| 85 | * and/or SGI on/off. |
| 86 | */ |
| 87 | const struct ieee80211_vht_rateset * ieee80211_ra_vht_get_rateset(int mcs, |
| 88 | 	 int nss, int chan40, int chan80, int sgi); |
| 89 | |
| 90 | /* Check whether SGI should be used. */ |
| 91 | int ieee80211_ra_vht_use_sgi(struct ieee80211_node *); |