Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jan 2008 03:04:07 GMT
From:      Sam Leffler <sam@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 134279 for review
Message-ID:  <200801280304.m0S347A3089152@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=134279

Change 134279 by sam@sam_ebb on 2008/01/28 03:03:29

	checkpoint sephe's pending changes (hand transcribed) so I can work
	on ap mode

Affected files ...

.. //depot/projects/vap/sys/dev/ral/rt2560.c#11 edit
.. //depot/projects/vap/sys/dev/ral/rt2560reg.h#3 edit
.. //depot/projects/vap/sys/dev/ral/rt2560var.h#7 edit

Differences ...

==== //depot/projects/vap/sys/dev/ral/rt2560.c#11 (text) ====

@@ -158,7 +158,7 @@
 static void		rt2560_get_macaddr(struct rt2560_softc *, uint8_t *);
 static void		rt2560_update_promisc(struct rt2560_softc *);
 static const char	*rt2560_get_rf(int);
-static void		rt2560_read_eeprom(struct rt2560_softc *);
+static void		rt2560_read_config(struct rt2560_softc *);
 static int		rt2560_bbp_init(struct rt2560_softc *);
 static void		rt2560_set_txantenna(struct rt2560_softc *, int);
 static void		rt2560_set_rxantenna(struct rt2560_softc *, int);
@@ -220,7 +220,7 @@
 	rt2560_get_macaddr(sc, ic->ic_myaddr);
 
 	/* retrieve RF rev. no and various other things from EEPROM */
-	rt2560_read_eeprom(sc);
+	rt2560_read_config(sc);
 
 	device_printf(dev, "MAC/BBP RT2560 (rev 0x%02x), RF %s\n",
 	    sc->asic_rev, rt2560_get_rf(sc->rf_rev));
@@ -358,7 +358,6 @@
 	
 	rt2560_stop(sc);
 	RAL_LOCK(sc);
-	callout_stop(&sc->watchdog_ch);
 	callout_stop(&sc->rssadapt_ch);
 
 	bpfdetach(ifp);
@@ -916,7 +915,13 @@
 	bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map,
 	    BUS_DMASYNC_POSTREAD);
 
-	for (; sc->txq.next_encrypt != hw;) {
+	while (sc->txq.next_encrypt != hw) {
+		if (sc->txq.next_encrypt == sc->txq.cur_encrypt) {
+			printf("hw encrypt %d, cur_encrypt %d\n", hw,
+			    sc->txq.cur_encrypt);
+			break;
+		}
+
 		desc = &sc->txq.desc[sc->txq.next_encrypt];
 
 		if ((le32toh(desc->flags) & RT2560_TX_BUSY) ||
@@ -1022,9 +1027,16 @@
 	bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map,
 	    BUS_DMASYNC_PREWRITE);
 
-	sc->sc_tx_timer = 0;
-	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-	rt2560_start(ifp);
+	if (sc->prioq.queued == 0 && sc->txq.queued == 0)
+		sc->sc_tx_timer = 0;
+
+	if (sc->txq.queued < RT2560_TX_RING_COUNT - 1) {
+		sc->sc_flags &= ~RT2560_F_DATA_OACTIVE;
+		if ((sc->sc_flags &
+		    (RT2560_F_DATA_OACTIVE | RT2560_F_PRIO_OACTIVE)) == 0)
+			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+		rt2560_start(ifp);
+	}
 }
 
 static void
@@ -1100,9 +1112,16 @@
 	bus_dmamap_sync(sc->prioq.desc_dmat, sc->prioq.desc_map,
 	    BUS_DMASYNC_PREWRITE);
 
-	sc->sc_tx_timer = 0;
-	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
-	rt2560_start(ifp);
+	if (sc->prioq.queued == 0 && sc->txq.queued == 0)
+		sc->sc_tx_timer = 0;
+
+	if (sc->txq.queued < RT2560_PRIO_RING_COUNT - 1) {
+		sc->sc_flags &= ~RT2560_F_PRIO_OACTIVE;
+		if ((sc->sc_flags &
+		    (RT2560_F_DATA_OACTIVE | RT2560_F_PRIO_OACTIVE)) == 0)
+			ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+		rt2560_start(ifp);
+	}
 }
 
 /*
@@ -1218,7 +1237,7 @@
 			bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m);
 		}
 
-		sc->sc_flags |= RAL_INPUT_RUNNING;
+		sc->sc_flags |= RT2560_F_INPUT_RUNNING;
 		RAL_UNLOCK(sc);
 		wh = mtod(m, struct ieee80211_frame *);
 		ni = ieee80211_find_rxnode(ic,
@@ -1238,7 +1257,7 @@
 			    RT2560_RSSI(sc, desc->rssi), RT2560_NOISE_FLOOR, 0);
 
 		RAL_LOCK(sc);
-		sc->sc_flags &= ~RAL_INPUT_RUNNING;
+		sc->sc_flags &= ~RT2560_F_INPUT_RUNNING;
 skip:		desc->flags = htole32(RT2560_RX_BUSY);
 
 		DPRINTFN(sc, 15, "decryption done idx=%u\n", sc->rxq.cur_decrypt);
@@ -1396,8 +1415,10 @@
 	if (r & RT2560_DECRYPTION_DONE)
 		rt2560_decryption_intr(sc);
 
-	if (r & RT2560_RX_DONE)
+	if (r & RT2560_RX_DONE) {
 		rt2560_rx_intr(sc);
+		rt2560_encryption_intr(sc);
+	}
 
 	/* re-enable interrupts */
 	RAL_WRITE(sc, RT2560_CSR8, RT2560_INTR_MASK);
