• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Main code of XRadio drivers
3  *
4  * Copyright (c) 2013
5  * Xradio Technology Co., Ltd. <www.xradiotech.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 
12 /*Linux version 3.4.0 compilation*/
13 #include <linux/version.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/firmware.h>
17 #include <linux/etherdevice.h>
18 #include <linux/vmalloc.h>
19 #include <linux/random.h>
20 #include <linux/sched.h>
21 #include <net/mac80211.h>
22 #include <linux/platform_device.h>
23 #include <linux/mutex.h>
24 #include <linux/proc_fs.h>
25 
26 
27 #include "platform.h"
28 #include "xradio.h"
29 #include "txrx.h"
30 #include "sbus.h"
31 #include "fwio.h"
32 #include "hwio.h"
33 #include "bh.h"
34 #include "sta.h"
35 #include "ap.h"
36 #include "scan.h"
37 #include "pm.h"
38 #include "vendor.h"
39 #include "xr_version.h"
40 #include "debug.h"
41 
42 #ifndef CONFIG_DRIVERS_HDF_XR829
43 MODULE_AUTHOR("XRadioTech");
44 MODULE_DESCRIPTION("XRadioTech WLAN driver core");
45 MODULE_LICENSE("GPL");
46 MODULE_ALIAS("xradio_core");
47 #endif
48 
49 char *drv_version   = XRADIO_VERSION;
50 //char *drv_buildtime = __DATE__" "__TIME__;
51 char *drv_buildtime = " ";
52 
53 #define XRADIO_MAC_CHARLEN 18
54 #ifdef XRADIO_MACPARAM_HEX
55 /* insmod xradio_wlan.ko macaddr=0xDC, 0x44, 0x6D, 0x00, 0x00, 0x00 */
56 static u8 xradio_macaddr_param[ETH_ALEN] = { 0x0 };
57 
58 #ifndef CONFIG_DRIVERS_HDF_XR829
59 module_param_array_named(macaddr, xradio_macaddr_param, byte, NULL, S_IRUGO);
60 #endif
61 #else
62 /* insmod xradio_wlan.ko macaddr=xx:xx:xx:xx:xx:xx */
63 static char *xradio_macaddr_param;
64 #ifndef CONFIG_DRIVERS_HDF_XR829
65 module_param_named(macaddr, xradio_macaddr_param, charp, S_IRUGO);
66 #endif
67 #endif
68 
69 #ifndef CONFIG_DRIVERS_HDF_XR829
70 MODULE_PARM_DESC(macaddr, "First MAC address");
71 #endif
72 
73 #ifdef HW_RESTART
74 void xradio_restart_work(struct work_struct *work);
75 #endif
76 
77 static struct proc_dir_entry *hwinfo_proc_dir;
78 static struct proc_dir_entry *hwinfo_proc_node;
79 
80 #define HWINFO_SIZE (4 * 64)
81 static u8 *hwinfo_buffer;
82 static DEFINE_MUTEX(hwinfo_buffer_lock);
83 
84 /* TODO: use rates and channels from the device */
85 #define RATETAB_ENT(_rate, _rateid, _flags)		\
86 	{						\
87 		.bitrate  = (_rate),    \
88 		.hw_value = (_rateid),  \
89 		.flags    = (_flags),   \
90 	}
91 
92 static struct ieee80211_rate xradio_rates[] = {
93 	RATETAB_ENT(10,  0,   0),
94 	RATETAB_ENT(20,  1,   0),
95 	RATETAB_ENT(55,  2,   0),
96 	RATETAB_ENT(110, 3,   0),
97 	RATETAB_ENT(60,  6,  0),
98 	RATETAB_ENT(90,  7,  0),
99 	RATETAB_ENT(120, 8,  0),
100 	RATETAB_ENT(180, 9,  0),
101 	RATETAB_ENT(240, 10, 0),
102 	RATETAB_ENT(360, 11, 0),
103 	RATETAB_ENT(480, 12, 0),
104 	RATETAB_ENT(540, 13, 0),
105 };
106 
107 static struct ieee80211_rate xradio_mcs_rates[] = {
108 	RATETAB_ENT(65,  14, IEEE80211_TX_RC_MCS),
109 	RATETAB_ENT(130, 15, IEEE80211_TX_RC_MCS),
110 	RATETAB_ENT(195, 16, IEEE80211_TX_RC_MCS),
111 	RATETAB_ENT(260, 17, IEEE80211_TX_RC_MCS),
112 	RATETAB_ENT(390, 18, IEEE80211_TX_RC_MCS),
113 	RATETAB_ENT(520, 19, IEEE80211_TX_RC_MCS),
114 	RATETAB_ENT(585, 20, IEEE80211_TX_RC_MCS),
115 	RATETAB_ENT(650, 21, IEEE80211_TX_RC_MCS),
116 };
117 
118 #define xradio_g_rates      (xradio_rates + 0)
119 #define xradio_a_rates      (xradio_rates + 4)
120 #define xradio_n_rates      (xradio_mcs_rates)
121 
122 #define xradio_g_rates_size (ARRAY_SIZE(xradio_rates))
123 #define xradio_a_rates_size (ARRAY_SIZE(xradio_rates) - 4)
124 #define xradio_n_rates_size (ARRAY_SIZE(xradio_mcs_rates))
125 
126 #define CHAN2G(_channel, _freq, _flags) {   \
127 	.band             = NL80211_BAND_2GHZ,  \
128 	.center_freq      = (_freq),              \
129 	.hw_value         = (_channel),           \
130 	.flags            = (_flags),             \
131 	.max_antenna_gain = 0,                    \
132 	.max_power        = 30,                   \
133 }
134 
135 #define CHAN5G(_channel, _flags) {   \
136 	.band             = NL80211_BAND_5GHZ,     \
137 	.center_freq      = 5000 + (5 * (_channel)), \
138 	.hw_value         = (_channel),              \
139 	.flags            = (_flags),                \
140 	.max_antenna_gain = 0,                       \
141 	.max_power        = 30,                      \
142 }
143 
144 static struct ieee80211_channel xradio_2ghz_chantable[] = {
145 	CHAN2G(1, 2412, 0),
146 	CHAN2G(2, 2417, 0),
147 	CHAN2G(3, 2422, 0),
148 	CHAN2G(4, 2427, 0),
149 	CHAN2G(5, 2432, 0),
150 	CHAN2G(6, 2437, 0),
151 	CHAN2G(7, 2442, 0),
152 	CHAN2G(8, 2447, 0),
153 	CHAN2G(9, 2452, 0),
154 	CHAN2G(10, 2457, 0),
155 	CHAN2G(11, 2462, 0),
156 	CHAN2G(12, 2467, 0),
157 	CHAN2G(13, 2472, 0),
158 	CHAN2G(14, 2484, 0),
159 };
160 
161 #ifdef CONFIG_XRADIO_5GHZ_SUPPORT
162 static struct ieee80211_channel xradio_5ghz_chantable[] = {
163 	CHAN5G(34, 0),		CHAN5G(36, 0),
164 	CHAN5G(38, 0),		CHAN5G(40, 0),
165 	CHAN5G(42, 0),		CHAN5G(44, 0),
166 	CHAN5G(46, 0),		CHAN5G(48, 0),
167 	CHAN5G(52, 0),		CHAN5G(56, 0),
168 	CHAN5G(60, 0),		CHAN5G(64, 0),
169 	CHAN5G(100, 0),		CHAN5G(104, 0),
170 	CHAN5G(108, 0),		CHAN5G(112, 0),
171 	CHAN5G(116, 0),		CHAN5G(120, 0),
172 	CHAN5G(124, 0),		CHAN5G(128, 0),
173 	CHAN5G(132, 0),		CHAN5G(136, 0),
174 	CHAN5G(140, 0),		CHAN5G(149, 0),
175 	CHAN5G(153, 0),		CHAN5G(157, 0),
176 	CHAN5G(161, 0),		CHAN5G(165, 0),
177 	CHAN5G(184, 0),		CHAN5G(188, 0),
178 	CHAN5G(192, 0),		CHAN5G(196, 0),
179 	CHAN5G(200, 0),		CHAN5G(204, 0),
180 	CHAN5G(208, 0),		CHAN5G(212, 0),
181 	CHAN5G(216, 0),
182 };
183 #endif /* CONFIG_XRADIO_5GHZ_SUPPORT */
184 
185 static struct ieee80211_supported_band xradio_band_2ghz = {
186 	.channels = xradio_2ghz_chantable,
187 	.n_channels = ARRAY_SIZE(xradio_2ghz_chantable),
188 	.bitrates = xradio_g_rates,
189 	.n_bitrates = xradio_g_rates_size,
190 	.ht_cap = {
191 		.cap = IEEE80211_HT_CAP_GRN_FLD
192 
193 #ifdef SUPPORT_HT40
194 
195 #ifndef SUPPORT_NON_HT40_CHIP
196 			| IEEE80211_HT_CAP_SUP_WIDTH_20_40
197 			| IEEE80211_HT_CAP_SGI_20
198 			| IEEE80211_HT_CAP_SGI_40
199 #endif
200 
201 #endif
202 
203 			| (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT),
204 		.ht_supported  = 1,
205 		.ampdu_factor  = IEEE80211_HT_MAX_AMPDU_32K,
206 		.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE,
207 		.mcs = {
208 			.rx_mask[0] = 0xFF,
209 
210 #ifdef SUPPORT_HT40
211 
212 			.rx_highest = __cpu_to_le16(0x0),
213 
214 #else
215 
216 			.rx_highest = __cpu_to_le16(0x41),
217 
218 #endif
219 
220 			.tx_params  = IEEE80211_HT_MCS_TX_DEFINED,
221 		},
222 	},
223 };
224 
225 #ifdef CONFIG_XRADIO_5GHZ_SUPPORT
226 static struct ieee80211_supported_band xradio_band_5ghz = {
227 	.channels   = xradio_5ghz_chantable,
228 	.n_channels = ARRAY_SIZE(xradio_5ghz_chantable),
229 	.bitrates   = xradio_a_rates,
230 	.n_bitrates = xradio_a_rates_size,
231 	.ht_cap = {
232 		.cap = IEEE80211_HT_CAP_GRN_FLD
233 
234 #ifdef SUPPORT_HT40
235 
236 #ifndef SUPPORT_NON_HT40_CHIP
237 
238 			| IEEE80211_HT_CAP_SUP_WIDTH_20_40
239 			| IEEE80211_HT_CAP_SGI_20
240 			| IEEE80211_HT_CAP_SGI_40
241 #endif
242 
243 #endif
244 
245 			| (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT),
246 		.ht_supported  = 1,
247 		.ampdu_factor  = IEEE80211_HT_MAX_AMPDU_8K,
248 		.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE,
249 		.mcs = {
250 			.rx_mask[0] = 0xFF,
251 
252 #ifdef SUPPORT_HT40
253 
254 			.rx_highest = __cpu_to_le16(0x0),
255 
256 #else
257 
258 			.rx_highest = __cpu_to_le16(0x41),
259 
260 #endif
261 
262 			.tx_params  = IEEE80211_HT_MCS_TX_DEFINED,
263 		},
264 	},
265 };
266 #endif /* CONFIG_XRADIO_5GHZ_SUPPORT */
267 
268 static const unsigned long xradio_ttl[] = {
269 	1 * HZ,	/* VO */
270 	2 * HZ,	/* VI */
271 	5 * HZ, /* BE */
272 	10 * HZ	/* BK */
273 };
274 
275 static const struct ieee80211_ops xradio_ops = {
276 	.start             = xradio_start,
277 	.stop              = xradio_stop,
278 	.add_interface     = xradio_add_interface,
279 	.remove_interface  = xradio_remove_interface,
280 	.change_interface  = xradio_change_interface,
281 	.tx                = xradio_tx,
282 	.hw_scan           = xradio_hw_scan,
283 #ifdef ROAM_OFFLOAD
284 	.sched_scan_start  = xradio_hw_sched_scan_start,
285 	.sched_scan_stop   = xradio_hw_sched_scan_stop,
286 #endif /*ROAM_OFFLOAD*/
287 	.set_tim           = xradio_set_tim,
288 	.sta_notify        = xradio_sta_notify,
289 	.sta_add           = xradio_sta_add,
290 	.sta_remove        = xradio_sta_remove,
291 	.set_key           = xradio_set_key,
292 	.set_rts_threshold = xradio_set_rts_thresholds,
293 	.config            = xradio_config,
294 	.bss_info_changed  = xradio_bss_info_changed,
295 	.prepare_multicast = xradio_prepare_multicast,
296 	.configure_filter  = xradio_configure_filter,
297 	.conf_tx           = xradio_conf_tx,
298 	.get_stats         = xradio_get_stats,
299 	.ampdu_action      = xradio_ampdu_action,
300 	.flush             = xradio_flush,
301 #ifdef CONFIG_PM
302 	.suspend           = xradio_wow_suspend,
303 	.resume            = xradio_wow_resume,
304 #endif /* CONFIG_PM */
305 	/* Intentionally not offloaded:					*/
306 	/*.channel_switch	 = xradio_channel_switch,		*/
307 	.remain_on_channel = xradio_remain_on_channel,
308 	.cancel_remain_on_channel = xradio_cancel_remain_on_channel,
309 #ifdef IPV6_FILTERING
310 	//.set_data_filter   = xradio_set_data_filter,
311 #endif /*IPV6_FILTERING*/
312 #ifdef CONFIG_XRADIO_TESTMODE
313 	.testmode_cmd      = xradio_testmode_cmd,
314 #endif /* CONFIG_XRADIO_TESTMODE */
315 	.change_mac        = xradio_change_mac,
316 };
317 
318 struct xradio_common *g_hw_priv;
319 
320 #ifdef CONFIG_PM
321 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
322 static const struct wiphy_wowlan_support xradio_wowlan = {
323 	.flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT,
324 };
325 #endif
326 #endif
327 /**************************** functions **********************************/
xradio_version_show(void)328 void xradio_version_show(void)
329 {
330 /* Show XRADIO version and compile time */
331 	xradio_dbg(XRADIO_DBG_ALWY, "Driver Label:%s  %s\n",
332 		   DRV_VERSION, DRV_BUILDTIME);
333 
334 /************* Linux Kernel config *************/
335 #ifdef CONFIG_XRADIO_NON_POWER_OF_TWO_BLOCKSIZES
336 	xradio_dbg(XRADIO_DBG_NIY,
337 		  "[CONFIG_XRADIO_NON_POWER_OF_TWO_BLOCKSIZES]\n");
338 #endif
339 
340 #ifdef CONFIG_XRADIO_USE_GPIO_IRQ
341 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_USE_GPIO_IRQ]\n");
342 #endif
343 
344 #ifdef CONFIG_XRADIO_5GHZ_SUPPORT
345 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_5GHZ_SUPPORT]\n");
346 #endif
347 
348 #ifdef CONFIG_XRADIO_WAPI_SUPPORT
349 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_WAPI_SUPPORT]\n");
350 #endif
351 
352 #ifdef CONFIG_XRADIO_USE_EXTENSIONS
353 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_USE_EXTENSIONS]\n");
354 #endif
355 
356 #ifdef CONFIG_PM
357 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_PM]\n");
358 #endif
359 
360 #ifdef CONFIG_XRADIO_SDIO
361 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_SDIO]\n");
362 #endif
363 
364 #ifdef CONFIG_XRADIO_DUMP_ON_ERROR
365 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_DUMP_ON_ERROR]\n");
366 #endif
367 
368 #ifdef CONFIG_XRADIO_DEBUGFS
369 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_DEBUGFS]\n");
370 #endif
371 
372 #ifdef CONFIG_XRADIO_ITP
373 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_ITP]\n");
374 #endif
375 
376 #ifdef CONFIG_XRADIO_TESTMODE
377 	xradio_dbg(XRADIO_DBG_NIY, "[CONFIG_XRADIO_TESTMODE]\n");
378 #endif
379 
380 /************ XRADIO Make File config ************/
381 #ifdef P2P_MULTIVIF
382 	xradio_dbg(XRADIO_DBG_NIY, "[P2P_MULTIVIF]\n");
383 #endif
384 
385 #ifdef MCAST_FWDING
386 	xradio_dbg(XRADIO_DBG_NIY, "[MCAST_FWDING]\n");
387 #endif
388 
389 #ifdef XRADIO_SUSPEND_RESUME_FILTER_ENABLE
390 	xradio_dbg(XRADIO_DBG_NIY, "[XRADIO_SUSPEND_RESUME_FILTER_ENABLE]\n");
391 #endif
392 
393 #ifdef AP_AGGREGATE_FW_FIX
394 	xradio_dbg(XRADIO_DBG_NIY, "[AP_AGGREGATE_FW_FIX]\n");
395 #endif
396 
397 #ifdef AP_HT_CAP_UPDATE
398 	xradio_dbg(XRADIO_DBG_NIY, "[AP_HT_CAP_UPDATE]\n");
399 #endif
400 
401 #ifdef PROBE_RESP_EXTRA_IE
402 	xradio_dbg(XRADIO_DBG_NIY, "[PROBE_RESP_EXTRA_IE]\n");
403 #endif
404 
405 #ifdef IPV6_FILTERING
406 	xradio_dbg(XRADIO_DBG_NIY, "[IPV6_FILTERING]\n");
407 #endif
408 
409 #ifdef ROAM_OFFLOAD
410 	xradio_dbg(XRADIO_DBG_NIY, "[ROAM_OFFLOAD]\n");
411 #endif
412 
413 #ifdef TES_P2P_0002_ROC_RESTART
414 	xradio_dbg(XRADIO_DBG_NIY, "[TES_P2P_0002_ROC_RESTART]\n");
415 #endif
416 
417 #ifdef TES_P2P_000B_EXTEND_INACTIVITY_CNT
418 	xradio_dbg(XRADIO_DBG_NIY, "[TES_P2P_000B_EXTEND_INACTIVITY_CNT]\n");
419 #endif
420 
421 #ifdef TES_P2P_000B_DISABLE_EAPOL_FILTER
422 	xradio_dbg(XRADIO_DBG_NIY, "[TES_P2P_000B_DISABLE_EAPOL_FILTER]\n");
423 #endif
424 
425 #ifdef HAS_PUT_TASK_STRUCT
426 	xradio_dbg(XRADIO_DBG_NIY, "[HAS_PUT_TASK_STRUCT]\n");
427 #endif
428 
429 /************* XRADIO.h config *************/
430 #ifdef HIDDEN_SSID
431 	xradio_dbg(XRADIO_DBG_NIY, "[HIDDEN_SSID]\n");
432 #endif
433 
434 #ifdef ROC_DEBUG
435 	xradio_dbg(XRADIO_DBG_NIY, "[ROC_DEBUG]\n");
436 #endif
437 
438 #ifdef XRADIO_RRM
439 	xradio_dbg(XRADIO_DBG_NIY, "[XRADIO_RRM]\n");
440 #endif
441 }
442 
443 /* return 0: failed*/
xradio_macaddr_val2char(char * c_mac,const u8 * v_mac)444 static inline int xradio_macaddr_val2char(char *c_mac, const u8 *v_mac)
445 {
446 	SYS_BUG(!v_mac || !c_mac);
447 	return sprintf(c_mac, "%02x:%02x:%02x:%02x:%02x:%02x\n",
448 		       v_mac[0], v_mac[1], v_mac[2],
449 		       v_mac[3], v_mac[4], v_mac[5]);
450 }
451 
452 #ifndef XRADIO_MACPARAM_HEX
xradio_macaddr_char2val(u8 * v_mac,const char * c_mac)453 static int xradio_macaddr_char2val(u8 *v_mac, const char *c_mac)
454 {
455 	int i = 0;
456 	const char *tmp_char = c_mac;
457 	SYS_BUG(!v_mac || !c_mac);
458 
459 	for (i = 0; i < ETH_ALEN; i++) {
460 		if (*tmp_char != 0) {
461 			v_mac[i] = simple_strtoul(tmp_char, (char **)&tmp_char, 16);
462 		} else {
463 			xradio_dbg(XRADIO_DBG_ERROR, "%s, Len Error\n", __func__);
464 			return -1;
465 		}
466 		if (i < ETH_ALEN - 1 && *tmp_char != ':') {
467 			xradio_dbg(XRADIO_DBG_ERROR, "%s, Format or Len Error\n",
468 				   __func__);
469 			return -1;
470 		}
471 		tmp_char++;
472 	}
473 	return 0;
474 }
475 #endif
476 
477 /*bit0: 1=multicast, 0=unicast*/
478 /*bit1: 1=locally, 0=universally(vendor use)*/
479 #define MACADDR_VAILID(a) ( \
480 (a[0] != 0 || a[1] != 0 ||  \
481  a[2] != 0 || a[3] != 0 ||  \
482  a[4] != 0 || a[5] != 0) && \
483  !(a[0] & 0x3))
484 
485 extern int get_custom_mac_address(int fmt, char *name, char *addr);
486 
487 #ifndef CONFIG_DRIVERS_HDF_XR829
xradio_get_mac_addrs(u8 * macaddr)488 static void xradio_get_mac_addrs(u8 *macaddr)
489 #else
490 void xradio_get_mac_addrs(uint8_t *macaddr)
491 #endif
492 {
493 	int ret = 0;
494 	SYS_BUG(!macaddr);
495 	/* Check mac addrs param, if exsist, use it first.*/
496 #ifdef XRADIO_MACPARAM_HEX
497 	memcpy(macaddr, xradio_macaddr_param, ETH_ALEN);
498 #else
499 	if (xradio_macaddr_param) {
500 		ret = xradio_macaddr_char2val(macaddr, xradio_macaddr_param);
501 	}
502 #endif
503 
504 	if (ret < 0 || !MACADDR_VAILID(macaddr)) {
505 		ret = get_custom_mac_address(1, "wifi", macaddr);
506 	}
507 
508 	/* Use random value to set mac addr */
509 	if (ret < 0 || !MACADDR_VAILID(macaddr)) {
510 		xradio_dbg(XRADIO_DBG_NIY, "Use random Mac addr!\n");
511 		get_random_bytes(macaddr, 6);
512 		macaddr[0] = 0xDC;
513 		macaddr[1] = 0x44;
514 		macaddr[2] = 0x6D;
515 	}
516 	xradio_dbg(XRADIO_DBG_NIY, "MACADDR=%02x:%02x:%02x:%02x:%02x:%02x\n",
517 		   macaddr[0], macaddr[1], macaddr[2],
518 		   macaddr[3], macaddr[4], macaddr[5]);
519 }
520 
xradio_set_ifce_comb(struct xradio_common * hw_priv,struct ieee80211_hw * hw)521 static void xradio_set_ifce_comb(struct xradio_common *hw_priv,
522 				 struct ieee80211_hw *hw)
523 {
524 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
525 #ifdef P2P_MULTIVIF
526 	hw_priv->if_limits1[0].max = 2;
527 #else
528 	hw_priv->if_limits1[0].max = 1;
529 #endif
530 
531 	hw_priv->if_limits1[0].types = BIT(NL80211_IFTYPE_STATION);
532 	hw_priv->if_limits1[1].max = 1;
533 	hw_priv->if_limits1[1].types = BIT(NL80211_IFTYPE_AP);
534 
535 #ifdef P2P_MULTIVIF
536 	hw_priv->if_limits2[0].max = 3;
537 #else
538 	hw_priv->if_limits2[0].max = 2;
539 #endif
540 	hw_priv->if_limits2[0].types = BIT(NL80211_IFTYPE_STATION);
541 
542 #ifdef P2P_MULTIVIF
543 	hw_priv->if_limits3[0].max = 2;
544 #else
545 	hw_priv->if_limits3[0].max = 1;
546 #endif
547 
548 	hw_priv->if_limits3[0].types = BIT(NL80211_IFTYPE_STATION);
549 	hw_priv->if_limits3[1].max = 1;
550 	hw_priv->if_limits3[1].types = BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
551 	hw_priv->if_limits3[2].max = 1;
552 	hw_priv->if_limits3[2].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
553 
554 	/* TODO:COMBO: mac80211 doesn't yet support more than 1
555 	 * different channel */
556 	hw_priv->if_combs[0].num_different_channels = 1;
557 #ifdef P2P_MULTIVIF
558 	hw_priv->if_combs[0].max_interfaces = 3;
559 #else
560 	hw_priv->if_combs[0].max_interfaces = 2;
561 #endif
562 	hw_priv->if_combs[0].limits = hw_priv->if_limits1;
563 	hw_priv->if_combs[0].n_limits = 2;
564 
565 	hw_priv->if_combs[1].num_different_channels = 1;
566 
567 #ifdef P2P_MULTIVIF
568 	hw_priv->if_combs[1].max_interfaces = 3;
569 #else
570 	hw_priv->if_combs[1].max_interfaces = 2;
571 #endif
572 	hw_priv->if_combs[1].limits = hw_priv->if_limits2;
573 	hw_priv->if_combs[1].n_limits = 1;
574 
575 	hw_priv->if_combs[2].num_different_channels = 1;
576 #ifdef P2P_MULTIVIF
577 	hw_priv->if_combs[2].max_interfaces = 3;
578 #else
579 	hw_priv->if_combs[2].max_interfaces = 2;
580 #endif
581 	hw_priv->if_combs[2].limits = hw_priv->if_limits3;
582 	hw_priv->if_combs[2].n_limits = 3;
583 
584 	hw->wiphy->iface_combinations = &hw_priv->if_combs[0];
585 	hw->wiphy->n_iface_combinations = 3;
586 }
587 
xradio_device_init(struct xradio_common * hw_priv)588 static int xradio_device_init(struct xradio_common *hw_priv)
589 {
590 	int ret = 0;
591 	SYS_BUG(!hw_priv);
592 	/* Add pm device. */
593 	hw_priv->plat_device = platform_device_alloc(XRADIO_PLAT_DEVICE, 0);
594 	if (!hw_priv->plat_device) {
595 		xradio_dbg(XRADIO_DBG_ERROR, "%s:platform_device_alloc failed!\n",
596 				__func__);
597 		return -ENOMEM;
598 	}
599 	hw_priv->plat_device->dev.platform_data = hw_priv;
600 	ret = platform_device_add(hw_priv->plat_device);
601 	if (ret) {
602 		xradio_dbg(XRADIO_DBG_ERROR, "%s:platform_device_add failed(%d)!\n",
603 				__func__, ret);
604 		kfree(hw_priv->plat_device);
605 		hw_priv->plat_device = NULL;
606 		return ret;
607 	}
608 
609 	return 0;
610 
611 }
612 
xradio_device_deinit(struct xradio_common * hw_priv)613 static void xradio_device_deinit(struct xradio_common *hw_priv)
614 {
615 	if (hw_priv->plat_device) {
616 		hw_priv->plat_device->dev.platform_data = NULL;
617 		/* kfree is already do in platform_device_unregister.*/
618 		platform_device_unregister(hw_priv->plat_device);
619 		hw_priv->plat_device = NULL;
620 		hw_priv->pdev = NULL;
621 	} else {
622 		xradio_dbg(XRADIO_DBG_WARN, "%s:hw_priv->plat_device is NULL!\n",
623 				__func__);
624 	}
625 }
626 
xradio_init_common(size_t hw_priv_data_len)627 struct ieee80211_hw *xradio_init_common(size_t hw_priv_data_len)
628 {
629 	int i;
630 	struct ieee80211_hw *hw;
631 	struct xradio_common *hw_priv;
632 	struct ieee80211_supported_band *sband;
633 	int band;
634 
635 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
636 
637 	/* Alloc ieee_802.11 hw and xradio_common struct. */
638 	hw = mac80211_alloc_hw(hw_priv_data_len, &xradio_ops);
639 	if (!hw)
640 		return NULL;
641 	hw_priv = hw->priv;
642 	xradio_dbg(XRADIO_DBG_ALWY, "Allocated hw_priv @ %p\n", hw_priv);
643 	xradio_dbg(XRADIO_DBG_MSG, "xradio_common_size=%zu, vif_data_size=%zu\n",
644 			sizeof(struct xradio_common), sizeof(struct xradio_vif));
645 	memset(hw_priv, 0, sizeof(*hw_priv));
646 
647 	/* Get MAC address. */
648 	xradio_get_mac_addrs((u8 *)&hw_priv->addresses[0]);
649 	memcpy(hw_priv->addresses[1].addr, hw_priv->addresses[0].addr, ETH_ALEN);
650 	hw_priv->addresses[1].addr[5] += 0x01;
651 #ifdef P2P_MULTIVIF
652 	memcpy(hw_priv->addresses[2].addr, hw_priv->addresses[1].addr, ETH_ALEN);
653 	hw_priv->addresses[2].addr[4] ^= 0x80;
654 #endif
655 
656 	/* Initialize members of hw_priv. */
657 	hw_priv->hw = hw;
658 	hw_priv->if_id_slot = 0;
659 	hw_priv->roc_if_id = -1;
660 	atomic_set(&hw_priv->num_vifs, 0);
661 	/* initial rates and channels TODO: fetch from FW */
662 	hw_priv->rates = xradio_rates;
663 	hw_priv->mcs_rates = xradio_n_rates;
664 #ifdef ROAM_OFFLOAD
665 	hw_priv->auto_scanning = 0;
666 	hw_priv->frame_rcvd = 0;
667 	hw_priv->num_scanchannels = 0;
668 	hw_priv->num_2g_channels = 0;
669 	hw_priv->num_5g_channels = 0;
670 #endif /*ROAM_OFFLOAD*/
671 #ifdef AP_AGGREGATE_FW_FIX
672 	/* Enable block ACK for 4 TID (BE, VI, VI, VO). */
673 	hw_priv->ba_tid_mask = 0xB1;  /*due to HW limitations*/
674 #else
675 	/* Enable block ACK for every TID but voice. */
676 	hw_priv->ba_tid_mask = 0x3F;
677 #endif
678 	hw_priv->noise = -94;
679 	/* hw_priv->beacon_req_id = cpu_to_le32(0); */
680 
681 	/* Initialize members of ieee80211_hw, it works in UMAC. */
682 	hw->sta_data_size = sizeof(struct xradio_sta_priv);
683 	hw->vif_data_size = sizeof(struct xradio_vif);
684 
685 
686 	ieee80211_hw_set(hw, SIGNAL_DBM);
687 	ieee80211_hw_set(hw, SUPPORTS_PS);
688 	ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
689 	ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
690 	ieee80211_hw_set(hw, CONNECTION_MONITOR);
691 	ieee80211_hw_set(hw, MFP_CAPABLE);
692 	/*
693 	hw->flags = IEEE80211_HW_SIGNAL_DBM     |
694 		    IEEE80211_HW_SUPPORTS_PS   |
695 		    IEEE80211_HW_SUPPORTS_DYNAMIC_PS   |
696 		    IEEE80211_HW_REPORTS_TX_ACK_STATUS |
697 		    IEEE80211_HW_CONNECTION_MONITOR;
698        */
699 		   //  IEEE80211_HW_SUPPORTS_UAPSD		  |
700 
701 		   // IEEE80211_HW_SUPPORTS_CQM_RSSI     |
702 		    /* Aggregation is fully controlled by firmware.
703 		     * Do not need any support from the mac80211 stack */
704 		    /* IEEE80211_HW_AMPDU_AGGREGATION  | */
705 //#if defined(CONFIG_XRADIO_USE_EXTENSIONS)
706 		   // IEEE80211_HW_SUPPORTS_P2P_PS          |
707 		   // IEEE80211_HW_SUPPORTS_CQM_BEACON_MISS |
708 		   // IEEE80211_HW_SUPPORTS_CQM_TX_FAIL     |
709 //#endif /* CONFIG_XRADIO_USE_EXTENSIONS */
710 		   // IEEE80211_HW_BEACON_FILTER;
711 	hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)    |
712 				     BIT(NL80211_IFTYPE_ADHOC)      |
713 				     BIT(NL80211_IFTYPE_AP)         |
714 				     BIT(NL80211_IFTYPE_MESH_POINT) |
715 				     BIT(NL80211_IFTYPE_P2P_CLIENT) |
716 				     BIT(NL80211_IFTYPE_P2P_GO)		|
717 					 BIT(NL80211_IFTYPE_P2P_DEVICE);
718 
719 	/* Support only for limited wowlan functionalities */
720 #ifdef CONFIG_PM
721 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
722 	hw->wiphy->wowlan = &xradio_wowlan;
723 #else
724 	hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY | WIPHY_WOWLAN_DISCONNECT;
725 	hw->wiphy->wowlan.n_patterns = 0;
726 #endif
727 #endif
728 
729 #if defined(CONFIG_XRADIO_USE_EXTENSIONS)
730 	hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
731 #endif /* CONFIG_XRADIO_USE_EXTENSIONS */
732 
733 #if defined(CONFIG_XRADIO_DISABLE_BEACON_HINTS)
734 	hw->wiphy->flags |= WIPHY_FLAG_DISABLE_BEACON_HINTS;
735 #endif
736 	hw->wiphy->n_addresses = XRWL_MAX_VIFS;
737 	hw->wiphy->addresses   = hw_priv->addresses;
738 	/*
739 	 * max_remain_on_channel_duration will bigger than 500 in
740 	 * wpa_supplicant v2.3, change to 2500 and default value=5000 in umac.
741 	 */
742 	hw->wiphy->max_remain_on_channel_duration = 2500;
743 	//hw->channel_change_time = 500;	/* TODO: find actual value */
744 	hw->extra_tx_headroom = WSM_TX_EXTRA_HEADROOM +
745 				8  /* TKIP IV */      +
746 				12 /* TKIP ICV and MIC */;
747 	hw->wiphy->bands[NL80211_BAND_2GHZ] = &xradio_band_2ghz;
748 #ifdef CONFIG_XRADIO_5GHZ_SUPPORT
749 	hw->wiphy->bands[NL80211_BAND_5GHZ] = &xradio_band_5ghz;
750 #endif /* CONFIG_XRADIO_5GHZ_SUPPORT */
751 	hw->queues         = AC_QUEUE_NUM;
752 	hw->max_rates      = MAX_RATES_STAGE;
753 	hw->max_rate_tries = MAX_RATES_RETRY;
754 	/* Channel params have to be cleared before registering wiphy again */
755 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
756 		sband = hw->wiphy->bands[band];
757 		if (!sband)
758 			continue;
759 		for (i = 0; i < sband->n_channels; i++) {
760 			sband->channels[i].flags = 0;
761 			sband->channels[i].max_antenna_gain = 0;
762 			sband->channels[i].max_power = 30;
763 		}
764 	}
765 	/*
766 	 * hw_priv->channel init value is the local->oper_channel init value;
767 	 *  when transplanting, take care.
768 	 */
769 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
770 		sband = hw->wiphy->bands[band];
771 		if (!sband)
772 			continue;
773 		if (!hw_priv->channel) {
774 			hw_priv->channel = &sband->channels[2];
775 		}
776 	}
777 	hw->wiphy->max_scan_ssids = WSM_SCAN_MAX_NUM_OF_SSIDS;
778 	hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
779 	SET_IEEE80211_PERM_ADDR(hw, hw_priv->addresses[0].addr);
780 
781 	xradio_vendor_init(hw->wiphy);
782 
783 	/* Initialize locks. */
784 	spin_lock_init(&hw_priv->vif_list_lock);
785 	sema_init(&hw_priv->wsm_cmd_sema, 1);
786 	sema_init(&hw_priv->conf_lock, 1);
787 	sema_init(&hw_priv->wsm_oper_lock, 1);
788 	atomic_set(&hw_priv->tx_lock, 0);
789 	sema_init(&hw_priv->tx_lock_sem, 1);
790 	sema_init(&hw_priv->dtor_lock, 1);
791 
792 	hw_priv->workqueue = create_singlethread_workqueue(XRADIO_WORKQUEUE);
793 	hw_priv->spare_workqueue = create_singlethread_workqueue(XRADIO_SPARE_WORKQUEUE);
794 	sema_init(&hw_priv->scan.lock, 1);
795 	sema_init(&hw_priv->scan.status_lock, 1);
796 	INIT_WORK(&hw_priv->scan.work, xradio_scan_work);
797 #ifdef ROAM_OFFLOAD
798 	INIT_WORK(&hw_priv->scan.swork, xradio_sched_scan_work);
799 #endif /*ROAM_OFFLOAD*/
800 	INIT_DELAYED_WORK(&hw_priv->scan.probe_work, xradio_probe_work);
801 	INIT_DELAYED_WORK(&hw_priv->scan.timeout, xradio_scan_timeout);
802 	hw_priv->scan.scan_failed_cnt = 0;
803 	INIT_DELAYED_WORK(&hw_priv->rem_chan_timeout, xradio_rem_chan_timeout);
804 	INIT_WORK(&hw_priv->tx_policy_upload_work, tx_policy_upload_work);
805 	atomic_set(&hw_priv->upload_count, 0);
806 	for (i = 0; i < (XRWL_MAX_VIFS-1); ++i) {
807 		hw_priv->scan_delay_status[i] = XRADIO_SCAN_ALLOW;
808 		hw_priv->scan_delay_time[i] = 0;
809 	}
810 
811 	spin_lock_init(&hw_priv->event_queue_lock);
812 	INIT_LIST_HEAD(&hw_priv->event_queue);
813 	INIT_WORK(&hw_priv->event_handler, xradio_event_handler);
814 	INIT_WORK(&hw_priv->ba_work, xradio_ba_work);
815 	spin_lock_init(&hw_priv->ba_lock);
816 	timer_setup(&hw_priv->ba_timer, xradio_ba_timer, 0);
817 	timer_setup(&hw_priv->BT_timer, xradio_bt_timer, 0);
818 
819 	if (unlikely(xradio_queue_stats_init(&hw_priv->tx_queue_stats,
820 			WLAN_LINK_ID_MAX, xradio_skb_dtor, hw_priv))) {
821 		mac80211_free_hw(hw);
822 		return NULL;
823 	}
824 	for (i = 0; i < AC_QUEUE_NUM; ++i) {
825 		if (unlikely(xradio_queue_init(&hw_priv->tx_queue[i],
826 				     &hw_priv->tx_queue_stats, i,
827 				     XRWL_MAX_QUEUE_SZ, xradio_ttl[i]))) {
828 			for (; i > 0; i--)
829 				xradio_queue_deinit(&hw_priv->tx_queue[i - 1]);
830 			xradio_queue_stats_deinit(&hw_priv->tx_queue_stats);
831 			mac80211_free_hw(hw);
832 			return NULL;
833 		}
834 	}
835 
836 	init_waitqueue_head(&hw_priv->channel_switch_done);
837 	init_waitqueue_head(&hw_priv->wsm_cmd_wq);
838 	init_waitqueue_head(&hw_priv->wsm_wakeup_done);
839 	init_waitqueue_head(&hw_priv->wsm_startup_done);
840 	init_waitqueue_head(&hw_priv->offchannel_wq);
841 	hw_priv->wsm_caps.firmwareReady = 0;
842 	hw_priv->driver_ready = 0;
843 	hw_priv->offchannel_done = 0;
844 	wsm_buf_init(&hw_priv->wsm_cmd_buf, xr_sdio_blksize_align(1024));
845 	spin_lock_init(&hw_priv->wsm_cmd.lock);
846 	tx_policy_init(hw_priv);
847 	xradio_init_resv_skb(hw_priv);
848 
849 	for (i = 0; i < XRWL_MAX_VIFS; i++)
850 		hw_priv->hw_bufs_used_vif[i] = 0;
851 
852 #ifdef MCAST_FWDING
853 	wsm_init_release_buffer_request(hw_priv);
854 	hw_priv->buf_released = 0;
855 #endif
856 	hw_priv->vif0_throttle = XRWL_HOST_VIF0_11BG_THROTTLE;
857 	hw_priv->vif1_throttle = XRWL_HOST_VIF1_11BG_THROTTLE;
858 
859 #if defined(CONFIG_XRADIO_DEBUG)
860 	hw_priv->wsm_enable_wsm_dumps = 0;
861 	hw_priv->wsm_dump_max_size = WSM_DUMP_MAX_SIZE;
862 #endif /* CONFIG_XRADIO_DEBUG */
863 	hw_priv->query_packetID = 0;
864 	atomic_set(&hw_priv->query_cnt, 0);
865 	INIT_WORK(&hw_priv->query_work, wsm_query_work);
866 	atomic_set(&hw_priv->suspend_state, XRADIO_RESUME);
867 	atomic_set(&hw_priv->suspend_lock_state, XRADIO_SUSPEND_LOCK_IDEL);
868 
869 #ifdef HW_RESTART
870 	hw_priv->exit_sync  = false;
871 	hw_priv->hw_restart = false;
872 	hw_priv->hw_cant_wakeup = false;
873 	INIT_WORK(&hw_priv->hw_restart_work, xradio_restart_work);
874 #endif
875 
876 #ifdef CONFIG_XRADIO_TESTMODE
877 	hw_priv->test_frame.data = NULL;
878 	hw_priv->test_frame.len = 0;
879 	spin_lock_init(&hw_priv->tsm_lock);
880 	INIT_DELAYED_WORK(&hw_priv->advance_scan_timeout,
881 			  xradio_advance_scan_timeout);
882 #endif /*CONFIG_XRADIO_TESTMODE*/
883 
884 	xradio_set_ifce_comb(hw_priv, hw_priv->hw);
885 #ifdef MONITOR_MODE
886 	hw_priv->monitor_if_id = -1;
887 	hw_priv->monitor_running = false;
888 #endif
889 #ifdef BOOT_NOT_READY_FIX
890 	hw_priv->boot_not_ready_cnt = 0;
891 	hw_priv->boot_not_ready = 0;
892 #endif
893 	hw_priv->join_chan = 1;
894 
895 	if (!g_hw_priv) {
896 		g_hw_priv = hw_priv;
897 		return hw;
898 	} else {		/*error:didn't release hw_priv last time. */
899 		mac80211_free_hw(hw);
900 		xradio_dbg(XRADIO_DBG_ERROR, "g_hw_priv is not NULL @ %p!\n", g_hw_priv);
901 		return NULL;
902 	}
903 }
904 
xradio_free_common(struct ieee80211_hw * dev)905 void xradio_free_common(struct ieee80211_hw *dev)
906 {
907 	int i;
908 	struct xradio_common *hw_priv = dev->priv;
909 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
910 
911 #ifdef CONFIG_XRADIO_TESTMODE
912 	kfree(hw_priv->test_frame.data);
913 #endif /* CONFIG_XRADIO_TESTMODE */
914 
915 	cancel_work_sync(&hw_priv->query_work);
916 	del_timer_sync(&hw_priv->ba_timer);
917 	del_timer_sync(&hw_priv->BT_timer);
918 	wsm_buf_deinit(&hw_priv->wsm_cmd_buf);
919 	flush_workqueue(hw_priv->workqueue);
920 	destroy_workqueue(hw_priv->workqueue);
921 	hw_priv->workqueue = NULL;
922 	flush_workqueue(hw_priv->spare_workqueue);
923 	destroy_workqueue(hw_priv->spare_workqueue);
924 	hw_priv->spare_workqueue = NULL;
925 
926 	xradio_deinit_resv_skb(hw_priv);
927 	if (hw_priv->skb_cache) {
928 		dev_kfree_skb(hw_priv->skb_cache);
929 		hw_priv->skb_cache = NULL;
930 	}
931 
932 	for (i = 0; i < 4; ++i)
933 		xradio_queue_deinit(&hw_priv->tx_queue[i]);
934 	xradio_queue_stats_deinit(&hw_priv->tx_queue_stats);
935 
936 #ifdef CONFIG_XRADIO_DEBUG
937 	for (i = 0; i < XRWL_MAX_VIFS; i++) {
938 		if (hw_priv->vif_list[i])
939 			xradio_dbg(XRADIO_DBG_ERROR,
940 			"vif_list[%d]is not NULL @ %p!\n", i, hw_priv->vif_list[i]);
941 	}
942 #endif
943 
944 #ifdef MCAST_FWDING
945 	wsm_deinit_release_buffer(hw_priv);
946 #endif
947 	/* unsigned int i; */
948 	mac80211_free_hw(dev);
949 	g_hw_priv = NULL;
950 }
951 
xradio_register_common(struct ieee80211_hw * dev)952 int xradio_register_common(struct ieee80211_hw *dev)
953 {
954 	int err = 0;
955 	struct xradio_common *hw_priv = dev->priv;
956 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
957 
958 	SET_IEEE80211_DEV(dev, hw_priv->pdev);
959 	err = mac80211_register_hw(dev);
960 	if (err) {
961 		xradio_dbg(XRADIO_DBG_ERROR, "Cannot register device (%d).\n", err);
962 		return err;
963 	}
964 	xradio_dbg(XRADIO_DBG_MSG, "is registered as '%s'\n",
965 		   wiphy_name(dev->wiphy));
966 	xradio_debug_init_common(hw_priv);
967 
968 #ifdef CONFIG_XRADIO_DEBUGFS
969 #if (SUPPORT_EPTA)
970 	SYS_WARN(wsm_set_epta_stat_dbg_ctrl(hw_priv, epta_stat_dbg_ctrl));
971 #endif
972 #endif
973 
974 	hw_priv->driver_ready = 1;
975 	wake_up(&hw_priv->wsm_startup_done);
976 	return 0;
977 }
978 
xradio_unregister_common(struct ieee80211_hw * dev)979 void xradio_unregister_common(struct ieee80211_hw *dev)
980 {
981 	struct xradio_common *hw_priv = dev->priv;
982 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
983 #ifdef CONFIG_XRADIO_ETF
984 	if (etf_is_connect()) {
985 		return ;
986 	}
987 #endif
988 
989 	if (wiphy_dev(dev->wiphy)) {
990 		mac80211_unregister_hw(dev);
991 		SET_IEEE80211_DEV(dev, NULL);
992 		xradio_debug_release_common(hw_priv);
993 	}
994 	hw_priv->driver_ready = 0;
995 }
996 
997 #ifdef HW_RESTART
xradio_find_rfkill(struct device * dev,void * data)998 static int xradio_find_rfkill(struct device *dev, void *data)
999 {
1000 	if (dev_name(dev)[0] == 'r' && dev_name(dev)[1] == 'f')
1001 		return true;
1002 	return false;
1003 }
1004 
xradio_core_reinit(struct xradio_common * hw_priv,int count)1005 int xradio_core_reinit(struct xradio_common *hw_priv, int count)
1006 {
1007 	int ret = 0;
1008 	u16 ctrl_reg;
1009 	int i = 0;
1010 	struct device *rfkill;
1011 	struct xradio_vif *priv = NULL;
1012 	struct wsm_operational_mode mode = {
1013 		.power_mode = wsm_power_mode_quiescent,
1014 		.disableMoreFlagUsage = true,
1015 	};
1016 
1017 	if (!hw_priv) {
1018 		xradio_dbg(XRADIO_DBG_ERROR, "%s hw_priv is NULL!\n", __func__);
1019 		return -1;
1020 	}
1021 
1022 	/* Need some time for restart hardware, don't suspend again.*/
1023 #ifdef CONFIG_PM
1024 	xradio_pm_lock_awake(&hw_priv->pm_state);
1025 #endif
1026 
1027 	xradio_dbg(XRADIO_DBG_ALWY, "%s %d!\n", __func__, __LINE__);
1028 
1029 	/* Disconnect with AP or STAs. */
1030 	xradio_for_each_vif(hw_priv, priv, i) {
1031 		if (!priv)
1032 			continue;
1033 		if (priv->join_status == XRADIO_JOIN_STATUS_STA) {
1034 			mac80211_connection_loss(priv->vif);
1035 			msleep(200);
1036 		} else if (priv->join_status == XRADIO_JOIN_STATUS_AP) {
1037 			wsm_send_disassoc_to_self(hw_priv, priv);
1038 			msleep(200);
1039 		}
1040 		xradio_remove_interface(hw_priv->hw, priv->vif);
1041 	}
1042 	xradio_stop(hw_priv->hw);
1043 	/* lock queue of network. */
1044 	xradio_tx_queues_lock(hw_priv);
1045 
1046 #ifdef BH_PROC_THREAD
1047 	/* restart proc thread. */
1048 	bh_proc_reinit(hw_priv);
1049 #endif
1050 
1051 	/*deinit dev */
1052 	xradio_dev_deinit(hw_priv);
1053 
1054 	/*reinit status refer to hif. */
1055 	hw_priv->powersave_enabled = false;
1056 	hw_priv->wsm_caps.firmwareReady = 0;
1057 	atomic_set(&hw_priv->bh_rx, 0);
1058 	atomic_set(&hw_priv->bh_tx, 0);
1059 	atomic_set(&hw_priv->bh_term, 0);
1060 	hw_priv->buf_id_tx = 0;
1061 	hw_priv->buf_id_rx = 0;
1062 	hw_priv->wsm_rx_seq = 0;
1063 	hw_priv->wsm_tx_seq = 0;
1064 	hw_priv->device_can_sleep = 0;
1065 	hw_priv->hw_bufs_used = 0;
1066 #ifdef BOOT_NOT_READY_FIX
1067 	hw_priv->boot_not_ready_cnt = 0;
1068 	hw_priv->boot_not_ready = 0;
1069 #endif
1070 	memset(&hw_priv->hw_bufs_used_vif, 0, sizeof(hw_priv->hw_bufs_used_vif));
1071 	for (i = 0; i < (XRWL_MAX_VIFS-1); ++i) {
1072 		hw_priv->scan_delay_status[i] = XRADIO_SCAN_ALLOW;
1073 		hw_priv->scan_delay_time[i] = 0;
1074 	}
1075 	atomic_set(&hw_priv->query_cnt, 0);
1076 	hw_priv->query_packetID = 0;
1077 	tx_policy_init(hw_priv);
1078 
1079 #ifdef BOOT_NOT_READY_FIX
1080 restart:
1081 #endif
1082 
1083 	/*move parent to plat_device*/
1084 	ret = device_move(&hw_priv->hw->wiphy->dev,
1085 			&hw_priv->plat_device->dev, 0);
1086 	if (ret < 0) {
1087 		xradio_dbg(XRADIO_DBG_ERROR,
1088 			"%s:device move parent"
1089 			"to plat_device failed\n", __func__);
1090 		goto exit;
1091 	}
1092 	ret = mac80211_ifdev_move(hw_priv->hw, &hw_priv->plat_device->dev, 0);
1093 	if (ret < 0) {
1094 		xradio_dbg(XRADIO_DBG_ERROR,
1095 			"%s:net_device move parent"
1096 			"to plat_device failed\n", __func__);
1097 		goto exit;
1098 	}
1099 
1100 	/*
1101 	 * If the wlan device can't wake up, we need to
1102 	 * close the bt device to restart the wlan&bt device
1103 	 */
1104 	if (hw_priv->hw_cant_wakeup && count > 1)
1105 		xradio_bt_power(false);
1106 
1107 	/*reinit sdio sbus. */
1108 	sbus_sdio_deinit();
1109 	hw_priv->pdev = sbus_sdio_init((struct sbus_ops **)&hw_priv->sbus_ops,
1110 				       &hw_priv->sbus_priv);
1111 	if (!hw_priv->pdev) {
1112 		xradio_dbg(XRADIO_DBG_ERROR, "%s:sbus_sdio_init failed\n", __func__);
1113 		ret = -ETIMEDOUT;
1114 		goto exit;
1115 	}
1116 
1117 	/*move parent to sdio device*/
1118 	ret = device_move(&hw_priv->hw->wiphy->dev, hw_priv->pdev, 1);
1119 	if (ret < 0) {
1120 		xradio_dbg(XRADIO_DBG_ERROR,
1121 			"%s:device move parent to sdio failed\n", __func__);
1122 		goto exit;
1123 	}
1124 	SET_IEEE80211_DEV(hw_priv->hw, hw_priv->pdev);
1125 	ret = mac80211_ifdev_move(hw_priv->hw, hw_priv->pdev, 1);
1126 	if (ret < 0) {
1127 		xradio_dbg(XRADIO_DBG_ERROR,
1128 			"%s:net_device move parent to sdio failed\n", __func__);
1129 		goto exit;
1130 	}
1131 
1132 	rfkill = device_find_child(&hw_priv->hw->wiphy->dev, NULL, xradio_find_rfkill);
1133 	device_move(rfkill, &hw_priv->hw->wiphy->dev, 1);
1134 	put_device(rfkill);
1135 
1136 	/*wake up bh thread. */
1137 	if (hw_priv->bh_thread == NULL) {
1138 		hw_priv->bh_error = 0;
1139 		atomic_set(&hw_priv->tx_lock, 0);
1140 		xradio_register_bh(hw_priv);
1141 	} else {
1142 #ifdef CONFIG_XRADIO_SUSPEND_POWER_OFF
1143 		WARN_ON(xradio_bh_resume(hw_priv));
1144 #endif
1145 	}
1146 
1147 	/* Load firmware and register Interrupt Handler */
1148 	ret = xradio_load_firmware(hw_priv);
1149 #ifdef BOOT_NOT_READY_FIX
1150 	if (ret && hw_priv->boot_not_ready && (hw_priv->boot_not_ready_cnt < 6)) {
1151 		ret = 0;
1152 		hw_priv->boot_not_ready = 0;
1153 		if (hw_priv->bh_thread != NULL)
1154 			xradio_unregister_bh(hw_priv);
1155 		goto restart;
1156 	}
1157 #endif
1158 	if (ret) {
1159 		xradio_dbg(XRADIO_DBG_ERROR, "%s:xradio_load_firmware failed(%d).\n",
1160 			   __func__, ret);
1161 		goto exit;
1162 	}
1163 	hw_priv->hw_cant_wakeup = false;
1164 
1165 	/* Set sdio blocksize. */
1166 	hw_priv->sbus_ops->lock(hw_priv->sbus_priv);
1167 	SYS_WARN(hw_priv->sbus_ops->set_block_size(hw_priv->sbus_priv,
1168 		 SDIO_BLOCK_SIZE));
1169 	hw_priv->sbus_ops->unlock(hw_priv->sbus_priv);
1170 	if (wait_event_interruptible_timeout(hw_priv->wsm_startup_done,
1171 				hw_priv->wsm_caps.firmwareReady, 3*HZ) <= 0) {
1172 
1173 		/* TODO: Needs to find how to reset device */
1174 		/*       in QUEUE mode properly.           */
1175 		xradio_dbg(XRADIO_DBG_ERROR, "%s:Firmware Startup Timeout!\n",
1176 			   __func__);
1177 		ret = -ETIMEDOUT;
1178 		goto exit;
1179 	}
1180 	xradio_dbg(XRADIO_DBG_ALWY, "%s:Firmware Startup Done.\n", __func__);
1181 
1182 	/* Keep device wake up. */
1183 	ret = xradio_reg_write_16(hw_priv, HIF_CONTROL_REG_ID, HIF_CTRL_WUP_BIT);
1184 	if (xradio_reg_read_16(hw_priv, HIF_CONTROL_REG_ID, &ctrl_reg))
1185 		ret = xradio_reg_read_16(hw_priv, HIF_CONTROL_REG_ID, &ctrl_reg);
1186 	SYS_WARN(!(ctrl_reg & HIF_CTRL_RDY_BIT));
1187 
1188 	/*
1189 	 * We finish device restart here.
1190 	 */
1191 	hw_priv->hw_restart = false;
1192 	atomic_set(&hw_priv->suspend_state, XRADIO_RESUME);
1193 	wake_up(&hw_priv->wsm_wakeup_done);
1194 
1195 	/* Set device mode parameter. */
1196 	for (i = 0; i < xrwl_get_nr_hw_ifaces(hw_priv); i++) {
1197 		/* Set low-power mode. */
1198 		ret = wsm_set_operational_mode(hw_priv, &mode, i);
1199 		/* Enable multi-TX confirmation */
1200 		ret = wsm_use_multi_tx_conf(hw_priv, true, i);
1201 	}
1202 
1203 #ifdef CONFIG_XRADIO_DEBUGFS
1204 #if (SUPPORT_EPTA)
1205 	SYS_WARN(wsm_set_epta_stat_dbg_ctrl(hw_priv, epta_stat_dbg_ctrl));
1206 #endif
1207 #endif
1208 
1209 #if 0
1210 	/*
1211 	 * IF USE xradio_register_common TO REINIT, U SHOULD ENABLE THIS.
1212 	 * fix super standby hang in scan interface.
1213 	 * Since resume from super standby, mac system will register ieee80211_hw to
1214 	 * subsystem, and the wiphy->max_scan_ie_len will decrease 47 every round whose
1215 	 * initial value is IEEE80211_MAX_DATA_LEN, after about 40~50 round, this value will
1216 	 * under 143. and the 143 is the default scan ie length from supplicant, this will return
1217 	 * -22 in nl80211.c
1218 	 * if (n_ssids > wiphy->max_scan_ssids) {
1219 	 * 	return -EINVAL;
1220 	 * }
1221 	 * we need to reinit this value in super standby recovery.
1222 	 */
1223 	hw_priv->hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
1224 #endif
1225 	/*
1226 	 * Restart umac, use mac80211_restart_hw.
1227 	 * Use xradio_register_common may cause umac scan sync problems.
1228 	 */
1229 	if (!ret) {
1230 		mac80211_restart_hw(hw_priv->hw);
1231 	}
1232 
1233 	/*
1234 	 * Unlock queue of network. regardless of xradio_tx_queues_lock,
1235 	 * this must be here to make sure all queue is unlock.
1236 	 */
1237 	for (i = 0; i < 4; ++i) {
1238 		struct xradio_queue *queue = &hw_priv->tx_queue[i];
1239 		spin_lock_bh(&queue->lock);
1240 		if (queue->tx_locked_cnt > 0) {
1241 			queue->tx_locked_cnt = 0;
1242 			mac80211_wake_queue(hw_priv->hw, queue->queue_id);
1243 		}
1244 		spin_unlock_bh(&queue->lock);
1245 	}
1246 
1247 exit:
1248 #ifdef CONFIG_PM
1249 	xradio_pm_unlock_awake(&hw_priv->pm_state);
1250 #endif
1251 	xradio_dbg(XRADIO_DBG_ALWY, "%s end!\n", __func__);
1252 
1253 	return ret;
1254 }
1255 
1256 #define RESTARTS_TIMES_LIMIT   5
xradio_restart_work(struct work_struct * work)1257 void xradio_restart_work(struct work_struct *work)
1258 {
1259 	struct xradio_common *hw_priv =
1260 		container_of(work, struct xradio_common, hw_restart_work);
1261 	int i = 0;
1262 	int ret = 0;
1263 
1264 	xradio_dbg(XRADIO_DBG_ALWY, "%s\n", __func__);
1265 
1266 	hw_priv->hw_restart_work_running = 1;
1267 	if (hw_priv->bh_error) {
1268 		xradio_unregister_bh(hw_priv);
1269 	}
1270 
1271 	for (i = 0; i < RESTARTS_TIMES_LIMIT; i++) {
1272 		ret = xradio_core_reinit(hw_priv, i);
1273 		if (!ret)
1274 			break;
1275 		xradio_dbg(XRADIO_DBG_ALWY, "%s again, count = %d!\n", __func__, i);
1276 		down(&hw_priv->wsm_cmd_sema);
1277 		hw_priv->hw_restart = true;
1278 		up(&hw_priv->wsm_cmd_sema);
1279 		if (hw_priv->bh_thread != NULL)
1280 			xradio_unregister_bh(hw_priv);
1281 #ifdef ERROR_HANG_DRIVER
1282 		if (error_hang_driver) {
1283 			/*it will arrive here if error occurs in poweroff resume.*/
1284 			hw_priv->bh_error = 0x80000000; /*make it different from real bh error.*/
1285 			wsm_printk(XRADIO_DBG_ERROR, "%s error_hang_driver\n", __func__);
1286 			hw_priv->hw_restart_work_running = 0;
1287 			return ;
1288 		}
1289 #endif
1290 
1291 	}
1292 	hw_priv->hw_restart_work_running = 0;
1293 }
1294 #endif
1295 
xradio_core_init(void)1296 int xradio_core_init(void)
1297 {
1298 	int err = -ENOMEM;
1299 	u16 ctrl_reg;
1300 	int if_id;
1301 	struct ieee80211_hw *dev;
1302 	struct xradio_common *hw_priv;
1303 	struct wsm_operational_mode mode = {
1304 		.power_mode = wsm_power_mode_quiescent,
1305 		.disableMoreFlagUsage = true,
1306 	};
1307 	xradio_version_show();
1308 
1309 	/*init xradio_common */
1310 	dev = xradio_init_common(sizeof(struct xradio_common));
1311 	if (!dev) {
1312 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_init_common failed\n");
1313 		return err;
1314 	}
1315 	hw_priv = dev->priv;
1316 	if (xradio_device_init(hw_priv)) {
1317 		xradio_free_common(dev);
1318 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_device_init failed\n");
1319 		return err;
1320 	}
1321 
1322 #ifdef BH_PROC_THREAD
1323 	err = bh_proc_init(hw_priv);
1324 	if (err) {
1325 		bh_printk(XRADIO_DBG_ERROR,
1326 			"%s bh_proc_init err=%d\n", __func__, err);
1327 		return err;
1328 	}
1329 #endif
1330 
1331 #ifdef BOOT_NOT_READY_FIX
1332 start:
1333 #endif
1334 	/*init sdio sbus */
1335 	hw_priv->pdev = sbus_sdio_init((struct sbus_ops **)&hw_priv->sbus_ops,
1336 				&hw_priv->sbus_priv);
1337 	if (!hw_priv->pdev) {
1338 		err = -ETIMEDOUT;
1339 		xradio_dbg(XRADIO_DBG_ERROR, "sbus_sdio_init failed\n");
1340 		goto err1;
1341 	}
1342 
1343 	/* WSM callbacks. */
1344 	hw_priv->wsm_cbc.scan_complete = xradio_scan_complete_cb;
1345 	hw_priv->wsm_cbc.tx_confirm = xradio_tx_confirm_cb;
1346 	hw_priv->wsm_cbc.rx = xradio_rx_cb;
1347 	hw_priv->wsm_cbc.suspend_resume = xradio_suspend_resume;
1348 	/* hw_priv->wsm_cbc.set_pm_complete = xradio_set_pm_complete_cb; */
1349 	hw_priv->wsm_cbc.channel_switch = xradio_channel_switch_cb;
1350 
1351 	/*init pm and wakelock. */
1352 #ifdef CONFIG_PM
1353 	err = xradio_pm_init(&hw_priv->pm_state, hw_priv);
1354 	if (err) {
1355 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_pm_init failed(%d).\n", err);
1356 		goto err2;
1357 	}
1358 #endif
1359 	/* Register bh thread*/
1360 	err = xradio_register_bh(hw_priv);
1361 	if (err) {
1362 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_register_bh failed(%d).\n",
1363 			   err);
1364 		goto err3;
1365 	}
1366 
1367 	/* Load firmware and register Interrupt Handler */
1368 	err = xradio_load_firmware(hw_priv);
1369 #ifdef BOOT_NOT_READY_FIX
1370 	if (err && hw_priv->boot_not_ready && (hw_priv->boot_not_ready_cnt < 6)) {/*workaround that */
1371 		hw_priv->boot_not_ready = 0;
1372 		err = 0;
1373 		xradio_unregister_bh(hw_priv);
1374 #ifdef CONFIG_PM
1375 		xradio_pm_deinit(&hw_priv->pm_state);
1376 #endif
1377 		sbus_sdio_deinit();
1378 		goto start;
1379 	}
1380 #endif
1381 	if (err) {
1382 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_load_firmware failed(%d).\n",
1383 			   err);
1384 		goto err4;
1385 	}
1386 
1387 	/* Set sdio blocksize. */
1388 	hw_priv->sbus_ops->lock(hw_priv->sbus_priv);
1389 	SYS_WARN(hw_priv->sbus_ops->set_block_size(hw_priv->sbus_priv,
1390 			SDIO_BLOCK_SIZE));
1391 	hw_priv->sbus_ops->unlock(hw_priv->sbus_priv);
1392 
1393 	if (wait_event_interruptible_timeout(hw_priv->wsm_startup_done,
1394 				hw_priv->wsm_caps.firmwareReady, 3*HZ) <= 0) {
1395 
1396 		/* TODO: Needs to find how to reset device */
1397 		/*       in QUEUE mode properly.           */
1398 		xradio_dbg(XRADIO_DBG_ERROR, "Firmware Startup Timeout!\n");
1399 		err = -ETIMEDOUT;
1400 		goto err5;
1401 	}
1402 	xradio_dbg(XRADIO_DBG_ALWY, "Firmware Startup Done.\n");
1403 
1404 	/* Keep device wake up. */
1405 	err = xradio_reg_bit_operate(hw_priv, HIF_CONTROL_REG_ID, HIF_CTRL_WUP_BIT, 0);
1406 	if (err) {
1407 		xradio_dbg(XRADIO_DBG_ERROR, "device wake up failed(%d)!\n", err);
1408 		goto err5;
1409 	}
1410 	SYS_WARN(xradio_reg_read_16(hw_priv, HIF_CONTROL_REG_ID, &ctrl_reg));
1411 	SYS_WARN(!(ctrl_reg & HIF_CTRL_RDY_BIT));
1412 
1413 	/* ETF mode don't need following steps, just return here*/
1414 #ifdef CONFIG_XRADIO_ETF
1415 	if (etf_is_connect()) {
1416 		etf_set_core(hw_priv);
1417 		xradio_dbg(XRADIO_DBG_ALWY, "%s Enter ETF mode!\n", __func__);
1418 		return 0;
1419 	}
1420 #endif
1421 
1422 	/* Set device mode parameter. */
1423 	for (if_id = 0; if_id < xrwl_get_nr_hw_ifaces(hw_priv); if_id++) {
1424 		u32 multi_enabled = __cpu_to_le32(BIT(0));
1425 		/* Set low-power mode. */
1426 		SYS_WARN(wsm_set_operational_mode(hw_priv, &mode, if_id));
1427 		if (hw_priv->wsm_caps.firmwareCap & 0x8000) {
1428 			multi_enabled |= __cpu_to_le32(BIT(2));
1429 			xradio_dbg(XRADIO_DBG_WARN, "enable Multi-Rx!\n");
1430 		}
1431 		/* Enable multi-TX confirmation */
1432 		SYS_WARN(wsm_use_multi_tx_conf(hw_priv, multi_enabled, if_id));
1433 	}
1434 
1435 	/* Register wireless net device. */
1436 	err = xradio_register_common(dev);
1437 	if (err) {
1438 		xradio_dbg(XRADIO_DBG_ERROR,
1439 			   "xradio_register_common failed(%d)!\n", err);
1440 		goto err5;
1441 	}
1442 	return err;
1443 
1444 err5:
1445 	xradio_dev_deinit(hw_priv);
1446 err4:
1447 	xradio_unregister_bh(hw_priv);
1448 err3:
1449 #ifdef CONFIG_PM
1450 	xradio_pm_deinit(&hw_priv->pm_state);
1451 err2:
1452 #endif
1453 #ifdef ERROR_HANG_DRIVER
1454 	/*we want to use sdio in hang driver.*/
1455 	if (!error_hang_driver) {
1456 		sbus_sdio_deinit();
1457 	}
1458 #else
1459 	sbus_sdio_deinit();
1460 #endif
1461 err1:
1462 #ifdef ERROR_HANG_DRIVER
1463 	xradio_hang_driver_for_debug(hw_priv, err);
1464 #endif
1465 	xradio_device_deinit(hw_priv);
1466 	xradio_free_common(dev);
1467 	return err;
1468 }
1469 
xradio_core_deinit(void)1470 void xradio_core_deinit(void)
1471 {
1472 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
1473 	if (g_hw_priv) {
1474 #ifdef HW_RESTART
1475 		down(&g_hw_priv->wsm_cmd_sema);
1476 		g_hw_priv->exit_sync = true;
1477 		up(&g_hw_priv->wsm_cmd_sema);
1478 		cancel_work_sync(&g_hw_priv->hw_restart_work);
1479 #endif
1480 		xradio_vendor_close_mkeep_alive();
1481 #ifdef ERROR_HANG_DRIVER
1482 		/*we hang driver here before unregister.*/
1483 		xradio_hang_driver_for_debug(g_hw_priv, g_hw_priv->bh_error);
1484 #endif
1485 
1486 #ifdef CONFIG_XRADIO_ETF
1487 		if (etf_is_connect()) {
1488 			etf_set_core(NULL);
1489 			xradio_dbg(XRADIO_DBG_ALWY, "%s Exit ETF mode!\n", __func__);
1490 		} else
1491 			xradio_unregister_common(g_hw_priv->hw);
1492 #else
1493 		xradio_unregister_common(g_hw_priv->hw);
1494 #endif
1495 
1496 #ifdef BH_PROC_THREAD
1497 		bh_proc_deinit(g_hw_priv);
1498 #endif
1499 		xradio_dev_deinit(g_hw_priv);
1500 		xradio_unregister_bh(g_hw_priv);
1501 #ifdef CONFIG_PM
1502 		xradio_pm_deinit(&g_hw_priv->pm_state);
1503 #endif
1504 		xradio_device_deinit(g_hw_priv);
1505 		xradio_free_common(g_hw_priv->hw);
1506 		sbus_sdio_deinit();
1507 	}
1508 	return;
1509 }
1510 
hwinfo_proc_show(struct seq_file * m,void * v)1511 static int hwinfo_proc_show(struct seq_file *m, void *v)
1512 {
1513 	char *buf;
1514 	size_t hwinfo_size = HWINFO_SIZE;
1515 	size_t size;
1516 
1517 	if (hwinfo_buffer == NULL)
1518 		return 0;
1519 
1520 	size = seq_get_buf(m, &buf);
1521 
1522 	/* single_ can only show once */
1523 	if (unlikely(hwinfo_size >= size)) {
1524 		/* if buffer is not enough, seq will double it and try again */
1525 		xradio_dbg(XRADIO_DBG_WARN,
1526 				   "hwinfo file size is over than seq buffer, try expand and try again\n");
1527 		/* set seq overflowed like seq_set_overflow() */
1528 		seq_commit(m, size);
1529 		goto out;
1530 	}
1531 
1532 	mutex_lock(&hwinfo_buffer_lock);
1533 	memcpy(buf, hwinfo_buffer, hwinfo_size);
1534 	mutex_unlock(&hwinfo_buffer_lock);
1535 	seq_commit(m, hwinfo_size);
1536 
1537 out:
1538 	return 0;
1539 }
1540 
hwinfo_proc_open(struct inode * p_inode,struct file * p_file)1541 int hwinfo_proc_open(struct inode *p_inode, struct file *p_file)
1542 {
1543 	return single_open(p_file, hwinfo_proc_show, NULL);
1544 }
1545 
1546 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
1547 static struct proc_ops hwinfo_proc_op = {
1548 	.proc_open    = hwinfo_proc_open,
1549 	.proc_read    = seq_read,
1550 	.proc_lseek   = seq_lseek,
1551 	.proc_release = single_release,
1552 };
1553 
1554 #else
1555 
1556 static struct file_operations hwinfo_proc_op = {
1557 	.owner		= THIS_MODULE,
1558 	.open		= hwinfo_proc_open,
1559 	.read		= seq_read,
1560 	.llseek		= seq_lseek,
1561 	.release	= single_release,
1562 };
1563 #endif
1564 
1565 /* Init Module function -> Called by insmod */
1566 #ifndef CONFIG_DRIVERS_HDF_XR829
xradio_core_entry(void)1567 int __init xradio_core_entry(void)
1568 #else
1569 int  xradio_core_entry(void)
1570 #endif
1571 {
1572 	int ret = 0;
1573 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
1574 	ret = xradio_plat_init();
1575 	if (ret) {
1576 		xradio_dbg(XRADIO_DBG_ERROR, "xradio_plat_init failed(%d)!\n", ret);
1577 		return ret;
1578 	}
1579 	ret = xradio_host_dbg_init();
1580 	if (ret) {
1581 		xradio_dbg(XRADIO_DBG_ERROR, "%s dbg init failed(%d)!\n", __func__, ret);
1582 		xradio_plat_deinit();
1583 		return ret;
1584 	}
1585 #ifdef CONFIG_XRADIO_ETF
1586 	ret = xradio_etf_init();
1587 	if (ret) {
1588 		xradio_dbg(XRADIO_DBG_ERROR, "%s ETF init failed(%d)!\n", __func__, ret);
1589 		xradio_host_dbg_deinit();
1590 		xradio_plat_deinit();
1591 		return ret;
1592 	}
1593 #endif
1594 
1595 	hwinfo_proc_dir = proc_mkdir("xradio", NULL);
1596 	hwinfo_proc_node = proc_create("hwinfo", 0644, hwinfo_proc_dir, &hwinfo_proc_op);
1597 
1598 	return 0;
1599 }
1600 
1601 /* Called at Driver Unloading */
xradio_core_exit(void)1602 void xradio_core_exit(void)
1603 {
1604 	remove_proc_entry("hwinfo", hwinfo_proc_dir);
1605 	remove_proc_entry("xradio", NULL);
1606 
1607 	if (hwinfo_buffer) {
1608 		kfree(hwinfo_buffer);
1609 		hwinfo_buffer = NULL;
1610 	}
1611 
1612 #ifdef CONFIG_XRADIO_ETF
1613 	xradio_etf_deinit();
1614 #endif
1615 	xradio_host_dbg_deinit();
1616 	xradio_plat_deinit();
1617 	xradio_dbg(XRADIO_DBG_TRC, "%s\n", __func__);
1618 }
1619 
1620 #ifdef CONFIG_DRIVERS_HDF_XR829
1621 EXPORT_SYMBOL(xradio_get_mac_addrs);
1622 #endif