main.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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 || priv->mesh_open)
  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. if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST))
  261. return nr_addrs;
  262. netif_addr_lock_bh(dev);
  263. for (mc_list = dev->mc_list; mc_list; mc_list = mc_list->next) {
  264. if (mac_in_list(cmd->maclist, nr_addrs, mc_list->dmi_addr)) {
  265. lbs_deb_net("mcast address %s:%pM skipped\n", dev->name,
  266. mc_list->dmi_addr);
  267. continue;
  268. }
  269. if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE)
  270. break;
  271. memcpy(&cmd->maclist[6*i], mc_list->dmi_addr, ETH_ALEN);
  272. lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name,
  273. mc_list->dmi_addr);
  274. i++;
  275. }
  276. netif_addr_unlock_bh(dev);
  277. if (mc_list)
  278. return -EOVERFLOW;
  279. return i;
  280. }
  281. static void lbs_set_mcast_worker(struct work_struct *work)
  282. {
  283. struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work);
  284. struct cmd_ds_mac_multicast_adr mcast_cmd;
  285. int dev_flags;
  286. int nr_addrs;
  287. int old_mac_control = priv->mac_control;
  288. lbs_deb_enter(LBS_DEB_NET);
  289. dev_flags = priv->dev->flags;
  290. if (priv->mesh_dev)
  291. dev_flags |= priv->mesh_dev->flags;
  292. if (dev_flags & IFF_PROMISC) {
  293. priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  294. priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE |
  295. CMD_ACT_MAC_MULTICAST_ENABLE);
  296. goto out_set_mac_control;
  297. } else if (dev_flags & IFF_ALLMULTI) {
  298. do_allmulti:
  299. priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  300. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  301. CMD_ACT_MAC_MULTICAST_ENABLE);
  302. goto out_set_mac_control;
  303. }
  304. /* Once for priv->dev, again for priv->mesh_dev if it exists */
  305. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0);
  306. if (nr_addrs >= 0 && priv->mesh_dev)
  307. nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs);
  308. if (nr_addrs < 0)
  309. goto do_allmulti;
  310. if (nr_addrs) {
  311. int size = offsetof(struct cmd_ds_mac_multicast_adr,
  312. maclist[6*nr_addrs]);
  313. mcast_cmd.action = cpu_to_le16(CMD_ACT_SET);
  314. mcast_cmd.hdr.size = cpu_to_le16(size);
  315. mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs);
  316. lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size);
  317. priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
  318. } else
  319. priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
  320. priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE |
  321. CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
  322. out_set_mac_control:
  323. if (priv->mac_control != old_mac_control)
  324. lbs_set_mac_control(priv);
  325. lbs_deb_leave(LBS_DEB_NET);
  326. }
  327. void lbs_set_multicast_list(struct net_device *dev)
  328. {
  329. struct lbs_private *priv = dev->ml_priv;
  330. schedule_work(&priv->mcast_work);
  331. }
  332. /**
  333. * @brief This function handles the major jobs in the LBS driver.
  334. * It handles all events generated by firmware, RX data received
  335. * from firmware and TX data sent from kernel.
  336. *
  337. * @param data A pointer to lbs_thread structure
  338. * @return 0
  339. */
  340. static int lbs_thread(void *data)
  341. {
  342. struct net_device *dev = data;
  343. struct lbs_private *priv = dev->ml_priv;
  344. wait_queue_t wait;
  345. lbs_deb_enter(LBS_DEB_THREAD);
  346. init_waitqueue_entry(&wait, current);
  347. for (;;) {
  348. int shouldsleep;
  349. u8 resp_idx;
  350. lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
  351. priv->currenttxskb, priv->dnld_sent);
  352. add_wait_queue(&priv->waitq, &wait);
  353. set_current_state(TASK_INTERRUPTIBLE);
  354. spin_lock_irq(&priv->driver_lock);
  355. if (kthread_should_stop())
  356. shouldsleep = 0; /* Bye */
  357. else if (priv->surpriseremoved)
  358. shouldsleep = 1; /* We need to wait until we're _told_ to die */
  359. else if (priv->psstate == PS_STATE_SLEEP)
  360. shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */
  361. else if (priv->cmd_timed_out)
  362. shouldsleep = 0; /* Command timed out. Recover */
  363. else if (!priv->fw_ready)
  364. shouldsleep = 1; /* Firmware not ready. We're waiting for it */
  365. else if (priv->dnld_sent)
  366. shouldsleep = 1; /* Something is en route to the device already */
  367. else if (priv->tx_pending_len > 0)
  368. shouldsleep = 0; /* We've a packet to send */
  369. else if (priv->resp_len[priv->resp_idx])
  370. shouldsleep = 0; /* We have a command response */
  371. else if (priv->cur_cmd)
  372. shouldsleep = 1; /* Can't send a command; one already running */
  373. else if (!list_empty(&priv->cmdpendingq) &&
  374. !(priv->wakeup_dev_required))
  375. shouldsleep = 0; /* We have a command to send */
  376. else if (__kfifo_len(priv->event_fifo))
  377. shouldsleep = 0; /* We have an event to process */
  378. else
  379. shouldsleep = 1; /* No command */
  380. if (shouldsleep) {
  381. lbs_deb_thread("sleeping, connect_status %d, "
  382. "psmode %d, psstate %d\n",
  383. priv->connect_status,
  384. priv->psmode, priv->psstate);
  385. spin_unlock_irq(&priv->driver_lock);
  386. schedule();
  387. } else
  388. spin_unlock_irq(&priv->driver_lock);
  389. lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
  390. priv->currenttxskb, priv->dnld_sent);
  391. set_current_state(TASK_RUNNING);
  392. remove_wait_queue(&priv->waitq, &wait);
  393. lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
  394. priv->currenttxskb, priv->dnld_sent);
  395. if (kthread_should_stop()) {
  396. lbs_deb_thread("break from main thread\n");
  397. break;
  398. }
  399. if (priv->surpriseremoved) {
  400. lbs_deb_thread("adapter removed; waiting to die...\n");
  401. continue;
  402. }
  403. lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
  404. priv->currenttxskb, priv->dnld_sent);
  405. /* Process any pending command response */
  406. spin_lock_irq(&priv->driver_lock);
  407. resp_idx = priv->resp_idx;
  408. if (priv->resp_len[resp_idx]) {
  409. spin_unlock_irq(&priv->driver_lock);
  410. lbs_process_command_response(priv,
  411. priv->resp_buf[resp_idx],
  412. priv->resp_len[resp_idx]);
  413. spin_lock_irq(&priv->driver_lock);
  414. priv->resp_len[resp_idx] = 0;
  415. }
  416. spin_unlock_irq(&priv->driver_lock);
  417. /* Process hardware events, e.g. card removed, link lost */
  418. spin_lock_irq(&priv->driver_lock);
  419. while (__kfifo_len(priv->event_fifo)) {
  420. u32 event;
  421. __kfifo_get(priv->event_fifo, (unsigned char *) &event,
  422. sizeof(event));
  423. spin_unlock_irq(&priv->driver_lock);
  424. lbs_process_event(priv, event);
  425. spin_lock_irq(&priv->driver_lock);
  426. }
  427. spin_unlock_irq(&priv->driver_lock);
  428. if (priv->wakeup_dev_required) {
  429. lbs_deb_thread("Waking up device...\n");
  430. /* Wake up device */
  431. if (priv->exit_deep_sleep(priv))
  432. lbs_deb_thread("Wakeup device failed\n");
  433. continue;
  434. }
  435. /* command timeout stuff */
  436. if (priv->cmd_timed_out && priv->cur_cmd) {
  437. struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
  438. if (++priv->nr_retries > 3) {
  439. lbs_pr_info("Excessive timeouts submitting "
  440. "command 0x%04x\n",
  441. le16_to_cpu(cmdnode->cmdbuf->command));
  442. lbs_complete_command(priv, cmdnode, -ETIMEDOUT);
  443. priv->nr_retries = 0;
  444. if (priv->reset_card)
  445. priv->reset_card(priv);
  446. } else {
  447. priv->cur_cmd = NULL;
  448. priv->dnld_sent = DNLD_RES_RECEIVED;
  449. lbs_pr_info("requeueing command 0x%04x due "
  450. "to timeout (#%d)\n",
  451. le16_to_cpu(cmdnode->cmdbuf->command),
  452. priv->nr_retries);
  453. /* Stick it back at the _top_ of the pending queue
  454. for immediate resubmission */
  455. list_add(&cmdnode->list, &priv->cmdpendingq);
  456. }
  457. }
  458. priv->cmd_timed_out = 0;
  459. if (!priv->fw_ready)
  460. continue;
  461. /* Check if we need to confirm Sleep Request received previously */
  462. if (priv->psstate == PS_STATE_PRE_SLEEP &&
  463. !priv->dnld_sent && !priv->cur_cmd) {
  464. if (priv->connect_status == LBS_CONNECTED) {
  465. lbs_deb_thread("pre-sleep, currenttxskb %p, "
  466. "dnld_sent %d, cur_cmd %p\n",
  467. priv->currenttxskb, priv->dnld_sent,
  468. priv->cur_cmd);
  469. lbs_ps_confirm_sleep(priv);
  470. } else {
  471. /* workaround for firmware sending
  472. * deauth/linkloss event immediately
  473. * after sleep request; remove this
  474. * after firmware fixes it
  475. */
  476. priv->psstate = PS_STATE_AWAKE;
  477. lbs_pr_alert("ignore PS_SleepConfirm in "
  478. "non-connected state\n");
  479. }
  480. }
  481. /* The PS state is changed during processing of Sleep Request
  482. * event above
  483. */
  484. if ((priv->psstate == PS_STATE_SLEEP) ||
  485. (priv->psstate == PS_STATE_PRE_SLEEP))
  486. continue;
  487. if (priv->is_deep_sleep)
  488. continue;
  489. /* Execute the next command */
  490. if (!priv->dnld_sent && !priv->cur_cmd)
  491. lbs_execute_next_command(priv);
  492. /* Wake-up command waiters which can't sleep in
  493. * lbs_prepare_and_send_command
  494. */
  495. if (!list_empty(&priv->cmdpendingq))
  496. wake_up_all(&priv->cmd_pending);
  497. spin_lock_irq(&priv->driver_lock);
  498. if (!priv->dnld_sent && priv->tx_pending_len > 0) {
  499. int ret = priv->hw_host_to_card(priv, MVMS_DAT,
  500. priv->tx_pending_buf,
  501. priv->tx_pending_len);
  502. if (ret) {
  503. lbs_deb_tx("host_to_card failed %d\n", ret);
  504. priv->dnld_sent = DNLD_RES_RECEIVED;
  505. }
  506. priv->tx_pending_len = 0;
  507. if (!priv->currenttxskb) {
  508. /* We can wake the queues immediately if we aren't
  509. waiting for TX feedback */
  510. if (priv->connect_status == LBS_CONNECTED)
  511. netif_wake_queue(priv->dev);
  512. if (priv->mesh_dev &&
  513. priv->mesh_connect_status == LBS_CONNECTED)
  514. netif_wake_queue(priv->mesh_dev);
  515. }
  516. }
  517. spin_unlock_irq(&priv->driver_lock);
  518. }
  519. del_timer(&priv->command_timer);
  520. del_timer(&priv->auto_deepsleep_timer);
  521. wake_up_all(&priv->cmd_pending);
  522. lbs_deb_leave(LBS_DEB_THREAD);
  523. return 0;
  524. }
  525. static int lbs_suspend_callback(struct lbs_private *priv, unsigned long dummy,
  526. struct cmd_header *cmd)
  527. {
  528. lbs_deb_enter(LBS_DEB_FW);
  529. netif_device_detach(priv->dev);
  530. if (priv->mesh_dev)
  531. netif_device_detach(priv->mesh_dev);
  532. priv->fw_ready = 0;
  533. lbs_deb_leave(LBS_DEB_FW);
  534. return 0;
  535. }
  536. int lbs_suspend(struct lbs_private *priv)
  537. {
  538. struct cmd_header cmd;
  539. int ret;
  540. lbs_deb_enter(LBS_DEB_FW);
  541. if (priv->wol_criteria == 0xffffffff) {
  542. lbs_pr_info("Suspend attempt without configuring wake params!\n");
  543. return -EINVAL;
  544. }
  545. memset(&cmd, 0, sizeof(cmd));
  546. ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_ACTIVATE, &cmd,
  547. sizeof(cmd), lbs_suspend_callback, 0);
  548. if (ret)
  549. lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret);
  550. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  551. return ret;
  552. }
  553. EXPORT_SYMBOL_GPL(lbs_suspend);
  554. void lbs_resume(struct lbs_private *priv)
  555. {
  556. lbs_deb_enter(LBS_DEB_FW);
  557. priv->fw_ready = 1;
  558. /* Firmware doesn't seem to give us RX packets any more
  559. until we send it some command. Might as well update */
  560. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  561. 0, 0, NULL);
  562. netif_device_attach(priv->dev);
  563. if (priv->mesh_dev)
  564. netif_device_attach(priv->mesh_dev);
  565. lbs_deb_leave(LBS_DEB_FW);
  566. }
  567. EXPORT_SYMBOL_GPL(lbs_resume);
  568. /**
  569. * @brief This function gets the HW spec from the firmware and sets
  570. * some basic parameters.
  571. *
  572. * @param priv A pointer to struct lbs_private structure
  573. * @return 0 or -1
  574. */
  575. static int lbs_setup_firmware(struct lbs_private *priv)
  576. {
  577. int ret = -1;
  578. s16 curlevel = 0, minlevel = 0, maxlevel = 0;
  579. lbs_deb_enter(LBS_DEB_FW);
  580. /* Read MAC address from firmware */
  581. memset(priv->current_addr, 0xff, ETH_ALEN);
  582. ret = lbs_update_hw_spec(priv);
  583. if (ret)
  584. goto done;
  585. /* Read power levels if available */
  586. ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel);
  587. if (ret == 0) {
  588. priv->txpower_cur = curlevel;
  589. priv->txpower_min = minlevel;
  590. priv->txpower_max = maxlevel;
  591. }
  592. lbs_set_mac_control(priv);
  593. done:
  594. lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
  595. return ret;
  596. }
  597. /**
  598. * This function handles the timeout of command sending.
  599. * It will re-send the same command again.
  600. */
  601. static void command_timer_fn(unsigned long data)
  602. {
  603. struct lbs_private *priv = (struct lbs_private *)data;
  604. unsigned long flags;
  605. lbs_deb_enter(LBS_DEB_CMD);
  606. spin_lock_irqsave(&priv->driver_lock, flags);
  607. if (!priv->cur_cmd)
  608. goto out;
  609. lbs_pr_info("command 0x%04x timed out\n",
  610. le16_to_cpu(priv->cur_cmd->cmdbuf->command));
  611. priv->cmd_timed_out = 1;
  612. wake_up_interruptible(&priv->waitq);
  613. out:
  614. spin_unlock_irqrestore(&priv->driver_lock, flags);
  615. lbs_deb_leave(LBS_DEB_CMD);
  616. }
  617. /**
  618. * This function put the device back to deep sleep mode when timer expires
  619. * and no activity (command, event, data etc.) is detected.
  620. */
  621. static void auto_deepsleep_timer_fn(unsigned long data)
  622. {
  623. struct lbs_private *priv = (struct lbs_private *)data;
  624. int ret;
  625. lbs_deb_enter(LBS_DEB_CMD);
  626. if (priv->is_activity_detected) {
  627. priv->is_activity_detected = 0;
  628. } else {
  629. if (priv->is_auto_deep_sleep_enabled &&
  630. (!priv->wakeup_dev_required) &&
  631. (priv->connect_status != LBS_CONNECTED)) {
  632. lbs_deb_main("Entering auto deep sleep mode...\n");
  633. ret = lbs_prepare_and_send_command(priv,
  634. CMD_802_11_DEEP_SLEEP, 0,
  635. 0, 0, NULL);
  636. if (ret)
  637. lbs_pr_err("Enter Deep Sleep command failed\n");
  638. }
  639. }
  640. mod_timer(&priv->auto_deepsleep_timer , jiffies +
  641. (priv->auto_deep_sleep_timeout * HZ)/1000);
  642. lbs_deb_leave(LBS_DEB_CMD);
  643. }
  644. int lbs_enter_auto_deep_sleep(struct lbs_private *priv)
  645. {
  646. lbs_deb_enter(LBS_DEB_SDIO);
  647. priv->is_auto_deep_sleep_enabled = 1;
  648. if (priv->is_deep_sleep)
  649. priv->wakeup_dev_required = 1;
  650. mod_timer(&priv->auto_deepsleep_timer ,
  651. jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000);
  652. lbs_deb_leave(LBS_DEB_SDIO);
  653. return 0;
  654. }
  655. int lbs_exit_auto_deep_sleep(struct lbs_private *priv)
  656. {
  657. lbs_deb_enter(LBS_DEB_SDIO);
  658. priv->is_auto_deep_sleep_enabled = 0;
  659. priv->auto_deep_sleep_timeout = 0;
  660. del_timer(&priv->auto_deepsleep_timer);
  661. lbs_deb_leave(LBS_DEB_SDIO);
  662. return 0;
  663. }
  664. static int lbs_init_adapter(struct lbs_private *priv)
  665. {
  666. size_t bufsize;
  667. int i, ret = 0;
  668. lbs_deb_enter(LBS_DEB_MAIN);
  669. /* Allocate buffer to store the BSSID list */
  670. bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
  671. priv->networks = kzalloc(bufsize, GFP_KERNEL);
  672. if (!priv->networks) {
  673. lbs_pr_err("Out of memory allocating beacons\n");
  674. ret = -1;
  675. goto out;
  676. }
  677. /* Initialize scan result lists */
  678. INIT_LIST_HEAD(&priv->network_free_list);
  679. INIT_LIST_HEAD(&priv->network_list);
  680. for (i = 0; i < MAX_NETWORK_COUNT; i++) {
  681. list_add_tail(&priv->networks[i].list,
  682. &priv->network_free_list);
  683. }
  684. memset(priv->current_addr, 0xff, ETH_ALEN);
  685. priv->connect_status = LBS_DISCONNECTED;
  686. priv->mesh_connect_status = LBS_DISCONNECTED;
  687. priv->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  688. priv->mode = IW_MODE_INFRA;
  689. priv->channel = DEFAULT_AD_HOC_CHANNEL;
  690. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  691. priv->radio_on = 1;
  692. priv->enablehwauto = 1;
  693. priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
  694. priv->psmode = LBS802_11POWERMODECAM;
  695. priv->psstate = PS_STATE_FULL_POWER;
  696. priv->is_deep_sleep = 0;
  697. priv->is_auto_deep_sleep_enabled = 0;
  698. priv->wakeup_dev_required = 0;
  699. init_waitqueue_head(&priv->ds_awake_q);
  700. mutex_init(&priv->lock);
  701. setup_timer(&priv->command_timer, command_timer_fn,
  702. (unsigned long)priv);
  703. setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
  704. (unsigned long)priv);
  705. INIT_LIST_HEAD(&priv->cmdfreeq);
  706. INIT_LIST_HEAD(&priv->cmdpendingq);
  707. spin_lock_init(&priv->driver_lock);
  708. init_waitqueue_head(&priv->cmd_pending);
  709. /* Allocate the command buffers */
  710. if (lbs_allocate_cmd_buffer(priv)) {
  711. lbs_pr_err("Out of memory allocating command buffers\n");
  712. ret = -ENOMEM;
  713. goto out;
  714. }
  715. priv->resp_idx = 0;
  716. priv->resp_len[0] = priv->resp_len[1] = 0;
  717. /* Create the event FIFO */
  718. priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
  719. if (IS_ERR(priv->event_fifo)) {
  720. lbs_pr_err("Out of memory allocating event FIFO buffer\n");
  721. ret = -ENOMEM;
  722. goto out;
  723. }
  724. out:
  725. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  726. return ret;
  727. }
  728. static void lbs_free_adapter(struct lbs_private *priv)
  729. {
  730. lbs_deb_enter(LBS_DEB_MAIN);
  731. lbs_free_cmd_buffer(priv);
  732. if (priv->event_fifo)
  733. kfifo_free(priv->event_fifo);
  734. del_timer(&priv->command_timer);
  735. del_timer(&priv->auto_deepsleep_timer);
  736. kfree(priv->networks);
  737. priv->networks = NULL;
  738. lbs_deb_leave(LBS_DEB_MAIN);
  739. }
  740. static const struct net_device_ops lbs_netdev_ops = {
  741. .ndo_open = lbs_dev_open,
  742. .ndo_stop = lbs_eth_stop,
  743. .ndo_start_xmit = lbs_hard_start_xmit,
  744. .ndo_set_mac_address = lbs_set_mac_address,
  745. .ndo_tx_timeout = lbs_tx_timeout,
  746. .ndo_set_multicast_list = lbs_set_multicast_list,
  747. .ndo_change_mtu = eth_change_mtu,
  748. .ndo_validate_addr = eth_validate_addr,
  749. };
  750. /**
  751. * @brief This function adds the card. it will probe the
  752. * card, allocate the lbs_priv and initialize the device.
  753. *
  754. * @param card A pointer to card
  755. * @return A pointer to struct lbs_private structure
  756. */
  757. struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
  758. {
  759. struct net_device *dev;
  760. struct wireless_dev *wdev;
  761. struct lbs_private *priv = NULL;
  762. lbs_deb_enter(LBS_DEB_MAIN);
  763. /* Allocate an Ethernet device and register it */
  764. wdev = lbs_cfg_alloc(dmdev);
  765. if (IS_ERR(wdev)) {
  766. lbs_pr_err("cfg80211 init failed\n");
  767. goto done;
  768. }
  769. /* TODO? */
  770. wdev->iftype = NL80211_IFTYPE_STATION;
  771. priv = wdev_priv(wdev);
  772. priv->wdev = wdev;
  773. if (lbs_init_adapter(priv)) {
  774. lbs_pr_err("failed to initialize adapter structure.\n");
  775. goto err_wdev;
  776. }
  777. //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
  778. dev = alloc_netdev(0, "wlan%d", ether_setup);
  779. if (!dev) {
  780. dev_err(dmdev, "no memory for network device instance\n");
  781. goto err_adapter;
  782. }
  783. dev->ieee80211_ptr = wdev;
  784. dev->ml_priv = priv;
  785. SET_NETDEV_DEV(dev, dmdev);
  786. wdev->netdev = dev;
  787. priv->dev = dev;
  788. dev->netdev_ops = &lbs_netdev_ops;
  789. dev->watchdog_timeo = 5 * HZ;
  790. dev->ethtool_ops = &lbs_ethtool_ops;
  791. #ifdef WIRELESS_EXT
  792. dev->wireless_handlers = &lbs_handler_def;
  793. #endif
  794. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  795. // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ??
  796. priv->card = card;
  797. priv->infra_open = 0;
  798. priv->rtap_net_dev = NULL;
  799. strcpy(dev->name, "wlan%d");
  800. lbs_deb_thread("Starting main thread...\n");
  801. init_waitqueue_head(&priv->waitq);
  802. priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
  803. if (IS_ERR(priv->main_thread)) {
  804. lbs_deb_thread("Error creating main thread.\n");
  805. goto err_ndev;
  806. }
  807. priv->work_thread = create_singlethread_workqueue("lbs_worker");
  808. INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
  809. INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
  810. INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
  811. priv->wol_criteria = 0xffffffff;
  812. priv->wol_gpio = 0xff;
  813. goto done;
  814. err_ndev:
  815. free_netdev(dev);
  816. err_adapter:
  817. lbs_free_adapter(priv);
  818. err_wdev:
  819. lbs_cfg_free(priv);
  820. priv = NULL;
  821. done:
  822. lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
  823. return priv;
  824. }
  825. EXPORT_SYMBOL_GPL(lbs_add_card);
  826. void lbs_remove_card(struct lbs_private *priv)
  827. {
  828. struct net_device *dev = priv->dev;
  829. lbs_deb_enter(LBS_DEB_MAIN);
  830. lbs_remove_mesh(priv);
  831. lbs_remove_rtap(priv);
  832. dev = priv->dev;
  833. cancel_delayed_work_sync(&priv->scan_work);
  834. cancel_delayed_work_sync(&priv->assoc_work);
  835. cancel_work_sync(&priv->mcast_work);
  836. /* worker thread destruction blocks on the in-flight command which
  837. * should have been cleared already in lbs_stop_card().
  838. */
  839. lbs_deb_main("destroying worker thread\n");
  840. destroy_workqueue(priv->work_thread);
  841. lbs_deb_main("done destroying worker thread\n");
  842. if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
  843. priv->psmode = LBS802_11POWERMODECAM;
  844. lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
  845. }
  846. lbs_send_disconnect_notification(priv);
  847. if (priv->is_deep_sleep) {
  848. priv->is_deep_sleep = 0;
  849. wake_up_interruptible(&priv->ds_awake_q);
  850. }
  851. /* Stop the thread servicing the interrupts */
  852. priv->surpriseremoved = 1;
  853. kthread_stop(priv->main_thread);
  854. lbs_free_adapter(priv);
  855. lbs_cfg_free(priv);
  856. priv->dev = NULL;
  857. free_netdev(dev);
  858. lbs_deb_leave(LBS_DEB_MAIN);
  859. }
  860. EXPORT_SYMBOL_GPL(lbs_remove_card);
  861. static int lbs_rtap_supported(struct lbs_private *priv)
  862. {
  863. if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
  864. return 1;
  865. /* newer firmware use a capability mask */
  866. return ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
  867. (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK));
  868. }
  869. int lbs_start_card(struct lbs_private *priv)
  870. {
  871. struct net_device *dev = priv->dev;
  872. int ret = -1;
  873. lbs_deb_enter(LBS_DEB_MAIN);
  874. /* poke the firmware */
  875. ret = lbs_setup_firmware(priv);
  876. if (ret)
  877. goto done;
  878. if (lbs_cfg_register(priv)) {
  879. lbs_pr_err("cannot register device\n");
  880. goto done;
  881. }
  882. lbs_update_channel(priv);
  883. lbs_init_mesh(priv);
  884. /*
  885. * While rtap isn't related to mesh, only mesh-enabled
  886. * firmware implements the rtap functionality via
  887. * CMD_802_11_MONITOR_MODE.
  888. */
  889. if (lbs_rtap_supported(priv)) {
  890. if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
  891. lbs_pr_err("cannot register lbs_rtap attribute\n");
  892. }
  893. lbs_debugfs_init_one(priv, dev);
  894. lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
  895. ret = 0;
  896. done:
  897. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  898. return ret;
  899. }
  900. EXPORT_SYMBOL_GPL(lbs_start_card);
  901. void lbs_stop_card(struct lbs_private *priv)
  902. {
  903. struct net_device *dev;
  904. struct cmd_ctrl_node *cmdnode;
  905. unsigned long flags;
  906. lbs_deb_enter(LBS_DEB_MAIN);
  907. if (!priv)
  908. goto out;
  909. dev = priv->dev;
  910. netif_stop_queue(dev);
  911. netif_carrier_off(dev);
  912. lbs_debugfs_remove_one(priv);
  913. lbs_deinit_mesh(priv);
  914. if (lbs_rtap_supported(priv))
  915. device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
  916. /* Delete the timeout of the currently processing command */
  917. del_timer_sync(&priv->command_timer);
  918. del_timer_sync(&priv->auto_deepsleep_timer);
  919. /* Flush pending command nodes */
  920. spin_lock_irqsave(&priv->driver_lock, flags);
  921. lbs_deb_main("clearing pending commands\n");
  922. list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
  923. cmdnode->result = -ENOENT;
  924. cmdnode->cmdwaitqwoken = 1;
  925. wake_up_interruptible(&cmdnode->cmdwait_q);
  926. }
  927. /* Flush the command the card is currently processing */
  928. if (priv->cur_cmd) {
  929. lbs_deb_main("clearing current command\n");
  930. priv->cur_cmd->result = -ENOENT;
  931. priv->cur_cmd->cmdwaitqwoken = 1;
  932. wake_up_interruptible(&priv->cur_cmd->cmdwait_q);
  933. }
  934. lbs_deb_main("done clearing commands\n");
  935. spin_unlock_irqrestore(&priv->driver_lock, flags);
  936. unregister_netdev(dev);
  937. out:
  938. lbs_deb_leave(LBS_DEB_MAIN);
  939. }
  940. EXPORT_SYMBOL_GPL(lbs_stop_card);
  941. void lbs_queue_event(struct lbs_private *priv, u32 event)
  942. {
  943. unsigned long flags;
  944. lbs_deb_enter(LBS_DEB_THREAD);
  945. spin_lock_irqsave(&priv->driver_lock, flags);
  946. if (priv->psstate == PS_STATE_SLEEP)
  947. priv->psstate = PS_STATE_AWAKE;
  948. __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
  949. wake_up_interruptible(&priv->waitq);
  950. spin_unlock_irqrestore(&priv->driver_lock, flags);
  951. lbs_deb_leave(LBS_DEB_THREAD);
  952. }
  953. EXPORT_SYMBOL_GPL(lbs_queue_event);
  954. void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
  955. {
  956. lbs_deb_enter(LBS_DEB_THREAD);
  957. if (priv->psstate == PS_STATE_SLEEP)
  958. priv->psstate = PS_STATE_AWAKE;
  959. /* Swap buffers by flipping the response index */
  960. BUG_ON(resp_idx > 1);
  961. priv->resp_idx = resp_idx;
  962. wake_up_interruptible(&priv->waitq);
  963. lbs_deb_leave(LBS_DEB_THREAD);
  964. }
  965. EXPORT_SYMBOL_GPL(lbs_notify_command_response);
  966. static int __init lbs_init_module(void)
  967. {
  968. lbs_deb_enter(LBS_DEB_MAIN);
  969. memset(&confirm_sleep, 0, sizeof(confirm_sleep));
  970. confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
  971. confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
  972. confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
  973. lbs_debugfs_init();
  974. lbs_deb_leave(LBS_DEB_MAIN);
  975. return 0;
  976. }
  977. static void __exit lbs_exit_module(void)
  978. {
  979. lbs_deb_enter(LBS_DEB_MAIN);
  980. lbs_debugfs_remove();
  981. lbs_deb_leave(LBS_DEB_MAIN);
  982. }
  983. /*
  984. * rtap interface support fuctions
  985. */
  986. static int lbs_rtap_open(struct net_device *dev)
  987. {
  988. /* Yes, _stop_ the queue. Because we don't support injection */
  989. lbs_deb_enter(LBS_DEB_MAIN);
  990. netif_carrier_off(dev);
  991. netif_stop_queue(dev);
  992. lbs_deb_leave(LBS_DEB_LEAVE);
  993. return 0;
  994. }
  995. static int lbs_rtap_stop(struct net_device *dev)
  996. {
  997. lbs_deb_enter(LBS_DEB_MAIN);
  998. lbs_deb_leave(LBS_DEB_MAIN);
  999. return 0;
  1000. }
  1001. static netdev_tx_t lbs_rtap_hard_start_xmit(struct sk_buff *skb,
  1002. struct net_device *dev)
  1003. {
  1004. netif_stop_queue(dev);
  1005. return NETDEV_TX_BUSY;
  1006. }
  1007. static void lbs_remove_rtap(struct lbs_private *priv)
  1008. {
  1009. lbs_deb_enter(LBS_DEB_MAIN);
  1010. if (priv->rtap_net_dev == NULL)
  1011. goto out;
  1012. unregister_netdev(priv->rtap_net_dev);
  1013. free_netdev(priv->rtap_net_dev);
  1014. priv->rtap_net_dev = NULL;
  1015. out:
  1016. lbs_deb_leave(LBS_DEB_MAIN);
  1017. }
  1018. static const struct net_device_ops rtap_netdev_ops = {
  1019. .ndo_open = lbs_rtap_open,
  1020. .ndo_stop = lbs_rtap_stop,
  1021. .ndo_start_xmit = lbs_rtap_hard_start_xmit,
  1022. };
  1023. static int lbs_add_rtap(struct lbs_private *priv)
  1024. {
  1025. int ret = 0;
  1026. struct net_device *rtap_dev;
  1027. lbs_deb_enter(LBS_DEB_MAIN);
  1028. if (priv->rtap_net_dev) {
  1029. ret = -EPERM;
  1030. goto out;
  1031. }
  1032. rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
  1033. if (rtap_dev == NULL) {
  1034. ret = -ENOMEM;
  1035. goto out;
  1036. }
  1037. memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
  1038. rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
  1039. rtap_dev->netdev_ops = &rtap_netdev_ops;
  1040. rtap_dev->ml_priv = priv;
  1041. SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent);
  1042. ret = register_netdev(rtap_dev);
  1043. if (ret) {
  1044. free_netdev(rtap_dev);
  1045. goto out;
  1046. }
  1047. priv->rtap_net_dev = rtap_dev;
  1048. out:
  1049. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1050. return ret;
  1051. }
  1052. module_init(lbs_init_module);
  1053. module_exit(lbs_exit_module);
  1054. MODULE_DESCRIPTION("Libertas WLAN Driver Library");
  1055. MODULE_AUTHOR("Marvell International Ltd.");
  1056. MODULE_LICENSE("GPL");