main.c 19 KB

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