if_ae.c revision 1.75.6.1 1 /* $NetBSD: if_ae.c,v 1.75.6.1 2006/09/11 21:26:54 tron Exp $ */
2
3 /*
4 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
5 * adapters.
6 *
7 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
8 *
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.
14 */
15
16 #include <sys/cdefs.h>
17 __KERNEL_RCSID(0, "$NetBSD: if_ae.c,v 1.75.6.1 2006/09/11 21:26:54 tron Exp $");
18
19 #include "bpfilter.h"
20
21 #include <sys/param.h>
22 #include <sys/systm.h>
23 #include <sys/device.h>
24 #include <sys/mbuf.h>
25 #include <sys/socket.h>
26
27 #include <net/if.h>
28 #include <net/if_media.h>
29 #include <net/if_ether.h>
30
31 #include <machine/bus.h>
32
33 #include <dev/ic/dp8390reg.h>
34 #include <dev/ic/dp8390var.h>
35 #include <mac68k/dev/if_aevar.h>
36
37 #define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
38
39 int
40 ae_size_card_memory(bst, bsh, ofs)
41 bus_space_tag_t bst;
42 bus_space_handle_t bsh;
43 int ofs;
44 {
45 int i1, i2, i3, i4, i8;
46
47 /*
48 * banks; also assume it will generally mirror in upper banks
49 * if not installed.
50 */
51 i1 = (8192 * 0);
52 i2 = (8192 * 1);
53 i3 = (8192 * 2);
54 i4 = (8192 * 3);
55
56 i8 = (8192 * 4);
57
58 bus_space_write_2(bst, bsh, ofs + i8, 0x8888);
59 bus_space_write_2(bst, bsh, ofs + i4, 0x4444);
60 bus_space_write_2(bst, bsh, ofs + i3, 0x3333);
61 bus_space_write_2(bst, bsh, ofs + i2, 0x2222);
62 bus_space_write_2(bst, bsh, ofs + i1, 0x1111);
63
64 /*
65 * 1) If the memory range is decoded completely, it does not
66 * matter what we write first: High tags written into
67 * the void are lost.
68 * 2) If the memory range is not decoded completely (banks are
69 * mirrored), high tags are overwritten by lower ones.
70 * 3) Lazy implementation of pathological cases - none found yet.
71 */
72
73 if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
74 bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
75 bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
76 bus_space_read_2(bst, bsh, ofs + i4) == 0x4444 &&
77 bus_space_read_2(bst, bsh, ofs + i8) == 0x8888)
78 return 8192 * 8;
79
80 if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
81 bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
82 bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
83 bus_space_read_2(bst, bsh, ofs + i4) == 0x4444)
84 return 8192 * 4;
85
86 if ((bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
87 bus_space_read_2(bst, bsh, ofs + i2) == 0x2222) ||
88 (bus_space_read_2(bst, bsh, ofs + i1) == 0x3333 &&
89 bus_space_read_2(bst, bsh, ofs + i2) == 0x4444))
90 return 8192 * 2;
91
92 if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 ||
93 bus_space_read_2(bst, bsh, ofs + i1) == 0x4444)
94 return 8192;
95
96 return 0;
97 }
98
99 /*
100 * Zero memory and verify that it is clear. The only difference between
101 * this and the default test_mem function is that the DP8390-based NuBus
102 * cards * apparently require word-wide writes and byte-wide reads, an
103 * `interesting' combination.
104 */
105 int
106 ae_test_mem(sc)
107 struct dp8390_softc *sc;
108 {
109 bus_space_tag_t buft = sc->sc_buft;
110 bus_space_handle_t bufh = sc->sc_bufh;
111 int i;
112
113 bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
114 sc->mem_size / 2);
115
116 for (i = 0; i < sc->mem_size; ++i) {
117 if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) {
118 printf(": failed to clear NIC buffer at offset %x - "
119 "check configuration\n", (sc->mem_start + i));
120 return 1;
121 }
122 }
123
124 return 0;
125 }
126
127 /*
128 * Copy packet from mbuf to the board memory Currently uses an extra
129 * buffer/extra memory copy, unless the whole packet fits in one mbuf.
130 *
131 * As in the test_mem function, we use word-wide writes.
132 */
133 int
134 ae_write_mbuf(sc, m, buf)
135 struct dp8390_softc *sc;
136 struct mbuf *m;
137 int buf;
138 {
139 u_char *data, savebyte[2];
140 int len, wantbyte;
141 u_short totlen = 0;
142
143 wantbyte = 0;
144
145 for (; m ; m = m->m_next) {
146 data = mtod(m, u_char *);
147 len = m->m_len;
148 totlen += len;
149 if (len > 0) {
150 /* Finish the last word. */
151 if (wantbyte) {
152 savebyte[1] = *data;
153 bus_space_write_region_2(sc->sc_buft,
154 sc->sc_bufh, buf, (u_int16_t *)savebyte, 1);
155 buf += 2;
156 data++;
157 len--;
158 wantbyte = 0;
159 }
160 /* Output contiguous words. */
161 if (len > 1) {
162 bus_space_write_region_2(
163 sc->sc_buft, sc->sc_bufh,
164 buf, (u_int16_t *)data, len >> 1);
165 buf += len & ~1;
166 data += len & ~1;
167 len &= 1;
168 }
169 /* Save last byte, if necessary. */
170 if (len == 1) {
171 savebyte[0] = *data;
172 wantbyte = 1;
173 }
174 }
175 }
176
177 len = ETHER_PAD_LEN - totlen;
178 if (wantbyte) {
179 savebyte[1] = 0;
180 bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
181 buf, (u_int16_t *)savebyte, 1);
182 buf += 2;
183 if (len > 0)
184 totlen++;
185 len--;
186 }
187 /* if sent data is shorter than EHTER_PAD_LEN, put 0 to padding */
188 if (len > 0) {
189 bus_space_set_region_2(sc->sc_buft, sc->sc_bufh, buf, 0,
190 len >> 1);
191 totlen = ETHER_PAD_LEN;
192 }
193 return (totlen);
194 }
195