Lines Matching refs:wl

32 void wl1251_enable_interrupts(struct wl1251 *wl)
34 wl->if_ops->enable_irq(wl);
37 void wl1251_disable_interrupts(struct wl1251 *wl)
39 wl->if_ops->disable_irq(wl);
42 static int wl1251_power_off(struct wl1251 *wl)
44 return wl->if_ops->power(wl, false);
47 static int wl1251_power_on(struct wl1251 *wl)
49 return wl->if_ops->power(wl, true);
52 static int wl1251_fetch_firmware(struct wl1251 *wl)
55 struct device *dev = wiphy_dev(wl->hw->wiphy);
72 wl->fw_len = fw->size;
73 wl->fw = vmalloc(wl->fw_len);
75 if (!wl->fw) {
81 memcpy(wl->fw, fw->data, wl->fw_len);
91 static int wl1251_fetch_nvs(struct wl1251 *wl)
94 struct device *dev = wiphy_dev(wl->hw->wiphy);
111 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
113 if (!wl->nvs) {
119 wl->nvs_len = fw->size;
129 static void wl1251_fw_wakeup(struct wl1251 *wl)
134 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
135 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
141 static int wl1251_chip_wakeup(struct wl1251 *wl)
145 ret = wl1251_power_on(wl);
150 wl->if_ops->reset(wl);
154 wl1251_set_partition(wl,
161 wl1251_fw_wakeup(wl);
166 wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
170 switch (wl->chip_id) {
173 wl->chip_id);
177 wl->chip_id);
181 wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
186 if (wl->fw == NULL) {
187 ret = wl1251_fetch_firmware(wl);
200 struct wl1251 *wl =
204 mutex_lock(&wl->mutex);
208 if (wl->state == WL1251_STATE_OFF)
211 ret = wl1251_ps_elp_wakeup(wl);
215 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
217 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
221 if (wl->data_path) {
222 wl->rx_counter = wl1251_mem_read32(
223 wl, wl->data_path->rx_control_addr);
226 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
246 wl->rx_counter - wl->rx_handled);
250 wl->rx_handled = wl->rx_counter;
253 wl->rx_counter);
256 intr &= wl->intr_mask;
265 wl1251_rx(wl);
270 wl1251_rx(wl);
275 wl1251_tx_complete(wl);
280 wl1251_event_handle(wl, 0);
285 wl1251_event_handle(wl, 1);
295 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
299 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
300 wl1251_ps_elp_sleep(wl);
303 mutex_unlock(&wl->mutex);
306 static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
311 ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
313 wl->tx_mgmt_frm_rate,
314 wl->tx_mgmt_frm_mod);
322 if (is_zero_ether_addr(wl->bssid))
323 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
325 ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
330 ret = wl1251_event_wait(wl, JOIN_EVENT_COMPLETE_ID, 100);
342 struct wl1251 *wl = hw->priv;
345 skb_queue_tail(&wl->tx_queue, skb);
352 ieee80211_queue_work(wl->hw, &wl->tx_work);
358 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_HIGH_WATERMARK) {
361 spin_lock_irqsave(&wl->wl_lock, flags);
362 ieee80211_stop_queues(wl->hw);
363 wl->tx_queue_stopped = true;
364 spin_unlock_irqrestore(&wl->wl_lock, flags);
370 struct wl1251 *wl = hw->priv;
376 mutex_lock(&wl->mutex);
378 if (wl->state != WL1251_STATE_OFF) {
380 wl->state);
385 ret = wl1251_chip_wakeup(wl);
389 ret = wl1251_boot(wl);
393 ret = wl1251_hw_init(wl);
397 ret = wl1251_acx_station_id(wl);
401 wl->state = WL1251_STATE_ON;
403 wl1251_info("firmware booted (%s)", wl->fw_ver);
406 wiphy->hw_version = wl->chip_id;
407 strscpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version));
411 wl1251_power_off(wl);
413 mutex_unlock(&wl->mutex);
420 struct wl1251 *wl = hw->priv;
426 mutex_lock(&wl->mutex);
428 WARN_ON(wl->state != WL1251_STATE_ON);
430 if (wl->scanning) {
435 ieee80211_scan_completed(wl->hw, &info);
436 wl->scanning = false;
439 wl->state = WL1251_STATE_OFF;
441 wl1251_disable_interrupts(wl);
443 mutex_unlock(&wl->mutex);
445 cancel_work_sync(&wl->irq_work);
446 cancel_work_sync(&wl->tx_work);
447 cancel_delayed_work_sync(&wl->elp_work);
449 mutex_lock(&wl->mutex);
452 wl1251_tx_flush(wl);
453 wl1251_power_off(wl);
455 eth_zero_addr(wl->bssid);
456 wl->listen_int = 1;
457 wl->bss_type = MAX_BSS_TYPE;
459 wl->data_in_count = 0;
460 wl->rx_counter = 0;
461 wl->rx_handled = 0;
462 wl->rx_current_buffer = 0;
463 wl->rx_last_id = 0;
464 wl->next_tx_complete = 0;
465 wl->elp = false;
466 wl->station_mode = STATION_ACTIVE_MODE;
467 wl->psm_entry_retry = 0;
468 wl->tx_queue_stopped = false;
469 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
470 wl->rssi_thold = 0;
471 wl->channel = WL1251_DEFAULT_CHANNEL;
472 wl->monitor_present = false;
473 wl->joined = false;
475 wl1251_debugfs_reset(wl);
477 mutex_unlock(&wl->mutex);
483 struct wl1251 *wl = hw->priv;
493 mutex_lock(&wl->mutex);
494 if (wl->vif) {
499 wl->vif = vif;
503 wl->bss_type = BSS_TYPE_STA_BSS;
506 wl->bss_type = BSS_TYPE_IBSS;
513 if (!ether_addr_equal_unaligned(wl->mac_addr, vif->addr)) {
514 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
515 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
516 ret = wl1251_acx_station_id(wl);
522 mutex_unlock(&wl->mutex);
529 struct wl1251 *wl = hw->priv;
531 mutex_lock(&wl->mutex);
533 wl->vif = NULL;
534 eth_zero_addr(wl->bssid);
535 mutex_unlock(&wl->mutex);
538 static int wl1251_build_null_data(struct wl1251 *wl)
545 if (wl->bss_type == BSS_TYPE_IBSS) {
549 skb = ieee80211_nullfunc_get(wl->hw, wl->vif, -1, false);
556 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, ptr, size);
566 static int wl1251_build_qos_null_data(struct wl1251 *wl)
572 memcpy(template.addr1, wl->bssid, ETH_ALEN);
573 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
574 memcpy(template.addr3, wl->bssid, ETH_ALEN);
583 return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
587 static bool wl1251_can_do_pm(struct ieee80211_conf *conf, struct wl1251 *wl)
589 return (conf->flags & IEEE80211_CONF_PS) && !wl->monitor_present;
594 struct wl1251 *wl = hw->priv;
608 mutex_lock(&wl->mutex);
610 ret = wl1251_ps_elp_wakeup(wl);
618 wl->monitor_present = true;
621 wl->monitor_present = false;
625 ret = wl1251_acx_feature_cfg(wl, mode);
630 if (channel != wl->channel) {
631 wl->channel = channel;
640 if (wl->vif == NULL) {
641 wl->joined = false;
642 ret = wl1251_cmd_data_path_rx(wl, wl->channel, 1);
644 ret = wl1251_join(wl, wl->bss_type, wl->channel,
645 wl->beacon_int, wl->dtim_period);
651 if (wl1251_can_do_pm(conf, wl) && !wl->psm_requested) {
654 wl->psm_requested = true;
656 wl->dtim_period = conf->ps_dtim_period;
658 ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
659 wl->dtim_period);
664 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
667 } else if (!wl1251_can_do_pm(conf, wl) && wl->psm_requested) {
670 wl->psm_requested = false;
672 if (wl->station_mode != STATION_ACTIVE_MODE) {
673 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
679 if (changed & IEEE80211_CONF_CHANGE_IDLE && !wl->scanning) {
681 ret = wl1251_ps_set_mode(wl, STATION_IDLE);
685 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
688 ret = wl1251_join(wl, wl->bss_type, wl->channel,
689 wl->beacon_int, wl->dtim_period);
695 if (conf->power_level != wl->power_level) {
696 ret = wl1251_acx_tx_power(wl, conf->power_level);
700 wl->power_level = conf->power_level;
704 wl1251_ps_elp_sleep(wl);
707 mutex_unlock(&wl->mutex);
723 struct wl1251 *wl = hw->priv;
725 if (unlikely(wl->state == WL1251_STATE_OFF))
762 struct wl1251 *wl = hw->priv;
776 mutex_lock(&wl->mutex);
778 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
779 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
786 wl->rx_config &= ~CFG_MC_FILTER_EN;
788 wl->rx_filter |= CFG_RX_FCS_ERROR;
790 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
791 wl->rx_config &= ~CFG_SSID_FILTER_EN;
794 wl->rx_filter |= CFG_RX_CTL_EN;
795 if (*total & FIF_OTHER_BSS || is_zero_ether_addr(wl->bssid))
796 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
798 wl->rx_filter |= CFG_RX_PREQ_EN;
800 if (wl->state == WL1251_STATE_OFF)
803 ret = wl1251_ps_elp_wakeup(wl);
808 ret = wl1251_acx_group_address_tbl(wl, false, NULL, 0);
810 ret = wl1251_acx_group_address_tbl(wl, fp->enabled,
817 wl1251_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
819 wl1251_ps_elp_sleep(wl);
822 mutex_unlock(&wl->mutex);
827 static int wl1251_set_key_type(struct wl1251 *wl,
871 struct wl1251 *wl = hw->priv;
901 mutex_lock(&wl->mutex);
905 if (wl->monitor_present) {
919 ret = wl1251_ps_elp_wakeup(wl);
923 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
954 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
961 wl1251_ps_elp_sleep(wl);
964 mutex_unlock(&wl->mutex);
977 struct wl1251 *wl = hw->priv;
990 mutex_lock(&wl->mutex);
992 if (wl->scanning) {
998 ret = wl1251_ps_elp_wakeup(wl);
1003 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
1006 ret = wl1251_join(wl, wl->bss_type, wl->channel,
1007 wl->beacon_int, wl->dtim_period);
1012 skb = ieee80211_probereq_get(wl->hw, wl->vif->addr, ssid, ssid_len,
1021 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
1027 ret = wl1251_cmd_trigger_scan_to(wl, 0);
1031 wl->scanning = true;
1033 ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
1037 wl->scanning = false;
1044 ret = wl1251_ps_set_mode(wl, STATION_IDLE);
1046 wl1251_ps_elp_sleep(wl);
1049 mutex_unlock(&wl->mutex);
1056 struct wl1251 *wl = hw->priv;
1059 mutex_lock(&wl->mutex);
1061 ret = wl1251_ps_elp_wakeup(wl);
1065 ret = wl1251_acx_rts_threshold(wl, (u16) value);
1069 wl1251_ps_elp_sleep(wl);
1072 mutex_unlock(&wl->mutex);
1082 struct wl1251 *wl = hw->priv;
1089 mutex_lock(&wl->mutex);
1091 ret = wl1251_ps_elp_wakeup(wl);
1096 ret = wl1251_acx_low_rssi(wl, bss_conf->cqm_rssi_thold,
1102 wl->rssi_thold = bss_conf->cqm_rssi_thold;
1106 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
1107 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1109 if (!is_zero_ether_addr(wl->bssid)) {
1110 ret = wl1251_build_null_data(wl);
1114 ret = wl1251_build_qos_null_data(wl);
1118 ret = wl1251_join(wl, wl->bss_type, wl->channel,
1119 wl->beacon_int, wl->dtim_period);
1127 wl->beacon_int = bss_conf->beacon_int;
1129 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
1133 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
1140 ret = wl1251_acx_aid(wl, vif->cfg.aid);
1145 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1146 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1151 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
1153 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
1162 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1164 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1169 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1171 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1180 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
1183 ret = wl1251_acx_arp_ip_filter(wl, enable, addr);
1193 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
1201 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1209 ret = wl1251_join(wl, wl->bss_type, wl->channel,
1210 wl->beacon_int, wl->dtim_period);
1217 wl1251_ps_elp_sleep(wl);
1220 mutex_unlock(&wl->mutex);
1290 struct wl1251 *wl = hw->priv;
1293 mutex_lock(&wl->mutex);
1297 ret = wl1251_ps_elp_wakeup(wl);
1302 ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
1313 ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
1321 wl1251_ps_elp_sleep(wl);
1324 mutex_unlock(&wl->mutex);
1332 struct wl1251 *wl = hw->priv;
1340 survey->noise = wl->noise;
1375 static int wl1251_read_eeprom_byte(struct wl1251 *wl, off_t offset, u8 *data)
1379 wl1251_reg_write32(wl, EE_ADDR, offset);
1380 wl1251_reg_write32(wl, EE_CTL, EE_CTL_READ);
1385 if (!(wl1251_reg_read32(wl, EE_CTL) & EE_CTL_READ))
1394 *data = wl1251_reg_read32(wl, EE_DATA);
1398 static int wl1251_read_eeprom(struct wl1251 *wl, off_t offset,
1404 wl1251_reg_write32(wl, EE_START, 0);
1407 ret = wl1251_read_eeprom_byte(wl, offset + i, &data[i]);
1415 static int wl1251_read_eeprom_mac(struct wl1251 *wl)
1420 wl1251_set_partition(wl, 0, 0, REGISTERS_BASE, REGISTERS_DOWN_SIZE);
1422 ret = wl1251_read_eeprom(wl, 0x1c, mac, sizeof(mac));
1430 wl->mac_addr[i] = mac[ETH_ALEN - i - 1];
1440 static int wl1251_check_nvs_mac(struct wl1251 *wl)
1442 if (wl->nvs_len < 0x24)
1446 if (wl->nvs[NVS_OFF_MAC_LEN] != 2 ||
1447 wl->nvs[NVS_OFF_MAC_ADDR_LO] != 0x6d ||
1448 wl->nvs[NVS_OFF_MAC_ADDR_HI] != 0x54)
1454 static int wl1251_read_nvs_mac(struct wl1251 *wl)
1459 ret = wl1251_check_nvs_mac(wl);
1465 mac[i] = wl->nvs[NVS_OFF_MAC_DATA + ETH_ALEN - i - 1];
1471 memcpy(wl->mac_addr, mac, ETH_ALEN);
1475 static int wl1251_write_nvs_mac(struct wl1251 *wl)
1479 ret = wl1251_check_nvs_mac(wl);
1485 wl->nvs[NVS_OFF_MAC_DATA + i] = wl->mac_addr[ETH_ALEN - i - 1];
1490 static int wl1251_register_hw(struct wl1251 *wl)
1494 if (wl->mac80211_registered)
1497 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1499 ret = ieee80211_register_hw(wl->hw);
1505 wl->mac80211_registered = true;
1512 int wl1251_init_ieee80211(struct wl1251 *wl)
1517 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1523 ieee80211_hw_set(wl->hw, SIGNAL_DBM);
1524 ieee80211_hw_set(wl->hw, SUPPORTS_PS);
1526 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1528 wl->hw->wiphy->max_scan_ssids = 1;
1533 wl->hw->wiphy->max_scan_ie_len = 512;
1535 wl->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wl1251_band_2ghz;
1537 wl->hw->queues = 4;
1539 if (wl->nvs == NULL && !wl->use_eeprom) {
1540 ret = wl1251_fetch_nvs(wl);
1545 if (wl->use_eeprom)
1546 ret = wl1251_read_eeprom_mac(wl);
1548 ret = wl1251_read_nvs_mac(wl);
1550 if (ret == 0 && !is_valid_ether_addr(wl->mac_addr))
1559 memcpy(wl->mac_addr, nokia_oui, 3);
1560 get_random_bytes(wl->mac_addr + 3, 3);
1561 if (!wl->use_eeprom)
1562 wl1251_write_nvs_mac(wl);
1564 wl1251_warning("Setting random MAC address: %pM", wl->mac_addr);
1567 ret = wl1251_register_hw(wl);
1571 wl1251_debugfs_init(wl);
1584 struct wl1251 *wl;
1587 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
1593 wl = hw->priv;
1594 memset(wl, 0, sizeof(*wl));
1596 wl->hw = hw;
1598 wl->data_in_count = 0;
1600 skb_queue_head_init(&wl->tx_queue);
1602 INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
1603 wl->channel = WL1251_DEFAULT_CHANNEL;
1604 wl->monitor_present = false;
1605 wl->joined = false;
1606 wl->scanning = false;
1607 wl->bss_type = MAX_BSS_TYPE;
1608 wl->default_key = 0;
1609 wl->listen_int = 1;
1610 wl->rx_counter = 0;
1611 wl->rx_handled = 0;
1612 wl->rx_current_buffer = 0;
1613 wl->rx_last_id = 0;
1614 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1615 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
1616 wl->elp = false;
1617 wl->station_mode = STATION_ACTIVE_MODE;
1618 wl->psm_requested = false;
1619 wl->psm_entry_retry = 0;
1620 wl->tx_queue_stopped = false;
1621 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
1622 wl->rssi_thold = 0;
1623 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1624 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1625 wl->vif = NULL;
1628 wl->tx_frames[i] = NULL;
1630 wl->next_tx_complete = 0;
1632 INIT_WORK(&wl->irq_work, wl1251_irq_work);
1633 INIT_WORK(&wl->tx_work, wl1251_tx_work);
1635 wl->state = WL1251_STATE_OFF;
1636 mutex_init(&wl->mutex);
1637 spin_lock_init(&wl->wl_lock);
1639 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1640 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1642 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1643 if (!wl->rx_descriptor) {
1653 int wl1251_free_hw(struct wl1251 *wl)
1655 ieee80211_unregister_hw(wl->hw);
1657 wl1251_debugfs_exit(wl);
1659 kfree(wl->target_mem_map);
1660 kfree(wl->data_path);
1661 vfree(wl->fw);
1662 wl->fw = NULL;
1663 kfree(wl->nvs);
1664 wl->nvs = NULL;
1666 kfree(wl->rx_descriptor);
1667 wl->rx_descriptor = NULL;
1669 ieee80211_free_hw(wl->hw);