xref: /openbsd-src/sys/dev/pci/if_fxp_pci.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: if_fxp_pci.c,v 1.8 2001/08/09 21:12:51 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 <vm/vm.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 		return (1);
109 	}
110 
111 	return (0);
112 }
113 
114 void
115 fxp_pci_attach(parent, self, aux)
116 	struct device *parent, *self;
117 	void *aux;
118 {
119 	struct fxp_softc *sc = (struct fxp_softc *)self;
120 	struct pci_attach_args *pa = aux;
121 	pci_chipset_tag_t pc = pa->pa_pc;
122 	pci_intr_handle_t ih;
123 	const char *intrstr = NULL;
124 	u_int8_t enaddr[6];
125 	bus_space_tag_t iot = pa->pa_iot;
126 	bus_addr_t iobase;
127 	bus_size_t iosize;
128 	pcireg_t rev = PCI_REVISION(pa->pa_class);
129 
130 	if (pci_io_find(pc, pa->pa_tag, FXP_PCI_IOBA, &iobase, &iosize)) {
131 		printf(": can't find i/o space\n");
132 		return;
133 	}
134 
135 	if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_sh)) {
136 		printf(": can't map i/o space\n");
137 		return;
138 	}
139 	sc->sc_st = iot;
140 	sc->sc_dmat = pa->pa_dmat;
141 
142 	/*
143 	 * Allocate our interrupt.
144 	 */
145 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
146 	    pa->pa_intrline, &ih)) {
147 		printf(": couldn't map interrupt\n");
148 		return;
149 	}
150 
151 	intrstr = pci_intr_string(pc, ih);
152 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc,
153 	    self->dv_xname);
154 	if (sc->sc_ih == NULL) {
155 		printf(": couldn't establish interrupt");
156 		if (intrstr != NULL)
157 			printf(" at %s", intrstr);
158 		printf("\n");
159 		return;
160 	}
161 
162 	switch (PCI_PRODUCT(pa->pa_id)) {
163 	case PCI_PRODUCT_INTEL_82562:
164 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
165 		/* FALLTHROUGH */
166 	case PCI_PRODUCT_INTEL_82559:
167 	case PCI_PRODUCT_INTEL_82559ER:
168 		sc->not_82557 = 1;
169 		break;
170 	case PCI_PRODUCT_INTEL_82557:
171 		/*
172 		 * revisions
173 		 * 2 = 82557
174 		 * 4-6 = 82558
175 		 * 8 = 82559
176 		 */
177 		sc->not_82557 = (rev >= 4) ? 1 : 0;
178 		break;
179 	default:
180 		sc->not_82557 = 0;
181 		break;
182 	}
183 
184 	/* Do generic parts of attach. */
185 	if (fxp_attach_common(sc, enaddr, intrstr)) {
186 		/* Failed! */
187 		return;
188 	}
189 }
190