2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
30 #include "wl12xx_80211.h"
33 #define WL18XX_LOGGER_SDIO_BUFF_MAX (0x1020)
34 #define WL18XX_DATA_RAM_BASE_ADDRESS (0x20000000)
35 #define WL18XX_LOGGER_SDIO_BUFF_ADDR (0x40159c)
36 #define WL18XX_LOGGER_BUFF_OFFSET (sizeof(struct fw_logger_information))
37 #define WL18XX_LOGGER_READ_POINT_OFFSET (12)
39 int wlcore_event_fw_logger(struct wl1271
*wl
)
42 struct fw_logger_information fw_log
;
44 u32 internal_fw_addrbase
= WL18XX_DATA_RAM_BASE_ADDRESS
;
45 u32 addr
= WL18XX_LOGGER_SDIO_BUFF_ADDR
;
46 u32 end_buff_addr
= WL18XX_LOGGER_SDIO_BUFF_ADDR
+
47 WL18XX_LOGGER_BUFF_OFFSET
;
54 buffer
= kzalloc(WL18XX_LOGGER_SDIO_BUFF_MAX
, GFP_KERNEL
);
56 wl1271_error("Fail to allocate fw logger memory");
57 fw_log
.actual_buff_size
= cpu_to_le32(0);
61 ret
= wlcore_read(wl
, addr
, buffer
, WL18XX_LOGGER_SDIO_BUFF_MAX
,
64 wl1271_error("Fail to read logger buffer, error_id = %d",
66 fw_log
.actual_buff_size
= cpu_to_le32(0);
70 memcpy(&fw_log
, buffer
, sizeof(fw_log
));
72 if (le32_to_cpu(fw_log
.actual_buff_size
) == 0)
75 actual_len
= le32_to_cpu(fw_log
.actual_buff_size
);
76 start_loc
= (le32_to_cpu(fw_log
.buff_read_ptr
) -
77 internal_fw_addrbase
) - addr
;
78 end_buff_addr
+= le32_to_cpu(fw_log
.max_buff_size
);
79 available_len
= end_buff_addr
-
80 (le32_to_cpu(fw_log
.buff_read_ptr
) -
81 internal_fw_addrbase
);
82 actual_len
= min(actual_len
, available_len
);
85 wl12xx_copy_fwlog(wl
, &buffer
[start_loc
], len
);
86 clear_addr
= addr
+ start_loc
+ le32_to_cpu(fw_log
.actual_buff_size
) +
89 len
= le32_to_cpu(fw_log
.actual_buff_size
) - len
;
92 &buffer
[WL18XX_LOGGER_BUFF_OFFSET
],
94 clear_addr
= addr
+ WL18XX_LOGGER_BUFF_OFFSET
+ len
+
98 /* double check that clear address and write pointer are the same */
99 if (clear_addr
!= le32_to_cpu(fw_log
.buff_write_ptr
)) {
100 wl1271_error("Calculate of clear addr Clear = %x, write = %x",
101 clear_addr
, le32_to_cpu(fw_log
.buff_write_ptr
));
104 /* indicate FW about Clear buffer */
105 ret
= wlcore_write32(wl
, addr
+ WL18XX_LOGGER_READ_POINT_OFFSET
,
106 fw_log
.buff_write_ptr
);
110 return le32_to_cpu(fw_log
.actual_buff_size
);
112 EXPORT_SYMBOL_GPL(wlcore_event_fw_logger
);
114 void wlcore_event_rssi_trigger(struct wl1271
*wl
, s8
*metric_arr
)
116 struct wl12xx_vif
*wlvif
;
117 struct ieee80211_vif
*vif
;
118 enum nl80211_cqm_rssi_threshold_event event
;
119 s8 metric
= metric_arr
[0];
121 wl1271_debug(DEBUG_EVENT
, "RSSI trigger metric: %d", metric
);
123 /* TODO: check actual multi-role support */
124 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
125 if (metric
<= wlvif
->rssi_thold
)
126 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
;
128 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
;
130 vif
= wl12xx_wlvif_to_vif(wlvif
);
131 if (event
!= wlvif
->last_rssi_event
)
132 ieee80211_cqm_rssi_notify(vif
, event
, GFP_KERNEL
);
133 wlvif
->last_rssi_event
= event
;
136 EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger
);
138 static void wl1271_stop_ba_event(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
140 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
142 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
143 u8 hlid
= wlvif
->sta
.hlid
;
144 if (!wl
->links
[hlid
].ba_bitmap
)
146 ieee80211_stop_rx_ba_session(vif
, wl
->links
[hlid
].ba_bitmap
,
147 vif
->bss_conf
.bssid
);
150 struct wl1271_link
*lnk
;
151 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
,
153 lnk
= &wl
->links
[hlid
];
157 ieee80211_stop_rx_ba_session(vif
,
164 void wlcore_event_soft_gemini_sense(struct wl1271
*wl
, u8 enable
)
166 struct wl12xx_vif
*wlvif
;
169 set_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
171 clear_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
172 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
173 wl1271_recalc_rx_streaming(wl
, wlvif
);
177 EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense
);
179 void wlcore_event_sched_scan_completed(struct wl1271
*wl
,
182 wl1271_debug(DEBUG_EVENT
, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
186 ieee80211_sched_scan_stopped(wl
->hw
);
187 wl
->sched_vif
= NULL
;
190 EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed
);
192 void wlcore_event_ba_rx_constraint(struct wl1271
*wl
,
193 unsigned long roles_bitmap
,
194 unsigned long allowed_bitmap
)
196 struct wl12xx_vif
*wlvif
;
198 wl1271_debug(DEBUG_EVENT
, "%s: roles=0x%lx allowed=0x%lx",
199 __func__
, roles_bitmap
, allowed_bitmap
);
201 wl12xx_for_each_wlvif(wl
, wlvif
) {
202 if (wlvif
->role_id
== WL12XX_INVALID_ROLE_ID
||
203 !test_bit(wlvif
->role_id
, &roles_bitmap
))
206 wlvif
->ba_allowed
= !!test_bit(wlvif
->role_id
,
208 if (!wlvif
->ba_allowed
)
209 wl1271_stop_ba_event(wl
, wlvif
);
212 EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint
);
214 void wlcore_event_channel_switch(struct wl1271
*wl
,
215 unsigned long roles_bitmap
,
218 struct wl12xx_vif
*wlvif
;
219 struct ieee80211_vif
*vif
;
221 wl1271_debug(DEBUG_EVENT
, "%s: roles=0x%lx success=%d",
222 __func__
, roles_bitmap
, success
);
224 wl12xx_for_each_wlvif(wl
, wlvif
) {
225 if (wlvif
->role_id
== WL12XX_INVALID_ROLE_ID
||
226 !test_bit(wlvif
->role_id
, &roles_bitmap
))
229 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
,
233 vif
= wl12xx_wlvif_to_vif(wlvif
);
235 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
236 ieee80211_chswitch_done(vif
, success
);
237 cancel_delayed_work(&wlvif
->channel_switch_work
);
239 set_bit(WLVIF_FLAG_BEACON_DISABLED
, &wlvif
->flags
);
240 ieee80211_csa_finish(vif
);
244 EXPORT_SYMBOL_GPL(wlcore_event_channel_switch
);
246 void wlcore_event_dummy_packet(struct wl1271
*wl
)
249 wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
253 wl1271_debug(DEBUG_EVENT
, "DUMMY_PACKET_ID_EVENT_ID");
254 wl1271_tx_dummy_packet(wl
);
256 EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet
);
258 static void wlcore_disconnect_sta(struct wl1271
*wl
, unsigned long sta_bitmap
)
260 u32 num_packets
= wl
->conf
.tx
.max_tx_retries
;
261 struct wl12xx_vif
*wlvif
;
262 struct ieee80211_vif
*vif
;
263 struct ieee80211_sta
*sta
;
267 for_each_set_bit(h
, &sta_bitmap
, wl
->num_links
) {
269 /* find the ap vif connected to this sta */
270 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
271 if (!test_bit(h
, wlvif
->ap
.sta_hlid_map
))
279 vif
= wl12xx_wlvif_to_vif(wlvif
);
280 addr
= wl
->links
[h
].addr
;
283 sta
= ieee80211_find_sta(vif
, addr
);
285 wl1271_debug(DEBUG_EVENT
, "remove sta %d", h
);
286 ieee80211_report_low_ack(sta
, num_packets
);
292 void wlcore_event_max_tx_failure(struct wl1271
*wl
, unsigned long sta_bitmap
)
294 wl1271_debug(DEBUG_EVENT
, "MAX_TX_FAILURE_EVENT_ID");
295 wlcore_disconnect_sta(wl
, sta_bitmap
);
297 EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure
);
299 void wlcore_event_inactive_sta(struct wl1271
*wl
, unsigned long sta_bitmap
)
301 wl1271_debug(DEBUG_EVENT
, "INACTIVE_STA_EVENT_ID");
302 wlcore_disconnect_sta(wl
, sta_bitmap
);
304 EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta
);
306 void wlcore_event_roc_complete(struct wl1271
*wl
)
308 wl1271_debug(DEBUG_EVENT
, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
310 ieee80211_ready_on_channel(wl
->hw
);
312 EXPORT_SYMBOL_GPL(wlcore_event_roc_complete
);
314 void wlcore_event_beacon_loss(struct wl1271
*wl
, unsigned long roles_bitmap
)
317 * We are HW_MONITOR device. On beacon loss - queue
318 * connection loss work. Cancel it on REGAINED event.
320 struct wl12xx_vif
*wlvif
;
321 struct ieee80211_vif
*vif
;
322 int delay
= wl
->conf
.conn
.synch_fail_thold
*
323 wl
->conf
.conn
.bss_lose_timeout
;
325 wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap
);
327 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
328 if (wlvif
->role_id
== WL12XX_INVALID_ROLE_ID
||
329 !test_bit(wlvif
->role_id
, &roles_bitmap
))
332 vif
= wl12xx_wlvif_to_vif(wlvif
);
334 /* don't attempt roaming in case of p2p */
336 ieee80211_connection_loss(vif
);
341 * if the work is already queued, it should take place.
342 * We don't want to delay the connection loss
343 * indication any more.
345 ieee80211_queue_delayed_work(wl
->hw
,
346 &wlvif
->connection_loss_work
,
347 msecs_to_jiffies(delay
));
349 ieee80211_cqm_beacon_loss_notify(vif
, GFP_KERNEL
);
352 EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss
);
354 int wl1271_event_unmask(struct wl1271
*wl
)
358 wl1271_debug(DEBUG_EVENT
, "unmasking event_mask 0x%x", wl
->event_mask
);
359 ret
= wl1271_acx_event_mbox_mask(wl
, ~(wl
->event_mask
));
366 int wl1271_event_handle(struct wl1271
*wl
, u8 mbox_num
)
370 wl1271_debug(DEBUG_EVENT
, "EVENT on mbox %d", mbox_num
);
375 /* first we read the mbox descriptor */
376 ret
= wlcore_read(wl
, wl
->mbox_ptr
[mbox_num
], wl
->mbox
,
377 wl
->mbox_size
, false);
381 /* process the descriptor */
382 ret
= wl
->ops
->process_mailbox_events(wl
);
387 * TODO: we just need this because one bit is in a different
388 * place. Is there any better way?
390 ret
= wl
->ops
->ack_event(wl
);