xmit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. Broadcom B43 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. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  20. Boston, MA 02110-1301, USA.
  21. */
  22. #include "xmit.h"
  23. #include "phy_common.h"
  24. #include "dma.h"
  25. #include "pio.h"
  26. /* Extract the bitrate index out of a CCK PLCP header. */
  27. static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
  28. {
  29. switch (plcp->raw[0]) {
  30. case 0x0A:
  31. return 0;
  32. case 0x14:
  33. return 1;
  34. case 0x37:
  35. return 2;
  36. case 0x6E:
  37. return 3;
  38. }
  39. B43_WARN_ON(1);
  40. return -1;
  41. }
  42. /* Extract the bitrate index out of an OFDM PLCP header. */
  43. static u8 b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
  44. {
  45. int base = aphy ? 0 : 4;
  46. switch (plcp->raw[0] & 0xF) {
  47. case 0xB:
  48. return base + 0;
  49. case 0xF:
  50. return base + 1;
  51. case 0xA:
  52. return base + 2;
  53. case 0xE:
  54. return base + 3;
  55. case 0x9:
  56. return base + 4;
  57. case 0xD:
  58. return base + 5;
  59. case 0x8:
  60. return base + 6;
  61. case 0xC:
  62. return base + 7;
  63. }
  64. B43_WARN_ON(1);
  65. return -1;
  66. }
  67. u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
  68. {
  69. switch (bitrate) {
  70. case B43_CCK_RATE_1MB:
  71. return 0x0A;
  72. case B43_CCK_RATE_2MB:
  73. return 0x14;
  74. case B43_CCK_RATE_5MB:
  75. return 0x37;
  76. case B43_CCK_RATE_11MB:
  77. return 0x6E;
  78. }
  79. B43_WARN_ON(1);
  80. return 0;
  81. }
  82. u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
  83. {
  84. switch (bitrate) {
  85. case B43_OFDM_RATE_6MB:
  86. return 0xB;
  87. case B43_OFDM_RATE_9MB:
  88. return 0xF;
  89. case B43_OFDM_RATE_12MB:
  90. return 0xA;
  91. case B43_OFDM_RATE_18MB:
  92. return 0xE;
  93. case B43_OFDM_RATE_24MB:
  94. return 0x9;
  95. case B43_OFDM_RATE_36MB:
  96. return 0xD;
  97. case B43_OFDM_RATE_48MB:
  98. return 0x8;
  99. case B43_OFDM_RATE_54MB:
  100. return 0xC;
  101. }
  102. B43_WARN_ON(1);
  103. return 0;
  104. }
  105. void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
  106. const u16 octets, const u8 bitrate)
  107. {
  108. __le32 *data = &(plcp->data);
  109. __u8 *raw = plcp->raw;
  110. if (b43_is_ofdm_rate(bitrate)) {
  111. u32 d;
  112. d = b43_plcp_get_ratecode_ofdm(bitrate);
  113. B43_WARN_ON(octets & 0xF000);
  114. d |= (octets << 5);
  115. *data = cpu_to_le32(d);
  116. } else {
  117. u32 plen;
  118. plen = octets * 16 / bitrate;
  119. if ((octets * 16 % bitrate) > 0) {
  120. plen++;
  121. if ((bitrate == B43_CCK_RATE_11MB)
  122. && ((octets * 8 % 11) < 4)) {
  123. raw[1] = 0x84;
  124. } else
  125. raw[1] = 0x04;
  126. } else
  127. raw[1] = 0x04;
  128. *data |= cpu_to_le32(plen << 16);
  129. raw[0] = b43_plcp_get_ratecode_cck(bitrate);
  130. }
  131. }
  132. static u8 b43_calc_fallback_rate(u8 bitrate)
  133. {
  134. switch (bitrate) {
  135. case B43_CCK_RATE_1MB:
  136. return B43_CCK_RATE_1MB;
  137. case B43_CCK_RATE_2MB:
  138. return B43_CCK_RATE_1MB;
  139. case B43_CCK_RATE_5MB:
  140. return B43_CCK_RATE_2MB;
  141. case B43_CCK_RATE_11MB:
  142. return B43_CCK_RATE_5MB;
  143. case B43_OFDM_RATE_6MB:
  144. return B43_CCK_RATE_5MB;
  145. case B43_OFDM_RATE_9MB:
  146. return B43_OFDM_RATE_6MB;
  147. case B43_OFDM_RATE_12MB:
  148. return B43_OFDM_RATE_9MB;
  149. case B43_OFDM_RATE_18MB:
  150. return B43_OFDM_RATE_12MB;
  151. case B43_OFDM_RATE_24MB:
  152. return B43_OFDM_RATE_18MB;
  153. case B43_OFDM_RATE_36MB:
  154. return B43_OFDM_RATE_24MB;
  155. case B43_OFDM_RATE_48MB:
  156. return B43_OFDM_RATE_36MB;
  157. case B43_OFDM_RATE_54MB:
  158. return B43_OFDM_RATE_48MB;
  159. }
  160. B43_WARN_ON(1);
  161. return 0;
  162. }
  163. /* Generate a TX data header. */
  164. int b43_generate_txhdr(struct b43_wldev *dev,
  165. u8 *_txhdr,
  166. const unsigned char *fragment_data,
  167. unsigned int fragment_len,
  168. const struct ieee80211_tx_info *info,
  169. u16 cookie)
  170. {
  171. struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
  172. const struct b43_phy *phy = &dev->phy;
  173. const struct ieee80211_hdr *wlhdr =
  174. (const struct ieee80211_hdr *)fragment_data;
  175. int use_encryption = !!info->control.hw_key;
  176. __le16 fctl = wlhdr->frame_control;
  177. struct ieee80211_rate *fbrate;
  178. u8 rate, rate_fb;
  179. int rate_ofdm, rate_fb_ofdm;
  180. unsigned int plcp_fragment_len;
  181. u32 mac_ctl = 0;
  182. u16 phy_ctl = 0;
  183. u8 extra_ft = 0;
  184. struct ieee80211_rate *txrate;
  185. memset(txhdr, 0, sizeof(*txhdr));
  186. txrate = ieee80211_get_tx_rate(dev->wl->hw, info);
  187. rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB;
  188. rate_ofdm = b43_is_ofdm_rate(rate);
  189. fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate;
  190. rate_fb = fbrate->hw_value;
  191. rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
  192. if (rate_ofdm)
  193. txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
  194. else
  195. txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
  196. txhdr->mac_frame_ctl = wlhdr->frame_control;
  197. memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
  198. /* Calculate duration for fallback rate */
  199. if ((rate_fb == rate) ||
  200. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  201. (wlhdr->duration_id == cpu_to_le16(0))) {
  202. /* If the fallback rate equals the normal rate or the
  203. * dur_id field contains an AID, CFP magic or 0,
  204. * use the original dur_id field. */
  205. txhdr->dur_fb = wlhdr->duration_id;
  206. } else {
  207. txhdr->dur_fb = ieee80211_generic_frame_duration(
  208. dev->wl->hw, info->control.vif, fragment_len, fbrate);
  209. }
  210. plcp_fragment_len = fragment_len + FCS_LEN;
  211. if (use_encryption) {
  212. u8 key_idx = info->control.hw_key->hw_key_idx;
  213. struct b43_key *key;
  214. int wlhdr_len;
  215. size_t iv_len;
  216. B43_WARN_ON(key_idx >= dev->max_nr_keys);
  217. key = &(dev->key[key_idx]);
  218. if (unlikely(!key->keyconf)) {
  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. /* Hardware appends ICV. */
  227. plcp_fragment_len += info->control.hw_key->icv_len;
  228. key_idx = b43_kidx_to_fw(dev, key_idx);
  229. mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
  230. B43_TXH_MAC_KEYIDX;
  231. mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
  232. B43_TXH_MAC_KEYALG;
  233. wlhdr_len = ieee80211_hdrlen(fctl);
  234. iv_len = min((size_t) info->control.hw_key->iv_len,
  235. ARRAY_SIZE(txhdr->iv));
  236. memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
  237. }
  238. if (b43_is_old_txhdr_format(dev)) {
  239. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
  240. plcp_fragment_len, rate);
  241. } else {
  242. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
  243. plcp_fragment_len, rate);
  244. }
  245. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
  246. plcp_fragment_len, rate_fb);
  247. /* Extra Frame Types */
  248. if (rate_fb_ofdm)
  249. extra_ft |= B43_TXH_EFT_FB_OFDM;
  250. else
  251. extra_ft |= B43_TXH_EFT_FB_CCK;
  252. /* Set channel radio code. Note that the micrcode ORs 0x100 to
  253. * this value before comparing it to the value in SHM, if this
  254. * is a 5Ghz packet.
  255. */
  256. txhdr->chan_radio_code = phy->channel;
  257. /* PHY TX Control word */
  258. if (rate_ofdm)
  259. phy_ctl |= B43_TXH_PHY_ENC_OFDM;
  260. else
  261. phy_ctl |= B43_TXH_PHY_ENC_CCK;
  262. if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE)
  263. phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
  264. switch (b43_ieee80211_antenna_sanitize(dev, info->antenna_sel_tx)) {
  265. case 0: /* Default */
  266. phy_ctl |= B43_TXH_PHY_ANT01AUTO;
  267. break;
  268. case 1: /* Antenna 0 */
  269. phy_ctl |= B43_TXH_PHY_ANT0;
  270. break;
  271. case 2: /* Antenna 1 */
  272. phy_ctl |= B43_TXH_PHY_ANT1;
  273. break;
  274. case 3: /* Antenna 2 */
  275. phy_ctl |= B43_TXH_PHY_ANT2;
  276. break;
  277. case 4: /* Antenna 3 */
  278. phy_ctl |= B43_TXH_PHY_ANT3;
  279. break;
  280. default:
  281. B43_WARN_ON(1);
  282. }
  283. /* MAC control */
  284. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  285. mac_ctl |= B43_TXH_MAC_ACK;
  286. /* use hardware sequence counter as the non-TID counter */
  287. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  288. mac_ctl |= B43_TXH_MAC_HWSEQ;
  289. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  290. mac_ctl |= B43_TXH_MAC_STMSDU;
  291. if (phy->type == B43_PHYTYPE_A)
  292. mac_ctl |= B43_TXH_MAC_5GHZ;
  293. if (info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
  294. mac_ctl |= B43_TXH_MAC_LONGFRAME;
  295. /* Generate the RTS or CTS-to-self frame */
  296. if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
  297. (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
  298. unsigned int len;
  299. struct ieee80211_hdr *hdr;
  300. int rts_rate, rts_rate_fb;
  301. int rts_rate_ofdm, rts_rate_fb_ofdm;
  302. struct b43_plcp_hdr6 *plcp;
  303. struct ieee80211_rate *rts_cts_rate;
  304. rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
  305. rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
  306. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  307. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  308. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  309. if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
  310. struct ieee80211_cts *cts;
  311. if (b43_is_old_txhdr_format(dev)) {
  312. cts = (struct ieee80211_cts *)
  313. (txhdr->old_format.rts_frame);
  314. } else {
  315. cts = (struct ieee80211_cts *)
  316. (txhdr->new_format.rts_frame);
  317. }
  318. ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
  319. fragment_data, fragment_len,
  320. info, cts);
  321. mac_ctl |= B43_TXH_MAC_SENDCTS;
  322. len = sizeof(struct ieee80211_cts);
  323. } else {
  324. struct ieee80211_rts *rts;
  325. if (b43_is_old_txhdr_format(dev)) {
  326. rts = (struct ieee80211_rts *)
  327. (txhdr->old_format.rts_frame);
  328. } else {
  329. rts = (struct ieee80211_rts *)
  330. (txhdr->new_format.rts_frame);
  331. }
  332. ieee80211_rts_get(dev->wl->hw, info->control.vif,
  333. fragment_data, fragment_len,
  334. info, rts);
  335. mac_ctl |= B43_TXH_MAC_SENDRTS;
  336. len = sizeof(struct ieee80211_rts);
  337. }
  338. len += FCS_LEN;
  339. /* Generate the PLCP headers for the RTS/CTS frame */
  340. if (b43_is_old_txhdr_format(dev))
  341. plcp = &txhdr->old_format.rts_plcp;
  342. else
  343. plcp = &txhdr->new_format.rts_plcp;
  344. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  345. len, rts_rate);
  346. plcp = &txhdr->rts_plcp_fb;
  347. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  348. len, rts_rate_fb);
  349. if (b43_is_old_txhdr_format(dev)) {
  350. hdr = (struct ieee80211_hdr *)
  351. (&txhdr->old_format.rts_frame);
  352. } else {
  353. hdr = (struct ieee80211_hdr *)
  354. (&txhdr->new_format.rts_frame);
  355. }
  356. txhdr->rts_dur_fb = hdr->duration_id;
  357. if (rts_rate_ofdm) {
  358. extra_ft |= B43_TXH_EFT_RTS_OFDM;
  359. txhdr->phy_rate_rts =
  360. b43_plcp_get_ratecode_ofdm(rts_rate);
  361. } else {
  362. extra_ft |= B43_TXH_EFT_RTS_CCK;
  363. txhdr->phy_rate_rts =
  364. b43_plcp_get_ratecode_cck(rts_rate);
  365. }
  366. if (rts_rate_fb_ofdm)
  367. extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
  368. else
  369. extra_ft |= B43_TXH_EFT_RTSFB_CCK;
  370. }
  371. /* Magic cookie */
  372. if (b43_is_old_txhdr_format(dev))
  373. txhdr->old_format.cookie = cpu_to_le16(cookie);
  374. else
  375. txhdr->new_format.cookie = cpu_to_le16(cookie);
  376. /* Apply the bitfields */
  377. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  378. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  379. txhdr->extra_ft = extra_ft;
  380. return 0;
  381. }
  382. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  383. u8 in_rssi, int ofdm,
  384. int adjust_2053, int adjust_2050)
  385. {
  386. struct b43_phy *phy = &dev->phy;
  387. struct b43_phy_g *gphy = phy->g;
  388. s32 tmp;
  389. switch (phy->radio_ver) {
  390. case 0x2050:
  391. if (ofdm) {
  392. tmp = in_rssi;
  393. if (tmp > 127)
  394. tmp -= 256;
  395. tmp *= 73;
  396. tmp /= 64;
  397. if (adjust_2050)
  398. tmp += 25;
  399. else
  400. tmp -= 3;
  401. } else {
  402. if (dev->dev->bus->sprom.
  403. boardflags_lo & B43_BFL_RSSI) {
  404. if (in_rssi > 63)
  405. in_rssi = 63;
  406. B43_WARN_ON(phy->type != B43_PHYTYPE_G);
  407. tmp = gphy->nrssi_lt[in_rssi];
  408. tmp = 31 - tmp;
  409. tmp *= -131;
  410. tmp /= 128;
  411. tmp -= 57;
  412. } else {
  413. tmp = in_rssi;
  414. tmp = 31 - tmp;
  415. tmp *= -149;
  416. tmp /= 128;
  417. tmp -= 68;
  418. }
  419. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  420. tmp += 25;
  421. }
  422. break;
  423. case 0x2060:
  424. if (in_rssi > 127)
  425. tmp = in_rssi - 256;
  426. else
  427. tmp = in_rssi;
  428. break;
  429. default:
  430. tmp = in_rssi;
  431. tmp -= 11;
  432. tmp *= 103;
  433. tmp /= 64;
  434. if (adjust_2053)
  435. tmp -= 109;
  436. else
  437. tmp -= 83;
  438. }
  439. return (s8) tmp;
  440. }
  441. //TODO
  442. #if 0
  443. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  444. {
  445. struct b43_phy *phy = &dev->phy;
  446. s8 ret;
  447. if (phy->type == B43_PHYTYPE_A) {
  448. //TODO: Incomplete specs.
  449. ret = 0;
  450. } else
  451. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  452. return ret;
  453. }
  454. #endif
  455. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  456. {
  457. struct ieee80211_rx_status status;
  458. struct b43_plcp_hdr6 *plcp;
  459. struct ieee80211_hdr *wlhdr;
  460. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  461. __le16 fctl;
  462. u16 phystat0, phystat3, chanstat, mactime;
  463. u32 macstat;
  464. u16 chanid;
  465. u16 phytype;
  466. int padding;
  467. memset(&status, 0, sizeof(status));
  468. /* Get metadata about the frame from the header. */
  469. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  470. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  471. macstat = le32_to_cpu(rxhdr->mac_status);
  472. mactime = le16_to_cpu(rxhdr->mac_time);
  473. chanstat = le16_to_cpu(rxhdr->channel);
  474. phytype = chanstat & B43_RX_CHAN_PHYTYPE;
  475. if (macstat & B43_RX_MAC_FCSERR)
  476. dev->wl->ieee_stats.dot11FCSErrorCount++;
  477. if (macstat & B43_RX_MAC_DECERR) {
  478. /* Decryption with the given key failed.
  479. * Drop the packet. We also won't be able to decrypt it with
  480. * the key in software. */
  481. goto drop;
  482. }
  483. /* Skip PLCP and padding */
  484. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  485. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  486. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  487. goto drop;
  488. }
  489. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  490. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  491. /* The skb contains the Wireless Header + payload data now */
  492. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  493. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  494. goto drop;
  495. }
  496. wlhdr = (struct ieee80211_hdr *)(skb->data);
  497. fctl = wlhdr->frame_control;
  498. if (macstat & B43_RX_MAC_DEC) {
  499. unsigned int keyidx;
  500. int wlhdr_len;
  501. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  502. >> B43_RX_MAC_KEYIDX_SHIFT);
  503. /* We must adjust the key index here. We want the "physical"
  504. * key index, but the ucode passed it slightly different.
  505. */
  506. keyidx = b43_kidx_to_raw(dev, keyidx);
  507. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  508. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  509. wlhdr_len = ieee80211_hdrlen(fctl);
  510. if (unlikely(skb->len < (wlhdr_len + 3))) {
  511. b43dbg(dev->wl,
  512. "RX: Packet size underrun (3)\n");
  513. goto drop;
  514. }
  515. status.flag |= RX_FLAG_DECRYPTED;
  516. }
  517. }
  518. /* Link quality statistics */
  519. status.noise = dev->stats.link_noise;
  520. if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
  521. // s8 rssi = max(rxhdr->power0, rxhdr->power1);
  522. //TODO: Find out what the rssi value is (dBm or percentage?)
  523. // and also find out what the maximum possible value is.
  524. // Fill status.ssi and status.signal fields.
  525. } else {
  526. status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
  527. (phystat0 & B43_RX_PHYST0_OFDM),
  528. (phystat0 & B43_RX_PHYST0_GAINCTL),
  529. (phystat3 & B43_RX_PHYST3_TRSTATE));
  530. status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
  531. }
  532. if (phystat0 & B43_RX_PHYST0_OFDM)
  533. status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
  534. phytype == B43_PHYTYPE_A);
  535. else
  536. status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
  537. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  538. /*
  539. * All frames on monitor interfaces and beacons always need a full
  540. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  541. * purposes and beacons for IBSS merging.
  542. * This code assumes we get to process the packet within 16 bits
  543. * of timestamp, i.e. about 65 milliseconds after the PHY received
  544. * the first symbol.
  545. */
  546. if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
  547. u16 low_mactime_now;
  548. b43_tsf_read(dev, &status.mactime);
  549. low_mactime_now = status.mactime;
  550. status.mactime = status.mactime & ~0xFFFFULL;
  551. status.mactime += mactime;
  552. if (low_mactime_now <= mactime)
  553. status.mactime -= 0x10000;
  554. status.flag |= RX_FLAG_TSFT;
  555. }
  556. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  557. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  558. case B43_PHYTYPE_A:
  559. status.band = IEEE80211_BAND_5GHZ;
  560. B43_WARN_ON(1);
  561. /* FIXME: We don't really know which value the "chanid" contains.
  562. * So the following assignment might be wrong. */
  563. status.freq = b43_channel_to_freq_5ghz(chanid);
  564. break;
  565. case B43_PHYTYPE_G:
  566. status.band = IEEE80211_BAND_2GHZ;
  567. /* chanid is the radio channel cookie value as used
  568. * to tune the radio. */
  569. status.freq = chanid + 2400;
  570. break;
  571. case B43_PHYTYPE_N:
  572. /* chanid is the SHM channel cookie. Which is the plain
  573. * channel number in b43. */
  574. if (chanstat & B43_RX_CHAN_5GHZ) {
  575. status.band = IEEE80211_BAND_5GHZ;
  576. status.freq = b43_freq_to_channel_5ghz(chanid);
  577. } else {
  578. status.band = IEEE80211_BAND_2GHZ;
  579. status.freq = b43_freq_to_channel_2ghz(chanid);
  580. }
  581. break;
  582. default:
  583. B43_WARN_ON(1);
  584. goto drop;
  585. }
  586. dev->stats.last_rx = jiffies;
  587. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  588. return;
  589. drop:
  590. b43dbg(dev->wl, "RX: Packet dropped\n");
  591. dev_kfree_skb_any(skb);
  592. }
  593. void b43_handle_txstatus(struct b43_wldev *dev,
  594. const struct b43_txstatus *status)
  595. {
  596. b43_debugfs_log_txstat(dev, status);
  597. if (status->intermediate)
  598. return;
  599. if (status->for_ampdu)
  600. return;
  601. if (!status->acked)
  602. dev->wl->ieee_stats.dot11ACKFailureCount++;
  603. if (status->rts_count) {
  604. if (status->rts_count == 0xF) //FIXME
  605. dev->wl->ieee_stats.dot11RTSFailureCount++;
  606. else
  607. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  608. }
  609. if (b43_using_pio_transfers(dev))
  610. b43_pio_handle_txstatus(dev, status);
  611. else
  612. b43_dma_handle_txstatus(dev, status);
  613. b43_phy_txpower_check(dev, 0);
  614. }
  615. /* Fill out the mac80211 TXstatus report based on the b43-specific
  616. * txstatus report data. This returns a boolean whether the frame was
  617. * successfully transmitted. */
  618. bool b43_fill_txstatus_report(struct ieee80211_tx_info *report,
  619. const struct b43_txstatus *status)
  620. {
  621. bool frame_success = 1;
  622. if (status->acked) {
  623. /* The frame was ACKed. */
  624. report->flags |= IEEE80211_TX_STAT_ACK;
  625. } else {
  626. /* The frame was not ACKed... */
  627. if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
  628. /* ...but we expected an ACK. */
  629. frame_success = 0;
  630. report->status.excessive_retries = 1;
  631. }
  632. }
  633. if (status->frame_count == 0) {
  634. /* The frame was not transmitted at all. */
  635. report->status.retry_count = 0;
  636. } else
  637. report->status.retry_count = status->frame_count - 1;
  638. return frame_success;
  639. }
  640. /* Stop any TX operation on the device (suspend the hardware queues) */
  641. void b43_tx_suspend(struct b43_wldev *dev)
  642. {
  643. if (b43_using_pio_transfers(dev))
  644. b43_pio_tx_suspend(dev);
  645. else
  646. b43_dma_tx_suspend(dev);
  647. }
  648. /* Resume any TX operation on the device (resume the hardware queues) */
  649. void b43_tx_resume(struct b43_wldev *dev)
  650. {
  651. if (b43_using_pio_transfers(dev))
  652. b43_pio_tx_resume(dev);
  653. else
  654. b43_dma_tx_resume(dev);
  655. }