main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*
  2. * Copyright (C) 2008, cozybit Inc.
  3. * Copyright (C) 2003-2006, Marvell International Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/hardirq.h>
  12. #include <linux/slab.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/module.h>
  15. #include "libertas_tf.h"
  16. #define DRIVER_RELEASE_VERSION "004.p0"
  17. /* thinfirm version: 5.132.X.pX */
  18. #define LBTF_FW_VER_MIN 0x05840300
  19. #define LBTF_FW_VER_MAX 0x0584ffff
  20. #define QOS_CONTROL_LEN 2
  21. /* Module parameters */
  22. unsigned int lbtf_debug;
  23. EXPORT_SYMBOL_GPL(lbtf_debug);
  24. module_param_named(libertas_tf_debug, lbtf_debug, int, 0644);
  25. static const char lbtf_driver_version[] = "THINFIRM-USB8388-" DRIVER_RELEASE_VERSION
  26. #ifdef DEBUG
  27. "-dbg"
  28. #endif
  29. "";
  30. struct workqueue_struct *lbtf_wq;
  31. static const struct ieee80211_channel lbtf_channels[] = {
  32. { .center_freq = 2412, .hw_value = 1 },
  33. { .center_freq = 2417, .hw_value = 2 },
  34. { .center_freq = 2422, .hw_value = 3 },
  35. { .center_freq = 2427, .hw_value = 4 },
  36. { .center_freq = 2432, .hw_value = 5 },
  37. { .center_freq = 2437, .hw_value = 6 },
  38. { .center_freq = 2442, .hw_value = 7 },
  39. { .center_freq = 2447, .hw_value = 8 },
  40. { .center_freq = 2452, .hw_value = 9 },
  41. { .center_freq = 2457, .hw_value = 10 },
  42. { .center_freq = 2462, .hw_value = 11 },
  43. { .center_freq = 2467, .hw_value = 12 },
  44. { .center_freq = 2472, .hw_value = 13 },
  45. { .center_freq = 2484, .hw_value = 14 },
  46. };
  47. /* This table contains the hardware specific values for the modulation rates. */
  48. static const struct ieee80211_rate lbtf_rates[] = {
  49. { .bitrate = 10,
  50. .hw_value = 0, },
  51. { .bitrate = 20,
  52. .hw_value = 1,
  53. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  54. { .bitrate = 55,
  55. .hw_value = 2,
  56. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  57. { .bitrate = 110,
  58. .hw_value = 3,
  59. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  60. { .bitrate = 60,
  61. .hw_value = 5,
  62. .flags = 0 },
  63. { .bitrate = 90,
  64. .hw_value = 6,
  65. .flags = 0 },
  66. { .bitrate = 120,
  67. .hw_value = 7,
  68. .flags = 0 },
  69. { .bitrate = 180,
  70. .hw_value = 8,
  71. .flags = 0 },
  72. { .bitrate = 240,
  73. .hw_value = 9,
  74. .flags = 0 },
  75. { .bitrate = 360,
  76. .hw_value = 10,
  77. .flags = 0 },
  78. { .bitrate = 480,
  79. .hw_value = 11,
  80. .flags = 0 },
  81. { .bitrate = 540,
  82. .hw_value = 12,
  83. .flags = 0 },
  84. };
  85. static void lbtf_cmd_work(struct work_struct *work)
  86. {
  87. struct lbtf_private *priv = container_of(work, struct lbtf_private,
  88. cmd_work);
  89. lbtf_deb_enter(LBTF_DEB_CMD);
  90. spin_lock_irq(&priv->driver_lock);
  91. /* command response? */
  92. if (priv->cmd_response_rxed) {
  93. priv->cmd_response_rxed = 0;
  94. spin_unlock_irq(&priv->driver_lock);
  95. lbtf_process_rx_command(priv);
  96. spin_lock_irq(&priv->driver_lock);
  97. }
  98. if (priv->cmd_timed_out && priv->cur_cmd) {
  99. struct cmd_ctrl_node *cmdnode = priv->cur_cmd;
  100. if (++priv->nr_retries > 10) {
  101. lbtf_complete_command(priv, cmdnode,
  102. -ETIMEDOUT);
  103. priv->nr_retries = 0;
  104. } else {
  105. priv->cur_cmd = NULL;
  106. /* Stick it back at the _top_ of the pending
  107. * queue for immediate resubmission */
  108. list_add(&cmdnode->list, &priv->cmdpendingq);
  109. }
  110. }
  111. priv->cmd_timed_out = 0;
  112. spin_unlock_irq(&priv->driver_lock);
  113. if (!priv->fw_ready) {
  114. lbtf_deb_leave_args(LBTF_DEB_CMD, "fw not ready");
  115. return;
  116. }
  117. /* Execute the next command */
  118. if (!priv->cur_cmd)
  119. lbtf_execute_next_command(priv);
  120. lbtf_deb_leave(LBTF_DEB_CMD);
  121. }
  122. /**
  123. * lbtf_setup_firmware: initialize firmware.
  124. *
  125. * @priv A pointer to struct lbtf_private structure
  126. *
  127. * Returns: 0 on success.
  128. */
  129. static int lbtf_setup_firmware(struct lbtf_private *priv)
  130. {
  131. int ret = -1;
  132. lbtf_deb_enter(LBTF_DEB_FW);
  133. /*
  134. * Read priv address from HW
  135. */
  136. memset(priv->current_addr, 0xff, ETH_ALEN);
  137. ret = lbtf_update_hw_spec(priv);
  138. if (ret) {
  139. ret = -1;
  140. goto done;
  141. }
  142. lbtf_set_mac_control(priv);
  143. lbtf_set_radio_control(priv);
  144. ret = 0;
  145. done:
  146. lbtf_deb_leave_args(LBTF_DEB_FW, "ret: %d", ret);
  147. return ret;
  148. }
  149. /**
  150. * This function handles the timeout of command sending.
  151. * It will re-send the same command again.
  152. */
  153. static void command_timer_fn(unsigned long data)
  154. {
  155. struct lbtf_private *priv = (struct lbtf_private *)data;
  156. unsigned long flags;
  157. lbtf_deb_enter(LBTF_DEB_CMD);
  158. spin_lock_irqsave(&priv->driver_lock, flags);
  159. if (!priv->cur_cmd) {
  160. printk(KERN_DEBUG "libertastf: command timer expired; "
  161. "no pending command\n");
  162. goto out;
  163. }
  164. printk(KERN_DEBUG "libertas: command %x timed out\n",
  165. le16_to_cpu(priv->cur_cmd->cmdbuf->command));
  166. priv->cmd_timed_out = 1;
  167. queue_work(lbtf_wq, &priv->cmd_work);
  168. out:
  169. spin_unlock_irqrestore(&priv->driver_lock, flags);
  170. lbtf_deb_leave(LBTF_DEB_CMD);
  171. }
  172. static int lbtf_init_adapter(struct lbtf_private *priv)
  173. {
  174. lbtf_deb_enter(LBTF_DEB_MAIN);
  175. memset(priv->current_addr, 0xff, ETH_ALEN);
  176. mutex_init(&priv->lock);
  177. priv->vif = NULL;
  178. setup_timer(&priv->command_timer, command_timer_fn,
  179. (unsigned long)priv);
  180. INIT_LIST_HEAD(&priv->cmdfreeq);
  181. INIT_LIST_HEAD(&priv->cmdpendingq);
  182. spin_lock_init(&priv->driver_lock);
  183. /* Allocate the command buffers */
  184. if (lbtf_allocate_cmd_buffer(priv))
  185. return -1;
  186. lbtf_deb_leave(LBTF_DEB_MAIN);
  187. return 0;
  188. }
  189. static void lbtf_free_adapter(struct lbtf_private *priv)
  190. {
  191. lbtf_deb_enter(LBTF_DEB_MAIN);
  192. lbtf_free_cmd_buffer(priv);
  193. del_timer(&priv->command_timer);
  194. lbtf_deb_leave(LBTF_DEB_MAIN);
  195. }
  196. static void lbtf_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  197. {
  198. struct lbtf_private *priv = hw->priv;
  199. priv->skb_to_tx = skb;
  200. queue_work(lbtf_wq, &priv->tx_work);
  201. /*
  202. * queue will be restarted when we receive transmission feedback if
  203. * there are no buffered multicast frames to send
  204. */
  205. ieee80211_stop_queues(priv->hw);
  206. }
  207. static void lbtf_tx_work(struct work_struct *work)
  208. {
  209. struct lbtf_private *priv = container_of(work, struct lbtf_private,
  210. tx_work);
  211. unsigned int len;
  212. struct ieee80211_tx_info *info;
  213. struct txpd *txpd;
  214. struct sk_buff *skb = NULL;
  215. int err;
  216. lbtf_deb_enter(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  217. if ((priv->vif->type == NL80211_IFTYPE_AP) &&
  218. (!skb_queue_empty(&priv->bc_ps_buf)))
  219. skb = skb_dequeue(&priv->bc_ps_buf);
  220. else if (priv->skb_to_tx) {
  221. skb = priv->skb_to_tx;
  222. priv->skb_to_tx = NULL;
  223. } else {
  224. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  225. return;
  226. }
  227. len = skb->len;
  228. info = IEEE80211_SKB_CB(skb);
  229. txpd = (struct txpd *) skb_push(skb, sizeof(struct txpd));
  230. if (priv->surpriseremoved) {
  231. dev_kfree_skb_any(skb);
  232. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  233. return;
  234. }
  235. memset(txpd, 0, sizeof(struct txpd));
  236. /* Activate per-packet rate selection */
  237. txpd->tx_control |= cpu_to_le32(MRVL_PER_PACKET_RATE |
  238. ieee80211_get_tx_rate(priv->hw, info)->hw_value);
  239. /* copy destination address from 802.11 header */
  240. memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
  241. ETH_ALEN);
  242. txpd->tx_packet_length = cpu_to_le16(len);
  243. txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  244. lbtf_deb_hex(LBTF_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  245. BUG_ON(priv->tx_skb);
  246. spin_lock_irq(&priv->driver_lock);
  247. priv->tx_skb = skb;
  248. err = priv->hw_host_to_card(priv, MVMS_DAT, skb->data, skb->len);
  249. spin_unlock_irq(&priv->driver_lock);
  250. if (err) {
  251. dev_kfree_skb_any(skb);
  252. priv->tx_skb = NULL;
  253. pr_err("TX error: %d", err);
  254. }
  255. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  256. }
  257. static int lbtf_op_start(struct ieee80211_hw *hw)
  258. {
  259. struct lbtf_private *priv = hw->priv;
  260. void *card = priv->card;
  261. int ret = -1;
  262. lbtf_deb_enter(LBTF_DEB_MACOPS);
  263. if (!priv->fw_ready)
  264. /* Upload firmware */
  265. if (priv->hw_prog_firmware(card))
  266. goto err_prog_firmware;
  267. /* poke the firmware */
  268. priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
  269. priv->radioon = RADIO_ON;
  270. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  271. ret = lbtf_setup_firmware(priv);
  272. if (ret)
  273. goto err_prog_firmware;
  274. if ((priv->fwrelease < LBTF_FW_VER_MIN) ||
  275. (priv->fwrelease > LBTF_FW_VER_MAX)) {
  276. ret = -1;
  277. goto err_prog_firmware;
  278. }
  279. printk(KERN_INFO "libertastf: Marvell WLAN 802.11 thinfirm adapter\n");
  280. lbtf_deb_leave(LBTF_DEB_MACOPS);
  281. return 0;
  282. err_prog_firmware:
  283. priv->hw_reset_device(card);
  284. lbtf_deb_leave_args(LBTF_DEB_MACOPS, "error programing fw; ret=%d", ret);
  285. return ret;
  286. }
  287. static void lbtf_op_stop(struct ieee80211_hw *hw)
  288. {
  289. struct lbtf_private *priv = hw->priv;
  290. unsigned long flags;
  291. struct sk_buff *skb;
  292. struct cmd_ctrl_node *cmdnode;
  293. lbtf_deb_enter(LBTF_DEB_MACOPS);
  294. /* Flush pending command nodes */
  295. spin_lock_irqsave(&priv->driver_lock, flags);
  296. list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
  297. cmdnode->result = -ENOENT;
  298. cmdnode->cmdwaitqwoken = 1;
  299. wake_up_interruptible(&cmdnode->cmdwait_q);
  300. }
  301. spin_unlock_irqrestore(&priv->driver_lock, flags);
  302. cancel_work_sync(&priv->cmd_work);
  303. cancel_work_sync(&priv->tx_work);
  304. while ((skb = skb_dequeue(&priv->bc_ps_buf)))
  305. dev_kfree_skb_any(skb);
  306. priv->radioon = RADIO_OFF;
  307. lbtf_set_radio_control(priv);
  308. lbtf_deb_leave(LBTF_DEB_MACOPS);
  309. }
  310. static int lbtf_op_add_interface(struct ieee80211_hw *hw,
  311. struct ieee80211_vif *vif)
  312. {
  313. struct lbtf_private *priv = hw->priv;
  314. lbtf_deb_enter(LBTF_DEB_MACOPS);
  315. if (priv->vif != NULL)
  316. return -EOPNOTSUPP;
  317. priv->vif = vif;
  318. switch (vif->type) {
  319. case NL80211_IFTYPE_MESH_POINT:
  320. case NL80211_IFTYPE_AP:
  321. lbtf_set_mode(priv, LBTF_AP_MODE);
  322. break;
  323. case NL80211_IFTYPE_STATION:
  324. lbtf_set_mode(priv, LBTF_STA_MODE);
  325. break;
  326. default:
  327. priv->vif = NULL;
  328. return -EOPNOTSUPP;
  329. }
  330. lbtf_set_mac_address(priv, (u8 *) vif->addr);
  331. lbtf_deb_leave(LBTF_DEB_MACOPS);
  332. return 0;
  333. }
  334. static void lbtf_op_remove_interface(struct ieee80211_hw *hw,
  335. struct ieee80211_vif *vif)
  336. {
  337. struct lbtf_private *priv = hw->priv;
  338. lbtf_deb_enter(LBTF_DEB_MACOPS);
  339. if (priv->vif->type == NL80211_IFTYPE_AP ||
  340. priv->vif->type == NL80211_IFTYPE_MESH_POINT)
  341. lbtf_beacon_ctrl(priv, 0, 0);
  342. lbtf_set_mode(priv, LBTF_PASSIVE_MODE);
  343. lbtf_set_bssid(priv, 0, NULL);
  344. priv->vif = NULL;
  345. lbtf_deb_leave(LBTF_DEB_MACOPS);
  346. }
  347. static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
  348. {
  349. struct lbtf_private *priv = hw->priv;
  350. struct ieee80211_conf *conf = &hw->conf;
  351. lbtf_deb_enter(LBTF_DEB_MACOPS);
  352. if (conf->channel->center_freq != priv->cur_freq) {
  353. priv->cur_freq = conf->channel->center_freq;
  354. lbtf_set_channel(priv, conf->channel->hw_value);
  355. }
  356. lbtf_deb_leave(LBTF_DEB_MACOPS);
  357. return 0;
  358. }
  359. static u64 lbtf_op_prepare_multicast(struct ieee80211_hw *hw,
  360. struct netdev_hw_addr_list *mc_list)
  361. {
  362. struct lbtf_private *priv = hw->priv;
  363. int i;
  364. struct netdev_hw_addr *ha;
  365. int mc_count = netdev_hw_addr_list_count(mc_list);
  366. if (!mc_count || mc_count > MRVDRV_MAX_MULTICAST_LIST_SIZE)
  367. return mc_count;
  368. priv->nr_of_multicastmacaddr = mc_count;
  369. i = 0;
  370. netdev_hw_addr_list_for_each(ha, mc_list)
  371. memcpy(&priv->multicastlist[i++], ha->addr, ETH_ALEN);
  372. return mc_count;
  373. }
  374. #define SUPPORTED_FIF_FLAGS (FIF_PROMISC_IN_BSS | FIF_ALLMULTI)
  375. static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
  376. unsigned int changed_flags,
  377. unsigned int *new_flags,
  378. u64 multicast)
  379. {
  380. struct lbtf_private *priv = hw->priv;
  381. int old_mac_control = priv->mac_control;
  382. lbtf_deb_enter(LBTF_DEB_MACOPS);
  383. changed_flags &= SUPPORTED_FIF_FLAGS;
  384. *new_flags &= SUPPORTED_FIF_FLAGS;
  385. if (!changed_flags) {
  386. lbtf_deb_leave(LBTF_DEB_MACOPS);
  387. return;
  388. }
  389. if (*new_flags & (FIF_PROMISC_IN_BSS))
  390. priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  391. else
  392. priv->mac_control &= ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  393. if (*new_flags & (FIF_ALLMULTI) ||
  394. multicast > MRVDRV_MAX_MULTICAST_LIST_SIZE) {
  395. priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  396. priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
  397. } else if (multicast) {
  398. priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
  399. priv->mac_control &= ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  400. lbtf_cmd_set_mac_multicast_addr(priv);
  401. } else {
  402. priv->mac_control &= ~(CMD_ACT_MAC_MULTICAST_ENABLE |
  403. CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
  404. if (priv->nr_of_multicastmacaddr) {
  405. priv->nr_of_multicastmacaddr = 0;
  406. lbtf_cmd_set_mac_multicast_addr(priv);
  407. }
  408. }
  409. if (priv->mac_control != old_mac_control)
  410. lbtf_set_mac_control(priv);
  411. lbtf_deb_leave(LBTF_DEB_MACOPS);
  412. }
  413. static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
  414. struct ieee80211_vif *vif,
  415. struct ieee80211_bss_conf *bss_conf,
  416. u32 changes)
  417. {
  418. struct lbtf_private *priv = hw->priv;
  419. struct sk_buff *beacon;
  420. lbtf_deb_enter(LBTF_DEB_MACOPS);
  421. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
  422. switch (priv->vif->type) {
  423. case NL80211_IFTYPE_AP:
  424. case NL80211_IFTYPE_MESH_POINT:
  425. beacon = ieee80211_beacon_get(hw, vif);
  426. if (beacon) {
  427. lbtf_beacon_set(priv, beacon);
  428. kfree_skb(beacon);
  429. lbtf_beacon_ctrl(priv, 1,
  430. bss_conf->beacon_int);
  431. }
  432. break;
  433. default:
  434. break;
  435. }
  436. }
  437. if (changes & BSS_CHANGED_BSSID) {
  438. bool activate = !is_zero_ether_addr(bss_conf->bssid);
  439. lbtf_set_bssid(priv, activate, bss_conf->bssid);
  440. }
  441. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  442. if (bss_conf->use_short_preamble)
  443. priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
  444. else
  445. priv->preamble = CMD_TYPE_LONG_PREAMBLE;
  446. lbtf_set_radio_control(priv);
  447. }
  448. lbtf_deb_leave(LBTF_DEB_MACOPS);
  449. }
  450. static int lbtf_op_get_survey(struct ieee80211_hw *hw, int idx,
  451. struct survey_info *survey)
  452. {
  453. struct lbtf_private *priv = hw->priv;
  454. struct ieee80211_conf *conf = &hw->conf;
  455. if (idx != 0)
  456. return -ENOENT;
  457. survey->channel = conf->channel;
  458. survey->filled = SURVEY_INFO_NOISE_DBM;
  459. survey->noise = priv->noise;
  460. return 0;
  461. }
  462. static const struct ieee80211_ops lbtf_ops = {
  463. .tx = lbtf_op_tx,
  464. .start = lbtf_op_start,
  465. .stop = lbtf_op_stop,
  466. .add_interface = lbtf_op_add_interface,
  467. .remove_interface = lbtf_op_remove_interface,
  468. .config = lbtf_op_config,
  469. .prepare_multicast = lbtf_op_prepare_multicast,
  470. .configure_filter = lbtf_op_configure_filter,
  471. .bss_info_changed = lbtf_op_bss_info_changed,
  472. .get_survey = lbtf_op_get_survey,
  473. };
  474. int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
  475. {
  476. struct ieee80211_rx_status stats;
  477. struct rxpd *prxpd;
  478. int need_padding;
  479. unsigned int flags;
  480. struct ieee80211_hdr *hdr;
  481. lbtf_deb_enter(LBTF_DEB_RX);
  482. prxpd = (struct rxpd *) skb->data;
  483. memset(&stats, 0, sizeof(stats));
  484. if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
  485. stats.flag |= RX_FLAG_FAILED_FCS_CRC;
  486. stats.freq = priv->cur_freq;
  487. stats.band = IEEE80211_BAND_2GHZ;
  488. stats.signal = prxpd->snr;
  489. priv->noise = prxpd->nf;
  490. /* Marvell rate index has a hole at value 4 */
  491. if (prxpd->rx_rate > 4)
  492. --prxpd->rx_rate;
  493. stats.rate_idx = prxpd->rx_rate;
  494. skb_pull(skb, sizeof(struct rxpd));
  495. hdr = (struct ieee80211_hdr *)skb->data;
  496. flags = le32_to_cpu(*(__le32 *)(skb->data + 4));
  497. need_padding = ieee80211_is_data_qos(hdr->frame_control);
  498. need_padding ^= ieee80211_has_a4(hdr->frame_control);
  499. need_padding ^= ieee80211_is_data_qos(hdr->frame_control) &&
  500. (*ieee80211_get_qos_ctl(hdr) &
  501. IEEE80211_QOS_CTL_A_MSDU_PRESENT);
  502. if (need_padding) {
  503. memmove(skb->data + 2, skb->data, skb->len);
  504. skb_reserve(skb, 2);
  505. }
  506. memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
  507. lbtf_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
  508. skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
  509. lbtf_deb_hex(LBTF_DEB_RX, "RX Data", skb->data,
  510. min_t(unsigned int, skb->len, 100));
  511. ieee80211_rx_irqsafe(priv->hw, skb);
  512. lbtf_deb_leave(LBTF_DEB_RX);
  513. return 0;
  514. }
  515. EXPORT_SYMBOL_GPL(lbtf_rx);
  516. /**
  517. * lbtf_add_card: Add and initialize the card, no fw upload yet.
  518. *
  519. * @card A pointer to card
  520. *
  521. * Returns: pointer to struct lbtf_priv.
  522. */
  523. struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev)
  524. {
  525. struct ieee80211_hw *hw;
  526. struct lbtf_private *priv = NULL;
  527. lbtf_deb_enter(LBTF_DEB_MAIN);
  528. hw = ieee80211_alloc_hw(sizeof(struct lbtf_private), &lbtf_ops);
  529. if (!hw)
  530. goto done;
  531. priv = hw->priv;
  532. if (lbtf_init_adapter(priv))
  533. goto err_init_adapter;
  534. priv->hw = hw;
  535. priv->card = card;
  536. priv->tx_skb = NULL;
  537. hw->queues = 1;
  538. hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  539. hw->extra_tx_headroom = sizeof(struct txpd);
  540. memcpy(priv->channels, lbtf_channels, sizeof(lbtf_channels));
  541. memcpy(priv->rates, lbtf_rates, sizeof(lbtf_rates));
  542. priv->band.n_bitrates = ARRAY_SIZE(lbtf_rates);
  543. priv->band.bitrates = priv->rates;
  544. priv->band.n_channels = ARRAY_SIZE(lbtf_channels);
  545. priv->band.channels = priv->channels;
  546. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  547. hw->wiphy->interface_modes =
  548. BIT(NL80211_IFTYPE_STATION) |
  549. BIT(NL80211_IFTYPE_ADHOC);
  550. skb_queue_head_init(&priv->bc_ps_buf);
  551. SET_IEEE80211_DEV(hw, dmdev);
  552. INIT_WORK(&priv->cmd_work, lbtf_cmd_work);
  553. INIT_WORK(&priv->tx_work, lbtf_tx_work);
  554. if (ieee80211_register_hw(hw))
  555. goto err_init_adapter;
  556. goto done;
  557. err_init_adapter:
  558. lbtf_free_adapter(priv);
  559. ieee80211_free_hw(hw);
  560. priv = NULL;
  561. done:
  562. lbtf_deb_leave_args(LBTF_DEB_MAIN, "priv %p", priv);
  563. return priv;
  564. }
  565. EXPORT_SYMBOL_GPL(lbtf_add_card);
  566. int lbtf_remove_card(struct lbtf_private *priv)
  567. {
  568. struct ieee80211_hw *hw = priv->hw;
  569. lbtf_deb_enter(LBTF_DEB_MAIN);
  570. priv->surpriseremoved = 1;
  571. del_timer(&priv->command_timer);
  572. lbtf_free_adapter(priv);
  573. priv->hw = NULL;
  574. ieee80211_unregister_hw(hw);
  575. ieee80211_free_hw(hw);
  576. lbtf_deb_leave(LBTF_DEB_MAIN);
  577. return 0;
  578. }
  579. EXPORT_SYMBOL_GPL(lbtf_remove_card);
  580. void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail)
  581. {
  582. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb);
  583. ieee80211_tx_info_clear_status(info);
  584. /*
  585. * Commented out, otherwise we never go beyond 1Mbit/s using mac80211
  586. * default pid rc algorithm.
  587. *
  588. * info->status.retry_count = MRVL_DEFAULT_RETRIES - retrycnt;
  589. */
  590. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && !fail)
  591. info->flags |= IEEE80211_TX_STAT_ACK;
  592. skb_pull(priv->tx_skb, sizeof(struct txpd));
  593. ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb);
  594. priv->tx_skb = NULL;
  595. if (!priv->skb_to_tx && skb_queue_empty(&priv->bc_ps_buf))
  596. ieee80211_wake_queues(priv->hw);
  597. else
  598. queue_work(lbtf_wq, &priv->tx_work);
  599. }
  600. EXPORT_SYMBOL_GPL(lbtf_send_tx_feedback);
  601. void lbtf_bcn_sent(struct lbtf_private *priv)
  602. {
  603. struct sk_buff *skb = NULL;
  604. if (priv->vif->type != NL80211_IFTYPE_AP)
  605. return;
  606. if (skb_queue_empty(&priv->bc_ps_buf)) {
  607. bool tx_buff_bc = false;
  608. while ((skb = ieee80211_get_buffered_bc(priv->hw, priv->vif))) {
  609. skb_queue_tail(&priv->bc_ps_buf, skb);
  610. tx_buff_bc = true;
  611. }
  612. if (tx_buff_bc) {
  613. ieee80211_stop_queues(priv->hw);
  614. queue_work(lbtf_wq, &priv->tx_work);
  615. }
  616. }
  617. skb = ieee80211_beacon_get(priv->hw, priv->vif);
  618. if (skb) {
  619. lbtf_beacon_set(priv, skb);
  620. kfree_skb(skb);
  621. }
  622. }
  623. EXPORT_SYMBOL_GPL(lbtf_bcn_sent);
  624. static int __init lbtf_init_module(void)
  625. {
  626. lbtf_deb_enter(LBTF_DEB_MAIN);
  627. lbtf_wq = create_workqueue("libertastf");
  628. if (lbtf_wq == NULL) {
  629. printk(KERN_ERR "libertastf: couldn't create workqueue\n");
  630. return -ENOMEM;
  631. }
  632. lbtf_deb_leave(LBTF_DEB_MAIN);
  633. return 0;
  634. }
  635. static void __exit lbtf_exit_module(void)
  636. {
  637. lbtf_deb_enter(LBTF_DEB_MAIN);
  638. destroy_workqueue(lbtf_wq);
  639. lbtf_deb_leave(LBTF_DEB_MAIN);
  640. }
  641. module_init(lbtf_init_module);
  642. module_exit(lbtf_exit_module);
  643. MODULE_DESCRIPTION("Libertas WLAN Thinfirm Driver Library");
  644. MODULE_AUTHOR("Cozybit Inc.");
  645. MODULE_LICENSE("GPL");