@@ -1475,8 +1496,6 @@
 
 	desc->flags = htole32(flags);
 	desc->flags |= htole32(len << 16);
-	desc->flags |= encrypt ? htole32(RT2560_TX_CIPHER_BUSY) :
-	    htole32(RT2560_TX_BUSY | RT2560_TX_VALID);
 
 	desc->physaddr = htole32(physaddr);
 	desc->wme = htole16(
@@ -1508,6 +1527,11 @@
 		if (rate != 2 && (ic->ic_flags & IEEE80211_F_SHPREAMBLE))
 			desc->plcp_signal |= 0x08;
 	}
+
+	if (!encrypt)
+		desc->flags |= htole32(RT2560_TX_VALID);
+	desc->flags |= encrypt ? htole32(RT2560_TX_CIPHER_BUSY) :
+				 htole32(RT2560_TX_BUSY);
 }
 
 static int
@@ -1970,6 +1994,7 @@
 		if (sc->txq.queued >= RT2560_TX_RING_COUNT - 1) {
 			IFQ_DRV_PREPEND(&ifp->if_snd, m);
 			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+			sc->sc_flags |= RT2560_F_DATA_OACTIVE;
 			break;
 		}
 
@@ -1988,7 +2013,6 @@
 		}
 
 		sc->sc_tx_timer = 5;
-		callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc);
 	}
 
 	RAL_UNLOCK(sc);
@@ -1998,16 +2022,24 @@
 rt2560_watchdog(void *arg)
 {
 	struct rt2560_softc *sc = arg;
+	struct ifnet *ifp = sc->sc_ifp;
 
+	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+		return;
+
+	rt2560_encryption_intr(sc);
+	rt2560_tx_intr(sc);
+
 	if (sc->sc_tx_timer > 0) {
 		if (--sc->sc_tx_timer == 0) {
 			device_printf(sc->sc_dev, "device timeout\n");
 			rt2560_init(sc);
-			sc->sc_ifp->if_oerrors++;
+			ifp->if_oerrors++;
 			return;
 		}
 		callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc);
 	}
+	callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc);
 }
 
 static int
@@ -2063,6 +2095,16 @@
 	uint32_t val;
 	int ntries;
 
+	for (ntries = 0; ntries < 100; ntries++) {
+		if (!(RAL_READ(sc, RT2560_BBPCSR) & RT2560_BBP_BUSY))
+			break;
+		DELAY(1);
+	}
+	if (ntries == 100) {
+		device_printf(sc->sc_dev, "could not read from BBP\n");
+		return 0;
+	}
+
 	val = RT2560_BBP_BUSY | reg << 8;
 	RAL_WRITE(sc, RT2560_BBPCSR, val);
 
@@ -2438,7 +2480,7 @@
 }
 
 static void
-rt2560_read_eeprom(struct rt2560_softc *sc)
+rt2560_read_config(struct rt2560_softc *sc)
 {
 	uint16_t val;
 	int i;
@@ -2454,6 +2496,9 @@
 	/* read default values for BBP registers */
 	for (i = 0; i < 16; i++) {
 		val = rt2560_eeprom_read(sc, RT2560_EEPROM_BBP_BASE + i);
+		if (val == 0 || val == 0xffff)
+			continue;
+
 		sc->bbp_prom[i].reg = val >> 8;
 		sc->bbp_prom[i].val = val & 0xff;
 	}
@@ -2461,8 +2506,12 @@
 	/* read Tx power for all b/g channels */
 	for (i = 0; i < 14 / 2; i++) {
 		val = rt2560_eeprom_read(sc, RT2560_EEPROM_TXPOWER + i);
-		sc->txpow[i * 2] = val >> 8;
-		sc->txpow[i * 2 + 1] = val & 0xff;
+		sc->txpow[i * 2] = val & 0xff;
+		sc->txpow[i * 2 + 1] = val >> 8;
+	}
+	for (i = 0; i < 14; i++) {
+		if (sc->txpow[i] > 31)
+			sc->txpow[i] = 24;
 	}
 
 	val = rt2560_eeprom_read(sc, RT2560_EEPROM_CALIBRATE);
@@ -2520,14 +2569,14 @@
 		rt2560_bbp_write(sc, rt2560_def_bbp[i].reg,
 		    rt2560_def_bbp[i].val);
 	}
