wl1271_main.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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. ieee80211_queue_work(wl->hw, &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. ieee80211_queue_work(wl->hw, &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. ret = wl1271_cmd_join(wl);
  313. if (ret < 0)
  314. goto out_sleep;
  315. out_sleep:
  316. wl1271_ps_elp_sleep(wl);
  317. out:
  318. mutex_unlock(&wl->mutex);
  319. }
  320. int wl1271_plt_start(struct wl1271 *wl)
  321. {
  322. int ret;
  323. mutex_lock(&wl->mutex);
  324. wl1271_notice("power up");
  325. if (wl->state != WL1271_STATE_OFF) {
  326. wl1271_error("cannot go into PLT state because not "
  327. "in off state: %d", wl->state);
  328. ret = -EBUSY;
  329. goto out;
  330. }
  331. wl->state = WL1271_STATE_PLT;
  332. ret = wl1271_chip_wakeup(wl);
  333. if (ret < 0)
  334. goto out;
  335. ret = wl1271_boot(wl);
  336. if (ret < 0)
  337. goto out;
  338. wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  339. ret = wl1271_plt_init(wl);
  340. if (ret < 0)
  341. goto out;
  342. out:
  343. mutex_unlock(&wl->mutex);
  344. return ret;
  345. }
  346. int wl1271_plt_stop(struct wl1271 *wl)
  347. {
  348. int ret = 0;
  349. mutex_lock(&wl->mutex);
  350. wl1271_notice("power down");
  351. if (wl->state != WL1271_STATE_PLT) {
  352. wl1271_error("cannot power down because not in PLT "
  353. "state: %d", wl->state);
  354. ret = -EBUSY;
  355. goto out;
  356. }
  357. wl1271_disable_interrupts(wl);
  358. wl1271_power_off(wl);
  359. wl->state = WL1271_STATE_OFF;
  360. out:
  361. mutex_unlock(&wl->mutex);
  362. return ret;
  363. }
  364. static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  365. {
  366. struct wl1271 *wl = hw->priv;
  367. skb_queue_tail(&wl->tx_queue, skb);
  368. /*
  369. * The chip specific setup must run before the first TX packet -
  370. * before that, the tx_work will not be initialized!
  371. */
  372. ieee80211_queue_work(wl->hw, &wl->tx_work);
  373. /*
  374. * The workqueue is slow to process the tx_queue and we need stop
  375. * the queue here, otherwise the queue will get too long.
  376. */
  377. if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
  378. ieee80211_stop_queues(wl->hw);
  379. /*
  380. * FIXME: this is racy, the variable is not properly
  381. * protected. Maybe fix this by removing the stupid
  382. * variable altogether and checking the real queue state?
  383. */
  384. wl->tx_queue_stopped = true;
  385. }
  386. return NETDEV_TX_OK;
  387. }
  388. static int wl1271_op_start(struct ieee80211_hw *hw)
  389. {
  390. struct wl1271 *wl = hw->priv;
  391. int ret = 0;
  392. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  393. mutex_lock(&wl->mutex);
  394. if (wl->state != WL1271_STATE_OFF) {
  395. wl1271_error("cannot start because not in off state: %d",
  396. wl->state);
  397. ret = -EBUSY;
  398. goto out;
  399. }
  400. ret = wl1271_chip_wakeup(wl);
  401. if (ret < 0)
  402. goto out;
  403. ret = wl1271_boot(wl);
  404. if (ret < 0)
  405. goto out;
  406. ret = wl1271_hw_init(wl);
  407. if (ret < 0)
  408. goto out;
  409. wl->state = WL1271_STATE_ON;
  410. wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
  411. out:
  412. if (ret < 0)
  413. wl1271_power_off(wl);
  414. mutex_unlock(&wl->mutex);
  415. return ret;
  416. }
  417. static void wl1271_op_stop(struct ieee80211_hw *hw)
  418. {
  419. struct wl1271 *wl = hw->priv;
  420. int i;
  421. wl1271_info("down");
  422. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  423. mutex_lock(&wl->mutex);
  424. WARN_ON(wl->state != WL1271_STATE_ON);
  425. if (wl->scanning) {
  426. mutex_unlock(&wl->mutex);
  427. ieee80211_scan_completed(wl->hw, true);
  428. mutex_lock(&wl->mutex);
  429. wl->scanning = false;
  430. }
  431. wl->state = WL1271_STATE_OFF;
  432. wl1271_disable_interrupts(wl);
  433. mutex_unlock(&wl->mutex);
  434. cancel_work_sync(&wl->irq_work);
  435. cancel_work_sync(&wl->tx_work);
  436. cancel_work_sync(&wl->filter_work);
  437. mutex_lock(&wl->mutex);
  438. /* let's notify MAC80211 about the remaining pending TX frames */
  439. wl1271_tx_flush(wl);
  440. wl1271_power_off(wl);
  441. memset(wl->bssid, 0, ETH_ALEN);
  442. memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
  443. wl->ssid_len = 0;
  444. wl->listen_int = 1;
  445. wl->bss_type = MAX_BSS_TYPE;
  446. wl->band = IEEE80211_BAND_2GHZ;
  447. wl->rx_counter = 0;
  448. wl->elp = false;
  449. wl->psm = 0;
  450. wl->tx_queue_stopped = false;
  451. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  452. wl->tx_blocks_available = 0;
  453. wl->tx_results_count = 0;
  454. wl->tx_packets_count = 0;
  455. wl->tx_security_last_seq = 0;
  456. wl->tx_security_seq_16 = 0;
  457. wl->tx_security_seq_32 = 0;
  458. wl->time_offset = 0;
  459. wl->session_counter = 0;
  460. for (i = 0; i < NUM_TX_QUEUES; i++)
  461. wl->tx_blocks_freed[i] = 0;
  462. wl1271_debugfs_reset(wl);
  463. mutex_unlock(&wl->mutex);
  464. }
  465. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  466. struct ieee80211_if_init_conf *conf)
  467. {
  468. struct wl1271 *wl = hw->priv;
  469. int ret = 0;
  470. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  471. conf->type, conf->mac_addr);
  472. mutex_lock(&wl->mutex);
  473. switch (conf->type) {
  474. case NL80211_IFTYPE_STATION:
  475. wl->bss_type = BSS_TYPE_STA_BSS;
  476. break;
  477. case NL80211_IFTYPE_ADHOC:
  478. wl->bss_type = BSS_TYPE_IBSS;
  479. break;
  480. default:
  481. ret = -EOPNOTSUPP;
  482. goto out;
  483. }
  484. /* FIXME: what if conf->mac_addr changes? */
  485. out:
  486. mutex_unlock(&wl->mutex);
  487. return ret;
  488. }
  489. static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
  490. struct ieee80211_if_init_conf *conf)
  491. {
  492. wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
  493. }
  494. #if 0
  495. static int wl1271_op_config_interface(struct ieee80211_hw *hw,
  496. struct ieee80211_vif *vif,
  497. struct ieee80211_if_conf *conf)
  498. {
  499. struct wl1271 *wl = hw->priv;
  500. struct sk_buff *beacon;
  501. int ret;
  502. wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
  503. conf->bssid);
  504. wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
  505. conf->ssid_len);
  506. mutex_lock(&wl->mutex);
  507. ret = wl1271_ps_elp_wakeup(wl, false);
  508. if (ret < 0)
  509. goto out;
  510. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  511. ret = wl1271_cmd_build_null_data(wl);
  512. if (ret < 0)
  513. goto out_sleep;
  514. wl->ssid_len = conf->ssid_len;
  515. if (wl->ssid_len)
  516. memcpy(wl->ssid, conf->ssid, wl->ssid_len);
  517. if (wl->bss_type != BSS_TYPE_IBSS) {
  518. ret = wl1271_cmd_join(wl);
  519. if (ret < 0)
  520. goto out_sleep;
  521. }
  522. if (conf->changed & IEEE80211_IFCC_BEACON) {
  523. beacon = ieee80211_beacon_get(hw, vif);
  524. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
  525. beacon->data, beacon->len);
  526. if (ret < 0) {
  527. dev_kfree_skb(beacon);
  528. goto out_sleep;
  529. }
  530. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
  531. beacon->data, beacon->len);
  532. dev_kfree_skb(beacon);
  533. if (ret < 0)
  534. goto out_sleep;
  535. ret = wl1271_cmd_join(wl);
  536. if (ret < 0)
  537. goto out_sleep;
  538. }
  539. out_sleep:
  540. wl1271_ps_elp_sleep(wl);
  541. out:
  542. mutex_unlock(&wl->mutex);
  543. return ret;
  544. }
  545. #endif
  546. static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
  547. {
  548. struct wl1271 *wl = hw->priv;
  549. struct ieee80211_conf *conf = &hw->conf;
  550. int channel, ret = 0;
  551. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  552. wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
  553. channel,
  554. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  555. conf->power_level);
  556. mutex_lock(&wl->mutex);
  557. wl->band = conf->channel->band;
  558. ret = wl1271_ps_elp_wakeup(wl, false);
  559. if (ret < 0)
  560. goto out;
  561. if (channel != wl->channel) {
  562. u8 old_channel = wl->channel;
  563. wl->channel = channel;
  564. ret = wl1271_cmd_join(wl);
  565. if (ret < 0) {
  566. wl->channel = old_channel;
  567. goto out_sleep;
  568. }
  569. }
  570. ret = wl1271_cmd_build_null_data(wl);
  571. if (ret < 0)
  572. goto out_sleep;
  573. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  574. wl1271_info("psm enabled");
  575. wl->psm_requested = true;
  576. /*
  577. * We enter PSM only if we're already associated.
  578. * If we're not, we'll enter it when joining an SSID,
  579. * through the bss_info_changed() hook.
  580. */
  581. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  582. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  583. wl->psm_requested) {
  584. wl1271_info("psm disabled");
  585. wl->psm_requested = false;
  586. if (wl->psm)
  587. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE);
  588. }
  589. if (conf->power_level != wl->power_level) {
  590. ret = wl1271_acx_tx_power(wl, conf->power_level);
  591. if (ret < 0)
  592. goto out;
  593. wl->power_level = conf->power_level;
  594. }
  595. out_sleep:
  596. wl1271_ps_elp_sleep(wl);
  597. out:
  598. mutex_unlock(&wl->mutex);
  599. return ret;
  600. }
  601. #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  602. FIF_ALLMULTI | \
  603. FIF_FCSFAIL | \
  604. FIF_BCN_PRBRESP_PROMISC | \
  605. FIF_CONTROL | \
  606. FIF_OTHER_BSS)
  607. static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
  608. unsigned int changed,
  609. unsigned int *total,u64 multicast)
  610. {
  611. struct wl1271 *wl = hw->priv;
  612. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
  613. *total &= WL1271_SUPPORTED_FILTERS;
  614. changed &= WL1271_SUPPORTED_FILTERS;
  615. if (changed == 0)
  616. return;
  617. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  618. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  619. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  620. /*
  621. * FIXME: workqueues need to be properly cancelled on stop(), for
  622. * now let's just disable changing the filter settings. They will
  623. * be updated any on config().
  624. */
  625. /* schedule_work(&wl->filter_work); */
  626. }
  627. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  628. struct ieee80211_vif *vif,
  629. struct ieee80211_sta *sta,
  630. struct ieee80211_key_conf *key_conf)
  631. {
  632. struct wl1271 *wl = hw->priv;
  633. const u8 *addr;
  634. int ret;
  635. u32 tx_seq_32 = 0;
  636. u16 tx_seq_16 = 0;
  637. u8 key_type;
  638. static const u8 bcast_addr[ETH_ALEN] =
  639. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  640. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  641. addr = sta ? sta->addr : bcast_addr;
  642. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  643. wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  644. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  645. key_conf->alg, key_conf->keyidx,
  646. key_conf->keylen, key_conf->flags);
  647. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  648. if (is_zero_ether_addr(addr)) {
  649. /* We dont support TX only encryption */
  650. ret = -EOPNOTSUPP;
  651. goto out;
  652. }
  653. mutex_lock(&wl->mutex);
  654. ret = wl1271_ps_elp_wakeup(wl, false);
  655. if (ret < 0)
  656. goto out_unlock;
  657. switch (key_conf->alg) {
  658. case ALG_WEP:
  659. key_type = KEY_WEP;
  660. key_conf->hw_key_idx = key_conf->keyidx;
  661. break;
  662. case ALG_TKIP:
  663. key_type = KEY_TKIP;
  664. key_conf->hw_key_idx = key_conf->keyidx;
  665. tx_seq_32 = wl->tx_security_seq_32;
  666. tx_seq_16 = wl->tx_security_seq_16;
  667. break;
  668. case ALG_CCMP:
  669. key_type = KEY_AES;
  670. key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  671. tx_seq_32 = wl->tx_security_seq_32;
  672. tx_seq_16 = wl->tx_security_seq_16;
  673. break;
  674. default:
  675. wl1271_error("Unknown key algo 0x%x", key_conf->alg);
  676. ret = -EOPNOTSUPP;
  677. goto out_sleep;
  678. }
  679. switch (cmd) {
  680. case SET_KEY:
  681. ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
  682. key_conf->keyidx, key_type,
  683. key_conf->keylen, key_conf->key,
  684. addr, tx_seq_32, tx_seq_16);
  685. if (ret < 0) {
  686. wl1271_error("Could not add or replace key");
  687. goto out_sleep;
  688. }
  689. break;
  690. case DISABLE_KEY:
  691. ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
  692. key_conf->keyidx, key_type,
  693. key_conf->keylen, key_conf->key,
  694. addr, 0, 0);
  695. if (ret < 0) {
  696. wl1271_error("Could not remove key");
  697. goto out_sleep;
  698. }
  699. break;
  700. default:
  701. wl1271_error("Unsupported key cmd 0x%x", cmd);
  702. ret = -EOPNOTSUPP;
  703. goto out_sleep;
  704. break;
  705. }
  706. out_sleep:
  707. wl1271_ps_elp_sleep(wl);
  708. out_unlock:
  709. mutex_unlock(&wl->mutex);
  710. out:
  711. return ret;
  712. }
  713. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  714. struct cfg80211_scan_request *req)
  715. {
  716. struct wl1271 *wl = hw->priv;
  717. int ret;
  718. u8 *ssid = NULL;
  719. size_t ssid_len = 0;
  720. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  721. if (req->n_ssids) {
  722. ssid = req->ssids[0].ssid;
  723. ssid_len = req->ssids[0].ssid_len;
  724. }
  725. mutex_lock(&wl->mutex);
  726. ret = wl1271_ps_elp_wakeup(wl, false);
  727. if (ret < 0)
  728. goto out;
  729. ret = wl1271_cmd_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
  730. wl1271_ps_elp_sleep(wl);
  731. out:
  732. mutex_unlock(&wl->mutex);
  733. return ret;
  734. }
  735. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  736. {
  737. struct wl1271 *wl = hw->priv;
  738. int ret;
  739. mutex_lock(&wl->mutex);
  740. ret = wl1271_ps_elp_wakeup(wl, false);
  741. if (ret < 0)
  742. goto out;
  743. ret = wl1271_acx_rts_threshold(wl, (u16) value);
  744. if (ret < 0)
  745. wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
  746. wl1271_ps_elp_sleep(wl);
  747. out:
  748. mutex_unlock(&wl->mutex);
  749. return ret;
  750. }
  751. static u32 wl1271_enabled_rates_get(struct wl1271 *wl, u64 basic_rate_set)
  752. {
  753. struct ieee80211_supported_band *band;
  754. u32 enabled_rates = 0;
  755. int bit;
  756. band = wl->hw->wiphy->bands[wl->band];
  757. for (bit = 0; bit < band->n_bitrates; bit++) {
  758. if (basic_rate_set & 0x1)
  759. enabled_rates |= band->bitrates[bit].hw_value;
  760. basic_rate_set >>= 1;
  761. }
  762. return enabled_rates;
  763. }
  764. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  765. struct ieee80211_vif *vif,
  766. struct ieee80211_bss_conf *bss_conf,
  767. u32 changed)
  768. {
  769. enum wl1271_cmd_ps_mode mode;
  770. struct wl1271 *wl = hw->priv;
  771. int ret;
  772. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  773. mutex_lock(&wl->mutex);
  774. ret = wl1271_ps_elp_wakeup(wl, false);
  775. if (ret < 0)
  776. goto out;
  777. if (changed & BSS_CHANGED_ASSOC) {
  778. if (bss_conf->assoc) {
  779. wl->beacon_int = bss_conf->beacon_int;
  780. wl->dtim_period = bss_conf->dtim_period;
  781. wl->aid = bss_conf->aid;
  782. ret = wl1271_cmd_join(wl);
  783. if (ret < 0) {
  784. wl1271_warning("Association configuration "
  785. "failed %d", ret);
  786. goto out_sleep;
  787. }
  788. ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
  789. if (ret < 0)
  790. goto out_sleep;
  791. ret = wl1271_acx_aid(wl, wl->aid);
  792. if (ret < 0)
  793. goto out_sleep;
  794. /* If we want to go in PSM but we're not there yet */
  795. if (wl->psm_requested && !wl->psm) {
  796. mode = STATION_POWER_SAVE_MODE;
  797. ret = wl1271_ps_set_mode(wl, mode);
  798. if (ret < 0)
  799. goto out_sleep;
  800. }
  801. } else {
  802. /* use defaults when not associated */
  803. wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
  804. wl->dtim_period = WL1271_DEFAULT_DTIM_PERIOD;
  805. wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET;
  806. wl->aid = 0;
  807. }
  808. }
  809. if (changed & BSS_CHANGED_ERP_SLOT) {
  810. if (bss_conf->use_short_slot)
  811. ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
  812. else
  813. ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
  814. if (ret < 0) {
  815. wl1271_warning("Set slot time failed %d", ret);
  816. goto out_sleep;
  817. }
  818. }
  819. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  820. if (bss_conf->use_short_preamble)
  821. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  822. else
  823. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  824. }
  825. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  826. if (bss_conf->use_cts_prot)
  827. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  828. else
  829. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  830. if (ret < 0) {
  831. wl1271_warning("Set ctsprotect failed %d", ret);
  832. goto out_sleep;
  833. }
  834. }
  835. if (changed & BSS_CHANGED_BASIC_RATES) {
  836. wl->basic_rate_set = wl1271_enabled_rates_get(
  837. wl, bss_conf->basic_rates);
  838. ret = wl1271_acx_rate_policies(wl, wl->basic_rate_set);
  839. if (ret < 0) {
  840. wl1271_warning("Set rate policies failed %d", ret);
  841. goto out_sleep;
  842. }
  843. ret = wl1271_cmd_join(wl);
  844. if (ret < 0) {
  845. wl1271_warning("Join with new basic rate "
  846. "set failed %d", ret);
  847. goto out_sleep;
  848. }
  849. }
  850. out_sleep:
  851. wl1271_ps_elp_sleep(wl);
  852. out:
  853. mutex_unlock(&wl->mutex);
  854. }
  855. /* can't be const, mac80211 writes to this */
  856. static struct ieee80211_rate wl1271_rates[] = {
  857. { .bitrate = 10,
  858. .hw_value = 0x1,
  859. .hw_value_short = 0x1, },
  860. { .bitrate = 20,
  861. .hw_value = 0x2,
  862. .hw_value_short = 0x2,
  863. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  864. { .bitrate = 55,
  865. .hw_value = 0x4,
  866. .hw_value_short = 0x4,
  867. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  868. { .bitrate = 110,
  869. .hw_value = 0x20,
  870. .hw_value_short = 0x20,
  871. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  872. { .bitrate = 60,
  873. .hw_value = 0x8,
  874. .hw_value_short = 0x8, },
  875. { .bitrate = 90,
  876. .hw_value = 0x10,
  877. .hw_value_short = 0x10, },
  878. { .bitrate = 120,
  879. .hw_value = 0x40,
  880. .hw_value_short = 0x40, },
  881. { .bitrate = 180,
  882. .hw_value = 0x80,
  883. .hw_value_short = 0x80, },
  884. { .bitrate = 240,
  885. .hw_value = 0x200,
  886. .hw_value_short = 0x200, },
  887. { .bitrate = 360,
  888. .hw_value = 0x400,
  889. .hw_value_short = 0x400, },
  890. { .bitrate = 480,
  891. .hw_value = 0x800,
  892. .hw_value_short = 0x800, },
  893. { .bitrate = 540,
  894. .hw_value = 0x1000,
  895. .hw_value_short = 0x1000, },
  896. };
  897. /* can't be const, mac80211 writes to this */
  898. static struct ieee80211_channel wl1271_channels[] = {
  899. { .hw_value = 1, .center_freq = 2412},
  900. { .hw_value = 2, .center_freq = 2417},
  901. { .hw_value = 3, .center_freq = 2422},
  902. { .hw_value = 4, .center_freq = 2427},
  903. { .hw_value = 5, .center_freq = 2432},
  904. { .hw_value = 6, .center_freq = 2437},
  905. { .hw_value = 7, .center_freq = 2442},
  906. { .hw_value = 8, .center_freq = 2447},
  907. { .hw_value = 9, .center_freq = 2452},
  908. { .hw_value = 10, .center_freq = 2457},
  909. { .hw_value = 11, .center_freq = 2462},
  910. { .hw_value = 12, .center_freq = 2467},
  911. { .hw_value = 13, .center_freq = 2472},
  912. };
  913. /* can't be const, mac80211 writes to this */
  914. static struct ieee80211_supported_band wl1271_band_2ghz = {
  915. .channels = wl1271_channels,
  916. .n_channels = ARRAY_SIZE(wl1271_channels),
  917. .bitrates = wl1271_rates,
  918. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  919. };
  920. static const struct ieee80211_ops wl1271_ops = {
  921. .start = wl1271_op_start,
  922. .stop = wl1271_op_stop,
  923. .add_interface = wl1271_op_add_interface,
  924. .remove_interface = wl1271_op_remove_interface,
  925. .config = wl1271_op_config,
  926. /* .config_interface = wl1271_op_config_interface, */
  927. .configure_filter = wl1271_op_configure_filter,
  928. .tx = wl1271_op_tx,
  929. .set_key = wl1271_op_set_key,
  930. .hw_scan = wl1271_op_hw_scan,
  931. .bss_info_changed = wl1271_op_bss_info_changed,
  932. .set_rts_threshold = wl1271_op_set_rts_threshold,
  933. };
  934. static int wl1271_register_hw(struct wl1271 *wl)
  935. {
  936. int ret;
  937. if (wl->mac80211_registered)
  938. return 0;
  939. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  940. ret = ieee80211_register_hw(wl->hw);
  941. if (ret < 0) {
  942. wl1271_error("unable to register mac80211 hw: %d", ret);
  943. return ret;
  944. }
  945. wl->mac80211_registered = true;
  946. wl1271_notice("loaded");
  947. return 0;
  948. }
  949. static int wl1271_init_ieee80211(struct wl1271 *wl)
  950. {
  951. /* The tx descriptor buffer and the TKIP space. */
  952. wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
  953. sizeof(struct wl1271_tx_hw_descr);
  954. /* unit us */
  955. /* FIXME: find a proper value */
  956. wl->hw->channel_change_time = 10000;
  957. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  958. IEEE80211_HW_NOISE_DBM;
  959. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  960. wl->hw->wiphy->max_scan_ssids = 1;
  961. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
  962. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  963. return 0;
  964. }
  965. static void wl1271_device_release(struct device *dev)
  966. {
  967. }
  968. static struct platform_device wl1271_device = {
  969. .name = "wl1271",
  970. .id = -1,
  971. /* device model insists to have a release function */
  972. .dev = {
  973. .release = wl1271_device_release,
  974. },
  975. };
  976. #define WL1271_DEFAULT_CHANNEL 0
  977. static int __devinit wl1271_probe(struct spi_device *spi)
  978. {
  979. struct wl12xx_platform_data *pdata;
  980. struct ieee80211_hw *hw;
  981. struct wl1271 *wl;
  982. int ret, i;
  983. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  984. pdata = spi->dev.platform_data;
  985. if (!pdata) {
  986. wl1271_error("no platform data");
  987. return -ENODEV;
  988. }
  989. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  990. if (!hw) {
  991. wl1271_error("could not alloc ieee80211_hw");
  992. return -ENOMEM;
  993. }
  994. wl = hw->priv;
  995. memset(wl, 0, sizeof(*wl));
  996. wl->hw = hw;
  997. dev_set_drvdata(&spi->dev, wl);
  998. wl->spi = spi;
  999. skb_queue_head_init(&wl->tx_queue);
  1000. INIT_WORK(&wl->filter_work, wl1271_filter_work);
  1001. INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
  1002. wl->channel = WL1271_DEFAULT_CHANNEL;
  1003. wl->scanning = false;
  1004. wl->default_key = 0;
  1005. wl->listen_int = 1;
  1006. wl->rx_counter = 0;
  1007. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  1008. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  1009. wl->elp = false;
  1010. wl->psm = 0;
  1011. wl->psm_requested = false;
  1012. wl->tx_queue_stopped = false;
  1013. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  1014. wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
  1015. wl->dtim_period = WL1271_DEFAULT_DTIM_PERIOD;
  1016. wl->basic_rate_set = WL1271_DEFAULT_BASIC_RATE_SET;
  1017. wl->band = IEEE80211_BAND_2GHZ;
  1018. for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
  1019. wl->tx_frames[i] = NULL;
  1020. spin_lock_init(&wl->wl_lock);
  1021. /*
  1022. * In case our MAC address is not correctly set,
  1023. * we use a random but Nokia MAC.
  1024. */
  1025. memcpy(wl->mac_addr, nokia_oui, 3);
  1026. get_random_bytes(wl->mac_addr + 3, 3);
  1027. wl->state = WL1271_STATE_OFF;
  1028. mutex_init(&wl->mutex);
  1029. wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
  1030. if (!wl->rx_descriptor) {
  1031. wl1271_error("could not allocate memory for rx descriptor");
  1032. ret = -ENOMEM;
  1033. goto out_free;
  1034. }
  1035. /* This is the only SPI value that we need to set here, the rest
  1036. * comes from the board-peripherals file */
  1037. spi->bits_per_word = 32;
  1038. ret = spi_setup(spi);
  1039. if (ret < 0) {
  1040. wl1271_error("spi_setup failed");
  1041. goto out_free;
  1042. }
  1043. wl->set_power = pdata->set_power;
  1044. if (!wl->set_power) {
  1045. wl1271_error("set power function missing in platform data");
  1046. ret = -ENODEV;
  1047. goto out_free;
  1048. }
  1049. wl->irq = spi->irq;
  1050. if (wl->irq < 0) {
  1051. wl1271_error("irq missing in platform data");
  1052. ret = -ENODEV;
  1053. goto out_free;
  1054. }
  1055. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  1056. if (ret < 0) {
  1057. wl1271_error("request_irq() failed: %d", ret);
  1058. goto out_free;
  1059. }
  1060. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1061. disable_irq(wl->irq);
  1062. ret = platform_device_register(&wl1271_device);
  1063. if (ret) {
  1064. wl1271_error("couldn't register platform device");
  1065. goto out_irq;
  1066. }
  1067. dev_set_drvdata(&wl1271_device.dev, wl);
  1068. ret = wl1271_init_ieee80211(wl);
  1069. if (ret)
  1070. goto out_platform;
  1071. ret = wl1271_register_hw(wl);
  1072. if (ret)
  1073. goto out_platform;
  1074. wl1271_debugfs_init(wl);
  1075. wl1271_notice("initialized");
  1076. return 0;
  1077. out_platform:
  1078. platform_device_unregister(&wl1271_device);
  1079. out_irq:
  1080. free_irq(wl->irq, wl);
  1081. out_free:
  1082. kfree(wl->rx_descriptor);
  1083. wl->rx_descriptor = NULL;
  1084. ieee80211_free_hw(hw);
  1085. return ret;
  1086. }
  1087. static int __devexit wl1271_remove(struct spi_device *spi)
  1088. {
  1089. struct wl1271 *wl = dev_get_drvdata(&spi->dev);
  1090. ieee80211_unregister_hw(wl->hw);
  1091. wl1271_debugfs_exit(wl);
  1092. platform_device_unregister(&wl1271_device);
  1093. free_irq(wl->irq, wl);
  1094. kfree(wl->target_mem_map);
  1095. kfree(wl->fw);
  1096. wl->fw = NULL;
  1097. kfree(wl->nvs);
  1098. wl->nvs = NULL;
  1099. kfree(wl->rx_descriptor);
  1100. wl->rx_descriptor = NULL;
  1101. kfree(wl->fw_status);
  1102. kfree(wl->tx_res_if);
  1103. ieee80211_free_hw(wl->hw);
  1104. return 0;
  1105. }
  1106. static struct spi_driver wl1271_spi_driver = {
  1107. .driver = {
  1108. .name = "wl1271",
  1109. .bus = &spi_bus_type,
  1110. .owner = THIS_MODULE,
  1111. },
  1112. .probe = wl1271_probe,
  1113. .remove = __devexit_p(wl1271_remove),
  1114. };
  1115. static int __init wl1271_init(void)
  1116. {
  1117. int ret;
  1118. ret = spi_register_driver(&wl1271_spi_driver);
  1119. if (ret < 0) {
  1120. wl1271_error("failed to register spi driver: %d", ret);
  1121. goto out;
  1122. }
  1123. out:
  1124. return ret;
  1125. }
  1126. static void __exit wl1271_exit(void)
  1127. {
  1128. spi_unregister_driver(&wl1271_spi_driver);
  1129. wl1271_notice("unloaded");
  1130. }
  1131. module_init(wl1271_init);
  1132. module_exit(wl1271_exit);
  1133. MODULE_LICENSE("GPL");
  1134. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
  1135. MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");