main.c 32 KB

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