Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2004-2011 Atheros Communications Inc.
0003  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
0004  *
0005  * Permission to use, copy, modify, and/or distribute this software for any
0006  * purpose with or without fee is hereby granted, provided that the above
0007  * copyright notice and this permission notice appear in all copies.
0008  *
0009  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0010  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0011  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0012  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0013  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0014  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0015  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0016  */
0017 
0018 #include "core.h"
0019 
0020 #include <linux/module.h>
0021 #include <linux/moduleparam.h>
0022 #include <linux/export.h>
0023 #include <linux/vmalloc.h>
0024 
0025 #include "debug.h"
0026 #include "hif-ops.h"
0027 #include "htc-ops.h"
0028 #include "cfg80211.h"
0029 
0030 unsigned int debug_mask;
0031 static unsigned int suspend_mode;
0032 static unsigned int wow_mode;
0033 static unsigned int uart_debug;
0034 static unsigned int uart_rate = 115200;
0035 static unsigned int ath6kl_p2p;
0036 static unsigned int testmode;
0037 static unsigned int recovery_enable;
0038 static unsigned int heart_beat_poll;
0039 
0040 module_param(debug_mask, uint, 0644);
0041 module_param(suspend_mode, uint, 0644);
0042 module_param(wow_mode, uint, 0644);
0043 module_param(uart_debug, uint, 0644);
0044 module_param(uart_rate, uint, 0644);
0045 module_param(ath6kl_p2p, uint, 0644);
0046 module_param(testmode, uint, 0644);
0047 module_param(recovery_enable, uint, 0644);
0048 module_param(heart_beat_poll, uint, 0644);
0049 MODULE_PARM_DESC(recovery_enable, "Enable recovery from firmware error");
0050 MODULE_PARM_DESC(heart_beat_poll,
0051          "Enable fw error detection periodic polling in msecs - Also set recovery_enable for this to be effective");
0052 
0053 
0054 void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
0055 {
0056     ath6kl_htc_tx_complete(ar, skb);
0057 }
0058 EXPORT_SYMBOL(ath6kl_core_tx_complete);
0059 
0060 void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe)
0061 {
0062     ath6kl_htc_rx_complete(ar, skb, pipe);
0063 }
0064 EXPORT_SYMBOL(ath6kl_core_rx_complete);
0065 
0066 int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
0067 {
0068     struct ath6kl_bmi_target_info targ_info;
0069     struct wireless_dev *wdev;
0070     int ret = 0, i;
0071 
0072     switch (htc_type) {
0073     case ATH6KL_HTC_TYPE_MBOX:
0074         ath6kl_htc_mbox_attach(ar);
0075         break;
0076     case ATH6KL_HTC_TYPE_PIPE:
0077         ath6kl_htc_pipe_attach(ar);
0078         break;
0079     default:
0080         WARN_ON(1);
0081         return -ENOMEM;
0082     }
0083 
0084     ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
0085     if (!ar->ath6kl_wq)
0086         return -ENOMEM;
0087 
0088     ret = ath6kl_bmi_init(ar);
0089     if (ret)
0090         goto err_wq;
0091 
0092     /*
0093      * Turn on power to get hardware (target) version and leave power
0094      * on delibrately as we will boot the hardware anyway within few
0095      * seconds.
0096      */
0097     ret = ath6kl_hif_power_on(ar);
0098     if (ret)
0099         goto err_bmi_cleanup;
0100 
0101     ret = ath6kl_bmi_get_target_info(ar, &targ_info);
0102     if (ret)
0103         goto err_power_off;
0104 
0105     ar->version.target_ver = le32_to_cpu(targ_info.version);
0106     ar->target_type = le32_to_cpu(targ_info.type);
0107     ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
0108 
0109     ret = ath6kl_init_hw_params(ar);
0110     if (ret)
0111         goto err_power_off;
0112 
0113     ar->htc_target = ath6kl_htc_create(ar);
0114 
0115     if (!ar->htc_target) {
0116         ret = -ENOMEM;
0117         goto err_power_off;
0118     }
0119 
0120     ar->testmode = testmode;
0121 
0122     ret = ath6kl_init_fetch_firmwares(ar);
0123     if (ret)
0124         goto err_htc_cleanup;
0125 
0126     /* FIXME: we should free all firmwares in the error cases below */
0127 
0128     /*
0129      * Backwards compatibility support for older ar6004 firmware images
0130      * which do not set these feature flags.
0131      */
0132     if (ar->target_type == TARGET_TYPE_AR6004 &&
0133         ar->fw_api <= 4) {
0134         __set_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
0135               ar->fw_capabilities);
0136         __set_bit(ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS,
0137               ar->fw_capabilities);
0138 
0139         if (ar->hw.id == AR6004_HW_1_3_VERSION)
0140             __set_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
0141                   ar->fw_capabilities);
0142     }
0143 
0144     /* Indicate that WMI is enabled (although not ready yet) */
0145     set_bit(WMI_ENABLED, &ar->flag);
0146     ar->wmi = ath6kl_wmi_init(ar);
0147     if (!ar->wmi) {
0148         ath6kl_err("failed to initialize wmi\n");
0149         ret = -EIO;
0150         goto err_htc_cleanup;
0151     }
0152 
0153     ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
0154 
0155     /* setup access class priority mappings */
0156     ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest  */
0157     ar->ac_stream_pri_map[WMM_AC_BE] = 1;
0158     ar->ac_stream_pri_map[WMM_AC_VI] = 2;
0159     ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
0160 
0161     /* allocate some buffers that handle larger AMSDU frames */
0162     ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
0163 
0164     ath6kl_cookie_init(ar);
0165 
0166     ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
0167              ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
0168 
0169     if (suspend_mode &&
0170         suspend_mode >= WLAN_POWER_STATE_CUT_PWR &&
0171         suspend_mode <= WLAN_POWER_STATE_WOW)
0172         ar->suspend_mode = suspend_mode;
0173     else
0174         ar->suspend_mode = 0;
0175 
0176     if (suspend_mode == WLAN_POWER_STATE_WOW &&
0177         (wow_mode == WLAN_POWER_STATE_CUT_PWR ||
0178          wow_mode == WLAN_POWER_STATE_DEEP_SLEEP))
0179         ar->wow_suspend_mode = wow_mode;
0180     else
0181         ar->wow_suspend_mode = 0;
0182 
0183     if (uart_debug)
0184         ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
0185     ar->hw.uarttx_rate = uart_rate;
0186 
0187     set_bit(FIRST_BOOT, &ar->flag);
0188 
0189     ath6kl_debug_init(ar);
0190 
0191     ret = ath6kl_init_hw_start(ar);
0192     if (ret) {
0193         ath6kl_err("Failed to start hardware: %d\n", ret);
0194         goto err_rxbuf_cleanup;
0195     }
0196 
0197     /* give our connected endpoints some buffers */
0198     ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
0199     ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
0200 
0201     ret = ath6kl_cfg80211_init(ar);
0202     if (ret)
0203         goto err_rxbuf_cleanup;
0204 
0205     ret = ath6kl_debug_init_fs(ar);
0206     if (ret) {
0207         wiphy_unregister(ar->wiphy);
0208         goto err_rxbuf_cleanup;
0209     }
0210 
0211     for (i = 0; i < ar->vif_max; i++)
0212         ar->avail_idx_map |= BIT(i);
0213 
0214     rtnl_lock();
0215     wiphy_lock(ar->wiphy);
0216 
0217     /* Add an initial station interface */
0218     wdev = ath6kl_interface_add(ar, "wlan%d", NET_NAME_ENUM,
0219                     NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
0220 
0221     wiphy_unlock(ar->wiphy);
0222     rtnl_unlock();
0223 
0224     if (!wdev) {
0225         ath6kl_err("Failed to instantiate a network device\n");
0226         ret = -ENOMEM;
0227         wiphy_unregister(ar->wiphy);
0228         goto err_rxbuf_cleanup;
0229     }
0230 
0231     ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
0232            __func__, wdev->netdev->name, wdev->netdev, ar);
0233 
0234     ar->fw_recovery.enable = !!recovery_enable;
0235     if (!ar->fw_recovery.enable)
0236         return ret;
0237 
0238     if (heart_beat_poll &&
0239         test_bit(ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
0240              ar->fw_capabilities))
0241         ar->fw_recovery.hb_poll = heart_beat_poll;
0242 
0243     ath6kl_recovery_init(ar);
0244 
0245     return ret;
0246 
0247 err_rxbuf_cleanup:
0248     ath6kl_debug_cleanup(ar);
0249     ath6kl_htc_flush_rx_buf(ar->htc_target);
0250     ath6kl_cleanup_amsdu_rxbufs(ar);
0251     ath6kl_wmi_shutdown(ar->wmi);
0252     clear_bit(WMI_ENABLED, &ar->flag);
0253     ar->wmi = NULL;
0254 err_htc_cleanup:
0255     ath6kl_htc_cleanup(ar->htc_target);
0256 err_power_off:
0257     ath6kl_hif_power_off(ar);
0258 err_bmi_cleanup:
0259     ath6kl_bmi_cleanup(ar);
0260 err_wq:
0261     destroy_workqueue(ar->ath6kl_wq);
0262 
0263     return ret;
0264 }
0265 EXPORT_SYMBOL(ath6kl_core_init);
0266 
0267 struct ath6kl *ath6kl_core_create(struct device *dev)
0268 {
0269     struct ath6kl *ar;
0270     u8 ctr;
0271 
0272     ar = ath6kl_cfg80211_create();
0273     if (!ar)
0274         return NULL;
0275 
0276     ar->p2p = !!ath6kl_p2p;
0277     ar->dev = dev;
0278 
0279     ar->vif_max = 1;
0280 
0281     ar->max_norm_iface = 1;
0282 
0283     spin_lock_init(&ar->lock);
0284     spin_lock_init(&ar->mcastpsq_lock);
0285     spin_lock_init(&ar->list_lock);
0286 
0287     init_waitqueue_head(&ar->event_wq);
0288     sema_init(&ar->sem, 1);
0289 
0290     INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
0291     INIT_LIST_HEAD(&ar->vif_list);
0292 
0293     clear_bit(WMI_ENABLED, &ar->flag);
0294     clear_bit(SKIP_SCAN, &ar->flag);
0295     clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
0296 
0297     ar->tx_pwr = 0;
0298     ar->intra_bss = 1;
0299     ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
0300 
0301     ar->state = ATH6KL_STATE_OFF;
0302 
0303     memset((u8 *)ar->sta_list, 0,
0304            AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
0305 
0306     /* Init the PS queues */
0307     for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
0308         spin_lock_init(&ar->sta_list[ctr].psq_lock);
0309         skb_queue_head_init(&ar->sta_list[ctr].psq);
0310         skb_queue_head_init(&ar->sta_list[ctr].apsdq);
0311         ar->sta_list[ctr].mgmt_psq_len = 0;
0312         INIT_LIST_HEAD(&ar->sta_list[ctr].mgmt_psq);
0313         ar->sta_list[ctr].aggr_conn =
0314             kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
0315         if (!ar->sta_list[ctr].aggr_conn) {
0316             ath6kl_err("Failed to allocate memory for sta aggregation information\n");
0317             ath6kl_core_destroy(ar);
0318             return NULL;
0319         }
0320     }
0321 
0322     skb_queue_head_init(&ar->mcastpsq);
0323 
0324     memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
0325 
0326     return ar;
0327 }
0328 EXPORT_SYMBOL(ath6kl_core_create);
0329 
0330 void ath6kl_core_cleanup(struct ath6kl *ar)
0331 {
0332     ath6kl_hif_power_off(ar);
0333 
0334     ath6kl_recovery_cleanup(ar);
0335 
0336     destroy_workqueue(ar->ath6kl_wq);
0337 
0338     if (ar->htc_target)
0339         ath6kl_htc_cleanup(ar->htc_target);
0340 
0341     ath6kl_cookie_cleanup(ar);
0342 
0343     ath6kl_cleanup_amsdu_rxbufs(ar);
0344 
0345     ath6kl_bmi_cleanup(ar);
0346 
0347     ath6kl_debug_cleanup(ar);
0348 
0349     kfree(ar->fw_board);
0350     kfree(ar->fw_otp);
0351     vfree(ar->fw);
0352     kfree(ar->fw_patch);
0353     kfree(ar->fw_testscript);
0354 
0355     ath6kl_cfg80211_cleanup(ar);
0356 }
0357 EXPORT_SYMBOL(ath6kl_core_cleanup);
0358 
0359 void ath6kl_core_destroy(struct ath6kl *ar)
0360 {
0361     ath6kl_cfg80211_destroy(ar);
0362 }
0363 EXPORT_SYMBOL(ath6kl_core_destroy);
0364 
0365 MODULE_AUTHOR("Qualcomm Atheros");
0366 MODULE_DESCRIPTION("Core module for AR600x SDIO and USB devices.");
0367 MODULE_LICENSE("Dual BSD/GPL");