xmit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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, 6);
  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((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((struct b43legacy_plcp_hdr4 *)
  242. (&txhdr->plcp_fb), plcp_fragment_len,
  243. rate_fb->hw_value);
  244. /* PHY TX Control word */
  245. if (rate_ofdm)
  246. phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM;
  247. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  248. phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
  249. phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
  250. /* MAC control */
  251. rates = info->control.rates;
  252. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  253. mac_ctl |= B43legacy_TX4_MAC_ACK;
  254. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  255. mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
  256. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  257. mac_ctl |= B43legacy_TX4_MAC_STMSDU;
  258. if (rate_fb_ofdm)
  259. mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
  260. /* Overwrite rates[0].count to make the retry calculation
  261. * in the tx status easier. need the actual retry limit to
  262. * detect whether the fallback rate was used.
  263. */
  264. if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  265. (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
  266. rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
  267. mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
  268. } else {
  269. rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
  270. }
  271. /* Generate the RTS or CTS-to-self frame */
  272. if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  273. (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
  274. unsigned int len;
  275. struct ieee80211_hdr *hdr;
  276. int rts_rate;
  277. int rts_rate_fb;
  278. int rts_rate_fb_ofdm;
  279. rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
  280. rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
  281. rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
  282. if (rts_rate_fb_ofdm)
  283. mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
  284. if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  285. ieee80211_ctstoself_get(dev->wl->hw,
  286. info->control.vif,
  287. fragment_data,
  288. fragment_len, info,
  289. (struct ieee80211_cts *)
  290. (txhdr->rts_frame));
  291. mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
  292. len = sizeof(struct ieee80211_cts);
  293. } else {
  294. ieee80211_rts_get(dev->wl->hw,
  295. info->control.vif,
  296. fragment_data, fragment_len, info,
  297. (struct ieee80211_rts *)
  298. (txhdr->rts_frame));
  299. mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
  300. len = sizeof(struct ieee80211_rts);
  301. }
  302. len += FCS_LEN;
  303. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  304. (&txhdr->rts_plcp),
  305. len, rts_rate);
  306. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  307. (&txhdr->rts_plcp_fb),
  308. len, rts_rate_fb);
  309. hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
  310. txhdr->rts_dur_fb = hdr->duration_id;
  311. }
  312. /* Magic cookie */
  313. txhdr->cookie = cpu_to_le16(cookie);
  314. /* Apply the bitfields */
  315. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  316. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  317. return 0;
  318. }
  319. int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
  320. u8 *txhdr,
  321. const unsigned char *fragment_data,
  322. unsigned int fragment_len,
  323. struct ieee80211_tx_info *info,
  324. u16 cookie)
  325. {
  326. return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
  327. fragment_data, fragment_len,
  328. info, cookie);
  329. }
  330. static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
  331. u8 in_rssi, int ofdm,
  332. int adjust_2053, int adjust_2050)
  333. {
  334. struct b43legacy_phy *phy = &dev->phy;
  335. s32 tmp;
  336. switch (phy->radio_ver) {
  337. case 0x2050:
  338. if (ofdm) {
  339. tmp = in_rssi;
  340. if (tmp > 127)
  341. tmp -= 256;
  342. tmp *= 73;
  343. tmp /= 64;
  344. if (adjust_2050)
  345. tmp += 25;
  346. else
  347. tmp -= 3;
  348. } else {
  349. if (dev->dev->bus->sprom.boardflags_lo
  350. & B43legacy_BFL_RSSI) {
  351. if (in_rssi > 63)
  352. in_rssi = 63;
  353. tmp = phy->nrssi_lt[in_rssi];
  354. tmp = 31 - tmp;
  355. tmp *= -131;
  356. tmp /= 128;
  357. tmp -= 57;
  358. } else {
  359. tmp = in_rssi;
  360. tmp = 31 - tmp;
  361. tmp *= -149;
  362. tmp /= 128;
  363. tmp -= 68;
  364. }
  365. if (phy->type == B43legacy_PHYTYPE_G &&
  366. adjust_2050)
  367. tmp += 25;
  368. }
  369. break;
  370. case 0x2060:
  371. if (in_rssi > 127)
  372. tmp = in_rssi - 256;
  373. else
  374. tmp = in_rssi;
  375. break;
  376. default:
  377. tmp = in_rssi;
  378. tmp -= 11;
  379. tmp *= 103;
  380. tmp /= 64;
  381. if (adjust_2053)
  382. tmp -= 109;
  383. else
  384. tmp -= 83;
  385. }
  386. return (s8)tmp;
  387. }
  388. void b43legacy_rx(struct b43legacy_wldev *dev,
  389. struct sk_buff *skb,
  390. const void *_rxhdr)
  391. {
  392. struct ieee80211_rx_status status;
  393. struct b43legacy_plcp_hdr6 *plcp;
  394. struct ieee80211_hdr *wlhdr;
  395. const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
  396. __le16 fctl;
  397. u16 phystat0;
  398. u16 phystat3;
  399. u16 chanstat;
  400. u16 mactime;
  401. u32 macstat;
  402. u16 chanid;
  403. u8 jssi;
  404. int padding;
  405. memset(&status, 0, sizeof(status));
  406. /* Get metadata about the frame from the header. */
  407. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  408. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  409. jssi = rxhdr->jssi;
  410. macstat = le16_to_cpu(rxhdr->mac_status);
  411. mactime = le16_to_cpu(rxhdr->mac_time);
  412. chanstat = le16_to_cpu(rxhdr->channel);
  413. if (macstat & B43legacy_RX_MAC_FCSERR)
  414. dev->wl->ieee_stats.dot11FCSErrorCount++;
  415. /* Skip PLCP and padding */
  416. padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
  417. if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
  418. padding))) {
  419. b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
  420. goto drop;
  421. }
  422. plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
  423. skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
  424. /* The skb contains the Wireless Header + payload data now */
  425. if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
  426. b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
  427. goto drop;
  428. }
  429. wlhdr = (struct ieee80211_hdr *)(skb->data);
  430. fctl = wlhdr->frame_control;
  431. if ((macstat & B43legacy_RX_MAC_DEC) &&
  432. !(macstat & B43legacy_RX_MAC_DECERR)) {
  433. unsigned int keyidx;
  434. int wlhdr_len;
  435. int iv_len;
  436. int icv_len;
  437. keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
  438. >> B43legacy_RX_MAC_KEYIDX_SHIFT);
  439. /* We must adjust the key index here. We want the "physical"
  440. * key index, but the ucode passed it slightly different.
  441. */
  442. keyidx = b43legacy_kidx_to_raw(dev, keyidx);
  443. B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
  444. if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
  445. /* Remove PROTECTED flag to mark it as decrypted. */
  446. B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
  447. fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  448. wlhdr->frame_control = fctl;
  449. wlhdr_len = ieee80211_hdrlen(fctl);
  450. if (unlikely(skb->len < (wlhdr_len + 3))) {
  451. b43legacydbg(dev->wl, "RX: Packet size"
  452. " underrun3\n");
  453. goto drop;
  454. }
  455. if (skb->data[wlhdr_len + 3] & (1 << 5)) {
  456. /* The Ext-IV Bit is set in the "KeyID"
  457. * octet of the IV.
  458. */
  459. iv_len = 8;
  460. icv_len = 8;
  461. } else {
  462. iv_len = 4;
  463. icv_len = 4;
  464. }
  465. if (unlikely(skb->len < (wlhdr_len + iv_len +
  466. icv_len))) {
  467. b43legacydbg(dev->wl, "RX: Packet size"
  468. " underrun4\n");
  469. goto drop;
  470. }
  471. /* Remove the IV */
  472. memmove(skb->data + iv_len, skb->data, wlhdr_len);
  473. skb_pull(skb, iv_len);
  474. /* Remove the ICV */
  475. skb_trim(skb, skb->len - icv_len);
  476. status.flag |= RX_FLAG_DECRYPTED;
  477. }
  478. }
  479. status.signal = b43legacy_rssi_postprocess(dev, jssi,
  480. (phystat0 & B43legacy_RX_PHYST0_OFDM),
  481. (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
  482. (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
  483. /* change to support A PHY */
  484. if (phystat0 & B43legacy_RX_PHYST0_OFDM)
  485. status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
  486. else
  487. status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
  488. status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
  489. /*
  490. * All frames on monitor interfaces and beacons always need a full
  491. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  492. * purposes and beacons for IBSS merging.
  493. * This code assumes we get to process the packet within 16 bits
  494. * of timestamp, i.e. about 65 milliseconds after the PHY received
  495. * the first symbol.
  496. */
  497. if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
  498. u16 low_mactime_now;
  499. b43legacy_tsf_read(dev, &status.mactime);
  500. low_mactime_now = status.mactime;
  501. status.mactime = status.mactime & ~0xFFFFULL;
  502. status.mactime += mactime;
  503. if (low_mactime_now <= mactime)
  504. status.mactime -= 0x10000;
  505. status.flag |= RX_FLAG_MACTIME_MPDU;
  506. }
  507. chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
  508. B43legacy_RX_CHAN_ID_SHIFT;
  509. switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
  510. case B43legacy_PHYTYPE_B:
  511. case B43legacy_PHYTYPE_G:
  512. status.band = IEEE80211_BAND_2GHZ;
  513. status.freq = chanid + 2400;
  514. break;
  515. default:
  516. b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
  517. chanstat);
  518. }
  519. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  520. ieee80211_rx_irqsafe(dev->wl->hw, skb);
  521. return;
  522. drop:
  523. b43legacydbg(dev->wl, "RX: Packet dropped\n");
  524. dev_kfree_skb_any(skb);
  525. }
  526. void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
  527. const struct b43legacy_txstatus *status)
  528. {
  529. b43legacy_debugfs_log_txstat(dev, status);
  530. if (status->intermediate)
  531. return;
  532. if (status->for_ampdu)
  533. return;
  534. if (!status->acked)
  535. dev->wl->ieee_stats.dot11ACKFailureCount++;
  536. if (status->rts_count) {
  537. if (status->rts_count == 0xF) /* FIXME */
  538. dev->wl->ieee_stats.dot11RTSFailureCount++;
  539. else
  540. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  541. }
  542. if (b43legacy_using_pio(dev))
  543. b43legacy_pio_handle_txstatus(dev, status);
  544. else
  545. b43legacy_dma_handle_txstatus(dev, status);
  546. }
  547. /* Handle TX status report as received through DMA/PIO queues */
  548. void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
  549. const struct b43legacy_hwtxstatus *hw)
  550. {
  551. struct b43legacy_txstatus status;
  552. u8 tmp;
  553. status.cookie = le16_to_cpu(hw->cookie);
  554. status.seq = le16_to_cpu(hw->seq);
  555. status.phy_stat = hw->phy_stat;
  556. tmp = hw->count;
  557. status.frame_count = (tmp >> 4);
  558. status.rts_count = (tmp & 0x0F);
  559. tmp = hw->flags << 1;
  560. status.supp_reason = ((tmp & 0x1C) >> 2);
  561. status.pm_indicated = !!(tmp & 0x80);
  562. status.intermediate = !!(tmp & 0x40);
  563. status.for_ampdu = !!(tmp & 0x20);
  564. status.acked = !!(tmp & 0x02);
  565. b43legacy_handle_txstatus(dev, &status);
  566. }
  567. /* Stop any TX operation on the device (suspend the hardware queues) */
  568. void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
  569. {
  570. if (b43legacy_using_pio(dev))
  571. b43legacy_pio_freeze_txqueues(dev);
  572. else
  573. b43legacy_dma_tx_suspend(dev);
  574. }
  575. /* Resume any TX operation on the device (resume the hardware queues) */
  576. void b43legacy_tx_resume(struct b43legacy_wldev *dev)
  577. {
  578. if (b43legacy_using_pio(dev))
  579. b43legacy_pio_thaw_txqueues(dev);
  580. else
  581. b43legacy_dma_tx_resume(dev);
  582. }
  583. /* Initialize the QoS parameters */
  584. void b43legacy_qos_init(struct b43legacy_wldev *dev)
  585. {
  586. /* FIXME: This function must probably be called from the mac80211
  587. * config callback. */
  588. return;
  589. b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
  590. /* FIXME kill magic */
  591. b43legacy_write16(dev, 0x688,
  592. b43legacy_read16(dev, 0x688) | 0x4);
  593. /*TODO: We might need some stack support here to get the values. */
  594. }