xmit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. void 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. B43_WARN_ON(!key->keyconf);
  216. /* Hardware appends ICV. */
  217. plcp_fragment_len += txctl->icv_len;
  218. key_idx = b43_kidx_to_fw(dev, key_idx);
  219. mac_ctl |= (key_idx << B43_TXH_MAC_KEYIDX_SHIFT) &
  220. B43_TXH_MAC_KEYIDX;
  221. mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) &
  222. B43_TXH_MAC_KEYALG;
  223. wlhdr_len = ieee80211_get_hdrlen(fctl);
  224. iv_len = min((size_t) txctl->iv_len,
  225. ARRAY_SIZE(txhdr->iv));
  226. memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
  227. }
  228. if (b43_is_old_txhdr_format(dev)) {
  229. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->old_format.plcp),
  230. plcp_fragment_len, rate);
  231. } else {
  232. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->new_format.plcp),
  233. plcp_fragment_len, rate);
  234. }
  235. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
  236. plcp_fragment_len, rate_fb);
  237. /* Extra Frame Types */
  238. if (rate_fb_ofdm)
  239. extra_ft |= B43_TXH_EFT_FB_OFDM;
  240. else
  241. extra_ft |= B43_TXH_EFT_FB_CCK;
  242. /* Set channel radio code. Note that the micrcode ORs 0x100 to
  243. * this value before comparing it to the value in SHM, if this
  244. * is a 5Ghz packet.
  245. */
  246. txhdr->chan_radio_code = phy->channel;
  247. /* PHY TX Control word */
  248. if (rate_ofdm)
  249. phy_ctl |= B43_TXH_PHY_ENC_OFDM;
  250. else
  251. phy_ctl |= B43_TXH_PHY_ENC_CCK;
  252. if (dev->short_preamble)
  253. phy_ctl |= B43_TXH_PHY_SHORTPRMBL;
  254. switch (b43_ieee80211_antenna_sanitize(dev, txctl->antenna_sel_tx)) {
  255. case 0: /* Default */
  256. phy_ctl |= B43_TXH_PHY_ANT01AUTO;
  257. break;
  258. case 1: /* Antenna 0 */
  259. phy_ctl |= B43_TXH_PHY_ANT0;
  260. break;
  261. case 2: /* Antenna 1 */
  262. phy_ctl |= B43_TXH_PHY_ANT1;
  263. break;
  264. case 3: /* Antenna 2 */
  265. phy_ctl |= B43_TXH_PHY_ANT2;
  266. break;
  267. case 4: /* Antenna 3 */
  268. phy_ctl |= B43_TXH_PHY_ANT3;
  269. break;
  270. default:
  271. B43_WARN_ON(1);
  272. }
  273. /* MAC control */
  274. if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
  275. mac_ctl |= B43_TXH_MAC_ACK;
  276. if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  277. ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
  278. mac_ctl |= B43_TXH_MAC_HWSEQ;
  279. if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
  280. mac_ctl |= B43_TXH_MAC_STMSDU;
  281. if (phy->type == B43_PHYTYPE_A)
  282. mac_ctl |= B43_TXH_MAC_5GHZ;
  283. if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
  284. mac_ctl |= B43_TXH_MAC_LONGFRAME;
  285. /* Generate the RTS or CTS-to-self frame */
  286. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  287. (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
  288. unsigned int len;
  289. struct ieee80211_hdr *hdr;
  290. int rts_rate, rts_rate_fb;
  291. int rts_rate_ofdm, rts_rate_fb_ofdm;
  292. struct b43_plcp_hdr6 *plcp;
  293. rts_rate = txctl->rts_cts_rate;
  294. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  295. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  296. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  297. if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  298. struct ieee80211_cts *cts;
  299. if (b43_is_old_txhdr_format(dev)) {
  300. cts = (struct ieee80211_cts *)
  301. (txhdr->old_format.rts_frame);
  302. } else {
  303. cts = (struct ieee80211_cts *)
  304. (txhdr->new_format.rts_frame);
  305. }
  306. ieee80211_ctstoself_get(dev->wl->hw, txctl->vif,
  307. fragment_data, fragment_len,
  308. txctl, cts);
  309. mac_ctl |= B43_TXH_MAC_SENDCTS;
  310. len = sizeof(struct ieee80211_cts);
  311. } else {
  312. struct ieee80211_rts *rts;
  313. if (b43_is_old_txhdr_format(dev)) {
  314. rts = (struct ieee80211_rts *)
  315. (txhdr->old_format.rts_frame);
  316. } else {
  317. rts = (struct ieee80211_rts *)
  318. (txhdr->new_format.rts_frame);
  319. }
  320. ieee80211_rts_get(dev->wl->hw, txctl->vif,
  321. fragment_data, fragment_len,
  322. txctl, rts);
  323. mac_ctl |= B43_TXH_MAC_SENDRTS;
  324. len = sizeof(struct ieee80211_rts);
  325. }
  326. len += FCS_LEN;
  327. /* Generate the PLCP headers for the RTS/CTS frame */
  328. if (b43_is_old_txhdr_format(dev))
  329. plcp = &txhdr->old_format.rts_plcp;
  330. else
  331. plcp = &txhdr->new_format.rts_plcp;
  332. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  333. len, rts_rate);
  334. plcp = &txhdr->rts_plcp_fb;
  335. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)plcp,
  336. len, rts_rate_fb);
  337. if (b43_is_old_txhdr_format(dev)) {
  338. hdr = (struct ieee80211_hdr *)
  339. (&txhdr->old_format.rts_frame);
  340. } else {
  341. hdr = (struct ieee80211_hdr *)
  342. (&txhdr->new_format.rts_frame);
  343. }
  344. txhdr->rts_dur_fb = hdr->duration_id;
  345. if (rts_rate_ofdm) {
  346. extra_ft |= B43_TXH_EFT_RTS_OFDM;
  347. txhdr->phy_rate_rts =
  348. b43_plcp_get_ratecode_ofdm(rts_rate);
  349. } else {
  350. extra_ft |= B43_TXH_EFT_RTS_CCK;
  351. txhdr->phy_rate_rts =
  352. b43_plcp_get_ratecode_cck(rts_rate);
  353. }
  354. if (rts_rate_fb_ofdm)
  355. extra_ft |= B43_TXH_EFT_RTSFB_OFDM;
  356. else
  357. extra_ft |= B43_TXH_EFT_RTSFB_CCK;
  358. }
  359. /* Magic cookie */
  360. if (b43_is_old_txhdr_format(dev))
  361. txhdr->old_format.cookie = cpu_to_le16(cookie);
  362. else
  363. txhdr->new_format.cookie = cpu_to_le16(cookie);
  364. /* Apply the bitfields */
  365. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  366. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  367. txhdr->extra_ft = extra_ft;
  368. }
  369. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  370. u8 in_rssi, int ofdm,
  371. int adjust_2053, int adjust_2050)
  372. {
  373. struct b43_phy *phy = &dev->phy;
  374. s32 tmp;
  375. switch (phy->radio_ver) {
  376. case 0x2050:
  377. if (ofdm) {
  378. tmp = in_rssi;
  379. if (tmp > 127)
  380. tmp -= 256;
  381. tmp *= 73;
  382. tmp /= 64;
  383. if (adjust_2050)
  384. tmp += 25;
  385. else
  386. tmp -= 3;
  387. } else {
  388. if (dev->dev->bus->sprom.
  389. boardflags_lo & B43_BFL_RSSI) {
  390. if (in_rssi > 63)
  391. in_rssi = 63;
  392. tmp = phy->nrssi_lt[in_rssi];
  393. tmp = 31 - tmp;
  394. tmp *= -131;
  395. tmp /= 128;
  396. tmp -= 57;
  397. } else {
  398. tmp = in_rssi;
  399. tmp = 31 - tmp;
  400. tmp *= -149;
  401. tmp /= 128;
  402. tmp -= 68;
  403. }
  404. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  405. tmp += 25;
  406. }
  407. break;
  408. case 0x2060:
  409. if (in_rssi > 127)
  410. tmp = in_rssi - 256;
  411. else
  412. tmp = in_rssi;
  413. break;
  414. default:
  415. tmp = in_rssi;
  416. tmp -= 11;
  417. tmp *= 103;
  418. tmp /= 64;
  419. if (adjust_2053)
  420. tmp -= 109;
  421. else
  422. tmp -= 83;
  423. }
  424. return (s8) tmp;
  425. }
  426. //TODO
  427. #if 0
  428. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  429. {
  430. struct b43_phy *phy = &dev->phy;
  431. s8 ret;
  432. if (phy->type == B43_PHYTYPE_A) {
  433. //TODO: Incomplete specs.
  434. ret = 0;
  435. } else
  436. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  437. return ret;
  438. }
  439. #endif
  440. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  441. {
  442. struct ieee80211_rx_status status;
  443. struct b43_plcp_hdr6 *plcp;
  444. struct ieee80211_hdr *wlhdr;
  445. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  446. u16 fctl;
  447. u16 phystat0, phystat3, chanstat, mactime;
  448. u32 macstat;
  449. u16 chanid;
  450. u8 jssi;
  451. int padding;
  452. memset(&status, 0, sizeof(status));
  453. /* Get metadata about the frame from the header. */
  454. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  455. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  456. jssi = rxhdr->jssi;
  457. macstat = le32_to_cpu(rxhdr->mac_status);
  458. mactime = le16_to_cpu(rxhdr->mac_time);
  459. chanstat = le16_to_cpu(rxhdr->channel);
  460. if (macstat & B43_RX_MAC_FCSERR)
  461. dev->wl->ieee_stats.dot11FCSErrorCount++;
  462. if (macstat & B43_RX_MAC_DECERR) {
  463. /* Decryption with the given key failed.
  464. * Drop the packet. We also won't be able to decrypt it with
  465. * the key in software. */
  466. goto drop;
  467. }
  468. /* Skip PLCP and padding */
  469. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  470. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  471. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  472. goto drop;
  473. }
  474. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  475. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  476. /* The skb contains the Wireless Header + payload data now */
  477. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  478. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  479. goto drop;
  480. }
  481. wlhdr = (struct ieee80211_hdr *)(skb->data);
  482. fctl = le16_to_cpu(wlhdr->frame_control);
  483. if (macstat & B43_RX_MAC_DEC) {
  484. unsigned int keyidx;
  485. int wlhdr_len;
  486. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  487. >> B43_RX_MAC_KEYIDX_SHIFT);
  488. /* We must adjust the key index here. We want the "physical"
  489. * key index, but the ucode passed it slightly different.
  490. */
  491. keyidx = b43_kidx_to_raw(dev, keyidx);
  492. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  493. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  494. wlhdr_len = ieee80211_get_hdrlen(fctl);
  495. if (unlikely(skb->len < (wlhdr_len + 3))) {
  496. b43dbg(dev->wl,
  497. "RX: Packet size underrun (3)\n");
  498. goto drop;
  499. }
  500. status.flag |= RX_FLAG_DECRYPTED;
  501. }
  502. }
  503. status.ssi = b43_rssi_postprocess(dev, jssi,
  504. (phystat0 & B43_RX_PHYST0_OFDM),
  505. (phystat0 & B43_RX_PHYST0_GAINCTL),
  506. (phystat3 & B43_RX_PHYST3_TRSTATE));
  507. status.noise = dev->stats.link_noise;
  508. /* the next line looks wrong, but is what mac80211 wants */
  509. status.signal = (jssi * 100) / B43_RX_MAX_SSI;
  510. if (phystat0 & B43_RX_PHYST0_OFDM)
  511. status.rate = b43_plcp_get_bitrate_ofdm(plcp);
  512. else
  513. status.rate = b43_plcp_get_bitrate_cck(plcp);
  514. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  515. /*
  516. * If monitors are present get full 64-bit timestamp. This
  517. * code assumes we get to process the packet within 16 bits
  518. * of timestamp, i.e. about 65 milliseconds after the PHY
  519. * received the first symbol.
  520. */
  521. if (dev->wl->radiotap_enabled) {
  522. u16 low_mactime_now;
  523. b43_tsf_read(dev, &status.mactime);
  524. low_mactime_now = status.mactime;
  525. status.mactime = status.mactime & ~0xFFFFULL;
  526. status.mactime += mactime;
  527. if (low_mactime_now <= mactime)
  528. status.mactime -= 0x10000;
  529. status.flag |= RX_FLAG_TSFT;
  530. }
  531. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  532. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  533. case B43_PHYTYPE_A:
  534. status.phymode = MODE_IEEE80211A;
  535. B43_WARN_ON(1);
  536. /* FIXME: We don't really know which value the "chanid" contains.
  537. * So the following assignment might be wrong. */
  538. status.channel = chanid;
  539. status.freq = b43_channel_to_freq_5ghz(status.channel);
  540. break;
  541. case B43_PHYTYPE_G:
  542. status.phymode = MODE_IEEE80211G;
  543. /* chanid is the radio channel cookie value as used
  544. * to tune the radio. */
  545. status.freq = chanid + 2400;
  546. status.channel = b43_freq_to_channel_2ghz(status.freq);
  547. break;
  548. case B43_PHYTYPE_N:
  549. status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
  550. /* chanid is the SHM channel cookie. Which is the plain
  551. * channel number in b43. */
  552. status.channel = chanid;
  553. if (chanstat & B43_RX_CHAN_5GHZ)
  554. status.freq = b43_freq_to_channel_5ghz(status.freq);
  555. else
  556. status.freq = b43_freq_to_channel_2ghz(status.freq);
  557. break;
  558. default:
  559. B43_WARN_ON(1);
  560. goto drop;
  561. }
  562. dev->stats.last_rx = jiffies;
  563. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  564. return;
  565. drop:
  566. b43dbg(dev->wl, "RX: Packet dropped\n");
  567. dev_kfree_skb_any(skb);
  568. }
  569. void b43_handle_txstatus(struct b43_wldev *dev,
  570. const struct b43_txstatus *status)
  571. {
  572. b43_debugfs_log_txstat(dev, status);
  573. if (status->intermediate)
  574. return;
  575. if (status->for_ampdu)
  576. return;
  577. if (!status->acked)
  578. dev->wl->ieee_stats.dot11ACKFailureCount++;
  579. if (status->rts_count) {
  580. if (status->rts_count == 0xF) //FIXME
  581. dev->wl->ieee_stats.dot11RTSFailureCount++;
  582. else
  583. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  584. }
  585. b43_dma_handle_txstatus(dev, status);
  586. }
  587. /* Handle TX status report as received through DMA/PIO queues */
  588. void b43_handle_hwtxstatus(struct b43_wldev *dev,
  589. const struct b43_hwtxstatus *hw)
  590. {
  591. struct b43_txstatus status;
  592. u8 tmp;
  593. status.cookie = le16_to_cpu(hw->cookie);
  594. status.seq = le16_to_cpu(hw->seq);
  595. status.phy_stat = hw->phy_stat;
  596. tmp = hw->count;
  597. status.frame_count = (tmp >> 4);
  598. status.rts_count = (tmp & 0x0F);
  599. tmp = hw->flags;
  600. status.supp_reason = ((tmp & 0x1C) >> 2);
  601. status.pm_indicated = !!(tmp & 0x80);
  602. status.intermediate = !!(tmp & 0x40);
  603. status.for_ampdu = !!(tmp & 0x20);
  604. status.acked = !!(tmp & 0x02);
  605. b43_handle_txstatus(dev, &status);
  606. }
  607. /* Stop any TX operation on the device (suspend the hardware queues) */
  608. void b43_tx_suspend(struct b43_wldev *dev)
  609. {
  610. b43_dma_tx_suspend(dev);
  611. }
  612. /* Resume any TX operation on the device (resume the hardware queues) */
  613. void b43_tx_resume(struct b43_wldev *dev)
  614. {
  615. b43_dma_tx_resume(dev);
  616. }
  617. #if 0
  618. static void upload_qos_parms(struct b43_wldev *dev,
  619. const u16 * parms, u16 offset)
  620. {
  621. int i;
  622. for (i = 0; i < B43_NR_QOSPARMS; i++) {
  623. b43_shm_write16(dev, B43_SHM_SHARED,
  624. offset + (i * 2), parms[i]);
  625. }
  626. }
  627. #endif
  628. /* Initialize the QoS parameters */
  629. void b43_qos_init(struct b43_wldev *dev)
  630. {
  631. /* FIXME: This function must probably be called from the mac80211
  632. * config callback. */
  633. return;
  634. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  635. //FIXME kill magic
  636. b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
  637. /*TODO: We might need some stack support here to get the values. */
  638. }