if_ep_pci.c revision 1.1 1 /* $NetBSD: if_ep_pci.c,v 1.1 1996/04/25 02:17:06 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) novatel.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Herb Peyerl.
18 * 4. The name of Herb Peyerl may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "bpfilter.h"
34
35 #include <sys/param.h>
36 #include <sys/mbuf.h>
37 #include <sys/socket.h>
38 #include <sys/ioctl.h>
39 #include <sys/errno.h>
40 #include <sys/syslog.h>
41 #include <sys/select.h>
42 #include <sys/device.h>
43
44 #include <net/if.h>
45 #include <net/if_dl.h>
46 #include <net/if_types.h>
47
48 #ifdef INET
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
51 #include <netinet/in_var.h>
52 #include <netinet/ip.h>
53 #include <netinet/if_ether.h>
54 #endif
55
56 #ifdef NS
57 #include <netns/ns.h>
58 #include <netns/ns_if.h>
59 #endif
60
61 #if NBPFILTER > 0
62 #include <net/bpf.h>
63 #include <net/bpfdesc.h>
64 #endif
65
66 #include <machine/cpu.h>
67 #include <machine/pio.h>
68
69 #include <dev/ic/elink3var.h>
70 #include <dev/ic/elink3reg.h>
71
72 #include <dev/pci/pcivar.h>
73 #include <dev/pci/pcireg.h>
74 #include <dev/pci/pcidevs.h>
75
76 /* PCI constants */
77 #define PCI_VENDORID(x) ((x) & 0xFFFF)
78 #define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
79 #define PCI_CONN 0x48 /* Connector type */
80 #define PCI_CBMA 0x10 /* Configuration Base Memory Address */
81
82 int ep_pci_match __P((struct device *, void *, void *));
83 void ep_pci_attach __P((struct device *, struct device *, void *));
84
85 struct cfattach ep_pci_ca = {
86 sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
87 };
88
89 int
90 ep_pci_match(parent, match, aux)
91 struct device *parent;
92 void *match, *aux;
93 {
94 struct cfdata *cf = match;
95 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
96
97 if (PCI_VENDORID(pa->pa_id) != PCI_VENDOR_3COM)
98 return 0;
99
100 switch (PCI_CHIPID(pa->pa_id)) {
101 case PCI_PRODUCT_3COM_3C590:
102 case PCI_PRODUCT_3COM_3C595:
103 break;
104 default:
105 return 0;
106 }
107
108 return 1;
109 }
110
111 void
112 ep_pci_attach(parent, self, aux)
113 struct device *parent, *self;
114 void *aux;
115 {
116 struct ep_softc *sc = (void *)self;
117 u_short conn = 0;
118 struct pci_attach_args *pa = aux;
119 pci_chipset_tag_t pc = pa->pa_pc;
120 pci_intr_handle_t ih;
121 int iobase;
122 u_short i;
123 char *model;
124 const char *intrstr = NULL;
125
126 if (pci_map_io(pa->pa_tag, PCI_CBMA, &iobase)) {
127 printf(": couldn't map io\n");
128 return;
129 }
130 sc->bustype = EP_BUS_PCI;
131 sc->ep_iobase = iobase; /* & 0xfffffff0 */
132 i = pci_conf_read(pc, pa->pa_tag, PCI_CONN);
133
134 /*
135 * Bits 13,12,9 of the isa adapter are the same as bits
136 * 5,4,3 of the pci adapter
137 */
138 if (i & IS_PCI_AUI)
139 conn |= IS_AUI;
140 if (i & IS_PCI_BNC)
141 conn |= IS_BNC;
142 if (i & IS_PCI_UTP)
143 conn |= IS_UTP;
144
145 GO_WINDOW(0);
146
147 switch (PCI_CHIPID(pa->pa_id)) {
148 case PCI_PRODUCT_3COM_3C590:
149 model = "3Com 3C590 Ethernet";
150 break;
151
152 case PCI_PRODUCT_3COM_3C595:
153 model = "3Com 3C595 Ethernet";
154 break;
155 default:
156 model = "unknown model!";
157 }
158
159 printf(": %s\n", model);
160
161 epconfig(sc, conn);
162
163 /* Enable the card. */
164 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
165 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
166 PCI_COMMAND_MASTER_ENABLE);
167
168 /* Map and establish the interrupt. */
169 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
170 pa->pa_intrline, &ih)) {
171 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
172 return;
173 }
174 intrstr = pci_intr_string(pc, ih);
175 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
176 if (sc->sc_ih == NULL) {
177 printf("%s: couldn't establish interrupt",
178 sc->sc_dev.dv_xname);
179 if (intrstr != NULL)
180 printf(" at %s", intrstr);
181 printf("\n");
182 return;
183 }
184 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
185
186 epstop(sc);
187 }
188