1 /* $NetBSD: if_ep_eisa.c,v 1.40 2009/01/31 13:54:10 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following 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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org>
35 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Herb Peyerl.
49 * This product includes software developed by Jonathan Stone.
50 * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse
51 * or promote products derived from this software without specific
52 * prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.40 2009/01/31 13:54:10 martin Exp $");
72 #include <sys/param.h>
73 #include <sys/systm.h>
75 #include <sys/socket.h>
76 #include <sys/ioctl.h>
77 #include <sys/errno.h>
78 #include <sys/syslog.h>
79 #include <sys/select.h>
80 #include <sys/device.h>
83 #include <net/if_dl.h>
84 #include <net/if_ether.h>
85 #include <net/if_media.h>
88 #include <netinet/in.h>
89 #include <netinet/in_systm.h>
90 #include <netinet/in_var.h>
91 #include <netinet/ip.h>
92 #include <netinet/if_inarp.h>
98 #include <net/bpfdesc.h>
103 #include <sys/intr.h>
105 #include <dev/mii/miivar.h>
107 #include <dev/ic/elink3var.h>
108 #include <dev/ic/elink3reg.h>
110 #include <dev/eisa/eisareg.h>
111 #include <dev/eisa/eisavar.h>
112 #include <dev/eisa/eisadevs.h>
114 static int ep_eisa_match(device_t
, cfdata_t
, void *);
115 static void ep_eisa_attach(device_t
, device_t
, void *);
117 CFATTACH_DECL_NEW(ep_eisa
, sizeof(struct ep_softc
),
118 ep_eisa_match
, ep_eisa_attach
, NULL
, NULL
);
120 /* XXX move these somewhere else */
121 /* While attaching we need a few special EISA registers of the card,
122 these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */
123 #define EP_EISA_CFG_BASE 0x0c80
124 #define EP_EISA_CFG_CONTROL 0x0004 /* 1 byte */
125 #define EP_EISA_CFG_RESOURCE 0x0008 /* 2 byte */
126 #define EP_EISA_CFG_SIZE 0x000a
128 /* The generic driver backend only needs access to the standard ports,
129 mapped at the beginning of the eisa slot space */
130 #define EP_IOPORT_OFFSET 0x0000
131 #define EP_IOPORT_SIZE 0x0020
133 /* Bits for the eisa control register */
134 #define EISA_RESET 0x04
135 #define EISA_ERROR 0x02
136 #define EISA_ENABLE 0x01
138 static const struct ep_eisa_product
{
139 const char *eep_eisaid
; /* EISA ID */
140 u_short eep_chipset
; /* 3Com chipset used */
141 int eep_flags
; /* initial softc flags */
142 const char *eep_name
; /* device name */
143 } ep_eisa_products
[] = {
144 { "TCM5090", ELINK_CHIPSET_3C509
,
145 0, EISA_PRODUCT_TCM5090
},
146 { "TCM5091", ELINK_CHIPSET_3C509
,
147 0, EISA_PRODUCT_TCM5091
},
148 { "TCM5092", ELINK_CHIPSET_3C509
,
149 0, EISA_PRODUCT_TCM5092
},
150 { "TCM5093", ELINK_CHIPSET_3C509
,
151 0, EISA_PRODUCT_TCM5093
},
152 { "TCM5094", ELINK_CHIPSET_3C509
,
153 0, EISA_PRODUCT_TCM5094
},
154 { "TCM5095", ELINK_CHIPSET_3C509
,
155 0, EISA_PRODUCT_TCM5095
},
156 { "TCM5098", ELINK_CHIPSET_3C509
,
157 0, EISA_PRODUCT_TCM5098
},
160 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
161 * MII connector for an external PHY. We treat it as
162 * `manual' in the core driver.
164 { "TCM5920", ELINK_CHIPSET_VORTEX
,
165 0, EISA_PRODUCT_TCM5920
},
166 { "TCM5970", ELINK_CHIPSET_VORTEX
,
167 0, EISA_PRODUCT_TCM5970
},
168 { "TCM5971", ELINK_CHIPSET_VORTEX
,
169 0, EISA_PRODUCT_TCM5971
},
170 { "TCM5972", ELINK_CHIPSET_VORTEX
,
171 0, EISA_PRODUCT_TCM5972
},
177 static const struct ep_eisa_product
*
178 ep_eisa_lookup(const struct eisa_attach_args
*ea
)
180 const struct ep_eisa_product
*eep
;
182 for (eep
= ep_eisa_products
; eep
->eep_name
!= NULL
; eep
++)
183 if (strcmp(ea
->ea_idstring
, eep
->eep_eisaid
) == 0)
190 ep_eisa_match(device_t parent
, cfdata_t match
, void *aux
)
192 struct eisa_attach_args
*ea
= aux
;
194 /* must match one of our known ID strings */
195 if (ep_eisa_lookup(ea
) != NULL
)
202 ep_eisa_attach(device_t parent
, device_t self
, void *aux
)
204 struct ep_softc
*sc
= device_private(self
);
205 struct eisa_attach_args
*ea
= aux
;
206 bus_space_tag_t iot
= ea
->ea_iot
;
207 bus_space_handle_t ioh
, ioh_cfg
;
208 eisa_chipset_tag_t ec
= ea
->ea_ec
;
209 eisa_intr_handle_t ih
;
211 const struct ep_eisa_product
*eep
;
215 if (bus_space_map(iot
, EISA_SLOT_ADDR(ea
->ea_slot
) + EP_EISA_CFG_BASE
,
216 EP_EISA_CFG_SIZE
, 0, &ioh_cfg
)) {
218 panic("ep_eisa_attach: can't map eisa cfg i/o space");
220 if (bus_space_map(iot
, EISA_SLOT_ADDR(ea
->ea_slot
) + EP_IOPORT_OFFSET
,
221 EP_IOPORT_SIZE
, 0, &ioh
)) {
223 panic("ep_eisa_attach: can't map i/o space");
230 bus_space_write_1(iot
, ioh_cfg
, EP_EISA_CFG_CONTROL
, EISA_ENABLE
);
233 /* Read the IRQ from the card. */
234 irq
= bus_space_read_2(iot
, ioh_cfg
, EP_EISA_CFG_RESOURCE
) >> 12;
236 eep
= ep_eisa_lookup(ea
);
239 panic("ep_eisa_attach: impossible");
242 /* we don't need access to the config registers any more, but
243 noone else should be able to map this space, so keep it
246 bus_space_unmap(iot
, ioh_cfg
, EP_EISA_CFG_SIZE
);
249 printf(": %s\n", eep
->eep_name
);
255 sc
->bustype
= ELINK_BUS_EISA
;
256 sc
->ep_flags
= eep
->eep_flags
;
258 if (eisa_intr_map(ec
, irq
, &ih
)) {
259 aprint_error_dev(sc
->sc_dev
, "couldn't map interrupt (%u)\n",
263 intrstr
= eisa_intr_string(ec
, ih
);
264 sc
->sc_ih
= eisa_intr_establish(ec
, ih
, IST_EDGE
, IPL_NET
,
266 if (sc
->sc_ih
== NULL
) {
267 aprint_error_dev(sc
->sc_dev
, "couldn't establish interrupt");
269 aprint_error(" at %s", intrstr
);
274 aprint_normal_dev(sc
->sc_dev
, "interrupting at %s\n", intrstr
);
276 epconfig(sc
, eep
->eep_chipset
, NULL
);