PERFORCE change 136365 for review

Sam Leffler sam at FreeBSD.org
Wed Feb 27 20:06:39 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=136365

Change 136365 by sam at sam_ebb on 2008/02/27 20:06:21

	load rt2661 firmware with firmware(9); still needs files glue

Affected files ...

.. //depot/projects/vap/sys/contrib/dev/ral/LICENSE#1 add
.. //depot/projects/vap/sys/contrib/dev/ral/Makefile#1 add
.. //depot/projects/vap/sys/contrib/dev/ral/rt2561.fw.uu#1 add
.. //depot/projects/vap/sys/contrib/dev/ral/rt2561s.fw.uu#1 add
.. //depot/projects/vap/sys/contrib/dev/ral/rt2661.fw.uu#1 add
.. //depot/projects/vap/sys/contrib/dev/ral/rt2661_ucode.h#1 add
.. //depot/projects/vap/sys/dev/ral/if_ral_pci.c#6 edit
.. //depot/projects/vap/sys/dev/ral/rt2661.c#16 edit
.. //depot/projects/vap/sys/dev/ral/rt2661_ucode.h#3 delete
.. //depot/projects/vap/sys/dev/ral/rt2661var.h#8 edit

Differences ...

==== //depot/projects/vap/sys/dev/ral/if_ral_pci.c#6 (text+ko) ====

@@ -59,6 +59,7 @@
 #include <dev/ral/rt2661var.h>
 
 MODULE_DEPEND(ral, pci, 1, 1, 1);
+MODULE_DEPEND(ral, firmware, 1, 1, 1);
 MODULE_DEPEND(ral, wlan, 1, 1, 1);
 MODULE_DEPEND(ral, wlan_rssadapt, 1, 1, 1);
 

==== //depot/projects/vap/sys/dev/ral/rt2661.c#16 (text) ====

@@ -38,6 +38,7 @@
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/endian.h>
+#include <sys/firmware.h>
 
 #include <machine/bus.h>
 #include <machine/resource.h>
@@ -64,7 +65,6 @@
 
 #include <dev/ral/rt2661reg.h>
 #include <dev/ral/rt2661var.h>
-#include <dev/ral/rt2661_ucode.h>
 
 #define RAL_DEBUG
 #ifdef RAL_DEBUG
@@ -163,8 +163,7 @@
 static void		rt2661_init(void *);
 static void		rt2661_stop(void *);
 static void             rt2661_stop_locked(struct rt2661_softc *);
-static int		rt2661_load_microcode(struct rt2661_softc *,
-			    const uint8_t *, int);
+static int		rt2661_load_microcode(struct rt2661_softc *);
 #ifdef notyet
 static void		rt2661_rx_tune(struct rt2661_softc *);
 static void		rt2661_radar_start(struct rt2661_softc *);
@@ -205,10 +204,10 @@
 	struct ieee80211com *ic = &sc->sc_ic;
 	struct ifnet *ifp;
 	uint32_t val;
-	const uint8_t *ucode = NULL;
-	int error, ac, ntries, size = 0;
+	int error, ac, ntries;
 	uint8_t bands;
 
+	sc->sc_id = id;
 	sc->sc_dev = dev;
 
 	mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
@@ -236,30 +235,6 @@
 	    rt2661_get_rf(sc->rf_rev));
 
 	/*
-	 * Load 8051 microcode into NIC.
-	 */
-	switch (id) {
-	case 0x0301:
-		ucode = rt2561s_ucode;
-		size = sizeof rt2561s_ucode;
-		break;
-	case 0x0302:
-		ucode = rt2561_ucode;
-		size = sizeof rt2561_ucode;
-		break;
-	case 0x0401:
-		ucode = rt2661_ucode;
-		size = sizeof rt2661_ucode;
-		break;
-	}
-
-	error = rt2661_load_microcode(sc, ucode, size);
-	if (error != 0) {
-		device_printf(sc->sc_dev, "could not load 8051 microcode\n");
-		goto fail1;
-	}
-
-	/*
 	 * Allocate Tx and Rx rings.
 	 */
 	for (ac = 0; ac < 4; ac++) {
@@ -2508,10 +2483,22 @@
 	struct ieee80211com *ic = &sc->sc_ic;
 	struct ifnet *ifp = ic->ic_ifp;
 	uint32_t tmp, sta[3];
-	int i, ntries;
+	int i, error, ntries;
 
 	RAL_LOCK(sc);
 
+	if ((sc->sc_flags & RAL_FW_LOADED) == 0) {
+		error = rt2661_load_microcode(sc);
+		if (error != 0) {
+			if_printf(ifp,
+			    "%s: could not load 8051 microcode, error %d\n",
+			    __func__, error);
+			RAL_UNLOCK(sc);
+			return;
+		}
+		sc->sc_flags |= RAL_FW_LOADED;
+	}
+
 	rt2661_stop_locked(sc);
 
 	/* initialize Tx rings */
@@ -2684,10 +2671,37 @@
 }
 
 static int
