xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/ssv6xxx/smac/init.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2015 South Silicon Valley Microelectronics Inc.
3  * Copyright (c) 2015 iComm Corporation
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/nl80211.h>
20 #include <linux/kthread.h>
21 #include <linux/etherdevice.h>
22 #include <linux/version.h>
23 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
24 #include <crypto/hash.h>
25 #else
26 #include <linux/crypto.h>
27 #endif
28 #include <ssv6200.h>
29 #include <hci/hctrl.h>
30 #include <ssv_version.h>
31 #include <ssv_firmware_version.h>
32 #include "dev_tbl.h"
33 #include "dev.h"
34 #include "lib.h"
35 #include "ssv_rc.h"
36 #include "ap.h"
37 #include "efuse.h"
38 #include "sar.h"
39 #include "ssv_cfgvendor.h"
40 
41 #ifdef CONFIG_SSV_SUPPORT_ANDROID
42 #include "ssv_pm.h"
43 #endif
44 #include "linux_80211.h"
45 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
46 #include "linux_2_6_35.h"
47 #endif
48 #ifdef CONFIG_SSV6XXX_DEBUGFS
49 #include "ssv6xxx_debugfs.h"
50 #endif
51 #ifdef MULTI_THREAD_ENCRYPT
52 #include <linux/cpu.h>
53 #include <linux/notifier.h>
54 #endif
55 MODULE_AUTHOR("iComm Semiconductor Co., Ltd");
56 MODULE_DESCRIPTION("Support for SSV6xxx wireless LAN cards.");
57 MODULE_SUPPORTED_DEVICE("SSV6xxx 802.11n WLAN cards");
58 MODULE_LICENSE("Dual BSD/GPL");
59 #define WIFI_FIRMWARE_NAME "ssv6051-sw.bin"
60 static const struct ieee80211_iface_limit ssv6xxx_p2p_limits[] = {
61  {
62   .max = 2,
63   .types = BIT(NL80211_IFTYPE_STATION),
64  },
65  {
66   .max = 1,
67   .types = BIT(NL80211_IFTYPE_P2P_GO) |
68        BIT(NL80211_IFTYPE_P2P_CLIENT) |
69     BIT(NL80211_IFTYPE_AP),
70  },
71 };
72 static const struct ieee80211_iface_combination
73 ssv6xxx_iface_combinations_p2p[] = {
74  { .num_different_channels = 1,
75    .max_interfaces = SSV6200_MAX_VIF,
76    .beacon_int_infra_match = true,
77    .limits = ssv6xxx_p2p_limits,
78    .n_limits = ARRAY_SIZE(ssv6xxx_p2p_limits),
79  },
80 };
81 #define LBYTESWAP(a) ((((a) & 0x00ff00ff) << 8) | \
82     (((a) & 0xff00ff00) >> 8))
83 #define LONGSWAP(a) ((LBYTESWAP(a) << 16) | (LBYTESWAP(a) >> 16))
84 #define CHAN2G(_freq,_idx) { \
85     .band = INDEX_80211_BAND_2GHZ, \
86     .center_freq = (_freq), \
87     .hw_value = (_idx), \
88     .max_power = 20, \
89 }
90 #ifndef WLAN_CIPHER_SUITE_SMS4
91 #define WLAN_CIPHER_SUITE_SMS4 0x00147201
92 #endif
93 #define SHPCHECK(__hw_rate,__flags) \
94     ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate +3 ) : 0)
95 #define RATE(_bitrate,_hw_rate,_flags) { \
96     .bitrate = (_bitrate), \
97     .flags = (_flags), \
98     .hw_value = (_hw_rate), \
99     .hw_value_short = SHPCHECK(_hw_rate,_flags) \
100 }
101 extern struct ssv6xxx_cfg ssv_cfg;
102 static const struct ieee80211_channel ssv6200_2ghz_chantable[] =
103 {
104     CHAN2G(2412, 1 ),
105     CHAN2G(2417, 2 ),
106     CHAN2G(2422, 3 ),
107     CHAN2G(2427, 4 ),
108     CHAN2G(2432, 5 ),
109     CHAN2G(2437, 6 ),
110     CHAN2G(2442, 7 ),
111     CHAN2G(2447, 8 ),
112     CHAN2G(2452, 9 ),
113     CHAN2G(2457, 10),
114     CHAN2G(2462, 11),
115     CHAN2G(2467, 12),
116     CHAN2G(2472, 13),
117     CHAN2G(2484, 14),
118 };
119 static struct ieee80211_rate ssv6200_legacy_rates[] =
120 {
121     RATE(10, 0x00, 0),
122     RATE(20, 0x01, IEEE80211_RATE_SHORT_PREAMBLE),
123     RATE(55, 0x02, IEEE80211_RATE_SHORT_PREAMBLE),
124     RATE(110, 0x03, IEEE80211_RATE_SHORT_PREAMBLE),
125     RATE(60, 0x07, 0),
126     RATE(90, 0x08, 0),
127     RATE(120, 0x09, 0),
128     RATE(180, 0x0a, 0),
129     RATE(240, 0x0b, 0),
130     RATE(360, 0x0c, 0),
131     RATE(480, 0x0d, 0),
132     RATE(540, 0x0e, 0),
133 };
134 #ifdef CONFIG_SSV_SUPPORT_ANDROID
135 extern struct ssv_softc * ssv_notify_sc;
136 #endif
137 #ifdef CONFIG_SSV_CABRIO_E
138 struct ssv6xxx_ch_cfg ch_cfg_z[] = {
139  {ADR_ABB_REGISTER_1, 0, 0x151559fc},
140  {ADR_LDO_REGISTER, 0, 0x00eb7c1c},
141  {ADR_RX_ADC_REGISTER, 0, 0x20d000d2}
142 };
143 struct ssv6xxx_ch_cfg ch_cfg_p[] = {
144  {ADR_ABB_REGISTER_1, 0, 0x151559fc},
145  {ADR_RX_ADC_REGISTER, 0, 0x20d000d2}
146 };
ssv6xxx_do_iq_calib(struct ssv_hw * sh,struct ssv6xxx_iqk_cfg * p_cfg)147 int ssv6xxx_do_iq_calib(struct ssv_hw *sh, struct ssv6xxx_iqk_cfg *p_cfg)
148 {
149     struct sk_buff *skb;
150     struct cfg_host_cmd *host_cmd;
151     int ret = 0;
152     printk("# Do init_cali (iq)\n");
153     skb = ssv_skb_alloc(HOST_CMD_HDR_LEN + IQK_CFG_LEN + PHY_SETTING_SIZE + RF_SETTING_SIZE);
154     if(skb == NULL)
155     {
156         printk("init ssv6xxx_do_iq_calib fail!!!\n");
157         return (-1);
158     }
159     if((PHY_SETTING_SIZE > MAX_PHY_SETTING_TABLE_SIZE) ||
160         (RF_SETTING_SIZE > MAX_RF_SETTING_TABLE_SIZE))
161     {
162         printk("Please recheck RF or PHY table size!!!\n");
163         WARN_ON(1);
164         return (-1);
165     }
166     skb->data_len = HOST_CMD_HDR_LEN + IQK_CFG_LEN + PHY_SETTING_SIZE + RF_SETTING_SIZE;
167     skb->len = skb->data_len;
168     host_cmd = (struct cfg_host_cmd *)skb->data;
169     host_cmd->c_type = HOST_CMD;
170     host_cmd->h_cmd = (u8)SSV6XXX_HOST_CMD_INIT_CALI;
171     host_cmd->len = skb->data_len;
172     p_cfg->phy_tbl_size = PHY_SETTING_SIZE;
173     p_cfg->rf_tbl_size = RF_SETTING_SIZE;
174     memcpy(host_cmd->dat32, p_cfg, IQK_CFG_LEN);
175     memcpy(host_cmd->dat8+IQK_CFG_LEN, phy_setting, PHY_SETTING_SIZE);
176     memcpy(host_cmd->dat8+IQK_CFG_LEN+PHY_SETTING_SIZE, ssv6200_rf_tbl, RF_SETTING_SIZE);
177     sh->hci.hci_ops->hci_send_cmd(skb);
178     ssv_skb_free(skb);
179     {
180     u32 timeout;
181     sh->sc->iq_cali_done = IQ_CALI_RUNNING;
182     set_current_state(TASK_INTERRUPTIBLE);
183     timeout = wait_event_interruptible_timeout(sh->sc->fw_wait_q,
184                                                sh->sc->iq_cali_done,
185                                                msecs_to_jiffies(500));
186     set_current_state(TASK_RUNNING);
187     if (timeout == 0)
188         return -ETIME;
189     if (sh->sc->iq_cali_done != IQ_CALI_OK)
190         return (-1);
191     }
192     return ret;
193 }
194 #endif
195 #define HT_CAP_RX_STBC_ONE_STREAM 0x1
196 #ifdef CONFIG_SSV_WAPI
197 static const u32 ssv6xxx_cipher_suites[] = {
198     WLAN_CIPHER_SUITE_WEP40,
199     WLAN_CIPHER_SUITE_WEP104,
200     WLAN_CIPHER_SUITE_TKIP,
201     WLAN_CIPHER_SUITE_CCMP,
202     WLAN_CIPHER_SUITE_SMS4,
203     WLAN_CIPHER_SUITE_AES_CMAC
204 };
205 #endif
206 #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
207 static const struct wiphy_wowlan_support wowlan_support = {
208 #ifdef SSV_WAKEUP_HOST
209     .flags = WIPHY_WOWLAN_ANY,
210 #else
211     .flags = WIPHY_WOWLAN_DISCONNECT,
212 #endif
213     .n_patterns = 0,
214     .pattern_max_len = 0,
215     .pattern_min_len = 0,
216 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
217     .max_pkt_offset = 0,
218 #endif
219 };
220 #endif
ssv6xxx_set_80211_hw_capab(struct ssv_softc * sc)221 static void ssv6xxx_set_80211_hw_capab(struct ssv_softc *sc)
222 {
223     struct ieee80211_hw *hw=sc->hw;
224     struct ssv_hw *sh=sc->sh;
225     struct ieee80211_sta_ht_cap *ht_info;
226 #ifdef CONFIG_SSV_WAPI
227     hw->wiphy->cipher_suites = ssv6xxx_cipher_suites;
228     hw->wiphy->n_cipher_suites = ARRAY_SIZE(ssv6xxx_cipher_suites);
229 #endif
230 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
231     hw->flags = IEEE80211_HW_SIGNAL_DBM;
232 #else
233     ieee80211_hw_set(hw, SIGNAL_DBM);
234 #endif
235 #ifdef CONFIG_SSV_SUPPORT_ANDROID
236 #endif
237     hw->rate_control_algorithm = "ssv6xxx_rate_control";
238     ht_info = &sc->sbands[INDEX_80211_BAND_2GHZ].ht_cap;
239     ampdu_db_log("sh->cfg.hw_caps = 0x%x\n", sh->cfg.hw_caps);
240     if (sh->cfg.hw_caps & SSV6200_HW_CAP_HT) {
241         if (sh->cfg.hw_caps & SSV6200_HW_CAP_AMPDU_RX)
242         {
243 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
244             hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
245             ampdu_db_log("set IEEE80211_HW_AMPDU_AGGREGATION(0x%x)\n", ((hw->flags)&IEEE80211_HW_AMPDU_AGGREGATION));
246 #else
247             ieee80211_hw_set(hw, AMPDU_AGGREGATION);
248             ampdu_db_log("set IEEE80211_HW_AMPDU_AGGREGATION(%d)\n", ieee80211_hw_check(hw, AMPDU_AGGREGATION));
249 #endif
250         }
251         ht_info->cap = IEEE80211_HT_CAP_SM_PS;
252         if (sh->cfg.hw_caps & SSV6200_HW_CAP_GF) {
253             ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
254             ht_info->cap |= HT_CAP_RX_STBC_ONE_STREAM<<IEEE80211_HT_CAP_RX_STBC_SHIFT;
255         }
256         if (sh->cfg.hw_caps & SSV6200_HT_CAP_SGI_20)
257             ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
258         ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_32K;
259         ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
260         memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
261         ht_info->mcs.rx_mask[0] = 0xff;
262         ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
263      ht_info->mcs.rx_highest = cpu_to_le16(SSV6200_RX_HIGHEST_RATE);
264         ht_info->ht_supported = true;
265     }
266     hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
267 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
268     if (sh->cfg.hw_caps & SSV6200_HW_CAP_P2P) {
269         hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_CLIENT);
270         hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO);
271         hw->wiphy->iface_combinations = ssv6xxx_iface_combinations_p2p;
272   hw->wiphy->n_iface_combinations = ARRAY_SIZE(ssv6xxx_iface_combinations_p2p);
273 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
274         hw->wiphy->flags |= WIPHY_FLAG_ENFORCE_COMBINATIONS;
275 #endif
276     }
277 #endif
278 #if LINUX_VERSION_CODE > KERNEL_VERSION(3,5,0)
279     hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
280 #endif
281     if (sh->cfg.hw_caps & SSV6200_HW_CAP_AP){
282         hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
283 #if LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0)
284         hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
285 #endif
286     }
287 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 2, 0)
288     if (sh->cfg.hw_caps & SSV6200_HW_CAP_TDLS){
289       hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
290       hw->wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
291       printk("TDLS function enabled in sta.cfg\n");
292     }
293 #endif
294     hw->queues = 4;
295  hw->max_rates = 4;
296 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
297  hw->channel_change_time = 5000;
298 #endif
299  hw->max_listen_interval = 1;
300  hw->max_rate_tries = HW_MAX_RATE_TRIES;
301     hw->extra_tx_headroom = TXPB_OFFSET + AMPDU_DELIMITER_LEN;
302     if (sizeof(struct ampdu_hdr_st) > SSV_SKB_info_size)
303         hw->extra_tx_headroom += sizeof(struct ampdu_hdr_st);
304     else
305         hw->extra_tx_headroom += SSV_SKB_info_size;
306     if (sh->cfg.hw_caps & SSV6200_HW_CAP_2GHZ) {
307   hw->wiphy->bands[INDEX_80211_BAND_2GHZ] =
308    &sc->sbands[INDEX_80211_BAND_2GHZ];
309     }
310 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
311     if (sh->cfg.hw_caps & SSV6200_HW_CAP_AMPDU_TX)
312         #ifdef PREFER_RX
313         hw->max_rx_aggregation_subframes = 64;
314         #else
315         hw->max_rx_aggregation_subframes = 16;
316         #endif
317     else
318         hw->max_rx_aggregation_subframes = 12;
319     hw->max_tx_aggregation_subframes = 64;
320 #endif
321     hw->sta_data_size = sizeof(struct ssv_sta_priv_data);
322     hw->vif_data_size = sizeof(struct ssv_vif_priv_data);
323     memcpy(sh->maddr[0].addr, &sh->cfg.maddr[0][0], ETH_ALEN);
324     hw->wiphy->addresses = sh->maddr;
325     hw->wiphy->n_addresses = 1;
326     if (sh->cfg.hw_caps & SSV6200_HW_CAP_P2P) {
327         int i;
328         for (i = 1; i < SSV6200_MAX_HW_MAC_ADDR; i++) {
329       memcpy(sh->maddr[i].addr, sh->maddr[i-1].addr,
330              ETH_ALEN);
331       sh->maddr[i].addr[5]++;
332       hw->wiphy->n_addresses++;
333      }
334     }
335     if (!is_zero_ether_addr(sh->cfg.maddr[1]))
336     {
337         memcpy(sh->maddr[1].addr, sh->cfg.maddr[1], ETH_ALEN);
338         if (hw->wiphy->n_addresses < 2)
339             hw->wiphy->n_addresses = 2;
340     }
341 #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
342 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0))
343     hw->wiphy->wowlan = wowlan_support;
344 #else
345     hw->wiphy->wowlan = &wowlan_support;
346 #endif
347 #endif
348 
349 #if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(CONFIG_SSV_VENDOR_EXT_SUPPORT)
350     {
351         int err = 0;
352         struct ssv_softc *softc = (struct ssv_softc *)hw->priv;
353         if (softc)
354         {
355             set_wiphy_dev(hw->wiphy, softc->dev);
356             *((struct ssv_softc **)wiphy_priv(hw->wiphy)) = softc;
357         }
358        	printk("Registering Vendor80211\n");
359        	err = ssv_cfgvendor_attach(hw->wiphy);
360        	if (unlikely(err < 0)) {
361        		printk("Couldn not attach vendor commands (%d)\n", err);
362        	}
363     }
364 #endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WL_VENDOR_EXT_SUPPORT) */
365 
366 }
367 #ifdef MULTI_THREAD_ENCRYPT
ssv6xxx_cpu_callback(struct notifier_block * nfb,unsigned long action,void * hcpu)368 int ssv6xxx_cpu_callback(struct notifier_block *nfb,
369                          unsigned long action,
370                          void *hcpu)
371 {
372     struct ssv_softc *sc = container_of(nfb, struct ssv_softc, cpu_nfb);
373     int hotcpu = (unsigned long)hcpu;
374     struct ssv_encrypt_task_list *ta = NULL;
375     switch (action) {
376     case CPU_UP_PREPARE:
377     case CPU_UP_PREPARE_FROZEN:
378     case CPU_DOWN_FAILED: {
379             int cpu = 0;
380             list_for_each_entry(ta, &sc->encrypt_task_head, list)
381             {
382                 if(cpu == hotcpu)
383                     break;
384                 cpu++;
385             }
386             if(ta->encrypt_task->state & TASK_UNINTERRUPTIBLE)
387             {
388                 kthread_bind(ta->encrypt_task, hotcpu);
389             }
390             printk("encrypt_task %p state is %ld\n", ta->encrypt_task, ta->encrypt_task->state);
391             break;
392         }
393     case CPU_ONLINE:
394     case CPU_ONLINE_FROZEN: {
395             int cpu = 0;
396             list_for_each_entry(ta, &sc->encrypt_task_head, list)
397             {
398                 if(cpu == hotcpu)
399                 {
400                     ta->cpu_offline = 0;
401                     if ( (ta->started == 0) && (cpu_online(cpu)) )
402                     {
403                         wake_up_process(ta->encrypt_task);
404                         ta->started = 1;
405                         printk("wake up encrypt_task %p state is %ld, cpu = %d\n", ta->encrypt_task, ta->encrypt_task->state, cpu);
406                     }
407                     break;
408                 }
409                 cpu++;
410             }
411             printk("encrypt_task %p state is %ld\n", ta->encrypt_task, ta->encrypt_task->state);
412             break;
413         }
414 #ifdef CONFIG_HOTPLUG_CPU
415     case CPU_UP_CANCELED:
416     case CPU_UP_CANCELED_FROZEN:
417     case CPU_DOWN_PREPARE: {
418             int cpu = 0;
419             list_for_each_entry(ta, &sc->encrypt_task_head, list)
420             {
421                 if(cpu == hotcpu)
422                 {
423                     ta->cpu_offline = 1;
424                     break;
425                 }
426                 cpu++;
427             }
428             printk("p = %p\n",ta->encrypt_task);
429             break;
430         }
431     case CPU_DEAD:
432     case CPU_DEAD_FROZEN: {
433             break;
434         }
435 #endif
436     }
437     return NOTIFY_OK;
438 }
439 #endif
ssv6xxx_watchdog_restart_hw(struct ssv_softc * sc)440 void ssv6xxx_watchdog_restart_hw(struct ssv_softc *sc)
441 {
442     printk("%s(): \n", __FUNCTION__);
443     sc->restart_counter++;
444     sc->force_triger_reset = true;
445     sc->beacon_info[0].pubf_addr = 0x00;
446     sc->beacon_info[1].pubf_addr = 0x00;
447     ieee80211_restart_hw(sc->hw);
448 }
449 #ifdef CONFIG_SSV_RSSI
450 extern struct rssi_res_st rssi_res;
451 #endif
ssv6200_watchdog_timeout(unsigned long arg)452 void ssv6200_watchdog_timeout(unsigned long arg)
453 {
454 #ifdef CONFIG_SSV_RSSI
455     static u32 count=0;
456     struct rssi_res_st *rssi_tmp0 = NULL, *rssi_tmp1 = NULL;
457 #endif
458     struct ssv_softc *sc = (struct ssv_softc *)arg;
459     if(sc->watchdog_flag == WD_BARKING) {
460         ssv6xxx_watchdog_restart_hw(sc);
461         mod_timer(&sc->watchdog_timeout, jiffies + WATCHDOG_TIMEOUT);
462         return;
463     }
464     if (sc->watchdog_flag != WD_SLEEP)
465         sc->watchdog_flag = WD_BARKING;
466 #ifdef CONFIG_SSV_RSSI
467     count++;
468     if(count == 6) {
469         count = 0;
470         if (list_empty(&rssi_res.rssi_list)) {
471             return;
472         }
473         list_for_each_entry_safe(rssi_tmp0, rssi_tmp1, &rssi_res.rssi_list, rssi_list) {
474             if (rssi_tmp0->timeout) {
475                 list_del_rcu(&rssi_tmp0->rssi_list);
476                 kfree(rssi_tmp0);
477             }
478         }
479     }
480 #endif
481     mod_timer(&sc->watchdog_timeout, jiffies + WATCHDOG_TIMEOUT);
482     return;
483 }
ssv6xxx_preload_sw_cipher(void)484 static void ssv6xxx_preload_sw_cipher(void)
485 {
486 #ifdef USE_LOCAL_CRYPTO
487     struct crypto_blkcipher *tmpblkcipher;
488     struct crypto_cipher *tmpcipher;
489 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
490     struct crypto_ahash *tmphash;
491 #else
492     struct crypto_hash *tmphash;
493 #endif
494     printk("Pre-load cipher\n");
495     tmpblkcipher = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
496  if (IS_ERR(tmpblkcipher)) {
497     printk(" ARC4 cipher allocate fail \n");
498  } else {
499     crypto_free_blkcipher(tmpblkcipher);
500     }
501  tmpcipher = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
502  if (IS_ERR(tmpcipher)) {
503      printk(" aes cipher allocate fail \n");
504  } else {
505     crypto_free_cipher(tmpcipher);
506  }
507 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
508  tmphash =crypto_alloc_ahash("michael_mic", 0, CRYPTO_ALG_ASYNC);
509 #else
510  tmphash =crypto_alloc_hash("michael_mic", 0, CRYPTO_ALG_ASYNC);
511 #endif
512  if (IS_ERR(tmphash)) {
513      printk(" mic hash allocate fail \n");
514  } else {
515 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
516  crypto_free_ahash(tmphash);
517 #else
518  crypto_free_hash(tmphash);
519 #endif
520  }
521 #endif
522 }
ssv6xxx_init_softc(struct ssv_softc * sc)523 static int ssv6xxx_init_softc(struct ssv_softc *sc)
524 {
525     void *channels;
526     int ret=0;
527 #ifdef MULTI_THREAD_ENCRYPT
528     unsigned int cpu;
529 #endif
530     sc->sc_flags = SC_OP_INVALID;
531     mutex_init(&sc->mutex);
532     mutex_init(&sc->mem_mutex);
533     sc->config_wq= create_singlethread_workqueue("ssv6xxx_cong_wq");
534     sc->thermal_wq= create_singlethread_workqueue("ssv6xxx_thermal_wq");
535     INIT_DELAYED_WORK(&sc->thermal_monitor_work, thermal_monitor);
536     INIT_WORK(&sc->set_tim_work, ssv6200_set_tim_work);
537     INIT_WORK(&sc->bcast_start_work, ssv6200_bcast_start_work);
538     INIT_DELAYED_WORK(&sc->bcast_stop_work, ssv6200_bcast_stop_work);
539     INIT_DELAYED_WORK(&sc->bcast_tx_work, ssv6200_bcast_tx_work);
540     INIT_WORK(&sc->set_ampdu_rx_add_work, ssv6xxx_set_ampdu_rx_add_work);
541     INIT_WORK(&sc->set_ampdu_rx_del_work, ssv6xxx_set_ampdu_rx_del_work);
542 #ifdef CONFIG_SSV_SUPPORT_ANDROID
543 #ifdef CONFIG_HAS_EARLYSUSPEND
544     sc->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
545     sc->early_suspend.suspend = ssv6xxx_early_suspend;
546     sc->early_suspend.resume = ssv6xxx_late_resume;
547     register_early_suspend(&sc->early_suspend);
548 #endif
549     ssv_wakelock_init(sc);
550 #endif
551     sc->mac_deci_tbl = sta_deci_tbl;
552     memset((void *)&sc->tx, 0, sizeof(struct ssv_tx));
553     sc->tx.hw_txqid[WMM_AC_VO] = 3; sc->tx.ac_txqid[3] = WMM_AC_VO;
554     sc->tx.hw_txqid[WMM_AC_VI] = 2; sc->tx.ac_txqid[2] = WMM_AC_VI;
555     sc->tx.hw_txqid[WMM_AC_BE] = 1; sc->tx.ac_txqid[1] = WMM_AC_BE;
556     sc->tx.hw_txqid[WMM_AC_BK] = 0; sc->tx.ac_txqid[0] = WMM_AC_BK;
557     INIT_LIST_HEAD(&sc->tx.ampdu_tx_que);
558     spin_lock_init(&sc->tx.ampdu_tx_que_lock);
559     memset((void *)&sc->rx, 0, sizeof(struct ssv_rx));
560     spin_lock_init(&sc->rx.rxq_lock);
561     skb_queue_head_init(&sc->rx.rxq_head);
562     sc->rx.rx_buf = ssv_skb_alloc(MAX_FRAME_SIZE);
563     if (sc->rx.rx_buf == NULL)
564         return -ENOMEM;
565  memset(&sc->bcast_txq, 0, sizeof(struct ssv6xxx_bcast_txq));
566  spin_lock_init(&sc->bcast_txq.txq_lock);
567  skb_queue_head_init(&sc->bcast_txq.qhead);
568  spin_lock_init(&sc->ps_state_lock);
569 #ifdef CONFIG_P2P_NOA
570  spin_lock_init(&sc->p2p_noa.p2p_config_lock);
571 #endif
572  if (sc->sh->cfg.hw_caps & SSV6200_HW_CAP_2GHZ) {
573         channels = kmemdup(ssv6200_2ghz_chantable,
574    sizeof(ssv6200_2ghz_chantable), GFP_KERNEL);
575   if (!channels) {
576             kfree(sc->rx.rx_buf);
577       return -ENOMEM;
578         }
579   sc->sbands[INDEX_80211_BAND_2GHZ].channels = channels;
580   sc->sbands[INDEX_80211_BAND_2GHZ].band = INDEX_80211_BAND_2GHZ;
581   sc->sbands[INDEX_80211_BAND_2GHZ].n_channels =
582    ARRAY_SIZE(ssv6200_2ghz_chantable);
583   sc->sbands[INDEX_80211_BAND_2GHZ].bitrates = ssv6200_legacy_rates;
584   sc->sbands[INDEX_80211_BAND_2GHZ].n_bitrates =
585    ARRAY_SIZE(ssv6200_legacy_rates);
586  }
587  sc->cur_channel = NULL;
588  sc->hw_chan = (-1);
589     ssv6xxx_set_80211_hw_capab(sc);
590     ret = ssv6xxx_rate_control_register();
591     if (ret != 0) {
592         printk("%s(): Failed to register rc algorithm.\n", __FUNCTION__);
593     }
594 #ifdef MULTI_THREAD_ENCRYPT
595     skb_queue_head_init(&sc->preprocess_q);
596     skb_queue_head_init(&sc->crypted_q);
597     #ifdef CONFIG_SSV6XXX_DEBUGFS
598     sc->max_preprocess_q_len = 0;
599     sc->max_crypted_q_len = 0;
600     #endif
601     spin_lock_init(&sc->crypt_st_lock);
602     INIT_LIST_HEAD(&sc->encrypt_task_head);
603     for_each_cpu(cpu, cpu_present_mask)
604     {
605         struct ssv_encrypt_task_list *ta = kzalloc(sizeof(*ta), GFP_KERNEL);
606   memset(ta, 0, sizeof(*ta));
607         ta->encrypt_task = kthread_create_on_node(ssv6xxx_encrypt_task, sc, cpu_to_node(cpu), "%d/ssv6xxx_encrypt_task", cpu);
608         init_waitqueue_head(&ta->encrypt_wait_q);
609         if (!IS_ERR(ta->encrypt_task))
610         {
611             printk("[MT-ENCRYPT]: create kthread %p for CPU %d, ret = %d\n", ta->encrypt_task, cpu, ret);
612 #ifdef KTHREAD_BIND
613             kthread_bind(ta->encrypt_task, cpu);
614 #endif
615             list_add_tail(&ta->list, &sc->encrypt_task_head);
616             if (cpu_online(cpu))
617             {
618              wake_up_process(ta->encrypt_task);
619                 ta->started = 1;
620             }
621             ta->cpu_no = cpu;
622         }
623         else
624         {
625             printk("[MT-ENCRYPT]: Fail to create kthread\n");
626         }
627     }
628     sc->cpu_nfb.notifier_call = ssv6xxx_cpu_callback;
629 #ifdef KTHREAD_BIND
630     register_cpu_notifier(&sc->cpu_nfb);
631 #endif
632 #endif
633     init_waitqueue_head(&sc->tx_wait_q);
634     sc->tx_wait_q_woken = 0;
635     skb_queue_head_init(&sc->tx_skb_q);
636     #ifdef CONFIG_SSV6XXX_DEBUGFS
637     sc->max_tx_skb_q_len = 0;
638     #endif
639     sc->tx_task = kthread_run(ssv6xxx_tx_task, sc, "ssv6xxx_tx_task");
640     sc->tx_q_empty = false;
641     skb_queue_head_init(&sc->tx_done_q);
642     init_waitqueue_head(&sc->rx_wait_q);
643     sc->rx_wait_q_woken = 0;
644     skb_queue_head_init(&sc->rx_skb_q);
645     sc->rx_task = kthread_run(ssv6xxx_rx_task, sc, "ssv6xxx_rx_task");
646     ssv6xxx_preload_sw_cipher();
647     init_timer(&sc->watchdog_timeout);
648     sc->watchdog_timeout.expires = jiffies + 20*HZ;
649     sc->watchdog_timeout.data = (unsigned long)sc;
650     sc->watchdog_timeout.function = ssv6200_watchdog_timeout;
651     init_waitqueue_head(&sc->fw_wait_q);
652 #ifdef CONFIG_SSV_RSSI
653     INIT_LIST_HEAD(&rssi_res.rssi_list);
654     rssi_res.rssi = 0;
655 #endif
656     add_timer(&sc->watchdog_timeout);
657     //if(get_flash_info(sc) == 1)
658     sc->is_sar_enabled = get_flash_info(sc);
659     if (sc->is_sar_enabled)
660         queue_delayed_work(sc->thermal_wq, &sc->thermal_monitor_work, THERMAL_MONITOR_TIME);
661         //schedule_delayed_work(&sc->thermal_monitor_work, THERMAL_MONITOR_TIME);
662     return ret;
663 }
664 
ssv6xxx_deinit_prepare(void)665 void ssv6xxx_deinit_prepare(void)
666 {
667     printk("%s\n", __FUNCTION__);
668 
669 #ifdef CONFIG_SSV_SUPPORT_ANDROID
670 	printk("%s :ps_status = %d\n", __FUNCTION__,PWRSV_PREPARE);
671     ssv6xxx_watchdog_controller(ssv_notify_sc->sh ,(u8)SSV6XXX_HOST_CMD_WATCHDOG_STOP);
672     ssv_notify_sc->ps_status = PWRSV_PREPARE;
673 
674 	while(ssv_notify_sc->bScanning == true){
675         printk("+");
676         msleep(100);
677     }
678 	printk("\n");
679 #endif
680 
681 }
682 
683 
ssv6xxx_deinit_softc(struct ssv_softc * sc)684 static int ssv6xxx_deinit_softc(struct ssv_softc *sc)
685 {
686     void *channels;
687  struct sk_buff* skb;
688     u8 remain_size;
689 #ifdef MULTI_THREAD_ENCRYPT
690     struct ssv_encrypt_task_list *qtask = NULL;
691     int counter = 0;
692 #endif
693     printk("%s():\n", __FUNCTION__);
694     if (sc->sh->cfg.hw_caps & SSV6200_HW_CAP_2GHZ) {
695         channels = sc->sbands[INDEX_80211_BAND_2GHZ].channels;
696         kfree(channels);
697     }
698 #ifdef CONFIG_SSV_SUPPORT_ANDROID
699 #ifdef CONFIG_HAS_EARLYSUSPEND
700     unregister_early_suspend(&sc->early_suspend);
701 #endif
702     ssv_wakelock_destroy(sc);
703 #endif
704     ssv_skb_free(sc->rx.rx_buf);
705     sc->rx.rx_buf = NULL;
706     ssv6xxx_rate_control_unregister();
707     cancel_delayed_work_sync(&sc->bcast_tx_work);
708     //ssv6xxx_watchdog_controller(sc->sh ,(u8)SSV6XXX_HOST_CMD_WATCHDOG_STOP);
709     del_timer_sync(&sc->watchdog_timeout);
710     cancel_delayed_work(&sc->thermal_monitor_work);
711     sc->ps_status = PWRSV_PREPARE;
712     flush_workqueue(sc->thermal_wq);
713     destroy_workqueue(sc->thermal_wq);
714  do{
715   skb = ssv6200_bcast_dequeue(&sc->bcast_txq, &remain_size);
716   if(skb)
717             ssv6xxx_txbuf_free_skb(skb, (void*)sc);
718   else
719    break;
720  }while(remain_size);
721 #ifdef MULTI_THREAD_ENCRYPT
722     unregister_cpu_notifier(&sc->cpu_nfb);
723     if (!list_empty(&sc->encrypt_task_head))
724     {
725         for (qtask = list_entry((&sc->encrypt_task_head)->next, typeof(*qtask), list);
726                 !list_empty(&sc->encrypt_task_head);
727                 qtask = list_entry((&sc->encrypt_task_head)->next, typeof(*qtask), list))
728         {
729             counter++;
730             printk("Stopping encrypt task %d: ...\n", counter);
731             kthread_stop(qtask->encrypt_task);
732             printk("Stopped encrypt task %d: ...\n", counter);
733             list_del(&qtask->list);
734             kfree(qtask);
735         }
736     }
737 #endif
738     if (sc->tx_task != NULL)
739     {
740         printk("Stopping TX task...\n");
741         kthread_stop(sc->tx_task);
742   sc->tx_task = NULL;
743         printk("Stopped TX task.\n");
744     }
745     if (sc->rx_task != NULL)
746     {
747         printk("Stopping RX task...\n");
748         kthread_stop(sc->rx_task);
749   sc->rx_task = NULL;
750         printk("Stopped RX task.\n");
751     }
752 #ifdef MULTI_THREAD_ENCRYPT
753     while((skb = skb_dequeue(&sc->preprocess_q)) != NULL)
754     {
755         SKB_info *skb_info = (SKB_info *)skb->head;
756         if(skb_info->crypt_st == PKT_CRYPT_ST_ENC_PRE)
757             ssv6xxx_txbuf_free_skb(skb, (void*)sc);
758         else
759             dev_kfree_skb_any(skb);
760     }
761     while((skb = skb_dequeue(&sc->crypted_q)) != NULL)
762     {
763         SKB_info *skb_info = (SKB_info *)skb->head;
764         if(skb_info->crypt_st == PKT_CRYPT_ST_ENC_DONE)
765             ssv6xxx_txbuf_free_skb(skb, (void*)sc);
766         else
767             dev_kfree_skb_any(skb);
768     }
769     printk("[MT-ENCRYPT]: end of de-init\n");
770 #endif
771     destroy_workqueue(sc->config_wq);
772     return 0;
773 }
ssv6xxx_hw_set_replay_ignore(struct ssv_hw * sh,u8 ignore)774 static void ssv6xxx_hw_set_replay_ignore(struct ssv_hw *sh,u8 ignore)
775 {
776     u32 temp;
777     SMAC_REG_READ(sh,ADR_SCRT_SET,&temp);
778     temp = temp & SCRT_RPLY_IGNORE_I_MSK;
779     temp |= (ignore << SCRT_RPLY_IGNORE_SFT);
780     SMAC_REG_WRITE(sh,ADR_SCRT_SET, temp);
781 }
782 extern char *cfgfirmwarepath ;
ssv6xxx_init_mac(struct ssv_hw * sh)783 int ssv6xxx_init_mac(struct ssv_hw *sh)
784 {
785     struct ssv_softc *sc=sh->sc;
786     int i = 0 , ret=0;
787     u8 temp_path[256] = "";
788 #ifdef SSV6200_ECO
789     u32 *ptr, id_len, regval, temp[0x8];
790 #else
791      u32 *ptr, id_len, regval;
792 #endif
793  char *chip_id = sh->chip_id;
794     printk(KERN_INFO "SVN version %d\n", ssv_root_version);
795     printk(KERN_INFO "SVN ROOT URL %s \n", SSV_ROOT_URl);
796     printk(KERN_INFO "COMPILER HOST %s \n", COMPILERHOST);
797     printk(KERN_INFO "COMPILER DATE %s \n", COMPILERDATE);
798     printk(KERN_INFO "COMPILER OS %s \n", COMPILEROS);
799     printk(KERN_INFO "COMPILER OS ARCH %s \n", COMPILEROSARCH);
800     SMAC_REG_READ(sh, ADR_IC_TIME_TAG_1, &regval);
801     sh->chip_tag = ((u64)regval<<32);
802     SMAC_REG_READ(sh, ADR_IC_TIME_TAG_0, &regval);
803     sh->chip_tag |= (regval);
804     printk(KERN_INFO "CHIP TAG: %llx \n", sh->chip_tag);
805     SMAC_REG_READ(sh, ADR_CHIP_ID_3, &regval);
806     *((u32 *)&chip_id[0]) = (u32)LONGSWAP(regval);
807     SMAC_REG_READ(sh, ADR_CHIP_ID_2, &regval);
808     *((u32 *)&chip_id[4]) = (u32)LONGSWAP(regval);
809     SMAC_REG_READ(sh, ADR_CHIP_ID_1, &regval);
810     *((u32 *)&chip_id[8]) = (u32)LONGSWAP(regval);
811     SMAC_REG_READ(sh, ADR_CHIP_ID_0, &regval);
812     *((u32 *)&chip_id[12]) = (u32)LONGSWAP(regval);
813     chip_id[12+sizeof(u32)] = 0;
814     printk(KERN_INFO "CHIP ID: %s \n",chip_id);
815     if(sc->ps_status == PWRSV_ENABLE){
816 #ifdef CONFIG_SSV_SUPPORT_ANDROID
817         printk(KERN_INFO "%s: wifi Alive lock timeout after 3 secs!\n",__FUNCTION__);
818         {
819             ssv_wake_timeout(sc, 3);
820             printk(KERN_INFO "wifi Alive lock!\n");
821         }
822 #endif
823 #ifdef CONFIG_SSV_HW_ENCRYPT_SW_DECRYPT
824         SMAC_REG_WRITE(sh, ADR_RX_FLOW_DATA, M_ENG_MACRX|(M_ENG_HWHCI<<4));
825 #else
826         SMAC_REG_WRITE(sh, ADR_RX_FLOW_DATA, M_ENG_MACRX|(M_ENG_ENCRYPT_SEC<<4)|(M_ENG_HWHCI<<8));
827 #endif
828         SMAC_REG_WRITE(sc->sh, ADR_RX_FLOW_MNG, M_ENG_MACRX|(M_ENG_HWHCI<<4));
829 #if Enable_AMPDU_FW_Retry
830         SMAC_REG_WRITE(sh, ADR_RX_FLOW_CTRL, M_ENG_MACRX|(M_ENG_CPU<<4)|(M_ENG_HWHCI<<8));
831 #else
832         SMAC_REG_WRITE(sh, ADR_RX_FLOW_CTRL, M_ENG_MACRX|(M_ENG_HWHCI<<4));
833 #endif
834         SMAC_REG_WRITE(sc->sh, ADR_MRX_FLT_TB0+6*4, (sc->mac_deci_tbl[6]));
835         return ret;
836     }
837     SMAC_REG_SET_BITS(sh, ADR_PHY_EN_1, (0 << RG_PHY_MD_EN_SFT), RG_PHY_MD_EN_MSK);
838     SMAC_REG_WRITE(sh, ADR_BRG_SW_RST, 1 << MAC_SW_RST_SFT);
839     do
840     {
841         SMAC_REG_READ(sh, ADR_BRG_SW_RST, & regval);
842         i ++;
843         if (i >10000){
844             printk("MAC reset fail !!!!\n");
845             WARN_ON(1);
846             ret = 1;
847             goto exit;
848         }
849     } while (regval != 0);
850  SMAC_REG_WRITE(sc->sh, ADR_TXQ4_MTX_Q_AIFSN, 0xffff2101);
851     SMAC_REG_SET_BITS(sc->sh, ADR_MTX_BCN_EN_MISC, 0, MTX_HALT_MNG_UNTIL_DTIM_MSK);
852     SMAC_REG_WRITE(sh, ADR_CONTROL, 0x12000006);
853     SMAC_REG_WRITE(sh, ADR_RX_TIME_STAMP_CFG, ((28<<MRX_STP_OFST_SFT)|0x01));
854     SMAC_REG_WRITE(sh, ADR_HCI_TX_RX_INFO_SIZE,
855           ((u32)(TXPB_OFFSET) << TX_PBOFFSET_SFT) |
856           ((u32)(sh->tx_desc_len) << TX_INFO_SIZE_SFT) |
857           ((u32)(sh->rx_desc_len) << RX_INFO_SIZE_SFT) |
858           ((u32)(sh->rx_pinfo_pad) << RX_LAST_PHY_SIZE_SFT )
859     );
860     SMAC_REG_READ(sh,ADR_MMU_CTRL, &regval);
861  regval |= (0xff<<MMU_SHARE_MCU_SFT);
862     SMAC_REG_WRITE(sh,ADR_MMU_CTRL, regval);
863     SMAC_REG_READ(sh,ADR_MRX_WATCH_DOG, &regval);
864     regval &= 0xfffffff0;
865     SMAC_REG_WRITE(sh,ADR_MRX_WATCH_DOG, regval);
866     SMAC_REG_READ(sh, ADR_TRX_ID_THRESHOLD, &id_len);
867     id_len = (id_len&0xffff0000 ) |
868              (SSV6200_ID_TX_THRESHOLD<<TX_ID_THOLD_SFT)|
869              (SSV6200_ID_RX_THRESHOLD<<RX_ID_THOLD_SFT);
870     SMAC_REG_WRITE(sh, ADR_TRX_ID_THRESHOLD, id_len);
871     SMAC_REG_READ(sh, ADR_ID_LEN_THREADSHOLD1, &id_len);
872     id_len = (id_len&0x0f )|
873              (SSV6200_PAGE_TX_THRESHOLD<<ID_TX_LEN_THOLD_SFT)|
874              (SSV6200_PAGE_RX_THRESHOLD<<ID_RX_LEN_THOLD_SFT);
875     SMAC_REG_WRITE(sh, ADR_ID_LEN_THREADSHOLD1, id_len);
876 #ifdef CONFIG_SSV_CABRIO_MB_DEBUG
877  SMAC_REG_READ(sh, ADR_MB_DBG_CFG3, &regval);
878     regval |= (debug_buffer<<0);
879     SMAC_REG_WRITE(sh, ADR_MB_DBG_CFG3, regval);
880  SMAC_REG_READ(sh, ADR_MB_DBG_CFG2, &regval);
881     regval |= (DEBUG_SIZE<<16);
882     SMAC_REG_WRITE(sh, ADR_MB_DBG_CFG2, regval);
883     SMAC_REG_READ(sh, ADR_MB_DBG_CFG1, &regval);
884     regval |= (1<<MB_DBG_EN_SFT);
885     SMAC_REG_WRITE(sh, ADR_MB_DBG_CFG1, regval);
886     SMAC_REG_READ(sh, ADR_MBOX_HALT_CFG, &regval);
887     regval |= (1<<MB_ERR_AUTO_HALT_EN_SFT);
888     SMAC_REG_WRITE(sh, ADR_MBOX_HALT_CFG, regval);
889 #endif
890 SMAC_REG_READ(sc->sh, ADR_MTX_BCN_EN_MISC, &regval);
891 regval|=(1<<MTX_TSF_TIMER_EN_SFT);
892 SMAC_REG_WRITE(sc->sh, ADR_MTX_BCN_EN_MISC, regval);
893 #ifdef SSV6200_ECO
894     SMAC_REG_WRITE(sh, 0xcd010004, 0x1213);
895     for(i=0;i<SSV_RC_MAX_STA;i++)
896     {
897         if(i==0)
898         {
899             sh->hw_buf_ptr[i] = ssv6xxx_pbuf_alloc(sc, sizeof(phy_info_tbl)+
900                                                     sizeof(struct ssv6xxx_hw_sec), NOTYPE_BUF);
901          if((sh->hw_buf_ptr[i]>>28) != 8)
902          {
903           printk("opps allocate pbuf error\n");
904           WARN_ON(1);
905           ret = 1;
906           goto exit;
907          }
908         }
909         else
910         {
911             sh->hw_buf_ptr[i] = ssv6xxx_pbuf_alloc(sc, sizeof(struct ssv6xxx_hw_sec), NOTYPE_BUF);
912             if((sh->hw_buf_ptr[i]>>28) != 8)
913             {
914                 printk("opps allocate pbuf error\n");
915                 WARN_ON(1);
916                 ret = 1;
917                 goto exit;
918             }
919         }
920     }
921     for (i = 0; i < 0x8; i++) {
922         temp[i] = 0;
923         temp[i] = ssv6xxx_pbuf_alloc(sc, 256,NOTYPE_BUF);
924     }
925     for (i = 0; i < 0x8; i++) {
926         if(temp[i] == 0x800e0000)
927             printk("0x800e0000\n");
928         else
929             ssv6xxx_pbuf_free(sc,temp[i]);
930     }
931 #else
932     sh->hw_buf_ptr = ssv6xxx_pbuf_alloc(sc, sizeof(phy_info_tbl)+
933                                             sizeof(struct ssv6xxx_hw_sec), NOTYPE_BUF);
934  if((sh->hw_buf_ptr>>28) != 8)
935  {
936   printk("opps allocate pbuf error\n");
937   WARN_ON(1);
938   ret = 1;
939   goto exit;
940  }
941 #endif
942 #ifdef SSV6200_ECO
943     for(i=0;i<SSV_RC_MAX_STA;i++)
944         sh->hw_sec_key[i] = sh->hw_buf_ptr[i];
945     for(i=0;i<SSV_RC_MAX_STA;i++)
946     {
947   int x;
948         for(x=0; x<sizeof(struct ssv6xxx_hw_sec); x+=4) {
949             SMAC_REG_WRITE(sh, sh->hw_sec_key[i]+x, 0);
950         }
951     }
952     SMAC_REG_READ(sh, ADR_SCRT_SET, &regval);
953  regval &= SCRT_PKT_ID_I_MSK;
954  regval |= ((sh->hw_sec_key[0] >> 16) << SCRT_PKT_ID_SFT);
955  SMAC_REG_WRITE(sh, ADR_SCRT_SET, regval);
956     sh->hw_pinfo = sh->hw_sec_key[0] + sizeof(struct ssv6xxx_hw_sec);
957     for(i=0, ptr=phy_info_tbl; i<PHY_INFO_TBL1_SIZE; i++, ptr++) {
958         SMAC_REG_WRITE(sh, ADR_INFO0+i*4, *ptr);
959         SMAC_REG_CONFIRM(sh, ADR_INFO0+i*4, *ptr);
960     }
961 #else
962     sh->hw_sec_key = sh->hw_buf_ptr;
963     for(i=0; i<sizeof(struct ssv6xxx_hw_sec); i+=4) {
964         SMAC_REG_WRITE(sh, sh->hw_sec_key+i, 0);
965     }
966     SMAC_REG_READ(sh, ADR_SCRT_SET, &regval);
967  regval &= SCRT_PKT_ID_I_MSK;
968  regval |= ((sh->hw_sec_key >> 16) << SCRT_PKT_ID_SFT);
969  SMAC_REG_WRITE(sh, ADR_SCRT_SET, regval);
970     sh->hw_pinfo = sh->hw_sec_key + sizeof(struct ssv6xxx_hw_sec);
971     for(i=0, ptr=phy_info_tbl; i<PHY_INFO_TBL1_SIZE; i++, ptr++) {
972         SMAC_REG_WRITE(sh, ADR_INFO0+i*4, *ptr);
973         SMAC_REG_CONFIRM(sh, ADR_INFO0+i*4, *ptr);
974     }
975 #endif
976  for(i=0; i<PHY_INFO_TBL2_SIZE; i++, ptr++) {
977         SMAC_REG_WRITE(sh, sh->hw_pinfo+i*4, *ptr);
978         SMAC_REG_CONFIRM(sh, sh->hw_pinfo+i*4, *ptr);
979     }
980     for(i=0; i<PHY_INFO_TBL3_SIZE; i++, ptr++) {
981         SMAC_REG_WRITE(sh, sh->hw_pinfo+
982         (PHY_INFO_TBL2_SIZE<<2)+i*4, *ptr);
983         SMAC_REG_CONFIRM(sh, sh->hw_pinfo+
984         (PHY_INFO_TBL2_SIZE<<2)+i*4, *ptr);
985     }
986     SMAC_REG_WRITE(sh, ADR_INFO_RATE_OFFSET, 0x00040000);
987  SMAC_REG_WRITE(sh, ADR_INFO_IDX_ADDR, sh->hw_pinfo);
988     SMAC_REG_WRITE(sh, ADR_INFO_LEN_ADDR, sh->hw_pinfo+(PHY_INFO_TBL2_SIZE)*4);
989  printk("ADR_INFO_IDX_ADDR[%08x] ADR_INFO_LEN_ADDR[%08x]\n", sh->hw_pinfo, sh->hw_pinfo+(PHY_INFO_TBL2_SIZE)*4);
990     SMAC_REG_WRITE(sh, ADR_GLBLE_SET,
991           (0 << OP_MODE_SFT) |
992           (0 << SNIFFER_MODE_SFT) |
993           (1 << DUP_FLT_SFT) |
994           (SSV6200_TX_PKT_RSVD_SETTING << TX_PKT_RSVD_SFT) |
995           ((u32)(RXPB_OFFSET) << PB_OFFSET_SFT)
996     );
997     SMAC_REG_WRITE(sh, ADR_STA_MAC_0, *((u32 *)&sh->cfg.maddr[0][0]));
998     SMAC_REG_WRITE(sh, ADR_STA_MAC_1, *((u32 *)&sh->cfg.maddr[0][4]));
999     SMAC_REG_WRITE(sh, ADR_BSSID_0, *((u32 *)&sc->bssid[0]));
1000     SMAC_REG_WRITE(sh, ADR_BSSID_1, *((u32 *)&sc->bssid[4]));
1001     SMAC_REG_WRITE(sh, ADR_TX_ETHER_TYPE_0, 0x00000000);
1002     SMAC_REG_WRITE(sh, ADR_TX_ETHER_TYPE_1, 0x00000000);
1003     SMAC_REG_WRITE(sh, ADR_RX_ETHER_TYPE_0, 0x00000000);
1004     SMAC_REG_WRITE(sh, ADR_RX_ETHER_TYPE_1, 0x00000000);
1005     SMAC_REG_WRITE(sh, ADR_REASON_TRAP0, 0x7FBC7F87);
1006     SMAC_REG_WRITE(sh, ADR_REASON_TRAP1, 0x0000003F);
1007 #ifndef FW_WSID_WATCH_LIST
1008     SMAC_REG_WRITE(sh, ADR_TRAP_HW_ID, M_ENG_HWHCI);
1009 #else
1010     SMAC_REG_WRITE(sh, ADR_TRAP_HW_ID, M_ENG_CPU);
1011 #endif
1012     SMAC_REG_WRITE(sh, ADR_WSID0, 0x00000000);
1013     SMAC_REG_WRITE(sh, ADR_WSID1, 0x00000000);
1014 #ifdef CONFIG_SSV_HW_ENCRYPT_SW_DECRYPT
1015     SMAC_REG_WRITE(sh, ADR_RX_FLOW_DATA, M_ENG_MACRX|(M_ENG_HWHCI<<4));
1016 #else
1017     SMAC_REG_WRITE(sh, ADR_RX_FLOW_DATA, M_ENG_MACRX|(M_ENG_ENCRYPT_SEC<<4)|(M_ENG_HWHCI<<8));
1018 #endif
1019 #if defined(CONFIG_P2P_NOA) || defined(CONFIG_RX_MGMT_CHECK)
1020     SMAC_REG_WRITE(sh, ADR_RX_FLOW_MNG, M_ENG_MACRX|(M_ENG_CPU<<4)|(M_ENG_HWHCI<<8));
1021 #else
1022     SMAC_REG_WRITE(sh, ADR_RX_FLOW_MNG, M_ENG_MACRX|(M_ENG_HWHCI<<4));
1023 #endif
1024     #if Enable_AMPDU_FW_Retry
1025     SMAC_REG_WRITE(sh, ADR_RX_FLOW_CTRL, M_ENG_MACRX|(M_ENG_CPU<<4)|(M_ENG_HWHCI<<8));
1026     #else
1027     SMAC_REG_WRITE(sh, ADR_RX_FLOW_CTRL, M_ENG_MACRX|(M_ENG_HWHCI<<4));
1028     #endif
1029     ssv6xxx_hw_set_replay_ignore(sh, 1);
1030     ssv6xxx_update_decision_table(sc);
1031     SMAC_REG_SET_BITS(sc->sh, ADR_GLBLE_SET, SSV6200_OPMODE_STA, OP_MODE_MSK);
1032     SMAC_REG_WRITE(sh, ADR_SDIO_MASK, 0xfffe1fff);
1033 #ifdef CONFIG_SSV_TX_LOWTHRESHOLD
1034     SMAC_REG_WRITE(sh, ADR_TX_LIMIT_INTR, 0x80000000 |
1035         SSV6200_TX_LOWTHRESHOLD_ID_TRIGGER << 16 |SSV6200_TX_LOWTHRESHOLD_PAGE_TRIGGER);
1036 #else
1037     SMAC_REG_WRITE(sh, ADR_MB_THRESHOLD6, 0x80000000);
1038     SMAC_REG_WRITE(sh, ADR_MB_THRESHOLD8, 0x04020000);
1039     SMAC_REG_WRITE(sh, ADR_MB_THRESHOLD9, 0x00000404);
1040 #endif
1041 #ifdef CONFIG_SSV_SUPPORT_BTCX
1042         SMAC_REG_WRITE(sh, ADR_BTCX0,COEXIST_EN_MSK|(WIRE_MODE_SZ<<WIRE_MODE_SFT)
1043                            |WIFI_TX_SW_POL_MSK | BT_SW_POL_MSK);
1044         SMAC_REG_WRITE(sh, ADR_BTCX1,SSV6200_BT_PRI_SMP_TIME|(SSV6200_BT_STA_SMP_TIME<<BT_STA_SMP_TIME_SFT)
1045                            |(SSV6200_WLAN_REMAIN_TIME<<WLAN_REMAIN_TIME_SFT));
1046         SMAC_REG_WRITE(sh, ADR_SWITCH_CTL,BT_2WIRE_EN_MSK);
1047         SMAC_REG_WRITE(sh, ADR_PAD7, 1);
1048         SMAC_REG_WRITE(sh, ADR_PAD8, 0);
1049         SMAC_REG_WRITE(sh, ADR_PAD9, 1);
1050         SMAC_REG_WRITE(sh, ADR_PAD25, 1);
1051         SMAC_REG_WRITE(sh, ADR_PAD27, 8);
1052         SMAC_REG_WRITE(sh, ADR_PAD28, 8);
1053 #endif
1054     if (cfgfirmwarepath != NULL)
1055     {
1056         sprintf(temp_path,"%s%s",cfgfirmwarepath,WIFI_FIRMWARE_NAME);
1057         ret = SMAC_LOAD_FW(sh,temp_path,1);
1058         printk(KERN_INFO "Firmware name cfgfirmwarepath=%s\n", temp_path);
1059     }
1060     else if (sh->cfg.firmware_path[0] != 0x00)
1061     {
1062         sprintf(temp_path,"%s%s",sh->cfg.firmware_path,WIFI_FIRMWARE_NAME);
1063         ret = SMAC_LOAD_FW(sh,temp_path,1);
1064         printk(KERN_INFO "Firmware name sh->cfg.firmware_path=%s\n", temp_path);
1065     }
1066     else
1067     {
1068         printk(KERN_INFO "Firmware name CABRIO_E_FIRMWARE_NAME=%s\n", WIFI_FIRMWARE_NAME);
1069         ret = SMAC_LOAD_FW(sh,WIFI_FIRMWARE_NAME,0);
1070     }
1071     SMAC_REG_READ(sh, FW_VERSION_REG, &regval);
1072     if (regval == ssv_firmware_version)
1073     {
1074         SMAC_REG_SET_BITS(sh, ADR_PHY_EN_1, (1 << RG_PHY_MD_EN_SFT), RG_PHY_MD_EN_MSK);
1075         printk(KERN_INFO "Firmware version %d\n", regval);
1076     }
1077     else
1078     {
1079         printk(KERN_INFO "!! SOS !! SOS !!\n");
1080         printk(KERN_INFO "Firmware version not mapping %d\n", regval);
1081         ret = -1;
1082     }
1083     ssv6xxx_watchdog_controller(sh ,(u8)SSV6XXX_HOST_CMD_WATCHDOG_START);
1084 exit:
1085     return ret;
1086 }
ssv6xxx_deinit_mac(struct ssv_softc * sc)1087 void ssv6xxx_deinit_mac(struct ssv_softc *sc)
1088 {
1089 #ifdef SSV6200_ECO
1090     int i;
1091     for(i = 0; i < SSV_RC_MAX_STA; i++)
1092     {
1093         if(sc->sh->hw_buf_ptr[i])
1094             ssv6xxx_pbuf_free(sc, sc->sh->hw_buf_ptr[i]);
1095     }
1096 #else
1097     if(sc->sh->hw_buf_ptr)
1098      ssv6xxx_pbuf_free(sc, sc->sh->hw_buf_ptr);
1099 #endif
1100 }
ssv6xxx_deinit_hw(struct ssv_softc * sc)1101 void inline ssv6xxx_deinit_hw(struct ssv_softc *sc)
1102 {
1103     printk("%s(): \n", __FUNCTION__);
1104  ssv6xxx_deinit_mac(sc);
1105 }
ssv6xxx_restart_hw(struct ssv_softc * sc)1106 void ssv6xxx_restart_hw(struct ssv_softc *sc)
1107 {
1108     printk("%s(): \n", __FUNCTION__);
1109     printk("**************************\n");
1110     printk("*** Software MAC reset ***\n");
1111     printk("**************************\n");
1112     sc->restart_counter++;
1113     sc->force_triger_reset = true;
1114     HCI_STOP(sc->sh);
1115     SMAC_REG_WRITE(sc->sh, 0xce000004, 0x0);
1116     sc->beacon_info[0].pubf_addr = 0x00;
1117     sc->beacon_info[1].pubf_addr = 0x00;
1118     ieee80211_restart_hw(sc->hw);
1119 }
1120 #ifdef CONFIG_SSV_CABRIO_E
1121 extern struct ssv6xxx_iqk_cfg init_iqk_cfg;
1122 #endif
ssv6xxx_init_hw(struct ssv_hw * sh)1123 static int ssv6xxx_init_hw(struct ssv_hw *sh)
1124 {
1125     int ret=0,i=0,x=0;
1126 #ifdef CONFIG_SSV_CABRIO_E
1127     u32 regval;
1128 #endif
1129     sh->tx_desc_len = SSV6XXX_TX_DESC_LEN;
1130     sh->rx_desc_len = SSV6XXX_RX_DESC_LEN;
1131     sh->rx_pinfo_pad = 0x04;
1132     sh->tx_page_available = SSV6200_PAGE_TX_THRESHOLD;
1133     sh->ampdu_divider = SSV6XXX_AMPDU_DIVIDER;
1134     memset(sh->page_count, 0, sizeof(sh->page_count));
1135 #ifdef CONFIG_SSV_CABRIO_E
1136     if (sh->cfg.force_chip_identity)
1137     {
1138         printk("Force use external RF setting [%08x]\n",sh->cfg.force_chip_identity);
1139         sh->cfg.chip_identity = sh->cfg.force_chip_identity;
1140     }
1141     if(sh->cfg.chip_identity == SSV6051Z)
1142     {
1143         sh->p_ch_cfg = &ch_cfg_z[0];
1144         sh->ch_cfg_size = sizeof(ch_cfg_z) / sizeof(struct ssv6xxx_ch_cfg);
1145         memcpy(phy_info_tbl,phy_info_6051z,sizeof(phy_info_6051z));
1146     }
1147     else if(sh->cfg.chip_identity == SSV6051P)
1148     {
1149         sh->p_ch_cfg = &ch_cfg_p[0];
1150         sh->ch_cfg_size = sizeof(ch_cfg_p) / sizeof(struct ssv6xxx_ch_cfg);
1151     }
1152     switch (sh->cfg.chip_identity) {
1153         case SSV6051Q_P1:
1154         case SSV6051Q_P2:
1155         case SSV6051Q:
1156             printk("SSV6051Q setting\n");
1157             for (i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++){
1158                 if (ssv6200_rf_tbl[i].address == 0xCE010008)
1159                     ssv6200_rf_tbl[i].data = 0x008DF61B;
1160                 if (ssv6200_rf_tbl[i].address == 0xCE010014)
1161                     ssv6200_rf_tbl[i].data = 0x3D3E84FE;
1162                 if (ssv6200_rf_tbl[i].address == 0xCE010018)
1163                     ssv6200_rf_tbl[i].data = 0x01457D79;
1164                 if (ssv6200_rf_tbl[i].address == 0xCE01001C)
1165                     ssv6200_rf_tbl[i].data = 0x000103A7;
1166                 if (ssv6200_rf_tbl[i].address == 0xCE010020)
1167                     ssv6200_rf_tbl[i].data = 0x000103A6;
1168                 if (ssv6200_rf_tbl[i].address == 0xCE01002C)
1169                     ssv6200_rf_tbl[i].data = 0x00032CA8;
1170                 if (ssv6200_rf_tbl[i].address == 0xCE010048)
1171                     ssv6200_rf_tbl[i].data = 0xFCCCCF27;
1172                 if (ssv6200_rf_tbl[i].address == 0xCE010050)
1173                     ssv6200_rf_tbl[i].data = 0x0047C000;
1174             }
1175             break;
1176         case SSV6051Z:
1177             printk("SSV6051Z setting\n");
1178             for (i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++){
1179                 if (ssv6200_rf_tbl[i].address == 0xCE010008)
1180                     ssv6200_rf_tbl[i].data = 0x004D561C;
1181                 if (ssv6200_rf_tbl[i].address == 0xCE010014)
1182                     ssv6200_rf_tbl[i].data = 0x3D9E84FE;
1183                 if (ssv6200_rf_tbl[i].address == 0xCE010018)
1184                     ssv6200_rf_tbl[i].data = 0x00457D79;
1185                 if (ssv6200_rf_tbl[i].address == 0xCE01001C)
1186                     ssv6200_rf_tbl[i].data = 0x000103EB;
1187                 if (ssv6200_rf_tbl[i].address == 0xCE010020)
1188                     ssv6200_rf_tbl[i].data = 0x000103EA;
1189                 if (ssv6200_rf_tbl[i].address == 0xCE01002C)
1190                     ssv6200_rf_tbl[i].data = 0x00062CA8;
1191                 if (ssv6200_rf_tbl[i].address == 0xCE010048)
1192                     ssv6200_rf_tbl[i].data = 0xFCCCCF27;
1193                 if (ssv6200_rf_tbl[i].address == 0xCE010050)
1194                     ssv6200_rf_tbl[i].data = 0x0047C000;
1195             }
1196             break;
1197         case SSV6051P:
1198             printk("SSV6051P setting\n");
1199             for (i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++){
1200                 if (ssv6200_rf_tbl[i].address == 0xCE010008)
1201                     ssv6200_rf_tbl[i].data = 0x008B7C1C;
1202                 if (ssv6200_rf_tbl[i].address == 0xCE010014)
1203                     ssv6200_rf_tbl[i].data = 0x3D7E84FE;
1204                 if (ssv6200_rf_tbl[i].address == 0xCE010018)
1205                     ssv6200_rf_tbl[i].data = 0x01457D79;
1206                 if (ssv6200_rf_tbl[i].address == 0xCE01001C)
1207                     ssv6200_rf_tbl[i].data = 0x000103EB;
1208                 if (ssv6200_rf_tbl[i].address == 0xCE010020)
1209                     ssv6200_rf_tbl[i].data = 0x000103EA;
1210                 if (ssv6200_rf_tbl[i].address == 0xCE01002C)
1211                     ssv6200_rf_tbl[i].data = 0x00032CA8;
1212                 if (ssv6200_rf_tbl[i].address == 0xCE010048)
1213                     ssv6200_rf_tbl[i].data = 0xFCCCCC27;
1214                 if (ssv6200_rf_tbl[i].address == 0xCE010050)
1215                     ssv6200_rf_tbl[i].data = 0x0047C000;
1216                 if (ssv6200_rf_tbl[i].address == 0xC0001D00)
1217                     ssv6200_rf_tbl[i].data = 0x5E000040;
1218             }
1219             break;
1220         default:
1221             printk("No RF setting\n");
1222             while(1){
1223                 printk("**************\n");
1224                 printk("* Call Help! *\n");
1225                 printk("**************\n");
1226                 WARN_ON(1);
1227                 msleep(10000);
1228             };
1229             break;
1230     }
1231     if(sh->cfg.crystal_type == SSV6XXX_IQK_CFG_XTAL_26M)
1232     {
1233         init_iqk_cfg.cfg_xtal = SSV6XXX_IQK_CFG_XTAL_26M;
1234         printk("SSV6XXX_IQK_CFG_XTAL_26M\n");
1235     }
1236     else if(sh->cfg.crystal_type == SSV6XXX_IQK_CFG_XTAL_40M)
1237     {
1238         init_iqk_cfg.cfg_xtal = SSV6XXX_IQK_CFG_XTAL_40M;
1239         printk("SSV6XXX_IQK_CFG_XTAL_40M\n");
1240     }
1241     else if(sh->cfg.crystal_type == SSV6XXX_IQK_CFG_XTAL_24M)
1242     {
1243         printk("SSV6XXX_IQK_CFG_XTAL_24M\n");
1244         init_iqk_cfg.cfg_xtal = SSV6XXX_IQK_CFG_XTAL_24M;
1245         for(i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++)
1246         {
1247             if(ssv6200_rf_tbl[i].address == ADR_SX_ENABLE_REGISTER)
1248                 ssv6200_rf_tbl[i].data = 0x0003E07C;
1249             if(ssv6200_rf_tbl[i].address == ADR_DPLL_DIVIDER_REGISTER)
1250                 ssv6200_rf_tbl[i].data = 0x00406000;
1251             if(ssv6200_rf_tbl[i].address == ADR_DPLL_FB_DIVIDER_REGISTERS_I)
1252                 ssv6200_rf_tbl[i].data = 0x00000028;
1253             if(ssv6200_rf_tbl[i].address == ADR_DPLL_FB_DIVIDER_REGISTERS_II)
1254                 ssv6200_rf_tbl[i].data = 0x00000000;
1255         }
1256     }
1257     else
1258     {
1259         printk("Illegal xtal setting !![No XX.cfg]\n");
1260         printk("default value is SSV6XXX_IQK_CFG_XTAL_26M!!\n");
1261     }
1262     for(i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++)
1263     {
1264         if(ssv6200_rf_tbl[i].address == ADR_SYN_KVCO_XO_FINE_TUNE_CBANK)
1265         {
1266             if(sh->cfg.crystal_frequency_offset)
1267             {
1268                 ssv6200_rf_tbl[i].data &= RG_XOSC_CBANK_XO_I_MSK;
1269                 ssv6200_rf_tbl[i].data |= (sh->cfg.crystal_frequency_offset << RG_XOSC_CBANK_XO_SFT);
1270             }
1271         }
1272     }
1273     for (i=0; i<sizeof(phy_setting)/sizeof(struct ssv6xxx_dev_table); i++){
1274         if (phy_setting[i].address == ADR_TX_GAIN_FACTOR){
1275             switch (sh->cfg.chip_identity) {
1276                 case SSV6051Q_P1:
1277                 case SSV6051Q_P2:
1278                 case SSV6051Q:
1279                     printk("SSV6051Q setting [0x5B606C72]\n");
1280                     phy_setting[i].data = 0x5B606C72;
1281                     break;
1282                 case SSV6051Z:
1283                     printk("SSV6051Z setting [0x60606060]\n");
1284                     phy_setting[i].data = 0x60606060;
1285                     break;
1286                 case SSV6051P:
1287                     printk("SSV6051P setting [0x6C726C72]\n");
1288                     phy_setting[i].data = 0x6C726C72;
1289                     break;
1290                 default:
1291                     printk("Use default power setting\n");
1292                     break;
1293             }
1294             if (sh->cfg.wifi_tx_gain_level_b){
1295                 phy_setting[i].data &= 0xffff0000;
1296                 phy_setting[i].data |= wifi_tx_gain[sh->cfg.wifi_tx_gain_level_b] & 0x0000ffff;
1297             }
1298             if (sh->cfg.wifi_tx_gain_level_gn){
1299                 phy_setting[i].data &= 0x0000ffff;
1300                 phy_setting[i].data |= wifi_tx_gain[sh->cfg.wifi_tx_gain_level_gn] & 0xffff0000;
1301             }
1302             printk("TX power setting 0x%x\n",phy_setting[i].data);
1303             init_iqk_cfg.cfg_def_tx_scale_11b = (phy_setting[i].data>>0) & 0xff;
1304             init_iqk_cfg.cfg_def_tx_scale_11b_p0d5 = (phy_setting[i].data>>8) & 0xff;
1305             init_iqk_cfg.cfg_def_tx_scale_11g = (phy_setting[i].data>>16) & 0xff;
1306             init_iqk_cfg.cfg_def_tx_scale_11g_p0d5 = (phy_setting[i].data>>24) & 0xff;
1307             break;
1308         }
1309     }
1310     if(sh->cfg.volt_regulator == SSV6XXX_VOLT_LDO_CONVERT)
1311     {
1312         printk("Volt regulator LDO\n");
1313         for(i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++)
1314         {
1315             if(ssv6200_rf_tbl[i].address == ADR_PMU_2)
1316             {
1317                 ssv6200_rf_tbl[i].data &= 0xFFFFFFFE;
1318                 ssv6200_rf_tbl[i].data |= 0x00000000;
1319             }
1320         }
1321     }
1322     else if(sh->cfg.volt_regulator == SSV6XXX_VOLT_DCDC_CONVERT)
1323     {
1324         printk("Volt regulator DCDC\n");
1325         for(i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++)
1326         {
1327             if(ssv6200_rf_tbl[i].address == ADR_PMU_2)
1328             {
1329                 ssv6200_rf_tbl[i].data &= 0xFFFFFFFE;
1330                 ssv6200_rf_tbl[i].data |= 0x00000001;
1331             }
1332         }
1333     }
1334     else
1335     {
1336         printk("Illegal volt regulator setting !![No XX.cfg]\n");
1337         printk("default value is SSV6XXX_VOLT_DCDC_CONVERT!!\n");
1338     }
1339 #endif
1340     while(ssv_cfg.configuration[x][0])
1341     {
1342         for(i=0; i<sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table); i++)
1343         {
1344             if(ssv6200_rf_tbl[i].address == ssv_cfg.configuration[x][0])
1345             {
1346                 ssv6200_rf_tbl[i].data = ssv_cfg.configuration[x][1];
1347                 break;
1348             }
1349         }
1350         for(i=0; i<sizeof(phy_setting)/sizeof(struct ssv6xxx_dev_table); i++)
1351         {
1352             if(phy_setting[i].address == ssv_cfg.configuration[x][0])
1353             {
1354                 phy_setting[i].data = ssv_cfg.configuration[x][1];
1355                 break;
1356             }
1357         }
1358         x++;
1359     };
1360     if (ret == 0) ret = SSV6XXX_SET_HW_TABLE(sh, ssv6200_rf_tbl);
1361     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_PHY_EN_1, 0x00000000);
1362 #ifdef CONFIG_SSV_CABRIO_E
1363     SMAC_REG_READ(sh, ADR_PHY_EN_0, &regval);
1364     if (regval & (1<<RG_RF_BB_CLK_SEL_SFT)) {
1365         printk("already do clock switch\n");
1366     }
1367     else {
1368         printk("reset PLL\n");
1369         SMAC_REG_READ(sh, ADR_DPLL_CP_PFD_REGISTER, &regval);
1370         regval |= ((1<<RG_DP_BBPLL_PD_SFT) | (1<<RG_DP_BBPLL_SDM_EDGE_SFT));
1371         SMAC_REG_WRITE(sh, ADR_DPLL_CP_PFD_REGISTER, regval);
1372         regval &= ~((1<<RG_DP_BBPLL_PD_SFT) | (1<<RG_DP_BBPLL_SDM_EDGE_SFT));
1373         SMAC_REG_WRITE(sh, ADR_DPLL_CP_PFD_REGISTER, regval);
1374         mdelay(10);
1375     }
1376 #endif
1377     if (ret == 0) ret = SSV6XXX_SET_HW_TABLE(sh, ssv6200_phy_tbl);
1378 #ifdef CONFIG_SSV_CABRIO_E
1379     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_TRX_DUMMY_REGISTER, 0xEAAAAAAA);
1380     SMAC_REG_READ(sh,ADR_TRX_DUMMY_REGISTER,&regval);
1381     if (regval != 0xEAAAAAAA)
1382     {
1383         printk("@@@@@@@@@@@@\n");
1384         printk(" SDIO issue -- please check 0xCE01008C %08x!!\n",regval);
1385         printk(" It shouble be 0xEAAAAAAA!!\n");
1386         printk("@@@@@@@@@@@@ \n");
1387     }
1388 #endif
1389 #ifdef CONFIG_SSV_CABRIO_E
1390     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_PAD53, 0x21);
1391     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_PAD54, 0x3000);
1392     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_PIN_SEL_0, 0x4000);
1393     if (ret == 0) ret = SMAC_REG_WRITE(sh, 0xc0000304, 0x01);
1394     if (ret == 0) ret = SMAC_REG_WRITE(sh, 0xc0000308, 0x01);
1395 #endif
1396     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_CLOCK_SELECTION, 0x3);
1397 #ifdef CONFIG_SSV_CABRIO_E
1398     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_TRX_DUMMY_REGISTER, 0xAAAAAAAA);
1399 #endif
1400     if ((ret=ssv6xxx_set_channel(sh->sc, sh->cfg.def_chan)))
1401         return ret;
1402     if (ret == 0) ret = SMAC_REG_WRITE(sh, ADR_PHY_EN_1,
1403                                 (RG_PHYRX_MD_EN_MSK | RG_PHYTX_MD_EN_MSK |
1404                                 RG_PHY11GN_MD_EN_MSK | RG_PHY11B_MD_EN_MSK |
1405                                 RG_PHYRXFIFO_MD_EN_MSK | RG_PHYTXFIFO_MD_EN_MSK |
1406                                 RG_PHY11BGN_MD_EN_MSK));
1407     return ret;
1408 }
ssv6xxx_check_mac2(struct ssv_hw * sh)1409 static void ssv6xxx_check_mac2(struct ssv_hw *sh)
1410 {
1411   const u8 addr_mask[6]={0xfd, 0xff, 0xff, 0xff, 0xff, 0xfc};
1412   u8 i;
1413   bool invalid = false;
1414   for ( i=0; i<6; i++) {
1415        if ((ssv_cfg.maddr[0][i] & addr_mask[i]) !=
1416                (ssv_cfg.maddr[1][i] & addr_mask[i])){
1417            invalid = true;
1418            printk (" i %d , mac1[i] %x, mac2[i] %x, mask %x \n",i, ssv_cfg.maddr[0][i] ,ssv_cfg.maddr[1][i],addr_mask[i]);
1419            break;
1420        }
1421    }
1422    if (invalid){
1423        memcpy(&ssv_cfg.maddr[1][0], &ssv_cfg.maddr[0][0], 6);
1424        ssv_cfg.maddr[1][5] ^= 0x01;
1425        if (ssv_cfg.maddr[1][5] < ssv_cfg.maddr[0][5]){
1426            u8 temp;
1427            temp = ssv_cfg.maddr[0][5];
1428            ssv_cfg.maddr[0][5] = ssv_cfg.maddr[1][5];
1429            ssv_cfg.maddr[1][5] = temp;
1430            sh->cfg.maddr[0][5] = ssv_cfg.maddr[0][5];
1431        }
1432        printk("MAC 2 address invalid!!\n" );
1433        printk("After modification, MAC1 %pM, MAC2 %pM\n",ssv_cfg.maddr[0],
1434            ssv_cfg.maddr[1]);
1435    }
1436 }
ssv6xxx_read_configuration(struct ssv_hw * sh)1437 static int ssv6xxx_read_configuration(struct ssv_hw *sh)
1438 {
1439     extern u32 sdio_sr_bhvr;
1440     if(is_valid_ether_addr(&ssv_cfg.maddr[0][0]))
1441         memcpy(&sh->cfg.maddr[0][0], &ssv_cfg.maddr[0][0], ETH_ALEN);
1442     if(is_valid_ether_addr(&ssv_cfg.maddr[1][0])){
1443         ssv6xxx_check_mac2(sh);
1444         memcpy(&sh->cfg.maddr[1][0], &ssv_cfg.maddr[1][0], ETH_ALEN);
1445     }
1446     if(ssv_cfg.hw_caps)
1447         sh->cfg.hw_caps = ssv_cfg.hw_caps;
1448     else
1449         sh->cfg.hw_caps = SSV6200_HW_CAP_HT |
1450                     SSV6200_HW_CAP_2GHZ |
1451                     SSV6200_HW_CAP_SECURITY |
1452                     SSV6200_HW_CAP_P2P|
1453                     SSV6200_HT_CAP_SGI_20|
1454                     SSV6200_HW_CAP_AMPDU_RX|
1455                     SSV6200_HW_CAP_AMPDU_TX|
1456                     SSV6200_HW_CAP_AP;
1457     if(ssv_cfg.def_chan)
1458         sh->cfg.def_chan = ssv_cfg.def_chan;
1459     else
1460         sh->cfg.def_chan = 6;
1461     sh->cfg.use_wpa2_only = ssv_cfg.use_wpa2_only;
1462     if(ssv_cfg.crystal_type == 26)
1463         sh->cfg.crystal_type = SSV6XXX_IQK_CFG_XTAL_26M;
1464     else if(ssv_cfg.crystal_type == 40)
1465         sh->cfg.crystal_type = SSV6XXX_IQK_CFG_XTAL_40M;
1466     else if(ssv_cfg.crystal_type == 24)
1467         sh->cfg.crystal_type = SSV6XXX_IQK_CFG_XTAL_24M;
1468     else
1469     {
1470         printk("Please redefine xtal_clock(wifi.cfg)!!\n");
1471         WARN_ON(1);
1472         return 1;
1473     }
1474     if(ssv_cfg.volt_regulator < 2)
1475         sh->cfg.volt_regulator = ssv_cfg.volt_regulator;
1476     else
1477     {
1478         printk("Please redefine volt_regulator(wifi.cfg)!!\n");
1479         WARN_ON(1);
1480         return 1;
1481     }
1482     sh->cfg.wifi_tx_gain_level_gn = ssv_cfg.wifi_tx_gain_level_gn;
1483     sh->cfg.wifi_tx_gain_level_b = ssv_cfg.wifi_tx_gain_level_b;
1484     sh->cfg.rssi_ctl = ssv_cfg.rssi_ctl;
1485     sh->cfg.sr_bhvr = ssv_cfg.sr_bhvr;
1486     sdio_sr_bhvr = ssv_cfg.sr_bhvr;
1487     sh->cfg.force_chip_identity = ssv_cfg.force_chip_identity;
1488     strncpy(sh->cfg.firmware_path,ssv_cfg.firmware_path,sizeof(sh->cfg.firmware_path)-1);
1489     strncpy(sh->cfg.flash_bin_path, ssv_cfg.flash_bin_path,sizeof(sh->cfg.flash_bin_path) - 1);
1490     strncpy(sh->cfg.mac_address_path,ssv_cfg.mac_address_path,sizeof(sh->cfg.mac_address_path)-1);
1491     strncpy(sh->cfg.mac_output_path,ssv_cfg.mac_output_path,sizeof(sh->cfg.mac_output_path)-1);
1492     sh->cfg.ignore_efuse_mac = ssv_cfg.ignore_efuse_mac;
1493     sh->cfg.mac_address_mode = ssv_cfg.mac_address_mode;
1494     return 0;
1495 }
ssv6xxx_read_hw_info(struct ssv_softc * sc)1496 static int ssv6xxx_read_hw_info(struct ssv_softc *sc)
1497 {
1498     struct ssv_hw *sh;
1499     sh = kzalloc(sizeof(struct ssv_hw), GFP_KERNEL);
1500     if (sh == NULL)
1501         return -ENOMEM;
1502     memset((void *)sh, 0, sizeof(struct ssv_hw));
1503     sc->sh = sh;
1504     sh->sc = sc;
1505     sh->priv = sc->dev->platform_data;
1506     if(ssv6xxx_read_configuration(sh))
1507         return -ENOMEM;
1508     sh->hci.dev = sc->dev;
1509     sh->hci.hci_ops = NULL;
1510     sh->hci.hci_rx_cb = ssv6200_rx;
1511     sh->hci.rx_cb_args = (void *)sc;
1512     sh->hci.hci_tx_cb= ssv6xxx_tx_cb;
1513     sh->hci.tx_cb_args = (void *)sc;
1514 #ifdef RATE_CONTROL_REALTIME_UPDATA
1515     sh->hci.hci_skb_update_cb = ssv6xxx_tx_rate_update;
1516     sh->hci.skb_update_args = (void *)sc;
1517 #else
1518     sh->hci.hci_skb_update_cb = NULL;
1519     sh->hci.skb_update_args = NULL;
1520 #endif
1521     sh->hci.hci_tx_flow_ctrl_cb = ssv6200_tx_flow_control;
1522     sh->hci.tx_fctrl_cb_args = (void *)sc;
1523     sh->hci.hci_tx_q_empty_cb = ssv6xxx_tx_q_empty_cb;
1524     sh->hci.tx_q_empty_args = (void *)sc;
1525     sh->hci.if_ops = sh->priv->ops;
1526     sh->hci.hci_tx_buf_free_cb = ssv6xxx_txbuf_free_skb;
1527     sh->hci.tx_buf_free_args = (void *)sc;
1528     return 0;
1529 }
ssv6xxx_init_device(struct ssv_softc * sc,const char * name)1530 static int ssv6xxx_init_device(struct ssv_softc *sc, const char *name)
1531 {
1532     struct ieee80211_hw *hw = sc->hw;
1533     struct ssv_hw *sh;
1534     int error = 0;
1535     BUG_ON(!sc->dev->platform_data);
1536     if ((error=ssv6xxx_read_hw_info(sc)) != 0) {
1537         return error;
1538     }
1539     sh = sc->sh;
1540     if (sh->cfg.hw_caps == 0)
1541         return -1;
1542     ssv6xxx_hci_register(&sh->hci);
1543     efuse_read_all_map(sh);
1544     if ((error=ssv6xxx_init_softc(sc)) != 0) {
1545         ssv6xxx_deinit_softc(sc);
1546       ssv6xxx_hci_deregister();
1547       kfree(sh);
1548         return error;
1549     }
1550     if ((error=ssv6xxx_init_hw(sc->sh)) != 0) {
1551         ssv6xxx_deinit_hw(sc);
1552       ssv6xxx_deinit_softc(sc);
1553       ssv6xxx_hci_deregister();
1554       kfree(sh);
1555         return error;
1556     }
1557     if ((error=ieee80211_register_hw(hw)) != 0) {
1558         printk(KERN_ERR "Failed to register w. %d.\n", error);
1559         ssv6xxx_deinit_hw(sc);
1560       ssv6xxx_deinit_softc(sc);
1561       ssv6xxx_hci_deregister();
1562         kfree(sh);
1563       return error;
1564     }
1565 #ifdef CONFIG_SSV6XXX_DEBUGFS
1566     ssv6xxx_init_debugfs(sc, name);
1567 #endif
1568     return 0;
1569 }
ssv6xxx_deinit_device(struct ssv_softc * sc)1570 static void ssv6xxx_deinit_device(struct ssv_softc *sc)
1571 {
1572     printk("%s(): \n", __FUNCTION__);
1573 #ifdef CONFIG_SSV6XXX_DEBUGFS
1574     ssv6xxx_deinit_debugfs(sc);
1575 #endif
1576     ssv6xxx_rf_disable(sc->sh);
1577     ieee80211_unregister_hw(sc->hw);
1578     ssv6xxx_deinit_hw(sc);
1579     ssv6xxx_deinit_softc(sc);
1580     ssv6xxx_hci_deregister();
1581     kfree(sc->sh);
1582 }
1583 extern struct ieee80211_ops ssv6200_ops;
ssv6xxx_dev_probe(struct platform_device * pdev)1584 int ssv6xxx_dev_probe(struct platform_device *pdev)
1585 {
1586 #ifdef CONFIG_SSV6200_CLI_ENABLE
1587     extern struct ssv_softc *ssv_dbg_sc;
1588 #endif
1589 #ifdef CONFIG_SSV_SMARTLINK
1590     extern struct ssv_softc *ssv_smartlink_sc;
1591 #endif
1592     struct ssv_softc *softc;
1593     struct ieee80211_hw *hw;
1594     int ret;
1595     if (!pdev->dev.platform_data) {
1596         dev_err(&pdev->dev, "no platform data specified!\n");
1597         return -EINVAL;
1598     }
1599     printk("%s(): ssv6200 device found !\n", __FUNCTION__);
1600     hw = ieee80211_alloc_hw(sizeof(struct ssv_softc), &ssv6200_ops);
1601     if (hw == NULL) {
1602         dev_err(&pdev->dev, "No memory for ieee80211_hw\n");
1603         return -ENOMEM;
1604     }
1605     SET_IEEE80211_DEV(hw, &pdev->dev);
1606     dev_set_drvdata(&pdev->dev, hw);
1607     memset((void *)hw->priv, 0, sizeof(struct ssv_softc));
1608     softc = hw->priv;
1609     softc->hw = hw;
1610     softc->dev = &pdev->dev;
1611     ret = ssv6xxx_init_device(softc, pdev->name);
1612     if (ret) {
1613         dev_err(&pdev->dev, "Failed to initialize device\n");
1614         ieee80211_free_hw(hw);
1615         return ret;
1616     }
1617 #ifdef CONFIG_SSV6200_CLI_ENABLE
1618  ssv_dbg_sc = softc;
1619 #endif
1620 #ifdef CONFIG_SSV_SMARTLINK
1621     ssv_smartlink_sc = softc;
1622 #endif
1623 #ifdef CONFIG_SSV_SUPPORT_ANDROID
1624     ssv_notify_sc = softc;
1625 #endif
1626     wiphy_info(hw->wiphy, "%s\n", "SSV6200 of South Silicon Valley");
1627     return 0;
1628 }
1629 EXPORT_SYMBOL(ssv6xxx_dev_probe);
ssv6xxx_dev_remove(struct platform_device * pdev)1630 int ssv6xxx_dev_remove(struct platform_device *pdev)
1631 {
1632     struct ieee80211_hw *hw=dev_get_drvdata(&pdev->dev);
1633     struct ssv_softc *softc=hw->priv;
1634     printk("ssv6xxx_dev_remove(): pdev=%p, hw=%p\n", pdev, hw);
1635     ssv6xxx_deinit_device(softc);
1636     printk("ieee80211_free_hw(): \n");
1637     ieee80211_free_hw(hw);
1638     pr_info("ssv6200: Driver unloaded\n");
1639     return 0;
1640 }
1641 EXPORT_SYMBOL(ssv6xxx_dev_remove);
1642 static const struct platform_device_id ssv6xxx_id_table[] = {
1643     {
1644         .name = "ssv6200",
1645         .driver_data = 0x00,
1646     },
1647     {},
1648 };
1649 MODULE_DEVICE_TABLE(platform, ssv6xxx_id_table);
1650 static struct platform_driver ssv6xxx_driver =
1651 {
1652     .probe = ssv6xxx_dev_probe,
1653 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
1654     .remove = __devexit_p(ssv6xxx_dev_remove),
1655 #else
1656     .remove = ssv6xxx_dev_remove,
1657 #endif
1658     .id_table = ssv6xxx_id_table,
1659     .driver = {
1660         .name = "SSV WLAN driver",
1661         .owner = THIS_MODULE,
1662     }
1663 };
1664 #if (defined(CONFIG_SSV_SUPPORT_ANDROID)||defined(CONFIG_SSV_BUILD_AS_ONE_KO))
ssv6xxx_init(void)1665 int ssv6xxx_init(void)
1666 #else
1667 static int __init ssv6xxx_init(void)
1668 #endif
1669 {
1670     extern void *ssv_dbg_phy_table;
1671     extern u32 ssv_dbg_phy_len;
1672     extern void *ssv_dbg_rf_table;
1673     extern u32 ssv_dbg_rf_len;
1674     ssv_dbg_phy_table = (void *)ssv6200_phy_tbl;
1675     ssv_dbg_phy_len = sizeof(ssv6200_phy_tbl)/sizeof(struct ssv6xxx_dev_table);
1676     ssv_dbg_rf_table = (void *)ssv6200_rf_tbl;
1677     ssv_dbg_rf_len = sizeof(ssv6200_rf_tbl)/sizeof(struct ssv6xxx_dev_table);
1678     return platform_driver_register(&ssv6xxx_driver);
1679 }
1680 #if (defined(CONFIG_SSV_SUPPORT_ANDROID)||defined(CONFIG_SSV_BUILD_AS_ONE_KO))
ssv6xxx_exit(void)1681 void ssv6xxx_exit(void)
1682 #else
1683 static void __exit ssv6xxx_exit(void)
1684 #endif
1685 {
1686     platform_driver_unregister(&ssv6xxx_driver);
1687 }
1688 #if (defined(CONFIG_SSV_SUPPORT_ANDROID)||defined(CONFIG_SSV_BUILD_AS_ONE_KO))
1689 EXPORT_SYMBOL(ssv6xxx_init);
1690 EXPORT_SYMBOL(ssv6xxx_exit);
1691 #else
1692 module_init(ssv6xxx_init);
1693 module_exit(ssv6xxx_exit);
1694 #endif
1695