Deleted Added
sdiff udiff text old ( 298944 ) new ( 298948 )
full compact
1/*-
2 * Copyright (c) 2009-2010 Weongyo Jeong <weongyo@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/bwn/if_bwn.c 298948 2016-05-02 22:58:11Z adrian $");
32
33/*
34 * The Broadcom Wireless LAN controller driver.
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>

--- 30 unchanged lines hidden (view full) ---

70#include <net80211/ieee80211_radiotap.h>
71#include <net80211/ieee80211_regdomain.h>
72#include <net80211/ieee80211_phy.h>
73#include <net80211/ieee80211_ratectl.h>
74
75#include <dev/bwn/if_bwnreg.h>
76#include <dev/bwn/if_bwnvar.h>
77
78#include <dev/bwn/if_bwn_debug.h>
79#include <dev/bwn/if_bwn_misc.h>
80#include <dev/bwn/if_bwn_phy_g.h>
81#include <dev/bwn/if_bwn_phy_lp.h>
82
83static SYSCTL_NODE(_hw, OID_AUTO, bwn, CTLFLAG_RD, 0,
84 "Broadcom driver parameters");
85
86/*
87 * Tunable & sysctl variables.
88 */
89
90#ifdef BWN_DEBUG
91static int bwn_debug = 0;
92SYSCTL_INT(_hw_bwn, OID_AUTO, debug, CTLFLAG_RWTUN, &bwn_debug, 0,
93 "Broadcom debugging printfs");
94#endif
95
96static int bwn_bfp = 0; /* use "Bad Frames Preemption" */
97SYSCTL_INT(_hw_bwn, OID_AUTO, bfp, CTLFLAG_RW, &bwn_bfp, 0,
98 "uses Bad Frames Preemption");
99static int bwn_bluetooth = 1;
100SYSCTL_INT(_hw_bwn, OID_AUTO, bluetooth, CTLFLAG_RW, &bwn_bluetooth, 0,
101 "turns on Bluetooth Coexistence");

--- 13 unchanged lines hidden (view full) ---

115static void bwn_attach_pre(struct bwn_softc *);
116static int bwn_attach_post(struct bwn_softc *);
117static void bwn_sprom_bugfixes(device_t);
118static int bwn_init(struct bwn_softc *);
119static void bwn_parent(struct ieee80211com *);
120static void bwn_start(struct bwn_softc *);
121static int bwn_transmit(struct ieee80211com *, struct mbuf *);
122static int bwn_attach_core(struct bwn_mac *);
123static int bwn_phy_getinfo(struct bwn_mac *, int);
124static int bwn_chiptest(struct bwn_mac *);
125static int bwn_setup_channels(struct bwn_mac *, int, int);
126static void bwn_shm_ctlword(struct bwn_mac *, uint16_t,
127 uint16_t);
128static void bwn_addchannels(struct ieee80211_channel [], int, int *,
129 const struct bwn_channelinfo *, int);
130static int bwn_raw_xmit(struct ieee80211_node *, struct mbuf *,
131 const struct ieee80211_bpf_params *);
132static void bwn_updateslot(struct ieee80211com *);
133static void bwn_update_promisc(struct ieee80211com *);

--- 126 unchanged lines hidden (view full) ---

