xmit.c 17 KB

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