main.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. /*
  2. * This file contains the major functions in WLAN
  3. * driver. It includes init, exit, open, close and main
  4. * thread etc..
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #include <linux/module.h>
  8. #include <linux/delay.h>
  9. #include <linux/etherdevice.h>
  10. #include <linux/hardirq.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/if_arp.h>
  13. #include <linux/kthread.h>
  14. #include <linux/kfifo.h>
  15. #include <linux/slab.h>
  16. #include <net/cfg80211.h>
  17. #include "host.h"
  18. #include "decl.h"
  19. #include "dev.h"
  20. #include "cfg.h"
  21. #include "debugfs.h"
  22. #include "cmd.h"
  23. #include "mesh.h"
  24. #define DRIVER_RELEASE_VERSION "323.p0"
  25. const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
  26. #ifdef DEBUG
  27. "-dbg"
  28. #endif
  29. "";
  30. /* Module parameters */
  31. unsigned int lbs_debug;
  32. EXPORT_SYMBOL_GPL(lbs_debug);
  33. module_param_named(libertas_debug, lbs_debug, int, 0644);
  34. unsigned int lbs_disablemesh;
  35. EXPORT_SYMBOL_GPL(lbs_disablemesh);
  36. module_param_named(libertas_disablemesh, lbs_disablemesh, int, 0644);
  37. /*
  38. * This global structure is used to send the confirm_sleep command as
  39. * fast as possible down to the firmware.
  40. */
  41. struct cmd_confirm_sleep confirm_sleep;
  42. /*
  43. * the table to keep region code
  44. */
  45. u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
  46. { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
  47. /*
  48. * FW rate table. FW refers to rates by their index in this table, not by the
  49. * rate value itself. Values of 0x00 are
  50. * reserved positions.
  51. */
  52. static u8 fw_data_rates[MAX_RATES] =
  53. { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
  54. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
  55. };
  56. /**
  57. * lbs_fw_index_to_data_rate - use index to get the data rate
  58. *
  59. * @idx: The index of data rate
  60. * returns: data rate or 0
  61. */
  62. u32 lbs_fw_index_to_data_rate(u8 idx)
  63. {
  64. if (idx >= sizeof(fw_data_rates))
  65. idx = 0;
  66. return fw_data_rates[idx];
  67. }
  68. /**
  69. * lbs_data_rate_to_fw_index - use rate to get the index
  70. *
  71. * @rate: data rate
  72. * returns: index or 0
  73. */
  74. u8 lbs_data_rate_to_fw_index(u32 rate)
  75. {
  76. u8 i;
  77. if (!rate)
  78. return 0;
  79. for (i = 0; i < sizeof(fw_data_rates); i++) {
  80. if (rate == fw_data_rates[i])
  81. return i;
  82. }
  83. return 0;
  84. }
  85. int lbs_set_iface_type(struct lbs_private *priv, enum nl80211_iftype type)
  86. {
  87. int ret = 0;
  88. switch (type) {
  89. case NL80211_IFTYPE_MONITOR:
  90. ret = lbs_set_monitor_mode(priv, 1);
  91. break;
  92. case NL80211_IFTYPE_STATION:
  93. if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
  94. ret = lbs_set_monitor_mode(priv, 0);
  95. if (!ret)
  96. ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
  97. break;
  98. case NL80211_IFTYPE_ADHOC:
  99. if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
  100. ret = lbs_set_monitor_mode(priv, 0);
  101. if (!ret)
  102. ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
  103. break;
  104. default:
  105. ret = -ENOTSUPP;
  106. }
  107. return ret;
  108. }
  109. int lbs_start_iface(struct lbs_private *priv)
  110. {
  111. struct cmd_ds_802_11_mac_address cmd;
  112. int ret;
  113. if (priv->power_restore) {
  114. ret = priv->power_restore(priv);
  115. if (ret)
  116. return ret;
  117. }
  118. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  119. cmd.action = cpu_to_le16(CMD_ACT_SET);
  120. memcpy(cmd.macadd, priv->current_addr, ETH_ALEN);
  121. ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
  122. if (ret) {
  123. lbs_deb_net("set MAC address failed\n");
  124. goto err;
  125. }
  126. ret = lbs_set_iface_type(priv, priv->wdev->iftype);
  127. if (ret) {
  128. lbs_deb_net("set iface type failed\n");
  129. goto err;
  130. }
  131. lbs_update_channel(priv);
  132. priv->iface_running = true;
  133. return 0;
  134. err:
  135. if (priv->power_save)
  136. priv->power_save(priv);
  137. return ret;
  138. }
  139. /**
  140. * lbs_dev_open - open the ethX interface
  141. *
  142. * @dev: A pointer to &net_device structure
  143. * returns: 0 or -EBUSY if monitor mode active
  144. */
  145. static int lbs_dev_open(struct net_device *dev)
  146. {
  147. struct lbs_private *priv = dev->ml_priv;
  148. int ret = 0;
  149. lbs_deb_enter(LBS_DEB_NET);
  150. if (!priv->iface_running) {
  151. ret = lbs_start_iface(priv);
  152. if (ret)
  153. goto out;
  154. }
  155. spin_lock_irq(&priv->driver_lock);
  156. netif_carrier_off(dev);
  157. if (!priv->tx_pending_len)
  158. netif_wake_queue(dev);
  159. spin_unlock_irq(&priv->driver_lock);
  160. out:
  161. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  162. return ret;
  163. }
  164. static bool lbs_command_queue_empty(struct lbs_private *priv)
  165. {
  166. unsigned long flags;
  167. bool ret;
  168. spin_lock_irqsave(&priv->driver_lock, flags);
  169. ret = priv->cur_cmd == NULL && list_empty(&priv->cmdpendingq);
  170. spin_unlock_irqrestore(&priv->driver_lock, flags);
  171. return ret;
  172. }
  173. int lbs_stop_iface(struct lbs_private *priv)
  174. {
  175. unsigned long flags;
  176. int ret = 0;
  177. lbs_deb_enter(LBS_DEB_MAIN);
  178. spin_lock_irqsave(&priv->driver_lock, flags);
  179. priv->iface_running = false;
  180. kfree_skb(priv->currenttxskb);
  181. priv->currenttxskb = NULL;
  182. priv->tx_pending_len = 0;
  183. spin_unlock_irqrestore(&priv->driver_lock, flags);
  184. cancel_work_sync(&priv->mcast_work);
  185. del_timer_sync(&priv->tx_lockup_timer);
  186. /* Disable command processing, and wait for all commands to complete */
  187. lbs_deb_main("waiting for commands to complete\n");
  188. wait_event(priv->waitq, lbs_command_queue_empty(priv));
  189. lbs_deb_main("all commands completed\n");
  190. if (priv->power_save)
  191. ret = priv->power_save(priv);
  192. lbs_deb_leave(LBS_DEB_MAIN);
  193. return ret;
  194. }
  195. /**
  196. * lbs_eth_stop - close the ethX interface
  197. *
  198. * @dev: A pointer to &net_device structure
  199. * returns: 0
  200. */
  201. static int lbs_eth_stop(struct net_device *dev)
  202. {
  203. struct lbs_private *priv = dev->ml_priv;
  204. lbs_deb_enter(LBS_DEB_NET);
  205. if (priv->connect_status == LBS_CONNECTED)
  206. lbs_disconnect(priv, WLAN_REASON_DEAUTH_LEAVING);
  207. spin_lock_irq(&priv->driver_lock);
  208. netif_stop_queue(dev);
  209. spin_unlock_irq(&priv->driver_lock);
  210. lbs_update_mcast(priv);
  211. cancel_delayed_work_sync(&priv->scan_work);
  212. if (priv->scan_req)
  213. lbs_scan_done(priv);
  214. netif_carrier_off(priv->dev);
  215. if (!lbs_iface_active(priv))
  216. lbs_stop_iface(priv);
  217. lbs_deb_leave(LBS_DEB_NET);
  218. return 0;
  219. }
  220. void lbs_host_to_card_done(struct lbs_private *priv)
  221. {
  222. unsigned long flags;
  223. lbs_deb_enter(LBS_DEB_THREAD);
  224. spin_lock_irqsave(&priv->driver_lock, flags);
  225. del_timer(&priv->tx_lockup_timer);
  226. priv->dnld_sent = DNLD_RES_RECEIVED;
  227. /* Wake main thread if commands are pending */
  228. if (!priv->cur_cmd || priv->tx_pending_len > 0) {
  229. if (!priv->wakeup_dev_required)
  230. wake_up(&priv->waitq);
  231. }
  232. spin_unlock_irqrestore(&priv->driver_lock, flags);
  233. lbs_deb_leave(LBS_DEB_THREAD);
  234. }
  235. EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
  236. int lbs_set_mac_address(struct net_device *dev, void *addr)
  237. {
  238. int ret = 0;
  239. struct lbs_private *priv = dev->ml_priv;
  240. struct sockaddr *phwaddr = addr;
  241. lbs_deb_enter(LBS_DEB_NET);
  242. /*
  243. * Can only set MAC address when all interfaces are down, to be written
  244. * to the hardware when one of them is brought up.
  245. */
  246. if (lbs_iface_active(priv))
  247. return -EBUSY;
  248. /* In case it was called from the mesh device */
  249. dev = priv->dev;
  250. memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
  251. memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  252. if (priv->mesh_dev)
  253. memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  254. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  255. return ret;
  256. }
  257. static inline int mac_in_list(unsigned char *list, int list_len,
  258. unsigned char *mac)
  259. {
  260. while (list_len) {
  261. if (!memcmp(list, mac, ETH_ALEN))
  262. return 1;
  263. list += ETH_ALEN;
  264. list_len--;
  265. }
  266. return 0;
  267. }
  268. static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd,
  269. struct net_device *dev, int nr_addrs)
  270. {
  271. int i = nr_addrs;
  272. struct netdev_hw_addr *ha;
  273. int cnt;
  274. if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST))
  275. return nr_addrs;
  276. netif_addr_lock_bh(dev);
  277. cnt = netdev_mc_count(dev);
  278. netdev_for_each_mc_addr(ha, dev) {
  279. if (mac_in_list(cmd->maclist, nr_addrs, ha->addr)) {
  280. lbs_deb_net("mcast address %s:%pM skipped\n", dev->name,
  281. ha->addr);
  282. cnt--;
  283. continue;
  284. }
  285. if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE)
  286. break;
  287. memcpy(&cmd->maclist[6*i], ha->addr, ETH_ALEN);
  288. lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name,
  289. ha->addr);
  290. i++;
  291. cnt--;
  292. }
  293. netif_addr_unlock_bh(dev);
  294. if (cnt)
  295. return -EOVERFLOW;
  296. return i;
  297. }
  298. void lbs_update_mcast(struct lbs_private *priv)
  299. {
  300. struct cmd_ds_mac_multicast_adr mcast_cmd;
  301. int dev_flags = 0;
  302. int nr_addrs;
  303. int old_mac_control = priv->mac_control;
  304. lbs_deb_enter(LBS_DEB_NET);
  305. if (netif_running(priv->dev))
  306. dev_flags |= priv->dev->flags;
  307. if (priv->mesh_dev && netif_running(priv->mesh_dev))
  308. dev_flags |= priv->mesh_dev->flags;
  309. if (dev_flags & IFF_PROMISC) {
  310. priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  311. priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
  312. CMD_ACT_MAC_MULTICAST_ENABLE);
  313. goto out_set_mac_control;
  314. } else if (dev_flags & IFF_ALLMULTI) {
  315. do_allmulti:
  316. priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  317. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  318. CMD_ACT_MAC_MULTICAST_ENABLE);
  319. goto out_set_mac_control;
  320. }
  321. /* Once for priv->dev, again for priv->mesh_dev if it exists */
  322. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0);
  323. if (nr_addrs >= 0 && priv->mesh_dev)
  324. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs);
  325. if (nr_addrs < 0)
  326. goto do_allmulti;
  327. if (nr_addrs) {
  328. int size = offsetof(struct cmd_ds_mac_multicast_adr,
  329. maclist[6*nr_addrs]);
  330. mcast_cmd.action = cpu_to_le16(CMD_ACT_SET);
  331. mcast_cmd.hdr.size = cpu_to_le16(size);
  332. mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs);
  333. lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size);
  334. priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
  335. } else
  336. priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
  337. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  338. CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
  339. out_set_mac_control:
  340. if (priv->mac_control != old_mac_control)
  341. lbs_set_mac_control(priv);
  342. lbs_deb_leave(LBS_DEB_NET);
  343. }
  344. static void lbs_set_mcast_worker(struct work_struct *work)
  345. {
  346. struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work);
  347. lbs_update_mcast(priv);
  348. }
  349. void lbs_set_multicast_list(struct net_device *dev)
  350. {
  351. struct lbs_private *priv = dev->ml_priv;
  352. schedule_work(&priv->mcast_work);
  353. }
  354. /**
  355. * lbs_thread - handles the major jobs in the LBS driver.
  356. * It handles all events generated by firmware, RX data received
  357. * from firmware and TX data sent from kernel.
  358. *
  359. * @data: A pointer to &lbs_thread structure
  360. * returns: 0
  361. */
  362. static int lbs_thread(void *data)
  363. {
  364. struct net_device *dev = data;
  365. struct lbs_private *priv = dev->ml_priv;
  366. wait_queue_t wait;
  367. lbs_deb_enter(LBS_DEB_THREAD);
  368. init_waitqueue_entry(&wait, current);
  369. for (;;) {
  370. int shouldsleep;
  371. u8 resp_idx;
  372. lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
  373. priv->currenttxskb, priv->dnld_sent);
  374. add_wait_queue(&priv->waitq, &wait);
  375. set_current_state(TASK_INTERRUPTIBLE);
  376. spin_lock_irq(&priv->driver_lock);
  377. if (kthread_should_stop())
  378. shouldsleep = 0; /* Bye */
  379. else if (priv->surpriseremoved)
  380. shouldsleep = 1; /* We need to wait until we're _told_ to die */
  381. else if (priv->psstate == PS_STATE_SLEEP)
  382. shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
  383. else if (priv->cmd_timed_out)
  384. shouldsleep = 0; /* Command timed out. Recover */
  385. else if (!priv->fw_ready)
  386. shouldsleep = 1; /* Firmware not ready. We're waiting for it */
  387. else if (priv->dnld_sent)
  388. shouldsleep = 1; /* Something is en route to the device already */
  389. else if (priv->tx_pending_len > 0)
  390. shouldsleep = 0; /* We've a packet to send */
  391. else if (priv->resp_len[priv->resp_idx])
  392. shouldsleep = 0; /* We have a command response */
  393. else if (priv->cur_cmd)
  394. shouldsleep = 1; /* Can't send a command; one already running */
  395. else if (!list_empty(&priv->cmdpendingq) &&
  396. !(priv->wakeup_dev_required))
  397. shouldsleep = 0; /* We have a command to send */
  398. else if (kfifo_len(&priv->event_fifo))
  399. shouldsleep = 0; /* We have an event to process */
  400. else
  401. shouldsleep = 1; /* No command */
  402. if (shouldsleep) {
  403. lbs_deb_thread("sleeping, connect_status %d, "
  404. "psmode %d, psstate %d\n",
  405. priv->connect_status,
  406. priv->psmode, priv->psstate);
  407. spin_unlock_irq(&priv->driver_lock);
  408. schedule();
  409. } else
  410. spin_unlock_irq(&priv->driver_lock);
  411. lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
  412. priv->currenttxskb, priv->dnld_sent);
  413. set_current_state(TASK_RUNNING);
  414. remove_wait_queue(&priv->waitq, &wait);
  415. lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
  416. priv->currenttxskb, priv->dnld_sent);
  417. if (kthread_should_stop()) {
  418. lbs_deb_thread("break from main thread\n");
  419. break;
  420. }
  421. if (priv->surpriseremoved) {
  422. lbs_deb_thread("adapter removed; waiting to die...\n");
  423. continue;
  424. }
  425. lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
  426. priv->currenttxskb, priv->dnld_sent);
  427. /* Process any pending command response */
  428. spin_lock_irq(&priv->driver_lock);
  429. resp_idx = priv->resp_idx;
  430. if (priv->resp_len[resp_idx]) {
  431. spin_unlock_irq(&priv->driver_lock);
  432. lbs_process_command_response(priv,
  433. priv->resp_buf[resp_idx],
  434. priv->resp_len[resp_idx]);
  435. spin_lock_irq(&priv->driver_lock);
  436. priv->resp_len[resp_idx] = 0;
  437. }
  438. spin_unlock_irq(&priv->driver_lock);
  439. /* Process hardware events, e.g. card removed, link lost */
  440. spin_lock_irq(&priv->driver_lock);
  441. while (kfifo_len(&priv->event_fifo)) {
  442. u32 event;
  443. if (kfifo_out(&priv->event_fifo,
  444. (unsigned char *) &event, sizeof(event)) !=
  445. sizeof(event))
  446. break;
  447. spin_unlock_irq(&priv->driver_lock);
  448. lbs_process_event(priv, event);
  449. spin_lock_irq(&priv->driver_lock);
  450. }
  451. spin_unlock_irq(&priv->driver_lock);
  452. if (priv->wakeup_dev_required) {
  453. lbs_deb_thread("Waking up device...\n");
  454. /* Wake up device */
  455. if (priv->exit_deep_sleep(priv))
  456. lbs_deb_thread("Wakeup device failed\n");
  457. continue;
  458. }
  459. /* command timeout stuff */
  460. if (priv->cmd_timed_out && priv->cur_cmd) {
  461. struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
  462. netdev_info(dev, "Timeout submitting command 0x%04x\n",
  463. le16_to_cpu(cmdnode->cmdbuf->command));
  464. lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
  465. if (priv->reset_card)
  466. priv->reset_card(priv);
  467. }
  468. priv->cmd_timed_out = 0;
  469. if (!priv->fw_ready)
  470. continue;
  471. /* Check if we need to confirm Sleep Request received previously */
  472. if (priv->psstate == PS_STATE_PRE_SLEEP &&
  473. !priv->dnld_sent && !priv->cur_cmd) {
  474. if (priv->connect_status == LBS_CONNECTED) {
  475. lbs_deb_thread("pre-sleep, currenttxskb %p, "
  476. "dnld_sent %d, cur_cmd %p\n",
  477. priv->currenttxskb, priv->dnld_sent,
  478. priv->cur_cmd);
  479. lbs_ps_confirm_sleep(priv);
  480. } else {
  481. /* workaround for firmware sending
  482. * deauth/linkloss event immediately
  483. * after sleep request; remove this
  484. * after firmware fixes it
  485. */
  486. priv->psstate = PS_STATE_AWAKE;
  487. netdev_alert(dev,
  488. "ignore PS_SleepConfirm in non-connected state\n");
  489. }
  490. }
  491. /* The PS state is changed during processing of Sleep Request
  492. * event above
  493. */
  494. if ((priv->psstate == PS_STATE_SLEEP) ||
  495. (priv->psstate == PS_STATE_PRE_SLEEP))
  496. continue;
  497. if (priv->is_deep_sleep)
  498. continue;
  499. /* Execute the next command */
  500. if (!priv->dnld_sent && !priv->cur_cmd)
  501. lbs_execute_next_command(priv);
  502. spin_lock_irq(&priv->driver_lock);
  503. if (!priv->dnld_sent && priv->tx_pending_len > 0) {
  504. int ret = priv->hw_host_to_card(priv, MVMS_DAT,
  505. priv->tx_pending_buf,
  506. priv->tx_pending_len);
  507. if (ret) {
  508. lbs_deb_tx("host_to_card failed %d\n", ret);
  509. priv->dnld_sent = DNLD_RES_RECEIVED;
  510. } else {
  511. mod_timer(&priv->tx_lockup_timer,
  512. jiffies + (HZ * 5));
  513. }
  514. priv->tx_pending_len = 0;
  515. if (!priv->currenttxskb) {
  516. /* We can wake the queues immediately if we aren't
  517. waiting for TX feedback */
  518. if (priv->connect_status == LBS_CONNECTED)
  519. netif_wake_queue(priv->dev);
  520. if (priv->mesh_dev &&
  521. netif_running(priv->mesh_dev))
  522. netif_wake_queue(priv->mesh_dev);
  523. }
  524. }
  525. spin_unlock_irq(&priv->driver_lock);
  526. }
  527. del_timer(&priv->command_timer);
  528. del_timer(&priv->tx_lockup_timer);
  529. del_timer(&priv->auto_deepsleep_timer);
  530. lbs_deb_leave(LBS_DEB_THREAD);
  531. return 0;
  532. }
  533. /**
  534. * lbs_setup_firmware - gets the HW spec from the firmware and sets
  535. * some basic parameters
  536. *
  537. * @priv: A pointer to &struct lbs_private structure
  538. * returns: 0 or -1
  539. */
  540. static int lbs_setup_firmware(struct lbs_private *priv)
  541. {
  542. int ret = -1;
  543. s16 curlevel = 0, minlevel = 0, maxlevel = 0;
  544. lbs_deb_enter(LBS_DEB_FW);
  545. /* Read MAC address from firmware */
  546. memset(priv->current_addr, 0xff, ETH_ALEN);
  547. ret = lbs_update_hw_spec(priv);
  548. if (ret)
  549. goto done;
  550. /* Read power levels if available */
  551. ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
  552. if (ret == 0) {
  553. priv->txpower_cur = curlevel;
  554. priv->txpower_min = minlevel;
  555. priv->txpower_max = maxlevel;
  556. }
  557. /* Send cmd to FW to enable 11D function */
  558. ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1);
  559. lbs_set_mac_control(priv);
  560. done:
  561. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  562. return ret;
  563. }
  564. int lbs_suspend(struct lbs_private *priv)
  565. {
  566. int ret;
  567. lbs_deb_enter(LBS_DEB_FW);
  568. if (priv->is_deep_sleep) {
  569. ret = lbs_set_deep_sleep(priv, 0);
  570. if (ret) {
  571. netdev_err(priv->dev,
  572. "deep sleep cancellation failed: %d\n", ret);
  573. return ret;
  574. }
  575. priv->deep_sleep_required = 1;
  576. }
  577. ret = lbs_set_host_sleep(priv, 1);
  578. netif_device_detach(priv->dev);
  579. if (priv->mesh_dev)
  580. netif_device_detach(priv->mesh_dev);
  581. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  582. return ret;
  583. }
  584. EXPORT_SYMBOL_GPL(lbs_suspend);
  585. int lbs_resume(struct lbs_private *priv)
  586. {
  587. int ret;
  588. lbs_deb_enter(LBS_DEB_FW);
  589. ret = lbs_set_host_sleep(priv, 0);
  590. netif_device_attach(priv->dev);
  591. if (priv->mesh_dev)
  592. netif_device_attach(priv->mesh_dev);
  593. if (priv->deep_sleep_required) {
  594. priv->deep_sleep_required = 0;
  595. ret = lbs_set_deep_sleep(priv, 1);
  596. if (ret)
  597. netdev_err(priv->dev,
  598. "deep sleep activation failed: %d\n", ret);
  599. }
  600. if (priv->setup_fw_on_resume)
  601. ret = lbs_setup_firmware(priv);
  602. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  603. return ret;
  604. }
  605. EXPORT_SYMBOL_GPL(lbs_resume);
  606. /**
  607. * lbs_cmd_timeout_handler - handles the timeout of command sending.
  608. * It will re-send the same command again.
  609. *
  610. * @data: &struct lbs_private pointer
  611. */
  612. static void lbs_cmd_timeout_handler(unsigned long data)
  613. {
  614. struct lbs_private *priv = (struct lbs_private *)data;
  615. unsigned long flags;
  616. lbs_deb_enter(LBS_DEB_CMD);
  617. spin_lock_irqsave(&priv->driver_lock, flags);
  618. if (!priv->cur_cmd)
  619. goto out;
  620. netdev_info(priv->dev, "command 0x%04x timed out\n",
  621. le16_to_cpu(priv->cur_cmd->cmdbuf->command));
  622. priv->cmd_timed_out = 1;
  623. /*
  624. * If the device didn't even acknowledge the command, reset the state
  625. * so that we don't block all future commands due to this one timeout.
  626. */
  627. if (priv->dnld_sent == DNLD_CMD_SENT)
  628. priv->dnld_sent = DNLD_RES_RECEIVED;
  629. wake_up(&priv->waitq);
  630. out:
  631. spin_unlock_irqrestore(&priv->driver_lock, flags);
  632. lbs_deb_leave(LBS_DEB_CMD);
  633. }
  634. /**
  635. * lbs_tx_lockup_handler - handles the timeout of the passing of TX frames
  636. * to the hardware. This is known to frequently happen with SD8686 when
  637. * waking up after a Wake-on-WLAN-triggered resume.
  638. *
  639. * @data: &struct lbs_private pointer
  640. */
  641. static void lbs_tx_lockup_handler(unsigned long data)
  642. {
  643. struct lbs_private *priv = (struct lbs_private *)data;
  644. unsigned long flags;
  645. lbs_deb_enter(LBS_DEB_TX);
  646. spin_lock_irqsave(&priv->driver_lock, flags);
  647. netdev_info(priv->dev, "TX lockup detected\n");
  648. if (priv->reset_card)
  649. priv->reset_card(priv);
  650. priv->dnld_sent = DNLD_RES_RECEIVED;
  651. wake_up_interruptible(&priv->waitq);
  652. spin_unlock_irqrestore(&priv->driver_lock, flags);
  653. lbs_deb_leave(LBS_DEB_TX);
  654. }
  655. /**
  656. * auto_deepsleep_timer_fn - put the device back to deep sleep mode when
  657. * timer expires and no activity (command, event, data etc.) is detected.
  658. * @data: &struct lbs_private pointer
  659. * returns: N/A
  660. */
  661. static void auto_deepsleep_timer_fn(unsigned long data)
  662. {
  663. struct lbs_private *priv = (struct lbs_private *)data;
  664. lbs_deb_enter(LBS_DEB_CMD);
  665. if (priv->is_activity_detected) {
  666. priv->is_activity_detected = 0;
  667. } else {
  668. if (priv->is_auto_deep_sleep_enabled &&
  669. (!priv->wakeup_dev_required) &&
  670. (priv->connect_status != LBS_CONNECTED)) {
  671. struct cmd_header cmd;
  672. lbs_deb_main("Entering auto deep sleep mode...\n");
  673. memset(&cmd, 0, sizeof(cmd));
  674. cmd.size = cpu_to_le16(sizeof(cmd));
  675. lbs_cmd_async(priv, CMD_802_11_DEEP_SLEEP, &cmd,
  676. sizeof(cmd));
  677. }
  678. }
  679. mod_timer(&priv->auto_deepsleep_timer , jiffies +
  680. (priv->auto_deep_sleep_timeout * HZ)/1000);
  681. lbs_deb_leave(LBS_DEB_CMD);
  682. }
  683. int lbs_enter_auto_deep_sleep(struct lbs_private *priv)
  684. {
  685. lbs_deb_enter(LBS_DEB_SDIO);
  686. priv->is_auto_deep_sleep_enabled = 1;
  687. if (priv->is_deep_sleep)
  688. priv->wakeup_dev_required = 1;
  689. mod_timer(&priv->auto_deepsleep_timer ,
  690. jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000);
  691. lbs_deb_leave(LBS_DEB_SDIO);
  692. return 0;
  693. }
  694. int lbs_exit_auto_deep_sleep(struct lbs_private *priv)
  695. {
  696. lbs_deb_enter(LBS_DEB_SDIO);
  697. priv->is_auto_deep_sleep_enabled = 0;
  698. priv->auto_deep_sleep_timeout = 0;
  699. del_timer(&priv->auto_deepsleep_timer);
  700. lbs_deb_leave(LBS_DEB_SDIO);
  701. return 0;
  702. }
  703. static int lbs_init_adapter(struct lbs_private *priv)
  704. {
  705. int ret;
  706. lbs_deb_enter(LBS_DEB_MAIN);
  707. memset(priv->current_addr, 0xff, ETH_ALEN);
  708. priv->connect_status = LBS_DISCONNECTED;
  709. priv->channel = DEFAULT_AD_HOC_CHANNEL;
  710. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  711. priv->radio_on = 1;
  712. priv->psmode = LBS802_11POWERMODECAM;
  713. priv->psstate = PS_STATE_FULL_POWER;
  714. priv->is_deep_sleep = 0;
  715. priv->is_auto_deep_sleep_enabled = 0;
  716. priv->deep_sleep_required = 0;
  717. priv->wakeup_dev_required = 0;
  718. init_waitqueue_head(&priv->ds_awake_q);
  719. init_waitqueue_head(&priv->scan_q);
  720. priv->authtype_auto = 1;
  721. priv->is_host_sleep_configured = 0;
  722. priv->is_host_sleep_activated = 0;
  723. init_waitqueue_head(&priv->host_sleep_q);
  724. mutex_init(&priv->lock);
  725. setup_timer(&priv->command_timer, lbs_cmd_timeout_handler,
  726. (unsigned long)priv);
  727. setup_timer(&priv->tx_lockup_timer, lbs_tx_lockup_handler,
  728. (unsigned long)priv);
  729. setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
  730. (unsigned long)priv);
  731. INIT_LIST_HEAD(&priv->cmdfreeq);
  732. INIT_LIST_HEAD(&priv->cmdpendingq);
  733. spin_lock_init(&priv->driver_lock);
  734. /* Allocate the command buffers */
  735. if (lbs_allocate_cmd_buffer(priv)) {
  736. pr_err("Out of memory allocating command buffers\n");
  737. ret = -ENOMEM;
  738. goto out;
  739. }
  740. priv->resp_idx = 0;
  741. priv->resp_len[0] = priv->resp_len[1] = 0;
  742. /* Create the event FIFO */
  743. ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL);
  744. if (ret) {
  745. pr_err("Out of memory allocating event FIFO buffer\n");
  746. goto out;
  747. }
  748. out:
  749. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  750. return ret;
  751. }
  752. static void lbs_free_adapter(struct lbs_private *priv)
  753. {
  754. lbs_deb_enter(LBS_DEB_MAIN);
  755. lbs_free_cmd_buffer(priv);
  756. kfifo_free(&priv->event_fifo);
  757. del_timer(&priv->command_timer);
  758. del_timer(&priv->tx_lockup_timer);
  759. del_timer(&priv->auto_deepsleep_timer);
  760. lbs_deb_leave(LBS_DEB_MAIN);
  761. }
  762. static const struct net_device_ops lbs_netdev_ops = {
  763. .ndo_open = lbs_dev_open,
  764. .ndo_stop = lbs_eth_stop,
  765. .ndo_start_xmit = lbs_hard_start_xmit,
  766. .ndo_set_mac_address = lbs_set_mac_address,
  767. .ndo_set_rx_mode = lbs_set_multicast_list,
  768. .ndo_change_mtu = eth_change_mtu,
  769. .ndo_validate_addr = eth_validate_addr,
  770. };
  771. /**
  772. * lbs_add_card - adds the card. It will probe the
  773. * card, allocate the lbs_priv and initialize the device.
  774. *
  775. * @card: A pointer to card
  776. * @dmdev: A pointer to &struct device
  777. * returns: A pointer to &struct lbs_private structure
  778. */
  779. struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
  780. {
  781. struct net_device *dev;
  782. struct wireless_dev *wdev;
  783. struct lbs_private *priv = NULL;
  784. lbs_deb_enter(LBS_DEB_MAIN);
  785. /* Allocate an Ethernet device and register it */
  786. wdev = lbs_cfg_alloc(dmdev);
  787. if (IS_ERR(wdev)) {
  788. pr_err("cfg80211 init failed\n");
  789. goto done;
  790. }
  791. wdev->iftype = NL80211_IFTYPE_STATION;
  792. priv = wdev_priv(wdev);
  793. priv->wdev = wdev;
  794. if (lbs_init_adapter(priv)) {
  795. pr_err("failed to initialize adapter structure\n");
  796. goto err_wdev;
  797. }
  798. dev = alloc_netdev(0, "wlan%d", ether_setup);
  799. if (!dev) {
  800. dev_err(dmdev, "no memory for network device instance\n");
  801. goto err_adapter;
  802. }
  803. dev->ieee80211_ptr = wdev;
  804. dev->ml_priv = priv;
  805. SET_NETDEV_DEV(dev, dmdev);
  806. wdev->netdev = dev;
  807. priv->dev = dev;
  808. dev->netdev_ops = &lbs_netdev_ops;
  809. dev->watchdog_timeo = 5 * HZ;
  810. dev->ethtool_ops = &lbs_ethtool_ops;
  811. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  812. priv->card = card;
  813. strcpy(dev->name, "wlan%d");
  814. lbs_deb_thread("Starting main thread...\n");
  815. init_waitqueue_head(&priv->waitq);
  816. priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
  817. if (IS_ERR(priv->main_thread)) {
  818. lbs_deb_thread("Error creating main thread.\n");
  819. goto err_ndev;
  820. }
  821. priv->work_thread = create_singlethread_workqueue("lbs_worker");
  822. INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
  823. priv->wol_criteria = EHS_REMOVE_WAKEUP;
  824. priv->wol_gpio = 0xff;
  825. priv->wol_gap = 20;
  826. priv->ehs_remove_supported = true;
  827. goto done;
  828. err_ndev:
  829. free_netdev(dev);
  830. err_adapter:
  831. lbs_free_adapter(priv);
  832. err_wdev:
  833. lbs_cfg_free(priv);
  834. priv = NULL;
  835. done:
  836. lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
  837. return priv;
  838. }
  839. EXPORT_SYMBOL_GPL(lbs_add_card);
  840. void lbs_remove_card(struct lbs_private *priv)
  841. {
  842. struct net_device *dev = priv->dev;
  843. lbs_deb_enter(LBS_DEB_MAIN);
  844. lbs_remove_mesh(priv);
  845. lbs_scan_deinit(priv);
  846. /* worker thread destruction blocks on the in-flight command which
  847. * should have been cleared already in lbs_stop_card().
  848. */
  849. lbs_deb_main("destroying worker thread\n");
  850. destroy_workqueue(priv->work_thread);
  851. lbs_deb_main("done destroying worker thread\n");
  852. if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
  853. priv->psmode = LBS802_11POWERMODECAM;
  854. lbs_set_ps_mode(priv, PS_MODE_ACTION_EXIT_PS, true);
  855. }
  856. if (priv->is_deep_sleep) {
  857. priv->is_deep_sleep = 0;
  858. wake_up_interruptible(&priv->ds_awake_q);
  859. }
  860. priv->is_host_sleep_configured = 0;
  861. priv->is_host_sleep_activated = 0;
  862. wake_up_interruptible(&priv->host_sleep_q);
  863. /* Stop the thread servicing the interrupts */
  864. priv->surpriseremoved = 1;
  865. kthread_stop(priv->main_thread);
  866. lbs_free_adapter(priv);
  867. lbs_cfg_free(priv);
  868. free_netdev(dev);
  869. lbs_deb_leave(LBS_DEB_MAIN);
  870. }
  871. EXPORT_SYMBOL_GPL(lbs_remove_card);
  872. int lbs_rtap_supported(struct lbs_private *priv)
  873. {
  874. if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
  875. return 1;
  876. /* newer firmware use a capability mask */
  877. return ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
  878. (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK));
  879. }
  880. int lbs_start_card(struct lbs_private *priv)
  881. {
  882. struct net_device *dev = priv->dev;
  883. int ret = -1;
  884. lbs_deb_enter(LBS_DEB_MAIN);
  885. /* poke the firmware */
  886. ret = lbs_setup_firmware(priv);
  887. if (ret)
  888. goto done;
  889. if (!lbs_disablemesh)
  890. lbs_init_mesh(priv);
  891. else
  892. pr_info("%s: mesh disabled\n", dev->name);
  893. if (lbs_cfg_register(priv)) {
  894. pr_err("cannot register device\n");
  895. goto done;
  896. }
  897. if (lbs_mesh_activated(priv))
  898. lbs_start_mesh(priv);
  899. lbs_debugfs_init_one(priv, dev);
  900. netdev_info(dev, "Marvell WLAN 802.11 adapter\n");
  901. ret = 0;
  902. done:
  903. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  904. return ret;
  905. }
  906. EXPORT_SYMBOL_GPL(lbs_start_card);
  907. void lbs_stop_card(struct lbs_private *priv)
  908. {
  909. struct net_device *dev;
  910. lbs_deb_enter(LBS_DEB_MAIN);
  911. if (!priv)
  912. goto out;
  913. dev = priv->dev;
  914. netif_stop_queue(dev);
  915. netif_carrier_off(dev);
  916. lbs_debugfs_remove_one(priv);
  917. lbs_deinit_mesh(priv);
  918. unregister_netdev(dev);
  919. out:
  920. lbs_deb_leave(LBS_DEB_MAIN);
  921. }
  922. EXPORT_SYMBOL_GPL(lbs_stop_card);
  923. void lbs_queue_event(struct lbs_private *priv, u32 event)
  924. {
  925. unsigned long flags;
  926. lbs_deb_enter(LBS_DEB_THREAD);
  927. spin_lock_irqsave(&priv->driver_lock, flags);
  928. if (priv->psstate == PS_STATE_SLEEP)
  929. priv->psstate = PS_STATE_AWAKE;
  930. kfifo_in(&priv->event_fifo, (unsigned char *) &event, sizeof(u32));
  931. wake_up(&priv->waitq);
  932. spin_unlock_irqrestore(&priv->driver_lock, flags);
  933. lbs_deb_leave(LBS_DEB_THREAD);
  934. }
  935. EXPORT_SYMBOL_GPL(lbs_queue_event);
  936. void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
  937. {
  938. lbs_deb_enter(LBS_DEB_THREAD);
  939. if (priv->psstate == PS_STATE_SLEEP)
  940. priv->psstate = PS_STATE_AWAKE;
  941. /* Swap buffers by flipping the response index */
  942. BUG_ON(resp_idx > 1);
  943. priv->resp_idx = resp_idx;
  944. wake_up(&priv->waitq);
  945. lbs_deb_leave(LBS_DEB_THREAD);
  946. }
  947. EXPORT_SYMBOL_GPL(lbs_notify_command_response);
  948. /**
  949. * lbs_get_firmware - Retrieves two-stage firmware
  950. *
  951. * @dev: A pointer to &device structure
  952. * @user_helper: User-defined helper firmware file
  953. * @user_mainfw: User-defined main firmware file
  954. * @card_model: Bus-specific card model ID used to filter firmware table
  955. * elements
  956. * @fw_table: Table of firmware file names and device model numbers
  957. * terminated by an entry with a NULL helper name
  958. * @helper: On success, the helper firmware; caller must free
  959. * @mainfw: On success, the main firmware; caller must free
  960. *
  961. * returns: 0 on success, non-zero on failure
  962. */
  963. int lbs_get_firmware(struct device *dev, const char *user_helper,
  964. const char *user_mainfw, u32 card_model,
  965. const struct lbs_fw_table *fw_table,
  966. const struct firmware **helper,
  967. const struct firmware **mainfw)
  968. {
  969. const struct lbs_fw_table *iter;
  970. int ret;
  971. BUG_ON(helper == NULL);
  972. BUG_ON(mainfw == NULL);
  973. /* Try user-specified firmware first */
  974. if (user_helper) {
  975. ret = request_firmware(helper, user_helper, dev);
  976. if (ret) {
  977. dev_err(dev, "couldn't find helper firmware %s\n",
  978. user_helper);
  979. goto fail;
  980. }
  981. }
  982. if (user_mainfw) {
  983. ret = request_firmware(mainfw, user_mainfw, dev);
  984. if (ret) {
  985. dev_err(dev, "couldn't find main firmware %s\n",
  986. user_mainfw);
  987. goto fail;
  988. }
  989. }
  990. if (*helper && *mainfw)
  991. return 0;
  992. /* Otherwise search for firmware to use. If neither the helper or
  993. * the main firmware were specified by the user, then we need to
  994. * make sure that found helper & main are from the same entry in
  995. * fw_table.
  996. */
  997. iter = fw_table;
  998. while (iter && iter->helper) {
  999. if (iter->model != card_model)
  1000. goto next;
  1001. if (*helper == NULL) {
  1002. ret = request_firmware(helper, iter->helper, dev);
  1003. if (ret)
  1004. goto next;
  1005. /* If the device has one-stage firmware (ie cf8305) and
  1006. * we've got it then we don't need to bother with the
  1007. * main firmware.
  1008. */
  1009. if (iter->fwname == NULL)
  1010. return 0;
  1011. }
  1012. if (*mainfw == NULL) {
  1013. ret = request_firmware(mainfw, iter->fwname, dev);
  1014. if (ret && !user_helper) {
  1015. /* Clear the helper if it wasn't user-specified
  1016. * and the main firmware load failed, to ensure
  1017. * we don't have mismatched firmware pairs.
  1018. */
  1019. release_firmware(*helper);
  1020. *helper = NULL;
  1021. }
  1022. }
  1023. if (*helper && *mainfw)
  1024. return 0;
  1025. next:
  1026. iter++;
  1027. }
  1028. fail:
  1029. /* Failed */
  1030. if (*helper) {
  1031. release_firmware(*helper);
  1032. *helper = NULL;
  1033. }
  1034. if (*mainfw) {
  1035. release_firmware(*mainfw);
  1036. *mainfw = NULL;
  1037. }
  1038. return -ENOENT;
  1039. }
  1040. EXPORT_SYMBOL_GPL(lbs_get_firmware);
  1041. static int __init lbs_init_module(void)
  1042. {
  1043. lbs_deb_enter(LBS_DEB_MAIN);
  1044. memset(&confirm_sleep, 0, sizeof(confirm_sleep));
  1045. confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
  1046. confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
  1047. confirm_sleep.action = cpu_to_le16(PS_MODE_ACTION_SLEEP_CONFIRMED);
  1048. lbs_debugfs_init();
  1049. lbs_deb_leave(LBS_DEB_MAIN);
  1050. return 0;
  1051. }
  1052. static void __exit lbs_exit_module(void)
  1053. {
  1054. lbs_deb_enter(LBS_DEB_MAIN);
  1055. lbs_debugfs_remove();
  1056. lbs_deb_leave(LBS_DEB_MAIN);
  1057. }
  1058. module_init(lbs_init_module);
  1059. module_exit(lbs_exit_module);
  1060. MODULE_DESCRIPTION("Libertas WLAN Driver Library");
  1061. MODULE_AUTHOR("Marvell International Ltd.");
  1062. MODULE_LICENSE("GPL");