xmit.c 17 KB

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