1fa20c234SSam Leffler /*- 2fa20c234SSam Leffler * Copyright (c) 2005 John Bicket 3fa20c234SSam Leffler * All rights reserved. 4fa20c234SSam Leffler * 5fa20c234SSam Leffler * Redistribution and use in source and binary forms, with or without 6fa20c234SSam Leffler * modification, are permitted provided that the following conditions 7fa20c234SSam Leffler * are met: 8fa20c234SSam Leffler * 1. Redistributions of source code must retain the above copyright 9fa20c234SSam Leffler * notice, this list of conditions and the following disclaimer, 10fa20c234SSam Leffler * without modification. 11fa20c234SSam Leffler * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12fa20c234SSam Leffler * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13fa20c234SSam Leffler * redistribution must be conditioned upon including a substantially 14fa20c234SSam Leffler * similar Disclaimer requirement for further binary redistribution. 15fa20c234SSam Leffler * 3. Neither the names of the above-listed copyright holders nor the names 16fa20c234SSam Leffler * of any contributors may be used to endorse or promote products derived 17fa20c234SSam Leffler * from this software without specific prior written permission. 18fa20c234SSam Leffler * 19fa20c234SSam Leffler * Alternatively, this software may be distributed under the terms of the 20fa20c234SSam Leffler * GNU General Public License ("GPL") version 2 as published by the Free 21fa20c234SSam Leffler * Software Foundation. 22fa20c234SSam Leffler * 23fa20c234SSam Leffler * NO WARRANTY 24fa20c234SSam Leffler * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25fa20c234SSam Leffler * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26fa20c234SSam Leffler * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 27fa20c234SSam Leffler * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 28fa20c234SSam Leffler * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 29fa20c234SSam Leffler * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30fa20c234SSam Leffler * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31fa20c234SSam Leffler * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 32fa20c234SSam Leffler * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33fa20c234SSam Leffler * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 34fa20c234SSam Leffler * THE POSSIBILITY OF SUCH DAMAGES. 35fa20c234SSam Leffler * 36fa20c234SSam Leffler * $FreeBSD$ 37fa20c234SSam Leffler */ 38fa20c234SSam Leffler 39fa20c234SSam Leffler /* 40fa20c234SSam Leffler * Defintions for the Atheros Wireless LAN controller driver. 41fa20c234SSam Leffler */ 42fa20c234SSam Leffler #ifndef _DEV_ATH_RATE_SAMPLE_H 43fa20c234SSam Leffler #define _DEV_ATH_RATE_SAMPLE_H 44fa20c234SSam Leffler 45fa20c234SSam Leffler /* per-device state */ 46fa20c234SSam Leffler struct sample_softc { 47fa20c234SSam Leffler struct ath_ratectrl arc; /* base state */ 48fa20c234SSam Leffler int ath_smoothing_rate; /* ewma percentage (out of 100) */ 49fa20c234SSam Leffler int ath_sample_rate; /* send a different bit-rate 1/X packets */ 50fa20c234SSam Leffler }; 51fa20c234SSam Leffler #define ATH_SOFTC_SAMPLE(sc) ((struct sample_softc *)sc->sc_rc) 52fa20c234SSam Leffler 53fa20c234SSam Leffler struct rate_info { 54fa20c234SSam Leffler int rate; 55fa20c234SSam Leffler int rix; 56fa20c234SSam Leffler int rateCode; 57fa20c234SSam Leffler int shortPreambleRateCode; 58fa20c234SSam Leffler }; 59fa20c234SSam Leffler 60fa20c234SSam Leffler 61fa20c234SSam Leffler struct rate_stats { 62fa20c234SSam Leffler int average_tx_time; 63fa20c234SSam Leffler int successive_failures; 64fa20c234SSam Leffler int tries; 65fa20c234SSam Leffler int total_packets; 66fa20c234SSam Leffler int packets_acked; 67fa20c234SSam Leffler int perfect_tx_time; /* transmit time for 0 retries */ 68fa20c234SSam Leffler int last_tx; 69fa20c234SSam Leffler }; 70fa20c234SSam Leffler 71fa20c234SSam Leffler /* 72fa20c234SSam Leffler * for now, we track performance for three different packet 73fa20c234SSam Leffler * size buckets 74fa20c234SSam Leffler */ 75fa20c234SSam Leffler #define NUM_PACKET_SIZE_BINS 3 76fa20c234SSam Leffler static int packet_size_bins[NUM_PACKET_SIZE_BINS] = {250, 1600, 3000}; 77fa20c234SSam Leffler 78fa20c234SSam Leffler /* per-node state */ 79fa20c234SSam Leffler struct sample_node { 80fa20c234SSam Leffler int static_rate_ndx; 81fa20c234SSam Leffler int num_rates; 82fa20c234SSam Leffler 83fa20c234SSam Leffler struct rate_info rates[IEEE80211_RATE_MAXSIZE]; 84fa20c234SSam Leffler 85fa20c234SSam Leffler struct rate_stats stats[NUM_PACKET_SIZE_BINS][IEEE80211_RATE_MAXSIZE]; 86fa20c234SSam Leffler int sample_num[NUM_PACKET_SIZE_BINS]; 87fa20c234SSam Leffler int packets_sent[NUM_PACKET_SIZE_BINS]; 88fa20c234SSam Leffler 89fa20c234SSam Leffler }; 90fa20c234SSam Leffler #define ATH_NODE_SAMPLE(an) ((struct sample_node *)&an[1]) 91fa20c234SSam Leffler 92fa20c234SSam Leffler #ifndef MIN 93fa20c234SSam Leffler #define MIN(a,b) ((a) < (b) ? (a) : (b)) 94fa20c234SSam Leffler #endif 95fa20c234SSam Leffler #ifndef MAX 96fa20c234SSam Leffler #define MAX(a,b) ((a) > (b) ? (a) : (b)) 97fa20c234SSam Leffler #endif 98fa20c234SSam Leffler 99fa20c234SSam Leffler #define WIFI_CW_MIN 31 100fa20c234SSam Leffler #define WIFI_CW_MAX 1023 101fa20c234SSam Leffler 102fa20c234SSam Leffler /* 103fa20c234SSam Leffler * Calculate the transmit duration of a frame. 104fa20c234SSam Leffler */ 105fa20c234SSam Leffler static unsigned calc_usecs_unicast_packet(struct ath_softc *sc, 106fa20c234SSam Leffler int length, 107fa20c234SSam Leffler int rix, int retries) { 108fa20c234SSam Leffler const HAL_RATE_TABLE *rt = sc->sc_currates; 109fa20c234SSam Leffler 110fa20c234SSam Leffler 111fa20c234SSam Leffler /* pg 205 ieee.802.11.pdf */ 112fa20c234SSam Leffler unsigned t_slot = 20; 113fa20c234SSam Leffler unsigned t_difs = 50; 114fa20c234SSam Leffler unsigned t_sifs = 10; 115fa20c234SSam Leffler int tt = 0; 116fa20c234SSam Leffler int x = 0; 117fa20c234SSam Leffler int cw = WIFI_CW_MIN; 118fa20c234SSam Leffler int cix = rt->info[rix].controlRate; 119fa20c234SSam Leffler KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); 120fa20c234SSam Leffler 121fa20c234SSam Leffler if (rt->info[rix].phy == IEEE80211_T_OFDM) { 122fa20c234SSam Leffler t_slot = 9; 123fa20c234SSam Leffler t_sifs = 9; 124fa20c234SSam Leffler t_difs = 28; 125fa20c234SSam Leffler } 126fa20c234SSam Leffler tt += t_difs; 127fa20c234SSam Leffler tt += (retries+1)*(t_sifs + rt->info[cix].spAckDuration); 128fa20c234SSam Leffler tt += (retries+1)*ath_hal_computetxtime(sc->sc_ah, rt, length, 129fa20c234SSam Leffler rix, AH_TRUE); 130fa20c234SSam Leffler for (x = 0; x <= retries; x++) { 131fa20c234SSam Leffler cw = MIN(WIFI_CW_MAX, (cw + 1) * 2); 132fa20c234SSam Leffler tt += (t_slot * cw/2); 133fa20c234SSam Leffler } 134fa20c234SSam Leffler return tt; 135fa20c234SSam Leffler } 136fa20c234SSam Leffler #endif /* _DEV_ATH_RATE_SAMPLE_H */ 137