if_ae.c revision 1.66 1 1.66 thorpej /* $NetBSD: if_ae.c,v 1.66 1997/11/02 00:29:56 thorpej Exp $ */
2 1.14 cgd
3 1.1 briggs /*
4 1.21 briggs * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
5 1.21 briggs * adapters.
6 1.1 briggs *
7 1.21 briggs * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
8 1.1 briggs *
9 1.21 briggs * Copyright (C) 1993, David Greenman. This software may be used, modified,
10 1.21 briggs * copied, distributed, and sold, in both source and binary form provided that
11 1.21 briggs * the above copyright and these terms are retained. Under no circumstances is
12 1.21 briggs * the author responsible for the proper functioning of this software, nor does
13 1.21 briggs * the author assume any responsibility for damages incurred with its use.
14 1.1 briggs */
15 1.1 briggs
16 1.1 briggs #include "bpfilter.h"
17 1.1 briggs
18 1.9 briggs #include <sys/param.h>
19 1.9 briggs #include <sys/systm.h>
20 1.64 scottr #include <sys/device.h>
21 1.9 briggs #include <sys/mbuf.h>
22 1.9 briggs #include <sys/socket.h>
23 1.1 briggs
24 1.5 briggs #include <net/if.h>
25 1.66 thorpej #include <net/if_media.h>
26 1.58 is #include <net/if_ether.h>
27 1.1 briggs
28 1.51 scottr #include <machine/bus.h>
29 1.51 scottr
30 1.31 cgd #include <dev/ic/dp8390reg.h>
31 1.64 scottr #include <dev/ic/dp8390var.h>
32 1.65 scottr #include <mac68k/dev/if_aevar.h>
33 1.8 briggs
34 1.52 scottr struct cfdriver ae_cd = {
35 1.52 scottr NULL, "ae", DV_IFNET
36 1.52 scottr };
37 1.12 lkestel
38 1.52 scottr int
39 1.52 scottr ae_size_card_memory(bst, bsh, ofs)
40 1.52 scottr bus_space_tag_t bst;
41 1.52 scottr bus_space_handle_t bsh;
42 1.52 scottr int ofs;
43 1.8 briggs {
44 1.52 scottr int i1, i2, i3, i4;
45 1.15 briggs
46 1.15 briggs /*
47 1.15 briggs * banks; also assume it will generally mirror in upper banks
48 1.15 briggs * if not installed.
49 1.15 briggs */
50 1.57 scottr i1 = (8192 * 0);
51 1.57 scottr i2 = (8192 * 1);
52 1.57 scottr i3 = (8192 * 2);
53 1.57 scottr i4 = (8192 * 3);
54 1.21 briggs
55 1.52 scottr bus_space_write_2(bst, bsh, ofs + i1, 0x1111);
56 1.52 scottr bus_space_write_2(bst, bsh, ofs + i2, 0x2222);
57 1.52 scottr bus_space_write_2(bst, bsh, ofs + i3, 0x3333);
58 1.52 scottr bus_space_write_2(bst, bsh, ofs + i4, 0x4444);
59 1.52 scottr
60 1.52 scottr if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
61 1.52 scottr bus_space_read_2(bst, bsh, ofs + i2) == 0x2222 &&
62 1.52 scottr bus_space_read_2(bst, bsh, ofs + i3) == 0x3333 &&
63 1.52 scottr bus_space_read_2(bst, bsh, ofs + i4) == 0x4444)
64 1.25 briggs return 8192 * 4;
65 1.21 briggs
66 1.52 scottr if ((bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 &&
67 1.52 scottr bus_space_read_2(bst, bsh, ofs + i2) == 0x2222) ||
68 1.52 scottr (bus_space_read_2(bst, bsh, ofs + i1) == 0x3333 &&
69 1.52 scottr bus_space_read_2(bst, bsh, ofs + i2) == 0x4444))
70 1.25 briggs return 8192 * 2;
71 1.15 briggs
72 1.52 scottr if (bus_space_read_2(bst, bsh, ofs + i1) == 0x1111 ||
73 1.52 scottr bus_space_read_2(bst, bsh, ofs + i1) == 0x4444)
74 1.21 briggs return 8192;
75 1.15 briggs
76 1.21 briggs return 0;
77 1.54 scottr }
78 1.54 scottr
79 1.54 scottr /*
80 1.64 scottr * Zero memory and verify that it is clear. The only difference between
81 1.64 scottr * this and the default test_mem function is that the DP8390-based NuBus
82 1.64 scottr * cards * apparently require word-wide writes and byte-wide reads, an
83 1.64 scottr * `interesting' combination.
84 1.54 scottr */
85 1.56 scottr int
86 1.64 scottr ae_test_mem(sc)
87 1.64 scottr struct dp8390_softc *sc;
88 1.54 scottr {
89 1.64 scottr bus_space_tag_t buft = sc->sc_buft;
90 1.64 scottr bus_space_handle_t bufh = sc->sc_bufh;
91 1.54 scottr int i;
92 1.54 scottr
93 1.64 scottr bus_space_set_region_2(buft, bufh, sc->mem_start, 0,
94 1.64 scottr sc->mem_size / 2);
95 1.54 scottr
96 1.56 scottr for (i = 0; i < sc->mem_size; ++i) {
97 1.56 scottr if (bus_space_read_1(sc->sc_buft, sc->sc_bufh, i)) {
98 1.64 scottr printf(": failed to clear NIC buffer at offset %x - "
99 1.64 scottr "check configuration\n", (sc->mem_start + i));
100 1.56 scottr return 1;
101 1.56 scottr }
102 1.56 scottr }
103 1.54 scottr
104 1.56 scottr return 0;
105 1.8 briggs }
106 1.8 briggs
107 1.1 briggs /*
108 1.64 scottr * Copy packet from mbuf to the board memory Currently uses an extra
109 1.64 scottr * buffer/extra memory copy, unless the whole packet fits in one mbuf.
110 1.21 briggs *
111 1.64 scottr * As in the test_mem function, we use word-wide writes.
112 1.21 briggs */
113 1.52 scottr int
114 1.64 scottr ae_write_mbuf(sc, m, buf)
115 1.64 scottr struct dp8390_softc *sc;
116 1.21 briggs struct mbuf *m;
117 1.52 scottr int buf;
118 1.21 briggs {
119 1.21 briggs u_char *data, savebyte[2];
120 1.52 scottr int len, wantbyte;
121 1.25 briggs u_short totlen = 0;
122 1.21 briggs
123 1.21 briggs wantbyte = 0;
124 1.21 briggs
125 1.34 briggs for (; m ; m = m->m_next) {
126 1.21 briggs data = mtod(m, u_char *);
127 1.21 briggs len = m->m_len;
128 1.21 briggs totlen += len;
129 1.21 briggs if (len > 0) {
130 1.21 briggs /* Finish the last word. */
131 1.21 briggs if (wantbyte) {
132 1.21 briggs savebyte[1] = *data;
133 1.55 scottr bus_space_write_region_2(sc->sc_buft,
134 1.55 scottr sc->sc_bufh, buf, savebyte, 1);
135 1.21 briggs buf += 2;
136 1.21 briggs data++;
137 1.21 briggs len--;
138 1.21 briggs wantbyte = 0;
139 1.21 briggs }
140 1.21 briggs /* Output contiguous words. */
141 1.21 briggs if (len > 1) {
142 1.55 scottr bus_space_write_region_2(sc->sc_buft,
143 1.55 scottr sc->sc_bufh, buf, data, len >> 1);
144 1.21 briggs buf += len & ~1;
145 1.21 briggs data += len & ~1;
146 1.21 briggs len &= 1;
147 1.21 briggs }
148 1.21 briggs /* Save last byte, if necessary. */
149 1.21 briggs if (len == 1) {
150 1.21 briggs savebyte[0] = *data;
151 1.21 briggs wantbyte = 1;
152 1.21 briggs }
153 1.21 briggs }
154 1.21 briggs }
155 1.21 briggs
156 1.21 briggs if (wantbyte) {
157 1.21 briggs savebyte[1] = 0;
158 1.55 scottr bus_space_write_region_2(sc->sc_buft, sc->sc_bufh,
159 1.52 scottr buf, savebyte, 1);
160 1.21 briggs }
161 1.21 briggs return (totlen);
162 1.1 briggs }
163