rt2661.c (184345) | rt2661.c (190526) |
---|---|
1/* $FreeBSD: head/sys/dev/ral/rt2661.c 184345 2008-10-27 16:46:50Z sam $ */ | 1/* $FreeBSD: head/sys/dev/ral/rt2661.c 190526 2009-03-29 17:59:14Z sam $ */ |
2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> | 2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> |
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 184345 2008-10-27 16:46:50Z sam $"); | 21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 190526 2009-03-29 17:59:14Z sam $"); |
22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 120 unchanged lines hidden (view full) --- 150 const uint8_t *); 151static void rt2661_set_macaddr(struct rt2661_softc *, 152 const uint8_t *); 153static void rt2661_update_promisc(struct ifnet *); 154static int rt2661_wme_update(struct ieee80211com *) __unused; 155static void rt2661_update_slot(struct ifnet *); 156static const char *rt2661_get_rf(int); 157static void rt2661_read_eeprom(struct rt2661_softc *, | 22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 120 unchanged lines hidden (view full) --- 150 const uint8_t *); 151static void rt2661_set_macaddr(struct rt2661_softc *, 152 const uint8_t *); 153static void rt2661_update_promisc(struct ifnet *); 154static int rt2661_wme_update(struct ieee80211com *) __unused; 155static void rt2661_update_slot(struct ifnet *); 156static const char *rt2661_get_rf(int); 157static void rt2661_read_eeprom(struct rt2661_softc *, |
158 struct ieee80211com *); | 158 uint8_t macaddr[IEEE80211_ADDR_LEN]); |
159static int rt2661_bbp_init(struct rt2661_softc *); 160static void rt2661_init_locked(struct rt2661_softc *); 161static void rt2661_init(void *); 162static void rt2661_stop_locked(struct rt2661_softc *); 163static void rt2661_stop(void *); 164static int rt2661_load_microcode(struct rt2661_softc *); 165#ifdef notyet 166static void rt2661_rx_tune(struct rt2661_softc *); --- 32 unchanged lines hidden (view full) --- 199rt2661_attach(device_t dev, int id) 200{ 201 struct rt2661_softc *sc = device_get_softc(dev); 202 struct ieee80211com *ic; 203 struct ifnet *ifp; 204 uint32_t val; 205 int error, ac, ntries; 206 uint8_t bands; | 159static int rt2661_bbp_init(struct rt2661_softc *); 160static void rt2661_init_locked(struct rt2661_softc *); 161static void rt2661_init(void *); 162static void rt2661_stop_locked(struct rt2661_softc *); 163static void rt2661_stop(void *); 164static int rt2661_load_microcode(struct rt2661_softc *); 165#ifdef notyet 166static void rt2661_rx_tune(struct rt2661_softc *); --- 32 unchanged lines hidden (view full) --- 199rt2661_attach(device_t dev, int id) 200{ 201 struct rt2661_softc *sc = device_get_softc(dev); 202 struct ieee80211com *ic; 203 struct ifnet *ifp; 204 uint32_t val; 205 int error, ac, ntries; 206 uint8_t bands; |
207 uint8_t macaddr[IEEE80211_ADDR_LEN]; |
|
207 208 sc->sc_id = id; 209 sc->sc_dev = dev; 210 211 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); 212 if (ifp == NULL) { 213 device_printf(sc->sc_dev, "can not if_alloc()\n"); 214 return ENOMEM; --- 14 unchanged lines hidden (view full) --- 229 if (ntries == 1000) { 230 device_printf(sc->sc_dev, 231 "timeout waiting for NIC to initialize\n"); 232 error = EIO; 233 goto fail1; 234 } 235 236 /* retrieve RF rev. no and various other things from EEPROM */ | 208 209 sc->sc_id = id; 210 sc->sc_dev = dev; 211 212 ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); 213 if (ifp == NULL) { 214 device_printf(sc->sc_dev, "can not if_alloc()\n"); 215 return ENOMEM; --- 14 unchanged lines hidden (view full) --- 230 if (ntries == 1000) { 231 device_printf(sc->sc_dev, 232 "timeout waiting for NIC to initialize\n"); 233 error = EIO; 234 goto fail1; 235 } 236 237 /* retrieve RF rev. no and various other things from EEPROM */ |
237 rt2661_read_eeprom(sc, ic); | 238 rt2661_read_eeprom(sc, macaddr); |
238 239 device_printf(dev, "MAC/BBP RT%X, RF %s\n", val, 240 rt2661_get_rf(sc->rf_rev)); 241 242 /* 243 * Allocate Tx and Rx rings. 244 */ 245 for (ac = 0; ac < 4; ac++) { --- 52 unchanged lines hidden (view full) --- 298 299 bands = 0; 300 setbit(&bands, IEEE80211_MODE_11B); 301 setbit(&bands, IEEE80211_MODE_11G); 302 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) 303 setbit(&bands, IEEE80211_MODE_11A); 304 ieee80211_init_channels(ic, NULL, &bands); 305 | 239 240 device_printf(dev, "MAC/BBP RT%X, RF %s\n", val, 241 rt2661_get_rf(sc->rf_rev)); 242 243 /* 244 * Allocate Tx and Rx rings. 245 */ 246 for (ac = 0; ac < 4; ac++) { --- 52 unchanged lines hidden (view full) --- 299 300 bands = 0; 301 setbit(&bands, IEEE80211_MODE_11B); 302 setbit(&bands, IEEE80211_MODE_11G); 303 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) 304 setbit(&bands, IEEE80211_MODE_11A); 305 ieee80211_init_channels(ic, NULL, &bands); 306 |
306 ieee80211_ifattach(ic); | 307 ieee80211_ifattach(ic, macaddr); |
307 ic->ic_newassoc = rt2661_newassoc; 308 ic->ic_node_alloc = rt2661_node_alloc; 309#if 0 310 ic->ic_wme.wme_update = rt2661_wme_update; 311#endif 312 ic->ic_scan_start = rt2661_scan_start; 313 ic->ic_scan_end = rt2661_scan_end; 314 ic->ic_set_channel = rt2661_set_channel; --- 1899 unchanged lines hidden (view full) --- 2214 case RT2661_RF_5325: return "RT5325 (MIMO XR)"; 2215 case RT2661_RF_2527: return "RT2527"; 2216 case RT2661_RF_2529: return "RT2529 (MIMO XR)"; 2217 default: return "unknown"; 2218 } 2219} 2220 2221static void | 308 ic->ic_newassoc = rt2661_newassoc; 309 ic->ic_node_alloc = rt2661_node_alloc; 310#if 0 311 ic->ic_wme.wme_update = rt2661_wme_update; 312#endif 313 ic->ic_scan_start = rt2661_scan_start; 314 ic->ic_scan_end = rt2661_scan_end; 315 ic->ic_set_channel = rt2661_set_channel; --- 1899 unchanged lines hidden (view full) --- 2215 case RT2661_RF_5325: return "RT5325 (MIMO XR)"; 2216 case RT2661_RF_2527: return "RT2527"; 2217 case RT2661_RF_2529: return "RT2529 (MIMO XR)"; 2218 default: return "unknown"; 2219 } 2220} 2221 2222static void |
2222rt2661_read_eeprom(struct rt2661_softc *sc, struct ieee80211com *ic) | 2223rt2661_read_eeprom(struct rt2661_softc *sc, uint8_t macaddr[IEEE80211_ADDR_LEN]) |
2223{ 2224 uint16_t val; 2225 int i; 2226 2227 /* read MAC address */ 2228 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC01); | 2224{ 2225 uint16_t val; 2226 int i; 2227 2228 /* read MAC address */ 2229 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC01); |
2229 ic->ic_myaddr[0] = val & 0xff; 2230 ic->ic_myaddr[1] = val >> 8; | 2230 macaddr[0] = val & 0xff; 2231 macaddr[1] = val >> 8; |
2231 2232 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC23); | 2232 2233 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC23); |
2233 ic->ic_myaddr[2] = val & 0xff; 2234 ic->ic_myaddr[3] = val >> 8; | 2234 macaddr[2] = val & 0xff; 2235 macaddr[3] = val >> 8; |
2235 2236 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC45); | 2236 2237 val = rt2661_eeprom_read(sc, RT2661_EEPROM_MAC45); |
2237 ic->ic_myaddr[4] = val & 0xff; 2238 ic->ic_myaddr[5] = val >> 8; | 2238 macaddr[4] = val & 0xff; 2239 macaddr[5] = val >> 8; |
2239 2240 val = rt2661_eeprom_read(sc, RT2661_EEPROM_ANTENNA); 2241 /* XXX: test if different from 0xffff? */ 2242 sc->rf_rev = (val >> 11) & 0x1f; 2243 sc->hw_radio = (val >> 10) & 0x1; 2244 sc->rx_ant = (val >> 4) & 0x3; 2245 sc->tx_ant = (val >> 2) & 0x3; 2246 sc->nb_ant = val & 0x3; --- 161 unchanged lines hidden (view full) --- 2408 2409 /* load base address of Rx ring */ 2410 RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 2); 2411 2412 /* initialize MAC registers to default values */ 2413 for (i = 0; i < N(rt2661_def_mac); i++) 2414 RAL_WRITE(sc, rt2661_def_mac[i].reg, rt2661_def_mac[i].val); 2415 | 2240 2241 val = rt2661_eeprom_read(sc, RT2661_EEPROM_ANTENNA); 2242 /* XXX: test if different from 0xffff? */ 2243 sc->rf_rev = (val >> 11) & 0x1f; 2244 sc->hw_radio = (val >> 10) & 0x1; 2245 sc->rx_ant = (val >> 4) & 0x3; 2246 sc->tx_ant = (val >> 2) & 0x3; 2247 sc->nb_ant = val & 0x3; --- 161 unchanged lines hidden (view full) --- 2409 2410 /* load base address of Rx ring */ 2411 RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 2); 2412 2413 /* initialize MAC registers to default values */ 2414 for (i = 0; i < N(rt2661_def_mac); i++) 2415 RAL_WRITE(sc, rt2661_def_mac[i].reg, rt2661_def_mac[i].val); 2416 |
2416 IEEE80211_ADDR_COPY(ic->ic_myaddr, IF_LLADDR(ifp)); 2417 rt2661_set_macaddr(sc, ic->ic_myaddr); | 2417 rt2661_set_macaddr(sc, IF_LLADDR(ifp)); |
2418 2419 /* set host ready */ 2420 RAL_WRITE(sc, RT2661_MAC_CSR1, 3); 2421 RAL_WRITE(sc, RT2661_MAC_CSR1, 0); 2422 2423 /* wait for BBP/RF to wakeup */ 2424 for (ntries = 0; ntries < 1000; ntries++) { 2425 if (RAL_READ(sc, RT2661_MAC_CSR12) & 8) --- 467 unchanged lines hidden --- | 2418 2419 /* set host ready */ 2420 RAL_WRITE(sc, RT2661_MAC_CSR1, 3); 2421 RAL_WRITE(sc, RT2661_MAC_CSR1, 0); 2422 2423 /* wait for BBP/RF to wakeup */ 2424 for (ntries = 0; ntries < 1000; ntries++) { 2425 if (RAL_READ(sc, RT2661_MAC_CSR12) & 8) --- 467 unchanged lines hidden --- |