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