main.c 31 KB

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