260static struct bwn_dma_ring *bwn_dma_select(struct bwn_mac *,
261 uint8_t);
262static int bwn_dma_attach(struct bwn_mac *);
263static struct bwn_dma_ring *bwn_dma_ringsetup(struct bwn_mac *,
264 int, int, int);
265static struct bwn_dma_ring *bwn_dma_parse_cookie(struct bwn_mac *,
266 const struct bwn_txstatus *, uint16_t, int *);
267static void bwn_dma_free(struct bwn_mac *);
268static int bwn_fw_gets(struct bwn_mac *, enum bwn_fwtype);
269static int bwn_fw_get(struct bwn_mac *, enum bwn_fwtype,
270 const char *, struct bwn_fwfile *);
271static void bwn_release_firmware(struct bwn_mac *);
272static void bwn_do_release_fw(struct bwn_fwfile *);
273static uint16_t bwn_fwcaps_read(struct bwn_mac *);
274static int bwn_fwinitvals_write(struct bwn_mac *,
275 const struct bwn_fwinitvals *, size_t, size_t);
276static uint16_t bwn_ant2phy(int);
277static void bwn_mac_write_bssid(struct bwn_mac *);
278static void bwn_mac_setfilter(struct bwn_mac *, uint16_t,
279 const uint8_t *);
280static void bwn_key_dowrite(struct bwn_mac *, uint8_t, uint8_t,
281 const uint8_t *, size_t, const uint8_t *);
282static void bwn_key_macwrite(struct bwn_mac *, uint8_t,
283 const uint8_t *);

--- 31 unchanged lines hidden (view full) ---

315static int bwn_tx_isfull(struct bwn_softc *, struct mbuf *);
316static int bwn_set_txhdr(struct bwn_mac *,
317 struct ieee80211_node *, struct mbuf *, struct bwn_txhdr *,
318 uint16_t);
319static void bwn_plcp_genhdr(struct bwn_plcp4 *, const uint16_t,
320 const uint8_t);
321static uint8_t bwn_antenna_sanitize(struct bwn_mac *, uint8_t);
322static uint8_t bwn_get_fbrate(uint8_t);
323static void bwn_txpwr(void *, int);
324static void bwn_tasks(void *);
325static void bwn_task_15s(struct bwn_mac *);
326static void bwn_task_30s(struct bwn_mac *);
327static void bwn_task_60s(struct bwn_mac *);
328static int bwn_plcp_get_ofdmrate(struct bwn_mac *, struct bwn_plcp6 *,
329 uint8_t);
330static int bwn_plcp_get_cckrate(struct bwn_mac *, struct bwn_plcp6 *);
331static void bwn_rx_radiotap(struct bwn_mac *, struct mbuf *,
332 const struct bwn_rxhdr4 *, struct bwn_plcp6 *, int,
333 int, int);
334static void bwn_tsf_read(struct bwn_mac *, uint64_t *);
335static void bwn_set_slot_time(struct bwn_mac *, uint16_t);
336static void bwn_watchdog(void *);
337static void bwn_dma_stop(struct bwn_mac *);
338static void bwn_pio_stop(struct bwn_mac *);
339static void bwn_dma_ringstop(struct bwn_dma_ring **);
340static void bwn_led_attach(struct bwn_mac *);
341static void bwn_led_newstate(struct bwn_mac *, enum ieee80211_state);
342static void bwn_led_event(struct bwn_mac *, int);

--- 80 unchanged lines hidden (view full) ---

