📄 if_le_pci.c
字号:
#undef LEDEBUG#define DWIO/* $OpenBSD: if_le_pci.c,v 1.12 1999/08/10 08:10:35 deraadt Exp $ *//* $NetBSD: if_le_pci.c,v 1.13 1996/10/25 21:33:32 cgd Exp $ *//*- * Copyright (c) 1995 Charles M. Hannum. All rights reserved. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)if_le.c 8.2 (Berkeley) 11/16/93 */#include "bpfilter.h"#include <sys/param.h>#include <sys/systm.h>#include <sys/mbuf.h>#include <sys/syslog.h>#include <sys/socket.h>#if defined(PROM)#include <pci/device.h>#else#include <sys/device.h>#endif#include <vm/vm.h>#include <vm/vm_kern.h>#include <vm/vm_param.h>#include <net/if.h>#include <net/if_media.h>#ifdef INET#include <netinet/in.h>#include <netinet/if_ether.h>#endif#include <vm/vm.h>#include <machine/cpu.h>#ifdef PROM#include <pci/pcireg.h>#include <pci/pcivar.h>#include <pci/pcidevs.h>#include "am7990reg.h"#include "am7990var.h"#include "if_levar.h"#else#include <machine/bus.h>#include <machine/intr.h>#include <dev/pci/pcireg.h>#include <dev/pci/pcivar.h>#include <dev/pci/pcidevs.h>#include <dev/ic/am7990reg.h>#include <dev/ic/am7990var.h>#include <dev/pci/if_levar.h>#endif#ifdef __alpha__ /* XXX *//* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */ #undef vtophys#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)(va))#endifint le_pci_match __P((struct device *, void *, void *));void le_pci_attach __P((struct device *, struct device *, void *));#ifdef PROM/* host <-> little endian conversion */#if #endian(little)#define ltohl(x) (x)#define ltohs(x) (x)#define htoll(x) (x)#define htols(x) (x)#else#define ltohl(x) \ ({ \ unsigned long v = x; \ ((v & 0x000000ff) << 24) | \ ((v & 0x0000ff00) << 8) | \ ((v >> 8) & 0x0000ff00) | \ ((v >> 24) & 0x000000ff); \ })#define ltohs(x) \ ({ \ unsigned short v = x; \ (((v << 8) & 0xff00) | \ ((v >> 8) & 0x00ff)); \ })#define htoll(x) ltohl(x)#define htols(x) ltohs(x)#endif#ifdef P6032#define htorl(x) x#define rtohl(x) x#define htors(x) x#define rtohs(x) x#else#define htorl(x) htoll(x)#define rtohl(x) ltohl(x)#define htors(x) htols(x)#define rtohs(x) ltohs(x)#endif#define htoml(x) htoll(x)#define mtohl(x) ltohl(x)#define htoms(x) htols(x)#define mtohs(x) ltohs(x)hide void le_pci_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));hide u_int16_t le_pci_rdcsr __P((struct am7990_softc *, u_int16_t));hide void le_pci_wrbcr __P((struct am7990_softc *, u_int16_t, u_int16_t));hide u_int16_t le_pci_rdbcr __P((struct am7990_softc *, u_int16_t));hide void le_pci_wranr __P((struct am7990_softc *, u_int16_t, u_int16_t, u_int16_t));hide u_int16_t le_pci_rdanr __P((struct am7990_softc *, u_int16_t, u_int16_t));#include "am7990.c"#undef vtophys#define vtophys(va) _pci_dmamap ((vm_offset_t)(va), 0)#elsestruct cfattach le_pci_ca = { sizeof(struct le_softc), le_pci_match, le_pci_attach};#endif/* * PCI constants. * XXX These should be in a common file! */#define PCI_CBIO 0x10 /* Configuration Base IO Address */hide voidle_pci_wrcsr(sc, port, val) struct am7990_softc *sc; u_int16_t port, val;{ struct le_softc *lesc = (struct le_softc *)sc;#ifdef PROM#ifdef DWIO *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rap) = htorl(port); *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rdp) = htorl(val);#else *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rap) = htors(port); *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rdp) = htors(val);#endif#else bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; bus_space_write_2(iot, ioh, lesc->sc_rap, port); bus_space_write_2(iot, ioh, lesc->sc_rdp, val);#endif}hide u_int16_tle_pci_rdcsr(sc, port) struct am7990_softc *sc; u_int16_t port;{ struct le_softc *lesc = (struct le_softc *)sc;#ifdef PROM u_int16_t val;#ifdef DWIO *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rap) = htorl(port); val = *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rdp); val = rtohs(val);#else *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rap) = htors(port); val = rtohs(*(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rdp));#endif#else bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; u_int16_t val; bus_space_write_2(iot, ioh, lesc->sc_rap, port); val = bus_space_read_2(iot, ioh, lesc->sc_rdp);#endif return (val);}hide voidle_pci_wrbcr(sc, port, val) struct am7990_softc *sc; u_int16_t port, val;{ struct le_softc *lesc = (struct le_softc *)sc;#ifdef PROM#ifdef DWIO *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rap) = htorl(port); *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_bdp) = htorl(val);#else *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rap) = htors(port); *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_bdp) = htors(val);#endif#else bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; bus_space_write_2(iot, ioh, lesc->sc_rap, port); bus_space_write_2(iot, ioh, lesc->sc_rbp, val);#endif}hide u_int16_tle_pci_rdbcr(sc, port) struct am7990_softc *sc; u_int16_t port;{ struct le_softc *lesc = (struct le_softc *)sc;#ifdef PROM u_int16_t val;#ifdef DWIO *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_rap) = htorl(port); val = *(volatile u_int32_t *)(lesc->sc_iobase + lesc->sc_bdp); val = rtohs(val);#else *(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_rap) = htors(port); val = rtohs(*(volatile u_int16_t *)(lesc->sc_iobase + lesc->sc_bdp));#endif#else bus_space_tag_t iot = lesc->sc_iot; bus_space_handle_t ioh = lesc->sc_ioh; u_int16_t val; bus_space_write_2(iot, ioh, lesc->sc_rap, port); val = bus_space_read_2(iot, ioh, lesc->sc_rbp);#endif return (val);}hide voidle_pci_wranr(sc, phy, port, val) struct am7990_softc *sc; u_int16_t phy, port, val;{ le_pci_wrbcr (sc, 33, (phy << 5) | port); le_pci_wrbcr (sc, 34, val);}hide u_int16_tle_pci_rdanr(sc, phy, port) struct am7990_softc *sc; u_int16_t phy, port;{ le_pci_wrbcr (sc, 33, (phy << 5) | port); return le_pci_rdbcr (sc, 34);}intle_pci_match(parent, match, aux) struct device *parent; void *match, *aux;{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -