1 #include "wl1251_acx.h"
3 #include <linux/module.h>
4 #include <linux/crc7.h>
5 #include <linux/spi/spi.h>
8 #include "wl12xx_80211.h"
10 #include "wl1251_spi.h"
11 #include "wl1251_ps.h"
13 int wl12xx_acx_frame_rates(struct wl12xx *wl, u8 ctrl_rate, u8 ctrl_mod,
14 u8 mgt_rate, u8 mgt_mod)
16 struct acx_fw_gen_frame_rates *rates;
19 wl12xx_debug(DEBUG_ACX, "acx frame rates");
21 rates = kzalloc(sizeof(*rates), GFP_KERNEL);
27 rates->tx_ctrl_frame_rate = ctrl_rate;
28 rates->tx_ctrl_frame_mod = ctrl_mod;
29 rates->tx_mgt_frame_rate = mgt_rate;
30 rates->tx_mgt_frame_mod = mgt_mod;
32 ret = wl12xx_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
33 rates, sizeof(*rates));
35 wl12xx_error("Failed to set FW rates and modulation");
45 int wl12xx_acx_station_id(struct wl12xx *wl)
47 struct acx_dot11_station_id *mac;
50 wl12xx_debug(DEBUG_ACX, "acx dot11_station_id");
52 mac = kzalloc(sizeof(*mac), GFP_KERNEL);
58 for (i = 0; i < ETH_ALEN; i++)
59 mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
61 ret = wl12xx_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
70 int wl12xx_acx_default_key(struct wl12xx *wl, u8 key_id)
72 struct acx_dot11_default_key *default_key;
75 wl12xx_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
77 default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
83 default_key->id = key_id;
85 ret = wl12xx_cmd_configure(wl, DOT11_DEFAULT_KEY,
86 default_key, sizeof(*default_key));
88 wl12xx_error("Couldnt set default key");
92 wl->default_key = key_id;
99 int wl12xx_acx_wake_up_conditions(struct wl12xx *wl, u8 wake_up_event,
102 struct acx_wake_up_condition *wake_up;
105 wl12xx_debug(DEBUG_ACX, "acx wake up conditions");
107 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
113 wake_up->wake_up_event = wake_up_event;
114 wake_up->listen_interval = listen_interval;
116 ret = wl12xx_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
117 wake_up, sizeof(*wake_up));
119 wl12xx_warning("could not set wake up conditions: %d", ret);
128 int wl12xx_acx_sleep_auth(struct wl12xx *wl, u8 sleep_auth)
130 struct acx_sleep_auth *auth;
133 wl12xx_debug(DEBUG_ACX, "acx sleep auth");
135 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
141 auth->sleep_auth = sleep_auth;
143 ret = wl12xx_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
152 int wl12xx_acx_fw_version(struct wl12xx *wl, char *buf, size_t len)
154 struct acx_revision *rev;
157 wl12xx_debug(DEBUG_ACX, "acx fw rev");
159 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
165 ret = wl12xx_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
167 wl12xx_warning("ACX_FW_REV interrogate failed");
171 /* be careful with the buffer sizes */
172 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
175 * if the firmware version string is exactly
176 * sizeof(rev->fw_version) long or fw_len is less than
177 * sizeof(rev->fw_version) it won't be null terminated
179 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
186 int wl12xx_acx_tx_power(struct wl12xx *wl, int power)
188 struct acx_current_tx_power *acx;
191 wl12xx_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
193 if (power < 0 || power > 25)
196 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
202 acx->current_tx_power = power * 10;
204 ret = wl12xx_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
206 wl12xx_warning("configure of tx power failed: %d", ret);
215 int wl12xx_acx_feature_cfg(struct wl12xx *wl)
217 struct acx_feature_config *feature;
220 wl12xx_debug(DEBUG_ACX, "acx feature cfg");
222 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
228 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
229 feature->data_flow_options = 0;
230 feature->options = 0;
232 ret = wl12xx_cmd_configure(wl, ACX_FEATURE_CFG,
233 feature, sizeof(*feature));
235 wl12xx_error("Couldnt set HW encryption");
244 int wl12xx_acx_mem_map(struct wl12xx *wl, struct acx_header *mem_map,
249 wl12xx_debug(DEBUG_ACX, "acx mem map");
251 ret = wl12xx_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
258 int wl12xx_acx_data_path_params(struct wl12xx *wl,
259 struct acx_data_path_params_resp *resp)
261 struct acx_data_path_params *params;
264 wl12xx_debug(DEBUG_ACX, "acx data path params");
266 params = kzalloc(sizeof(*params), GFP_KERNEL);
272 params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
273 params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
275 params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
276 params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
278 params->tx_complete_threshold = 1;
280 params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
282 params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
284 ret = wl12xx_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
285 params, sizeof(*params));
289 /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
290 ret = wl12xx_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
291 resp, sizeof(*resp));
294 wl12xx_warning("failed to read data path parameters: %d", ret);
296 } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
297 wl12xx_warning("data path parameter acx status failed");
307 int wl12xx_acx_rx_msdu_life_time(struct wl12xx *wl, u32 life_time)
309 struct acx_rx_msdu_lifetime *acx;
312 wl12xx_debug(DEBUG_ACX, "acx rx msdu life time");
314 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
320 acx->lifetime = life_time;
321 ret = wl12xx_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
324 wl12xx_warning("failed to set rx msdu life time: %d", ret);
333 int wl12xx_acx_rx_config(struct wl12xx *wl, u32 config, u32 filter)
335 struct acx_rx_config *rx_config;
338 wl12xx_debug(DEBUG_ACX, "acx rx config");
340 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
346 rx_config->config_options = config;
347 rx_config->filter_options = filter;
349 ret = wl12xx_cmd_configure(wl, ACX_RX_CFG,
350 rx_config, sizeof(*rx_config));
352 wl12xx_warning("failed to set rx config: %d", ret);
361 int wl12xx_acx_pd_threshold(struct wl12xx *wl)
363 struct acx_packet_detection *pd;
366 wl12xx_debug(DEBUG_ACX, "acx data pd threshold");
368 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
374 /* FIXME: threshold value not set */
376 ret = wl12xx_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
378 wl12xx_warning("failed to set pd threshold: %d", ret);
387 int wl12xx_acx_slot(struct wl12xx *wl, enum acx_slot_type slot_time)
389 struct acx_slot *slot;
392 wl12xx_debug(DEBUG_ACX, "acx slot");
394 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
400 slot->wone_index = STATION_WONE_INDEX;
401 slot->slot_time = slot_time;
403 ret = wl12xx_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
405 wl12xx_warning("failed to set slot time: %d", ret);
414 int wl12xx_acx_group_address_tbl(struct wl12xx *wl)
416 struct acx_dot11_grp_addr_tbl *acx;
419 wl12xx_debug(DEBUG_ACX, "acx group address tbl");
421 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
430 memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
432 ret = wl12xx_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
435 wl12xx_warning("failed to set group addr table: %d", ret);
444 int wl12xx_acx_service_period_timeout(struct wl12xx *wl)
446 struct acx_rx_timeout *rx_timeout;
449 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
455 wl12xx_debug(DEBUG_ACX, "acx service period timeout");
457 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
458 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
460 ret = wl12xx_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
461 rx_timeout, sizeof(*rx_timeout));
463 wl12xx_warning("failed to set service period timeout: %d",
473 int wl12xx_acx_rts_threshold(struct wl12xx *wl, u16 rts_threshold)
475 struct acx_rts_threshold *rts;
478 wl12xx_debug(DEBUG_ACX, "acx rts threshold");
480 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
486 rts->threshold = rts_threshold;
488 ret = wl12xx_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
490 wl12xx_warning("failed to set rts threshold: %d", ret);
499 int wl12xx_acx_beacon_filter_opt(struct wl12xx *wl)
501 struct acx_beacon_filter_option *beacon_filter;
504 wl12xx_debug(DEBUG_ACX, "acx beacon filter opt");
506 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
507 if (!beacon_filter) {
512 beacon_filter->enable = 0;
513 beacon_filter->max_num_beacons = 0;
515 ret = wl12xx_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
516 beacon_filter, sizeof(*beacon_filter));
518 wl12xx_warning("failed to set beacon filter opt: %d", ret);
523 kfree(beacon_filter);
527 int wl12xx_acx_beacon_filter_table(struct wl12xx *wl)
529 struct acx_beacon_filter_ie_table *ie_table;
532 wl12xx_debug(DEBUG_ACX, "acx beacon filter table");
534 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
540 ie_table->num_ie = 0;
541 memset(ie_table->table, 0, BEACON_FILTER_TABLE_MAX_SIZE);
543 ret = wl12xx_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
544 ie_table, sizeof(*ie_table));
546 wl12xx_warning("failed to set beacon filter table: %d", ret);
555 int wl12xx_acx_sg_enable(struct wl12xx *wl)
557 struct acx_bt_wlan_coex *pta;
560 wl12xx_debug(DEBUG_ACX, "acx sg enable");
562 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
568 pta->enable = SG_ENABLE;
570 ret = wl12xx_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
572 wl12xx_warning("failed to set softgemini enable: %d", ret);
581 int wl12xx_acx_sg_cfg(struct wl12xx *wl)
583 struct acx_bt_wlan_coex_param *param;
586 wl12xx_debug(DEBUG_ACX, "acx sg cfg");
588 param = kzalloc(sizeof(*param), GFP_KERNEL);
594 /* BT-WLAN coext parameters */
595 param->min_rate = RATE_INDEX_24MBPS;
596 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
597 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
598 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
599 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
600 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
601 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
602 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
603 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
604 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
605 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
606 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
607 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
608 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
609 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
610 param->signal_type = PTA_SIGNALING_TYPE_DEF;
611 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
612 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
613 param->max_cts = PTA_MAX_NUM_CTS_DEF;
614 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
615 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
616 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
617 param->wlan_elp_hp = PTA_ELP_HP_DEF;
618 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
619 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
620 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
621 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
622 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
624 ret = wl12xx_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
626 wl12xx_warning("failed to set sg config: %d", ret);
635 int wl12xx_acx_cca_threshold(struct wl12xx *wl)
637 struct acx_energy_detection *detection;
640 wl12xx_debug(DEBUG_ACX, "acx cca threshold");
642 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
648 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
649 detection->tx_energy_detection = 0;
651 ret = wl12xx_cmd_configure(wl, ACX_CCA_THRESHOLD,
652 detection, sizeof(*detection));
654 wl12xx_warning("failed to set cca threshold: %d", ret);
663 int wl12xx_acx_bcn_dtim_options(struct wl12xx *wl)
665 struct acx_beacon_broadcast *bb;
668 wl12xx_debug(DEBUG_ACX, "acx bcn dtim options");
670 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
676 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
677 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
678 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
679 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
681 ret = wl12xx_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
683 wl12xx_warning("failed to set rx config: %d", ret);
692 int wl12xx_acx_aid(struct wl12xx *wl, u16 aid)
694 struct acx_aid *acx_aid;
697 wl12xx_debug(DEBUG_ACX, "acx aid");
699 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
707 ret = wl12xx_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
709 wl12xx_warning("failed to set aid: %d", ret);
718 int wl12xx_acx_event_mbox_mask(struct wl12xx *wl, u32 event_mask)
720 struct acx_event_mask *mask;
723 wl12xx_debug(DEBUG_ACX, "acx event mbox mask");
725 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
731 /* high event mask is unused */
732 mask->high_event_mask = 0xffffffff;
734 mask->event_mask = event_mask;
736 ret = wl12xx_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
737 mask, sizeof(*mask));
739 wl12xx_warning("failed to set acx_event_mbox_mask: %d", ret);
748 int wl12xx_acx_set_preamble(struct wl12xx *wl, enum acx_preamble_type preamble)
750 struct acx_preamble *acx;
753 wl12xx_debug(DEBUG_ACX, "acx_set_preamble");
755 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
761 acx->preamble = preamble;
763 ret = wl12xx_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
765 wl12xx_warning("Setting of preamble failed: %d", ret);
774 int wl12xx_acx_cts_protect(struct wl12xx *wl,
775 enum acx_ctsprotect_type ctsprotect)
777 struct acx_ctsprotect *acx;
780 wl12xx_debug(DEBUG_ACX, "acx_set_ctsprotect");
782 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
788 acx->ctsprotect = ctsprotect;
790 ret = wl12xx_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
792 wl12xx_warning("Setting of ctsprotect failed: %d", ret);
801 int wl12xx_acx_tsf_info(struct wl12xx *wl, u64 *mactime)
803 struct acx_tsf_info *tsf_info;
806 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
812 ret = wl12xx_cmd_interrogate(wl, ACX_TSF_INFO,
813 tsf_info, sizeof(*tsf_info));
815 wl12xx_warning("ACX_FW_REV interrogate failed");
819 *mactime = tsf_info->current_tsf_lsb |
820 (tsf_info->current_tsf_msb << 31);
827 int wl12xx_acx_statistics(struct wl12xx *wl, struct acx_statistics *stats)
831 wl12xx_debug(DEBUG_ACX, "acx statistics");
833 ret = wl12xx_cmd_interrogate(wl, ACX_STATISTICS, stats,
836 wl12xx_warning("acx statistics failed: %d", ret);