main.c 19 KB

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