1 /* $OpenBSD: if_ep_pci.c,v 1.38 2024/05/24 06:02:53 jsg Exp $ */
2 /* $NetBSD: if_ep_pci.c,v 1.13 1996/10/21 22:56:38 thorpej Exp $ */
3
4 /*
5 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Herb Peyerl.
19 * 4. The name of Herb Peyerl may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/timeout.h>
37 #include <sys/device.h>
38
39 #include <net/if.h>
40 #include <net/if_media.h>
41
42 #include <netinet/in.h>
43 #include <netinet/if_ether.h>
44
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47
48 #include <dev/mii/miivar.h>
49
50 #include <dev/ic/elink3var.h>
51 #include <dev/ic/elink3reg.h>
52
53 #include <dev/pci/pcivar.h>
54 #include <dev/pci/pcireg.h>
55 #include <dev/pci/pcidevs.h>
56
57 /*
58 * PCI constants.
59 * XXX These should be in a common file!
60 */
61 #define PCI_CONN 0x48 /* Connector type */
62 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
63
64 int ep_pci_match(struct device *, void *, void *);
65 void ep_pci_attach(struct device *, struct device *, void *);
66
67 const struct cfattach ep_pci_ca = {
68 sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
69 };
70
71 const struct pci_matchid ep_pci_devices[] = {
72 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C590 },
73 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595MII },
74 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595T4 },
75 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C595TX },
76 };
77
78 int
ep_pci_match(struct device * parent,void * match,void * aux)79 ep_pci_match(struct device *parent, void *match, void *aux)
80 {
81 return (pci_matchbyid((struct pci_attach_args *)aux, ep_pci_devices,
82 nitems(ep_pci_devices)));
83 }
84
85 void
ep_pci_attach(struct device * parent,struct device * self,void * aux)86 ep_pci_attach(struct device *parent, struct device *self, void *aux)
87 {
88 struct ep_softc *sc = (void *)self;
89 struct pci_attach_args *pa = aux;
90 pci_chipset_tag_t pc = pa->pa_pc;
91 bus_size_t iosize;
92 pci_intr_handle_t ih;
93 pcireg_t i;
94 const char *intrstr = NULL;
95
96 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
97 &sc->sc_iot, &sc->sc_ioh, NULL, &iosize, 0)) {
98 printf(": can't map i/o space\n");
99 return;
100 }
101
102 sc->bustype = EP_BUS_PCI;
103
104 i = pci_conf_read(pc, pa->pa_tag, PCI_CONN);
105
106 GO_WINDOW(0);
107
108 printf(":");
109
110 epconfig(sc, EP_CHIPSET_VORTEX, NULL);
111
112 /* Map and establish the interrupt. */
113 if (pci_intr_map(pa, &ih)) {
114 printf(", couldn't map interrupt\n");
115 bus_space_unmap(sc->sc_iot, sc->sc_ioh, iosize);
116 return;
117 }
118 intrstr = pci_intr_string(pc, ih);
119 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr,
120 sc, sc->sc_dev.dv_xname);
121 if (sc->sc_ih == NULL) {
122 printf(": couldn't establish interrupt");
123 if (intrstr != NULL)
124 printf(" at %s", intrstr);
125 printf("\n");
126 bus_space_unmap(sc->sc_iot, sc->sc_ioh, iosize);
127 return;
128 }
129 printf(" %s\n", intrstr);
130 }
131