Deleted Added
full compact
if_de.c (12293) if_de.c (12341)
1/*-
2 * Copyright (c) 1994, 1995 Matt Thomas (matt@lkg.dec.com)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
1/*-
2 * Copyright (c) 1994, 1995 Matt Thomas (matt@lkg.dec.com)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * $Id: if_de.c,v 1.35 1995/10/26 07:40:11 davidg Exp $
24 * $Id: if_de.c,v 1.36 1995/11/14 10:03:56 phk Exp $
25 *
26 */
27
28/*
29 * DEC DC21040 PCI Ethernet Controller
30 *
31 * Written by Matt Thomas
32 * BPF support code stolen directly from if_ec.c
33 *
34 * This driver supports the DEC DE435 or any other PCI
35 * board which support DC21040, DC21041, or DC21140 (mostly).
36 */
37
38#if defined(__FreeBSD__)
39#include "de.h"
40#endif
41#if NDE > 0 || !defined(__FreeBSD__)
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/mbuf.h>
46#include <sys/protosw.h>
47#include <sys/socket.h>
48#include <sys/ioctl.h>
49#include <sys/errno.h>
50#include <sys/malloc.h>
51#include <sys/kernel.h>
52#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */
53#if defined(__FreeBSD__)
54#include <sys/devconf.h>
55#include <machine/clock.h>
56#elif defined(__bsdi__) || defined(__NetBSD__)
57#include <sys/device.h>
58#endif
59
60#include <net/if.h>
61#include <net/if_types.h>
62#include <net/if_dl.h>
63#include <net/route.h>
64
65#include "bpfilter.h"
66#if NBPFILTER > 0
67#include <net/bpf.h>
68#include <net/bpfdesc.h>
69#endif
70
71#ifdef INET
72#include <netinet/in.h>
73#include <netinet/in_systm.h>
74#include <netinet/in_var.h>
75#include <netinet/ip.h>
76#include <netinet/if_ether.h>
77#endif
78
79#ifdef NS
80#include <netns/ns.h>
81#include <netns/ns_if.h>
82#endif
83
84#include <vm/vm.h>
85#include <vm/vm_kern.h>
86#include <vm/vm_param.h>
87
88#if defined(__FreeBSD__)
89#include <pci.h>
90#if NPCI > 0
91#include <pci/pcivar.h>
92#include <pci/dc21040.h>
93#endif
94#endif /* __FreeBSD__ */
95
96#if defined(__bsdi__)
97#include <i386/pci/pci.h>
98#include <i386/pci/ic/dc21040.h>
99#include <i386/isa/isa.h>
100#include <i386/isa/icu.h>
101#include <i386/isa/dma.h>
102#include <i386/isa/isavar.h>
103#include <eisa.h>
104#if NEISA > 0
105#include <i386/eisa/eisa.h>
106#define TULIP_EISA
107#endif
108#endif /* __bsdi__ */
109
110#if defined(__NetBSD__)
111#include <dev/pci/pcivar.h>
112#include <dev/ic/dc21040reg.h>
113#if defined(__i386__)
114#include <i386/isa/isa_machdep.h>
115#endif
116#endif /* __NetBSD__ */
117
118/*
119 * Intel CPUs should use I/O mapped access.
120 * (NetBSD doesn't support it yet)
121 */
122#if defined(__i386__) && !defined(__NetBSD__)
123#define TULIP_IOMAPPED
124#endif
125
126/*
127 * This module supports
128 * the DEC DC21040 PCI Ethernet Controller.
129 * the DEC DC21041 PCI Ethernet Controller.
130 * the DEC DC21140 PCI Fast Ethernet Controller.
131 */
132
133typedef struct {
134 tulip_desc_t *ri_first;
135 tulip_desc_t *ri_last;
136 tulip_desc_t *ri_nextin;
137 tulip_desc_t *ri_nextout;
138 int ri_max;
139 int ri_free;
140} tulip_ringinfo_t;
141
142#ifdef TULIP_IOMAPPED
143typedef tulip_uint16_t tulip_csrptr_t;
144
145#define TULIP_EISA_CSRSIZE 16
146#define TULIP_EISA_CSROFFSET 0
147#define TULIP_PCI_CSRSIZE 8
148#define TULIP_PCI_CSROFFSET 0
149
150#define TULIP_READ_CSR(sc, csr) (inl((sc)->tulip_csrs.csr))
151#define TULIP_WRITE_CSR(sc, csr, val) outl((sc)->tulip_csrs.csr, val)
152
153#define TULIP_READ_CSRBYTE(sc, csr) (inb((sc)->tulip_csrs.csr))
154#define TULIP_WRITE_CSRBYTE(sc, csr, val) outb((sc)->tulip_csrs.csr, val)
155
156#else /* TULIP_IOMAPPED */
157
158typedef volatile tulip_uint32_t *tulip_csrptr_t;
159
160#if defined(__alpha__)
161#define TULIP_PCI_CSRSIZE (256 / sizeof(tulip_uint32_t))
162#define TULIP_PCI_CSROFFSET (24 / sizeof(tulip_uint32_t))
163#elif defined(__i386__)
164#define TULIP_PCI_CSRSIZE (8 / sizeof(tulip_uint32_t))
165#define TULIP_PCI_CSROFFSET 0
166#endif
167
168/*
169 * macros to read and write CSRs. Note that the "0 +" in
170 * READ_CSR is to prevent the macro from being an lvalue
171 * and WRITE_CSR shouldn't be assigned from.
172 */
173#define TULIP_READ_CSR(sc, csr) (0 + *(sc)->tulip_csrs.csr)
174#ifndef __alpha__
175#define TULIP_WRITE_CSR(sc, csr, val) \
176 ((void)(*(sc)->tulip_csrs.csr = (val)))
177#else
178#define TULIP_WRITE_CSR(sc, csr, val) \
179 ((void)(*(sc)->tulip_csrs.csr = (val), MB()))
180#endif
181
182#endif /* TULIP_IOMAPPED */
183
184typedef struct {
185 tulip_csrptr_t csr_busmode; /* CSR0 */
186 tulip_csrptr_t csr_txpoll; /* CSR1 */
187 tulip_csrptr_t csr_rxpoll; /* CSR2 */
188 tulip_csrptr_t csr_rxlist; /* CSR3 */
189 tulip_csrptr_t csr_txlist; /* CSR4 */
190 tulip_csrptr_t csr_status; /* CSR5 */
191 tulip_csrptr_t csr_command; /* CSR6 */
192 tulip_csrptr_t csr_intr; /* CSR7 */
193 tulip_csrptr_t csr_missed_frame; /* CSR8 */
194
195 /* DC21040 specific registers */
196
197 tulip_csrptr_t csr_enetrom; /* CSR9 */
198 tulip_csrptr_t csr_reserved; /* CSR10 */
199 tulip_csrptr_t csr_full_duplex; /* CSR11 */
200
201 /* DC21040/DC21041 common registers */
202
203 tulip_csrptr_t csr_sia_status; /* CSR12 */
204 tulip_csrptr_t csr_sia_connectivity; /* CSR13 */
205 tulip_csrptr_t csr_sia_tx_rx; /* CSR14 */
206 tulip_csrptr_t csr_sia_general; /* CSR15 */
207
208 /* DC21140/DC21041 common registers */
209
210 tulip_csrptr_t csr_srom_mii; /* CSR9 */
211 tulip_csrptr_t csr_gp_timer; /* CSR11 */
212
213 /* DC21140 specific registers */
214
215 tulip_csrptr_t csr_gp; /* CSR12 */
216 tulip_csrptr_t csr_watchdog; /* CSR15 */
217
218 /* DC21041 specific registers */
219
220 tulip_csrptr_t csr_bootrom; /* CSR10 */
221} tulip_regfile_t;
222
223/*
224 * The DC21040 has a stupid restriction in that the receive
225 * buffers must be longword aligned. But since Ethernet
226 * headers are not a multiple of longwords in size this forces
227 * the data to non-longword aligned. Since IP requires the
228 * data to be longword aligned, we need to copy it after it has
229 * been DMA'ed in our memory.
230 *
231 * Since we have to copy it anyways, we might as well as allocate
232 * dedicated receive space for the input. This allows to use a
233 * small receive buffer size and more ring entries to be able to
234 * better keep with a flood of tiny Ethernet packets.
235 *
236 * The receive space MUST ALWAYS be a multiple of the page size.
237 * And the number of receive descriptors multiplied by the size
238 * of the receive buffers must equal the recevive space. This
239 * is so that we can manipulate the page tables so that even if a
240 * packet wraps around the end of the receive space, we can
241 * treat it as virtually contiguous.
242 *
243 * The above used to be true (the stupid restriction is still true)
244 * but we gone to directly DMA'ing into MBUFs because with 100Mb
245 * cards the copying is just too much of a hit.
246 */
247#if defined(__alpha__)
248#define TULIP_COPY_RXDATA 1
249#endif
250
251#define TULIP_RXDESCS 16
252#define TULIP_TXDESCS 128
253#define TULIP_RXQ_TARGET 8
254
255typedef enum {
256 TULIP_DC21040_GENERIC,
257 TULIP_DC21040_ZX314_MASTER,
258 TULIP_DC21040_ZX314_SLAVE,
259 TULIP_DC21140_DEC_EB,
260 TULIP_DC21140_DEC_DE500,
261 TULIP_DC21140_COGENT_EM100,
262 TULIP_DC21140_ZNYX_ZX34X,
263 TULIP_DC21041_GENERIC,
264 TULIP_DC21041_DE450
265} tulip_board_t;
266
267typedef struct _tulip_softc_t tulip_softc_t;
268
269typedef struct {
270 tulip_board_t bd_type;
271 const char *bd_description;
272 int (*bd_media_probe)(tulip_softc_t *sc);
273 void (*bd_media_select)(tulip_softc_t *sc);
274} tulip_boardsw_t;
275
276typedef enum {
277 TULIP_DC21040, TULIP_DC21140,
278 TULIP_DC21041, TULIP_DE425,
279 TULIP_CHIPID_UNKNOWN
280} tulip_chipid_t;
281
282typedef enum {
283 TULIP_PROBE_INACTIVE, TULIP_PROBE_10BASET, TULIP_PROBE_AUI,
284 TULIP_PROBE_BNC
285} tulip_probe_state_t;
286
287typedef enum {
288 TULIP_MEDIA_UNKNOWN, TULIP_MEDIA_10BASET,
289 TULIP_MEDIA_BNC, TULIP_MEDIA_AUI,
290 TULIP_MEDIA_BNCAUI, TULIP_MEDIA_100BASET
291} tulip_media_t;
292
293struct _tulip_softc_t {
294#if defined(__bsdi__)
295 struct device tulip_dev; /* base device */
296 struct isadev tulip_id; /* ISA device */
297 struct intrhand tulip_ih; /* intrrupt vectoring */
298 struct atshutdown tulip_ats; /* shutdown hook */
299#endif
300#if defined(__NetBSD__)
301 struct device tulip_dev; /* base device */
302 void *tulip_ih; /* intrrupt vectoring */
303 void *tulip_ats; /* shutdown hook */
304#endif
305 struct arpcom tulip_ac;
306 tulip_regfile_t tulip_csrs;
307 unsigned tulip_flags;
308#define TULIP_WANTSETUP 0x0001
309#define TULIP_WANTHASH 0x0002
310#define TULIP_DOINGSETUP 0x0004
311#define TULIP_ALTPHYS 0x0008 /* use AUI */
312#define TULIP_TXPROBE_ACTIVE 0x0010
313#define TULIP_TXPROBE_OK 0x0020
314#define TULIP_INRESET 0x0040
315#define TULIP_WANTRXACT 0x0080
316#define TULIP_SLAVEDROM 0x0100
317#define TULIP_ROMOK 0x0200
318 unsigned char tulip_rombuf[128];
319 tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)];
320 tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)];
321 tulip_uint32_t tulip_intrmask;
322 tulip_uint32_t tulip_cmdmode;
323 tulip_uint32_t tulip_revinfo;
324 tulip_uint32_t tulip_gpticks;
325 /* tulip_uint32_t tulip_bus; XXX */
326 tulip_media_t tulip_media;
327 tulip_probe_state_t tulip_probe_state;
328 tulip_chipid_t tulip_chipid;
329 const tulip_boardsw_t *tulip_boardsw;
330 tulip_softc_t *tulip_slaves;
331 struct ifqueue tulip_txq;
332 struct ifqueue tulip_rxq;
333 tulip_ringinfo_t tulip_rxinfo;
334 tulip_ringinfo_t tulip_txinfo;
335};
336
337#ifndef IFF_ALTPHYS
338#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */
339#endif
340static const char *tulip_chipdescs[] = {
341 "DC21040 [10Mb/s]",
342 "DC21140 [10-100Mb/s]",
343 "DC21041 [10Mb/s]",
344#if defined(TULIP_EISA)
345 "DE425 [10Mb/s]"
346#endif
347};
348
349#if defined(__FreeBSD__)
350typedef void ifnet_ret_t;
351typedef int ioctl_cmd_t;
352tulip_softc_t *tulips[NDE];
353#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit])
354#endif
355#if defined(__bsdi__)
356typedef int ifnet_ret_t;
357typedef int ioctl_cmd_t;
358extern struct cfdriver decd;
359#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit])
360#define TULIP_BURSTSIZE(unit) 3
361#endif
362#if defined(__NetBSD__)
363typedef void ifnet_ret_t;
364typedef u_long ioctl_cmd_t;
365extern struct cfdriver decd;
366#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit])
367#endif
368
369#ifndef TULIP_BURSTSIZE
370#define TULIP_BURSTSIZE(unit) 3
371#endif
372
373#define tulip_if tulip_ac.ac_if
374#define tulip_unit tulip_ac.ac_if.if_unit
375#define tulip_name tulip_ac.ac_if.if_name
376#define tulip_bpf tulip_ac.ac_if.if_bpf
377#define tulip_hwaddr tulip_ac.ac_enaddr
378
379#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */
380#define TULIP_CHECK_RXCRC 0
381#define TULIP_MAX_TXSEG 30
382
383#define TULIP_ADDREQUAL(a1, a2) \
384 (((u_short *)a1)[0] == ((u_short *)a2)[0] \
385 && ((u_short *)a1)[1] == ((u_short *)a2)[1] \
386 && ((u_short *)a1)[2] == ((u_short *)a2)[2])
387#define TULIP_ADDRBRDCST(a1) \
388 (((u_short *)a1)[0] == 0xFFFFU \
389 && ((u_short *)a1)[1] == 0xFFFFU \
390 && ((u_short *)a1)[2] == 0xFFFFU)
391
392static ifnet_ret_t tulip_start(struct ifnet *ifp);
393static void tulip_rx_intr(tulip_softc_t *sc);
394static void tulip_addr_filter(tulip_softc_t *sc);
395
396
397static int
398tulip_dc21040_media_probe(
399 tulip_softc_t * const sc)
400{
401 int cnt;
402
403 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0);
404 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
405 for (cnt = 0; cnt < 2400; cnt++) {
406 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
407 break;
408 DELAY(1000);
409 }
410 return (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) != 0;
411}
412
413static void
414tulip_dc21040_media_select(
415 tulip_softc_t * const sc)
416{
25 *
26 */
27
28/*
29 * DEC DC21040 PCI Ethernet Controller
30 *
31 * Written by Matt Thomas
32 * BPF support code stolen directly from if_ec.c
33 *
34 * This driver supports the DEC DE435 or any other PCI
35 * board which support DC21040, DC21041, or DC21140 (mostly).
36 */
37
38#if defined(__FreeBSD__)
39#include "de.h"
40#endif
41#if NDE > 0 || !defined(__FreeBSD__)
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/mbuf.h>
46#include <sys/protosw.h>
47#include <sys/socket.h>
48#include <sys/ioctl.h>
49#include <sys/errno.h>
50#include <sys/malloc.h>
51#include <sys/kernel.h>
52#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */
53#if defined(__FreeBSD__)
54#include <sys/devconf.h>
55#include <machine/clock.h>
56#elif defined(__bsdi__) || defined(__NetBSD__)
57#include <sys/device.h>
58#endif
59
60#include <net/if.h>
61#include <net/if_types.h>
62#include <net/if_dl.h>
63#include <net/route.h>
64
65#include "bpfilter.h"
66#if NBPFILTER > 0
67#include <net/bpf.h>
68#include <net/bpfdesc.h>
69#endif
70
71#ifdef INET
72#include <netinet/in.h>
73#include <netinet/in_systm.h>
74#include <netinet/in_var.h>
75#include <netinet/ip.h>
76#include <netinet/if_ether.h>
77#endif
78
79#ifdef NS
80#include <netns/ns.h>
81#include <netns/ns_if.h>
82#endif
83
84#include <vm/vm.h>
85#include <vm/vm_kern.h>
86#include <vm/vm_param.h>
87
88#if defined(__FreeBSD__)
89#include <pci.h>
90#if NPCI > 0
91#include <pci/pcivar.h>
92#include <pci/dc21040.h>
93#endif
94#endif /* __FreeBSD__ */
95
96#if defined(__bsdi__)
97#include <i386/pci/pci.h>
98#include <i386/pci/ic/dc21040.h>
99#include <i386/isa/isa.h>
100#include <i386/isa/icu.h>
101#include <i386/isa/dma.h>
102#include <i386/isa/isavar.h>
103#include <eisa.h>
104#if NEISA > 0
105#include <i386/eisa/eisa.h>
106#define TULIP_EISA
107#endif
108#endif /* __bsdi__ */
109
110#if defined(__NetBSD__)
111#include <dev/pci/pcivar.h>
112#include <dev/ic/dc21040reg.h>
113#if defined(__i386__)
114#include <i386/isa/isa_machdep.h>
115#endif
116#endif /* __NetBSD__ */
117
118/*
119 * Intel CPUs should use I/O mapped access.
120 * (NetBSD doesn't support it yet)
121 */
122#if defined(__i386__) && !defined(__NetBSD__)
123#define TULIP_IOMAPPED
124#endif
125
126/*
127 * This module supports
128 * the DEC DC21040 PCI Ethernet Controller.
129 * the DEC DC21041 PCI Ethernet Controller.
130 * the DEC DC21140 PCI Fast Ethernet Controller.
131 */
132
133typedef struct {
134 tulip_desc_t *ri_first;
135 tulip_desc_t *ri_last;
136 tulip_desc_t *ri_nextin;
137 tulip_desc_t *ri_nextout;
138 int ri_max;
139 int ri_free;
140} tulip_ringinfo_t;
141
142#ifdef TULIP_IOMAPPED
143typedef tulip_uint16_t tulip_csrptr_t;
144
145#define TULIP_EISA_CSRSIZE 16
146#define TULIP_EISA_CSROFFSET 0
147#define TULIP_PCI_CSRSIZE 8
148#define TULIP_PCI_CSROFFSET 0
149
150#define TULIP_READ_CSR(sc, csr) (inl((sc)->tulip_csrs.csr))
151#define TULIP_WRITE_CSR(sc, csr, val) outl((sc)->tulip_csrs.csr, val)
152
153#define TULIP_READ_CSRBYTE(sc, csr) (inb((sc)->tulip_csrs.csr))
154#define TULIP_WRITE_CSRBYTE(sc, csr, val) outb((sc)->tulip_csrs.csr, val)
155
156#else /* TULIP_IOMAPPED */
157
158typedef volatile tulip_uint32_t *tulip_csrptr_t;
159
160#if defined(__alpha__)
161#define TULIP_PCI_CSRSIZE (256 / sizeof(tulip_uint32_t))
162#define TULIP_PCI_CSROFFSET (24 / sizeof(tulip_uint32_t))
163#elif defined(__i386__)
164#define TULIP_PCI_CSRSIZE (8 / sizeof(tulip_uint32_t))
165#define TULIP_PCI_CSROFFSET 0
166#endif
167
168/*
169 * macros to read and write CSRs. Note that the "0 +" in
170 * READ_CSR is to prevent the macro from being an lvalue
171 * and WRITE_CSR shouldn't be assigned from.
172 */
173#define TULIP_READ_CSR(sc, csr) (0 + *(sc)->tulip_csrs.csr)
174#ifndef __alpha__
175#define TULIP_WRITE_CSR(sc, csr, val) \
176 ((void)(*(sc)->tulip_csrs.csr = (val)))
177#else
178#define TULIP_WRITE_CSR(sc, csr, val) \
179 ((void)(*(sc)->tulip_csrs.csr = (val), MB()))
180#endif
181
182#endif /* TULIP_IOMAPPED */
183
184typedef struct {
185 tulip_csrptr_t csr_busmode; /* CSR0 */
186 tulip_csrptr_t csr_txpoll; /* CSR1 */
187 tulip_csrptr_t csr_rxpoll; /* CSR2 */
188 tulip_csrptr_t csr_rxlist; /* CSR3 */
189 tulip_csrptr_t csr_txlist; /* CSR4 */
190 tulip_csrptr_t csr_status; /* CSR5 */
191 tulip_csrptr_t csr_command; /* CSR6 */
192 tulip_csrptr_t csr_intr; /* CSR7 */
193 tulip_csrptr_t csr_missed_frame; /* CSR8 */
194
195 /* DC21040 specific registers */
196
197 tulip_csrptr_t csr_enetrom; /* CSR9 */
198 tulip_csrptr_t csr_reserved; /* CSR10 */
199 tulip_csrptr_t csr_full_duplex; /* CSR11 */
200
201 /* DC21040/DC21041 common registers */
202
203 tulip_csrptr_t csr_sia_status; /* CSR12 */
204 tulip_csrptr_t csr_sia_connectivity; /* CSR13 */
205 tulip_csrptr_t csr_sia_tx_rx; /* CSR14 */
206 tulip_csrptr_t csr_sia_general; /* CSR15 */
207
208 /* DC21140/DC21041 common registers */
209
210 tulip_csrptr_t csr_srom_mii; /* CSR9 */
211 tulip_csrptr_t csr_gp_timer; /* CSR11 */
212
213 /* DC21140 specific registers */
214
215 tulip_csrptr_t csr_gp; /* CSR12 */
216 tulip_csrptr_t csr_watchdog; /* CSR15 */
217
218 /* DC21041 specific registers */
219
220 tulip_csrptr_t csr_bootrom; /* CSR10 */
221} tulip_regfile_t;
222
223/*
224 * The DC21040 has a stupid restriction in that the receive
225 * buffers must be longword aligned. But since Ethernet
226 * headers are not a multiple of longwords in size this forces
227 * the data to non-longword aligned. Since IP requires the
228 * data to be longword aligned, we need to copy it after it has
229 * been DMA'ed in our memory.
230 *
231 * Since we have to copy it anyways, we might as well as allocate
232 * dedicated receive space for the input. This allows to use a
233 * small receive buffer size and more ring entries to be able to
234 * better keep with a flood of tiny Ethernet packets.
235 *
236 * The receive space MUST ALWAYS be a multiple of the page size.
237 * And the number of receive descriptors multiplied by the size
238 * of the receive buffers must equal the recevive space. This
239 * is so that we can manipulate the page tables so that even if a
240 * packet wraps around the end of the receive space, we can
241 * treat it as virtually contiguous.
242 *
243 * The above used to be true (the stupid restriction is still true)
244 * but we gone to directly DMA'ing into MBUFs because with 100Mb
245 * cards the copying is just too much of a hit.
246 */
247#if defined(__alpha__)
248#define TULIP_COPY_RXDATA 1
249#endif
250
251#define TULIP_RXDESCS 16
252#define TULIP_TXDESCS 128
253#define TULIP_RXQ_TARGET 8
254
255typedef enum {
256 TULIP_DC21040_GENERIC,
257 TULIP_DC21040_ZX314_MASTER,
258 TULIP_DC21040_ZX314_SLAVE,
259 TULIP_DC21140_DEC_EB,
260 TULIP_DC21140_DEC_DE500,
261 TULIP_DC21140_COGENT_EM100,
262 TULIP_DC21140_ZNYX_ZX34X,
263 TULIP_DC21041_GENERIC,
264 TULIP_DC21041_DE450
265} tulip_board_t;
266
267typedef struct _tulip_softc_t tulip_softc_t;
268
269typedef struct {
270 tulip_board_t bd_type;
271 const char *bd_description;
272 int (*bd_media_probe)(tulip_softc_t *sc);
273 void (*bd_media_select)(tulip_softc_t *sc);
274} tulip_boardsw_t;
275
276typedef enum {
277 TULIP_DC21040, TULIP_DC21140,
278 TULIP_DC21041, TULIP_DE425,
279 TULIP_CHIPID_UNKNOWN
280} tulip_chipid_t;
281
282typedef enum {
283 TULIP_PROBE_INACTIVE, TULIP_PROBE_10BASET, TULIP_PROBE_AUI,
284 TULIP_PROBE_BNC
285} tulip_probe_state_t;
286
287typedef enum {
288 TULIP_MEDIA_UNKNOWN, TULIP_MEDIA_10BASET,
289 TULIP_MEDIA_BNC, TULIP_MEDIA_AUI,
290 TULIP_MEDIA_BNCAUI, TULIP_MEDIA_100BASET
291} tulip_media_t;
292
293struct _tulip_softc_t {
294#if defined(__bsdi__)
295 struct device tulip_dev; /* base device */
296 struct isadev tulip_id; /* ISA device */
297 struct intrhand tulip_ih; /* intrrupt vectoring */
298 struct atshutdown tulip_ats; /* shutdown hook */
299#endif
300#if defined(__NetBSD__)
301 struct device tulip_dev; /* base device */
302 void *tulip_ih; /* intrrupt vectoring */
303 void *tulip_ats; /* shutdown hook */
304#endif
305 struct arpcom tulip_ac;
306 tulip_regfile_t tulip_csrs;
307 unsigned tulip_flags;
308#define TULIP_WANTSETUP 0x0001
309#define TULIP_WANTHASH 0x0002
310#define TULIP_DOINGSETUP 0x0004
311#define TULIP_ALTPHYS 0x0008 /* use AUI */
312#define TULIP_TXPROBE_ACTIVE 0x0010
313#define TULIP_TXPROBE_OK 0x0020
314#define TULIP_INRESET 0x0040
315#define TULIP_WANTRXACT 0x0080
316#define TULIP_SLAVEDROM 0x0100
317#define TULIP_ROMOK 0x0200
318 unsigned char tulip_rombuf[128];
319 tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)];
320 tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)];
321 tulip_uint32_t tulip_intrmask;
322 tulip_uint32_t tulip_cmdmode;
323 tulip_uint32_t tulip_revinfo;
324 tulip_uint32_t tulip_gpticks;
325 /* tulip_uint32_t tulip_bus; XXX */
326 tulip_media_t tulip_media;
327 tulip_probe_state_t tulip_probe_state;
328 tulip_chipid_t tulip_chipid;
329 const tulip_boardsw_t *tulip_boardsw;
330 tulip_softc_t *tulip_slaves;
331 struct ifqueue tulip_txq;
332 struct ifqueue tulip_rxq;
333 tulip_ringinfo_t tulip_rxinfo;
334 tulip_ringinfo_t tulip_txinfo;
335};
336
337#ifndef IFF_ALTPHYS
338#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */
339#endif
340static const char *tulip_chipdescs[] = {
341 "DC21040 [10Mb/s]",
342 "DC21140 [10-100Mb/s]",
343 "DC21041 [10Mb/s]",
344#if defined(TULIP_EISA)
345 "DE425 [10Mb/s]"
346#endif
347};
348
349#if defined(__FreeBSD__)
350typedef void ifnet_ret_t;
351typedef int ioctl_cmd_t;
352tulip_softc_t *tulips[NDE];
353#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit])
354#endif
355#if defined(__bsdi__)
356typedef int ifnet_ret_t;
357typedef int ioctl_cmd_t;
358extern struct cfdriver decd;
359#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit])
360#define TULIP_BURSTSIZE(unit) 3
361#endif
362#if defined(__NetBSD__)
363typedef void ifnet_ret_t;
364typedef u_long ioctl_cmd_t;
365extern struct cfdriver decd;
366#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit])
367#endif
368
369#ifndef TULIP_BURSTSIZE
370#define TULIP_BURSTSIZE(unit) 3
371#endif
372
373#define tulip_if tulip_ac.ac_if
374#define tulip_unit tulip_ac.ac_if.if_unit
375#define tulip_name tulip_ac.ac_if.if_name
376#define tulip_bpf tulip_ac.ac_if.if_bpf
377#define tulip_hwaddr tulip_ac.ac_enaddr
378
379#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */
380#define TULIP_CHECK_RXCRC 0
381#define TULIP_MAX_TXSEG 30
382
383#define TULIP_ADDREQUAL(a1, a2) \
384 (((u_short *)a1)[0] == ((u_short *)a2)[0] \
385 && ((u_short *)a1)[1] == ((u_short *)a2)[1] \
386 && ((u_short *)a1)[2] == ((u_short *)a2)[2])
387#define TULIP_ADDRBRDCST(a1) \
388 (((u_short *)a1)[0] == 0xFFFFU \
389 && ((u_short *)a1)[1] == 0xFFFFU \
390 && ((u_short *)a1)[2] == 0xFFFFU)
391
392static ifnet_ret_t tulip_start(struct ifnet *ifp);
393static void tulip_rx_intr(tulip_softc_t *sc);
394static void tulip_addr_filter(tulip_softc_t *sc);
395
396
397static int
398tulip_dc21040_media_probe(
399 tulip_softc_t * const sc)
400{
401 int cnt;
402
403 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0);
404 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
405 for (cnt = 0; cnt < 2400; cnt++) {
406 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
407 break;
408 DELAY(1000);
409 }
410 return (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) != 0;
411}
412
413static void
414tulip_dc21040_media_select(
415 tulip_softc_t * const sc)
416{
417 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160;
417 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
418 |TULIP_CMD_BACKOFFCTR;
418 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
419 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
420 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
421 printf("%s%d: enabling Thinwire/AUI port\n",
422 sc->tulip_if.if_name, sc->tulip_if.if_unit);
423 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_AUI);
424 sc->tulip_flags |= TULIP_ALTPHYS;
425 } else {
426 if (sc->tulip_flags & TULIP_ALTPHYS)
427 printf("%s%d: enabling 10baseT/UTP port\n",
428 sc->tulip_if.if_name, sc->tulip_if.if_unit);
429 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
430 sc->tulip_flags &= ~TULIP_ALTPHYS;
431 sc->tulip_media = TULIP_MEDIA_10BASET;
432 }
433}
434
435static const tulip_boardsw_t tulip_dc21040_boardsw = {
436 TULIP_DC21040_GENERIC,
437 "",
438 tulip_dc21040_media_probe,
439 tulip_dc21040_media_select
440};
441
442static int
443tulip_zx314_media_probe(
444 tulip_softc_t * const sc)
445{
446 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0);
447 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
448 return 0;
449}
450
451static void
452tulip_zx314_media_select(
453 tulip_softc_t * const sc)
454{
419 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
420 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
421 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
422 printf("%s%d: enabling Thinwire/AUI port\n",
423 sc->tulip_if.if_name, sc->tulip_if.if_unit);
424 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_AUI);
425 sc->tulip_flags |= TULIP_ALTPHYS;
426 } else {
427 if (sc->tulip_flags & TULIP_ALTPHYS)
428 printf("%s%d: enabling 10baseT/UTP port\n",
429 sc->tulip_if.if_name, sc->tulip_if.if_unit);
430 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
431 sc->tulip_flags &= ~TULIP_ALTPHYS;
432 sc->tulip_media = TULIP_MEDIA_10BASET;
433 }
434}
435
436static const tulip_boardsw_t tulip_dc21040_boardsw = {
437 TULIP_DC21040_GENERIC,
438 "",
439 tulip_dc21040_media_probe,
440 tulip_dc21040_media_select
441};
442
443static int
444tulip_zx314_media_probe(
445 tulip_softc_t * const sc)
446{
447 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0);
448 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
449 return 0;
450}
451
452static void
453tulip_zx314_media_select(
454 tulip_softc_t * const sc)
455{
455 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160;
456 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
457 |TULIP_CMD_BACKOFFCTR;
456 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
457 if (sc->tulip_flags & TULIP_ALTPHYS)
458 printf("%s%d: enabling 10baseT/UTP port\n",
459 sc->tulip_if.if_name, sc->tulip_if.if_unit);
460 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
461 sc->tulip_flags &= ~TULIP_ALTPHYS;
462 sc->tulip_media = TULIP_MEDIA_10BASET;
463}
464
465
466static const tulip_boardsw_t tulip_dc21040_zx314_master_boardsw = {
467 TULIP_DC21040_ZX314_MASTER,
468 "ZNYX ZX314 ",
469 tulip_zx314_media_probe,
470 tulip_zx314_media_select
471};
472
473static const tulip_boardsw_t tulip_dc21040_zx314_slave_boardsw = {
474 TULIP_DC21040_ZX314_SLAVE,
475 "ZNYX ZX314 ",
476 tulip_zx314_media_probe,
477 tulip_zx314_media_select
478};
479
480static int
481tulip_dc21140_evalboard_media_probe(
482 tulip_softc_t * const sc)
483{
484 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS);
485 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT);
486 TULIP_WRITE_CSR(sc, csr_command,
487 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
488 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
489 TULIP_WRITE_CSR(sc, csr_command,
490 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
491 DELAY(1000000);
492 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_EB_OK100) != 0;
493}
494
495static void
496tulip_dc21140_evalboard_media_select(
497 tulip_softc_t * const sc)
498{
458 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
459 if (sc->tulip_flags & TULIP_ALTPHYS)
460 printf("%s%d: enabling 10baseT/UTP port\n",
461 sc->tulip_if.if_name, sc->tulip_if.if_unit);
462 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET);
463 sc->tulip_flags &= ~TULIP_ALTPHYS;
464 sc->tulip_media = TULIP_MEDIA_10BASET;
465}
466
467
468static const tulip_boardsw_t tulip_dc21040_zx314_master_boardsw = {
469 TULIP_DC21040_ZX314_MASTER,
470 "ZNYX ZX314 ",
471 tulip_zx314_media_probe,
472 tulip_zx314_media_select
473};
474
475static const tulip_boardsw_t tulip_dc21040_zx314_slave_boardsw = {
476 TULIP_DC21040_ZX314_SLAVE,
477 "ZNYX ZX314 ",
478 tulip_zx314_media_probe,
479 tulip_zx314_media_select
480};
481
482static int
483tulip_dc21140_evalboard_media_probe(
484 tulip_softc_t * const sc)
485{
486 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS);
487 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT);
488 TULIP_WRITE_CSR(sc, csr_command,
489 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
490 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
491 TULIP_WRITE_CSR(sc, csr_command,
492 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
493 DELAY(1000000);
494 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_EB_OK100) != 0;
495}
496
497static void
498tulip_dc21140_evalboard_media_select(
499 tulip_softc_t * const sc)
500{
499 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE;
501 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE
502 |TULIP_CMD_BACKOFFCTR;
500 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS);
501 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT);
502 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
503 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
504 printf("%s%d: enabling 100baseTX UTP port\n",
505 sc->tulip_if.if_name, sc->tulip_if.if_unit);
506 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
507 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
508 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
509 sc->tulip_flags |= TULIP_ALTPHYS;
510 sc->tulip_media = TULIP_MEDIA_100BASET;
511 } else {
512 if (sc->tulip_flags & TULIP_ALTPHYS)
513 printf("%s%d: enabling 10baseT UTP port\n",
514 sc->tulip_if.if_name, sc->tulip_if.if_unit);
515 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
516 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
517 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
518 sc->tulip_flags &= ~TULIP_ALTPHYS;
519 sc->tulip_media = TULIP_MEDIA_10BASET;
520 }
521}
522
523static const tulip_boardsw_t tulip_dc21140_eb_boardsw = {
524 TULIP_DC21140_DEC_EB,
525 "",
526 tulip_dc21140_evalboard_media_probe,
527 tulip_dc21140_evalboard_media_select
528};
529
530static int
531tulip_dc21140_cogent_em100_media_probe(
532 tulip_softc_t * const sc)
533{
534 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS);
535 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT);
536 TULIP_WRITE_CSR(sc, csr_command,
537 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
538 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
539 TULIP_WRITE_CSR(sc, csr_command,
540 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
541 return 1;
542}
543
544static void
545tulip_dc21140_cogent_em100_media_select(
546 tulip_softc_t * const sc)
547{
503 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS);
504 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT);
505 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
506 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
507 printf("%s%d: enabling 100baseTX UTP port\n",
508 sc->tulip_if.if_name, sc->tulip_if.if_unit);
509 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
510 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
511 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
512 sc->tulip_flags |= TULIP_ALTPHYS;
513 sc->tulip_media = TULIP_MEDIA_100BASET;
514 } else {
515 if (sc->tulip_flags & TULIP_ALTPHYS)
516 printf("%s%d: enabling 10baseT UTP port\n",
517 sc->tulip_if.if_name, sc->tulip_if.if_unit);
518 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
519 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
520 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
521 sc->tulip_flags &= ~TULIP_ALTPHYS;
522 sc->tulip_media = TULIP_MEDIA_10BASET;
523 }
524}
525
526static const tulip_boardsw_t tulip_dc21140_eb_boardsw = {
527 TULIP_DC21140_DEC_EB,
528 "",
529 tulip_dc21140_evalboard_media_probe,
530 tulip_dc21140_evalboard_media_select
531};
532
533static int
534tulip_dc21140_cogent_em100_media_probe(
535 tulip_softc_t * const sc)
536{
537 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS);
538 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT);
539 TULIP_WRITE_CSR(sc, csr_command,
540 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
541 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
542 TULIP_WRITE_CSR(sc, csr_command,
543 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
544 return 1;
545}
546
547static void
548tulip_dc21140_cogent_em100_media_select(
549 tulip_softc_t * const sc)
550{
548 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE;
551 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE
552 |TULIP_CMD_BACKOFFCTR;
549 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS);
550 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT);
551 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
552 printf("%s%d: enabling 100baseTX UTP port\n",
553 sc->tulip_if.if_name, sc->tulip_if.if_unit);
554 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
555 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
556 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
557 sc->tulip_flags |= TULIP_ALTPHYS;
558 sc->tulip_media = TULIP_MEDIA_100BASET;
559}
560
561static const tulip_boardsw_t tulip_dc21140_cogent_em100_boardsw = {
562 TULIP_DC21140_COGENT_EM100,
563 "Cogent EM100 ",
564 tulip_dc21140_cogent_em100_media_probe,
565 tulip_dc21140_cogent_em100_media_select
566};
567
568
569static int
570tulip_dc21140_znyx_zx34x_media_probe(
571 tulip_softc_t * const sc)
572{
573 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS);
574 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT);
575 TULIP_WRITE_CSR(sc, csr_command,
576 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
577 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
578 TULIP_WRITE_CSR(sc, csr_command,
579 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
580 DELAY(1000000);
581
582 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_ZX34X_OK10);
583}
584
585static void
586tulip_dc21140_znyx_zx34x_media_select(
587 tulip_softc_t * const sc)
588{
553 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS);
554 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT);
555 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
556 printf("%s%d: enabling 100baseTX UTP port\n",
557 sc->tulip_if.if_name, sc->tulip_if.if_unit);
558 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
559 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
560 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
561 sc->tulip_flags |= TULIP_ALTPHYS;
562 sc->tulip_media = TULIP_MEDIA_100BASET;
563}
564
565static const tulip_boardsw_t tulip_dc21140_cogent_em100_boardsw = {
566 TULIP_DC21140_COGENT_EM100,
567 "Cogent EM100 ",
568 tulip_dc21140_cogent_em100_media_probe,
569 tulip_dc21140_cogent_em100_media_select
570};
571
572
573static int
574tulip_dc21140_znyx_zx34x_media_probe(
575 tulip_softc_t * const sc)
576{
577 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS);
578 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT);
579 TULIP_WRITE_CSR(sc, csr_command,
580 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
581 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
582 TULIP_WRITE_CSR(sc, csr_command,
583 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
584 DELAY(1000000);
585
586 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_ZX34X_OK10);
587}
588
589static void
590tulip_dc21140_znyx_zx34x_media_select(
591 tulip_softc_t * const sc)
592{
589 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE;
593 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE
594 |TULIP_CMD_BACKOFFCTR;
590 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS);
591 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT);
592 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
593 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
594 printf("%s%d: enabling 100baseTX UTP port\n",
595 sc->tulip_if.if_name, sc->tulip_if.if_unit);
596 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
597 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
598 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
599 sc->tulip_flags |= TULIP_ALTPHYS;
600 sc->tulip_media = TULIP_MEDIA_100BASET;
601 } else {
602 if (sc->tulip_flags & TULIP_ALTPHYS)
603 printf("%s%d: enabling 10baseT UTP port\n",
604 sc->tulip_if.if_name, sc->tulip_if.if_unit);
605 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
606 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
607 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
608 sc->tulip_flags &= ~TULIP_ALTPHYS;
609 sc->tulip_media = TULIP_MEDIA_10BASET;
610 }
611}
612
613static const tulip_boardsw_t tulip_dc21140_znyx_zx34x_boardsw = {
614 TULIP_DC21140_ZNYX_ZX34X,
615 "ZNYX ZX34X ",
616 tulip_dc21140_znyx_zx34x_media_probe,
617 tulip_dc21140_znyx_zx34x_media_select
618};
619
620static int
621tulip_dc21140_de500_media_probe(
622 tulip_softc_t * const sc)
623{
624 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS);
625 DELAY(1000);
626 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX);
627 if ((TULIP_READ_CSR(sc, csr_gp) &
628 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) !=
629 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10))
630 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) != 0;
631 TULIP_WRITE_CSR(sc, csr_gp,
632 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100);
633 TULIP_WRITE_CSR(sc, csr_command,
634 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
635 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
636 TULIP_WRITE_CSR(sc, csr_command,
637 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
638 DELAY(1000000);
639 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) != 0;
640}
641
642static void
643tulip_dc21140_de500_media_select(
644 tulip_softc_t * const sc)
645{
595 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS);
596 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT);
597 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
598 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
599 printf("%s%d: enabling 100baseTX UTP port\n",
600 sc->tulip_if.if_name, sc->tulip_if.if_unit);
601 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
602 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
603 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
604 sc->tulip_flags |= TULIP_ALTPHYS;
605 sc->tulip_media = TULIP_MEDIA_100BASET;
606 } else {
607 if (sc->tulip_flags & TULIP_ALTPHYS)
608 printf("%s%d: enabling 10baseT UTP port\n",
609 sc->tulip_if.if_name, sc->tulip_if.if_unit);
610 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
611 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
612 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
613 sc->tulip_flags &= ~TULIP_ALTPHYS;
614 sc->tulip_media = TULIP_MEDIA_10BASET;
615 }
616}
617
618static const tulip_boardsw_t tulip_dc21140_znyx_zx34x_boardsw = {
619 TULIP_DC21140_ZNYX_ZX34X,
620 "ZNYX ZX34X ",
621 tulip_dc21140_znyx_zx34x_media_probe,
622 tulip_dc21140_znyx_zx34x_media_select
623};
624
625static int
626tulip_dc21140_de500_media_probe(
627 tulip_softc_t * const sc)
628{
629 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS);
630 DELAY(1000);
631 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX);
632 if ((TULIP_READ_CSR(sc, csr_gp) &
633 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) !=
634 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10))
635 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) != 0;
636 TULIP_WRITE_CSR(sc, csr_gp,
637 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100);
638 TULIP_WRITE_CSR(sc, csr_command,
639 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT |
640 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
641 TULIP_WRITE_CSR(sc, csr_command,
642 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
643 DELAY(1000000);
644 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) != 0;
645}
646
647static void
648tulip_dc21140_de500_media_select(
649 tulip_softc_t * const sc)
650{
646 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE;
651 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE
652 |TULIP_CMD_BACKOFFCTR;
647 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS);
648 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
649 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
650 printf("%s%d: enabling 100baseTX UTP port\n",
651 sc->tulip_if.if_name, sc->tulip_if.if_unit);
652 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
653 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
654 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
655 sc->tulip_flags |= TULIP_ALTPHYS;
656 sc->tulip_media = TULIP_MEDIA_100BASET;
657 TULIP_WRITE_CSR(sc, csr_gp,
658 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100);
659 } else {
660 if (sc->tulip_flags & TULIP_ALTPHYS)
661 printf("%s%d: enabling 10baseT UTP port\n",
662 sc->tulip_if.if_name, sc->tulip_if.if_unit);
663 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
664 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
665 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
666 sc->tulip_flags &= ~TULIP_ALTPHYS;
667 sc->tulip_media = TULIP_MEDIA_10BASET;
668 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX);
669 }
670}
671
672static const tulip_boardsw_t tulip_dc21140_de500_boardsw = {
673 TULIP_DC21140_DEC_DE500, "Digital DE500 ",
674 tulip_dc21140_de500_media_probe,
675 tulip_dc21140_de500_media_select
676};
677
678static int
679tulip_dc21041_media_probe(
680 tulip_softc_t * const sc)
681{
682 return 0;
683}
684
685static void
686tulip_dc21041_media_select(
687 tulip_softc_t * const sc)
688{
689 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
653 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS);
654 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
655 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0)
656 printf("%s%d: enabling 100baseTX UTP port\n",
657 sc->tulip_if.if_name, sc->tulip_if.if_unit);
658 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT
659 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER;
660 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
661 sc->tulip_flags |= TULIP_ALTPHYS;
662 sc->tulip_media = TULIP_MEDIA_100BASET;
663 TULIP_WRITE_CSR(sc, csr_gp,
664 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100);
665 } else {
666 if (sc->tulip_flags & TULIP_ALTPHYS)
667 printf("%s%d: enabling 10baseT UTP port\n",
668 sc->tulip_if.if_name, sc->tulip_if.if_unit);
669 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT
670 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER);
671 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
672 sc->tulip_flags &= ~TULIP_ALTPHYS;
673 sc->tulip_media = TULIP_MEDIA_10BASET;
674 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX);
675 }
676}
677
678static const tulip_boardsw_t tulip_dc21140_de500_boardsw = {
679 TULIP_DC21140_DEC_DE500, "Digital DE500 ",
680 tulip_dc21140_de500_media_probe,
681 tulip_dc21140_de500_media_select
682};
683
684static int
685tulip_dc21041_media_probe(
686 tulip_softc_t * const sc)
687{
688 return 0;
689}
690
691static void
692tulip_dc21041_media_select(
693 tulip_softc_t * const sc)
694{
695 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
690 /* |TULIP_CMD_FULLDUPLEX */ |TULIP_CMD_THRSHLD160;
696 /* |TULIP_CMD_FULLDUPLEX */ |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
691 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_GPTIMEOUT
692 |TULIP_STS_ABNRMLINTR|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
693 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
694 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) {
695 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
696 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE);
697 sc->tulip_flags |= TULIP_ALTPHYS|TULIP_WANTRXACT;
698 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
699 }
700 } else {
701 if (sc->tulip_flags & TULIP_ALTPHYS) {
702 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
703 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE|TULIP_ALTPHYS);
704 sc->tulip_flags |= TULIP_WANTRXACT;
705 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
706 }
707 }
708
709 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) {
710 if (sc->tulip_media == TULIP_MEDIA_10BASET) {
711 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
712 } else if (sc->tulip_media == TULIP_MEDIA_BNC) {
713 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
714 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
715 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
716 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
717 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
718 return;
719 } else if (sc->tulip_media == TULIP_MEDIA_AUI) {
720 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
721 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
722 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
723 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
724 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
725 return;
726 }
727
728 switch (sc->tulip_probe_state) {
729 case TULIP_PROBE_INACTIVE: {
730 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
731 sc->tulip_if.if_flags |= IFF_OACTIVE;
732 sc->tulip_gpticks = 200;
733 sc->tulip_probe_state = TULIP_PROBE_10BASET;
734 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
735 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET);
736 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET);
737 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET);
738 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */
739 break;
740 }
741 case TULIP_PROBE_10BASET: {
742 if (--sc->tulip_gpticks > 0) {
743 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
744 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */
745 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
746 break;
747 }
748 }
749 sc->tulip_gpticks = 4;
750 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) {
751 sc->tulip_probe_state = TULIP_PROBE_BNC;
752 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
753 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
754 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
755 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
756 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
757 } else {
758 sc->tulip_probe_state = TULIP_PROBE_AUI;
759 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
760 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
761 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
762 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
763 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
764 }
765 break;
766 }
767 case TULIP_PROBE_BNC:
768 case TULIP_PROBE_AUI: {
769 if (sc->tulip_flags & TULIP_TXPROBE_OK) {
770 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
771 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE);
772 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */
773 if ((sc->tulip_probe_state == TULIP_PROBE_AUI
774 && sc->tulip_media != TULIP_MEDIA_AUI)
775 || (sc->tulip_probe_state == TULIP_PROBE_BNC
776 && sc->tulip_media != TULIP_MEDIA_AUI)) {
777 printf("%s%d: enabling %s port\n",
778 sc->tulip_if.if_name, sc->tulip_if.if_unit,
779 sc->tulip_probe_state == TULIP_PROBE_BNC
780 ? "Thinwire/BNC" : "AUI");
781 if (sc->tulip_probe_state == TULIP_PROBE_AUI)
782 sc->tulip_media = TULIP_MEDIA_AUI;
783 else if (sc->tulip_probe_state == TULIP_PROBE_BNC)
784 sc->tulip_media = TULIP_MEDIA_BNC;
785 }
786 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
787 break;
788 }
789 if ((sc->tulip_flags & TULIP_WANTRXACT) == 0
790 || (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_RXACTIVITY)) {
791 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) {
792 struct mbuf *m;
793 /*
794 * Before we are sure this is the right media we need
795 * to send a small packet to make sure there's carrier.
796 * Strangely, BNC and AUI will 'see" receive data if
797 * either is connected so the transmit is the only way
798 * to verify the connectivity.
799 */
800 MGETHDR(m, M_DONTWAIT, MT_DATA);
801 if (m == NULL) {
802 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
803 break;
804 }
805 /*
806 * Construct a LLC TEST message which will point to ourselves.
807 */
808 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
809 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_shost, 6);
810 mtod(m, struct ether_header *)->ether_type = htons(3);
811 mtod(m, unsigned char *)[14] = 0;
812 mtod(m, unsigned char *)[15] = 0;
813 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
814 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
815 /*
816 * send it!
817 */
818 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
819 sc->tulip_flags &= ~TULIP_TXPROBE_OK;
820 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
821 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
822 IF_PREPEND(&sc->tulip_if.if_snd, m);
823 tulip_start(&sc->tulip_if);
824 break;
825 }
826 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
827 }
828 /*
829 * Take 2 passes through before deciding to not
830 * wait for receive activity. Then take another
831 * two passes before spitting out a warning.
832 */
833 if (sc->tulip_gpticks > 0 && --sc->tulip_gpticks == 0) {
834 if (sc->tulip_flags & TULIP_WANTRXACT) {
835 sc->tulip_flags &= ~TULIP_WANTRXACT;
836 sc->tulip_gpticks = 4;
837 } else {
838 printf("%s%d: autosense failed: cable problem?\n",
839 sc->tulip_name, sc->tulip_unit);
840 }
841 }
842 /*
843 * Since this media failed to probe, try the other one.
844 */
845 if (sc->tulip_probe_state == TULIP_PROBE_AUI) {
846 sc->tulip_probe_state = TULIP_PROBE_BNC;
847 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
848 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
849 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
850 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
851 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
852 } else {
853 sc->tulip_probe_state = TULIP_PROBE_AUI;
854 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
855 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
856 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
857 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
858 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
859 }
860 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
861 break;
862 }
863 }
864 } else {
865 /*
866 * If the link has passed LinkPass, 10baseT is the
867 * proper media to use.
868 */
869 if (sc->tulip_media != TULIP_MEDIA_10BASET)
870 printf("%s%d: enabling 10baseT/UTP port\n",
871 sc->tulip_if.if_name, sc->tulip_if.if_unit);
872 if (sc->tulip_media != TULIP_MEDIA_10BASET
873 || (sc->tulip_flags & TULIP_INRESET)) {
874 sc->tulip_media = TULIP_MEDIA_10BASET;
875 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
876 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET);
877 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET);
878 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET);
879 }
880 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */
881 sc->tulip_gpticks = 1;
882 sc->tulip_probe_state = TULIP_PROBE_10BASET;
883 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
884 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
885 }
886 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
887}
888
889static const tulip_boardsw_t tulip_dc21041_boardsw = {
890 TULIP_DC21041_GENERIC,
891 "",
892 tulip_dc21041_media_probe,
893 tulip_dc21041_media_select
894};
895
896static const tulip_boardsw_t tulip_dc21041_de450_boardsw = {
897 TULIP_DC21041_DE450,
898 "Digital DE450 ",
899 tulip_dc21041_media_probe,
900 tulip_dc21041_media_select
901};
902
903static void
904tulip_reset(
905 tulip_softc_t * const sc)
906{
907 tulip_ringinfo_t *ri;
908 tulip_desc_t *di;
909
910 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
911 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
912 33MHz that comes to two microseconds but wait a
913 bit longer anyways) */
914
915 sc->tulip_flags |= TULIP_INRESET;
916 sc->tulip_intrmask = 0;
917 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
918
919 TULIP_WRITE_CSR(sc, csr_txlist, vtophys(&sc->tulip_txinfo.ri_first[0]));
920 TULIP_WRITE_CSR(sc, csr_rxlist, vtophys(&sc->tulip_rxinfo.ri_first[0]));
921 TULIP_WRITE_CSR(sc, csr_busmode,
922 (1 << (TULIP_BURSTSIZE(sc->tulip_unit) + 8))
923 |TULIP_BUSMODE_CACHE_ALIGN8
924 |(BYTE_ORDER != LITTLE_ENDIAN ? TULIP_BUSMODE_BIGENDIAN : 0));
925
926 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
927 /*
928 * Free all the mbufs that were on the transmit ring.
929 */
930 for (;;) {
931 struct mbuf *m;
932 IF_DEQUEUE(&sc->tulip_txq, m);
933 if (m == NULL)
934 break;
935 m_freem(m);
936 }
937
938 ri = &sc->tulip_txinfo;
939 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
940 ri->ri_free = ri->ri_max;
941 for (di = ri->ri_first; di < ri->ri_last; di++)
942 di->d_status = 0;
943
944 /*
945 * We need to collect all the mbufs were on the
946 * receive ring before we reinit it either to put
947 * them back on or to know if we have to allocate
948 * more.
949 */
950 ri = &sc->tulip_rxinfo;
951 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
952 ri->ri_free = ri->ri_max;
953 for (di = ri->ri_first; di < ri->ri_last; di++) {
954 di->d_status = 0;
955 di->d_length1 = 0; di->d_addr1 = 0;
956 di->d_length2 = 0; di->d_addr2 = 0;
957 }
958 for (;;) {
959 struct mbuf *m;
960 IF_DEQUEUE(&sc->tulip_rxq, m);
961 if (m == NULL)
962 break;
963 m_freem(m);
964 }
965
966 (*sc->tulip_boardsw->bd_media_select)(sc);
967
968 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
969 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
970 |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED;
971 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET);
972 tulip_addr_filter(sc);
973}
974
975static void
976tulip_init(
977 tulip_softc_t * const sc)
978{
979 if (sc->tulip_if.if_flags & IFF_UP) {
980 sc->tulip_if.if_flags |= IFF_RUNNING;
981 if (sc->tulip_if.if_flags & IFF_PROMISC) {
982 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
983 } else {
984 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
985 if (sc->tulip_if.if_flags & IFF_ALLMULTI) {
986 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
987 } else {
988 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
989 }
990 }
991 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
992 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) {
993 tulip_rx_intr(sc);
994 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
995 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
996 } else {
997 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
998 tulip_start(&sc->tulip_if);
999 }
1000 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
1001 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1002 } else {
1003 tulip_reset(sc);
1004 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1005 }
1006}
1007
1008
1009#if TULIP_CHECK_RXCRC
1010static unsigned
1011tulip_crc32(
1012 u_char *addr,
1013 int len)
1014{
1015 unsigned int crc = 0xFFFFFFFF;
1016 static unsigned int crctbl[256];
1017 int idx;
1018 static int done;
1019 /*
1020 * initialize the multicast address CRC table
1021 */
1022 for (idx = 0; !done && idx < 256; idx++) {
1023 unsigned int tmp = idx;
1024 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1025 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1026 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1027 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1028 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1029 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1030 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1031 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1032 crctbl[idx] = tmp;
1033 }
1034 done = 1;
1035
1036 while (len-- > 0)
1037 crc = (crc >> 8) ^ crctbl[*addr++] ^ crctbl[crc & 0xFF];
1038
1039 return crc;
1040}
1041#endif
1042
1043static void
1044tulip_rx_intr(
1045 tulip_softc_t * const sc)
1046{
1047 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
1048 struct ifnet * const ifp = &sc->tulip_if;
1049
1050 for (;;) {
1051 struct ether_header eh;
1052 tulip_desc_t *eop = ri->ri_nextin;
1053 int total_len = 0;
1054 struct mbuf *m = NULL;
1055 int accept = 0;
1056
1057 if (sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
1058 goto queue_mbuf;
1059
1060 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
1061 break;
1062
1063 total_len = ((eop->d_status >> 16) & 0x7FF) - 4;
1064 IF_DEQUEUE(&sc->tulip_rxq, m);
1065 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0) {
1066
1067#if TULIP_CHECK_RXCRC
1068 unsigned crc = tulip_crc32(mtod(m, unsigned char *), total_len);
1069 if (~crc != *((unsigned *) &bufaddr[total_len])) {
1070 printf("%s%d: bad rx crc: %08x [rx] != %08x\n",
1071 sc->tulip_name, sc->tulip_unit,
1072 *((unsigned *) &bufaddr[total_len]), ~crc);
1073 goto next;
1074 }
1075#endif
1076 eh = *mtod(m, struct ether_header *);
1077#if NBPFILTER > 0
1078 if (sc->tulip_bpf != NULL)
1079 bpf_tap(sc->tulip_bpf, mtod(m, caddr_t), total_len);
1080#endif
1081 if ((sc->tulip_if.if_flags & IFF_PROMISC)
1082 && (eh.ether_dhost[0] & 1) == 0
1083 && !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr))
1084 goto next;
1085 accept = 1;
1086 total_len -= sizeof(struct ether_header);
1087 } else {
1088 ifp->if_ierrors++;
1089 }
1090 next:
1091 ifp->if_ipackets++;
1092 if (++ri->ri_nextin == ri->ri_last)
1093 ri->ri_nextin = ri->ri_first;
1094 queue_mbuf:
1095 /*
1096 * Either we are priming the TULIP with mbufs (m == NULL)
1097 * or we are about to accept an mbuf for the upper layers
1098 * so we need to allocate an mbuf to replace it. If we
1099 * can't replace, then count it as an input error and reuse
1100 * the mbuf.
1101 */
1102 if (accept || m == NULL) {
1103 struct mbuf *m0;
1104 MGETHDR(m0, M_DONTWAIT, MT_DATA);
1105 if (m0 != NULL) {
1106#if defined(TULIP_COPY_RXDATA)
1107 if (!accept || total_len >= MHLEN) {
1108#endif
1109 MCLGET(m0, M_DONTWAIT);
1110 if ((m0->m_flags & M_EXT) == 0) {
1111 m_freem(m0);
1112 m0 = NULL;
1113 }
1114#if defined(TULIP_COPY_RXDATA)
1115 }
1116#endif
1117 }
1118 if (accept) {
1119 if (m0 != NULL) {
1120#if defined(__bsdi__)
1121 eh.ether_type = ntohs(eh.ether_type);
1122#endif
1123#if !defined(TULIP_COPY_RXDATA)
1124 m->m_data += sizeof(struct ether_header);
1125 m->m_len = m->m_pkthdr.len = total_len;
1126 m->m_pkthdr.rcvif = ifp;
1127 ether_input(ifp, &eh, m);
1128 m = m0;
1129#else
1130 bcopy(mtod(m, caddr_t) + sizeof(struct ether_header),
1131 mtod(m0, caddr_t), total_len);
1132 m0->m_len = m0->m_pkthdr.len = total_len;
1133 m0->m_pkthdr.rcvif = ifp;
1134 ether_input(ifp, &eh, m0);
1135#endif
1136 } else {
1137 ifp->if_ierrors++;
1138 }
1139 } else {
1140 m = m0;
1141 }
1142 }
1143 if (m == NULL)
1144 break;
1145 /*
1146 * Now give the buffer to the TULIP and save in our
1147 * receive queue.
1148 */
1149 ri->ri_nextout->d_length1 = MCLBYTES - 4;
1150 ri->ri_nextout->d_addr1 = vtophys(mtod(m, caddr_t));
1151 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1152 if (++ri->ri_nextout == ri->ri_last)
1153 ri->ri_nextout = ri->ri_first;
1154 IF_ENQUEUE(&sc->tulip_rxq, m);
1155 }
1156}
1157
1158static int
1159tulip_tx_intr(
1160 tulip_softc_t * const sc)
1161{
1162 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
1163 struct mbuf *m;
1164 int xmits = 0;
1165
1166 while (ri->ri_free < ri->ri_max) {
1167 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
1168 break;
1169
1170 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) {
1171 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) {
1172 /*
1173 * We've just finished processing a setup packet.
1174 * Mark that we can finished it. If there's not
1175 * another pending, startup the TULIP receiver.
1176 * Make sure we ack the RXSTOPPED so we won't get
1177 * an abormal interrupt indication.
1178 */
1179 sc->tulip_flags &= ~TULIP_DOINGSETUP;
1180 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) {
1181 tulip_rx_intr(sc);
1182 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
1183 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
1184 TULIP_WRITE_CSR(sc, csr_status, TULIP_STS_RXSTOPPED);
1185 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1186 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
1187 }
1188 } else {
1189 IF_DEQUEUE(&sc->tulip_txq, m);
1190 m_freem(m);
1191 xmits++;
1192 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
1193 if ((ri->ri_nextin->d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) == 0)
1194 sc->tulip_flags |= TULIP_TXPROBE_OK;
1195 (*sc->tulip_boardsw->bd_media_select)(sc);
1196 } else {
1197 sc->tulip_if.if_collisions +=
1198 (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK)
1199 >> TULIP_DSTS_V_TxCOLLCNT;
1200 if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM)
1201 sc->tulip_if.if_oerrors++;
1202 }
1203 }
1204 }
1205
1206 if (++ri->ri_nextin == ri->ri_last)
1207 ri->ri_nextin = ri->ri_first;
1208 ri->ri_free++;
1209 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
1210 }
1211 sc->tulip_if.if_opackets += xmits;
1212 return xmits;
1213}
1214
1215static ifnet_ret_t
1216tulip_start(
1217 struct ifnet * const ifp)
1218{
1219 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit);
1220 struct ifqueue * const ifq = &ifp->if_snd;
1221 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
1222 struct mbuf *m, *m0, *next_m0;
1223
1224 if ((ifp->if_flags & IFF_RUNNING) == 0
1225 && (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
1226 return;
1227
1228 for (;;) {
1229 tulip_desc_t *eop, *nextout;
1230 int segcnt, free, recopy;
1231 tulip_uint32_t d_status;
1232
1233 if (sc->tulip_flags & TULIP_WANTSETUP) {
1234 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
1235 ifp->if_flags |= IFF_OACTIVE;
1236 return;
1237 }
1238 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
1239 sizeof(sc->tulip_setupbuf));
1240 sc->tulip_flags &= ~TULIP_WANTSETUP;
1241 sc->tulip_flags |= TULIP_DOINGSETUP;
1242 ri->ri_free--;
1243 ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
1244 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
1245 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
1246 if (sc->tulip_flags & TULIP_WANTHASH)
1247 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
1248 ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf);
1249 ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf);
1250 ri->ri_nextout->d_length2 = 0;
1251 ri->ri_nextout->d_addr2 = 0;
1252 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1253 TULIP_WRITE_CSR(sc, csr_txpoll, 1);
1254 /*
1255 * Advance the ring for the next transmit packet.
1256 */
1257 if (++ri->ri_nextout == ri->ri_last)
1258 ri->ri_nextout = ri->ri_first;
1259 /*
1260 * Make sure the next descriptor is owned by us since it
1261 * may have been set up above if we ran out of room in the
1262 * ring.
1263 */
1264 ri->ri_nextout->d_status = 0;
1265 }
1266
1267 IF_DEQUEUE(ifq, m);
1268 if (m == NULL)
1269 break;
1270
1271 /*
1272 * Now we try to fill in our transmit descriptors. This is
1273 * a bit reminiscent of going on the Ark two by two
1274 * since each descriptor for the TULIP can describe
1275 * two buffers. So we advance through packet filling
1276 * each of the two entries at a time to to fill each
1277 * descriptor. Clear the first and last segment bits
1278 * in each descriptor (actually just clear everything
1279 * but the end-of-ring or chain bits) to make sure
1280 * we don't get messed up by previously sent packets.
1281 *
1282 * We may fail to put the entire packet on the ring if
1283 * there is either not enough ring entries free or if the
1284 * packet has more than MAX_TXSEG segments. In the former
1285 * case we will just wait for the ring to empty. In the
1286 * latter case we have to recopy.
1287 */
1288 d_status = 0;
1289 recopy = 0;
1290 eop = nextout = ri->ri_nextout;
1291 m0 = m;
1292 segcnt = 0;
1293 free = ri->ri_free;
1294 do {
1295 int len = m0->m_len;
1296 caddr_t addr = mtod(m0, caddr_t);
1297 unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1));
1298
1299 next_m0 = m0->m_next;
1300 while (len > 0) {
1301 unsigned slen = min(len, clsize);
1302
1303 segcnt++;
1304 if (segcnt > TULIP_MAX_TXSEG) {
1305 recopy = 1;
1306 next_m0 = NULL; /* to break out of outside loop */
1307 break;
1308 }
1309 if (segcnt & 1) {
1310 if (--free == 0) {
1311 /*
1312 * There's no more room but since nothing
1313 * has been committed at this point, just
1314 * show output is active, put back the
1315 * mbuf and return.
1316 */
1317 ifp->if_flags |= IFF_OACTIVE;
1318 IF_PREPEND(ifq, m);
1319 return;
1320 }
1321 eop = nextout;
1322 if (++nextout == ri->ri_last)
1323 nextout = ri->ri_first;
1324 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
1325 eop->d_status = d_status;
1326 eop->d_addr1 = vtophys(addr); eop->d_length1 = slen;
1327 } else {
1328 /*
1329 * Fill in second half of descriptor
1330 */
1331 eop->d_addr2 = vtophys(addr); eop->d_length2 = slen;
1332 }
1333 d_status = TULIP_DSTS_OWNER;
1334 len -= slen;
1335 addr += slen;
1336 clsize = CLBYTES;
1337 }
1338 } while ((m0 = next_m0) != NULL);
1339
1340 /*
1341 * The packet exceeds the number of transmit buffer
1342 * entries that we can use for one packet, so we have
1343 * recopy it into one mbuf and then try again.
1344 */
1345 if (recopy) {
1346 MGETHDR(m0, M_DONTWAIT, MT_DATA);
1347 if (m0 != NULL) {
1348 if (m->m_pkthdr.len > MHLEN) {
1349 MCLGET(m0, M_DONTWAIT);
1350 if ((m0->m_flags & M_EXT) == 0) {
1351 m_freem(m);
1352 m_freem(m0);
1353 continue;
1354 }
1355 }
1356 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
1357 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
1358 IF_PREPEND(ifq, m0);
1359 }
1360 m_freem(m);
1361 continue;
1362 }
1363
1364 /*
1365 * The descriptors have been filled in. Now get ready
1366 * to transmit.
1367 */
1368#if NBPFILTER > 0
1369 if (sc->tulip_bpf != NULL)
1370 bpf_mtap(sc->tulip_bpf, m);
1371#endif
1372 IF_ENQUEUE(&sc->tulip_txq, m);
1373
1374 /*
1375 * Make sure the next descriptor after this packet is owned
1376 * by us since it may have been set up above if we ran out
1377 * of room in the ring.
1378 */
1379 nextout->d_status = 0;
1380
1381 /*
1382 * If we only used the first segment of the last descriptor,
1383 * make sure the second segment will not be used.
1384 */
1385 if (segcnt & 1) {
1386 eop->d_addr2 = 0;
1387 eop->d_length2 = 0;
1388 }
1389
1390 /*
1391 * Mark the last and first segments, indicate we want a transmit
1392 * complete interrupt, give the descriptors to the TULIP, and tell
1393 * it to transmit!
1394 */
1395 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
1396
1397 /*
1398 * Note that ri->ri_nextout is still the start of the packet
1399 * and until we set the OWNER bit, we can still back out of
1400 * everything we have done.
1401 */
1402 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
1403 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1404
1405 /*
1406 * This advances the ring for us.
1407 */
1408 ri->ri_nextout = nextout;
1409 ri->ri_free = free;
1410
1411 TULIP_WRITE_CSR(sc, csr_txpoll, 1);
1412 }
1413 if (m != NULL) {
1414 ifp->if_flags |= IFF_OACTIVE;
1415 IF_PREPEND(ifq, m);
1416 }
1417}
1418
1419static int
1420tulip_intr(
1421 void *arg)
1422{
1423 tulip_softc_t * sc = (tulip_softc_t *) arg;
1424 tulip_uint32_t csr;
1425#if defined(__bsdi__)
1426 int progress = 1;
1427#else
1428 int progress = 0;
1429#endif
1430
1431 do {
1432 while ((csr = TULIP_READ_CSR(sc, csr_status)) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) {
1433 progress = 1;
1434 TULIP_WRITE_CSR(sc, csr_status, csr & sc->tulip_intrmask);
1435
1436 if (csr & TULIP_STS_SYSERROR) {
1437 if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) {
1438 tulip_reset(sc);
1439 tulip_init(sc);
1440 break;
1441 }
1442 }
1443 if (csr & (TULIP_STS_GPTIMEOUT|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL)) {
1444 if (sc->tulip_chipid == TULIP_DC21041) {
1445 (*sc->tulip_boardsw->bd_media_select)(sc);
1446 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL))
1447 csr &= ~TULIP_STS_ABNRMLINTR;
1448 }
1449 }
1450 if (csr & TULIP_STS_ABNRMLINTR) {
1451 printf("%s%d: abnormal interrupt: 0x%05x [0x%05x]\n",
1452 sc->tulip_name, sc->tulip_unit, csr, csr & sc->tulip_intrmask);
1453 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1454 }
1455 if (csr & TULIP_STS_RXINTR)
1456 tulip_rx_intr(sc);
1457 if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) {
1458 tulip_tx_intr(sc);
1459 tulip_start(&sc->tulip_if);
1460 }
1461 }
1462 } while ((sc = sc->tulip_slaves) != NULL);
1463 return progress;
1464}
1465
1466/*
1467 *
1468 */
1469
1470static void
1471tulip_delay_300ns(
1472 tulip_softc_t * const sc)
1473{
1474 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1475 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1476
1477 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1478 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1479
1480 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1481 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1482}
1483
1484#define EMIT do { TULIP_WRITE_CSR(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)
1485
1486static void
1487tulip_idle_srom(
1488 tulip_softc_t * const sc)
1489{
1490 unsigned bit, csr;
1491
1492 csr = SROMSEL | SROMRD; EMIT;
1493 csr ^= SROMCS; EMIT;
1494 csr ^= SROMCLKON; EMIT;
1495
1496 /*
1497 * Write 25 cycles of 0 which will force the SROM to be idle.
1498 */
1499 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1500 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1501 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1502 }
1503 csr ^= SROMCLKOFF; EMIT;
1504 csr ^= SROMCS; EMIT; EMIT;
1505 csr = 0; EMIT;
1506}
1507
1508
1509static void
1510tulip_read_srom(
1511 tulip_softc_t * const sc)
1512{
1513 int idx;
1514 const unsigned bitwidth = SROM_BITWIDTH;
1515 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1516 const unsigned msb = 1 << (bitwidth + 3 - 1);
1517 unsigned lastidx = (1 << bitwidth) - 1;
1518
1519 tulip_idle_srom(sc);
1520
1521 for (idx = 0; idx <= lastidx; idx++) {
1522 unsigned lastbit, data, bits, bit, csr;
1523 csr = SROMSEL | SROMRD; EMIT;
1524 csr ^= SROMCSON; EMIT;
1525 csr ^= SROMCLKON; EMIT;
1526
1527 lastbit = 0;
1528 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1529 const unsigned thisbit = bits & msb;
1530 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1531 if (thisbit != lastbit) {
1532 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1533 }
1534 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1535 lastbit = thisbit;
1536 }
1537 csr ^= SROMCLKOFF; EMIT;
1538
1539 for (data = 0, bits = 0; bits < 16; bits++) {
1540 data <<= 1;
1541 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1542 data |= TULIP_READ_CSR(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1543 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1544 }
1545 sc->tulip_rombuf[idx*2] = data & 0xFF;
1546 sc->tulip_rombuf[idx*2+1] = data >> 8;
1547 csr = SROMSEL | SROMRD; EMIT;
1548 csr = 0; EMIT;
1549 }
1550}
1551
1552#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
1553#define tulip_srom_crcok(databuf) ( \
1554 ((tulip_crc32(databuf, 126) & 0xFFFF) ^ 0xFFFF)== \
1555 ((databuf)[126] | ((databuf)[127] << 8)))
1556
1557static unsigned
1558tulip_crc32(
1559 const unsigned char *databuf,
1560 size_t datalen)
1561{
1562 u_int idx, bit, data, crc = 0xFFFFFFFFUL;
1563
1564 for (idx = 0; idx < datalen; idx++)
1565 for (data = *databuf++, bit = 0; bit < 8; bit++, data >>= 1)
1566 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0);
1567 return crc;
1568}
1569
1570
1571/*
1572 * This deals with the vagaries of the address roms and the
1573 * brain-deadness that various vendors commit in using them.
1574 */
1575static int
1576tulip_read_macaddr(
1577 tulip_softc_t *sc)
1578{
1579 int cksum, rom_cksum, idx;
1580 tulip_uint32_t csr;
1581 unsigned char tmpbuf[8];
1582 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
1583
1584 if (sc->tulip_chipid == TULIP_DC21040) {
1585 TULIP_WRITE_CSR(sc, csr_enetrom, 1);
1586 for (idx = 0; idx < 32; idx++) {
1587 int cnt = 0;
1588 while (((csr = TULIP_READ_CSR(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
1589 cnt++;
1590 sc->tulip_rombuf[idx] = csr & 0xFF;
1591 }
1592 sc->tulip_boardsw = &tulip_dc21040_boardsw;
1593#if defined(TULIP_EISA)
1594 } else if (sc->tulip_chipid == TULIP_DE425) {
1595 int cnt;
1596 for (idx = 0, cnt = 0; idx < sizeof(testpat) && cnt < 32; cnt++) {
1597 tmpbuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom);
1598 if (tmpbuf[idx] == testpat[idx])
1599 ++idx;
1600 else
1601 idx = 0;
1602 }
1603 for (idx = 0; idx < 32; idx++)
1604 sc->tulip_rombuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom);
1605 sc->tulip_boardsw = &tulip_dc21040_boardsw;
1606#endif /* TULIP_EISA */
1607 } else {
1608 int new_srom_fmt = 0;
1609 /*
1610 * Assume all DC21140 board are compatible with the
1611 * DEC 10/100 evaluation board. Not really valid but
1612 * it's the best we can do until every one switches to
1613 * the new SROM format.
1614 */
1615 if (sc->tulip_chipid == TULIP_DC21140)
1616 sc->tulip_boardsw = &tulip_dc21140_eb_boardsw;
1617 /*
1618 * Thankfully all DC21041's act the same.
1619 */
1620 if (sc->tulip_chipid == TULIP_DC21041)
1621 sc->tulip_boardsw = &tulip_dc21041_boardsw;
1622 tulip_read_srom(sc);
1623 if (tulip_srom_crcok(sc->tulip_rombuf)) {
1624 /*
1625 * SROM CRC is valid therefore it must be in the
1626 * new format.
1627 */
1628 new_srom_fmt = 1;
1629 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
1630 /*
1631 * No checksum is present. See if the SROM id checks out;
1632 * the first 18 bytes should be 0 followed by a 1 followed
1633 * by the number of adapters (which we don't deal with yet).
1634 */
1635 for (idx = 0; idx < 18; idx++) {
1636 if (sc->tulip_rombuf[idx] != 0)
1637 break;
1638 }
1639 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
1640 new_srom_fmt = 2;
1641 }
1642 if (new_srom_fmt) {
1643 /*
1644 * New SROM format. Copy out the Ethernet address.
1645 * If it contains a DE500-XA string, then it must be
1646 * a DE500-XA.
1647 */
1648 bcopy(sc->tulip_rombuf + 20, sc->tulip_hwaddr, 6);
1649 if (bcmp(sc->tulip_rombuf + 29, "DE500-XA", 8) == 0)
1650 sc->tulip_boardsw = &tulip_dc21140_de500_boardsw;
1651 if (bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0)
1652 sc->tulip_boardsw = &tulip_dc21041_de450_boardsw;
1653 if (sc->tulip_boardsw == NULL)
1654 return -6;
1655 sc->tulip_flags |= TULIP_ROMOK;
1656 return 0;
1657 }
1658 }
1659
1660
1661 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
1662 /*
1663 * Some folks don't use the standard ethernet rom format
1664 * but instead just put the address in the first 6 bytes
1665 * of the rom and let the rest be all 0xffs. (Can we say
1666 * ZNYX???)
1667 */
1668 for (idx = 6; idx < 32; idx++) {
1669 if (sc->tulip_rombuf[idx] != 0xFF)
1670 return -4;
1671 }
1672 /*
1673 * Make sure the address is not multicast or locally assigned
1674 * that the OUI is not 00-00-00.
1675 */
1676 if ((sc->tulip_rombuf[0] & 3) != 0)
1677 return -4;
1678 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
1679 && sc->tulip_rombuf[2] == 0)
1680 return -4;
1681 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6);
1682 sc->tulip_flags |= TULIP_ROMOK;
1683 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0
1684 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1
1685 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2
1686 && (sc->tulip_hwaddr[3] & ~3) == 0xF0) {
1687 /*
1688 * Now if the OUI is ZNYX and hwaddr[3] == 0xF0 .. 0xF3
1689 * then it's a ZX314 Master port.
1690 */
1691 sc->tulip_boardsw = &tulip_dc21040_zx314_master_boardsw;
1692 }
1693 return 0;
1694 } else {
1695 /*
1696 * A number of makers of multiport boards (ZNYX and Cogent)
1697 * only put on one address ROM on their DC21040 boards. So
1698 * if the ROM is all zeros and this is a DC21040, look at the
1699 * previous configured boards (as long as they are on the same
1700 * PCI bus and the bus number is non-zero) until we find the
1701 * master board with address ROM. We then use its address ROM
1702 * as the base for this board. (we add our relative board
1703 * to the last byte of its address).
1704 */
1705 if (sc->tulip_chipid == TULIP_DC21040 /* && sc->tulip_bus != 0 XXX */) {
1706 for (idx = 0; idx < 32; idx++) {
1707 if (sc->tulip_rombuf[idx] != 0)
1708 break;
1709 }
1710 if (idx == 32) {
1711 int root_unit;
1712 tulip_softc_t *root_sc = NULL;
1713 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
1714 root_sc = TULIP_UNIT_TO_SOFTC(root_unit);
1715 if (root_sc == NULL || (root_sc->tulip_flags & (TULIP_ROMOK|TULIP_SLAVEDROM)) == TULIP_ROMOK)
1716 break;
1717 root_sc = NULL;
1718 }
1719 if (root_sc != NULL
1720 /* && root_sc->tulip_bus == sc->tulip_bus XXX */) {
1721 bcopy(root_sc->tulip_hwaddr, sc->tulip_hwaddr, 6);
1722 sc->tulip_hwaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
1723 sc->tulip_flags |= TULIP_SLAVEDROM;
1724 if (root_sc->tulip_boardsw->bd_type == TULIP_DC21040_ZX314_MASTER) {
1725 sc->tulip_boardsw = &tulip_dc21040_zx314_slave_boardsw;
1726 /*
1727 * Now for a truly disgusting kludge: all 4 DC21040s on
1728 * the ZX314 share the same INTA line so the mapping
1729 * setup by the BIOS on the PCI bridge is worthless.
1730 * Rather than reprogramming the value in the config
1731 * register, we will handle this internally.
1732 */
1733 sc->tulip_slaves = root_sc->tulip_slaves;
1734 root_sc->tulip_slaves = sc;
1735 }
1736 return 0;
1737 }
1738 }
1739 }
1740 }
1741
1742 /*
1743 * This is the standard DEC address ROM test.
1744 */
1745
1746 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
1747 return -3;
1748
1749 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
1750 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
1751 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
1752 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
1753 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
1754 return -2;
1755
1756 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6);
1757
1758 cksum = *(u_short *) &sc->tulip_hwaddr[0];
1759 cksum *= 2;
1760 if (cksum > 65535) cksum -= 65535;
1761 cksum += *(u_short *) &sc->tulip_hwaddr[2];
1762 if (cksum > 65535) cksum -= 65535;
1763 cksum *= 2;
1764 if (cksum > 65535) cksum -= 65535;
1765 cksum += *(u_short *) &sc->tulip_hwaddr[4];
1766 if (cksum >= 65535) cksum -= 65535;
1767
1768 rom_cksum = *(u_short *) &sc->tulip_rombuf[6];
1769
1770 if (cksum != rom_cksum)
1771 return -1;
1772
1773 /*
1774 * Check for various boards based on OUI. Did I say braindead?
1775 */
1776
1777 if (sc->tulip_chipid == TULIP_DC21140) {
1778 if (sc->tulip_hwaddr[0] == TULIP_OUI_COGENT_0
1779 && sc->tulip_hwaddr[1] == TULIP_OUI_COGENT_1
1780 && sc->tulip_hwaddr[2] == TULIP_OUI_COGENT_2) {
1781 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID)
1782 sc->tulip_boardsw = &tulip_dc21140_cogent_em100_boardsw;
1783 }
1784 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0
1785 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1
1786 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2) {
1787 /* this at least works for the zx342 from Znyx */
1788 sc->tulip_boardsw = &tulip_dc21140_znyx_zx34x_boardsw;
1789 }
1790 }
1791
1792 sc->tulip_flags |= TULIP_ROMOK;
1793 return 0;
1794}
1795
1796static void
1797tulip_addr_filter(
1798 tulip_softc_t * const sc)
1799{
1800 tulip_uint32_t *sp = sc->tulip_setupdata;
1801 struct ether_multistep step;
1802 struct ether_multi *enm;
1803 int i;
1804
1805 sc->tulip_flags &= ~TULIP_WANTHASH;
1806 sc->tulip_flags |= TULIP_WANTSETUP;
1807 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
1808 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
1809 if (sc->tulip_ac.ac_multicnt > 14) {
1810 unsigned hash;
1811 /*
1812 * If we have more than 14 multicasts, we have
1813 * go into hash perfect mode (512 bit multicast
1814 * hash and one perfect hardware).
1815 */
1816
1817 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
1818 hash = tulip_mchash(etherbroadcastaddr);
1819 sp[hash >> 4] |= 1 << (hash & 0xF);
1820 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm);
1821 while (enm != NULL) {
1822 hash = tulip_mchash(enm->enm_addrlo);
1823 sp[hash >> 4] |= 1 << (hash & 0xF);
1824 ETHER_NEXT_MULTI(step, enm);
1825 }
1826 sc->tulip_flags |= TULIP_WANTHASH;
1827 sp[39] = ((u_short *) sc->tulip_ac.ac_enaddr)[0];
1828 sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[1];
1829 sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[2];
1830 } else {
1831 /*
1832 * Else can get perfect filtering for 16 addresses.
1833 */
1834 i = 0;
1835 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm);
1836 for (; enm != NULL; i++) {
1837 *sp++ = ((u_short *) enm->enm_addrlo)[0];
1838 *sp++ = ((u_short *) enm->enm_addrlo)[1];
1839 *sp++ = ((u_short *) enm->enm_addrlo)[2];
1840 ETHER_NEXT_MULTI(step, enm);
1841 }
1842 /*
1843 * Add the broadcast address.
1844 */
1845 i++;
1846 *sp++ = 0xFFFF;
1847 *sp++ = 0xFFFF;
1848 *sp++ = 0xFFFF;
1849 /*
1850 * Pad the rest with our hardware address
1851 */
1852 for (; i < 16; i++) {
1853 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0];
1854 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1];
1855 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2];
1856 }
1857 }
1858}
1859
1860static int
1861tulip_ioctl(
1862 struct ifnet * const ifp,
1863 ioctl_cmd_t cmd,
1864 caddr_t data)
1865{
1866 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit);
1867 struct ifaddr *ifa = (struct ifaddr *)data;
1868 struct ifreq *ifr = (struct ifreq *) data;
1869 int s, error = 0;
1870
1871 s = splimp();
1872
1873 switch (cmd) {
1874 case SIOCSIFADDR: {
1875
1876 ifp->if_flags |= IFF_UP;
1877 switch(ifa->ifa_addr->sa_family) {
1878#ifdef INET
1879 case AF_INET: {
1880 sc->tulip_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
1881 tulip_init(sc);
1882#if defined(__FreeBSD__) || defined(__NetBSD__)
1883 arp_ifinit(&sc->tulip_ac, ifa);
1884#elif defined(__bsdi__)
1885 arpwhohas(&sc->tulip_ac, &IA_SIN(ifa)->sin_addr);
1886#endif
1887 break;
1888 }
1889#endif /* INET */
1890
1891#ifdef NS
1892 /*
1893 * This magic copied from if_is.c; I don't use XNS,
1894 * so I have no way of telling if this actually
1895 * works or not.
1896 */
1897 case AF_NS: {
1898 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
1899 if (ns_nullhost(*ina)) {
1900 ina->x_host = *(union ns_host *)(sc->tulip_ac.ac_enaddr);
1901 } else {
1902 ifp->if_flags &= ~IFF_RUNNING;
1903 bcopy((caddr_t)ina->x_host.c_host,
1904 (caddr_t)sc->tulip_ac.ac_enaddr,
1905 sizeof sc->tulip_ac.ac_enaddr);
1906 }
1907
1908 tulip_init(sc);
1909 break;
1910 }
1911#endif /* NS */
1912
1913 default: {
1914 tulip_init(sc);
1915 break;
1916 }
1917 }
1918 break;
1919 }
1920 case SIOCGIFADDR: {
1921 bcopy((caddr_t) sc->tulip_ac.ac_enaddr,
1922 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
1923 6);
1924 break;
1925 }
1926
1927 case SIOCSIFFLAGS: {
1928 /*
1929 * Changing the connection forces a reset.
1930 */
1931 if (sc->tulip_flags & TULIP_ALTPHYS) {
1932 if ((ifp->if_flags & IFF_ALTPHYS) == 0)
1933 tulip_reset(sc);
1934 } else {
1935 if (ifp->if_flags & IFF_ALTPHYS)
1936 tulip_reset(sc);
1937 }
1938 tulip_init(sc);
1939 break;
1940 }
1941
1942 case SIOCADDMULTI:
1943 case SIOCDELMULTI: {
1944 /*
1945 * Update multicast listeners
1946 */
1947 if (cmd == SIOCADDMULTI)
1948 error = ether_addmulti(ifr, &sc->tulip_ac);
1949 else
1950 error = ether_delmulti(ifr, &sc->tulip_ac);
1951
1952 if (error == ENETRESET) {
1953 tulip_addr_filter(sc); /* reset multicast filtering */
1954 tulip_init(sc);
1955 error = 0;
1956 }
1957 break;
1958 }
1959#if defined(SIOCSIFMTU)
1960#if !defined(ifr_mtu)
1961#define ifr_mtu ifr_metric
1962#endif
1963 case SIOCSIFMTU:
1964 /*
1965 * Set the interface MTU.
1966 */
1967 if (ifr->ifr_mtu > ETHERMTU) {
1968 error = EINVAL;
1969 break;
1970 }
1971 ifp->if_mtu = ifr->ifr_mtu;
1972 break;
1973#endif
1974
1975 default: {
1976 error = EINVAL;
1977 break;
1978 }
1979 }
1980
1981 splx(s);
1982 return error;
1983}
1984
1985static void
1986tulip_attach(
1987 tulip_softc_t * const sc)
1988{
1989 struct ifnet * const ifp = &sc->tulip_if;
1990
1991 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
1992 ifp->if_ioctl = tulip_ioctl;
1993 ifp->if_output = ether_output;
1994 ifp->if_start = tulip_start;
1995
1996#ifdef __FreeBSD__
1997 printf("%s%d", sc->tulip_name, sc->tulip_unit);
1998#endif
1999 printf(": %s%s pass %d.%d Ethernet address %s\n",
2000 sc->tulip_boardsw->bd_description,
2001 tulip_chipdescs[sc->tulip_chipid],
2002 (sc->tulip_revinfo & 0xF0) >> 4,
2003 sc->tulip_revinfo & 0x0F,
2004 ether_sprintf(sc->tulip_hwaddr));
2005
2006 if ((*sc->tulip_boardsw->bd_media_probe)(sc)) {
2007 ifp->if_flags |= IFF_ALTPHYS;
2008 } else {
2009 sc->tulip_flags |= TULIP_ALTPHYS;
2010 }
2011
2012 tulip_reset(sc);
2013
2014 if_attach(ifp);
2015#if defined(__NetBSD__)
2016 ether_ifattach(ifp);
2017#endif
2018
2019#if NBPFILTER > 0
2020 bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
2021#endif
2022}
2023
2024static void
2025tulip_initcsrs(
2026 tulip_softc_t * const sc,
2027 tulip_csrptr_t csr_base,
2028 size_t csr_size)
2029{
2030 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
2031 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
2032 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2033 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
2034 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
2035 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
2036 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
2037 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
2038 sc->tulip_csrs.csr_missed_frame = csr_base + 8 * csr_size;
2039 if (sc->tulip_chipid == TULIP_DC21040) {
2040 sc->tulip_csrs.csr_enetrom = csr_base + 9 * csr_size;
2041 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size;
2042 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size;
2043 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2044 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2045 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2046 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2047#if defined(TULIP_EISA)
2048 } else if (sc->tulip_chipid == TULIP_DE425) {
2049 sc->tulip_csrs.csr_enetrom = csr_base + DE425_ENETROM_OFFSET;
2050 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size;
2051 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size;
2052 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2053 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2054 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2055 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2056#endif /* TULIP_EISA */
2057 } else if (sc->tulip_chipid == TULIP_DC21140) {
2058 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size;
2059 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size;
2060 sc->tulip_csrs.csr_gp = csr_base + 12 * csr_size;
2061 sc->tulip_csrs.csr_watchdog = csr_base + 15 * csr_size;
2062 } else if (sc->tulip_chipid == TULIP_DC21041) {
2063 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size;
2064 sc->tulip_csrs.csr_bootrom = csr_base + 10 * csr_size;
2065 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size;
2066 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2067 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2068 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2069 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2070 }
2071}
2072
2073static void
2074tulip_initring(
2075 tulip_softc_t * const sc,
2076 tulip_ringinfo_t * const ri,
2077 tulip_desc_t *descs,
2078 int ndescs)
2079{
2080 ri->ri_max = ndescs;
2081 ri->ri_first = descs;
2082 ri->ri_last = ri->ri_first + ri->ri_max;
2083 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
2084 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
2085}
2086
2087/*
2088 * This is the PCI configuration support. Since the DC21040 is available
2089 * on both EISA and PCI boards, one must be careful in how defines the
2090 * DC21040 in the config file.
2091 */
2092
2093#define PCI_CFID 0x00 /* Configuration ID */
2094#define PCI_CFCS 0x04 /* Configurtion Command/Status */
2095#define PCI_CFRV 0x08 /* Configuration Revision */
2096#define PCI_CFLT 0x0c /* Configuration Latency Timer */
2097#define PCI_CBIO 0x10 /* Configuration Base IO Address */
2098#define PCI_CBMA 0x14 /* Configuration Base Memory Address */
2099#define PCI_CFIT 0x3c /* Configuration Interrupt */
2100#define PCI_CFDA 0x40 /* Configuration Driver Area */
2101
2102#if defined(TULIP_EISA)
2103static const int tulip_eisa_irqs[4] = { IRQ5, IRQ9, IRQ10, IRQ11 };
2104#endif
2105
2106#if defined(__FreeBSD__)
2107
2108#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit
2109
2110static int
2111tulip_pci_shutdown(
2112 struct kern_devconf * const kdc,
2113 int force)
2114{
2115 if (kdc->kdc_unit < NDE) {
2116 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit);
2117 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2118 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2119 33MHz that comes to two microseconds but wait a
2120 bit longer anyways) */
2121 }
2122 (void) dev_detach(kdc);
2123 return 0;
2124}
2125
2126static char*
2127tulip_pci_probe(
2128 pcici_t config_id,
2129 pcidi_t device_id)
2130{
2131 if (PCI_VENDORID(device_id) != DEC_VENDORID)
2132 return NULL;
2133 if (PCI_CHIPID(device_id) == DC21040_CHIPID)
2134 return "Digital DC21040 Ethernet";
2135 if (PCI_CHIPID(device_id) == DC21041_CHIPID)
2136 return "Digital DC21041 Ethernet";
2137 if (PCI_CHIPID(device_id) == DC21140_CHIPID)
2138 return "Digital DC21140 Fast Ethernet";
2139 return NULL;
2140}
2141
2142static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2143static u_long tulip_pci_count;
2144
2145static struct pci_device dedevice = {
2146 "de",
2147 tulip_pci_probe,
2148 tulip_pci_attach,
2149 &tulip_pci_count,
2150 tulip_pci_shutdown,
2151};
2152
2153DATA_SET (pcidevice_set, dedevice);
2154#endif /* __FreeBSD__ */
2155
2156#if defined(__bsdi__)
2157#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux
2158
2159static void
2160tulip_shutdown(
2161 void *arg)
2162{
2163 tulip_softc_t * const sc = (tulip_softc_t *) arg;
2164 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2165 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2166 33MHz that comes to two microseconds but wait a
2167 bit longer anyways) */
2168}
2169
2170static int
2171tulip_pci_match(
2172 pci_devaddr_t *pa)
2173{
2174 int irq;
2175 unsigned id;
2176
2177 id = pci_inl(pa, PCI_VENDOR_ID);
2178 if (PCI_VENDORID(id) != DEC_VENDORID)
2179 return 0;
2180 id = PCI_CHIPID(id);
2181 if (id != DC21040_CHIPID && id != DC21041_CHIPID && id != DC21140_CHIPID)
2182 return 0;
2183 irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
2184 if (irq == 0 || irq >= 16) {
2185 printf("de?: invalid IRQ %d; skipping\n", irq);
2186 return 0;
2187 }
2188 return 1;
2189}
2190
2191static int
2192tulip_probe(
2193 struct device *parent,
2194 struct cfdata *cf,
2195 void *aux)
2196{
2197 struct isa_attach_args * const ia = (struct isa_attach_args *) aux;
2198 unsigned irq, slot;
2199 pci_devaddr_t *pa;
2200
2201#if defined(TULIP_EISA)
2202 if ((slot = eisa_match(cf, ia)) != 0) {
2203 unsigned tmp;
2204 ia->ia_iobase = slot << 12;
2205 ia->ia_iosize = EISA_NPORT;
2206 eisa_slotalloc(slot);
2207 tmp = inb(ia->ia_iobase + DE425_CFG0);
2208 irq = tulip_eisa_irqs[(tmp >> 1) & 0x03];
2209 /*
2210 * Until BSD/OS likes level interrupts, force
2211 * the DE425 into edge-triggered mode.
2212 */
2213 if ((tmp & 1) == 0)
2214 outb(ia->ia_iobase + DE425_CFG0, tmp | 1);
2215 /*
2216 * CBIO needs to map to the EISA slot
2217 * enable I/O access and Master
2218 */
2219 outl(ia->ia_iobase + DE425_CBIO, ia->ia_iobase);
2220 outl(ia->ia_iobase + DE425_CFCS, 5 | inl(ia->ia_iobase + DE425_CFCS));
2221 ia->ia_aux = NULL;
2222 } else {
2223#endif /* TULIP_EISA */
2224 pa = pci_scan(tulip_pci_match);
2225 if (pa == NULL)
2226 return 0;
2227
2228 irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF));
2229
2230 /* Get the base address; assume the BIOS set it up correctly */
2231#if defined(TULIP_IOMAPPED)
2232 ia->ia_maddr = NULL;
2233 ia->ia_msize = 0;
2234 ia->ia_iobase = pci_inl(pa, PCI_CBIO) & ~7;
2235 pci_outl(pa, PCI_CBIO, 0xFFFFFFFF);
2236 ia->ia_iosize = ((~pci_inl(pa, PCI_CBIO)) | 7) + 1;
2237 pci_outl(pa, PCI_CBIO, (int) ia->ia_iobase);
2238
2239 /* Disable memory space access */
2240 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~2);
2241#else
2242 ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7);
2243 pci_outl(pa, PCI_CBMA, 0xFFFFFFFF);
2244 ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1;
2245 pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr);
2246 ia->ia_iobase = 0;
2247 ia->ia_iosize = 0;
2248
2249 /* Disable I/O space access */
2250 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1);
2251#endif /* TULIP_IOMAPPED */
2252
2253 ia->ia_aux = (void *) pa;
2254#if defined(TULIP_EISA)
2255 }
2256#endif
2257
2258 /* PCI bus masters don't use host DMA channels */
2259 ia->ia_drq = DRQNONE;
2260
2261 if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
2262 printf("de%d: error: desired IRQ of %d does not match device's actual IRQ of %d,\n",
2263 cf->cf_unit,
2264 ffs(ia->ia_irq) - 1, ffs(irq) - 1);
2265 return 0;
2266 }
2267 if (ia->ia_irq == IRQUNK && (ia->ia_irq = isa_irqalloc(irq)) == 0) {
2268 printf("de%d: warning: IRQ %d is shared\n", cf->cf_unit, ffs(irq) - 1);
2269 ia->ia_irq = irq;
2270 }
2271 return 1;
2272}
2273
2274static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2275
2276#if defined(TULIP_EISA)
2277static char *tulip_eisa_ids[] = {
2278 "DEC4250",
2279 NULL
2280};
2281#endif
2282
2283struct cfdriver decd = {
2284 0, "de", tulip_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t),
2285#if defined(TULIP_EISA)
2286 tulip_eisa_ids
2287#endif
2288};
2289
2290#endif /* __bsdi__ */
2291
2292#if defined(__NetBSD__)
2293#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux
2294
2295static void
2296tulip_pci_shutdown(
2297 void *arg)
2298{
2299 tulip_softc_t * const sc = (tulip_softc_t *) arg;
2300 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2301 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2302 33MHz that comes to two microseconds but wait a
2303 bit longer anyways) */
2304}
2305
2306static int
2307tulip_pci_probe(
2308 struct device *parent,
2309 void *match,
2310 void *aux)
2311{
2312 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
2313
2314 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
2315 return 0;
2316 if (PCI_CHIPID(pa->pa_id) == DC21040_CHIPID
2317 || PCI_CHIPID(pa->pa_id) == DC21041_CHIPID
2318 || PCI_CHIPID(pa->pa_id) == DC21140_CHIPID)
2319 return 1;
2320
2321 return 0;
2322}
2323
2324static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2325
2326struct cfdriver decd = {
2327 0, "de", tulip_pci_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t)
2328};
2329
2330#endif /* __NetBSD__ */
2331
2332static void
2333tulip_pci_attach(
2334 TULIP_PCI_ATTACH_ARGS)
2335{
2336#if defined(__FreeBSD__)
2337 tulip_softc_t *sc;
2338#endif
2339#if defined(__bsdi__)
2340 tulip_softc_t * const sc = (tulip_softc_t *) self;
2341 struct isa_attach_args * const ia = (struct isa_attach_args *) aux;
2342 pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux;
2343 int unit = sc->tulip_dev.dv_unit;
2344#endif
2345#if defined(__NetBSD__)
2346 tulip_softc_t * const sc = (tulip_softc_t *) self;
2347 struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
2348 int unit = sc->tulip_dev.dv_unit;
2349#endif
2350 int retval, idx, revinfo, id;
2351#if !defined(TULIP_IOMAPPED) && !defined(__bsdi__)
2352 vm_offset_t pa_csrs;
2353#endif
2354 unsigned csroffset = TULIP_PCI_CSROFFSET;
2355 unsigned csrsize = TULIP_PCI_CSRSIZE;
2356 tulip_csrptr_t csr_base;
2357 tulip_desc_t *rxdescs, *txdescs;
2358 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
2359
2360#if defined(__FreeBSD__)
2361 if (unit >= NDE) {
2362 printf("de%d: not configured; kernel is built for only %d device%s.\n",
2363 unit, NDE, NDE == 1 ? "" : "s");
2364 return;
2365 }
2366#endif
2367
2368#if defined(__FreeBSD__)
2369 revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF;
2370 id = pci_conf_read(config_id, PCI_CFID);
2371#endif
2372#if defined(__bsdi__)
2373 if (pa != NULL) {
2374 revinfo = pci_inl(pa, PCI_CFRV) & 0xFF;
2375 id = pci_inl(pa, PCI_CFID);
2376#if defined(TULIP_EISA)
2377 } else {
2378 revinfo = inl(ia->ia_iobase + DE425_CFRV) & 0xFF;
2379 csroffset = TULIP_EISA_CSROFFSET;
2380 csrsize = TULIP_EISA_CSRSIZE;
2381 chipid = TULIP_DE425;
2382#endif
2383 }
2384#endif
2385#if defined(__NetBSD__)
2386 revinfo = pci_conf_read(pa->pa_tag, PCI_CFRV) & 0xFF;
2387 id = pa->pa_id;
2388#endif
2389
2390 if (PCI_VENDORID(id) == DEC_VENDORID) {
2391 if (PCI_CHIPID(id) == DC21040_CHIPID) chipid = TULIP_DC21040;
2392 else if (PCI_CHIPID(id) == DC21140_CHIPID) chipid = TULIP_DC21140;
2393 else if (PCI_CHIPID(id) == DC21041_CHIPID) chipid = TULIP_DC21041;
2394 }
2395 if (chipid == TULIP_CHIPID_UNKNOWN)
2396 return;
2397
2398 if ((chipid == TULIP_DC21040 || chipid == TULIP_DE425) && revinfo < 0x20) {
2399#ifdef __FreeBSD__
2400 printf("de%d", unit);
2401#endif
2402 printf(": not configured; DC21040 pass 2.0 required (%d.%d found)\n",
2403 revinfo >> 4, revinfo & 0x0f);
2404 return;
2405 } else if (chipid == TULIP_DC21140 && revinfo < 0x11) {
2406#ifdef __FreeBSD__
2407 printf("de%d", unit);
2408#endif
2409 printf(": not configured; DC21140 pass 1.1 required (%d.%d found)\n",
2410 revinfo >> 4, revinfo & 0x0f);
2411 return;
2412 }
2413
2414#if defined(__FreeBSD__)
2415 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
2416 if (sc == NULL)
2417 return;
2418 bzero(sc, sizeof(*sc)); /* Zero out the softc*/
2419#endif
2420
2421 rxdescs = (tulip_desc_t *)
2422 malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
2423 if (rxdescs == NULL) {
2424#if defined(__FreeBSD__)
2425 free((caddr_t) sc, M_DEVBUF);
2426#endif
2427 return;
2428 }
2429
2430 txdescs = (tulip_desc_t *)
2431 malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
2432 if (txdescs == NULL) {
2433 free((caddr_t) rxdescs, M_DEVBUF);
2434#if defined(__FreeBSD__)
2435 free((caddr_t) sc, M_DEVBUF);
2436#endif
2437 return;
2438 }
2439
2440 sc->tulip_chipid = chipid;
2441 sc->tulip_unit = unit;
2442 sc->tulip_name = "de";
2443 sc->tulip_revinfo = revinfo;
2444#if defined(__FreeBSD__)
2445#if defined(TULIP_IOMAPPED)
2446 retval = pci_map_port(config_id, PCI_CBIO, &csr_base);
2447#else
2448 retval = pci_map_mem(config_id, PCI_CBMA, (vm_offset_t *) &csr_base, &pa_csrs);
2449#endif
2450 if (!retval) {
2451 free((caddr_t) txdescs, M_DEVBUF);
2452 free((caddr_t) rxdescs, M_DEVBUF);
2453 free((caddr_t) sc, M_DEVBUF);
2454 return;
2455 }
2456 tulips[unit] = sc;
2457#endif /* __FreeBSD__ */
2458
2459#if defined(__bsdi__)
2460#if defined(TULIP_IOMAPPED)
2461 csr_base = ia->ia_iobase;
2462#else
2463 csr_base = (vm_offset_t) mapphys((vm_offset_t) ia->ia_maddr, ia->ia_msize);
2464#endif
2465#endif /* __bsdi__ */
2466
2467#if defined(__NetBSD__)
2468#if defined(TULIP_IOMAPPED)
2469 retval = pci_map_io(pa->pa_tag, PCI_CBIO, &csr_base);
2470#else
2471 retval = pci_map_mem(pa->pa_tag, PCI_CBMA, (vm_offset_t *) &csr_base, &pa_csrs);
2472#endif
2473 if (retval) {
2474 free((caddr_t) txdescs, M_DEVBUF);
2475 free((caddr_t) rxdescs, M_DEVBUF);
2476 return;
2477 }
2478#endif /* __NetBSD__ */
2479
2480 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
2481 tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS);
2482 tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS);
2483 if ((retval = tulip_read_macaddr(sc)) < 0) {
2484#ifdef __FreeBSD__
2485 printf("%s%d", sc->tulip_name, sc->tulip_unit);
2486#endif
2487 printf(": can't read ENET ROM (why=%d) (", retval);
2488 for (idx = 0; idx < 32; idx++)
2489 printf("%02x", sc->tulip_rombuf[idx]);
2490 printf("\n");
2491 printf("%s%d: %s%s pass %d.%d Ethernet address %s\n",
2492 sc->tulip_name, sc->tulip_unit,
2493 (sc->tulip_boardsw != NULL ? sc->tulip_boardsw->bd_description : ""),
2494 tulip_chipdescs[sc->tulip_chipid],
2495 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F,
2496 "unknown");
2497 } else {
2498 /*
2499 * Make sure there won't be any interrupts or such...
2500 */
2501 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2502 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2503 33MHz that comes to two microseconds but wait a
2504 bit longer anyways) */
2505#if defined(__NetBSD__)
2506 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2507 sc->tulip_ih = pci_map_int(pa->pa_tag, PCI_IPL_NET, tulip_intr, sc);
2508 if (sc->tulip_ih == NULL) {
2509 printf("%s%d: couldn't map interrupt\n",
2510 sc->tulip_name, sc->tulip_unit);
2511 return;
2512 }
2513#if defined(__i386__)
2514 /* gross but netbsd won't print the irq otherwise */
2515 printf(" irq %d", ((struct intrhand *) sc->tulip_ih)->ih_irq);
2516#endif
2517 }
2518 sc->tulip_ats = shutdownhook_establish(tulip_pci_shutdown, sc);
2519 if (sc->tulip_ats == NULL)
2520 printf("%s%d: warning: couldn't establish shutdown hook\n",
2521 sc->tulip_name, sc->tulip_unit);
2522#endif
2523#if defined(__FreeBSD__)
2524 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2525 if (!pci_map_int(config_id, tulip_intr, (void*) sc, &net_imask)) {
2526 printf("%s%d: couldn't map interrupt\n",
2527 sc->tulip_name, sc->tulip_unit);
2528 return;
2529 }
2530 }
2531#endif
2532#if defined(__bsdi__)
2533 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2534 isa_establish(&sc->tulip_id, &sc->tulip_dev);
2535
2536 sc->tulip_ih.ih_fun = tulip_intr;
2537 sc->tulip_ih.ih_arg = (void *)sc;
2538 intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET);
2539 }
2540
2541 sc->tulip_ats.func = tulip_shutdown;
2542 sc->tulip_ats.arg = (void *) sc;
2543 atshutdown(&sc->tulip_ats, ATSH_ADD);
2544#endif
2545 tulip_reset(sc);
2546 tulip_attach(sc);
2547 }
2548}
2549#endif /* NDE > 0 */
697 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_GPTIMEOUT
698 |TULIP_STS_ABNRMLINTR|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
699 if (sc->tulip_if.if_flags & IFF_ALTPHYS) {
700 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) {
701 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
702 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE);
703 sc->tulip_flags |= TULIP_ALTPHYS|TULIP_WANTRXACT;
704 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
705 }
706 } else {
707 if (sc->tulip_flags & TULIP_ALTPHYS) {
708 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
709 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE|TULIP_ALTPHYS);
710 sc->tulip_flags |= TULIP_WANTRXACT;
711 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
712 }
713 }
714
715 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) {
716 if (sc->tulip_media == TULIP_MEDIA_10BASET) {
717 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
718 } else if (sc->tulip_media == TULIP_MEDIA_BNC) {
719 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
720 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
721 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
722 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
723 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
724 return;
725 } else if (sc->tulip_media == TULIP_MEDIA_AUI) {
726 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
727 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
728 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
729 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
730 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
731 return;
732 }
733
734 switch (sc->tulip_probe_state) {
735 case TULIP_PROBE_INACTIVE: {
736 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
737 sc->tulip_if.if_flags |= IFF_OACTIVE;
738 sc->tulip_gpticks = 200;
739 sc->tulip_probe_state = TULIP_PROBE_10BASET;
740 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
741 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET);
742 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET);
743 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET);
744 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */
745 break;
746 }
747 case TULIP_PROBE_10BASET: {
748 if (--sc->tulip_gpticks > 0) {
749 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
750 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */
751 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
752 break;
753 }
754 }
755 sc->tulip_gpticks = 4;
756 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) {
757 sc->tulip_probe_state = TULIP_PROBE_BNC;
758 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
759 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
760 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
761 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
762 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
763 } else {
764 sc->tulip_probe_state = TULIP_PROBE_AUI;
765 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
766 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
767 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
768 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
769 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
770 }
771 break;
772 }
773 case TULIP_PROBE_BNC:
774 case TULIP_PROBE_AUI: {
775 if (sc->tulip_flags & TULIP_TXPROBE_OK) {
776 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
777 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE);
778 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */
779 if ((sc->tulip_probe_state == TULIP_PROBE_AUI
780 && sc->tulip_media != TULIP_MEDIA_AUI)
781 || (sc->tulip_probe_state == TULIP_PROBE_BNC
782 && sc->tulip_media != TULIP_MEDIA_AUI)) {
783 printf("%s%d: enabling %s port\n",
784 sc->tulip_if.if_name, sc->tulip_if.if_unit,
785 sc->tulip_probe_state == TULIP_PROBE_BNC
786 ? "Thinwire/BNC" : "AUI");
787 if (sc->tulip_probe_state == TULIP_PROBE_AUI)
788 sc->tulip_media = TULIP_MEDIA_AUI;
789 else if (sc->tulip_probe_state == TULIP_PROBE_BNC)
790 sc->tulip_media = TULIP_MEDIA_BNC;
791 }
792 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
793 break;
794 }
795 if ((sc->tulip_flags & TULIP_WANTRXACT) == 0
796 || (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_RXACTIVITY)) {
797 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) {
798 struct mbuf *m;
799 /*
800 * Before we are sure this is the right media we need
801 * to send a small packet to make sure there's carrier.
802 * Strangely, BNC and AUI will 'see" receive data if
803 * either is connected so the transmit is the only way
804 * to verify the connectivity.
805 */
806 MGETHDR(m, M_DONTWAIT, MT_DATA);
807 if (m == NULL) {
808 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
809 break;
810 }
811 /*
812 * Construct a LLC TEST message which will point to ourselves.
813 */
814 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
815 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_shost, 6);
816 mtod(m, struct ether_header *)->ether_type = htons(3);
817 mtod(m, unsigned char *)[14] = 0;
818 mtod(m, unsigned char *)[15] = 0;
819 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
820 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
821 /*
822 * send it!
823 */
824 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
825 sc->tulip_flags &= ~TULIP_TXPROBE_OK;
826 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
827 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
828 IF_PREPEND(&sc->tulip_if.if_snd, m);
829 tulip_start(&sc->tulip_if);
830 break;
831 }
832 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
833 }
834 /*
835 * Take 2 passes through before deciding to not
836 * wait for receive activity. Then take another
837 * two passes before spitting out a warning.
838 */
839 if (sc->tulip_gpticks > 0 && --sc->tulip_gpticks == 0) {
840 if (sc->tulip_flags & TULIP_WANTRXACT) {
841 sc->tulip_flags &= ~TULIP_WANTRXACT;
842 sc->tulip_gpticks = 4;
843 } else {
844 printf("%s%d: autosense failed: cable problem?\n",
845 sc->tulip_name, sc->tulip_unit);
846 }
847 }
848 /*
849 * Since this media failed to probe, try the other one.
850 */
851 if (sc->tulip_probe_state == TULIP_PROBE_AUI) {
852 sc->tulip_probe_state = TULIP_PROBE_BNC;
853 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
854 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC);
855 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC);
856 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC);
857 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
858 } else {
859 sc->tulip_probe_state = TULIP_PROBE_AUI;
860 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
861 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI);
862 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI);
863 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI);
864 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */
865 }
866 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
867 break;
868 }
869 }
870 } else {
871 /*
872 * If the link has passed LinkPass, 10baseT is the
873 * proper media to use.
874 */
875 if (sc->tulip_media != TULIP_MEDIA_10BASET)
876 printf("%s%d: enabling 10baseT/UTP port\n",
877 sc->tulip_if.if_name, sc->tulip_if.if_unit);
878 if (sc->tulip_media != TULIP_MEDIA_10BASET
879 || (sc->tulip_flags & TULIP_INRESET)) {
880 sc->tulip_media = TULIP_MEDIA_10BASET;
881 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
882 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET);
883 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET);
884 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET);
885 }
886 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */
887 sc->tulip_gpticks = 1;
888 sc->tulip_probe_state = TULIP_PROBE_10BASET;
889 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT;
890 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
891 }
892 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
893}
894
895static const tulip_boardsw_t tulip_dc21041_boardsw = {
896 TULIP_DC21041_GENERIC,
897 "",
898 tulip_dc21041_media_probe,
899 tulip_dc21041_media_select
900};
901
902static const tulip_boardsw_t tulip_dc21041_de450_boardsw = {
903 TULIP_DC21041_DE450,
904 "Digital DE450 ",
905 tulip_dc21041_media_probe,
906 tulip_dc21041_media_select
907};
908
909static void
910tulip_reset(
911 tulip_softc_t * const sc)
912{
913 tulip_ringinfo_t *ri;
914 tulip_desc_t *di;
915
916 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
917 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
918 33MHz that comes to two microseconds but wait a
919 bit longer anyways) */
920
921 sc->tulip_flags |= TULIP_INRESET;
922 sc->tulip_intrmask = 0;
923 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
924
925 TULIP_WRITE_CSR(sc, csr_txlist, vtophys(&sc->tulip_txinfo.ri_first[0]));
926 TULIP_WRITE_CSR(sc, csr_rxlist, vtophys(&sc->tulip_rxinfo.ri_first[0]));
927 TULIP_WRITE_CSR(sc, csr_busmode,
928 (1 << (TULIP_BURSTSIZE(sc->tulip_unit) + 8))
929 |TULIP_BUSMODE_CACHE_ALIGN8
930 |(BYTE_ORDER != LITTLE_ENDIAN ? TULIP_BUSMODE_BIGENDIAN : 0));
931
932 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
933 /*
934 * Free all the mbufs that were on the transmit ring.
935 */
936 for (;;) {
937 struct mbuf *m;
938 IF_DEQUEUE(&sc->tulip_txq, m);
939 if (m == NULL)
940 break;
941 m_freem(m);
942 }
943
944 ri = &sc->tulip_txinfo;
945 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
946 ri->ri_free = ri->ri_max;
947 for (di = ri->ri_first; di < ri->ri_last; di++)
948 di->d_status = 0;
949
950 /*
951 * We need to collect all the mbufs were on the
952 * receive ring before we reinit it either to put
953 * them back on or to know if we have to allocate
954 * more.
955 */
956 ri = &sc->tulip_rxinfo;
957 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
958 ri->ri_free = ri->ri_max;
959 for (di = ri->ri_first; di < ri->ri_last; di++) {
960 di->d_status = 0;
961 di->d_length1 = 0; di->d_addr1 = 0;
962 di->d_length2 = 0; di->d_addr2 = 0;
963 }
964 for (;;) {
965 struct mbuf *m;
966 IF_DEQUEUE(&sc->tulip_rxq, m);
967 if (m == NULL)
968 break;
969 m_freem(m);
970 }
971
972 (*sc->tulip_boardsw->bd_media_select)(sc);
973
974 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
975 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
976 |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED;
977 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET);
978 tulip_addr_filter(sc);
979}
980
981static void
982tulip_init(
983 tulip_softc_t * const sc)
984{
985 if (sc->tulip_if.if_flags & IFF_UP) {
986 sc->tulip_if.if_flags |= IFF_RUNNING;
987 if (sc->tulip_if.if_flags & IFF_PROMISC) {
988 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
989 } else {
990 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
991 if (sc->tulip_if.if_flags & IFF_ALLMULTI) {
992 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
993 } else {
994 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
995 }
996 }
997 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
998 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) {
999 tulip_rx_intr(sc);
1000 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
1001 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
1002 } else {
1003 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
1004 tulip_start(&sc->tulip_if);
1005 }
1006 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
1007 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1008 } else {
1009 tulip_reset(sc);
1010 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1011 }
1012}
1013
1014
1015#if TULIP_CHECK_RXCRC
1016static unsigned
1017tulip_crc32(
1018 u_char *addr,
1019 int len)
1020{
1021 unsigned int crc = 0xFFFFFFFF;
1022 static unsigned int crctbl[256];
1023 int idx;
1024 static int done;
1025 /*
1026 * initialize the multicast address CRC table
1027 */
1028 for (idx = 0; !done && idx < 256; idx++) {
1029 unsigned int tmp = idx;
1030 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1031 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1032 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1033 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1034 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1035 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1036 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1037 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */
1038 crctbl[idx] = tmp;
1039 }
1040 done = 1;
1041
1042 while (len-- > 0)
1043 crc = (crc >> 8) ^ crctbl[*addr++] ^ crctbl[crc & 0xFF];
1044
1045 return crc;
1046}
1047#endif
1048
1049static void
1050tulip_rx_intr(
1051 tulip_softc_t * const sc)
1052{
1053 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
1054 struct ifnet * const ifp = &sc->tulip_if;
1055
1056 for (;;) {
1057 struct ether_header eh;
1058 tulip_desc_t *eop = ri->ri_nextin;
1059 int total_len = 0;
1060 struct mbuf *m = NULL;
1061 int accept = 0;
1062
1063 if (sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
1064 goto queue_mbuf;
1065
1066 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
1067 break;
1068
1069 total_len = ((eop->d_status >> 16) & 0x7FF) - 4;
1070 IF_DEQUEUE(&sc->tulip_rxq, m);
1071 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0) {
1072
1073#if TULIP_CHECK_RXCRC
1074 unsigned crc = tulip_crc32(mtod(m, unsigned char *), total_len);
1075 if (~crc != *((unsigned *) &bufaddr[total_len])) {
1076 printf("%s%d: bad rx crc: %08x [rx] != %08x\n",
1077 sc->tulip_name, sc->tulip_unit,
1078 *((unsigned *) &bufaddr[total_len]), ~crc);
1079 goto next;
1080 }
1081#endif
1082 eh = *mtod(m, struct ether_header *);
1083#if NBPFILTER > 0
1084 if (sc->tulip_bpf != NULL)
1085 bpf_tap(sc->tulip_bpf, mtod(m, caddr_t), total_len);
1086#endif
1087 if ((sc->tulip_if.if_flags & IFF_PROMISC)
1088 && (eh.ether_dhost[0] & 1) == 0
1089 && !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr))
1090 goto next;
1091 accept = 1;
1092 total_len -= sizeof(struct ether_header);
1093 } else {
1094 ifp->if_ierrors++;
1095 }
1096 next:
1097 ifp->if_ipackets++;
1098 if (++ri->ri_nextin == ri->ri_last)
1099 ri->ri_nextin = ri->ri_first;
1100 queue_mbuf:
1101 /*
1102 * Either we are priming the TULIP with mbufs (m == NULL)
1103 * or we are about to accept an mbuf for the upper layers
1104 * so we need to allocate an mbuf to replace it. If we
1105 * can't replace, then count it as an input error and reuse
1106 * the mbuf.
1107 */
1108 if (accept || m == NULL) {
1109 struct mbuf *m0;
1110 MGETHDR(m0, M_DONTWAIT, MT_DATA);
1111 if (m0 != NULL) {
1112#if defined(TULIP_COPY_RXDATA)
1113 if (!accept || total_len >= MHLEN) {
1114#endif
1115 MCLGET(m0, M_DONTWAIT);
1116 if ((m0->m_flags & M_EXT) == 0) {
1117 m_freem(m0);
1118 m0 = NULL;
1119 }
1120#if defined(TULIP_COPY_RXDATA)
1121 }
1122#endif
1123 }
1124 if (accept) {
1125 if (m0 != NULL) {
1126#if defined(__bsdi__)
1127 eh.ether_type = ntohs(eh.ether_type);
1128#endif
1129#if !defined(TULIP_COPY_RXDATA)
1130 m->m_data += sizeof(struct ether_header);
1131 m->m_len = m->m_pkthdr.len = total_len;
1132 m->m_pkthdr.rcvif = ifp;
1133 ether_input(ifp, &eh, m);
1134 m = m0;
1135#else
1136 bcopy(mtod(m, caddr_t) + sizeof(struct ether_header),
1137 mtod(m0, caddr_t), total_len);
1138 m0->m_len = m0->m_pkthdr.len = total_len;
1139 m0->m_pkthdr.rcvif = ifp;
1140 ether_input(ifp, &eh, m0);
1141#endif
1142 } else {
1143 ifp->if_ierrors++;
1144 }
1145 } else {
1146 m = m0;
1147 }
1148 }
1149 if (m == NULL)
1150 break;
1151 /*
1152 * Now give the buffer to the TULIP and save in our
1153 * receive queue.
1154 */
1155 ri->ri_nextout->d_length1 = MCLBYTES - 4;
1156 ri->ri_nextout->d_addr1 = vtophys(mtod(m, caddr_t));
1157 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1158 if (++ri->ri_nextout == ri->ri_last)
1159 ri->ri_nextout = ri->ri_first;
1160 IF_ENQUEUE(&sc->tulip_rxq, m);
1161 }
1162}
1163
1164static int
1165tulip_tx_intr(
1166 tulip_softc_t * const sc)
1167{
1168 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
1169 struct mbuf *m;
1170 int xmits = 0;
1171
1172 while (ri->ri_free < ri->ri_max) {
1173 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
1174 break;
1175
1176 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) {
1177 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) {
1178 /*
1179 * We've just finished processing a setup packet.
1180 * Mark that we can finished it. If there's not
1181 * another pending, startup the TULIP receiver.
1182 * Make sure we ack the RXSTOPPED so we won't get
1183 * an abormal interrupt indication.
1184 */
1185 sc->tulip_flags &= ~TULIP_DOINGSETUP;
1186 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) {
1187 tulip_rx_intr(sc);
1188 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
1189 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
1190 TULIP_WRITE_CSR(sc, csr_status, TULIP_STS_RXSTOPPED);
1191 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1192 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask);
1193 }
1194 } else {
1195 IF_DEQUEUE(&sc->tulip_txq, m);
1196 m_freem(m);
1197 xmits++;
1198 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
1199 if ((ri->ri_nextin->d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) == 0)
1200 sc->tulip_flags |= TULIP_TXPROBE_OK;
1201 (*sc->tulip_boardsw->bd_media_select)(sc);
1202 } else {
1203 sc->tulip_if.if_collisions +=
1204 (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK)
1205 >> TULIP_DSTS_V_TxCOLLCNT;
1206 if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM)
1207 sc->tulip_if.if_oerrors++;
1208 }
1209 }
1210 }
1211
1212 if (++ri->ri_nextin == ri->ri_last)
1213 ri->ri_nextin = ri->ri_first;
1214 ri->ri_free++;
1215 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
1216 }
1217 sc->tulip_if.if_opackets += xmits;
1218 return xmits;
1219}
1220
1221static ifnet_ret_t
1222tulip_start(
1223 struct ifnet * const ifp)
1224{
1225 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit);
1226 struct ifqueue * const ifq = &ifp->if_snd;
1227 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
1228 struct mbuf *m, *m0, *next_m0;
1229
1230 if ((ifp->if_flags & IFF_RUNNING) == 0
1231 && (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
1232 return;
1233
1234 for (;;) {
1235 tulip_desc_t *eop, *nextout;
1236 int segcnt, free, recopy;
1237 tulip_uint32_t d_status;
1238
1239 if (sc->tulip_flags & TULIP_WANTSETUP) {
1240 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
1241 ifp->if_flags |= IFF_OACTIVE;
1242 return;
1243 }
1244 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
1245 sizeof(sc->tulip_setupbuf));
1246 sc->tulip_flags &= ~TULIP_WANTSETUP;
1247 sc->tulip_flags |= TULIP_DOINGSETUP;
1248 ri->ri_free--;
1249 ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
1250 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
1251 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
1252 if (sc->tulip_flags & TULIP_WANTHASH)
1253 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
1254 ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf);
1255 ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf);
1256 ri->ri_nextout->d_length2 = 0;
1257 ri->ri_nextout->d_addr2 = 0;
1258 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1259 TULIP_WRITE_CSR(sc, csr_txpoll, 1);
1260 /*
1261 * Advance the ring for the next transmit packet.
1262 */
1263 if (++ri->ri_nextout == ri->ri_last)
1264 ri->ri_nextout = ri->ri_first;
1265 /*
1266 * Make sure the next descriptor is owned by us since it
1267 * may have been set up above if we ran out of room in the
1268 * ring.
1269 */
1270 ri->ri_nextout->d_status = 0;
1271 }
1272
1273 IF_DEQUEUE(ifq, m);
1274 if (m == NULL)
1275 break;
1276
1277 /*
1278 * Now we try to fill in our transmit descriptors. This is
1279 * a bit reminiscent of going on the Ark two by two
1280 * since each descriptor for the TULIP can describe
1281 * two buffers. So we advance through packet filling
1282 * each of the two entries at a time to to fill each
1283 * descriptor. Clear the first and last segment bits
1284 * in each descriptor (actually just clear everything
1285 * but the end-of-ring or chain bits) to make sure
1286 * we don't get messed up by previously sent packets.
1287 *
1288 * We may fail to put the entire packet on the ring if
1289 * there is either not enough ring entries free or if the
1290 * packet has more than MAX_TXSEG segments. In the former
1291 * case we will just wait for the ring to empty. In the
1292 * latter case we have to recopy.
1293 */
1294 d_status = 0;
1295 recopy = 0;
1296 eop = nextout = ri->ri_nextout;
1297 m0 = m;
1298 segcnt = 0;
1299 free = ri->ri_free;
1300 do {
1301 int len = m0->m_len;
1302 caddr_t addr = mtod(m0, caddr_t);
1303 unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1));
1304
1305 next_m0 = m0->m_next;
1306 while (len > 0) {
1307 unsigned slen = min(len, clsize);
1308
1309 segcnt++;
1310 if (segcnt > TULIP_MAX_TXSEG) {
1311 recopy = 1;
1312 next_m0 = NULL; /* to break out of outside loop */
1313 break;
1314 }
1315 if (segcnt & 1) {
1316 if (--free == 0) {
1317 /*
1318 * There's no more room but since nothing
1319 * has been committed at this point, just
1320 * show output is active, put back the
1321 * mbuf and return.
1322 */
1323 ifp->if_flags |= IFF_OACTIVE;
1324 IF_PREPEND(ifq, m);
1325 return;
1326 }
1327 eop = nextout;
1328 if (++nextout == ri->ri_last)
1329 nextout = ri->ri_first;
1330 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
1331 eop->d_status = d_status;
1332 eop->d_addr1 = vtophys(addr); eop->d_length1 = slen;
1333 } else {
1334 /*
1335 * Fill in second half of descriptor
1336 */
1337 eop->d_addr2 = vtophys(addr); eop->d_length2 = slen;
1338 }
1339 d_status = TULIP_DSTS_OWNER;
1340 len -= slen;
1341 addr += slen;
1342 clsize = CLBYTES;
1343 }
1344 } while ((m0 = next_m0) != NULL);
1345
1346 /*
1347 * The packet exceeds the number of transmit buffer
1348 * entries that we can use for one packet, so we have
1349 * recopy it into one mbuf and then try again.
1350 */
1351 if (recopy) {
1352 MGETHDR(m0, M_DONTWAIT, MT_DATA);
1353 if (m0 != NULL) {
1354 if (m->m_pkthdr.len > MHLEN) {
1355 MCLGET(m0, M_DONTWAIT);
1356 if ((m0->m_flags & M_EXT) == 0) {
1357 m_freem(m);
1358 m_freem(m0);
1359 continue;
1360 }
1361 }
1362 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
1363 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
1364 IF_PREPEND(ifq, m0);
1365 }
1366 m_freem(m);
1367 continue;
1368 }
1369
1370 /*
1371 * The descriptors have been filled in. Now get ready
1372 * to transmit.
1373 */
1374#if NBPFILTER > 0
1375 if (sc->tulip_bpf != NULL)
1376 bpf_mtap(sc->tulip_bpf, m);
1377#endif
1378 IF_ENQUEUE(&sc->tulip_txq, m);
1379
1380 /*
1381 * Make sure the next descriptor after this packet is owned
1382 * by us since it may have been set up above if we ran out
1383 * of room in the ring.
1384 */
1385 nextout->d_status = 0;
1386
1387 /*
1388 * If we only used the first segment of the last descriptor,
1389 * make sure the second segment will not be used.
1390 */
1391 if (segcnt & 1) {
1392 eop->d_addr2 = 0;
1393 eop->d_length2 = 0;
1394 }
1395
1396 /*
1397 * Mark the last and first segments, indicate we want a transmit
1398 * complete interrupt, give the descriptors to the TULIP, and tell
1399 * it to transmit!
1400 */
1401 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
1402
1403 /*
1404 * Note that ri->ri_nextout is still the start of the packet
1405 * and until we set the OWNER bit, we can still back out of
1406 * everything we have done.
1407 */
1408 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
1409 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
1410
1411 /*
1412 * This advances the ring for us.
1413 */
1414 ri->ri_nextout = nextout;
1415 ri->ri_free = free;
1416
1417 TULIP_WRITE_CSR(sc, csr_txpoll, 1);
1418 }
1419 if (m != NULL) {
1420 ifp->if_flags |= IFF_OACTIVE;
1421 IF_PREPEND(ifq, m);
1422 }
1423}
1424
1425static int
1426tulip_intr(
1427 void *arg)
1428{
1429 tulip_softc_t * sc = (tulip_softc_t *) arg;
1430 tulip_uint32_t csr;
1431#if defined(__bsdi__)
1432 int progress = 1;
1433#else
1434 int progress = 0;
1435#endif
1436
1437 do {
1438 while ((csr = TULIP_READ_CSR(sc, csr_status)) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) {
1439 progress = 1;
1440 TULIP_WRITE_CSR(sc, csr_status, csr & sc->tulip_intrmask);
1441
1442 if (csr & TULIP_STS_SYSERROR) {
1443 if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) {
1444 tulip_reset(sc);
1445 tulip_init(sc);
1446 break;
1447 }
1448 }
1449 if (csr & (TULIP_STS_GPTIMEOUT|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL)) {
1450 if (sc->tulip_chipid == TULIP_DC21041) {
1451 (*sc->tulip_boardsw->bd_media_select)(sc);
1452 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL))
1453 csr &= ~TULIP_STS_ABNRMLINTR;
1454 }
1455 }
1456 if (csr & TULIP_STS_ABNRMLINTR) {
1457 printf("%s%d: abnormal interrupt: 0x%05x [0x%05x]\n",
1458 sc->tulip_name, sc->tulip_unit, csr, csr & sc->tulip_intrmask);
1459 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode);
1460 }
1461 if (csr & TULIP_STS_RXINTR)
1462 tulip_rx_intr(sc);
1463 if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) {
1464 tulip_tx_intr(sc);
1465 tulip_start(&sc->tulip_if);
1466 }
1467 }
1468 } while ((sc = sc->tulip_slaves) != NULL);
1469 return progress;
1470}
1471
1472/*
1473 *
1474 */
1475
1476static void
1477tulip_delay_300ns(
1478 tulip_softc_t * const sc)
1479{
1480 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1481 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1482
1483 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1484 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1485
1486 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1487 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode);
1488}
1489
1490#define EMIT do { TULIP_WRITE_CSR(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)
1491
1492static void
1493tulip_idle_srom(
1494 tulip_softc_t * const sc)
1495{
1496 unsigned bit, csr;
1497
1498 csr = SROMSEL | SROMRD; EMIT;
1499 csr ^= SROMCS; EMIT;
1500 csr ^= SROMCLKON; EMIT;
1501
1502 /*
1503 * Write 25 cycles of 0 which will force the SROM to be idle.
1504 */
1505 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1506 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1507 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1508 }
1509 csr ^= SROMCLKOFF; EMIT;
1510 csr ^= SROMCS; EMIT; EMIT;
1511 csr = 0; EMIT;
1512}
1513
1514
1515static void
1516tulip_read_srom(
1517 tulip_softc_t * const sc)
1518{
1519 int idx;
1520 const unsigned bitwidth = SROM_BITWIDTH;
1521 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1522 const unsigned msb = 1 << (bitwidth + 3 - 1);
1523 unsigned lastidx = (1 << bitwidth) - 1;
1524
1525 tulip_idle_srom(sc);
1526
1527 for (idx = 0; idx <= lastidx; idx++) {
1528 unsigned lastbit, data, bits, bit, csr;
1529 csr = SROMSEL | SROMRD; EMIT;
1530 csr ^= SROMCSON; EMIT;
1531 csr ^= SROMCLKON; EMIT;
1532
1533 lastbit = 0;
1534 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1535 const unsigned thisbit = bits & msb;
1536 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1537 if (thisbit != lastbit) {
1538 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1539 }
1540 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1541 lastbit = thisbit;
1542 }
1543 csr ^= SROMCLKOFF; EMIT;
1544
1545 for (data = 0, bits = 0; bits < 16; bits++) {
1546 data <<= 1;
1547 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1548 data |= TULIP_READ_CSR(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1549 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1550 }
1551 sc->tulip_rombuf[idx*2] = data & 0xFF;
1552 sc->tulip_rombuf[idx*2+1] = data >> 8;
1553 csr = SROMSEL | SROMRD; EMIT;
1554 csr = 0; EMIT;
1555 }
1556}
1557
1558#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
1559#define tulip_srom_crcok(databuf) ( \
1560 ((tulip_crc32(databuf, 126) & 0xFFFF) ^ 0xFFFF)== \
1561 ((databuf)[126] | ((databuf)[127] << 8)))
1562
1563static unsigned
1564tulip_crc32(
1565 const unsigned char *databuf,
1566 size_t datalen)
1567{
1568 u_int idx, bit, data, crc = 0xFFFFFFFFUL;
1569
1570 for (idx = 0; idx < datalen; idx++)
1571 for (data = *databuf++, bit = 0; bit < 8; bit++, data >>= 1)
1572 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0);
1573 return crc;
1574}
1575
1576
1577/*
1578 * This deals with the vagaries of the address roms and the
1579 * brain-deadness that various vendors commit in using them.
1580 */
1581static int
1582tulip_read_macaddr(
1583 tulip_softc_t *sc)
1584{
1585 int cksum, rom_cksum, idx;
1586 tulip_uint32_t csr;
1587 unsigned char tmpbuf[8];
1588 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
1589
1590 if (sc->tulip_chipid == TULIP_DC21040) {
1591 TULIP_WRITE_CSR(sc, csr_enetrom, 1);
1592 for (idx = 0; idx < 32; idx++) {
1593 int cnt = 0;
1594 while (((csr = TULIP_READ_CSR(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
1595 cnt++;
1596 sc->tulip_rombuf[idx] = csr & 0xFF;
1597 }
1598 sc->tulip_boardsw = &tulip_dc21040_boardsw;
1599#if defined(TULIP_EISA)
1600 } else if (sc->tulip_chipid == TULIP_DE425) {
1601 int cnt;
1602 for (idx = 0, cnt = 0; idx < sizeof(testpat) && cnt < 32; cnt++) {
1603 tmpbuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom);
1604 if (tmpbuf[idx] == testpat[idx])
1605 ++idx;
1606 else
1607 idx = 0;
1608 }
1609 for (idx = 0; idx < 32; idx++)
1610 sc->tulip_rombuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom);
1611 sc->tulip_boardsw = &tulip_dc21040_boardsw;
1612#endif /* TULIP_EISA */
1613 } else {
1614 int new_srom_fmt = 0;
1615 /*
1616 * Assume all DC21140 board are compatible with the
1617 * DEC 10/100 evaluation board. Not really valid but
1618 * it's the best we can do until every one switches to
1619 * the new SROM format.
1620 */
1621 if (sc->tulip_chipid == TULIP_DC21140)
1622 sc->tulip_boardsw = &tulip_dc21140_eb_boardsw;
1623 /*
1624 * Thankfully all DC21041's act the same.
1625 */
1626 if (sc->tulip_chipid == TULIP_DC21041)
1627 sc->tulip_boardsw = &tulip_dc21041_boardsw;
1628 tulip_read_srom(sc);
1629 if (tulip_srom_crcok(sc->tulip_rombuf)) {
1630 /*
1631 * SROM CRC is valid therefore it must be in the
1632 * new format.
1633 */
1634 new_srom_fmt = 1;
1635 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
1636 /*
1637 * No checksum is present. See if the SROM id checks out;
1638 * the first 18 bytes should be 0 followed by a 1 followed
1639 * by the number of adapters (which we don't deal with yet).
1640 */
1641 for (idx = 0; idx < 18; idx++) {
1642 if (sc->tulip_rombuf[idx] != 0)
1643 break;
1644 }
1645 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
1646 new_srom_fmt = 2;
1647 }
1648 if (new_srom_fmt) {
1649 /*
1650 * New SROM format. Copy out the Ethernet address.
1651 * If it contains a DE500-XA string, then it must be
1652 * a DE500-XA.
1653 */
1654 bcopy(sc->tulip_rombuf + 20, sc->tulip_hwaddr, 6);
1655 if (bcmp(sc->tulip_rombuf + 29, "DE500-XA", 8) == 0)
1656 sc->tulip_boardsw = &tulip_dc21140_de500_boardsw;
1657 if (bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0)
1658 sc->tulip_boardsw = &tulip_dc21041_de450_boardsw;
1659 if (sc->tulip_boardsw == NULL)
1660 return -6;
1661 sc->tulip_flags |= TULIP_ROMOK;
1662 return 0;
1663 }
1664 }
1665
1666
1667 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
1668 /*
1669 * Some folks don't use the standard ethernet rom format
1670 * but instead just put the address in the first 6 bytes
1671 * of the rom and let the rest be all 0xffs. (Can we say
1672 * ZNYX???)
1673 */
1674 for (idx = 6; idx < 32; idx++) {
1675 if (sc->tulip_rombuf[idx] != 0xFF)
1676 return -4;
1677 }
1678 /*
1679 * Make sure the address is not multicast or locally assigned
1680 * that the OUI is not 00-00-00.
1681 */
1682 if ((sc->tulip_rombuf[0] & 3) != 0)
1683 return -4;
1684 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
1685 && sc->tulip_rombuf[2] == 0)
1686 return -4;
1687 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6);
1688 sc->tulip_flags |= TULIP_ROMOK;
1689 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0
1690 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1
1691 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2
1692 && (sc->tulip_hwaddr[3] & ~3) == 0xF0) {
1693 /*
1694 * Now if the OUI is ZNYX and hwaddr[3] == 0xF0 .. 0xF3
1695 * then it's a ZX314 Master port.
1696 */
1697 sc->tulip_boardsw = &tulip_dc21040_zx314_master_boardsw;
1698 }
1699 return 0;
1700 } else {
1701 /*
1702 * A number of makers of multiport boards (ZNYX and Cogent)
1703 * only put on one address ROM on their DC21040 boards. So
1704 * if the ROM is all zeros and this is a DC21040, look at the
1705 * previous configured boards (as long as they are on the same
1706 * PCI bus and the bus number is non-zero) until we find the
1707 * master board with address ROM. We then use its address ROM
1708 * as the base for this board. (we add our relative board
1709 * to the last byte of its address).
1710 */
1711 if (sc->tulip_chipid == TULIP_DC21040 /* && sc->tulip_bus != 0 XXX */) {
1712 for (idx = 0; idx < 32; idx++) {
1713 if (sc->tulip_rombuf[idx] != 0)
1714 break;
1715 }
1716 if (idx == 32) {
1717 int root_unit;
1718 tulip_softc_t *root_sc = NULL;
1719 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
1720 root_sc = TULIP_UNIT_TO_SOFTC(root_unit);
1721 if (root_sc == NULL || (root_sc->tulip_flags & (TULIP_ROMOK|TULIP_SLAVEDROM)) == TULIP_ROMOK)
1722 break;
1723 root_sc = NULL;
1724 }
1725 if (root_sc != NULL
1726 /* && root_sc->tulip_bus == sc->tulip_bus XXX */) {
1727 bcopy(root_sc->tulip_hwaddr, sc->tulip_hwaddr, 6);
1728 sc->tulip_hwaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
1729 sc->tulip_flags |= TULIP_SLAVEDROM;
1730 if (root_sc->tulip_boardsw->bd_type == TULIP_DC21040_ZX314_MASTER) {
1731 sc->tulip_boardsw = &tulip_dc21040_zx314_slave_boardsw;
1732 /*
1733 * Now for a truly disgusting kludge: all 4 DC21040s on
1734 * the ZX314 share the same INTA line so the mapping
1735 * setup by the BIOS on the PCI bridge is worthless.
1736 * Rather than reprogramming the value in the config
1737 * register, we will handle this internally.
1738 */
1739 sc->tulip_slaves = root_sc->tulip_slaves;
1740 root_sc->tulip_slaves = sc;
1741 }
1742 return 0;
1743 }
1744 }
1745 }
1746 }
1747
1748 /*
1749 * This is the standard DEC address ROM test.
1750 */
1751
1752 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
1753 return -3;
1754
1755 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
1756 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
1757 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
1758 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
1759 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
1760 return -2;
1761
1762 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6);
1763
1764 cksum = *(u_short *) &sc->tulip_hwaddr[0];
1765 cksum *= 2;
1766 if (cksum > 65535) cksum -= 65535;
1767 cksum += *(u_short *) &sc->tulip_hwaddr[2];
1768 if (cksum > 65535) cksum -= 65535;
1769 cksum *= 2;
1770 if (cksum > 65535) cksum -= 65535;
1771 cksum += *(u_short *) &sc->tulip_hwaddr[4];
1772 if (cksum >= 65535) cksum -= 65535;
1773
1774 rom_cksum = *(u_short *) &sc->tulip_rombuf[6];
1775
1776 if (cksum != rom_cksum)
1777 return -1;
1778
1779 /*
1780 * Check for various boards based on OUI. Did I say braindead?
1781 */
1782
1783 if (sc->tulip_chipid == TULIP_DC21140) {
1784 if (sc->tulip_hwaddr[0] == TULIP_OUI_COGENT_0
1785 && sc->tulip_hwaddr[1] == TULIP_OUI_COGENT_1
1786 && sc->tulip_hwaddr[2] == TULIP_OUI_COGENT_2) {
1787 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID)
1788 sc->tulip_boardsw = &tulip_dc21140_cogent_em100_boardsw;
1789 }
1790 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0
1791 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1
1792 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2) {
1793 /* this at least works for the zx342 from Znyx */
1794 sc->tulip_boardsw = &tulip_dc21140_znyx_zx34x_boardsw;
1795 }
1796 }
1797
1798 sc->tulip_flags |= TULIP_ROMOK;
1799 return 0;
1800}
1801
1802static void
1803tulip_addr_filter(
1804 tulip_softc_t * const sc)
1805{
1806 tulip_uint32_t *sp = sc->tulip_setupdata;
1807 struct ether_multistep step;
1808 struct ether_multi *enm;
1809 int i;
1810
1811 sc->tulip_flags &= ~TULIP_WANTHASH;
1812 sc->tulip_flags |= TULIP_WANTSETUP;
1813 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
1814 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
1815 if (sc->tulip_ac.ac_multicnt > 14) {
1816 unsigned hash;
1817 /*
1818 * If we have more than 14 multicasts, we have
1819 * go into hash perfect mode (512 bit multicast
1820 * hash and one perfect hardware).
1821 */
1822
1823 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
1824 hash = tulip_mchash(etherbroadcastaddr);
1825 sp[hash >> 4] |= 1 << (hash & 0xF);
1826 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm);
1827 while (enm != NULL) {
1828 hash = tulip_mchash(enm->enm_addrlo);
1829 sp[hash >> 4] |= 1 << (hash & 0xF);
1830 ETHER_NEXT_MULTI(step, enm);
1831 }
1832 sc->tulip_flags |= TULIP_WANTHASH;
1833 sp[39] = ((u_short *) sc->tulip_ac.ac_enaddr)[0];
1834 sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[1];
1835 sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[2];
1836 } else {
1837 /*
1838 * Else can get perfect filtering for 16 addresses.
1839 */
1840 i = 0;
1841 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm);
1842 for (; enm != NULL; i++) {
1843 *sp++ = ((u_short *) enm->enm_addrlo)[0];
1844 *sp++ = ((u_short *) enm->enm_addrlo)[1];
1845 *sp++ = ((u_short *) enm->enm_addrlo)[2];
1846 ETHER_NEXT_MULTI(step, enm);
1847 }
1848 /*
1849 * Add the broadcast address.
1850 */
1851 i++;
1852 *sp++ = 0xFFFF;
1853 *sp++ = 0xFFFF;
1854 *sp++ = 0xFFFF;
1855 /*
1856 * Pad the rest with our hardware address
1857 */
1858 for (; i < 16; i++) {
1859 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0];
1860 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1];
1861 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2];
1862 }
1863 }
1864}
1865
1866static int
1867tulip_ioctl(
1868 struct ifnet * const ifp,
1869 ioctl_cmd_t cmd,
1870 caddr_t data)
1871{
1872 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit);
1873 struct ifaddr *ifa = (struct ifaddr *)data;
1874 struct ifreq *ifr = (struct ifreq *) data;
1875 int s, error = 0;
1876
1877 s = splimp();
1878
1879 switch (cmd) {
1880 case SIOCSIFADDR: {
1881
1882 ifp->if_flags |= IFF_UP;
1883 switch(ifa->ifa_addr->sa_family) {
1884#ifdef INET
1885 case AF_INET: {
1886 sc->tulip_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
1887 tulip_init(sc);
1888#if defined(__FreeBSD__) || defined(__NetBSD__)
1889 arp_ifinit(&sc->tulip_ac, ifa);
1890#elif defined(__bsdi__)
1891 arpwhohas(&sc->tulip_ac, &IA_SIN(ifa)->sin_addr);
1892#endif
1893 break;
1894 }
1895#endif /* INET */
1896
1897#ifdef NS
1898 /*
1899 * This magic copied from if_is.c; I don't use XNS,
1900 * so I have no way of telling if this actually
1901 * works or not.
1902 */
1903 case AF_NS: {
1904 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
1905 if (ns_nullhost(*ina)) {
1906 ina->x_host = *(union ns_host *)(sc->tulip_ac.ac_enaddr);
1907 } else {
1908 ifp->if_flags &= ~IFF_RUNNING;
1909 bcopy((caddr_t)ina->x_host.c_host,
1910 (caddr_t)sc->tulip_ac.ac_enaddr,
1911 sizeof sc->tulip_ac.ac_enaddr);
1912 }
1913
1914 tulip_init(sc);
1915 break;
1916 }
1917#endif /* NS */
1918
1919 default: {
1920 tulip_init(sc);
1921 break;
1922 }
1923 }
1924 break;
1925 }
1926 case SIOCGIFADDR: {
1927 bcopy((caddr_t) sc->tulip_ac.ac_enaddr,
1928 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
1929 6);
1930 break;
1931 }
1932
1933 case SIOCSIFFLAGS: {
1934 /*
1935 * Changing the connection forces a reset.
1936 */
1937 if (sc->tulip_flags & TULIP_ALTPHYS) {
1938 if ((ifp->if_flags & IFF_ALTPHYS) == 0)
1939 tulip_reset(sc);
1940 } else {
1941 if (ifp->if_flags & IFF_ALTPHYS)
1942 tulip_reset(sc);
1943 }
1944 tulip_init(sc);
1945 break;
1946 }
1947
1948 case SIOCADDMULTI:
1949 case SIOCDELMULTI: {
1950 /*
1951 * Update multicast listeners
1952 */
1953 if (cmd == SIOCADDMULTI)
1954 error = ether_addmulti(ifr, &sc->tulip_ac);
1955 else
1956 error = ether_delmulti(ifr, &sc->tulip_ac);
1957
1958 if (error == ENETRESET) {
1959 tulip_addr_filter(sc); /* reset multicast filtering */
1960 tulip_init(sc);
1961 error = 0;
1962 }
1963 break;
1964 }
1965#if defined(SIOCSIFMTU)
1966#if !defined(ifr_mtu)
1967#define ifr_mtu ifr_metric
1968#endif
1969 case SIOCSIFMTU:
1970 /*
1971 * Set the interface MTU.
1972 */
1973 if (ifr->ifr_mtu > ETHERMTU) {
1974 error = EINVAL;
1975 break;
1976 }
1977 ifp->if_mtu = ifr->ifr_mtu;
1978 break;
1979#endif
1980
1981 default: {
1982 error = EINVAL;
1983 break;
1984 }
1985 }
1986
1987 splx(s);
1988 return error;
1989}
1990
1991static void
1992tulip_attach(
1993 tulip_softc_t * const sc)
1994{
1995 struct ifnet * const ifp = &sc->tulip_if;
1996
1997 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
1998 ifp->if_ioctl = tulip_ioctl;
1999 ifp->if_output = ether_output;
2000 ifp->if_start = tulip_start;
2001
2002#ifdef __FreeBSD__
2003 printf("%s%d", sc->tulip_name, sc->tulip_unit);
2004#endif
2005 printf(": %s%s pass %d.%d Ethernet address %s\n",
2006 sc->tulip_boardsw->bd_description,
2007 tulip_chipdescs[sc->tulip_chipid],
2008 (sc->tulip_revinfo & 0xF0) >> 4,
2009 sc->tulip_revinfo & 0x0F,
2010 ether_sprintf(sc->tulip_hwaddr));
2011
2012 if ((*sc->tulip_boardsw->bd_media_probe)(sc)) {
2013 ifp->if_flags |= IFF_ALTPHYS;
2014 } else {
2015 sc->tulip_flags |= TULIP_ALTPHYS;
2016 }
2017
2018 tulip_reset(sc);
2019
2020 if_attach(ifp);
2021#if defined(__NetBSD__)
2022 ether_ifattach(ifp);
2023#endif
2024
2025#if NBPFILTER > 0
2026 bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
2027#endif
2028}
2029
2030static void
2031tulip_initcsrs(
2032 tulip_softc_t * const sc,
2033 tulip_csrptr_t csr_base,
2034 size_t csr_size)
2035{
2036 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
2037 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
2038 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
2039 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
2040 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
2041 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
2042 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
2043 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
2044 sc->tulip_csrs.csr_missed_frame = csr_base + 8 * csr_size;
2045 if (sc->tulip_chipid == TULIP_DC21040) {
2046 sc->tulip_csrs.csr_enetrom = csr_base + 9 * csr_size;
2047 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size;
2048 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size;
2049 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2050 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2051 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2052 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2053#if defined(TULIP_EISA)
2054 } else if (sc->tulip_chipid == TULIP_DE425) {
2055 sc->tulip_csrs.csr_enetrom = csr_base + DE425_ENETROM_OFFSET;
2056 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size;
2057 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size;
2058 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2059 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2060 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2061 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2062#endif /* TULIP_EISA */
2063 } else if (sc->tulip_chipid == TULIP_DC21140) {
2064 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size;
2065 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size;
2066 sc->tulip_csrs.csr_gp = csr_base + 12 * csr_size;
2067 sc->tulip_csrs.csr_watchdog = csr_base + 15 * csr_size;
2068 } else if (sc->tulip_chipid == TULIP_DC21041) {
2069 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size;
2070 sc->tulip_csrs.csr_bootrom = csr_base + 10 * csr_size;
2071 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size;
2072 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size;
2073 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size;
2074 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size;
2075 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size;
2076 }
2077}
2078
2079static void
2080tulip_initring(
2081 tulip_softc_t * const sc,
2082 tulip_ringinfo_t * const ri,
2083 tulip_desc_t *descs,
2084 int ndescs)
2085{
2086 ri->ri_max = ndescs;
2087 ri->ri_first = descs;
2088 ri->ri_last = ri->ri_first + ri->ri_max;
2089 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
2090 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
2091}
2092
2093/*
2094 * This is the PCI configuration support. Since the DC21040 is available
2095 * on both EISA and PCI boards, one must be careful in how defines the
2096 * DC21040 in the config file.
2097 */
2098
2099#define PCI_CFID 0x00 /* Configuration ID */
2100#define PCI_CFCS 0x04 /* Configurtion Command/Status */
2101#define PCI_CFRV 0x08 /* Configuration Revision */
2102#define PCI_CFLT 0x0c /* Configuration Latency Timer */
2103#define PCI_CBIO 0x10 /* Configuration Base IO Address */
2104#define PCI_CBMA 0x14 /* Configuration Base Memory Address */
2105#define PCI_CFIT 0x3c /* Configuration Interrupt */
2106#define PCI_CFDA 0x40 /* Configuration Driver Area */
2107
2108#if defined(TULIP_EISA)
2109static const int tulip_eisa_irqs[4] = { IRQ5, IRQ9, IRQ10, IRQ11 };
2110#endif
2111
2112#if defined(__FreeBSD__)
2113
2114#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit
2115
2116static int
2117tulip_pci_shutdown(
2118 struct kern_devconf * const kdc,
2119 int force)
2120{
2121 if (kdc->kdc_unit < NDE) {
2122 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit);
2123 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2124 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2125 33MHz that comes to two microseconds but wait a
2126 bit longer anyways) */
2127 }
2128 (void) dev_detach(kdc);
2129 return 0;
2130}
2131
2132static char*
2133tulip_pci_probe(
2134 pcici_t config_id,
2135 pcidi_t device_id)
2136{
2137 if (PCI_VENDORID(device_id) != DEC_VENDORID)
2138 return NULL;
2139 if (PCI_CHIPID(device_id) == DC21040_CHIPID)
2140 return "Digital DC21040 Ethernet";
2141 if (PCI_CHIPID(device_id) == DC21041_CHIPID)
2142 return "Digital DC21041 Ethernet";
2143 if (PCI_CHIPID(device_id) == DC21140_CHIPID)
2144 return "Digital DC21140 Fast Ethernet";
2145 return NULL;
2146}
2147
2148static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2149static u_long tulip_pci_count;
2150
2151static struct pci_device dedevice = {
2152 "de",
2153 tulip_pci_probe,
2154 tulip_pci_attach,
2155 &tulip_pci_count,
2156 tulip_pci_shutdown,
2157};
2158
2159DATA_SET (pcidevice_set, dedevice);
2160#endif /* __FreeBSD__ */
2161
2162#if defined(__bsdi__)
2163#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux
2164
2165static void
2166tulip_shutdown(
2167 void *arg)
2168{
2169 tulip_softc_t * const sc = (tulip_softc_t *) arg;
2170 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2171 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2172 33MHz that comes to two microseconds but wait a
2173 bit longer anyways) */
2174}
2175
2176static int
2177tulip_pci_match(
2178 pci_devaddr_t *pa)
2179{
2180 int irq;
2181 unsigned id;
2182
2183 id = pci_inl(pa, PCI_VENDOR_ID);
2184 if (PCI_VENDORID(id) != DEC_VENDORID)
2185 return 0;
2186 id = PCI_CHIPID(id);
2187 if (id != DC21040_CHIPID && id != DC21041_CHIPID && id != DC21140_CHIPID)
2188 return 0;
2189 irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
2190 if (irq == 0 || irq >= 16) {
2191 printf("de?: invalid IRQ %d; skipping\n", irq);
2192 return 0;
2193 }
2194 return 1;
2195}
2196
2197static int
2198tulip_probe(
2199 struct device *parent,
2200 struct cfdata *cf,
2201 void *aux)
2202{
2203 struct isa_attach_args * const ia = (struct isa_attach_args *) aux;
2204 unsigned irq, slot;
2205 pci_devaddr_t *pa;
2206
2207#if defined(TULIP_EISA)
2208 if ((slot = eisa_match(cf, ia)) != 0) {
2209 unsigned tmp;
2210 ia->ia_iobase = slot << 12;
2211 ia->ia_iosize = EISA_NPORT;
2212 eisa_slotalloc(slot);
2213 tmp = inb(ia->ia_iobase + DE425_CFG0);
2214 irq = tulip_eisa_irqs[(tmp >> 1) & 0x03];
2215 /*
2216 * Until BSD/OS likes level interrupts, force
2217 * the DE425 into edge-triggered mode.
2218 */
2219 if ((tmp & 1) == 0)
2220 outb(ia->ia_iobase + DE425_CFG0, tmp | 1);
2221 /*
2222 * CBIO needs to map to the EISA slot
2223 * enable I/O access and Master
2224 */
2225 outl(ia->ia_iobase + DE425_CBIO, ia->ia_iobase);
2226 outl(ia->ia_iobase + DE425_CFCS, 5 | inl(ia->ia_iobase + DE425_CFCS));
2227 ia->ia_aux = NULL;
2228 } else {
2229#endif /* TULIP_EISA */
2230 pa = pci_scan(tulip_pci_match);
2231 if (pa == NULL)
2232 return 0;
2233
2234 irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF));
2235
2236 /* Get the base address; assume the BIOS set it up correctly */
2237#if defined(TULIP_IOMAPPED)
2238 ia->ia_maddr = NULL;
2239 ia->ia_msize = 0;
2240 ia->ia_iobase = pci_inl(pa, PCI_CBIO) & ~7;
2241 pci_outl(pa, PCI_CBIO, 0xFFFFFFFF);
2242 ia->ia_iosize = ((~pci_inl(pa, PCI_CBIO)) | 7) + 1;
2243 pci_outl(pa, PCI_CBIO, (int) ia->ia_iobase);
2244
2245 /* Disable memory space access */
2246 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~2);
2247#else
2248 ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7);
2249 pci_outl(pa, PCI_CBMA, 0xFFFFFFFF);
2250 ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1;
2251 pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr);
2252 ia->ia_iobase = 0;
2253 ia->ia_iosize = 0;
2254
2255 /* Disable I/O space access */
2256 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1);
2257#endif /* TULIP_IOMAPPED */
2258
2259 ia->ia_aux = (void *) pa;
2260#if defined(TULIP_EISA)
2261 }
2262#endif
2263
2264 /* PCI bus masters don't use host DMA channels */
2265 ia->ia_drq = DRQNONE;
2266
2267 if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
2268 printf("de%d: error: desired IRQ of %d does not match device's actual IRQ of %d,\n",
2269 cf->cf_unit,
2270 ffs(ia->ia_irq) - 1, ffs(irq) - 1);
2271 return 0;
2272 }
2273 if (ia->ia_irq == IRQUNK && (ia->ia_irq = isa_irqalloc(irq)) == 0) {
2274 printf("de%d: warning: IRQ %d is shared\n", cf->cf_unit, ffs(irq) - 1);
2275 ia->ia_irq = irq;
2276 }
2277 return 1;
2278}
2279
2280static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2281
2282#if defined(TULIP_EISA)
2283static char *tulip_eisa_ids[] = {
2284 "DEC4250",
2285 NULL
2286};
2287#endif
2288
2289struct cfdriver decd = {
2290 0, "de", tulip_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t),
2291#if defined(TULIP_EISA)
2292 tulip_eisa_ids
2293#endif
2294};
2295
2296#endif /* __bsdi__ */
2297
2298#if defined(__NetBSD__)
2299#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux
2300
2301static void
2302tulip_pci_shutdown(
2303 void *arg)
2304{
2305 tulip_softc_t * const sc = (tulip_softc_t *) arg;
2306 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2307 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2308 33MHz that comes to two microseconds but wait a
2309 bit longer anyways) */
2310}
2311
2312static int
2313tulip_pci_probe(
2314 struct device *parent,
2315 void *match,
2316 void *aux)
2317{
2318 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
2319
2320 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
2321 return 0;
2322 if (PCI_CHIPID(pa->pa_id) == DC21040_CHIPID
2323 || PCI_CHIPID(pa->pa_id) == DC21041_CHIPID
2324 || PCI_CHIPID(pa->pa_id) == DC21140_CHIPID)
2325 return 1;
2326
2327 return 0;
2328}
2329
2330static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
2331
2332struct cfdriver decd = {
2333 0, "de", tulip_pci_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t)
2334};
2335
2336#endif /* __NetBSD__ */
2337
2338static void
2339tulip_pci_attach(
2340 TULIP_PCI_ATTACH_ARGS)
2341{
2342#if defined(__FreeBSD__)
2343 tulip_softc_t *sc;
2344#endif
2345#if defined(__bsdi__)
2346 tulip_softc_t * const sc = (tulip_softc_t *) self;
2347 struct isa_attach_args * const ia = (struct isa_attach_args *) aux;
2348 pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux;
2349 int unit = sc->tulip_dev.dv_unit;
2350#endif
2351#if defined(__NetBSD__)
2352 tulip_softc_t * const sc = (tulip_softc_t *) self;
2353 struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
2354 int unit = sc->tulip_dev.dv_unit;
2355#endif
2356 int retval, idx, revinfo, id;
2357#if !defined(TULIP_IOMAPPED) && !defined(__bsdi__)
2358 vm_offset_t pa_csrs;
2359#endif
2360 unsigned csroffset = TULIP_PCI_CSROFFSET;
2361 unsigned csrsize = TULIP_PCI_CSRSIZE;
2362 tulip_csrptr_t csr_base;
2363 tulip_desc_t *rxdescs, *txdescs;
2364 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
2365
2366#if defined(__FreeBSD__)
2367 if (unit >= NDE) {
2368 printf("de%d: not configured; kernel is built for only %d device%s.\n",
2369 unit, NDE, NDE == 1 ? "" : "s");
2370 return;
2371 }
2372#endif
2373
2374#if defined(__FreeBSD__)
2375 revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF;
2376 id = pci_conf_read(config_id, PCI_CFID);
2377#endif
2378#if defined(__bsdi__)
2379 if (pa != NULL) {
2380 revinfo = pci_inl(pa, PCI_CFRV) & 0xFF;
2381 id = pci_inl(pa, PCI_CFID);
2382#if defined(TULIP_EISA)
2383 } else {
2384 revinfo = inl(ia->ia_iobase + DE425_CFRV) & 0xFF;
2385 csroffset = TULIP_EISA_CSROFFSET;
2386 csrsize = TULIP_EISA_CSRSIZE;
2387 chipid = TULIP_DE425;
2388#endif
2389 }
2390#endif
2391#if defined(__NetBSD__)
2392 revinfo = pci_conf_read(pa->pa_tag, PCI_CFRV) & 0xFF;
2393 id = pa->pa_id;
2394#endif
2395
2396 if (PCI_VENDORID(id) == DEC_VENDORID) {
2397 if (PCI_CHIPID(id) == DC21040_CHIPID) chipid = TULIP_DC21040;
2398 else if (PCI_CHIPID(id) == DC21140_CHIPID) chipid = TULIP_DC21140;
2399 else if (PCI_CHIPID(id) == DC21041_CHIPID) chipid = TULIP_DC21041;
2400 }
2401 if (chipid == TULIP_CHIPID_UNKNOWN)
2402 return;
2403
2404 if ((chipid == TULIP_DC21040 || chipid == TULIP_DE425) && revinfo < 0x20) {
2405#ifdef __FreeBSD__
2406 printf("de%d", unit);
2407#endif
2408 printf(": not configured; DC21040 pass 2.0 required (%d.%d found)\n",
2409 revinfo >> 4, revinfo & 0x0f);
2410 return;
2411 } else if (chipid == TULIP_DC21140 && revinfo < 0x11) {
2412#ifdef __FreeBSD__
2413 printf("de%d", unit);
2414#endif
2415 printf(": not configured; DC21140 pass 1.1 required (%d.%d found)\n",
2416 revinfo >> 4, revinfo & 0x0f);
2417 return;
2418 }
2419
2420#if defined(__FreeBSD__)
2421 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
2422 if (sc == NULL)
2423 return;
2424 bzero(sc, sizeof(*sc)); /* Zero out the softc*/
2425#endif
2426
2427 rxdescs = (tulip_desc_t *)
2428 malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
2429 if (rxdescs == NULL) {
2430#if defined(__FreeBSD__)
2431 free((caddr_t) sc, M_DEVBUF);
2432#endif
2433 return;
2434 }
2435
2436 txdescs = (tulip_desc_t *)
2437 malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
2438 if (txdescs == NULL) {
2439 free((caddr_t) rxdescs, M_DEVBUF);
2440#if defined(__FreeBSD__)
2441 free((caddr_t) sc, M_DEVBUF);
2442#endif
2443 return;
2444 }
2445
2446 sc->tulip_chipid = chipid;
2447 sc->tulip_unit = unit;
2448 sc->tulip_name = "de";
2449 sc->tulip_revinfo = revinfo;
2450#if defined(__FreeBSD__)
2451#if defined(TULIP_IOMAPPED)
2452 retval = pci_map_port(config_id, PCI_CBIO, &csr_base);
2453#else
2454 retval = pci_map_mem(config_id, PCI_CBMA, (vm_offset_t *) &csr_base, &pa_csrs);
2455#endif
2456 if (!retval) {
2457 free((caddr_t) txdescs, M_DEVBUF);
2458 free((caddr_t) rxdescs, M_DEVBUF);
2459 free((caddr_t) sc, M_DEVBUF);
2460 return;
2461 }
2462 tulips[unit] = sc;
2463#endif /* __FreeBSD__ */
2464
2465#if defined(__bsdi__)
2466#if defined(TULIP_IOMAPPED)
2467 csr_base = ia->ia_iobase;
2468#else
2469 csr_base = (vm_offset_t) mapphys((vm_offset_t) ia->ia_maddr, ia->ia_msize);
2470#endif
2471#endif /* __bsdi__ */
2472
2473#if defined(__NetBSD__)
2474#if defined(TULIP_IOMAPPED)
2475 retval = pci_map_io(pa->pa_tag, PCI_CBIO, &csr_base);
2476#else
2477 retval = pci_map_mem(pa->pa_tag, PCI_CBMA, (vm_offset_t *) &csr_base, &pa_csrs);
2478#endif
2479 if (retval) {
2480 free((caddr_t) txdescs, M_DEVBUF);
2481 free((caddr_t) rxdescs, M_DEVBUF);
2482 return;
2483 }
2484#endif /* __NetBSD__ */
2485
2486 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
2487 tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS);
2488 tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS);
2489 if ((retval = tulip_read_macaddr(sc)) < 0) {
2490#ifdef __FreeBSD__
2491 printf("%s%d", sc->tulip_name, sc->tulip_unit);
2492#endif
2493 printf(": can't read ENET ROM (why=%d) (", retval);
2494 for (idx = 0; idx < 32; idx++)
2495 printf("%02x", sc->tulip_rombuf[idx]);
2496 printf("\n");
2497 printf("%s%d: %s%s pass %d.%d Ethernet address %s\n",
2498 sc->tulip_name, sc->tulip_unit,
2499 (sc->tulip_boardsw != NULL ? sc->tulip_boardsw->bd_description : ""),
2500 tulip_chipdescs[sc->tulip_chipid],
2501 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F,
2502 "unknown");
2503 } else {
2504 /*
2505 * Make sure there won't be any interrupts or such...
2506 */
2507 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2508 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at
2509 33MHz that comes to two microseconds but wait a
2510 bit longer anyways) */
2511#if defined(__NetBSD__)
2512 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2513 sc->tulip_ih = pci_map_int(pa->pa_tag, PCI_IPL_NET, tulip_intr, sc);
2514 if (sc->tulip_ih == NULL) {
2515 printf("%s%d: couldn't map interrupt\n",
2516 sc->tulip_name, sc->tulip_unit);
2517 return;
2518 }
2519#if defined(__i386__)
2520 /* gross but netbsd won't print the irq otherwise */
2521 printf(" irq %d", ((struct intrhand *) sc->tulip_ih)->ih_irq);
2522#endif
2523 }
2524 sc->tulip_ats = shutdownhook_establish(tulip_pci_shutdown, sc);
2525 if (sc->tulip_ats == NULL)
2526 printf("%s%d: warning: couldn't establish shutdown hook\n",
2527 sc->tulip_name, sc->tulip_unit);
2528#endif
2529#if defined(__FreeBSD__)
2530 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2531 if (!pci_map_int(config_id, tulip_intr, (void*) sc, &net_imask)) {
2532 printf("%s%d: couldn't map interrupt\n",
2533 sc->tulip_name, sc->tulip_unit);
2534 return;
2535 }
2536 }
2537#endif
2538#if defined(__bsdi__)
2539 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) {
2540 isa_establish(&sc->tulip_id, &sc->tulip_dev);
2541
2542 sc->tulip_ih.ih_fun = tulip_intr;
2543 sc->tulip_ih.ih_arg = (void *)sc;
2544 intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET);
2545 }
2546
2547 sc->tulip_ats.func = tulip_shutdown;
2548 sc->tulip_ats.arg = (void *) sc;
2549 atshutdown(&sc->tulip_ats, ATSH_ADD);
2550#endif
2551 tulip_reset(sc);
2552 tulip_attach(sc);
2553 }
2554}
2555#endif /* NDE > 0 */