main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. /*
  2. * This file is part of wl12xx
  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/spi/spi.h>
  29. #include <linux/crc32.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/spi/wl12xx.h>
  32. #include "wl12xx.h"
  33. #include "wl12xx_80211.h"
  34. #include "reg.h"
  35. #include "wl1251.h"
  36. #include "spi.h"
  37. #include "event.h"
  38. #include "tx.h"
  39. #include "rx.h"
  40. #include "ps.h"
  41. #include "init.h"
  42. #include "debugfs.h"
  43. static void wl12xx_disable_interrupts(struct wl12xx *wl)
  44. {
  45. disable_irq(wl->irq);
  46. }
  47. static void wl12xx_power_off(struct wl12xx *wl)
  48. {
  49. wl->set_power(false);
  50. }
  51. static void wl12xx_power_on(struct wl12xx *wl)
  52. {
  53. wl->set_power(true);
  54. }
  55. static irqreturn_t wl12xx_irq(int irq, void *cookie)
  56. {
  57. struct wl12xx *wl;
  58. wl12xx_debug(DEBUG_IRQ, "IRQ");
  59. wl = cookie;
  60. schedule_work(&wl->irq_work);
  61. return IRQ_HANDLED;
  62. }
  63. static int wl12xx_fetch_firmware(struct wl12xx *wl)
  64. {
  65. const struct firmware *fw;
  66. int ret;
  67. ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev);
  68. if (ret < 0) {
  69. wl12xx_error("could not get firmware: %d", ret);
  70. return ret;
  71. }
  72. if (fw->size % 4) {
  73. wl12xx_error("firmware size is not multiple of 32 bits: %zu",
  74. fw->size);
  75. ret = -EILSEQ;
  76. goto out;
  77. }
  78. wl->fw_len = fw->size;
  79. wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
  80. if (!wl->fw) {
  81. wl12xx_error("could not allocate memory for the firmware");
  82. ret = -ENOMEM;
  83. goto out;
  84. }
  85. memcpy(wl->fw, fw->data, wl->fw_len);
  86. ret = 0;
  87. out:
  88. release_firmware(fw);
  89. return ret;
  90. }
  91. static int wl12xx_fetch_nvs(struct wl12xx *wl)
  92. {
  93. const struct firmware *fw;
  94. int ret;
  95. ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev);
  96. if (ret < 0) {
  97. wl12xx_error("could not get nvs file: %d", ret);
  98. return ret;
  99. }
  100. if (fw->size % 4) {
  101. wl12xx_error("nvs size is not multiple of 32 bits: %zu",
  102. fw->size);
  103. ret = -EILSEQ;
  104. goto out;
  105. }
  106. wl->nvs_len = fw->size;
  107. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  108. if (!wl->nvs) {
  109. wl12xx_error("could not allocate memory for the nvs file");
  110. ret = -ENOMEM;
  111. goto out;
  112. }
  113. memcpy(wl->nvs, fw->data, wl->nvs_len);
  114. ret = 0;
  115. out:
  116. release_firmware(fw);
  117. return ret;
  118. }
  119. static void wl12xx_fw_wakeup(struct wl12xx *wl)
  120. {
  121. u32 elp_reg;
  122. elp_reg = ELPCTRL_WAKE_UP;
  123. wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  124. elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
  125. if (!(elp_reg & ELPCTRL_WLAN_READY)) {
  126. wl12xx_warning("WLAN not ready");
  127. elp_reg = ELPCTRL_WAKE_UP_WLAN_READY;
  128. wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  129. }
  130. }
  131. static int wl12xx_chip_wakeup(struct wl12xx *wl)
  132. {
  133. int ret = 0;
  134. wl12xx_power_on(wl);
  135. msleep(wl->chip.power_on_sleep);
  136. wl12xx_spi_reset(wl);
  137. wl12xx_spi_init(wl);
  138. /* We don't need a real memory partition here, because we only want
  139. * to use the registers at this point. */
  140. wl12xx_set_partition(wl,
  141. 0x00000000,
  142. 0x00000000,
  143. REGISTERS_BASE,
  144. REGISTERS_DOWN_SIZE);
  145. /* ELP module wake up */
  146. wl12xx_fw_wakeup(wl);
  147. /* whal_FwCtrl_BootSm() */
  148. /* 0. read chip id from CHIP_ID */
  149. wl->chip.id = wl12xx_reg_read32(wl, CHIP_ID_B);
  150. /* 1. check if chip id is valid */
  151. switch (wl->chip.id) {
  152. case CHIP_ID_1251_PG12:
  153. wl12xx_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
  154. wl->chip.id);
  155. wl1251_setup(wl);
  156. break;
  157. case CHIP_ID_1271_PG10:
  158. case CHIP_ID_1251_PG10:
  159. case CHIP_ID_1251_PG11:
  160. default:
  161. wl12xx_error("unsupported chip id: 0x%x", wl->chip.id);
  162. ret = -ENODEV;
  163. goto out;
  164. }
  165. if (wl->fw == NULL) {
  166. ret = wl12xx_fetch_firmware(wl);
  167. if (ret < 0)
  168. goto out;
  169. }
  170. /* No NVS from netlink, try to get it from the filesystem */
  171. if (wl->nvs == NULL) {
  172. ret = wl12xx_fetch_nvs(wl);
  173. if (ret < 0)
  174. goto out;
  175. }
  176. out:
  177. return ret;
  178. }
  179. static void wl12xx_filter_work(struct work_struct *work)
  180. {
  181. struct wl12xx *wl =
  182. container_of(work, struct wl12xx, filter_work);
  183. int ret;
  184. mutex_lock(&wl->mutex);
  185. if (wl->state == WL12XX_STATE_OFF)
  186. goto out;
  187. ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
  188. if (ret < 0)
  189. goto out;
  190. out:
  191. mutex_unlock(&wl->mutex);
  192. }
  193. int wl12xx_plt_start(struct wl12xx *wl)
  194. {
  195. int ret;
  196. wl12xx_notice("power up");
  197. if (wl->state != WL12XX_STATE_OFF) {
  198. wl12xx_error("cannot go into PLT state because not "
  199. "in off state: %d", wl->state);
  200. return -EBUSY;
  201. }
  202. wl->state = WL12XX_STATE_PLT;
  203. ret = wl12xx_chip_wakeup(wl);
  204. if (ret < 0)
  205. return ret;
  206. ret = wl->chip.op_boot(wl);
  207. if (ret < 0)
  208. return ret;
  209. wl12xx_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  210. ret = wl->chip.op_plt_init(wl);
  211. if (ret < 0)
  212. return ret;
  213. return 0;
  214. }
  215. int wl12xx_plt_stop(struct wl12xx *wl)
  216. {
  217. wl12xx_notice("power down");
  218. if (wl->state != WL12XX_STATE_PLT) {
  219. wl12xx_error("cannot power down because not in PLT "
  220. "state: %d", wl->state);
  221. return -EBUSY;
  222. }
  223. wl12xx_disable_interrupts(wl);
  224. wl12xx_power_off(wl);
  225. wl->state = WL12XX_STATE_OFF;
  226. return 0;
  227. }
  228. static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  229. {
  230. struct wl12xx *wl = hw->priv;
  231. skb_queue_tail(&wl->tx_queue, skb);
  232. schedule_work(&wl->tx_work);
  233. /*
  234. * The workqueue is slow to process the tx_queue and we need stop
  235. * the queue here, otherwise the queue will get too long.
  236. */
  237. if (skb_queue_len(&wl->tx_queue) >= WL12XX_TX_QUEUE_MAX_LENGTH) {
  238. ieee80211_stop_queues(wl->hw);
  239. /*
  240. * FIXME: this is racy, the variable is not properly
  241. * protected. Maybe fix this by removing the stupid
  242. * variable altogether and checking the real queue state?
  243. */
  244. wl->tx_queue_stopped = true;
  245. }
  246. return NETDEV_TX_OK;
  247. }
  248. static int wl12xx_op_start(struct ieee80211_hw *hw)
  249. {
  250. struct wl12xx *wl = hw->priv;
  251. int ret = 0;
  252. wl12xx_debug(DEBUG_MAC80211, "mac80211 start");
  253. mutex_lock(&wl->mutex);
  254. if (wl->state != WL12XX_STATE_OFF) {
  255. wl12xx_error("cannot start because not in off state: %d",
  256. wl->state);
  257. ret = -EBUSY;
  258. goto out;
  259. }
  260. ret = wl12xx_chip_wakeup(wl);
  261. if (ret < 0)
  262. return ret;
  263. ret = wl->chip.op_boot(wl);
  264. if (ret < 0)
  265. goto out;
  266. ret = wl->chip.op_hw_init(wl);
  267. if (ret < 0)
  268. goto out;
  269. ret = wl12xx_acx_station_id(wl);
  270. if (ret < 0)
  271. goto out;
  272. wl->state = WL12XX_STATE_ON;
  273. wl12xx_info("firmware booted (%s)", wl->chip.fw_ver);
  274. out:
  275. if (ret < 0)
  276. wl12xx_power_off(wl);
  277. mutex_unlock(&wl->mutex);
  278. return ret;
  279. }
  280. static void wl12xx_op_stop(struct ieee80211_hw *hw)
  281. {
  282. struct wl12xx *wl = hw->priv;
  283. wl12xx_info("down");
  284. wl12xx_debug(DEBUG_MAC80211, "mac80211 stop");
  285. mutex_lock(&wl->mutex);
  286. WARN_ON(wl->state != WL12XX_STATE_ON);
  287. if (wl->scanning) {
  288. mutex_unlock(&wl->mutex);
  289. ieee80211_scan_completed(wl->hw, true);
  290. mutex_lock(&wl->mutex);
  291. wl->scanning = false;
  292. }
  293. wl->state = WL12XX_STATE_OFF;
  294. wl12xx_disable_interrupts(wl);
  295. mutex_unlock(&wl->mutex);
  296. cancel_work_sync(&wl->irq_work);
  297. cancel_work_sync(&wl->tx_work);
  298. cancel_work_sync(&wl->filter_work);
  299. mutex_lock(&wl->mutex);
  300. /* let's notify MAC80211 about the remaining pending TX frames */
  301. wl12xx_tx_flush(wl);
  302. wl12xx_power_off(wl);
  303. memset(wl->bssid, 0, ETH_ALEN);
  304. wl->listen_int = 1;
  305. wl->bss_type = MAX_BSS_TYPE;
  306. wl->data_in_count = 0;
  307. wl->rx_counter = 0;
  308. wl->rx_handled = 0;
  309. wl->rx_current_buffer = 0;
  310. wl->rx_last_id = 0;
  311. wl->next_tx_complete = 0;
  312. wl->elp = false;
  313. wl->psm = 0;
  314. wl->tx_queue_stopped = false;
  315. wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
  316. wl12xx_debugfs_reset(wl);
  317. mutex_unlock(&wl->mutex);
  318. }
  319. static int wl12xx_op_add_interface(struct ieee80211_hw *hw,
  320. struct ieee80211_if_init_conf *conf)
  321. {
  322. struct wl12xx *wl = hw->priv;
  323. DECLARE_MAC_BUF(mac);
  324. int ret = 0;
  325. wl12xx_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
  326. conf->type, print_mac(mac, conf->mac_addr));
  327. mutex_lock(&wl->mutex);
  328. switch (conf->type) {
  329. case NL80211_IFTYPE_STATION:
  330. wl->bss_type = BSS_TYPE_STA_BSS;
  331. break;
  332. case NL80211_IFTYPE_ADHOC:
  333. wl->bss_type = BSS_TYPE_IBSS;
  334. break;
  335. default:
  336. ret = -EOPNOTSUPP;
  337. goto out;
  338. }
  339. if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
  340. memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
  341. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  342. ret = wl12xx_acx_station_id(wl);
  343. if (ret < 0)
  344. goto out;
  345. }
  346. out:
  347. mutex_unlock(&wl->mutex);
  348. return ret;
  349. }
  350. static void wl12xx_op_remove_interface(struct ieee80211_hw *hw,
  351. struct ieee80211_if_init_conf *conf)
  352. {
  353. wl12xx_debug(DEBUG_MAC80211, "mac80211 remove interface");
  354. }
  355. static int wl12xx_build_null_data(struct wl12xx *wl)
  356. {
  357. struct wl12xx_null_data_template template;
  358. if (!is_zero_ether_addr(wl->bssid)) {
  359. memcpy(template.header.da, wl->bssid, ETH_ALEN);
  360. memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
  361. } else {
  362. memset(template.header.da, 0xff, ETH_ALEN);
  363. memset(template.header.bssid, 0xff, ETH_ALEN);
  364. }
  365. memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
  366. template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
  367. IEEE80211_STYPE_NULLFUNC);
  368. return wl12xx_cmd_template_set(wl, CMD_NULL_DATA, &template,
  369. sizeof(template));
  370. }
  371. static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid)
  372. {
  373. struct wl12xx_ps_poll_template template;
  374. memcpy(template.bssid, wl->bssid, ETH_ALEN);
  375. memcpy(template.ta, wl->mac_addr, ETH_ALEN);
  376. template.aid = aid;
  377. template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
  378. return wl12xx_cmd_template_set(wl, CMD_PS_POLL, &template,
  379. sizeof(template));
  380. }
  381. static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed)
  382. {
  383. struct wl12xx *wl = hw->priv;
  384. struct ieee80211_conf *conf = &hw->conf;
  385. int channel, ret = 0;
  386. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  387. wl12xx_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
  388. channel,
  389. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  390. conf->power_level);
  391. mutex_lock(&wl->mutex);
  392. if (channel != wl->channel) {
  393. /* FIXME: use beacon interval provided by mac80211 */
  394. ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
  395. if (ret < 0)
  396. goto out;
  397. wl->channel = channel;
  398. }
  399. ret = wl12xx_build_null_data(wl);
  400. if (ret < 0)
  401. goto out;
  402. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  403. wl12xx_info("psm enabled");
  404. wl->psm_requested = true;
  405. /*
  406. * We enter PSM only if we're already associated.
  407. * If we're not, we'll enter it when joining an SSID,
  408. * through the bss_info_changed() hook.
  409. */
  410. ret = wl12xx_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  411. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  412. wl->psm_requested) {
  413. wl12xx_info("psm disabled");
  414. wl->psm_requested = false;
  415. if (wl->psm)
  416. ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE);
  417. }
  418. if (conf->power_level != wl->power_level) {
  419. ret = wl12xx_acx_tx_power(wl, conf->power_level);
  420. if (ret < 0)
  421. goto out;
  422. wl->power_level = conf->power_level;
  423. }
  424. out:
  425. mutex_unlock(&wl->mutex);
  426. return ret;
  427. }
  428. #define WL12XX_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  429. FIF_ALLMULTI | \
  430. FIF_FCSFAIL | \
  431. FIF_BCN_PRBRESP_PROMISC | \
  432. FIF_CONTROL | \
  433. FIF_OTHER_BSS)
  434. static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
  435. unsigned int changed,
  436. unsigned int *total,
  437. int mc_count,
  438. struct dev_addr_list *mc_list)
  439. {
  440. struct wl12xx *wl = hw->priv;
  441. wl12xx_debug(DEBUG_MAC80211, "mac80211 configure filter");
  442. *total &= WL12XX_SUPPORTED_FILTERS;
  443. changed &= WL12XX_SUPPORTED_FILTERS;
  444. if (changed == 0)
  445. /* no filters which we support changed */
  446. return;
  447. /* FIXME: wl->rx_config and wl->rx_filter are not protected */
  448. wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
  449. wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
  450. if (*total & FIF_PROMISC_IN_BSS) {
  451. wl->rx_config |= CFG_BSSID_FILTER_EN;
  452. wl->rx_config |= CFG_RX_ALL_GOOD;
  453. }
  454. if (*total & FIF_ALLMULTI)
  455. /*
  456. * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
  457. * all multicast frames
  458. */
  459. wl->rx_config &= ~CFG_MC_FILTER_EN;
  460. if (*total & FIF_FCSFAIL)
  461. wl->rx_filter |= CFG_RX_FCS_ERROR;
  462. if (*total & FIF_BCN_PRBRESP_PROMISC) {
  463. wl->rx_config &= ~CFG_BSSID_FILTER_EN;
  464. wl->rx_config &= ~CFG_SSID_FILTER_EN;
  465. }
  466. if (*total & FIF_CONTROL)
  467. wl->rx_filter |= CFG_RX_CTL_EN;
  468. if (*total & FIF_OTHER_BSS)
  469. wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
  470. /*
  471. * FIXME: workqueues need to be properly cancelled on stop(), for
  472. * now let's just disable changing the filter settings. They will
  473. * be updated any on config().
  474. */
  475. /* schedule_work(&wl->filter_work); */
  476. }
  477. /* HW encryption */
  478. static int wl12xx_set_key_type(struct wl12xx *wl, struct acx_set_key *key,
  479. enum set_key_cmd cmd,
  480. struct ieee80211_key_conf *mac80211_key,
  481. const u8 *addr)
  482. {
  483. switch (mac80211_key->alg) {
  484. case ALG_WEP:
  485. if (is_broadcast_ether_addr(addr))
  486. key->key_type = KEY_WEP_DEFAULT;
  487. else
  488. key->key_type = KEY_WEP_ADDR;
  489. mac80211_key->hw_key_idx = mac80211_key->keyidx;
  490. break;
  491. case ALG_TKIP:
  492. if (is_broadcast_ether_addr(addr))
  493. key->key_type = KEY_TKIP_MIC_GROUP;
  494. else
  495. key->key_type = KEY_TKIP_MIC_PAIRWISE;
  496. mac80211_key->hw_key_idx = mac80211_key->keyidx;
  497. break;
  498. case ALG_CCMP:
  499. if (is_broadcast_ether_addr(addr))
  500. key->key_type = KEY_AES_GROUP;
  501. else
  502. key->key_type = KEY_AES_PAIRWISE;
  503. mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  504. break;
  505. default:
  506. wl12xx_error("Unknown key algo 0x%x", mac80211_key->alg);
  507. return -EOPNOTSUPP;
  508. }
  509. return 0;
  510. }
  511. static int wl12xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  512. struct ieee80211_vif *vif,
  513. struct ieee80211_sta *sta,
  514. struct ieee80211_key_conf *key)
  515. {
  516. struct wl12xx *wl = hw->priv;
  517. struct acx_set_key wl_key;
  518. const u8 *addr;
  519. int ret;
  520. static const u8 bcast_addr[ETH_ALEN] =
  521. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  522. wl12xx_debug(DEBUG_MAC80211, "mac80211 set key");
  523. memset(&wl_key, 0, sizeof(wl_key));
  524. addr = sta ? sta->addr : bcast_addr;
  525. wl12xx_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  526. wl12xx_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  527. wl12xx_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  528. key->alg, key->keyidx, key->keylen, key->flags);
  529. wl12xx_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
  530. mutex_lock(&wl->mutex);
  531. switch (cmd) {
  532. case SET_KEY:
  533. wl_key.key_action = KEY_ADD_OR_REPLACE;
  534. break;
  535. case DISABLE_KEY:
  536. wl_key.key_action = KEY_REMOVE;
  537. break;
  538. default:
  539. wl12xx_error("Unsupported key cmd 0x%x", cmd);
  540. break;
  541. }
  542. ret = wl12xx_set_key_type(wl, &wl_key, cmd, key, addr);
  543. if (ret < 0) {
  544. wl12xx_error("Set KEY type failed");
  545. goto out;
  546. }
  547. if (wl_key.key_type != KEY_WEP_DEFAULT)
  548. memcpy(wl_key.addr, addr, ETH_ALEN);
  549. if ((wl_key.key_type == KEY_TKIP_MIC_GROUP) ||
  550. (wl_key.key_type == KEY_TKIP_MIC_PAIRWISE)) {
  551. /*
  552. * We get the key in the following form:
  553. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  554. * but the target is expecting:
  555. * TKIP - RX MIC - TX MIC
  556. */
  557. memcpy(wl_key.key, key->key, 16);
  558. memcpy(wl_key.key + 16, key->key + 24, 8);
  559. memcpy(wl_key.key + 24, key->key + 16, 8);
  560. } else {
  561. memcpy(wl_key.key, key->key, key->keylen);
  562. }
  563. wl_key.key_size = key->keylen;
  564. wl_key.id = key->keyidx;
  565. wl_key.ssid_profile = 0;
  566. wl12xx_dump(DEBUG_CRYPT, "TARGET KEY: ", &wl_key, sizeof(wl_key));
  567. if (wl12xx_cmd_send(wl, CMD_SET_KEYS, &wl_key, sizeof(wl_key)) < 0) {
  568. wl12xx_error("Set KEY failed");
  569. ret = -EOPNOTSUPP;
  570. goto out;
  571. }
  572. out:
  573. mutex_unlock(&wl->mutex);
  574. return ret;
  575. }
  576. static int wl12xx_build_basic_rates(char *rates)
  577. {
  578. u8 index = 0;
  579. rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
  580. rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
  581. rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
  582. rates[index++] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
  583. return index;
  584. }
  585. static int wl12xx_build_extended_rates(char *rates)
  586. {
  587. u8 index = 0;
  588. rates[index++] = IEEE80211_OFDM_RATE_6MB;
  589. rates[index++] = IEEE80211_OFDM_RATE_9MB;
  590. rates[index++] = IEEE80211_OFDM_RATE_12MB;
  591. rates[index++] = IEEE80211_OFDM_RATE_18MB;
  592. rates[index++] = IEEE80211_OFDM_RATE_24MB;
  593. rates[index++] = IEEE80211_OFDM_RATE_36MB;
  594. rates[index++] = IEEE80211_OFDM_RATE_48MB;
  595. rates[index++] = IEEE80211_OFDM_RATE_54MB;
  596. return index;
  597. }
  598. static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len)
  599. {
  600. struct wl12xx_probe_req_template template;
  601. struct wl12xx_ie_rates *rates;
  602. char *ptr;
  603. u16 size;
  604. ptr = (char *)&template;
  605. size = sizeof(struct ieee80211_header);
  606. memset(template.header.da, 0xff, ETH_ALEN);
  607. memset(template.header.bssid, 0xff, ETH_ALEN);
  608. memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
  609. template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  610. /* IEs */
  611. /* SSID */
  612. template.ssid.header.id = WLAN_EID_SSID;
  613. template.ssid.header.len = ssid_len;
  614. if (ssid_len && ssid)
  615. memcpy(template.ssid.ssid, ssid, ssid_len);
  616. size += sizeof(struct wl12xx_ie_header) + ssid_len;
  617. ptr += size;
  618. /* Basic Rates */
  619. rates = (struct wl12xx_ie_rates *)ptr;
  620. rates->header.id = WLAN_EID_SUPP_RATES;
  621. rates->header.len = wl12xx_build_basic_rates(rates->rates);
  622. size += sizeof(struct wl12xx_ie_header) + rates->header.len;
  623. ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
  624. /* Extended rates */
  625. rates = (struct wl12xx_ie_rates *)ptr;
  626. rates->header.id = WLAN_EID_EXT_SUPP_RATES;
  627. rates->header.len = wl12xx_build_extended_rates(rates->rates);
  628. size += sizeof(struct wl12xx_ie_header) + rates->header.len;
  629. wl12xx_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
  630. return wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, &template,
  631. size);
  632. }
  633. static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len,
  634. u8 active_scan, u8 high_prio, u8 num_channels,
  635. u8 probe_requests)
  636. {
  637. int i, ret;
  638. u32 split_scan = 0;
  639. u16 scan_options = 0;
  640. struct cmd_scan *params;
  641. struct wl12xx_command *cmd_answer;
  642. if (wl->scanning)
  643. return -EINVAL;
  644. params = kzalloc(sizeof(*params), GFP_KERNEL);
  645. if (!params)
  646. return -ENOMEM;
  647. params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
  648. params->params.rx_filter_options =
  649. cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
  650. /* High priority scan */
  651. if (!active_scan)
  652. scan_options |= SCAN_PASSIVE;
  653. if (high_prio)
  654. scan_options |= SCAN_PRIORITY_HIGH;
  655. params->params.scan_options = scan_options;
  656. params->params.num_channels = num_channels;
  657. params->params.num_probe_requests = probe_requests;
  658. params->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
  659. params->params.tid_trigger = 0;
  660. for (i = 0; i < num_channels; i++) {
  661. params->channels[i].min_duration = cpu_to_le32(30000);
  662. params->channels[i].max_duration = cpu_to_le32(60000);
  663. memset(&params->channels[i].bssid_lsb, 0xff, 4);
  664. memset(&params->channels[i].bssid_msb, 0xff, 2);
  665. params->channels[i].early_termination = 0;
  666. params->channels[i].tx_power_att = 0;
  667. params->channels[i].channel = i + 1;
  668. memset(params->channels[i].pad, 0, 3);
  669. }
  670. for (i = num_channels; i < SCAN_MAX_NUM_OF_CHANNELS; i++)
  671. memset(&params->channels[i], 0,
  672. sizeof(struct basic_scan_channel_parameters));
  673. if (len && ssid) {
  674. params->params.ssid_len = len;
  675. memcpy(params->params.ssid, ssid, len);
  676. } else {
  677. params->params.ssid_len = 0;
  678. memset(params->params.ssid, 0, 32);
  679. }
  680. ret = wl12xx_build_probe_req(wl, ssid, len);
  681. if (ret < 0) {
  682. wl12xx_error("PROBE request template failed");
  683. goto out;
  684. }
  685. ret = wl12xx_cmd_send(wl, CMD_TRIGGER_SCAN_TO, &split_scan,
  686. sizeof(u32));
  687. if (ret < 0) {
  688. wl12xx_error("Split SCAN failed");
  689. goto out;
  690. }
  691. wl12xx_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
  692. wl->scanning = true;
  693. ret = wl12xx_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
  694. if (ret < 0)
  695. wl12xx_error("SCAN failed");
  696. wl12xx_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
  697. cmd_answer = (struct wl12xx_command *) params;
  698. if (cmd_answer->status != CMD_STATUS_SUCCESS) {
  699. wl12xx_error("TEST command answer error: %d",
  700. cmd_answer->status);
  701. wl->scanning = false;
  702. ret = -EIO;
  703. goto out;
  704. }
  705. out:
  706. kfree(params);
  707. return ret;
  708. }
  709. static int wl12xx_op_hw_scan(struct ieee80211_hw *hw,
  710. struct cfg80211_scan_request *req)
  711. {
  712. struct wl12xx *wl = hw->priv;
  713. int ret;
  714. u8 *ssid = NULL;
  715. size_t ssid_len = 0;
  716. wl12xx_debug(DEBUG_MAC80211, "mac80211 hw scan");
  717. if (req->n_ssids) {
  718. ssid = req->ssids[0].ssid;
  719. ssid_len = req->ssids[0].ssid_len;
  720. }
  721. mutex_lock(&wl->mutex);
  722. ret = wl12xx_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
  723. mutex_unlock(&wl->mutex);
  724. return ret;
  725. }
  726. static int wl12xx_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  727. {
  728. struct wl12xx *wl = hw->priv;
  729. int ret;
  730. ret = wl12xx_acx_rts_threshold(wl, (u16) value);
  731. if (ret < 0)
  732. wl12xx_warning("wl12xx_op_set_rts_threshold failed: %d", ret);
  733. return ret;
  734. }
  735. static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
  736. struct ieee80211_vif *vif,
  737. struct ieee80211_bss_conf *bss_conf,
  738. u32 changed)
  739. {
  740. enum acx_ps_mode mode;
  741. struct wl12xx *wl = hw->priv;
  742. struct sk_buff *beacon;
  743. int ret;
  744. wl12xx_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  745. mutex_lock(&wl->mutex);
  746. if (changed & BSS_CHANGED_ASSOC) {
  747. if (bss_conf->assoc) {
  748. wl->aid = bss_conf->aid;
  749. ret = wl12xx_build_ps_poll(wl, wl->aid);
  750. if (ret < 0)
  751. goto out;
  752. ret = wl12xx_acx_aid(wl, wl->aid);
  753. if (ret < 0)
  754. goto out;
  755. /* If we want to go in PSM but we're not there yet */
  756. if (wl->psm_requested && !wl->psm) {
  757. mode = STATION_POWER_SAVE_MODE;
  758. ret = wl12xx_ps_set_mode(wl, mode);
  759. if (ret < 0)
  760. goto out;
  761. }
  762. }
  763. }
  764. if (changed & BSS_CHANGED_ERP_SLOT) {
  765. if (bss_conf->use_short_slot)
  766. ret = wl12xx_acx_slot(wl, SLOT_TIME_SHORT);
  767. else
  768. ret = wl12xx_acx_slot(wl, SLOT_TIME_LONG);
  769. if (ret < 0) {
  770. wl12xx_warning("Set slot time failed %d", ret);
  771. goto out;
  772. }
  773. }
  774. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  775. if (bss_conf->use_short_preamble)
  776. wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  777. else
  778. wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  779. }
  780. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  781. if (bss_conf->use_cts_prot)
  782. ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  783. else
  784. ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  785. if (ret < 0) {
  786. wl12xx_warning("Set ctsprotect failed %d", ret);
  787. goto out;
  788. }
  789. }
  790. if (changed & BSS_CHANGED_BSSID) {
  791. memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
  792. ret = wl12xx_build_null_data(wl);
  793. if (ret < 0)
  794. goto out;
  795. if (wl->bss_type != BSS_TYPE_IBSS) {
  796. ret = wl12xx_cmd_join(wl, wl->bss_type, 5, 100, 1);
  797. if (ret < 0)
  798. goto out;
  799. }
  800. }
  801. if (changed & BSS_CHANGED_BEACON) {
  802. beacon = ieee80211_beacon_get(hw, vif);
  803. ret = wl12xx_cmd_template_set(wl, CMD_BEACON, beacon->data,
  804. beacon->len);
  805. if (ret < 0) {
  806. dev_kfree_skb(beacon);
  807. goto out;
  808. }
  809. ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
  810. beacon->len);
  811. dev_kfree_skb(beacon);
  812. if (ret < 0)
  813. goto out;
  814. ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0);
  815. if (ret < 0)
  816. goto out;
  817. }
  818. out:
  819. mutex_unlock(&wl->mutex);
  820. }
  821. /* can't be const, mac80211 writes to this */
  822. static struct ieee80211_rate wl12xx_rates[] = {
  823. { .bitrate = 10,
  824. .hw_value = 0x1,
  825. .hw_value_short = 0x1, },
  826. { .bitrate = 20,
  827. .hw_value = 0x2,
  828. .hw_value_short = 0x2,
  829. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  830. { .bitrate = 55,
  831. .hw_value = 0x4,
  832. .hw_value_short = 0x4,
  833. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  834. { .bitrate = 110,
  835. .hw_value = 0x20,
  836. .hw_value_short = 0x20,
  837. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  838. { .bitrate = 60,
  839. .hw_value = 0x8,
  840. .hw_value_short = 0x8, },
  841. { .bitrate = 90,
  842. .hw_value = 0x10,
  843. .hw_value_short = 0x10, },
  844. { .bitrate = 120,
  845. .hw_value = 0x40,
  846. .hw_value_short = 0x40, },
  847. { .bitrate = 180,
  848. .hw_value = 0x80,
  849. .hw_value_short = 0x80, },
  850. { .bitrate = 240,
  851. .hw_value = 0x200,
  852. .hw_value_short = 0x200, },
  853. { .bitrate = 360,
  854. .hw_value = 0x400,
  855. .hw_value_short = 0x400, },
  856. { .bitrate = 480,
  857. .hw_value = 0x800,
  858. .hw_value_short = 0x800, },
  859. { .bitrate = 540,
  860. .hw_value = 0x1000,
  861. .hw_value_short = 0x1000, },
  862. };
  863. /* can't be const, mac80211 writes to this */
  864. static struct ieee80211_channel wl12xx_channels[] = {
  865. { .hw_value = 1, .center_freq = 2412},
  866. { .hw_value = 2, .center_freq = 2417},
  867. { .hw_value = 3, .center_freq = 2422},
  868. { .hw_value = 4, .center_freq = 2427},
  869. { .hw_value = 5, .center_freq = 2432},
  870. { .hw_value = 6, .center_freq = 2437},
  871. { .hw_value = 7, .center_freq = 2442},
  872. { .hw_value = 8, .center_freq = 2447},
  873. { .hw_value = 9, .center_freq = 2452},
  874. { .hw_value = 10, .center_freq = 2457},
  875. { .hw_value = 11, .center_freq = 2462},
  876. { .hw_value = 12, .center_freq = 2467},
  877. { .hw_value = 13, .center_freq = 2472},
  878. };
  879. /* can't be const, mac80211 writes to this */
  880. static struct ieee80211_supported_band wl12xx_band_2ghz = {
  881. .channels = wl12xx_channels,
  882. .n_channels = ARRAY_SIZE(wl12xx_channels),
  883. .bitrates = wl12xx_rates,
  884. .n_bitrates = ARRAY_SIZE(wl12xx_rates),
  885. };
  886. static const struct ieee80211_ops wl12xx_ops = {
  887. .start = wl12xx_op_start,
  888. .stop = wl12xx_op_stop,
  889. .add_interface = wl12xx_op_add_interface,
  890. .remove_interface = wl12xx_op_remove_interface,
  891. .config = wl12xx_op_config,
  892. .configure_filter = wl12xx_op_configure_filter,
  893. .tx = wl12xx_op_tx,
  894. .set_key = wl12xx_op_set_key,
  895. .hw_scan = wl12xx_op_hw_scan,
  896. .bss_info_changed = wl12xx_op_bss_info_changed,
  897. .set_rts_threshold = wl12xx_op_set_rts_threshold,
  898. };
  899. static int wl12xx_register_hw(struct wl12xx *wl)
  900. {
  901. int ret;
  902. if (wl->mac80211_registered)
  903. return 0;
  904. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  905. ret = ieee80211_register_hw(wl->hw);
  906. if (ret < 0) {
  907. wl12xx_error("unable to register mac80211 hw: %d", ret);
  908. return ret;
  909. }
  910. wl->mac80211_registered = true;
  911. wl12xx_notice("loaded");
  912. return 0;
  913. }
  914. static int wl12xx_init_ieee80211(struct wl12xx *wl)
  915. {
  916. /* The tx descriptor buffer and the TKIP space */
  917. wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
  918. + WL12XX_TKIP_IV_SPACE;
  919. /* unit us */
  920. /* FIXME: find a proper value */
  921. wl->hw->channel_change_time = 10000;
  922. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  923. IEEE80211_HW_NOISE_DBM;
  924. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  925. wl->hw->wiphy->max_scan_ssids = 1;
  926. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl12xx_band_2ghz;
  927. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  928. return 0;
  929. }
  930. #define WL12XX_DEFAULT_CHANNEL 1
  931. static int __devinit wl12xx_probe(struct spi_device *spi)
  932. {
  933. struct wl12xx_platform_data *pdata;
  934. struct ieee80211_hw *hw;
  935. struct wl12xx *wl;
  936. int ret, i;
  937. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  938. pdata = spi->dev.platform_data;
  939. if (!pdata) {
  940. wl12xx_error("no platform data");
  941. return -ENODEV;
  942. }
  943. hw = ieee80211_alloc_hw(sizeof(*wl), &wl12xx_ops);
  944. if (!hw) {
  945. wl12xx_error("could not alloc ieee80211_hw");
  946. return -ENOMEM;
  947. }
  948. wl = hw->priv;
  949. memset(wl, 0, sizeof(*wl));
  950. wl->hw = hw;
  951. dev_set_drvdata(&spi->dev, wl);
  952. wl->spi = spi;
  953. wl->data_in_count = 0;
  954. skb_queue_head_init(&wl->tx_queue);
  955. INIT_WORK(&wl->tx_work, wl12xx_tx_work);
  956. INIT_WORK(&wl->filter_work, wl12xx_filter_work);
  957. wl->channel = WL12XX_DEFAULT_CHANNEL;
  958. wl->scanning = false;
  959. wl->default_key = 0;
  960. wl->listen_int = 1;
  961. wl->rx_counter = 0;
  962. wl->rx_handled = 0;
  963. wl->rx_current_buffer = 0;
  964. wl->rx_last_id = 0;
  965. wl->rx_config = WL12XX_DEFAULT_RX_CONFIG;
  966. wl->rx_filter = WL12XX_DEFAULT_RX_FILTER;
  967. wl->elp = false;
  968. wl->psm = 0;
  969. wl->psm_requested = false;
  970. wl->tx_queue_stopped = false;
  971. wl->power_level = WL12XX_DEFAULT_POWER_LEVEL;
  972. /* We use the default power on sleep time until we know which chip
  973. * we're using */
  974. wl->chip.power_on_sleep = WL12XX_DEFAULT_POWER_ON_SLEEP;
  975. for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
  976. wl->tx_frames[i] = NULL;
  977. wl->next_tx_complete = 0;
  978. /*
  979. * In case our MAC address is not correctly set,
  980. * we use a random but Nokia MAC.
  981. */
  982. memcpy(wl->mac_addr, nokia_oui, 3);
  983. get_random_bytes(wl->mac_addr + 3, 3);
  984. wl->state = WL12XX_STATE_OFF;
  985. mutex_init(&wl->mutex);
  986. wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
  987. wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
  988. /* This is the only SPI value that we need to set here, the rest
  989. * comes from the board-peripherals file */
  990. spi->bits_per_word = 32;
  991. ret = spi_setup(spi);
  992. if (ret < 0) {
  993. wl12xx_error("spi_setup failed");
  994. goto out_free;
  995. }
  996. wl->set_power = pdata->set_power;
  997. if (!wl->set_power) {
  998. wl12xx_error("set power function missing in platform data");
  999. return -ENODEV;
  1000. }
  1001. wl->irq = spi->irq;
  1002. if (wl->irq < 0) {
  1003. wl12xx_error("irq missing in platform data");
  1004. return -ENODEV;
  1005. }
  1006. ret = request_irq(wl->irq, wl12xx_irq, 0, DRIVER_NAME, wl);
  1007. if (ret < 0) {
  1008. wl12xx_error("request_irq() failed: %d", ret);
  1009. goto out_free;
  1010. }
  1011. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1012. disable_irq(wl->irq);
  1013. ret = wl12xx_init_ieee80211(wl);
  1014. if (ret)
  1015. goto out_irq;
  1016. ret = wl12xx_register_hw(wl);
  1017. if (ret)
  1018. goto out_irq;
  1019. wl12xx_debugfs_init(wl);
  1020. wl12xx_notice("initialized");
  1021. return 0;
  1022. out_irq:
  1023. free_irq(wl->irq, wl);
  1024. out_free:
  1025. ieee80211_free_hw(hw);
  1026. return ret;
  1027. }
  1028. static int __devexit wl12xx_remove(struct spi_device *spi)
  1029. {
  1030. struct wl12xx *wl = dev_get_drvdata(&spi->dev);
  1031. ieee80211_unregister_hw(wl->hw);
  1032. wl12xx_debugfs_exit(wl);
  1033. free_irq(wl->irq, wl);
  1034. kfree(wl->target_mem_map);
  1035. kfree(wl->data_path);
  1036. kfree(wl->fw);
  1037. wl->fw = NULL;
  1038. kfree(wl->nvs);
  1039. wl->nvs = NULL;
  1040. ieee80211_free_hw(wl->hw);
  1041. return 0;
  1042. }
  1043. static struct spi_driver wl12xx_spi_driver = {
  1044. .driver = {
  1045. .name = "wl12xx",
  1046. .bus = &spi_bus_type,
  1047. .owner = THIS_MODULE,
  1048. },
  1049. .probe = wl12xx_probe,
  1050. .remove = __devexit_p(wl12xx_remove),
  1051. };
  1052. static int __init wl12xx_init(void)
  1053. {
  1054. int ret;
  1055. ret = spi_register_driver(&wl12xx_spi_driver);
  1056. if (ret < 0) {
  1057. wl12xx_error("failed to register spi driver: %d", ret);
  1058. goto out;
  1059. }
  1060. out:
  1061. return ret;
  1062. }
  1063. static void __exit wl12xx_exit(void)
  1064. {
  1065. spi_unregister_driver(&wl12xx_spi_driver);
  1066. wl12xx_notice("unloaded");
  1067. }
  1068. module_init(wl12xx_init);
  1069. module_exit(wl12xx_exit);
  1070. MODULE_LICENSE("GPL");
  1071. MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
  1072. "Luciano Coelho <luciano.coelho@nokia.com>");