-rt2661_load_microcode(struct rt2661_softc *sc, const uint8_t *ucode, int size)
+rt2661_load_microcode(struct rt2661_softc *sc)
 {
-	int ntries;
+	struct ifnet *ifp = sc->sc_ifp;
+	const struct firmware *fp;
+	const char *imagename;
+	int ntries, error;
+
+	RAL_LOCK_ASSERT(sc);
+
+	switch (sc->sc_id) {
+	case 0x0301: imagename = "rt2561sfw"; break;
+	case 0x0302: imagename = "rt2561fw"; break;
+	case 0x0401: imagename = "rt2661fw"; break;
+	default:
+		if_printf(ifp, "%s: unexpected pci device id 0x%x, "
+		    "don't know how to retrieve firmware\n",
+		    __func__, sc->sc_id);
+		return EINVAL;
+	}
+	RAL_UNLOCK(sc);
+	fp = firmware_get(imagename);
+	RAL_LOCK(sc);
+	if (fp == NULL) {
+		if_printf(ifp, "%s: unable to retrieve firmware image %s\n",
+		    __func__, imagename);
+		return EINVAL;
+	}
 
+	/*
+	 * Load 8051 microcode into NIC.
+	 */
 	/* reset 8051 */
 	RAL_WRITE(sc, RT2661_MCU_CNTL_CSR, RT2661_MCU_RESET);
 
@@ -2698,7 +2712,7 @@
 
 	/* write 8051's microcode */
 	RAL_WRITE(sc, RT2661_MCU_CNTL_CSR, RT2661_MCU_RESET | RT2661_MCU_SEL);
-	RAL_WRITE_REGION_1(sc, RT2661_MCU_CODE_BASE, ucode, size);
+	RAL_WRITE_REGION_1(sc, RT2661_MCU_CODE_BASE, fp->data, fp->datasize);
 	RAL_WRITE(sc, RT2661_MCU_CNTL_CSR, RT2661_MCU_RESET);
 
 	/* kick 8051's ass */
@@ -2711,10 +2725,14 @@
 		DELAY(100);
 	}
 	if (ntries == 500) {
-		printf("timeout waiting for MCU to initialize\n");
-		return EIO;
-	}
-	return 0;
+		if_printf(ifp, "%s: timeout waiting for MCU to initialize\n",
+		    __func__);
+		error = EIO;
+	} else
+		error = 0;
+
+	firmware_put(fp, FIRMWARE_UNLOAD);
+	return error;
 }
 
 #ifdef notyet

==== //depot/projects/vap/sys/dev/ral/rt2661var.h#8 (text) ====

@@ -121,6 +121,10 @@
  * ------------------------------------------------
  */
 	
+	int                             sc_flags;
+#define	RAL_FW_LOADED		0x1
+#define	RAL_INPUT_RUNNING	0x2
+	int				sc_id;
 	struct ieee80211_channel	*sc_curchan;
 
 	uint8_t				rf_rev;
@@ -160,11 +164,8 @@
 
 	struct rt2661_rx_radiotap_header sc_rxtap;
 	int				sc_rxtap_len;
-
 	struct rt2661_tx_radiotap_header sc_txtap;
 	int				sc_txtap_len;
-#define                 RAL_INPUT_RUNNING       1
-	int                             sc_flags;
 };
 
 int	rt2661_attach(device_t, int);
@@ -174,5 +175,6 @@
 void	rt2661_resume(void *);
 void	rt2661_intr(void *);
 
-#define RAL_LOCK(sc)	mtx_lock(&(sc)->sc_mtx)
-#define RAL_UNLOCK(sc)	mtx_unlock(&(sc)->sc_mtx)
+#define RAL_LOCK(sc)		mtx_lock(&(sc)->sc_mtx)
+#define RAL_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
+#define RAL_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mtx)


More information about the p4-projects mailing list