PageRenderTime 73ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/mac80211/compat_wl12xx/drivers/net/wireless/wl12xx/main.c

https://github.com/MiniCMX/android_hardware_ti_wlan
C | 6146 lines | 4596 code | 1056 blank | 494 comment | 766 complexity | 30a110685dd6d5734e7145f902b23def MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/firmware.h>
  25. #include <linux/delay.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/crc32.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/slab.h>
  32. #include <linux/wl12xx.h>
  33. #include <linux/sched.h>
  34. #include <linux/interrupt.h>
  35. #include "wl12xx.h"
  36. #include "debug.h"
  37. #include "wl12xx_80211.h"
  38. #include "reg.h"
  39. #include "io.h"
  40. #include "event.h"
  41. #include "tx.h"
  42. #include "rx.h"
  43. #include "ps.h"
  44. #include "init.h"
  45. #include "debugfs.h"
  46. #include "cmd.h"
  47. #include "boot.h"
  48. #include "testmode.h"
  49. #include "scan.h"
  50. #include "version.h"
  51. #define WL1271_BOOT_RETRIES 3
  52. static struct conf_drv_settings default_conf = {
  53. .sg = {
  54. .params = {
  55. [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
  56. [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
  57. [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
  58. [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
  59. [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
  60. [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
  61. [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
  62. [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
  63. [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
  64. [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
  65. [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
  66. [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
  67. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
  68. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
  69. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
  70. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
  71. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
  72. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
  73. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
  74. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
  75. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
  76. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
  77. [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
  78. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
  79. [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
  80. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
  81. /* active scan params */
  82. [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
  83. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
  84. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
  85. /* passive scan params */
  86. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
  87. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
  88. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
  89. /* passive scan in dual antenna params */
  90. [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
  91. [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
  92. [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
  93. /* general params */
  94. [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
  95. [CONF_SG_ANTENNA_CONFIGURATION] = 0,
  96. [CONF_SG_BEACON_MISS_PERCENT] = 60,
  97. [CONF_SG_DHCP_TIME] = 5000,
  98. [CONF_SG_RXT] = 1200,
  99. [CONF_SG_TXT] = 1000,
  100. [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
  101. [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
  102. [CONF_SG_HV3_MAX_SERVED] = 6,
  103. [CONF_SG_PS_POLL_TIMEOUT] = 10,
  104. [CONF_SG_UPSD_TIMEOUT] = 10,
  105. [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
  106. [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
  107. [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
  108. /* AP params */
  109. [CONF_AP_BEACON_MISS_TX] = 3,
  110. [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
  111. [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
  112. [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
  113. [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
  114. [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
  115. /* CTS Diluting params */
  116. [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
  117. [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
  118. },
  119. .state = CONF_SG_PROTECTIVE,
  120. },
  121. .rx = {
  122. .rx_msdu_life_time = 512000,
  123. .packet_detection_threshold = 0,
  124. .ps_poll_timeout = 15,
  125. .upsd_timeout = 15,
  126. .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
  127. .rx_cca_threshold = 0,
  128. .irq_blk_threshold = 0xFFFF,
  129. .irq_pkt_threshold = 0,
  130. .irq_timeout = 600,
  131. .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
  132. },
  133. .tx = {
  134. .tx_energy_detection = 0,
  135. .sta_rc_conf = {
  136. .enabled_rates = 0,
  137. .short_retry_limit = 10,
  138. .long_retry_limit = 10,
  139. .aflags = 0,
  140. },
  141. .ac_conf_count = 4,
  142. .ac_conf = {
  143. [CONF_TX_AC_BE] = {
  144. .ac = CONF_TX_AC_BE,
  145. .cw_min = 15,
  146. .cw_max = 63,
  147. .aifsn = 3,
  148. .tx_op_limit = 0,
  149. },
  150. [CONF_TX_AC_BK] = {
  151. .ac = CONF_TX_AC_BK,
  152. .cw_min = 15,
  153. .cw_max = 63,
  154. .aifsn = 7,
  155. .tx_op_limit = 0,
  156. },
  157. [CONF_TX_AC_VI] = {
  158. .ac = CONF_TX_AC_VI,
  159. .cw_min = 15,
  160. .cw_max = 63,
  161. .aifsn = CONF_TX_AIFS_PIFS,
  162. .tx_op_limit = 3008,
  163. },
  164. [CONF_TX_AC_VO] = {
  165. .ac = CONF_TX_AC_VO,
  166. .cw_min = 15,
  167. .cw_max = 63,
  168. .aifsn = CONF_TX_AIFS_PIFS,
  169. .tx_op_limit = 1504,
  170. },
  171. },
  172. .max_tx_retries = 100,
  173. .ap_aging_period = 300,
  174. .tid_conf_count = 4,
  175. .tid_conf = {
  176. [CONF_TX_AC_BE] = {
  177. .queue_id = CONF_TX_AC_BE,
  178. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  179. .tsid = CONF_TX_AC_BE,
  180. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  181. .ack_policy = CONF_ACK_POLICY_LEGACY,
  182. .apsd_conf = {0, 0},
  183. },
  184. [CONF_TX_AC_BK] = {
  185. .queue_id = CONF_TX_AC_BK,
  186. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  187. .tsid = CONF_TX_AC_BK,
  188. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  189. .ack_policy = CONF_ACK_POLICY_LEGACY,
  190. .apsd_conf = {0, 0},
  191. },
  192. [CONF_TX_AC_VI] = {
  193. .queue_id = CONF_TX_AC_VI,
  194. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  195. .tsid = CONF_TX_AC_VI,
  196. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  197. .ack_policy = CONF_ACK_POLICY_LEGACY,
  198. .apsd_conf = {0, 0},
  199. },
  200. [CONF_TX_AC_VO] = {
  201. .queue_id = CONF_TX_AC_VO,
  202. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  203. .tsid = CONF_TX_AC_VO,
  204. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  205. .ack_policy = CONF_ACK_POLICY_LEGACY,
  206. .apsd_conf = {0, 0},
  207. },
  208. },
  209. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  210. .tx_compl_timeout = 700,
  211. .tx_compl_threshold = 4,
  212. .basic_rate = CONF_HW_BIT_RATE_1MBPS,
  213. .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
  214. .tmpl_short_retry_limit = 10,
  215. .tmpl_long_retry_limit = 10,
  216. },
  217. .conn = {
  218. .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  219. .listen_interval = 1,
  220. .suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  221. .suspend_listen_interval = 1,
  222. .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
  223. .bcn_filt_ie_count = 3,
  224. .bcn_filt_ie = {
  225. [0] = {
  226. .ie = WLAN_EID_CHANNEL_SWITCH,
  227. .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
  228. },
  229. [1] = {
  230. .ie = WLAN_EID_HT_INFORMATION,
  231. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  232. },
  233. [2] = {
  234. .ie = WLAN_EID_ERP_INFO,
  235. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  236. },
  237. },
  238. .synch_fail_thold = 12,
  239. .bss_lose_timeout = 400,
  240. .cons_bcn_loss_time = 5000,
  241. .max_bcn_loss_time = 10000,
  242. .beacon_rx_timeout = 10000,
  243. .broadcast_timeout = 20000,
  244. .rx_broadcast_in_ps = 1,
  245. .ps_poll_threshold = 10,
  246. .bet_enable = CONF_BET_MODE_ENABLE,
  247. .bet_max_consecutive = 50,
  248. .psm_entry_retries = 8,
  249. .psm_exit_retries = 16,
  250. .psm_entry_nullfunc_retries = 3,
  251. .dynamic_ps_timeout = 1500,
  252. .forced_ps = false,
  253. .keep_alive_interval = 55000,
  254. .max_listen_interval = 20,
  255. },
  256. .itrim = {
  257. .enable = false,
  258. .timeout = 50000,
  259. },
  260. .pm_config = {
  261. .host_clk_settling_time = 5000,
  262. .host_fast_wakeup_support = false
  263. },
  264. .roam_trigger = {
  265. .trigger_pacing = 1,
  266. .avg_weight_rssi_beacon = 20,
  267. .avg_weight_rssi_data = 10,
  268. .avg_weight_snr_beacon = 20,
  269. .avg_weight_snr_data = 10,
  270. },
  271. .scan = {
  272. .min_dwell_time_active = 7500,
  273. .max_dwell_time_active = 30000,
  274. .min_dwell_time_passive = 100000,
  275. .max_dwell_time_passive = 100000,
  276. .num_probe_reqs = 2,
  277. .split_scan_timeout = 50000,
  278. },
  279. .sched_scan = {
  280. /*
  281. * Values are in TU/1000 but since sched scan FW command
  282. * params are in TUs rounding up may occur.
  283. */
  284. .base_dwell_time = 7500,
  285. .max_dwell_time_delta = 22500,
  286. /* based on 250bits per probe @1Mbps */
  287. .dwell_time_delta_per_probe = 2000,
  288. /* based on 250bits per probe @6Mbps (plus a bit more) */
  289. .dwell_time_delta_per_probe_5 = 350,
  290. .dwell_time_passive = 100000,
  291. .dwell_time_dfs = 150000,
  292. .num_probe_reqs = 2,
  293. .rssi_threshold = -90,
  294. .snr_threshold = 0,
  295. },
  296. .rf = {
  297. .tx_per_channel_power_compensation_2 = {
  298. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  299. },
  300. .tx_per_channel_power_compensation_5 = {
  301. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  302. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  303. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  304. },
  305. },
  306. .ht = {
  307. .rx_ba_win_size = 8,
  308. .tx_ba_win_size = 64,
  309. .inactivity_timeout = 10000,
  310. .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
  311. },
  312. .mem_wl127x = {
  313. .num_stations = 1,
  314. .ssid_profiles = 1,
  315. .rx_block_num = 70,
  316. .tx_min_block_num = 40,
  317. .dynamic_memory = 1,
  318. .min_req_tx_blocks = 100,
  319. .min_req_rx_blocks = 22,
  320. .tx_min = 27,
  321. },
  322. .mem_wl128x = {
  323. .num_stations = 1,
  324. .ssid_profiles = 1,
  325. .rx_block_num = 40,
  326. .tx_min_block_num = 40,
  327. .dynamic_memory = 1,
  328. .min_req_tx_blocks = 45,
  329. .min_req_rx_blocks = 22,
  330. .tx_min = 27,
  331. },
  332. .fm_coex = {
  333. .enable = true,
  334. .swallow_period = 5,
  335. .n_divider_fref_set_1 = 0xff, /* default */
  336. .n_divider_fref_set_2 = 12,
  337. .m_divider_fref_set_1 = 0xffff,
  338. .m_divider_fref_set_2 = 148, /* default */
  339. .coex_pll_stabilization_time = 0xffffffff, /* default */
  340. .ldo_stabilization_time = 0xffff, /* default */
  341. .fm_disturbed_band_margin = 0xff, /* default */
  342. .swallow_clk_diff = 0xff, /* default */
  343. },
  344. .rx_streaming = {
  345. .duration = 150,
  346. .queues = 0x1,
  347. .interval = 20,
  348. .always = 0,
  349. },
  350. .fwlog = {
  351. .mode = WL12XX_FWLOG_ON_DEMAND,
  352. .mem_blocks = 2,
  353. .severity = 0,
  354. .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
  355. .output = WL12XX_FWLOG_OUTPUT_HOST,
  356. .threshold = 0,
  357. },
  358. .hci_io_ds = HCI_IO_DS_6MA,
  359. .rate = {
  360. .rate_retry_score = 32000,
  361. .per_add = 8192,
  362. .per_th1 = 2048,
  363. .per_th2 = 4096,
  364. .max_per = 8100,
  365. .inverse_curiosity_factor = 5,
  366. .tx_fail_low_th = 4,
  367. .tx_fail_high_th = 10,
  368. .per_alpha_shift = 4,
  369. .per_add_shift = 13,
  370. .per_beta1_shift = 10,
  371. .per_beta2_shift = 8,
  372. .rate_check_up = 2,
  373. .rate_check_down = 12,
  374. .rate_retry_policy = {
  375. 0x00, 0x00, 0x00, 0x00, 0x00,
  376. 0x00, 0x00, 0x00, 0x00, 0x00,
  377. 0x00, 0x00, 0x00,
  378. },
  379. },
  380. .hangover = {
  381. .recover_time = 0,
  382. .hangover_period = 20,
  383. .dynamic_mode = 1,
  384. .early_termination_mode = 1,
  385. .max_period = 20,
  386. .min_period = 1,
  387. .increase_delta = 1,
  388. .decrease_delta = 2,
  389. .quiet_time = 4,
  390. .increase_time = 1,
  391. .window_size = 16,
  392. },
  393. };
  394. static char *fwlog_param;
  395. static bool bug_on_recovery;
  396. static char *fref_param;
  397. static char *tcxo_param;
  398. static void __wl1271_op_remove_interface(struct wl1271 *wl,
  399. struct ieee80211_vif *vif,
  400. bool reset_tx_queues);
  401. static void wl1271_op_stop(struct ieee80211_hw *hw);
  402. static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
  403. static DEFINE_MUTEX(wl_list_mutex);
  404. static LIST_HEAD(wl_list);
  405. static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  406. unsigned char operstate)
  407. {
  408. int ret;
  409. if (operstate != IF_OPER_UP)
  410. return 0;
  411. if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
  412. return 0;
  413. ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
  414. if (ret < 0)
  415. return ret;
  416. wl12xx_croc(wl, wlvif->role_id);
  417. wl1271_info("Association completed.");
  418. return 0;
  419. }
  420. static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
  421. void *arg)
  422. {
  423. struct net_device *dev = arg;
  424. struct wireless_dev *wdev;
  425. struct wiphy *wiphy;
  426. struct ieee80211_hw *hw;
  427. struct wl1271 *wl;
  428. struct wl1271 *wl_temp;
  429. struct wl12xx_vif *wlvif;
  430. int ret = 0;
  431. /* Check that this notification is for us. */
  432. if (what != NETDEV_CHANGE)
  433. return NOTIFY_DONE;
  434. wdev = dev->ieee80211_ptr;
  435. if (wdev == NULL)
  436. return NOTIFY_DONE;
  437. wiphy = wdev->wiphy;
  438. if (wiphy == NULL)
  439. return NOTIFY_DONE;
  440. hw = wiphy_priv(wiphy);
  441. if (hw == NULL)
  442. return NOTIFY_DONE;
  443. wl_temp = hw->priv;
  444. mutex_lock(&wl_list_mutex);
  445. list_for_each_entry(wl, &wl_list, list) {
  446. if (wl == wl_temp)
  447. break;
  448. }
  449. mutex_unlock(&wl_list_mutex);
  450. if (wl != wl_temp)
  451. return NOTIFY_DONE;
  452. mutex_lock(&wl->mutex);
  453. if (wl->state == WL1271_STATE_OFF)
  454. goto out;
  455. if (dev->operstate != IF_OPER_UP)
  456. goto out;
  457. /*
  458. * The correct behavior should be just getting the appropriate wlvif
  459. * from the given dev, but currently we don't have a mac80211
  460. * interface for it.
  461. */
  462. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  463. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  464. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  465. continue;
  466. ret = wl1271_ps_elp_wakeup(wl);
  467. if (ret < 0)
  468. goto out;
  469. wl1271_check_operstate(wl, wlvif,
  470. ieee80211_get_operstate(vif));
  471. wl1271_ps_elp_sleep(wl);
  472. }
  473. out:
  474. mutex_unlock(&wl->mutex);
  475. return NOTIFY_OK;
  476. }
  477. static int wl1271_reg_notify(struct wiphy *wiphy,
  478. struct regulatory_request *request)
  479. {
  480. struct ieee80211_supported_band *band;
  481. struct ieee80211_channel *ch;
  482. int i;
  483. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  484. for (i = 0; i < band->n_channels; i++) {
  485. ch = &band->channels[i];
  486. if (ch->flags & IEEE80211_CHAN_DISABLED)
  487. continue;
  488. if (ch->flags & IEEE80211_CHAN_RADAR)
  489. ch->flags |= IEEE80211_CHAN_NO_IBSS |
  490. IEEE80211_CHAN_PASSIVE_SCAN;
  491. }
  492. return 0;
  493. }
  494. static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  495. bool enable)
  496. {
  497. int ret = 0;
  498. /* we should hold wl->mutex */
  499. ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
  500. if (ret < 0)
  501. goto out;
  502. if (enable)
  503. set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
  504. else
  505. clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
  506. out:
  507. return ret;
  508. }
  509. /*
  510. * this function is being called when the rx_streaming interval
  511. * has beed changed or rx_streaming should be disabled
  512. */
  513. int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  514. {
  515. int ret = 0;
  516. int period = wl->conf.rx_streaming.interval;
  517. /* don't reconfigure if rx_streaming is disabled */
  518. if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
  519. goto out;
  520. /* reconfigure/disable according to new streaming_period */
  521. if (period &&
  522. test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
  523. (wl->conf.rx_streaming.always ||
  524. test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
  525. ret = wl1271_set_rx_streaming(wl, wlvif, true);
  526. else {
  527. ret = wl1271_set_rx_streaming(wl, wlvif, false);
  528. /* don't cancel_work_sync since we might deadlock */
  529. del_timer_sync(&wlvif->rx_streaming_timer);
  530. }
  531. out:
  532. return ret;
  533. }
  534. static void wl1271_rx_streaming_enable_work(struct work_struct *work)
  535. {
  536. int ret;
  537. struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
  538. rx_streaming_enable_work);
  539. struct wl1271 *wl = wlvif->wl;
  540. mutex_lock(&wl->mutex);
  541. if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
  542. !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
  543. (!wl->conf.rx_streaming.always &&
  544. !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
  545. goto out;
  546. if (!wl->conf.rx_streaming.interval)
  547. goto out;
  548. ret = wl1271_ps_elp_wakeup(wl);
  549. if (ret < 0)
  550. goto out;
  551. ret = wl1271_set_rx_streaming(wl, wlvif, true);
  552. if (ret < 0)
  553. goto out_sleep;
  554. /* stop it after some time of inactivity */
  555. mod_timer(&wlvif->rx_streaming_timer,
  556. jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
  557. out_sleep:
  558. wl1271_ps_elp_sleep(wl);
  559. out:
  560. mutex_unlock(&wl->mutex);
  561. }
  562. static void wl1271_rx_streaming_disable_work(struct work_struct *work)
  563. {
  564. int ret;
  565. struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
  566. rx_streaming_disable_work);
  567. struct wl1271 *wl = wlvif->wl;
  568. mutex_lock(&wl->mutex);
  569. if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
  570. goto out;
  571. ret = wl1271_ps_elp_wakeup(wl);
  572. if (ret < 0)
  573. goto out;
  574. ret = wl1271_set_rx_streaming(wl, wlvif, false);
  575. if (ret)
  576. goto out_sleep;
  577. out_sleep:
  578. wl1271_ps_elp_sleep(wl);
  579. out:
  580. mutex_unlock(&wl->mutex);
  581. }
  582. static void wl1271_rx_streaming_timer(unsigned long data)
  583. {
  584. struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
  585. struct wl1271 *wl = wlvif->wl;
  586. ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
  587. }
  588. static void wl1271_conf_init(struct wl1271 *wl)
  589. {
  590. /*
  591. * This function applies the default configuration to the driver. This
  592. * function is invoked upon driver load (spi probe.)
  593. *
  594. * The configuration is stored in a run-time structure in order to
  595. * facilitate for run-time adjustment of any of the parameters. Making
  596. * changes to the configuration structure will apply the new values on
  597. * the next interface up (wl1271_op_start.)
  598. */
  599. /* apply driver default configuration */
  600. memcpy(&wl->conf, &default_conf, sizeof(default_conf));
  601. /* Adjust settings according to optional module parameters */
  602. if (fwlog_param) {
  603. if (!strcmp(fwlog_param, "continuous")) {
  604. wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
  605. } else if (!strcmp(fwlog_param, "ondemand")) {
  606. wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
  607. } else if (!strcmp(fwlog_param, "dbgpins")) {
  608. wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
  609. wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
  610. } else if (!strcmp(fwlog_param, "disable")) {
  611. wl->conf.fwlog.mem_blocks = 0;
  612. wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
  613. } else {
  614. wl1271_error("Unknown fwlog parameter %s", fwlog_param);
  615. }
  616. }
  617. wl->ref_clock = -1;
  618. if (fref_param) {
  619. if (!strcmp(fref_param, "19.2"))
  620. wl->ref_clock = WL12XX_REFCLOCK_19;
  621. else if (!strcmp(fref_param, "26"))
  622. wl->ref_clock = WL12XX_REFCLOCK_26;
  623. else if (!strcmp(fref_param, "26x"))
  624. wl->ref_clock = WL12XX_REFCLOCK_26_XTAL;
  625. else if (!strcmp(fref_param, "38.4"))
  626. wl->ref_clock = WL12XX_REFCLOCK_38;
  627. else if (!strcmp(fref_param, "38.4x"))
  628. wl->ref_clock = WL12XX_REFCLOCK_38_XTAL;
  629. else if (!strcmp(fref_param, "52"))
  630. wl->ref_clock = WL12XX_REFCLOCK_52;
  631. else
  632. wl1271_error("Invalid fref parameter %s", fref_param);
  633. }
  634. wl->tcxo_clock = -1;
  635. if (tcxo_param) {
  636. if (!strcmp(tcxo_param, "19.2"))
  637. wl->tcxo_clock = WL12XX_TCXOCLOCK_19_2;
  638. else if (!strcmp(tcxo_param, "26"))
  639. wl->tcxo_clock = WL12XX_TCXOCLOCK_26;
  640. else if (!strcmp(tcxo_param, "38.4"))
  641. wl->tcxo_clock = WL12XX_TCXOCLOCK_38_4;
  642. else if (!strcmp(tcxo_param, "52"))
  643. wl->tcxo_clock = WL12XX_TCXOCLOCK_52;
  644. else if (!strcmp(tcxo_param, "16.368"))
  645. wl->tcxo_clock = WL12XX_TCXOCLOCK_16_368;
  646. else if (!strcmp(tcxo_param, "32.736"))
  647. wl->tcxo_clock = WL12XX_TCXOCLOCK_32_736;
  648. else if (!strcmp(tcxo_param, "16.8"))
  649. wl->tcxo_clock = WL12XX_TCXOCLOCK_16_8;
  650. else if (!strcmp(tcxo_param, "33.6"))
  651. wl->tcxo_clock = WL12XX_TCXOCLOCK_33_6;
  652. else
  653. wl1271_error("Invalid tcxo parameter %s", tcxo_param);
  654. }
  655. }
  656. static int wl1271_plt_init(struct wl1271 *wl)
  657. {
  658. int ret;
  659. if (wl->chip.id == CHIP_ID_1283_PG20)
  660. ret = wl128x_cmd_general_parms(wl);
  661. else
  662. ret = wl1271_cmd_general_parms(wl);
  663. if (ret < 0)
  664. return ret;
  665. if (wl->chip.id == CHIP_ID_1283_PG20)
  666. ret = wl128x_cmd_radio_parms(wl);
  667. else
  668. ret = wl1271_cmd_radio_parms(wl);
  669. if (ret < 0)
  670. return ret;
  671. if (wl->chip.id != CHIP_ID_1283_PG20) {
  672. ret = wl1271_cmd_ext_radio_parms(wl);
  673. if (ret < 0)
  674. return ret;
  675. }
  676. if (ret < 0)
  677. return ret;
  678. /* Chip-specific initializations */
  679. ret = wl1271_chip_specific_init(wl);
  680. if (ret < 0)
  681. return ret;
  682. ret = wl1271_acx_init_mem_config(wl);
  683. if (ret < 0)
  684. return ret;
  685. ret = wl12xx_acx_mem_cfg(wl);
  686. if (ret < 0)
  687. goto out_free_memmap;
  688. /* Enable data path */
  689. ret = wl1271_cmd_data_path(wl, 1);
  690. if (ret < 0)
  691. goto out_free_memmap;
  692. /* Configure for CAM power saving (ie. always active) */
  693. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  694. if (ret < 0)
  695. goto out_free_memmap;
  696. /* configure PM */
  697. ret = wl1271_acx_pm_config(wl);
  698. if (ret < 0)
  699. goto out_free_memmap;
  700. return 0;
  701. out_free_memmap:
  702. kfree(wl->target_mem_map);
  703. wl->target_mem_map = NULL;
  704. return ret;
  705. }
  706. static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
  707. struct wl12xx_vif *wlvif,
  708. u8 hlid, u8 tx_pkts)
  709. {
  710. bool fw_ps, single_sta;
  711. fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
  712. single_sta = (wl->active_sta_count == 1);
  713. /*
  714. * Wake up from high level PS if the STA is asleep with too little
  715. * packets in FW or if the STA is awake.
  716. */
  717. if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
  718. wl12xx_ps_link_end(wl, wlvif, hlid);
  719. /*
  720. * Start high-level PS if the STA is asleep with enough blocks in FW.
  721. * Make an exception if this is the only connected station. In this
  722. * case FW-memory congestion is not a problem.
  723. */
  724. else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
  725. wl12xx_ps_link_start(wl, wlvif, hlid, true);
  726. }
  727. static void wl12xx_irq_update_links_status(struct wl1271 *wl,
  728. struct wl12xx_vif *wlvif,
  729. struct wl12xx_fw_status *status)
  730. {
  731. struct wl1271_link *lnk;
  732. u32 cur_fw_ps_map;
  733. u8 hlid, cnt;
  734. /* TODO: also use link_fast_bitmap here */
  735. cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
  736. if (wl->ap_fw_ps_map != cur_fw_ps_map) {
  737. wl1271_debug(DEBUG_PSM,
  738. "link ps prev 0x%x cur 0x%x changed 0x%x",
  739. wl->ap_fw_ps_map, cur_fw_ps_map,
  740. wl->ap_fw_ps_map ^ cur_fw_ps_map);
  741. wl->ap_fw_ps_map = cur_fw_ps_map;
  742. }
  743. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
  744. lnk = &wl->links[hlid];
  745. cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
  746. lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
  747. lnk->allocated_pkts -= cnt;
  748. wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
  749. lnk->allocated_pkts);
  750. }
  751. }
  752. static void wl12xx_fw_status(struct wl1271 *wl,
  753. struct wl12xx_fw_status *status)
  754. {
  755. struct wl12xx_vif *wlvif;
  756. struct timespec ts;
  757. u32 old_tx_blk_count = wl->tx_blocks_available;
  758. int avail, freed_blocks;
  759. int i;
  760. wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
  761. wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
  762. "drv_rx_counter = %d, tx_results_counter = %d)",
  763. status->intr,
  764. status->fw_rx_counter,
  765. status->drv_rx_counter,
  766. status->tx_results_counter);
  767. for (i = 0; i < NUM_TX_QUEUES; i++) {
  768. /* prevent wrap-around in freed-packets counter */
  769. wl->tx_allocated_pkts[i] -=
  770. (status->tx_released_pkts[i] -
  771. wl->tx_pkts_freed[i]) & 0xff;
  772. wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
  773. }
  774. /* prevent wrap-around in total blocks counter */
  775. if (likely(wl->tx_blocks_freed <=
  776. le32_to_cpu(status->total_released_blks)))
  777. freed_blocks = le32_to_cpu(status->total_released_blks) -
  778. wl->tx_blocks_freed;
  779. else
  780. freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
  781. le32_to_cpu(status->total_released_blks);
  782. wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
  783. wl->tx_allocated_blocks -= freed_blocks;
  784. avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
  785. /*
  786. * The FW might change the total number of TX memblocks before
  787. * we get a notification about blocks being released. Thus, the
  788. * available blocks calculation might yield a temporary result
  789. * which is lower than the actual available blocks. Keeping in
  790. * mind that only blocks that were allocated can be moved from
  791. * TX to RX, tx_blocks_available should never decrease here.
  792. */
  793. wl->tx_blocks_available = max((int)wl->tx_blocks_available,
  794. avail);
  795. /* if more blocks are available now, tx work can be scheduled */
  796. if (wl->tx_blocks_available > old_tx_blk_count)
  797. clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
  798. /* for AP update num of allocated TX blocks per link and ps status */
  799. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  800. wl12xx_irq_update_links_status(wl, wlvif, status);
  801. }
  802. /* update the host-chipset time offset */
  803. getnstimeofday(&ts);
  804. wl->time_offset = (timespec_to_ns(&ts) >> 10) -
  805. (s64)le32_to_cpu(status->fw_localtime);
  806. }
  807. static void wl1271_flush_deferred_work(struct wl1271 *wl)
  808. {
  809. struct sk_buff *skb;
  810. /* Pass all received frames to the network stack */
  811. while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
  812. ieee80211_rx_ni(wl->hw, skb);
  813. /* Return sent skbs to the network stack */
  814. while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
  815. ieee80211_tx_status_ni(wl->hw, skb);
  816. }
  817. static void wl1271_netstack_work(struct work_struct *work)
  818. {
  819. struct wl1271 *wl =
  820. container_of(work, struct wl1271, netstack_work);
  821. do {
  822. wl1271_flush_deferred_work(wl);
  823. } while (skb_queue_len(&wl->deferred_rx_queue));
  824. }
  825. #define WL1271_IRQ_MAX_LOOPS 256
  826. static irqreturn_t wl1271_irq(int irq, void *cookie)
  827. {
  828. int ret;
  829. u32 intr;
  830. int loopcount = WL1271_IRQ_MAX_LOOPS;
  831. struct wl1271 *wl = (struct wl1271 *)cookie;
  832. bool done = false;
  833. unsigned int defer_count;
  834. unsigned long flags;
  835. /* TX might be handled here, avoid redundant work */
  836. set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
  837. cancel_work_sync(&wl->tx_work);
  838. /*
  839. * In case edge triggered interrupt must be used, we cannot iterate
  840. * more than once without introducing race conditions with the hardirq.
  841. */
  842. if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
  843. loopcount = 1;
  844. mutex_lock(&wl->mutex);
  845. wl1271_debug(DEBUG_IRQ, "IRQ work");
  846. if (unlikely(wl->state == WL1271_STATE_OFF))
  847. goto out;
  848. ret = wl1271_ps_elp_wakeup(wl);
  849. if (ret < 0)
  850. goto out;
  851. while (!done && loopcount--) {
  852. /*
  853. * In order to avoid a race with the hardirq, clear the flag
  854. * before acknowledging the chip. Since the mutex is held,
  855. * wl1271_ps_elp_wakeup cannot be called concurrently.
  856. */
  857. clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
  858. smp_mb__after_clear_bit();
  859. wl12xx_fw_status(wl, wl->fw_status);
  860. intr = le32_to_cpu(wl->fw_status->intr);
  861. intr &= WL1271_INTR_MASK;
  862. if (!intr) {
  863. done = true;
  864. continue;
  865. }
  866. if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
  867. wl1271_error("watchdog interrupt received! "
  868. "starting recovery.");
  869. wl->watchdog_recovery = true;
  870. wl12xx_queue_recovery_work(wl);
  871. /* restarting the chip. ignore any other interrupt. */
  872. goto out;
  873. }
  874. if (likely(intr & WL1271_ACX_INTR_DATA)) {
  875. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
  876. wl12xx_rx(wl, wl->fw_status);
  877. /* Check if any tx blocks were freed */
  878. spin_lock_irqsave(&wl->wl_lock, flags);
  879. if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
  880. wl1271_tx_total_queue_count(wl) > 0) {
  881. spin_unlock_irqrestore(&wl->wl_lock, flags);
  882. /*
  883. * In order to avoid starvation of the TX path,
  884. * call the work function directly.
  885. */
  886. wl1271_tx_work_locked(wl);
  887. } else {
  888. spin_unlock_irqrestore(&wl->wl_lock, flags);
  889. }
  890. /* check for tx results */
  891. if (wl->fw_status->tx_results_counter !=
  892. (wl->tx_results_count & 0xff))
  893. wl1271_tx_complete(wl);
  894. /* Make sure the deferred queues don't get too long */
  895. defer_count = skb_queue_len(&wl->deferred_tx_queue) +
  896. skb_queue_len(&wl->deferred_rx_queue);
  897. if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
  898. wl1271_flush_deferred_work(wl);
  899. }
  900. if (intr & WL1271_ACX_INTR_EVENT_A) {
  901. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
  902. wl1271_event_handle(wl, 0);
  903. }
  904. if (intr & WL1271_ACX_INTR_EVENT_B) {
  905. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
  906. wl1271_event_handle(wl, 1);
  907. }
  908. if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
  909. wl1271_debug(DEBUG_IRQ,
  910. "WL1271_ACX_INTR_INIT_COMPLETE");
  911. if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
  912. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
  913. }
  914. wl1271_ps_elp_sleep(wl);
  915. out:
  916. spin_lock_irqsave(&wl->wl_lock, flags);
  917. /* In case TX was not handled here, queue TX work */
  918. clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
  919. if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
  920. wl1271_tx_total_queue_count(wl) > 0)
  921. ieee80211_queue_work(wl->hw, &wl->tx_work);
  922. #ifdef CONFIG_HAS_WAKELOCK
  923. if (test_and_clear_bit(WL1271_FLAG_WAKE_LOCK, &wl->flags))
  924. wake_unlock(&wl->wake_lock);
  925. #endif
  926. spin_unlock_irqrestore(&wl->wl_lock, flags);
  927. mutex_unlock(&wl->mutex);
  928. return IRQ_HANDLED;
  929. }
  930. static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
  931. {
  932. const struct firmware *fw;
  933. const char *fw_name;
  934. enum wl12xx_fw_type fw_type;
  935. int ret;
  936. u8 open_count;
  937. open_count = ieee80211_get_open_count(wl->hw, NULL);
  938. if (plt) {
  939. fw_type = WL12XX_FW_TYPE_PLT;
  940. if (wl->chip.id == CHIP_ID_1283_PG20)
  941. fw_name = WL128X_PLT_FW_NAME;
  942. else
  943. fw_name = WL127X_PLT_FW_NAME;
  944. } else {
  945. if (open_count > 1) {
  946. fw_type = WL12XX_FW_TYPE_MULTI;
  947. if (wl->chip.id == CHIP_ID_1283_PG20)
  948. fw_name = WL128X_FW_NAME_MULTI;
  949. else
  950. fw_name = WL127X_FW_NAME_MULTI;
  951. } else {
  952. fw_type = WL12XX_FW_TYPE_NORMAL;
  953. if (wl->chip.id == CHIP_ID_1283_PG20)
  954. fw_name = WL128X_FW_NAME_SINGLE;
  955. else
  956. fw_name = WL127X_FW_NAME_SINGLE;
  957. }
  958. }
  959. if (wl->saved_fw_type == fw_type)
  960. return 0;
  961. wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
  962. ret = request_firmware(&fw, fw_name, wl->dev);
  963. if (ret < 0) {
  964. wl1271_error("could not get firmware %s: %d", fw_name, ret);
  965. return ret;
  966. }
  967. if (fw->size % 4) {
  968. wl1271_error("firmware size is not multiple of 32 bits: %zu",
  969. fw->size);
  970. ret = -EILSEQ;
  971. goto out;
  972. }
  973. vfree(wl->fw);
  974. wl->saved_fw_type = WL12XX_FW_TYPE_NONE;
  975. wl->fw_len = fw->size;
  976. wl->fw = vmalloc(wl->fw_len);
  977. if (!wl->fw) {
  978. wl1271_error("could not allocate memory for the firmware");
  979. ret = -ENOMEM;
  980. goto out;
  981. }
  982. memcpy(wl->fw, fw->data, wl->fw_len);
  983. ret = 0;
  984. wl->saved_fw_type = fw_type;
  985. out:
  986. release_firmware(fw);
  987. return ret;
  988. }
  989. static int wl1271_fetch_nvs(struct wl1271 *wl)
  990. {
  991. const struct firmware *fw;
  992. int ret;
  993. ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
  994. if (ret < 0) {
  995. wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
  996. ret);
  997. return ret;
  998. }
  999. wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
  1000. if (!wl->nvs) {
  1001. wl1271_error("could not allocate memory for the nvs file");
  1002. ret = -ENOMEM;
  1003. goto out;
  1004. }
  1005. wl->nvs_len = fw->size;
  1006. out:
  1007. release_firmware(fw);
  1008. return ret;
  1009. }
  1010. void wl12xx_queue_recovery_work(struct wl1271 *wl)
  1011. {
  1012. if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
  1013. ieee80211_queue_work(wl->hw, &wl->recovery_work);
  1014. }
  1015. size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
  1016. {
  1017. size_t len = 0;
  1018. /* The FW log is a length-value list, find where the log end */
  1019. while (len < maxlen) {
  1020. if (memblock[len] == 0)
  1021. break;
  1022. if (len + memblock[len] + 1 > maxlen)
  1023. break;
  1024. len += memblock[len] + 1;
  1025. }
  1026. /* Make sure we have enough room */
  1027. len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
  1028. /* Fill the FW log file, consumed by the sysfs fwlog entry */
  1029. memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
  1030. wl->fwlog_size += len;
  1031. return len;
  1032. }
  1033. static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
  1034. {
  1035. u32 addr;
  1036. u32 first_addr;
  1037. u8 *block;
  1038. if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
  1039. (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
  1040. (wl->conf.fwlog.mem_blocks == 0))
  1041. return;
  1042. wl1271_info("Reading FW panic log");
  1043. block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
  1044. if (!block)
  1045. return;
  1046. /* Make sure the chip is awake and the logger isn't active. */
  1047. if (!wl1271_ps_elp_wakeup(wl)) {
  1048. /* Do not send a stop fwlog command if the fw is hanged */
  1049. if (!wl->watchdog_recovery)
  1050. wl12xx_cmd_stop_fwlog(wl);
  1051. }
  1052. else
  1053. goto out;
  1054. /* Read the first memory block address */
  1055. wl12xx_fw_status(wl, wl->fw_status);
  1056. first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
  1057. if (!first_addr)
  1058. goto out;
  1059. /* Traverse the memory blocks linked list */
  1060. addr = first_addr;
  1061. do {
  1062. memset(block, 0, WL12XX_HW_BLOCK_SIZE);
  1063. wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
  1064. false);
  1065. /*
  1066. * Memory blocks are linked to one another. The first 4 bytes
  1067. * of each memory block hold the hardware address of the next
  1068. * one. The last memory block points to the first one.
  1069. */
  1070. addr = le32_to_cpup((__le32 *)block);
  1071. if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
  1072. WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
  1073. break;
  1074. } while (addr && (addr != first_addr));
  1075. wake_up_interruptible(&wl->fwlog_waitq);
  1076. out:
  1077. kfree(block);
  1078. }
  1079. static void wl1271_recovery_work(struct work_struct *work)
  1080. {
  1081. struct wl1271 *wl =
  1082. container_of(work, struct wl1271, recovery_work);
  1083. struct wl12xx_vif *wlvif;
  1084. struct ieee80211_vif *vif;
  1085. mutex_lock(&wl->mutex);
  1086. if (wl->state != WL1271_STATE_ON)
  1087. goto out_unlock;
  1088. /* Avoid a recursive recovery */
  1089. set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
  1090. wl12xx_read_fwlog_panic(wl);
  1091. wl->watchdog_recovery = false;
  1092. wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
  1093. wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
  1094. BUG_ON(bug_on_recovery &&
  1095. !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
  1096. /*
  1097. * Advance security sequence number to overcome potential progress
  1098. * in the firmware during recovery. This doens't hurt if the network is
  1099. * not encrypted.
  1100. */
  1101. wl12xx_for_each_wlvif(wl, wlvif) {
  1102. if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
  1103. test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
  1104. wlvif->tx_security_seq +=
  1105. WL1271_TX_SQN_POST_RECOVERY_PADDING;
  1106. }
  1107. /* Prevent spurious TX during FW restart */
  1108. ieee80211_stop_queues(wl->hw);
  1109. if (wl->sched_scanning) {
  1110. ieee80211_sched_scan_stopped(wl->hw);
  1111. wl->sched_scanning = false;
  1112. }
  1113. /* reboot the chipset */
  1114. while (!list_empty(&wl->wlvif_list)) {
  1115. wlvif = list_first_entry(&wl->wlvif_list,
  1116. struct wl12xx_vif, list);
  1117. vif = wl12xx_wlvif_to_vif(wlvif);
  1118. __wl1271_op_remove_interface(wl, vif, false);
  1119. }
  1120. mutex_unlock(&wl->mutex);
  1121. wl1271_op_stop(wl->hw);
  1122. clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
  1123. ieee80211_restart_hw(wl->hw);
  1124. /*
  1125. * Its safe to enable TX now - the queues are stopped after a request
  1126. * to restart the HW.
  1127. */
  1128. ieee80211_wake_queues(wl->hw);
  1129. return;
  1130. out_unlock:
  1131. mutex_unlock(&wl->mutex);
  1132. }
  1133. static void wl1271_fw_wakeup(struct wl1271 *wl)
  1134. {
  1135. u32 elp_reg;
  1136. elp_reg = ELPCTRL_WAKE_UP;
  1137. wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  1138. }
  1139. static int wl1271_setup(struct wl1271 *wl)
  1140. {
  1141. wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
  1142. if (!wl->fw_status)
  1143. return -ENOMEM;
  1144. wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
  1145. if (!wl->tx_res_if) {
  1146. kfree(wl->fw_status);
  1147. return -ENOMEM;
  1148. }
  1149. return 0;
  1150. }
  1151. static int wl12xx_set_power_on(struct wl1271 *wl)
  1152. {
  1153. int ret;
  1154. msleep(WL1271_PRE_POWER_ON_SLEEP);
  1155. ret = wl1271_power_on(wl);
  1156. if (ret < 0)
  1157. goto out;
  1158. msleep(WL1271_POWER_ON_SLEEP);
  1159. wl1271_io_reset(wl);
  1160. wl1271_io_init(wl);
  1161. wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
  1162. /* ELP module wake up */
  1163. wl1271_fw_wakeup(wl);
  1164. out:
  1165. return ret;
  1166. }
  1167. static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
  1168. {
  1169. int ret = 0;
  1170. ret = wl12xx_set_power_on(wl);
  1171. if (ret < 0)
  1172. goto out;
  1173. /*
  1174. * For wl127x based devices we could use the default block
  1175. * size (512 bytes), but due to a bug in the sdio driver, we
  1176. * need to set it explicitly after the chip is powered on. To
  1177. * simplify the code and since the performance impact is
  1178. * negligible, we use the same block size for all different
  1179. * chip types.
  1180. */
  1181. if (!wl1271_set_block_size(wl))
  1182. wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
  1183. switch (wl->chip.id) {
  1184. case CHIP_ID_1271_PG10:
  1185. wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
  1186. wl->chip.id);
  1187. ret = wl1271_setup(wl);
  1188. if (ret < 0)
  1189. goto out;
  1190. wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
  1191. break;
  1192. case CHIP_ID_1271_PG20:
  1193. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
  1194. wl->chip.id);
  1195. ret = wl1271_setup(wl);
  1196. if (ret < 0)
  1197. goto out;
  1198. wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
  1199. break;
  1200. case CHIP_ID_1283_PG20:
  1201. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
  1202. wl->chip.id);
  1203. ret = wl1271_setup(wl);
  1204. if (ret < 0)
  1205. goto out;
  1206. break;
  1207. case CHIP_ID_1283_PG10:
  1208. default:
  1209. wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
  1210. ret = -ENODEV;
  1211. goto out;
  1212. }
  1213. ret = wl12xx_fetch_firmware(wl, plt);
  1214. if (ret < 0)
  1215. goto out;
  1216. /* No NVS from netlink, try to get it from the filesystem */
  1217. if (wl->nvs == NULL) {
  1218. ret = wl1271_fetch_nvs(wl);
  1219. if (ret < 0)
  1220. goto out;
  1221. }
  1222. out:
  1223. return ret;
  1224. }
  1225. int wl1271_plt_start(struct wl1271 *wl)
  1226. {
  1227. int retries = WL1271_BOOT_RETRIES;
  1228. struct wiphy *wiphy = wl->hw->wiphy;
  1229. int ret;
  1230. mutex_lock(&wl->mutex);
  1231. wl1271_notice("power up");
  1232. if (wl->state != WL1271_STATE_OFF) {
  1233. wl1271_error("cannot go into PLT state because not "
  1234. "in off state: %d", wl->state);
  1235. ret = -EBUSY;
  1236. goto out;
  1237. }
  1238. while (retries) {
  1239. retries--;
  1240. ret = wl12xx_chip_wakeup(wl, true);
  1241. if (ret < 0)
  1242. goto power_off;
  1243. ret = wl1271_boot(wl);
  1244. if (ret < 0)
  1245. goto power_off;
  1246. ret = wl1271_plt_init(wl);
  1247. if (ret < 0)
  1248. goto irq_disable;
  1249. wl->state = WL1271_STATE_PLT;
  1250. wl1271_notice("firmware booted in PLT mode (%s)",
  1251. wl->chip.fw_ver_str);
  1252. /* update hw/fw version info in wiphy struct */
  1253. wiphy->hw_version = wl->chip.id;
  1254. strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
  1255. sizeof(wiphy->fw_version));
  1256. goto out;
  1257. irq_disable:
  1258. mutex_unlock(&wl->mutex);
  1259. /* Unlocking the mutex in the middle of handling is
  1260. inherently unsafe. In this case we deem it safe to do,
  1261. because we need to let any possibly pending IRQ out of
  1262. the system (and while we are WL1271_STATE_OFF the IRQ
  1263. work function will not do anything.) Also, any other
  1264. possible concurrent operations will fail due to the
  1265. current state, hence the wl1271 struct should be safe. */
  1266. wl1271_disable_interrupts(wl);
  1267. wl1271_flush_deferred_work(wl);
  1268. cancel_work_sync(&wl->netstack_work);
  1269. mutex_lock(&wl->mutex);
  1270. power_off:
  1271. wl1271_power_off(wl);
  1272. }
  1273. wl1271_error("firmware boot in PLT mode failed despite %d retries",
  1274. WL1271_BOOT_RETRIES);
  1275. out:
  1276. mutex_unlock(&wl->mutex);
  1277. return ret;
  1278. }
  1279. int wl1271_plt_stop(struct wl1271 *wl)
  1280. {
  1281. int ret = 0;
  1282. wl1271_notice("power down");
  1283. /*
  1284. * Interrupts must be disabled before setting the state to OFF.
  1285. * Otherwise, the interrupt handler might be called and exit without
  1286. * reading the interrupt status.
  1287. */
  1288. wl1271_disable_interrupts(wl);
  1289. mutex_lock(&wl->mutex);
  1290. if (wl->state != WL1271_STATE_PLT) {
  1291. mutex_unlock(&wl->mutex);
  1292. /*
  1293. * This will not necessarily enable interrupts as interrupts
  1294. * may have been disabled when op_stop was called. It will,
  1295. * however, balance the above call to disable_interrupts().
  1296. */
  1297. wl1271_enable_interrupts(wl);
  1298. wl1271_error("cannot power down because not in PLT "
  1299. "state: %d", wl->state);
  1300. ret = -EBUSY;
  1301. goto out;
  1302. }
  1303. mutex_unlock(&wl->mutex);
  1304. wl1271_flush_deferred_work(wl);
  1305. cancel_work_sync(&wl->netstack_work);
  1306. cancel_work_sync(&wl->recovery_work);
  1307. cancel_delayed_work_sync(&wl->elp_work);
  1308. mutex_lock(&wl->mutex);
  1309. wl1271_power_off(wl);
  1310. wl->flags = 0;
  1311. wl->state = WL1271_STATE_OFF;
  1312. wl->rx_counter = 0;
  1313. mutex_unlock(&wl->mutex);
  1314. out:
  1315. return ret;
  1316. }
  1317. static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  1318. {
  1319. struct wl1271 *wl = hw->priv;
  1320. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1321. struct ieee80211_vif *vif = info->control.vif;
  1322. struct wl12xx_vif *wlvif = NULL;
  1323. unsigned long flags;
  1324. int q, mapping;
  1325. u8 hlid;
  1326. if (vif)
  1327. wlvif = wl12xx_vif_to_data(vif);
  1328. mapping = skb_get_queue_mapping(skb);
  1329. q = wl1271_tx_get_queue(mapping);
  1330. hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
  1331. spin_lock_irqsave(&wl->wl_lock, flags);
  1332. /* queue the packet */
  1333. if (hlid == WL12XX_INVALID_LINK_ID ||
  1334. (wlvif && !test_bit(hlid, wlvif->links_map))) {
  1335. wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
  1336. ieee80211_free_txskb(hw, skb);
  1337. goto out;
  1338. }
  1339. wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
  1340. skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
  1341. wl->tx_queue_count[q]++;
  1342. /*
  1343. * The workqueue is slow to process the tx_queue and we need stop
  1344. * the queue here, otherwise the queue will get too long.
  1345. */
  1346. if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
  1347. wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
  1348. ieee80211_stop_queue(wl->hw, mapping);
  1349. set_bit(q, &wl->stopped_queues_map);
  1350. }
  1351. /*
  1352. * The chip specific setup must run before the first TX packet -
  1353. * before that, the tx_work will not be initialized!
  1354. */
  1355. if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
  1356. !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
  1357. ieee80211_queue_work(wl->hw, &wl->tx_work);
  1358. out:
  1359. spin_unlock_irqrestore(&wl->wl_lock, flags);
  1360. }
  1361. int wl1271_tx_dummy_packet(struct wl1271 *wl)
  1362. {
  1363. unsigned long flags;
  1364. int q;
  1365. /* no need to queue a new dummy packet if one is already pending */
  1366. if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
  1367. return 0;
  1368. q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
  1369. spin_lock_irqsave(&wl->wl_lock, flags);
  1370. set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
  1371. wl->tx_queue_count[q]++;
  1372. spin_unlock_irqrestore(&wl->wl_lock, flags);
  1373. /* The FW is low on RX memory blocks, so send the dummy packet asap */
  1374. if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
  1375. wl1271_tx_work_locked(wl);
  1376. /*
  1377. * If the FW TX is busy, TX work will be scheduled by the threaded
  1378. * interrupt handler function
  1379. */
  1380. return 0;
  1381. }
  1382. /*
  1383. * The size of the dummy packet should be at least 1400 bytes. However, in
  1384. * order to minimize the number of bus transactions, aligning it to 512 bytes
  1385. * boundaries could be beneficial, performance wise
  1386. */
  1387. #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
  1388. static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
  1389. {
  1390. struct sk_buff *skb;
  1391. struct ieee80211_hdr_3addr *hdr;
  1392. unsigned int dummy_packet_size;
  1393. dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
  1394. sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
  1395. skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
  1396. if (!skb) {
  1397. wl1271_warning("Failed to allocate a dummy packet skb");
  1398. return NULL;
  1399. }
  1400. skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
  1401. hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
  1402. memset(hdr, 0, sizeof(*hdr));
  1403. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  1404. IEEE80211_STYPE_NULLFUNC |
  1405. IEEE80211_FCTL_TODS);
  1406. memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
  1407. /* Dummy packets require the TID to be management */
  1408. skb->priority = WL1271_TID_MGMT;
  1409. /* Initialize all fields that might be used */
  1410. skb_set_queue_mapping(skb, 0);
  1411. memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
  1412. return skb;
  1413. }
  1414. static struct notifier_block wl1271_dev_notifier = {
  1415. .notifier_call = wl1271_dev_notify,
  1416. };
  1417. #ifdef CONFIG_PM
  1418. int wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p)
  1419. {
  1420. int num_fields = 0, in_field = 0, fields_size = 0;
  1421. int i, pattern_len = 0;
  1422. if (!p->mask) {
  1423. wl1271_warning("No mask in WoWLAN pattern");
  1424. return -EINVAL;
  1425. }
  1426. /* The pattern is broken up into segments of bytes at different offsets
  1427. * that need to be checked by the FW filter. Each segment is called
  1428. * a field in the FW API. We verify that the total number of fields
  1429. * required for this pattern won't exceed FW limits (8)
  1430. * as well as the total fields buffer won't exceed the FW limit.
  1431. * Note that if there's a pattern which crosses Ethernet/IP header
  1432. * boundary a new field is required.
  1433. */
  1434. for (i = 0; i < p->pattern_len; i++) {
  1435. if (test_bit(i, (unsigned long *)p->mask)) {
  1436. if (!in_field) {
  1437. in_field = 1;
  1438. pattern_len = 1;
  1439. } else {
  1440. if (i == WL1271_RX_FILTER_ETH_HEADER_SIZE) {
  1441. num_fields++;
  1442. fields_size += pattern_len +
  1443. RX_FILTER_FIELD_OVERHEAD;
  1444. pattern_len = 1;
  1445. } else
  1446. pattern_len++;
  1447. }
  1448. } else {
  1449. if (in_field) {
  1450. in_field = 0;
  1451. fields_size += pattern_len +
  1452. RX_FILTER_FIELD_OVERHEAD;
  1453. num_fields++;
  1454. }
  1455. }
  1456. }
  1457. if (in_field) {
  1458. fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD;
  1459. num_fields++;
  1460. }
  1461. if (num_fields > WL1271_RX_FILTER_MAX_FIELDS) {
  1462. wl1271_warning("RX Filter too complex. Too many segments");
  1463. return -EINVAL;
  1464. }
  1465. if (fields_size > WL1271_RX_FILTER_MAX_FIELDS_SIZE) {
  1466. wl1271_warning("RX filter pattern is too big");
  1467. return -E2BIG;
  1468. }
  1469. return 0;
  1470. }
  1471. struct wl12xx_rx_data_filter *wl1271_rx_filter_alloc(void)
  1472. {
  1473. return kzalloc(sizeof(struct wl12xx_rx_data_filter), GFP_KERNEL);
  1474. }
  1475. void wl1271_rx_filter_free(struct wl12xx_rx_data_filter *filter)
  1476. {
  1477. int i;
  1478. if (filter == NULL)
  1479. return;
  1480. for (i = 0; i < filter->num_fields; i++)
  1481. kfree(filter->fields[i].pattern);
  1482. kfree(filter);
  1483. }
  1484. int wl1271_rx_filter_alloc_field(struct wl12xx_rx_data_filter *filter,
  1485. u16 offset, u8 flags,
  1486. u8 *pattern, u8 len)
  1487. {
  1488. struct wl12xx_rx_data_filter_field *field;
  1489. if (filter->num_fields == WL1271_RX_FILTER_MAX_FIELDS) {
  1490. wl1271_warning("Max fields per RX filter. can't alloc another");
  1491. return -EINVAL;
  1492. }
  1493. field = &filter->fields[filter->num_fields];
  1494. field->pattern = kzalloc(len, GFP_KERNEL);
  1495. if (!field->pattern) {
  1496. wl1271_warning("Failed to allocate RX filter pattern");
  1497. return -ENOMEM;
  1498. }
  1499. filter->num_fields++;
  1500. field->offset = cpu_to_le16(offset);
  1501. field->flags = flags;
  1502. field->len = len;
  1503. memcpy(field->pattern, pattern, len);
  1504. return 0;
  1505. }
  1506. int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_data_filter *filter)
  1507. {
  1508. int i, fields_size = 0;
  1509. for (i = 0; i < filter->num_fields; i++)
  1510. fields_size += filter->fields[i].len +
  1511. sizeof(struct wl12xx_rx_data_filter_field) -
  1512. sizeof(u8 *);
  1513. return fields_size;
  1514. }
  1515. void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_data_filter *filter,
  1516. u8 *buf)
  1517. {
  1518. int i;
  1519. struct wl12xx_rx_data_filter_field *field;
  1520. for (i = 0; i < filter->num_fields; i++) {
  1521. field = (struct wl12xx_rx_data_filter_field *)buf;
  1522. field->offset = filter->fields[i].offset;
  1523. field->flags = filter->fields[i].flags;
  1524. field->len = filter->fields[i].len;
  1525. memcpy(&field->pattern, filter->fields[i].pattern, field->len);
  1526. buf += sizeof(struct wl12xx_rx_data_filter_field) -
  1527. sizeof(u8 *) + field->len;
  1528. }
  1529. }
  1530. /* Allocates an RX filter returned through f
  1531. * which needs to be freed using rx_filter_free()
  1532. */
  1533. int wl1271_convert_wowlan_pattern_to_rx_filter(
  1534. struct cfg80211_wowlan_trig_pkt_pattern *p,
  1535. struct wl12xx_rx_data_filter **f)
  1536. {
  1537. int i, j, ret = 0;
  1538. struct wl12xx_rx_data_filter *filter;
  1539. u16 offset;
  1540. u8 flags, len;
  1541. filter = wl1271_rx_filter_alloc();
  1542. if (!filter) {
  1543. wl1271_warning("Failed to alloc rx filter");
  1544. ret = -ENOMEM;
  1545. goto err;
  1546. }
  1547. i = 0;
  1548. while (i < p->pattern_len) {
  1549. if (!test_bit(i, (unsigned long *)p->mask)) {
  1550. i++;
  1551. continue;
  1552. }
  1553. for (j = i; j < p->pattern_len; j++) {
  1554. if (!test_bit(j, (unsigned long *)p->mask))
  1555. break;
  1556. if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE &&
  1557. j >= WL1271_RX_FILTER_ETH_HEADER_SIZE)
  1558. break;
  1559. }
  1560. if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE) {
  1561. offset = i;
  1562. flags = WL1271_RX_FILTER_FLAG_ETHERNET_HEADER;
  1563. } else {
  1564. offset = i - WL1271_RX_FILTER_ETH_HEADER_SIZE;
  1565. flags = WL1271_RX_FILTER_FLAG_IP_HEADER;
  1566. }
  1567. len = j - i;
  1568. ret = wl1271_rx_filter_alloc_field(filter,
  1569. offset,
  1570. flags,
  1571. &p->pattern[i], len);
  1572. if (ret)
  1573. goto err;
  1574. i = j;
  1575. }
  1576. filter->action = FILTER_SIGNAL;
  1577. *f = filter;
  1578. return 0;
  1579. err:
  1580. wl1271_rx_filter_free(filter);
  1581. *f = NULL;
  1582. return ret;
  1583. }
  1584. static int wl1271_configure_wowlan(struct wl1271 *wl,
  1585. struct cfg80211_wowlan *wow)
  1586. {
  1587. int i, ret;
  1588. if (!wow || wow->any || !wow->n_patterns) {
  1589. wl1271_rx_data_filtering_enable(wl, 0, FILTER_SIGNAL);
  1590. wl1271_rx_data_filters_clear_all(wl);
  1591. return 0;
  1592. }
  1593. WARN_ON(wow->n_patterns > WL1271_MAX_RX_FILTERS);
  1594. /* Validate all incoming patterns before clearing current FW state */
  1595. for (i = 0; i < wow->n_patterns; i++) {
  1596. ret = wl1271_validate_wowlan_pattern(&wow->patterns[i]);
  1597. if (ret) {
  1598. wl1271_warning("validate_wowlan_pattern "
  1599. "failed (%d)", ret);
  1600. return ret;
  1601. }
  1602. }
  1603. wl1271_rx_data_filtering_enable(wl, 0, FILTER_SIGNAL);
  1604. wl1271_rx_data_filters_clear_all(wl);
  1605. /* Translate WoWLAN patterns into filters */
  1606. for (i = 0; i < wow->n_patterns; i++) {
  1607. struct cfg80211_wowlan_trig_pkt_pattern *p;
  1608. struct wl12xx_rx_data_filter *filter = NULL;
  1609. p = &wow->patterns[i];
  1610. ret = wl1271_convert_wowlan_pattern_to_rx_filter(p, &filter);
  1611. if (ret) {
  1612. wl1271_warning("convert_wowlan_pattern_to_rx_filter "
  1613. "failed (%d)", ret);
  1614. goto out;
  1615. }
  1616. ret = wl1271_rx_data_filter_enable(wl, i, 1, filter);
  1617. wl1271_rx_filter_free(filter);
  1618. if (ret) {
  1619. wl1271_warning("rx_data_filter_enable "
  1620. " failed (%d)", ret);
  1621. goto out;
  1622. }
  1623. }
  1624. ret = wl1271_rx_data_filtering_enable(wl, 1, FILTER_DROP);
  1625. if (ret) {
  1626. wl1271_warning("rx_data_filtering_enable failed (%d)", ret);
  1627. goto out;
  1628. }
  1629. out:
  1630. return ret;
  1631. }
  1632. static int wl1271_configure_suspend_sta(struct wl1271 *wl,
  1633. struct wl12xx_vif *wlvif,
  1634. struct cfg80211_wowlan *wow)
  1635. {
  1636. int ret = 0;
  1637. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  1638. goto out;
  1639. ret = wl1271_ps_elp_wakeup(wl);
  1640. if (ret < 0)
  1641. goto out;
  1642. ret = wl1271_acx_wake_up_conditions(wl, wlvif,
  1643. wl->conf.conn.suspend_wake_up_event,
  1644. wl->conf.conn.suspend_listen_interval);
  1645. if (ret < 0)
  1646. wl1271_error("suspend: set wake up conditions failed: %d", ret);
  1647. wl1271_ps_elp_sleep(wl);
  1648. out:
  1649. return ret;
  1650. }
  1651. static int wl1271_configure_suspend_ap(struct wl1271 *wl,
  1652. struct wl12xx_vif *wlvif)
  1653. {
  1654. int ret = 0;
  1655. if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
  1656. goto out;
  1657. ret = wl1271_ps_elp_wakeup(wl);
  1658. if (ret < 0)
  1659. goto out;
  1660. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
  1661. wl1271_ps_elp_sleep(wl);
  1662. out:
  1663. return ret;
  1664. }
  1665. static int wl1271_configure_suspend(struct wl1271 *wl,
  1666. struct wl12xx_vif *wlvif,
  1667. struct cfg80211_wowlan *wow)
  1668. {
  1669. if (wlvif->bss_type == BSS_TYPE_STA_BSS)
  1670. return wl1271_configure_suspend_sta(wl, wlvif, wow);
  1671. if (wlvif->bss_type == BSS_TYPE_AP_BSS)
  1672. return wl1271_configure_suspend_ap(wl, wlvif);
  1673. return 0;
  1674. }
  1675. static void wl1271_configure_resume(struct wl1271 *wl,
  1676. struct wl12xx_vif *wlvif)
  1677. {
  1678. int ret = 0;
  1679. bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
  1680. bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
  1681. if ((!is_ap) && (!is_sta))
  1682. return;
  1683. ret = wl1271_ps_elp_wakeup(wl);
  1684. if (ret < 0)
  1685. return;
  1686. if (is_sta) {
  1687. ret = wl1271_acx_wake_up_conditions(wl, wlvif,
  1688. wl->conf.conn.wake_up_event,
  1689. wl->conf.conn.listen_interval);
  1690. if (ret < 0)
  1691. wl1271_error("resume: wake up conditions failed: %d",
  1692. ret);
  1693. } else if (is_ap) {
  1694. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
  1695. }
  1696. wl1271_ps_elp_sleep(wl);
  1697. }
  1698. static int wl1271_op_suspend(struct ieee80211_hw *hw,
  1699. struct cfg80211_wowlan *wow)
  1700. {
  1701. struct wl1271 *wl = hw->priv;
  1702. struct wl12xx_vif *wlvif;
  1703. int ret;
  1704. wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
  1705. WARN_ON(!wow);
  1706. wl1271_tx_flush(wl);
  1707. mutex_lock(&wl->mutex);
  1708. wl->wow_enabled = true;
  1709. wl12xx_for_each_wlvif(wl, wlvif) {
  1710. ret = wl1271_configure_suspend(wl, wlvif, wow);
  1711. if (ret < 0) {
  1712. wl1271_warning("couldn't prepare device to suspend");
  1713. return ret;
  1714. }
  1715. }
  1716. mutex_unlock(&wl->mutex);
  1717. /* flush any remaining work */
  1718. wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
  1719. /*
  1720. * disable and re-enable interrupts in order to flush
  1721. * the threaded_irq
  1722. */
  1723. wl1271_disable_interrupts(wl);
  1724. /*
  1725. * set suspended flag to avoid triggering a new threaded_irq
  1726. * work. no need for spinlock as interrupts are disabled.
  1727. */
  1728. set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
  1729. wl1271_enable_interrupts(wl);
  1730. flush_work(&wl->tx_work);
  1731. flush_delayed_work(&wl->elp_work);
  1732. return 0;
  1733. }
  1734. static int wl1271_op_resume(struct ieee80211_hw *hw)
  1735. {
  1736. struct wl1271 *wl = hw->priv;
  1737. struct wl12xx_vif *wlvif;
  1738. unsigned long flags;
  1739. bool run_irq_work = false;
  1740. wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
  1741. wl->wow_enabled);
  1742. WARN_ON(!wl->wow_enabled);
  1743. /*
  1744. * re-enable irq_work enqueuing, and call irq_work directly if
  1745. * there is a pending work.
  1746. */
  1747. spin_lock_irqsave(&wl->wl_lock, flags);
  1748. clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
  1749. if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
  1750. run_irq_work = true;
  1751. spin_unlock_irqrestore(&wl->wl_lock, flags);
  1752. if (run_irq_work) {
  1753. wl1271_debug(DEBUG_MAC80211,
  1754. "run postponed irq_work directly");
  1755. wl1271_irq(0, wl);
  1756. wl1271_enable_interrupts(wl);
  1757. }
  1758. mutex_lock(&wl->mutex);
  1759. wl12xx_for_each_wlvif(wl, wlvif) {
  1760. wl1271_configure_resume(wl, wlvif);
  1761. }
  1762. wl->wow_enabled = false;
  1763. mutex_unlock(&wl->mutex);
  1764. return 0;
  1765. }
  1766. #endif /* CONFIG_PM */
  1767. static int wl1271_op_start(struct ieee80211_hw *hw)
  1768. {
  1769. struct wl1271 *wl = hw->priv;
  1770. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  1771. /*
  1772. * We have to delay the booting of the hardware because
  1773. * we need to know the local MAC address before downloading and
  1774. * initializing the firmware. The MAC address cannot be changed
  1775. * after boot, and without the proper MAC address, the firmware
  1776. * will not function properly.
  1777. *
  1778. * The MAC address is first known when the corresponding interface
  1779. * is added. That is where we will initialize the hardware.
  1780. */
  1781. /*
  1782. * store wl in the global wl_list, used to find wl
  1783. * in the wl1271_dev_notify callback
  1784. */
  1785. mutex_lock(&wl_list_mutex);
  1786. list_add(&wl->list, &wl_list);
  1787. mutex_unlock(&wl_list_mutex);
  1788. return 0;
  1789. }
  1790. static void wl1271_op_stop(struct ieee80211_hw *hw)
  1791. {
  1792. struct wl1271 *wl = hw->priv;
  1793. int i;
  1794. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  1795. /*
  1796. * Interrupts must be disabled before setting the state to OFF.
  1797. * Otherwise, the interrupt handler might be called and exit without
  1798. * reading the interrupt status.
  1799. */
  1800. wl1271_disable_interrupts(wl);
  1801. mutex_lock(&wl->mutex);
  1802. if (wl->state == WL1271_STATE_OFF) {
  1803. mutex_unlock(&wl->mutex);
  1804. /*
  1805. * This will not necessarily enable interrupts as interrupts
  1806. * may have been disabled when op_stop was called. It will,
  1807. * however, balance the above call to disable_interrupts().
  1808. */
  1809. wl1271_enable_interrupts(wl);
  1810. return;
  1811. }
  1812. /*
  1813. * this must be before the cancel_work calls below, so that the work
  1814. * functions don't perform further work.
  1815. */
  1816. wl->state = WL1271_STATE_OFF;
  1817. mutex_unlock(&wl->mutex);
  1818. mutex_lock(&wl_list_mutex);
  1819. list_del(&wl->list);
  1820. mutex_unlock(&wl_list_mutex);
  1821. wl1271_flush_deferred_work(wl);
  1822. cancel_delayed_work_sync(&wl->scan_complete_work);
  1823. cancel_work_sync(&wl->netstack_work);
  1824. cancel_work_sync(&wl->tx_work);
  1825. cancel_delayed_work_sync(&wl->elp_work);
  1826. /* let's notify MAC80211 about the remaining pending TX frames */
  1827. wl12xx_tx_reset(wl, true);
  1828. mutex_lock(&wl->mutex);
  1829. wl1271_power_off(wl);
  1830. wl->fw_type = WL12XX_FW_TYPE_NONE;
  1831. wl->band = IEEE80211_BAND_2GHZ;
  1832. wl->rx_counter = 0;
  1833. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  1834. wl->tx_blocks_available = 0;
  1835. wl->tx_allocated_blocks = 0;
  1836. wl->tx_results_count = 0;
  1837. wl->tx_packets_count = 0;
  1838. wl->time_offset = 0;
  1839. wl->ap_fw_ps_map = 0;
  1840. wl->ap_ps_map = 0;
  1841. wl->sched_scanning = false;
  1842. memset(wl->roles_map, 0, sizeof(wl->roles_map));
  1843. memset(wl->links_map, 0, sizeof(wl->links_map));
  1844. memset(wl->roc_map, 0, sizeof(wl->roc_map));
  1845. wl->active_sta_count = 0;
  1846. /* The system link is always allocated */
  1847. __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
  1848. /*
  1849. * this is performed after the cancel_work calls and the associated
  1850. * mutex_lock, so that wl1271_op_add_interface does not accidentally
  1851. * get executed before all these vars have been reset.
  1852. */
  1853. wl->flags = 0;
  1854. wl->tx_blocks_freed = 0;
  1855. for (i = 0; i < NUM_TX_QUEUES; i++) {
  1856. wl->tx_pkts_freed[i] = 0;
  1857. wl->tx_allocated_pkts[i] = 0;
  1858. }
  1859. wl1271_debugfs_reset(wl);
  1860. kfree(wl->fw_status);
  1861. wl->fw_status = NULL;
  1862. kfree(wl->tx_res_if);
  1863. wl->tx_res_if = NULL;
  1864. kfree(wl->target_mem_map);
  1865. wl->target_mem_map = NULL;
  1866. mutex_unlock(&wl->mutex);
  1867. }
  1868. static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
  1869. {
  1870. u8 policy = find_first_zero_bit(wl->rate_policies_map,
  1871. WL12XX_MAX_RATE_POLICIES);
  1872. if (policy >= WL12XX_MAX_RATE_POLICIES)
  1873. return -EBUSY;
  1874. __set_bit(policy, wl->rate_policies_map);
  1875. *idx = policy;
  1876. return 0;
  1877. }
  1878. static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
  1879. {
  1880. if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
  1881. return;
  1882. __clear_bit(*idx, wl->rate_policies_map);
  1883. *idx = WL12XX_MAX_RATE_POLICIES;
  1884. }
  1885. static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1886. {
  1887. switch (wlvif->bss_type) {
  1888. case BSS_TYPE_AP_BSS:
  1889. if (wlvif->p2p)
  1890. return WL1271_ROLE_P2P_GO;
  1891. else
  1892. return WL1271_ROLE_AP;
  1893. case BSS_TYPE_STA_BSS:
  1894. if (wlvif->p2p)
  1895. return WL1271_ROLE_P2P_CL;
  1896. else
  1897. return WL1271_ROLE_STA;
  1898. case BSS_TYPE_IBSS:
  1899. return WL1271_ROLE_IBSS;
  1900. default:
  1901. wl1271_error("invalid bss_type: %d", wlvif->bss_type);
  1902. }
  1903. return WL12XX_INVALID_ROLE_TYPE;
  1904. }
  1905. static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
  1906. {
  1907. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  1908. int i;
  1909. /* clear everything but the persistent data */
  1910. memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
  1911. switch (ieee80211_vif_type_p2p(vif)) {
  1912. case NL80211_IFTYPE_P2P_CLIENT:
  1913. wlvif->p2p = 1;
  1914. /* fall-through */
  1915. case NL80211_IFTYPE_STATION:
  1916. wlvif->bss_type = BSS_TYPE_STA_BSS;
  1917. break;
  1918. case NL80211_IFTYPE_ADHOC:
  1919. wlvif->bss_type = BSS_TYPE_IBSS;
  1920. break;
  1921. case NL80211_IFTYPE_P2P_GO:
  1922. wlvif->p2p = 1;
  1923. /* fall-through */
  1924. case NL80211_IFTYPE_AP:
  1925. wlvif->bss_type = BSS_TYPE_AP_BSS;
  1926. break;
  1927. default:
  1928. wlvif->bss_type = MAX_BSS_TYPE;
  1929. return -EOPNOTSUPP;
  1930. }
  1931. wlvif->role_id = WL12XX_INVALID_ROLE_ID;
  1932. wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
  1933. wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
  1934. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1935. wlvif->bss_type == BSS_TYPE_IBSS) {
  1936. /* init sta/ibss data */
  1937. wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
  1938. wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
  1939. wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
  1940. wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
  1941. } else {
  1942. /* init ap data */
  1943. wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
  1944. wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
  1945. wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
  1946. wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
  1947. for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
  1948. wl12xx_allocate_rate_policy(wl,
  1949. &wlvif->ap.ucast_rate_idx[i]);
  1950. }
  1951. wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
  1952. wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
  1953. wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
  1954. wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
  1955. wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
  1956. wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
  1957. /*
  1958. * mac80211 configures some values globally, while we treat them
  1959. * per-interface. thus, on init, we have to copy them from wl
  1960. */
  1961. wlvif->band = wl->band;
  1962. wlvif->channel = wl->channel;
  1963. wlvif->power_level = wl->power_level;
  1964. INIT_WORK(&wlvif->rx_streaming_enable_work,
  1965. wl1271_rx_streaming_enable_work);
  1966. INIT_WORK(&wlvif->rx_streaming_disable_work,
  1967. wl1271_rx_streaming_disable_work);
  1968. INIT_LIST_HEAD(&wlvif->list);
  1969. setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
  1970. (unsigned long) wlvif);
  1971. return 0;
  1972. }
  1973. static bool wl12xx_init_fw(struct wl1271 *wl)
  1974. {
  1975. int retries = WL1271_BOOT_RETRIES;
  1976. bool booted = false;
  1977. struct wiphy *wiphy = wl->hw->wiphy;
  1978. int ret;
  1979. while (retries) {
  1980. retries--;
  1981. ret = wl12xx_chip_wakeup(wl, false);
  1982. if (ret < 0)
  1983. goto power_off;
  1984. ret = wl1271_boot(wl);
  1985. if (ret < 0)
  1986. goto power_off;
  1987. ret = wl1271_hw_init(wl);
  1988. if (ret < 0)
  1989. goto irq_disable;
  1990. booted = true;
  1991. break;
  1992. irq_disable:
  1993. mutex_unlock(&wl->mutex);
  1994. /* Unlocking the mutex in the middle of handling is
  1995. inherently unsafe. In this case we deem it safe to do,
  1996. because we need to let any possibly pending IRQ out of
  1997. the system (and while we are WL1271_STATE_OFF the IRQ
  1998. work function will not do anything.) Also, any other
  1999. possible concurrent operations will fail due to the
  2000. current state, hence the wl1271 struct should be safe. */
  2001. wl1271_disable_interrupts(wl);
  2002. wl1271_flush_deferred_work(wl);
  2003. cancel_work_sync(&wl->netstack_work);
  2004. mutex_lock(&wl->mutex);
  2005. power_off:
  2006. wl1271_power_off(wl);
  2007. }
  2008. if (!booted) {
  2009. wl1271_error("firmware boot failed despite %d retries",
  2010. WL1271_BOOT_RETRIES);
  2011. goto out;
  2012. }
  2013. wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
  2014. /* update hw/fw version info in wiphy struct */
  2015. wiphy->hw_version = wl->chip.id;
  2016. strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
  2017. sizeof(wiphy->fw_version));
  2018. /*
  2019. * Now we know if 11a is supported (info from the NVS), so disable
  2020. * 11a channels if not supported
  2021. */
  2022. if (!wl->enable_11a)
  2023. wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
  2024. wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
  2025. wl->enable_11a ? "" : "not ");
  2026. wl->state = WL1271_STATE_ON;
  2027. wl->watchdog_recovery = false;
  2028. out:
  2029. return booted;
  2030. }
  2031. static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
  2032. {
  2033. return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
  2034. }
  2035. static bool wl12xx_need_fw_change(struct ieee80211_hw *hw,
  2036. struct ieee80211_vif *vif,
  2037. enum wl12xx_fw_type current_fw,
  2038. bool add)
  2039. {
  2040. struct wl1271 *wl = hw->priv;
  2041. u8 open_count;
  2042. if (ieee80211_suspending(hw))
  2043. return false;
  2044. if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
  2045. return false;
  2046. open_count = ieee80211_get_open_count(hw, vif);
  2047. wl1271_info("open_count=%d, add=%d, current_fw=%d",
  2048. open_count, add, current_fw);
  2049. if (add)
  2050. open_count++;
  2051. if (open_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
  2052. return true;
  2053. if (open_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
  2054. return true;
  2055. return false;
  2056. }
  2057. /*
  2058. * enter "forced psm". this is an ugly optimization used to make
  2059. * fw change a bit more disconnection-persistent.
  2060. */
  2061. static void wl12xx_force_active_psm(struct wl1271 *wl)
  2062. {
  2063. struct wl12xx_vif *wlvif;
  2064. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  2065. wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
  2066. }
  2067. }
  2068. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  2069. struct ieee80211_vif *vif)
  2070. {
  2071. struct wl1271 *wl = hw->priv;
  2072. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2073. int ret = 0;
  2074. u8 role_type;
  2075. int open_count;
  2076. bool booted = false;
  2077. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  2078. ieee80211_vif_type_p2p(vif), vif->addr);
  2079. mutex_lock(&wl->mutex);
  2080. ret = wl1271_ps_elp_wakeup(wl);
  2081. if (ret < 0)
  2082. goto out_unlock;
  2083. /*
  2084. * in some very corner case HW recovery scenarios its possible to
  2085. * get here before __wl1271_op_remove_interface is complete, so
  2086. * opt out if that is the case.
  2087. */
  2088. if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
  2089. test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
  2090. ret = -EBUSY;
  2091. goto out;
  2092. }
  2093. ret = wl12xx_init_vif_data(wl, vif);
  2094. if (ret < 0)
  2095. goto out;
  2096. wlvif->wl = wl;
  2097. role_type = wl12xx_get_role_type(wl, wlvif);
  2098. if (role_type == WL12XX_INVALID_ROLE_TYPE) {
  2099. ret = -EINVAL;
  2100. goto out;
  2101. }
  2102. if (wl12xx_need_fw_change(hw, vif, wl->fw_type, true)) {
  2103. wl12xx_force_active_psm(wl);
  2104. set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
  2105. mutex_unlock(&wl->mutex);
  2106. wl1271_recovery_work(&wl->recovery_work);
  2107. return 0;
  2108. }
  2109. /*
  2110. * TODO: after the nvs issue will be solved, move this block
  2111. * to start(), and make sure here the driver is ON.
  2112. */
  2113. wl1271_info("state: %d", wl->state);
  2114. if (wl->state == WL1271_STATE_OFF) {
  2115. /*
  2116. * we still need this in order to configure the fw
  2117. * while uploading the nvs
  2118. */
  2119. memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
  2120. booted = wl12xx_init_fw(wl);
  2121. if (!booted) {
  2122. ret = -EINVAL;
  2123. goto out;
  2124. }
  2125. }
  2126. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  2127. wlvif->bss_type == BSS_TYPE_IBSS) {
  2128. /*
  2129. * The device role is a special role used for
  2130. * rx and tx frames prior to association (as
  2131. * the STA role can get packets only from
  2132. * its associated bssid)
  2133. */
  2134. ret = wl12xx_cmd_role_enable(wl, vif->addr,
  2135. WL1271_ROLE_DEVICE,
  2136. &wlvif->dev_role_id);
  2137. if (ret < 0)
  2138. goto out;
  2139. }
  2140. ret = wl12xx_cmd_role_enable(wl, vif->addr,
  2141. role_type, &wlvif->role_id);
  2142. if (ret < 0)
  2143. goto out;
  2144. ret = wl1271_init_vif_specific(wl, vif);
  2145. if (ret < 0)
  2146. goto out;
  2147. list_add(&wlvif->list, &wl->wlvif_list);
  2148. set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
  2149. if (wlvif->bss_type == BSS_TYPE_AP_BSS)
  2150. wl->ap_count++;
  2151. else
  2152. wl->sta_count++;
  2153. open_count = ieee80211_get_open_count(hw, vif);
  2154. if (open_count > 0) /* Multi Role */
  2155. ieee80211_roaming_status(vif, false);
  2156. else /* Single Role */
  2157. ieee80211_roaming_status(vif, true);
  2158. out:
  2159. wl1271_ps_elp_sleep(wl);
  2160. out_unlock:
  2161. mutex_unlock(&wl->mutex);
  2162. return ret;
  2163. }
  2164. static void __wl1271_op_remove_interface(struct wl1271 *wl,
  2165. struct ieee80211_vif *vif,
  2166. bool reset_tx_queues)
  2167. {
  2168. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2169. int i, ret;
  2170. wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
  2171. if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
  2172. return;
  2173. /* because of hardware recovery, we may get here twice */
  2174. if (wl->state != WL1271_STATE_ON)
  2175. return;
  2176. wl1271_info("down");
  2177. if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
  2178. wl->scan_vif == vif) {
  2179. wl->scan.state = WL1271_SCAN_STATE_IDLE;
  2180. memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
  2181. wl->scan_vif = NULL;
  2182. wl->scan.req = NULL;
  2183. ieee80211_scan_completed(wl->hw, true);
  2184. }
  2185. if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
  2186. /* disable active roles and clear RX filters */
  2187. ret = wl1271_ps_elp_wakeup(wl);
  2188. if (ret < 0)
  2189. goto deinit;
  2190. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  2191. wlvif->bss_type == BSS_TYPE_IBSS) {
  2192. wl1271_configure_wowlan(wl, NULL);
  2193. if (wl12xx_dev_role_started(wlvif))
  2194. wl12xx_stop_dev(wl, wlvif);
  2195. ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
  2196. if (ret < 0)
  2197. goto deinit;
  2198. }
  2199. ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
  2200. if (ret < 0)
  2201. goto deinit;
  2202. wl1271_ps_elp_sleep(wl);
  2203. }
  2204. deinit:
  2205. /* clear all hlids (except system_hlid) */
  2206. wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
  2207. if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
  2208. wlvif->bss_type == BSS_TYPE_IBSS) {
  2209. wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
  2210. wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
  2211. wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
  2212. wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
  2213. } else {
  2214. wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
  2215. wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
  2216. wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
  2217. wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
  2218. for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
  2219. wl12xx_free_rate_policy(wl,
  2220. &wlvif->ap.ucast_rate_idx[i]);
  2221. wl1271_free_ap_keys(wl, wlvif);
  2222. }
  2223. dev_kfree_skb(wlvif->probereq);
  2224. wlvif->probereq = NULL;
  2225. memset(wl->rx_data_filters_status, 0,
  2226. sizeof(wl->rx_data_filters_status));
  2227. wl12xx_tx_reset_wlvif(wl, wlvif);
  2228. if (wl->last_wlvif == wlvif)
  2229. wl->last_wlvif = NULL;
  2230. list_del(&wlvif->list);
  2231. memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
  2232. wlvif->role_id = WL12XX_INVALID_ROLE_ID;
  2233. wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
  2234. if (wlvif->bss_type == BSS_TYPE_AP_BSS)
  2235. wl->ap_count--;
  2236. else
  2237. wl->sta_count--;
  2238. mutex_unlock(&wl->mutex);
  2239. del_timer_sync(&wlvif->rx_streaming_timer);
  2240. cancel_work_sync(&wlvif->rx_streaming_enable_work);
  2241. cancel_work_sync(&wlvif->rx_streaming_disable_work);
  2242. mutex_lock(&wl->mutex);
  2243. }
  2244. static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
  2245. struct ieee80211_vif *vif)
  2246. {
  2247. struct wl1271 *wl = hw->priv;
  2248. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2249. struct wl12xx_vif *iter;
  2250. bool cancel_recovery = true;
  2251. mutex_lock(&wl->mutex);
  2252. if (wl->state == WL1271_STATE_OFF ||
  2253. !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
  2254. goto out;
  2255. /*
  2256. * wl->vif can be null here if someone shuts down the interface
  2257. * just when hardware recovery has been started.
  2258. */
  2259. wl12xx_for_each_wlvif(wl, iter) {
  2260. if (iter != wlvif)
  2261. continue;
  2262. __wl1271_op_remove_interface(wl, vif, true);
  2263. break;
  2264. }
  2265. WARN_ON(iter != wlvif);
  2266. if (wl12xx_need_fw_change(hw, vif, wl->fw_type, false)) {
  2267. wl12xx_force_active_psm(wl);
  2268. set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
  2269. wl12xx_queue_recovery_work(wl);
  2270. cancel_recovery = false;
  2271. }
  2272. out:
  2273. mutex_unlock(&wl->mutex);
  2274. if (cancel_recovery)
  2275. cancel_work_sync(&wl->recovery_work);
  2276. }
  2277. static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
  2278. struct ieee80211_vif *vif,
  2279. enum nl80211_iftype new_type, bool p2p)
  2280. {
  2281. struct wl1271 *wl = hw->priv;
  2282. int ret;
  2283. set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
  2284. wl1271_op_remove_interface(hw, vif);
  2285. vif->type = new_type;
  2286. vif->p2p = p2p;
  2287. ret = wl1271_op_add_interface(hw, vif);
  2288. clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
  2289. return ret;
  2290. }
  2291. static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  2292. bool set_assoc)
  2293. {
  2294. int ret;
  2295. bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
  2296. /*
  2297. * One of the side effects of the JOIN command is that is clears
  2298. * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
  2299. * to a WPA/WPA2 access point will therefore kill the data-path.
  2300. * Currently the only valid scenario for JOIN during association
  2301. * is on roaming, in which case we will also be given new keys.
  2302. * Keep the below message for now, unless it starts bothering
  2303. * users who really like to roam a lot :)
  2304. */
  2305. if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  2306. wl1271_info("JOIN while associated.");
  2307. /* clear encryption type */
  2308. wlvif->encryption_type = KEY_NONE;
  2309. if (set_assoc)
  2310. set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
  2311. if (is_ibss)
  2312. ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
  2313. else
  2314. ret = wl12xx_cmd_role_start_sta(wl, wlvif);
  2315. if (ret < 0)
  2316. goto out;
  2317. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  2318. goto out;
  2319. /*
  2320. * The join command disable the keep-alive mode, shut down its process,
  2321. * and also clear the template config, so we need to reset it all after
  2322. * the join. The acx_aid starts the keep-alive process, and the order
  2323. * of the commands below is relevant.
  2324. */
  2325. ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
  2326. if (ret < 0)
  2327. goto out;
  2328. ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
  2329. if (ret < 0)
  2330. goto out;
  2331. ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
  2332. if (ret < 0)
  2333. goto out;
  2334. ret = wl1271_acx_keep_alive_config(wl, wlvif,
  2335. CMD_TEMPL_KLV_IDX_NULL_DATA,
  2336. ACX_KEEP_ALIVE_TPL_VALID);
  2337. if (ret < 0)
  2338. goto out;
  2339. out:
  2340. return ret;
  2341. }
  2342. static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  2343. {
  2344. int ret;
  2345. if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
  2346. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  2347. wl12xx_cmd_stop_channel_switch(wl);
  2348. ieee80211_chswitch_done(vif, false);
  2349. }
  2350. /* to stop listening to a channel, we disconnect */
  2351. ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
  2352. if (ret < 0)
  2353. goto out;
  2354. /* reset TX security counters on a clean disconnect */
  2355. wlvif->tx_security_last_seq_lsb = 0;
  2356. wlvif->tx_security_seq = 0;
  2357. out:
  2358. return ret;
  2359. }
  2360. static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  2361. {
  2362. wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
  2363. wlvif->rate_set = wlvif->basic_rate_set;
  2364. }
  2365. static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  2366. bool idle)
  2367. {
  2368. int ret;
  2369. bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
  2370. if (idle == cur_idle)
  2371. return 0;
  2372. if (idle) {
  2373. /* no need to croc if we weren't busy (e.g. during boot) */
  2374. if (wl12xx_dev_role_started(wlvif)) {
  2375. ret = wl12xx_stop_dev(wl, wlvif);
  2376. if (ret < 0)
  2377. goto out;
  2378. }
  2379. wlvif->rate_set =
  2380. wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  2381. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  2382. if (ret < 0)
  2383. goto out;
  2384. ret = wl1271_acx_keep_alive_config(
  2385. wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
  2386. ACX_KEEP_ALIVE_TPL_INVALID);
  2387. if (ret < 0)
  2388. goto out;
  2389. clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
  2390. } else {
  2391. /* The current firmware only supports sched_scan in idle */
  2392. if (wl->sched_scanning) {
  2393. wl1271_scan_sched_scan_stop(wl, wlvif);
  2394. ieee80211_sched_scan_stopped(wl->hw);
  2395. }
  2396. ret = wl12xx_start_dev(wl, wlvif);
  2397. if (ret < 0)
  2398. goto out;
  2399. set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
  2400. }
  2401. out:
  2402. return ret;
  2403. }
  2404. static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  2405. struct ieee80211_conf *conf, u32 changed)
  2406. {
  2407. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  2408. int channel, ret;
  2409. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  2410. /* if the channel changes while joined, join again */
  2411. if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
  2412. ((wlvif->band != conf->channel->band) ||
  2413. (wlvif->channel != channel))) {
  2414. /* send all pending packets */
  2415. wl1271_tx_work_locked(wl);
  2416. wlvif->band = conf->channel->band;
  2417. wlvif->channel = channel;
  2418. if (!is_ap) {
  2419. /*
  2420. * FIXME: the mac80211 should really provide a fixed
  2421. * rate to use here. for now, just use the smallest
  2422. * possible rate for the band as a fixed rate for
  2423. * association frames and other control messages.
  2424. */
  2425. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  2426. wl1271_set_band_rate(wl, wlvif);
  2427. wlvif->basic_rate =
  2428. wl1271_tx_min_rate_get(wl,
  2429. wlvif->basic_rate_set);
  2430. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  2431. if (ret < 0)
  2432. wl1271_warning("rate policy for channel "
  2433. "failed %d", ret);
  2434. if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
  2435. &wlvif->flags)) {
  2436. #if 0
  2437. if (wl12xx_dev_role_started(wlvif)) {
  2438. /* roaming */
  2439. ret = wl12xx_croc(wl,
  2440. wlvif->dev_role_id);
  2441. if (ret < 0)
  2442. return ret;
  2443. }
  2444. ret = wl1271_join(wl, wlvif, false);
  2445. if (ret < 0)
  2446. wl1271_warning("cmd join on channel "
  2447. "failed %d", ret);
  2448. #endif
  2449. } else {
  2450. /*
  2451. * change the ROC channel. do it only if we are
  2452. * not idle. otherwise, CROC will be called
  2453. * anyway.
  2454. */
  2455. if (wl12xx_dev_role_started(wlvif) &&
  2456. !(conf->flags & IEEE80211_CONF_IDLE)) {
  2457. ret = wl12xx_stop_dev(wl, wlvif);
  2458. if (ret < 0)
  2459. return ret;
  2460. ret = wl12xx_start_dev(wl, wlvif);
  2461. if (ret < 0)
  2462. return ret;
  2463. }
  2464. }
  2465. }
  2466. }
  2467. if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
  2468. if ((conf->flags & IEEE80211_CONF_PS) &&
  2469. test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
  2470. !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
  2471. int ps_mode;
  2472. char *ps_mode_str;
  2473. if (wl->conf.conn.forced_ps) {
  2474. ps_mode = STATION_POWER_SAVE_MODE;
  2475. ps_mode_str = "forced";
  2476. } else {
  2477. ps_mode = STATION_AUTO_PS_MODE;
  2478. ps_mode_str = "auto";
  2479. }
  2480. wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
  2481. ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
  2482. if (ret < 0)
  2483. wl1271_warning("enter %s ps failed %d",
  2484. ps_mode_str, ret);
  2485. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  2486. test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
  2487. wl1271_debug(DEBUG_PSM, "auto ps disabled");
  2488. ret = wl1271_ps_set_mode(wl, wlvif,
  2489. STATION_ACTIVE_MODE);
  2490. if (ret < 0)
  2491. wl1271_warning("exit auto ps failed %d", ret);
  2492. }
  2493. }
  2494. if (conf->power_level != wlvif->power_level) {
  2495. ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
  2496. if (ret < 0)
  2497. return ret;
  2498. wlvif->power_level = conf->power_level;
  2499. }
  2500. return 0;
  2501. }
  2502. static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
  2503. {
  2504. struct wl1271 *wl = hw->priv;
  2505. struct wl12xx_vif *wlvif;
  2506. struct ieee80211_conf *conf = &hw->conf;
  2507. int channel, ret = 0;
  2508. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  2509. wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
  2510. " changed 0x%x",
  2511. channel,
  2512. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  2513. conf->power_level,
  2514. conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
  2515. changed);
  2516. /*
  2517. * mac80211 will go to idle nearly immediately after transmitting some
  2518. * frames, such as the deauth. To make sure those frames reach the air,
  2519. * wait here until the TX queue is fully flushed.
  2520. */
  2521. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
  2522. ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
  2523. (conf->flags & IEEE80211_CONF_IDLE)))
  2524. wl1271_tx_flush(wl);
  2525. mutex_lock(&wl->mutex);
  2526. /* we support configuring the channel and band even while off */
  2527. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  2528. wl->band = conf->channel->band;
  2529. wl->channel = channel;
  2530. }
  2531. if (changed & IEEE80211_CONF_CHANGE_POWER)
  2532. wl->power_level = conf->power_level;
  2533. if (unlikely(wl->state == WL1271_STATE_OFF))
  2534. goto out;
  2535. ret = wl1271_ps_elp_wakeup(wl);
  2536. if (ret < 0)
  2537. goto out;
  2538. /* configure each interface */
  2539. wl12xx_for_each_wlvif(wl, wlvif) {
  2540. ret = wl12xx_config_vif(wl, wlvif, conf, changed);
  2541. if (ret < 0)
  2542. goto out_sleep;
  2543. }
  2544. out_sleep:
  2545. wl1271_ps_elp_sleep(wl);
  2546. out:
  2547. mutex_unlock(&wl->mutex);
  2548. return ret;
  2549. }
  2550. struct wl1271_filter_params {
  2551. bool enabled;
  2552. int mc_list_length;
  2553. u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
  2554. };
  2555. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2556. static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
  2557. struct netdev_hw_addr_list *mc_list)
  2558. #else
  2559. static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count,
  2560. struct dev_addr_list *mc_list)
  2561. #endif
  2562. {
  2563. struct wl1271_filter_params *fp;
  2564. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2565. struct netdev_hw_addr *ha;
  2566. #else
  2567. int i;
  2568. #endif
  2569. struct wl1271 *wl = hw->priv;
  2570. if (unlikely(wl->state == WL1271_STATE_OFF))
  2571. return 0;
  2572. fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
  2573. if (!fp) {
  2574. wl1271_error("Out of memory setting filters.");
  2575. return 0;
  2576. }
  2577. /* update multicast filtering parameters */
  2578. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2579. fp->mc_list_length = 0;
  2580. if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
  2581. #else
  2582. fp->enabled = true;
  2583. if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) {
  2584. mc_count = 0;
  2585. #endif
  2586. fp->enabled = false;
  2587. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2588. } else {
  2589. fp->enabled = true;
  2590. netdev_hw_addr_list_for_each(ha, mc_list) {
  2591. #else
  2592. }
  2593. fp->mc_list_length = 0;
  2594. for (i = 0; i < mc_count; i++) {
  2595. if (mc_list->da_addrlen == ETH_ALEN) {
  2596. #endif
  2597. memcpy(fp->mc_list[fp->mc_list_length],
  2598. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2599. ha->addr, ETH_ALEN);
  2600. #else
  2601. mc_list->da_addr, ETH_ALEN);
  2602. #endif
  2603. fp->mc_list_length++;
  2604. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
  2605. }
  2606. #else
  2607. } else
  2608. wl1271_warning("Unknown mc address length.");
  2609. mc_list = mc_list->next;
  2610. #endif
  2611. }
  2612. return (u64)(unsigned long)fp;
  2613. }
  2614. #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  2615. FIF_ALLMULTI | \
  2616. FIF_FCSFAIL | \
  2617. FIF_BCN_PRBRESP_PROMISC | \
  2618. FIF_CONTROL | \
  2619. FIF_OTHER_BSS)
  2620. static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
  2621. unsigned int changed,
  2622. unsigned int *total, u64 multicast)
  2623. {
  2624. struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
  2625. struct wl1271 *wl = hw->priv;
  2626. struct wl12xx_vif *wlvif;
  2627. int ret;
  2628. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
  2629. " total %x", changed, *total);
  2630. mutex_lock(&wl->mutex);
  2631. *total &= WL1271_SUPPORTED_FILTERS;
  2632. changed &= WL1271_SUPPORTED_FILTERS;
  2633. if (unlikely(wl->state == WL1271_STATE_OFF))
  2634. goto out;
  2635. ret = wl1271_ps_elp_wakeup(wl);
  2636. if (ret < 0)
  2637. goto out;
  2638. wl12xx_for_each_wlvif(wl, wlvif) {
  2639. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  2640. if (*total & FIF_ALLMULTI)
  2641. ret = wl1271_acx_group_address_tbl(wl, wlvif,
  2642. false,
  2643. NULL, 0);
  2644. else if (fp)
  2645. ret = wl1271_acx_group_address_tbl(wl, wlvif,
  2646. fp->enabled,
  2647. fp->mc_list,
  2648. fp->mc_list_length);
  2649. if (ret < 0)
  2650. goto out_sleep;
  2651. }
  2652. }
  2653. /*
  2654. * the fw doesn't provide an api to configure the filters. instead,
  2655. * the filters configuration is based on the active roles / ROC
  2656. * state.
  2657. */
  2658. out_sleep:
  2659. wl1271_ps_elp_sleep(wl);
  2660. out:
  2661. mutex_unlock(&wl->mutex);
  2662. kfree(fp);
  2663. }
  2664. static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  2665. u8 id, u8 key_type, u8 key_size,
  2666. const u8 *key, u8 hlid, u32 tx_seq_32,
  2667. u16 tx_seq_16)
  2668. {
  2669. struct wl1271_ap_key *ap_key;
  2670. int i;
  2671. wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
  2672. if (key_size > MAX_KEY_SIZE)
  2673. return -EINVAL;
  2674. /*
  2675. * Find next free entry in ap_keys. Also check we are not replacing
  2676. * an existing key.
  2677. */
  2678. for (i = 0; i < MAX_NUM_KEYS; i++) {
  2679. if (wlvif->ap.recorded_keys[i] == NULL)
  2680. break;
  2681. if (wlvif->ap.recorded_keys[i]->id == id) {
  2682. wl1271_warning("trying to record key replacement");
  2683. return -EINVAL;
  2684. }
  2685. }
  2686. if (i == MAX_NUM_KEYS)
  2687. return -EBUSY;
  2688. ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
  2689. if (!ap_key)
  2690. return -ENOMEM;
  2691. ap_key->id = id;
  2692. ap_key->key_type = key_type;
  2693. ap_key->key_size = key_size;
  2694. memcpy(ap_key->key, key, key_size);
  2695. ap_key->hlid = hlid;
  2696. ap_key->tx_seq_32 = tx_seq_32;
  2697. ap_key->tx_seq_16 = tx_seq_16;
  2698. wlvif->ap.recorded_keys[i] = ap_key;
  2699. return 0;
  2700. }
  2701. static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  2702. {
  2703. int i;
  2704. for (i = 0; i < MAX_NUM_KEYS; i++) {
  2705. kfree(wlvif->ap.recorded_keys[i]);
  2706. wlvif->ap.recorded_keys[i] = NULL;
  2707. }
  2708. }
  2709. static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  2710. {
  2711. int i, ret = 0;
  2712. struct wl1271_ap_key *key;
  2713. bool wep_key_added = false;
  2714. for (i = 0; i < MAX_NUM_KEYS; i++) {
  2715. u8 hlid;
  2716. if (wlvif->ap.recorded_keys[i] == NULL)
  2717. break;
  2718. key = wlvif->ap.recorded_keys[i];
  2719. hlid = key->hlid;
  2720. if (hlid == WL12XX_INVALID_LINK_ID)
  2721. hlid = wlvif->ap.bcast_hlid;
  2722. ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
  2723. key->id, key->key_type,
  2724. key->key_size, key->key,
  2725. hlid, key->tx_seq_32,
  2726. key->tx_seq_16);
  2727. if (ret < 0)
  2728. goto out;
  2729. if (key->key_type == KEY_WEP)
  2730. wep_key_added = true;
  2731. }
  2732. if (wep_key_added) {
  2733. ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
  2734. wlvif->ap.bcast_hlid);
  2735. if (ret < 0)
  2736. goto out;
  2737. }
  2738. out:
  2739. wl1271_free_ap_keys(wl, wlvif);
  2740. return ret;
  2741. }
  2742. static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  2743. u16 action, u8 id, u8 key_type,
  2744. u8 key_size, const u8 *key, u32 tx_seq_32,
  2745. u16 tx_seq_16, struct ieee80211_sta *sta)
  2746. {
  2747. int ret;
  2748. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  2749. if (is_ap) {
  2750. struct wl1271_station *wl_sta;
  2751. u8 hlid;
  2752. if (sta) {
  2753. wl_sta = (struct wl1271_station *)sta->drv_priv;
  2754. hlid = wl_sta->hlid;
  2755. } else {
  2756. hlid = wlvif->ap.bcast_hlid;
  2757. }
  2758. if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  2759. /*
  2760. * We do not support removing keys after AP shutdown.
  2761. * Pretend we do to make mac80211 happy.
  2762. */
  2763. if (action != KEY_ADD_OR_REPLACE)
  2764. return 0;
  2765. ret = wl1271_record_ap_key(wl, wlvif, id,
  2766. key_type, key_size,
  2767. key, hlid, tx_seq_32,
  2768. tx_seq_16);
  2769. } else {
  2770. ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
  2771. id, key_type, key_size,
  2772. key, hlid, tx_seq_32,
  2773. tx_seq_16);
  2774. }
  2775. if (ret < 0)
  2776. return ret;
  2777. } else {
  2778. const u8 *addr;
  2779. static const u8 bcast_addr[ETH_ALEN] = {
  2780. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2781. };
  2782. addr = sta ? sta->addr : bcast_addr;
  2783. if (is_zero_ether_addr(addr)) {
  2784. /* We dont support TX only encryption */
  2785. return -EOPNOTSUPP;
  2786. }
  2787. /* The wl1271 does not allow to remove unicast keys - they
  2788. will be cleared automatically on next CMD_JOIN. Ignore the
  2789. request silently, as we dont want the mac80211 to emit
  2790. an error message. */
  2791. if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
  2792. return 0;
  2793. /* don't remove key if hlid was already deleted */
  2794. if (action == KEY_REMOVE &&
  2795. wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
  2796. return 0;
  2797. ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
  2798. id, key_type, key_size,
  2799. key, addr, tx_seq_32,
  2800. tx_seq_16);
  2801. if (ret < 0)
  2802. return ret;
  2803. }
  2804. return 0;
  2805. }
  2806. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2807. struct ieee80211_vif *vif,
  2808. struct ieee80211_sta *sta,
  2809. struct ieee80211_key_conf *key_conf)
  2810. {
  2811. struct wl1271 *wl = hw->priv;
  2812. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2813. int ret;
  2814. u32 tx_seq_32 = 0;
  2815. u16 tx_seq_16 = 0;
  2816. u8 key_type;
  2817. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  2818. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
  2819. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  2820. key_conf->cipher, key_conf->keyidx,
  2821. key_conf->keylen, key_conf->flags);
  2822. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  2823. mutex_lock(&wl->mutex);
  2824. if (unlikely(wl->state == WL1271_STATE_OFF)) {
  2825. ret = -EAGAIN;
  2826. goto out_unlock;
  2827. }
  2828. ret = wl1271_ps_elp_wakeup(wl);
  2829. if (ret < 0)
  2830. goto out_unlock;
  2831. switch (key_conf->cipher) {
  2832. case WLAN_CIPHER_SUITE_WEP40:
  2833. case WLAN_CIPHER_SUITE_WEP104:
  2834. key_type = KEY_WEP;
  2835. key_conf->hw_key_idx = key_conf->keyidx;
  2836. break;
  2837. case WLAN_CIPHER_SUITE_TKIP:
  2838. key_type = KEY_TKIP;
  2839. key_conf->hw_key_idx = key_conf->keyidx;
  2840. tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
  2841. tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
  2842. break;
  2843. case WLAN_CIPHER_SUITE_CCMP:
  2844. key_type = KEY_AES;
  2845. key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2846. tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
  2847. tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
  2848. break;
  2849. case WL1271_CIPHER_SUITE_GEM:
  2850. key_type = KEY_GEM;
  2851. tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
  2852. tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
  2853. break;
  2854. default:
  2855. wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
  2856. ret = -EOPNOTSUPP;
  2857. goto out_sleep;
  2858. }
  2859. switch (cmd) {
  2860. case SET_KEY:
  2861. ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
  2862. key_conf->keyidx, key_type,
  2863. key_conf->keylen, key_conf->key,
  2864. tx_seq_32, tx_seq_16, sta);
  2865. if (ret < 0) {
  2866. wl1271_error("Could not add or replace key");
  2867. goto out_sleep;
  2868. }
  2869. /*
  2870. * reconfiguring arp response if the unicast (or common)
  2871. * encryption key type was changed
  2872. */
  2873. if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
  2874. (sta || key_type == KEY_WEP) &&
  2875. wlvif->encryption_type != key_type) {
  2876. wlvif->encryption_type = key_type;
  2877. ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
  2878. if (ret < 0) {
  2879. wl1271_warning("build arp rsp failed: %d", ret);
  2880. goto out_sleep;
  2881. }
  2882. }
  2883. break;
  2884. case DISABLE_KEY:
  2885. ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
  2886. key_conf->keyidx, key_type,
  2887. key_conf->keylen, key_conf->key,
  2888. 0, 0, sta);
  2889. if (ret < 0) {
  2890. wl1271_error("Could not remove key");
  2891. goto out_sleep;
  2892. }
  2893. break;
  2894. default:
  2895. wl1271_error("Unsupported key cmd 0x%x", cmd);
  2896. ret = -EOPNOTSUPP;
  2897. break;
  2898. }
  2899. out_sleep:
  2900. wl1271_ps_elp_sleep(wl);
  2901. out_unlock:
  2902. mutex_unlock(&wl->mutex);
  2903. return ret;
  2904. }
  2905. static int wl1271_op_set_default_key_idx(struct ieee80211_hw *hw,
  2906. struct ieee80211_vif *vif,
  2907. int key_idx)
  2908. {
  2909. struct wl1271 *wl = hw->priv;
  2910. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2911. int ret = 0;
  2912. mutex_lock(&wl->mutex);
  2913. if (wlvif->default_key == key_idx)
  2914. goto out_unlock;
  2915. ret = wl1271_ps_elp_wakeup(wl);
  2916. if (ret < 0)
  2917. goto out_unlock;
  2918. wlvif->default_key = key_idx;
  2919. /* the default WEP key needs to be configured at least once */
  2920. if (wlvif->encryption_type == KEY_WEP) {
  2921. ret = wl12xx_cmd_set_default_wep_key(wl,
  2922. key_idx,
  2923. wlvif->sta.hlid);
  2924. if (ret < 0)
  2925. goto out_sleep;
  2926. }
  2927. out_sleep:
  2928. wl1271_ps_elp_sleep(wl);
  2929. out_unlock:
  2930. mutex_unlock(&wl->mutex);
  2931. return ret;
  2932. }
  2933. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  2934. struct ieee80211_vif *vif,
  2935. struct cfg80211_scan_request *req)
  2936. {
  2937. struct wl1271 *wl = hw->priv;
  2938. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  2939. int ret;
  2940. u8 *ssid = NULL;
  2941. size_t len = 0;
  2942. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  2943. if (req->n_ssids) {
  2944. ssid = req->ssids[0].ssid;
  2945. len = req->ssids[0].ssid_len;
  2946. }
  2947. mutex_lock(&wl->mutex);
  2948. if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
  2949. /*
  2950. * We cannot return -EBUSY here because cfg80211 will expect
  2951. * a call to ieee80211_scan_completed if we do - in this case
  2952. * there won't be any call.
  2953. */
  2954. ret = -EAGAIN;
  2955. goto out;
  2956. }
  2957. ret = wl1271_ps_elp_wakeup(wl);
  2958. if (ret < 0)
  2959. goto out;
  2960. /* fail if there is any role in ROC */
  2961. if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
  2962. /* don't allow scanning right now */
  2963. ret = -EBUSY;
  2964. goto out_sleep;
  2965. }
  2966. ret = wl1271_scan(hw->priv, vif, ssid, len, req);
  2967. out_sleep:
  2968. wl1271_ps_elp_sleep(wl);
  2969. out:
  2970. mutex_unlock(&wl->mutex);
  2971. return ret;
  2972. }
  2973. static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
  2974. struct ieee80211_vif *vif)
  2975. {
  2976. struct wl1271 *wl = hw->priv;
  2977. int ret;
  2978. wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
  2979. mutex_lock(&wl->mutex);
  2980. if (wl->state == WL1271_STATE_OFF)
  2981. goto out;
  2982. if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
  2983. goto out;
  2984. ret = wl1271_ps_elp_wakeup(wl);
  2985. if (ret < 0)
  2986. goto out;
  2987. if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
  2988. ret = wl1271_scan_stop(wl);
  2989. if (ret < 0)
  2990. goto out_sleep;
  2991. }
  2992. wl->scan.state = WL1271_SCAN_STATE_IDLE;
  2993. memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
  2994. wl->scan_vif = NULL;
  2995. wl->scan.req = NULL;
  2996. ieee80211_scan_completed(wl->hw, true);
  2997. out_sleep:
  2998. wl1271_ps_elp_sleep(wl);
  2999. out:
  3000. mutex_unlock(&wl->mutex);
  3001. cancel_delayed_work_sync(&wl->scan_complete_work);
  3002. }
  3003. static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
  3004. struct ieee80211_vif *vif,
  3005. struct cfg80211_sched_scan_request *req,
  3006. struct ieee80211_sched_scan_ies *ies)
  3007. {
  3008. struct wl1271 *wl = hw->priv;
  3009. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3010. int ret;
  3011. wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
  3012. mutex_lock(&wl->mutex);
  3013. if (wl->state == WL1271_STATE_OFF) {
  3014. ret = -EAGAIN;
  3015. goto out;
  3016. }
  3017. ret = wl1271_ps_elp_wakeup(wl);
  3018. if (ret < 0)
  3019. goto out;
  3020. ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
  3021. if (ret < 0)
  3022. goto out_sleep;
  3023. ret = wl1271_scan_sched_scan_start(wl, wlvif);
  3024. if (ret < 0)
  3025. goto out_sleep;
  3026. wl->sched_scanning = true;
  3027. out_sleep:
  3028. wl1271_ps_elp_sleep(wl);
  3029. out:
  3030. mutex_unlock(&wl->mutex);
  3031. return ret;
  3032. }
  3033. static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
  3034. struct ieee80211_vif *vif)
  3035. {
  3036. struct wl1271 *wl = hw->priv;
  3037. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3038. int ret;
  3039. wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
  3040. mutex_lock(&wl->mutex);
  3041. if (wl->state == WL1271_STATE_OFF)
  3042. goto out;
  3043. ret = wl1271_ps_elp_wakeup(wl);
  3044. if (ret < 0)
  3045. goto out;
  3046. wl1271_scan_sched_scan_stop(wl, wlvif);
  3047. wl1271_ps_elp_sleep(wl);
  3048. out:
  3049. mutex_unlock(&wl->mutex);
  3050. }
  3051. static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  3052. {
  3053. struct wl1271 *wl = hw->priv;
  3054. int ret = 0;
  3055. mutex_lock(&wl->mutex);
  3056. if (unlikely(wl->state == WL1271_STATE_OFF)) {
  3057. ret = -EAGAIN;
  3058. goto out;
  3059. }
  3060. ret = wl1271_ps_elp_wakeup(wl);
  3061. if (ret < 0)
  3062. goto out;
  3063. ret = wl1271_acx_frag_threshold(wl, value);
  3064. if (ret < 0)
  3065. wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
  3066. wl1271_ps_elp_sleep(wl);
  3067. out:
  3068. mutex_unlock(&wl->mutex);
  3069. return ret;
  3070. }
  3071. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  3072. {
  3073. struct wl1271 *wl = hw->priv;
  3074. struct wl12xx_vif *wlvif;
  3075. int ret = 0;
  3076. mutex_lock(&wl->mutex);
  3077. if (unlikely(wl->state == WL1271_STATE_OFF)) {
  3078. ret = -EAGAIN;
  3079. goto out;
  3080. }
  3081. ret = wl1271_ps_elp_wakeup(wl);
  3082. if (ret < 0)
  3083. goto out;
  3084. wl12xx_for_each_wlvif(wl, wlvif) {
  3085. ret = wl1271_acx_rts_threshold(wl, wlvif, value);
  3086. if (ret < 0)
  3087. wl1271_warning("set rts threshold failed: %d", ret);
  3088. }
  3089. wl1271_ps_elp_sleep(wl);
  3090. out:
  3091. mutex_unlock(&wl->mutex);
  3092. return ret;
  3093. }
  3094. static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
  3095. int offset)
  3096. {
  3097. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3098. u8 ssid_len;
  3099. const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
  3100. skb->len - offset);
  3101. if (!ptr) {
  3102. wl1271_error("No SSID in IEs!");
  3103. return -ENOENT;
  3104. }
  3105. ssid_len = ptr[1];
  3106. if (ssid_len > IEEE80211_MAX_SSID_LEN) {
  3107. wl1271_error("SSID is too long!");
  3108. return -EINVAL;
  3109. }
  3110. wlvif->ssid_len = ssid_len;
  3111. memcpy(wlvif->ssid, ptr+2, ssid_len);
  3112. return 0;
  3113. }
  3114. static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
  3115. {
  3116. int len;
  3117. const u8 *next, *end = skb->data + skb->len;
  3118. u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
  3119. skb->len - ieoffset);
  3120. if (!ie)
  3121. return;
  3122. len = ie[1] + 2;
  3123. next = ie + len;
  3124. memmove(ie, next, end - next);
  3125. skb_trim(skb, skb->len - len);
  3126. }
  3127. static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
  3128. unsigned int oui, u8 oui_type,
  3129. int ieoffset)
  3130. {
  3131. int len;
  3132. const u8 *next, *end = skb->data + skb->len;
  3133. u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
  3134. skb->data + ieoffset,
  3135. skb->len - ieoffset);
  3136. if (!ie)
  3137. return;
  3138. len = ie[1] + 2;
  3139. next = ie + len;
  3140. memmove(ie, next, end - next);
  3141. skb_trim(skb, skb->len - len);
  3142. }
  3143. static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
  3144. struct ieee80211_vif *vif)
  3145. {
  3146. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3147. struct sk_buff *skb;
  3148. int ret;
  3149. skb = ieee80211_proberesp_get(wl->hw, vif);
  3150. if (!skb)
  3151. return -EOPNOTSUPP;
  3152. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  3153. CMD_TEMPL_AP_PROBE_RESPONSE,
  3154. skb->data,
  3155. skb->len, 0,
  3156. rates);
  3157. dev_kfree_skb(skb);
  3158. return ret;
  3159. }
  3160. static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
  3161. struct ieee80211_vif *vif,
  3162. u8 *probe_rsp_data,
  3163. size_t probe_rsp_len,
  3164. u32 rates)
  3165. {
  3166. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3167. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  3168. u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
  3169. int ssid_ie_offset, ie_offset, templ_len;
  3170. const u8 *ptr;
  3171. /* no need to change probe response if the SSID is set correctly */
  3172. if (wlvif->ssid_len > 0)
  3173. return wl1271_cmd_template_set(wl, wlvif->role_id,
  3174. CMD_TEMPL_AP_PROBE_RESPONSE,
  3175. probe_rsp_data,
  3176. probe_rsp_len, 0,
  3177. rates);
  3178. if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
  3179. wl1271_error("probe_rsp template too big");
  3180. return -EINVAL;
  3181. }
  3182. /* start searching from IE offset */
  3183. ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  3184. ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
  3185. probe_rsp_len - ie_offset);
  3186. if (!ptr) {
  3187. wl1271_error("No SSID in beacon!");
  3188. return -EINVAL;
  3189. }
  3190. ssid_ie_offset = ptr - probe_rsp_data;
  3191. ptr += (ptr[1] + 2);
  3192. memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
  3193. /* insert SSID from bss_conf */
  3194. probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
  3195. probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
  3196. memcpy(probe_rsp_templ + ssid_ie_offset + 2,
  3197. bss_conf->ssid, bss_conf->ssid_len);
  3198. templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
  3199. memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
  3200. ptr, probe_rsp_len - (ptr - probe_rsp_data));
  3201. templ_len += probe_rsp_len - (ptr - probe_rsp_data);
  3202. return wl1271_cmd_template_set(wl, wlvif->role_id,
  3203. CMD_TEMPL_AP_PROBE_RESPONSE,
  3204. probe_rsp_templ,
  3205. templ_len, 0,
  3206. rates);
  3207. }
  3208. static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
  3209. struct ieee80211_vif *vif,
  3210. struct ieee80211_bss_conf *bss_conf,
  3211. u32 changed)
  3212. {
  3213. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3214. int ret = 0;
  3215. if (changed & BSS_CHANGED_ERP_SLOT) {
  3216. if (bss_conf->use_short_slot)
  3217. ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
  3218. else
  3219. ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
  3220. if (ret < 0) {
  3221. wl1271_warning("Set slot time failed %d", ret);
  3222. goto out;
  3223. }
  3224. }
  3225. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3226. if (bss_conf->use_short_preamble)
  3227. wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
  3228. else
  3229. wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
  3230. }
  3231. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  3232. if (bss_conf->use_cts_prot)
  3233. ret = wl1271_acx_cts_protect(wl, wlvif,
  3234. CTSPROTECT_ENABLE);
  3235. else
  3236. ret = wl1271_acx_cts_protect(wl, wlvif,
  3237. CTSPROTECT_DISABLE);
  3238. if (ret < 0) {
  3239. wl1271_warning("Set ctsprotect failed %d", ret);
  3240. goto out;
  3241. }
  3242. }
  3243. out:
  3244. return ret;
  3245. }
  3246. static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
  3247. struct ieee80211_vif *vif,
  3248. struct ieee80211_bss_conf *bss_conf,
  3249. u32 changed)
  3250. {
  3251. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3252. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  3253. int ret = 0;
  3254. if ((changed & BSS_CHANGED_BEACON_INT)) {
  3255. wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
  3256. bss_conf->beacon_int);
  3257. wlvif->beacon_int = bss_conf->beacon_int;
  3258. }
  3259. if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
  3260. u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  3261. if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
  3262. wl1271_debug(DEBUG_AP, "probe response updated");
  3263. set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
  3264. }
  3265. }
  3266. if ((changed & BSS_CHANGED_BEACON)) {
  3267. struct ieee80211_hdr *hdr;
  3268. u32 min_rate;
  3269. int ieoffset = offsetof(struct ieee80211_mgmt,
  3270. u.beacon.variable);
  3271. struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
  3272. u16 tmpl_id;
  3273. if (!beacon) {
  3274. ret = -EINVAL;
  3275. goto out;
  3276. }
  3277. wl1271_debug(DEBUG_MASTER, "beacon updated");
  3278. ret = wl1271_ssid_set(vif, beacon, ieoffset);
  3279. if (ret < 0) {
  3280. dev_kfree_skb(beacon);
  3281. goto out;
  3282. }
  3283. min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  3284. tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
  3285. CMD_TEMPL_BEACON;
  3286. ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
  3287. beacon->data,
  3288. beacon->len, 0,
  3289. min_rate);
  3290. if (ret < 0) {
  3291. dev_kfree_skb(beacon);
  3292. goto out;
  3293. }
  3294. /*
  3295. * In case we already have a probe-resp beacon set explicitly
  3296. * by usermode, don't use the beacon data.
  3297. */
  3298. if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
  3299. goto end_bcn;
  3300. /* remove TIM ie from probe response */
  3301. wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
  3302. /*
  3303. * remove p2p ie from probe response.
  3304. * the fw reponds to probe requests that don't include
  3305. * the p2p ie. probe requests with p2p ie will be passed,
  3306. * and will be responded by the supplicant (the spec
  3307. * forbids including the p2p ie when responding to probe
  3308. * requests that didn't include it).
  3309. */
  3310. wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
  3311. WLAN_OUI_TYPE_WFA_P2P, ieoffset);
  3312. hdr = (struct ieee80211_hdr *) beacon->data;
  3313. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  3314. IEEE80211_STYPE_PROBE_RESP);
  3315. if (is_ap)
  3316. ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
  3317. beacon->data,
  3318. beacon->len,
  3319. min_rate);
  3320. else
  3321. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  3322. CMD_TEMPL_PROBE_RESPONSE,
  3323. beacon->data,
  3324. beacon->len, 0,
  3325. min_rate);
  3326. end_bcn:
  3327. dev_kfree_skb(beacon);
  3328. if (ret < 0)
  3329. goto out;
  3330. }
  3331. out:
  3332. if (ret != 0)
  3333. wl1271_error("beacon info change failed: %d", ret);
  3334. return ret;
  3335. }
  3336. /* AP mode changes */
  3337. static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
  3338. struct ieee80211_vif *vif,
  3339. struct ieee80211_bss_conf *bss_conf,
  3340. u32 changed)
  3341. {
  3342. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3343. int ret = 0;
  3344. if ((changed & BSS_CHANGED_BASIC_RATES)) {
  3345. u32 rates = bss_conf->basic_rates;
  3346. wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
  3347. wlvif->band);
  3348. wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
  3349. wlvif->basic_rate_set);
  3350. ret = wl1271_init_ap_rates(wl, wlvif);
  3351. if (ret < 0) {
  3352. wl1271_error("AP rate policy change failed %d", ret);
  3353. goto out;
  3354. }
  3355. ret = wl1271_ap_init_templates(wl, vif);
  3356. if (ret < 0)
  3357. goto out;
  3358. }
  3359. ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
  3360. if (ret < 0)
  3361. goto out;
  3362. if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
  3363. if (bss_conf->enable_beacon) {
  3364. if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  3365. ret = wl12xx_cmd_role_start_ap(wl, wlvif);
  3366. if (ret < 0)
  3367. goto out;
  3368. ret = wl1271_ap_init_hwenc(wl, wlvif);
  3369. if (ret < 0)
  3370. goto out;
  3371. set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
  3372. wl1271_debug(DEBUG_AP, "started AP");
  3373. }
  3374. } else {
  3375. if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  3376. ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
  3377. if (ret < 0)
  3378. goto out;
  3379. clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
  3380. clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
  3381. &wlvif->flags);
  3382. wl1271_debug(DEBUG_AP, "stopped AP");
  3383. }
  3384. }
  3385. }
  3386. ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
  3387. if (ret < 0)
  3388. goto out;
  3389. /* Handle HT information change */
  3390. if ((changed & BSS_CHANGED_HT) &&
  3391. (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
  3392. ret = wl1271_acx_set_ht_information(wl, wlvif,
  3393. bss_conf->ht_operation_mode);
  3394. if (ret < 0) {
  3395. wl1271_warning("Set ht information failed %d", ret);
  3396. goto out;
  3397. }
  3398. }
  3399. if (!list_empty(&wl->peers_list) &&
  3400. test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  3401. struct ap_peers *peer, *next;
  3402. enum ieee80211_sta_state state = IEEE80211_STA_NONE;
  3403. list_for_each_entry_safe(peer, next, &wl->peers_list, list) {
  3404. wl1271_op_sta_add_locked(peer->hw, peer->vif,
  3405. &peer->sta);
  3406. while (state < peer->sta.state)
  3407. wl12xx_update_sta_state(wl, &peer->sta,
  3408. ++state);
  3409. wl1271_debug(DEBUG_AP, "add sta %pM", peer->sta.addr);
  3410. list_del(&peer->list);
  3411. kfree(peer);
  3412. }
  3413. }
  3414. out:
  3415. return;
  3416. }
  3417. /* STA/IBSS mode changes */
  3418. static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
  3419. struct ieee80211_vif *vif,
  3420. struct ieee80211_bss_conf *bss_conf,
  3421. u32 changed)
  3422. {
  3423. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3424. bool do_join = false, set_assoc = false;
  3425. bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
  3426. bool ibss_joined = false;
  3427. u32 sta_rate_set = 0;
  3428. int ret;
  3429. struct ieee80211_sta *sta;
  3430. bool sta_exists = false;
  3431. struct ieee80211_sta_ht_cap sta_ht_cap;
  3432. if (is_ibss) {
  3433. ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
  3434. changed);
  3435. if (ret < 0)
  3436. goto out;
  3437. }
  3438. if (changed & BSS_CHANGED_IBSS) {
  3439. if (bss_conf->ibss_joined) {
  3440. set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
  3441. ibss_joined = true;
  3442. } else {
  3443. if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
  3444. &wlvif->flags))
  3445. wl1271_unjoin(wl, wlvif);
  3446. }
  3447. }
  3448. if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
  3449. do_join = true;
  3450. /* Need to update the SSID (for filtering etc) */
  3451. if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
  3452. do_join = true;
  3453. if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
  3454. wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
  3455. bss_conf->enable_beacon ? "enabled" : "disabled");
  3456. do_join = true;
  3457. }
  3458. if (changed & BSS_CHANGED_IDLE && !is_ibss) {
  3459. ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
  3460. if (ret < 0)
  3461. wl1271_warning("idle mode change failed %d", ret);
  3462. }
  3463. if ((changed & BSS_CHANGED_CQM)) {
  3464. bool enable = false;
  3465. if (bss_conf->cqm_rssi_thold)
  3466. enable = true;
  3467. ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
  3468. bss_conf->cqm_rssi_thold,
  3469. bss_conf->cqm_rssi_hyst);
  3470. if (ret < 0)
  3471. goto out;
  3472. wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
  3473. }
  3474. if (changed & BSS_CHANGED_BSSID)
  3475. if (!is_zero_ether_addr(bss_conf->bssid)) {
  3476. ret = wl12xx_cmd_build_null_data(wl, wlvif);
  3477. if (ret < 0)
  3478. goto out;
  3479. ret = wl1271_build_qos_null_data(wl, vif);
  3480. if (ret < 0)
  3481. goto out;
  3482. /* Need to update the BSSID (for filtering etc) */
  3483. do_join = true;
  3484. }
  3485. if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
  3486. rcu_read_lock();
  3487. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  3488. if (!sta)
  3489. goto sta_not_found;
  3490. /* save the supp_rates of the ap */
  3491. sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
  3492. if (sta->ht_cap.ht_supported)
  3493. sta_rate_set |=
  3494. (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
  3495. sta_ht_cap = sta->ht_cap;
  3496. sta_exists = true;
  3497. sta_not_found:
  3498. rcu_read_unlock();
  3499. }
  3500. if ((changed & BSS_CHANGED_ASSOC)) {
  3501. if (bss_conf->assoc) {
  3502. u32 rates;
  3503. int ieoffset;
  3504. wlvif->aid = bss_conf->aid;
  3505. wlvif->beacon_int = bss_conf->beacon_int;
  3506. set_assoc = true;
  3507. /*
  3508. * use basic rates from AP, and determine lowest rate
  3509. * to use with control frames.
  3510. */
  3511. rates = bss_conf->basic_rates;
  3512. wlvif->basic_rate_set =
  3513. wl1271_tx_enabled_rates_get(wl, rates,
  3514. wlvif->band);
  3515. wlvif->basic_rate =
  3516. wl1271_tx_min_rate_get(wl,
  3517. wlvif->basic_rate_set);
  3518. if (sta_rate_set)
  3519. wlvif->rate_set =
  3520. wl1271_tx_enabled_rates_get(wl,
  3521. sta_rate_set,
  3522. wlvif->band);
  3523. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  3524. if (ret < 0)
  3525. goto out;
  3526. /*
  3527. * with wl1271, we don't need to update the
  3528. * beacon_int and dtim_period, because the firmware
  3529. * updates it by itself when the first beacon is
  3530. * received after a join.
  3531. */
  3532. ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
  3533. if (ret < 0)
  3534. goto out;
  3535. /*
  3536. * Get a template for hardware connection maintenance
  3537. */
  3538. dev_kfree_skb(wlvif->probereq);
  3539. wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
  3540. wlvif,
  3541. NULL);
  3542. ieoffset = offsetof(struct ieee80211_mgmt,
  3543. u.probe_req.variable);
  3544. wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
  3545. /* enable the connection monitoring feature */
  3546. wlvif->sta.first_bcn_loss = 0;
  3547. wlvif->sta.last_bcn_loss = 0;
  3548. ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
  3549. if (ret < 0)
  3550. goto out;
  3551. } else {
  3552. /* use defaults when not associated */
  3553. bool was_assoc =
  3554. !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
  3555. &wlvif->flags);
  3556. bool was_ifup =
  3557. !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
  3558. &wlvif->flags);
  3559. wlvif->aid = 0;
  3560. /* free probe-request template */
  3561. dev_kfree_skb(wlvif->probereq);
  3562. wlvif->probereq = NULL;
  3563. /* revert back to minimum rates for the current band */
  3564. wl1271_set_band_rate(wl, wlvif);
  3565. wlvif->basic_rate =
  3566. wl1271_tx_min_rate_get(wl,
  3567. wlvif->basic_rate_set);
  3568. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  3569. if (ret < 0)
  3570. goto out;
  3571. /* disable connection monitor features */
  3572. ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
  3573. /* Disable the keep-alive feature */
  3574. ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
  3575. if (ret < 0)
  3576. goto out;
  3577. /* restore the bssid filter and go to dummy bssid */
  3578. if (was_assoc) {
  3579. /*
  3580. * we might have to disable roc, if there was
  3581. * no IF_OPER_UP notification.
  3582. */
  3583. if (!was_ifup) {
  3584. ret = wl12xx_croc(wl, wlvif->role_id);
  3585. if (ret < 0)
  3586. goto out;
  3587. }
  3588. /*
  3589. * (we also need to disable roc in case of
  3590. * roaming on the same channel. until we will
  3591. * have a better flow...)
  3592. */
  3593. if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
  3594. ret = wl12xx_croc(wl,
  3595. wlvif->dev_role_id);
  3596. if (ret < 0)
  3597. goto out;
  3598. }
  3599. wl1271_unjoin(wl, wlvif);
  3600. if (!bss_conf->idle)
  3601. wl12xx_start_dev(wl, wlvif);
  3602. }
  3603. }
  3604. }
  3605. if (changed & BSS_CHANGED_IBSS) {
  3606. wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
  3607. bss_conf->ibss_joined);
  3608. if (bss_conf->ibss_joined) {
  3609. u32 rates = bss_conf->basic_rates;
  3610. wlvif->basic_rate_set =
  3611. wl1271_tx_enabled_rates_get(wl, rates,
  3612. wlvif->band);
  3613. wlvif->basic_rate =
  3614. wl1271_tx_min_rate_get(wl,
  3615. wlvif->basic_rate_set);
  3616. /* by default, use 11b + OFDM rates */
  3617. wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
  3618. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  3619. if (ret < 0)
  3620. goto out;
  3621. }
  3622. }
  3623. ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
  3624. if (ret < 0)
  3625. goto out;
  3626. if (do_join) {
  3627. ret = wl1271_join(wl, wlvif, set_assoc);
  3628. if (ret < 0) {
  3629. wl1271_warning("cmd join failed %d", ret);
  3630. goto out;
  3631. }
  3632. /* ROC until connected (after EAPOL exchange) */
  3633. if (!is_ibss) {
  3634. ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
  3635. if (ret < 0)
  3636. goto out;
  3637. wl1271_check_operstate(wl, wlvif,
  3638. ieee80211_get_operstate(vif));
  3639. }
  3640. /*
  3641. * stop device role if started (we might already be in
  3642. * STA/IBSS role).
  3643. */
  3644. if (wl12xx_dev_role_started(wlvif)) {
  3645. ret = wl12xx_stop_dev(wl, wlvif);
  3646. if (ret < 0)
  3647. goto out;
  3648. }
  3649. }
  3650. /* Handle new association with HT. Do this after join. */
  3651. if (sta_exists) {
  3652. if ((changed & BSS_CHANGED_HT) &&
  3653. (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
  3654. ret = wl1271_acx_set_ht_capabilities(wl,
  3655. &sta_ht_cap,
  3656. true,
  3657. wlvif->sta.hlid);
  3658. if (ret < 0) {
  3659. wl1271_warning("Set ht cap true failed %d",
  3660. ret);
  3661. goto out;
  3662. }
  3663. }
  3664. /* handle new association without HT and disassociation */
  3665. else if (changed & BSS_CHANGED_ASSOC) {
  3666. ret = wl1271_acx_set_ht_capabilities(wl,
  3667. &sta_ht_cap,
  3668. false,
  3669. wlvif->sta.hlid);
  3670. if (ret < 0) {
  3671. wl1271_warning("Set ht cap false failed %d",
  3672. ret);
  3673. goto out;
  3674. }
  3675. }
  3676. }
  3677. /* Handle HT information change. Done after join. */
  3678. if ((changed & BSS_CHANGED_HT) &&
  3679. (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
  3680. ret = wl1271_acx_set_ht_information(wl, wlvif,
  3681. bss_conf->ht_operation_mode);
  3682. if (ret < 0) {
  3683. wl1271_warning("Set ht information failed %d", ret);
  3684. goto out;
  3685. }
  3686. }
  3687. /* Handle arp filtering. Done after join. */
  3688. if ((changed & BSS_CHANGED_ARP_FILTER) ||
  3689. (!is_ibss && (changed & BSS_CHANGED_QOS))) {
  3690. __be32 addr = bss_conf->arp_addr_list[0];
  3691. wlvif->sta.qos = bss_conf->qos;
  3692. WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
  3693. if (bss_conf->arp_addr_cnt == 1 &&
  3694. bss_conf->arp_filter_enabled) {
  3695. wlvif->ip_addr = addr;
  3696. /*
  3697. * The template should have been configured only upon
  3698. * association. however, it seems that the correct ip
  3699. * isn't being set (when sending), so we have to
  3700. * reconfigure the template upon every ip change.
  3701. */
  3702. ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
  3703. if (ret < 0) {
  3704. wl1271_warning("build arp rsp failed: %d", ret);
  3705. goto out;
  3706. }
  3707. ret = wl1271_acx_arp_ip_filter(wl, wlvif,
  3708. (ACX_ARP_FILTER_ARP_FILTERING |
  3709. ACX_ARP_FILTER_AUTO_ARP),
  3710. addr);
  3711. } else {
  3712. wlvif->ip_addr = 0;
  3713. ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
  3714. }
  3715. if (ret < 0)
  3716. goto out;
  3717. }
  3718. out:
  3719. return;
  3720. }
  3721. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  3722. struct ieee80211_vif *vif,
  3723. struct ieee80211_bss_conf *bss_conf,
  3724. u32 changed)
  3725. {
  3726. struct wl1271 *wl = hw->priv;
  3727. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3728. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  3729. int ret;
  3730. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
  3731. (int)changed);
  3732. if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
  3733. !bss_conf->enable_beacon)
  3734. wl1271_tx_flush(wl);
  3735. mutex_lock(&wl->mutex);
  3736. if (unlikely(wl->state == WL1271_STATE_OFF))
  3737. goto out;
  3738. if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
  3739. goto out;
  3740. ret = wl1271_ps_elp_wakeup(wl);
  3741. if (ret < 0)
  3742. goto out;
  3743. if (is_ap)
  3744. wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
  3745. else
  3746. wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
  3747. wl1271_ps_elp_sleep(wl);
  3748. out:
  3749. mutex_unlock(&wl->mutex);
  3750. }
  3751. static void wl1271_op_get_current_rssi(struct ieee80211_hw *hw,
  3752. struct ieee80211_vif *vif,
  3753. struct station_info *sinfo)
  3754. {
  3755. struct wl1271 *wl = hw->priv;
  3756. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3757. int rssi = 0;
  3758. int ret;
  3759. wl1271_debug(DEBUG_MAC80211, "mac80211 get current rssi");
  3760. mutex_lock(&wl->mutex);
  3761. if (unlikely(wl->state == WL1271_STATE_OFF))
  3762. goto out;
  3763. if (wlvif->bss_type != BSS_TYPE_STA_BSS)
  3764. goto out;
  3765. ret = wl1271_ps_elp_wakeup(wl);
  3766. if (ret < 0)
  3767. goto out;
  3768. ret = wl12xx_acx_sta_get_rssi(wl, wlvif, &rssi);
  3769. if (ret < 0)
  3770. goto out_sleep;
  3771. sinfo->signal = (s8)rssi;
  3772. out_sleep:
  3773. wl1271_ps_elp_sleep(wl);
  3774. out:
  3775. mutex_unlock(&wl->mutex);
  3776. }
  3777. static int wl12xx_op_set_rx_filters(struct ieee80211_hw *hw,
  3778. struct cfg80211_wowlan *wowlan)
  3779. {
  3780. struct wl1271 *wl = hw->priv;
  3781. int ret = 0;
  3782. mutex_lock(&wl->mutex);
  3783. wl1271_debug(DEBUG_MAC80211, "mac80211 set rx filters");
  3784. if (unlikely(wl->state == WL1271_STATE_OFF))
  3785. goto out;
  3786. ret = wl1271_ps_elp_wakeup(wl);
  3787. if (ret < 0)
  3788. goto out;
  3789. ret = wl1271_configure_wowlan(wl, wowlan);
  3790. wl1271_ps_elp_sleep(wl);
  3791. out:
  3792. mutex_unlock(&wl->mutex);
  3793. return ret;
  3794. }
  3795. static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
  3796. struct ieee80211_vif *vif, u16 queue,
  3797. const struct ieee80211_tx_queue_params *params)
  3798. {
  3799. struct wl1271 *wl = hw->priv;
  3800. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3801. u8 ps_scheme;
  3802. int ret = 0;
  3803. mutex_lock(&wl->mutex);
  3804. wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
  3805. if (params->uapsd)
  3806. ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
  3807. else
  3808. ps_scheme = CONF_PS_SCHEME_LEGACY;
  3809. if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
  3810. goto out;
  3811. ret = wl1271_ps_elp_wakeup(wl);
  3812. if (ret < 0)
  3813. goto out;
  3814. /*
  3815. * the txop is confed in units of 32us by the mac80211,
  3816. * we need us
  3817. */
  3818. ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
  3819. params->cw_min, params->cw_max,
  3820. params->aifs, params->txop << 5);
  3821. if (ret < 0)
  3822. goto out_sleep;
  3823. ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
  3824. CONF_CHANNEL_TYPE_EDCF,
  3825. wl1271_tx_get_queue(queue),
  3826. ps_scheme, CONF_ACK_POLICY_LEGACY,
  3827. 0, 0);
  3828. out_sleep:
  3829. wl1271_ps_elp_sleep(wl);
  3830. out:
  3831. mutex_unlock(&wl->mutex);
  3832. return ret;
  3833. }
  3834. static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
  3835. struct ieee80211_vif *vif)
  3836. {
  3837. struct wl1271 *wl = hw->priv;
  3838. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3839. u64 mactime = ULLONG_MAX;
  3840. int ret;
  3841. wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
  3842. mutex_lock(&wl->mutex);
  3843. if (unlikely(wl->state == WL1271_STATE_OFF))
  3844. goto out;
  3845. ret = wl1271_ps_elp_wakeup(wl);
  3846. if (ret < 0)
  3847. goto out;
  3848. ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
  3849. if (ret < 0)
  3850. goto out_sleep;
  3851. out_sleep:
  3852. wl1271_ps_elp_sleep(wl);
  3853. out:
  3854. mutex_unlock(&wl->mutex);
  3855. return mactime;
  3856. }
  3857. static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
  3858. struct survey_info *survey)
  3859. {
  3860. struct wl1271 *wl = hw->priv;
  3861. struct ieee80211_conf *conf = &hw->conf;
  3862. if (idx != 0)
  3863. return -ENOENT;
  3864. survey->channel = conf->channel;
  3865. survey->filled = SURVEY_INFO_NOISE_DBM;
  3866. survey->noise = wl->noise;
  3867. return 0;
  3868. }
  3869. static int wl1271_allocate_sta(struct wl1271 *wl,
  3870. struct wl12xx_vif *wlvif,
  3871. struct ieee80211_sta *sta)
  3872. {
  3873. struct wl1271_station *wl_sta;
  3874. int ret;
  3875. if (wl->active_sta_count >= AP_MAX_STATIONS) {
  3876. wl1271_warning("could not allocate HLID - too much stations");
  3877. return -EBUSY;
  3878. }
  3879. wl_sta = (struct wl1271_station *)sta->drv_priv;
  3880. ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
  3881. if (ret < 0) {
  3882. wl1271_warning("could not allocate HLID - too many links");
  3883. return -EBUSY;
  3884. }
  3885. set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
  3886. memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
  3887. wl->active_sta_count++;
  3888. return 0;
  3889. }
  3890. void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
  3891. {
  3892. if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
  3893. return;
  3894. clear_bit(hlid, wlvif->ap.sta_hlid_map);
  3895. memset(wl->links[hlid].addr, 0, ETH_ALEN);
  3896. /* mac will send DELBA after recovery */
  3897. if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
  3898. wl->links[hlid].ba_bitmap = 0;
  3899. __clear_bit(hlid, &wl->ap_ps_map);
  3900. __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
  3901. wl12xx_free_link(wl, wlvif, &hlid);
  3902. wl->active_sta_count--;
  3903. }
  3904. void wl12xx_update_sta_state(struct wl1271 *wl,
  3905. struct ieee80211_sta *sta,
  3906. enum ieee80211_sta_state state)
  3907. {
  3908. struct wl1271_station *wl_sta;
  3909. u8 hlid;
  3910. int ret;
  3911. wl_sta = (struct wl1271_station *)sta->drv_priv;
  3912. hlid = wl_sta->hlid;
  3913. if (state == IEEE80211_STA_AUTHORIZED) {
  3914. ret = wl12xx_cmd_set_peer_state(wl, hlid);
  3915. if (ret < 0)
  3916. return;
  3917. ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
  3918. hlid);
  3919. if (ret < 0)
  3920. return;
  3921. }
  3922. }
  3923. int wl1271_op_sta_add_locked(struct ieee80211_hw *hw,
  3924. struct ieee80211_vif *vif,
  3925. struct ieee80211_sta *sta)
  3926. {
  3927. struct wl1271 *wl = hw->priv;
  3928. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3929. struct wl1271_station *wl_sta;
  3930. int ret = 0;
  3931. u8 hlid;
  3932. struct ap_peers *new_peer;
  3933. if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  3934. new_peer = kzalloc(sizeof(struct ap_peers), GFP_KERNEL);
  3935. memcpy(&new_peer->sta, sta, sizeof(struct ieee80211_sta));
  3936. new_peer->hw = hw;
  3937. new_peer->vif = vif;
  3938. list_add(&new_peer->list, &wl->peers_list);
  3939. wl1271_debug(DEBUG_AP, "add pending sta %pM to the list",
  3940. new_peer->sta.addr);
  3941. goto out;
  3942. }
  3943. ret = wl1271_allocate_sta(wl, wlvif, sta);
  3944. if (ret < 0)
  3945. goto out;
  3946. wl_sta = (struct wl1271_station *)sta->drv_priv;
  3947. hlid = wl_sta->hlid;
  3948. ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
  3949. if (ret < 0)
  3950. wl1271_free_sta(wl, wlvif, hlid);
  3951. out:
  3952. return ret;
  3953. }
  3954. static int wl1271_op_sta_add(struct ieee80211_hw *hw,
  3955. struct ieee80211_vif *vif,
  3956. struct ieee80211_sta *sta)
  3957. {
  3958. struct wl1271 *wl = hw->priv;
  3959. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3960. int ret = 0;
  3961. mutex_lock(&wl->mutex);
  3962. if (unlikely(wl->state == WL1271_STATE_OFF))
  3963. goto out;
  3964. if (wlvif->bss_type != BSS_TYPE_AP_BSS)
  3965. goto out;
  3966. wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
  3967. ret = wl1271_ps_elp_wakeup(wl);
  3968. if (ret < 0)
  3969. goto out;
  3970. ret = wl1271_op_sta_add_locked(hw, vif, sta);
  3971. wl1271_ps_elp_sleep(wl);
  3972. out:
  3973. mutex_unlock(&wl->mutex);
  3974. return ret;
  3975. }
  3976. static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
  3977. struct ieee80211_vif *vif,
  3978. struct ieee80211_sta *sta)
  3979. {
  3980. struct wl1271 *wl = hw->priv;
  3981. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  3982. struct wl1271_station *wl_sta;
  3983. int ret = 0, id;
  3984. mutex_lock(&wl->mutex);
  3985. if (!list_empty(&wl->peers_list) &&
  3986. !test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
  3987. struct ap_peers *peer, *next;
  3988. list_for_each_entry_safe(peer, next, &wl->peers_list, list) {
  3989. if (compare_ether_addr(sta->addr, peer->sta.addr))
  3990. continue;
  3991. wl1271_debug(DEBUG_AP, "remove pending sta %pM from the"
  3992. " list", peer->sta.addr);
  3993. list_del(&peer->list);
  3994. kfree(peer);
  3995. }
  3996. goto out;
  3997. }
  3998. if (unlikely(wl->state == WL1271_STATE_OFF))
  3999. goto out;
  4000. if (wlvif->bss_type != BSS_TYPE_AP_BSS)
  4001. goto out;
  4002. wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
  4003. wl_sta = (struct wl1271_station *)sta->drv_priv;
  4004. id = wl_sta->hlid;
  4005. if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
  4006. goto out;
  4007. ret = wl1271_ps_elp_wakeup(wl);
  4008. if (ret < 0)
  4009. goto out;
  4010. ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
  4011. if (ret < 0)
  4012. goto out_sleep;
  4013. wl1271_free_sta(wl, wlvif, wl_sta->hlid);
  4014. out_sleep:
  4015. wl1271_ps_elp_sleep(wl);
  4016. out:
  4017. mutex_unlock(&wl->mutex);
  4018. return ret;
  4019. }
  4020. void wl12xx_op_sta_state(struct ieee80211_hw *hw,
  4021. struct ieee80211_vif *vif,
  4022. struct ieee80211_sta *sta,
  4023. enum ieee80211_sta_state state)
  4024. {
  4025. struct wl1271 *wl = hw->priv;
  4026. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  4027. int ret;
  4028. if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
  4029. return;
  4030. wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d",
  4031. sta->aid, state);
  4032. mutex_lock(&wl->mutex);
  4033. if (unlikely(wl->state == WL1271_STATE_OFF))
  4034. goto out;
  4035. if (wlvif->bss_type != BSS_TYPE_AP_BSS)
  4036. goto out;
  4037. ret = wl1271_ps_elp_wakeup(wl);
  4038. if (ret < 0)
  4039. goto out;
  4040. wl12xx_update_sta_state(wl, sta, state);
  4041. wl1271_ps_elp_sleep(wl);
  4042. out:
  4043. mutex_unlock(&wl->mutex);
  4044. }
  4045. static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
  4046. struct ieee80211_vif *vif,
  4047. enum ieee80211_ampdu_mlme_action action,
  4048. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4049. u8 buf_size)
  4050. {
  4051. struct wl1271 *wl = hw->priv;
  4052. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  4053. int ret;
  4054. u8 hlid, *ba_bitmap;
  4055. wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
  4056. tid);
  4057. /* sanity check - the fields in FW are only 8bits wide */
  4058. if (WARN_ON(tid > 0xFF))
  4059. return -ENOTSUPP;
  4060. mutex_lock(&wl->mutex);
  4061. if (unlikely(wl->state == WL1271_STATE_OFF)) {
  4062. ret = -EAGAIN;
  4063. goto out;
  4064. }
  4065. if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
  4066. hlid = wlvif->sta.hlid;
  4067. ba_bitmap = &wlvif->sta.ba_rx_bitmap;
  4068. } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
  4069. struct wl1271_station *wl_sta;
  4070. wl_sta = (struct wl1271_station *)sta->drv_priv;
  4071. hlid = wl_sta->hlid;
  4072. ba_bitmap = &wl->links[hlid].ba_bitmap;
  4073. } else {
  4074. ret = -EINVAL;
  4075. goto out;
  4076. }
  4077. ret = wl1271_ps_elp_wakeup(wl);
  4078. if (ret < 0)
  4079. goto out;
  4080. wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
  4081. tid, action);
  4082. switch (action) {
  4083. case IEEE80211_AMPDU_RX_START:
  4084. if (!wlvif->ba_support || !wlvif->ba_allowed) {
  4085. ret = -ENOTSUPP;
  4086. break;
  4087. }
  4088. if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
  4089. ret = -EBUSY;
  4090. wl1271_error("exceeded max RX BA sessions");
  4091. break;
  4092. }
  4093. if (*ba_bitmap & BIT(tid)) {
  4094. ret = -EINVAL;
  4095. wl1271_error("cannot enable RX BA session on active "
  4096. "tid: %d", tid);
  4097. break;
  4098. }
  4099. ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
  4100. hlid);
  4101. if (!ret) {
  4102. *ba_bitmap |= BIT(tid);
  4103. wl->ba_rx_session_count++;
  4104. }
  4105. break;
  4106. case IEEE80211_AMPDU_RX_STOP:
  4107. if (!(*ba_bitmap & BIT(tid))) {
  4108. ret = -EINVAL;
  4109. wl1271_error("no active RX BA session on tid: %d",
  4110. tid);
  4111. break;
  4112. }
  4113. ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
  4114. hlid);
  4115. if (!ret) {
  4116. *ba_bitmap &= ~BIT(tid);
  4117. if (wl->ba_rx_session_count > 0)
  4118. wl->ba_rx_session_count--;
  4119. }
  4120. break;
  4121. /*
  4122. * The BA initiator session management in FW independently.
  4123. * Falling break here on purpose for all TX APDU commands.
  4124. */
  4125. case IEEE80211_AMPDU_TX_START:
  4126. case IEEE80211_AMPDU_TX_STOP:
  4127. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4128. ret = -EINVAL;
  4129. break;
  4130. default:
  4131. wl1271_error("Incorrect ampdu action id=%x\n", action);
  4132. ret = -EINVAL;
  4133. }
  4134. wl1271_ps_elp_sleep(wl);
  4135. out:
  4136. mutex_unlock(&wl->mutex);
  4137. return ret;
  4138. }
  4139. static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
  4140. struct ieee80211_vif *vif,
  4141. const struct cfg80211_bitrate_mask *mask)
  4142. {
  4143. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  4144. struct wl1271 *wl = hw->priv;
  4145. int i, ret = 0;
  4146. wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
  4147. mask->control[NL80211_BAND_2GHZ].legacy,
  4148. mask->control[NL80211_BAND_5GHZ].legacy);
  4149. mutex_lock(&wl->mutex);
  4150. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  4151. wlvif->bitrate_masks[i] =
  4152. wl1271_tx_enabled_rates_get(wl,
  4153. mask->control[i].legacy,
  4154. i);
  4155. if (unlikely(wl->state == WL1271_STATE_OFF))
  4156. goto out;
  4157. if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
  4158. !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
  4159. ret = wl1271_ps_elp_wakeup(wl);
  4160. if (ret < 0)
  4161. goto out;
  4162. wl1271_set_band_rate(wl, wlvif);
  4163. wlvif->basic_rate =
  4164. wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  4165. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  4166. wl1271_ps_elp_sleep(wl);
  4167. }
  4168. out:
  4169. mutex_unlock(&wl->mutex);
  4170. return ret;
  4171. }
  4172. static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
  4173. struct ieee80211_channel_switch *ch_switch)
  4174. {
  4175. struct wl1271 *wl = hw->priv;
  4176. struct wl12xx_vif *wlvif;
  4177. int ret;
  4178. wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
  4179. wl1271_tx_flush(wl);
  4180. mutex_lock(&wl->mutex);
  4181. if (unlikely(wl->state == WL1271_STATE_OFF)) {
  4182. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  4183. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  4184. ieee80211_chswitch_done(vif, false);
  4185. }
  4186. goto out;
  4187. }
  4188. ret = wl1271_ps_elp_wakeup(wl);
  4189. if (ret < 0)
  4190. goto out;
  4191. /* TODO: change mac80211 to pass vif as param */
  4192. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  4193. ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
  4194. if (!ret)
  4195. set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
  4196. }
  4197. wl1271_ps_elp_sleep(wl);
  4198. out:
  4199. mutex_unlock(&wl->mutex);
  4200. }
  4201. static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
  4202. {
  4203. struct wl1271 *wl = hw->priv;
  4204. bool ret = false;
  4205. mutex_lock(&wl->mutex);
  4206. if (unlikely(wl->state == WL1271_STATE_OFF))
  4207. goto out;
  4208. /* packets are considered pending if in the TX queue or the FW */
  4209. ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
  4210. out:
  4211. mutex_unlock(&wl->mutex);
  4212. return ret;
  4213. }
  4214. /* can't be const, mac80211 writes to this */
  4215. static struct ieee80211_rate wl1271_rates[] = {
  4216. { .bitrate = 10,
  4217. .hw_value = CONF_HW_BIT_RATE_1MBPS,
  4218. .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
  4219. { .bitrate = 20,
  4220. .hw_value = CONF_HW_BIT_RATE_2MBPS,
  4221. .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
  4222. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  4223. { .bitrate = 55,
  4224. .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
  4225. .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
  4226. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  4227. { .bitrate = 110,
  4228. .hw_value = CONF_HW_BIT_RATE_11MBPS,
  4229. .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
  4230. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  4231. { .bitrate = 60,
  4232. .hw_value = CONF_HW_BIT_RATE_6MBPS,
  4233. .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
  4234. { .bitrate = 90,
  4235. .hw_value = CONF_HW_BIT_RATE_9MBPS,
  4236. .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
  4237. { .bitrate = 120,
  4238. .hw_value = CONF_HW_BIT_RATE_12MBPS,
  4239. .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
  4240. { .bitrate = 180,
  4241. .hw_value = CONF_HW_BIT_RATE_18MBPS,
  4242. .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
  4243. { .bitrate = 240,
  4244. .hw_value = CONF_HW_BIT_RATE_24MBPS,
  4245. .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
  4246. { .bitrate = 360,
  4247. .hw_value = CONF_HW_BIT_RATE_36MBPS,
  4248. .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
  4249. { .bitrate = 480,
  4250. .hw_value = CONF_HW_BIT_RATE_48MBPS,
  4251. .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
  4252. { .bitrate = 540,
  4253. .hw_value = CONF_HW_BIT_RATE_54MBPS,
  4254. .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
  4255. };
  4256. /* can't be const, mac80211 writes to this */
  4257. static struct ieee80211_channel wl1271_channels[] = {
  4258. { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
  4259. { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
  4260. { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
  4261. { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
  4262. { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
  4263. { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
  4264. { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
  4265. { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
  4266. { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
  4267. { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
  4268. { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
  4269. { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
  4270. { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
  4271. { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
  4272. };
  4273. /* mapping to indexes for wl1271_rates */
  4274. static const u8 wl1271_rate_to_idx_2ghz[] = {
  4275. /* MCS rates are used only with 11n */
  4276. 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
  4277. 7, /* CONF_HW_RXTX_RATE_MCS7 */
  4278. 6, /* CONF_HW_RXTX_RATE_MCS6 */
  4279. 5, /* CONF_HW_RXTX_RATE_MCS5 */
  4280. 4, /* CONF_HW_RXTX_RATE_MCS4 */
  4281. 3, /* CONF_HW_RXTX_RATE_MCS3 */
  4282. 2, /* CONF_HW_RXTX_RATE_MCS2 */
  4283. 1, /* CONF_HW_RXTX_RATE_MCS1 */
  4284. 0, /* CONF_HW_RXTX_RATE_MCS0 */
  4285. 11, /* CONF_HW_RXTX_RATE_54 */
  4286. 10, /* CONF_HW_RXTX_RATE_48 */
  4287. 9, /* CONF_HW_RXTX_RATE_36 */
  4288. 8, /* CONF_HW_RXTX_RATE_24 */
  4289. /* TI-specific rate */
  4290. CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
  4291. 7, /* CONF_HW_RXTX_RATE_18 */
  4292. 6, /* CONF_HW_RXTX_RATE_12 */
  4293. 3, /* CONF_HW_RXTX_RATE_11 */
  4294. 5, /* CONF_HW_RXTX_RATE_9 */
  4295. 4, /* CONF_HW_RXTX_RATE_6 */
  4296. 2, /* CONF_HW_RXTX_RATE_5_5 */
  4297. 1, /* CONF_HW_RXTX_RATE_2 */
  4298. 0 /* CONF_HW_RXTX_RATE_1 */
  4299. };
  4300. /* 11n STA capabilities */
  4301. #define HW_RX_HIGHEST_RATE 72
  4302. #define WL12XX_HT_CAP { \
  4303. .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
  4304. (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
  4305. .ht_supported = true, \
  4306. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
  4307. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
  4308. .mcs = { \
  4309. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
  4310. .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
  4311. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
  4312. }, \
  4313. }
  4314. /* can't be const, mac80211 writes to this */
  4315. static struct ieee80211_supported_band wl1271_band_2ghz = {
  4316. .channels = wl1271_channels,
  4317. .n_channels = ARRAY_SIZE(wl1271_channels),
  4318. .bitrates = wl1271_rates,
  4319. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  4320. .ht_cap = WL12XX_HT_CAP,
  4321. };
  4322. /* 5 GHz data rates for WL1273 */
  4323. static struct ieee80211_rate wl1271_rates_5ghz[] = {
  4324. { .bitrate = 60,
  4325. .hw_value = CONF_HW_BIT_RATE_6MBPS,
  4326. .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
  4327. { .bitrate = 90,
  4328. .hw_value = CONF_HW_BIT_RATE_9MBPS,
  4329. .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
  4330. { .bitrate = 120,
  4331. .hw_value = CONF_HW_BIT_RATE_12MBPS,
  4332. .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
  4333. { .bitrate = 180,
  4334. .hw_value = CONF_HW_BIT_RATE_18MBPS,
  4335. .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
  4336. { .bitrate = 240,
  4337. .hw_value = CONF_HW_BIT_RATE_24MBPS,
  4338. .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
  4339. { .bitrate = 360,
  4340. .hw_value = CONF_HW_BIT_RATE_36MBPS,
  4341. .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
  4342. { .bitrate = 480,
  4343. .hw_value = CONF_HW_BIT_RATE_48MBPS,
  4344. .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
  4345. { .bitrate = 540,
  4346. .hw_value = CONF_HW_BIT_RATE_54MBPS,
  4347. .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
  4348. };
  4349. /* 5 GHz band channels for WL1273 */
  4350. static struct ieee80211_channel wl1271_channels_5ghz[] = {
  4351. { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
  4352. { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
  4353. { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
  4354. { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
  4355. { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
  4356. { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
  4357. { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
  4358. { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
  4359. { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
  4360. { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
  4361. { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
  4362. { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
  4363. { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
  4364. { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
  4365. { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
  4366. { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
  4367. { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
  4368. { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
  4369. { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
  4370. { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
  4371. { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
  4372. { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
  4373. { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
  4374. { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
  4375. { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
  4376. { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
  4377. { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
  4378. { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
  4379. { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
  4380. { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
  4381. { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
  4382. { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
  4383. { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
  4384. { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
  4385. };
  4386. /* mapping to indexes for wl1271_rates_5ghz */
  4387. static const u8 wl1271_rate_to_idx_5ghz[] = {
  4388. /* MCS rates are used only with 11n */
  4389. 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
  4390. 7, /* CONF_HW_RXTX_RATE_MCS7 */
  4391. 6, /* CONF_HW_RXTX_RATE_MCS6 */
  4392. 5, /* CONF_HW_RXTX_RATE_MCS5 */
  4393. 4, /* CONF_HW_RXTX_RATE_MCS4 */
  4394. 3, /* CONF_HW_RXTX_RATE_MCS3 */
  4395. 2, /* CONF_HW_RXTX_RATE_MCS2 */
  4396. 1, /* CONF_HW_RXTX_RATE_MCS1 */
  4397. 0, /* CONF_HW_RXTX_RATE_MCS0 */
  4398. 7, /* CONF_HW_RXTX_RATE_54 */
  4399. 6, /* CONF_HW_RXTX_RATE_48 */
  4400. 5, /* CONF_HW_RXTX_RATE_36 */
  4401. 4, /* CONF_HW_RXTX_RATE_24 */
  4402. /* TI-specific rate */
  4403. CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
  4404. 3, /* CONF_HW_RXTX_RATE_18 */
  4405. 2, /* CONF_HW_RXTX_RATE_12 */
  4406. CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
  4407. 1, /* CONF_HW_RXTX_RATE_9 */
  4408. 0, /* CONF_HW_RXTX_RATE_6 */
  4409. CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
  4410. CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
  4411. CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
  4412. };
  4413. static struct ieee80211_supported_band wl1271_band_5ghz = {
  4414. .channels = wl1271_channels_5ghz,
  4415. .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
  4416. .bitrates = wl1271_rates_5ghz,
  4417. .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
  4418. .ht_cap = WL12XX_HT_CAP,
  4419. };
  4420. static const u8 *wl1271_band_rate_to_idx[] = {
  4421. [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
  4422. [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
  4423. };
  4424. static const struct ieee80211_ops wl1271_ops = {
  4425. .start = wl1271_op_start,
  4426. .stop = wl1271_op_stop,
  4427. .add_interface = wl1271_op_add_interface,
  4428. .remove_interface = wl1271_op_remove_interface,
  4429. .change_interface = wl12xx_op_change_interface,
  4430. #ifdef CONFIG_PM
  4431. .suspend = wl1271_op_suspend,
  4432. .resume = wl1271_op_resume,
  4433. #endif
  4434. .config = wl1271_op_config,
  4435. .prepare_multicast = wl1271_op_prepare_multicast,
  4436. .configure_filter = wl1271_op_configure_filter,
  4437. .tx = wl1271_op_tx,
  4438. .set_key = wl1271_op_set_key,
  4439. .hw_scan = wl1271_op_hw_scan,
  4440. .cancel_hw_scan = wl1271_op_cancel_hw_scan,
  4441. .sched_scan_start = wl1271_op_sched_scan_start,
  4442. .sched_scan_stop = wl1271_op_sched_scan_stop,
  4443. .bss_info_changed = wl1271_op_bss_info_changed,
  4444. .set_frag_threshold = wl1271_op_set_frag_threshold,
  4445. .set_rts_threshold = wl1271_op_set_rts_threshold,
  4446. .conf_tx = wl1271_op_conf_tx,
  4447. .get_tsf = wl1271_op_get_tsf,
  4448. .get_survey = wl1271_op_get_survey,
  4449. .sta_add = wl1271_op_sta_add,
  4450. .sta_remove = wl1271_op_sta_remove,
  4451. .sta_state = wl12xx_op_sta_state,
  4452. .ampdu_action = wl1271_op_ampdu_action,
  4453. .tx_frames_pending = wl1271_tx_frames_pending,
  4454. .set_bitrate_mask = wl12xx_set_bitrate_mask,
  4455. .channel_switch = wl12xx_op_channel_switch,
  4456. .set_default_key_idx = wl1271_op_set_default_key_idx,
  4457. .get_current_rssi = wl1271_op_get_current_rssi,
  4458. .set_rx_filters = wl12xx_op_set_rx_filters,
  4459. CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
  4460. };
  4461. u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
  4462. {
  4463. u8 idx;
  4464. BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
  4465. if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
  4466. wl1271_error("Illegal RX rate from HW: %d", rate);
  4467. return 0;
  4468. }
  4469. idx = wl1271_band_rate_to_idx[band][rate];
  4470. if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
  4471. wl1271_error("Unsupported RX rate from HW: %d", rate);
  4472. return 0;
  4473. }
  4474. return idx;
  4475. }
  4476. static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
  4477. struct device_attribute *attr,
  4478. char *buf)
  4479. {
  4480. struct wl1271 *wl = dev_get_drvdata(dev);
  4481. ssize_t len;
  4482. len = PAGE_SIZE;
  4483. mutex_lock(&wl->mutex);
  4484. len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
  4485. wl->sg_enabled);
  4486. mutex_unlock(&wl->mutex);
  4487. return len;
  4488. }
  4489. static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
  4490. struct device_attribute *attr,
  4491. const char *buf, size_t count)
  4492. {
  4493. struct wl1271 *wl = dev_get_drvdata(dev);
  4494. unsigned long res;
  4495. int ret;
  4496. ret = kstrtoul(buf, 10, &res);
  4497. if (ret < 0) {
  4498. wl1271_warning("incorrect value written to bt_coex_mode");
  4499. return count;
  4500. }
  4501. mutex_lock(&wl->mutex);
  4502. res = !!res;
  4503. if (res == wl->sg_enabled)
  4504. goto out;
  4505. wl->sg_enabled = res;
  4506. if (wl->state == WL1271_STATE_OFF)
  4507. goto out;
  4508. ret = wl1271_ps_elp_wakeup(wl);
  4509. if (ret < 0)
  4510. goto out;
  4511. wl1271_acx_sg_enable(wl, wl->sg_enabled);
  4512. wl1271_ps_elp_sleep(wl);
  4513. out:
  4514. mutex_unlock(&wl->mutex);
  4515. return count;
  4516. }
  4517. static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
  4518. wl1271_sysfs_show_bt_coex_state,
  4519. wl1271_sysfs_store_bt_coex_state);
  4520. static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
  4521. struct device_attribute *attr,
  4522. char *buf)
  4523. {
  4524. struct wl1271 *wl = dev_get_drvdata(dev);
  4525. ssize_t len;
  4526. len = PAGE_SIZE;
  4527. mutex_lock(&wl->mutex);
  4528. if (wl->hw_pg_ver >= 0)
  4529. len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
  4530. else
  4531. len = snprintf(buf, len, "n/a\n");
  4532. mutex_unlock(&wl->mutex);
  4533. return len;
  4534. }
  4535. static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
  4536. wl1271_sysfs_show_hw_pg_ver, NULL);
  4537. static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
  4538. struct bin_attribute *bin_attr,
  4539. char *buffer, loff_t pos, size_t count)
  4540. {
  4541. struct device *dev = container_of(kobj, struct device, kobj);
  4542. struct wl1271 *wl = dev_get_drvdata(dev);
  4543. ssize_t len;
  4544. int ret;
  4545. ret = mutex_lock_interruptible(&wl->mutex);
  4546. if (ret < 0)
  4547. return -ERESTARTSYS;
  4548. /* Let only one thread read the log at a time, blocking others */
  4549. while (wl->fwlog_size == 0) {
  4550. DEFINE_WAIT(wait);
  4551. prepare_to_wait_exclusive(&wl->fwlog_waitq,
  4552. &wait,
  4553. TASK_INTERRUPTIBLE);
  4554. if (wl->fwlog_size != 0) {
  4555. finish_wait(&wl->fwlog_waitq, &wait);
  4556. break;
  4557. }
  4558. mutex_unlock(&wl->mutex);
  4559. schedule();
  4560. finish_wait(&wl->fwlog_waitq, &wait);
  4561. if (signal_pending(current))
  4562. return -ERESTARTSYS;
  4563. ret = mutex_lock_interruptible(&wl->mutex);
  4564. if (ret < 0)
  4565. return -ERESTARTSYS;
  4566. }
  4567. /* Check if the fwlog is still valid */
  4568. if (wl->fwlog_size < 0) {
  4569. mutex_unlock(&wl->mutex);
  4570. return 0;
  4571. }
  4572. /* Seeking is not supported - old logs are not kept. Disregard pos. */
  4573. len = min(count, (size_t)wl->fwlog_size);
  4574. wl->fwlog_size -= len;
  4575. memcpy(buffer, wl->fwlog, len);
  4576. /* Make room for new messages */
  4577. memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
  4578. mutex_unlock(&wl->mutex);
  4579. return len;
  4580. }
  4581. static struct bin_attribute fwlog_attr = {
  4582. .attr = {.name = "fwlog", .mode = S_IRUSR},
  4583. .read = wl1271_sysfs_read_fwlog,
  4584. };
  4585. static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
  4586. {
  4587. bool supported = false;
  4588. u8 major, minor;
  4589. if (wl->chip.id == CHIP_ID_1283_PG20) {
  4590. major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
  4591. minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
  4592. /* in wl128x we have the MAC address if the PG is >= (2, 1) */
  4593. if (major > 2 || (major == 2 && minor >= 1))
  4594. supported = true;
  4595. } else {
  4596. major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
  4597. minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
  4598. /* in wl127x we have the MAC address if the PG is >= (3, 1) */
  4599. if (major == 3 && minor >= 1)
  4600. supported = true;
  4601. }
  4602. wl1271_debug(DEBUG_PROBE,
  4603. "PG Ver major = %d minor = %d, MAC %s present",
  4604. major, minor, supported ? "is" : "is not");
  4605. return supported;
  4606. }
  4607. static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
  4608. u32 oui, u32 nic, int n)
  4609. {
  4610. int i;
  4611. wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
  4612. oui, nic, n);
  4613. if (nic + n - 1 > 0xffffff)
  4614. wl1271_warning("NIC part of the MAC address wraps around!");
  4615. for (i = 0; i < n; i++) {
  4616. wl->addresses[i].addr[0] = (u8)(oui >> 16);
  4617. wl->addresses[i].addr[1] = (u8)(oui >> 8);
  4618. wl->addresses[i].addr[2] = (u8) oui;
  4619. wl->addresses[i].addr[3] = (u8)(nic >> 16);
  4620. wl->addresses[i].addr[4] = (u8)(nic >> 8);
  4621. wl->addresses[i].addr[5] = (u8) nic;
  4622. nic++;
  4623. }
  4624. wl->hw->wiphy->n_addresses = n;
  4625. wl->hw->wiphy->addresses = wl->addresses;
  4626. }
  4627. static void wl12xx_get_fuse_mac(struct wl1271 *wl)
  4628. {
  4629. u32 mac1, mac2;
  4630. wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
  4631. mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
  4632. mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
  4633. /* these are the two parts of the BD_ADDR */
  4634. wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
  4635. ((mac1 & 0xff000000) >> 24);
  4636. wl->fuse_nic_addr = mac1 & 0xffffff;
  4637. wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
  4638. }
  4639. static int wl12xx_get_hw_info(struct wl1271 *wl)
  4640. {
  4641. int ret;
  4642. u32 die_info;
  4643. ret = wl12xx_set_power_on(wl);
  4644. if (ret < 0)
  4645. goto out;
  4646. wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
  4647. if (wl->chip.id == CHIP_ID_1283_PG20)
  4648. die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
  4649. else
  4650. die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
  4651. wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
  4652. if (!wl12xx_mac_in_fuse(wl)) {
  4653. wl->fuse_oui_addr = 0;
  4654. wl->fuse_nic_addr = 0;
  4655. } else {
  4656. wl12xx_get_fuse_mac(wl);
  4657. }
  4658. wl1271_power_off(wl);
  4659. out:
  4660. return ret;
  4661. }
  4662. static int wl1271_register_hw(struct wl1271 *wl)
  4663. {
  4664. int ret;
  4665. u32 oui_addr = 0, nic_addr = 0;
  4666. if (wl->mac80211_registered)
  4667. return 0;
  4668. ret = wl12xx_get_hw_info(wl);
  4669. if (ret < 0) {
  4670. wl1271_error("couldn't get hw info");
  4671. goto out;
  4672. }
  4673. ret = wl1271_fetch_nvs(wl);
  4674. if (ret == 0) {
  4675. /* NOTE: The wl->nvs->nvs element must be first, in
  4676. * order to simplify the casting, we assume it is at
  4677. * the beginning of the wl->nvs structure.
  4678. */
  4679. u8 *nvs_ptr = (u8 *)wl->nvs;
  4680. oui_addr =
  4681. (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
  4682. nic_addr =
  4683. (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
  4684. }
  4685. /* if the MAC address is zeroed in the NVS derive from fuse */
  4686. if (oui_addr == 0 && nic_addr == 0) {
  4687. oui_addr = wl->fuse_oui_addr;
  4688. /* fuse has the BD_ADDR, the WLAN addresses are the next two */
  4689. nic_addr = wl->fuse_nic_addr + 1;
  4690. }
  4691. wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
  4692. ret = ieee80211_register_hw(wl->hw);
  4693. if (ret < 0) {
  4694. wl1271_error("unable to register mac80211 hw: %d", ret);
  4695. goto out;
  4696. }
  4697. wl->mac80211_registered = true;
  4698. wl1271_debugfs_init(wl);
  4699. register_netdevice_notifier(&wl1271_dev_notifier);
  4700. wl1271_notice("loaded");
  4701. out:
  4702. return ret;
  4703. }
  4704. static void wl1271_unregister_hw(struct wl1271 *wl)
  4705. {
  4706. if (wl->state == WL1271_STATE_PLT)
  4707. wl1271_plt_stop(wl);
  4708. unregister_netdevice_notifier(&wl1271_dev_notifier);
  4709. ieee80211_unregister_hw(wl->hw);
  4710. wl->mac80211_registered = false;
  4711. }
  4712. static int wl1271_init_ieee80211(struct wl1271 *wl)
  4713. {
  4714. static const u32 cipher_suites[] = {
  4715. WLAN_CIPHER_SUITE_WEP40,
  4716. WLAN_CIPHER_SUITE_WEP104,
  4717. WLAN_CIPHER_SUITE_TKIP,
  4718. WLAN_CIPHER_SUITE_CCMP,
  4719. WL1271_CIPHER_SUITE_GEM,
  4720. };
  4721. /* The tx descriptor buffer and the TKIP space. */
  4722. wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
  4723. sizeof(struct wl1271_tx_hw_descr);
  4724. /* unit us */
  4725. /* FIXME: find a proper value */
  4726. wl->hw->channel_change_time = 10000;
  4727. wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
  4728. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4729. IEEE80211_HW_BEACON_FILTER |
  4730. IEEE80211_HW_SUPPORTS_PS |
  4731. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  4732. IEEE80211_HW_SUPPORTS_UAPSD |
  4733. IEEE80211_HW_HAS_RATE_CONTROL |
  4734. IEEE80211_HW_CONNECTION_MONITOR |
  4735. IEEE80211_HW_SUPPORTS_CQM_RSSI |
  4736. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  4737. IEEE80211_HW_SPECTRUM_MGMT |
  4738. IEEE80211_HW_AP_LINK_PS |
  4739. IEEE80211_HW_AMPDU_AGGREGATION |
  4740. IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
  4741. IEEE80211_HW_SCAN_WHILE_IDLE |
  4742. IEEE80211_HW_SUPPORTS_RX_FILTERS;
  4743. wl->hw->wiphy->cipher_suites = cipher_suites;
  4744. wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  4745. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  4746. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
  4747. BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
  4748. wl->hw->wiphy->features |= NL80211_FEATURE_SCHED_SCAN_INTERVALS;
  4749. wl->hw->wiphy->max_scan_ssids = 1;
  4750. wl->hw->wiphy->max_sched_scan_ssids = 16;
  4751. wl->hw->wiphy->max_match_sets = 16;
  4752. /*
  4753. * Maximum length of elements in scanning probe request templates
  4754. * should be the maximum length possible for a template, without
  4755. * the IEEE80211 header of the template
  4756. */
  4757. wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
  4758. sizeof(struct ieee80211_header);
  4759. wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
  4760. sizeof(struct ieee80211_header);
  4761. wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  4762. /* make sure all our channels fit in the scanned_ch bitmask */
  4763. BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
  4764. ARRAY_SIZE(wl1271_channels_5ghz) >
  4765. WL1271_MAX_CHANNELS);
  4766. /*
  4767. * We keep local copies of the band structs because we need to
  4768. * modify them on a per-device basis.
  4769. */
  4770. memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
  4771. sizeof(wl1271_band_2ghz));
  4772. memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
  4773. sizeof(wl1271_band_5ghz));
  4774. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4775. &wl->bands[IEEE80211_BAND_2GHZ];
  4776. wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4777. &wl->bands[IEEE80211_BAND_5GHZ];
  4778. wl->hw->queues = 4;
  4779. wl->hw->max_rates = 1;
  4780. wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
  4781. /* the FW answers probe-requests in AP-mode */
  4782. wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  4783. wl->hw->wiphy->probe_resp_offload =
  4784. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  4785. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  4786. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  4787. SET_IEEE80211_DEV(wl->hw, wl->dev);
  4788. wl->hw->sta_data_size = sizeof(struct wl1271_station);
  4789. wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
  4790. wl->hw->max_rx_aggregation_subframes = 8;
  4791. return 0;
  4792. }
  4793. #define WL1271_DEFAULT_CHANNEL 0
  4794. static struct ieee80211_hw *wl1271_alloc_hw(void)
  4795. {
  4796. struct ieee80211_hw *hw;
  4797. struct wl1271 *wl;
  4798. int i, j, ret;
  4799. unsigned int order;
  4800. BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
  4801. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  4802. if (!hw) {
  4803. wl1271_error("could not alloc ieee80211_hw");
  4804. ret = -ENOMEM;
  4805. goto err_hw_alloc;
  4806. }
  4807. wl = hw->priv;
  4808. memset(wl, 0, sizeof(*wl));
  4809. INIT_LIST_HEAD(&wl->list);
  4810. INIT_LIST_HEAD(&wl->wlvif_list);
  4811. INIT_LIST_HEAD(&wl->peers_list);
  4812. wl->hw = hw;
  4813. for (i = 0; i < NUM_TX_QUEUES; i++)
  4814. for (j = 0; j < WL12XX_MAX_LINKS; j++)
  4815. skb_queue_head_init(&wl->links[j].tx_queue[i]);
  4816. skb_queue_head_init(&wl->deferred_rx_queue);
  4817. skb_queue_head_init(&wl->deferred_tx_queue);
  4818. INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
  4819. INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
  4820. INIT_WORK(&wl->tx_work, wl1271_tx_work);
  4821. INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
  4822. INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
  4823. wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
  4824. if (!wl->freezable_wq) {
  4825. ret = -ENOMEM;
  4826. goto err_hw;
  4827. }
  4828. wl->channel = WL1271_DEFAULT_CHANNEL;
  4829. wl->rx_counter = 0;
  4830. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  4831. wl->band = IEEE80211_BAND_2GHZ;
  4832. wl->flags = 0;
  4833. wl->sg_enabled = true;
  4834. wl->hw_pg_ver = -1;
  4835. wl->ap_ps_map = 0;
  4836. wl->ap_fw_ps_map = 0;
  4837. wl->quirks = 0;
  4838. wl->platform_quirks = 0;
  4839. wl->sched_scanning = false;
  4840. wl->system_hlid = WL12XX_SYSTEM_HLID;
  4841. wl->active_sta_count = 0;
  4842. wl->fwlog_size = 0;
  4843. init_waitqueue_head(&wl->fwlog_waitq);
  4844. /* The system link is always allocated */
  4845. __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
  4846. memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
  4847. for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
  4848. wl->tx_frames[i] = NULL;
  4849. spin_lock_init(&wl->wl_lock);
  4850. #ifdef CONFIG_HAS_WAKELOCK
  4851. wake_lock_init(&wl->wake_lock, WAKE_LOCK_SUSPEND, "wl1271_wake");
  4852. wake_lock_init(&wl->rx_wake, WAKE_LOCK_SUSPEND, "rx_wake");
  4853. #endif
  4854. wl->state = WL1271_STATE_OFF;
  4855. wl->fw_type = WL12XX_FW_TYPE_NONE;
  4856. wl->saved_fw_type = WL12XX_FW_TYPE_NONE;
  4857. mutex_init(&wl->mutex);
  4858. /* Apply default driver configuration. */
  4859. wl1271_conf_init(wl);
  4860. order = get_order(WL1271_AGGR_BUFFER_SIZE);
  4861. wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
  4862. if (!wl->aggr_buf) {
  4863. ret = -ENOMEM;
  4864. goto err_wq;
  4865. }
  4866. wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
  4867. if (!wl->dummy_packet) {
  4868. ret = -ENOMEM;
  4869. goto err_aggr;
  4870. }
  4871. /* Allocate one page for the FW log */
  4872. wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
  4873. if (!wl->fwlog) {
  4874. ret = -ENOMEM;
  4875. goto err_dummy_packet;
  4876. }
  4877. return hw;
  4878. err_dummy_packet:
  4879. dev_kfree_skb(wl->dummy_packet);
  4880. err_aggr:
  4881. free_pages((unsigned long)wl->aggr_buf, order);
  4882. err_wq:
  4883. destroy_workqueue(wl->freezable_wq);
  4884. err_hw:
  4885. wl1271_debugfs_exit(wl);
  4886. ieee80211_free_hw(hw);
  4887. err_hw_alloc:
  4888. return ERR_PTR(ret);
  4889. }
  4890. static int wl1271_free_hw(struct wl1271 *wl)
  4891. {
  4892. #ifdef CONFIG_HAS_WAKELOCK
  4893. wake_lock_destroy(&wl->wake_lock);
  4894. wake_lock_destroy(&wl->rx_wake);
  4895. #endif
  4896. /* Unblock any fwlog readers */
  4897. mutex_lock(&wl->mutex);
  4898. wl->fwlog_size = -1;
  4899. wake_up_interruptible_all(&wl->fwlog_waitq);
  4900. mutex_unlock(&wl->mutex);
  4901. device_remove_bin_file(wl->dev, &fwlog_attr);
  4902. device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
  4903. device_remove_file(wl->dev, &dev_attr_bt_coex_state);
  4904. free_page((unsigned long)wl->fwlog);
  4905. dev_kfree_skb(wl->dummy_packet);
  4906. free_pages((unsigned long)wl->aggr_buf,
  4907. get_order(WL1271_AGGR_BUFFER_SIZE));
  4908. wl1271_debugfs_exit(wl);
  4909. vfree(wl->fw);
  4910. wl->fw = NULL;
  4911. wl->saved_fw_type = WL12XX_FW_TYPE_NONE;
  4912. kfree(wl->nvs);
  4913. wl->nvs = NULL;
  4914. kfree(wl->fw_status);
  4915. kfree(wl->tx_res_if);
  4916. destroy_workqueue(wl->freezable_wq);
  4917. ieee80211_free_hw(wl->hw);
  4918. return 0;
  4919. }
  4920. static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
  4921. {
  4922. struct wl1271 *wl = cookie;
  4923. unsigned long flags;
  4924. wl1271_debug(DEBUG_IRQ, "IRQ");
  4925. /* complete the ELP completion */
  4926. spin_lock_irqsave(&wl->wl_lock, flags);
  4927. set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
  4928. if (wl->elp_compl) {
  4929. complete(wl->elp_compl);
  4930. wl->elp_compl = NULL;
  4931. }
  4932. if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
  4933. /* don't enqueue a work right now. mark it as pending */
  4934. set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
  4935. wl1271_debug(DEBUG_IRQ, "should not enqueue work");
  4936. disable_irq_nosync(wl->irq);
  4937. pm_wakeup_event(wl->dev, 0);
  4938. #ifdef CONFIG_HAS_WAKELOCK
  4939. if (!test_and_set_bit(WL1271_FLAG_WAKE_LOCK, &wl->flags))
  4940. wake_lock(&wl->wake_lock);
  4941. #endif
  4942. spin_unlock_irqrestore(&wl->wl_lock, flags);
  4943. return IRQ_HANDLED;
  4944. }
  4945. #ifdef CONFIG_HAS_WAKELOCK
  4946. if (!test_and_set_bit(WL1271_FLAG_WAKE_LOCK, &wl->flags))
  4947. wake_lock(&wl->wake_lock);
  4948. #endif
  4949. spin_unlock_irqrestore(&wl->wl_lock, flags);
  4950. return IRQ_WAKE_THREAD;
  4951. }
  4952. static int __devinit wl12xx_probe(struct platform_device *pdev)
  4953. {
  4954. struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
  4955. struct ieee80211_hw *hw;
  4956. struct wl1271 *wl;
  4957. unsigned long irqflags;
  4958. int ret = -ENODEV;
  4959. hw = wl1271_alloc_hw();
  4960. if (IS_ERR(hw)) {
  4961. wl1271_error("can't allocate hw");
  4962. ret = PTR_ERR(hw);
  4963. goto out;
  4964. }
  4965. wl = hw->priv;
  4966. wl->irq = platform_get_irq(pdev, 0);
  4967. if (wl->ref_clock < 0)
  4968. wl->ref_clock = pdata->board_ref_clock;
  4969. if (wl->tcxo_clock < 0)
  4970. wl->tcxo_clock = pdata->board_tcxo_clock;
  4971. wl->platform_quirks = pdata->platform_quirks;
  4972. wl->set_power = pdata->set_power;
  4973. wl->dev = &pdev->dev;
  4974. wl->if_ops = pdata->ops;
  4975. platform_set_drvdata(pdev, wl);
  4976. if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
  4977. irqflags = IRQF_TRIGGER_RISING;
  4978. else
  4979. irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
  4980. ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
  4981. irqflags,
  4982. pdev->name, wl);
  4983. if (ret < 0) {
  4984. wl1271_error("request_irq() failed: %d", ret);
  4985. goto out_free_hw;
  4986. }
  4987. ret = enable_irq_wake(wl->irq);
  4988. if (!ret) {
  4989. wl->irq_wake_enabled = true;
  4990. device_init_wakeup(wl->dev, 1);
  4991. if (pdata->pwr_in_suspend) {
  4992. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
  4993. hw->wiphy->wowlan.n_patterns = WL1271_MAX_RX_FILTERS;
  4994. hw->wiphy->wowlan.pattern_min_len = 1;
  4995. hw->wiphy->wowlan.pattern_max_len =
  4996. WL1271_RX_FILTER_MAX_PATTERN_SIZE;
  4997. }
  4998. }
  4999. disable_irq(wl->irq);
  5000. ret = wl1271_init_ieee80211(wl);
  5001. if (ret)
  5002. goto out_irq;
  5003. ret = wl1271_register_hw(wl);
  5004. if (ret)
  5005. goto out_irq;
  5006. /* Create sysfs file to control bt coex state */
  5007. ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
  5008. if (ret < 0) {
  5009. wl1271_error("failed to create sysfs file bt_coex_state");
  5010. goto out_irq;
  5011. }
  5012. /* Create sysfs file to get HW PG version */
  5013. ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
  5014. if (ret < 0) {
  5015. wl1271_error("failed to create sysfs file hw_pg_ver");
  5016. goto out_bt_coex_state;
  5017. }
  5018. /* Create sysfs file for the FW log */
  5019. ret = device_create_bin_file(wl->dev, &fwlog_attr);
  5020. if (ret < 0) {
  5021. wl1271_error("failed to create sysfs file fwlog");
  5022. goto out_hw_pg_ver;
  5023. }
  5024. return 0;
  5025. out_hw_pg_ver:
  5026. device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
  5027. out_bt_coex_state:
  5028. device_remove_file(wl->dev, &dev_attr_bt_coex_state);
  5029. out_irq:
  5030. free_irq(wl->irq, wl);
  5031. out_free_hw:
  5032. wl1271_free_hw(wl);
  5033. out:
  5034. return ret;
  5035. }
  5036. static int __devexit wl12xx_remove(struct platform_device *pdev)
  5037. {
  5038. struct wl1271 *wl = platform_get_drvdata(pdev);
  5039. if (wl->irq_wake_enabled) {
  5040. device_init_wakeup(wl->dev, 0);
  5041. disable_irq_wake(wl->irq);
  5042. }
  5043. wl1271_unregister_hw(wl);
  5044. free_irq(wl->irq, wl);
  5045. wl1271_free_hw(wl);
  5046. return 0;
  5047. }
  5048. static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
  5049. { "wl12xx", 0 },
  5050. { } /* Terminating Entry */
  5051. };
  5052. MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
  5053. static struct platform_driver wl12xx_driver = {
  5054. .probe = wl12xx_probe,
  5055. .remove = __devexit_p(wl12xx_remove),
  5056. .id_table = wl12xx_id_table,
  5057. .driver = {
  5058. .name = "wl12xx_driver",
  5059. .owner = THIS_MODULE,
  5060. }
  5061. };
  5062. static int __init wl12xx_init(void)
  5063. {
  5064. wl1271_info("driver version: %s", wl12xx_git_head);
  5065. wl1271_info("compilation time: %s", wl12xx_timestamp);
  5066. return platform_driver_register(&wl12xx_driver);
  5067. }
  5068. module_init(wl12xx_init);
  5069. static void __exit wl12xx_exit(void)
  5070. {
  5071. platform_driver_unregister(&wl12xx_driver);
  5072. }
  5073. module_exit(wl12xx_exit);
  5074. u32 wl12xx_debug_level = DEBUG_NONE;
  5075. EXPORT_SYMBOL_GPL(wl12xx_debug_level);
  5076. module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
  5077. MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
  5078. module_param_named(fwlog, fwlog_param, charp, 0);
  5079. MODULE_PARM_DESC(keymap,
  5080. "FW logger options: continuous, ondemand, dbgpins or disable");
  5081. module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
  5082. MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
  5083. module_param_named(fref, fref_param, charp, 0);
  5084. MODULE_PARM_DESC(fref, "FREF clock: 19.2, 26, 26x, 38.4, 38.4x, 52");
  5085. module_param_named(tcxo, tcxo_param, charp, 0);
  5086. MODULE_PARM_DESC(tcxo,
  5087. "TCXO clock: 19.2, 26, 38.4, 52, 16.368, 32.736, 16.8, 33.6");
  5088. MODULE_LICENSE("GPL");
  5089. MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
  5090. MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");