xmit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. /* Extract the bitrate index out of a CCK PLCP header. */
  26. static int b43_plcp_get_bitrate_idx_cck(struct b43_plcp_hdr6 *plcp)
  27. {
  28. switch (plcp->raw[0]) {
  29. case 0x0A:
  30. return 0;
  31. case 0x14:
  32. return 1;
  33. case 0x37:
  34. return 2;
  35. case 0x6E:
  36. return 3;
  37. }
  38. B43_WARN_ON(1);
  39. return -1;
  40. }
  41. /* Extract the bitrate index out of an OFDM PLCP header. */
  42. static u8 b43_plcp_get_bitrate_idx_ofdm(struct b43_plcp_hdr6 *plcp, bool aphy)
  43. {
  44. int base = aphy ? 0 : 4;
  45. switch (plcp->raw[0] & 0xF) {
  46. case 0xB:
  47. return base + 0;
  48. case 0xF:
  49. return base + 1;
  50. case 0xA:
  51. return base + 2;
  52. case 0xE:
  53. return base + 3;
  54. case 0x9:
  55. return base + 4;
  56. case 0xD:
  57. return base + 5;
  58. case 0x8:
  59. return base + 6;
  60. case 0xC:
  61. return base + 7;
  62. }
  63. B43_WARN_ON(1);
  64. return -1;
  65. }
  66. u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
  67. {
  68. switch (bitrate) {
  69. case B43_CCK_RATE_1MB:
  70. return 0x0A;
  71. case B43_CCK_RATE_2MB:
  72. return 0x14;
  73. case B43_CCK_RATE_5MB:
  74. return 0x37;
  75. case B43_CCK_RATE_11MB:
  76. return 0x6E;
  77. }
  78. B43_WARN_ON(1);
  79. return 0;
  80. }
  81. u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
  82. {
  83. switch (bitrate) {
  84. case B43_OFDM_RATE_6MB:
  85. return 0xB;
  86. case B43_OFDM_RATE_9MB:
  87. return 0xF;
  88. case B43_OFDM_RATE_12MB:
  89. return 0xA;
  90. case B43_OFDM_RATE_18MB:
  91. return 0xE;
  92. case B43_OFDM_RATE_24MB:
  93. return 0x9;
  94. case B43_OFDM_RATE_36MB:
  95. return 0xD;
  96. case B43_OFDM_RATE_48MB:
  97. return 0x8;
  98. case B43_OFDM_RATE_54MB:
  99. return 0xC;
  100. }
  101. B43_WARN_ON(1);
  102. return 0;
  103. }
  104. void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
  105. const u16 octets, const u8 bitrate)
  106. {
  107. __le32 *data = &(plcp->data);
  108. __u8 *raw = plcp->raw;
  109. if (b43_is_ofdm_rate(bitrate)) {
  110. u32 d;
  111. d = b43_plcp_get_ratecode_ofdm(bitrate);
  112. B43_WARN_ON(octets & 0xF000);
  113. d |= (octets << 5);
  114. *data = cpu_to_le32(d);
  115. } else {
  116. u32 plen;
  117. plen = octets * 16 / bitrate;
  118. if ((octets * 16 % bitrate) > 0) {
  119. plen++;
  120. if ((bitrate == B43_CCK_RATE_11MB)
  121. && ((octets * 8 % 11) < 4)) {
  122. raw[1] = 0x84;
  123. } else
  124. raw[1] = 0x04;
  125. } else
  126. raw[1] = 0x04;
  127. *data |= cpu_to_le32(plen << 16);
  128. raw[0] = b43_plcp_get_ratecode_cck(bitrate);
  129. }
  130. }
  131. static u8 b43_calc_fallback_rate(u8 bitrate)
  132. {
  133. switch (bitrate) {
  134. case B43_CCK_RATE_1MB:
  135. return B43_CCK_RATE_1MB;
  136. case B43_CCK_RATE_2MB:
  137. return B43_CCK_RATE_1MB;
  138. case B43_CCK_RATE_5MB:
  139. return B43_CCK_RATE_2MB;
  140. case B43_CCK_RATE_11MB:
  141. return B43_CCK_RATE_5MB;
  142. case B43_OFDM_RATE_6MB:
  143. return B43_CCK_RATE_5MB;
  144. case B43_OFDM_RATE_9MB:
  145. return B43_OFDM_RATE_6MB;
  146. case B43_OFDM_RATE_12MB:
  147. return B43_OFDM_RATE_9MB;
  148. case B43_OFDM_RATE_18MB:
  149. return B43_OFDM_RATE_12MB;
  150. case B43_OFDM_RATE_24MB:
  151. return B43_OFDM_RATE_18MB;
  152. case B43_OFDM_RATE_36MB:
  153. return B43_OFDM_RATE_24MB;
  154. case B43_OFDM_RATE_48MB:
  155. return B43_OFDM_RATE_36MB;
  156. case B43_OFDM_RATE_54MB:
  157. return B43_OFDM_RATE_48MB;
  158. }
  159. B43_WARN_ON(1);
  160. return 0;
  161. }
  162. /* Generate a TX data header. */
  163. int b43_generate_txhdr(struct b43_wldev *dev,
  164. u8 *_txhdr,
  165. const unsigned char *fragment_data,
  166. unsigned int fragment_len,
  167. const struct ieee80211_tx_control *txctl,
  168. u16 cookie)
  169. {
  170. struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
  171. const struct b43_phy *phy = &dev->phy;
  172. const struct ieee80211_hdr *wlhdr =
  173. (const struct ieee80211_hdr *)fragment_data;
  174. int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
  175. u16 fctl = le16_to_cpu(wlhdr->frame_control);
  176. struct ieee80211_rate *fbrate;
  177. u8 rate, rate_fb;
  178. int rate_ofdm, rate_fb_ofdm;
  179. unsigned int plcp_fragment_len;
  180. u32 mac_ctl = 0;
  181. u16 phy_ctl = 0;
  182. u8 extra_ft = 0;
  183. memset(txhdr, 0, sizeof(*txhdr));
  184. WARN_ON(!txctl->tx_rate);
  185. rate = txctl->tx_rate ? txctl->tx_rate->hw_value : B43_CCK_RATE_1MB;
  186. rate_ofdm = b43_is_ofdm_rate(rate);
  187. fbrate = txctl->alt_retry_rate ? : txctl->tx_rate;
  188. rate_fb = fbrate->hw_value;
  189. rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
  190. if (rate_ofdm)
  191. txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
  192. else
  193. txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
  194. txhdr->mac_frame_ctl = wlhdr->frame_control;
  195. memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
  196. /* Calculate duration for fallback rate */
  197. if ((rate_fb == rate) ||
  198. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  199. (wlhdr->duration_id == cpu_to_le16(0))) {
  200. /* If the fallback rate equals the normal rate or the
  201. * dur_id field contains an AID, CFP magic or 0,
  202. * use the original dur_id field. */
  203. txhdr->dur_fb = wlhdr->duration_id;
  204. } else {
  205. txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
  206. txctl->vif,
  207. fragment_len,
  208. fbrate);
  209. }
  210. plcp_fragment_len = fragment_len + FCS_LEN;
  211. if (use_encryption) {
  212. u8 key_idx = (u16) (txctl->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 += txctl->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_get_hdrlen(fctl);
  234. iv_len = min((size_t) txctl->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 (txctl->flags & IEEE80211_TXCTL_SHORT_PREAMBLE)
  263. phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
  264. switch (b43_ieee80211_antenna_sanitize(dev, txctl->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 (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
  285. mac_ctl |= B43_TXH_MAC_ACK;
  286. if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  287. ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
  288. mac_ctl |= B43_TXH_MAC_HWSEQ;
  289. if (txctl->flags & IEEE80211_TXCTL_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 (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
  294. mac_ctl |= B43_TXH_MAC_LONGFRAME;
  295. /* Generate the RTS or CTS-to-self frame */
  296. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  297. (txctl->flags & IEEE80211_TXCTL_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. WARN_ON(!txctl->rts_cts_rate);
  304. rts_rate = txctl->rts_cts_rate ? txctl->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 (txctl->flags & IEEE80211_TXCTL_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, txctl->vif,
  318. fragment_data, fragment_len,
  319. txctl, 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, txctl->vif,
  332. fragment_data, fragment_len,
  333. txctl, 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. u16 fctl;
  459. u16 phystat0, phystat3, chanstat, mactime;
  460. u32 macstat;
  461. u16 chanid;
  462. u16 phytype;
  463. u8 jssi;
  464. int padding;
  465. memset(&status, 0, sizeof(status));
  466. /* Get metadata about the frame from the header. */
  467. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  468. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  469. jssi = rxhdr->jssi;
  470. macstat = le32_to_cpu(rxhdr->mac_status);
  471. mactime = le16_to_cpu(rxhdr->mac_time);
  472. chanstat = le16_to_cpu(rxhdr->channel);
  473. phytype = chanstat & B43_RX_CHAN_PHYTYPE;
  474. if (macstat & B43_RX_MAC_FCSERR)
  475. dev->wl->ieee_stats.dot11FCSErrorCount++;
  476. if (macstat & B43_RX_MAC_DECERR) {
  477. /* Decryption with the given key failed.
  478. * Drop the packet. We also won't be able to decrypt it with
  479. * the key in software. */
  480. goto drop;
  481. }
  482. /* Skip PLCP and padding */
  483. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  484. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  485. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  486. goto drop;
  487. }
  488. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  489. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  490. /* The skb contains the Wireless Header + payload data now */
  491. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  492. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  493. goto drop;
  494. }
  495. wlhdr = (struct ieee80211_hdr *)(skb->data);
  496. fctl = le16_to_cpu(wlhdr->frame_control);
  497. if (macstat & B43_RX_MAC_DEC) {
  498. unsigned int keyidx;
  499. int wlhdr_len;
  500. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  501. >> B43_RX_MAC_KEYIDX_SHIFT);
  502. /* We must adjust the key index here. We want the "physical"
  503. * key index, but the ucode passed it slightly different.
  504. */
  505. keyidx = b43_kidx_to_raw(dev, keyidx);
  506. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  507. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  508. wlhdr_len = ieee80211_get_hdrlen(fctl);
  509. if (unlikely(skb->len < (wlhdr_len + 3))) {
  510. b43dbg(dev->wl,
  511. "RX: Packet size underrun (3)\n");
  512. goto drop;
  513. }
  514. status.flag |= RX_FLAG_DECRYPTED;
  515. }
  516. }
  517. status.ssi = b43_rssi_postprocess(dev, jssi,
  518. (phystat0 & B43_RX_PHYST0_OFDM),
  519. (phystat0 & B43_RX_PHYST0_GAINCTL),
  520. (phystat3 & B43_RX_PHYST3_TRSTATE));
  521. status.noise = dev->stats.link_noise;
  522. /* the next line looks wrong, but is what mac80211 wants */
  523. status.signal = (jssi * 100) / B43_RX_MAX_SSI;
  524. if (phystat0 & B43_RX_PHYST0_OFDM)
  525. status.rate_idx = b43_plcp_get_bitrate_idx_ofdm(plcp,
  526. phytype == B43_PHYTYPE_A);
  527. else
  528. status.rate_idx = b43_plcp_get_bitrate_idx_cck(plcp);
  529. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  530. /*
  531. * All frames on monitor interfaces and beacons always need a full
  532. * 64-bit timestamp. Monitor interfaces need it for diagnostic
  533. * purposes and beacons for IBSS merging.
  534. * This code assumes we get to process the packet within 16 bits
  535. * of timestamp, i.e. about 65 milliseconds after the PHY received
  536. * the first symbol.
  537. */
  538. if (((fctl & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE))
  539. == (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON)) ||
  540. dev->wl->radiotap_enabled) {
  541. u16 low_mactime_now;
  542. b43_tsf_read(dev, &status.mactime);
  543. low_mactime_now = status.mactime;
  544. status.mactime = status.mactime & ~0xFFFFULL;
  545. status.mactime += mactime;
  546. if (low_mactime_now <= mactime)
  547. status.mactime -= 0x10000;
  548. status.flag |= RX_FLAG_TSFT;
  549. }
  550. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  551. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  552. case B43_PHYTYPE_A:
  553. status.band = IEEE80211_BAND_5GHZ;
  554. B43_WARN_ON(1);
  555. /* FIXME: We don't really know which value the "chanid" contains.
  556. * So the following assignment might be wrong. */
  557. status.freq = b43_channel_to_freq_5ghz(chanid);
  558. break;
  559. case B43_PHYTYPE_G:
  560. status.band = IEEE80211_BAND_2GHZ;
  561. /* chanid is the radio channel cookie value as used
  562. * to tune the radio. */
  563. status.freq = chanid + 2400;
  564. break;
  565. case B43_PHYTYPE_N:
  566. /* chanid is the SHM channel cookie. Which is the plain
  567. * channel number in b43. */
  568. if (chanstat & B43_RX_CHAN_5GHZ) {
  569. status.band = IEEE80211_BAND_5GHZ;
  570. status.freq = b43_freq_to_channel_5ghz(chanid);
  571. } else {
  572. status.band = IEEE80211_BAND_2GHZ;
  573. status.freq = b43_freq_to_channel_2ghz(chanid);
  574. }
  575. break;
  576. default:
  577. B43_WARN_ON(1);
  578. goto drop;
  579. }
  580. dev->stats.last_rx = jiffies;
  581. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  582. return;
  583. drop:
  584. b43dbg(dev->wl, "RX: Packet dropped\n");
  585. dev_kfree_skb_any(skb);
  586. }
  587. void b43_handle_txstatus(struct b43_wldev *dev,
  588. const struct b43_txstatus *status)
  589. {
  590. b43_debugfs_log_txstat(dev, status);
  591. if (status->intermediate)
  592. return;
  593. if (status->for_ampdu)
  594. return;
  595. if (!status->acked)
  596. dev->wl->ieee_stats.dot11ACKFailureCount++;
  597. if (status->rts_count) {
  598. if (status->rts_count == 0xF) //FIXME
  599. dev->wl->ieee_stats.dot11RTSFailureCount++;
  600. else
  601. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  602. }
  603. b43_dma_handle_txstatus(dev, status);
  604. }
  605. /* Handle TX status report as received through DMA/PIO queues */
  606. void b43_handle_hwtxstatus(struct b43_wldev *dev,
  607. const struct b43_hwtxstatus *hw)
  608. {
  609. struct b43_txstatus status;
  610. u8 tmp;
  611. status.cookie = le16_to_cpu(hw->cookie);
  612. status.seq = le16_to_cpu(hw->seq);
  613. status.phy_stat = hw->phy_stat;
  614. tmp = hw->count;
  615. status.frame_count = (tmp >> 4);
  616. status.rts_count = (tmp & 0x0F);
  617. tmp = hw->flags;
  618. status.supp_reason = ((tmp & 0x1C) >> 2);
  619. status.pm_indicated = !!(tmp & 0x80);
  620. status.intermediate = !!(tmp & 0x40);
  621. status.for_ampdu = !!(tmp & 0x20);
  622. status.acked = !!(tmp & 0x02);
  623. b43_handle_txstatus(dev, &status);
  624. }
  625. /* Stop any TX operation on the device (suspend the hardware queues) */
  626. void b43_tx_suspend(struct b43_wldev *dev)
  627. {
  628. b43_dma_tx_suspend(dev);
  629. }
  630. /* Resume any TX operation on the device (resume the hardware queues) */
  631. void b43_tx_resume(struct b43_wldev *dev)
  632. {
  633. b43_dma_tx_resume(dev);
  634. }
  635. #if 0
  636. static void upload_qos_parms(struct b43_wldev *dev,
  637. const u16 * parms, u16 offset)
  638. {
  639. int i;
  640. for (i = 0; i < B43_NR_QOSPARMS; i++) {
  641. b43_shm_write16(dev, B43_SHM_SHARED,
  642. offset + (i * 2), parms[i]);
  643. }
  644. }
  645. #endif
  646. /* Initialize the QoS parameters */
  647. void b43_qos_init(struct b43_wldev *dev)
  648. {
  649. /* FIXME: This function must probably be called from the mac80211
  650. * config callback. */
  651. return;
  652. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  653. //FIXME kill magic
  654. b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
  655. /*TODO: We might need some stack support here to get the values. */
  656. }