Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3
  4  Broadcom B43legacy wireless driver
  5
  6  Transmission (TX/RX) related functions.
  7
  8  Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  9  Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
 10  Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
 11  Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
 12  Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
 13  Copyright (C) 2007 Larry Finger <Larry.Finger@lwfinger.net>
 14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 15
 16*/
 17
 18#include <net/dst.h>
 19
 20#include "xmit.h"
 21#include "phy.h"
 22#include "dma.h"
 23#include "pio.h"
 24
 25
 26/* Extract the bitrate out of a CCK PLCP header. */
 27static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp)
 28{
 29	switch (plcp->raw[0]) {
 30	case 0x0A:
 31		return 0;
 32	case 0x14:
 33		return 1;
 34	case 0x37:
 35		return 2;
 36	case 0x6E:
 37		return 3;
 38	}
 39	B43legacy_BUG_ON(1);
 40	return -1;
 41}
 42
 43/* Extract the bitrate out of an OFDM PLCP header. */
 44static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp,
 45					      bool aphy)
 46{
 47	int base = aphy ? 0 : 4;
 48
 49	switch (plcp->raw[0] & 0xF) {
 50	case 0xB:
 51		return base + 0;
 52	case 0xF:
 53		return base + 1;
 54	case 0xA:
 55		return base + 2;
 56	case 0xE:
 57		return base + 3;
 58	case 0x9:
 59		return base + 4;
 60	case 0xD:
 61		return base + 5;
 62	case 0x8:
 63		return base + 6;
 64	case 0xC:
 65		return base + 7;
 66	}
 67	B43legacy_BUG_ON(1);
 68	return -1;
 69}
 70
 71u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate)
 72{
 73	switch (bitrate) {
 74	case B43legacy_CCK_RATE_1MB:
 75		return 0x0A;
 76	case B43legacy_CCK_RATE_2MB:
 77		return 0x14;
 78	case B43legacy_CCK_RATE_5MB:
 79		return 0x37;
 80	case B43legacy_CCK_RATE_11MB:
 81		return 0x6E;
 82	}
 83	B43legacy_BUG_ON(1);
 84	return 0;
 85}
 86
 87u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate)
 88{
 89	switch (bitrate) {
 90	case B43legacy_OFDM_RATE_6MB:
 91		return 0xB;
 92	case B43legacy_OFDM_RATE_9MB:
 93		return 0xF;
 94	case B43legacy_OFDM_RATE_12MB:
 95		return 0xA;
 96	case B43legacy_OFDM_RATE_18MB:
 97		return 0xE;
 98	case B43legacy_OFDM_RATE_24MB:
 99		return 0x9;
100	case B43legacy_OFDM_RATE_36MB:
101		return 0xD;
102	case B43legacy_OFDM_RATE_48MB:
103		return 0x8;
104	case B43legacy_OFDM_RATE_54MB:
105		return 0xC;
106	}
107	B43legacy_BUG_ON(1);
108	return 0;
109}
110
111void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp,
112				 const u16 octets, const u8 bitrate)
113{
114	__le32 *data = &(plcp->data);
115	__u8 *raw = plcp->raw;
116
117	if (b43legacy_is_ofdm_rate(bitrate)) {
118		u16 d;
119
120		d = b43legacy_plcp_get_ratecode_ofdm(bitrate);
121		B43legacy_WARN_ON(octets & 0xF000);
122		d |= (octets << 5);
123		*data = cpu_to_le32(d);
124	} else {
125		u32 plen;
126
127		plen = octets * 16 / bitrate;
128		if ((octets * 16 % bitrate) > 0) {
129			plen++;
130			if ((bitrate == B43legacy_CCK_RATE_11MB)
131			    && ((octets * 8 % 11) < 4))
132				raw[1] = 0x84;
133			else
134				raw[1] = 0x04;
135		} else
136			raw[1] = 0x04;
137		*data |= cpu_to_le32(plen << 16);
138		raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate);
139	}
140}
141
142static u8 b43legacy_calc_fallback_rate(u8 bitrate)
143{
144	switch (bitrate) {
145	case B43legacy_CCK_RATE_1MB:
146		return B43legacy_CCK_RATE_1MB;
147	case B43legacy_CCK_RATE_2MB:
148		return B43legacy_CCK_RATE_1MB;
149	case B43legacy_CCK_RATE_5MB:
150		return B43legacy_CCK_RATE_2MB;
151	case B43legacy_CCK_RATE_11MB:
152		return B43legacy_CCK_RATE_5MB;
153	case B43legacy_OFDM_RATE_6MB:
154		return B43legacy_CCK_RATE_5MB;
155	case B43legacy_OFDM_RATE_9MB:
156		return B43legacy_OFDM_RATE_6MB;
157	case B43legacy_OFDM_RATE_12MB:
158		return B43legacy_OFDM_RATE_9MB;
159	case B43legacy_OFDM_RATE_18MB:
160		return B43legacy_OFDM_RATE_12MB;
161	case B43legacy_OFDM_RATE_24MB:
162		return B43legacy_OFDM_RATE_18MB;
163	case B43legacy_OFDM_RATE_36MB:
164		return B43legacy_OFDM_RATE_24MB;
165	case B43legacy_OFDM_RATE_48MB:
166		return B43legacy_OFDM_RATE_36MB;
167	case B43legacy_OFDM_RATE_54MB:
168		return B43legacy_OFDM_RATE_48MB;
169	}
170	B43legacy_BUG_ON(1);
171	return 0;
172}
173
174static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
175			       struct b43legacy_txhdr_fw3 *txhdr,
176			       const unsigned char *fragment_data,
177			       unsigned int fragment_len,
178			       struct ieee80211_tx_info *info,
179			       u16 cookie)
180{
181	const struct ieee80211_hdr *wlhdr;
182	int use_encryption = !!info->control.hw_key;
183	u8 rate;
184	struct ieee80211_rate *rate_fb;
185	int rate_ofdm;
186	int rate_fb_ofdm;
187	unsigned int plcp_fragment_len;
188	u32 mac_ctl = 0;
189	u16 phy_ctl = 0;
190	struct ieee80211_rate *tx_rate;
191	struct ieee80211_tx_rate *rates;
192
193	wlhdr = (const struct ieee80211_hdr *)fragment_data;
194
195	memset(txhdr, 0, sizeof(*txhdr));
196
197	tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info);
198
199	rate = tx_rate->hw_value;
200	rate_ofdm = b43legacy_is_ofdm_rate(rate);
201	rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : tx_rate;
202	rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
203
204	txhdr->mac_frame_ctl = wlhdr->frame_control;
205	memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN);
206
207	/* Calculate duration for fallback rate */
208	if ((rate_fb->hw_value == rate) ||
209	    (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
210	    (wlhdr->duration_id == cpu_to_le16(0))) {
211		/* If the fallback rate equals the normal rate or the
212		 * dur_id field contains an AID, CFP magic or 0,
213		 * use the original dur_id field. */
214		txhdr->dur_fb = wlhdr->duration_id;
215	} else {
216		txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
217							 info->control.vif,
218							 info->band,
219							 fragment_len,
220							 rate_fb);
221	}
222
223	plcp_fragment_len = fragment_len + FCS_LEN;
224	if (use_encryption) {
225		u8 key_idx = info->control.hw_key->hw_key_idx;
226		struct b43legacy_key *key;
227		int wlhdr_len;
228		size_t iv_len;
229
230		B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
231		key = &(dev->key[key_idx]);
232
233		if (key->enabled) {
234			/* Hardware appends ICV. */
235			plcp_fragment_len += info->control.hw_key->icv_len;
236
237			key_idx = b43legacy_kidx_to_fw(dev, key_idx);
238			mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
239				   B43legacy_TX4_MAC_KEYIDX;
240			mac_ctl |= (key->algorithm <<
241				   B43legacy_TX4_MAC_KEYALG_SHIFT) &
242				   B43legacy_TX4_MAC_KEYALG;
243			wlhdr_len = ieee80211_hdrlen(wlhdr->frame_control);
244			iv_len = min_t(size_t, info->control.hw_key->iv_len,
245				     ARRAY_SIZE(txhdr->iv));
246			memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
247		} else {
248			/* This key is invalid. This might only happen
249			 * in a short timeframe after machine resume before
250			 * we were able to reconfigure keys.
251			 * Drop this packet completely. Do not transmit it
252			 * unencrypted to avoid leaking information. */
253			return -ENOKEY;
254		}
255	}
256	b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
257				    (&txhdr->plcp), plcp_fragment_len,
258				    rate);
259	b43legacy_generate_plcp_hdr(&txhdr->plcp_fb, plcp_fragment_len,
260				    rate_fb->hw_value);
261
262	/* PHY TX Control word */
263	if (rate_ofdm)
264		phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM;
265	if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
266		phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
267	phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
268
269	/* MAC control */
270	rates = info->control.rates;
271	if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
272		mac_ctl |= B43legacy_TX4_MAC_ACK;
273	if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
274		mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
275	if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
276		mac_ctl |= B43legacy_TX4_MAC_STMSDU;
277	if (rate_fb_ofdm)
278		mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
279
280	/* Overwrite rates[0].count to make the retry calculation
281	 * in the tx status easier. need the actual retry limit to
282	 * detect whether the fallback rate was used.
283	 */
284	if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
285	    (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
286		rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
287		mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
288	} else {
289		rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
290	}
291
292	/* Generate the RTS or CTS-to-self frame */
293	if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
294	    (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
295		unsigned int len;
296		struct ieee80211_hdr *hdr;
297		int rts_rate;
298		int rts_rate_fb;
299		int rts_rate_fb_ofdm;
300
301		rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
302		rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
303		rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
304		if (rts_rate_fb_ofdm)
305			mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
306
307		if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
308			ieee80211_ctstoself_get(dev->wl->hw,
309						info->control.vif,
310						fragment_data,
311						fragment_len, info,
312						(struct ieee80211_cts *)
313						(txhdr->rts_frame));
314			mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
315			len = sizeof(struct ieee80211_cts);
316		} else {
317			ieee80211_rts_get(dev->wl->hw,
318					  info->control.vif,
319					  fragment_data, fragment_len, info,
320					  (struct ieee80211_rts *)
321					  (txhdr->rts_frame));
322			mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
323			len = sizeof(struct ieee80211_rts);
324		}
325		len += FCS_LEN;
326		b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
327					    (&txhdr->rts_plcp),
328					    len, rts_rate);
329		b43legacy_generate_plcp_hdr(&txhdr->rts_plcp_fb,
330					    len, rts_rate_fb);
331		hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
332		txhdr->rts_dur_fb = hdr->duration_id;
333	}
334
335	/* Magic cookie */
336	txhdr->cookie = cpu_to_le16(cookie);
337
338	/* Apply the bitfields */
339	txhdr->mac_ctl = cpu_to_le32(mac_ctl);
340	txhdr->phy_ctl = cpu_to_le16(phy_ctl);
341
342	return 0;
343}
344
345int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
346			      u8 *txhdr,
347			      const unsigned char *fragment_data,
348			      unsigned int fragment_len,
349			      struct ieee80211_tx_info *info,
350			      u16 cookie)
351{
352	return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
353			   fragment_data, fragment_len,
354			   info, cookie);
355}
356
357static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
358				     u8 in_rssi, int ofdm,
359				     int adjust_2053, int adjust_2050)
360{
361	struct b43legacy_phy *phy = &dev->phy;
362	s32 tmp;
363
364	switch (phy->radio_ver) {
365	case 0x2050:
366		if (ofdm) {
367			tmp = in_rssi;
368			if (tmp > 127)
369				tmp -= 256;
370			tmp *= 73;
371			tmp /= 64;
372			if (adjust_2050)
373				tmp += 25;
374			else
375				tmp -= 3;
376		} else {
377			if (dev->dev->bus->sprom.boardflags_lo
378			    & B43legacy_BFL_RSSI) {
379				if (in_rssi > 63)
380					in_rssi = 63;
381				tmp = phy->nrssi_lt[in_rssi];
382				tmp = 31 - tmp;
383				tmp *= -131;
384				tmp /= 128;
385				tmp -= 57;
386			} else {
387				tmp = in_rssi;
388				tmp = 31 - tmp;
389				tmp *= -149;
390				tmp /= 128;
391				tmp -= 68;
392			}
393			if (phy->type == B43legacy_PHYTYPE_G &&
394			    adjust_2050)
395				tmp += 25;
396		}
397		break;
398	case 0x2060:
399		if (in_rssi > 127)
400			tmp = in_rssi - 256;
401		else
402			tmp = in_rssi;
403		break;
404	default:
405		tmp = in_rssi;
406		tmp -= 11;
407		tmp *= 103;
408		tmp /= 64;
409		if (adjust_2053)
410			tmp -= 109;
411		else
412			tmp -= 83;
413	}
414
415	return (s8)tmp;
416}
417
418void b43legacy_rx(struct b43legacy_wldev *dev,
419		  struct sk_buff *skb,
420		  const void *_rxhdr)
421{
422	struct ieee80211_rx_status status;
423	struct b43legacy_plcp_hdr6 *plcp;
424	struct ieee80211_hdr *wlhdr;
425	const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
426	__le16 fctl;
427	u16 phystat0;
428	u16 phystat3;
429	u16 chanstat;
430	u16 mactime;
431	u32 macstat;
432	u16 chanid;
433	u8 jssi;
434	int padding;
435
436	memset(&status, 0, sizeof(status));
437
438	/* Get metadata about the frame from the header. */
439	phystat0 = le16_to_cpu(rxhdr->phy_status0);
440	phystat3 = le16_to_cpu(rxhdr->phy_status3);
441	jssi = rxhdr->jssi;
442	macstat = le16_to_cpu(rxhdr->mac_status);
443	mactime = le16_to_cpu(rxhdr->mac_time);
444	chanstat = le16_to_cpu(rxhdr->channel);
445
446	if (macstat & B43legacy_RX_MAC_FCSERR)
447		dev->wl->ieee_stats.dot11FCSErrorCount++;
448
449	/* Skip PLCP and padding */
450	padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
451	if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
452	    padding))) {
453		b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
454		goto drop;
455	}
456	plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
457	skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
458	/* The skb contains the Wireless Header + payload data now */
459	if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
460		b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
461		goto drop;
462	}
463	wlhdr = (struct ieee80211_hdr *)(skb->data);
464	fctl = wlhdr->frame_control;
465
466	if ((macstat & B43legacy_RX_MAC_DEC) &&
467	    !(macstat & B43legacy_RX_MAC_DECERR)) {
468		unsigned int keyidx;
469		int wlhdr_len;
470		int iv_len;
471		int icv_len;
472
473		keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
474			  >> B43legacy_RX_MAC_KEYIDX_SHIFT);
475		/* We must adjust the key index here. We want the "physical"
476		 * key index, but the ucode passed it slightly different.
477		 */
478		keyidx = b43legacy_kidx_to_raw(dev, keyidx);
479		B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
480
481		if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
482			/* Remove PROTECTED flag to mark it as decrypted. */
483			B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
484			fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
485			wlhdr->frame_control = fctl;
486
487			wlhdr_len = ieee80211_hdrlen(fctl);
488			if (unlikely(skb->len < (wlhdr_len + 3))) {
489				b43legacydbg(dev->wl, "RX: Packet size"
490					     " underrun3\n");
491				goto drop;
492			}
493			if (skb->data[wlhdr_len + 3] & (1 << 5)) {
494				/* The Ext-IV Bit is set in the "KeyID"
495				 * octet of the IV.
496				 */
497				iv_len = 8;
498				icv_len = 8;
499			} else {
500				iv_len = 4;
501				icv_len = 4;
502			}
503			if (unlikely(skb->len < (wlhdr_len + iv_len +
504			    icv_len))) {
505				b43legacydbg(dev->wl, "RX: Packet size"
506					     " underrun4\n");
507				goto drop;
508			}
509			/* Remove the IV */
510			memmove(skb->data + iv_len, skb->data, wlhdr_len);
511			skb_pull(skb, iv_len);
512			/* Remove the ICV */
513			skb_trim(skb, skb->len - icv_len);
514
515			status.flag |= RX_FLAG_DECRYPTED;
516		}
517	}
518
519	status.signal = b43legacy_rssi_postprocess(dev, jssi,
520				      (phystat0 & B43legacy_RX_PHYST0_OFDM),
521				      (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
522				      (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
523	/* change to support A PHY */
524	if (phystat0 & B43legacy_RX_PHYST0_OFDM)
525		status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
526	else
527		status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
528	status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
529
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 (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
539		u16 low_mactime_now;
540
541		b43legacy_tsf_read(dev, &status.mactime);
542		low_mactime_now = status.mactime;
543		status.mactime = status.mactime & ~0xFFFFULL;
544		status.mactime += mactime;
545		if (low_mactime_now <= mactime)
546			status.mactime -= 0x10000;
547		status.flag |= RX_FLAG_MACTIME_START;
548	}
549
550	chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
551		  B43legacy_RX_CHAN_ID_SHIFT;
552	switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
553	case B43legacy_PHYTYPE_B:
554	case B43legacy_PHYTYPE_G:
555		status.band = NL80211_BAND_2GHZ;
556		status.freq = chanid + 2400;
557		break;
558	default:
559		b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
560		       chanstat);
561		goto drop;
562	}
563
564	memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
565	ieee80211_rx_irqsafe(dev->wl->hw, skb);
566
567	return;
568drop:
569	b43legacydbg(dev->wl, "RX: Packet dropped\n");
570	dev_kfree_skb_any(skb);
571}
572
573void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
574			     const struct b43legacy_txstatus *status)
575{
576	b43legacy_debugfs_log_txstat(dev, status);
577
578	if (status->intermediate)
579		return;
580	if (status->for_ampdu)
581		return;
582	if (!status->acked)
583		dev->wl->ieee_stats.dot11ACKFailureCount++;
584	if (status->rts_count) {
585		if (status->rts_count == 0xF) /* FIXME */
586			dev->wl->ieee_stats.dot11RTSFailureCount++;
587		else
588			dev->wl->ieee_stats.dot11RTSSuccessCount++;
589	}
590
591	if (b43legacy_using_pio(dev))
592		b43legacy_pio_handle_txstatus(dev, status);
593	else
594		b43legacy_dma_handle_txstatus(dev, status);
595}
596
597/* Handle TX status report as received through DMA/PIO queues */
598void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
599				 const struct b43legacy_hwtxstatus *hw)
600{
601	struct b43legacy_txstatus status;
602	u8 tmp;
603
604	status.cookie = le16_to_cpu(hw->cookie);
605	status.seq = le16_to_cpu(hw->seq);
606	status.phy_stat = hw->phy_stat;
607	tmp = hw->count;
608	status.frame_count = (tmp >> 4);
609	status.rts_count = (tmp & 0x0F);
610	tmp = hw->flags << 1;
611	status.supp_reason = ((tmp & 0x1C) >> 2);
612	status.pm_indicated = !!(tmp & 0x80);
613	status.intermediate = !!(tmp & 0x40);
614	status.for_ampdu = !!(tmp & 0x20);
615	status.acked = !!(tmp & 0x02);
616
617	b43legacy_handle_txstatus(dev, &status);
618}
619
620/* Stop any TX operation on the device (suspend the hardware queues) */
621void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
622{
623	if (b43legacy_using_pio(dev))
624		b43legacy_pio_freeze_txqueues(dev);
625	else
626		b43legacy_dma_tx_suspend(dev);
627}
628
629/* Resume any TX operation on the device (resume the hardware queues) */
630void b43legacy_tx_resume(struct b43legacy_wldev *dev)
631{
632	if (b43legacy_using_pio(dev))
633		b43legacy_pio_thaw_txqueues(dev);
634	else
635		b43legacy_dma_tx_resume(dev);
636}
637
638/* Initialize the QoS parameters */
639void b43legacy_qos_init(struct b43legacy_wldev *dev)
640{
641	/* FIXME: This function must probably be called from the mac80211
642	 * config callback. */
643return;
644
645	b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
646	/* FIXME kill magic */
647	b43legacy_write16(dev, 0x688,
648			  b43legacy_read16(dev, 0x688) | 0x4);
649
650
651	/*TODO: We might need some stack support here to get the values. */
652}
v4.17
 
  1/*
  2
  3  Broadcom B43legacy wireless driver
  4
  5  Transmission (TX/RX) related functions.
  6
  7  Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  8  Copyright (C) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  9  Copyright (C) 2005, 2006 Michael Buesch <m@bues.ch>
 10  Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
 11  Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
 12  Copyright (C) 2007 Larry Finger <Larry.Finger@lwfinger.net>
 13
 14  This program is free software; you can redistribute it and/or modify
 15  it under the terms of the GNU General Public License as published by
 16  the Free Software Foundation; either version 2 of the License, or
 17  (at your option) any later version.
 18
 19  This program is distributed in the hope that it will be useful,
 20  but WITHOUT ANY WARRANTY; without even the implied warranty of
 21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 22  GNU General Public License for more details.
 23
 24  You should have received a copy of the GNU General Public License
 25  along with this program; see the file COPYING.  If not, write to
 26  the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
 27  Boston, MA 02110-1301, USA.
 28
 29*/
 30
 31#include <net/dst.h>
 32
 33#include "xmit.h"
 34#include "phy.h"
 35#include "dma.h"
 36#include "pio.h"
 37
 38
 39/* Extract the bitrate out of a CCK PLCP header. */
 40static u8 b43legacy_plcp_get_bitrate_idx_cck(struct b43legacy_plcp_hdr6 *plcp)
 41{
 42	switch (plcp->raw[0]) {
 43	case 0x0A:
 44		return 0;
 45	case 0x14:
 46		return 1;
 47	case 0x37:
 48		return 2;
 49	case 0x6E:
 50		return 3;
 51	}
 52	B43legacy_BUG_ON(1);
 53	return -1;
 54}
 55
 56/* Extract the bitrate out of an OFDM PLCP header. */
 57static u8 b43legacy_plcp_get_bitrate_idx_ofdm(struct b43legacy_plcp_hdr6 *plcp,
 58					      bool aphy)
 59{
 60	int base = aphy ? 0 : 4;
 61
 62	switch (plcp->raw[0] & 0xF) {
 63	case 0xB:
 64		return base + 0;
 65	case 0xF:
 66		return base + 1;
 67	case 0xA:
 68		return base + 2;
 69	case 0xE:
 70		return base + 3;
 71	case 0x9:
 72		return base + 4;
 73	case 0xD:
 74		return base + 5;
 75	case 0x8:
 76		return base + 6;
 77	case 0xC:
 78		return base + 7;
 79	}
 80	B43legacy_BUG_ON(1);
 81	return -1;
 82}
 83
 84u8 b43legacy_plcp_get_ratecode_cck(const u8 bitrate)
 85{
 86	switch (bitrate) {
 87	case B43legacy_CCK_RATE_1MB:
 88		return 0x0A;
 89	case B43legacy_CCK_RATE_2MB:
 90		return 0x14;
 91	case B43legacy_CCK_RATE_5MB:
 92		return 0x37;
 93	case B43legacy_CCK_RATE_11MB:
 94		return 0x6E;
 95	}
 96	B43legacy_BUG_ON(1);
 97	return 0;
 98}
 99
