main.c 19 KB

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