xmit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. Broadcom B43legacy wireless driver
  3. Transmission (TX/RX) related functions.
  4. Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  5. Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  6. Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
  7. Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
  8. Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. Copyright (C) 2007 Larry Finger <Larry.Finger@lwfinger.net>
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  21. Boston, MA 02110-1301, USA.
  22. */
  23. #include <net/dst.h>
  24. #include "xmit.h"
  25. #include "phy.h"
  26. #include "dma.h"
  27. #include "pio.h"
  28. /* Extract the bitrate out of a CCK PLCP header. */
  29. static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp)
  30. {
  31. switch (plcp->raw[0]) {
  32. case 0x0A:
  33. return 0;
  34. case 0x14:
  35. return 1;
  36. case 0x37:
  37. return 2;
  38. case 0x6E:
  39. return 3;
  40. }
  41. B43legacy_BUG_ON(1);
  42. return -1;
  43. }
  44. /* Extract the bitrate out of an OFDM PLCP header. */
  45. static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp,
  46. bool aphy)
  47. {
  48. int base = aphy ? 0 : 4;
  49. switch (plcp->raw[0] & 0xF) {
  50. case 0xB:
  51. return base + 0;
  52. case 0xF:
  53. return base + 1;
  54. case 0xA:
  55. return base + 2;
  56. case 0xE:
  57. return base + 3;
  58. case 0x9:
  59. return base + 4;
  60. case 0xD:
  61. return base + 5;
  62. case 0x8:
  63. return base + 6;
  64. case 0xC:
  65. return base + 7;
  66. }
  67. B43legacy_BUG_ON(1);
  68. return -1;
  69. }
  70. u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate)
  71. {
  72. switch (bitrate) {
  73. case B43legacy_CCK_RATE_1MB:
  74. return 0x0A;
  75. case B43legacy_CCK_RATE_2MB:
  76. return 0x14;
  77. case B43legacy_CCK_RATE_5MB:
  78. return 0x37;
  79. case B43legacy_CCK_RATE_11MB:
  80. return 0x6E;
  81. }
  82. B43legacy_BUG_ON(1);
  83. return 0;
  84. }
  85. u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate)
  86. {
  87. switch (bitrate) {
  88. case B43legacy_OFDM_RATE_6MB:
  89. return 0xB;
  90. case B43legacy_OFDM_RATE_9MB:
  91. return 0xF;
  92. case B43legacy_OFDM_RATE_12MB:
  93. return 0xA;
  94. case B43legacy_OFDM_RATE_18MB:
  95. return 0xE;
  96. case B43legacy_OFDM_RATE_24MB:
  97. return 0x9;
  98. case B43legacy_OFDM_RATE_36MB:
  99. return 0xD;
  100. case B43legacy_OFDM_RATE_48MB:
  101. return 0x8;
  102. case B43legacy_OFDM_RATE_54MB:
  103. return 0xC;
  104. }
  105. B43legacy_BUG_ON(1);
  106. return 0;
  107. }
  108. void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp,
  109. const u16 octets, const u8 bitrate)
  110. {
  111. __le32 *data = &(plcp->data);
  112. __u8 *raw = plcp->raw;
  113. if (b43legacy_is_ofdm_rate(bitrate)) {
  114. u16 d;
  115. d = b43legacy_plcp_get_ratecode_ofdm(bitrate);
  116. B43legacy_WARN_ON(octets & 0xF000);
  117. d |= (octets << 5);
  118. *data = cpu_to_le32(d);
  119. } else {
  120. u32 plen;
  121. plen = octets * 16 / bitrate;
  122. if ((octets * 16 % bitrate) > 0) {
  123. plen++;
  124. if ((bitrate == B43legacy_CCK_RATE_11MB)
  125. && ((octets * 8 % 11) < 4))
  126. raw[1] = 0x84;
  127. else
  128. raw[1] = 0x04;
  129. } else
  130. raw[1] = 0x04;
  131. *data |= cpu_to_le32(plen << 16);
  132. raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate);
  133. }
  134. }
  135. static u8 b43legacy_calc_fallback_rate(u8 bitrate)
  136. {
  137. switch (bitrate) {
  138. case B43legacy_CCK_RATE_1MB:
  139. return B43legacy_CCK_RATE_1MB;
  140. case B43legacy_CCK_RATE_2MB:
  141. return B43legacy_CCK_RATE_1MB;
  142. case B43legacy_CCK_RATE_5MB:
  143. return B43legacy_CCK_RATE_2MB;
  144. case B43legacy_CCK_RATE_11MB:
  145. return B43legacy_CCK_RATE_5MB;
  146. case B43legacy_OFDM_RATE_6MB:
  147. return B43legacy_CCK_RATE_5MB;
  148. case B43legacy_OFDM_RATE_9MB:
  149. return B43legacy_OFDM_RATE_6MB;
  150. case B43legacy_OFDM_RATE_12MB:
  151. return B43legacy_OFDM_RATE_9MB;
  152. case B43legacy_OFDM_RATE_18MB:
  153. return B43legacy_OFDM_RATE_12MB;
  154. case B43legacy_OFDM_RATE_24MB:
  155. return B43legacy_OFDM_RATE_18MB;
  156. case B43legacy_OFDM_RATE_36MB:
  157. return B43legacy_OFDM_RATE_24MB;
  158. case B43legacy_OFDM_RATE_48MB:
  159. return B43legacy_OFDM_RATE_36MB;
  160. case B43legacy_OFDM_RATE_54MB:
  161. return B43legacy_OFDM_RATE_48MB;
  162. }
  163. B43legacy_BUG_ON(1);
  164. return 0;
  165. }
  166. static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
  167. struct b43legacy_txhdr_fw3 *txhdr,
  168. const unsigned char *fragment_data,
  169. unsigned int fragment_len,
  170. struct ieee80211_tx_info *info,
  171. u16 cookie)
  172. {
  173. const struct ieee80211_hdr *wlhdr;
  174. int use_encryption = !!info->control.hw_key;
  175. u8 rate;
  176. struct ieee80211_rate *rate_fb;
  177. int rate_ofdm;
  178. int rate_fb_ofdm;
  179. unsigned int plcp_fragment_len;
  180. u32 mac_ctl = 0;
  181. u16 phy_ctl = 0;
  182. struct ieee80211_rate *tx_rate;
  183. struct ieee80211_tx_rate *rates;
  184. wlhdr = (const struct ieee80211_hdr *)fragment_data;
  185. memset(txhdr, 0, sizeof(*txhdr));
  186. tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info);
  187. rate = tx_rate->hw_value;
  188. rate_ofdm = b43legacy_is_ofdm_rate(rate);
  189. rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : tx_rate;
  190. rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
  191. txhdr->mac_frame_ctl = wlhdr->frame_control;
  192. memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN);
  193. /* Calculate duration for fallback rate */
  194. if ((rate_fb->hw_value == rate) ||
  195. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  196. (wlhdr->duration_id == cpu_to_le16(0))) {
  197. /* If the fallback rate equals the normal rate or the
  198. * dur_id field contains an AID, CFP magic or 0,
  199. * use the original dur_id field. */
  200. txhdr->dur_fb = wlhdr->duration_id;
  201. } else {
  202. txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
  203. info->control.vif,
  204. info->band,
  205. fragment_len,
  206. rate_fb);
  207. }
  208. plcp_fragment_len = fragment_len + FCS_LEN;
  209. if (use_encryption) {
  210. u8 key_idx = info->control.hw_key->hw_key_idx;
  211. struct b43legacy_key *key;
  212. int wlhdr_len;
  213. size_t iv_len;
  214. B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
  215. key = &(dev->key[key_idx]);
  216. if (key->enabled) {
  217. /* Hardware appends ICV. */
  218. plcp_fragment_len += info->control.hw_key->icv_len;
  219. key_idx = b43legacy_kidx_to_fw(dev, key_idx);
  220. mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
  221. B43legacy_TX4_MAC_KEYIDX;
  222. mac_ctl |= (key->algorithm <<
  223. B43legacy_TX4_MAC_KEYALG_SHIFT) &
  224. B43legacy_TX4_MAC_KEYALG;
  225. wlhdr_len = ieee80211_hdrlen(wlhdr->frame_control);
  226. iv_len = min_t(size_t, info->control.hw_key->iv_len,
  227. ARRAY_SIZE(txhdr->iv));
  228. memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
  229. } else {
  230. /* This key is invalid. This might only happen
  231. * in a short timeframe after machine resume before
  232. * we were able to reconfigure keys.
  233. * Drop this packet completely. Do not transmit it
  234. * unencrypted to avoid leaking information. */
  235. return -ENOKEY;
  236. }
  237. }
  238. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  239. (&txhdr->plcp), plcp_fragment_len,
  240. rate);
  241. b43legacy_generate_plcp_hdr(&txhdr->plcp_fb, plcp_fragment_len,
  242. rate_fb->hw_value);
  243. /* PHY TX Control word */
  244. if (rate_ofdm)
  245. phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM;
  246. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  247. phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
  248. phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
  249. /* MAC control */
  250. rates = info->control.rates;
  251. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  252. mac_ctl |= B43legacy_TX4_MAC_ACK;
  253. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  254. mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
  255. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  256. mac_ctl |= B43legacy_TX4_MAC_STMSDU;
  257. if (rate_fb_ofdm)
  258. mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
  259. /* Overwrite rates[0].count to make the retry calculation
  260. * in the tx status easier. need the actual retry limit to
  261. * detect whether the fallback rate was used.
  262. */
  263. if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  264. (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
  265. rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
  266. mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
  267. } else {
  268. rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
  269. }
  270. /* Generate the RTS or CTS-to-self frame */
  271. if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  272. (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
  273. unsigned int len;
  274. struct ieee80211_hdr *hdr;
  275. int rts_rate;
  276. int rts_rate_fb;
  277. int rts_rate_fb_ofdm;
  278. rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
  279. rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
  280. rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
  281. if (rts_rate_fb_ofdm)
  282. mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
  283. if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  284. ieee80211_ctstoself_get(dev->wl->hw,
  285. info->control.vif,
  286. fragment_data,
  287. fragment_len, info,
  288. (struct ieee80211_cts *)
  289. (txhdr->rts_frame));
  290. mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
  291. len = sizeof(struct ieee80211_cts);
  292. } else {
  293. ieee80211_rts_get(dev->wl->hw,
  294. info->control.vif,
  295. fragment_data, fragment_len, info,
  296. (struct ieee80211_rts *)
  297. (txhdr->rts_frame));
  298. mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
  299. len = sizeof(struct ieee80211_rts);
  300. }
  301. len += FCS_LEN;
  302. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  303. (&txhdr->rts_plcp),
  304. len, rts_rate);
  305. b43legacy_generate_plcp_hdr(&txhdr->rts_plcp_fb,
  306. len, rts_rate_fb);
  307. hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
  308. txhdr->rts_dur_fb = hdr->duration_id;
  309. }
  310. /* Magic cookie */
  311. txhdr->cookie = cpu_to_le16(cookie);
  312. /* Apply the bitfields */
  313. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  314. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  315. return 0;
  316. }
  317. int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
  318. u8 *txhdr,
  319. const unsigned char *fragment_data,
  320. unsigned int fragment_len,
  321. struct ieee80211_tx_info *info,
  322. u16 cookie)
  323. {
  324. return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
  325. fragment_data, fragment_len,
  326. info, cookie);
  327. }
  328. static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
  329. u8 in_rssi, int ofdm,
  330. int adjust_2053, int adjust_2050)
  331. {
  332. struct b43legacy_phy *phy = &dev->phy;
  333. s32 tmp;
  334. switch (phy->radio_ver) {
  335. case 0x2050:
  336. if (ofdm) {
  337. tmp = in_rssi;
  338. if (tmp > 127)
  339. tmp -= 256;
  340. tmp *= 73;
  341. tmp /= 64;
  342. if (adjust_2050)
  343. tmp += 25;
  344. else
  345. tmp -= 3;
  346. } else {
  347. if (dev->dev->bus->sprom.boardflags_lo
  348. & B43legacy_BFL_RSSI) {
  349. if (in_rssi > 63)
  350. in_rssi = 63;
  351. tmp = phy->nrssi_lt[in_rssi];
  352. tmp = 31 - tmp;
  353. tmp *= -131;
  354. tmp /= 128;
  355. tmp -= 57;
  356. } else {
  357. tmp = in_rssi;
  358. tmp = 31 - tmp;
  359. tmp *= -149;
  360. tmp /= 128;
  361. tmp -= 68;
  362. }
  363. if (phy->type == B43legacy_PHYTYPE_G &&
  364. adjust_2050)
  365. tmp += 25;
  366. }
  367. break;
  368. case 0x2060:
  369. if (in_rssi > 127)
  370. tmp = in_rssi - 256;
  371. else
  372. tmp = in_rssi;
  373. break;
  374. default:
  375. tmp = in_rssi;
  376. tmp -= 11;
  377. tmp *= 103;
  378. tmp /= 64;
  379. if (adjust_2053)
  380. tmp -= 109;
  381. else
  382. tmp -= 83;
  383. }
  384. return (s8)tmp;
  385. }
  386. void b43legacy_rx(struct b43legacy_wldev *dev,
  387. struct sk_buff *skb,
  388. const void *_rxhdr)
  389. {
  390. struct ieee80211_rx_status status;
  391. struct b43legacy_plcp_hdr6 *plcp;
  392. struct ieee80211_hdr *wlhdr;
  393. const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
  394. __le16 fctl;
  395. u16 phystat0;
  396. u16 phystat3;
  397. u16 chanstat;
  398. u16 mactime;
  399. u32 macstat;
  400. u16 chanid;
  401. u8 jssi;
  402. int padding;
  403. memset(&status, 0, sizeof(status));
  404. /* Get metadata about the frame from the header. */
  405. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  406. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  407. jssi = rxhdr->jssi;
  408. macstat = le16_to_cpu(rxhdr->mac_status);
  409. mactime = le16_to_cpu(rxhdr->mac_time);
  410. chanstat = le16_to_cpu(rxhdr->channel);
  411. if (macstat & B43legacy_RX_MAC_FCSERR)
  412. dev->wl->ieee_stats.dot11FCSErrorCount++;
  413. /* Skip PLCP and padding */
  414. padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
  415. if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
  416. padding))) {
  417. b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
  418. goto drop;
  419. }
  420. plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
  421. skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
  422. /* The skb contains the Wireless Header + payload data now */
  423. if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
  424. b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
  425. goto drop;
  426. }
  427. wlhdr = (struct ieee80211_hdr *)(skb->data);
  428. fctl = wlhdr->frame_control;
  429. if ((macstat & B43legacy_RX_MAC_DEC) &&
  430. !(macstat & B43legacy_RX_MAC_DECERR)) {
  431. unsigned int keyidx;
  432. int wlhdr_len;
  433. int iv_len;
  434. int icv_len;
  435. keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
  436. >> B43legacy_RX_MAC_KEYIDX_SHIFT);
  437. /* We must adjust the key index here. We want the "physical"
  438. * key index, but the ucode passed it slightly different.
  439. */
  440. keyidx = b43legacy_kidx_to_raw(dev, keyidx);
  441. B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
  442. if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
  443. /* Remove PROTECTED flag to mark it as decrypted. */
  444. B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
  445. fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  446. wlhdr->frame_control = fctl;
  447. wlhdr_len = ieee80211_hdrlen(fctl);
  448. if (unlikely(skb->len < (wlhdr_len + 3))) {
  449. b43legacydbg(dev->wl, "RX: Packet size"
  450. " underrun3\n");
  451. goto drop;
  452. }
  453. if (skb->data[wlhdr_len + 3] & (1 << 5)) {
  454. /* The Ext-IV Bit is set in the "KeyID"
  455. * octet of the IV.
  456. */
  457. iv_len = 8;
  458. icv_len = 8;
  459. } else {
  460. iv_len = 4;
  461. icv_len = 4;
  462. }
  463. if (unlikely(skb->len < (wlhdr_len + iv_len +
  464. icv_len))) {
  465. b43legacydbg(dev->wl, "RX: Packet size"
  466. " underrun4\n");
  467. goto drop;
  468. }
  469. /* Remove the IV */
  470. memmove(skb->data + iv_len, skb->data, wlhdr_len);
  471. skb_pull(skb, iv_len);
  472. /* Remove the ICV */
  473. skb_trim(skb, skb->len - icv_len);
  474. status.flag |= RX_FLAG_DECRYPTED;
  475. }
  476. }
  477. status.signal = b43legacy_rssi_postprocess(dev, jssi,
  478. (phystat0 & B43legacy_RX_PHYST0_OFDM),
  479. (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
  480. (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
  481. /* change to support A PHY */
  482. if (phystat0 & B43legacy_RX_PHYST0_OFDM)
  483. status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
  484. else
  485. status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
  486. status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
  487. /*
  488. * All frames on monitor interfaces and beacons always need a full
  489. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  490. * purposes and beacons for IBSS merging.
  491. * This code assumes we get to process the packet within 16 bits
  492. * of timestamp, i.e. about 65 milliseconds after the PHY received
  493. * the first symbol.
  494. */
  495. if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
  496. u16 low_mactime_now;
  497. b43legacy_tsf_read(dev, &status.mactime);
  498. low_mactime_now = status.mactime;
  499. status.mactime = status.mactime & ~0xFFFFULL;
  500. status.mactime += mactime;
  501. if (low_mactime_now <= mactime)
  502. status.mactime -= 0x10000;
  503. status.flag |= RX_FLAG_MACTIME_START;
  504. }
  505. chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
  506. B43legacy_RX_CHAN_ID_SHIFT;
  507. switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
  508. case B43legacy_PHYTYPE_B:
  509. case B43legacy_PHYTYPE_G:
  510. status.band = NL80211_BAND_2GHZ;
  511. status.freq = chanid + 2400;
  512. break;
  513. default:
  514. b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
  515. chanstat);
  516. }
  517. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  518. ieee80211_rx_irqsafe(dev->wl->hw, skb);
  519. return;
  520. drop:
  521. b43legacydbg(dev->wl, "RX: Packet dropped\n");
  522. dev_kfree_skb_any(skb);
  523. }
  524. void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
  525. const struct b43legacy_txstatus *status)
  526. {
  527. b43legacy_debugfs_log_txstat(dev, status);
  528. if (status->intermediate)
  529. return;
  530. if (status->for_ampdu)
  531. return;
  532. if (!status->acked)
  533. dev->wl->ieee_stats.dot11ACKFailureCount++;
  534. if (status->rts_count) {
  535. if (status->rts_count == 0xF) /* FIXME */
  536. dev->wl->ieee_stats.dot11RTSFailureCount++;
  537. else
  538. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  539. }
  540. if (b43legacy_using_pio(dev))
  541. b43legacy_pio_handle_txstatus(dev, status);
  542. else
  543. b43legacy_dma_handle_txstatus(dev, status);
  544. }
  545. /* Handle TX status report as received through DMA/PIO queues */
  546. void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
  547. const struct b43legacy_hwtxstatus *hw)
  548. {
  549. struct b43legacy_txstatus status;
  550. u8 tmp;
  551. status.cookie = le16_to_cpu(hw->cookie);
  552. status.seq = le16_to_cpu(hw->seq);
  553. status.phy_stat = hw->phy_stat;
  554. tmp = hw->count;
  555. status.frame_count = (tmp >> 4);
  556. status.rts_count = (tmp & 0x0F);
  557. tmp = hw->flags << 1;
  558. status.supp_reason = ((tmp & 0x1C) >> 2);
  559. status.pm_indicated = !!(tmp & 0x80);
  560. status.intermediate = !!(tmp & 0x40);
  561. status.for_ampdu = !!(tmp & 0x20);
  562. status.acked = !!(tmp & 0x02);
  563. b43legacy_handle_txstatus(dev, &status);
  564. }
  565. /* Stop any TX operation on the device (suspend the hardware queues) */
  566. void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
  567. {
  568. if (b43legacy_using_pio(dev))
  569. b43legacy_pio_freeze_txqueues(dev);
  570. else
  571. b43legacy_dma_tx_suspend(dev);
  572. }
  573. /* Resume any TX operation on the device (resume the hardware queues) */
  574. void b43legacy_tx_resume(struct b43legacy_wldev *dev)
  575. {
  576. if (b43legacy_using_pio(dev))
  577. b43legacy_pio_thaw_txqueues(dev);
  578. else
  579. b43legacy_dma_tx_resume(dev);
  580. }
  581. /* Initialize the QoS parameters */
  582. void b43legacy_qos_init(struct b43legacy_wldev *dev)
  583. {
  584. /* FIXME: This function must probably be called from the mac80211
  585. * config callback. */
  586. return;
  587. b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
  588. /* FIXME kill magic */
  589. b43legacy_write16(dev, 0x688,
  590. b43legacy_read16(dev, 0x688) | 0x4);
  591. /*TODO: We might need some stack support here to get the values. */
  592. }