| //------------------------------------------------------------------------------ |
| // Copyright (c) 2004-2010 Atheros Communications Inc. |
| // All rights reserved. |
| // |
| // |
| // |
| // Permission to use, copy, modify, and/or distribute this software for any |
| // purpose with or without fee is hereby granted, provided that the above |
| // copyright notice and this permission notice appear in all copies. |
| // |
| // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| // |
| // |
| // |
| // Author(s): ="Atheros" |
| //------------------------------------------------------------------------------ |
| |
| /* |
| * This driver is a pseudo ethernet driver to access the Atheros AR6000 |
| * WLAN Device |
| */ |
| #include <linux/vmalloc.h> |
| #include "ar6000_drv.h" |
| #ifdef ATH6K_CONFIG_CFG80211 |
| #include "cfg80211.h" |
| #endif /* ATH6K_CONFIG_CFG80211 */ |
| #include "htc.h" |
| #include "wmi_filter_linux.h" |
| #include "epping_test.h" |
| #include "wlan_config.h" |
| #include "ar3kconfig.h" |
| #ifdef ATH_SUPPORT_DFS |
| #include "dfs_host.h" |
| #endif |
| #include "ar6k_pal.h" |
| #include "AR6002/addrs.h" |
| #include "target_reg_table.h" |
| #ifdef P2P |
| #include "p2p_api.h" |
| #endif |
| #include "a_drv_api.h" |
| |
| #ifdef CONFIG_PLAT_AMBARELLA |
| #include <mach/board.h> |
| #include <plat/sd.h> |
| #endif |
| |
| /* LINUX_HACK_FUDGE_FACTOR -- this is used to provide a workaround for linux behavior. When |
| * the meta data was added to the header it was found that linux did not correctly provide |
| * enough headroom. However when more headroom was requested beyond what was truly needed |
| * Linux gave the requested headroom. Therefore to get the necessary headroom from Linux |
| * the driver requests more than is needed by the amount = LINUX_HACK_FUDGE_FACTOR */ |
| #define LINUX_HACK_FUDGE_FACTOR 16 |
| #define BDATA_BDADDR_OFFSET 28 |
| |
| A_UINT8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| A_UINT8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; |
| |
| #ifdef DEBUG |
| |
| #define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0) |
| #define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1) |
| #define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2) |
| #define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3) |
| #define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4) |
| #define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5) |
| #define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6) |
| |
| static ATH_DEBUG_MASK_DESCRIPTION driver_debug_desc[] = { |
| { ATH_DEBUG_DBG_LOG , "Target Debug Logs"}, |
| { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"}, |
| { ATH_DEBUG_WLAN_SCAN , "WLAN scan"}, |
| { ATH_DEBUG_WLAN_TX , "WLAN Tx"}, |
| { ATH_DEBUG_WLAN_RX , "WLAN Rx"}, |
| { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"}, |
| { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"}, |
| { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"}, |
| { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"}, |
| }; |
| |
| ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver, |
| "driver", |
| "Linux Driver Interface", |
| ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN | |
| ATH_DEBUG_HCI_BRIDGE, |
| ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc), |
| driver_debug_desc); |
| |
| #endif |
| |
| |
| #define IS_MAC_NULL(mac) (mac[0]==0 && mac[1]==0 && mac[2]==0 && mac[3]==0 && mac[4]==0 && mac[5]==0) |
| #define IS_MAC_BCAST(mac) (*mac==0xff) |
| |
| #define DESCRIPTION "Driver to access the AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_) |
| |
| MODULE_AUTHOR("Qualcomm Atheros"); |
| MODULE_DESCRIPTION(DESCRIPTION); |
| MODULE_LICENSE("Dual BSD/GPL"); |
| |
| #ifndef REORG_APTC_HEURISTICS |
| #undef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| #endif /* REORG_APTC_HEURISTICS */ |
| |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| A_TIMER aptcTimer[NUM_DEV]; |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| |
| #ifdef EXPORT_HCI_BRIDGE_INTERFACE |
| // callbacks registered by HCI transport driver |
| HCI_TRANSPORT_CALLBACKS ar6kHciTransCallbacks = { NULL }; |
| #endif |
| |
| unsigned int processDot11Hdr = 0; |
| char targetconf[10]={0,}; |
| int bmienable = BMIENABLE_DEFAULT; |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| char ifname[IFNAMSIZ] = {0,}; |
| char devmode[32] ={0,}; |
| char submode[32] ={0,}; |
| #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ |
| |
| int regcode = 0; |
| int wlaninitmode = WLAN_INIT_MODE_DEFAULT; |
| unsigned int bypasswmi = 0; |
| unsigned int debuglevel = 0; |
| int tspecCompliance = ATHEROS_COMPLIANCE; |
| unsigned int busspeedlow = 0; |
| unsigned int onebitmode = 0; |
| unsigned int skipflash = 0; |
| unsigned int wmitimeout = 2; |
| unsigned int wlanNodeCaching = 1; |
| unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT; |
| unsigned int logWmiRawMsgs = 0; |
| unsigned int enabletimerwar = 0; |
| unsigned int fwmode = 1; |
| unsigned int fwsubmode = 0; |
| unsigned int mbox_yield_limit = 99; |
| unsigned int enablerssicompensation = 0; |
| int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF; |
| int allow_trace_signal = 0; |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| unsigned int testmode =0; |
| #endif |
| unsigned int firmware_bridge = 0; |
| |
| unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC; |
| unsigned int panic_on_assert = 1; |
| unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT; |
| |
| unsigned int setuphci = SETUPHCI_DEFAULT; |
| unsigned int setuphcipal = SETUPHCIPAL_DEFAULT; |
| unsigned int loghci = 0; |
| unsigned int setupbtdev = SETUPBTDEV_DEFAULT; |
| #ifndef EXPORT_HCI_BRIDGE_INTERFACE |
| unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT; |
| unsigned int hciuartscale = HCIUARTSCALE_DEFAULT; |
| unsigned int hciuartstep = HCIUARTSTEP_DEFAULT; |
| #endif |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| unsigned int csumOffload=0; |
| unsigned int csumOffloadTest=0; |
| #endif |
| unsigned int eppingtest=0; |
| unsigned int regscanmode=0; |
| unsigned int num_device=1; |
| unsigned char ar6k_init=FALSE; |
| unsigned int rtc_reset_only_on_exit=0; |
| unsigned int mac_addr_method=0; |
| A_BOOL avail_ev_called=FALSE; |
| |
| #if defined(CONFIG_MMC_MSM) && defined(CONFIG_ARCH_MSM7X27) && defined(CONFIG_MSM_SOC_REV_A) |
| unsigned int refClock = 19200000; |
| #else |
| unsigned int refClock = 26000000; |
| #endif |
| |
| unsigned int max_psq_depth = MAX_DEFAULT_PS_QUEUE_DEPTH; |
| |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| module_param_string(ifname, ifname, sizeof(ifname), 0644); |
| module_param(regcode, int, 0644); |
| module_param(wlaninitmode, int, 0644); |
| module_param(bmienable, int, 0644); |
| module_param(bypasswmi, uint, 0644); |
| module_param(debuglevel, uint, 0644); |
| module_param(tspecCompliance, int, 0644); |
| module_param(onebitmode, uint, 0644); |
| module_param(busspeedlow, uint, 0644); |
| module_param(skipflash, uint, 0644); |
| module_param(wmitimeout, uint, 0644); |
| module_param(wlanNodeCaching, uint, 0644); |
| module_param(logWmiRawMsgs, uint, 0644); |
| module_param(enableuartprint, uint, 0644); |
| module_param(enabletimerwar, uint, 0644); |
| module_param(mbox_yield_limit, uint, 0644); |
| module_param(reduce_credit_dribble, int, 0644); |
| module_param(allow_trace_signal, int, 0644); |
| module_param(enablerssicompensation, uint, 0644); |
| module_param(processDot11Hdr, uint, 0644); |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| module_param(csumOffload, uint, 0644); |
| #endif |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| module_param(testmode, uint, 0644); |
| #endif |
| module_param(firmware_bridge, uint, 0644); |
| module_param(irqprocmode, uint, 0644); |
| module_param(nohifscattersupport, uint, 0644); |
| module_param(panic_on_assert, uint, 0644); |
| module_param(setuphci, uint, 0644); |
| module_param(setuphcipal, uint, 0644); |
| module_param(loghci, uint, 0644); |
| module_param(setupbtdev, uint, 0644); |
| #ifndef EXPORT_HCI_BRIDGE_INTERFACE |
| module_param(ar3khcibaud, uint, 0644); |
| module_param(hciuartscale, uint, 0644); |
| module_param(hciuartstep, uint, 0644); |
| #endif |
| module_param(eppingtest, uint, 0644); |
| module_param(regscanmode, uint, 0644); |
| module_param_string(devmode, devmode, sizeof(devmode), 0644); |
| module_param_string(submode, submode, sizeof(submode), 0644); |
| module_param_string(targetconf, targetconf, sizeof(targetconf), 0644); |
| module_param(rtc_reset_only_on_exit, uint, 0644); |
| module_param(mac_addr_method, uint, 0644); |
| module_param(refClock, uint, 0644); |
| module_param(max_psq_depth, uint, 0644); |
| #else |
| |
| #define __user |
| /* for linux 2.4 and lower */ |
| MODULE_PARM(bmienable,"i"); |
| MODULE_PARM(wlaninitmode,"i"); |
| MODULE_PARM(bypasswmi,"i"); |
| MODULE_PARM(debuglevel, "i"); |
| MODULE_PARM(onebitmode,"i"); |
| MODULE_PARM(busspeedlow, "i"); |
| MODULE_PARM(skipflash, "i"); |
| MODULE_PARM(wmitimeout, "i"); |
| MODULE_PARM(wlanNodeCaching, "i"); |
| MODULE_PARM(enableuartprint,"i"); |
| MODULE_PARM(logWmiRawMsgs, "i"); |
| MODULE_PARM(enabletimerwar,"i"); |
| MODULE_PARM(mbox_yield_limit,"i"); |
| MODULE_PARM(reduce_credit_dribble,"i"); |
| MODULE_PARM(allow_trace_signal,"i"); |
| MODULE_PARM(enablerssicompensation,"i"); |
| MODULE_PARM(processDot11Hdr,"i"); |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| MODULE_PARM(csumOffload,"i"); |
| #endif |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| MODULE_PARM(testmode, "i"); |
| #endif |
| MODULE_PARM(irqprocmode, "i"); |
| MODULE_PARM(nohifscattersupport, "i"); |
| MODULE_PARM(panic_on_assert, "i"); |
| MODULE_PARM(setuphci, "i"); |
| MODULE_PARM(setuphcipal, "i"); |
| MODULE_PARM(loghci, "i"); |
| MODULE_PARM(regscanmode, "i"); |
| MODULE_PARM(rtc_reset_only_on_exit, "i"); |
| MODULE_PARM(mac_addr_method, "i"); |
| MODULE_PARM(refClock, "i"); |
| MODULE_PARM(max_psq_depth, "i"); |
| #endif |
| |
| #if WLAN_CONFIG_FIRST_SCAN_2G_ONLY |
| unsigned int first_scan_2g_only = WLAN_CONFIG_FIRST_SCAN_2G_ONLY; |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| module_param(first_scan_2g_only, uint, 0644); |
| #else |
| MODULE_PARM(first_scan_2g_only, "i"); |
| #endif |
| #endif |
| |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10) |
| /* in 2.6.10 and later this is now a pointer to a uint */ |
| unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX; |
| #define mboxnum &_mboxnum |
| #else |
| unsigned int mboxnum = HTC_MAILBOX_NUM_MAX; |
| #endif |
| |
| #ifdef DEBUG |
| A_UINT32 g_dbg_flags = DBG_DEFAULTS; |
| unsigned int debugflags = 0; |
| int debugdriver = 0; |
| unsigned int debughtc = 0; |
| unsigned int debugbmi = 0; |
| unsigned int debughif = 0; |
| unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0}; |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| module_param(debugflags, uint, 0644); |
| module_param(debugdriver, int, 0644); |
| module_param(debughtc, uint, 0644); |
| module_param(debugbmi, uint, 0644); |
| module_param(debughif, uint, 0644); |
| module_param_array(txcreditsavailable, uint, mboxnum, 0644); |
| module_param_array(txcreditsconsumed, uint, mboxnum, 0644); |
| module_param_array(txcreditintrenable, uint, mboxnum, 0644); |
| module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644); |
| #else |
| /* linux 2.4 and lower */ |
| MODULE_PARM(debugflags,"i"); |
| MODULE_PARM(debugdriver, "i"); |
| MODULE_PARM(debughtc, "i"); |
| MODULE_PARM(debugbmi, "i"); |
| MODULE_PARM(debughif, "i"); |
| MODULE_PARM(txcreditsavailable, "0-3i"); |
| MODULE_PARM(txcreditsconsumed, "0-3i"); |
| MODULE_PARM(txcreditintrenable, "0-3i"); |
| MODULE_PARM(txcreditintrenableaggregate, "0-3i"); |
| #endif |
| |
| #endif /* DEBUG */ |
| |
| unsigned int resetok = 1; |
| unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0}; |
| unsigned int hifBusRequestNumMax = 40; |
| unsigned int war23838_disabled = 0; |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| unsigned int enableAPTCHeuristics = 1; |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| unsigned int psm_info = 99; |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| module_param_array(tx_attempt, uint, mboxnum, 0644); |
| module_param_array(tx_post, uint, mboxnum, 0644); |
| module_param_array(tx_complete, uint, mboxnum, 0644); |
| module_param(hifBusRequestNumMax, uint, 0644); |
| module_param(war23838_disabled, uint, 0644); |
| module_param(resetok, uint, 0644); |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| module_param(enableAPTCHeuristics, uint, 0644); |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| module_param(psm_info, uint, 0444); |
| #else |
| MODULE_PARM(tx_attempt, "0-3i"); |
| MODULE_PARM(tx_post, "0-3i"); |
| MODULE_PARM(tx_complete, "0-3i"); |
| MODULE_PARM(hifBusRequestNumMax, "i"); |
| MODULE_PARM(war23838_disabled, "i"); |
| MODULE_PARM(resetok, "i"); |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| MODULE_PARM(enableAPTCHeuristics, "i"); |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| MODULE_PARM(psm_info, "i"); |
| #endif |
| |
| #ifdef BLOCK_TX_PATH_FLAG |
| int blocktx = 0; |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| module_param(blocktx, int, 0644); |
| #else |
| MODULE_PARM(blocktx, "i"); |
| #endif |
| #endif /* BLOCK_TX_PATH_FLAG */ |
| |
| static A_INT16 rssi_compensation_table[NUM_DEV][96]; |
| |
| int reconnect_flag = 0; |
| static ar6k_pal_config_t ar6k_pal_config_g; |
| |
| // Load unload synchronization |
| DECLARE_WAIT_QUEUE_HEAD(load_complete); |
| DECLARE_WAIT_QUEUE_HEAD(scan_complete); |
| |
| // Indicates if the module load completed |
| static int mod_loaded = FALSE; |
| |
| /* Function declarations */ |
| static int ar6000_init_module(void); |
| static void ar6000_cleanup_module(void); |
| |
| struct completion avail_ev_completion; |
| |
| int ar6000_init(struct net_device *dev); |
| static int ar6000_open(struct net_device *dev); |
| static int ar6000_close(struct net_device *dev); |
| static int ar6000_init_control_info(AR_SOFTC_DEV_T *arPriv); |
| static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev); |
| |
| void ar6000_destroy(struct net_device *dev, unsigned int unregister); |
| void ar6000_cleanup(AR_SOFTC_T *ar); |
| static void ar6000_detect_error(unsigned long ptr); |
| static void ar6000_set_multicast_list(struct net_device *dev); |
| static struct net_device_stats *ar6000_get_stats(struct net_device *dev); |
| static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev); |
| |
| static void disconnect_timer_handler(unsigned long ptr); |
| |
| void read_rssi_compensation_param(AR_SOFTC_T *ar); |
| void target_register_tbl_attach(A_UINT32 target_type); |
| static void ar6000_uapsd_trigger_frame_rx(AR_SOFTC_DEV_T *arPriv, conn_t *conn); |
| static void delba_timer_callback(unsigned long ptr); |
| static int ar6000_check_hold_conn_status(AR_SOFTC_DEV_T *arPriv, A_UINT8 conn_status); |
| |
| extern int android_readwrite_file(const A_CHAR *filename, A_CHAR *rbuf, const A_CHAR *wbuf, size_t length); |
| /* for android builds we call external APIs that handle firmware download and configuration */ |
| #ifdef ANDROID_ENV |
| /* !!!! Interim android support to make it easier to patch the default driver for |
| * android use. You must define an external source file ar6000_android.c that handles the following |
| * APIs */ |
| extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks); |
| extern void android_module_exit(void); |
| extern void android_send_reload_event(AR_SOFTC_DEV_T *arPriv); |
| #define ANDROID_RELOAD_THRESHOLD_FOR_EP_FULL 5 |
| static int android_epfull_cnt; |
| #endif |
| /* |
| * HTC service connection handlers |
| */ |
| static A_STATUS ar6000_avail_ev(void *context, void *hif_handle); |
| |
| static A_STATUS ar6000_unavail_ev(void *context, void *hif_handle); |
| |
| A_STATUS ar6000_configure_target(AR_SOFTC_T *ar); |
| |
| static void ar6000_target_failure(void *Instance, A_STATUS Status); |
| |
| static void ar6000_rx(void *Context, HTC_PACKET *pPacket); |
| |
| static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint); |
| |
| static void ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPackets); |
| |
| static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket); |
| |
| #ifdef ATH_AR6K_11N_SUPPORT |
| static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num); |
| #endif |
| static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf); |
| //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf); |
| |
| static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length); |
| |
| static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count); |
| |
| static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar); |
| |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) |
| static ssize_t |
| ar6000_sysfs_bmi_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count); |
| |
| static ssize_t |
| ar6000_sysfs_bmi_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count); |
| #else |
| static ssize_t |
| ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, |
| struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count); |
| |
| static ssize_t |
| ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, |
| struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count); |
| #endif |
| |
| static A_STATUS |
| ar6000_sysfs_bmi_init(AR_SOFTC_T *ar); |
| |
| /* HCI PAL callback function declarations */ |
| A_STATUS ar6k_setup_hci_pal(AR_SOFTC_DEV_T *ar); |
| void ar6k_cleanup_hci_pal(AR_SOFTC_DEV_T *ar); |
| |
| static void |
| ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar); |
| |
| A_STATUS |
| ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode); |
| |
| /* |
| * Static variables |
| */ |
| |
| struct net_device *ar6000_devices[NUM_DEV]; |
| extern struct iw_handler_def ath_iw_handler_def; |
| static void ar6000_cookie_init(AR_SOFTC_T *ar); |
| static void ar6000_cookie_cleanup(AR_SOFTC_T *ar); |
| static void ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie); |
| static struct ar_cookie *ar6000_alloc_cookie(AR_SOFTC_T *ar); |
| |
| #ifdef USER_KEYS |
| static A_STATUS ar6000_reinstall_keys(AR_SOFTC_DEV_T *arPriv,A_UINT8 key_op_ctrl); |
| #endif |
| |
| |
| static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM]; |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
| static struct net_device_ops ar6000_netdev_ops = { |
| .ndo_init = NULL, |
| .ndo_open = ar6000_open, |
| .ndo_stop = ar6000_close, |
| .ndo_get_stats = ar6000_get_stats, |
| .ndo_do_ioctl = ar6000_ioctl, |
| .ndo_start_xmit = ar6000_data_tx, |
| .ndo_set_multicast_list = ar6000_set_multicast_list, |
| .ndo_change_mtu = eth_change_mtu, |
| }; |
| #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) */ |
| |
| /* Debug log support */ |
| |
| /* |
| * Flag to govern whether the debug logs should be parsed in the kernel |
| * or reported to the application. |
| */ |
| #define REPORT_DEBUG_LOGS_TO_APP |
| |
| A_STATUS |
| ar6000_set_host_app_area(AR_SOFTC_T *ar) |
| { |
| A_UINT32 address, data; |
| struct host_app_area_s host_app_area; |
| |
| /* Fetch the address of the host_app_area_s instance in the host interest area */ |
| address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_app_host_interest)); |
| if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != A_OK) { |
| return A_ERROR; |
| } |
| address = TARG_VTOP(ar->arTargetType, data); |
| host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION; |
| if (ar6000_WriteDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)&host_app_area, |
| sizeof(struct host_app_area_s)) != A_OK) |
| { |
| return A_ERROR; |
| } |
| |
| return A_OK; |
| } |
| |
| A_UINT32 |
| dbglog_get_debug_hdr_ptr(AR_SOFTC_T *ar) |
| { |
| A_UINT32 param; |
| A_UINT32 address; |
| A_STATUS status; |
| |
| address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dbglog_hdr)); |
| if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)¶m, 4)) != A_OK) |
| { |
| param = 0; |
| } |
| |
| return param; |
| } |
| |
| /* |
| * The dbglog module has been initialized. Its ok to access the relevant |
| * data stuctures over the diagnostic window. |
| */ |
| void |
| ar6000_dbglog_init_done(AR_SOFTC_DEV_T *arPriv) |
| { |
| AR_SOFTC_T *ar = arPriv->arSoftc; |
| ar->dbglog_init_done = TRUE; |
| } |
| |
| A_UINT32 |
| dbglog_get_debug_fragment(A_INT8 *datap, A_UINT32 len, A_UINT32 limit) |
| { |
| A_INT32 *buffer; |
| A_UINT32 count; |
| A_UINT32 numargs; |
| A_UINT32 length; |
| A_UINT32 fraglen; |
| |
| count = fraglen = 0; |
| buffer = (A_INT32 *)datap; |
| length = (limit >> 2); |
| |
| if (len <= limit) { |
| fraglen = len; |
| } else { |
| while (count < length) { |
| numargs = DBGLOG_GET_NUMARGS(buffer[count]); |
| fraglen = (count << 2); |
| count += numargs + 1; |
| } |
| } |
| |
| return fraglen; |
| } |
| |
| void |
| dbglog_parse_debug_logs(A_INT8 *datap, A_UINT32 len) |
| { |
| A_INT32 *buffer; |
| A_UINT32 count; |
| A_UINT32 timestamp; |
| A_UINT32 debugid; |
| A_UINT32 moduleid; |
| A_UINT32 numargs; |
| A_UINT32 length; |
| |
| count = 0; |
| buffer = (A_INT32 *)datap; |
| length = (len >> 2); |
| while (count < length) { |
| debugid = DBGLOG_GET_DBGID(buffer[count]); |
| moduleid = DBGLOG_GET_MODULEID(buffer[count]); |
| numargs = DBGLOG_GET_NUMARGS(buffer[count]); |
| timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]); |
| switch (numargs) { |
| case 0: |
| AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp)); |
| break; |
| |
| case 1: |
| AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid, |
| timestamp, buffer[count+1])); |
| break; |
| |
| case 2: |
| AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid, |
| timestamp, buffer[count+1], buffer[count+2])); |
| break; |
| |
| default: |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs)); |
| } |
| count += numargs + 1; |
| } |
| } |
| |
| int |
| ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar) |
| { |
| struct dbglog_hdr_s debug_hdr; |
| struct dbglog_buf_s debug_buf; |
| A_UINT32 address; |
| A_UINT32 length; |
| A_UINT32 dropped; |
| A_UINT32 firstbuf; |
| A_UINT32 debug_hdr_ptr; |
| |
| if (!ar->dbglog_init_done) return A_ERROR; |
| |
| |
| AR6000_SPIN_LOCK(&ar->arLock, 0); |
| |
| if (ar->dbgLogFetchInProgress) { |
| AR6000_SPIN_UNLOCK(&ar->arLock, 0); |
| return A_EBUSY; |
| } |
| |
| /* block out others */ |
| ar->dbgLogFetchInProgress = TRUE; |
| |
| AR6000_SPIN_UNLOCK(&ar->arLock, 0); |
| |
| debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar); |
| printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr); |
| |
| /* Get the contents of the ring buffer */ |
| if (debug_hdr_ptr) { |
| address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr); |
| length = sizeof(struct dbglog_hdr_s); |
| ar6000_ReadDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)&debug_hdr, length); |
| address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_hdr.dbuf); |
| firstbuf = address; |
| dropped = debug_hdr.dropped; |
| length = sizeof(struct dbglog_buf_s); |
| ar6000_ReadDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)&debug_buf, length); |
| |
| do { |
| address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_buf.buffer); |
| length = debug_buf.length; |
| if ((length) && (debug_buf.length <= debug_buf.bufsize)) { |
| /* Rewind the index if it is about to overrun the buffer */ |
| if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) { |
| ar->log_cnt = 0; |
| } |
| if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)&ar->log_buffer[ar->log_cnt], length)) |
| { |
| break; |
| } |
| ar6000_dbglog_event(ar->arDev[0], dropped, (A_INT8*)&ar->log_buffer[ar->log_cnt], length); |
| ar->log_cnt += length; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n", |
| debug_buf.length, debug_buf.bufsize)); |
| } |
| |
| address = TARG_VTOP(ar->arTargetType, (A_UINT32)debug_buf.next); |
| length = sizeof(struct dbglog_buf_s); |
| if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, |
| (A_UCHAR *)&debug_buf, length)) |
| { |
| break; |
| } |
| |
| } while (address != firstbuf); |
| } |
| |
| ar->dbgLogFetchInProgress = FALSE; |
| |
| return A_OK; |
| } |
| |
| void |
| ar6000_dbglog_event(AR_SOFTC_DEV_T *arPriv, A_UINT32 dropped, |
| A_INT8 *buffer, A_UINT32 length) |
| { |
| #ifdef REPORT_DEBUG_LOGS_TO_APP |
| #define MAX_WIRELESS_EVENT_SIZE 252 |
| /* |
| * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages. |
| * There seems to be a limitation on the length of message that could be |
| * transmitted to the user app via this mechanism. |
| */ |
| A_UINT32 send, sent; |
| |
| sent = 0; |
| send = dbglog_get_debug_fragment(&buffer[sent], length - sent, |
| MAX_WIRELESS_EVENT_SIZE); |
| while (send) { |
| ar6000_send_event_to_app(arPriv, WMIX_DBGLOG_EVENTID, (A_UINT8*)&buffer[sent], send); |
| sent += send; |
| send = dbglog_get_debug_fragment(&buffer[sent], length - sent, |
| MAX_WIRELESS_EVENT_SIZE); |
| } |
| #else |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n", |
| dropped, length)); |
| |
| /* Interpret the debug logs */ |
| dbglog_parse_debug_logs((A_INT8*)buffer, length); |
| #endif /* REPORT_DEBUG_LOGS_TO_APP */ |
| } |
| |
| void |
| ar6000_parse_dev_mode(A_CHAR *mode) |
| { |
| A_UINT8 i, match = FALSE, mode_len; |
| #ifdef P2P |
| A_UINT8 val_mode, val_submode; |
| #endif |
| A_UINT8 num_submode; |
| |
| char *valid_modes[] = { "sta", |
| "ap", |
| "ibss", |
| "bt30amp", |
| "sta,ap", |
| "ap,sta", |
| "ap,ap", |
| "sta,sta", |
| "sta,bt30amp", |
| "sta,ap,ap" |
| }; |
| #ifdef P2P |
| char *valid_submodes[] = { "none", |
| "p2pdev", |
| /*"p2pclient",*/ //persistent p2p support |
| /*"p2pgo", */ // persistent p2p support |
| "none,none", |
| "none,none,none", |
| "none,p2pdev", |
| "p2pdev,none", |
| /*"none,p2pclient",*/ //persistent p2p support |
| /*"none,p2pgo"*/ // persistent p2p support |
| }; |
| #endif |
| A_CHAR *dev_mode; |
| A_CHAR *str; |
| A_UINT32 host_int = 0; |
| |
| dev_mode = mode; |
| str = mode; |
| num_device = 0; |
| fwmode = 0; |
| |
| mode_len = strlen(dev_mode); |
| for (i=0; i <= 9; i++) { |
| if ((mode_len == strlen(valid_modes[i])) && (strcmp(dev_mode,valid_modes[i]))==0) { |
| match = TRUE; |
| break; |
| } |
| } |
| |
| if(!match) { |
| num_device = fwmode = 1; |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ERROR: Wrong mode. using default (single device STA mode).\n")); |
| return; |
| } |
| |
| do |
| { |
| str++; |
| if(*str == ',' || *str == '\0') { |
| num_device++; |
| if(strncmp(dev_mode,"ap",2) == 0) { |
| host_int = HI_OPTION_FW_MODE_AP; |
| } |
| else if(strncmp(dev_mode,"sta",3) == 0) { |
| host_int = HI_OPTION_FW_MODE_BSS_STA; |
| } |
| else if(strncmp(dev_mode,"ibss",4) == 0 ) { |
| host_int = HI_OPTION_FW_MODE_IBSS; |
| } else if(strncmp(dev_mode,"bt30amp",7) == 0) { |
| host_int = HI_OPTION_FW_MODE_BT30AMP; |
| } |
| |
| fwmode |= (host_int << ((num_device -1) * HI_OPTION_FW_MODE_BITS)); |
| dev_mode = ++str; |
| } |
| }while(*dev_mode != '\0'); |
| |
| /* Validate submode if present */ |
| if (!submode[0]) { |
| /* default "none" submode for all devices */ |
| fwsubmode = 0; |
| return; |
| } |
| |
| dev_mode = submode; |
| str = submode; |
| num_submode = 0; |
| fwsubmode = 0; |
| match = FALSE; |
| |
| #ifdef P2P |
| mode_len = strlen(dev_mode); |
| for (i=0; i<6; i++) { |
| if ((mode_len == strlen(valid_submodes[i])) && (strcmp(dev_mode,valid_submodes[i]))==0) { |
| match = TRUE; |
| break; |
| } |
| } |
| |
| if (!match) { |
| fwsubmode = 0; |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ERROR: Wrong submode. using default (none for all devs).\n")); |
| return; |
| } |
| |
| do |
| { |
| str++; |
| if(*str == ',' || *str == '\0') { |
| num_submode++; |
| if(strncmp(dev_mode,"none",4) == 0) { |
| host_int = HI_OPTION_FW_SUBMODE_NONE; |
| } |
| else if(strncmp(dev_mode,"p2pdev",6) == 0) { |
| host_int = HI_OPTION_FW_SUBMODE_P2PDEV; |
| } |
| else if(strncmp(dev_mode,"p2pclient",9) == 0 ) { |
| host_int = HI_OPTION_FW_SUBMODE_P2PCLIENT; |
| } else if(strncmp(dev_mode,"p2pgo",5) == 0 ) { |
| host_int = HI_OPTION_FW_SUBMODE_P2PGO; |
| } |
| fwsubmode |= (host_int << ((num_submode -1) * HI_OPTION_FW_SUBMODE_BITS)); |
| dev_mode = ++str; |
| } |
| }while(*dev_mode != '\0'); |
| |
| /* Validate if the subopmode is specified for all the devs. |
| */ |
| if (num_device != num_submode) { |
| /* default to "none" submode for all devices */ |
| fwsubmode = 0; |
| return; |
| } |
| |
| /* Validate if the submode specified is appropriate for the device modes |
| * specified for each device. The following is the validation recipe. |
| * fwmode fwsubmode |
| * ----------------------- |
| * IBSS none |
| * STA none,p2pdev,p2pclient |
| * AP none,p2pgo |
| */ |
| for (i=0; i<num_device; i++) { |
| val_mode = (fwmode >> (i * HI_OPTION_FW_MODE_BITS)) & |
| HI_OPTION_FW_MODE_MASK; |
| val_submode = (fwsubmode >> (i * HI_OPTION_FW_SUBMODE_BITS)) & |
| HI_OPTION_FW_SUBMODE_MASK; |
| switch (val_mode) { |
| case HI_OPTION_FW_MODE_IBSS: |
| if (val_submode != HI_OPTION_FW_SUBMODE_NONE) { |
| /* set submode to none */ |
| fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); |
| fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); |
| } |
| break; |
| |
| case HI_OPTION_FW_MODE_BSS_STA: |
| if (val_submode == HI_OPTION_FW_SUBMODE_P2PGO) { |
| /* set submode to none */ |
| fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); |
| fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); |
| } |
| |
| break; |
| case HI_OPTION_FW_MODE_AP: |
| if (val_submode == HI_OPTION_FW_SUBMODE_P2PDEV || |
| val_submode == HI_OPTION_FW_SUBMODE_P2PCLIENT) { |
| /* set submode to none */ |
| fwsubmode &= ~(HI_OPTION_FW_SUBMODE_MASK << (i*HI_OPTION_FW_SUBMODE_BITS)); |
| fwsubmode |= (HI_OPTION_FW_SUBMODE_NONE << (i * HI_OPTION_FW_SUBMODE_BITS)); |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| #endif |
| return; |
| } |
| |
| static int __init |
| ar6000_init_module(void) |
| { |
| static int probed = 0; |
| A_STATUS status; |
| OSDRV_CALLBACKS osdrvCallbacks; |
| |
| a_module_debug_support_init(); |
| printk("init-AR6003-driver 844\n"); |
| |
| #ifdef DEBUG |
| /* check for debug mask overrides */ |
| if (debughtc != 0) { |
| ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc); |
| } |
| if (debugbmi != 0) { |
| ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi); |
| } |
| if (debughif != 0) { |
| ATH_DEBUG_SET_DEBUG_MASK(hif,debughif); |
| } |
| if (debugdriver != 0) { |
| ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver); |
| } |
| |
| #endif |
| |
| A_REGISTER_MODULE_DEBUG_INFO(driver); |
| ar6k_init = FALSE; |
| A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks)); |
| osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev; |
| osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev; |
| |
| #ifdef CONFIG_PM |
| osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev; |
| osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev; |
| osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev; |
| #endif |
| |
| init_completion(&avail_ev_completion); |
| |
| ar6000_pm_init(); |
| if(devmode[0]) |
| ar6000_parse_dev_mode(devmode); |
| |
| #ifdef ANDROID_ENV |
| android_module_init(&osdrvCallbacks); |
| #endif |
| |
| #ifdef DEBUG |
| /* Set the debug flags if specified at load time */ |
| if(debugflags != 0) |
| { |
| g_dbg_flags = debugflags; |
| } |
| #endif |
| |
| if (probed) { |
| return -ENODEV; |
| } |
| probed++; |
| |
| #ifdef CONFIG_HOST_GPIO_SUPPORT |
| ar6000_gpio_init(); |
| #endif /* CONFIG_HOST_GPIO_SUPPORT */ |
| |
| status = HIFInit(&osdrvCallbacks); |
| if(status != A_OK) |
| return -ENODEV; |
| |
| return 0; |
| } |
| |
| #define AR6K_AVAIL_EV_COMPLETION_TIMEOUT (60 * HZ) |
| |
| static void __exit |
| ar6000_cleanup_module(void) |
| { |
| int i = 0; |
| struct net_device *ar6000_netdev; |
| AR_SOFTC_T *ar; |
| AR_SOFTC_DEV_T *arPriv = NULL; |
| unsigned long tmo = AR6K_AVAIL_EV_COMPLETION_TIMEOUT; |
| |
| if (!wait_event_interruptible_timeout(load_complete, mod_loaded != FALSE, 5 * HZ)) { |
| printk(KERN_ERR "Load did not complete. Unload did not proceed\n"); |
| return; |
| } |
| A_PRINTF("\nAR6K: %s()\n", __func__); |
| |
| tmo = wait_for_completion_timeout(&avail_ev_completion, tmo); |
| if (tmo == 0) { |
| A_PRINTF("AR6K: wait for avail_ev_completion %d sec timeout\n", |
| AR6K_AVAIL_EV_COMPLETION_TIMEOUT / HZ); |
| } |
| |
| if (ar6000_devices[0] != NULL) { |
| arPriv = (AR_SOFTC_DEV_T *) ar6k_priv(ar6000_devices[0]); |
| ar = arPriv->arSoftc; |
| ar6000_cleanup(ar); |
| } |
| for (i=0; i < num_device; i++) { |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| /* Delete the Adaptive Power Control timer */ |
| if (timer_pending(&aptcTimer[i])) { |
| del_timer_sync(&aptcTimer[i]); |
| } |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| if (ar6000_devices[i] != NULL) { |
| arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[i]); |
| if (arPriv) { |
| A_UNTIMEOUT(&arPriv->arSta.disconnect_timer); |
| } |
| ar6000_netdev = ar6000_devices[i]; |
| ar6000_devices[i] = NULL; |
| ar6000_destroy(ar6000_netdev, 1); |
| } |
| } |
| #ifdef P2P |
| p2p_deinit(); |
| #endif /* P2P */ |
| |
| HIFShutDownDevice(NULL); |
| |
| a_module_debug_support_cleanup(); |
| |
| ar6000_pm_exit(); |
| |
| |
| #ifdef ANDROID_ENV |
| android_module_exit(); |
| #endif |
| a_meminfo_report(TRUE); |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n")); |
| } |
| |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| void |
| aptcTimerHandler(unsigned long arg) |
| { |
| A_UINT32 numbytes; |
| A_UINT32 throughput; |
| AR_SOFTC_T *ar; |
| A_STATUS status; |
| APTC_TRAFFIC_RECORD *aptcTR; |
| A_UNIT8 i; |
| |
| ar = (AR_SOFTC_T *)arg; |
| A_ASSERT(ar != NULL); |
| |
| for(i = 0; i < num_device; i++) { |
| aptcTR = ar->arDev[i].aptcTR; |
| A_ASSERT(!timer_pending(&aptcTimer[i])); |
| AR6000_SPIN_LOCK(&ar->arLock, 0); |
| |
| /* Get the number of bytes transferred */ |
| numbytes = aptcTR->bytesTransmitted + aptcTR->bytesReceived; |
| aptcTR->bytesTransmitted = aptcTR->bytesReceived = 0; |
| |
| /* Calculate and decide based on throughput thresholds */ |
| throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */ |
| if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) { |
| /* Enable Sleep and delete the timer */ |
| A_ASSERT(ar->arWmiReady == TRUE); |
| AR6000_SPIN_UNLOCK(&ar->arLock, 0); |
| status = wmi_powermode_cmd(ar->arWmi, REC_POWER); |
| AR6000_SPIN_LOCK(&ar->arLock, 0); |
| A_ASSERT(status == A_OK); |
| aptcTR->timerScheduled = FALSE; |
| } else { |
| A_TIMEOUT_MS(&aptcTimer[i], APTC_TRAFFIC_SAMPLING_INTERVAL, 0); |
| } |
| |
| AR6000_SPIN_UNLOCK(&ar->arLock, 0); |
| } |
| } |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| |
| #ifdef ATH_AR6K_11N_SUPPORT |
| static void |
| ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num) |
| { |
| void * osbuf; |
| |
| while(num) { |
| if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) { |
| A_NETBUF_ENQUEUE(q, osbuf); |
| } else { |
| break; |
| } |
| num--; |
| } |
| |
| if(num) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(), allocation of netbuf failed", __func__)); |
| } |
| } |
| #endif |
| |
| static struct bin_attribute bmi_attr = { |
| .attr = {.name = "bmi", .mode = 0600}, |
| .read = ar6000_sysfs_bmi_read, |
| .write = ar6000_sysfs_bmi_write, |
| }; |
| |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) |
| static ssize_t |
| ar6000_sysfs_bmi_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count) |
| #else |
| static ssize_t |
| ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, |
| struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count) |
| #endif |
| { |
| int index; |
| AR_SOFTC_DEV_T *arPriv; |
| AR_SOFTC_T *ar = NULL; |
| HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", count)); |
| for (index=0; index < num_device; index++) { |
| arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[index]); |
| ar = arPriv->arSoftc; |
| osDevInfo = &ar->osDevInfo; |
| if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { |
| break; |
| } |
| } |
| |
| if (ar == NULL) return 0; |
| if (index == num_device) return 0; |
| |
| if ((BMIRawRead(ar->arHifDevice, (A_UCHAR*)buf, count, TRUE)) != A_OK) { |
| return 0; |
| } |
| |
| return count; |
| } |
| |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) |
| static ssize_t |
| ar6000_sysfs_bmi_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count) |
| #else |
| static ssize_t |
| ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, |
| struct bin_attribute *bin_attr, |
| char *buf, loff_t pos, size_t count) |
| #endif |
| { |
| int index; |
| AR_SOFTC_DEV_T *arPriv; |
| AR_SOFTC_T *ar = NULL; |
| HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", count)); |
| for (index=0; index < num_device; index++) { |
| arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(ar6000_devices[index]); |
| ar = arPriv->arSoftc; |
| osDevInfo = &ar->osDevInfo; |
| if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { |
| break; |
| } |
| } |
| |
| if (ar == NULL) return 0; |
| if (index == num_device) return 0; |
| |
| if ((BMIRawWrite(ar->arHifDevice, (A_UCHAR*)buf, count)) != A_OK) { |
| return 0; |
| } |
| |
| return count; |
| } |
| |
| static A_STATUS |
| ar6000_sysfs_bmi_init(AR_SOFTC_T *ar) |
| { |
| A_STATUS status; |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n")); |
| A_MEMZERO(&ar->osDevInfo, sizeof(HIF_DEVICE_OS_DEVICE_INFO)); |
| |
| /* Get the underlying OS device */ |
| status = HIFConfigureDevice(ar->arHifDevice, |
| HIF_DEVICE_GET_OS_DEVICE, |
| &ar->osDevInfo, |
| sizeof(HIF_DEVICE_OS_DEVICE_INFO)); |
| |
| if (A_FAILED(status)) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n")); |
| return A_ERROR; |
| } |
| |
| /* Create a bmi entry in the sysfs filesystem */ |
| if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n")); |
| return A_ERROR; |
| } |
| |
| return A_OK; |
| } |
| |
| static void |
| ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar) |
| { |
| if (ar->osDevInfo.pOSDevice) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n")); |
| sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr); |
| ar->osDevInfo.pOSDevice = NULL; |
| } |
| } |
| |
| #define bmifn(fn) do { \ |
| if ((fn) < A_OK) { \ |
| A_PRINTF("BMI operation failed: %d\n", __LINE__); \ |
| return A_ERROR; \ |
| } \ |
| } while(0) |
| |
| #ifdef INIT_MODE_DRV_ENABLED |
| |
| #define MCKINLEY_MAC_ADDRESS_OFFSET 0x16 |
| static |
| void calculate_crc(A_UINT32 TargetType, A_UCHAR *eeprom_data, size_t eeprom_size) |
| { |
| A_UINT16 *ptr_crc; |
| A_UINT16 *ptr16_eeprom; |
| A_UINT16 checksum; |
| A_UINT32 i; |
| |
| if (TargetType == TARGET_TYPE_AR6001) |
| { |
| ptr_crc = (A_UINT16 *)eeprom_data; |
| } |
| else if (TargetType == TARGET_TYPE_AR6003) |
| { |
| ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); |
| } |
| else if (TargetType == TARGET_TYPE_MCKINLEY) |
| { |
| eeprom_size = 1024; |
| ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); |
| } |
| else |
| { |
| ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); |
| } |
| |
| |
| // Clear the crc |
| *ptr_crc = 0; |
| |
| // Recalculate new CRC |
| checksum = 0; |
| ptr16_eeprom = (A_UINT16 *)eeprom_data; |
| for (i = 0;i < eeprom_size; i += 2) |
| { |
| checksum = checksum ^ (*ptr16_eeprom); |
| ptr16_eeprom++; |
| } |
| checksum = 0xFFFF ^ checksum; |
| *ptr_crc = checksum; |
| } |
| |
| #ifdef SOFTMAC_USED |
| #define AR6002_MAC_ADDRESS_OFFSET 0x0A |
| #define AR6003_MAC_ADDRESS_OFFSET 0x16 |
| |
| static void |
| ar6000_softmac(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t eeprom_size) |
| { |
| A_UCHAR *ptr_mac; |
| switch (ar->arTargetType) { |
| case TARGET_TYPE_AR6002: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET); |
| break; |
| case TARGET_TYPE_AR6003: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET); |
| break; |
| case TARGET_TYPE_MCKINLEY: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + MCKINLEY_MAC_ADDRESS_OFFSET); |
| break; |
| default: |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); |
| return; |
| } |
| ptr_mac[0] = ambarella_board_generic.wifi0_mac[0]; |
| ptr_mac[1] = ambarella_board_generic.wifi0_mac[1]; |
| ptr_mac[2] = ambarella_board_generic.wifi0_mac[2]; |
| ptr_mac[3] = ambarella_board_generic.wifi0_mac[3]; |
| ptr_mac[4] = ambarella_board_generic.wifi0_mac[4]; |
| ptr_mac[5] = ambarella_board_generic.wifi0_mac[5]; |
| |
| if (0==memcmp(ptr_mac, "\0\0\0\0\0\0",6)) { |
| ptr_mac[0] = 0x00; |
| ptr_mac[1] = 0x03; |
| ptr_mac[2] = 0x7F; |
| ptr_mac[3] = random32() & 0xff; |
| ptr_mac[4] = random32() & 0xff; |
| ptr_mac[5] = random32() & 0xff; |
| //memcpy(ptr_mac+3, "\3\4\5", 3); |
| |
| ambarella_board_generic.wifi0_mac[0] = ptr_mac[0]; |
| ambarella_board_generic.wifi0_mac[1] = ptr_mac[1]; |
| ambarella_board_generic.wifi0_mac[2] = ptr_mac[2]; |
| ambarella_board_generic.wifi0_mac[3] = ptr_mac[3]; |
| ambarella_board_generic.wifi0_mac[4] = ptr_mac[4]; |
| ambarella_board_generic.wifi0_mac[5] = ptr_mac[5]; |
| } |
| |
| calculate_crc(ar->arTargetType, eeprom_data, eeprom_size); |
| } |
| #endif |
| |
| #ifdef SOFTMAC_FILE_USED |
| #define AR6002_MAC_ADDRESS_OFFSET 0x0A |
| #define AR6003_MAC_ADDRESS_OFFSET 0x16 |
| static void |
| ar6000_softmac_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t eeprom_size) |
| { |
| /* We need to store the MAC, which comes either from the softmac file or is |
| * randomly generated, because we do not want to load a new MAC address |
| * if the chip goes into suspend and then is resumed later on. We ONLY |
| * want to load a new MAC if the driver is unloaded and then reloaded |
| */ |
| static A_UCHAR random_mac[6]; |
| const char *source = "random generated"; |
| const struct firmware *softmac_entry; |
| A_UCHAR *ptr_mac; |
| switch (ar->arTargetType) { |
| case TARGET_TYPE_AR6002: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET); |
| break; |
| case TARGET_TYPE_AR6003: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET); |
| break; |
| case TARGET_TYPE_MCKINLEY: |
| ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + MCKINLEY_MAC_ADDRESS_OFFSET); |
| break; |
| default: |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); |
| return; |
| } |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_WARN, |
| ("MAC from EEPROM %02X:%02X:%02X:%02X:%02X:%02X\n", |
| ptr_mac[0], ptr_mac[1], ptr_mac[2], |
| ptr_mac[3], ptr_mac[4], ptr_mac[5])); |
| |
| if (memcmp(random_mac, "\0\0\0\0\0\0", 6)!=0) { |
| memcpy(ptr_mac, random_mac, 6); |
| } else { |
| /* create a random MAC in case we cannot read file from system */ |
| ptr_mac[0] = random_mac[0] = 2; /* locally administered */ |
| ptr_mac[1] = random_mac[1] = 0x03; |
| ptr_mac[2] = random_mac[2] = 0x7F; |
| ptr_mac[3] = random_mac[3] = random32() & 0xff; |
| ptr_mac[4] = random_mac[4] = random32() & 0xff; |
| ptr_mac[5] = random_mac[5] = random32() & 0xff; |
| } |
| #if defined(CONFIG_ARCH_MSM9615) |
| if ((A_REQUEST_FIRMWARE(&softmac_entry, "ath6k/AR6003/hw2.1.1/softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0) |
| #else |
| if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0) |
| #endif |
| { |
| A_CHAR *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1); |
| if (macbuf) { |
| unsigned int softmac[6]; |
| memcpy(macbuf, softmac_entry->data, softmac_entry->size); |
| macbuf[softmac_entry->size] = '\0'; |
| if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x", |
| &softmac[0], &softmac[1], &softmac[2], |
| &softmac[3], &softmac[4], &softmac[5])==6) { |
| int i; |
| for (i=0; i<6; ++i) { |
| ptr_mac[i] = softmac[i] & 0xff; |
| } |
| source = "softmac file"; |
| A_MEMZERO(random_mac, sizeof(random_mac)); |
| } |
| A_FREE(macbuf); |
| } |
| A_RELEASE_FIRMWARE(softmac_entry); |
| } |
| |
| if (memcmp(random_mac, "\0\0\0\0\0\0", 6)!=0) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Warning! Random MAC address is just for testing purpose\n")); |
| } |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_WARN, |
| ("MAC from %s %02X:%02X:%02X:%02X:%02X:%02X\n", source, |
| ptr_mac[0], ptr_mac[1], ptr_mac[2], |
| ptr_mac[3], ptr_mac[4], ptr_mac[5])); |
| calculate_crc(ar->arTargetType, eeprom_data, eeprom_size); |
| } |
| #endif /* SOFTMAC_FILE_USED */ |
| |
| static void |
| ar6000_reg_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t eeprom_size, int regCode) |
| { |
| A_UCHAR *ptr_reg; |
| switch (ar->arTargetType) { |
| case TARGET_TYPE_AR6002: |
| ptr_reg = (A_UINT8 *)((A_UCHAR *)eeprom_data + 8); |
| break; |
| case TARGET_TYPE_AR6003: |
| ptr_reg = (A_UINT8 *)((A_UCHAR *)eeprom_data + 12); |
| break; |
| default: |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); |
| return; |
| } |
| |
| ptr_reg[0] = (A_UCHAR)(regCode&0xFF); |
| ptr_reg[1] = (A_UCHAR)((regCode>>8)&0xFF); |
| calculate_crc(ar->arTargetType, eeprom_data, eeprom_size); |
| } |
| |
| #ifdef ANDROID_ENV |
| static void |
| ar6000_psminfo_update(void) |
| { |
| char psm_filename[256]; |
| |
| do { |
| int ret = 0; |
| size_t length; |
| u8 *pdata = NULL; |
| |
| snprintf(psm_filename, sizeof(psm_filename), "/data/.psm.info"); |
| |
| if ( (ret = android_readwrite_file(psm_filename, NULL, NULL, 0)) < 0) { |
| break; |
| } else { |
| length = ret; |
| } |
| pdata = vmalloc(length); |
| if (!pdata) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Cannot allocate buffer for psm_info (%d)\n", __FUNCTION__,length)); |
| break; |
| } |
| |
| if ( android_readwrite_file(psm_filename, (char*)pdata, NULL, length) != length) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: file read error, length %d\n", __FUNCTION__, length)); |
| vfree(pdata); |
| break; |
| } |
| psm_info = *pdata - '0'; |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s: psm_info is %d\n", __FUNCTION__, psm_info)); |
| vfree(pdata); |
| } while (0); |
| } |
| #endif |
| |
| |
| static A_STATUS |
| ar6000_transfer_bin_file(AR_SOFTC_T *ar, AR6K_BIN_FILE file, A_UINT32 address, A_BOOL compressed) |
| { |
| A_STATUS status; |
| const char *filename; |
| const struct firmware *fw_entry; |
| A_UINT32 fw_entry_size; |
| A_UCHAR *tempEeprom; |
| A_UINT32 board_data_size; |
| |
| switch (file) { |
| case AR6K_OTP_FILE: |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_OTP_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_OTP_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| break; |
| |
| case AR6K_FIRMWARE_FILE: |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_FIRMWARE_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| if(ar->arVersion.targetconf_ver == AR6003_SUBVER_ROUTER) |
| filename = AR6003_REV3_ROUTER_FIRMWARE_FILE; |
| else if (ar->arVersion.targetconf_ver == AR6003_SUBVER_MOBILE) |
| filename = AR6003_REV3_MOBILE_FIRMWARE_FILE; |
| else if (ar->arVersion.targetconf_ver == AR6003_SUBVER_TABLET) |
| filename = AR6003_REV3_TABLET_FIRMWARE_FILE; |
| else |
| filename = AR6003_REV3_DEFAULT_FIRMWARE_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s firmware will be loaded\n", filename)); |
| |
| |
| if (eppingtest) { |
| bypasswmi = TRUE; |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_EPPING_FIRMWARE_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_EPPING_FIRMWARE_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n", |
| ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| compressed = 0; |
| } |
| |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| if(testmode == 1) { |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_TCMD_FIRMWARE_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_TCMD_FIRMWARE_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| compressed = 0; |
| } |
| #endif |
| #ifdef HTC_RAW_INTERFACE |
| if (!eppingtest && bypasswmi) { |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_ART_FIRMWARE_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_ART_FIRMWARE_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| compressed = 0; |
| } |
| #endif |
| break; |
| |
| case AR6K_PATCH_FILE: |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_PATCH_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_PATCH_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| break; |
| |
| case AR6K_BOARD_DATA_FILE: |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_BOARD_DATA_FILE; |
| } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_BOARD_DATA_FILE; |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| break; |
| |
| default: |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file)); |
| return A_ERROR; |
| } |
| if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); |
| return A_ENOENT; |
| } |
| |
| fw_entry_size = fw_entry->size; |
| tempEeprom = NULL; |
| |
| /* Load extended board data for AR6003 */ |
| if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) { |
| A_UINT32 board_ext_address; |
| A_INT32 board_ext_data_size; |
| |
| tempEeprom = A_MALLOC_NOWAIT(fw_entry->size); |
| if (!tempEeprom) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Memory allocation failed\n")); |
| A_RELEASE_FIRMWARE(fw_entry); |
| return A_ERROR; |
| } |
| |
| board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \ |
| (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0)); |
| |
| board_ext_data_size = 0; |
| if (ar->arTargetType == TARGET_TYPE_AR6002) { |
| board_ext_data_size = AR6002_BOARD_EXT_DATA_SZ; |
| } else if (ar->arTargetType == TARGET_TYPE_AR6003) { |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| board_ext_data_size = AR6003_VER2_BOARD_EXT_DATA_SZ; |
| } else { |
| board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ; |
| } |
| } |
| |
| /* AR6003 2.1.1 support 1792 bytes and 2048 bytes board file */ |
| if ((board_ext_data_size) && |
| (fw_entry->size < (board_data_size + board_ext_data_size))) |
| { |
| board_ext_data_size = fw_entry->size - board_data_size; |
| if (board_ext_data_size < 0) { |
| board_ext_data_size = 0; |
| } |
| } |
| |
| A_MEMCPY(tempEeprom, (A_UCHAR *)fw_entry->data, fw_entry->size); |
| |
| #ifdef SOFTMAC_FILE_USED |
| ar6000_softmac_update(ar, tempEeprom, board_data_size); |
| #endif |
| #ifdef SOFTMAC_USED |
| ar6000_softmac(ar, tempEeprom, board_data_size); |
| #endif |
| |
| if (regcode!=0) { |
| ar6000_reg_update(ar, tempEeprom, board_data_size, regcode); |
| } |
| |
| #ifdef ANDROID_ENV |
| ar6000_psminfo_update(); |
| #endif |
| /* Determine where in Target RAM to write Board Data */ |
| bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data), (A_UCHAR *)&board_ext_address, 4)); |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address)); |
| |
| /* check whether the target has allocated memory for extended board data and file contains extended board data */ |
| if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) { |
| A_UINT32 param; |
| |
| status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(((A_UINT32)tempEeprom) + board_data_size), board_ext_data_size); |
| |
| if (status != A_OK) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); |
| A_RELEASE_FIRMWARE(fw_entry); |
| return A_ERROR; |
| } |
| |
| /* Record the fact that extended board Data IS initialized */ |
| param = (board_ext_data_size << 16) | 1; |
| bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data_config), (A_UCHAR *)¶m, 4)); |
| } |
| fw_entry_size = board_data_size; |
| } |
| |
| if (compressed) { |
| status = BMIFastDownload(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); |
| } else { |
| if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) |
| { |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)tempEeprom, fw_entry_size); |
| } |
| else |
| { |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); |
| } |
| } |
| |
| if (tempEeprom) { |
| A_FREE(tempEeprom); |
| } |
| |
| if (status != A_OK) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); |
| A_RELEASE_FIRMWARE(fw_entry); |
| return A_ERROR; |
| } |
| A_RELEASE_FIRMWARE(fw_entry); |
| return A_OK; |
| } |
| #endif /* INIT_MODE_DRV_ENABLED */ |
| |
| A_STATUS |
| ar6000_update_bdaddr(AR_SOFTC_T *ar) |
| { |
| |
| if (setupbtdev != 0) { |
| A_UINT32 address; |
| |
| if (BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data), (A_UCHAR *)&address, 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n")); |
| return A_ERROR; |
| } |
| |
| if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (A_UCHAR *)ar->bdaddr, 6) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0], |
| ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3], |
| ar->bdaddr[4], ar->bdaddr[5])); |
| } |
| |
| return A_OK; |
| } |
| |
| A_STATUS |
| ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode) |
| { |
| #if defined(INIT_MODE_DRV_ENABLED) && defined(CONFIG_HOST_TCMD_SUPPORT) |
| const char *filename; |
| const struct firmware *fw_entry; |
| #endif |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n")); |
| |
| if (mode == WLAN_INIT_MODE_UDEV) { |
| A_CHAR version[16]; |
| const struct firmware *fw_entry; |
| |
| /* Get config using udev through a script in user space */ |
| if (snprintf(version, sizeof(version), "%2.2x", |
| ar->arVersion.target_ver) >= sizeof(version)) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("snprintf: Target version-%2.2x\n", |
| ar->arVersion.target_ver)); |
| return A_ERROR; |
| } |
| if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version)); |
| return A_ERROR; |
| } |
| |
| A_RELEASE_FIRMWARE(fw_entry); |
| #ifdef INIT_MODE_DRV_ENABLED |
| } else { |
| /* The config is contained within the driver itself */ |
| A_STATUS status; |
| A_UINT32 param, options, sleep, address; |
| |
| /* Temporarily disable system sleep */ |
| address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_OFFSET; |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| options = param; |
| param |= AR6K_OPTION_SLEEP_DISABLE; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = RTC_WMAC_BASE_ADDRESS + WLAN_SYSTEM_SLEEP_OFFSET; |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| sleep = param; |
| param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1); |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep)); |
| |
| if (ar->arTargetType == TARGET_TYPE_MCKINLEY) { |
| /* Run at 40/44MHz by default */ |
| param = CPU_CLOCK_STANDARD_SET(0); |
| } else if (ar->arTargetType == TARGET_TYPE_AR6003) { |
| /* Program analog PLL register */ |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001)); |
| /* Run at 80/88MHz by default */ |
| param = CPU_CLOCK_STANDARD_SET(1); |
| } else { |
| /* Run at 40/44MHz by default */ |
| param = CPU_CLOCK_STANDARD_SET(0); |
| } |
| address = RTC_SOC_BASE_ADDRESS + CPU_CLOCK_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| param = 0; |
| if (ar->arTargetType == TARGET_TYPE_AR6002) { |
| bmifn(BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ext_clk_detected), |
| (A_UCHAR *)¶m, 4)); |
| } |
| |
| /* LPO_CAL.ENABLE = 1 if no external clk is detected */ |
| if (param != 1) { |
| address = RTC_SOC_BASE_ADDRESS + LPO_CAL_OFFSET; |
| param = LPO_CAL_ENABLE_SET(1); |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| } |
| |
| /* Venus2.0: Lower SDIO pad drive strength */ |
| if ((ar->arVersion.target_ver == AR6003_REV2_VERSION) || |
| (ar->arVersion.target_ver == AR6003_REV3_VERSION)) |
| { |
| param = 0x28; |
| address = GPIO_BASE_ADDRESS + GPIO_PIN9_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| param = 0x20; |
| address = GPIO_BASE_ADDRESS + GPIO_PIN10_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = GPIO_BASE_ADDRESS + GPIO_PIN11_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = GPIO_BASE_ADDRESS + GPIO_PIN12_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = GPIO_BASE_ADDRESS + GPIO_PIN13_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| } |
| |
| /* Change the clock with module parameter refclock Mhz */ |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, 0x540678, refClock)); |
| |
| #ifdef FORCE_INTERNAL_CLOCK |
| /* Ignore external clock, if any, and force use of internal clock */ |
| if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { |
| /* hi_ext_clk_detected = 0 */ |
| param = 0; |
| bmifn(BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ext_clk_detected), |
| (A_UCHAR *)¶m, 4)); |
| |
| /* CLOCK_CONTROL &= ~LF_CLK32 */ |
| address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS; |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| param &= (~CLOCK_CONTROL_LF_CLK32_SET(1)); |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| } |
| #endif /* FORCE_INTERNAL_CLOCK */ |
| |
| /* Transfer Board Data from Target EEPROM to Target RAM */ |
| if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { |
| /* Determine where in Target RAM to write Board Data */ |
| bmifn(BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data), |
| (A_UCHAR *)&address, 4)); |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address)); |
| |
| /* Write EEPROM data to Target RAM */ |
| if ((status=ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, FALSE)) != A_OK) { |
| return A_ERROR; |
| } |
| |
| /* Record the fact that Board Data IS initialized */ |
| param = 1; |
| bmifn(BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data_initialized), |
| (A_UCHAR *)¶m, 4)); |
| |
| /* Transfer One time Programmable data */ |
| AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); |
| if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| address = BMI_SEGMENTED_WRITE_ADDR; |
| } |
| status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, TRUE); |
| if (status == A_OK) { |
| /* Execute the OTP code */ |
| #ifdef SOFTMAC_FILE_USED |
| param = 1; |
| #else |
| param = 0; |
| #endif |
| |
| #ifdef SOFTMAC_USED |
| param = 1; |
| #else |
| param = 0; |
| #endif |
| |
| if (regcode != 0) |
| param |= 0x2; |
| AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); |
| bmifn(BMIExecute(ar->arHifDevice, address, ¶m)); |
| } else if (status != A_ENOENT) { |
| return A_ERROR; |
| } |
| } else { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType)); |
| return A_ERROR; |
| } |
| |
| /* Download Target firmware */ |
| AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); |
| if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| address = BMI_SEGMENTED_WRITE_ADDR; |
| } |
| if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, TRUE)) != A_OK) { |
| return A_ERROR; |
| } |
| |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) |
| { |
| /* Set starting address for firmware */ |
| AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); |
| bmifn(BMISetAppStart(ar->arHifDevice, address)); |
| } |
| |
| /* Apply the patches */ |
| if (ar->arTargetType == TARGET_TYPE_AR6003) { |
| AR6K_DATASET_PATCH_ADDRESS(address, ar->arVersion.target_ver); |
| if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, FALSE)) != A_OK) { |
| return A_ERROR; |
| } |
| param = address; |
| bmifn(BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dset_list_head), |
| (A_UCHAR *)¶m, 4)); |
| } |
| |
| /* Restore system sleep */ |
| address = RTC_WMAC_BASE_ADDRESS + WLAN_SYSTEM_SLEEP_OFFSET; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep)); |
| |
| address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_OFFSET; |
| param = options | 0x20; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| if (ar->arTargetType == TARGET_TYPE_AR6003 || ar->arTargetType == TARGET_TYPE_MCKINLEY) { |
| /* Configure GPIO AR6003 UART */ |
| #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN |
| #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8 |
| #endif |
| param = CONFIG_AR600x_DEBUG_UART_TX_PIN; |
| bmifn(BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_dbg_uart_txpin), |
| (A_UCHAR *)¶m, 4)); |
| |
| #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23) |
| if (ATH_REGISTER_SUPPORTED_BY_TARGET(CLOCK_GPIO_OFFSET)) { |
| address = GPIO_BASE_ADDRESS + CLOCK_GPIO_OFFSET; |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1); |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| } else { |
| /* AR6004 has no need for a CLOCK_GPIO register */ |
| } |
| #endif |
| |
| /* Configure GPIO for BT Reset */ |
| #ifdef ATH6KL_CONFIG_GPIO_BT_RESET |
| #define CONFIG_AR600x_BT_RESET_PIN 0x16 |
| param = CONFIG_AR600x_BT_RESET_PIN; |
| bmifn(BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_hci_uart_support_pins), |
| (A_UCHAR *)¶m, 4)); |
| #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */ |
| |
| /* Configure UART flow control polarity */ |
| #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY |
| #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0 |
| #endif |
| |
| #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1) |
| if ((ar->arVersion.target_ver == AR6003_REV2_VERSION) || |
| (ar->arVersion.target_ver == AR6003_REV3_VERSION)) |
| { |
| param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2); |
| bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (A_UCHAR *)¶m, 4)); |
| } |
| #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */ |
| } |
| #ifdef HTC_RAW_INTERFACE |
| if (!eppingtest && bypasswmi) { |
| /* Don't run BMIDone for ART mode and force resetok=0 */ |
| resetok = 0; |
| msleep(1000); |
| param = 1; |
| status = BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_data_initialized), |
| (A_UCHAR *)¶m, 4); |
| } |
| #endif /* HTC_RAW_INTERFACE */ |
| |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| if (testmode == 2) { |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| filename = AR6003_REV2_UTF_FIRMWARE_FILE; |
| if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); |
| return A_ENOENT; |
| } |
| /* Download Target firmware */ |
| AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); |
| |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz); |
| param = 11008; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = 0x57D884; |
| filename = AR6003_REV2_TESTSCRIPT_FILE; |
| if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); |
| return A_ENOENT; |
| } |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); |
| |
| param = 0x57D884; |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ota_testscript); |
| bmifn(BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)¶m, 4)); |
| |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_test_apps_related); |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| param |= 1; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| A_RELEASE_FIRMWARE(fw_entry); |
| } |
| else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { |
| filename = AR6003_REV3_UTF_FIRMWARE_FILE; |
| if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); |
| return A_ENOENT; |
| } |
| /* Download Target firmware */ |
| address = BMI_SEGMENTED_WRITE_ADDR; |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); |
| |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz); |
| param = 4096; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| address = 0x57EF74; |
| filename = AR6003_REV3_TESTSCRIPT_FILE; |
| if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); |
| return A_ENOENT; |
| } |
| status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry->size); |
| |
| param = 0x57EF74; |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_ota_testscript); |
| bmifn(BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)¶m, 4)); |
| |
| address = HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_test_apps_related); |
| bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); |
| param |= 1; |
| bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); |
| |
| A_RELEASE_FIRMWARE(fw_entry); |
| } |
| } |
| #endif |
| #endif /* INIT_MODE_DRV_ENABLED */ |
| } |
| |
| return A_OK; |
| } |
| |
| A_STATUS |
| ar6000_configure_target(AR_SOFTC_T *ar) |
| { |
| A_UINT32 param; |
| if (enableuartprint) { |
| param = 1; |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_serial_enable), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n")); |
| } |
| |
| /* Tell target which HTC version it is used*/ |
| param = HTC_PROTOCOL_VERSION; |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_app_host_interest), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n")); |
| return A_ERROR; |
| } |
| |
| if (enabletimerwar) { |
| A_UINT32 param; |
| |
| if (BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n")); |
| return A_ERROR; |
| } |
| |
| param |= HI_OPTION_TIMER_WAR; |
| |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n")); |
| } |
| |
| /* set the firmware mode to STA/IBSS/AP */ |
| { |
| A_UINT32 param; |
| |
| if (BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n")); |
| return A_ERROR; |
| } |
| |
| param |= (num_device << HI_OPTION_NUM_DEV_SHIFT); |
| param |= (fwmode << HI_OPTION_FW_MODE_SHIFT); |
| param |= (mac_addr_method << HI_OPTION_MAC_ADDR_METHOD_SHIFT); |
| param |= (firmware_bridge << HI_OPTION_FW_BRIDGE_SHIFT); |
| param |= (fwsubmode << HI_OPTION_FW_SUBMODE_SHIFT); |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("NUM_DEV=%d FWMODE=0x%x FWSUBMODE=0x%x FWBR_BUF %d\n", |
| num_device, fwmode, fwsubmode, firmware_bridge)); |
| |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); |
| } |
| #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS |
| { |
| A_UINT32 param; |
| |
| if (BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n")); |
| return A_ERROR; |
| } |
| |
| param |= HI_OPTION_DISABLE_DBGLOG; |
| |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); |
| } |
| #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */ |
| |
| if (regscanmode) { |
| A_UINT32 param; |
| |
| if (BMIReadMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4)!= A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting regscanmode failed\n")); |
| return A_ERROR; |
| } |
| |
| if (regscanmode == 1) { |
| param |= HI_OPTION_SKIP_REG_SCAN; |
| } else if (regscanmode == 2) { |
| param |= HI_OPTION_INIT_REG_SCAN; |
| } |
| |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_option_flag), |
| (A_UCHAR *)¶m, |
| 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting regscanmode failed\n")); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Regulatory scan mode set\n")); |
| } |
| |
| /* |
| * Hardcode the address use for the extended board data |
| * Ideally this should be pre-allocate by the OS at boot time |
| * But since it is a new feature and board data is loaded |
| * at init time, we have to workaround this from host. |
| * It is difficult to patch the firmware boot code, |
| * but possible in theory. |
| */ |
| if (ar->arTargetType == TARGET_TYPE_AR6003) { |
| A_UINT32 ramReservedSz; |
| if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { |
| param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS; |
| ramReservedSz = AR6003_REV2_RAM_RESERVE_SIZE; |
| } else { |
| param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS; |
| if (testmode) { |
| ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE_TCMD; |
| } else { |
| ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE; |
| } |
| } |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_board_ext_data), |
| (A_UCHAR *)¶m, |
| 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n")); |
| return A_ERROR; |
| } |
| if (BMIWriteMemory(ar->arHifDevice, |
| HOST_INTEREST_ITEM_ADDRESS(ar->arTargetType, hi_end_RAM_reserve_sz), |
| (A_UCHAR *)&ramReservedSz, 4) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_end_RAM_reserve_sz failed \n")); |
| return A_ERROR; |
| } |
| } |
| |
| |
| /* since BMIInit is called in the driver layer, we have to set the block |
| * size here for the target */ |
| |
| if (A_FAILED(ar6000_set_htc_params(ar->arHifDevice, |
| ar->arTargetType, |
| mbox_yield_limit, |
| 0 /* use default number of control buffers */ |
| ))) { |
| return A_ERROR; |
| } |
| |
| if (setupbtdev != 0) { |
| if (A_FAILED(ar6000_set_hci_bridge_flags(ar->arHifDevice, |
| ar->arTargetType, |
| setupbtdev))) { |
| return A_ERROR; |
| } |
| } |
| |
| return A_OK; |
| } |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
| static void ar6000_ethtool_get_drvinfo(struct net_device *dev, |
| struct ethtool_drvinfo *info) |
| { |
| A_STATUS status; |
| HIF_DEVICE_OS_DEVICE_INFO osDevInfo; |
| AR_SOFTC_T *ar; |
| AR_SOFTC_DEV_T *arPriv; |
| struct ar6000_version *revinfo; |
| if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { |
| return; |
| } |
| ar = arPriv->arSoftc; |
| revinfo = &ar->arVersion; |
| strcpy(info->driver, "AR6000"); |
| snprintf(info->version, sizeof(info->version), "%u.%u.%u.%u", |
| ((revinfo->host_ver)&0xf0000000)>>28, |
| ((revinfo->host_ver)&0x0f000000)>>24, |
| ((revinfo->host_ver)&0x00ff0000)>>16, |
| ((revinfo->host_ver)&0x0000ffff)); |
| snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u.%u", |
| ((revinfo->wlan_ver)&0xf0000000)>>28, |
| ((revinfo->wlan_ver)&0x0f000000)>>24, |
| ((revinfo->wlan_ver)&0x00ff0000)>>16, |
| ((revinfo->wlan_ver)&0x0000ffff)); |
| |
| status = HIFConfigureDevice(ar->arHifDevice, |
| HIF_DEVICE_GET_OS_DEVICE, |
| &osDevInfo, |
| sizeof(HIF_DEVICE_OS_DEVICE_INFO)); |
| if (A_SUCCESS(status) && osDevInfo.pOSDevice) { |
| struct device *dev = (struct device*)osDevInfo.pOSDevice; |
| if (dev->bus && dev->bus->name) { |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
| const char *dinfo = dev_name(dev); |
| #else |
| const char *dinfo = kobject_name(&dev->kobj); |
| #endif |
| snprintf(info->bus_info, sizeof(info->bus_info), dinfo); |
| } |
| } |
| } |
| |
| static u32 ar6000_ethtool_get_link(struct net_device *dev) |
| { |
| AR_SOFTC_DEV_T *arPriv; |
| return ((arPriv = ar6k_priv(dev))!=NULL) ? arPriv->arConnected : 0; |
| } |
| |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| static u32 ar6000_ethtool_get_rx_csum(struct net_device *dev) |
| { |
| AR_SOFTC_DEV_T *arPriv; |
| if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { |
| return 0; |
| } |
| return (arPriv->arSoftc->rxMetaVersion==WMI_META_VERSION_2); |
| } |
| |
| static int ar6000_ethtool_set_rx_csum(struct net_device *dev, u32 enable) |
| { |
| AR_SOFTC_T *ar; |
| AR_SOFTC_DEV_T *arPriv; |
| A_UINT8 metaVersion; |
| if((dev == NULL) || ((arPriv = ar6k_priv(dev)) == NULL)) { |
| return -EIO; |
| } |
| ar = arPriv->arSoftc; |
| if (ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED) { |
| return -EIO; |
| } |
| metaVersion = (enable) ? WMI_META_VERSION_2 : 0; |
| if ((wmi_set_rx_frame_format_cmd(arPriv->arWmi, metaVersion, processDot11Hdr, processDot11Hdr)) != A_OK) { |
| return -EFAULT; |
| } |
| ar->rxMetaVersion = metaVersion; |
| return 0; |
| } |
| |
| static u32 ar6000_ethtool_get_tx_csum(struct net_device *dev) |
| { |
| return csumOffload; |
| } |
| |
| static int ar6000_ethtool_set_tx_csum(struct net_device *dev, u32 enable) |
| { |
| csumOffload = enable; |
| if(enable){ |
| dev->features |= NETIF_F_IP_CSUM; |
| } else { |
| dev->features &= ~NETIF_F_IP_CSUM; |
| } |
| return 0; |
| } |
| #endif /* CONFIG_CHECKSUM_OFFLOAD */ |
| |
| static const struct ethtool_ops ar6000_ethtool_ops = { |
| .get_drvinfo = ar6000_ethtool_get_drvinfo, |
| .get_link = ar6000_ethtool_get_link, |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| .get_rx_csum = ar6000_ethtool_get_rx_csum, |
| .set_rx_csum = ar6000_ethtool_set_rx_csum, |
| .get_tx_csum = ar6000_ethtool_get_tx_csum, |
| .set_tx_csum = ar6000_ethtool_set_tx_csum, |
| #endif /* CONFIG_CHECKSUM_OFFLOAD */ |
| }; |
| #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */ |
| |
| /* |
| * HTC Event handlers |
| */ |
| static A_STATUS |
| ar6000_avail_ev(void *context, void *hif_handle) |
| { |
| int i; |
| struct net_device *dev; |
| void *ar_netif; |
| AR_SOFTC_T *ar=NULL; |
| AR_SOFTC_DEV_T *arPriv; |
| int device_index = 0; |
| HTC_INIT_INFO htcInfo; |
| #ifdef ATH6K_CONFIG_CFG80211 |
| struct wireless_dev *wdev; |
| #endif /* ATH6K_CONFIG_CFG80211 */ |
| A_STATUS init_status = A_OK; |
| unsigned char devnum = 0; |
| unsigned char cnt = 0; |
| #ifdef SET_NETDEV_DEV |
| HIF_DEVICE_OS_DEVICE_INFO osDevInfo; |
| A_MEMZERO(&osDevInfo, sizeof(osDevInfo)); |
| if (A_OK != HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE, |
| &osDevInfo, sizeof(osDevInfo))) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Failed to get OS device instance\n", |
| __func__)); |
| return A_ERROR; |
| } |
| #endif |
| /* |
| * If ar6000_avail_ev is called more than once, this means that |
| * multiple AR600x devices have been inserted into the system. |
| * We do not support more than one AR600x device at this time. |
| */ |
| if (avail_ev_called) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ERROR: More than one AR600x device not supported by driver\n")); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| |
| avail_ev_called = TRUE; |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n")); |
| |
| |
| |
| ar = A_MALLOC(sizeof(AR_SOFTC_T)); |
| |
| if (ar == NULL) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR_SOFTC: can not allocate\n")); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| A_MEMZERO(ar, sizeof(AR_SOFTC_T)); |
| |
| #ifdef ATH_AR6K_11N_SUPPORT |
| if(aggr_init(ar6000_alloc_netbufs, ar6000_deliver_frames_to_nw_stack) != A_OK) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__)); |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| #endif |
| |
| A_MEMZERO((A_UINT8 *)ar->connTbl, NUM_CONN * sizeof(conn_t)); |
| /* Init the PS queues */ |
| for (i=0; i < NUM_CONN ; i++) { |
| #ifdef ATH_AR6K_11N_SUPPORT |
| if ((ar->connTbl[i].conn_aggr = aggr_init_conn()) == NULL) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s() Failed to initialize aggr.\n", __func__)); |
| A_FREE(ar); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| #endif |
| A_MUTEX_INIT(&ar->connTbl[i].psqLock); |
| A_NETBUF_QUEUE_INIT(&ar->connTbl[i].psq); |
| A_NETBUF_QUEUE_INIT(&ar->connTbl[i].apsdq); |
| } |
| if (ifname[0] == '\0') |
| strcpy(ifname, "wlan0"); |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| if(ifname[0]) { |
| for(i = 0; i < strlen(ifname); i++) { |
| if(ifname[i] >= '0' && ifname[i] <= '9' ) { |
| devnum = (devnum * 10) + (ifname[i] - '0'); |
| } |
| else { |
| cnt++; |
| } |
| } |
| ifname[cnt]='\0'; |
| } |
| #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ |
| ar->arConfNumDev = num_device; |
| for (i=0; i < num_device; i++) { |
| |
| if (ar6000_devices[i] != NULL) { |
| break; |
| } |
| |
| /* Save this. It gives a bit better readability especially since */ |
| /* we use another local "i" variable below. */ |
| device_index = i; |
| |
| #ifdef ATH6K_CONFIG_CFG80211 |
| #ifdef SET_NETDEV_DEV |
| wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice); |
| #else |
| wdev = ar6k_cfg80211_init(NULL); |
| #endif |
| |
| if (IS_ERR(wdev)) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__)); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| ar_netif = wdev_priv(wdev); |
| #else |
| dev = alloc_etherdev(sizeof(AR_SOFTC_DEV_T)); |
| if (dev == NULL) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n")); |
| A_FREE(ar); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| ether_setup(dev); |
| ar_netif = ar6k_priv(dev); |
| #endif /* ATH6K_CONFIG_CFG80211 */ |
| |
| if (ar_netif == NULL) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__)); |
| A_FREE(ar); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| |
| A_MEMZERO(ar_netif, sizeof(AR_SOFTC_DEV_T)); |
| arPriv = (AR_SOFTC_DEV_T *)ar_netif; |
| |
| #ifdef ATH6K_CONFIG_CFG80211 |
| arPriv->wdev = wdev; |
| wdev->iftype = NL80211_IFTYPE_STATION; |
| |
| dev = alloc_netdev_mq(0, "wlan%d", ether_setup, NUM_SUBQUEUE); |
| if (!dev) { |
| printk(KERN_CRIT "AR6K: no memory for network device instance\n"); |
| ar6k_cfg80211_deinit(arPriv); |
| A_FREE(ar); |
| return A_ERROR; |
| } |
| |
| dev->ieee80211_ptr = wdev; |
| SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy)); |
| wdev->netdev = dev; |
| arPriv->arNetworkType = INFRA_NETWORK; |
| #endif /* ATH6K_CONFIG_CFG80211 */ |
| |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
| if (ifname[0]) |
| { |
| sprintf(dev->name, "%s%d", ifname,(devnum + device_index)); |
| } |
| #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */ |
| |
| #ifdef SET_MODULE_OWNER |
| SET_MODULE_OWNER(dev); |
| #endif |
| |
| #ifdef SET_NETDEV_DEV |
| #if 0 |
| if (ar_netif) { |
| HIF_DEVICE_OS_DEVICE_INFO osDevInfo; |
| A_MEMZERO(&osDevInfo, sizeof(osDevInfo)); |
| if ( A_SUCCESS( HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE, |
| &osDevInfo, sizeof(osDevInfo))) ) { |
| SET_NETDEV_DEV(dev, osDevInfo.pOSDevice); |
| } |
| } |
| #endif |
| #endif |
| |
| arPriv->arNetDev = dev; |
| ar6000_devices[device_index] = dev; |
| arPriv->arSoftc = ar; |
| ar->arDev[device_index] = arPriv; |
| ar->arWlanState = WLAN_ENABLED; |
| arPriv->arDeviceIndex = device_index; |
| |
| ar->arWlanPowerState = WLAN_POWER_STATE_ON; |
| |
| #ifndef ATH6K_CONFIG_CFG80211 |
| #ifdef SET_NETDEV_DEV |
| SET_NETDEV_DEV(dev, osDevInfo.pOSDevice); |
| #endif |
| #endif |
| |
| if(ar6000_init_control_info(arPriv) != A_OK) { |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| init_waitqueue_head(&arPriv->arEvent); |
| |
| #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL |
| A_INIT_TIMER(&aptcTimer[i], aptcTimerHandler, ar); |
| #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ |
| |
| spin_lock_init(&arPriv->arPrivLock); |
| |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) |
| dev->open = &ar6000_open; |
| dev->stop = &ar6000_close; |
| dev->hard_start_xmit = &ar6000_data_tx; |
| dev->get_stats = &ar6000_get_stats; |
| |
| /* dev->tx_timeout = ar6000_tx_timeout; */ |
| dev->do_ioctl = &ar6000_ioctl; |
| dev->set_multicast_list = &ar6000_set_multicast_list; |
| #else |
| dev->netdev_ops = &ar6000_netdev_ops; |
| #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ |
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
| dev->ethtool_ops = &ar6000_ethtool_ops; |
| #endif |
| dev->watchdog_timeo = AR6000_TX_TIMEOUT; |
| dev->wireless_handlers = &ath_iw_handler_def; |
| |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) |
| dev->get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ |
| #else |
| ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ |
| #endif |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| if(csumOffload){ |
| |
| dev->features |= NETIF_F_IP_CSUM;/*advertise kernel capability |
| to do TCP/UDP CSUM offload for IPV4*/ |
| } |
| #endif |
| if (processDot11Hdr) { |
| dev->hard_header_len = sizeof(struct ieee80211_qosframe) + sizeof(ATH_LLC_SNAP_HDR) + sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR; |
| } else { |
| /* |
| * We need the OS to provide us with more headroom in order to |
| * perform dix to 802.3, WMI header encap, and the HTC header |
| */ |
| dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) + |
| sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR; |
| } |
| |
| if (!bypasswmi && !eppingtest) |
| { |
| /* Indicate that WMI is enabled (although not ready yet) */ |
| arPriv->arWmiEnabled = TRUE; |
| if ((arPriv->arWmi = wmi_init((void *) arPriv,arPriv->arDeviceIndex)) == NULL) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__)); |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s() Got WMI @ 0x%08x.\n", __func__, |
| (unsigned int) arPriv->arWmi)); |
| } |
| #ifdef P2P |
| /* Allocate P2P module context if this dev is in any of the P2P modes. |
| * For non-P2P devices, this may be allocated just in time when the |
| * device assumes a P2P submode. This may be needed when we do |
| * mode switch between none and P2P submodes. For later enhancement. |
| */ |
| if (arPriv->arNetworkSubType == SUBTYPE_P2PDEV || |
| arPriv->arNetworkSubType == SUBTYPE_P2PCLIENT || |
| arPriv->arNetworkSubType == SUBTYPE_P2PGO) { |
| arPriv->p2p_ctx = p2p_init(arPriv); |
| if (arPriv->p2p_ctx == NULL) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize p2p_ctx.\n", __func__)); |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| p2p_update_capability(A_WMI_GET_P2P_CTX(arPriv),arPriv->arNetworkSubType,num_device); |
| } |
| #endif /* P2P */ |
| } |
| |
| #ifdef CONFIG_HOST_TCMD_SUPPORT |
| if(testmode) { |
| ar->arTargetMode = AR6000_TCMD_MODE; |
| }else { |
| ar->arTargetMode = AR6000_WLAN_MODE; |
| } |
| #endif |
| ar->arWlanOff = FALSE; /* We are in ON state */ |
| #ifdef CONFIG_PM |
| ar->arWowState = WLAN_WOW_STATE_NONE; |
| ar->arBTOff = TRUE; /* BT chip assumed to be OFF */ |
| ar->arBTSharing = WLAN_CONFIG_BT_SHARING; |
| ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF; |
| ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND; |
| ar->arWow2Config = WLAN_CONFIG_PM_WOW2; |
| #endif /* CONFIG_PM */ |
| |
| A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, ar); |
| ar->arHBChallengeResp.seqNum = 0; |
| ar->arHBChallengeResp.outstanding = FALSE; |
| ar->arHBChallengeResp.missCnt = 0; |
| ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT; |
| ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT; |
| ar->arHifDevice = hif_handle; |
| sema_init(&ar->arSem, 1); |
| ar->bIsDestroyProgress = FALSE; |
| |
| ar->delbaState = REASON_DELBA_INIT; |
| ar->IsdelbaTimerInitialized = FALSE; |
| A_INIT_TIMER (&ar->delbaTimer, delba_timer_callback, ar); |
| |
| ar->isHostAsleep = 0; |
| |
| INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue); |
| /* |
| * If requested, perform some magic which requires no cooperation from |
| * the Target. It causes the Target to ignore flash and execute to the |
| * OS from ROM. |
| * |
| * This is intended to support recovery from a corrupted flash on Targets |
| * that support flash. |
| */ |
| if (skipflash) |
| { |
| //ar6000_reset_device_skipflash(ar->arHifDevice); |
| } |
| |
| BMIInit(); |
| |
| if (bmienable) { |
| ar6000_sysfs_bmi_init(ar); |
| } |
| |
| { |
| struct bmi_target_info targ_info; |
| A_MEMZERO(&targ_info, sizeof(targ_info)); |
| if (BMIGetTargetInfo(ar->arHifDevice, &targ_info) != A_OK) { |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| |
| ar->arVersion.target_ver = targ_info.target_ver; |
| ar->arTargetType = targ_info.target_type; |
| |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s() TARGET TYPE: %d\n", __func__,ar->arTargetType)); |
| target_register_tbl_attach(ar->arTargetType); |
| |
| /* do any target-specific preparation that can be done through BMI */ |
| if (ar6000_prepare_target(ar->arHifDevice, |
| targ_info.target_type, |
| targ_info.target_ver) != A_OK) { |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| |
| } |
| if (ar6000_configure_target(ar) != A_OK) { |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| |
| A_MEMZERO(&htcInfo,sizeof(htcInfo)); |
| htcInfo.pContext = ar; |
| htcInfo.TargetFailure = ar6000_target_failure; |
| |
| ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo); |
| |
| if (ar->arHtcTarget == NULL) { |
| init_status = A_ERROR; |
| goto avail_ev_failed; |
| } |
| |
| spin_lock_init(&ar->arLock); |
| |
| #ifdef CONFIG_CHECKSUM_OFFLOAD |
| if(csumOffload){ |
| |
| ar->rxMetaVersion=WMI_META_VERSION_2;/*if external frame work is also needed, change and use an extended rxMetaVerion*/ |
| } |
| #endif |
| |
| HIFClaimDevice(ar->arHifDevice, ar); |
| |
| if (bmienable) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); |
| if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || |
| (wlaninitmode == WLAN_INIT_MODE_DRV)) |
| { |
| A_STATUS status = A_OK; |
| do { |
| if ((status = ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK) |
| { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); |
| break; |
| } |
| |
| dev = ar6000_devices[0]; |
| #ifdef HTC_RAW_INTERFACE |
| if (!eppingtest && bypasswmi) { |
| break; /* Don't call ar6000_init for ART */ |
| } |
| #endif |
| status = (ar6000_init(dev)==0) ? A_OK : A_ERROR; |
| if (status != A_OK) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n")); |
| } |
| } while (FALSE); |
| |
| if (status != A_OK) { |
| init_status = status; |
| goto avail_ev_failed; |
| } |
| } |
| } |
| #ifdef CONFIG_PM |
| init_waitqueue_head(&ar->sleep_mode_cmd_completed_event); |
| #endif |
| for (i=0; i < num_device; i++) |
| { |
| dev = ar6000_devices[i]; |
| arPriv = ar6k_priv(dev); |
| ar = arPriv->arSoftc; |
| |
| /* Don't install the init function if BMI is requested */ |
| if (!bmienable) { |
| #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) |
| dev->init = ar6000_init; |
| #else |
| ar6000_netdev_ops.ndo_init = ar6000_init; |
| #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ |
| } |
| |
| /* This runs the init function if registered */ |
| if (register_netdev(dev)) { |
| AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("ar6000_avail: register_netdev failed\n")); |
| ar6000_cleanup(ar); |
| ar6000_devices[i] = NULL; |
| ar6000_destroy(dev, 0); |
| complete(&avail_ev_completion); |
| return A_ERROR; |
| } |
| AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n", |
| dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index, |
| (unsigned long)ar)); |
| |
| } |
| |
| avail_ev_failed : |
| if (A_FAILED(init_status)) { |
| if (bmienable) { |
| ar6000_sysfs_bmi_deinit(ar); |
| } |
| for (i=0; i < num_device; i++) |
| { |
| dev = ar6000_devices[i]; |
| arPriv = (AR_SOFTC_DEV_T *)ar6k_priv(dev); |
| if(arPriv->arWmiEnabled == TRUE) |
| { |
| wmi_shutdown(arPriv->arWmi); |
| arPriv->arWmiEnabled = FALSE; |
| } |
| ar6000_devices[i] = NULL; |
| } |
| A_FREE(ar); |
| } |
| complete(&avail_ev_completion); |
| |
| mod_loaded = TRUE; |
| wake_up_interruptible(&load_complete); |
| |
| printk("Completed loading the module %s\n", __func__); |
| return init_status; |
| } |
| |
| static void ar6000_target_failure(void *Instance, A_STATUS Status) |
| { |
| AR_SOFTC_T *ar = (AR_SOFTC_T *)Instance; |
| WMI_TARGET_ERROR_REPORT_EVENT errEvent; |
| static A_BOOL sip = FALSE; |
| A_UINT8 i; |
| |
| if (Status != A_OK) { |
| |
| printk(KERN_ERR "ar6000_target_failure: target asserted \n"); |
| |
| if (timer_pending(&ar->arHBChallengeResp.timer)) { |
| A_UNTIMEOUT(&ar->arHBChallengeResp.timer); |
| } |
| |
| /* try dumping target assertion information (if any) */ |
| ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType); |
| |
| /* |
| * Fetch the logs from the target via the diagnostic |
| * window. |
| */ |
| ar6000_dbglog_get_debug_logs(ar); |
| |
| /* Report the error only once */ |
| if (!sip) { |
| sip = TRUE; |
| errEvent.errorVal = WMI_TARGET_COM_ERR | |
| WMI_TARGET_FATAL_ERR; |
| for(i = 0; i < num_device; i++) |
| { |
| |
| ar6000_send_event_to_app(ar->arDev[i], WMI_ERROR_REPORT_EVENTID, |
| (A_UINT8 *)&errEvent, |
| sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); |
| |
| } |
| } |
| } |
| } |
| |
| static A_STATUS |
| ar6000_unavail_ev(void *context, void *hif_handle) |
| { |
| unsigned int old_reset_ok = resetok; |
| A_UINT8 i; |
| struct net_device *ar6000_netdev; |
| AR_SOFTC_T *ar = (AR_SOFTC_T*)context; |
| resetok = 0; /* card is remove, don't reset */ |
| ar6000_cleanup(ar); |
| resetok = old_reset_ok; |
| /* NULL out it's entry in the global list */ |
| for(i = 0; i < num_device; i++) { |
| ar6000_netdev = ar6000_devices[i]; |
| ar6000_devices[i] = NULL; |
| ar6000_destroy(ar6000_netdev, 1); |
| } |
| |
| return A_OK; |
| } |
| |
| /* |
| * EV93295 Kernel panic "cannot create duplicate filename 'bmi'" |
| */ |
| A_BOOL restart_endpoint_called = FALSE; |
| |
| void |
| ar6000_restart_endpoint(AR_SOFTC_T *ar) |
|