Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic Unmodified OpenBSD sources (except Ids)
details: https://anonhg.NetBSD.org/src/rev/6f96be072f7f
branches: trunk
changeset: 344899:6f96be072f7f
user: christos <christos%NetBSD.org@localhost>
date: Tue Apr 26 21:17:20 2016 +0000
description:
Unmodified OpenBSD sources (except Ids)
diffstat:
sys/dev/ic/rt2860.c | 3810 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/ic/rt2860reg.h | 616 +++++++-
sys/dev/ic/rt2860var.h | 211 ++
3 files changed, 4586 insertions(+), 51 deletions(-)
diffs (truncated from 4783 to 300 lines):
diff -r ca2ddc0e699a -r 6f96be072f7f sys/dev/ic/rt2860.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/rt2860.c Tue Apr 26 21:17:20 2016 +0000
@@ -0,0 +1,3810 @@
+/* $OpenBSD: rt2860.c,v 1.90 2016/04/13 10:49:26 mpi Exp $ */
+
+/*-
+ * Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini%free.fr@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*-
+ * Ralink Technology RT2860/RT3090/RT3390/RT3562 chipset driver
+ * http://www.ralinktech.com/
+ */
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+#include <sys/timeout.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/endian.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_amrr.h>
+#include <net80211/ieee80211_radiotap.h>
+
+#include <dev/ic/rt2860var.h>
+#include <dev/ic/rt2860reg.h>
+
+#include <dev/pci/pcidevs.h>
+
+#ifdef RAL_DEBUG
+#define DPRINTF(x) do { if (rt2860_debug > 0) printf x; } while (0)
+#define DPRINTFN(n, x) do { if (rt2860_debug >= (n)) printf x; } while (0)
+int rt2860_debug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n, x)
+#endif
+
+void rt2860_attachhook(struct device *);
+int rt2860_alloc_tx_ring(struct rt2860_softc *,
+ struct rt2860_tx_ring *);
+void rt2860_reset_tx_ring(struct rt2860_softc *,
+ struct rt2860_tx_ring *);
+void rt2860_free_tx_ring(struct rt2860_softc *,
+ struct rt2860_tx_ring *);
+int rt2860_alloc_tx_pool(struct rt2860_softc *);
+void rt2860_free_tx_pool(struct rt2860_softc *);
+int rt2860_alloc_rx_ring(struct rt2860_softc *,
+ struct rt2860_rx_ring *);
+void rt2860_reset_rx_ring(struct rt2860_softc *,
+ struct rt2860_rx_ring *);
+void rt2860_free_rx_ring(struct rt2860_softc *,
+ struct rt2860_rx_ring *);
+struct ieee80211_node *rt2860_node_alloc(struct ieee80211com *);
+int rt2860_media_change(struct ifnet *);
+void rt2860_iter_func(void *, struct ieee80211_node *);
+void rt2860_updatestats(struct rt2860_softc *);
+void rt2860_newassoc(struct ieee80211com *, struct ieee80211_node *,
+ int);
+void rt2860_node_leave(struct ieee80211com *,
+ struct ieee80211_node *);
+int rt2860_ampdu_rx_start(struct ieee80211com *,
+ struct ieee80211_node *, uint8_t);
+void rt2860_ampdu_rx_stop(struct ieee80211com *,
+ struct ieee80211_node *, uint8_t);
+int rt2860_newstate(struct ieee80211com *, enum ieee80211_state,
+ int);
+uint16_t rt3090_efuse_read_2(struct rt2860_softc *, uint16_t);
+uint16_t rt2860_eeprom_read_2(struct rt2860_softc *, uint16_t);
+void rt2860_intr_coherent(struct rt2860_softc *);
+void rt2860_drain_stats_fifo(struct rt2860_softc *);
+void rt2860_tx_intr(struct rt2860_softc *, int);
+void rt2860_rx_intr(struct rt2860_softc *);
+void rt2860_tbtt_intr(struct rt2860_softc *);
+void rt2860_gp_intr(struct rt2860_softc *);
+int rt2860_tx(struct rt2860_softc *, struct mbuf *,
+ struct ieee80211_node *);
+void rt2860_start(struct ifnet *);
+void rt2860_watchdog(struct ifnet *);
+int rt2860_ioctl(struct ifnet *, u_long, caddr_t);
+void rt2860_mcu_bbp_write(struct rt2860_softc *, uint8_t, uint8_t);
+uint8_t rt2860_mcu_bbp_read(struct rt2860_softc *, uint8_t);
+void rt2860_rf_write(struct rt2860_softc *, uint8_t, uint32_t);
+uint8_t rt3090_rf_read(struct rt2860_softc *, uint8_t);
+void rt3090_rf_write(struct rt2860_softc *, uint8_t, uint8_t);
+int rt2860_mcu_cmd(struct rt2860_softc *, uint8_t, uint16_t, int);
+void rt2860_enable_mrr(struct rt2860_softc *);
+void rt2860_set_txpreamble(struct rt2860_softc *);
+void rt2860_set_basicrates(struct rt2860_softc *);
+void rt2860_select_chan_group(struct rt2860_softc *, int);
+void rt2860_set_chan(struct rt2860_softc *, u_int);
+void rt3090_set_chan(struct rt2860_softc *, u_int);
+int rt3090_rf_init(struct rt2860_softc *);
+void rt3090_rf_wakeup(struct rt2860_softc *);
+int rt3090_filter_calib(struct rt2860_softc *, uint8_t, uint8_t,
+ uint8_t *);
+void rt3090_rf_setup(struct rt2860_softc *);
+void rt2860_set_leds(struct rt2860_softc *, uint16_t);
+void rt2860_set_gp_timer(struct rt2860_softc *, int);
+void rt2860_set_bssid(struct rt2860_softc *, const uint8_t *);
+void rt2860_set_macaddr(struct rt2860_softc *, const uint8_t *);
+void rt2860_updateslot(struct ieee80211com *);
+void rt2860_updateprot(struct ieee80211com *);
+void rt2860_updateedca(struct ieee80211com *);
+int rt2860_set_key(struct ieee80211com *, struct ieee80211_node *,
+ struct ieee80211_key *);
+void rt2860_delete_key(struct ieee80211com *,
+ struct ieee80211_node *, struct ieee80211_key *);
+#if NBPFILTER > 0
+int8_t rt2860_rssi2dbm(struct rt2860_softc *, uint8_t, uint8_t);
+#endif
+const char * rt2860_get_rf(uint8_t);
+int rt2860_read_eeprom(struct rt2860_softc *);
+int rt2860_bbp_init(struct rt2860_softc *);
+int rt2860_txrx_enable(struct rt2860_softc *);
+int rt2860_init(struct ifnet *);
+void rt2860_stop(struct ifnet *, int);
+int rt2860_load_microcode(struct rt2860_softc *);
+void rt2860_calib(struct rt2860_softc *);
+void rt3090_set_rx_antenna(struct rt2860_softc *, int);
+void rt2860_switch_chan(struct rt2860_softc *,
+ struct ieee80211_channel *);
+#ifndef IEEE80211_STA_ONLY
+int rt2860_setup_beacon(struct rt2860_softc *);
+#endif
+void rt2860_enable_tsf_sync(struct rt2860_softc *);
+
+static const struct {
+ uint32_t reg;
+ uint32_t val;
+} rt2860_def_mac[] = {
+ RT2860_DEF_MAC
+};
+
+static const struct {
+ uint8_t reg;
+ uint8_t val;
+} rt2860_def_bbp[] = {
+ RT2860_DEF_BBP
+};
+
+static const struct rfprog {
+ uint8_t chan;
+ uint32_t r1, r2, r3, r4;
+} rt2860_rf2850[] = {
+ RT2860_RF2850
+};
+
+struct {
+ uint8_t n, r, k;
+} rt3090_freqs[] = {
+ RT3070_RF3052
+};
+
+static const struct {
+ uint8_t reg;
+ uint8_t val;
+} rt3090_def_rf[] = {
+ RT3070_DEF_RF
+}, rt3572_def_rf[] = {
+ RT3572_DEF_RF
+};
+
+int
+rt2860_attach(void *xsc, int id)
+{
+ struct rt2860_softc *sc = xsc;
+ struct ieee80211com *ic = &sc->sc_ic;
+ int qid, ntries, error;
+ uint32_t tmp;
+
+ sc->amrr.amrr_min_success_threshold = 1;
+ sc->amrr.amrr_max_success_threshold = 15;
+
+ /* wait for NIC to initialize */
+ for (ntries = 0; ntries < 100; ntries++) {
+ tmp = RAL_READ(sc, RT2860_ASIC_VER_ID);
+ if (tmp != 0 && tmp != 0xffffffff)
+ break;
+ DELAY(10);
+ }
+ if (ntries == 100) {
+ printf("%s: timeout waiting for NIC to initialize\n",
+ sc->sc_dev.dv_xname);
+ return ETIMEDOUT;
+ }
+ sc->mac_ver = tmp >> 16;
+ sc->mac_rev = tmp & 0xffff;
+
+ if (sc->mac_ver != 0x2860 &&
+ (id == PCI_PRODUCT_RALINK_RT2890 ||
+ id == PCI_PRODUCT_RALINK_RT2790 ||
+ id == PCI_PRODUCT_AWT_RT2890))
+ sc->sc_flags |= RT2860_ADVANCED_PS;
+
+ /* retrieve RF rev. no and various other things from EEPROM */
+ rt2860_read_eeprom(sc);
+ printf(", address %s\n", ether_sprintf(ic->ic_myaddr));
+ printf("%s: MAC/BBP RT%X (rev 0x%04X), RF %s (MIMO %dT%dR)\n",
+ sc->sc_dev.dv_xname, sc->mac_ver, sc->mac_rev,
+ rt2860_get_rf(sc->rf_rev), sc->ntxchains, sc->nrxchains);
+
+ /*
+ * Allocate Tx (4 EDCAs + HCCA + Mgt) and Rx rings.
+ */
+ for (qid = 0; qid < 6; qid++) {
+ if ((error = rt2860_alloc_tx_ring(sc, &sc->txq[qid])) != 0) {
+ printf("%s: could not allocate Tx ring %d\n",
+ sc->sc_dev.dv_xname, qid);
+ goto fail1;
+ }
+ }
+
+ if ((error = rt2860_alloc_rx_ring(sc, &sc->rxq)) != 0) {
+ printf("%s: could not allocate Rx ring\n",
+ sc->sc_dev.dv_xname);
+ goto fail1;
+ }
+
+ if ((error = rt2860_alloc_tx_pool(sc)) != 0) {
+ printf("%s: could not allocate Tx pool\n",
+ sc->sc_dev.dv_xname);
+ goto fail2;
+ }
+
+ /* mgmt ring is broken on RT2860C, use EDCA AC VO ring instead */
+ sc->mgtqid = (sc->mac_ver == 0x2860 && sc->mac_rev == 0x0100) ?
+ EDCA_AC_VO : 5;
+
+ config_mountroot(xsc, rt2860_attachhook);
+
+ return 0;
+
+fail2: rt2860_free_rx_ring(sc, &sc->rxq);
+fail1: while (--qid >= 0)
+ rt2860_free_tx_ring(sc, &sc->txq[qid]);
+ return error;
+}
+
+void
+rt2860_attachhook(struct device *self)
+{
+ struct rt2860_softc *sc = (struct rt2860_softc *)self;
+ struct ieee80211com *ic = &sc->sc_ic;
+ struct ifnet *ifp = &ic->ic_if;
+ int i, error;
+
+ error = loadfirmware("ral-rt2860", &sc->ucode, &sc->ucsize);
+ if (error != 0) {
+ printf("%s: error %d, could not read firmware file %s\n",
+ sc->sc_dev.dv_xname, error, "ral-rt2860");
+ return;
+ }
+
+ ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
+ ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
+ ic->ic_state = IEEE80211_S_INIT;
+
+ /* set device capabilities */
+ ic->ic_caps =
+ IEEE80211_C_MONITOR | /* monitor mode supported */
+#ifndef IEEE80211_STA_ONLY
+ IEEE80211_C_IBSS | /* IBSS mode supported */
+ IEEE80211_C_HOSTAP | /* HostAP mode supported */
+ IEEE80211_C_APPMGT | /* HostAP power management */
Home |
Main Index |
Thread Index |
Old Index