xmit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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.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->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT));
  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) ? : 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.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.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. if (!ieee80211_is_pspoll(fctl))
  287. mac_ctl |= B43_TXH_MAC_HWSEQ;
  288. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  289. mac_ctl |= B43_TXH_MAC_STMSDU;
  290. if (phy->type == B43_PHYTYPE_A)
  291. mac_ctl |= B43_TXH_MAC_5GHZ;
  292. if (info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT)
  293. mac_ctl |= B43_TXH_MAC_LONGFRAME;
  294. /* Generate the RTS or CTS-to-self frame */
  295. if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
  296. (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
  297. unsigned int len;
  298. struct ieee80211_hdr *hdr;
  299. int rts_rate, rts_rate_fb;
  300. int rts_rate_ofdm, rts_rate_fb_ofdm;
  301. struct b43_plcp_hdr6 *plcp;
  302. struct ieee80211_rate *rts_cts_rate;
  303. rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info);
  304. rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB;
  305. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  306. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  307. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  308. if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
  309. struct ieee80211_cts *cts;
  310. if (b43_is_old_txhdr_format(dev)) {
  311. cts = (struct ieee80211_cts *)
  312. (txhdr->old_format.rts_frame);
  313. } else {
  314. cts = (struct ieee80211_cts *)
  315. (txhdr->new_format.rts_frame);
  316. }
  317. ieee80211_ctstoself_get(dev->wl->hw, info->control.vif,
  318. fragment_data, fragment_len,
  319. info, cts);
  320. mac_ctl |= B43_TXH_MAC_SENDCTS;
  321. len = sizeof(struct ieee80211_cts);
  322. } else {
  323. struct ieee80211_rts *rts;
  324. if (b43_is_old_txhdr_format(dev)) {
  325. rts = (struct ieee80211_rts *)
  326. (txhdr->old_format.rts_frame);
  327. } else {
  328. rts = (struct ieee80211_rts *)
  329. (txhdr->new_format.rts_frame);
  330. }
  331. ieee80211_rts_get(dev->wl->hw, info->control.vif,
  332. fragment_data, fragment_len,
  333. info, rts);
  334. mac_ctl |= B43_TXH_MAC_SENDRTS;
  335. len = sizeof(struct ieee80211_rts);
  336. }
  337. len += FCS_LEN;
  338. /* Generate the PLCP headers for the RTS/CTS frame */
  339. if (b43_is_old_txhdr_format(dev))
  340. plcp = &txhdr->old_format.rts_plcp;
  341. else
  342. plcp = &txhdr->new_format.rts_plcp;
  343. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  344. len, rts_rate);
  345. plcp = &txhdr->rts_plcp_fb;
  346. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  347. len, rts_rate_fb);
  348. if (b43_is_old_txhdr_format(dev)) {
  349. hdr = (struct ieee80211_hdr *)
  350. (&txhdr->old_format.rts_frame);
  351. } else {
  352. hdr = (struct ieee80211_hdr *)
  353. (&txhdr->new_format.rts_frame);
  354. }
  355. txhdr->rts_dur_fb = hdr->duration_id;
  356. if (rts_rate_ofdm) {
  357. extra_ft |= B43_TXH_EFT_RTS_OFDM;
  358. txhdr->phy_rate_rts =
  359. b43_plcp_get_ratecode_ofdm(rts_rate);
  360. } else {
  361. extra_ft |= B43_TXH_EFT_RTS_CCK;
  362. txhdr->phy_rate_rts =
  363. b43_plcp_get_ratecode_cck(rts_rate);
  364. }
  365. if (rts_rate_fb_ofdm)
  366. extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
  367. else
  368. extra_ft |= B43_TXH_EFT_RTSFB_CCK;
  369. }
  370. /* Magic cookie */
  371. if (b43_is_old_txhdr_format(dev))
  372. txhdr->old_format.cookie = cpu_to_le16(cookie);
  373. else
  374. txhdr->new_format.cookie = cpu_to_le16(cookie);
  375. /* Apply the bitfields */
  376. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  377. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  378. txhdr->extra_ft = extra_ft;
  379. return 0;
  380. }
  381. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  382. u8 in_rssi, int ofdm,
  383. int adjust_2053, int adjust_2050)
  384. {
  385. struct b43_phy *phy = &dev->phy;
  386. s32 tmp;
  387. switch (phy->radio_ver) {
  388. case 0x2050:
  389. if (ofdm) {
  390. tmp = in_rssi;
  391. if (tmp > 127)
  392. tmp -= 256;
  393. tmp *= 73;
  394. tmp /= 64;
  395. if (adjust_2050)
  396. tmp += 25;
  397. else
  398. tmp -= 3;
  399. } else {
  400. if (dev->dev->bus->sprom.
  401. boardflags_lo & B43_BFL_RSSI) {
  402. if (in_rssi > 63)
  403. in_rssi = 63;
  404. tmp = phy->nrssi_lt[in_rssi];
  405. tmp = 31 - tmp;
  406. tmp *= -131;
  407. tmp /= 128;
  408. tmp -= 57;
  409. } else {
  410. tmp = in_rssi;
  411. tmp = 31 - tmp;
  412. tmp *= -149;
  413. tmp /= 128;
  414. tmp -= 68;
  415. }
  416. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  417. tmp += 25;
  418. }
  419. break;
  420. case 0x2060:
  421. if (in_rssi > 127)
  422. tmp = in_rssi - 256;
  423. else
  424. tmp = in_rssi;
  425. break;
  426. default:
  427. tmp = in_rssi;
  428. tmp -= 11;
  429. tmp *= 103;
  430. tmp /= 64;
  431. if (adjust_2053)
  432. tmp -= 109;
  433. else
  434. tmp -= 83;
  435. }
  436. return (s8) tmp;
  437. }
  438. //TODO
  439. #if 0
  440. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  441. {
  442. struct b43_phy *phy = &dev->phy;
  443. s8 ret;
  444. if (phy->type == B43_PHYTYPE_A) {
  445. //TODO: Incomplete specs.
  446. ret = 0;
  447. } else
  448. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  449. return ret;
  450. }
  451. #endif
  452. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  453. {
  454. struct ieee80211_rx_status status;
  455. struct b43_plcp_hdr6 *plcp;
  456. struct ieee80211_hdr *wlhdr;
  457. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  458. __le16 fctl;
  459. u16 phystat0, phystat3, chanstat, mactime;
  460. u32 macstat;
  461. u16 chanid;
  462. u16 phytype;
  463. int padding;
  464. memset(&status, 0, sizeof(status));
  465. /* Get metadata about the frame from the header. */
  466. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  467. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  468. macstat = le32_to_cpu(rxhdr->mac_status);
  469. mactime = le16_to_cpu(rxhdr->mac_time);
  470. chanstat = le16_to_cpu(rxhdr->channel);
  471. phytype = chanstat & B43_RX_CHAN_PHYTYPE;
  472. if (macstat & B43_RX_MAC_FCSERR)
  473. dev->wl->ieee_stats.dot11FCSErrorCount++;
  474. if (macstat & B43_RX_MAC_DECERR) {
  475. /* Decryption with the given key failed.
  476. * Drop the packet. We also won't be able to decrypt it with
  477. * the key in software. */
  478. goto drop;
  479. }
  480. /* Skip PLCP and padding */
  481. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  482. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  483. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  484. goto drop;
  485. }
  486. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  487. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  488. /* The skb contains the Wireless Header + payload data now */
  489. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  490. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  491. goto drop;
  492. }
  493. wlhdr = (struct ieee80211_hdr *)(skb->data);
  494. fctl = wlhdr->frame_control;
  495. if (macstat & B43_RX_MAC_DEC) {
  496. unsigned int keyidx;
  497. int wlhdr_len;
  498. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  499. >> B43_RX_MAC_KEYIDX_SHIFT);
  500. /* We must adjust the key index here. We want the "physical"
  501. * key index, but the ucode passed it slightly different.
  502. */
  503. keyidx = b43_kidx_to_raw(dev, keyidx);
  504. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  505. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  506. wlhdr_len = ieee80211_hdrlen(fctl);
  507. if (unlikely(skb->len < (wlhdr_len + 3))) {
  508. b43dbg(dev->wl,
  509. "RX: Packet size underrun (3)\n");
  510. goto drop;
  511. }
  512. status.flag |= RX_FLAG_DECRYPTED;
  513. }
  514. }
  515. /* Link quality statistics */
  516. status.noise = dev->stats.link_noise;
  517. if ((chanstat & B43_RX_CHAN_PHYTYPE) == B43_PHYTYPE_N) {
  518. // s8 rssi = max(rxhdr->power0, rxhdr->power1);
  519. //TODO: Find out what the rssi value is (dBm or percentage?)
  520. // and also find out what the maximum possible value is.
  521. // Fill status.ssi and status.signal fields.
  522. } else {
  523. status.signal = b43_rssi_postprocess(dev, rxhdr->jssi,
  524. (phystat0 & B43_RX_PHYST0_OFDM),
  525. (phystat0 & B43_RX_PHYST0_GAINCTL),
  526. (phystat3 & B43_RX_PHYST3_TRSTATE));
  527. status.qual = (rxhdr->jssi * 100) / B43_RX_MAX_SSI;
  528. }
  529. if (phystat0 & B43_RX_PHYST0_OFDM)
  530. status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
  531. phytype == B43_PHYTYPE_A);
  532. else
  533. status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
  534. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  535. /*
  536. * All frames on monitor interfaces and beacons always need a full
  537. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  538. * purposes and beacons for IBSS merging.
  539. * This code assumes we get to process the packet within 16 bits
  540. * of timestamp, i.e. about 65 milliseconds after the PHY received
  541. * the first symbol.
  542. */
  543. if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
  544. u16 low_mactime_now;
  545. b43_tsf_read(dev, &status.mactime);
  546. low_mactime_now = status.mactime;
  547. status.mactime = status.mactime & ~0xFFFFULL;
  548. status.mactime += mactime;
  549. if (low_mactime_now <= mactime)
  550. status.mactime -= 0x10000;
  551. status.flag |= RX_FLAG_TSFT;
  552. }
  553. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  554. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  555. case B43_PHYTYPE_A:
  556. status.band = IEEE80211_BAND_5GHZ;
  557. B43_WARN_ON(1);
  558. /* FIXME: We don't really know which value the "chanid" contains.
  559. * So the following assignment might be wrong. */
  560. status.freq = b43_channel_to_freq_5ghz(chanid);
  561. break;
  562. case B43_PHYTYPE_G:
  563. status.band = IEEE80211_BAND_2GHZ;
  564. /* chanid is the radio channel cookie value as used
  565. * to tune the radio. */
  566. status.freq = chanid + 2400;
  567. break;
  568. case B43_PHYTYPE_N:
  569. /* chanid is the SHM channel cookie. Which is the plain
  570. * channel number in b43. */
  571. if (chanstat & B43_RX_CHAN_5GHZ) {
  572. status.band = IEEE80211_BAND_5GHZ;
  573. status.freq = b43_freq_to_channel_5ghz(chanid);
  574. } else {
  575. status.band = IEEE80211_BAND_2GHZ;
  576. status.freq = b43_freq_to_channel_2ghz(chanid);
  577. }
  578. break;
  579. default:
  580. B43_WARN_ON(1);
  581. goto drop;
  582. }
  583. dev->stats.last_rx = jiffies;
  584. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  585. return;
  586. drop:
  587. b43dbg(dev->wl, "RX: Packet dropped\n");
  588. dev_kfree_skb_any(skb);
  589. }
  590. void b43_handle_txstatus(struct b43_wldev *dev,
  591. const struct b43_txstatus *status)
  592. {
  593. b43_debugfs_log_txstat(dev, status);
  594. if (status->intermediate)
  595. return;
  596. if (status->for_ampdu)
  597. return;
  598. if (!status->acked)
  599. dev->wl->ieee_stats.dot11ACKFailureCount++;
  600. if (status->rts_count) {
  601. if (status->rts_count == 0xF) //FIXME
  602. dev->wl->ieee_stats.dot11RTSFailureCount++;
  603. else
  604. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  605. }
  606. if (b43_using_pio_transfers(dev))
  607. b43_pio_handle_txstatus(dev, status);
  608. else
  609. b43_dma_handle_txstatus(dev, status);
  610. }
  611. /* Fill out the mac80211 TXstatus report based on the b43-specific
  612. * txstatus report data. This returns a boolean whether the frame was
  613. * successfully transmitted. */
  614. bool b43_fill_txstatus_report(struct ieee80211_tx_info *report,
  615. const struct b43_txstatus *status)
  616. {
  617. bool frame_success = 1;
  618. if (status->acked) {
  619. /* The frame was ACKed. */
  620. report->flags |= IEEE80211_TX_STAT_ACK;
  621. } else {
  622. /* The frame was not ACKed... */
  623. if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) {
  624. /* ...but we expected an ACK. */
  625. frame_success = 0;
  626. report->status.excessive_retries = 1;
  627. }
  628. }
  629. if (status->frame_count == 0) {
  630. /* The frame was not transmitted at all. */
  631. report->status.retry_count = 0;
  632. } else
  633. report->status.retry_count = status->frame_count - 1;
  634. return frame_success;
  635. }
  636. /* Stop any TX operation on the device (suspend the hardware queues) */
  637. void b43_tx_suspend(struct b43_wldev *dev)
  638. {
  639. if (b43_using_pio_transfers(dev))
  640. b43_pio_tx_suspend(dev);
  641. else
  642. b43_dma_tx_suspend(dev);
  643. }
  644. /* Resume any TX operation on the device (resume the hardware queues) */
  645. void b43_tx_resume(struct b43_wldev *dev)
  646. {
  647. if (b43_using_pio_transfers(dev))
  648. b43_pio_tx_resume(dev);
  649. else
  650. b43_dma_tx_resume(dev);
  651. }