if_ne_zbus.c revision 1.8 1 /* $NetBSD: if_ne_zbus.c,v 1.8 2002/01/26 13:40:56 aymeric Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bernd Ernesti.
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, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Thanks to Village Tronic for giving me a card.
41 * Bernd Ernesti
42 */
43
44 #include <sys/param.h>
45 #include <sys/device.h>
46 #include <sys/malloc.h>
47 #include <sys/mbuf.h>
48 #include <sys/socket.h>
49 #include <sys/syslog.h>
50 #include <sys/systm.h>
51
52 #include <net/if.h>
53 #include <net/if_media.h>
54 #include <net/if_ether.h>
55
56 #include <machine/bus.h>
57
58 #include <dev/ic/dp8390reg.h>
59 #include <dev/ic/dp8390var.h>
60
61 #include <dev/ic/ne2000reg.h>
62 #include <dev/ic/ne2000var.h>
63
64 #include <dev/ic/rtl80x9reg.h>
65 #include <dev/ic/rtl80x9var.h>
66
67 #include <amiga/amiga/device.h>
68 #include <amiga/amiga/isr.h>
69
70 #include <amiga/dev/zbusvar.h>
71
72 int ne_zbus_match(struct device *, struct cfdata *, void *);
73 void ne_zbus_attach(struct device *, struct device *, void *);
74
75 struct ne_zbus_softc {
76 struct ne2000_softc sc_ne2000;
77 struct bus_space_tag sc_bst;
78 struct isr sc_isr;
79 };
80
81 struct cfattach ne_zbus_ca = {
82 sizeof(struct ne_zbus_softc), ne_zbus_match, ne_zbus_attach
83 };
84
85 /*
86 * The Amiga address are shifted by one bit to the ISA-Bus, but
87 * this is handled by the bus_space functions.
88 */
89 #define NE_ARIADNE_II_NPORTS 0x20
90 #define NE_ARIADNE_II_NICBASE 0x0300 /* 0x0600 */
91 #define NE_ARIADNE_II_NICSIZE 0x10
92 #define NE_ARIADNE_II_ASICBASE 0x0310 /* 0x0620 */
93 #define NE_ARIADNE_II_ASICSIZE 0x10
94
95 int
96 ne_zbus_match(struct device *parent, struct cfdata *cf, void *aux)
97 {
98 struct zbus_args *zap = aux;
99
100 /* Ariadne II ethernet card */
101 if (zap->manid == 2167 && zap->prodid == 202)
102 return (1);
103
104 /* X-surf ethernet card */
105 if (zap->manid == 4626 && zap->prodid == 23)
106 return (1);
107
108 return (0);
109 }
110
111 /*
112 * Install interface into kernel networking data structures
113 */
114 void
115 ne_zbus_attach(struct device *parent, struct device *self, void *aux)
116 {
117 struct ne_zbus_softc *zsc = (struct ne_zbus_softc *)self;
118 struct ne2000_softc *nsc = &zsc->sc_ne2000;
119 struct dp8390_softc *dsc = &nsc->sc_dp8390;
120 struct zbus_args *zap = aux;
121 bus_space_tag_t nict = &zsc->sc_bst;
122 bus_space_handle_t nich;
123 bus_space_tag_t asict = nict;
124 bus_space_handle_t asich;
125
126 dsc->sc_mediachange = rtl80x9_mediachange;
127 dsc->sc_mediastatus = rtl80x9_mediastatus;
128 dsc->init_card = rtl80x9_init_card;
129 dsc->sc_media_init = rtl80x9_media_init;
130
131 zsc->sc_bst.base = (u_long)zap->va + 0;
132 if (zap->manid == 4626)
133 zsc->sc_bst.base += 0x8000;
134
135 zsc->sc_bst.absm = &amiga_bus_stride_2;
136
137 printf("\n");
138
139 /* Map i/o space. */
140 if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) {
141 printf("%s: can't map nic i/o space\n", dsc->sc_dev.dv_xname);
142 return;
143 }
144
145 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE,
146 &asich)) {
147 printf("%s: can't map asic i/o space\n", dsc->sc_dev.dv_xname);
148 return;
149 }
150
151 dsc->sc_regt = nict;
152 dsc->sc_regh = nich;
153
154 nsc->sc_asict = asict;
155 nsc->sc_asich = asich;
156
157 /* This interface is always enabled. */
158 dsc->sc_enabled = 1;
159
160 /*
161 * Do generic NE2000 attach. This will read the station address
162 * from the EEPROM.
163 */
164 ne2000_attach(nsc, NULL);
165
166 zsc->sc_isr.isr_intr = dp8390_intr;
167 zsc->sc_isr.isr_arg = dsc;
168 zsc->sc_isr.isr_ipl = 2;
169 add_isr(&zsc->sc_isr);
170 }
171