xmit.c 17 KB

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