1193326Sed/*-
2193326Sed * Copyright (c) 2004-2008 Sam Leffler, Errno Consulting
3193326Sed * Copyright (c) 2004 Video54 Technologies, Inc.
4193326Sed * All rights reserved.
5193326Sed *
6193326Sed * Redistribution and use in source and binary forms, with or without
7193326Sed * modification, are permitted provided that the following conditions
8193326Sed * are met:
9193326Sed * 1. Redistributions of source code must retain the above copyright
10193326Sed *    notice, this list of conditions and the following disclaimer,
11193326Sed *    without modification.
12193326Sed * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13193326Sed *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14193326Sed *    redistribution must be conditioned upon including a substantially
15193326Sed *    similar Disclaimer requirement for further binary redistribution.
16193326Sed *
17193326Sed * NO WARRANTY
18193326Sed * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19193326Sed * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20193326Sed * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21193326Sed * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22193326Sed * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23193326Sed * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24193326Sed * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25193326Sed * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26193326Sed * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27193326Sed * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28193326Sed * THE POSSIBILITY OF SUCH DAMAGES.
29193326Sed *
30193326Sed * $FreeBSD: releng/10.3/sys/dev/ath/if_athrate.h 249578 2013-04-17 07:21:30Z adrian $
31193326Sed */
32193326Sed#ifndef _ATH_RATECTRL_H_
33193326Sed#define _ATH_RATECTRL_H_
34193326Sed
35193326Sed/*
36193326Sed * Interface definitions for transmit rate control modules for the
37193326Sed * Atheros driver.
38193326Sed *
39193326Sed * A rate control module is responsible for choosing the transmit rate
40193326Sed * for each data frame.  Management+control frames are always sent at
41193326Sed * a fixed rate.
42193326Sed *
43193326Sed * Only one module may be present at a time; the driver references
44193326Sed * rate control interfaces by symbol name.  If multiple modules are
45193326Sed * to be supported we'll need to switch to a registration-based scheme
46193326Sed * as is currently done, for example, for authentication modules.
47193326Sed *
48193326Sed * An instance of the rate control module is attached to each device
49193326Sed * at attach time and detached when the device is destroyed.  The module
50193326Sed * may associate data with each device and each node (station).  Both
51193326Sed * sets of storage are opaque except for the size of the per-node storage
52193326Sed * which must be provided when the module is attached.
53193326Sed *
54193326Sed * The rate control module is notified for each state transition and
55193326Sed * station association/reassociation.  Otherwise it is queried for a
56193326Sed * rate for each outgoing frame and provided status from each transmitted
57193326Sed * frame.  Any ancillary processing is the responsibility of the module
58193326Sed * (e.g. if periodic processing is required then the module should setup
59193326Sed * it's own timer).
60193326Sed *
61193326Sed * In addition to the transmit rate for each frame the module must also
62193326Sed * indicate the number of attempts to make at the specified rate.  If this
63193326Sed * number is != ATH_TXMAXTRY then an additional callback is made to setup
64193326Sed * additional transmit state.  The rate control code is assumed to write
65193326Sed * this additional data directly to the transmit descriptor.
66193326Sed */
67193326Sedstruct ath_softc;
68193326Sedstruct ath_node;
69193326Sedstruct ath_desc;
70193326Sed
71193326Sedstruct ath_ratectrl {
72193326Sed	size_t	arc_space;	/* space required for per-node state */
73193326Sed};
74193326Sed/*
75193326Sed * Attach/detach a rate control module.
76193326Sed */
77193326Sedstruct ath_ratectrl *ath_rate_attach(struct ath_softc *);
78193326Sedvoid	ath_rate_detach(struct ath_ratectrl *);
79193326Sed
80193326Sed#define	ATH_RC_NUM		4
81193326Sed
82193326Sed#define	ATH_RC_DS_FLAG		0x01	/* dual-stream rate */
83193326Sed#define	ATH_RC_CW40_FLAG	0x02	/* use HT40 */
84193326Sed#define	ATH_RC_SGI_FLAG		0x04	/* use short-GI */
85193326Sed#define	ATH_RC_HT_FLAG		0x08	/* use HT */
86193326Sed#define	ATH_RC_RTSCTS_FLAG	0x10	/* enable RTS/CTS protection */
87193326Sed#define	ATH_RC_STBC_FLAG	0x20	/* enable STBC */
88193326Sed#define	ATH_RC_TS_FLAG		0x40	/* triple-stream rate */
89193326Sed
90193326Sedstruct ath_rc_series {
91193326Sed	uint8_t rix;		/* ratetable index, not rate code */
92193326Sed	uint8_t ratecode;	/* hardware rate code */
93193326Sed	uint8_t tries;
94193326Sed	uint8_t tx_power_cap;
95193326Sed	uint16_t flags;
96193326Sed	uint16_t max4msframelen;
97193326Sed};
98193326Sed
99193326Sed/*
100193326Sed * State storage handling.
101193326Sed */
102193326Sed/*
103193326Sed * Initialize per-node state already allocated for the specified
104193326Sed * node; this space can be assumed initialized to zero.
105193326Sed */
106193326Sedvoid	ath_rate_node_init(struct ath_softc *, struct ath_node *);
107193326Sed/*
108193326Sed * Cleanup any per-node state prior to the node being reclaimed.
109193326Sed */
110193326Sedvoid	ath_rate_node_cleanup(struct ath_softc *, struct ath_node *);
111193326Sed/*
112193326Sed * Update rate control state on station associate/reassociate
113193326Sed * (when operating as an ap or for nodes discovered when operating
114193326Sed * in ibss mode).
115193326Sed */
116193326Sedvoid	ath_rate_newassoc(struct ath_softc *, struct ath_node *,
117193326Sed		int isNewAssociation);
118193326Sed
119193326Sed/*
120193326Sed * Transmit handling.
121193326Sed */
122193326Sed/*
123193326Sed * Return the four TX rate index and try counts for the current data packet.
124193326Sed */
125193326Sedvoid	ath_rate_getxtxrates(struct ath_softc *sc, struct ath_node *an,
126193326Sed		uint8_t rix0, struct ath_rc_series *rc);
127193326Sed
128193326Sed/*
129193326Sed * Return the transmit info for a data packet.  If multi-rate state
130193326Sed * is to be setup then try0 should contain a value other than ATH_TXMATRY
131193326Sed * and ath_rate_setupxtxdesc will be called after deciding if the frame
132193326Sed * can be transmitted with multi-rate retry.
133193326Sed */
134193326Sedvoid	ath_rate_findrate(struct ath_softc *, struct ath_node *,
135193326Sed		int shortPreamble, size_t frameLen,
136193326Sed		u_int8_t *rix, int *try0, u_int8_t *txrate);
137193326Sed/*
138193326Sed * Setup any extended (multi-rate) descriptor state for a data packet.
139193326Sed * The rate index returned by ath_rate_findrate is passed back in.
140193326Sed */
141193326Sedvoid	ath_rate_setupxtxdesc(struct ath_softc *, struct ath_node *,
142193326Sed		struct ath_desc *, int shortPreamble, u_int8_t rix);
143193326Sed/*
144193326Sed * Update rate control state for a packet associated with the
145193326Sed * supplied transmit descriptor.  The routine is invoked both
146193326Sed * for packets that were successfully sent and for those that
147193326Sed * failed (consult the descriptor for details).
148193326Sed *
149193326Sed * For A-MPDU frames, nframes and nbad indicate how many frames
150193326Sed * were in the aggregate, and how many failed.
151193326Sed */
152193326Sedstruct ath_buf;
153193326Sedvoid	ath_rate_tx_complete(struct ath_softc *, struct ath_node *,
154193326Sed		const struct ath_rc_series *, const struct ath_tx_status *,
155193326Sed		int pktlen, int nframes, int nbad);
156193326Sed
157193326Sed/*
158193326Sed * Fetch the global rate control statistics.
159193326Sed */
160193326Sedint	ath_rate_fetch_stats(struct ath_softc *sc, struct ath_rateioctl *rs);
161193326Sed
162193326Sed/*
163193326Sed * Fetch the per-node statistics.
164193326Sed */
165193326Sedint	ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an,
166193326Sed		struct ath_rateioctl *rs);
167193326Sed
168193326Sed#endif /* _ATH_RATECTRL_H_ */
169193326Sed