Module Name:    src
Committed By:   nakayama
Date:           Wed Apr 25 05:14:05 UTC 2012

Modified Files:
        src/sys/dev/ic: bwi.c

Log Message:
Fix alignment and endian bugs observed on sparc64.
Also apply some minor fix from FreeBSD.

Tested with Buffalo WLI-CB-G54 (BCM4306) and WLI3-CB-G54L (BCM4318)
on i386 and sparc64.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/ic/bwi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/bwi.c
diff -u src/sys/dev/ic/bwi.c:1.21 src/sys/dev/ic/bwi.c:1.22
--- src/sys/dev/ic/bwi.c:1.21	Sat Apr 14 02:15:01 2012
+++ src/sys/dev/ic/bwi.c	Wed Apr 25 05:14:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bwi.c,v 1.21 2012/04/14 02:15:01 nakayama Exp $	*/
+/*	$NetBSD: bwi.c,v 1.22 2012/04/25 05:14:05 nakayama Exp $	*/
 /*	$OpenBSD: bwi.c,v 1.74 2008/02/25 21:13:30 mglocker Exp $	*/
 
 /*
@@ -48,7 +48,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.21 2012/04/14 02:15:01 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.22 2012/04/25 05:14:05 nakayama Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -361,7 +361,7 @@ static uint8_t	 bwi_ieee80211_rate2plcp(
 static uint8_t	 bwi_ieee80211_plcp2rate(uint8_t rate, enum ieee80211_phymode);
 static enum bwi_ieee80211_modtype
 		 bwi_ieee80211_rate2modtype(uint8_t rate);
-static uint8_t	 bwi_ofdm_plcp2rate(const uint32_t *);
+static uint8_t	 bwi_ofdm_plcp2rate(const void *);
 static uint8_t	 bwi_ds_plcp2rate(const struct ieee80211_ds_plcp_hdr *);
 static void	 bwi_ofdm_plcp_header(uint32_t *, int, uint8_t);
 static void	 bwi_ds_plcp_header(struct ieee80211_ds_plcp_hdr *, int,
@@ -3178,7 +3178,7 @@ bwi_phy_init_11g(struct bwi_mac *mac)
 			RF_WRITE(mac, 0x52,
 			    (tpctl->tp_ctrl1 << 4) | tpctl->tp_ctrl2);
 		} else {
-			RF_FILT_SETBITS(mac, 0x52, 0xfff0, tpctl->tp_ctrl1);
+			RF_FILT_SETBITS(mac, 0x52, 0xfff0, tpctl->tp_ctrl2);
 		}
 
 		if (phy->phy_rev >= 6) {
@@ -8768,12 +8768,13 @@ bwi_ieee80211_rate2modtype(uint8_t rate)
 }
 
 static uint8_t
-bwi_ofdm_plcp2rate(const uint32_t *plcp0)
+bwi_ofdm_plcp2rate(const void *plcp0)
 {
 	uint32_t plcp;
 	uint8_t plcp_rate;
 
-	plcp = le32toh(*plcp0);
+	/* plcp0 may not be 32-bit aligned. */
+	plcp = le32dec(plcp0);
 	plcp_rate = __SHIFTOUT(plcp, IEEE80211_OFDM_PLCP_RATE_MASK);
 
 	return (bwi_ieee80211_plcp2rate(plcp_rate, IEEE80211_MODE_11G));
@@ -9105,8 +9106,9 @@ bwi_encap(struct bwi_softc *sc, int idx,
 		hdr->txh_fb_duration = htole16(dur);
 	}
 
-	hdr->txh_id = __SHIFTIN(BWI_TX_DATA_RING, BWI_TXH_ID_RING_MASK) |
-	    __SHIFTIN(idx, BWI_TXH_ID_IDX_MASK);
+	hdr->txh_id = htole16(
+	    __SHIFTIN(BWI_TX_DATA_RING, BWI_TXH_ID_RING_MASK) |
+	    __SHIFTIN(idx, BWI_TXH_ID_IDX_MASK));
 
 	bwi_plcp_header(hdr->txh_plcp, pkt_len, rate);
 	/* [TRC: XXX Use fallback rate.] */
@@ -9324,9 +9326,7 @@ bwi_txeof_status(struct bwi_softc *sc, i
 	while (idx != end_idx) {
 		/* [TRC: XXX Filter this out if it is not pending; see
 		   DragonFlyBSD's revision 1.5. */
-		/* [TRC: XXX be16toh is wrong, probably due to the
-		   build environment] */
-		_bwi_txeof(sc, be16toh(st->stats[idx].txs_id));
+		_bwi_txeof(sc, le16toh(st->stats[idx].txs_id));
 		idx = (idx + 1) % BWI_TXSTATS_NDESC;
 	}
 	st->stats_idx = idx;
@@ -9342,7 +9342,7 @@ bwi_txeof(struct bwi_softc *sc)
 		uint16_t tx_id, tx_info;
 
 		tx_status0 = CSR_READ_4(sc, BWI_TXSTATUS_0);
-		if (tx_status0 == 0)
+		if ((tx_status0 & BWI_TXSTATUS_0_MORE) == 0)
 			break;
 		tx_status1 = CSR_READ_4(sc, BWI_TXSTATUS_1);
 
@@ -9352,7 +9352,7 @@ bwi_txeof(struct bwi_softc *sc)
 		if (tx_info & 0x30) /* XXX */
 			continue;
 
-		_bwi_txeof(sc, le16toh(tx_id));
+		_bwi_txeof(sc, tx_id);
 
 		ifp->if_opackets++;
 	}

Reply via email to