summaryrefslogtreecommitdiff
path: root/sys/arch/sun3/dev/if_ie_subr.c
blob: 71af7166f5e5b6b2b3faac83d3a3460e9e4f3c0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*	$NetBSD: if_ie_subr.c,v 1.7 1995/09/26 04:02:04 gwr Exp $	*/

/*
 * Copyright (c) 1994 Gordon W. Ross
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Gordon Ross
 * 4. The name of the Author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Machine-dependent glue for the Intel Ethernet (ie) driver.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <net/if.h>

#ifdef INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#endif

#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <machine/dvma.h>
#include <machine/isr.h>
#include <machine/obio.h>
#include <machine/idprom.h>
#include <machine/vmparam.h>

#include "i82586.h"
#include "if_ie.h"
#include "if_ie_subr.h"

static void ie_obreset __P((struct ie_softc *));
static void ie_obattend __P((struct ie_softc *));
static void ie_obrun __P((struct ie_softc *));
static void ie_vmereset __P((struct ie_softc *));
static void ie_vmeattend __P((struct ie_softc *));
static void ie_vmerun __P((struct ie_softc *));

/*
 * zero/copy functions: OBIO can use the normal functions, but VME
 *    must do only byte or half-word (16 bit) accesses...
 */
static void wcopy(), wzero();

int
ie_md_match(parent, vcf, args)
	struct device *parent;
	void *vcf, *args;
{
	struct cfdata *cf = vcf;
	struct confargs *ca = args;
	int x, sz;

	switch (ca->ca_bustype) {

	case BUS_OBIO:
		if (ca->ca_paddr == -1)
			ca->ca_paddr = OBIO_INTEL_ETHER;
		sz = 1;
		break;

	case BUS_VME16:
		/* No default VME address. */
		if (ca->ca_paddr == -1)
			return(0);
		sz = 2;
		break;

	default:
		return (0);
	}

	/* Default interrupt level. */
	if (ca->ca_intpri == -1)
		ca->ca_intpri = 3;

	x = bus_peek(ca->ca_bustype, ca->ca_paddr, sz);
	return (x != -1);
}

void
ie_md_attach(parent, self, args)
	struct device *parent;
	struct device *self;
	void *args;
{
	struct ie_softc *sc = (void *) self;
	struct confargs *ca = args;
	caddr_t mem, reg;

	/*
	 * *note*: we don't detect the difference between a VME3E and
	 * a multibus/vme card.   if you want to use a 3E you'll have
	 * to fix this.
	 */

	switch (ca->ca_bustype) {
	case BUS_OBIO:
		sc->hard_type = IE_OBIO;
		sc->reset_586 = ie_obreset;
		sc->chan_attn = ie_obattend;
		sc->run_586 = ie_obrun;
		sc->sc_bcopy = bcopy;
		sc->sc_bzero = bzero;
		sc->sc_iobase = (caddr_t)DVMA_OBIO_SLAVE_BASE;
		sc->sc_msize = MEMSIZE;

		/* Map in the control register. */
		reg = obio_alloc(ca->ca_paddr, OBIO_INTEL_ETHER_SIZE);
		if (reg == NULL)
			panic(": not enough obio space\n");
		sc->sc_reg = reg;

		/* Allocate "shared" memory (DVMA space). */
		mem = dvma_malloc(sc->sc_msize);
		if (mem == NULL)
			panic(": not enough dvma space");
		sc->sc_maddr = mem;

		/* This is a FIXED address, in a page left by the PROM. */
		sc->scp = (volatile struct ie_sys_conf_ptr *)
		    (sc->sc_iobase + IE_SCP_ADDR);

		/* Install interrupt handler. */
		isr_add_autovect(ie_intr, (void *)sc, ca->ca_intpri);

		break;

	case BUS_VME16: {
		volatile struct ievme *iev;
		u_long  rampaddr;
		int     lcv;

		sc->hard_type = IE_VME;
		sc->reset_586 = ie_vmereset;
		sc->chan_attn = ie_vmeattend;
		sc->run_586 = ie_vmerun;
		sc->sc_bcopy = wcopy;
		sc->sc_bzero = wzero;
		sc->sc_msize = MEMSIZE;
		sc->sc_reg = bus_mapin(ca->ca_bustype, ca->ca_paddr,
							   sizeof(struct ievme));

		iev = (volatile struct ievme *) sc->sc_reg;
		/* top 12 bits */
		rampaddr = ca->ca_paddr & 0xfff00000;
		/* 4 more */
		rampaddr |= ((iev->status & IEVME_HADDR) << 16);
		sc->sc_maddr = bus_mapin(ca->ca_bustype, rampaddr, sc->sc_msize);
		sc->sc_iobase = sc->sc_maddr;
		iev->pectrl = iev->pectrl | IEVME_PARACK; /* clear to start */

		sc->scp = (volatile struct ie_sys_conf_ptr *)
		    (sc->sc_iobase + (IE_SCP_ADDR & (IEVME_PAGESIZE - 1)));

		/*
		 * set up mappings, direct map except for last page
		 * which is mapped at zero and at high address (for
		 * scp), zero ram
		 */

		for (lcv = 0; lcv < IEVME_MAPSZ - 1; lcv++)
			iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
		iev->pgmap[IEVME_MAPSZ - 1] = IEVME_SBORDR | IEVME_OBMEM | 0;
		(sc->sc_bzero)(sc->sc_maddr, sc->sc_msize);

		isr_add_vectored(ie_intr, (void *)sc,
						 ca->ca_intpri,
						 ca->ca_intvec);
		break;
	}

	default:
		printf("unknown\n");
		return;
	}

	/*
	 * set up pointers to data structures and buffer area.
	 */
	sc->iscp = (volatile struct ie_int_sys_conf_ptr *)
	    sc->sc_maddr;
	sc->scb = (volatile struct ie_sys_ctl_block *)
	    sc->sc_maddr + sizeof(struct ie_int_sys_conf_ptr);

	/*
	 * rest of first page is unused, rest of ram
	 * for buffers
	 */
	sc->buf_area = sc->sc_maddr + IEVME_PAGESIZE;
	sc->buf_area_sz = sc->sc_msize - IEVME_PAGESIZE;

	idprom_etheraddr(sc->sc_addr); /* ethernet addr */
}


