Staging: otus: logical/bit and confusion
[deliverable/linux.git] / drivers / staging / otus / 80211core / cwm.c
CommitLineData
4bd43f50
LR
1/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/* */
17/* Module Name : cwm.c */
18/* */
19/* Abstract */
20/* This module contains channel width related functions. */
21/* */
22/* NOTES */
23/* None */
24/* */
25/************************************************************************/
26
27#include "cprecomp.h"
28
29
30
31void zfCwmInit(zdev_t* dev) {
32 //u16_t i;
33 zmw_get_wlan_dev(dev);
34
35 switch (wd->wlanMode) {
36 case ZM_MODE_AP:
37 wd->cwm.cw_mode = CWM_MODE2040;
38 wd->cwm.cw_width = CWM_WIDTH40;
39 wd->cwm.cw_enable = 1;
40 break;
41 case ZM_MODE_INFRASTRUCTURE:
42 case ZM_MODE_PSEUDO:
43 case ZM_MODE_IBSS:
44 default:
45 wd->cwm.cw_mode = CWM_MODE2040;
46 wd->cwm.cw_width = CWM_WIDTH20;
47 wd->cwm.cw_enable = 1;
48 break;
49 }
50}
51
52
53void zfCoreCwmBusy(zdev_t* dev, u16_t busy)
54{
55
56 zmw_get_wlan_dev(dev);
57
58 zm_msg1_mm(ZM_LV_0, "CwmBusy=", busy);
59
60 if(wd->cwm.cw_mode == CWM_MODE20) {
61 wd->cwm.cw_width = CWM_WIDTH20;
62 return;
63 }
64
65 if(wd->cwm.cw_mode == CWM_MODE40) {
66 wd->cwm.cw_width = CWM_WIDTH40;
67 return;
68 }
69
70 if (busy) {
71 wd->cwm.cw_width = CWM_WIDTH20;
72 return;
73 }
74
75
76 if((wd->wlanMode == ZM_MODE_INFRASTRUCTURE || wd->wlanMode == ZM_MODE_PSEUDO ||
77 wd->wlanMode == ZM_MODE_IBSS)) {
1472dc9b
RK
78 if ((wd->sta.ie.HtCap.HtCapInfo & HTCAP_SupChannelWidthSet) &&
79 (wd->sta.ie.HtInfo.ChannelInfo & ExtHtCap_RecomTxWidthSet) &&
80 (wd->sta.ie.HtInfo.ChannelInfo & ExtHtCap_ExtChannelOffsetAbove)) {
4bd43f50
LR
81
82 wd->cwm.cw_width = CWM_WIDTH40;
83 }
84 else {
85 wd->cwm.cw_width = CWM_WIDTH20;
86 }
87
88 return;
89 }
90
91 if(wd->wlanMode == ZM_MODE_AP) {
92 wd->cwm.cw_width = CWM_WIDTH40;
93 }
94
95}
96
97
98
99
100u16_t zfCwmIsExtChanBusy(u32_t ctlBusy, u32_t extBusy)
101{
102 u32_t busy; /* percentage */
103 u32_t cycleTime, ctlClear;
104
105 cycleTime = 1280000; //1.28 seconds
106
107 if (cycleTime > ctlBusy) {
108 ctlClear = cycleTime - ctlBusy;
109 }
110 else
111 {
112 ctlClear = 0;
113 }
114
115 /* Compute ratio of extension channel busy to control channel clear
116 * as an approximation to extension channel cleanliness.
117 *
118 * According to the hardware folks, ext rxclear is undefined
119 * if the ctrl rxclear is de-asserted (i.e. busy)
120 */
121 if (ctlClear) {
122 busy = (extBusy * 100) / ctlClear;
123 } else {
124 busy = 0;
125 }
126 if (busy > ATH_CWM_EXTCH_BUSY_THRESHOLD) {
127 return TRUE;
128 }
129
130 return FALSE;
131}
This page took 0.065316 seconds and 5 git commands to generate.