Annotation of sys/arch/mvme88k/stand/sboot/if_le.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: if_le.c,v 1.4 2006/05/16 22:52:26 miod Exp $ */
2:
3: /*
4: * Copyright (c) 1995 Theo de Raadt
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16: * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: * SUCH DAMAGE.
26: *
27: * Copyright (c) 1993 Adam Glass
28: * All rights reserved.
29: *
30: * Redistribution and use in source and binary forms, with or without
31: * modification, are permitted provided that the following conditions
32: * are met:
33: * 1. Redistributions of source code must retain the above copyright
34: * notice, this list of conditions and the following disclaimer.
35: * 2. Redistributions in binary form must reproduce the above copyright
36: * notice, this list of conditions and the following disclaimer in the
37: * documentation and/or other materials provided with the distribution.
38: * 3. All advertising materials mentioning features or use of this software
39: * must display the following acknowledgement:
40: * This product includes software developed by Adam Glass.
41: * 4. The name of the Author may not be used to endorse or promote products
42: * derived from this software without specific prior written permission.
43: *
44: * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
45: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54: * SUCH DAMAGE.
55: */
56:
57: #include <sys/cdefs.h>
58: #include "sboot.h"
59: #include "if_lereg.h"
60:
61: struct {
62: struct lereg1 *sc_r1; /* LANCE registers */
63: struct lereg2 *sc_r2; /* RAM */
64: int next_rmd;
65: int next_tmd;
66: } le_softc;
67:
68: void
69: le_error(str, ler1)
70: char *str;
71: struct lereg1 *ler1;
72: {
73: /* ler1->ler1_rap = LE_CSRO done in caller */
74: if (ler1->ler1_rdp & LE_C0_BABL) {
75: printf("le0: been babbling, found by '%s'\n", str);
76: callrom();
77: }
78: if (ler1->ler1_rdp & LE_C0_CERR) {
79: ler1->ler1_rdp = LE_C0_CERR;
80: }
81: if (ler1->ler1_rdp & LE_C0_MISS) {
82: ler1->ler1_rdp = LE_C0_MISS;
83: }
84: if (ler1->ler1_rdp & LE_C0_MERR) {
85: printf("le0: memory error in '%s'\n", str);
86: callrom();
87: }
88: }
89:
90: void
91: le_reset(myea)
92: u_char *myea;
93: {
94: struct lereg1 *ler1 = le_softc.sc_r1;
95: struct lereg2 *ler2 = le_softc.sc_r2;
96: unsigned int a;
97: int timo = 100000, stat, i;
98:
99: ler1->ler1_rap = LE_CSR0;
100: ler1->ler1_rdp = LE_C0_STOP; /* do nothing until we are finished */
101:
102: bzero(ler2, sizeof(*ler2));
103:
104: ler2->ler2_mode = LE_MODE_NORMAL;
105: ler2->ler2_padr[0] = myea[1];
106: ler2->ler2_padr[1] = myea[0];
107: ler2->ler2_padr[2] = myea[3];
108: ler2->ler2_padr[3] = myea[2];
109: ler2->ler2_padr[4] = myea[5];
110: ler2->ler2_padr[5] = myea[4];
111:
112:
113: ler2->ler2_ladrf0 = 0;
114: ler2->ler2_ladrf1 = 0;
115:
116: a = (u_int) ler2->ler2_rmd;
117: ler2->ler2_rlen = LE_RLEN | (a >> 16);
118: ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
119:
120: a = (u_int) ler2->ler2_tmd;
121: ler2->ler2_tlen = LE_TLEN | (a >> 16);
122: ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
123:
124: ler1->ler1_rap = LE_CSR1;
125: a = (u_int) ler2;
126: ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
127: ler1->ler1_rap = LE_CSR2;
128: ler1->ler1_rdp = a >> 16;
129:
130: for (i = 0; i < LERBUF; i++) {
131: a = (u_int) & ler2->ler2_rbuf[i];
132: ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
133: ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
134: ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
135: ler2->ler2_rmd[i].rmd2 = -LEMTU;
136: ler2->ler2_rmd[i].rmd3 = 0;
137: }
138: for (i = 0; i < LETBUF; i++) {
139: a = (u_int) & ler2->ler2_tbuf[i];
140: ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
141: ler2->ler2_tmd[i].tmd1_bits = 0;
142: ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
143: ler2->ler2_tmd[i].tmd2 = 0;
144: ler2->ler2_tmd[i].tmd3 = 0;
145: }
146:
147: ler1->ler1_rap = LE_CSR3;
148: ler1->ler1_rdp = LE_C3_BSWP;
149:
150: ler1->ler1_rap = LE_CSR0;
151: ler1->ler1_rdp = LE_C0_INIT;
152: do {
153: if (--timo == 0) {
154: printf("le0: init timeout, stat = 0x%x\n", stat);
155: break;
156: }
157: stat = ler1->ler1_rdp;
158: } while ((stat & LE_C0_IDON) == 0);
159:
160: ler1->ler1_rdp = LE_C0_IDON;
161: le_softc.next_rmd = 0;
162: le_softc.next_tmd = 0;
163: ler1->ler1_rap = LE_CSR0;
164: ler1->ler1_rdp = LE_C0_STRT;
165: }
166:
167: int
168: le_poll(pkt, len)
169: void *pkt;
170: int len;
171: {
172: struct lereg1 *ler1 = le_softc.sc_r1;
173: struct lereg2 *ler2 = le_softc.sc_r2;
174: unsigned int a;
175: int length;
176: struct lermd *rmd;
177:
178: ler1->ler1_rap = LE_CSR0;
179: if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
180: ler1->ler1_rdp = LE_C0_RINT;
181: rmd = &ler2->ler2_rmd[le_softc.next_rmd];
182: if (rmd->rmd1_bits & LE_R1_OWN) {
183: return (0);
184: }
185: if (ler1->ler1_rdp & LE_C0_ERR)
186: le_error("le_poll", ler1);
187: if (rmd->rmd1_bits & LE_R1_ERR) {
188: printf("le0_poll: rmd status 0x%x\n", rmd->rmd1_bits);
189: length = 0;
190: goto cleanup;
191: }
192: if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)) {
193: printf("le_poll: chained packet\n");
194: callrom();
195: }
196: length = rmd->rmd3;
197: if (length >= LEMTU) {
198: length = 0;
199: printf("csr0 when bad things happen: %x\n", ler1->ler1_rdp);
200: callrom();
201: goto cleanup;
202: }
203: if (!length)
204: goto cleanup;
205: length -= 4;
206: if (length > 0)
207: bcopy((char *) &ler2->ler2_rbuf[le_softc.next_rmd], pkt, length);
208:
209: cleanup:
210: a = (u_int) & ler2->ler2_rbuf[le_softc.next_rmd];
211: rmd->rmd0 = a & LE_ADDR_LOW_MASK;
212: rmd->rmd1_hadr = a >> 16;
213: rmd->rmd2 = -LEMTU;
214: le_softc.next_rmd =
215: (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
216: rmd->rmd1_bits = LE_R1_OWN;
217: return length;
218: }
219:
220: int
221: le_put(pkt, len)
222: u_char *pkt;
223: size_t len;
224: {
225: struct lereg1 *ler1 = le_softc.sc_r1;
226: struct lereg2 *ler2 = le_softc.sc_r2;
227: struct letmd *tmd;
228: int timo = 100000, stat, i;
229: unsigned int a;
230:
231: ler1->ler1_rap = LE_CSR0;
232: if (ler1->ler1_rdp & LE_C0_ERR)
233: le_error("le_put(way before xmit)", ler1);
234: tmd = &ler2->ler2_tmd[le_softc.next_tmd];
235: while (tmd->tmd1_bits & LE_T1_OWN) {
236: printf("le0: output buffer busy\n");
237: }
238: bcopy(pkt, (char *) ler2->ler2_tbuf[le_softc.next_tmd], len);
239: if (len < 64)
240: tmd->tmd2 = -64;
241: else
242: tmd->tmd2 = -len;
243: tmd->tmd3 = 0;
244: if (ler1->ler1_rdp & LE_C0_ERR)
245: le_error("le_put(before xmit)", ler1);
246: tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
247: a = (u_int) & ler2->ler2_tbuf[le_softc.next_tmd];
248: tmd->tmd0 = a & LE_ADDR_LOW_MASK;
249: tmd->tmd1_hadr = a >> 16;
250: ler1->ler1_rdp = LE_C0_TDMD;
251: if (ler1->ler1_rdp & LE_C0_ERR)
252: le_error("le_put(after xmit)", ler1);
253: do {
254: if (--timo == 0) {
255: printf("le0: transmit timeout, stat = 0x%x\n",
256: stat);
257: if (ler1->ler1_rdp & LE_C0_ERR)
258: le_error("le_put(timeout)", ler1);
259: break;
260: }
261: stat = ler1->ler1_rdp;
262: } while ((stat & LE_C0_TINT) == 0);
263: ler1->ler1_rdp = LE_C0_TINT;
264: if (ler1->ler1_rdp & LE_C0_ERR) {
265: if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS | LE_C0_MERR)) !=
266: LE_C0_CERR)
267: printf("le_put: xmit error, buf %d\n", le_softc.next_tmd);
268: le_error("le_put(xmit error)", ler1);
269: }
270: le_softc.next_tmd = 0;
271: /* (le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
272: if (tmd->tmd1_bits & LE_T1_ERR) {
273: printf("le0: transmit error, error = 0x%x\n",
274: tmd->tmd3);
275: return -1;
276: }
277: return len;
278: }
279:
280: int
281: le_get(pkt, len, timeout)
282: u_char *pkt;
283: size_t len;
284: u_long timeout;
285: {
286: int cc;
287: int now, then;
288: int stopat = time() + timeout;
289: then = 0;
290:
291: cc = 0;
292: while ((now = time()) < stopat && !cc) {
293: cc = le_poll(pkt, len);
294: if (then != now) {
295: #ifdef LE_DEBUG
296: printf("%d \r", stopat - now);
297: #endif
298: then = now;
299: }
300: if (cc && (pkt[0] != myea[0] || pkt[1] != myea[1] ||
301: pkt[2] != myea[2] || pkt[3] != myea[3] ||
302: pkt[4] != myea[4] || pkt[5] != myea[5])) {
303: cc = 0; /* ignore broadcast / multicast */
304: #ifdef LE_DEBUG
305: printf("reject (%d sec left)\n", stopat - now);
306: #endif
307: }
308: }
309: #ifdef LE_DEBUG
310: printf("\n");
311: #endif
312: return cc;
313: }
314:
315: void
316: le_init()
317: {
318: caddr_t addr;
319: int *ea = (int *) LANCE_ADDR;
320: u_long *eram = (u_long *) ERAM_ADDR;
321: u_long e = *ea;
322: if ((e & 0x2fffff00) == 0x2fffff00) {
323: printf("ERROR: ethernet address not set! Use LSAD.\n");
324: callrom();
325: }
326: myea[0] = 0x08;
327: myea[1] = 0x00;
328: myea[2] = 0x3e;
329: e = e >> 8;
330: myea[5] = e & 0xff;
331: e = e >> 8;
332: myea[4] = e & 0xff;
333: e = e >> 8;
334: myea[3] = e;
335: printf("le0: ethernet address: %x:%x:%x:%x:%x:%x\n",
336: myea[0], myea[1], myea[2], myea[3], myea[4], myea[5]);
337: bzero(&le_softc, sizeof(le_softc));
338: le_softc.sc_r1 = (struct lereg1 *) LANCE_REG_ADDR;
339: le_softc.sc_r2 = (struct lereg2 *) (*eram - (1024 * 1024));
340: le_reset(myea);
341: }
342:
343: void
344: le_end()
345: {
346: struct lereg1 *ler1 = le_softc.sc_r1;
347:
348: ler1->ler1_rap = LE_CSR0;
349: ler1->ler1_rdp = LE_C0_STOP;
350: }
CVSweb