xmit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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 <st3@riseup.net>
  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 out of a CCK PLCP header. */
  27. static u8 b43_plcp_get_bitrate_cck(struct b43_plcp_hdr6 *plcp)
  28. {
  29. switch (plcp->raw[0]) {
  30. case 0x0A:
  31. return B43_CCK_RATE_1MB;
  32. case 0x14:
  33. return B43_CCK_RATE_2MB;
  34. case 0x37:
  35. return B43_CCK_RATE_5MB;
  36. case 0x6E:
  37. return B43_CCK_RATE_11MB;
  38. }
  39. B43_WARN_ON(1);
  40. return 0;
  41. }
  42. /* Extract the bitrate out of an OFDM PLCP header. */
  43. static u8 b43_plcp_get_bitrate_ofdm(struct b43_plcp_hdr6 *plcp)
  44. {
  45. switch (plcp->raw[0] & 0xF) {
  46. case 0xB:
  47. return B43_OFDM_RATE_6MB;
  48. case 0xF:
  49. return B43_OFDM_RATE_9MB;
  50. case 0xA:
  51. return B43_OFDM_RATE_12MB;
  52. case 0xE:
  53. return B43_OFDM_RATE_18MB;
  54. case 0x9:
  55. return B43_OFDM_RATE_24MB;
  56. case 0xD:
  57. return B43_OFDM_RATE_36MB;
  58. case 0x8:
  59. return B43_OFDM_RATE_48MB;
  60. case 0xC:
  61. return B43_OFDM_RATE_54MB;
  62. }
  63. B43_WARN_ON(1);
  64. return 0;
  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. static void generate_txhdr_fw4(struct b43_wldev *dev,
  163. struct b43_txhdr_fw4 *txhdr,
  164. const unsigned char *fragment_data,
  165. unsigned int fragment_len,
  166. const struct ieee80211_tx_control *txctl,
  167. u16 cookie)
  168. {
  169. const struct b43_phy *phy = &dev->phy;
  170. const struct ieee80211_hdr *wlhdr =
  171. (const struct ieee80211_hdr *)fragment_data;
  172. int use_encryption = (!(txctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT));
  173. u16 fctl = le16_to_cpu(wlhdr->frame_control);
  174. u8 rate, rate_fb;
  175. int rate_ofdm, rate_fb_ofdm;
  176. unsigned int plcp_fragment_len;
  177. u32 mac_ctl = 0;
  178. u16 phy_ctl = 0;
  179. u8 extra_ft = 0;
  180. memset(txhdr, 0, sizeof(*txhdr));
  181. rate = txctl->tx_rate;
  182. rate_ofdm = b43_is_ofdm_rate(rate);
  183. rate_fb = (txctl->alt_retry_rate == -1) ? rate : txctl->alt_retry_rate;
  184. rate_fb_ofdm = b43_is_ofdm_rate(rate_fb);
  185. if (rate_ofdm)
  186. txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate);
  187. else
  188. txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate);
  189. txhdr->mac_frame_ctl = wlhdr->frame_control;
  190. memcpy(txhdr->tx_receiver, wlhdr->addr1, 6);
  191. /* Calculate duration for fallback rate */
  192. if ((rate_fb == rate) ||
  193. (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
  194. (wlhdr->duration_id == cpu_to_le16(0))) {
  195. /* If the fallback rate equals the normal rate or the
  196. * dur_id field contains an AID, CFP magic or 0,
  197. * use the original dur_id field. */
  198. txhdr->dur_fb = wlhdr->duration_id;
  199. } else {
  200. int fbrate_base100kbps = B43_RATE_TO_BASE100KBPS(rate_fb);
  201. txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
  202. dev->wl->if_id,
  203. fragment_len,
  204. fbrate_base100kbps);
  205. }
  206. plcp_fragment_len = fragment_len + FCS_LEN;
  207. if (use_encryption) {
  208. u8 key_idx = (u16) (txctl->key_idx);
  209. struct b43_key *key;
  210. int wlhdr_len;
  211. size_t iv_len;
  212. B43_WARN_ON(key_idx >= dev->max_nr_keys);
  213. key = &(dev->key[key_idx]);
  214. B43_WARN_ON(!key->keyconf);
  215. /* Hardware appends ICV. */
  216. plcp_fragment_len += txctl->icv_len;
  217. key_idx = b43_kidx_to_fw(dev, key_idx);
  218. mac_ctl |= (key_idx << B43_TX4_MAC_KEYIDX_SHIFT) &
  219. B43_TX4_MAC_KEYIDX;
  220. mac_ctl |= (key->algorithm << B43_TX4_MAC_KEYALG_SHIFT) &
  221. B43_TX4_MAC_KEYALG;
  222. wlhdr_len = ieee80211_get_hdrlen(fctl);
  223. iv_len = min((size_t) txctl->iv_len,
  224. ARRAY_SIZE(txhdr->iv));
  225. memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len);
  226. }
  227. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp),
  228. plcp_fragment_len, rate);
  229. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb),
  230. plcp_fragment_len, rate_fb);
  231. /* Extra Frame Types */
  232. if (rate_fb_ofdm)
  233. extra_ft |= B43_TX4_EFT_FBOFDM;
  234. /* Set channel radio code. Note that the micrcode ORs 0x100 to
  235. * this value before comparing it to the value in SHM, if this
  236. * is a 5Ghz packet.
  237. */
  238. txhdr->chan_radio_code = phy->channel;
  239. /* PHY TX Control word */
  240. if (rate_ofdm)
  241. phy_ctl |= B43_TX4_PHY_OFDM;
  242. if (dev->short_preamble)
  243. phy_ctl |= B43_TX4_PHY_SHORTPRMBL;
  244. switch (txctl->antenna_sel_tx) {
  245. case 0:
  246. phy_ctl |= B43_TX4_PHY_ANTLAST;
  247. break;
  248. case 1:
  249. phy_ctl |= B43_TX4_PHY_ANT0;
  250. break;
  251. case 2:
  252. phy_ctl |= B43_TX4_PHY_ANT1;
  253. break;
  254. default:
  255. B43_WARN_ON(1);
  256. }
  257. /* MAC control */
  258. if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK))
  259. mac_ctl |= B43_TX4_MAC_ACK;
  260. if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
  261. ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)))
  262. mac_ctl |= B43_TX4_MAC_HWSEQ;
  263. if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
  264. mac_ctl |= B43_TX4_MAC_STMSDU;
  265. if (phy->type == B43_PHYTYPE_A)
  266. mac_ctl |= B43_TX4_MAC_5GHZ;
  267. /* Generate the RTS or CTS-to-self frame */
  268. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  269. (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
  270. unsigned int len;
  271. struct ieee80211_hdr *hdr;
  272. int rts_rate, rts_rate_fb;
  273. int rts_rate_ofdm, rts_rate_fb_ofdm;
  274. rts_rate = txctl->rts_cts_rate;
  275. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  276. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  277. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  278. if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  279. ieee80211_ctstoself_get(dev->wl->hw, dev->wl->if_id,
  280. fragment_data, fragment_len,
  281. txctl,
  282. (struct ieee80211_cts *)(txhdr->
  283. rts_frame));
  284. mac_ctl |= B43_TX4_MAC_SENDCTS;
  285. len = sizeof(struct ieee80211_cts);
  286. } else {
  287. ieee80211_rts_get(dev->wl->hw, dev->wl->if_id,
  288. fragment_data, fragment_len, txctl,
  289. (struct ieee80211_rts *)(txhdr->
  290. rts_frame));
  291. mac_ctl |= B43_TX4_MAC_SENDRTS;
  292. len = sizeof(struct ieee80211_rts);
  293. }
  294. len += FCS_LEN;
  295. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->
  296. rts_plcp), len,
  297. rts_rate);
  298. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->
  299. rts_plcp_fb),
  300. len, rts_rate_fb);
  301. hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
  302. txhdr->rts_dur_fb = hdr->duration_id;
  303. if (rts_rate_ofdm) {
  304. extra_ft |= B43_TX4_EFT_RTSOFDM;
  305. txhdr->phy_rate_rts =
  306. b43_plcp_get_ratecode_ofdm(rts_rate);
  307. } else
  308. txhdr->phy_rate_rts =
  309. b43_plcp_get_ratecode_cck(rts_rate);
  310. if (rts_rate_fb_ofdm)
  311. extra_ft |= B43_TX4_EFT_RTSFBOFDM;
  312. mac_ctl |= B43_TX4_MAC_LONGFRAME;
  313. }
  314. /* Magic cookie */
  315. txhdr->cookie = cpu_to_le16(cookie);
  316. /* Apply the bitfields */
  317. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  318. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  319. txhdr->extra_ft = extra_ft;
  320. }
  321. void b43_generate_txhdr(struct b43_wldev *dev,
  322. u8 * txhdr,
  323. const unsigned char *fragment_data,
  324. unsigned int fragment_len,
  325. const struct ieee80211_tx_control *txctl, u16 cookie)
  326. {
  327. generate_txhdr_fw4(dev, (struct b43_txhdr_fw4 *)txhdr,
  328. fragment_data, fragment_len, txctl, cookie);
  329. }
  330. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  331. u8 in_rssi, int ofdm,
  332. int adjust_2053, int adjust_2050)
  333. {
  334. struct b43_phy *phy = &dev->phy;
  335. s32 tmp;
  336. switch (phy->radio_ver) {
  337. case 0x2050:
  338. if (ofdm) {
  339. tmp = in_rssi;
  340. if (tmp > 127)
  341. tmp -= 256;
  342. tmp *= 73;
  343. tmp /= 64;
  344. if (adjust_2050)
  345. tmp += 25;
  346. else
  347. tmp -= 3;
  348. } else {
  349. if (dev->dev->bus->sprom.r1.
  350. boardflags_lo & B43_BFL_RSSI) {
  351. if (in_rssi > 63)
  352. in_rssi = 63;
  353. tmp = phy->nrssi_lt[in_rssi];
  354. tmp = 31 - tmp;
  355. tmp *= -131;
  356. tmp /= 128;
  357. tmp -= 57;
  358. } else {
  359. tmp = in_rssi;
  360. tmp = 31 - tmp;
  361. tmp *= -149;
  362. tmp /= 128;
  363. tmp -= 68;
  364. }
  365. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  366. tmp += 25;
  367. }
  368. break;
  369. case 0x2060:
  370. if (in_rssi > 127)
  371. tmp = in_rssi - 256;
  372. else
  373. tmp = in_rssi;
  374. break;
  375. default:
  376. tmp = in_rssi;
  377. tmp -= 11;
  378. tmp *= 103;
  379. tmp /= 64;
  380. if (adjust_2053)
  381. tmp -= 109;
  382. else
  383. tmp -= 83;
  384. }
  385. return (s8) tmp;
  386. }
  387. //TODO
  388. #if 0
  389. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  390. {
  391. struct b43_phy *phy = &dev->phy;
  392. s8 ret;
  393. if (phy->type == B43_PHYTYPE_A) {
  394. //TODO: Incomplete specs.
  395. ret = 0;
  396. } else
  397. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  398. return ret;
  399. }
  400. #endif
  401. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  402. {
  403. struct ieee80211_rx_status status;
  404. struct b43_plcp_hdr6 *plcp;
  405. struct ieee80211_hdr *wlhdr;
  406. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  407. u16 fctl;
  408. u16 phystat0, phystat3, chanstat, mactime;
  409. u32 macstat;
  410. u16 chanid;
  411. u8 jssi;
  412. int padding;
  413. memset(&status, 0, sizeof(status));
  414. /* Get metadata about the frame from the header. */
  415. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  416. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  417. jssi = rxhdr->jssi;
  418. macstat = le32_to_cpu(rxhdr->mac_status);
  419. mactime = le16_to_cpu(rxhdr->mac_time);
  420. chanstat = le16_to_cpu(rxhdr->channel);
  421. if (macstat & B43_RX_MAC_FCSERR)
  422. dev->wl->ieee_stats.dot11FCSErrorCount++;
  423. if (macstat & B43_RX_MAC_DECERR) {
  424. /* Decryption with the given key failed.
  425. * Drop the packet. We also won't be able to decrypt it with
  426. * the key in software. */
  427. goto drop;
  428. }
  429. /* Skip PLCP and padding */
  430. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  431. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  432. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  433. goto drop;
  434. }
  435. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  436. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  437. /* The skb contains the Wireless Header + payload data now */
  438. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  439. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  440. goto drop;
  441. }
  442. wlhdr = (struct ieee80211_hdr *)(skb->data);
  443. fctl = le16_to_cpu(wlhdr->frame_control);
  444. skb_trim(skb, skb->len - FCS_LEN);
  445. if (macstat & B43_RX_MAC_DEC) {
  446. unsigned int keyidx;
  447. int wlhdr_len;
  448. keyidx = ((macstat & B43_RX_MAC_KEYIDX)
  449. >> B43_RX_MAC_KEYIDX_SHIFT);
  450. /* We must adjust the key index here. We want the "physical"
  451. * key index, but the ucode passed it slightly different.
  452. */
  453. keyidx = b43_kidx_to_raw(dev, keyidx);
  454. B43_WARN_ON(keyidx >= dev->max_nr_keys);
  455. if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) {
  456. wlhdr_len = ieee80211_get_hdrlen(fctl);
  457. if (unlikely(skb->len < (wlhdr_len + 3))) {
  458. b43dbg(dev->wl,
  459. "RX: Packet size underrun (3)\n");
  460. goto drop;
  461. }
  462. status.flag |= RX_FLAG_DECRYPTED;
  463. }
  464. }
  465. status.ssi = b43_rssi_postprocess(dev, jssi,
  466. (phystat0 & B43_RX_PHYST0_OFDM),
  467. (phystat0 & B43_RX_PHYST0_GAINCTL),
  468. (phystat3 & B43_RX_PHYST3_TRSTATE));
  469. status.noise = dev->stats.link_noise;
  470. /* the next line looks wrong, but is what mac80211 wants */
  471. status.signal = (jssi * 100) / B43_RX_MAX_SSI;
  472. if (phystat0 & B43_RX_PHYST0_OFDM)
  473. status.rate = b43_plcp_get_bitrate_ofdm(plcp);
  474. else
  475. status.rate = b43_plcp_get_bitrate_cck(plcp);
  476. status.antenna = !!(phystat0 & B43_RX_PHYST0_ANT);
  477. status.mactime = mactime;
  478. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  479. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  480. case B43_PHYTYPE_A:
  481. status.phymode = MODE_IEEE80211A;
  482. B43_WARN_ON(1);
  483. /* FIXME: We don't really know which value the "chanid" contains.
  484. * So the following assignment might be wrong. */
  485. status.channel = chanid;
  486. status.freq = b43_channel_to_freq_5ghz(status.channel);
  487. break;
  488. case B43_PHYTYPE_G:
  489. status.phymode = MODE_IEEE80211G;
  490. /* chanid is the radio channel cookie value as used
  491. * to tune the radio. */
  492. status.freq = chanid + 2400;
  493. status.channel = b43_freq_to_channel_2ghz(status.freq);
  494. break;
  495. case B43_PHYTYPE_N:
  496. status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
  497. /* chanid is the SHM channel cookie. Which is the plain
  498. * channel number in b43. */
  499. status.channel = chanid;
  500. if (chanstat & B43_RX_CHAN_5GHZ)
  501. status.freq = b43_freq_to_channel_5ghz(status.freq);
  502. else
  503. status.freq = b43_freq_to_channel_2ghz(status.freq);
  504. break;
  505. default:
  506. B43_WARN_ON(1);
  507. goto drop;
  508. }
  509. dev->stats.last_rx = jiffies;
  510. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  511. return;
  512. drop:
  513. b43dbg(dev->wl, "RX: Packet dropped\n");
  514. dev_kfree_skb_any(skb);
  515. }
  516. void b43_handle_txstatus(struct b43_wldev *dev,
  517. const struct b43_txstatus *status)
  518. {
  519. b43_debugfs_log_txstat(dev, status);
  520. if (status->intermediate)
  521. return;
  522. if (status->for_ampdu)
  523. return;
  524. if (!status->acked)
  525. dev->wl->ieee_stats.dot11ACKFailureCount++;
  526. if (status->rts_count) {
  527. if (status->rts_count == 0xF) //FIXME
  528. dev->wl->ieee_stats.dot11RTSFailureCount++;
  529. else
  530. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  531. }
  532. if (b43_using_pio(dev))
  533. b43_pio_handle_txstatus(dev, status);
  534. else
  535. b43_dma_handle_txstatus(dev, status);
  536. }
  537. /* Handle TX status report as received through DMA/PIO queues */
  538. void b43_handle_hwtxstatus(struct b43_wldev *dev,
  539. const struct b43_hwtxstatus *hw)
  540. {
  541. struct b43_txstatus status;
  542. u8 tmp;
  543. status.cookie = le16_to_cpu(hw->cookie);
  544. status.seq = le16_to_cpu(hw->seq);
  545. status.phy_stat = hw->phy_stat;
  546. tmp = hw->count;
  547. status.frame_count = (tmp >> 4);
  548. status.rts_count = (tmp & 0x0F);
  549. tmp = hw->flags;
  550. status.supp_reason = ((tmp & 0x1C) >> 2);
  551. status.pm_indicated = !!(tmp & 0x80);
  552. status.intermediate = !!(tmp & 0x40);
  553. status.for_ampdu = !!(tmp & 0x20);
  554. status.acked = !!(tmp & 0x02);
  555. b43_handle_txstatus(dev, &status);
  556. }
  557. /* Stop any TX operation on the device (suspend the hardware queues) */
  558. void b43_tx_suspend(struct b43_wldev *dev)
  559. {
  560. if (b43_using_pio(dev))
  561. b43_pio_freeze_txqueues(dev);
  562. else
  563. b43_dma_tx_suspend(dev);
  564. }
  565. /* Resume any TX operation on the device (resume the hardware queues) */
  566. void b43_tx_resume(struct b43_wldev *dev)
  567. {
  568. if (b43_using_pio(dev))
  569. b43_pio_thaw_txqueues(dev);
  570. else
  571. b43_dma_tx_resume(dev);
  572. }
  573. #if 0
  574. static void upload_qos_parms(struct b43_wldev *dev,
  575. const u16 * parms, u16 offset)
  576. {
  577. int i;
  578. for (i = 0; i < B43_NR_QOSPARMS; i++) {
  579. b43_shm_write16(dev, B43_SHM_SHARED,
  580. offset + (i * 2), parms[i]);
  581. }
  582. }
  583. #endif
  584. /* Initialize the QoS parameters */
  585. void b43_qos_init(struct b43_wldev *dev)
  586. {
  587. /* FIXME: This function must probably be called from the mac80211
  588. * config callback. */
  589. return;
  590. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  591. //FIXME kill magic
  592. b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
  593. /*TODO: We might need some stack support here to get the values. */
  594. }