xmit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 <mb@bu3sch.de>
  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. const struct ieee80211_tx_control *txctl,
  171. u16 cookie)
  172. {
  173. const struct ieee80211_hdr *wlhdr;
  174. int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
  175. u16 fctl;
  176. u8 rate;
  177. struct ieee80211_rate *rate_fb;
  178. int rate_ofdm;
  179. int rate_fb_ofdm;
  180. unsigned int plcp_fragment_len;
  181. u32 mac_ctl = 0;
  182. u16 phy_ctl = 0;
  183. wlhdr = (const struct ieee80211_hdr *)fragment_data;
  184. fctl = le16_to_cpu(wlhdr->frame_control);
  185. memset(txhdr, 0, sizeof(*txhdr));
  186. rate = txctl->tx_rate->hw_value;
  187. rate_ofdm = b43legacy_is_ofdm_rate(rate);
  188. rate_fb = txctl->alt_retry_rate ? : txctl->tx_rate;
  189. rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
  190. txhdr->mac_frame_ctl = wlhdr->frame_control;
  191. memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
  192. /* Calculate duration for fallback rate */
  193. if ((rate_fb->hw_value == rate) ||
  194. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  195. (wlhdr->duration_id == cpu_to_le16(0))) {
  196. /* If the fallback rate equals the normal rate or the
  197. * dur_id field contains an AID, CFP magic or 0,
  198. * use the original dur_id field. */
  199. txhdr->dur_fb = wlhdr->duration_id;
  200. } else {
  201. txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
  202. txctl->vif,
  203. fragment_len,
  204. rate_fb);
  205. }
  206. plcp_fragment_len = fragment_len + FCS_LEN;
  207. if (use_encryption) {
  208. u8 key_idx = (u16)(txctl->key_idx);
  209. struct b43legacy_key *key;
  210. int wlhdr_len;
  211. size_t iv_len;
  212. B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
  213. key = &(dev->key[key_idx]);
  214. if (key->enabled) {
  215. /* Hardware appends ICV. */
  216. plcp_fragment_len += txctl->icv_len;
  217. key_idx = b43legacy_kidx_to_fw(dev, key_idx);
  218. mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
  219. B43legacy_TX4_MAC_KEYIDX;
  220. mac_ctl |= (key->algorithm <<
  221. B43legacy_TX4_MAC_KEYALG_SHIFT) &
  222. B43legacy_TX4_MAC_KEYALG;
  223. wlhdr_len = ieee80211_get_hdrlen(fctl);
  224. iv_len = min((size_t)txctl->iv_len,
  225. ARRAY_SIZE(txhdr->iv));
  226. memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
  227. } else {
  228. /* This key is invalid. This might only happen
  229. * in a short timeframe after machine resume before
  230. * we were able to reconfigure keys.
  231. * Drop this packet completely. Do not transmit it
  232. * unencrypted to avoid leaking information. */
  233. return -ENOKEY;
  234. }
  235. }
  236. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  237. (&txhdr->plcp), plcp_fragment_len,
  238. rate);
  239. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  240. (&txhdr->plcp_fb), plcp_fragment_len,
  241. rate_fb->hw_value);
  242. /* PHY TX Control word */
  243. if (rate_ofdm)
  244. phy_ctl |= B43legacy_TX4_PHY_OFDM;
  245. if (dev->short_preamble)
  246. phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
  247. switch (txctl->antenna_sel_tx) {
  248. case 0:
  249. phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
  250. break;
  251. case 1:
  252. phy_ctl |= B43legacy_TX4_PHY_ANT0;
  253. break;
  254. case 2:
  255. phy_ctl |= B43legacy_TX4_PHY_ANT1;
  256. break;
  257. default:
  258. B43legacy_BUG_ON(1);
  259. }
  260. /* MAC control */
  261. if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
  262. mac_ctl |= B43legacy_TX4_MAC_ACK;
  263. if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  264. ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
  265. mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
  266. if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
  267. mac_ctl |= B43legacy_TX4_MAC_STMSDU;
  268. if (rate_fb_ofdm)
  269. mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
  270. if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
  271. mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
  272. /* Generate the RTS or CTS-to-self frame */
  273. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  274. (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
  275. unsigned int len;
  276. struct ieee80211_hdr *hdr;
  277. int rts_rate;
  278. int rts_rate_fb;
  279. int rts_rate_ofdm;
  280. int rts_rate_fb_ofdm;
  281. rts_rate = txctl->rts_cts_rate->hw_value;
  282. rts_rate_ofdm = b43legacy_is_ofdm_rate(rts_rate);
  283. rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
  284. rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
  285. if (rts_rate_fb_ofdm)
  286. mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
  287. if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  288. ieee80211_ctstoself_get(dev->wl->hw,
  289. txctl->vif,
  290. fragment_data,
  291. fragment_len, txctl,
  292. (struct ieee80211_cts *)
  293. (txhdr->rts_frame));
  294. mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
  295. len = sizeof(struct ieee80211_cts);
  296. } else {
  297. ieee80211_rts_get(dev->wl->hw,
  298. txctl->vif,
  299. fragment_data, fragment_len, txctl,
  300. (struct ieee80211_rts *)
  301. (txhdr->rts_frame));
  302. mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
  303. len = sizeof(struct ieee80211_rts);
  304. }
  305. len += FCS_LEN;
  306. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  307. (&txhdr->rts_plcp),
  308. len, rts_rate);
  309. b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
  310. (&txhdr->rts_plcp_fb),
  311. len, rts_rate_fb);
  312. hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
  313. txhdr->rts_dur_fb = hdr->duration_id;
  314. }
  315. /* Magic cookie */
  316. txhdr->cookie = cpu_to_le16(cookie);
  317. /* Apply the bitfields */
  318. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  319. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  320. return 0;
  321. }
  322. int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
  323. u8 *txhdr,
  324. const unsigned char *fragment_data,
  325. unsigned int fragment_len,
  326. const struct ieee80211_tx_control *txctl,
  327. u16 cookie)
  328. {
  329. return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
  330. fragment_data, fragment_len,
  331. txctl, cookie);
  332. }
  333. static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
  334. u8 in_rssi, int ofdm,
  335. int adjust_2053, int adjust_2050)
  336. {
  337. struct b43legacy_phy *phy = &dev->phy;
  338. s32 tmp;
  339. switch (phy->radio_ver) {
  340. case 0x2050:
  341. if (ofdm) {
  342. tmp = in_rssi;
  343. if (tmp > 127)
  344. tmp -= 256;
  345. tmp *= 73;
  346. tmp /= 64;
  347. if (adjust_2050)
  348. tmp += 25;
  349. else
  350. tmp -= 3;
  351. } else {
  352. if (dev->dev->bus->sprom.boardflags_lo
  353. & B43legacy_BFL_RSSI) {
  354. if (in_rssi > 63)
  355. in_rssi = 63;
  356. tmp = phy->nrssi_lt[in_rssi];
  357. tmp = 31 - tmp;
  358. tmp *= -131;
  359. tmp /= 128;
  360. tmp -= 57;
  361. } else {
  362. tmp = in_rssi;
  363. tmp = 31 - tmp;
  364. tmp *= -149;
  365. tmp /= 128;
  366. tmp -= 68;
  367. }
  368. if (phy->type == B43legacy_PHYTYPE_G &&
  369. adjust_2050)
  370. tmp += 25;
  371. }
  372. break;
  373. case 0x2060:
  374. if (in_rssi > 127)
  375. tmp = in_rssi - 256;
  376. else
  377. tmp = in_rssi;
  378. break;
  379. default:
  380. tmp = in_rssi;
  381. tmp -= 11;
  382. tmp *= 103;
  383. tmp /= 64;
  384. if (adjust_2053)
  385. tmp -= 109;
  386. else
  387. tmp -= 83;
  388. }
  389. return (s8)tmp;
  390. }
  391. void b43legacy_rx(struct b43legacy_wldev *dev,
  392. struct sk_buff *skb,
  393. const void *_rxhdr)
  394. {
  395. struct ieee80211_rx_status status;
  396. struct b43legacy_plcp_hdr6 *plcp;
  397. struct ieee80211_hdr *wlhdr;
  398. const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
  399. u16 fctl;
  400. u16 phystat0;
  401. u16 phystat3;
  402. u16 chanstat;
  403. u16 mactime;
  404. u32 macstat;
  405. u16 chanid;
  406. u8 jssi;
  407. int padding;
  408. memset(&status, 0, sizeof(status));
  409. /* Get metadata about the frame from the header. */
  410. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  411. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  412. jssi = rxhdr->jssi;
  413. macstat = le16_to_cpu(rxhdr->mac_status);
  414. mactime = le16_to_cpu(rxhdr->mac_time);
  415. chanstat = le16_to_cpu(rxhdr->channel);
  416. if (macstat & B43legacy_RX_MAC_FCSERR)
  417. dev->wl->ieee_stats.dot11FCSErrorCount++;
  418. /* Skip PLCP and padding */
  419. padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
  420. if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
  421. padding))) {
  422. b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
  423. goto drop;
  424. }
  425. plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
  426. skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
  427. /* The skb contains the Wireless Header + payload data now */
  428. if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
  429. b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
  430. goto drop;
  431. }
  432. wlhdr = (struct ieee80211_hdr *)(skb->data);
  433. fctl = le16_to_cpu(wlhdr->frame_control);
  434. if ((macstat & B43legacy_RX_MAC_DEC) &&
  435. !(macstat & B43legacy_RX_MAC_DECERR)) {
  436. unsigned int keyidx;
  437. int wlhdr_len;
  438. int iv_len;
  439. int icv_len;
  440. keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
  441. >> B43legacy_RX_MAC_KEYIDX_SHIFT);
  442. /* We must adjust the key index here. We want the "physical"
  443. * key index, but the ucode passed it slightly different.
  444. */
  445. keyidx = b43legacy_kidx_to_raw(dev, keyidx);
  446. B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
  447. if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
  448. /* Remove PROTECTED flag to mark it as decrypted. */
  449. B43legacy_WARN_ON(!(fctl & IEEE80211_FCTL_PROTECTED));
  450. fctl &= ~IEEE80211_FCTL_PROTECTED;
  451. wlhdr->frame_control = cpu_to_le16(fctl);
  452. wlhdr_len = ieee80211_get_hdrlen(fctl);
  453. if (unlikely(skb->len < (wlhdr_len + 3))) {
  454. b43legacydbg(dev->wl, "RX: Packet size"
  455. " underrun3\n");
  456. goto drop;
  457. }
  458. if (skb->data[wlhdr_len + 3] & (1 << 5)) {
  459. /* The Ext-IV Bit is set in the "KeyID"
  460. * octet of the IV.
  461. */
  462. iv_len = 8;
  463. icv_len = 8;
  464. } else {
  465. iv_len = 4;
  466. icv_len = 4;
  467. }
  468. if (unlikely(skb->len < (wlhdr_len + iv_len +
  469. icv_len))) {
  470. b43legacydbg(dev->wl, "RX: Packet size"
  471. " underrun4\n");
  472. goto drop;
  473. }
  474. /* Remove the IV */
  475. memmove(skb->data + iv_len, skb->data, wlhdr_len);
  476. skb_pull(skb, iv_len);
  477. /* Remove the ICV */
  478. skb_trim(skb, skb->len - icv_len);
  479. status.flag |= RX_FLAG_DECRYPTED;
  480. }
  481. }
  482. status.ssi = b43legacy_rssi_postprocess(dev, jssi,
  483. (phystat0 & B43legacy_RX_PHYST0_OFDM),
  484. (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
  485. (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
  486. status.noise = dev->stats.link_noise;
  487. status.signal = (jssi * 100) / B43legacy_RX_MAX_SSI;
  488. /* change to support A PHY */
  489. if (phystat0 & B43legacy_RX_PHYST0_OFDM)
  490. status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
  491. else
  492. status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
  493. status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
  494. /*
  495. * All frames on monitor interfaces and beacons always need a full
  496. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  497. * purposes and beacons for IBSS merging.
  498. * This code assumes we get to process the packet within 16 bits
  499. * of timestamp, i.e. about 65 milliseconds after the PHY received
  500. * the first symbol.
  501. */
  502. if (((fctl & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
  503. == (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON)) ||
  504. dev->wl->radiotap_enabled) {
  505. u16 low_mactime_now;
  506. b43legacy_tsf_read(dev, &status.mactime);
  507. low_mactime_now = status.mactime;
  508. status.mactime = status.mactime & ~0xFFFFULL;
  509. status.mactime += mactime;
  510. if (low_mactime_now <= mactime)
  511. status.mactime -= 0x10000;
  512. status.flag |= RX_FLAG_TSFT;
  513. }
  514. chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
  515. B43legacy_RX_CHAN_ID_SHIFT;
  516. switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
  517. case B43legacy_PHYTYPE_B:
  518. case B43legacy_PHYTYPE_G:
  519. status.band = IEEE80211_BAND_2GHZ;
  520. status.freq = chanid + 2400;
  521. break;
  522. default:
  523. b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
  524. chanstat);
  525. }
  526. dev->stats.last_rx = jiffies;
  527. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  528. return;
  529. drop:
  530. b43legacydbg(dev->wl, "RX: Packet dropped\n");
  531. dev_kfree_skb_any(skb);
  532. }
  533. void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
  534. const struct b43legacy_txstatus *status)
  535. {
  536. b43legacy_debugfs_log_txstat(dev, status);
  537. if (status->intermediate)
  538. return;
  539. if (status->for_ampdu)
  540. return;
  541. if (!status->acked)
  542. dev->wl->ieee_stats.dot11ACKFailureCount++;
  543. if (status->rts_count) {
  544. if (status->rts_count == 0xF) /* FIXME */
  545. dev->wl->ieee_stats.dot11RTSFailureCount++;
  546. else
  547. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  548. }
  549. if (b43legacy_using_pio(dev))
  550. b43legacy_pio_handle_txstatus(dev, status);
  551. else
  552. b43legacy_dma_handle_txstatus(dev, status);
  553. }
  554. /* Handle TX status report as received through DMA/PIO queues */
  555. void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
  556. const struct b43legacy_hwtxstatus *hw)
  557. {
  558. struct b43legacy_txstatus status;
  559. u8 tmp;
  560. status.cookie = le16_to_cpu(hw->cookie);
  561. status.seq = le16_to_cpu(hw->seq);
  562. status.phy_stat = hw->phy_stat;
  563. tmp = hw->count;
  564. status.frame_count = (tmp >> 4);
  565. status.rts_count = (tmp & 0x0F);
  566. tmp = hw->flags;
  567. status.supp_reason = ((tmp & 0x1C) >> 2);
  568. status.pm_indicated = !!(tmp & 0x80);
  569. status.intermediate = !!(tmp & 0x40);
  570. status.for_ampdu = !!(tmp & 0x20);
  571. status.acked = !!(tmp & 0x02);
  572. b43legacy_handle_txstatus(dev, &status);
  573. }
  574. /* Stop any TX operation on the device (suspend the hardware queues) */
  575. void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
  576. {
  577. if (b43legacy_using_pio(dev))
  578. b43legacy_pio_freeze_txqueues(dev);
  579. else
  580. b43legacy_dma_tx_suspend(dev);
  581. }
  582. /* Resume any TX operation on the device (resume the hardware queues) */
  583. void b43legacy_tx_resume(struct b43legacy_wldev *dev)
  584. {
  585. if (b43legacy_using_pio(dev))
  586. b43legacy_pio_thaw_txqueues(dev);
  587. else
  588. b43legacy_dma_tx_resume(dev);
  589. }
  590. /* Initialize the QoS parameters */
  591. void b43legacy_qos_init(struct b43legacy_wldev *dev)
  592. {
  593. /* FIXME: This function must probably be called from the mac80211
  594. * config callback. */
  595. return;
  596. b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
  597. /* FIXME kill magic */
  598. b43legacy_write16(dev, 0x688,
  599. b43legacy_read16(dev, 0x688) | 0x4);
  600. /*TODO: We might need some stack support here to get the values. */
  601. }