1 /* $OpenBSD: if_rtwn.c,v 1.6 2015/08/28 00:03:53 deraadt Exp $ */
4 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5 * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
6 * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
24 #include <sys/param.h>
26 #include <sys/mutex.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/systm.h>
31 #include <sys/malloc.h>
32 #include <sys/queue.h>
33 #include <sys/taskqueue.h>
35 #include <sys/endian.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
42 #include <net/ethernet.h>
43 #include <net/if_media.h>
45 #include <net80211/ieee80211_var.h>
46 #include <net80211/ieee80211_radiotap.h>
48 #include <dev/rtwn/if_rtwnvar.h>
50 #include <dev/rtwn/pci/rtwn_pci_var.h>
51 #include <dev/rtwn/pci/rtwn_pci_reg.h>
55 rtwn_pci_write_1(struct rtwn_softc *sc, uint16_t addr, uint8_t val)
57 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
59 bus_space_write_1(pc->pc_st, pc->pc_sh, addr, val);
65 rtwn_pci_write_2(struct rtwn_softc *sc, uint16_t addr, uint16_t val)
67 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
70 bus_space_write_2(pc->pc_st, pc->pc_sh, addr, val);
76 rtwn_pci_write_4(struct rtwn_softc *sc, uint16_t addr, uint32_t val)
78 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
81 bus_space_write_4(pc->pc_st, pc->pc_sh, addr, val);
87 rtwn_pci_read_1(struct rtwn_softc *sc, uint16_t addr)
89 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
91 return (bus_space_read_1(pc->pc_st, pc->pc_sh, addr));
95 rtwn_pci_read_2(struct rtwn_softc *sc, uint16_t addr)
97 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
100 val = bus_space_read_2(pc->pc_st, pc->pc_sh, addr);
105 rtwn_pci_read_4(struct rtwn_softc *sc, uint16_t addr)
107 struct rtwn_pci_softc *pc = RTWN_PCI_SOFTC(sc);
110 val = bus_space_read_4(pc->pc_st, pc->pc_sh, addr);
115 rtwn_pci_delay(struct rtwn_softc *sc, int usec)
120 (void) mtx_sleep(sc, &sc->sc_mtx, 0, "rtwn_pci",
121 msecs_to_ticks(usec / 1000));