main.c 31 KB

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