ne2000.c revision 1.67 1 1.67 dyoung /* $NetBSD: ne2000.c,v 1.67 2010/02/24 22:37:58 dyoung Exp $ */
2 1.2 thorpej
3 1.2 thorpej /*-
4 1.8 thorpej * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.2 thorpej * All rights reserved.
6 1.2 thorpej *
7 1.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.2 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.2 thorpej * NASA Ames Research Center.
10 1.2 thorpej *
11 1.2 thorpej * Redistribution and use in source and binary forms, with or without
12 1.2 thorpej * modification, are permitted provided that the following conditions
13 1.2 thorpej * are met:
14 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.2 thorpej * notice, this list of conditions and the following disclaimer.
16 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.2 thorpej * documentation and/or other materials provided with the distribution.
19 1.2 thorpej *
20 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
31 1.2 thorpej */
32 1.2 thorpej
33 1.2 thorpej /*
34 1.2 thorpej * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
35 1.2 thorpej * adapters.
36 1.2 thorpej *
37 1.2 thorpej * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
38 1.2 thorpej *
39 1.2 thorpej * Copyright (C) 1993, David Greenman. This software may be used, modified,
40 1.2 thorpej * copied, distributed, and sold, in both source and binary form provided that
41 1.2 thorpej * the above copyright and these terms are retained. Under no circumstances is
42 1.2 thorpej * the author responsible for the proper functioning of this software, nor does
43 1.2 thorpej * the author assume any responsibility for damages incurred with its use.
44 1.2 thorpej */
45 1.2 thorpej
46 1.2 thorpej /*
47 1.2 thorpej * Common code shared by all NE2000-compatible Ethernet interfaces.
48 1.2 thorpej */
49 1.37 lukem
50 1.37 lukem #include <sys/cdefs.h>
51 1.67 dyoung __KERNEL_RCSID(0, "$NetBSD: ne2000.c,v 1.67 2010/02/24 22:37:58 dyoung Exp $");
52 1.2 thorpej
53 1.29 ws #include "opt_ipkdb.h"
54 1.29 ws
55 1.2 thorpej #include <sys/param.h>
56 1.2 thorpej #include <sys/systm.h>
57 1.2 thorpej #include <sys/device.h>
58 1.2 thorpej #include <sys/socket.h>
59 1.2 thorpej #include <sys/mbuf.h>
60 1.2 thorpej #include <sys/syslog.h>
61 1.2 thorpej
62 1.2 thorpej #include <net/if.h>
63 1.2 thorpej #include <net/if_dl.h>
64 1.2 thorpej #include <net/if_types.h>
65 1.5 thorpej #include <net/if_media.h>
66 1.2 thorpej
67 1.2 thorpej #include <net/if_ether.h>
68 1.2 thorpej
69 1.48 dsl #include <sys/bswap.h>
70 1.55 ad #include <sys/bus.h>
71 1.2 thorpej
72 1.11 sakamoto #ifndef __BUS_SPACE_HAS_STREAM_METHODS
73 1.10 sakamoto #define bus_space_write_stream_2 bus_space_write_2
74 1.10 sakamoto #define bus_space_write_multi_stream_2 bus_space_write_multi_2
75 1.10 sakamoto #define bus_space_read_multi_stream_2 bus_space_read_multi_2
76 1.11 sakamoto #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
77 1.10 sakamoto
78 1.29 ws #ifdef IPKDB_NE
79 1.29 ws #include <ipkdb/ipkdb.h>
80 1.29 ws #endif
81 1.29 ws
82 1.2 thorpej #include <dev/ic/dp8390reg.h>
83 1.2 thorpej #include <dev/ic/dp8390var.h>
84 1.2 thorpej
85 1.2 thorpej #include <dev/ic/ne2000reg.h>
86 1.2 thorpej #include <dev/ic/ne2000var.h>
87 1.17 mjacob
88 1.36 enami #include <dev/ic/ax88190reg.h>
89 1.36 enami
90 1.45 perry int ne2000_write_mbuf(struct dp8390_softc *, struct mbuf *, int);
91 1.54 christos int ne2000_ring_copy(struct dp8390_softc *, int, void *, u_short);
92 1.45 perry void ne2000_read_hdr(struct dp8390_softc *, int, struct dp8390_ring *);
93 1.45 perry int ne2000_test_mem(struct dp8390_softc *);
94 1.2 thorpej
95 1.45 perry void ne2000_writemem(bus_space_tag_t, bus_space_handle_t,
96 1.29 ws bus_space_tag_t, bus_space_handle_t, u_int8_t *, int, size_t,
97 1.45 perry int, int);
98 1.45 perry void ne2000_readmem(bus_space_tag_t, bus_space_handle_t,
99 1.45 perry bus_space_tag_t, bus_space_handle_t, int, u_int8_t *, size_t, int);
100 1.2 thorpej
101 1.44 mycroft #define ASIC_BARRIER(asict, asich) \
102 1.44 mycroft bus_space_barrier((asict), (asich), 0, 0x10, \
103 1.44 mycroft BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)
104 1.44 mycroft
105 1.26 enami int
106 1.60 dsl ne2000_attach(struct ne2000_softc *nsc, u_int8_t *myea)
107 1.2 thorpej {
108 1.2 thorpej struct dp8390_softc *dsc = &nsc->sc_dp8390;
109 1.2 thorpej bus_space_tag_t nict = dsc->sc_regt;
110 1.2 thorpej bus_space_handle_t nich = dsc->sc_regh;
111 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict;
112 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich;
113 1.2 thorpej u_int8_t romdata[16];
114 1.62 nonaka int memsize, i, useword, dmawidth;
115 1.2 thorpej
116 1.2 thorpej /*
117 1.19 enami * Detect it again unless caller specified it; this gives us
118 1.19 enami * the memory size.
119 1.2 thorpej */
120 1.42 mycroft if (nsc->sc_type == NE2000_TYPE_UNKNOWN)
121 1.19 enami nsc->sc_type = ne2000_detect(nict, nich, asict, asich);
122 1.42 mycroft
123 1.42 mycroft /*
124 1.42 mycroft * 8k of memory for NE1000, 16k for NE2000 and 24k for the
125 1.42 mycroft * card uses DL10019.
126 1.42 mycroft */
127 1.42 mycroft switch (nsc->sc_type) {
128 1.42 mycroft case NE2000_TYPE_UNKNOWN:
129 1.42 mycroft default:
130 1.57 cube aprint_error_dev(dsc->sc_dev, "where did the card go?\n");
131 1.42 mycroft return (1);
132 1.42 mycroft case NE2000_TYPE_NE1000:
133 1.42 mycroft memsize = 8192;
134 1.42 mycroft useword = 0;
135 1.62 nonaka dmawidth = NE2000_DMAWIDTH_8BIT;
136 1.42 mycroft break;
137 1.42 mycroft case NE2000_TYPE_NE2000:
138 1.42 mycroft case NE2000_TYPE_AX88190: /* XXX really? */
139 1.42 mycroft case NE2000_TYPE_AX88790:
140 1.42 mycroft memsize = 8192 * 2;
141 1.42 mycroft useword = 1;
142 1.62 nonaka dmawidth = NE2000_DMAWIDTH_16BIT;
143 1.42 mycroft break;
144 1.42 mycroft case NE2000_TYPE_DL10019:
145 1.42 mycroft case NE2000_TYPE_DL10022:
146 1.42 mycroft memsize = 8192 * 3;
147 1.42 mycroft useword = 1;
148 1.62 nonaka dmawidth = NE2000_DMAWIDTH_16BIT;
149 1.42 mycroft break;
150 1.2 thorpej }
151 1.2 thorpej
152 1.42 mycroft nsc->sc_useword = useword;
153 1.62 nonaka if (nsc->sc_dmawidth == NE2000_DMAWIDTH_UNKNOWN)
154 1.62 nonaka nsc->sc_dmawidth = dmawidth;
155 1.62 nonaka else
156 1.62 nonaka dmawidth = nsc->sc_dmawidth;
157 1.2 thorpej
158 1.2 thorpej dsc->cr_proto = ED_CR_RD2;
159 1.39 christos if (nsc->sc_type == NE2000_TYPE_AX88190 ||
160 1.39 christos nsc->sc_type == NE2000_TYPE_AX88790) {
161 1.27 enami dsc->rcr_proto = ED_RCR_INTT;
162 1.27 enami dsc->sc_flags |= DP8390_DO_AX88190_WORKAROUND;
163 1.27 enami } else
164 1.27 enami dsc->rcr_proto = 0;
165 1.2 thorpej
166 1.2 thorpej /*
167 1.2 thorpej * DCR gets:
168 1.2 thorpej *
169 1.2 thorpej * FIFO threshold to 8, No auto-init Remote DMA,
170 1.2 thorpej * byte order=80x86.
171 1.2 thorpej *
172 1.2 thorpej * NE1000 gets byte-wide DMA, NE2000 gets word-wide DMA.
173 1.2 thorpej */
174 1.62 nonaka dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
175 1.62 nonaka ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0);
176 1.2 thorpej
177 1.2 thorpej dsc->test_mem = ne2000_test_mem;
178 1.2 thorpej dsc->ring_copy = ne2000_ring_copy;
179 1.2 thorpej dsc->write_mbuf = ne2000_write_mbuf;
180 1.2 thorpej dsc->read_hdr = ne2000_read_hdr;
181 1.2 thorpej
182 1.2 thorpej /* Registers are linear. */
183 1.2 thorpej for (i = 0; i < 16; i++)
184 1.2 thorpej dsc->sc_reg_map[i] = i;
185 1.2 thorpej
186 1.2 thorpej /*
187 1.2 thorpej * NIC memory doens't start at zero on an NE board.
188 1.2 thorpej * The start address is tied to the bus width.
189 1.2 thorpej * (It happens to be computed the same way as mem size.)
190 1.2 thorpej */
191 1.2 thorpej dsc->mem_start = memsize;
192 1.2 thorpej
193 1.2 thorpej #ifdef GWETHER
194 1.2 thorpej {
195 1.2 thorpej int x, mstart = 0;
196 1.2 thorpej int8_t pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE],
197 1.2 thorpej tbuf[ED_PAGE_SIZE];
198 1.2 thorpej
199 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++)
200 1.2 thorpej pbuf0[i] = 0;
201 1.2 thorpej
202 1.2 thorpej /* Search for the start of RAM. */
203 1.2 thorpej for (x = 1; x < 256; x++) {
204 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, pbuf0,
205 1.15 thorpej x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword, 0);
206 1.2 thorpej ne2000_readmem(nict, nich, asict, asich,
207 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
208 1.34 thorpej if (memcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
209 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++)
210 1.2 thorpej pbuf[i] = 255 - x;
211 1.2 thorpej ne2000_writemem(nict, nich, asict, asich,
212 1.2 thorpej pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
213 1.15 thorpej useword, 0);
214 1.2 thorpej ne2000_readmem(nict, nich, asict, asich,
215 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE,
216 1.2 thorpej useword);
217 1.34 thorpej if (memcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
218 1.2 thorpej mstart = x << ED_PAGE_SHIFT;
219 1.2 thorpej memsize = ED_PAGE_SIZE;
220 1.2 thorpej break;
221 1.2 thorpej }
222 1.2 thorpej }
223 1.2 thorpej }
224 1.2 thorpej
225 1.2 thorpej if (mstart == 0) {
226 1.58 cegger aprint_error_dev(&dsc->sc_dev, "cannot find start of RAM\n");
227 1.26 enami return (1);
228 1.2 thorpej }
229 1.2 thorpej
230 1.2 thorpej /* Search for the end of RAM. */
231 1.2 thorpej for (++x; x < 256; x++) {
232 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, pbuf0,
233 1.15 thorpej x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword, 0);
234 1.2 thorpej ne2000_readmem(nict, nich, asict, asich,
235 1.2 thorpej x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
236 1.34 thorpej if (memcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
237 1.2 thorpej for (i = 0; i < ED_PAGE_SIZE; i++)
238 1.2 thorpej pbuf[i] = 255 - x;
239 1.2 thorpej ne2000_writemem(nict, nich, asict, asich,
240 1.2 thorpej pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
241 1.15 thorpej useword, 0);
242 1.2 thorpej ne2000_readmem(nict, nich, asict, asich,
243 1.13 msaitoh x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE,
244 1.2 thorpej useword);
245 1.34 thorpej if (memcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
246 1.2 thorpej memsize += ED_PAGE_SIZE;
247 1.2 thorpej else
248 1.2 thorpej break;
249 1.2 thorpej } else
250 1.2 thorpej break;
251 1.2 thorpej }
252 1.2 thorpej
253 1.2 thorpej printf("%s: RAM start 0x%x, size %d\n",
254 1.58 cegger device_xname(&dsc->sc_dev), mstart, memsize);
255 1.2 thorpej
256 1.2 thorpej dsc->mem_start = mstart;
257 1.2 thorpej }
258 1.2 thorpej #endif /* GWETHER */
259 1.2 thorpej
260 1.2 thorpej dsc->mem_size = memsize;
261 1.2 thorpej
262 1.2 thorpej if (myea == NULL) {
263 1.2 thorpej /* Read the station address. */
264 1.39 christos if (nsc->sc_type == NE2000_TYPE_AX88190 ||
265 1.39 christos nsc->sc_type == NE2000_TYPE_AX88790) {
266 1.27 enami /* Select page 0 registers. */
267 1.28 ws NIC_BARRIER(nict, nich);
268 1.27 enami bus_space_write_1(nict, nich, ED_P0_CR,
269 1.27 enami ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
270 1.28 ws NIC_BARRIER(nict, nich);
271 1.27 enami /* Select word transfer. */
272 1.62 nonaka bus_space_write_1(nict, nich, ED_P0_DCR,
273 1.62 nonaka ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0));
274 1.28 ws NIC_BARRIER(nict, nich);
275 1.27 enami ne2000_readmem(nict, nich, asict, asich,
276 1.36 enami AX88190_NODEID_OFFSET, dsc->sc_enaddr,
277 1.27 enami ETHER_ADDR_LEN, useword);
278 1.27 enami } else {
279 1.27 enami ne2000_readmem(nict, nich, asict, asich, 0, romdata,
280 1.27 enami sizeof(romdata), useword);
281 1.27 enami for (i = 0; i < ETHER_ADDR_LEN; i++)
282 1.27 enami dsc->sc_enaddr[i] =
283 1.27 enami romdata[i * (useword ? 2 : 1)];
284 1.27 enami }
285 1.2 thorpej } else
286 1.35 thorpej memcpy(dsc->sc_enaddr, myea, sizeof(dsc->sc_enaddr));
287 1.2 thorpej
288 1.2 thorpej /* Clear any pending interrupts that might have occurred above. */
289 1.28 ws NIC_BARRIER(nict, nich);
290 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
291 1.28 ws NIC_BARRIER(nict, nich);
292 1.2 thorpej
293 1.32 thorpej if (dsc->sc_media_init == NULL)
294 1.32 thorpej dsc->sc_media_init = dp8390_media_init;
295 1.32 thorpej
296 1.32 thorpej if (dp8390_config(dsc)) {
297 1.57 cube aprint_error_dev(dsc->sc_dev, "setup failed\n");
298 1.26 enami return (1);
299 1.2 thorpej }
300 1.2 thorpej
301 1.26 enami return (0);
302 1.2 thorpej }
303 1.2 thorpej
304 1.2 thorpej /*
305 1.2 thorpej * Detect an NE-2000 or compatible. Returns a model code.
306 1.2 thorpej */
307 1.2 thorpej int
308 1.60 dsl ne2000_detect(bus_space_tag_t nict, bus_space_handle_t nich, bus_space_tag_t asict, bus_space_handle_t asich)
309 1.2 thorpej {
310 1.2 thorpej static u_int8_t test_pattern[32] = "THIS is A memory TEST pattern";
311 1.2 thorpej u_int8_t test_buffer[32], tmp;
312 1.56 dholland int i, rv = NE2000_TYPE_UNKNOWN;
313 1.62 nonaka int dmawidth = NE2000_DMAWIDTH_16BIT;
314 1.2 thorpej
315 1.62 nonaka restart:
316 1.2 thorpej /* Reset the board. */
317 1.2 thorpej #ifdef GWETHER
318 1.2 thorpej bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0);
319 1.44 mycroft ASIC_BARRIER(asict, asich);
320 1.2 thorpej delay(200);
321 1.2 thorpej #endif /* GWETHER */
322 1.2 thorpej tmp = bus_space_read_1(asict, asich, NE2000_ASIC_RESET);
323 1.44 mycroft ASIC_BARRIER(asict, asich);
324 1.2 thorpej delay(10000);
325 1.2 thorpej
326 1.2 thorpej /*
327 1.2 thorpej * I don't know if this is necessary; probably cruft leftover from
328 1.2 thorpej * Clarkson packet driver code. Doesn't do a thing on the boards I've
329 1.2 thorpej * tested. -DG [note that a outb(0x84, 0) seems to work here, and is
330 1.2 thorpej * non-invasive...but some boards don't seem to reset and I don't have
331 1.2 thorpej * complete documentation on what the 'right' thing to do is...so we do
332 1.2 thorpej * the invasive thing for now. Yuck.]
333 1.2 thorpej */
334 1.2 thorpej bus_space_write_1(asict, asich, NE2000_ASIC_RESET, tmp);
335 1.44 mycroft ASIC_BARRIER(asict, asich);
336 1.2 thorpej delay(5000);
337 1.2 thorpej
338 1.2 thorpej /*
339 1.2 thorpej * This is needed because some NE clones apparently don't reset the
340 1.2 thorpej * NIC properly (or the NIC chip doesn't reset fully on power-up).
341 1.2 thorpej * XXX - this makes the probe invasive! Done against my better
342 1.2 thorpej * judgement. -DLG
343 1.2 thorpej */
344 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR,
345 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
346 1.28 ws NIC_BARRIER(nict, nich);
347 1.2 thorpej
348 1.2 thorpej delay(5000);
349 1.2 thorpej
350 1.4 thorpej /*
351 1.41 wiz * Generic probe routine for testing for the existence of a DS8390.
352 1.4 thorpej * Must be performed after the NIC has just been reset. This
353 1.4 thorpej * works by looking at certain register values that are guaranteed
354 1.4 thorpej * to be initialized a certain way after power-up or reset.
355 1.4 thorpej *
356 1.4 thorpej * Specifically:
357 1.4 thorpej *
358 1.4 thorpej * Register reset bits set bits
359 1.4 thorpej * -------- ---------- --------
360 1.4 thorpej * CR TXP, STA RD2, STP
361 1.4 thorpej * ISR RST
362 1.4 thorpej * IMR <all>
363 1.4 thorpej * DCR LAS
364 1.4 thorpej * TCR LB1, LB0
365 1.4 thorpej *
366 1.4 thorpej * We only look at CR and ISR, however, since looking at the others
367 1.4 thorpej * would require changing register pages, which would be intrusive
368 1.4 thorpej * if this isn't an 8390.
369 1.4 thorpej */
370 1.4 thorpej
371 1.2 thorpej tmp = bus_space_read_1(nict, nich, ED_P0_CR);
372 1.2 thorpej if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
373 1.2 thorpej (ED_CR_RD2 | ED_CR_STP))
374 1.4 thorpej goto out;
375 1.4 thorpej
376 1.4 thorpej tmp = bus_space_read_1(nict, nich, ED_P0_ISR);
377 1.4 thorpej if ((tmp & ED_ISR_RST) != ED_ISR_RST)
378 1.2 thorpej goto out;
379 1.2 thorpej
380 1.2 thorpej bus_space_write_1(nict, nich,
381 1.2 thorpej ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
382 1.28 ws NIC_BARRIER(nict, nich);
383 1.2 thorpej
384 1.2 thorpej for (i = 0; i < 100; i++) {
385 1.2 thorpej if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
386 1.2 thorpej ED_ISR_RST) {
387 1.2 thorpej /* Ack the reset bit. */
388 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
389 1.28 ws NIC_BARRIER(nict, nich);
390 1.2 thorpej break;
391 1.2 thorpej }
392 1.2 thorpej delay(100);
393 1.2 thorpej }
394 1.2 thorpej
395 1.2 thorpej #if 0
396 1.2 thorpej /* XXX */
397 1.2 thorpej if (i == 100)
398 1.2 thorpej goto out;
399 1.2 thorpej #endif
400 1.2 thorpej
401 1.2 thorpej /*
402 1.2 thorpej * Test the ability to read and write to the NIC memory. This has
403 1.2 thorpej * the side effect of determining if this is an NE1000 or an NE2000.
404 1.2 thorpej */
405 1.2 thorpej
406 1.2 thorpej /*
407 1.2 thorpej * This prevents packets from being stored in the NIC memory when
408 1.2 thorpej * the readmem routine turns on the start bit in the CR.
409 1.2 thorpej */
410 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
411 1.28 ws NIC_BARRIER(nict, nich);
412 1.2 thorpej
413 1.2 thorpej /* Temporarily initialize DCR for byte operations. */
414 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
415 1.2 thorpej
416 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT);
417 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT);
418 1.2 thorpej
419 1.2 thorpej /*
420 1.2 thorpej * Write a test pattern in byte mode. If this fails, then there
421 1.2 thorpej * probably isn't any memory at 8k - which likely means that the
422 1.2 thorpej * board is an NE2000.
423 1.2 thorpej */
424 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192,
425 1.15 thorpej sizeof(test_pattern), 0, 1);
426 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer,
427 1.2 thorpej sizeof(test_buffer), 0);
428 1.2 thorpej
429 1.34 thorpej if (memcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
430 1.2 thorpej /* not an NE1000 - try NE2000 */
431 1.62 nonaka bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS
432 1.62 nonaka | ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0));
433 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTART,
434 1.2 thorpej 16384 >> ED_PAGE_SHIFT);
435 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_PSTOP,
436 1.2 thorpej 32768 >> ED_PAGE_SHIFT);
437 1.2 thorpej
438 1.2 thorpej /*
439 1.2 thorpej * Write the test pattern in word mode. If this also fails,
440 1.2 thorpej * then we don't know what this board is.
441 1.2 thorpej */
442 1.2 thorpej ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384,
443 1.15 thorpej sizeof(test_pattern), 1, 0);
444 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer,
445 1.2 thorpej sizeof(test_buffer), 1);
446 1.2 thorpej
447 1.62 nonaka if (memcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
448 1.62 nonaka if (dmawidth == NE2000_DMAWIDTH_16BIT) {
449 1.62 nonaka /* try 8bit dma */
450 1.62 nonaka dmawidth = NE2000_DMAWIDTH_8BIT;
451 1.62 nonaka goto restart;
452 1.62 nonaka }
453 1.2 thorpej goto out; /* not an NE2000 either */
454 1.62 nonaka }
455 1.2 thorpej
456 1.2 thorpej rv = NE2000_TYPE_NE2000;
457 1.2 thorpej } else {
458 1.2 thorpej /* We're an NE1000. */
459 1.2 thorpej rv = NE2000_TYPE_NE1000;
460 1.62 nonaka dmawidth = NE2000_DMAWIDTH_8BIT;
461 1.2 thorpej }
462 1.2 thorpej
463 1.2 thorpej /* Clear any pending interrupts that might have occurred above. */
464 1.28 ws NIC_BARRIER(nict, nich);
465 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
466 1.2 thorpej
467 1.2 thorpej out:
468 1.2 thorpej return (rv);
469 1.2 thorpej }
470 1.2 thorpej
471 1.2 thorpej /*
472 1.2 thorpej * Write an mbuf chain to the destination NIC memory address using programmed
473 1.2 thorpej * I/O.
474 1.2 thorpej */
475 1.2 thorpej int
476 1.60 dsl ne2000_write_mbuf(struct dp8390_softc *sc, struct mbuf *m, int buf)
477 1.2 thorpej {
478 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
479 1.2 thorpej bus_space_tag_t nict = sc->sc_regt;
480 1.2 thorpej bus_space_handle_t nich = sc->sc_regh;
481 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict;
482 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich;
483 1.38 bouyer int savelen, padlen;
484 1.2 thorpej int maxwait = 100; /* about 120us */
485 1.2 thorpej
486 1.2 thorpej savelen = m->m_pkthdr.len;
487 1.38 bouyer if (savelen < ETHER_MIN_LEN - ETHER_CRC_LEN) {
488 1.38 bouyer padlen = ETHER_MIN_LEN - ETHER_CRC_LEN - savelen;
489 1.38 bouyer savelen = ETHER_MIN_LEN - ETHER_CRC_LEN;
490 1.38 bouyer } else
491 1.38 bouyer padlen = 0;
492 1.38 bouyer
493 1.2 thorpej
494 1.2 thorpej /* Select page 0 registers. */
495 1.28 ws NIC_BARRIER(nict, nich);
496 1.3 enami bus_space_write_1(nict, nich, ED_P0_CR,
497 1.3 enami ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
498 1.28 ws NIC_BARRIER(nict, nich);
499 1.2 thorpej
500 1.2 thorpej /* Reset remote DMA complete flag. */
501 1.3 enami bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
502 1.28 ws NIC_BARRIER(nict, nich);
503 1.2 thorpej
504 1.2 thorpej /* Set up DMA byte count. */
505 1.3 enami bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen);
506 1.3 enami bus_space_write_1(nict, nich, ED_P0_RBCR1, savelen >> 8);
507 1.2 thorpej
508 1.2 thorpej /* Set up destination address in NIC mem. */
509 1.3 enami bus_space_write_1(nict, nich, ED_P0_RSAR0, buf);
510 1.3 enami bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8);
511 1.2 thorpej
512 1.2 thorpej /* Set remote DMA write. */
513 1.28 ws NIC_BARRIER(nict, nich);
514 1.3 enami bus_space_write_1(nict, nich,
515 1.3 enami ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
516 1.28 ws NIC_BARRIER(nict, nich);
517 1.2 thorpej
518 1.2 thorpej /*
519 1.2 thorpej * Transfer the mbuf chain to the NIC memory. NE2000 cards
520 1.2 thorpej * require that data be transferred as words, and only words,
521 1.2 thorpej * so that case requires some extra code to patch over odd-length
522 1.2 thorpej * mbufs.
523 1.2 thorpej */
524 1.2 thorpej if (nsc->sc_type == NE2000_TYPE_NE1000) {
525 1.2 thorpej /* NE1000s are easy. */
526 1.2 thorpej for (; m != 0; m = m->m_next) {
527 1.2 thorpej if (m->m_len) {
528 1.2 thorpej bus_space_write_multi_1(asict, asich,
529 1.2 thorpej NE2000_ASIC_DATA, mtod(m, u_int8_t *),
530 1.2 thorpej m->m_len);
531 1.2 thorpej }
532 1.2 thorpej }
533 1.38 bouyer if (padlen) {
534 1.38 bouyer for(; padlen > 0; padlen--)
535 1.38 bouyer bus_space_write_1(asict, asich,
536 1.38 bouyer NE2000_ASIC_DATA, 0);
537 1.38 bouyer }
538 1.2 thorpej } else {
539 1.2 thorpej /* NE2000s are a bit trickier. */
540 1.12 thorpej u_int8_t *data, savebyte[2];
541 1.12 thorpej int l, leftover;
542 1.12 thorpej #ifdef DIAGNOSTIC
543 1.12 thorpej u_int8_t *lim;
544 1.12 thorpej #endif
545 1.12 thorpej /* Start out with no leftover data. */
546 1.12 thorpej leftover = 0;
547 1.12 thorpej savebyte[0] = savebyte[1] = 0;
548 1.2 thorpej
549 1.2 thorpej for (; m != 0; m = m->m_next) {
550 1.2 thorpej l = m->m_len;
551 1.2 thorpej if (l == 0)
552 1.2 thorpej continue;
553 1.2 thorpej data = mtod(m, u_int8_t *);
554 1.12 thorpej #ifdef DIAGNOSTIC
555 1.12 thorpej lim = data + l;
556 1.12 thorpej #endif
557 1.12 thorpej while (l > 0) {
558 1.12 thorpej if (leftover) {
559 1.12 thorpej /*
560 1.12 thorpej * Data left over (from mbuf or
561 1.12 thorpej * realignment). Buffer the next
562 1.12 thorpej * byte, and write it and the
563 1.12 thorpej * leftover data out.
564 1.12 thorpej */
565 1.12 thorpej savebyte[1] = *data++;
566 1.12 thorpej l--;
567 1.12 thorpej bus_space_write_stream_2(asict, asich,
568 1.12 thorpej NE2000_ASIC_DATA,
569 1.12 thorpej *(u_int16_t *)savebyte);
570 1.12 thorpej leftover = 0;
571 1.18 drochner } else if (BUS_SPACE_ALIGNED_POINTER(data,
572 1.12 thorpej u_int16_t) == 0) {
573 1.12 thorpej /*
574 1.12 thorpej * Unaligned data; buffer the next
575 1.12 thorpej * byte.
576 1.12 thorpej */
577 1.12 thorpej savebyte[0] = *data++;
578 1.12 thorpej l--;
579 1.12 thorpej leftover = 1;
580 1.12 thorpej } else {
581 1.12 thorpej /*
582 1.12 thorpej * Aligned data; output contiguous
583 1.12 thorpej * words as much as we can, then
584 1.12 thorpej * buffer the remaining byte, if any.
585 1.12 thorpej */
586 1.12 thorpej leftover = l & 1;
587 1.12 thorpej l &= ~1;
588 1.12 thorpej bus_space_write_multi_stream_2(asict,
589 1.12 thorpej asich, NE2000_ASIC_DATA,
590 1.12 thorpej (u_int16_t *)data, l >> 1);
591 1.12 thorpej data += l;
592 1.12 thorpej if (leftover)
593 1.12 thorpej savebyte[0] = *data++;
594 1.12 thorpej l = 0;
595 1.12 thorpej }
596 1.2 thorpej }
597 1.12 thorpej if (l < 0)
598 1.12 thorpej panic("ne2000_write_mbuf: negative len");
599 1.12 thorpej #ifdef DIAGNOSTIC
600 1.12 thorpej if (data != lim)
601 1.12 thorpej panic("ne2000_write_mbuf: data != lim");
602 1.12 thorpej #endif
603 1.2 thorpej }
604 1.12 thorpej if (leftover) {
605 1.2 thorpej savebyte[1] = 0;
606 1.10 sakamoto bus_space_write_stream_2(asict, asich, NE2000_ASIC_DATA,
607 1.2 thorpej *(u_int16_t *)savebyte);
608 1.38 bouyer }
609 1.38 bouyer if (padlen) {
610 1.43 mycroft for(; padlen > 1; padlen -= 2)
611 1.38 bouyer bus_space_write_stream_2(asict, asich,
612 1.38 bouyer NE2000_ASIC_DATA, 0);
613 1.2 thorpej }
614 1.2 thorpej }
615 1.28 ws NIC_BARRIER(nict, nich);
616 1.2 thorpej
617 1.46 bsh /* AX88796 doesn't seem to have remote DMA complete */
618 1.46 bsh if (sc->sc_flags & DP8390_NO_REMOTE_DMA_COMPLETE)
619 1.46 bsh return(savelen);
620 1.46 bsh
621 1.2 thorpej /*
622 1.2 thorpej * Wait for remote DMA to complete. This is necessary because on the
623 1.2 thorpej * transmit side, data is handled internally by the NIC in bursts, and
624 1.2 thorpej * we can't start another remote DMA until this one completes. Not
625 1.2 thorpej * waiting causes really bad things to happen - like the NIC wedging
626 1.2 thorpej * the bus.
627 1.2 thorpej */
628 1.2 thorpej while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
629 1.28 ws ED_ISR_RDC) && --maxwait) {
630 1.49 christos (void)bus_space_read_1(nict, nich, ED_P0_CRDA1);
631 1.49 christos (void)bus_space_read_1(nict, nich, ED_P0_CRDA0);
632 1.28 ws NIC_BARRIER(nict, nich);
633 1.28 ws DELAY(1);
634 1.28 ws }
635 1.2 thorpej
636 1.2 thorpej if (maxwait == 0) {
637 1.2 thorpej log(LOG_WARNING,
638 1.2 thorpej "%s: remote transmit DMA failed to complete\n",
639 1.57 cube device_xname(sc->sc_dev));
640 1.2 thorpej dp8390_reset(sc);
641 1.2 thorpej }
642 1.2 thorpej
643 1.2 thorpej return (savelen);
644 1.2 thorpej }
645 1.2 thorpej
646 1.2 thorpej /*
647 1.2 thorpej * Given a source and destination address, copy 'amout' of a packet from
648 1.2 thorpej * the ring buffer into a linear destination buffer. Takes into account
649 1.2 thorpej * ring-wrap.
650 1.2 thorpej */
651 1.2 thorpej int
652 1.60 dsl ne2000_ring_copy(struct dp8390_softc *sc, int src, void *dstv, u_short amount)
653 1.2 thorpej {
654 1.54 christos char *dst = dstv;
655 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
656 1.2 thorpej bus_space_tag_t nict = sc->sc_regt;
657 1.2 thorpej bus_space_handle_t nich = sc->sc_regh;
658 1.2 thorpej bus_space_tag_t asict = nsc->sc_asict;
659 1.2 thorpej bus_space_handle_t asich = nsc->sc_asich;
660 1.2 thorpej u_short tmp_amount;
661 1.42 mycroft int useword = nsc->sc_useword;
662 1.2 thorpej
663 1.2 thorpej /* Does copy wrap to lower addr in ring buffer? */
664 1.2 thorpej if (src + amount > sc->mem_end) {
665 1.2 thorpej tmp_amount = sc->mem_end - src;
666 1.2 thorpej
667 1.2 thorpej /* Copy amount up to end of NIC memory. */
668 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, src,
669 1.2 thorpej (u_int8_t *)dst, tmp_amount, useword);
670 1.2 thorpej
671 1.2 thorpej amount -= tmp_amount;
672 1.2 thorpej src = sc->mem_ring;
673 1.2 thorpej dst += tmp_amount;
674 1.2 thorpej }
675 1.2 thorpej
676 1.2 thorpej ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst,
677 1.2 thorpej amount, useword);
678 1.2 thorpej
679 1.2 thorpej return (src + amount);
680 1.2 thorpej }
681 1.2 thorpej
682 1.2 thorpej void
683 1.60 dsl ne2000_read_hdr(struct dp8390_softc *sc, int buf, struct dp8390_ring *hdr)
684 1.2 thorpej {
685 1.2 thorpej struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
686 1.2 thorpej
687 1.2 thorpej ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich,
688 1.2 thorpej buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring),
689 1.42 mycroft nsc->sc_useword);
690 1.7 thorpej #if BYTE_ORDER == BIG_ENDIAN
691 1.7 thorpej hdr->count = bswap16(hdr->count);
692 1.7 thorpej #endif
693 1.2 thorpej }
694 1.2 thorpej
695 1.2 thorpej int
696 1.52 christos ne2000_test_mem(struct dp8390_softc *sc)
697 1.2 thorpej {
698 1.2 thorpej
699 1.2 thorpej /* Noop. */
700 1.2 thorpej return (0);
701 1.2 thorpej }
702 1.2 thorpej
703 1.2 thorpej /*
704 1.2 thorpej * Given a NIC memory source address and a host memory destination address,
705 1.2 thorpej * copy 'amount' from NIC to host using programmed i/o. The 'amount' is
706 1.2 thorpej * rounded up to a word - ok as long as mbufs are word sized.
707 1.2 thorpej */
708 1.2 thorpej void
709 1.60 dsl ne2000_readmem(bus_space_tag_t nict, bus_space_handle_t nich, bus_space_tag_t asict, bus_space_handle_t asich, int src, u_int8_t *dst, size_t amount, int useword)
710 1.2 thorpej {
711 1.2 thorpej
712 1.2 thorpej /* Select page 0 registers. */
713 1.28 ws NIC_BARRIER(nict, nich);
714 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR,
715 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
716 1.28 ws NIC_BARRIER(nict, nich);
717 1.2 thorpej
718 1.2 thorpej /* Round up to a word. */
719 1.66 tsutsui amount = roundup2(amount, sizeof(uint16_t));
720 1.2 thorpej
721 1.2 thorpej /* Set up DMA byte count. */
722 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR0, amount);
723 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8);
724 1.2 thorpej
725 1.2 thorpej /* Set up source address in NIC mem. */
726 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR0, src);
727 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8);
728 1.2 thorpej
729 1.28 ws NIC_BARRIER(nict, nich);
730 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR,
731 1.2 thorpej ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA);
732 1.2 thorpej
733 1.44 mycroft ASIC_BARRIER(asict, asich);
734 1.2 thorpej if (useword)
735 1.10 sakamoto bus_space_read_multi_stream_2(asict, asich, NE2000_ASIC_DATA,
736 1.2 thorpej (u_int16_t *)dst, amount >> 1);
737 1.2 thorpej else
738 1.2 thorpej bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA,
739 1.2 thorpej dst, amount);
740 1.2 thorpej }
741 1.2 thorpej
742 1.2 thorpej /*
743 1.2 thorpej * Stripped down routine for writing a linear buffer to NIC memory. Only
744 1.2 thorpej * used in the probe routine to test the memory. 'len' must be even.
745 1.2 thorpej */
746 1.2 thorpej void
747 1.60 dsl ne2000_writemem(bus_space_tag_t nict, bus_space_handle_t nich, bus_space_tag_t asict, bus_space_handle_t asich, u_int8_t *src, int dst, size_t len, int useword, int quiet)
748 1.2 thorpej {
749 1.2 thorpej int maxwait = 100; /* about 120us */
750 1.2 thorpej
751 1.2 thorpej /* Select page 0 registers. */
752 1.28 ws NIC_BARRIER(nict, nich);
753 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR,
754 1.2 thorpej ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
755 1.28 ws NIC_BARRIER(nict, nich);
756 1.2 thorpej
757 1.2 thorpej /* Reset remote DMA complete flag. */
758 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
759 1.28 ws NIC_BARRIER(nict, nich);
760 1.2 thorpej
761 1.2 thorpej /* Set up DMA byte count. */
762 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR0, len);
763 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8);
764 1.2 thorpej
765 1.2 thorpej /* Set up destination address in NIC mem. */
766 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR0, dst);
767 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8);
768 1.2 thorpej
769 1.2 thorpej /* Set remote DMA write. */
770 1.28 ws NIC_BARRIER(nict, nich);
771 1.2 thorpej bus_space_write_1(nict, nich, ED_P0_CR,
772 1.2 thorpej ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
773 1.44 mycroft NIC_BARRIER(nict, nich);
774 1.2 thorpej
775 1.44 mycroft ASIC_BARRIER(asict, asich);
776 1.2 thorpej if (useword)
777 1.10 sakamoto bus_space_write_multi_stream_2(asict, asich, NE2000_ASIC_DATA,
778 1.2 thorpej (u_int16_t *)src, len >> 1);
779 1.2 thorpej else
780 1.2 thorpej bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA,
781 1.2 thorpej src, len);
782 1.44 mycroft ASIC_BARRIER(asict, asich);
783 1.2 thorpej
784 1.2 thorpej /*
785 1.2 thorpej * Wait for remote DMA to complete. This is necessary because on the
786 1.2 thorpej * transmit side, data is handled internally by the NIC in bursts, and
787 1.2 thorpej * we can't start another remote DMA until this one completes. Not
788 1.2 thorpej * waiting causes really bad things to happen - like the NIC wedging
789 1.2 thorpej * the bus.
790 1.2 thorpej */
791 1.2 thorpej while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
792 1.28 ws ED_ISR_RDC) && --maxwait)
793 1.28 ws DELAY(1);
794 1.2 thorpej
795 1.15 thorpej if (!quiet && maxwait == 0)
796 1.2 thorpej printf("ne2000_writemem: failed to complete\n");
797 1.24 itojun }
798 1.24 itojun
799 1.24 itojun int
800 1.60 dsl ne2000_detach(struct ne2000_softc *sc, int flags)
801 1.24 itojun {
802 1.26 enami
803 1.26 enami return (dp8390_detach(&sc->sc_dp8390, flags));
804 1.2 thorpej }
805 1.29 ws
806 1.29 ws #ifdef IPKDB_NE
807 1.29 ws /*
808 1.29 ws * This code is essentially the same as ne2000_attach above.
809 1.29 ws */
810 1.29 ws int
811 1.60 dsl ne2000_ipkdb_attach(struct ipkdb_if *kip)
812 1.29 ws {
813 1.29 ws struct ne2000_softc *np = kip->port;
814 1.29 ws struct dp8390_softc *dp = &np->sc_dp8390;
815 1.29 ws bus_space_tag_t nict = dp->sc_regt;
816 1.29 ws bus_space_handle_t nich = dp->sc_regh;
817 1.62 nonaka int i, useword, dmawidth;
818 1.29 ws
819 1.29 ws #ifdef GWETHER
820 1.29 ws /* Not supported (yet?) */
821 1.29 ws return -1;
822 1.29 ws #endif
823 1.29 ws
824 1.62 nonaka if (np->sc_type == NE2000_TYPE_UNKNOWN)
825 1.29 ws np->sc_type = ne2000_detect(nict, nich,
826 1.29 ws np->sc_asict, np->sc_asich);
827 1.62 nonaka if (np->sc_type == NE2000_TYPE_UNKNOWN)
828 1.29 ws return -1;
829 1.29 ws
830 1.42 mycroft useword = np->sc_useword;
831 1.62 nonaka dmawidth = np->sc_dmawidth;
832 1.29 ws
833 1.29 ws dp->cr_proto = ED_CR_RD2;
834 1.62 nonaka dp->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
835 1.62 nonaka ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0);
836 1.29 ws dp->rcr_proto = 0;
837 1.29 ws
838 1.29 ws dp->test_mem = ne2000_test_mem;
839 1.29 ws dp->ring_copy = ne2000_ring_copy;
840 1.29 ws dp->write_mbuf = ne2000_write_mbuf;
841 1.29 ws dp->read_hdr = ne2000_read_hdr;
842 1.29 ws
843 1.29 ws for (i = 0; i < 16; i++)
844 1.29 ws dp->sc_reg_map[i] = i;
845 1.29 ws
846 1.29 ws switch (np->sc_type) {
847 1.29 ws case NE2000_TYPE_NE1000:
848 1.29 ws dp->mem_start = dp->mem_size = 8192;
849 1.29 ws kip->name = "ne1000";
850 1.29 ws break;
851 1.29 ws case NE2000_TYPE_NE2000:
852 1.29 ws dp->mem_start = dp->mem_size = 8192 * 2;
853 1.29 ws kip->name = "ne2000";
854 1.29 ws break;
855 1.29 ws case NE2000_TYPE_DL10019:
856 1.33 thorpej case NE2000_TYPE_DL10022:
857 1.29 ws dp->mem_start = dp->mem_size = 8192 * 3;
858 1.33 thorpej kip->name = (np->sc_type == NE2000_TYPE_DL10019) ?
859 1.33 thorpej "dl10022" : "dl10019";
860 1.29 ws break;
861 1.29 ws case NE2000_TYPE_AX88190:
862 1.39 christos case NE2000_TYPE_AX88790:
863 1.29 ws dp->rcr_proto = ED_RCR_INTT;
864 1.29 ws dp->sc_flags |= DP8390_DO_AX88190_WORKAROUND;
865 1.29 ws dp->mem_start = dp->mem_size = 8192 * 2;
866 1.29 ws kip->name = "ax88190";
867 1.29 ws break;
868 1.53 cube default:
869 1.53 cube return -1;
870 1.53 cube break;
871 1.29 ws }
872 1.29 ws
873 1.29 ws if (dp8390_ipkdb_attach(kip))
874 1.29 ws return -1;
875 1.29 ws
876 1.29 ws dp->mem_ring = dp->mem_start
877 1.29 ws + ((dp->txb_cnt * ED_TXBUF_SIZE) << ED_PAGE_SHIFT);
878 1.29 ws
879 1.29 ws if (!(kip->flags & IPKDB_MYHW)) {
880 1.29 ws char romdata[16];
881 1.29 ws
882 1.29 ws /* Read the station address. */
883 1.39 christos if (np->sc_type == NE2000_TYPE_AX88190 ||
884 1.39 christos np->sc_type == NE2000_TYPE_AX88790) {
885 1.29 ws /* Select page 0 registers. */
886 1.29 ws NIC_BARRIER(nict, nich);
887 1.29 ws bus_space_write_1(nict, nich, ED_P0_CR,
888 1.29 ws ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
889 1.29 ws NIC_BARRIER(nict, nich);
890 1.29 ws /* Select word transfer */
891 1.62 nonaka bus_space_write_1(nict, nich, ED_P0_DCR,
892 1.62 nonaka ((dmawidth == NE2000_DMAWIDTH_16BIT) ? ED_DCR_WTS : 0));
893 1.29 ws ne2000_readmem(nict, nich, np->sc_asict, np->sc_asich,
894 1.36 enami AX88190_NODEID_OFFSET, kip->myenetaddr,
895 1.29 ws ETHER_ADDR_LEN, useword);
896 1.29 ws } else {
897 1.29 ws ne2000_readmem(nict, nich, np->sc_asict, np->sc_asich,
898 1.29 ws 0, romdata, sizeof romdata, useword);
899 1.29 ws for (i = 0; i < ETHER_ADDR_LEN; i++)
900 1.42 mycroft kip->myenetaddr[i] = romdata[i << useword];
901 1.29 ws }
902 1.29 ws kip->flags |= IPKDB_MYHW;
903 1.29 ws
904 1.29 ws }
905 1.29 ws dp8390_stop(dp);
906 1.29 ws
907 1.29 ws return 0;
908 1.29 ws }
909 1.29 ws #endif
910 1.50 peter
911 1.61 uwe bool
912 1.67 dyoung ne2000_suspend(device_t self, const pmf_qual_t *qual)
913 1.61 uwe {
914 1.61 uwe struct ne2000_softc *sc = device_private(self);
915 1.61 uwe struct dp8390_softc *dsc = &sc->sc_dp8390;
916 1.61 uwe int s;
917 1.61 uwe
918 1.61 uwe s = splnet();
919 1.61 uwe
920 1.61 uwe dp8390_stop(dsc);
921 1.61 uwe dp8390_disable(dsc);
922 1.61 uwe
923 1.61 uwe splx(s);
924 1.61 uwe return true;
925 1.61 uwe }
926 1.61 uwe
927 1.61 uwe bool
928 1.67 dyoung ne2000_resume(device_t self, const pmf_qual_t *qual)
929 1.61 uwe {
930 1.61 uwe struct ne2000_softc *sc = device_private(self);
931 1.61 uwe struct dp8390_softc *dsc = &sc->sc_dp8390;
932 1.61 uwe struct ifnet *ifp = &dsc->sc_ec.ec_if;
933 1.61 uwe int s;
934 1.61 uwe
935 1.61 uwe s = splnet();
936 1.61 uwe
937 1.61 uwe if (ifp->if_flags & IFF_UP) {
938 1.61 uwe if (dp8390_enable(dsc) == 0)
939 1.61 uwe dp8390_init(dsc);
940 1.61 uwe }
941 1.61 uwe
942 1.61 uwe splx(s);
943 1.61 uwe return true;
944 1.61 uwe }
945