Home | History | Annotate | Line # | Download | only in pci
if_athn_pci.c revision 1.10.4.2
      1  1.10.4.2  yamt /*	$NetBSD: if_athn_pci.c,v 1.10.4.2 2014/05/22 11:40:24 yamt Exp $	*/
      2  1.10.4.2  yamt /*	$OpenBSD: if_athn_pci.c,v 1.11 2011/01/08 10:02:32 damien Exp $	*/
      3  1.10.4.2  yamt 
      4  1.10.4.2  yamt /*-
      5  1.10.4.2  yamt  * Copyright (c) 2009 Damien Bergamini <damien.bergamini (at) free.fr>
      6  1.10.4.2  yamt  *
      7  1.10.4.2  yamt  * Permission to use, copy, modify, and distribute this software for any
      8  1.10.4.2  yamt  * purpose with or without fee is hereby granted, provided that the above
      9  1.10.4.2  yamt  * copyright notice and this permission notice appear in all copies.
     10  1.10.4.2  yamt  *
     11  1.10.4.2  yamt  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  1.10.4.2  yamt  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  1.10.4.2  yamt  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  1.10.4.2  yamt  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  1.10.4.2  yamt  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  1.10.4.2  yamt  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  1.10.4.2  yamt  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  1.10.4.2  yamt  */
     19  1.10.4.2  yamt 
     20  1.10.4.2  yamt /*
     21  1.10.4.2  yamt  * PCI front-end for Atheros 802.11a/g/n chipsets.
     22  1.10.4.2  yamt  */
     23  1.10.4.2  yamt 
     24  1.10.4.2  yamt #include <sys/cdefs.h>
     25  1.10.4.2  yamt __KERNEL_RCSID(0, "$NetBSD: if_athn_pci.c,v 1.10.4.2 2014/05/22 11:40:24 yamt Exp $");
     26  1.10.4.2  yamt 
     27  1.10.4.2  yamt #include "opt_inet.h"
     28  1.10.4.2  yamt 
     29  1.10.4.2  yamt #include <sys/param.h>
     30  1.10.4.2  yamt #include <sys/sockio.h>
     31  1.10.4.2  yamt #include <sys/mbuf.h>
     32  1.10.4.2  yamt #include <sys/kernel.h>
     33  1.10.4.2  yamt #include <sys/socket.h>
     34  1.10.4.2  yamt #include <sys/systm.h>
     35  1.10.4.2  yamt #include <sys/malloc.h>
     36  1.10.4.2  yamt #include <sys/callout.h>
     37  1.10.4.2  yamt #include <sys/device.h>
     38  1.10.4.2  yamt 
     39  1.10.4.2  yamt #include <sys/bus.h>
     40  1.10.4.2  yamt #include <sys/intr.h>
     41  1.10.4.2  yamt 
     42  1.10.4.2  yamt #include <net/if.h>
     43  1.10.4.2  yamt #include <net/if_ether.h>
     44  1.10.4.2  yamt #include <net/if_media.h>
     45  1.10.4.2  yamt 
     46  1.10.4.2  yamt #include <net80211/ieee80211_var.h>
     47  1.10.4.2  yamt #include <net80211/ieee80211_amrr.h>
     48  1.10.4.2  yamt #include <net80211/ieee80211_radiotap.h>
     49  1.10.4.2  yamt 
     50  1.10.4.2  yamt #include <dev/ic/athnreg.h>
     51  1.10.4.2  yamt #include <dev/ic/athnvar.h>
     52  1.10.4.2  yamt 
     53  1.10.4.2  yamt #include <dev/pci/pcireg.h>
     54  1.10.4.2  yamt #include <dev/pci/pcivar.h>
     55  1.10.4.2  yamt #include <dev/pci/pcidevs.h>
     56  1.10.4.2  yamt 
     57  1.10.4.2  yamt #define PCI_SUBSYSID_ATHEROS_COEX2WIRE		0x309b
     58  1.10.4.2  yamt #define PCI_SUBSYSID_ATHEROS_COEX3WIRE_SA	0x30aa
     59  1.10.4.2  yamt #define PCI_SUBSYSID_ATHEROS_COEX3WIRE_DA	0x30ab
     60  1.10.4.2  yamt 
     61  1.10.4.2  yamt #define ATHN_PCI_MMBA	PCI_BAR(0)	/* memory mapped base */
     62  1.10.4.2  yamt 
     63  1.10.4.2  yamt struct athn_pci_softc {
     64  1.10.4.2  yamt 	struct athn_softc	psc_sc;
     65  1.10.4.2  yamt 
     66  1.10.4.2  yamt 	/* PCI specific goo. */
     67  1.10.4.2  yamt 	pci_chipset_tag_t	psc_pc;
     68  1.10.4.2  yamt 	pcitag_t		psc_tag;
     69  1.10.4.2  yamt 	pci_intr_handle_t	psc_pih;
     70  1.10.4.2  yamt 	void			*psc_ih;
     71  1.10.4.2  yamt 	bus_space_tag_t		psc_iot;
     72  1.10.4.2  yamt 	bus_space_handle_t	psc_ioh;
     73  1.10.4.2  yamt 	bus_size_t		psc_mapsz;
     74  1.10.4.2  yamt 	int			psc_cap_off;
     75  1.10.4.2  yamt };
     76  1.10.4.2  yamt 
     77  1.10.4.2  yamt #define Static static
     78  1.10.4.2  yamt 
     79  1.10.4.2  yamt Static int	athn_pci_match(device_t, cfdata_t, void *);
     80  1.10.4.2  yamt Static void	athn_pci_attach(device_t, device_t, void *);
     81  1.10.4.2  yamt Static int	athn_pci_detach(device_t, int);
     82  1.10.4.2  yamt Static int	athn_pci_activate(device_t, enum devact);
     83  1.10.4.2  yamt 
     84  1.10.4.2  yamt CFATTACH_DECL_NEW(athn_pci, sizeof(struct athn_pci_softc), athn_pci_match,
     85  1.10.4.2  yamt     athn_pci_attach, athn_pci_detach, athn_pci_activate);
     86  1.10.4.2  yamt 
     87  1.10.4.2  yamt Static bool	athn_pci_resume(device_t, const pmf_qual_t *);
     88  1.10.4.2  yamt Static bool	athn_pci_suspend(device_t, const pmf_qual_t *);
     89  1.10.4.2  yamt Static uint32_t	athn_pci_read(struct athn_softc *, uint32_t);
     90  1.10.4.2  yamt Static void	athn_pci_write(struct athn_softc *, uint32_t, uint32_t);
     91  1.10.4.2  yamt Static void	athn_pci_write_barrier(struct athn_softc *);
     92  1.10.4.2  yamt Static void	athn_pci_disable_aspm(struct athn_softc *);
     93  1.10.4.2  yamt 
     94  1.10.4.2  yamt Static int
     95  1.10.4.2  yamt athn_pci_match(device_t parent, cfdata_t match, void *aux)
     96  1.10.4.2  yamt {
     97  1.10.4.2  yamt 	static const struct {
     98  1.10.4.2  yamt 		pci_vendor_id_t		apd_vendor;
     99  1.10.4.2  yamt 		pci_product_id_t	apd_product;
    100  1.10.4.2  yamt 	} athn_pci_devices[] = {
    101  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR5416 },
    102  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR5418 },
    103  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9160 },
    104  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9280 },
    105  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9281 },
    106  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9285 },
    107  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR2427 },
    108  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9227 },
    109  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9287 },
    110  1.10.4.2  yamt 		{ PCI_VENDOR_ATHEROS, PCI_PRODUCT_ATHEROS_AR9300 }
    111  1.10.4.2  yamt 	};
    112  1.10.4.2  yamt 	struct pci_attach_args *pa = aux;
    113  1.10.4.2  yamt 	size_t i;
    114  1.10.4.2  yamt 
    115  1.10.4.2  yamt 	for (i = 0; i < __arraycount(athn_pci_devices); i++) {
    116  1.10.4.2  yamt 		if (PCI_VENDOR(pa->pa_id) == athn_pci_devices[i].apd_vendor &&
    117  1.10.4.2  yamt 		    PCI_PRODUCT(pa->pa_id) == athn_pci_devices[i].apd_product)
    118  1.10.4.2  yamt 			/*
    119  1.10.4.2  yamt 			 * Match better than 1, we prefer this driver
    120  1.10.4.2  yamt 			 * over ath(4)
    121  1.10.4.2  yamt 			 */
    122  1.10.4.2  yamt 			return 10;
    123  1.10.4.2  yamt 	}
    124  1.10.4.2  yamt 	return 0;
    125  1.10.4.2  yamt }
    126  1.10.4.2  yamt 
    127  1.10.4.2  yamt Static void
    128  1.10.4.2  yamt athn_pci_attach(device_t parent, device_t self, void *aux)
    129  1.10.4.2  yamt {
    130  1.10.4.2  yamt 	struct athn_pci_softc *psc = device_private(self);
    131  1.10.4.2  yamt 	struct athn_softc *sc = &psc->psc_sc;
    132  1.10.4.2  yamt 	struct ieee80211com *ic = &sc->sc_ic;
    133  1.10.4.2  yamt 	struct pci_attach_args *pa = aux;
    134  1.10.4.2  yamt 	const char *intrstr;
    135  1.10.4.2  yamt 	pcireg_t memtype, reg;
    136  1.10.4.2  yamt 	pci_product_id_t subsysid;
    137  1.10.4.2  yamt 	int error;
    138  1.10.4.2  yamt 	char intrbuf[PCI_INTRSTR_LEN];
    139  1.10.4.2  yamt 
    140  1.10.4.2  yamt 	sc->sc_dev = self;
    141  1.10.4.2  yamt 	sc->sc_dmat = pa->pa_dmat;
    142  1.10.4.2  yamt 	psc->psc_pc = pa->pa_pc;
    143  1.10.4.2  yamt 	psc->psc_tag = pa->pa_tag;
    144  1.10.4.2  yamt 
    145  1.10.4.2  yamt 	sc->sc_ops.read = athn_pci_read;
    146  1.10.4.2  yamt 	sc->sc_ops.write = athn_pci_write;
    147  1.10.4.2  yamt 	sc->sc_ops.write_barrier = athn_pci_write_barrier;
    148  1.10.4.2  yamt 
    149  1.10.4.2  yamt 	/*
    150  1.10.4.2  yamt 	 * Get the offset of the PCI Express Capability Structure in PCI
    151  1.10.4.2  yamt 	 * Configuration Space (Linux hardcodes it as 0x60.)
    152  1.10.4.2  yamt 	 */
    153  1.10.4.2  yamt 	error = pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_PCIEXPRESS,
    154  1.10.4.2  yamt 	    &psc->psc_cap_off, NULL);
    155  1.10.4.2  yamt 	if (error != 0) {	/* Found. */
    156  1.10.4.2  yamt 		sc->sc_disable_aspm = athn_pci_disable_aspm;
    157  1.10.4.2  yamt 		sc->sc_flags |= ATHN_FLAG_PCIE;
    158  1.10.4.2  yamt 	}
    159  1.10.4.2  yamt 	/*
    160  1.10.4.2  yamt 	 * Noone knows why this shit is necessary but there are claims that
    161  1.10.4.2  yamt 	 * not doing this may cause very frequent PCI FATAL interrupts from
    162  1.10.4.2  yamt 	 * the card: http://bugzilla.kernel.org/show_bug.cgi?id=13483
    163  1.10.4.2  yamt 	 */
    164  1.10.4.2  yamt 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x40);
    165  1.10.4.2  yamt 	if (reg & 0xff00)
    166  1.10.4.2  yamt 		pci_conf_write(pa->pa_pc, pa->pa_tag, 0x40, reg & ~0xff00);
    167  1.10.4.2  yamt 
    168  1.10.4.2  yamt 	/* Change latency timer; default value yields poor results. */
    169  1.10.4.2  yamt 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    170  1.10.4.2  yamt 	reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    171  1.10.4.2  yamt 	reg |= 168 << PCI_LATTIMER_SHIFT;
    172  1.10.4.2  yamt 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, reg);
    173  1.10.4.2  yamt 
    174  1.10.4.2  yamt 	/* Determine if bluetooth is also supported (combo chip.) */
    175  1.10.4.2  yamt 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    176  1.10.4.2  yamt 	subsysid = PCI_PRODUCT(reg);
    177  1.10.4.2  yamt 	if (subsysid == PCI_SUBSYSID_ATHEROS_COEX3WIRE_SA ||
    178  1.10.4.2  yamt 	    subsysid == PCI_SUBSYSID_ATHEROS_COEX3WIRE_DA)
    179  1.10.4.2  yamt 		sc->sc_flags |= ATHN_FLAG_BTCOEX3WIRE;
    180  1.10.4.2  yamt 	else if (subsysid == PCI_SUBSYSID_ATHEROS_COEX2WIRE)
    181  1.10.4.2  yamt 		sc->sc_flags |= ATHN_FLAG_BTCOEX2WIRE;
    182  1.10.4.2  yamt 
    183  1.10.4.2  yamt 	/*
    184  1.10.4.2  yamt 	 * Setup memory-mapping of PCI registers.
    185  1.10.4.2  yamt 	 */
    186  1.10.4.2  yamt 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, ATHN_PCI_MMBA);
    187  1.10.4.2  yamt 	if (memtype != PCI_MAPREG_TYPE_MEM &&
    188  1.10.4.2  yamt 	    memtype != PCI_MAPREG_MEM_TYPE_64BIT) {
    189  1.10.4.2  yamt 		aprint_error_dev(self, "bad pci register type %d\n",
    190  1.10.4.2  yamt 		    (int)memtype);
    191  1.10.4.2  yamt 		goto fail;
    192  1.10.4.2  yamt 	}
    193  1.10.4.2  yamt 	error = pci_mapreg_map(pa, ATHN_PCI_MMBA, memtype, 0, &psc->psc_iot,
    194  1.10.4.2  yamt 	    &psc->psc_ioh, NULL, &psc->psc_mapsz);
    195  1.10.4.2  yamt 	if (error != 0) {
    196  1.10.4.2  yamt 		aprint_error_dev(self, "cannot map register space\n");
    197  1.10.4.2  yamt 		goto fail;
    198  1.10.4.2  yamt 	}
    199  1.10.4.2  yamt 
    200  1.10.4.2  yamt 	/*
    201  1.10.4.2  yamt 	 * Arrange interrupt line.
    202  1.10.4.2  yamt 	 */
    203  1.10.4.2  yamt 	if (pci_intr_map(pa, &psc->psc_pih) != 0) {
    204  1.10.4.2  yamt 		aprint_error_dev(self, "couldn't map interrupt\n");
    205  1.10.4.2  yamt 		goto fail1;
    206  1.10.4.2  yamt 	}
    207  1.10.4.2  yamt 
    208  1.10.4.2  yamt 	intrstr = pci_intr_string(psc->psc_pc, psc->psc_pih, intrbuf, sizeof(intrbuf));
    209  1.10.4.2  yamt 	psc->psc_ih = pci_intr_establish(psc->psc_pc, psc->psc_pih, IPL_NET,
    210  1.10.4.2  yamt 	    athn_intr, sc);
    211  1.10.4.2  yamt 	if (psc->psc_ih == NULL) {
    212  1.10.4.2  yamt 		aprint_error_dev(self, "couldn't map interrupt\n");
    213  1.10.4.2  yamt 		goto fail1;
    214  1.10.4.2  yamt 	}
    215  1.10.4.2  yamt 
    216  1.10.4.2  yamt 	ic->ic_ifp = &sc->sc_if;
    217  1.10.4.2  yamt 	if (athn_attach(sc) != 0)
    218  1.10.4.2  yamt 		goto fail2;
    219  1.10.4.2  yamt 
    220  1.10.4.2  yamt 	aprint_verbose_dev(self, "interrupting at %s\n", intrstr);
    221  1.10.4.2  yamt 
    222  1.10.4.2  yamt 	if (pmf_device_register(self, athn_pci_suspend, athn_pci_resume)) {
    223  1.10.4.2  yamt 		pmf_class_network_register(self, &sc->sc_if);
    224  1.10.4.2  yamt 		pmf_device_suspend(self, &sc->sc_qual);
    225  1.10.4.2  yamt 	}
    226  1.10.4.2  yamt 	else
    227  1.10.4.2  yamt 		aprint_error_dev(self, "couldn't establish power handler\n");
    228  1.10.4.2  yamt 
    229  1.10.4.2  yamt 	ieee80211_announce(ic);
    230  1.10.4.2  yamt 	return;
    231  1.10.4.2  yamt 
    232  1.10.4.2  yamt  fail2:
    233  1.10.4.2  yamt 	pci_intr_disestablish(psc->psc_pc, psc->psc_ih);
    234  1.10.4.2  yamt 	psc->psc_ih = NULL;
    235  1.10.4.2  yamt  fail1:
    236  1.10.4.2  yamt 	bus_space_unmap(psc->psc_iot, psc->psc_ioh, psc->psc_mapsz);
    237  1.10.4.2  yamt 	psc->psc_mapsz = 0;
    238  1.10.4.2  yamt  fail:
    239  1.10.4.2  yamt 	return;
    240  1.10.4.2  yamt }
    241  1.10.4.2  yamt 
    242  1.10.4.2  yamt Static int
    243  1.10.4.2  yamt athn_pci_detach(device_t self, int flags)
    244  1.10.4.2  yamt {
    245  1.10.4.2  yamt 	struct athn_pci_softc *psc = device_private(self);
    246  1.10.4.2  yamt 	struct athn_softc *sc = &psc->psc_sc;
    247  1.10.4.2  yamt 
    248  1.10.4.2  yamt 	if (psc->psc_ih != NULL) {
    249  1.10.4.2  yamt 		athn_detach(sc);
    250  1.10.4.2  yamt 		pci_intr_disestablish(psc->psc_pc, psc->psc_ih);
    251  1.10.4.2  yamt 		psc->psc_ih = NULL;
    252  1.10.4.2  yamt 	}
    253  1.10.4.2  yamt 	if (psc->psc_mapsz > 0) {
    254  1.10.4.2  yamt 		bus_space_unmap(psc->psc_iot, psc->psc_ioh, psc->psc_mapsz);
    255  1.10.4.2  yamt 		psc->psc_mapsz = 0;
    256  1.10.4.2  yamt 	}
    257  1.10.4.2  yamt 	return 0;
    258  1.10.4.2  yamt }
    259  1.10.4.2  yamt 
    260  1.10.4.2  yamt Static int
    261  1.10.4.2  yamt athn_pci_activate(device_t self, enum devact act)
    262  1.10.4.2  yamt {
    263  1.10.4.2  yamt 	struct athn_pci_softc *psc = device_private(self);
    264  1.10.4.2  yamt 	struct athn_softc *sc = &psc->psc_sc;
    265  1.10.4.2  yamt 
    266  1.10.4.2  yamt 	switch (act) {
    267  1.10.4.2  yamt 	case DVACT_DEACTIVATE:
    268  1.10.4.2  yamt 		if_deactivate(sc->sc_ic.ic_ifp);
    269  1.10.4.2  yamt 		break;
    270  1.10.4.2  yamt 	}
    271  1.10.4.2  yamt 	return 0;
    272  1.10.4.2  yamt }
    273  1.10.4.2  yamt 
    274  1.10.4.2  yamt Static bool
    275  1.10.4.2  yamt athn_pci_suspend(device_t self, const pmf_qual_t *qual)
    276  1.10.4.2  yamt {
    277  1.10.4.2  yamt 	struct athn_pci_softc *psc = device_private(self);
    278  1.10.4.2  yamt 	struct athn_softc *sc = &psc->psc_sc;
    279  1.10.4.2  yamt 
    280  1.10.4.2  yamt 	athn_suspend(sc);
    281  1.10.4.2  yamt 	if (psc->psc_ih != NULL) {
    282  1.10.4.2  yamt 		pci_intr_disestablish(psc->psc_pc, psc->psc_ih);
    283  1.10.4.2  yamt 		psc->psc_ih = NULL;
    284  1.10.4.2  yamt 	}
    285  1.10.4.2  yamt 	return true;
    286  1.10.4.2  yamt }
    287  1.10.4.2  yamt 
    288  1.10.4.2  yamt Static bool
    289  1.10.4.2  yamt athn_pci_resume(device_t self, const pmf_qual_t *qual)
    290  1.10.4.2  yamt {
    291  1.10.4.2  yamt 	struct athn_pci_softc *psc = device_private(self);
    292  1.10.4.2  yamt 	struct athn_softc *sc = &psc->psc_sc;
    293  1.10.4.2  yamt 	pcireg_t reg;
    294  1.10.4.2  yamt 
    295  1.10.4.2  yamt 	/*
    296  1.10.4.2  yamt 	 * XXX: see comment in athn_attach().
    297  1.10.4.2  yamt 	 */
    298  1.10.4.2  yamt 	reg = pci_conf_read(psc->psc_pc, psc->psc_tag, 0x40);
    299  1.10.4.2  yamt 	if (reg & 0xff00)
    300  1.10.4.2  yamt 		pci_conf_write(psc->psc_pc, psc->psc_tag, 0x40, reg & ~0xff00);
    301  1.10.4.2  yamt 
    302  1.10.4.2  yamt 	psc->psc_ih = pci_intr_establish(psc->psc_pc, psc->psc_pih, IPL_NET,
    303  1.10.4.2  yamt 	    athn_intr, sc);
    304  1.10.4.2  yamt 	if (psc->psc_ih == NULL) {
    305  1.10.4.2  yamt 		aprint_error_dev(self, "couldn't map interrupt\n");
    306  1.10.4.2  yamt 		return false;
    307  1.10.4.2  yamt 	}
    308  1.10.4.2  yamt 	return athn_resume(sc);
    309  1.10.4.2  yamt }
    310  1.10.4.2  yamt 
    311  1.10.4.2  yamt Static uint32_t
    312  1.10.4.2  yamt athn_pci_read(struct athn_softc *sc, uint32_t addr)
    313  1.10.4.2  yamt {
    314  1.10.4.2  yamt 	struct athn_pci_softc *psc = (struct athn_pci_softc *)sc;
    315  1.10.4.2  yamt 
    316  1.10.4.2  yamt 	return bus_space_read_4(psc->psc_iot, psc->psc_ioh, addr);
    317  1.10.4.2  yamt }
    318  1.10.4.2  yamt 
    319  1.10.4.2  yamt Static void
    320  1.10.4.2  yamt athn_pci_write(struct athn_softc *sc, uint32_t addr, uint32_t val)
    321  1.10.4.2  yamt {
    322  1.10.4.2  yamt 	struct athn_pci_softc *psc = (struct athn_pci_softc *)sc;
    323  1.10.4.2  yamt 
    324  1.10.4.2  yamt 	bus_space_write_4(psc->psc_iot, psc->psc_ioh, addr, val);
    325  1.10.4.2  yamt }
    326  1.10.4.2  yamt 
    327  1.10.4.2  yamt Static void
    328  1.10.4.2  yamt athn_pci_write_barrier(struct athn_softc *sc)
    329  1.10.4.2  yamt {
    330  1.10.4.2  yamt 	struct athn_pci_softc *psc = (struct athn_pci_softc *)sc;
    331  1.10.4.2  yamt 
    332  1.10.4.2  yamt 	bus_space_barrier(psc->psc_iot, psc->psc_ioh, 0, psc->psc_mapsz,
    333  1.10.4.2  yamt 	    BUS_SPACE_BARRIER_WRITE);
    334  1.10.4.2  yamt }
    335  1.10.4.2  yamt 
    336  1.10.4.2  yamt Static void
    337  1.10.4.2  yamt athn_pci_disable_aspm(struct athn_softc *sc)
    338  1.10.4.2  yamt {
    339  1.10.4.2  yamt 	struct athn_pci_softc *psc = (struct athn_pci_softc *)sc;
    340  1.10.4.2  yamt 	pcireg_t reg;
    341  1.10.4.2  yamt 
    342  1.10.4.2  yamt 	/* Disable PCIe Active State Power Management (ASPM). */
    343  1.10.4.2  yamt 	reg = pci_conf_read(psc->psc_pc, psc->psc_tag,
    344  1.10.4.2  yamt 	    psc->psc_cap_off + PCIE_LCSR);
    345  1.10.4.2  yamt 	reg &= ~(PCIE_LCSR_ASPM_L0S | PCIE_LCSR_ASPM_L1);
    346  1.10.4.2  yamt 	pci_conf_write(psc->psc_pc, psc->psc_tag,
    347  1.10.4.2  yamt 	    psc->psc_cap_off + PCIE_LCSR, reg);
    348  1.10.4.2  yamt }
    349