main.c 31 KB

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