xref: /openbsd/sys/dev/pci/if_fxp_pci.c (revision db3296cf)
1 /*	$OpenBSD: if_fxp_pci.c,v 1.20 2003/06/13 17:49:03 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 1995, David Greenman
5  * All rights reserved.
6  *
7  * Modifications to support NetBSD:
8  * Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice unmodified, this list of conditions, and the following
15  *    disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	Id: if_fxp.c,v 1.55 1998/08/04 08:53:12 dg Exp
33  */
34 
35 /*
36  * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
37  */
38 
39 #include "bpfilter.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/mbuf.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/socket.h>
47 #include <sys/syslog.h>
48 
49 #include <net/if.h>
50 #include <net/if_dl.h>
51 #include <net/if_media.h>
52 #include <net/if_types.h>
53 
54 #ifdef INET
55 #include <netinet/in.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/in_var.h>
58 #include <netinet/ip.h>
59 #endif
60 
61 #include <sys/ioctl.h>
62 #include <sys/errno.h>
63 #include <sys/device.h>
64 
65 #include <netinet/if_ether.h>
66 
67 #include <uvm/uvm_extern.h>
68 
69 #include <machine/cpu.h>
70 #include <machine/bus.h>
71 #include <machine/intr.h>
72 
73 #include <dev/mii/miivar.h>
74 
75 #include <dev/ic/fxpreg.h>
76 #include <dev/ic/fxpvar.h>
77 
78 #include <dev/pci/pcivar.h>
79 #include <dev/pci/pcireg.h>
80 #include <dev/pci/pcidevs.h>
81 
82 int fxp_pci_match(struct device *, void *, void *);
83 void fxp_pci_attach(struct device *, struct device *, void *);
84 
85 struct cfattach fxp_pci_ca = {
86 	sizeof(struct fxp_softc), fxp_pci_match, fxp_pci_attach
87 };
88 
89 const struct pci_matchid fxp_pci_devices[] = {
90 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82557 },
91 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559 },
92 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559ER },
93 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562 },
94 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_0 },
95 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_1 },
96 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_2 },
97 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_0 },
98 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 },
99 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 },
100 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 },
101 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_4 },
102 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_5 },
103 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 },
104 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 },
105 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 },
106 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 },
107 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_4 },
108 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_5 },
109 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_M },
110 };
111 
112 /*
113  * Check if a device is an 82557.
114  */
115 int
116 fxp_pci_match(parent, match, aux)
117 	struct device *parent;
118 	void *match;
119 	void *aux;
120 {
121 	return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices,
122 	    sizeof(fxp_pci_devices)/sizeof(fxp_pci_devices[0])));
123 }
124 
125 void
126 fxp_pci_attach(parent, self, aux)
127 	struct device *parent, *self;
128 	void *aux;
129 {
130 	struct fxp_softc *sc = (struct fxp_softc *)self;
131 	struct pci_attach_args *pa = aux;
132 	pci_chipset_tag_t pc = pa->pa_pc;
133 	pci_intr_handle_t ih;
134 	const char *intrstr = NULL;
135 	u_int8_t enaddr[6];
136 	bus_space_tag_t iot = pa->pa_iot;
137 	bus_addr_t iobase;
138 	bus_size_t iosize;
139 	pcireg_t rev = PCI_REVISION(pa->pa_class);
140 
141 	if (pci_io_find(pc, pa->pa_tag, FXP_PCI_IOBA, &iobase, &iosize)) {
142 		printf(": can't find i/o space\n");
143 		return;
144 	}
145 
146 	if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_sh)) {
147 		printf(": can't map i/o space\n");
148 		return;
149 	}
150 	sc->sc_st = iot;
151 	sc->sc_dmat = pa->pa_dmat;
152 
153 	/*
154 	 * Allocate our interrupt.
155 	 */
156 	if (pci_intr_map(pa, &ih)) {
157 		printf(": couldn't map interrupt\n");
158 		return;
159 	}
160 
161 	intrstr = pci_intr_string(pc, ih);
162 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc,
163 	    self->dv_xname);
164 	if (sc->sc_ih == NULL) {
165 		printf(": couldn't establish interrupt");
166 		if (intrstr != NULL)
167 			printf(" at %s", intrstr);
168 		printf("\n");
169 		return;
170 	}
171 
172 	switch (PCI_PRODUCT(pa->pa_id)) {
173 	case PCI_PRODUCT_INTEL_82562:
174 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
175 		/* FALLTHROUGH */
176 	case PCI_PRODUCT_INTEL_82559:
177 	case PCI_PRODUCT_INTEL_82559ER:
178 		sc->not_82557 = 1;
179 		break;
180 	case PCI_PRODUCT_INTEL_82557:
181 		/*
182 		 * revisions
183 		 * 2 = 82557
184 		 * 4-6 = 82558
185 		 * 8 = 82559
186 		 */
187 		sc->not_82557 = (rev >= 4) ? 1 : 0;
188 		break;
189 	case PCI_PRODUCT_INTEL_PRO_100_VE_0:
190 	case PCI_PRODUCT_INTEL_PRO_100_VE_1:
191 	case PCI_PRODUCT_INTEL_PRO_100_VE_2:
192 	case PCI_PRODUCT_INTEL_PRO_100_VE_3:
193 	case PCI_PRODUCT_INTEL_PRO_100_VE_4:
194 	case PCI_PRODUCT_INTEL_PRO_100_VM_0:
195 	case PCI_PRODUCT_INTEL_PRO_100_VM_1:
196 	case PCI_PRODUCT_INTEL_PRO_100_VM_2:
197 	case PCI_PRODUCT_INTEL_PRO_100_VM_3:
198 	case PCI_PRODUCT_INTEL_PRO_100_VM_4:
199 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
200 		sc->not_82557 = 0;
201 		break;
202 	default:
203 		sc->not_82557 = 0;
204 		break;
205 	}
206 
207 	/* Do generic parts of attach. */
208 	if (fxp_attach_common(sc, enaddr, intrstr)) {
209 		/* Failed! */
210 		return;
211 	}
212 }
213