Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Nov 2017 00:17:53 +0000 (UTC)
From:      Andriy Voskoboinyk <avos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325303 - head/sys/dev/usb/wlan
Message-ID:  <201711020017.vA20HrNN099254@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avos
Date: Thu Nov  2 00:17:52 2017
New Revision: 325303
URL: https://svnweb.freebsd.org/changeset/base/325303

Log:
  rsu(4): trim code for Rx rate calculation.
  
  Include ridx <-> rate conversion functions from rtwn(4) +
  reuse already calculated value for ieee80211_radiotap(9).
  
  Tested with Asus USB-N10, STA mode.

Modified:
  head/sys/dev/usb/wlan/if_rsu.c

Modified: head/sys/dev/usb/wlan/if_rsu.c
==============================================================================
--- head/sys/dev/usb/wlan/if_rsu.c	Wed Nov  1 23:20:04 2017	(r325302)
+++ head/sys/dev/usb/wlan/if_rsu.c	Thu Nov  2 00:17:52 2017	(r325303)
@@ -68,8 +68,11 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb/usbdi.h>
 #include "usbdevs.h"
 
+#include <dev/rtwn/if_rtwn_ridx.h>	/* XXX */
 #include <dev/usb/wlan/if_rsureg.h>
 
+#define RSU_RATE_IS_CCK	RTWN_RATE_IS_CCK
+
 #ifdef USB_DEBUG
 static int rsu_debug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, rsu, CTLFLAG_RW, 0, "USB rsu");
@@ -2382,44 +2385,6 @@ rsu_rx_frame(struct rsu_softc *sc, struct mbuf *m)
 		rssi = rsu_hwrssi_to_rssi(sc, sc->sc_currssi);
 	}
 
-	if (ieee80211_radiotap_active(ic)) {
-		struct rsu_rx_radiotap_header *tap = &sc->sc_rxtap;
-
-		/* Map HW rate index to 802.11 rate. */
-		tap->wr_flags = 0;		/* TODO */
-		tap->wr_tsft = rsu_get_tsf_high(sc);
-		if (le32toh(stat->tsf_low) > rsu_get_tsf_low(sc))
-			tap->wr_tsft--;
-		tap->wr_tsft = (uint64_t)htole32(tap->wr_tsft) << 32;
-		tap->wr_tsft += stat->tsf_low;
-
-		if (rate < 12) {
-			switch (rate) {
-			/* CCK. */
-			case  0: tap->wr_rate =   2; break;
-			case  1: tap->wr_rate =   4; break;
-			case  2: tap->wr_rate =  11; break;
-			case  3: tap->wr_rate =  22; break;
-			/* OFDM. */
-			case  4: tap->wr_rate =  12; break;
-			case  5: tap->wr_rate =  18; break;
-			case  6: tap->wr_rate =  24; break;
-			case  7: tap->wr_rate =  36; break;
-			case  8: tap->wr_rate =  48; break;
-			case  9: tap->wr_rate =  72; break;
-			case 10: tap->wr_rate =  96; break;
-			case 11: tap->wr_rate = 108; break;
-			}
-		} else {			/* MCS0~15. */
-			/* Bit 7 set means HT MCS instead of rate. */
-			tap->wr_rate = 0x80 | (rate - 12);
-		}
-
-		tap->wr_dbm_antsignal = rssi;
-		tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
-		tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
-	};
-
 	/* Hardware does Rx TCP checksum offload. */
 	/*
 	 * This flag can be set for some other
@@ -2465,64 +2430,33 @@ rsu_rx_frame(struct rsu_softc *sc, struct mbuf *m)
 	rxs.c_nf = -96;
 
 	/* Rate */
-	if (!(rxdw3 & R92S_RXDW3_HTC)) {
-		switch (rate) {
-		/* CCK. */
-		case 0:
-			rxs.c_rate = 2;
+	if (rate < 12) {
+		rxs.c_rate = ridx2rate[rate];
+		if (RSU_RATE_IS_CCK(rate))
 			rxs.c_pktflags |= IEEE80211_RX_F_CCK;
-			break;
-		case 1:
-			rxs.c_rate = 4;
-			rxs.c_pktflags |= IEEE80211_RX_F_CCK;
-			break;
-		case 2:
-			rxs.c_rate = 11;
-			rxs.c_pktflags |= IEEE80211_RX_F_CCK;
-			break;
-		case 3:
-			rxs.c_rate = 22;
-			rxs.c_pktflags |= IEEE80211_RX_F_CCK;
-			break;
-		/* OFDM. */
-		case 4:
-			rxs.c_rate = 12;
+		else
 			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 5:
-			rxs.c_rate = 18;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 6:
-			rxs.c_rate = 24;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 7:
-			rxs.c_rate = 36;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 8:
-			rxs.c_rate = 48;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 9:
-			rxs.c_rate = 72;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 10:
-			rxs.c_rate = 96;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		case 11:
-			rxs.c_rate = 108;
-			rxs.c_pktflags |= IEEE80211_RX_F_OFDM;
-			break;
-		}
-	} else if (rate >= 12) {	/* MCS0~15. */
-		/* Bit 7 set means HT MCS instead of rate. */
-		rxs.c_rate = (rate - 12);
+	} else {
+		rxs.c_rate = IEEE80211_RATE_MCS | (rate - 12);
 		rxs.c_pktflags |= IEEE80211_RX_F_HT;
 	}
+
+	if (ieee80211_radiotap_active(ic)) {
+		struct rsu_rx_radiotap_header *tap = &sc->sc_rxtap;
+
+		/* Map HW rate index to 802.11 rate. */
+		tap->wr_flags = 0;		/* TODO */
+		tap->wr_tsft = rsu_get_tsf_high(sc);
+		if (le32toh(stat->tsf_low) > rsu_get_tsf_low(sc))
+			tap->wr_tsft--;
+		tap->wr_tsft = (uint64_t)htole32(tap->wr_tsft) << 32;
+		tap->wr_tsft += stat->tsf_low;
+
+		tap->wr_rate = rxs.c_rate;
+		tap->wr_dbm_antsignal = rssi;
+		tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq);
+		tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
+	};
 
 	(void) ieee80211_add_rx_params(m, &rxs);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711020017.vA20HrNN099254>