/*
 * MULTIBUS/VME support
 */
void 
ie_vmereset(sc)
	struct ie_softc *sc;
{
	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
	iev->status = IEVME_RESET;
	delay(100);		/* XXX could be shorter? */
	iev->status = 0;
}

void 
ie_vmeattend(sc)
	struct ie_softc *sc;
{
	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;

	iev->status |= IEVME_ATTEN;	/* flag! */
	iev->status &= ~IEVME_ATTEN;	/* down. */
}

void 
ie_vmerun(sc)
	struct ie_softc *sc;
{
	volatile struct ievme *iev = (struct ievme *) sc->sc_reg;

	iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
}

/*
 * onboard ie support
 */
void
ie_obreset(sc)
	struct ie_softc *sc;
{
	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
	ieo->obctrl = 0;
	delay(100);			/* XXX could be shorter? */
	ieo->obctrl = IEOB_NORSET;
}
void
ie_obattend(sc)
	struct ie_softc *sc;
{
	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;

	ieo->obctrl |= IEOB_ATTEN;	/* flag! */
	ieo->obctrl &= ~IEOB_ATTEN;	/* down. */
}

void
ie_obrun(sc)
	struct ie_softc *sc;
{
	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;

	ieo->obctrl |= (IEOB_ONAIR|IEOB_IENAB|IEOB_NORSET);
}

/*
 * wcopy/wzero - like bcopy/bzero but largest access is 16-bits,
 * and also does byte swaps...
 * XXX - Would be nice to have asm versions in some library...
 */

static void
wzero(vb, l)
	void *vb;
	u_int l;
{
	u_char *b = vb;
	u_char *be = b + l;
	u_short *sp;

	if (l == 0)
		return;

	/* front, */
	if ((u_long)b & 1)
		*b++ = 0;

	/* back, */
	if (b != be && ((u_long)be & 1) != 0) {
		be--;
		*be = 0;
	}

	/* and middle. */
	sp = (u_short *)b;
	while (sp != (u_short *)be)
		*sp++ = 0;
}

static void
wcopy(vb1, vb2, l)
	const void *vb1;
	void *vb2;
	u_int l;
{
	const u_char *b1e, *b1 = vb1;
	u_char *b2 = vb2;
	u_short *sp;
	int bstore = 0;

	if (l == 0)
		return;

	/* front, */
	if ((u_long)b1 & 1) {
		*b2++ = *b1++;
		l--;
	}

	/* middle, */
	sp = (u_short *)b1;
	b1e = b1 + l;
	if (l & 1)
		b1e--;
	bstore = (u_long)b2 & 1;

	while (sp < (u_short *)b1e) {
		if (bstore) {
			b2[1] = *sp & 0xff;
			b2[0] = *sp >> 8;
		} else
			*((short *)b2) = *sp;
		sp++;
		b2 += 2;
	}

	/* and back. */
	if (l & 1)
		*b2 = *b1e;
}