xmit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. Broadcom B43 wireless driver
  3. Transmission (TX/RX) related functions.
  4. Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  5. Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  6. Copyright (C) 2005, 2006 Michael Buesch <mb@bu3sch.de>
  7. Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
  8. Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  20. Boston, MA 02110-1301, USA.
  21. */
  22. #include "xmit.h"
  23. #include "phy.h"
  24. #include "dma.h"
  25. #include "pio.h"
  26. /* Extract the bitrate 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. if (txctl->flags & IEEE80211_TXCTL_LONG_RETRY_LIMIT)
  268. mac_ctl |= B43_TX4_MAC_LONGFRAME;
  269. /* Generate the RTS or CTS-to-self frame */
  270. if ((txctl->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
  271. (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
  272. unsigned int len;
  273. struct ieee80211_hdr *hdr;
  274. int rts_rate, rts_rate_fb;
  275. int rts_rate_ofdm, rts_rate_fb_ofdm;
  276. rts_rate = txctl->rts_cts_rate;
  277. rts_rate_ofdm = b43_is_ofdm_rate(rts_rate);
  278. rts_rate_fb = b43_calc_fallback_rate(rts_rate);
  279. rts_rate_fb_ofdm = b43_is_ofdm_rate(rts_rate_fb);
  280. if (txctl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  281. ieee80211_ctstoself_get(dev->wl->hw, dev->wl->if_id,
  282. fragment_data, fragment_len,
  283. txctl,
  284. (struct ieee80211_cts *)(txhdr->
  285. rts_frame));
  286. mac_ctl |= B43_TX4_MAC_SENDCTS;
  287. len = sizeof(struct ieee80211_cts);
  288. } else {
  289. ieee80211_rts_get(dev->wl->hw, dev->wl->if_id,
  290. fragment_data, fragment_len, txctl,
  291. (struct ieee80211_rts *)(txhdr->
  292. rts_frame));
  293. mac_ctl |= B43_TX4_MAC_SENDRTS;
  294. len = sizeof(struct ieee80211_rts);
  295. }
  296. len += FCS_LEN;
  297. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->
  298. rts_plcp), len,
  299. rts_rate);
  300. b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->
  301. rts_plcp_fb),
  302. len, rts_rate_fb);
  303. hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
  304. txhdr->rts_dur_fb = hdr->duration_id;
  305. if (rts_rate_ofdm) {
  306. extra_ft |= B43_TX4_EFT_RTSOFDM;
  307. txhdr->phy_rate_rts =
  308. b43_plcp_get_ratecode_ofdm(rts_rate);
  309. } else
  310. txhdr->phy_rate_rts =
  311. b43_plcp_get_ratecode_cck(rts_rate);
  312. if (rts_rate_fb_ofdm)
  313. extra_ft |= B43_TX4_EFT_RTSFBOFDM;
  314. }
  315. /* Magic cookie */
  316. txhdr->cookie = cpu_to_le16(cookie);
  317. /* Apply the bitfields */
  318. txhdr->mac_ctl = cpu_to_le32(mac_ctl);
  319. txhdr->phy_ctl = cpu_to_le16(phy_ctl);
  320. txhdr->extra_ft = extra_ft;
  321. }
  322. void b43_generate_txhdr(struct b43_wldev *dev,
  323. u8 * txhdr,
  324. const unsigned char *fragment_data,
  325. unsigned int fragment_len,
  326. const struct ieee80211_tx_control *txctl, u16 cookie)
  327. {
  328. generate_txhdr_fw4(dev, (struct b43_txhdr_fw4 *)txhdr,
  329. fragment_data, fragment_len, txctl, cookie);
  330. }
  331. static s8 b43_rssi_postprocess(struct b43_wldev *dev,
  332. u8 in_rssi, int ofdm,
  333. int adjust_2053, int adjust_2050)
  334. {
  335. struct b43_phy *phy = &dev->phy;
  336. s32 tmp;
  337. switch (phy->radio_ver) {
  338. case 0x2050:
  339. if (ofdm) {
  340. tmp = in_rssi;
  341. if (tmp > 127)
  342. tmp -= 256;
  343. tmp *= 73;
  344. tmp /= 64;
  345. if (adjust_2050)
  346. tmp += 25;
  347. else
  348. tmp -= 3;
  349. } else {
  350. if (dev->dev->bus->sprom.
  351. boardflags_lo & B43_BFL_RSSI) {
  352. if (in_rssi > 63)
  353. in_rssi = 63;
  354. tmp = phy->nrssi_lt[in_rssi];
  355. tmp = 31 - tmp;
  356. tmp *= -131;
  357. tmp /= 128;
  358. tmp -= 57;
  359. } else {
  360. tmp = in_rssi;
  361. tmp = 31 - tmp;
  362. tmp *= -149;
  363. tmp /= 128;
  364. tmp -= 68;
  365. }
  366. if (phy->type == B43_PHYTYPE_G && adjust_2050)
  367. tmp += 25;
  368. }
  369. break;
  370. case 0x2060:
  371. if (in_rssi > 127)
  372. tmp = in_rssi - 256;
  373. else
  374. tmp = in_rssi;
  375. break;
  376. default:
  377. tmp = in_rssi;
  378. tmp -= 11;
  379. tmp *= 103;
  380. tmp /= 64;
  381. if (adjust_2053)
  382. tmp -= 109;
  383. else
  384. tmp -= 83;
  385. }
  386. return (s8) tmp;
  387. }
  388. //TODO
  389. #if 0
  390. static s8 b43_rssinoise_postprocess(struct b43_wldev *dev, u8 in_rssi)
  391. {
  392. struct b43_phy *phy = &dev->phy;
  393. s8 ret;
  394. if (phy->type == B43_PHYTYPE_A) {
  395. //TODO: Incomplete specs.
  396. ret = 0;
  397. } else
  398. ret = b43_rssi_postprocess(dev, in_rssi, 0, 1, 1);
  399. return ret;
  400. }
  401. #endif
  402. void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
  403. {
  404. struct ieee80211_rx_status status;
  405. struct b43_plcp_hdr6 *plcp;
  406. struct ieee80211_hdr *wlhdr;
  407. const struct b43_rxhdr_fw4 *rxhdr = _rxhdr;
  408. u16 fctl;
  409. u16 phystat0, phystat3, chanstat, mactime;
  410. u32 macstat;
  411. u16 chanid;
  412. u8 jssi;
  413. int padding;
  414. memset(&status, 0, sizeof(status));
  415. /* Get metadata about the frame from the header. */
  416. phystat0 = le16_to_cpu(rxhdr->phy_status0);
  417. phystat3 = le16_to_cpu(rxhdr->phy_status3);
  418. jssi = rxhdr->jssi;
  419. macstat = le32_to_cpu(rxhdr->mac_status);
  420. mactime = le16_to_cpu(rxhdr->mac_time);
  421. chanstat = le16_to_cpu(rxhdr->channel);
  422. if (macstat & B43_RX_MAC_FCSERR)
  423. dev->wl->ieee_stats.dot11FCSErrorCount++;
  424. if (macstat & B43_RX_MAC_DECERR) {
  425. /* Decryption with the given key failed.
  426. * Drop the packet. We also won't be able to decrypt it with
  427. * the key in software. */
  428. goto drop;
  429. }
  430. /* Skip PLCP and padding */
  431. padding = (macstat & B43_RX_MAC_PADDING) ? 2 : 0;
  432. if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) {
  433. b43dbg(dev->wl, "RX: Packet size underrun (1)\n");
  434. goto drop;
  435. }
  436. plcp = (struct b43_plcp_hdr6 *)(skb->data + padding);
  437. skb_pull(skb, sizeof(struct b43_plcp_hdr6) + padding);
  438. /* The skb contains the Wireless Header + payload data now */
  439. if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) {
  440. b43dbg(dev->wl, "RX: Packet size underrun (2)\n");
  441. goto drop;
  442. }
  443. wlhdr = (struct ieee80211_hdr *)(skb->data);
  444. fctl = le16_to_cpu(wlhdr->frame_control);
  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. status.flag |= RX_FLAG_TSFT;
  479. chanid = (chanstat & B43_RX_CHAN_ID) >> B43_RX_CHAN_ID_SHIFT;
  480. switch (chanstat & B43_RX_CHAN_PHYTYPE) {
  481. case B43_PHYTYPE_A:
  482. status.phymode = MODE_IEEE80211A;
  483. B43_WARN_ON(1);
  484. /* FIXME: We don't really know which value the "chanid" contains.
  485. * So the following assignment might be wrong. */
  486. status.channel = chanid;
  487. status.freq = b43_channel_to_freq_5ghz(status.channel);
  488. break;
  489. case B43_PHYTYPE_G:
  490. status.phymode = MODE_IEEE80211G;
  491. /* chanid is the radio channel cookie value as used
  492. * to tune the radio. */
  493. status.freq = chanid + 2400;
  494. status.channel = b43_freq_to_channel_2ghz(status.freq);
  495. break;
  496. case B43_PHYTYPE_N:
  497. status.phymode = 0xDEAD /*FIXME MODE_IEEE80211N*/;
  498. /* chanid is the SHM channel cookie. Which is the plain
  499. * channel number in b43. */
  500. status.channel = chanid;
  501. if (chanstat & B43_RX_CHAN_5GHZ)
  502. status.freq = b43_freq_to_channel_5ghz(status.freq);
  503. else
  504. status.freq = b43_freq_to_channel_2ghz(status.freq);
  505. break;
  506. default:
  507. B43_WARN_ON(1);
  508. goto drop;
  509. }
  510. dev->stats.last_rx = jiffies;
  511. ieee80211_rx_irqsafe(dev->wl->hw, skb, &status);
  512. return;
  513. drop:
  514. b43dbg(dev->wl, "RX: Packet dropped\n");
  515. dev_kfree_skb_any(skb);
  516. }
  517. void b43_handle_txstatus(struct b43_wldev *dev,
  518. const struct b43_txstatus *status)
  519. {
  520. b43_debugfs_log_txstat(dev, status);
  521. if (status->intermediate)
  522. return;
  523. if (status->for_ampdu)
  524. return;
  525. if (!status->acked)
  526. dev->wl->ieee_stats.dot11ACKFailureCount++;
  527. if (status->rts_count) {
  528. if (status->rts_count == 0xF) //FIXME
  529. dev->wl->ieee_stats.dot11RTSFailureCount++;
  530. else
  531. dev->wl->ieee_stats.dot11RTSSuccessCount++;
  532. }
  533. if (b43_using_pio(dev))
  534. b43_pio_handle_txstatus(dev, status);
  535. else
  536. b43_dma_handle_txstatus(dev, status);
  537. }
  538. /* Handle TX status report as received through DMA/PIO queues */
  539. void b43_handle_hwtxstatus(struct b43_wldev *dev,
  540. const struct b43_hwtxstatus *hw)
  541. {
  542. struct b43_txstatus status;
  543. u8 tmp;
  544. status.cookie = le16_to_cpu(hw->cookie);
  545. status.seq = le16_to_cpu(hw->seq);
  546. status.phy_stat = hw->phy_stat;
  547. tmp = hw->count;
  548. status.frame_count = (tmp >> 4);
  549. status.rts_count = (tmp & 0x0F);
  550. tmp = hw->flags;
  551. status.supp_reason = ((tmp & 0x1C) >> 2);
  552. status.pm_indicated = !!(tmp & 0x80);
  553. status.intermediate = !!(tmp & 0x40);
  554. status.for_ampdu = !!(tmp & 0x20);
  555. status.acked = !!(tmp & 0x02);
  556. b43_handle_txstatus(dev, &status);
  557. }
  558. /* Stop any TX operation on the device (suspend the hardware queues) */
  559. void b43_tx_suspend(struct b43_wldev *dev)
  560. {
  561. if (b43_using_pio(dev))
  562. b43_pio_freeze_txqueues(dev);
  563. else
  564. b43_dma_tx_suspend(dev);
  565. }
  566. /* Resume any TX operation on the device (resume the hardware queues) */
  567. void b43_tx_resume(struct b43_wldev *dev)
  568. {
  569. if (b43_using_pio(dev))
  570. b43_pio_thaw_txqueues(dev);
  571. else
  572. b43_dma_tx_resume(dev);
  573. }
  574. #if 0
  575. static void upload_qos_parms(struct b43_wldev *dev,
  576. const u16 * parms, u16 offset)
  577. {
  578. int i;
  579. for (i = 0; i < B43_NR_QOSPARMS; i++) {
  580. b43_shm_write16(dev, B43_SHM_SHARED,
  581. offset + (i * 2), parms[i]);
  582. }
  583. }
  584. #endif
  585. /* Initialize the QoS parameters */
  586. void b43_qos_init(struct b43_wldev *dev)
  587. {
  588. /* FIXME: This function must probably be called from the mac80211
  589. * config callback. */
  590. return;
  591. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  592. //FIXME kill magic
  593. b43_write16(dev, 0x688, b43_read16(dev, 0x688) | 0x4);
  594. /*TODO: We might need some stack support here to get the values. */
  595. }