xref: /openbsd-src/sys/dev/pci/if_fxp_pci.c (revision 47911bd667ac77dc523b8a13ef40b012dbffa741)
1 /*	$OpenBSD: if_fxp_pci.c,v 1.17 2002/11/26 16:14:49 jason 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_PRO_100_VE_0 },
95 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 },
96 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 },
97 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 },
98 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 },
99 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 },
100 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 },
101 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 },
102 };
103 
104 /*
105  * Check if a device is an 82557.
106  */
107 int
108 fxp_pci_match(parent, match, aux)
109 	struct device *parent;
110 	void *match;
111 	void *aux;
112 {
113 	return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices,
114 	    sizeof(fxp_pci_devices)/sizeof(fxp_pci_devices[0])));
115 }
116 
117 void
118 fxp_pci_attach(parent, self, aux)
119 	struct device *parent, *self;
120 	void *aux;
121 {
122 	struct fxp_softc *sc = (struct fxp_softc *)self;
123 	struct pci_attach_args *pa = aux;
124 	pci_chipset_tag_t pc = pa->pa_pc;
125 	pci_intr_handle_t ih;
126 	const char *intrstr = NULL;
127 	u_int8_t enaddr[6];
128 	bus_space_tag_t iot = pa->pa_iot;
129 	bus_addr_t iobase;
130 	bus_size_t iosize;
131 	pcireg_t rev = PCI_REVISION(pa->pa_class);
132 
133 	if (pci_io_find(pc, pa->pa_tag, FXP_PCI_IOBA, &iobase, &iosize)) {
134 		printf(": can't find i/o space\n");
135 		return;
136 	}
137 
138 	if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_sh)) {
139 		printf(": can't map i/o space\n");
140 		return;
141 	}
142 	sc->sc_st = iot;
143 	sc->sc_dmat = pa->pa_dmat;
144 
145 	/*
146 	 * Allocate our interrupt.
147 	 */
148 	if (pci_intr_map(pa, &ih)) {
149 		printf(": couldn't map interrupt\n");
150 		return;
151 	}
152 
153 	intrstr = pci_intr_string(pc, ih);
154 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc,
155 	    self->dv_xname);
156 	if (sc->sc_ih == NULL) {
157 		printf(": couldn't establish interrupt");
158 		if (intrstr != NULL)
159 			printf(" at %s", intrstr);
160 		printf("\n");
161 		return;
162 	}
163 
164 	switch (PCI_PRODUCT(pa->pa_id)) {
165 	case PCI_PRODUCT_INTEL_82562:
166 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
167 		/* FALLTHROUGH */
168 	case PCI_PRODUCT_INTEL_82559:
169 	case PCI_PRODUCT_INTEL_82559ER:
170 		sc->not_82557 = 1;
171 		break;
172 	case PCI_PRODUCT_INTEL_82557:
173 		/*
174 		 * revisions
175 		 * 2 = 82557
176 		 * 4-6 = 82558
177 		 * 8 = 82559
178 		 */
179 		sc->not_82557 = (rev >= 4) ? 1 : 0;
180 		break;
181 	case PCI_PRODUCT_INTEL_PRO_100_VE_0:
182 	case PCI_PRODUCT_INTEL_PRO_100_VE_1:
183 	case PCI_PRODUCT_INTEL_PRO_100_VE_2:
184 	case PCI_PRODUCT_INTEL_PRO_100_VE_3:
185 	case PCI_PRODUCT_INTEL_PRO_100_VM_0:
186 	case PCI_PRODUCT_INTEL_PRO_100_VM_1:
187 	case PCI_PRODUCT_INTEL_PRO_100_VM_2:
188 	case PCI_PRODUCT_INTEL_PRO_100_VM_3:
189 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
190 		sc->not_82557 = 0;
191 		break;
192 	default:
193 		sc->not_82557 = 0;
194 		break;
195 	}
196 
197 	/* Do generic parts of attach. */
198 	if (fxp_attach_common(sc, enaddr, intrstr)) {
199 		/* Failed! */
200 		return;
201 	}
202 }
203