main.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. /**
  2. * This file contains the major functions in WLAN
  3. * driver. It includes init, exit, open, close and main
  4. * thread etc..
  5. */
  6. #include <linux/moduleparam.h>
  7. #include <linux/delay.h>
  8. #include <linux/etherdevice.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/if_arp.h>
  11. #include <linux/kthread.h>
  12. #include <linux/kfifo.h>
  13. #include <linux/stddef.h>
  14. #include <linux/ieee80211.h>
  15. #include <net/iw_handler.h>
  16. #include <net/cfg80211.h>
  17. #include "host.h"
  18. #include "decl.h"
  19. #include "dev.h"
  20. #include "wext.h"
  21. #include "cfg.h"
  22. #include "debugfs.h"
  23. #include "scan.h"
  24. #include "assoc.h"
  25. #include "cmd.h"
  26. #define DRIVER_RELEASE_VERSION "323.p0"
  27. const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
  28. #ifdef DEBUG
  29. "-dbg"
  30. #endif
  31. "";
  32. /* Module parameters */
  33. unsigned int lbs_debug;
  34. EXPORT_SYMBOL_GPL(lbs_debug);
  35. module_param_named(libertas_debug, lbs_debug, int, 0644);
  36. /* This global structure is used to send the confirm_sleep command as
  37. * fast as possible down to the firmware. */
  38. struct cmd_confirm_sleep confirm_sleep;
  39. /**
  40. * the table to keep region code
  41. */
  42. u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] =
  43. { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
  44. /**
  45. * FW rate table. FW refers to rates by their index in this table, not by the
  46. * rate value itself. Values of 0x00 are
  47. * reserved positions.
  48. */
  49. static u8 fw_data_rates[MAX_RATES] =
  50. { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
  51. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
  52. };
  53. /**
  54. * @brief use index to get the data rate
  55. *
  56. * @param idx The index of data rate
  57. * @return data rate or 0
  58. */
  59. u32 lbs_fw_index_to_data_rate(u8 idx)
  60. {
  61. if (idx >= sizeof(fw_data_rates))
  62. idx = 0;
  63. return fw_data_rates[idx];
  64. }
  65. /**
  66. * @brief use rate to get the index
  67. *
  68. * @param rate data rate
  69. * @return index or 0
  70. */
  71. u8 lbs_data_rate_to_fw_index(u32 rate)
  72. {
  73. u8 i;
  74. if (!rate)
  75. return 0;
  76. for (i = 0; i < sizeof(fw_data_rates); i++) {
  77. if (rate == fw_data_rates[i])
  78. return i;
  79. }
  80. return 0;
  81. }
  82. static int lbs_add_rtap(struct lbs_private *priv);
  83. static void lbs_remove_rtap(struct lbs_private *priv);
  84. /**
  85. * Get function for sysfs attribute rtap
  86. */
  87. static ssize_t lbs_rtap_get(struct device *dev,
  88. struct device_attribute *attr, char * buf)
  89. {
  90. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  91. return snprintf(buf, 5, "0x%X\n", priv->monitormode);
  92. }
  93. /**
  94. * Set function for sysfs attribute rtap
  95. */
  96. static ssize_t lbs_rtap_set(struct device *dev,
  97. struct device_attribute *attr, const char * buf, size_t count)
  98. {
  99. int monitor_mode;
  100. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  101. sscanf(buf, "%x", &monitor_mode);
  102. if (monitor_mode) {
  103. if (priv->monitormode == monitor_mode)
  104. return strlen(buf);
  105. if (!priv->monitormode) {
  106. if (priv->infra_open || lbs_mesh_open(priv))
  107. return -EBUSY;
  108. if (priv->mode == IW_MODE_INFRA)
  109. lbs_cmd_80211_deauthenticate(priv,
  110. priv->curbssparams.bssid,
  111. WLAN_REASON_DEAUTH_LEAVING);
  112. else if (priv->mode == IW_MODE_ADHOC)
  113. lbs_adhoc_stop(priv);
  114. lbs_add_rtap(priv);
  115. }
  116. priv->monitormode = monitor_mode;
  117. } else {
  118. if (!priv->monitormode)
  119. return strlen(buf);
  120. priv->monitormode = 0;
  121. lbs_remove_rtap(priv);
  122. if (priv->currenttxskb) {
  123. dev_kfree_skb_any(priv->currenttxskb);
  124. priv->currenttxskb = NULL;
  125. }
  126. /* Wake queues, command thread, etc. */
  127. lbs_host_to_card_done(priv);
  128. }
  129. lbs_prepare_and_send_command(priv,
  130. CMD_802_11_MONITOR_MODE, CMD_ACT_SET,
  131. CMD_OPTION_WAITFORRSP, 0, &priv->monitormode);
  132. return strlen(buf);
  133. }
  134. /**
  135. * lbs_rtap attribute to be exported per ethX interface
  136. * through sysfs (/sys/class/net/ethX/lbs_rtap)
  137. */
  138. static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
  139. /**
  140. * @brief This function opens the ethX interface
  141. *
  142. * @param dev A pointer to net_device structure
  143. * @return 0 or -EBUSY if monitor mode active
  144. */
  145. static int lbs_dev_open(struct net_device *dev)
  146. {
  147. struct lbs_private *priv = dev->ml_priv;
  148. int ret = 0;
  149. lbs_deb_enter(LBS_DEB_NET);
  150. spin_lock_irq(&priv->driver_lock);
  151. if (priv->monitormode) {
  152. ret = -EBUSY;
  153. goto out;
  154. }
  155. priv->infra_open = 1;
  156. if (priv->connect_status == LBS_CONNECTED)
  157. netif_carrier_on(dev);
  158. else
  159. netif_carrier_off(dev);
  160. if (!priv->tx_pending_len)
  161. netif_wake_queue(dev);
  162. out:
  163. spin_unlock_irq(&priv->driver_lock);
  164. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  165. return ret;
  166. }
  167. /**
  168. * @brief This function closes the ethX interface
  169. *
  170. * @param dev A pointer to net_device structure
  171. * @return 0
  172. */
  173. static int lbs_eth_stop(struct net_device *dev)
  174. {
  175. struct lbs_private *priv = dev->ml_priv;
  176. lbs_deb_enter(LBS_DEB_NET);
  177. spin_lock_irq(&priv->driver_lock);
  178. priv->infra_open = 0;
  179. netif_stop_queue(dev);
  180. spin_unlock_irq(&priv->driver_lock);
  181. schedule_work(&priv->mcast_work);
  182. lbs_deb_leave(LBS_DEB_NET);
  183. return 0;
  184. }
  185. static void lbs_tx_timeout(struct net_device *dev)
  186. {
  187. struct lbs_private *priv = dev->ml_priv;
  188. lbs_deb_enter(LBS_DEB_TX);
  189. lbs_pr_err("tx watch dog timeout\n");
  190. dev->trans_start = jiffies;
  191. if (priv->currenttxskb)
  192. lbs_send_tx_feedback(priv, 0);
  193. /* XX: Shouldn't we also call into the hw-specific driver
  194. to kick it somehow? */
  195. lbs_host_to_card_done(priv);
  196. /* More often than not, this actually happens because the
  197. firmware has crapped itself -- rather than just a very
  198. busy medium. So send a harmless command, and if/when
  199. _that_ times out, we'll kick it in the head. */
  200. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  201. 0, 0, NULL);
  202. lbs_deb_leave(LBS_DEB_TX);
  203. }
  204. void lbs_host_to_card_done(struct lbs_private *priv)
  205. {
  206. unsigned long flags;
  207. lbs_deb_enter(LBS_DEB_THREAD);
  208. spin_lock_irqsave(&priv->driver_lock, flags);
  209. priv->dnld_sent = DNLD_RES_RECEIVED;
  210. /* Wake main thread if commands are pending */
  211. if (!priv->cur_cmd || priv->tx_pending_len > 0) {
  212. if (!priv->wakeup_dev_required)
  213. wake_up_interruptible(&priv->waitq);
  214. }
  215. spin_unlock_irqrestore(&priv->driver_lock, flags);
  216. lbs_deb_leave(LBS_DEB_THREAD);
  217. }
  218. EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
  219. int lbs_set_mac_address(struct net_device *dev, void *addr)
  220. {
  221. int ret = 0;
  222. struct lbs_private *priv = dev->ml_priv;
  223. struct sockaddr *phwaddr = addr;
  224. struct cmd_ds_802_11_mac_address cmd;
  225. lbs_deb_enter(LBS_DEB_NET);
  226. /* In case it was called from the mesh device */
  227. dev = priv->dev;
  228. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  229. cmd.action = cpu_to_le16(CMD_ACT_SET);
  230. memcpy(cmd.macadd, phwaddr->sa_data, ETH_ALEN);
  231. ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd);
  232. if (ret) {
  233. lbs_deb_net("set MAC address failed\n");
  234. goto done;
  235. }
  236. memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN);
  237. memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  238. if (priv->mesh_dev)
  239. memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN);
  240. done:
  241. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  242. return ret;
  243. }
  244. static inline int mac_in_list(unsigned char *list, int list_len,
  245. unsigned char *mac)
  246. {
  247. while (list_len) {
  248. if (!memcmp(list, mac, ETH_ALEN))
  249. return 1;
  250. list += ETH_ALEN;
  251. list_len--;
  252. }
  253. return 0;
  254. }
  255. static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd,
  256. struct net_device *dev, int nr_addrs)
  257. {
  258. int i = nr_addrs;
  259. struct dev_mc_list *mc_list;
  260. 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. lbs_mesh_connected(priv))
  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->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  687. priv->mode = IW_MODE_INFRA;
  688. priv->channel = DEFAULT_AD_HOC_CHANNEL;
  689. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  690. priv->radio_on = 1;
  691. priv->enablehwauto = 1;
  692. priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
  693. priv->psmode = LBS802_11POWERMODECAM;
  694. priv->psstate = PS_STATE_FULL_POWER;
  695. priv->is_deep_sleep = 0;
  696. priv->is_auto_deep_sleep_enabled = 0;
  697. priv->wakeup_dev_required = 0;
  698. init_waitqueue_head(&priv->ds_awake_q);
  699. mutex_init(&priv->lock);
  700. setup_timer(&priv->command_timer, command_timer_fn,
  701. (unsigned long)priv);
  702. setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn,
  703. (unsigned long)priv);
  704. INIT_LIST_HEAD(&priv->cmdfreeq);
  705. INIT_LIST_HEAD(&priv->cmdpendingq);
  706. spin_lock_init(&priv->driver_lock);
  707. init_waitqueue_head(&priv->cmd_pending);
  708. /* Allocate the command buffers */
  709. if (lbs_allocate_cmd_buffer(priv)) {
  710. lbs_pr_err("Out of memory allocating command buffers\n");
  711. ret = -ENOMEM;
  712. goto out;
  713. }
  714. priv->resp_idx = 0;
  715. priv->resp_len[0] = priv->resp_len[1] = 0;
  716. /* Create the event FIFO */
  717. priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
  718. if (IS_ERR(priv->event_fifo)) {
  719. lbs_pr_err("Out of memory allocating event FIFO buffer\n");
  720. ret = -ENOMEM;
  721. goto out;
  722. }
  723. out:
  724. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  725. return ret;
  726. }
  727. static void lbs_free_adapter(struct lbs_private *priv)
  728. {
  729. lbs_deb_enter(LBS_DEB_MAIN);
  730. lbs_free_cmd_buffer(priv);
  731. if (priv->event_fifo)
  732. kfifo_free(priv->event_fifo);
  733. del_timer(&priv->command_timer);
  734. del_timer(&priv->auto_deepsleep_timer);
  735. kfree(priv->networks);
  736. priv->networks = NULL;
  737. lbs_deb_leave(LBS_DEB_MAIN);
  738. }
  739. static const struct net_device_ops lbs_netdev_ops = {
  740. .ndo_open = lbs_dev_open,
  741. .ndo_stop = lbs_eth_stop,
  742. .ndo_start_xmit = lbs_hard_start_xmit,
  743. .ndo_set_mac_address = lbs_set_mac_address,
  744. .ndo_tx_timeout = lbs_tx_timeout,
  745. .ndo_set_multicast_list = lbs_set_multicast_list,
  746. .ndo_change_mtu = eth_change_mtu,
  747. .ndo_validate_addr = eth_validate_addr,
  748. };
  749. /**
  750. * @brief This function adds the card. it will probe the
  751. * card, allocate the lbs_priv and initialize the device.
  752. *
  753. * @param card A pointer to card
  754. * @return A pointer to struct lbs_private structure
  755. */
  756. struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
  757. {
  758. struct net_device *dev;
  759. struct wireless_dev *wdev;
  760. struct lbs_private *priv = NULL;
  761. lbs_deb_enter(LBS_DEB_MAIN);
  762. /* Allocate an Ethernet device and register it */
  763. wdev = lbs_cfg_alloc(dmdev);
  764. if (IS_ERR(wdev)) {
  765. lbs_pr_err("cfg80211 init failed\n");
  766. goto done;
  767. }
  768. /* TODO? */
  769. wdev->iftype = NL80211_IFTYPE_STATION;
  770. priv = wdev_priv(wdev);
  771. priv->wdev = wdev;
  772. if (lbs_init_adapter(priv)) {
  773. lbs_pr_err("failed to initialize adapter structure.\n");
  774. goto err_wdev;
  775. }
  776. //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
  777. dev = alloc_netdev(0, "wlan%d", ether_setup);
  778. if (!dev) {
  779. dev_err(dmdev, "no memory for network device instance\n");
  780. goto err_adapter;
  781. }
  782. dev->ieee80211_ptr = wdev;
  783. dev->ml_priv = priv;
  784. SET_NETDEV_DEV(dev, dmdev);
  785. wdev->netdev = dev;
  786. priv->dev = dev;
  787. dev->netdev_ops = &lbs_netdev_ops;
  788. dev->watchdog_timeo = 5 * HZ;
  789. dev->ethtool_ops = &lbs_ethtool_ops;
  790. #ifdef WIRELESS_EXT
  791. dev->wireless_handlers = &lbs_handler_def;
  792. #endif
  793. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  794. // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ??
  795. priv->card = card;
  796. priv->infra_open = 0;
  797. priv->rtap_net_dev = NULL;
  798. strcpy(dev->name, "wlan%d");
  799. lbs_deb_thread("Starting main thread...\n");
  800. init_waitqueue_head(&priv->waitq);
  801. priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main");
  802. if (IS_ERR(priv->main_thread)) {
  803. lbs_deb_thread("Error creating main thread.\n");
  804. goto err_ndev;
  805. }
  806. priv->work_thread = create_singlethread_workqueue("lbs_worker");
  807. INIT_DELAYED_WORK(&priv->assoc_work, lbs_association_worker);
  808. INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
  809. INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
  810. priv->wol_criteria = 0xffffffff;
  811. priv->wol_gpio = 0xff;
  812. goto done;
  813. err_ndev:
  814. free_netdev(dev);
  815. err_adapter:
  816. lbs_free_adapter(priv);
  817. err_wdev:
  818. lbs_cfg_free(priv);
  819. priv = NULL;
  820. done:
  821. lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv);
  822. return priv;
  823. }
  824. EXPORT_SYMBOL_GPL(lbs_add_card);
  825. void lbs_remove_card(struct lbs_private *priv)
  826. {
  827. struct net_device *dev = priv->dev;
  828. lbs_deb_enter(LBS_DEB_MAIN);
  829. lbs_remove_mesh(priv);
  830. lbs_remove_rtap(priv);
  831. dev = priv->dev;
  832. cancel_delayed_work_sync(&priv->scan_work);
  833. cancel_delayed_work_sync(&priv->assoc_work);
  834. cancel_work_sync(&priv->mcast_work);
  835. /* worker thread destruction blocks on the in-flight command which
  836. * should have been cleared already in lbs_stop_card().
  837. */
  838. lbs_deb_main("destroying worker thread\n");
  839. destroy_workqueue(priv->work_thread);
  840. lbs_deb_main("done destroying worker thread\n");
  841. if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
  842. priv->psmode = LBS802_11POWERMODECAM;
  843. lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
  844. }
  845. lbs_send_disconnect_notification(priv);
  846. if (priv->is_deep_sleep) {
  847. priv->is_deep_sleep = 0;
  848. wake_up_interruptible(&priv->ds_awake_q);
  849. }
  850. /* Stop the thread servicing the interrupts */
  851. priv->surpriseremoved = 1;
  852. kthread_stop(priv->main_thread);
  853. lbs_free_adapter(priv);
  854. lbs_cfg_free(priv);
  855. priv->dev = NULL;
  856. free_netdev(dev);
  857. lbs_deb_leave(LBS_DEB_MAIN);
  858. }
  859. EXPORT_SYMBOL_GPL(lbs_remove_card);
  860. static int lbs_rtap_supported(struct lbs_private *priv)
  861. {
  862. if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
  863. return 1;
  864. /* newer firmware use a capability mask */
  865. return ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
  866. (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK));
  867. }
  868. int lbs_start_card(struct lbs_private *priv)
  869. {
  870. struct net_device *dev = priv->dev;
  871. int ret = -1;
  872. lbs_deb_enter(LBS_DEB_MAIN);
  873. /* poke the firmware */
  874. ret = lbs_setup_firmware(priv);
  875. if (ret)
  876. goto done;
  877. if (lbs_cfg_register(priv)) {
  878. lbs_pr_err("cannot register device\n");
  879. goto done;
  880. }
  881. lbs_update_channel(priv);
  882. lbs_init_mesh(priv);
  883. /*
  884. * While rtap isn't related to mesh, only mesh-enabled
  885. * firmware implements the rtap functionality via
  886. * CMD_802_11_MONITOR_MODE.
  887. */
  888. if (lbs_rtap_supported(priv)) {
  889. if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
  890. lbs_pr_err("cannot register lbs_rtap attribute\n");
  891. }
  892. lbs_debugfs_init_one(priv, dev);
  893. lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name);
  894. ret = 0;
  895. done:
  896. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  897. return ret;
  898. }
  899. EXPORT_SYMBOL_GPL(lbs_start_card);
  900. void lbs_stop_card(struct lbs_private *priv)
  901. {
  902. struct net_device *dev;
  903. struct cmd_ctrl_node *cmdnode;
  904. unsigned long flags;
  905. lbs_deb_enter(LBS_DEB_MAIN);
  906. if (!priv)
  907. goto out;
  908. dev = priv->dev;
  909. netif_stop_queue(dev);
  910. netif_carrier_off(dev);
  911. lbs_debugfs_remove_one(priv);
  912. lbs_deinit_mesh(priv);
  913. if (lbs_rtap_supported(priv))
  914. device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
  915. /* Delete the timeout of the currently processing command */
  916. del_timer_sync(&priv->command_timer);
  917. del_timer_sync(&priv->auto_deepsleep_timer);
  918. /* Flush pending command nodes */
  919. spin_lock_irqsave(&priv->driver_lock, flags);
  920. lbs_deb_main("clearing pending commands\n");
  921. list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
  922. cmdnode->result = -ENOENT;
  923. cmdnode->cmdwaitqwoken = 1;
  924. wake_up_interruptible(&cmdnode->cmdwait_q);
  925. }
  926. /* Flush the command the card is currently processing */
  927. if (priv->cur_cmd) {
  928. lbs_deb_main("clearing current command\n");
  929. priv->cur_cmd->result = -ENOENT;
  930. priv->cur_cmd->cmdwaitqwoken = 1;
  931. wake_up_interruptible(&priv->cur_cmd->cmdwait_q);
  932. }
  933. lbs_deb_main("done clearing commands\n");
  934. spin_unlock_irqrestore(&priv->driver_lock, flags);
  935. unregister_netdev(dev);
  936. out:
  937. lbs_deb_leave(LBS_DEB_MAIN);
  938. }
  939. EXPORT_SYMBOL_GPL(lbs_stop_card);
  940. void lbs_queue_event(struct lbs_private *priv, u32 event)
  941. {
  942. unsigned long flags;
  943. lbs_deb_enter(LBS_DEB_THREAD);
  944. spin_lock_irqsave(&priv->driver_lock, flags);
  945. if (priv->psstate == PS_STATE_SLEEP)
  946. priv->psstate = PS_STATE_AWAKE;
  947. __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
  948. wake_up_interruptible(&priv->waitq);
  949. spin_unlock_irqrestore(&priv->driver_lock, flags);
  950. lbs_deb_leave(LBS_DEB_THREAD);
  951. }
  952. EXPORT_SYMBOL_GPL(lbs_queue_event);
  953. void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
  954. {
  955. lbs_deb_enter(LBS_DEB_THREAD);
  956. if (priv->psstate == PS_STATE_SLEEP)
  957. priv->psstate = PS_STATE_AWAKE;
  958. /* Swap buffers by flipping the response index */
  959. BUG_ON(resp_idx > 1);
  960. priv->resp_idx = resp_idx;
  961. wake_up_interruptible(&priv->waitq);
  962. lbs_deb_leave(LBS_DEB_THREAD);
  963. }
  964. EXPORT_SYMBOL_GPL(lbs_notify_command_response);
  965. static int __init lbs_init_module(void)
  966. {
  967. lbs_deb_enter(LBS_DEB_MAIN);
  968. memset(&confirm_sleep, 0, sizeof(confirm_sleep));
  969. confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE);
  970. confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep));
  971. confirm_sleep.action = cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
  972. lbs_debugfs_init();
  973. lbs_deb_leave(LBS_DEB_MAIN);
  974. return 0;
  975. }
  976. static void __exit lbs_exit_module(void)
  977. {
  978. lbs_deb_enter(LBS_DEB_MAIN);
  979. lbs_debugfs_remove();
  980. lbs_deb_leave(LBS_DEB_MAIN);
  981. }
  982. /*
  983. * rtap interface support fuctions
  984. */
  985. static int lbs_rtap_open(struct net_device *dev)
  986. {
  987. /* Yes, _stop_ the queue. Because we don't support injection */
  988. lbs_deb_enter(LBS_DEB_MAIN);
  989. netif_carrier_off(dev);
  990. netif_stop_queue(dev);
  991. lbs_deb_leave(LBS_DEB_LEAVE);
  992. return 0;
  993. }
  994. static int lbs_rtap_stop(struct net_device *dev)
  995. {
  996. lbs_deb_enter(LBS_DEB_MAIN);
  997. lbs_deb_leave(LBS_DEB_MAIN);
  998. return 0;
  999. }
  1000. static netdev_tx_t lbs_rtap_hard_start_xmit(struct sk_buff *skb,
  1001. struct net_device *dev)
  1002. {
  1003. netif_stop_queue(dev);
  1004. return NETDEV_TX_BUSY;
  1005. }
  1006. static void lbs_remove_rtap(struct lbs_private *priv)
  1007. {
  1008. lbs_deb_enter(LBS_DEB_MAIN);
  1009. if (priv->rtap_net_dev == NULL)
  1010. goto out;
  1011. unregister_netdev(priv->rtap_net_dev);
  1012. free_netdev(priv->rtap_net_dev);
  1013. priv->rtap_net_dev = NULL;
  1014. out:
  1015. lbs_deb_leave(LBS_DEB_MAIN);
  1016. }
  1017. static const struct net_device_ops rtap_netdev_ops = {
  1018. .ndo_open = lbs_rtap_open,
  1019. .ndo_stop = lbs_rtap_stop,
  1020. .ndo_start_xmit = lbs_rtap_hard_start_xmit,
  1021. };
  1022. static int lbs_add_rtap(struct lbs_private *priv)
  1023. {
  1024. int ret = 0;
  1025. struct net_device *rtap_dev;
  1026. lbs_deb_enter(LBS_DEB_MAIN);
  1027. if (priv->rtap_net_dev) {
  1028. ret = -EPERM;
  1029. goto out;
  1030. }
  1031. rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
  1032. if (rtap_dev == NULL) {
  1033. ret = -ENOMEM;
  1034. goto out;
  1035. }
  1036. memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
  1037. rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
  1038. rtap_dev->netdev_ops = &rtap_netdev_ops;
  1039. rtap_dev->ml_priv = priv;
  1040. SET_NETDEV_DEV(rtap_dev, priv->dev->dev.parent);
  1041. ret = register_netdev(rtap_dev);
  1042. if (ret) {
  1043. free_netdev(rtap_dev);
  1044. goto out;
  1045. }
  1046. priv->rtap_net_dev = rtap_dev;
  1047. out:
  1048. lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
  1049. return ret;
  1050. }
  1051. module_init(lbs_init_module);
  1052. module_exit(lbs_exit_module);
  1053. MODULE_DESCRIPTION("Libertas WLAN Driver Library");
  1054. MODULE_AUTHOR("Marvell International Ltd.");
  1055. MODULE_LICENSE("GPL");