Date: Mon, 2 May 2016 22:58:11 +0000 (UTC) From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298948 - in head/sys: conf dev/bwn modules/bwn Message-ID: <201605022258.u42MwB4q075269@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: adrian Date: Mon May 2 22:58:11 2016 New Revision: 298948 URL: https://svnweb.freebsd.org/changeset/base/298948 Log: [bwn] break out the 'g' phy code into a separate source file. * Break out the 'g' phy code; * Break out the debugging bits into a separate source file, since some debugging prints are done in the phy code; * Make some more chip methods in if_bwn.c public. This brings the size of if_bwn.c down to 6,805 lines which is now approaching managable. Added: head/sys/dev/bwn/if_bwn_debug.h (contents, props changed) head/sys/dev/bwn/if_bwn_phy_g.c (contents, props changed) head/sys/dev/bwn/if_bwn_phy_g.h (contents, props changed) Modified: head/sys/conf/files head/sys/dev/bwn/if_bwn.c head/sys/dev/bwn/if_bwn_misc.h head/sys/dev/bwn/if_bwn_phy_lp.c head/sys/modules/bwn/Makefile Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Mon May 2 22:30:46 2016 (r298947) +++ head/sys/conf/files Mon May 2 22:58:11 2016 (r298948) @@ -1132,6 +1132,8 @@ dev/bwi/if_bwi_pci.c optional bwi pci # XXX Work around clang warning, until maintainer approves fix. dev/bwn/if_bwn.c optional bwn siba_bwn \ compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" +dev/bwn/if_bwn_phy_g.c optional bwn siba_bwn \ + compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" dev/bwn/if_bwn_phy_lp.c optional bwn siba_bwn \ compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" dev/cardbus/cardbus.c optional cardbus Modified: head/sys/dev/bwn/if_bwn.c ============================================================================== --- head/sys/dev/bwn/if_bwn.c Mon May 2 22:30:46 2016 (r298947) +++ head/sys/dev/bwn/if_bwn.c Mon May 2 22:58:11 2016 (r298948) @@ -75,7 +75,9 @@ __FBSDID("$FreeBSD$"); #include <dev/bwn/if_bwnreg.h> #include <dev/bwn/if_bwnvar.h> +#include <dev/bwn/if_bwn_debug.h> #include <dev/bwn/if_bwn_misc.h> +#include <dev/bwn/if_bwn_phy_g.h> #include <dev/bwn/if_bwn_phy_lp.h> static SYSCTL_NODE(_hw, OID_AUTO, bwn, CTLFLAG_RD, 0, @@ -89,33 +91,6 @@ static SYSCTL_NODE(_hw, OID_AUTO, bwn, C static int bwn_debug = 0; SYSCTL_INT(_hw_bwn, OID_AUTO, debug, CTLFLAG_RWTUN, &bwn_debug, 0, "Broadcom debugging printfs"); -enum { - BWN_DEBUG_XMIT = 0x00000001, /* basic xmit operation */ - BWN_DEBUG_RECV = 0x00000002, /* basic recv operation */ - BWN_DEBUG_STATE = 0x00000004, /* 802.11 state transitions */ - BWN_DEBUG_TXPOW = 0x00000008, /* tx power processing */ - BWN_DEBUG_RESET = 0x00000010, /* reset processing */ - BWN_DEBUG_OPS = 0x00000020, /* bwn_ops processing */ - BWN_DEBUG_BEACON = 0x00000040, /* beacon handling */ - BWN_DEBUG_WATCHDOG = 0x00000080, /* watchdog timeout */ - BWN_DEBUG_INTR = 0x00000100, /* ISR */ - BWN_DEBUG_CALIBRATE = 0x00000200, /* periodic calibration */ - BWN_DEBUG_NODE = 0x00000400, /* node management */ - BWN_DEBUG_LED = 0x00000800, /* led management */ - BWN_DEBUG_CMD = 0x00001000, /* cmd submission */ - BWN_DEBUG_LO = 0x00002000, /* LO */ - BWN_DEBUG_FW = 0x00004000, /* firmware */ - BWN_DEBUG_WME = 0x00008000, /* WME */ - BWN_DEBUG_RF = 0x00010000, /* RF */ - BWN_DEBUG_FATAL = 0x80000000, /* fatal errors */ - BWN_DEBUG_ANY = 0xffffffff -}; -#define DPRINTF(sc, m, fmt, ...) do { \ - if (sc->sc_debug & (m)) \ - printf(fmt, __VA_ARGS__); \ -} while (0) -#else -#define DPRINTF(sc, m, fmt, ...) do { (void) sc; } while (0) #endif static int bwn_bfp = 0; /* use "Bad Frames Preemption" */ @@ -145,40 +120,9 @@ static void bwn_parent(struct ieee80211c static void bwn_start(struct bwn_softc *); static int bwn_transmit(struct ieee80211com *, struct mbuf *); static int bwn_attach_core(struct bwn_mac *); -static void bwn_reset_core(struct bwn_mac *, uint32_t); static int bwn_phy_getinfo(struct bwn_mac *, int); static int bwn_chiptest(struct bwn_mac *); static int bwn_setup_channels(struct bwn_mac *, int, int); -static int bwn_phy_g_attach(struct bwn_mac *); -static void bwn_phy_g_detach(struct bwn_mac *); -static void bwn_phy_g_init_pre(struct bwn_mac *); -static int bwn_phy_g_prepare_hw(struct bwn_mac *); -static int bwn_phy_g_init(struct bwn_mac *); -static void bwn_phy_g_exit(struct bwn_mac *); -static uint16_t bwn_phy_g_read(struct bwn_mac *, uint16_t); -static void bwn_phy_g_write(struct bwn_mac *, uint16_t, - uint16_t); -static uint16_t bwn_phy_g_rf_read(struct bwn_mac *, uint16_t); -static void bwn_phy_g_rf_write(struct bwn_mac *, uint16_t, - uint16_t); -static int bwn_phy_g_hwpctl(struct bwn_mac *); -static void bwn_phy_g_rf_onoff(struct bwn_mac *, int); -static int bwn_phy_g_switch_channel(struct bwn_mac *, uint32_t); -static uint32_t bwn_phy_g_get_default_chan(struct bwn_mac *); -static void bwn_phy_g_set_antenna(struct bwn_mac *, int); -static int bwn_phy_g_im(struct bwn_mac *, int); -static int bwn_phy_g_recalc_txpwr(struct bwn_mac *, int); -static void bwn_phy_g_set_txpwr(struct bwn_mac *); -static void bwn_phy_g_task_15s(struct bwn_mac *); -static void bwn_phy_g_task_60s(struct bwn_mac *); -static uint16_t bwn_phy_g_txctl(struct bwn_mac *); -static void bwn_phy_switch_analog(struct bwn_mac *, int); -static uint16_t bwn_shm_read_2(struct bwn_mac *, uint16_t, uint16_t); -static void bwn_shm_write_2(struct bwn_mac *, uint16_t, uint16_t, - uint16_t); -static uint32_t bwn_shm_read_4(struct bwn_mac *, uint16_t, uint16_t); -static void bwn_shm_write_4(struct bwn_mac *, uint16_t, uint16_t, - uint32_t); static void bwn_shm_ctlword(struct bwn_mac *, uint16_t, uint16_t); static void bwn_addchannels(struct ieee80211_channel [], int, int *, @@ -321,47 +265,6 @@ static struct bwn_dma_ring *bwn_dma_ring static struct bwn_dma_ring *bwn_dma_parse_cookie(struct bwn_mac *, const struct bwn_txstatus *, uint16_t, int *); static void bwn_dma_free(struct bwn_mac *); -static void bwn_phy_g_init_sub(struct bwn_mac *); -static uint8_t bwn_has_hwpctl(struct bwn_mac *); -static void bwn_phy_init_b5(struct bwn_mac *); -static void bwn_phy_init_b6(struct bwn_mac *); -static void bwn_phy_init_a(struct bwn_mac *); -static void bwn_loopback_calcgain(struct bwn_mac *); -static uint16_t bwn_rf_init_bcm2050(struct bwn_mac *); -static void bwn_lo_g_init(struct bwn_mac *); -static void bwn_lo_g_adjust(struct bwn_mac *); -static void bwn_lo_get_powervector(struct bwn_mac *); -static struct bwn_lo_calib *bwn_lo_calibset(struct bwn_mac *, - const struct bwn_bbatt *, const struct bwn_rfatt *); -static void bwn_lo_write(struct bwn_mac *, struct bwn_loctl *); -static void bwn_phy_hwpctl_init(struct bwn_mac *); -static void bwn_phy_g_switch_chan(struct bwn_mac *, int, uint8_t); -static void bwn_phy_g_set_txpwr_sub(struct bwn_mac *, - const struct bwn_bbatt *, const struct bwn_rfatt *, - uint8_t); -static void bwn_phy_g_set_bbatt(struct bwn_mac *, uint16_t); -static uint16_t bwn_rf_2050_rfoverval(struct bwn_mac *, uint16_t, uint32_t); -static void bwn_spu_workaround(struct bwn_mac *, uint8_t); -static void bwn_wa_init(struct bwn_mac *); -static void bwn_ofdmtab_write_2(struct bwn_mac *, uint16_t, uint16_t, - uint16_t); -static void bwn_dummy_transmission(struct bwn_mac *, int, int); -static void bwn_ofdmtab_write_4(struct bwn_mac *, uint16_t, uint16_t, - uint32_t); -static void bwn_gtab_write(struct bwn_mac *, uint16_t, uint16_t, - uint16_t); -static void bwn_ram_write(struct bwn_mac *, uint16_t, uint32_t); -static void bwn_psctl(struct bwn_mac *, uint32_t); -static int16_t bwn_nrssi_read(struct bwn_mac *, uint16_t); -static void bwn_nrssi_offset(struct bwn_mac *); -static void bwn_nrssi_threshold(struct bwn_mac *); -static void bwn_nrssi_slope_11g(struct bwn_mac *); -static void bwn_set_all_gains(struct bwn_mac *, int16_t, int16_t, - int16_t); -static void bwn_set_original_gains(struct bwn_mac *); -static void bwn_hwpctl_early_init(struct bwn_mac *); -static void bwn_hwpctl_init_gphy(struct bwn_mac *); -static uint16_t bwn_phy_g_chan2freq(uint8_t); static int bwn_fw_gets(struct bwn_mac *, enum bwn_fwtype); static int bwn_fw_get(struct bwn_mac *, enum bwn_fwtype, const char *, struct bwn_fwfile *); @@ -370,7 +273,6 @@ static void bwn_do_release_fw(struct bwn static uint16_t bwn_fwcaps_read(struct bwn_mac *); static int bwn_fwinitvals_write(struct bwn_mac *, const struct bwn_fwinitvals *, size_t, size_t); -static int bwn_switch_channel(struct bwn_mac *, int); static uint16_t bwn_ant2phy(int); static void bwn_mac_write_bssid(struct bwn_mac *); static void bwn_mac_setfilter(struct bwn_mac *, uint16_t, @@ -418,12 +320,6 @@ static void bwn_plcp_genhdr(struct bwn_p const uint8_t); static uint8_t bwn_antenna_sanitize(struct bwn_mac *, uint8_t); static uint8_t bwn_get_fbrate(uint8_t); -static int bwn_phy_shm_tssi_read(struct bwn_mac *, uint16_t); -static void bwn_phy_g_setatt(struct bwn_mac *, int *, int *); -static void bwn_phy_lock(struct bwn_mac *); -static void bwn_phy_unlock(struct bwn_mac *); -static void bwn_rf_lock(struct bwn_mac *); -static void bwn_rf_unlock(struct bwn_mac *); static void bwn_txpwr(void *, int); static void bwn_tasks(void *); static void bwn_task_15s(struct bwn_mac *); @@ -436,7 +332,6 @@ static void bwn_rx_radiotap(struct bwn_m const struct bwn_rxhdr4 *, struct bwn_plcp6 *, int, int, int); static void bwn_tsf_read(struct bwn_mac *, uint64_t *); -static void bwn_phy_g_dc_lookup_init(struct bwn_mac *, uint8_t); static void bwn_set_slot_time(struct bwn_mac *, uint16_t); static void bwn_watchdog(void *); static void bwn_dma_stop(struct bwn_mac *); @@ -533,13 +428,6 @@ static const struct bwn_channelinfo bwn_ .nchannels = 110 }; -static const uint16_t bwn_tab_noise_g1[] = BWN_TAB_NOISE_G1; -static const uint16_t bwn_tab_noise_g2[] = BWN_TAB_NOISE_G2; -static const uint16_t bwn_tab_noisescale_g1[] = BWN_TAB_NOISESCALE_G1; -static const uint16_t bwn_tab_noisescale_g2[] = BWN_TAB_NOISESCALE_G2; -static const uint16_t bwn_tab_noisescale_g3[] = BWN_TAB_NOISESCALE_G3; -const uint8_t bwn_bitrev_table[256] = BWN_BITREV_TABLE; - #define VENDOR_LED_ACT(vendor) \ { \ .vid = PCI_VENDOR_##vendor, \ @@ -1361,7 +1249,7 @@ fail: return (error); } -static void +void bwn_reset_core(struct bwn_mac *mac, uint32_t flags) { struct bwn_softc *sc = mac->mac_sc; @@ -1531,7 +1419,7 @@ bwn_setup_channels(struct bwn_mac *mac, return (ic->ic_nchans == 0 ? ENXIO : 0); } -static uint32_t +uint32_t bwn_shm_read_4(struct bwn_mac *mac, uint16_t way, uint16_t offset) { uint32_t ret; @@ -1557,7 +1445,7 @@ out: return (ret); } -static uint16_t +uint16_t bwn_shm_read_2(struct bwn_mac *mac, uint16_t way, uint16_t offset) { uint16_t ret; @@ -1593,7 +1481,7 @@ bwn_shm_ctlword(struct bwn_mac *mac, uin BWN_WRITE_4(mac, BWN_SHM_CONTROL, control); } -static void +void bwn_shm_write_4(struct bwn_mac *mac, uint16_t way, uint16_t offset, uint32_t value) { @@ -1616,7 +1504,7 @@ bwn_shm_write_4(struct bwn_mac *mac, uin BWN_WRITE_4(mac, BWN_SHM_DATA, value); } -static void +void bwn_shm_write_2(struct bwn_mac *mac, uint16_t way, uint16_t offset, uint16_t value) { @@ -1698,683 +1586,6 @@ bwn_addchannels(struct ieee80211_channel } static int -bwn_phy_g_attach(struct bwn_mac *mac) -{ - struct bwn_softc *sc = mac->mac_sc; - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - unsigned int i; - int16_t pab0, pab1, pab2; - static int8_t bwn_phy_g_tssi2dbm_table[] = BWN_PHY_G_TSSI2DBM_TABLE; - int8_t bg; - - bg = (int8_t)siba_sprom_get_tssi_bg(sc->sc_dev); - pab0 = (int16_t)siba_sprom_get_pa0b0(sc->sc_dev); - pab1 = (int16_t)siba_sprom_get_pa0b1(sc->sc_dev); - pab2 = (int16_t)siba_sprom_get_pa0b2(sc->sc_dev); - - if ((siba_get_chipid(sc->sc_dev) == 0x4301) && (phy->rf_ver != 0x2050)) - device_printf(sc->sc_dev, "not supported anymore\n"); - - pg->pg_flags = 0; - if (pab0 == 0 || pab1 == 0 || pab2 == 0 || pab0 == -1 || pab1 == -1 || - pab2 == -1) { - pg->pg_idletssi = 52; - pg->pg_tssi2dbm = bwn_phy_g_tssi2dbm_table; - return (0); - } - - pg->pg_idletssi = (bg == 0 || bg == -1) ? 62 : bg; - pg->pg_tssi2dbm = (uint8_t *)malloc(64, M_DEVBUF, M_NOWAIT | M_ZERO); - if (pg->pg_tssi2dbm == NULL) { - device_printf(sc->sc_dev, "failed to allocate buffer\n"); - return (ENOMEM); - } - for (i = 0; i < 64; i++) { - int32_t m1, m2, f, q, delta; - int8_t j = 0; - - m1 = BWN_TSSI2DBM(16 * pab0 + i * pab1, 32); - m2 = MAX(BWN_TSSI2DBM(32768 + i * pab2, 256), 1); - f = 256; - - do { - if (j > 15) { - device_printf(sc->sc_dev, - "failed to generate tssi2dBm\n"); - free(pg->pg_tssi2dbm, M_DEVBUF); - return (ENOMEM); - } - q = BWN_TSSI2DBM(f * 4096 - BWN_TSSI2DBM(m2 * f, 16) * - f, 2048); - delta = abs(q - f); - f = q; - j++; - } while (delta >= 2); - - pg->pg_tssi2dbm[i] = MIN(MAX(BWN_TSSI2DBM(m1 * f, 8192), -127), - 128); - } - - pg->pg_flags |= BWN_PHY_G_FLAG_TSSITABLE_ALLOC; - return (0); -} - -static void -bwn_phy_g_detach(struct bwn_mac *mac) -{ - struct bwn_phy_g *pg = &mac->mac_phy.phy_g; - - if (pg->pg_flags & BWN_PHY_G_FLAG_TSSITABLE_ALLOC) { - free(pg->pg_tssi2dbm, M_DEVBUF); - pg->pg_tssi2dbm = NULL; - } - pg->pg_flags = 0; -} - -static void -bwn_phy_g_init_pre(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - void *tssi2dbm; - int idletssi; - unsigned int i; - - tssi2dbm = pg->pg_tssi2dbm; - idletssi = pg->pg_idletssi; - - memset(pg, 0, sizeof(*pg)); - - pg->pg_tssi2dbm = tssi2dbm; - pg->pg_idletssi = idletssi; - - memset(pg->pg_minlowsig, 0xff, sizeof(pg->pg_minlowsig)); - - for (i = 0; i < N(pg->pg_nrssi); i++) - pg->pg_nrssi[i] = -1000; - for (i = 0; i < N(pg->pg_nrssi_lt); i++) - pg->pg_nrssi_lt[i] = i; - pg->pg_lofcal = 0xffff; - pg->pg_initval = 0xffff; - pg->pg_immode = BWN_IMMODE_NONE; - pg->pg_ofdmtab_dir = BWN_OFDMTAB_DIR_UNKNOWN; - pg->pg_avgtssi = 0xff; - - pg->pg_loctl.tx_bias = 0xff; - TAILQ_INIT(&pg->pg_loctl.calib_list); -} - -static int -bwn_phy_g_prepare_hw(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - struct bwn_softc *sc = mac->mac_sc; - struct bwn_txpwr_loctl *lo = &pg->pg_loctl; - static const struct bwn_rfatt rfatt0[] = { - { 3, 0 }, { 1, 0 }, { 5, 0 }, { 7, 0 }, { 9, 0 }, { 2, 0 }, - { 0, 0 }, { 4, 0 }, { 6, 0 }, { 8, 0 }, { 1, 1 }, { 2, 1 }, - { 3, 1 }, { 4, 1 } - }; - static const struct bwn_rfatt rfatt1[] = { - { 2, 1 }, { 4, 1 }, { 6, 1 }, { 8, 1 }, { 10, 1 }, { 12, 1 }, - { 14, 1 } - }; - static const struct bwn_rfatt rfatt2[] = { - { 0, 1 }, { 2, 1 }, { 4, 1 }, { 6, 1 }, { 8, 1 }, { 9, 1 }, - { 9, 1 } - }; - static const struct bwn_bbatt bbatt_0[] = { - { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 } - }; - - KASSERT(phy->type == BWN_PHYTYPE_G, ("%s fail", __func__)); - - if (phy->rf_ver == 0x2050 && phy->rf_rev < 6) - pg->pg_bbatt.att = 0; - else - pg->pg_bbatt.att = 2; - - /* prepare Radio Attenuation */ - pg->pg_rfatt.padmix = 0; - - if (siba_get_pci_subvendor(sc->sc_dev) == SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == SIBA_BOARD_BCM4309G) { - if (siba_get_pci_revid(sc->sc_dev) < 0x43) { - pg->pg_rfatt.att = 2; - goto done; - } else if (siba_get_pci_revid(sc->sc_dev) < 0x51) { - pg->pg_rfatt.att = 3; - goto done; - } - } - - if (phy->type == BWN_PHYTYPE_A) { - pg->pg_rfatt.att = 0x60; - goto done; - } - - switch (phy->rf_ver) { - case 0x2050: - switch (phy->rf_rev) { - case 0: - pg->pg_rfatt.att = 5; - goto done; - case 1: - if (phy->type == BWN_PHYTYPE_G) { - if (siba_get_pci_subvendor(sc->sc_dev) == - SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == - SIBA_BOARD_BCM4309G && - siba_get_pci_revid(sc->sc_dev) >= 30) - pg->pg_rfatt.att = 3; - else if (siba_get_pci_subvendor(sc->sc_dev) == - SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == - SIBA_BOARD_BU4306) - pg->pg_rfatt.att = 3; - else - pg->pg_rfatt.att = 1; - } else { - if (siba_get_pci_subvendor(sc->sc_dev) == - SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == - SIBA_BOARD_BCM4309G && - siba_get_pci_revid(sc->sc_dev) >= 30) - pg->pg_rfatt.att = 7; - else - pg->pg_rfatt.att = 6; - } - goto done; - case 2: - if (phy->type == BWN_PHYTYPE_G) { - if (siba_get_pci_subvendor(sc->sc_dev) == - SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == - SIBA_BOARD_BCM4309G && - siba_get_pci_revid(sc->sc_dev) >= 30) - pg->pg_rfatt.att = 3; - else if (siba_get_pci_subvendor(sc->sc_dev) == - SIBA_BOARDVENDOR_BCM && - siba_get_pci_subdevice(sc->sc_dev) == - SIBA_BOARD_BU4306) - pg->pg_rfatt.att = 5; - else if (siba_get_chipid(sc->sc_dev) == 0x4320) - pg->pg_rfatt.att = 4; - else - pg->pg_rfatt.att = 3; - } else - pg->pg_rfatt.att = 6; - goto done; - case 3: - pg->pg_rfatt.att = 5; - goto done; - case 4: - case 5: - pg->pg_rfatt.att = 1; - goto done; - case 6: - case 7: - pg->pg_rfatt.att = 5; - goto done; - case 8: - pg->pg_rfatt.att = 0xa; - pg->pg_rfatt.padmix = 1; - goto done; - case 9: - default: - pg->pg_rfatt.att = 5; - goto done; - } - break; - case 0x2053: - switch (phy->rf_rev) { - case 1: - pg->pg_rfatt.att = 6; - goto done; - } - break; - } - pg->pg_rfatt.att = 5; -done: - pg->pg_txctl = (bwn_phy_g_txctl(mac) << 4); - - if (!bwn_has_hwpctl(mac)) { - lo->rfatt.array = rfatt0; - lo->rfatt.len = N(rfatt0); - lo->rfatt.min = 0; - lo->rfatt.max = 9; - goto genbbatt; - } - if (phy->rf_ver == 0x2050 && phy->rf_rev == 8) { - lo->rfatt.array = rfatt1; - lo->rfatt.len = N(rfatt1); - lo->rfatt.min = 0; - lo->rfatt.max = 14; - goto genbbatt; - } - lo->rfatt.array = rfatt2; - lo->rfatt.len = N(rfatt2); - lo->rfatt.min = 0; - lo->rfatt.max = 9; -genbbatt: - lo->bbatt.array = bbatt_0; - lo->bbatt.len = N(bbatt_0); - lo->bbatt.min = 0; - lo->bbatt.max = 8; - - BWN_READ_4(mac, BWN_MACCTL); - if (phy->rev == 1) { - phy->gmode = 0; - bwn_reset_core(mac, 0); - bwn_phy_g_init_sub(mac); - phy->gmode = 1; - bwn_reset_core(mac, BWN_TGSLOW_SUPPORT_G); - } - return (0); -} - -static uint16_t -bwn_phy_g_txctl(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - - if (phy->rf_ver != 0x2050) - return (0); - if (phy->rf_rev == 1) - return (BWN_TXCTL_PA2DB | BWN_TXCTL_TXMIX); - if (phy->rf_rev < 6) - return (BWN_TXCTL_PA2DB); - if (phy->rf_rev == 8) - return (BWN_TXCTL_TXMIX); - return (0); -} - -static int -bwn_phy_g_init(struct bwn_mac *mac) -{ - - bwn_phy_g_init_sub(mac); - return (0); -} - -static void -bwn_phy_g_exit(struct bwn_mac *mac) -{ - struct bwn_txpwr_loctl *lo = &mac->mac_phy.phy_g.pg_loctl; - struct bwn_lo_calib *cal, *tmp; - - if (lo == NULL) - return; - TAILQ_FOREACH_SAFE(cal, &lo->calib_list, list, tmp) { - TAILQ_REMOVE(&lo->calib_list, cal, list); - free(cal, M_DEVBUF); - } -} - -static uint16_t -bwn_phy_g_read(struct bwn_mac *mac, uint16_t reg) -{ - - BWN_WRITE_2(mac, BWN_PHYCTL, reg); - return (BWN_READ_2(mac, BWN_PHYDATA)); -} - -static void -bwn_phy_g_write(struct bwn_mac *mac, uint16_t reg, uint16_t value) -{ - - BWN_WRITE_2(mac, BWN_PHYCTL, reg); - BWN_WRITE_2(mac, BWN_PHYDATA, value); -} - -static uint16_t -bwn_phy_g_rf_read(struct bwn_mac *mac, uint16_t reg) -{ - - KASSERT(reg != 1, ("%s:%d: fail", __func__, __LINE__)); - BWN_WRITE_2(mac, BWN_RFCTL, reg | 0x80); - return (BWN_READ_2(mac, BWN_RFDATALO)); -} - -static void -bwn_phy_g_rf_write(struct bwn_mac *mac, uint16_t reg, uint16_t value) -{ - - KASSERT(reg != 1, ("%s:%d: fail", __func__, __LINE__)); - BWN_WRITE_2(mac, BWN_RFCTL, reg); - BWN_WRITE_2(mac, BWN_RFDATALO, value); -} - -static int -bwn_phy_g_hwpctl(struct bwn_mac *mac) -{ - - return (mac->mac_phy.rev >= 6); -} - -static void -bwn_phy_g_rf_onoff(struct bwn_mac *mac, int on) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - unsigned int channel; - uint16_t rfover, rfoverval; - - if (on) { - if (phy->rf_on) - return; - - BWN_PHY_WRITE(mac, 0x15, 0x8000); - BWN_PHY_WRITE(mac, 0x15, 0xcc00); - BWN_PHY_WRITE(mac, 0x15, (phy->gmode ? 0xc0 : 0x0)); - if (pg->pg_flags & BWN_PHY_G_FLAG_RADIOCTX_VALID) { - BWN_PHY_WRITE(mac, BWN_PHY_RFOVER, - pg->pg_radioctx_over); - BWN_PHY_WRITE(mac, BWN_PHY_RFOVERVAL, - pg->pg_radioctx_overval); - pg->pg_flags &= ~BWN_PHY_G_FLAG_RADIOCTX_VALID; - } - channel = phy->chan; - bwn_phy_g_switch_chan(mac, 6, 1); - bwn_phy_g_switch_chan(mac, channel, 0); - return; - } - - rfover = BWN_PHY_READ(mac, BWN_PHY_RFOVER); - rfoverval = BWN_PHY_READ(mac, BWN_PHY_RFOVERVAL); - pg->pg_radioctx_over = rfover; - pg->pg_radioctx_overval = rfoverval; - pg->pg_flags |= BWN_PHY_G_FLAG_RADIOCTX_VALID; - BWN_PHY_WRITE(mac, BWN_PHY_RFOVER, rfover | 0x008c); - BWN_PHY_WRITE(mac, BWN_PHY_RFOVERVAL, rfoverval & 0xff73); -} - -static int -bwn_phy_g_switch_channel(struct bwn_mac *mac, uint32_t newchan) -{ - - if ((newchan < 1) || (newchan > 14)) - return (EINVAL); - bwn_phy_g_switch_chan(mac, newchan, 0); - - return (0); -} - -static uint32_t -bwn_phy_g_get_default_chan(struct bwn_mac *mac) -{ - - return (1); -} - -static void -bwn_phy_g_set_antenna(struct bwn_mac *mac, int antenna) -{ - struct bwn_phy *phy = &mac->mac_phy; - uint64_t hf; - int autodiv = 0; - uint16_t tmp; - - if (antenna == BWN_ANTAUTO0 || antenna == BWN_ANTAUTO1) - autodiv = 1; - - hf = bwn_hf_read(mac) & ~BWN_HF_UCODE_ANTDIV_HELPER; - bwn_hf_write(mac, hf); - - BWN_PHY_WRITE(mac, BWN_PHY_BBANDCFG, - (BWN_PHY_READ(mac, BWN_PHY_BBANDCFG) & ~BWN_PHY_BBANDCFG_RXANT) | - ((autodiv ? BWN_ANTAUTO1 : antenna) - << BWN_PHY_BBANDCFG_RXANT_SHIFT)); - - if (autodiv) { - tmp = BWN_PHY_READ(mac, BWN_PHY_ANTDWELL); - if (antenna == BWN_ANTAUTO1) - tmp &= ~BWN_PHY_ANTDWELL_AUTODIV1; - else - tmp |= BWN_PHY_ANTDWELL_AUTODIV1; - BWN_PHY_WRITE(mac, BWN_PHY_ANTDWELL, tmp); - } - tmp = BWN_PHY_READ(mac, BWN_PHY_ANTWRSETT); - if (autodiv) - tmp |= BWN_PHY_ANTWRSETT_ARXDIV; - else - tmp &= ~BWN_PHY_ANTWRSETT_ARXDIV; - BWN_PHY_WRITE(mac, BWN_PHY_ANTWRSETT, tmp); - if (phy->rev >= 2) { - BWN_PHY_WRITE(mac, BWN_PHY_OFDM61, - BWN_PHY_READ(mac, BWN_PHY_OFDM61) | BWN_PHY_OFDM61_10); - BWN_PHY_WRITE(mac, BWN_PHY_DIVSRCHGAINBACK, - (BWN_PHY_READ(mac, BWN_PHY_DIVSRCHGAINBACK) & 0xff00) | - 0x15); - if (phy->rev == 2) - BWN_PHY_WRITE(mac, BWN_PHY_ADIVRELATED, 8); - else - BWN_PHY_WRITE(mac, BWN_PHY_ADIVRELATED, - (BWN_PHY_READ(mac, BWN_PHY_ADIVRELATED) & 0xff00) | - 8); - } - if (phy->rev >= 6) - BWN_PHY_WRITE(mac, BWN_PHY_OFDM9B, 0xdc); - - hf |= BWN_HF_UCODE_ANTDIV_HELPER; - bwn_hf_write(mac, hf); -} - -static int -bwn_phy_g_im(struct bwn_mac *mac, int mode) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - - KASSERT(phy->type == BWN_PHYTYPE_G, ("%s: fail", __func__)); - KASSERT(mode == BWN_IMMODE_NONE, ("%s: fail", __func__)); - - if (phy->rev == 0 || !phy->gmode) - return (ENODEV); - - pg->pg_aci_wlan_automatic = 0; - return (0); -} - -static int -bwn_phy_g_recalc_txpwr(struct bwn_mac *mac, int ignore_tssi) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - struct bwn_softc *sc = mac->mac_sc; - unsigned int tssi; - int cck, ofdm; - int power; - int rfatt, bbatt; - unsigned int max; - - KASSERT(phy->type == BWN_PHYTYPE_G, ("%s: fail", __func__)); - - cck = bwn_phy_shm_tssi_read(mac, BWN_SHARED_TSSI_CCK); - ofdm = bwn_phy_shm_tssi_read(mac, BWN_SHARED_TSSI_OFDM_G); - if (cck < 0 && ofdm < 0) { - if (ignore_tssi == 0) - return (BWN_TXPWR_RES_DONE); - cck = 0; - ofdm = 0; - } - tssi = (cck < 0) ? ofdm : ((ofdm < 0) ? cck : (cck + ofdm) / 2); - if (pg->pg_avgtssi != 0xff) - tssi = (tssi + pg->pg_avgtssi) / 2; - pg->pg_avgtssi = tssi; - KASSERT(tssi < BWN_TSSI_MAX, ("%s:%d: fail", __func__, __LINE__)); - - max = siba_sprom_get_maxpwr_bg(sc->sc_dev); - if (siba_sprom_get_bf_lo(sc->sc_dev) & BWN_BFL_PACTRL) - max -= 3; - if (max >= 120) { - device_printf(sc->sc_dev, "invalid max TX-power value\n"); - max = 80; - siba_sprom_set_maxpwr_bg(sc->sc_dev, max); - } - - power = MIN(MAX((phy->txpower < 0) ? 0 : (phy->txpower << 2), 0), max) - - (pg->pg_tssi2dbm[MIN(MAX(pg->pg_idletssi - pg->pg_curtssi + - tssi, 0x00), 0x3f)]); - if (power == 0) - return (BWN_TXPWR_RES_DONE); - - rfatt = -((power + 7) / 8); - bbatt = (-(power / 2)) - (4 * rfatt); - if ((rfatt == 0) && (bbatt == 0)) - return (BWN_TXPWR_RES_DONE); - pg->pg_bbatt_delta = bbatt; - pg->pg_rfatt_delta = rfatt; - return (BWN_TXPWR_RES_NEED_ADJUST); -} - -static void -bwn_phy_g_set_txpwr(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - struct bwn_softc *sc = mac->mac_sc; - int rfatt, bbatt; - uint8_t txctl; - - bwn_mac_suspend(mac); - - BWN_ASSERT_LOCKED(sc); - - bbatt = pg->pg_bbatt.att; - bbatt += pg->pg_bbatt_delta; - rfatt = pg->pg_rfatt.att; - rfatt += pg->pg_rfatt_delta; - - bwn_phy_g_setatt(mac, &bbatt, &rfatt); - txctl = pg->pg_txctl; - if ((phy->rf_ver == 0x2050) && (phy->rf_rev == 2)) { - if (rfatt <= 1) { - if (txctl == 0) { - txctl = BWN_TXCTL_PA2DB | BWN_TXCTL_TXMIX; - rfatt += 2; - bbatt += 2; - } else if (siba_sprom_get_bf_lo(sc->sc_dev) & - BWN_BFL_PACTRL) { - bbatt += 4 * (rfatt - 2); - rfatt = 2; - } - } else if (rfatt > 4 && txctl) { - txctl = 0; - if (bbatt < 3) { - rfatt -= 3; - bbatt += 2; - } else { - rfatt -= 2; - bbatt -= 2; - } - } - } - pg->pg_txctl = txctl; - bwn_phy_g_setatt(mac, &bbatt, &rfatt); - pg->pg_rfatt.att = rfatt; - pg->pg_bbatt.att = bbatt; - - DPRINTF(sc, BWN_DEBUG_TXPOW, "%s: adjust TX power\n", __func__); - - bwn_phy_lock(mac); - bwn_rf_lock(mac); - bwn_phy_g_set_txpwr_sub(mac, &pg->pg_bbatt, &pg->pg_rfatt, - pg->pg_txctl); - bwn_rf_unlock(mac); - bwn_phy_unlock(mac); - - bwn_mac_enable(mac); -} - -static void -bwn_phy_g_task_15s(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - struct bwn_softc *sc = mac->mac_sc; - struct bwn_txpwr_loctl *lo = &pg->pg_loctl; - unsigned long expire, now; - struct bwn_lo_calib *cal, *tmp; - uint8_t expired = 0; - - bwn_mac_suspend(mac); - - if (lo == NULL) - goto fail; - - BWN_GETTIME(now); - if (bwn_has_hwpctl(mac)) { - expire = now - BWN_LO_PWRVEC_EXPIRE; - if (ieee80211_time_before(lo->pwr_vec_read_time, expire)) { - bwn_lo_get_powervector(mac); - bwn_phy_g_dc_lookup_init(mac, 0); - } - goto fail; - } - - expire = now - BWN_LO_CALIB_EXPIRE; - TAILQ_FOREACH_SAFE(cal, &lo->calib_list, list, tmp) { - if (!ieee80211_time_before(cal->calib_time, expire)) - continue; - if (BWN_BBATTCMP(&cal->bbatt, &pg->pg_bbatt) && - BWN_RFATTCMP(&cal->rfatt, &pg->pg_rfatt)) { - KASSERT(!expired, ("%s:%d: fail", __func__, __LINE__)); - expired = 1; - } - - DPRINTF(sc, BWN_DEBUG_LO, "expired BB %u RF %u %u I %d Q %d\n", - cal->bbatt.att, cal->rfatt.att, cal->rfatt.padmix, - cal->ctl.i, cal->ctl.q); - - TAILQ_REMOVE(&lo->calib_list, cal, list); - free(cal, M_DEVBUF); - } - if (expired || TAILQ_EMPTY(&lo->calib_list)) { - cal = bwn_lo_calibset(mac, &pg->pg_bbatt, - &pg->pg_rfatt); - if (cal == NULL) { - device_printf(sc->sc_dev, - "failed to recalibrate LO\n"); - goto fail; - } - TAILQ_INSERT_TAIL(&lo->calib_list, cal, list); - bwn_lo_write(mac, &cal->ctl); - } - -fail: - bwn_mac_enable(mac); -} - -static void -bwn_phy_g_task_60s(struct bwn_mac *mac) -{ - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_softc *sc = mac->mac_sc; - uint8_t old = phy->chan; - - if (!(siba_sprom_get_bf_lo(sc->sc_dev) & BWN_BFL_RSSI)) - return; - - bwn_mac_suspend(mac); - bwn_nrssi_slope_11g(mac); - if ((phy->rf_ver == 0x2050) && (phy->rf_rev == 8)) { - bwn_switch_channel(mac, (old >= 8) ? 1 : 13); - bwn_switch_channel(mac, old); - } - bwn_mac_enable(mac); -} - -static void -bwn_phy_switch_analog(struct bwn_mac *mac, int on) -{ - - BWN_WRITE_2(mac, BWN_PHY0, on ? 0 : 0xf4); -} - -static int bwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, const struct ieee80211_bpf_params *params) { @@ -4302,2836 +3513,108 @@ bwn_dma_ring_addr(void *arg, bus_dma_seg } } -static void -bwn_phy_g_init_sub(struct bwn_mac *mac) +void +bwn_ram_write(struct bwn_mac *mac, uint16_t offset, uint32_t val) { - struct bwn_phy *phy = &mac->mac_phy; - struct bwn_phy_g *pg = &phy->phy_g; - struct bwn_softc *sc = mac->mac_sc; - uint16_t i, tmp; - - if (phy->rev == 1) - bwn_phy_init_b5(mac); - else - bwn_phy_init_b6(mac); - - if (phy->rev >= 2 || phy->gmode) - bwn_phy_init_a(mac); - - if (phy->rev >= 2) { - BWN_PHY_WRITE(mac, BWN_PHY_ANALOGOVER, 0); - BWN_PHY_WRITE(mac, BWN_PHY_ANALOGOVERVAL, 0); - } - if (phy->rev == 2) { - BWN_PHY_WRITE(mac, BWN_PHY_RFOVER, 0); - BWN_PHY_WRITE(mac, BWN_PHY_PGACTL, 0xc0); - } - if (phy->rev > 5) { - BWN_PHY_WRITE(mac, BWN_PHY_RFOVER, 0x400); - BWN_PHY_WRITE(mac, BWN_PHY_PGACTL, 0xc0); - } - if (phy->gmode || phy->rev >= 2) { - tmp = BWN_PHY_READ(mac, BWN_PHY_VERSION_OFDM); - tmp &= BWN_PHYVER_VERSION; - if (tmp == 3 || tmp == 5) { - BWN_PHY_WRITE(mac, BWN_PHY_OFDM(0xc2), 0x1816); - BWN_PHY_WRITE(mac, BWN_PHY_OFDM(0xc3), 0x8006); - } - if (tmp == 5) { - BWN_PHY_SETMASK(mac, BWN_PHY_OFDM(0xcc), 0x00ff, - 0x1f00); - } - } - if ((phy->rev <= 2 && phy->gmode) || phy->rev >= 2) - BWN_PHY_WRITE(mac, BWN_PHY_OFDM(0x7e), 0x78); - if (phy->rf_rev == 8) { - BWN_PHY_SET(mac, BWN_PHY_EXTG(0x01), 0x80); - BWN_PHY_SET(mac, BWN_PHY_OFDM(0x3e), 0x4); - } - if (BWN_HAS_LOOPBACK(phy)) - bwn_loopback_calcgain(mac); - - if (phy->rf_rev != 8) { - if (pg->pg_initval == 0xffff) - pg->pg_initval = bwn_rf_init_bcm2050(mac); - else - BWN_RF_WRITE(mac, 0x0078, pg->pg_initval); - } - bwn_lo_g_init(mac); - if (BWN_HAS_TXMAG(phy)) { - BWN_RF_WRITE(mac, 0x52, - (BWN_RF_READ(mac, 0x52) & 0xff00) - | pg->pg_loctl.tx_bias | - pg->pg_loctl.tx_magn); - } else { - BWN_RF_SETMASK(mac, 0x52, 0xfff0, pg->pg_loctl.tx_bias); - } - if (phy->rev >= 6) { - BWN_PHY_SETMASK(mac, BWN_PHY_CCK(0x36), 0x0fff, - (pg->pg_loctl.tx_bias << 12)); - } - if (siba_sprom_get_bf_lo(sc->sc_dev) & BWN_BFL_PACTRL) - BWN_PHY_WRITE(mac, BWN_PHY_CCK(0x2e), 0x8075); - else - BWN_PHY_WRITE(mac, BWN_PHY_CCK(0x2e), 0x807f); - if (phy->rev < 2) - BWN_PHY_WRITE(mac, BWN_PHY_CCK(0x2f), 0x101); - else - BWN_PHY_WRITE(mac, BWN_PHY_CCK(0x2f), 0x202); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605022258.u42MwB4q075269>