| 1 | /*	$OpenBSD: ieee80211_ra.h,v 1.2 2021/10/11 09:01:06 stsp Exp $	*/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2021 Christian Ehrhardt <ehrhardt@genua.de> |
| 5 | * Copyright (c) 2021 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 an MCS. |
| 22 | * All uint64_t numbers in this struct use fixed-point arithmetic. |
| 23 | */ |
| 24 | struct ieee80211_ra_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_init() and ieee80211_ra_add_stats() only. |
| 38 | */ |
| 39 | struct ieee80211_ra_node { |
| 40 | 	/* Bitmaps MCS 0-31. */ |
| 41 | 	uint32_t valid_probes; |
| 42 | 	uint32_t valid_rates; |
| 43 | 	uint32_t candidate_rates; |
| 44 | 	uint32_t probed_rates; |
| 45 | |
| 46 | 	/* Probing state. */ |
| 47 | 	int probing; |
| 48 | #define IEEE80211_RA_NOT_PROBING	0x0 |
| 49 | #define IEEE80211_RA_PROBING_DOWN	0x1 |
| 50 | #define IEEE80211_RA_PROBING_UP		0x2 |
| 51 | #define IEEE80211_RA_PROBING_INTER	0x4 /* combined with UP or DOWN */ |
| 52 | |
| 53 | 	/* The current best MCS found by probing. */ |
| 54 | 	int best_mcs; |
| 55 | |
| 56 | 	/* Goodput statistics for each MCS. */ |
| 57 | 	struct ieee80211_ra_goodput_stats g[IEEE80211_HT_RATESET_NUM_MCS]; |
| 58 | }; |
| 59 | |
| 60 | /* Initialize rate adaptation state. */ |
| 61 | void	ieee80211_ra_node_init(struct ieee80211_ra_node *); |
| 62 | |
| 63 | /* |
| 64 | * Drivers report information about 802.11n/HT Tx attempts here. |
| 65 | * mcs: The HT MCS used during this Tx attempt. |
| 66 | * total: How many Tx attempts (initial attempt + any retries) were made? |
| 67 | * fail: How many of these Tx attempts failed? |
| 68 | */ |
| 69 | void	ieee80211_ra_add_stats_ht(struct ieee80211_ra_node *, |
| 70 | 	 struct ieee80211com *, struct ieee80211_node *, |
| 71 | 	 int mcs, unsigned int total, unsigned int fail); |
| 72 | |
| 73 | /* Drivers call this function to update ni->ni_txmcs. */ |
| 74 | void	ieee80211_ra_choose(struct ieee80211_ra_node *, |
| 75 | 	 struct ieee80211com *, struct ieee80211_node *); |
| 76 | |
| 77 | /* Get the HT rateset for a particular HT MCS with 40MHz and/or SGI on/off. */ |
| 78 | const struct ieee80211_ht_rateset * ieee80211_ra_get_ht_rateset(int mcs, |
| 79 | 	 int chan40, int sgi); |
| 80 | |
| 81 | /* Check whether SGI should be used. */ |
| 82 | int ieee80211_ra_use_ht_sgi(struct ieee80211_node *); |