main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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(unsigned long data)
  148. {
  149. struct lbtf_private *priv = (struct lbtf_private *)data;
  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. setup_timer(&priv->command_timer, command_timer_fn,
  173. (unsigned long)priv);
  174. INIT_LIST_HEAD(&priv->cmdfreeq);
  175. INIT_LIST_HEAD(&priv->cmdpendingq);
  176. spin_lock_init(&priv->driver_lock);
  177. /* Allocate the command buffers */
  178. if (lbtf_allocate_cmd_buffer(priv))
  179. return -1;
  180. lbtf_deb_leave(LBTF_DEB_MAIN);
  181. return 0;
  182. }
  183. static void lbtf_free_adapter(struct lbtf_private *priv)
  184. {
  185. lbtf_deb_enter(LBTF_DEB_MAIN);
  186. lbtf_free_cmd_buffer(priv);
  187. del_timer(&priv->command_timer);
  188. lbtf_deb_leave(LBTF_DEB_MAIN);
  189. }
  190. static void lbtf_op_tx(struct ieee80211_hw *hw,
  191. struct ieee80211_tx_control *control,
  192. struct sk_buff *skb)
  193. {
  194. struct lbtf_private *priv = hw->priv;
  195. priv->skb_to_tx = skb;
  196. queue_work(lbtf_wq, &priv->tx_work);
  197. /*
  198. * queue will be restarted when we receive transmission feedback if
  199. * there are no buffered multicast frames to send
  200. */
  201. ieee80211_stop_queues(priv->hw);
  202. }
  203. static void lbtf_tx_work(struct work_struct *work)
  204. {
  205. struct lbtf_private *priv = container_of(work, struct lbtf_private,
  206. tx_work);
  207. unsigned int len;
  208. struct ieee80211_tx_info *info;
  209. struct txpd *txpd;
  210. struct sk_buff *skb = NULL;
  211. int err;
  212. lbtf_deb_enter(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  213. if ((priv->vif->type == NL80211_IFTYPE_AP) &&
  214. (!skb_queue_empty(&priv->bc_ps_buf)))
  215. skb = skb_dequeue(&priv->bc_ps_buf);
  216. else if (priv->skb_to_tx) {
  217. skb = priv->skb_to_tx;
  218. priv->skb_to_tx = NULL;
  219. } else {
  220. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  221. return;
  222. }
  223. len = skb->len;
  224. info = IEEE80211_SKB_CB(skb);
  225. txpd = (struct txpd *) skb_push(skb, sizeof(struct txpd));
  226. if (priv->surpriseremoved) {
  227. dev_kfree_skb_any(skb);
  228. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  229. return;
  230. }
  231. memset(txpd, 0, sizeof(struct txpd));
  232. /* Activate per-packet rate selection */
  233. txpd->tx_control |= cpu_to_le32(MRVL_PER_PACKET_RATE |
  234. ieee80211_get_tx_rate(priv->hw, info)->hw_value);
  235. /* copy destination address from 802.11 header */
  236. memcpy(txpd->tx_dest_addr_high, skb->data + sizeof(struct txpd) + 4,
  237. ETH_ALEN);
  238. txpd->tx_packet_length = cpu_to_le16(len);
  239. txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  240. lbtf_deb_hex(LBTF_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  241. BUG_ON(priv->tx_skb);
  242. spin_lock_irq(&priv->driver_lock);
  243. priv->tx_skb = skb;
  244. err = priv->hw_host_to_card(priv, MVMS_DAT, skb->data, skb->len);
  245. spin_unlock_irq(&priv->driver_lock);
  246. if (err) {
  247. dev_kfree_skb_any(skb);
  248. priv->tx_skb = NULL;
  249. pr_err("TX error: %d", err);
  250. }
  251. lbtf_deb_leave(LBTF_DEB_MACOPS | LBTF_DEB_TX);
  252. }
  253. static int lbtf_op_start(struct ieee80211_hw *hw)
  254. {
  255. struct lbtf_private *priv = hw->priv;
  256. void *card = priv->card;
  257. int ret = -1;
  258. lbtf_deb_enter(LBTF_DEB_MACOPS);
  259. if (!priv->fw_ready)
  260. /* Upload firmware */
  261. if (priv->hw_prog_firmware(card))
  262. goto err_prog_firmware;
  263. /* poke the firmware */
  264. priv->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
  265. priv->radioon = RADIO_ON;
  266. priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
  267. ret = lbtf_setup_firmware(priv);
  268. if (ret)
  269. goto err_prog_firmware;
  270. if ((priv->fwrelease < LBTF_FW_VER_MIN) ||
  271. (priv->fwrelease > LBTF_FW_VER_MAX)) {
  272. ret = -1;
  273. goto err_prog_firmware;
  274. }
  275. printk(KERN_INFO "libertastf: Marvell WLAN 802.11 thinfirm adapter\n");
  276. lbtf_deb_leave(LBTF_DEB_MACOPS);
  277. return 0;
  278. err_prog_firmware:
  279. priv->hw_reset_device(card);
  280. lbtf_deb_leave_args(LBTF_DEB_MACOPS, "error programming fw; ret=%d", ret);
  281. return ret;
  282. }
  283. static void lbtf_op_stop(struct ieee80211_hw *hw)
  284. {
  285. struct lbtf_private *priv = hw->priv;
  286. unsigned long flags;
  287. struct sk_buff *skb;
  288. struct cmd_ctrl_node *cmdnode;
  289. lbtf_deb_enter(LBTF_DEB_MACOPS);
  290. /* Flush pending command nodes */
  291. spin_lock_irqsave(&priv->driver_lock, flags);
  292. list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
  293. cmdnode->result = -ENOENT;
  294. cmdnode->cmdwaitqwoken = 1;
  295. wake_up_interruptible(&cmdnode->cmdwait_q);
  296. }
  297. spin_unlock_irqrestore(&priv->driver_lock, flags);
  298. cancel_work_sync(&priv->cmd_work);
  299. cancel_work_sync(&priv->tx_work);
  300. while ((skb = skb_dequeue(&priv->bc_ps_buf)))
  301. dev_kfree_skb_any(skb);
  302. priv->radioon = RADIO_OFF;
  303. lbtf_set_radio_control(priv);
  304. lbtf_deb_leave(LBTF_DEB_MACOPS);
  305. }
  306. static int lbtf_op_add_interface(struct ieee80211_hw *hw,
  307. struct ieee80211_vif *vif)
  308. {
  309. struct lbtf_private *priv = hw->priv;
  310. lbtf_deb_enter(LBTF_DEB_MACOPS);
  311. if (priv->vif != NULL)
  312. return -EOPNOTSUPP;
  313. priv->vif = vif;
  314. switch (vif->type) {
  315. case NL80211_IFTYPE_MESH_POINT:
  316. case NL80211_IFTYPE_AP:
  317. lbtf_set_mode(priv, LBTF_AP_MODE);
  318. break;
  319. case NL80211_IFTYPE_STATION:
  320. lbtf_set_mode(priv, LBTF_STA_MODE);
  321. break;
  322. default:
  323. priv->vif = NULL;
  324. return -EOPNOTSUPP;
  325. }
  326. lbtf_set_mac_address(priv, (u8 *) vif->addr);
  327. lbtf_deb_leave(LBTF_DEB_MACOPS);
  328. return 0;
  329. }
  330. static void lbtf_op_remove_interface(struct ieee80211_hw *hw,
  331. struct ieee80211_vif *vif)
  332. {
  333. struct lbtf_private *priv = hw->priv;
  334. lbtf_deb_enter(LBTF_DEB_MACOPS);
  335. if (priv->vif->type == NL80211_IFTYPE_AP ||
  336. priv->vif->type == NL80211_IFTYPE_MESH_POINT)
  337. lbtf_beacon_ctrl(priv, 0, 0);
  338. lbtf_set_mode(priv, LBTF_PASSIVE_MODE);
  339. lbtf_set_bssid(priv, 0, NULL);
  340. priv->vif = NULL;
  341. lbtf_deb_leave(LBTF_DEB_MACOPS);
  342. }
  343. static int lbtf_op_config(struct ieee80211_hw *hw, u32 changed)
  344. {
  345. struct lbtf_private *priv = hw->priv;
  346. struct ieee80211_conf *conf = &hw->conf;
  347. lbtf_deb_enter(LBTF_DEB_MACOPS);
  348. if (conf->chandef.chan->center_freq != priv->cur_freq) {
  349. priv->cur_freq = conf->chandef.chan->center_freq;
  350. lbtf_set_channel(priv, conf->chandef.chan->hw_value);
  351. }
  352. lbtf_deb_leave(LBTF_DEB_MACOPS);
  353. return 0;
  354. }
  355. static u64 lbtf_op_prepare_multicast(struct ieee80211_hw *hw,
  356. struct netdev_hw_addr_list *mc_list)
  357. {
  358. struct lbtf_private *priv = hw->priv;
  359. int i;
  360. struct netdev_hw_addr *ha;
  361. int mc_count = netdev_hw_addr_list_count(mc_list);
  362. if (!mc_count || mc_count > MRVDRV_MAX_MULTICAST_LIST_SIZE)
  363. return mc_count;
  364. priv->nr_of_multicastmacaddr = mc_count;
  365. i = 0;
  366. netdev_hw_addr_list_for_each(ha, mc_list)
  367. memcpy(&priv->multicastlist[i++], ha->addr, ETH_ALEN);
  368. return mc_count;
  369. }
  370. #define SUPPORTED_FIF_FLAGS FIF_ALLMULTI
  371. static void lbtf_op_configure_filter(struct ieee80211_hw *hw,
  372. unsigned int changed_flags,
  373. unsigned int *new_flags,
  374. u64 multicast)
  375. {
  376. struct lbtf_private *priv = hw->priv;
  377. int old_mac_control = priv->mac_control;
  378. lbtf_deb_enter(LBTF_DEB_MACOPS);
  379. changed_flags &= SUPPORTED_FIF_FLAGS;
  380. *new_flags &= SUPPORTED_FIF_FLAGS;
  381. if (!changed_flags) {
  382. lbtf_deb_leave(LBTF_DEB_MACOPS);
  383. return;
  384. }
  385. priv->mac_control &= ~CMD_ACT_MAC_PROMISCUOUS_ENABLE;
  386. if (*new_flags & (FIF_ALLMULTI) ||
  387. multicast > MRVDRV_MAX_MULTICAST_LIST_SIZE) {
  388. priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  389. priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE;
  390. } else if (multicast) {
  391. priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE;
  392. priv->mac_control &= ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE;
  393. lbtf_cmd_set_mac_multicast_addr(priv);
  394. } else {
  395. priv->mac_control &= ~(CMD_ACT_MAC_MULTICAST_ENABLE |
  396. CMD_ACT_MAC_ALL_MULTICAST_ENABLE);
  397. if (priv->nr_of_multicastmacaddr) {
  398. priv->nr_of_multicastmacaddr = 0;
  399. lbtf_cmd_set_mac_multicast_addr(priv);
  400. }
  401. }
  402. if (priv->mac_control != old_mac_control)
  403. lbtf_set_mac_control(priv);
  404. lbtf_deb_leave(LBTF_DEB_MACOPS);
  405. }
  406. static void lbtf_op_bss_info_changed(struct ieee80211_hw *hw,
  407. struct ieee80211_vif *vif,
  408. struct ieee80211_bss_conf *bss_conf,
  409. u32 changes)
  410. {
  411. struct lbtf_private *priv = hw->priv;
  412. struct sk_buff *beacon;
  413. lbtf_deb_enter(LBTF_DEB_MACOPS);
  414. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_INT)) {
  415. switch (priv->vif->type) {
  416. case NL80211_IFTYPE_AP:
  417. case NL80211_IFTYPE_MESH_POINT:
  418. beacon = ieee80211_beacon_get(hw, vif);
  419. if (beacon) {
  420. lbtf_beacon_set(priv, beacon);
  421. kfree_skb(beacon);
  422. lbtf_beacon_ctrl(priv, 1,
  423. bss_conf->beacon_int);
  424. }
  425. break;
  426. default:
  427. break;
  428. }
  429. }
  430. if (changes & BSS_CHANGED_BSSID) {
  431. bool activate = !is_zero_ether_addr(bss_conf->bssid);
  432. lbtf_set_bssid(priv, activate, bss_conf->bssid);
  433. }
  434. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  435. if (bss_conf->use_short_preamble)
  436. priv->preamble = CMD_TYPE_SHORT_PREAMBLE;
  437. else
  438. priv->preamble = CMD_TYPE_LONG_PREAMBLE;
  439. lbtf_set_radio_control(priv);
  440. }
  441. lbtf_deb_leave(LBTF_DEB_MACOPS);
  442. }
  443. static int lbtf_op_get_survey(struct ieee80211_hw *hw, int idx,
  444. struct survey_info *survey)
  445. {
  446. struct lbtf_private *priv = hw->priv;
  447. struct ieee80211_conf *conf = &hw->conf;
  448. if (idx != 0)
  449. return -ENOENT;
  450. survey->channel = conf->chandef.chan;
  451. survey->filled = SURVEY_INFO_NOISE_DBM;
  452. survey->noise = priv->noise;
  453. return 0;
  454. }
  455. static const struct ieee80211_ops lbtf_ops = {
  456. .tx = lbtf_op_tx,
  457. .start = lbtf_op_start,
  458. .stop = lbtf_op_stop,
  459. .add_interface = lbtf_op_add_interface,
  460. .remove_interface = lbtf_op_remove_interface,
  461. .config = lbtf_op_config,
  462. .prepare_multicast = lbtf_op_prepare_multicast,
  463. .configure_filter = lbtf_op_configure_filter,
  464. .bss_info_changed = lbtf_op_bss_info_changed,
  465. .get_survey = lbtf_op_get_survey,
  466. };
  467. int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
  468. {
  469. struct ieee80211_rx_status stats;
  470. struct rxpd *prxpd;
  471. int need_padding;
  472. unsigned int flags;
  473. struct ieee80211_hdr *hdr;
  474. lbtf_deb_enter(LBTF_DEB_RX);
  475. prxpd = (struct rxpd *) skb->data;
  476. memset(&stats, 0, sizeof(stats));
  477. if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
  478. stats.flag |= RX_FLAG_FAILED_FCS_CRC;
  479. stats.freq = priv->cur_freq;
  480. stats.band = NL80211_BAND_2GHZ;
  481. stats.signal = prxpd->snr;
  482. priv->noise = prxpd->nf;
  483. /* Marvell rate index has a hole at value 4 */
  484. if (prxpd->rx_rate > 4)
  485. --prxpd->rx_rate;
  486. stats.rate_idx = prxpd->rx_rate;
  487. skb_pull(skb, sizeof(struct rxpd));
  488. hdr = (struct ieee80211_hdr *)skb->data;
  489. flags = le32_to_cpu(*(__le32 *)(skb->data + 4));
  490. need_padding = ieee80211_is_data_qos(hdr->frame_control);
  491. need_padding ^= ieee80211_has_a4(hdr->frame_control);
  492. need_padding ^= ieee80211_is_data_qos(hdr->frame_control) &&
  493. (*ieee80211_get_qos_ctl(hdr) &
  494. IEEE80211_QOS_CTL_A_MSDU_PRESENT);
  495. if (need_padding) {
  496. memmove(skb->data + 2, skb->data, skb->len);
  497. skb_reserve(skb, 2);
  498. }
  499. memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
  500. lbtf_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
  501. skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
  502. lbtf_deb_hex(LBTF_DEB_RX, "RX Data", skb->data,
  503. min_t(unsigned int, skb->len, 100));
  504. ieee80211_rx_irqsafe(priv->hw, skb);
  505. lbtf_deb_leave(LBTF_DEB_RX);
  506. return 0;
  507. }
  508. EXPORT_SYMBOL_GPL(lbtf_rx);
  509. /**
  510. * lbtf_add_card: Add and initialize the card, no fw upload yet.
  511. *
  512. * @card A pointer to card
  513. *
  514. * Returns: pointer to struct lbtf_priv.
  515. */
  516. struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev)
  517. {
  518. struct ieee80211_hw *hw;
  519. struct lbtf_private *priv = NULL;
  520. lbtf_deb_enter(LBTF_DEB_MAIN);
  521. hw = ieee80211_alloc_hw(sizeof(struct lbtf_private), &lbtf_ops);
  522. if (!hw)
  523. goto done;
  524. priv = hw->priv;
  525. if (lbtf_init_adapter(priv))
  526. goto err_init_adapter;
  527. priv->hw = hw;
  528. priv->card = card;
  529. priv->tx_skb = NULL;
  530. hw->queues = 1;
  531. ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
  532. hw->extra_tx_headroom = sizeof(struct txpd);
  533. memcpy(priv->channels, lbtf_channels, sizeof(lbtf_channels));
  534. memcpy(priv->rates, lbtf_rates, sizeof(lbtf_rates));
  535. priv->band.n_bitrates = ARRAY_SIZE(lbtf_rates);
  536. priv->band.bitrates = priv->rates;
  537. priv->band.n_channels = ARRAY_SIZE(lbtf_channels);
  538. priv->band.channels = priv->channels;
  539. hw->wiphy->bands[NL80211_BAND_2GHZ] = &priv->band;
  540. hw->wiphy->interface_modes =
  541. BIT(NL80211_IFTYPE_STATION) |
  542. BIT(NL80211_IFTYPE_ADHOC);
  543. skb_queue_head_init(&priv->bc_ps_buf);
  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");