wl1271_main.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2009 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/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/firmware.h>
  27. #include <linux/delay.h>
  28. #include <linux/irq.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/crc32.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/spi/wl12xx.h>
  33. #include "wl1271.h"
  34. #include "wl12xx_80211.h"
  35. #include "wl1271_reg.h"
  36. #include "wl1271_spi.h"
  37. #include "wl1271_event.h"
  38. #include "wl1271_tx.h"
  39. #include "wl1271_rx.h"
  40. #include "wl1271_ps.h"
  41. #include "wl1271_init.h"
  42. #include "wl1271_debugfs.h"
  43. #include "wl1271_cmd.h"
  44. #include "wl1271_boot.h"
  45. static int wl1271_plt_init(struct wl1271 *wl)
  46. {
  47. int ret;
  48. ret = wl1271_acx_init_mem_config(wl);
  49. if (ret < 0)
  50. return ret;
  51. ret = wl1271_cmd_data_path(wl, wl->channel, 1);
  52. if (ret < 0)
  53. return ret;
  54. return 0;
  55. }
  56. static void wl1271_disable_interrupts(struct wl1271 *wl)
  57. {
  58. disable_irq(wl->irq);
  59. }
  60. static void wl1271_power_off(struct wl1271 *wl)
  61. {
  62. wl->set_power(false);
  63. }
  64. static void wl1271_power_on(struct wl1271 *wl)
  65. {
  66. wl->set_power(true);
  67. }
  68. static void wl1271_fw_status(struct wl1271 *wl, struct wl1271_fw_status *status)
  69. {
  70. u32 total = 0;
  71. int i;
  72. /*
  73. * FIXME: Reading the FW status directly from the registers seems to
  74. * be the right thing to do, but it doesn't work. And in the
  75. * reference driver, there is a workaround called
  76. * USE_SDIO_24M_WORKAROUND, which reads the status from memory
  77. * instead, so we do the same here.
  78. */
  79. wl1271_spi_mem_read(wl, STATUS_MEM_ADDRESS, status, sizeof(*status));
  80. wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
  81. "drv_rx_counter = %d, tx_results_counter = %d)",
  82. status->intr,
  83. status->fw_rx_counter,
  84. status->drv_rx_counter,
  85. status->tx_results_counter);
  86. /* update number of available TX blocks */
  87. for (i = 0; i < NUM_TX_QUEUES; i++) {
  88. u32 cnt = status->tx_released_blks[i] - wl->tx_blocks_freed[i];
  89. wl->tx_blocks_freed[i] = status->tx_released_blks[i];
  90. wl->tx_blocks_available += cnt;
  91. total += cnt;
  92. }
  93. /* if more blocks are available now, schedule some tx work */
  94. if (total && !skb_queue_empty(&wl->tx_queue))
  95. schedule_work(&wl->tx_work);
  96. /* update the host-chipset time offset */
  97. wl->time_offset = jiffies_to_usecs(jiffies) - status->fw_localtime;
  98. }
  99. #define WL1271_IRQ_MAX_LOOPS 10
  100. static void wl1271_irq_work(struct work_struct *work)
  101. {
  102. u32 intr, ctr = WL1271_IRQ_MAX_LOOPS;
  103. int ret;
  104. struct wl1271 *wl =
  105. container_of(work, struct wl1271, irq_work);
  106. mutex_lock(&wl->mutex);
  107. wl1271_debug(DEBUG_IRQ, "IRQ work");
  108. if (wl->state == WL1271_STATE_OFF)
  109. goto out;
  110. ret = wl1271_ps_elp_wakeup(wl, true);
  111. if (ret < 0)
  112. goto out;
  113. wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  114. intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  115. if (!intr) {
  116. wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
  117. goto out_sleep;
  118. }
  119. intr &= WL1271_INTR_MASK;
  120. do {
  121. wl1271_fw_status(wl, wl->fw_status);
  122. if (intr & (WL1271_ACX_INTR_EVENT_A |
  123. WL1271_ACX_INTR_EVENT_B)) {
  124. wl1271_debug(DEBUG_IRQ,
  125. "WL1271_ACX_INTR_EVENT (0x%x)", intr);
  126. if (intr & WL1271_ACX_INTR_EVENT_A)
  127. wl1271_event_handle(wl, 0);
  128. else
  129. wl1271_event_handle(wl, 1);
  130. }
  131. if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
  132. wl1271_debug(DEBUG_IRQ,
  133. "WL1271_ACX_INTR_INIT_COMPLETE");
  134. if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
  135. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
  136. if (intr & WL1271_ACX_INTR_DATA) {
  137. u8 tx_res_cnt = wl->fw_status->tx_results_counter -
  138. wl->tx_results_count;
  139. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
  140. /* check for tx results */
  141. if (tx_res_cnt)
  142. wl1271_tx_complete(wl, tx_res_cnt);
  143. wl1271_rx(wl, wl->fw_status);
  144. }
  145. intr = wl1271_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  146. intr &= WL1271_INTR_MASK;
  147. } while (intr && --ctr);
  148. out_sleep:
  149. wl1271_reg_write32(wl, ACX_REG_INTERRUPT_MASK,
  150. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  151. wl1271_ps_elp_sleep(wl);
  152. out:
  153. mutex_unlock(&wl->mutex);
  154. }
  155. static irqreturn_t wl1271_irq(int irq, void *cookie)
  156. {
  157. struct wl1271 *wl;
  158. unsigned long flags;
  159. wl1271_debug(DEBUG_IRQ, "IRQ");
  160. wl = cookie;
  161. /* complete the ELP completion */
  162. spin_lock_irqsave(&wl->wl_lock, flags);
  163. if (wl->elp_compl) {
  164. complete(wl->elp_compl);
  165. wl->elp_compl = NULL;
  166. }
  167. schedule_work(&wl->irq_work);
  168. spin_unlock_irqrestore(&wl->wl_lock, flags);
  169. return IRQ_HANDLED;
  170. }
  171. static int wl1271_fetch_firmware(struct wl1271 *wl)
  172. {
  173. const struct firmware *fw;
  174. int ret;
  175. ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
  176. if (ret < 0) {
  177. wl1271_error("could not get firmware: %d", ret);
  178. return ret;
  179. }
  180. if (fw->size % 4) {
  181. wl1271_error("firmware size is not multiple of 32 bits: %zu",
  182. fw->size);
  183. ret = -EILSEQ;
  184. goto out;
  185. }
  186. wl->fw_len = fw->size;
  187. wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
  188. if (!wl->fw) {
  189. wl1271_error("could not allocate memory for the firmware");
  190. ret = -ENOMEM;
  191. goto out;
  192. }
  193. memcpy(wl->fw, fw->data, wl->fw_len);
  194. ret = 0;
  195. out:
  196. release_firmware(fw);
  197. return ret;
  198. }
  199. static int wl1271_fetch_nvs(struct wl1271 *wl)
  200. {
  201. const struct firmware *fw;
  202. int ret;
  203. ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
  204. if (ret < 0) {
  205. wl1271_error("could not get nvs file: %d", ret);
  206. return ret;
  207. }
  208. if (fw->size % 4) {
  209. wl1271_error("nvs size is not multiple of 32 bits: %zu",
  210. fw->size);
  211. ret = -EILSEQ;
  212. goto out;
  213. }
  214. wl->nvs_len = fw->size;
  215. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  216. if (!wl->nvs) {
  217. wl1271_error("could not allocate memory for the nvs file");
  218. ret = -ENOMEM;
  219. goto out;
  220. }
  221. memcpy(wl->nvs, fw->data, wl->nvs_len);
  222. ret = 0;
  223. out:
  224. release_firmware(fw);
  225. return ret;
  226. }
  227. static void wl1271_fw_wakeup(struct wl1271 *wl)
  228. {
  229. u32 elp_reg;
  230. elp_reg = ELPCTRL_WAKE_UP;
  231. wl1271_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  232. }
  233. static int wl1271_setup(struct wl1271 *wl)
  234. {
  235. wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
  236. if (!wl->fw_status)
  237. return -ENOMEM;
  238. wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
  239. if (!wl->tx_res_if) {
  240. kfree(wl->fw_status);
  241. return -ENOMEM;
  242. }
  243. INIT_WORK(&wl->irq_work, wl1271_irq_work);
  244. INIT_WORK(&wl->tx_work, wl1271_tx_work);
  245. return 0;
  246. }
  247. static int wl1271_chip_wakeup(struct wl1271 *wl)
  248. {
  249. int ret = 0;
  250. wl1271_power_on(wl);
  251. msleep(WL1271_POWER_ON_SLEEP);
  252. wl1271_spi_reset(wl);
  253. wl1271_spi_init(wl);
  254. /* We don't need a real memory partition here, because we only want
  255. * to use the registers at this point. */
  256. wl1271_set_partition(wl,
  257. 0x00000000,
  258. 0x00000000,
  259. REGISTERS_BASE,
  260. REGISTERS_DOWN_SIZE);
  261. /* ELP module wake up */
  262. wl1271_fw_wakeup(wl);
  263. /* whal_FwCtrl_BootSm() */
  264. /* 0. read chip id from CHIP_ID */
  265. wl->chip.id = wl1271_reg_read32(wl, CHIP_ID_B);
  266. /* 1. check if chip id is valid */
  267. switch (wl->chip.id) {
  268. case CHIP_ID_1271_PG10:
  269. wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
  270. wl->chip.id);
  271. ret = wl1271_setup(wl);
  272. if (ret < 0)
  273. goto out;
  274. break;
  275. case CHIP_ID_1271_PG20:
  276. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
  277. wl->chip.id);
  278. ret = wl1271_setup(wl);
  279. if (ret < 0)
  280. goto out;
  281. break;
  282. default:
  283. wl1271_error("unsupported chip id: 0x%x", wl->chip.id);
  284. ret = -ENODEV;
  285. goto out;
  286. }
  287. if (wl->fw == NULL) {
  288. ret = wl1271_fetch_firmware(wl);
  289. if (ret < 0)
  290. goto out;
  291. }
  292. /* No NVS from netlink, try to get it from the filesystem */
  293. if (wl->nvs == NULL) {
  294. ret = wl1271_fetch_nvs(wl);
  295. if (ret < 0)
  296. goto out;
  297. }
  298. out:
  299. return ret;
  300. }
  301. static void wl1271_filter_work(struct work_struct *work)
  302. {
  303. struct wl1271 *wl =
  304. container_of(work, struct wl1271, filter_work);
  305. int ret;
  306. mutex_lock(&wl->mutex);
  307. if (wl->state == WL1271_STATE_OFF)
  308. goto out;
  309. ret = wl1271_ps_elp_wakeup(wl, false);
  310. if (ret < 0)
  311. goto out;
  312. /* FIXME: replace the magic numbers with proper definitions */
  313. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  314. if (ret < 0)
  315. goto out_sleep;
  316. out_sleep:
  317. wl1271_ps_elp_sleep(wl);
  318. out:
  319. mutex_unlock(&wl->mutex);
  320. }
  321. int wl1271_plt_start(struct wl1271 *wl)
  322. {
  323. int ret;
  324. mutex_lock(&wl->mutex);
  325. wl1271_notice("power up");
  326. if (wl->state != WL1271_STATE_OFF) {
  327. wl1271_error("cannot go into PLT state because not "
  328. "in off state: %d", wl->state);
  329. ret = -EBUSY;
  330. goto out;
  331. }
  332. wl->state = WL1271_STATE_PLT;
  333. ret = wl1271_chip_wakeup(wl);
  334. if (ret < 0)
  335. goto out;
  336. ret = wl1271_boot(wl);
  337. if (ret < 0)
  338. goto out;
  339. wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  340. ret = wl1271_plt_init(wl);
  341. if (ret < 0)
  342. goto out;
  343. out:
  344. mutex_unlock(&wl->mutex);
  345. return ret;
  346. }
  347. int wl1271_plt_stop(struct wl1271 *wl)
  348. {
  349. int ret = 0;
  350. mutex_lock(&wl->mutex);
  351. wl1271_notice("power down");
  352. if (wl->state != WL1271_STATE_PLT) {
  353. wl1271_error("cannot power down because not in PLT "
  354. "state: %d", wl->state);
  355. ret = -EBUSY;
  356. goto out;
  357. }
  358. wl1271_disable_interrupts(wl);
  359. wl1271_power_off(wl);
  360. wl->state = WL1271_STATE_OFF;
  361. out:
  362. mutex_unlock(&wl->mutex);
  363. return ret;
  364. }
  365. static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  366. {
  367. struct wl1271 *wl = hw->priv;
  368. skb_queue_tail(&wl->tx_queue, skb);
  369. /*
  370. * The chip specific setup must run before the first TX packet -
  371. * before that, the tx_work will not be initialized!
  372. */
  373. schedule_work(&wl->tx_work);
  374. /*
  375. * The workqueue is slow to process the tx_queue and we need stop
  376. * the queue here, otherwise the queue will get too long.
  377. */
  378. if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
  379. ieee80211_stop_queues(wl->hw);
  380. /*
  381. * FIXME: this is racy, the variable is not properly
  382. * protected. Maybe fix this by removing the stupid
  383. * variable altogether and checking the real queue state?
  384. */
  385. wl->tx_queue_stopped = true;
  386. }
  387. return NETDEV_TX_OK;
  388. }
  389. static int wl1271_op_start(struct ieee80211_hw *hw)
  390. {
  391. struct wl1271 *wl = hw->priv;
  392. int ret = 0;
  393. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  394. mutex_lock(&wl->mutex);
  395. if (wl->state != WL1271_STATE_OFF) {
  396. wl1271_error("cannot start because not in off state: %d",
  397. wl->state);
  398. ret = -EBUSY;
  399. goto out;
  400. }
  401. ret = wl1271_chip_wakeup(wl);
  402. if (ret < 0)
  403. goto out;
  404. ret = wl1271_boot(wl);
  405. if (ret < 0)
  406. goto out;
  407. ret = wl1271_hw_init(wl);
  408. if (ret < 0)
  409. goto out;
  410. wl->state = WL1271_STATE_ON;
  411. wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
  412. out:
  413. if (ret < 0)
  414. wl1271_power_off(wl);
  415. mutex_unlock(&wl->mutex);
  416. return ret;
  417. }
  418. static void wl1271_op_stop(struct ieee80211_hw *hw)
  419. {
  420. struct wl1271 *wl = hw->priv;
  421. int i;
  422. wl1271_info("down");
  423. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  424. mutex_lock(&wl->mutex);
  425. WARN_ON(wl->state != WL1271_STATE_ON);
  426. if (wl->scanning) {
  427. mutex_unlock(&wl->mutex);
  428. ieee80211_scan_completed(wl->hw, true);
  429. mutex_lock(&wl->mutex);
  430. wl->scanning = false;
  431. }
  432. wl->state = WL1271_STATE_OFF;
  433. wl1271_disable_interrupts(wl);
  434. mutex_unlock(&wl->mutex);
  435. cancel_work_sync(&wl->irq_work);
  436. cancel_work_sync(&wl->tx_work);
  437. cancel_work_sync(&wl->filter_work);
  438. mutex_lock(&wl->mutex);
  439. /* let's notify MAC80211 about the remaining pending TX frames */
  440. wl1271_tx_flush(wl);
  441. wl1271_power_off(wl);
  442. memset(wl->bssid, 0, ETH_ALEN);
  443. memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
  444. wl->ssid_len = 0;
  445. wl->listen_int = 1;
  446. wl->bss_type = MAX_BSS_TYPE;
  447. wl->band = IEEE80211_BAND_2GHZ;
  448. wl->rx_counter = 0;
  449. wl->elp = false;
  450. wl->psm = 0;
  451. wl->tx_queue_stopped = false;
  452. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  453. wl->tx_blocks_available = 0;
  454. wl->tx_results_count = 0;
  455. wl->tx_packets_count = 0;
  456. wl->tx_security_last_seq = 0;
  457. wl->tx_security_seq_16 = 0;
  458. wl->tx_security_seq_32 = 0;
  459. wl->time_offset = 0;
  460. wl->session_counter = 0;
  461. for (i = 0; i < NUM_TX_QUEUES; i++)
  462. wl->tx_blocks_freed[i] = 0;
  463. wl1271_debugfs_reset(wl);
  464. mutex_unlock(&wl->mutex);
  465. }
  466. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  467. struct ieee80211_if_init_conf *conf)
  468. {
  469. struct wl1271 *wl = hw->priv;
  470. int ret = 0;
  471. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  472. conf->type, conf->mac_addr);
  473. mutex_lock(&wl->mutex);
  474. switch (conf->type) {
  475. case NL80211_IFTYPE_STATION:
  476. wl->bss_type = BSS_TYPE_STA_BSS;
  477. break;
  478. case NL80211_IFTYPE_ADHOC:
  479. wl->bss_type = BSS_TYPE_IBSS;
  480. break;
  481. default:
  482. ret = -EOPNOTSUPP;
  483. goto out;
  484. }
  485. /* FIXME: what if conf->mac_addr changes? */
  486. out:
  487. mutex_unlock(&wl->mutex);
  488. return ret;
  489. }
  490. static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
  491. struct ieee80211_if_init_conf *conf)
  492. {
  493. wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
  494. }
  495. #if 0
  496. static int wl1271_op_config_interface(struct ieee80211_hw *hw,
  497. struct ieee80211_vif *vif,
  498. struct ieee80211_if_conf *conf)
  499. {
  500. struct wl1271 *wl = hw->priv;
  501. struct sk_buff *beacon;
  502. int ret;
  503. wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
  504. conf->bssid);
  505. wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
  506. conf->ssid_len);
  507. mutex_lock(&wl->mutex);
  508. ret = wl1271_ps_elp_wakeup(wl, false);
  509. if (ret < 0)
  510. goto out;
  511. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  512. ret = wl1271_cmd_build_null_data(wl);
  513. if (ret < 0)
  514. goto out_sleep;
  515. wl->ssid_len = conf->ssid_len;
  516. if (wl->ssid_len)
  517. memcpy(wl->ssid, conf->ssid, wl->ssid_len);
  518. if (wl->bss_type != BSS_TYPE_IBSS) {
  519. /* FIXME: replace the magic numbers with proper definitions */
  520. ret = wl1271_cmd_join(wl, wl->bss_type, 5, 100, 1);
  521. if (ret < 0)
  522. goto out_sleep;
  523. }
  524. if (conf->changed & IEEE80211_IFCC_BEACON) {
  525. beacon = ieee80211_beacon_get(hw, vif);
  526. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
  527. beacon->data, beacon->len);
  528. if (ret < 0) {
  529. dev_kfree_skb(beacon);
  530. goto out_sleep;
  531. }
  532. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
  533. beacon->data, beacon->len);
  534. dev_kfree_skb(beacon);
  535. if (ret < 0)
  536. goto out_sleep;
  537. /* FIXME: replace the magic numbers with proper definitions */
  538. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  539. if (ret < 0)
  540. goto out_sleep;
  541. }
  542. out_sleep:
  543. wl1271_ps_elp_sleep(wl);
  544. out:
  545. mutex_unlock(&wl->mutex);
  546. return ret;
  547. }
  548. #endif
  549. static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
  550. {
  551. struct wl1271 *wl = hw->priv;
  552. struct ieee80211_conf *conf = &hw->conf;
  553. int channel, ret = 0;
  554. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  555. wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
  556. channel,
  557. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  558. conf->power_level);
  559. mutex_lock(&wl->mutex);
  560. wl->band = conf->channel->band;
  561. ret = wl1271_ps_elp_wakeup(wl, false);
  562. if (ret < 0)
  563. goto out;
  564. if (channel != wl->channel) {
  565. u8 old_channel = wl->channel;
  566. wl->channel = channel;
  567. /* FIXME: use beacon interval provided by mac80211 */
  568. ret = wl1271_cmd_join(wl, wl->bss_type, 1, 100, 0);
  569. if (ret < 0) {
  570. wl->channel = old_channel;
  571. goto out_sleep;
  572. }
  573. }
  574. ret = wl1271_cmd_build_null_data(wl);
  575. if (ret < 0)
  576. goto out_sleep;
  577. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  578. wl1271_info("psm enabled");
  579. wl->psm_requested = true;
  580. /*
  581. * We enter PSM only if we're already associated.
  582. * If we're not, we'll enter it when joining an SSID,
  583. * through the bss_info_changed() hook.
  584. */
  585. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  586. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  587. wl->psm_requested) {
  588. wl1271_info("psm disabled");
  589. wl->psm_requested = false;
  590. if (wl->psm)
  591. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE);
  592. }
  593. if (conf->power_level != wl->power_level) {
  594. ret = wl1271_acx_tx_power(wl, conf->power_level);
  595. if (ret < 0)
  596. goto out;
  597. wl->power_level = conf->power_level;
  598. }
  599. out_sleep:
  600. wl1271_ps_elp_sleep(wl);
  601. out:
  602. mutex_unlock(&wl->mutex);
  603. return ret;
  604. }
  605. #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  606. FIF_ALLMULTI | \
  607. FIF_FCSFAIL | \
  608. FIF_BCN_PRBRESP_PROMISC | \
  609. FIF_CONTROL | \
  610. FIF_OTHER_BSS)
  611. static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
  612. unsigned int changed,
  613. unsigned int *total,u64 multicast)
  614. {
  615. struct wl1271 *wl = hw->priv;
  616. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
  617. *total &= WL1271_SUPPORTED_FILTERS;
  618. changed &= WL1271_SUPPORTED_FILTERS;
  619. if (changed == 0)
  620. return;
  621. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  622. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  623. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  624. /*
  625. * FIXME: workqueues need to be properly cancelled on stop(), for
  626. * now let's just disable changing the filter settings. They will
  627. * be updated any on config().
  628. */
  629. /* schedule_work(&wl->filter_work); */
  630. }
  631. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  632. struct ieee80211_vif *vif,
  633. struct ieee80211_sta *sta,
  634. struct ieee80211_key_conf *key_conf)
  635. {
  636. struct wl1271 *wl = hw->priv;
  637. const u8 *addr;
  638. int ret;
  639. u32 tx_seq_32 = 0;
  640. u16 tx_seq_16 = 0;
  641. u8 key_type;
  642. static const u8 bcast_addr[ETH_ALEN] =
  643. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  644. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  645. addr = sta ? sta->addr : bcast_addr;
  646. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  647. wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  648. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  649. key_conf->alg, key_conf->keyidx,
  650. key_conf->keylen, key_conf->flags);
  651. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  652. if (is_zero_ether_addr(addr)) {
  653. /* We dont support TX only encryption */
  654. ret = -EOPNOTSUPP;
  655. goto out;
  656. }
  657. mutex_lock(&wl->mutex);
  658. ret = wl1271_ps_elp_wakeup(wl, false);
  659. if (ret < 0)
  660. goto out_unlock;
  661. switch (key_conf->alg) {
  662. case ALG_WEP:
  663. key_type = KEY_WEP;
  664. key_conf->hw_key_idx = key_conf->keyidx;
  665. break;
  666. case ALG_TKIP:
  667. key_type = KEY_TKIP;
  668. key_conf->hw_key_idx = key_conf->keyidx;
  669. tx_seq_32 = wl->tx_security_seq_32;
  670. tx_seq_16 = wl->tx_security_seq_16;
  671. break;
  672. case ALG_CCMP:
  673. key_type = KEY_AES;
  674. key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  675. tx_seq_32 = wl->tx_security_seq_32;
  676. tx_seq_16 = wl->tx_security_seq_16;
  677. break;
  678. default:
  679. wl1271_error("Unknown key algo 0x%x", key_conf->alg);
  680. ret = -EOPNOTSUPP;
  681. goto out_sleep;
  682. }
  683. switch (cmd) {
  684. case SET_KEY:
  685. ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
  686. key_conf->keyidx, key_type,
  687. key_conf->keylen, key_conf->key,
  688. addr, tx_seq_32, tx_seq_16);
  689. if (ret < 0) {
  690. wl1271_error("Could not add or replace key");
  691. goto out_sleep;
  692. }
  693. break;
  694. case DISABLE_KEY:
  695. ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
  696. key_conf->keyidx, key_type,
  697. key_conf->keylen, key_conf->key,
  698. addr, 0, 0);
  699. if (ret < 0) {
  700. wl1271_error("Could not remove key");
  701. goto out_sleep;
  702. }
  703. break;
  704. default:
  705. wl1271_error("Unsupported key cmd 0x%x", cmd);
  706. ret = -EOPNOTSUPP;
  707. goto out_sleep;
  708. break;
  709. }
  710. out_sleep:
  711. wl1271_ps_elp_sleep(wl);
  712. out_unlock:
  713. mutex_unlock(&wl->mutex);
  714. out:
  715. return ret;
  716. }
  717. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  718. struct cfg80211_scan_request *req)
  719. {
  720. struct wl1271 *wl = hw->priv;
  721. int ret;
  722. u8 *ssid = NULL;
  723. size_t ssid_len = 0;
  724. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  725. if (req->n_ssids) {
  726. ssid = req->ssids[0].ssid;
  727. ssid_len = req->ssids[0].ssid_len;
  728. }
  729. mutex_lock(&wl->mutex);
  730. ret = wl1271_ps_elp_wakeup(wl, false);
  731. if (ret < 0)
  732. goto out;
  733. ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
  734. wl1271_ps_elp_sleep(wl);
  735. out:
  736. mutex_unlock(&wl->mutex);
  737. return ret;
  738. }
  739. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  740. {
  741. struct wl1271 *wl = hw->priv;
  742. int ret;
  743. mutex_lock(&wl->mutex);
  744. ret = wl1271_ps_elp_wakeup(wl, false);
  745. if (ret < 0)
  746. goto out;
  747. ret = wl1271_acx_rts_threshold(wl, (u16) value);
  748. if (ret < 0)
  749. wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
  750. wl1271_ps_elp_sleep(wl);
  751. out:
  752. mutex_unlock(&wl->mutex);
  753. return ret;
  754. }
  755. static u32 wl1271_enabled_rates_get(struct wl1271 *wl, u64 basic_rate_set)
  756. {
  757. struct ieee80211_supported_band *band;
  758. u32 enabled_rates = 0;
  759. int bit;
  760. band = wl->hw->wiphy->bands[wl->band];
  761. for (bit = 0; bit < band->n_bitrates; bit++) {
  762. if (basic_rate_set & 0x1)
  763. enabled_rates |= band->bitrates[bit].hw_value;
  764. basic_rate_set >>= 1;
  765. }
  766. return enabled_rates;
  767. }
  768. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  769. struct ieee80211_vif *vif,
  770. struct ieee80211_bss_conf *bss_conf,
  771. u32 changed)
  772. {
  773. enum wl1271_cmd_ps_mode mode;
  774. struct wl1271 *wl = hw->priv;
  775. int ret;
  776. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  777. mutex_lock(&wl->mutex);
  778. ret = wl1271_ps_elp_wakeup(wl, false);
  779. if (ret < 0)
  780. goto out;
  781. if (changed & BSS_CHANGED_ASSOC) {
  782. if (bss_conf->assoc) {
  783. wl->aid = bss_conf->aid;
  784. ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
  785. if (ret < 0)
  786. goto out_sleep;
  787. ret = wl1271_acx_aid(wl, wl->aid);
  788. if (ret < 0)
  789. goto out_sleep;
  790. /* If we want to go in PSM but we're not there yet */
  791. if (wl->psm_requested && !wl->psm) {
  792. mode = STATION_POWER_SAVE_MODE;
  793. ret = wl1271_ps_set_mode(wl, mode);
  794. if (ret < 0)
  795. goto out_sleep;
  796. }
  797. }
  798. }
  799. if (changed & BSS_CHANGED_ERP_SLOT) {
  800. if (bss_conf->use_short_slot)
  801. ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
  802. else
  803. ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
  804. if (ret < 0) {
  805. wl1271_warning("Set slot time failed %d", ret);
  806. goto out_sleep;
  807. }
  808. }
  809. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  810. if (bss_conf->use_short_preamble)
  811. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  812. else
  813. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  814. }
  815. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  816. if (bss_conf->use_cts_prot)
  817. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  818. else
  819. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  820. if (ret < 0) {
  821. wl1271_warning("Set ctsprotect failed %d", ret);
  822. goto out_sleep;
  823. }
  824. }
  825. if (changed & BSS_CHANGED_BASIC_RATES) {
  826. u32 enabled_rates = wl1271_enabled_rates_get(
  827. wl, bss_conf->basic_rates);
  828. ret = wl1271_acx_rate_policies(wl, enabled_rates);
  829. if (ret < 0) {
  830. wl1271_warning("Set rate policies failed %d", ret);
  831. goto out_sleep;
  832. }
  833. }
  834. out_sleep:
  835. wl1271_ps_elp_sleep(wl);
  836. out:
  837. mutex_unlock(&wl->mutex);
  838. }
  839. /* can't be const, mac80211 writes to this */
  840. static struct ieee80211_rate wl1271_rates[] = {
  841. { .bitrate = 10,
  842. .hw_value = 0x1,
  843. .hw_value_short = 0x1, },
  844. { .bitrate = 20,
  845. .hw_value = 0x2,
  846. .hw_value_short = 0x2,
  847. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  848. { .bitrate = 55,
  849. .hw_value = 0x4,
  850. .hw_value_short = 0x4,
  851. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  852. { .bitrate = 110,
  853. .hw_value = 0x20,
  854. .hw_value_short = 0x20,
  855. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  856. { .bitrate = 60,
  857. .hw_value = 0x8,
  858. .hw_value_short = 0x8, },
  859. { .bitrate = 90,
  860. .hw_value = 0x10,
  861. .hw_value_short = 0x10, },
  862. { .bitrate = 120,
  863. .hw_value = 0x40,
  864. .hw_value_short = 0x40, },
  865. { .bitrate = 180,
  866. .hw_value = 0x80,
  867. .hw_value_short = 0x80, },
  868. { .bitrate = 240,
  869. .hw_value = 0x200,
  870. .hw_value_short = 0x200, },
  871. { .bitrate = 360,
  872. .hw_value = 0x400,
  873. .hw_value_short = 0x400, },
  874. { .bitrate = 480,
  875. .hw_value = 0x800,
  876. .hw_value_short = 0x800, },
  877. { .bitrate = 540,
  878. .hw_value = 0x1000,
  879. .hw_value_short = 0x1000, },
  880. };
  881. /* can't be const, mac80211 writes to this */
  882. static struct ieee80211_channel wl1271_channels[] = {
  883. { .hw_value = 1, .center_freq = 2412},
  884. { .hw_value = 2, .center_freq = 2417},
  885. { .hw_value = 3, .center_freq = 2422},
  886. { .hw_value = 4, .center_freq = 2427},
  887. { .hw_value = 5, .center_freq = 2432},
  888. { .hw_value = 6, .center_freq = 2437},
  889. { .hw_value = 7, .center_freq = 2442},
  890. { .hw_value = 8, .center_freq = 2447},
  891. { .hw_value = 9, .center_freq = 2452},
  892. { .hw_value = 10, .center_freq = 2457},
  893. { .hw_value = 11, .center_freq = 2462},
  894. { .hw_value = 12, .center_freq = 2467},
  895. { .hw_value = 13, .center_freq = 2472},
  896. };
  897. /* can't be const, mac80211 writes to this */
  898. static struct ieee80211_supported_band wl1271_band_2ghz = {
  899. .channels = wl1271_channels,
  900. .n_channels = ARRAY_SIZE(wl1271_channels),
  901. .bitrates = wl1271_rates,
  902. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  903. };
  904. static const struct ieee80211_ops wl1271_ops = {
  905. .start = wl1271_op_start,
  906. .stop = wl1271_op_stop,
  907. .add_interface = wl1271_op_add_interface,
  908. .remove_interface = wl1271_op_remove_interface,
  909. .config = wl1271_op_config,
  910. /* .config_interface = wl1271_op_config_interface, */
  911. .configure_filter = wl1271_op_configure_filter,
  912. .tx = wl1271_op_tx,
  913. .set_key = wl1271_op_set_key,
  914. .hw_scan = wl1271_op_hw_scan,
  915. .bss_info_changed = wl1271_op_bss_info_changed,
  916. .set_rts_threshold = wl1271_op_set_rts_threshold,
  917. };
  918. static int wl1271_register_hw(struct wl1271 *wl)
  919. {
  920. int ret;
  921. if (wl->mac80211_registered)
  922. return 0;
  923. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  924. ret = ieee80211_register_hw(wl->hw);
  925. if (ret < 0) {
  926. wl1271_error("unable to register mac80211 hw: %d", ret);
  927. return ret;
  928. }
  929. wl->mac80211_registered = true;
  930. wl1271_notice("loaded");
  931. return 0;
  932. }
  933. static int wl1271_init_ieee80211(struct wl1271 *wl)
  934. {
  935. /* The tx descriptor buffer and the TKIP space. */
  936. wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
  937. sizeof(struct wl1271_tx_hw_descr);
  938. /* unit us */
  939. /* FIXME: find a proper value */
  940. wl->hw->channel_change_time = 10000;
  941. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  942. IEEE80211_HW_NOISE_DBM;
  943. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  944. wl->hw->wiphy->max_scan_ssids = 1;
  945. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
  946. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  947. return 0;
  948. }
  949. static void wl1271_device_release(struct device *dev)
  950. {
  951. }
  952. static struct platform_device wl1271_device = {
  953. .name = "wl1271",
  954. .id = -1,
  955. /* device model insists to have a release function */
  956. .dev = {
  957. .release = wl1271_device_release,
  958. },
  959. };
  960. #define WL1271_DEFAULT_CHANNEL 0
  961. static int __devinit wl1271_probe(struct spi_device *spi)
  962. {
  963. struct wl12xx_platform_data *pdata;
  964. struct ieee80211_hw *hw;
  965. struct wl1271 *wl;
  966. int ret, i;
  967. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  968. pdata = spi->dev.platform_data;
  969. if (!pdata) {
  970. wl1271_error("no platform data");
  971. return -ENODEV;
  972. }
  973. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  974. if (!hw) {
  975. wl1271_error("could not alloc ieee80211_hw");
  976. return -ENOMEM;
  977. }
  978. wl = hw->priv;
  979. memset(wl, 0, sizeof(*wl));
  980. wl->hw = hw;
  981. dev_set_drvdata(&spi->dev, wl);
  982. wl->spi = spi;
  983. skb_queue_head_init(&wl->tx_queue);
  984. INIT_WORK(&wl->filter_work, wl1271_filter_work);
  985. INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
  986. wl->channel = WL1271_DEFAULT_CHANNEL;
  987. wl->scanning = false;
  988. wl->default_key = 0;
  989. wl->listen_int = 1;
  990. wl->rx_counter = 0;
  991. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  992. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  993. wl->elp = false;
  994. wl->psm = 0;
  995. wl->psm_requested = false;
  996. wl->tx_queue_stopped = false;
  997. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  998. wl->band = IEEE80211_BAND_2GHZ;
  999. /* We use the default power on sleep time until we know which chip
  1000. * we're using */
  1001. for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
  1002. wl->tx_frames[i] = NULL;
  1003. spin_lock_init(&wl->wl_lock);
  1004. /*
  1005. * In case our MAC address is not correctly set,
  1006. * we use a random but Nokia MAC.
  1007. */
  1008. memcpy(wl->mac_addr, nokia_oui, 3);
  1009. get_random_bytes(wl->mac_addr + 3, 3);
  1010. wl->state = WL1271_STATE_OFF;
  1011. mutex_init(&wl->mutex);
  1012. wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
  1013. if (!wl->rx_descriptor) {
  1014. wl1271_error("could not allocate memory for rx descriptor");
  1015. ret = -ENOMEM;
  1016. goto out_free;
  1017. }
  1018. /* This is the only SPI value that we need to set here, the rest
  1019. * comes from the board-peripherals file */
  1020. spi->bits_per_word = 32;
  1021. ret = spi_setup(spi);
  1022. if (ret < 0) {
  1023. wl1271_error("spi_setup failed");
  1024. goto out_free;
  1025. }
  1026. wl->set_power = pdata->set_power;
  1027. if (!wl->set_power) {
  1028. wl1271_error("set power function missing in platform data");
  1029. ret = -ENODEV;
  1030. goto out_free;
  1031. }
  1032. wl->irq = spi->irq;
  1033. if (wl->irq < 0) {
  1034. wl1271_error("irq missing in platform data");
  1035. ret = -ENODEV;
  1036. goto out_free;
  1037. }
  1038. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  1039. if (ret < 0) {
  1040. wl1271_error("request_irq() failed: %d", ret);
  1041. goto out_free;
  1042. }
  1043. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1044. disable_irq(wl->irq);
  1045. ret = platform_device_register(&wl1271_device);
  1046. if (ret) {
  1047. wl1271_error("couldn't register platform device");
  1048. goto out_irq;
  1049. }
  1050. dev_set_drvdata(&wl1271_device.dev, wl);
  1051. ret = wl1271_init_ieee80211(wl);
  1052. if (ret)
  1053. goto out_platform;
  1054. ret = wl1271_register_hw(wl);
  1055. if (ret)
  1056. goto out_platform;
  1057. wl1271_debugfs_init(wl);
  1058. wl1271_notice("initialized");
  1059. return 0;
  1060. out_platform:
  1061. platform_device_unregister(&wl1271_device);
  1062. out_irq:
  1063. free_irq(wl->irq, wl);
  1064. out_free:
  1065. kfree(wl->rx_descriptor);
  1066. wl->rx_descriptor = NULL;
  1067. ieee80211_free_hw(hw);
  1068. return ret;
  1069. }
  1070. static int __devexit wl1271_remove(struct spi_device *spi)
  1071. {
  1072. struct wl1271 *wl = dev_get_drvdata(&spi->dev);
  1073. ieee80211_unregister_hw(wl->hw);
  1074. wl1271_debugfs_exit(wl);
  1075. platform_device_unregister(&wl1271_device);
  1076. free_irq(wl->irq, wl);
  1077. kfree(wl->target_mem_map);
  1078. kfree(wl->fw);
  1079. wl->fw = NULL;
  1080. kfree(wl->nvs);
  1081. wl->nvs = NULL;
  1082. kfree(wl->rx_descriptor);
  1083. wl->rx_descriptor = NULL;
  1084. kfree(wl->fw_status);
  1085. kfree(wl->tx_res_if);
  1086. ieee80211_free_hw(wl->hw);
  1087. return 0;
  1088. }
  1089. static struct spi_driver wl1271_spi_driver = {
  1090. .driver = {
  1091. .name = "wl1271",
  1092. .bus = &spi_bus_type,
  1093. .owner = THIS_MODULE,
  1094. },
  1095. .probe = wl1271_probe,
  1096. .remove = __devexit_p(wl1271_remove),
  1097. };
  1098. static int __init wl1271_init(void)
  1099. {
  1100. int ret;
  1101. ret = spi_register_driver(&wl1271_spi_driver);
  1102. if (ret < 0) {
  1103. wl1271_error("failed to register spi driver: %d", ret);
  1104. goto out;
  1105. }
  1106. out:
  1107. return ret;
  1108. }
  1109. static void __exit wl1271_exit(void)
  1110. {
  1111. spi_unregister_driver(&wl1271_spi_driver);
  1112. wl1271_notice("unloaded");
  1113. }
  1114. module_init(wl1271_init);
  1115. module_exit(wl1271_exit);
  1116. MODULE_LICENSE("GPL");
  1117. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");