aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00.h
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2007-10-13 10:26:36 -0400
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:02:53 -0500
commit69f81a2cac860cf183eb9ef7787525c3552d4612 (patch)
treeb149e55f1e21df8edf33046e662ce8f00834f1ac /drivers/net/wireless/rt2x00/rt2x00.h
parent8de8c5162b157884aa4855564cbfd9ec9119c819 (diff)
[PATCH] rt2x00: Implement SW diversity
When mac80211 indicates that the default antenna setup should be used _and_ that this default setup is SW_DIVERSITY. This requires sampling and storing the RSSI per antenna and check once every 2 seconds to determine if the RSSI has changed significantly. Once this is the case we should sample the other antenna for a short period and evaluate if we need to swap antenna or not. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2x00.h')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h87
1 files changed, 72 insertions, 15 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index d6f0a72b7a0c..e7533e2ccd2e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -241,6 +241,43 @@ struct link_qual {
241}; 241};
242 242
243/* 243/*
244 * Antenna settings about the currently active link.
245 */
246struct link_ant {
247 /*
248 * Antenna flags
249 */
250 unsigned int flags;
251#define ANTENNA_RX_DIVERSITY 0x00000001
252#define ANTENNA_TX_DIVERSITY 0x00000002
253#define ANTENNA_MODE_SAMPLE 0x00000004
254
255 /*
256 * Currently active TX/RX antenna setup.
257 * When software diversity is used, this will indicate
258 * which antenna is actually used at this time.
259 */
260 struct antenna_setup active;
261
262 /*
263 * RSSI information for the different antenna's.
264 * These statistics are used to determine when
265 * to switch antenna when using software diversity.
266 *
267 * rssi[0] -> Antenna A RSSI
268 * rssi[1] -> Antenna B RSSI
269 */
270 int rssi_history[2];
271
272 /*
273 * Current RSSI average of the currently active antenna.
274 * Similar to the avg_rssi in the link_qual structure
275 * this value is updated by using the walking average.
276 */
277 int rssi_ant;
278};
279
280/*
244 * To optimize the quality of the link we need to store 281 * To optimize the quality of the link we need to store
245 * the quality of received frames and periodically 282 * the quality of received frames and periodically
246 * optimize the link. 283 * optimize the link.
@@ -259,11 +296,9 @@ struct link {
259 struct link_qual qual; 296 struct link_qual qual;
260 297
261 /* 298 /*
262 * Currently active TX/RX antenna setup. 299 * TX/RX antenna setup.
263 * When software diversity is used, this will indicate
264 * which antenna is actually used at this time.
265 */ 300 */
266 struct antenna_setup active_ant; 301 struct link_ant ant;
267 302
268 /* 303 /*
269 * Active VGC level 304 * Active VGC level
@@ -277,25 +312,47 @@ struct link {
277}; 312};
278 313
279/* 314/*
280 * Update the rssi using the walking average approach. 315 * Small helper macro to work with moving/walking averages.
281 */ 316 */
282static inline void rt2x00_update_link_rssi(struct link *link, int rssi) 317#define MOVING_AVERAGE(__avg, __val, __samples) \
283{ 318 ( (((__avg) * ((__samples) - 1)) + (__val)) / (__samples) )
284 if (link->qual.avg_rssi) 319
285 rssi = ((link->qual.avg_rssi * 7) + rssi) / 8; 320/*
286 link->qual.avg_rssi = rssi; 321 * When we lack RSSI information return something less then -80 to
287} 322 * tell the driver to tune the device to maximum sensitivity.
323 */
324#define DEFAULT_RSSI ( -128 )
288 325
289/* 326/*
290 * When the avg_rssi is unset or no frames have been received), 327 * Link quality access functions.
291 * we need to return the default value which needs to be less
292 * than -80 so the device will select the maximum sensitivity.
293 */ 328 */
294static inline int rt2x00_get_link_rssi(struct link *link) 329static inline int rt2x00_get_link_rssi(struct link *link)
295{ 330{
296 if (link->qual.avg_rssi && link->qual.rx_success) 331 if (link->qual.avg_rssi && link->qual.rx_success)
297 return link->qual.avg_rssi; 332 return link->qual.avg_rssi;
298 return -128; 333 return DEFAULT_RSSI;
334}
335
336static inline int rt2x00_get_link_ant_rssi(struct link *link)
337{
338 if (link->ant.rssi_ant && link->qual.rx_success)
339 return link->ant.rssi_ant;
340 return DEFAULT_RSSI;
341}
342
343static inline int rt2x00_get_link_ant_rssi_history(struct link *link,
344 enum antenna ant)
345{
346 if (link->ant.rssi_history[ant - ANTENNA_A])
347 return link->ant.rssi_history[ant - ANTENNA_A];
348 return DEFAULT_RSSI;
349}
350
351static inline int rt2x00_update_ant_rssi(struct link *link, int rssi)
352{
353 int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A];
354 link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi;
355 return old_rssi;
299} 356}
300 357
301/* 358/*