if_athrate.h revision 238632
1138570Ssam/*- 2178354Ssam * Copyright (c) 2004-2008 Sam Leffler, Errno Consulting 3138570Ssam * Copyright (c) 2004 Video54 Technologies, Inc. 4138570Ssam * All rights reserved. 5138570Ssam * 6138570Ssam * Redistribution and use in source and binary forms, with or without 7138570Ssam * modification, are permitted provided that the following conditions 8138570Ssam * are met: 9138570Ssam * 1. Redistributions of source code must retain the above copyright 10138570Ssam * notice, this list of conditions and the following disclaimer, 11170375Ssam * without modification. 12138570Ssam * 2. Redistributions in binary form must reproduce at minimum a disclaimer 13138570Ssam * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 14138570Ssam * redistribution must be conditioned upon including a substantially 15138570Ssam * similar Disclaimer requirement for further binary redistribution. 16138570Ssam * 17138570Ssam * NO WARRANTY 18138570Ssam * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19138570Ssam * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20138570Ssam * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 21138570Ssam * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22138570Ssam * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 23138570Ssam * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24138570Ssam * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25138570Ssam * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26138570Ssam * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27138570Ssam * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28138570Ssam * THE POSSIBILITY OF SUCH DAMAGES. 29138570Ssam * 30138570Ssam * $FreeBSD: head/sys/dev/ath/if_athrate.h 238632 2012-07-20 01:27:20Z adrian $ 31138570Ssam */ 32138570Ssam#ifndef _ATH_RATECTRL_H_ 33138570Ssam#define _ATH_RATECTRL_H_ 34138570Ssam 35138570Ssam/* 36138570Ssam * Interface definitions for transmit rate control modules for the 37138570Ssam * Atheros driver. 38138570Ssam * 39138570Ssam * A rate control module is responsible for choosing the transmit rate 40138570Ssam * for each data frame. Management+control frames are always sent at 41138570Ssam * a fixed rate. 42138570Ssam * 43138570Ssam * Only one module may be present at a time; the driver references 44138570Ssam * rate control interfaces by symbol name. If multiple modules are 45138570Ssam * to be supported we'll need to switch to a registration-based scheme 46138570Ssam * as is currently done, for example, for authentication modules. 47138570Ssam * 48138570Ssam * An instance of the rate control module is attached to each device 49138570Ssam * at attach time and detached when the device is destroyed. The module 50138570Ssam * may associate data with each device and each node (station). Both 51138570Ssam * sets of storage are opaque except for the size of the per-node storage 52138570Ssam * which must be provided when the module is attached. 53138570Ssam * 54138570Ssam * The rate control module is notified for each state transition and 55138570Ssam * station association/reassociation. Otherwise it is queried for a 56138570Ssam * rate for each outgoing frame and provided status from each transmitted 57138570Ssam * frame. Any ancillary processing is the responsibility of the module 58138570Ssam * (e.g. if periodic processing is required then the module should setup 59138570Ssam * it's own timer). 60138570Ssam * 61138570Ssam * In addition to the transmit rate for each frame the module must also 62138570Ssam * indicate the number of attempts to make at the specified rate. If this 63138570Ssam * number is != ATH_TXMAXTRY then an additional callback is made to setup 64138570Ssam * additional transmit state. The rate control code is assumed to write 65138570Ssam * this additional data directly to the transmit descriptor. 66138570Ssam */ 67138570Ssamstruct ath_softc; 68138570Ssamstruct ath_node; 69138570Ssamstruct ath_desc; 70138570Ssam 71138570Ssamstruct ath_ratectrl { 72138570Ssam size_t arc_space; /* space required for per-node state */ 73138570Ssam}; 74138570Ssam/* 75138570Ssam * Attach/detach a rate control module. 76138570Ssam */ 77138570Ssamstruct ath_ratectrl *ath_rate_attach(struct ath_softc *); 78138570Ssamvoid ath_rate_detach(struct ath_ratectrl *); 79138570Ssam 80227326Sadrian#define ATH_RC_NUM 4 81138570Ssam 82227326Sadrian#define ATH_RC_DS_FLAG 0x01 /* dual-stream rate */ 83227326Sadrian#define ATH_RC_CW40_FLAG 0x02 /* use HT40 */ 84227326Sadrian#define ATH_RC_SGI_FLAG 0x04 /* use short-GI */ 85227326Sadrian#define ATH_RC_HT_FLAG 0x08 /* use HT */ 86227326Sadrian#define ATH_RC_RTSCTS_FLAG 0x10 /* enable RTS/CTS protection */ 87227326Sadrian 88227326Sadrianstruct ath_rc_series { 89227326Sadrian uint8_t rix; /* ratetable index, not rate code */ 90227326Sadrian uint8_t ratecode; /* hardware rate code */ 91227326Sadrian uint8_t tries; 92227326Sadrian uint8_t flags; 93227326Sadrian uint32_t max4msframelen; 94227326Sadrian}; 95227326Sadrian 96138570Ssam/* 97138570Ssam * State storage handling. 98138570Ssam */ 99138570Ssam/* 100138570Ssam * Initialize per-node state already allocated for the specified 101138570Ssam * node; this space can be assumed initialized to zero. 102138570Ssam */ 103138570Ssamvoid ath_rate_node_init(struct ath_softc *, struct ath_node *); 104138570Ssam/* 105138570Ssam * Cleanup any per-node state prior to the node being reclaimed. 106138570Ssam */ 107138570Ssamvoid ath_rate_node_cleanup(struct ath_softc *, struct ath_node *); 108138570Ssam/* 109138570Ssam * Update rate control state on station associate/reassociate 110138570Ssam * (when operating as an ap or for nodes discovered when operating 111138570Ssam * in ibss mode). 112138570Ssam */ 113138570Ssamvoid ath_rate_newassoc(struct ath_softc *, struct ath_node *, 114138570Ssam int isNewAssociation); 115138570Ssam 116138570Ssam/* 117138570Ssam * Transmit handling. 118138570Ssam */ 119138570Ssam/* 120218160Sadrian * Return the four TX rate index and try counts for the current data packet. 121218160Sadrian */ 122218160Sadrianvoid ath_rate_getxtxrates(struct ath_softc *sc, struct ath_node *an, 123227364Sadrian uint8_t rix0, struct ath_rc_series *rc); 124218160Sadrian 125218160Sadrian/* 126138570Ssam * Return the transmit info for a data packet. If multi-rate state 127138570Ssam * is to be setup then try0 should contain a value other than ATH_TXMATRY 128138570Ssam * and ath_rate_setupxtxdesc will be called after deciding if the frame 129138570Ssam * can be transmitted with multi-rate retry. 130138570Ssam */ 131138570Ssamvoid ath_rate_findrate(struct ath_softc *, struct ath_node *, 132144546Ssam int shortPreamble, size_t frameLen, 133138570Ssam u_int8_t *rix, int *try0, u_int8_t *txrate); 134138570Ssam/* 135138570Ssam * Setup any extended (multi-rate) descriptor state for a data packet. 136138570Ssam * The rate index returned by ath_rate_findrate is passed back in. 137138570Ssam */ 138138570Ssamvoid ath_rate_setupxtxdesc(struct ath_softc *, struct ath_node *, 139144546Ssam struct ath_desc *, int shortPreamble, u_int8_t rix); 140138570Ssam/* 141138570Ssam * Update rate control state for a packet associated with the 142138570Ssam * supplied transmit descriptor. The routine is invoked both 143138570Ssam * for packets that were successfully sent and for those that 144138570Ssam * failed (consult the descriptor for details). 145227364Sadrian * 146227364Sadrian * For A-MPDU frames, nframes and nbad indicate how many frames 147227364Sadrian * were in the aggregate, and how many failed. 148138570Ssam */ 149165185Ssamstruct ath_buf; 150138570Ssamvoid ath_rate_tx_complete(struct ath_softc *, struct ath_node *, 151227364Sadrian const struct ath_rc_series *, const struct ath_tx_status *, 152227364Sadrian int pktlen, int nframes, int nbad); 153238632Sadrian 154238632Sadrian/* 155238632Sadrian * Fetch the global rate control statistics. 156238632Sadrian */ 157238632Sadrianint ath_rate_fetch_stats(struct ath_softc *sc, struct ath_rateioctl *rs); 158238632Sadrian 159238632Sadrian/* 160238632Sadrian * Fetch the per-node statistics. 161238632Sadrian */ 162238632Sadrianint ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an, 163238632Sadrian struct ath_rateioctl *rs); 164238632Sadrian 165138570Ssam#endif /* _ATH_RATECTRL_H_ */ 166