xref: /netbsd/sys/arch/x68k/dev/if_ne_neptune.c (revision bf9ec67e)
1 /*	$NetBSD: if_ne_neptune.c,v 1.4 2001/02/21 05:44:32 minoura Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
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.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include "opt_inet.h"
41 #include "opt_ns.h"
42 #include "bpfilter.h"
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mbuf.h>
47 #include <sys/socket.h>
48 #include <sys/ioctl.h>
49 #include <sys/errno.h>
50 #include <sys/syslog.h>
51 #include <sys/select.h>
52 #include <sys/device.h>
53 
54 #include <net/if.h>
55 #include <net/if_dl.h>
56 #include <net/if_ether.h>
57 #include <net/if_media.h>
58 
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #include <netinet/if_inarp.h>
65 #endif
66 
67 #ifdef NS
68 #include <netns/ns.h>
69 #include <netns/ns_if.h>
70 #endif
71 
72 #if NBPFILTER > 0
73 #include <net/bpf.h>
74 #include <net/bpfdesc.h>
75 #endif
76 
77 #include <machine/bus.h>
78 
79 #include <dev/ic/dp8390reg.h>
80 #include <dev/ic/dp8390var.h>
81 
82 #include <dev/ic/ne2000reg.h>
83 #include <dev/ic/ne2000var.h>
84 
85 #include <dev/ic/rtl80x9reg.h>
86 #include <dev/ic/rtl80x9var.h>
87 
88 #include <arch/x68k/dev/neptunevar.h>
89 
90 static int ne_neptune_match __P((struct device *, struct cfdata *, void *));
91 static void ne_neptune_attach __P((struct device *, struct device *, void *));
92 static int ne_neptune_intr __P((void *));
93 
94 #define ne_neptune_softc ne2000_softc
95 
96 struct cfattach ne_neptune_ca = {
97 	sizeof(struct ne_neptune_softc), ne_neptune_match, ne_neptune_attach
98 };
99 
100 int
101 ne_neptune_match(parent, match, aux)
102 	struct device *parent;
103 	struct cfdata *match;
104 	void *aux;
105 {
106 	struct neptune_attach_args *na = aux;
107 	bus_space_tag_t nict = na->na_bst;
108 	bus_space_handle_t nich;
109 	bus_space_tag_t asict;
110 	bus_space_handle_t asich;
111 	int rv = 0;
112 
113 	if (na->na_addr == NEPTUNECF_ADDR_DEFAULT)
114 		na->na_addr = 0x300;
115 
116 	/* Make sure this is a valid NE[12]000 i/o address. */
117 	if ((na->na_addr & 0x1f) != 0)
118 		return (0);
119 
120 	/* Map i/o space. */
121 	if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich))
122 		return (0);
123 
124 	asict = nict;
125 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
126 	    NE2000_ASIC_NPORTS*2, &asich))
127 		goto out;
128 
129 	/* Look for an NE2000-compatible card. */
130 	rv = ne2000_detect(nict, nich, asict, asich);
131 
132  out:
133 	bus_space_unmap(nict, nich, NE2000_NPORTS);
134 	return (rv);
135 }
136 
137 void
138 ne_neptune_attach(parent, self, aux)
139 	struct device *parent, *self;
140 	void *aux;
141 {
142 	struct ne_neptune_softc *nsc = (struct ne_neptune_softc *)self;
143 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
144 	struct neptune_attach_args *na = aux;
145 	bus_space_tag_t nict = na->na_bst;
146 	bus_space_handle_t nich;
147 	bus_space_tag_t asict = nict;
148 	bus_space_handle_t asich;
149 	const char *typestr;
150 	int netype;
151 
152 	printf("\n");
153 
154 	/* Map i/o space. */
155 	if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich)) {
156 		printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
157 		return;
158 	}
159 
160 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
161 	    NE2000_ASIC_NPORTS*2, &asich)) {
162 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
163 		return;
164 	}
165 
166 	dsc->sc_regt = nict;
167 	dsc->sc_regh = nich;
168 
169 	nsc->sc_asict = asict;
170 	nsc->sc_asich = asich;
171 
172 	/*
173 	 * Detect it again, so we can print some information about the
174 	 * interface.
175 	 */
176 	netype = ne2000_detect(nict, nich, asict, asich);
177 	switch (netype) {
178 	case NE2000_TYPE_NE1000:
179 		typestr = "NE1000";
180 		break;
181 
182 	case NE2000_TYPE_NE2000:
183 		typestr = "NE2000";
184 		/*
185 		 * Check for a RealTek 8019.
186 		 */
187 		bus_space_write_1(nict, nich, ED_P0_CR,
188 		    ED_CR_PAGE_0 | ED_CR_STP);
189 		if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
190 								RTL0_8019ID0 &&
191 		    bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
192 								RTL0_8019ID1) {
193 			typestr = "NE2000 (RTL8019)";
194 			dsc->sc_mediachange = rtl80x9_mediachange;
195 			dsc->sc_mediastatus = rtl80x9_mediastatus;
196 			dsc->init_card = rtl80x9_init_card;
197 			dsc->sc_media_init = rtl80x9_media_init;
198 		}
199 		break;
200 
201 	default:
202 		printf("%s: where did the card go?!\n", dsc->sc_dev.dv_xname);
203 		return;
204 	}
205 
206 	printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, typestr);
207 
208 	/* This interface is always enabled. */
209 	dsc->sc_enabled = 1;
210 
211 	/*
212 	 * Do generic NE2000 attach.  This will read the station address
213 	 * from the EEPROM.
214 	 */
215 	ne2000_attach(nsc, NULL);
216 
217 	/* Establish the interrupt handler. */
218 	if (neptune_intr_establish(na->na_intr, "ne", ne_neptune_intr, dsc))
219 		printf("%s: couldn't establish interrupt handler\n",
220 		    dsc->sc_dev.dv_xname);
221 }
222 
223 static int
224 ne_neptune_intr(arg)
225 	void *arg;
226 {
227 	spl4();			/* XXX */
228 	return dp8390_intr(arg);
229 }
230