-#if 0
+
 	/* initialize BBP registers to values stored in EEPROM */
 	for (i = 0; i < 16; i++) {
-		if (sc->bbp_prom[i].reg == 0xff)
+		if (sc->bbp_prom[i].reg == 0 && sc->bbp_prom[i].val == 0)
 			continue;
 		rt2560_bbp_write(sc, sc->bbp_prom[i].reg, sc->bbp_prom[i].val);
 	}
-#endif
+	rt2560_bbp_write(sc, 17, 0x48); /* XXX restore bbp17 */
 
 	return 0;
 #undef N
@@ -2622,8 +2671,6 @@
 	/* set basic rate set (will be updated later) */
 	RAL_WRITE(sc, RT2560_ARSP_PLCP_1, 0x153);
 
-	rt2560_set_txantenna(sc, sc->tx_ant);
-	rt2560_set_rxantenna(sc, sc->rx_ant);
 	rt2560_update_slot(ifp);
 	rt2560_update_plcp(sc);
 	rt2560_update_led(sc, 0, 0);
@@ -2637,6 +2684,9 @@
 		return;
 	}
 
+	rt2560_set_txantenna(sc, sc->tx_ant);
+	rt2560_set_rxantenna(sc, sc->rx_ant);
+
 	/* set default BSS channel */
 	rt2560_set_chan(sc, ic->ic_curchan);
 
@@ -2664,6 +2714,8 @@
 	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
 	ifp->if_drv_flags |= IFF_DRV_RUNNING;
 
+	callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc);
+
 	ieee80211_start_all(ic);		/* start all vap's */
 
 	RAL_UNLOCK(sc);
@@ -2678,13 +2730,15 @@
 	struct ifnet *ifp = ic->ic_ifp;
 	volatile int *flags = &sc->sc_flags;
 
-	while (*flags & RAL_INPUT_RUNNING) {
+	while (*flags & RT2560_F_INPUT_RUNNING) {
 		tsleep(sc, 0, "ralrunning", hz/10);
 	}
 
 	RAL_LOCK(sc);
+
+	callout_stop(&sc->watchdog_ch);
+
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
-		sc->sc_tx_timer = 0;
 		ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
 
 		/* abort Tx */
@@ -2707,6 +2761,9 @@
 		rt2560_reset_tx_ring(sc, &sc->bcnq);
 		rt2560_reset_rx_ring(sc, &sc->rxq);
 	}
+	sc->sc_tx_timer = 0;
+	sc->sc_flags &= ~(RT2560_F_PRIO_OACTIVE | RT2560_F_DATA_OACTIVE);
+
 	RAL_UNLOCK(sc);
 }
 
@@ -2729,6 +2786,7 @@
 	}
 	if (sc->prioq.queued >= RT2560_PRIO_RING_COUNT) {
 		ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+		sc->sc_flags |= RT2560_F_PRIO_OACTIVE;
 		RAL_UNLOCK(sc);
 		m_freem(m);
 		ieee80211_free_node(ni);
@@ -2753,7 +2811,6 @@
 			goto bad;
 	}
 	sc->sc_tx_timer = 5;
-	callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc);
 
 	RAL_UNLOCK(sc);
 

==== //depot/projects/vap/sys/dev/ral/rt2560reg.h#3 (text) ====

@@ -333,8 +333,8 @@
 	{ RT2560_TXCSR1,      0x07614562 },	\
 	{ RT2560_ARSP_PLCP_0, 0x8c8d8b8a },	\
 	{ RT2560_ACKPCTCSR,   0x7038140a },	\
-	{ RT2560_ARTCSR1,     0x1d21252d },	\
-	{ RT2560_ARTCSR2,     0x1919191d },	\
+	{ RT2560_ARTCSR1,     0x21212929 },	\
+	{ RT2560_ARTCSR2,     0x1d1d1d1d },	\
 	{ RT2560_RXCSR0,      0xffffffff },	\
 	{ RT2560_RXCSR3,      0xb3aab3af },	\
 	{ RT2560_PCICSR,      0x000003b8 },	\

==== //depot/projects/vap/sys/dev/ral/rt2560var.h#7 (text) ====

@@ -159,8 +159,10 @@
 
 	struct rt2560_tx_radiotap_header sc_txtap;
 	int			sc_txtap_len;
-#define                 RAL_INPUT_RUNNING       1
 	int                     sc_flags;
+#define	RT2560_F_INPUT_RUNNING	0x1
+#define	RT2560_F_PRIO_OACTIVE	0x2
+#define	RT2560_F_DATA_OACTIVE	0x4
 };
 
 int	rt2560_attach(device_t, int);



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