wl1251_main.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Kalle Valo <kalle.valo@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/interrupt.h>
  25. #include <linux/firmware.h>
  26. #include <linux/delay.h>
  27. #include <linux/irq.h>
  28. #include <linux/crc32.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/vmalloc.h>
  31. #include <linux/slab.h>
  32. #include "wl1251.h"
  33. #include "wl12xx_80211.h"
  34. #include "wl1251_reg.h"
  35. #include "wl1251_io.h"
  36. #include "wl1251_cmd.h"
  37. #include "wl1251_event.h"
  38. #include "wl1251_tx.h"
  39. #include "wl1251_rx.h"
  40. #include "wl1251_ps.h"
  41. #include "wl1251_init.h"
  42. #include "wl1251_debugfs.h"
  43. #include "wl1251_boot.h"
  44. void wl1251_enable_interrupts(struct wl1251 *wl)
  45. {
  46. wl->if_ops->enable_irq(wl);
  47. }
  48. void wl1251_disable_interrupts(struct wl1251 *wl)
  49. {
  50. wl->if_ops->disable_irq(wl);
  51. }
  52. static void wl1251_power_off(struct wl1251 *wl)
  53. {
  54. wl->set_power(false);
  55. }
  56. static void wl1251_power_on(struct wl1251 *wl)
  57. {
  58. wl->set_power(true);
  59. }
  60. static int wl1251_fetch_firmware(struct wl1251 *wl)
  61. {
  62. const struct firmware *fw;
  63. struct device *dev = wiphy_dev(wl->hw->wiphy);
  64. int ret;
  65. ret = request_firmware(&fw, WL1251_FW_NAME, dev);
  66. if (ret < 0) {
  67. wl1251_error("could not get firmware: %d", ret);
  68. return ret;
  69. }
  70. if (fw->size % 4) {
  71. wl1251_error("firmware size is not multiple of 32 bits: %zu",
  72. fw->size);
  73. ret = -EILSEQ;
  74. goto out;
  75. }
  76. wl->fw_len = fw->size;
  77. wl->fw = vmalloc(wl->fw_len);
  78. if (!wl->fw) {
  79. wl1251_error("could not allocate memory for the firmware");
  80. ret = -ENOMEM;
  81. goto out;
  82. }
  83. memcpy(wl->fw, fw->data, wl->fw_len);
  84. ret = 0;
  85. out:
  86. release_firmware(fw);
  87. return ret;
  88. }
  89. static int wl1251_fetch_nvs(struct wl1251 *wl)
  90. {
  91. const struct firmware *fw;
  92. struct device *dev = wiphy_dev(wl->hw->wiphy);
  93. int ret;
  94. ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
  95. if (ret < 0) {
  96. wl1251_error("could not get nvs file: %d", ret);
  97. return ret;
  98. }
  99. if (fw->size % 4) {
  100. wl1251_error("nvs size is not multiple of 32 bits: %zu",
  101. fw->size);
  102. ret = -EILSEQ;
  103. goto out;
  104. }
  105. wl->nvs_len = fw->size;
  106. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  107. if (!wl->nvs) {
  108. wl1251_error("could not allocate memory for the nvs file");
  109. ret = -ENOMEM;
  110. goto out;
  111. }
  112. memcpy(wl->nvs, fw->data, wl->nvs_len);
  113. ret = 0;
  114. out:
  115. release_firmware(fw);
  116. return ret;
  117. }
  118. static void wl1251_fw_wakeup(struct wl1251 *wl)
  119. {
  120. u32 elp_reg;
  121. elp_reg = ELPCTRL_WAKE_UP;
  122. wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  123. elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
  124. if (!(elp_reg & ELPCTRL_WLAN_READY))
  125. wl1251_warning("WLAN not ready");
  126. }
  127. static int wl1251_chip_wakeup(struct wl1251 *wl)
  128. {
  129. int ret = 0;
  130. wl1251_power_on(wl);
  131. msleep(WL1251_POWER_ON_SLEEP);
  132. wl->if_ops->reset(wl);
  133. /* We don't need a real memory partition here, because we only want
  134. * to use the registers at this point. */
  135. wl1251_set_partition(wl,
  136. 0x00000000,
  137. 0x00000000,
  138. REGISTERS_BASE,
  139. REGISTERS_DOWN_SIZE);
  140. /* ELP module wake up */
  141. wl1251_fw_wakeup(wl);
  142. /* whal_FwCtrl_BootSm() */
  143. /* 0. read chip id from CHIP_ID */
  144. wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
  145. /* 1. check if chip id is valid */
  146. switch (wl->chip_id) {
  147. case CHIP_ID_1251_PG12:
  148. wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
  149. wl->chip_id);
  150. break;
  151. case CHIP_ID_1251_PG11:
  152. wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
  153. wl->chip_id);
  154. break;
  155. case CHIP_ID_1251_PG10:
  156. default:
  157. wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
  158. ret = -ENODEV;
  159. goto out;
  160. }
  161. if (wl->fw == NULL) {
  162. ret = wl1251_fetch_firmware(wl);
  163. if (ret < 0)
  164. goto out;
  165. }
  166. /* No NVS from netlink, try to get it from the filesystem */
  167. if (wl->nvs == NULL) {
  168. ret = wl1251_fetch_nvs(wl);
  169. if (ret < 0)
  170. goto out;
  171. }
  172. out:
  173. return ret;
  174. }
  175. #define WL1251_IRQ_LOOP_COUNT 10
  176. static void wl1251_irq_work(struct work_struct *work)
  177. {
  178. u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
  179. struct wl1251 *wl =
  180. container_of(work, struct wl1251, irq_work);
  181. int ret;
  182. mutex_lock(&wl->mutex);
  183. wl1251_debug(DEBUG_IRQ, "IRQ work");
  184. if (wl->state == WL1251_STATE_OFF)
  185. goto out;
  186. ret = wl1251_ps_elp_wakeup(wl);
  187. if (ret < 0)
  188. goto out;
  189. wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
  190. intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  191. wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
  192. do {
  193. if (wl->data_path) {
  194. wl->rx_counter = wl1251_mem_read32(
  195. wl, wl->data_path->rx_control_addr);
  196. /* We handle a frmware bug here */
  197. switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
  198. case 0:
  199. wl1251_debug(DEBUG_IRQ,
  200. "RX: FW and host in sync");
  201. intr &= ~WL1251_ACX_INTR_RX0_DATA;
  202. intr &= ~WL1251_ACX_INTR_RX1_DATA;
  203. break;
  204. case 1:
  205. wl1251_debug(DEBUG_IRQ, "RX: FW +1");
  206. intr |= WL1251_ACX_INTR_RX0_DATA;
  207. intr &= ~WL1251_ACX_INTR_RX1_DATA;
  208. break;
  209. case 2:
  210. wl1251_debug(DEBUG_IRQ, "RX: FW +2");
  211. intr |= WL1251_ACX_INTR_RX0_DATA;
  212. intr |= WL1251_ACX_INTR_RX1_DATA;
  213. break;
  214. default:
  215. wl1251_warning(
  216. "RX: FW and host out of sync: %d",
  217. wl->rx_counter - wl->rx_handled);
  218. break;
  219. }
  220. wl->rx_handled = wl->rx_counter;
  221. wl1251_debug(DEBUG_IRQ, "RX counter: %d",
  222. wl->rx_counter);
  223. }
  224. intr &= wl->intr_mask;
  225. if (intr == 0) {
  226. wl1251_debug(DEBUG_IRQ, "INTR is 0");
  227. goto out_sleep;
  228. }
  229. if (intr & WL1251_ACX_INTR_RX0_DATA) {
  230. wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
  231. wl1251_rx(wl);
  232. }
  233. if (intr & WL1251_ACX_INTR_RX1_DATA) {
  234. wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
  235. wl1251_rx(wl);
  236. }
  237. if (intr & WL1251_ACX_INTR_TX_RESULT) {
  238. wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
  239. wl1251_tx_complete(wl);
  240. }
  241. if (intr & (WL1251_ACX_INTR_EVENT_A |
  242. WL1251_ACX_INTR_EVENT_B)) {
  243. wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)",
  244. intr);
  245. if (intr & WL1251_ACX_INTR_EVENT_A)
  246. wl1251_event_handle(wl, 0);
  247. else
  248. wl1251_event_handle(wl, 1);
  249. }
  250. if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
  251. wl1251_debug(DEBUG_IRQ,
  252. "WL1251_ACX_INTR_INIT_COMPLETE");
  253. if (--ctr == 0)
  254. break;
  255. intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  256. } while (intr);
  257. out_sleep:
  258. wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
  259. wl1251_ps_elp_sleep(wl);
  260. out:
  261. mutex_unlock(&wl->mutex);
  262. }
  263. static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
  264. u16 beacon_interval, u8 dtim_period)
  265. {
  266. int ret;
  267. ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
  268. DEFAULT_HW_GEN_MODULATION_TYPE,
  269. wl->tx_mgmt_frm_rate,
  270. wl->tx_mgmt_frm_mod);
  271. if (ret < 0)
  272. goto out;
  273. ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
  274. dtim_period);
  275. if (ret < 0)
  276. goto out;
  277. /*
  278. * FIXME: we should wait for JOIN_EVENT_COMPLETE_ID but to simplify
  279. * locking we just sleep instead, for now
  280. */
  281. msleep(10);
  282. out:
  283. return ret;
  284. }
  285. static void wl1251_filter_work(struct work_struct *work)
  286. {
  287. struct wl1251 *wl =
  288. container_of(work, struct wl1251, filter_work);
  289. int ret;
  290. mutex_lock(&wl->mutex);
  291. if (wl->state == WL1251_STATE_OFF)
  292. goto out;
  293. ret = wl1251_ps_elp_wakeup(wl);
  294. if (ret < 0)
  295. goto out;
  296. ret = wl1251_join(wl, wl->bss_type, wl->channel, wl->beacon_int,
  297. wl->dtim_period);
  298. if (ret < 0)
  299. goto out_sleep;
  300. out_sleep:
  301. wl1251_ps_elp_sleep(wl);
  302. out:
  303. mutex_unlock(&wl->mutex);
  304. }
  305. static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  306. {
  307. struct wl1251 *wl = hw->priv;
  308. skb_queue_tail(&wl->tx_queue, skb);
  309. /*
  310. * The chip specific setup must run before the first TX packet -
  311. * before that, the tx_work will not be initialized!
  312. */
  313. ieee80211_queue_work(wl->hw, &wl->tx_work);
  314. /*
  315. * The workqueue is slow to process the tx_queue and we need stop
  316. * the queue here, otherwise the queue will get too long.
  317. */
  318. if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
  319. wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
  320. ieee80211_stop_queues(wl->hw);
  321. /*
  322. * FIXME: this is racy, the variable is not properly
  323. * protected. Maybe fix this by removing the stupid
  324. * variable altogether and checking the real queue state?
  325. */
  326. wl->tx_queue_stopped = true;
  327. }
  328. return NETDEV_TX_OK;
  329. }
  330. static int wl1251_op_start(struct ieee80211_hw *hw)
  331. {
  332. struct wl1251 *wl = hw->priv;
  333. int ret = 0;
  334. wl1251_debug(DEBUG_MAC80211, "mac80211 start");
  335. mutex_lock(&wl->mutex);
  336. if (wl->state != WL1251_STATE_OFF) {
  337. wl1251_error("cannot start because not in off state: %d",
  338. wl->state);
  339. ret = -EBUSY;
  340. goto out;
  341. }
  342. ret = wl1251_chip_wakeup(wl);
  343. if (ret < 0)
  344. goto out;
  345. ret = wl1251_boot(wl);
  346. if (ret < 0)
  347. goto out;
  348. ret = wl1251_hw_init(wl);
  349. if (ret < 0)
  350. goto out;
  351. ret = wl1251_acx_station_id(wl);
  352. if (ret < 0)
  353. goto out;
  354. wl->state = WL1251_STATE_ON;
  355. wl1251_info("firmware booted (%s)", wl->fw_ver);
  356. out:
  357. if (ret < 0)
  358. wl1251_power_off(wl);
  359. mutex_unlock(&wl->mutex);
  360. return ret;
  361. }
  362. static void wl1251_op_stop(struct ieee80211_hw *hw)
  363. {
  364. struct wl1251 *wl = hw->priv;
  365. wl1251_info("down");
  366. wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
  367. mutex_lock(&wl->mutex);
  368. WARN_ON(wl->state != WL1251_STATE_ON);
  369. if (wl->scanning) {
  370. mutex_unlock(&wl->mutex);
  371. ieee80211_scan_completed(wl->hw, true);
  372. mutex_lock(&wl->mutex);
  373. wl->scanning = false;
  374. }
  375. wl->state = WL1251_STATE_OFF;
  376. wl1251_disable_interrupts(wl);
  377. mutex_unlock(&wl->mutex);
  378. cancel_work_sync(&wl->irq_work);
  379. cancel_work_sync(&wl->tx_work);
  380. cancel_work_sync(&wl->filter_work);
  381. mutex_lock(&wl->mutex);
  382. /* let's notify MAC80211 about the remaining pending TX frames */
  383. wl1251_tx_flush(wl);
  384. wl1251_power_off(wl);
  385. memset(wl->bssid, 0, ETH_ALEN);
  386. wl->listen_int = 1;
  387. wl->bss_type = MAX_BSS_TYPE;
  388. wl->data_in_count = 0;
  389. wl->rx_counter = 0;
  390. wl->rx_handled = 0;
  391. wl->rx_current_buffer = 0;
  392. wl->rx_last_id = 0;
  393. wl->next_tx_complete = 0;
  394. wl->elp = false;
  395. wl->psm = 0;
  396. wl->tx_queue_stopped = false;
  397. wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
  398. wl->channel = WL1251_DEFAULT_CHANNEL;
  399. wl1251_debugfs_reset(wl);
  400. mutex_unlock(&wl->mutex);
  401. }
  402. static int wl1251_op_add_interface(struct ieee80211_hw *hw,
  403. struct ieee80211_vif *vif)
  404. {
  405. struct wl1251 *wl = hw->priv;
  406. int ret = 0;
  407. wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  408. vif->type, vif->addr);
  409. mutex_lock(&wl->mutex);
  410. if (wl->vif) {
  411. ret = -EBUSY;
  412. goto out;
  413. }
  414. wl->vif = vif;
  415. switch (vif->type) {
  416. case NL80211_IFTYPE_STATION:
  417. wl->bss_type = BSS_TYPE_STA_BSS;
  418. break;
  419. case NL80211_IFTYPE_ADHOC:
  420. wl->bss_type = BSS_TYPE_IBSS;
  421. break;
  422. default:
  423. ret = -EOPNOTSUPP;
  424. goto out;
  425. }
  426. if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
  427. memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
  428. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  429. ret = wl1251_acx_station_id(wl);
  430. if (ret < 0)
  431. goto out;
  432. }
  433. out:
  434. mutex_unlock(&wl->mutex);
  435. return ret;
  436. }
  437. static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
  438. struct ieee80211_vif *vif)
  439. {
  440. struct wl1251 *wl = hw->priv;
  441. mutex_lock(&wl->mutex);
  442. wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
  443. wl->vif = NULL;
  444. mutex_unlock(&wl->mutex);
  445. }
  446. static int wl1251_build_qos_null_data(struct wl1251 *wl)
  447. {
  448. struct ieee80211_qos_hdr template;
  449. memset(&template, 0, sizeof(template));
  450. memcpy(template.addr1, wl->bssid, ETH_ALEN);
  451. memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
  452. memcpy(template.addr3, wl->bssid, ETH_ALEN);
  453. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  454. IEEE80211_STYPE_QOS_NULLFUNC |
  455. IEEE80211_FCTL_TODS);
  456. /* FIXME: not sure what priority to use here */
  457. template.qos_ctrl = cpu_to_le16(0);
  458. return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
  459. sizeof(template));
  460. }
  461. static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
  462. {
  463. struct wl1251 *wl = hw->priv;
  464. struct ieee80211_conf *conf = &hw->conf;
  465. int channel, ret = 0;
  466. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  467. wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
  468. channel,
  469. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  470. conf->power_level);
  471. mutex_lock(&wl->mutex);
  472. ret = wl1251_ps_elp_wakeup(wl);
  473. if (ret < 0)
  474. goto out;
  475. if (channel != wl->channel) {
  476. wl->channel = channel;
  477. ret = wl1251_join(wl, wl->bss_type, wl->channel,
  478. wl->beacon_int, wl->dtim_period);
  479. if (ret < 0)
  480. goto out_sleep;
  481. }
  482. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  483. wl1251_debug(DEBUG_PSM, "psm enabled");
  484. wl->psm_requested = true;
  485. wl->dtim_period = conf->ps_dtim_period;
  486. ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
  487. wl->dtim_period);
  488. /*
  489. * mac80211 enables PSM only if we're already associated.
  490. */
  491. ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  492. if (ret < 0)
  493. goto out_sleep;
  494. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  495. wl->psm_requested) {
  496. wl1251_debug(DEBUG_PSM, "psm disabled");
  497. wl->psm_requested = false;
  498. if (wl->psm) {
  499. ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
  500. if (ret < 0)
  501. goto out_sleep;
  502. }
  503. }
  504. if (conf->power_level != wl->power_level) {
  505. ret = wl1251_acx_tx_power(wl, conf->power_level);
  506. if (ret < 0)
  507. goto out_sleep;
  508. wl->power_level = conf->power_level;
  509. }
  510. out_sleep:
  511. wl1251_ps_elp_sleep(wl);
  512. out:
  513. mutex_unlock(&wl->mutex);
  514. return ret;
  515. }
  516. #define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  517. FIF_ALLMULTI | \
  518. FIF_FCSFAIL | \
  519. FIF_BCN_PRBRESP_PROMISC | \
  520. FIF_CONTROL | \
  521. FIF_OTHER_BSS)
  522. static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
  523. unsigned int changed,
  524. unsigned int *total,u64 multicast)
  525. {
  526. struct wl1251 *wl = hw->priv;
  527. wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
  528. *total &= WL1251_SUPPORTED_FILTERS;
  529. changed &= WL1251_SUPPORTED_FILTERS;
  530. if (changed == 0)
  531. /* no filters which we support changed */
  532. return;
  533. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  534. wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
  535. wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
  536. if (*total & FIF_PROMISC_IN_BSS) {
  537. wl->rx_config |= CFG_BSSID_FILTER_EN;
  538. wl->rx_config |= CFG_RX_ALL_GOOD;
  539. }
  540. if (*total & FIF_ALLMULTI)
  541. /*
  542. * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
  543. * all multicast frames
  544. */
  545. wl->rx_config &= ~CFG_MC_FILTER_EN;
  546. if (*total & FIF_FCSFAIL)
  547. wl->rx_filter |= CFG_RX_FCS_ERROR;
  548. if (*total & FIF_BCN_PRBRESP_PROMISC) {
  549. wl->rx_config &= ~CFG_BSSID_FILTER_EN;
  550. wl->rx_config &= ~CFG_SSID_FILTER_EN;
  551. }
  552. if (*total & FIF_CONTROL)
  553. wl->rx_filter |= CFG_RX_CTL_EN;
  554. if (*total & FIF_OTHER_BSS)
  555. wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
  556. /*
  557. * FIXME: workqueues need to be properly cancelled on stop(), for
  558. * now let's just disable changing the filter settings. They will
  559. * be updated any on config().
  560. */
  561. /* schedule_work(&wl->filter_work); */
  562. }
  563. /* HW encryption */
  564. static int wl1251_set_key_type(struct wl1251 *wl,
  565. struct wl1251_cmd_set_keys *key,
  566. enum set_key_cmd cmd,
  567. struct ieee80211_key_conf *mac80211_key,
  568. const u8 *addr)
  569. {
  570. switch (mac80211_key->alg) {
  571. case ALG_WEP:
  572. if (is_broadcast_ether_addr(addr))
  573. key->key_type = KEY_WEP_DEFAULT;
  574. else
  575. key->key_type = KEY_WEP_ADDR;
  576. mac80211_key->hw_key_idx = mac80211_key->keyidx;
  577. break;
  578. case ALG_TKIP:
  579. if (is_broadcast_ether_addr(addr))
  580. key->key_type = KEY_TKIP_MIC_GROUP;
  581. else
  582. key->key_type = KEY_TKIP_MIC_PAIRWISE;
  583. mac80211_key->hw_key_idx = mac80211_key->keyidx;
  584. break;
  585. case ALG_CCMP:
  586. if (is_broadcast_ether_addr(addr))
  587. key->key_type = KEY_AES_GROUP;
  588. else
  589. key->key_type = KEY_AES_PAIRWISE;
  590. mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  591. break;
  592. default:
  593. wl1251_error("Unknown key algo 0x%x", mac80211_key->alg);
  594. return -EOPNOTSUPP;
  595. }
  596. return 0;
  597. }
  598. static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  599. struct ieee80211_vif *vif,
  600. struct ieee80211_sta *sta,
  601. struct ieee80211_key_conf *key)
  602. {
  603. struct wl1251 *wl = hw->priv;
  604. struct wl1251_cmd_set_keys *wl_cmd;
  605. const u8 *addr;
  606. int ret;
  607. static const u8 bcast_addr[ETH_ALEN] =
  608. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  609. wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
  610. wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
  611. if (!wl_cmd) {
  612. ret = -ENOMEM;
  613. goto out;
  614. }
  615. addr = sta ? sta->addr : bcast_addr;
  616. wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  617. wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  618. wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  619. key->alg, key->keyidx, key->keylen, key->flags);
  620. wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
  621. if (is_zero_ether_addr(addr)) {
  622. /* We dont support TX only encryption */
  623. ret = -EOPNOTSUPP;
  624. goto out;
  625. }
  626. mutex_lock(&wl->mutex);
  627. ret = wl1251_ps_elp_wakeup(wl);
  628. if (ret < 0)
  629. goto out_unlock;
  630. switch (cmd) {
  631. case SET_KEY:
  632. wl_cmd->key_action = KEY_ADD_OR_REPLACE;
  633. break;
  634. case DISABLE_KEY:
  635. wl_cmd->key_action = KEY_REMOVE;
  636. break;
  637. default:
  638. wl1251_error("Unsupported key cmd 0x%x", cmd);
  639. break;
  640. }
  641. ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
  642. if (ret < 0) {
  643. wl1251_error("Set KEY type failed");
  644. goto out_sleep;
  645. }
  646. if (wl_cmd->key_type != KEY_WEP_DEFAULT)
  647. memcpy(wl_cmd->addr, addr, ETH_ALEN);
  648. if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
  649. (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
  650. /*
  651. * We get the key in the following form:
  652. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  653. * but the target is expecting:
  654. * TKIP - RX MIC - TX MIC
  655. */
  656. memcpy(wl_cmd->key, key->key, 16);
  657. memcpy(wl_cmd->key + 16, key->key + 24, 8);
  658. memcpy(wl_cmd->key + 24, key->key + 16, 8);
  659. } else {
  660. memcpy(wl_cmd->key, key->key, key->keylen);
  661. }
  662. wl_cmd->key_size = key->keylen;
  663. wl_cmd->id = key->keyidx;
  664. wl_cmd->ssid_profile = 0;
  665. wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
  666. ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
  667. if (ret < 0) {
  668. wl1251_warning("could not set keys");
  669. goto out_sleep;
  670. }
  671. out_sleep:
  672. wl1251_ps_elp_sleep(wl);
  673. out_unlock:
  674. mutex_unlock(&wl->mutex);
  675. out:
  676. kfree(wl_cmd);
  677. return ret;
  678. }
  679. static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
  680. struct cfg80211_scan_request *req)
  681. {
  682. struct wl1251 *wl = hw->priv;
  683. struct sk_buff *skb;
  684. size_t ssid_len = 0;
  685. u8 *ssid = NULL;
  686. int ret;
  687. wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
  688. if (req->n_ssids) {
  689. ssid = req->ssids[0].ssid;
  690. ssid_len = req->ssids[0].ssid_len;
  691. }
  692. mutex_lock(&wl->mutex);
  693. if (wl->scanning) {
  694. wl1251_debug(DEBUG_SCAN, "scan already in progress");
  695. ret = -EINVAL;
  696. goto out;
  697. }
  698. ret = wl1251_ps_elp_wakeup(wl);
  699. if (ret < 0)
  700. goto out;
  701. skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
  702. req->ie, req->ie_len);
  703. if (!skb) {
  704. ret = -ENOMEM;
  705. goto out;
  706. }
  707. ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
  708. skb->len);
  709. dev_kfree_skb(skb);
  710. if (ret < 0)
  711. goto out_sleep;
  712. ret = wl1251_cmd_trigger_scan_to(wl, 0);
  713. if (ret < 0)
  714. goto out_sleep;
  715. wl->scanning = true;
  716. ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
  717. req->n_channels, WL1251_SCAN_NUM_PROBES);
  718. if (ret < 0) {
  719. wl->scanning = false;
  720. goto out_sleep;
  721. }
  722. out_sleep:
  723. wl1251_ps_elp_sleep(wl);
  724. out:
  725. mutex_unlock(&wl->mutex);
  726. return ret;
  727. }
  728. static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  729. {
  730. struct wl1251 *wl = hw->priv;
  731. int ret;
  732. mutex_lock(&wl->mutex);
  733. ret = wl1251_ps_elp_wakeup(wl);
  734. if (ret < 0)
  735. goto out;
  736. ret = wl1251_acx_rts_threshold(wl, (u16) value);
  737. if (ret < 0)
  738. wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
  739. wl1251_ps_elp_sleep(wl);
  740. out:
  741. mutex_unlock(&wl->mutex);
  742. return ret;
  743. }
  744. static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
  745. struct ieee80211_vif *vif,
  746. struct ieee80211_bss_conf *bss_conf,
  747. u32 changed)
  748. {
  749. struct wl1251 *wl = hw->priv;
  750. struct sk_buff *beacon, *skb;
  751. int ret;
  752. wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  753. mutex_lock(&wl->mutex);
  754. ret = wl1251_ps_elp_wakeup(wl);
  755. if (ret < 0)
  756. goto out;
  757. if (changed & BSS_CHANGED_BSSID) {
  758. memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
  759. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  760. if (!skb)
  761. goto out_sleep;
  762. ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
  763. skb->data, skb->len);
  764. dev_kfree_skb(skb);
  765. if (ret < 0)
  766. goto out_sleep;
  767. ret = wl1251_build_qos_null_data(wl);
  768. if (ret < 0)
  769. goto out;
  770. if (wl->bss_type != BSS_TYPE_IBSS) {
  771. ret = wl1251_join(wl, wl->bss_type, wl->channel,
  772. wl->beacon_int, wl->dtim_period);
  773. if (ret < 0)
  774. goto out_sleep;
  775. }
  776. }
  777. if (changed & BSS_CHANGED_ASSOC) {
  778. if (bss_conf->assoc) {
  779. wl->beacon_int = bss_conf->beacon_int;
  780. skb = ieee80211_pspoll_get(wl->hw, wl->vif);
  781. if (!skb)
  782. goto out_sleep;
  783. ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
  784. skb->data,
  785. skb->len);
  786. dev_kfree_skb(skb);
  787. if (ret < 0)
  788. goto out_sleep;
  789. ret = wl1251_acx_aid(wl, bss_conf->aid);
  790. if (ret < 0)
  791. goto out_sleep;
  792. } else {
  793. /* use defaults when not associated */
  794. wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
  795. wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
  796. }
  797. }
  798. if (changed & BSS_CHANGED_ERP_SLOT) {
  799. if (bss_conf->use_short_slot)
  800. ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
  801. else
  802. ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
  803. if (ret < 0) {
  804. wl1251_warning("Set slot time failed %d", ret);
  805. goto out_sleep;
  806. }
  807. }
  808. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  809. if (bss_conf->use_short_preamble)
  810. wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  811. else
  812. wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  813. }
  814. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  815. if (bss_conf->use_cts_prot)
  816. ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  817. else
  818. ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  819. if (ret < 0) {
  820. wl1251_warning("Set ctsprotect failed %d", ret);
  821. goto out_sleep;
  822. }
  823. }
  824. if (changed & BSS_CHANGED_BEACON) {
  825. beacon = ieee80211_beacon_get(hw, vif);
  826. ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
  827. beacon->len);
  828. if (ret < 0) {
  829. dev_kfree_skb(beacon);
  830. goto out_sleep;
  831. }
  832. ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
  833. beacon->len);
  834. dev_kfree_skb(beacon);
  835. if (ret < 0)
  836. goto out_sleep;
  837. ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
  838. wl->channel, wl->dtim_period);
  839. if (ret < 0)
  840. goto out_sleep;
  841. }
  842. out_sleep:
  843. wl1251_ps_elp_sleep(wl);
  844. out:
  845. mutex_unlock(&wl->mutex);
  846. }
  847. /* can't be const, mac80211 writes to this */
  848. static struct ieee80211_rate wl1251_rates[] = {
  849. { .bitrate = 10,
  850. .hw_value = 0x1,
  851. .hw_value_short = 0x1, },
  852. { .bitrate = 20,
  853. .hw_value = 0x2,
  854. .hw_value_short = 0x2,
  855. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  856. { .bitrate = 55,
  857. .hw_value = 0x4,
  858. .hw_value_short = 0x4,
  859. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  860. { .bitrate = 110,
  861. .hw_value = 0x20,
  862. .hw_value_short = 0x20,
  863. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  864. { .bitrate = 60,
  865. .hw_value = 0x8,
  866. .hw_value_short = 0x8, },
  867. { .bitrate = 90,
  868. .hw_value = 0x10,
  869. .hw_value_short = 0x10, },
  870. { .bitrate = 120,
  871. .hw_value = 0x40,
  872. .hw_value_short = 0x40, },
  873. { .bitrate = 180,
  874. .hw_value = 0x80,
  875. .hw_value_short = 0x80, },
  876. { .bitrate = 240,
  877. .hw_value = 0x200,
  878. .hw_value_short = 0x200, },
  879. { .bitrate = 360,
  880. .hw_value = 0x400,
  881. .hw_value_short = 0x400, },
  882. { .bitrate = 480,
  883. .hw_value = 0x800,
  884. .hw_value_short = 0x800, },
  885. { .bitrate = 540,
  886. .hw_value = 0x1000,
  887. .hw_value_short = 0x1000, },
  888. };
  889. /* can't be const, mac80211 writes to this */
  890. static struct ieee80211_channel wl1251_channels[] = {
  891. { .hw_value = 1, .center_freq = 2412},
  892. { .hw_value = 2, .center_freq = 2417},
  893. { .hw_value = 3, .center_freq = 2422},
  894. { .hw_value = 4, .center_freq = 2427},
  895. { .hw_value = 5, .center_freq = 2432},
  896. { .hw_value = 6, .center_freq = 2437},
  897. { .hw_value = 7, .center_freq = 2442},
  898. { .hw_value = 8, .center_freq = 2447},
  899. { .hw_value = 9, .center_freq = 2452},
  900. { .hw_value = 10, .center_freq = 2457},
  901. { .hw_value = 11, .center_freq = 2462},
  902. { .hw_value = 12, .center_freq = 2467},
  903. { .hw_value = 13, .center_freq = 2472},
  904. };
  905. static int wl1251_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
  906. const struct ieee80211_tx_queue_params *params)
  907. {
  908. enum wl1251_acx_ps_scheme ps_scheme;
  909. struct wl1251 *wl = hw->priv;
  910. int ret;
  911. mutex_lock(&wl->mutex);
  912. wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
  913. ret = wl1251_ps_elp_wakeup(wl);
  914. if (ret < 0)
  915. goto out;
  916. /* mac80211 uses units of 32 usec */
  917. ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
  918. params->cw_min, params->cw_max,
  919. params->aifs, params->txop * 32);
  920. if (ret < 0)
  921. goto out_sleep;
  922. if (params->uapsd)
  923. ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
  924. else
  925. ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
  926. ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
  927. CHANNEL_TYPE_EDCF,
  928. wl1251_tx_get_queue(queue), ps_scheme,
  929. WL1251_ACX_ACK_POLICY_LEGACY);
  930. if (ret < 0)
  931. goto out_sleep;
  932. out_sleep:
  933. wl1251_ps_elp_sleep(wl);
  934. out:
  935. mutex_unlock(&wl->mutex);
  936. return ret;
  937. }
  938. /* can't be const, mac80211 writes to this */
  939. static struct ieee80211_supported_band wl1251_band_2ghz = {
  940. .channels = wl1251_channels,
  941. .n_channels = ARRAY_SIZE(wl1251_channels),
  942. .bitrates = wl1251_rates,
  943. .n_bitrates = ARRAY_SIZE(wl1251_rates),
  944. };
  945. static const struct ieee80211_ops wl1251_ops = {
  946. .start = wl1251_op_start,
  947. .stop = wl1251_op_stop,
  948. .add_interface = wl1251_op_add_interface,
  949. .remove_interface = wl1251_op_remove_interface,
  950. .config = wl1251_op_config,
  951. .configure_filter = wl1251_op_configure_filter,
  952. .tx = wl1251_op_tx,
  953. .set_key = wl1251_op_set_key,
  954. .hw_scan = wl1251_op_hw_scan,
  955. .bss_info_changed = wl1251_op_bss_info_changed,
  956. .set_rts_threshold = wl1251_op_set_rts_threshold,
  957. .conf_tx = wl1251_op_conf_tx,
  958. };
  959. static int wl1251_register_hw(struct wl1251 *wl)
  960. {
  961. int ret;
  962. if (wl->mac80211_registered)
  963. return 0;
  964. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  965. ret = ieee80211_register_hw(wl->hw);
  966. if (ret < 0) {
  967. wl1251_error("unable to register mac80211 hw: %d", ret);
  968. return ret;
  969. }
  970. wl->mac80211_registered = true;
  971. wl1251_notice("loaded");
  972. return 0;
  973. }
  974. int wl1251_init_ieee80211(struct wl1251 *wl)
  975. {
  976. int ret;
  977. /* The tx descriptor buffer and the TKIP space */
  978. wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
  979. + WL1251_TKIP_IV_SPACE;
  980. /* unit us */
  981. /* FIXME: find a proper value */
  982. wl->hw->channel_change_time = 10000;
  983. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  984. IEEE80211_HW_NOISE_DBM |
  985. IEEE80211_HW_SUPPORTS_PS |
  986. IEEE80211_HW_BEACON_FILTER |
  987. IEEE80211_HW_SUPPORTS_UAPSD;
  988. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  989. wl->hw->wiphy->max_scan_ssids = 1;
  990. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
  991. wl->hw->queues = 4;
  992. ret = wl1251_register_hw(wl);
  993. if (ret)
  994. goto out;
  995. wl1251_debugfs_init(wl);
  996. wl1251_notice("initialized");
  997. ret = 0;
  998. out:
  999. return ret;
  1000. }
  1001. EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
  1002. struct ieee80211_hw *wl1251_alloc_hw(void)
  1003. {
  1004. struct ieee80211_hw *hw;
  1005. struct wl1251 *wl;
  1006. int i;
  1007. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  1008. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
  1009. if (!hw) {
  1010. wl1251_error("could not alloc ieee80211_hw");
  1011. return ERR_PTR(-ENOMEM);
  1012. }
  1013. wl = hw->priv;
  1014. memset(wl, 0, sizeof(*wl));
  1015. wl->hw = hw;
  1016. wl->data_in_count = 0;
  1017. skb_queue_head_init(&wl->tx_queue);
  1018. INIT_WORK(&wl->filter_work, wl1251_filter_work);
  1019. INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
  1020. wl->channel = WL1251_DEFAULT_CHANNEL;
  1021. wl->scanning = false;
  1022. wl->default_key = 0;
  1023. wl->listen_int = 1;
  1024. wl->rx_counter = 0;
  1025. wl->rx_handled = 0;
  1026. wl->rx_current_buffer = 0;
  1027. wl->rx_last_id = 0;
  1028. wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
  1029. wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
  1030. wl->elp = false;
  1031. wl->psm = 0;
  1032. wl->psm_requested = false;
  1033. wl->tx_queue_stopped = false;
  1034. wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
  1035. wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
  1036. wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
  1037. wl->vif = NULL;
  1038. for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
  1039. wl->tx_frames[i] = NULL;
  1040. wl->next_tx_complete = 0;
  1041. INIT_WORK(&wl->irq_work, wl1251_irq_work);
  1042. INIT_WORK(&wl->tx_work, wl1251_tx_work);
  1043. /*
  1044. * In case our MAC address is not correctly set,
  1045. * we use a random but Nokia MAC.
  1046. */
  1047. memcpy(wl->mac_addr, nokia_oui, 3);
  1048. get_random_bytes(wl->mac_addr + 3, 3);
  1049. wl->state = WL1251_STATE_OFF;
  1050. mutex_init(&wl->mutex);
  1051. wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
  1052. wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
  1053. wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
  1054. if (!wl->rx_descriptor) {
  1055. wl1251_error("could not allocate memory for rx descriptor");
  1056. ieee80211_free_hw(hw);
  1057. return ERR_PTR(-ENOMEM);
  1058. }
  1059. return hw;
  1060. }
  1061. EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
  1062. int wl1251_free_hw(struct wl1251 *wl)
  1063. {
  1064. ieee80211_unregister_hw(wl->hw);
  1065. wl1251_debugfs_exit(wl);
  1066. kfree(wl->target_mem_map);
  1067. kfree(wl->data_path);
  1068. vfree(wl->fw);
  1069. wl->fw = NULL;
  1070. kfree(wl->nvs);
  1071. wl->nvs = NULL;
  1072. kfree(wl->rx_descriptor);
  1073. wl->rx_descriptor = NULL;
  1074. ieee80211_free_hw(wl->hw);
  1075. return 0;
  1076. }
  1077. EXPORT_SYMBOL_GPL(wl1251_free_hw);
  1078. MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
  1079. MODULE_LICENSE("GPL");
  1080. MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");
  1081. MODULE_ALIAS("spi:wl1251");
  1082. MODULE_FIRMWARE(WL1251_FW_NAME);