xmit.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 out of a CCK PLCP header. */
  26. static u8 b43_plcp_get_bitrate_cck(struct b43_plcp_hdr6 *plcp)
  27. {
  28. switch (plcp->raw[0]) {
  29. case 0x0A:
  30. return B43_CCK_RATE_1MB;
  31. case 0x14:
  32. return B43_CCK_RATE_2MB;
  33. case 0x37:
  34. return B43_CCK_RATE_5MB;
  35. case 0x6E:
  36. return B43_CCK_RATE_11MB;
  37. }
  38. B43_WARN_ON(1);
  39. return 0;
  40. }
  41. /* Extract the bitrate out of an OFDM PLCP header. */
  42. static u8 b43_plcp_get_bitrate_ofdm(struct b43_plcp_hdr6 *plcp)
  43. {
  44. switch (plcp->raw[0] & 0xF) {
  45. case 0xB:
  46. return B43_OFDM_RATE_6MB;
  47. case 0xF:
  48. return B43_OFDM_RATE_9MB;
  49. case 0xA:
  50. return B43_OFDM_RATE_12MB;
  51. case 0xE:
  52. return B43_OFDM_RATE_18MB;
  53. case 0x9:
  54. return B43_OFDM_RATE_24MB;
  55. case 0xD:
  56. return B43_OFDM_RATE_36MB;
  57. case 0x8:
  58. return B43_OFDM_RATE_48MB;
  59. case 0xC:
  60. return B43_OFDM_RATE_54MB;
  61. }
  62. B43_WARN_ON(1);
  63. return 0;
  64. }
  65. u8 b43_plcp_get_ratecode_cck(const u8 bitrate)
  66. {
  67. switch (bitrate) {
  68. case B43_CCK_RATE_1MB:
  69. return 0x0A;
  70. case B43_CCK_RATE_2MB:
  71. return 0x14;
  72. case B43_CCK_RATE_5MB:
  73. return 0x37;
  74. case B43_CCK_RATE_11MB:
  75. return 0x6E;
  76. }
  77. B43_WARN_ON(1);
  78. return 0;
  79. }
  80. u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
  81. {
  82. switch (bitrate) {
  83. case B43_OFDM_RATE_6MB:
  84. return 0xB;
  85. case B43_OFDM_RATE_9MB:
  86. return 0xF;
  87. case B43_OFDM_RATE_12MB:
  88. return 0xA;
  89. case B43_OFDM_RATE_18MB:
  90. return 0xE;
  91. case B43_OFDM_RATE_24MB:
  92. return 0x9;
  93. case B43_OFDM_RATE_36MB:
  94. return 0xD;
  95. case B43_OFDM_RATE_48MB:
  96. return 0x8;
  97. case B43_OFDM_RATE_54MB:
  98. return 0xC;
  99. }
  100. B43_WARN_ON(1);
  101. return 0;
  102. }
  103. void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
  104. const u16 octets, const u8 bitrate)
  105. {
  106. __le32 *data = &(plcp->data);
  107. __u8 *raw = plcp->raw;
  108. if (b43_is_ofdm_rate(bitrate)) {
  109. u32 d;
  110. d = b43_plcp_get_ratecode_ofdm(bitrate);
  111. B43_WARN_ON(octets & 0xF000);
  112. d |= (octets << 5);
  113. *data = cpu_to_le32(d);
  114. } else {
  115. u32 plen;
  116. plen = octets * 16 / bitrate;
  117. if ((octets * 16 % bitrate) > 0) {
  118. plen++;
  119. if ((bitrate == B43_CCK_RATE_11MB)
  120. && ((octets * 8 % 11) < 4)) {
  121. raw[1] = 0x84;
  122. } else
  123. raw[1] = 0x04;
  124. } else
  125. raw[1] = 0x04;
  126. *data |= cpu_to_le32(plen << 16);
  127. raw[0] = b43_plcp_get_ratecode_cck(bitrate);
  128. }
  129. }
  130. static u8 b43_calc_fallback_rate(u8 bitrate)
  131. {
  132. switch (bitrate) {
  133. case B43_CCK_RATE_1MB:
  134. return B43_CCK_RATE_1MB;
  135. case B43_CCK_RATE_2MB:
  136. return B43_CCK_RATE_1MB;
  137. case B43_CCK_RATE_5MB:
  138. return B43_CCK_RATE_2MB;
  139. case B43_CCK_RATE_11MB:
  140. return B43_CCK_RATE_5MB;
  141. case B43_OFDM_RATE_6MB:
  142. return B43_CCK_RATE_5MB;
  143. case B43_OFDM_RATE_9MB:
  144. return B43_OFDM_RATE_6MB;
  145. case B43_OFDM_RATE_12MB:
  146. return B43_OFDM_RATE_9MB;
  147. case B43_OFDM_RATE_18MB:
  148. return B43_OFDM_RATE_12MB;
  149. case B43_OFDM_RATE_24MB:
  150. return B43_OFDM_RATE_18MB;
  151. case B43_OFDM_RATE_36MB:
  152. return B43_OFDM_RATE_24MB;
  153. case B43_OFDM_RATE_48MB:
  154. return B43_OFDM_RATE_36MB;
  155. case B43_OFDM_RATE_54MB:
  156. return B43_OFDM_RATE_48MB;
  157. }
  158. B43_WARN_ON(1);
  159. return 0;
  160. }
  161. /* Generate a TX data header. */
  162. int b43_generate_txhdr(struct b43_wldev *dev,
  163. u8 *_txhdr,
  164. const unsigned char *fragment_data,
  165. unsigned int fragment_len,
  166. const struct ieee80211_tx_control *txctl,
  167. u16 cookie)
  168. {
  169. struct b43_txhdr *txhdr = (struct b43_txhdr *)_txhdr;
  170. const struct b43_phy *phy = &dev->phy;
  171. const struct ieee80211_hdr *wlhdr =
  172. (const struct ieee80211_hdr *)fragment_data;
  173. int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
  174. u16 fctl = le16_to_cpu(wlhdr->frame_control);
  175. u8 rate, rate_fb;
  176. int rate_ofdm, rate_fb_ofdm;
  177. unsigned int plcp_fragment_len;
  178. u32 mac_ctl = 0;
  179. u16 phy_ctl = 0;
  180. u8 extra_ft = 0;
  181. memset(txhdr, 0, sizeof(*txhdr));
  182. rate = txctl->tx_rate;
  183. rate_ofdm = b43_is_ofdm_rate(rate);
  184. rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate;
  185. rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
  186. if (rate_ofdm)
  187. txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
  188. else
  189. txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
  190. txhdr->mac_frame_ctl = wlhdr->frame_control;
  191. memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
  192. /* Calculate duration for fallback rate */
  193. if ((rate_fb == rate) ||
  194. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  195. (wlhdr->duration_id == cpu_to_le16(0))) {
  196. /* If the fallback rate equals the normal rate or the
  197. * dur_id field contains an AID, CFP magic or 0,
  198. * use the original dur_id field. */
  199. txhdr->dur_fb = wlhdr->duration_id;
  200. } else {
  201. int fbrate_base100kbps = B43_RATE_TO_BASE100KBPS(rate_fb);
  202. txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
  203. txctl->vif,
  204. fragment_len,
  205. fbrate_base100kbps);
  206. }
  207. plcp_fragment_len = fragment_len + FCS_LEN;
  208. if (use_encryption) {
  209. u8 key_idx = (u16) (txctl->key_idx);
  210. struct b43_key *key;
  211. int wlhdr_len;
  212. size_t iv_len;
  213. B43_WARN_ON(key_idx >= dev->max_nr_keys);
  214. key = &(dev->key[key_idx]);
  215. if (unlikely(!key->keyconf)) {
  216. /* This key is invalid. This might only happen
  217. * in a short timeframe after machine resume before
  218. * we were able to reconfigure keys.
  219. * Drop this packet completely. Do not transmit it
  220. * unencrypted to avoid leaking information. */
  221. return -ENOKEY;
  222. }
  223. /* Hardware appends ICV. */
  224. plcp_fragment_len += txctl->icv_len;
  225. key_idx = b43_kidx_to_fw(dev, key_idx);
  226. mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
  227. B43_TXH_MAC_KEYIDX;
  228. mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
  229. B43_TXH_MAC_KEYALG;
  230. wlhdr_len = ieee80211_get_hdrlen(fctl);
  231. iv_len = min((size_t) txctl->iv_len,
  232. ARRAY_SIZE(txhdr->iv));
  233. memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
  234. }
  235. if (b43_is_old_txhdr_format(dev)) {
  236. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
  237. plcp_fragment_len, rate);
  238. } else {
  239. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
  240. plcp_fragment_len, rate);
  241. }
  242. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
  243. plcp_fragment_len, rate_fb);
  244. /* Extra Frame Types */
  245. if (rate_fb_ofdm)
  246. extra_ft |= B43_TXH_EFT_FB_OFDM;
  247. else
  248. extra_ft |= B43_TXH_EFT_FB_CCK;
  249. /* Set channel radio code. Note that the micrcode ORs 0x100 to
  250. * this value before comparing it to the value in SHM, if this
  251. * is a 5Ghz packet.
  252. */
  253. txhdr->chan_radio_code = phy->channel;
  254. /* PHY TX Control word */
  255. if (rate_ofdm)
  256. phy_ctl |= B43_TXH_PHY_ENC_OFDM;
  257. else
  258. phy_ctl |= B43_TXH_PHY_ENC_CCK;
  259. if (dev->short_preamble)
  260. phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
  261. switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) {
  262. case 0: /* Default */
  263. phy_ctl |= B43_TXH_PHY_ANT01AUTO;
  264. break;
  265. case 1: /* Antenna 0 */
  266. phy_ctl |= B43_TXH_PHY_ANT0;
  267. break;
  268. case 2: /* Antenna 1 */
  269. phy_ctl |= B43_TXH_PHY_ANT1;
  270. break;
  271. case 3: /* Antenna 2 */
  272. phy_ctl |= B43_TXH_PHY_ANT2;
  273. break;
  274. case 4: /* Antenna 3 */
  275. phy_ctl |= B43_TXH_PHY_ANT3;
  276. break;
  277. default:
  278. B43_WARN_ON(1);
  279. }
  280. /* MAC control */
  281. if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
  282. mac_ctl |= B43_TXH_MAC_ACK;
  283. if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  284. ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
  285. mac_ctl |= B43_TXH_MAC_HWSEQ;
  286. if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
  287. mac_ctl |= B43_TXH_MAC_STMSDU;
  288. if (phy->type == B43_PHYTYPE_A)
  289. mac_ctl |= B43_TXH_MAC_5GHZ;
  290. if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
  291. mac_ctl |= B43_TXH_MAC_LONGFRAME;
  292. /* Generate the RTS or CTS-to-self frame */
  293. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  294. (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
  295. unsigned int len;
  296. struct ieee80211_hdr *hdr;
  297. int rts_rate, rts_rate_fb;
  298. int rts_rate_ofdm, rts_rate_fb_ofdm;
  299. struct b43_plcp_hdr6 *plcp;
  300. rts_rate = txctl->rts_cts_rate;
  301. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  302. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  303. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  304. if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  305. struct ieee80211_cts *cts;
  306. if (b43_is_old_txhdr_format(dev)) {
  307. cts = (struct ieee80211_cts *)
  308. (txhdr->old_format.rts_frame);
  309. } else {
  310. cts = (struct ieee80211_cts *)
  311. (txhdr->new_format.rts_frame);
  312. }
  313. ieee80211_ctstoself_get(dev->wl->hw, txctl->vif,
  314. fragment_data, fragment_len,
  315. txctl, cts);
  316. mac_ctl |= B43_TXH_MAC_SENDCTS;
  317. len = sizeof(struct ieee80211_cts);
  318. } else {
  319. struct ieee80211_rts *rts;
  320. if (b43_is_old_txhdr_format(dev)) {
  321. rts = (struct ieee80211_rts *)
  322. (txhdr->old_format.rts_frame);
  323. } else {
  324. rts = (struct ieee80211_rts *)
  325. (txhdr->new_format.rts_frame);
  326. }
  327. ieee80211_rts_get(dev->wl->hw, txctl->vif,
  328. fragment_data, fragment_len,
  329. txctl, rts);
  330. mac_ctl |= B43_TXH_MAC_SENDRTS;
  331. len = sizeof(struct ieee80211_rts);
  332. }
  333. len += FCS_LEN;
  334. /* Generate the PLCP headers for the RTS/CTS frame */
  335. if (b43_is_old_txhdr_format(dev))
  336. plcp = &txhdr->old_format.rts_plcp;
  337. else
  338. plcp = &txhdr->new_format.rts_plcp;
  339. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  340. len, rts_rate);
  341. plcp = &txhdr->rts_plcp_fb;
  342. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  343. len, rts_rate_fb);
  344. if (b43_is_old_txhdr_format(dev)) {
  345. hdr = (struct ieee80211_hdr *)
  346. (&txhdr->old_format.rts_frame);
  347. } else {
  348. hdr = (struct ieee80211_hdr *)
  349. (&txhdr->new_format.rts_frame);
  350. }
  351. txhdr->rts_dur_fb = hdr->duration_id;
  352. if (rts_rate_ofdm) {
  353. extra_ft |= B43_TXH_EFT_RTS_OFDM;
  354. txhdr->phy_rate_rts =
  355. b43_plcp_get_ratecode_ofdm(rts_rate);
  356. } else {
  357. extra_ft |= B43_TXH_EFT_RTS_CCK;
  358. txhdr->phy_rate_rts =
  359. b43_plcp_get_ratecode_cck(rts_rate);
  360. }
  361. if (rts_rate_fb_ofdm)
  362. extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
  363. else
  364. extra_ft |= B43_TXH_EFT_RTSFB_CCK;
  365. }
  366. /* Magic cookie */
  367. if (b43_is_old_txhdr_format(dev))
  368. txhdr->old_format.cookie = cpu_to_le16(cookie);
  369. else
  370. txhdr->new_format.cookie = cpu_to_le16(cookie);
  371. /* Apply the bitfields */
  372. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  373. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  374. txhdr->extra_ft = extra_ft;
  375. return 0;
  376. }
  377. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  378. u8 in_rssi, int ofdm,
  379. int adjust_2053, int adjust_2050)
  380. {
  381. struct b43_phy *phy = &dev->phy;
  382. s32 tmp;
  383. switch (phy->radio_ver) {
  384. case 0x2050:
  385. if (ofdm) {
  386. tmp = in_rssi;
  387. if (tmp > 127)
  388. tmp -= 256;
  389. tmp *= 73;
  390. tmp /= 64;
  391. if (adjust_2050)
  392. tmp += 25;
  393. else
  394. tmp -= 3;
  395. } else {
  396. if (dev->dev->bus->sprom.
  397. boardflags_lo & B43_BFL_RSSI) {
  398. if (in_rssi > 63)
  399. in_rssi = 63;
  400. tmp = phy->nrssi_lt[in_rssi];
  401. tmp = 31 - tmp;
  402. tmp *= -131;
  403. tmp /= 128;
  404. tmp -= 57;
  405. } else {
  406. tmp = in_rssi;
  407. tmp = 31 - tmp;
  408. tmp *= -149;
  409. tmp /= 128;
  410. tmp -= 68;
  411. }
  412. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  413. tmp += 25;
  414. }
  415. break;
  416. case 0x2060:
  417. if (in_rssi > 127)
  418. tmp = in_rssi - 256;
  419. else
  420. tmp = in_rssi;
  421. break;
  422. default:
  423. tmp = in_rssi;
  424. tmp -= 11;
  425. tmp *= 103;
  426. tmp /= 64;
  427. if (adjust_2053)
  428. tmp -= 109;
  429. else
  430. tmp -= 83;
  431. }
  432. return (s8) tmp;
  433. }
  434. //TODO
  435. #if 0
  436. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  437. {
  438. struct b43_phy *phy = &dev->phy;
  439. s8 ret;
  440. if (phy->type == B43_PHYTYPE_A) {
  441. //TODO: Incomplete specs.
  442. ret = 0;
  443. } else
  444. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  445. return ret;
  446. }
  447. #endif
  448. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  449. {
  450. struct ieee80211_rx_status status;
  451. struct b43_plcp_hdr6 *plcp;
  452. struct ieee80211_hdr *wlhdr;
  453. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  454. u16 fctl;
  455. u16 phystat0, phystat3, chanstat, mactime;
  456. u32 macstat;
  457. u16 chanid;
  458. u8 jssi;
  459. int padding;
  460. memset(&status, 0, sizeof(status));
  461. /* Get metadata about the frame from the header. */
  462. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  463. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  464. jssi = rxhdr->jssi;
  465. macstat = le32_to_cpu(rxhdr->mac_status);
  466. mactime = le16_to_cpu(rxhdr->mac_time);
  467. chanstat = le16_to_cpu(rxhdr->channel);
  468. if (macstat & B43_RX_MAC_FCSERR)
  469. dev->wl->ieee_stats.dot11FCSErrorCount++;
  470. if (macstat & B43_RX_MAC_DECERR) {
  471. /* Decryption with the given key failed.
  472. * Drop the packet. We also won't be able to decrypt it with
  473. * the key in software. */
  474. goto drop;
  475. }
  476. /* Skip PLCP and padding */
  477. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  478. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  479. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  480. goto drop;
  481. }
  482. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  483. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  484. /* The skb contains the Wireless Header + payload data now */
  485. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  486. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  487. goto drop;
  488. }
  489. wlhdr = (struct ieee80211_hdr *)(skb->data);
  490. fctl = le16_to_cpu(wlhdr->frame_control);
  491. if (macstat & B43_RX_MAC_DEC) {
  492. unsigned int keyidx;
  493. int wlhdr_len;
  494. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  495. >> B43_RX_MAC_KEYIDX_SHIFT);
  496. /* We must adjust the key index here. We want the "physical"
  497. * key index, but the ucode passed it slightly different.
  498. */
  499. keyidx = b43_kidx_to_raw(dev, keyidx);
  500. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  501. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  502. wlhdr_len = ieee80211_get_hdrlen(fctl);
  503. if (unlikely(skb->len < (wlhdr_len + 3))) {
  504. b43dbg(dev->wl,
  505. "RX: Packet size underrun (3)\n");
  506. goto drop;
  507. }
  508. status.flag |= RX_FLAG_DECRYPTED;
  509. }
  510. }
  511. status.ssi = b43_rssi_postprocess(dev, jssi,
  512. (phystat0 & B43_RX_PHYST0_OFDM),
  513. (phystat0 & B43_RX_PHYST0_GAINCTL),
  514. (phystat3 & B43_RX_PHYST3_TRSTATE));
  515. status.noise = dev->stats.link_noise;
  516. /* the next line looks wrong, but is what mac80211 wants */
  517. status.signal = (jssi * 100) / B43_RX_MAX_SSI;
  518. if (phystat0 & B43_RX_PHYST0_OFDM)
  519. status.rate = b43_plcp_get_bitrate_ofdm(plcp);
  520. else
  521. status.rate = b43_plcp_get_bitrate_cck(plcp);
  522. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  523. /*
  524. * If monitors are present get full 64-bit timestamp. This
  525. * code assumes we get to process the packet within 16 bits
  526. * of timestamp, i.e. about 65 milliseconds after the PHY
  527. * received the first symbol.
  528. */
  529. if (dev->wl->radiotap_enabled) {
  530. u16 low_mactime_now;
  531. b43_tsf_read(dev, &status.mactime);
  532. low_mactime_now = status.mactime;
  533. status.mactime = status.mactime & ~0xFFFFULL;
  534. status.mactime += mactime;
  535. if (low_mactime_now <= mactime)
  536. status.mactime -= 0x10000;
  537. status.flag |= RX_FLAG_TSFT;
  538. }
  539. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  540. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  541. case B43_PHYTYPE_A:
  542. status.phymode = MODE_IEEE80211A;
  543. B43_WARN_ON(1);
  544. /* FIXME: We don't really know which value the "chanid" contains.
  545. * So the following assignment might be wrong. */
  546. status.channel = chanid;
  547. status.freq = b43_channel_to_freq_5ghz(status.channel);
  548. break;
  549. case B43_PHYTYPE_G:
  550. status.phymode = MODE_IEEE80211G;
  551. /* chanid is the radio channel cookie value as used
  552. * to tune the radio. */
  553. status.freq = chanid + 2400;
  554. status.channel = b43_freq_to_channel_2ghz(status.freq);
  555. break;
  556. case B43_PHYTYPE_N:
  557. status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
  558. /* chanid is the SHM channel cookie. Which is the plain
  559. * channel number in b43. */
  560. status.channel = chanid;
  561. if (chanstat & B43_RX_CHAN_5GHZ)
  562. status.freq = b43_freq_to_channel_5ghz(status.freq);
  563. else
  564. status.freq = b43_freq_to_channel_2ghz(status.freq);
  565. break;
  566. default:
  567. B43_WARN_ON(1);
  568. goto drop;
  569. }
  570. dev->stats.last_rx = jiffies;
  571. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  572. return;
  573. drop:
  574. b43dbg(dev->wl, "RX: Packet dropped\n");
  575. dev_kfree_skb_any(skb);
  576. }
  577. void b43_handle_txstatus(struct b43_wldev *dev,
  578. const struct b43_txstatus *status)
  579. {
  580. b43_debugfs_log_txstat(dev, status);
  581. if (status->intermediate)
  582. return;
  583. if (status->for_ampdu)
  584. return;
  585. if (!status->acked)
  586. dev->wl->ieee_stats.dot11ACKFailureCount++;
  587. if (status->rts_count) {
  588. if (status->rts_count == 0xF) //FIXME
  589. dev->wl->ieee_stats.dot11RTSFailureCount++;
  590. else
  591. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  592. }
  593. b43_dma_handle_txstatus(dev, status);
  594. }
  595. /* Handle TX status report as received through DMA/PIO queues */
  596. void b43_handle_hwtxstatus(struct b43_wldev *dev,
  597. const struct b43_hwtxstatus *hw)
  598. {
  599. struct b43_txstatus status;
  600. u8 tmp;
  601. status.cookie = le16_to_cpu(hw->cookie);
  602. status.seq = le16_to_cpu(hw->seq);
  603. status.phy_stat = hw->phy_stat;
  604. tmp = hw->count;
  605. status.frame_count = (tmp >> 4);
  606. status.rts_count = (tmp & 0x0F);
  607. tmp = hw->flags;
  608. status.supp_reason = ((tmp & 0x1C) >> 2);
  609. status.pm_indicated = !!(tmp & 0x80);
  610. status.intermediate = !!(tmp & 0x40);
  611. status.for_ampdu = !!(tmp & 0x20);
  612. status.acked = !!(tmp & 0x02);
  613. b43_handle_txstatus(dev, &status);
  614. }
  615. /* Stop any TX operation on the device (suspend the hardware queues) */
  616. void b43_tx_suspend(struct b43_wldev *dev)
  617. {
  618. b43_dma_tx_suspend(dev);
  619. }
  620. /* Resume any TX operation on the device (resume the hardware queues) */
  621. void b43_tx_resume(struct b43_wldev *dev)
  622. {
  623. b43_dma_tx_resume(dev);
  624. }
  625. #if 0
  626. static void upload_qos_parms(struct b43_wldev *dev,
  627. const u16 * parms, u16 offset)
  628. {
  629. int i;
  630. for (i = 0; i < B43_NR_QOSPARMS; i++) {
  631. b43_shm_write16(dev, B43_SHM_SHARED,
  632. offset + (i * 2), parms[i]);
  633. }
  634. }
  635. #endif
  636. /* Initialize the QoS parameters */
  637. void b43_qos_init(struct b43_wldev *dev)
  638. {
  639. /* FIXME: This function must probably be called from the mac80211
  640. * config callback. */
  641. return;
  642. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  643. //FIXME kill magic
  644. b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
  645. /*TODO: We might need some stack support here to get the values. */
  646. }