423 { 6010, 202, 30 }, { 6020, 204, 30 }, { 6030, 206, 30 },
424 { 6040, 208, 30 }, { 6050, 210, 30 }, { 6060, 212, 30 },
425 { 6070, 214, 30 }, { 6080, 216, 30 }, { 6090, 218, 30 },
426 { 6100, 220, 30 }, { 6110, 222, 30 }, { 6120, 224, 30 },
427 { 6130, 226, 30 }, { 6140, 228, 30 } },
428 .nchannels = 110
429};
430
431#define VENDOR_LED_ACT(vendor) \
432{ \
433 .vid = PCI_VENDOR_##vendor, \
434 .led_act = { BWN_VENDOR_LED_ACT_##vendor } \
435}
436
437static const struct {
438 uint16_t vid;

--- 805 unchanged lines hidden (view full) ---

1244 mac->mac_phy.switch_analog(mac, 0);
1245
1246 siba_dev_down(sc->sc_dev, 0);
1247fail:
1248 siba_powerdown(sc->sc_dev);
1249 return (error);
1250}
1251
1252void
1253bwn_reset_core(struct bwn_mac *mac, uint32_t flags)
1254{
1255 struct bwn_softc *sc = mac->mac_sc;
1256 uint32_t low, ctl;
1257
1258 flags |= (BWN_TGSLOW_PHYCLOCK_ENABLE | BWN_TGSLOW_PHYRESET);
1259
1260 siba_dev_up(sc->sc_dev, flags);

--- 153 unchanged lines hidden (view full) ---

1414 }
1415
1416 mac->mac_phy.supports_2ghz = have_bg;
1417 mac->mac_phy.supports_5ghz = have_a;
1418
1419 return (ic->ic_nchans == 0 ? ENXIO : 0);
1420}
1421
1422uint32_t
1423bwn_shm_read_4(struct bwn_mac *mac, uint16_t way, uint16_t offset)
1424{
1425 uint32_t ret;
1426
1427 BWN_ASSERT_LOCKED(mac->mac_sc);
1428
1429 if (way == BWN_SHARED) {
1430 KASSERT((offset & 0x0001) == 0,

--- 9 unchanged lines hidden (view full) ---

1440 offset >>= 2;
1441 }
1442 bwn_shm_ctlword(mac, way, offset);
1443 ret = BWN_READ_4(mac, BWN_SHM_DATA);
1444out:
1445 return (ret);
1446}
1447
1448uint16_t
1449bwn_shm_read_2(struct bwn_mac *mac, uint16_t way, uint16_t offset)
1450{
1451 uint16_t ret;
1452
1453 BWN_ASSERT_LOCKED(mac->mac_sc);
1454
1455 if (way == BWN_SHARED) {
1456 KASSERT((offset & 0x0001) == 0,

--- 19 unchanged lines hidden (view full) ---

1476 uint32_t control;
1477
1478 control = way;
1479 control <<= 16;
1480 control |= offset;
1481 BWN_WRITE_4(mac, BWN_SHM_CONTROL, control);
1482}
1483
1484void
1485bwn_shm_write_4(struct bwn_mac *mac, uint16_t way, uint16_t offset,
1486 uint32_t value)
1487{
1488 BWN_ASSERT_LOCKED(mac->mac_sc);
1489
1490 if (way == BWN_SHARED) {
1491 KASSERT((offset & 0x0001) == 0,
1492 ("%s:%d warn", __func__, __LINE__));

--- 6 unchanged lines hidden (view full) ---

1499 return;
1500 }
1501 offset >>= 2;
1502 }
1503 bwn_shm_ctlword(mac, way, offset);
1504 BWN_WRITE_4(mac, BWN_SHM_DATA, value);
1505}
1506
1507void
1508bwn_shm_write_2(struct bwn_mac *mac, uint16_t way, uint16_t offset,
1509 uint16_t value)
1510{
1511 BWN_ASSERT_LOCKED(mac->mac_sc);
1512
1513 if (way == BWN_SHARED) {
1514 KASSERT((offset & 0x0001) == 0,
1515 ("%s:%d warn", __func__, __LINE__));

--- 65 unchanged lines hidden (view full) ---

1581 c[0].ic_flags &= ~IEEE80211_CHAN_HT;
1582 c[0].ic_flags |= IEEE80211_CHAN_HT20; /* HT20 */
1583 c++, (*nchans)++;
1584 }
1585 }
1586}
1587
1588static int
1589bwn_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
1590 const struct ieee80211_bpf_params *params)
1591{
1592 struct ieee80211com *ic = ni->ni_ic;
1593 struct bwn_softc *sc = ic->ic_softc;
1594 struct bwn_mac *mac = sc->sc_curmac;
1595 int error;
1596

--- 1911 unchanged lines hidden (view full) ---

3508bwn_dma_ring_addr(void *arg, bus_dma_segment_t *seg, int nseg, int error)
3509{
3510 if (!error) {
3511 KASSERT(nseg == 1, ("too many segments(%d)\n", nseg));
3512 *((bus_addr_t *)arg) = seg->ds_addr;
3513 }
3514}
3515
3516void
3517bwn_ram_write(struct bwn_mac *mac, uint16_t offset, uint32_t val)
3518{
3519 uint32_t macctl;
3520
3521 KASSERT(offset % 4 == 0, ("%s:%d: fail", __func__, __LINE__));
3522
3523 macctl = BWN_READ_4(mac, BWN_MACCTL);
3524 if (macctl & BWN_MACCTL_BIGENDIAN)
3525 printf("TODO: need swap\n");
3526
3527 BWN_WRITE_4(mac, BWN_RAM_CONTROL, offset);
3528 BWN_BARRIER(mac, BUS_SPACE_BARRIER_WRITE);
3529 BWN_WRITE_4(mac, BWN_RAM_DATA, val);
3530}
3531
3532void
3533bwn_mac_suspend(struct bwn_mac *mac)
3534{
3535 struct bwn_softc *sc = mac->mac_sc;
3536 int i;
3537 uint32_t tmp;
3538
3539 KASSERT(mac->mac_suspended >= 0,

--- 43 unchanged lines hidden (view full) ---

3583 BWN_READ_4(mac, BWN_MACCTL) | BWN_MACCTL_ON);
3584 BWN_WRITE_4(mac, BWN_INTR_REASON, BWN_INTR_MAC_SUSPENDED);
3585 BWN_READ_4(mac, BWN_MACCTL);
3586 BWN_READ_4(mac, BWN_INTR_REASON);
3587 bwn_psctl(mac, 0);
3588 }
3589}
3590
3591void
3592bwn_psctl(struct bwn_mac *mac, uint32_t flags)
3593{
3594 struct bwn_softc *sc = mac->mac_sc;
3595 int i;
3596 uint16_t ucstat;
3597
3598 KASSERT(!((flags & BWN_PS_ON) && (flags & BWN_PS_OFF)),
3599 ("%s:%d: fail", __func__, __LINE__));

--- 12 unchanged lines hidden (view full) ---

3612 BWN_SHARED_UCODESTAT);
3613 if (ucstat != BWN_SHARED_UCODESTAT_SLEEP)
3614 break;
3615 DELAY(10);
3616 }
3617 }
3618}
3619
3620static int
3621bwn_fw_gets(struct bwn_mac *mac, enum bwn_fwtype type)
3622{
3623 struct bwn_softc *sc = mac->mac_sc;
3624 struct bwn_fw *fw = &mac->mac_fw;
3625 const uint8_t rev = siba_get_revid(sc->sc_dev);
3626 const char *filename;
3627 uint32_t high;

--- 380 unchanged lines hidden (view full) ---

4008 return (0);
4009fail:
4010 device_printf(sc->sc_dev, "initvals: invalid format\n");
4011 return (EPROTO);
4012#undef GET_NEXTIV16
4013#undef GET_NEXTIV32
4014}
4015
4016int
4017bwn_switch_channel(struct bwn_mac *mac, int chan)
4018{
4019 struct bwn_phy *phy = &(mac->mac_phy);
4020 struct bwn_softc *sc = mac->mac_sc;
4021 struct ieee80211com *ic = &sc->sc_ic;
4022 uint16_t channelcookie, savedcookie;
4023 int error;
4024

--- 2027 unchanged lines hidden (view full) ---

6052 slot = bwn_dma_nextslot(dr, dr->dr_curslot);
6053 KASSERT(!(slot & ~0x0fff), ("%s:%d: fail", __func__, __LINE__));
6054 dr->dr_curslot = slot;
6055 dr->dr_usedslot++;
6056
6057 return (slot);
6058}
6059
6060static struct bwn_pio_txqueue *
6061bwn_pio_parse_cookie(struct bwn_mac *mac, uint16_t cookie,
6062 struct bwn_pio_txpkt **pack)
6063{
6064 struct bwn_pio *pio = &mac->mac_method.pio;
6065 struct bwn_pio_txqueue *tq = NULL;
6066 unsigned int index;
6067

--- 738 unchanged lines hidden ---