2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 * Copyright (c) 2011 Neratec Solutions AG
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "dfs_debug.h"
25 * TODO: move into or synchronize this with generic header
26 * as soon as IF is defined
28 struct dfs_radar_pulse
{
35 /* internal struct to pass radar data */
36 struct ath_radar_data
{
44 /* convert pulse duration to usecs, considering clock mode */
45 static u32
dur_to_usecs(struct ath_hw
*ah
, u32 dur
)
47 const u32 AR93X_NSECS_PER_DUR
= 800;
48 const u32 AR93X_NSECS_PER_DUR_FAST
= (8000 / 11);
51 if (IS_CHAN_A_FAST_CLOCK(ah
, ah
->curchan
))
52 nsecs
= dur
* AR93X_NSECS_PER_DUR_FAST
;
54 nsecs
= dur
* AR93X_NSECS_PER_DUR
;
56 return (nsecs
+ 500) / 1000;
59 #define PRI_CH_RADAR_FOUND 0x01
60 #define EXT_CH_RADAR_FOUND 0x02
62 ath9k_postprocess_radar_event(struct ath_softc
*sc
,
63 struct ath_radar_data
*are
,
64 struct dfs_radar_pulse
*drp
)
69 ath_dbg(ath9k_hw_common(sc
->sc_ah
), DFS
,
70 "pulse_bw_info=0x%x, pri,ext len/rssi=(%u/%u, %u/%u)\n",
72 are
->pulse_length_pri
, are
->rssi
,
73 are
->pulse_length_ext
, are
->ext_rssi
);
76 * Only the last 2 bits of the BW info are relevant, they indicate
77 * which channel the radar was detected in.
79 are
->pulse_bw_info
&= 0x03;
81 switch (are
->pulse_bw_info
) {
82 case PRI_CH_RADAR_FOUND
:
83 /* radar in ctrl channel */
84 dur
= are
->pulse_length_pri
;
85 DFS_STAT_INC(sc
, pri_phy_errors
);
87 * cannot use ctrl channel RSSI
88 * if extension channel is stronger
90 rssi
= (are
->ext_rssi
>= (are
->rssi
+ 3)) ? 0 : are
->rssi
;
92 case EXT_CH_RADAR_FOUND
:
93 /* radar in extension channel */
94 dur
= are
->pulse_length_ext
;
95 DFS_STAT_INC(sc
, ext_phy_errors
);
97 * cannot use extension channel RSSI
98 * if control channel is stronger
100 rssi
= (are
->rssi
>= (are
->ext_rssi
+ 12)) ? 0 : are
->ext_rssi
;
102 case (PRI_CH_RADAR_FOUND
| EXT_CH_RADAR_FOUND
):
104 * Conducted testing, when pulse is on DC, both pri and ext
105 * durations are reported to be same
107 * Radiated testing, when pulse is on DC, different pri and
108 * ext durations are reported, so take the larger of the two
110 if (are
->pulse_length_ext
>= are
->pulse_length_pri
)
111 dur
= are
->pulse_length_ext
;
113 dur
= are
->pulse_length_pri
;
114 DFS_STAT_INC(sc
, dc_phy_errors
);
116 /* when both are present use stronger one */
117 rssi
= (are
->rssi
< are
->ext_rssi
) ? are
->ext_rssi
: are
->rssi
;
121 * Bogus bandwidth info was received in descriptor,
122 * so ignore this PHY error
124 DFS_STAT_INC(sc
, bwinfo_discards
);
129 DFS_STAT_INC(sc
, rssi_discards
);
134 * TODO: check chirping pulses
135 * checks for chirping are dependent on the DFS regulatory domain
136 * used, which is yet TBD
139 /* convert duration to usecs */
140 drp
->width
= dur_to_usecs(sc
->sc_ah
, dur
);
143 DFS_STAT_INC(sc
, pulses_detected
);
146 #undef PRI_CH_RADAR_FOUND
147 #undef EXT_CH_RADAR_FOUND
150 * DFS: check PHY-error for radar pulse and feed the detector
152 void ath9k_dfs_process_phyerr(struct ath_softc
*sc
, void *data
,
153 struct ath_rx_status
*rs
, u64 mactime
)
155 struct ath_radar_data ard
;
158 struct dfs_radar_pulse drp
;
159 struct ath_hw
*ah
= sc
->sc_ah
;
160 struct ath_common
*common
= ath9k_hw_common(ah
);
162 if ((!(rs
->rs_phyerr
!= ATH9K_PHYERR_RADAR
)) &&
163 (!(rs
->rs_phyerr
!= ATH9K_PHYERR_FALSE_RADAR_EXT
))) {
165 "Error: rs_phyer=0x%x not a radar error\n",
170 datalen
= rs
->rs_datalen
;
172 DFS_STAT_INC(sc
, datalen_discards
);
176 ard
.rssi
= rs
->rs_rssi_ctl0
;
177 ard
.ext_rssi
= rs
->rs_rssi_ext0
;
180 * hardware stores this as 8 bit signed value.
181 * we will cap it at 0 if it is a negative number
185 if (ard
.ext_rssi
& 0x80)
188 vdata_end
= (char *)data
+ datalen
;
189 ard
.pulse_bw_info
= vdata_end
[-1];
190 ard
.pulse_length_ext
= vdata_end
[-2];
191 ard
.pulse_length_pri
= vdata_end
[-3];
194 "bw_info=%d, length_pri=%d, length_ext=%d, "
195 "rssi_pri=%d, rssi_ext=%d\n",
196 ard
.pulse_bw_info
, ard
.pulse_length_pri
, ard
.pulse_length_ext
,
197 ard
.rssi
, ard
.ext_rssi
);
199 drp
.freq
= ah
->curchan
->channel
;
201 if (ath9k_postprocess_radar_event(sc
, &ard
, &drp
)) {
204 "ath9k_dfs_process_phyerr: channel=%d, ts=%llu, "
205 "width=%d, rssi=%d, delta_ts=%llu\n",
206 drp
.freq
, drp
.ts
, drp
.width
, drp
.rssi
, drp
.ts
-last_ts
);
209 * TODO: forward pulse to pattern detector
211 * ieee80211_add_radar_pulse(drp.freq, drp.ts,
212 * drp.width, drp.rssi);