main.c 31 KB

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