1 /* $NetBSD: if_ae.c,v 1.78 2006/09/09 06:25:08 tsutsui Exp $ */
4 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
7 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
9 * Copyright (C) 1993, David Greenman. This software may be used, modified,
10 * copied, distributed, and sold, in both source and binary form provided that
11 * the above copyright and these terms are retained. Under no circumstances is
12 * the author responsible for the proper functioning of this software, nor does
13 * the author assume any responsibility for damages incurred with its use.
16 #include <sys/cdefs.h>
17 __KERNEL_RCSID(0, "$NetBSD: if_ae.c,v 1.78 2006/09/09 06:25:08 tsutsui Exp $");
21 #include <sys/param.h>
22 #include <sys/systm.h>
23 #include <sys/device.h>
25 #include <sys/socket.h>
28 #include <net/if_media.h>
29 #include <net/if_ether.h>
31 #include <machine/bus.h>
33 #include <dev/ic/dp8390reg.h>
34 #include <dev/ic/dp8390var.h>
35 #include <mac68k/dev/if_aevar.h>
37 #define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
40 ae_size_card_memory(bus_space_tag_t bst
, bus_space_handle_t bsh
, int ofs
)
42 int i1
, i2
, i3
, i4
, i8
;
45 * banks; also assume it will generally mirror in upper banks
55 bus_space_write_2(bst
, bsh
, ofs
+ i8
, 0x8888);
56 bus_space_write_2(bst
, bsh
, ofs
+ i4
, 0x4444);
57 bus_space_write_2(bst
, bsh
, ofs
+ i3
, 0x3333);
58 bus_space_write_2(bst
, bsh
, ofs
+ i2
, 0x2222);
59 bus_space_write_2(bst
, bsh
, ofs
+ i1
, 0x1111);
62 * 1) If the memory range is decoded completely, it does not
63 * matter what we write first: High tags written into
65 * 2) If the memory range is not decoded completely (banks are
66 * mirrored), high tags are overwritten by lower ones.
67 * 3) Lazy implementation of pathological cases - none found yet.
70 if (bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x1111 &&
71 bus_space_read_2(bst
, bsh
, ofs
+ i2
) == 0x2222 &&
72 bus_space_read_2(bst
, bsh
, ofs
+ i3
) == 0x3333 &&
73 bus_space_read_2(bst
, bsh
, ofs
+ i4
) == 0x4444 &&
74 bus_space_read_2(bst
, bsh
, ofs
+ i8
) == 0x8888)
77 if (bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x1111 &&
78 bus_space_read_2(bst
, bsh
, ofs
+ i2
) == 0x2222 &&
79 bus_space_read_2(bst
, bsh
, ofs
+ i3
) == 0x3333 &&
80 bus_space_read_2(bst
, bsh
, ofs
+ i4
) == 0x4444)
83 if ((bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x1111 &&
84 bus_space_read_2(bst
, bsh
, ofs
+ i2
) == 0x2222) ||
85 (bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x3333 &&
86 bus_space_read_2(bst
, bsh
, ofs
+ i2
) == 0x4444))
89 if (bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x1111 ||
90 bus_space_read_2(bst
, bsh
, ofs
+ i1
) == 0x4444)
97 * Zero memory and verify that it is clear. The only difference between
98 * this and the default test_mem function is that the DP8390-based NuBus
99 * cards * apparently require word-wide writes and byte-wide reads, an
100 * `interesting' combination.
103 ae_test_mem(struct dp8390_softc
*sc
)
105 bus_space_tag_t buft
= sc
->sc_buft
;
106 bus_space_handle_t bufh
= sc
->sc_bufh
;
109 bus_space_set_region_2(buft
, bufh
, sc
->mem_start
, 0,
112 for (i
= 0; i
< sc
->mem_size
; ++i
) {
113 if (bus_space_read_1(sc
->sc_buft
, sc
->sc_bufh
, i
)) {
114 printf(": failed to clear NIC buffer at offset %x - "
115 "check configuration\n", (sc
->mem_start
+ i
));
124 * Copy packet from mbuf to the board memory Currently uses an extra
125 * buffer/extra memory copy, unless the whole packet fits in one mbuf.
127 * As in the test_mem function, we use word-wide writes.
130 ae_write_mbuf(struct dp8390_softc
*sc
, struct mbuf
*m
, int buf
)
132 u_char
*data
, savebyte
[2];
138 for (; m
; m
= m
->m_next
) {
139 data
= mtod(m
, u_char
*);
143 /* Finish the last word. */
146 bus_space_write_region_2(sc
->sc_buft
,
147 sc
->sc_bufh
, buf
, (u_int16_t
*)savebyte
, 1);
153 /* Output contiguous words. */
155 bus_space_write_region_2(
156 sc
->sc_buft
, sc
->sc_bufh
,
157 buf
, (u_int16_t
*)data
, len
>> 1);
162 /* Save last byte, if necessary. */
170 len
= ETHER_PAD_LEN
- totlen
;
173 bus_space_write_region_2(sc
->sc_buft
, sc
->sc_bufh
,
174 buf
, (u_int16_t
*)savebyte
, 1);
179 /* if sent data is shorter than EHTER_PAD_LEN, put 0 to padding */
181 bus_space_set_region_2(sc
->sc_buft
, sc
->sc_bufh
, buf
, 0,
183 totlen
= ETHER_PAD_LEN
;