100u8 b43legacy_plcp_get_ratecode_ofdm(const u8 bitrate)
101{
102	switch (bitrate) {
103	case B43legacy_OFDM_RATE_6MB:
104		return 0xB;
105	case B43legacy_OFDM_RATE_9MB:
106		return 0xF;
107	case B43legacy_OFDM_RATE_12MB:
108		return 0xA;
109	case B43legacy_OFDM_RATE_18MB:
110		return 0xE;
111	case B43legacy_OFDM_RATE_24MB:
112		return 0x9;
113	case B43legacy_OFDM_RATE_36MB:
114		return 0xD;
115	case B43legacy_OFDM_RATE_48MB:
116		return 0x8;
117	case B43legacy_OFDM_RATE_54MB:
118		return 0xC;
119	}
120	B43legacy_BUG_ON(1);
121	return 0;
122}
123
124void b43legacy_generate_plcp_hdr(struct b43legacy_plcp_hdr4 *plcp,
125				 const u16 octets, const u8 bitrate)
126{
127	__le32 *data = &(plcp->data);
128	__u8 *raw = plcp->raw;
129
130	if (b43legacy_is_ofdm_rate(bitrate)) {
131		u16 d;
132
133		d = b43legacy_plcp_get_ratecode_ofdm(bitrate);
134		B43legacy_WARN_ON(octets & 0xF000);
135		d |= (octets << 5);
136		*data = cpu_to_le32(d);
137	} else {
138		u32 plen;
139
140		plen = octets * 16 / bitrate;
141		if ((octets * 16 % bitrate) > 0) {
142			plen++;
143			if ((bitrate == B43legacy_CCK_RATE_11MB)
144			    && ((octets * 8 % 11) < 4))
145				raw[1] = 0x84;
146			else
147				raw[1] = 0x04;
148		} else
149			raw[1] = 0x04;
150		*data |= cpu_to_le32(plen << 16);
151		raw[0] = b43legacy_plcp_get_ratecode_cck(bitrate);
152	}
153}
154
155static u8 b43legacy_calc_fallback_rate(u8 bitrate)
156{
157	switch (bitrate) {
158	case B43legacy_CCK_RATE_1MB:
159		return B43legacy_CCK_RATE_1MB;
160	case B43legacy_CCK_RATE_2MB:
161		return B43legacy_CCK_RATE_1MB;
162	case B43legacy_CCK_RATE_5MB:
163		return B43legacy_CCK_RATE_2MB;
164	case B43legacy_CCK_RATE_11MB:
165		return B43legacy_CCK_RATE_5MB;
166	case B43legacy_OFDM_RATE_6MB:
167		return B43legacy_CCK_RATE_5MB;
168	case B43legacy_OFDM_RATE_9MB:
169		return B43legacy_OFDM_RATE_6MB;
170	case B43legacy_OFDM_RATE_12MB:
171		return B43legacy_OFDM_RATE_9MB;
172	case B43legacy_OFDM_RATE_18MB:
173		return B43legacy_OFDM_RATE_12MB;
174	case B43legacy_OFDM_RATE_24MB:
175		return B43legacy_OFDM_RATE_18MB;
176	case B43legacy_OFDM_RATE_36MB:
177		return B43legacy_OFDM_RATE_24MB;
178	case B43legacy_OFDM_RATE_48MB:
179		return B43legacy_OFDM_RATE_36MB;
180	case B43legacy_OFDM_RATE_54MB:
181		return B43legacy_OFDM_RATE_48MB;
182	}
183	B43legacy_BUG_ON(1);
184	return 0;
185}
186
187static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
188			       struct b43legacy_txhdr_fw3 *txhdr,
189			       const unsigned char *fragment_data,
190			       unsigned int fragment_len,
191			       struct ieee80211_tx_info *info,
192			       u16 cookie)
193{
194	const struct ieee80211_hdr *wlhdr;
195	int use_encryption = !!info->control.hw_key;
196	u8 rate;
197	struct ieee80211_rate *rate_fb;
198	int rate_ofdm;
199	int rate_fb_ofdm;
200	unsigned int plcp_fragment_len;
201	u32 mac_ctl = 0;
202	u16 phy_ctl = 0;
203	struct ieee80211_rate *tx_rate;
204	struct ieee80211_tx_rate *rates;
205
206	wlhdr = (const struct ieee80211_hdr *)fragment_data;
207
208	memset(txhdr, 0, sizeof(*txhdr));
209
210	tx_rate = ieee80211_get_tx_rate(dev->wl->hw, info);
211
212	rate = tx_rate->hw_value;
213	rate_ofdm = b43legacy_is_ofdm_rate(rate);
214	rate_fb = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : tx_rate;
215	rate_fb_ofdm = b43legacy_is_ofdm_rate(rate_fb->hw_value);
216
217	txhdr->mac_frame_ctl = wlhdr->frame_control;
218	memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN);
219
220	/* Calculate duration for fallback rate */
221	if ((rate_fb->hw_value == rate) ||
222	    (wlhdr->duration_id & cpu_to_le16(0x8000)) ||
223	    (wlhdr->duration_id == cpu_to_le16(0))) {
224		/* If the fallback rate equals the normal rate or the
225		 * dur_id field contains an AID, CFP magic or 0,
226		 * use the original dur_id field. */
227		txhdr->dur_fb = wlhdr->duration_id;
228	} else {
229		txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
230							 info->control.vif,
231							 info->band,
232							 fragment_len,
233							 rate_fb);
234	}
235
236	plcp_fragment_len = fragment_len + FCS_LEN;
237	if (use_encryption) {
238		u8 key_idx = info->control.hw_key->hw_key_idx;
239		struct b43legacy_key *key;
240		int wlhdr_len;
241		size_t iv_len;
242
243		B43legacy_WARN_ON(key_idx >= dev->max_nr_keys);
244		key = &(dev->key[key_idx]);
245
246		if (key->enabled) {
247			/* Hardware appends ICV. */
248			plcp_fragment_len += info->control.hw_key->icv_len;
249
250			key_idx = b43legacy_kidx_to_fw(dev, key_idx);
251			mac_ctl |= (key_idx << B43legacy_TX4_MAC_KEYIDX_SHIFT) &
252				   B43legacy_TX4_MAC_KEYIDX;
253			mac_ctl |= (key->algorithm <<
254				   B43legacy_TX4_MAC_KEYALG_SHIFT) &
255				   B43legacy_TX4_MAC_KEYALG;
256			wlhdr_len = ieee80211_hdrlen(wlhdr->frame_control);
257			iv_len = min_t(size_t, info->control.hw_key->iv_len,
258				     ARRAY_SIZE(txhdr->iv));
259			memcpy(txhdr->iv, ((u8 *)wlhdr) + wlhdr_len, iv_len);
260		} else {
261			/* This key is invalid. This might only happen
262			 * in a short timeframe after machine resume before
263			 * we were able to reconfigure keys.
264			 * Drop this packet completely. Do not transmit it
265			 * unencrypted to avoid leaking information. */
266			return -ENOKEY;
267		}
268	}
269	b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
270				    (&txhdr->plcp), plcp_fragment_len,
271				    rate);
272	b43legacy_generate_plcp_hdr(&txhdr->plcp_fb, plcp_fragment_len,
273				    rate_fb->hw_value);
274
275	/* PHY TX Control word */
276	if (rate_ofdm)
277		phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM;
278	if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
279		phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
280	phy_ctl |= B43legacy_TX4_PHY_ANTLAST;
281
282	/* MAC control */
283	rates = info->control.rates;
284	if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
285		mac_ctl |= B43legacy_TX4_MAC_ACK;
286	if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
287		mac_ctl |= B43legacy_TX4_MAC_HWSEQ;
288	if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
289		mac_ctl |= B43legacy_TX4_MAC_STMSDU;
290	if (rate_fb_ofdm)
291		mac_ctl |= B43legacy_TX4_MAC_FALLBACKOFDM;
292
293	/* Overwrite rates[0].count to make the retry calculation
294	 * in the tx status easier. need the actual retry limit to
295	 * detect whether the fallback rate was used.
296	 */
297	if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
298	    (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) {
299		rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count;
300		mac_ctl |= B43legacy_TX4_MAC_LONGFRAME;
301	} else {
302		rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count;
303	}
304
305	/* Generate the RTS or CTS-to-self frame */
306	if ((rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
307	    (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)) {
308		unsigned int len;
309		struct ieee80211_hdr *hdr;
310		int rts_rate;
311		int rts_rate_fb;
312		int rts_rate_fb_ofdm;
313
314		rts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info)->hw_value;
315		rts_rate_fb = b43legacy_calc_fallback_rate(rts_rate);
316		rts_rate_fb_ofdm = b43legacy_is_ofdm_rate(rts_rate_fb);
317		if (rts_rate_fb_ofdm)
318			mac_ctl |= B43legacy_TX4_MAC_CTSFALLBACKOFDM;
319
320		if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
321			ieee80211_ctstoself_get(dev->wl->hw,
322						info->control.vif,
323						fragment_data,
324						fragment_len, info,
325						(struct ieee80211_cts *)
326						(txhdr->rts_frame));
327			mac_ctl |= B43legacy_TX4_MAC_SENDCTS;
328			len = sizeof(struct ieee80211_cts);
329		} else {
330			ieee80211_rts_get(dev->wl->hw,
331					  info->control.vif,
332					  fragment_data, fragment_len, info,
333					  (struct ieee80211_rts *)
334					  (txhdr->rts_frame));
335			mac_ctl |= B43legacy_TX4_MAC_SENDRTS;
336			len = sizeof(struct ieee80211_rts);
337		}
338		len += FCS_LEN;
339		b43legacy_generate_plcp_hdr((struct b43legacy_plcp_hdr4 *)
340					    (&txhdr->rts_plcp),
341					    len, rts_rate);
342		b43legacy_generate_plcp_hdr(&txhdr->rts_plcp_fb,
343					    len, rts_rate_fb);
344		hdr = (struct ieee80211_hdr *)(&txhdr->rts_frame);
345		txhdr->rts_dur_fb = hdr->duration_id;
346	}
347
348	/* Magic cookie */
349	txhdr->cookie = cpu_to_le16(cookie);
350
351	/* Apply the bitfields */
352	txhdr->mac_ctl = cpu_to_le32(mac_ctl);
353	txhdr->phy_ctl = cpu_to_le16(phy_ctl);
354
355	return 0;
356}
357
358int b43legacy_generate_txhdr(struct b43legacy_wldev *dev,
359			      u8 *txhdr,
360			      const unsigned char *fragment_data,
361			      unsigned int fragment_len,
362			      struct ieee80211_tx_info *info,
363			      u16 cookie)
364{
365	return generate_txhdr_fw3(dev, (struct b43legacy_txhdr_fw3 *)txhdr,
366			   fragment_data, fragment_len,
367			   info, cookie);
368}
369
370static s8 b43legacy_rssi_postprocess(struct b43legacy_wldev *dev,
371				     u8 in_rssi, int ofdm,
372				     int adjust_2053, int adjust_2050)
373{
374	struct b43legacy_phy *phy = &dev->phy;
375	s32 tmp;
376
377	switch (phy->radio_ver) {
378	case 0x2050:
379		if (ofdm) {
380			tmp = in_rssi;
381			if (tmp > 127)
382				tmp -= 256;
383			tmp *= 73;
384			tmp /= 64;
385			if (adjust_2050)
386				tmp += 25;
387			else
388				tmp -= 3;
389		} else {
390			if (dev->dev->bus->sprom.boardflags_lo
391			    & B43legacy_BFL_RSSI) {
392				if (in_rssi > 63)
393					in_rssi = 63;
394				tmp = phy->nrssi_lt[in_rssi];
395				tmp = 31 - tmp;
396				tmp *= -131;
397				tmp /= 128;
398				tmp -= 57;
399			} else {
400				tmp = in_rssi;
401				tmp = 31 - tmp;
402				tmp *= -149;
403				tmp /= 128;
404				tmp -= 68;
405			}
406			if (phy->type == B43legacy_PHYTYPE_G &&
407			    adjust_2050)
408				tmp += 25;
409		}
410		break;
411	case 0x2060:
412		if (in_rssi > 127)
413			tmp = in_rssi - 256;
414		else
415			tmp = in_rssi;
416		break;
417	default:
418		tmp = in_rssi;
419		tmp -= 11;
420		tmp *= 103;
421		tmp /= 64;
422		if (adjust_2053)
423			tmp -= 109;
424		else
425			tmp -= 83;
426	}
427
428	return (s8)tmp;
429}
430
431void b43legacy_rx(struct b43legacy_wldev *dev,
432		  struct sk_buff *skb,
433		  const void *_rxhdr)
434{
435	struct ieee80211_rx_status status;
436	struct b43legacy_plcp_hdr6 *plcp;
437	struct ieee80211_hdr *wlhdr;
438	const struct b43legacy_rxhdr_fw3 *rxhdr = _rxhdr;
439	__le16 fctl;
440	u16 phystat0;
441	u16 phystat3;
442	u16 chanstat;
443	u16 mactime;
444	u32 macstat;
445	u16 chanid;
446	u8 jssi;
447	int padding;
448
449	memset(&status, 0, sizeof(status));
450
451	/* Get metadata about the frame from the header. */
452	phystat0 = le16_to_cpu(rxhdr->phy_status0);
453	phystat3 = le16_to_cpu(rxhdr->phy_status3);
454	jssi = rxhdr->jssi;
455	macstat = le16_to_cpu(rxhdr->mac_status);
456	mactime = le16_to_cpu(rxhdr->mac_time);
457	chanstat = le16_to_cpu(rxhdr->channel);
458
459	if (macstat & B43legacy_RX_MAC_FCSERR)
460		dev->wl->ieee_stats.dot11FCSErrorCount++;
461
462	/* Skip PLCP and padding */
463	padding = (macstat & B43legacy_RX_MAC_PADDING) ? 2 : 0;
464	if (unlikely(skb->len < (sizeof(struct b43legacy_plcp_hdr6) +
465	    padding))) {
466		b43legacydbg(dev->wl, "RX: Packet size underrun (1)\n");
467		goto drop;
468	}
469	plcp = (struct b43legacy_plcp_hdr6 *)(skb->data + padding);
470	skb_pull(skb, sizeof(struct b43legacy_plcp_hdr6) + padding);
471	/* The skb contains the Wireless Header + payload data now */
472	if (unlikely(skb->len < (2+2+6/*minimum hdr*/ + FCS_LEN))) {
473		b43legacydbg(dev->wl, "RX: Packet size underrun (2)\n");
474		goto drop;
475	}
476	wlhdr = (struct ieee80211_hdr *)(skb->data);
477	fctl = wlhdr->frame_control;
478
479	if ((macstat & B43legacy_RX_MAC_DEC) &&
480	    !(macstat & B43legacy_RX_MAC_DECERR)) {
481		unsigned int keyidx;
482		int wlhdr_len;
483		int iv_len;
484		int icv_len;
485
486		keyidx = ((macstat & B43legacy_RX_MAC_KEYIDX)
487			  >> B43legacy_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 = b43legacy_kidx_to_raw(dev, keyidx);
492		B43legacy_WARN_ON(keyidx >= dev->max_nr_keys);
493
494		if (dev->key[keyidx].algorithm != B43legacy_SEC_ALGO_NONE) {
495			/* Remove PROTECTED flag to mark it as decrypted. */
496			B43legacy_WARN_ON(!ieee80211_has_protected(fctl));
497			fctl &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
498			wlhdr->frame_control = fctl;
499
500			wlhdr_len = ieee80211_hdrlen(fctl);
501			if (unlikely(skb->len < (wlhdr_len + 3))) {
502				b43legacydbg(dev->wl, "RX: Packet size"
503					     " underrun3\n");
504				goto drop;
505			}
506			if (skb->data[wlhdr_len + 3] & (1 << 5)) {
507				/* The Ext-IV Bit is set in the "KeyID"
508				 * octet of the IV.
509				 */
510				iv_len = 8;
511				icv_len = 8;
512			} else {
513				iv_len = 4;
514				icv_len = 4;
515			}
516			if (unlikely(skb->len < (wlhdr_len + iv_len +
517			    icv_len))) {
518				b43legacydbg(dev->wl, "RX: Packet size"
519					     " underrun4\n");
520				goto drop;
521			}
522			/* Remove the IV */
523			memmove(skb->data + iv_len, skb->data, wlhdr_len);
524			skb_pull(skb, iv_len);
525			/* Remove the ICV */
526			skb_trim(skb, skb->len - icv_len);
527
528			status.flag |= RX_FLAG_DECRYPTED;
529		}
530	}
531
532	status.signal = b43legacy_rssi_postprocess(dev, jssi,
533				      (phystat0 & B43legacy_RX_PHYST0_OFDM),
534				      (phystat0 & B43legacy_RX_PHYST0_GAINCTL),
535				      (phystat3 & B43legacy_RX_PHYST3_TRSTATE));
536	/* change to support A PHY */
537	if (phystat0 & B43legacy_RX_PHYST0_OFDM)
538		status.rate_idx = b43legacy_plcp_get_bitrate_idx_ofdm(plcp, false);
539	else
540		status.rate_idx = b43legacy_plcp_get_bitrate_idx_cck(plcp);
541	status.antenna = !!(phystat0 & B43legacy_RX_PHYST0_ANT);
542
543	/*
544	 * All frames on monitor interfaces and beacons always need a full
545	 * 64-bit timestamp. Monitor interfaces need it for diagnostic
546	 * purposes and beacons for IBSS merging.
547	 * This code assumes we get to process the packet within 16 bits
548	 * of timestamp, i.e. about 65 milliseconds after the PHY received
549	 * the first symbol.
550	 */
551	if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) {
552		u16 low_mactime_now;
553
554		b43legacy_tsf_read(dev, &status.mactime);
555		low_mactime_now = status.mactime;
556		status.mactime = status.mactime & ~0xFFFFULL;
557		status.mactime += mactime;
558		if (low_mactime_now <= mactime)
559			status.mactime -= 0x10000;
560		status.flag |= RX_FLAG_MACTIME_START;
561	}
562
563	chanid = (chanstat & B43legacy_RX_CHAN_ID) >>
564		  B43legacy_RX_CHAN_ID_SHIFT;
565	switch (chanstat & B43legacy_RX_CHAN_PHYTYPE) {
566	case B43legacy_PHYTYPE_B:
567	case B43legacy_PHYTYPE_G:
568		status.band = NL80211_BAND_2GHZ;
569		status.freq = chanid + 2400;
570		break;
571	default:
572		b43legacywarn(dev->wl, "Unexpected value for chanstat (0x%X)\n",
573		       chanstat);
 
574	}
575
576	memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
577	ieee80211_rx_irqsafe(dev->wl->hw, skb);
578
579	return;
580drop:
581	b43legacydbg(dev->wl, "RX: Packet dropped\n");
582	dev_kfree_skb_any(skb);
583}
584
585void b43legacy_handle_txstatus(struct b43legacy_wldev *dev,
586			     const struct b43legacy_txstatus *status)
587{
588	b43legacy_debugfs_log_txstat(dev, status);
589
590	if (status->intermediate)
591		return;
592	if (status->for_ampdu)
593		return;
594	if (!status->acked)
595		dev->wl->ieee_stats.dot11ACKFailureCount++;
596	if (status->rts_count) {
597		if (status->rts_count == 0xF) /* FIXME */
598			dev->wl->ieee_stats.dot11RTSFailureCount++;
599		else
600			dev->wl->ieee_stats.dot11RTSSuccessCount++;
601	}
602
603	if (b43legacy_using_pio(dev))
604		b43legacy_pio_handle_txstatus(dev, status);
605	else
606		b43legacy_dma_handle_txstatus(dev, status);
607}
608
609/* Handle TX status report as received through DMA/PIO queues */
610void b43legacy_handle_hwtxstatus(struct b43legacy_wldev *dev,
611				 const struct b43legacy_hwtxstatus *hw)
612{
613	struct b43legacy_txstatus status;
614	u8 tmp;
615
616	status.cookie = le16_to_cpu(hw->cookie);
617	status.seq = le16_to_cpu(hw->seq);
618	status.phy_stat = hw->phy_stat;
619	tmp = hw->count;
620	status.frame_count = (tmp >> 4);
621	status.rts_count = (tmp & 0x0F);
622	tmp = hw->flags << 1;
623	status.supp_reason = ((tmp & 0x1C) >> 2);
624	status.pm_indicated = !!(tmp & 0x80);
625	status.intermediate = !!(tmp & 0x40);
626	status.for_ampdu = !!(tmp & 0x20);
627	status.acked = !!(tmp & 0x02);
628
629	b43legacy_handle_txstatus(dev, &status);
630}
631
632/* Stop any TX operation on the device (suspend the hardware queues) */
633void b43legacy_tx_suspend(struct b43legacy_wldev *dev)
634{
635	if (b43legacy_using_pio(dev))
636		b43legacy_pio_freeze_txqueues(dev);
637	else
638		b43legacy_dma_tx_suspend(dev);
639}
640
641/* Resume any TX operation on the device (resume the hardware queues) */
642void b43legacy_tx_resume(struct b43legacy_wldev *dev)
643{
644	if (b43legacy_using_pio(dev))
645		b43legacy_pio_thaw_txqueues(dev);
646	else
647		b43legacy_dma_tx_resume(dev);
648}
649
650/* Initialize the QoS parameters */
651void b43legacy_qos_init(struct b43legacy_wldev *dev)
652{
653	/* FIXME: This function must probably be called from the mac80211
654	 * config callback. */
655return;
656
657	b43legacy_hf_write(dev, b43legacy_hf_read(dev) | B43legacy_HF_EDCF);
658	/* FIXME kill magic */
659	b43legacy_write16(dev, 0x688,
660			  b43legacy_read16(dev, 0x688) | 0x4);
661
662
663	/*TODO: We might need some stack support here to get the values. */
664}