summaryrefslogtreecommitdiff
path: root/sys/arch/hppa/gsc/if_ie_gsc.c
blob: a0aa41e9180e2f96e544198c68ec7416cad7b73d (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
/*	$OpenBSD: if_ie_gsc.c,v 1.1 1999/01/03 23:59:18 mickey Exp $	*/

/*
 * Copyright (c) 1998 Michael Shalayeff
 * 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 Michael Shalayeff.
 * 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.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/socket.h>
#include <sys/sockio.h>

#include <vm/vm.h>
#include <vm/vm_kern.h>
#include <vm/pmap.h>

#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_media.h>

#include <netinet/in.h>
#include <netinet/if_ether.h>

#include <machine/bus.h>
#include <machine/intr.h>
#include <machine/iomod.h>
#include <machine/autoconf.h>

#include <hppa/dev/cpudevs.h>
#include <hppa/gsc/gscbusvar.h>

#include <dev/ic/i82586reg.h>
#include <dev/ic/i82586var.h>

#define	IEGSC_GECKO	IEMD_FLAG0

struct ie_gsc_regs {
	u_int32_t	ie_reset;
	u_int32_t	ie_port;
#define	IE_PORT_RESET	0
#define	IE_PORT_TEST	1
#define	IE_PORT_SCP	2
#define	IE_PORT_DUMP	3
	u_int32_t	ie_attn;
};

#define	IE_SCB	0x001e
#define	IE_ISCP	0x0040
#define	IE_SCP	0x0060
#define	IE_BUF	0x1000
#define	IE_EBUF	IE_SIZE
#define	IE_SIZE	0x4000

int	ie_gsc_probe __P((struct device *, void *, void *));
void	ie_gsc_attach __P((struct device *, struct device *, void *));

struct cfattach ie_gsc_ca = {
	sizeof(struct ie_softc), ie_gsc_probe, ie_gsc_attach
};

static int ie_media[] = {
	IFM_ETHER | IFM_10_2,
};
#define	IE_NMEDIA	(sizeof(ie_media) / sizeof(ie_media[0]))

void ie_gsc_reset __P((struct ie_softc *sc, int what));
int ie_gsc_intrhook __P((struct ie_softc *sc, int what));
void ie_gsc_attend __P((struct ie_softc *sc));
void ie_gsc_run __P((struct ie_softc *sc));
u_int16_t ie_gsc_read16 __P((struct ie_softc *sc, int offset));
void ie_gsc_write16 __P((struct ie_softc *sc, int offset, u_int16_t v));
void ie_gsc_write24 __P((struct ie_softc *sc, int offset, int addr));
void ie_gsc_memcopyin __P((struct ie_softc *sc, void *p, int offset, size_t));
void ie_gsc_memcopyout __P((struct ie_softc *sc, const void *p, int, size_t));


void
ie_gsc_reset(sc, what)
	struct ie_softc *sc;
	int what;
{
	register volatile struct ie_gsc_regs *r = sc->sc_reg;

	r->ie_reset = 0;
}

void
ie_gsc_attend(sc)
	struct ie_softc *sc;
{
	register volatile struct ie_gsc_regs *r = sc->sc_reg;

	r->ie_attn = 0;
}

void
ie_gsc_run(sc)
	struct ie_softc *sc;
{
}

int
ie_gsc_intrhook(sc, where)
	struct ie_softc *sc;
	int where;
{
	return 0;
}

u_int16_t
ie_gsc_read16(sc, offset)
	struct ie_softc *sc;
	int offset;
{
	return *(u_int16_t *)(sc->bh + offset);
}

void
ie_gsc_write16(sc, offset, v)
	struct ie_softc *sc;	
	int offset;
	u_int16_t v;
{
	*(u_int16_t *)(sc->bh + offset) = v;
}

void
ie_gsc_write24(sc, offset, addr)
	struct ie_softc *sc;	
	int offset;
	int addr;
{
	*(u_int16_t *)(sc->bh + offset + 0) = (addr      ) & 0xffff;
	*(u_int16_t *)(sc->bh + offset + 2) = (addr >> 16) & 0xffff;
}

void
ie_gsc_memcopyin(sc, p, offset, size)
	struct ie_softc	*sc;
	void *p;
	int offset;
	size_t size;
{
	register const u_int16_t *src = (void *)((u_long)sc->bh + offset);
	register u_int16_t *dst = p;
#ifdef DIAGNOSTIC
	if (size & 1)
		panic ("ie_gsc_memcopyin: odd size");
#endif
	bus_space_barrier(sc->bt, sc->bh, offset, size,
			  BUS_SPACE_BARRIER_READ);
	for (; size; size -= 2)
		*dst++ = *src++;
}

void
ie_gsc_memcopyout(sc, p, offset, size)
	struct ie_softc	*sc;
	const void *p;
	int offset;
	size_t size;
{
	register u_int16_t *dst = (void *)((u_long)sc->bh + offset);
	register const u_int16_t *src = p;
#ifdef DIAGNOSTIC
	if (size & 1)
		panic ("ie_gsc_memcopyout: odd size");
#endif
	for (; size; size -= 2)
		*dst++ = *src++;
	bus_space_barrier(sc->bt, sc->bh, offset, size,
			  BUS_SPACE_BARRIER_WRITE);
}


int
ie_gsc_probe(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	register struct gsc_attach_args *ga = aux;
	bus_space_handle_t ioh;
	int rv;

	if (ga->ga_type.iodc_type != HPPA_TYPE_FIO ||
	    (ga->ga_type.iodc_sv_model != HPPA_FIO_LAN &&
	     ga->ga_type.iodc_sv_model != HPPA_FIO_GLAN))
		return 0;

	if (bus_space_map(ga->ga_iot, ga->ga_hpa, IOMOD_HPASIZE, 0, &ioh))
		return 0;

	rv = 1 /* i82586_probe(ga->ga_iot, ioh) */;

	bus_space_unmap(ga->ga_iot, ioh, IOMOD_HPASIZE);
	return rv;
}

void
ie_gsc_attach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct pdc_lan_station_id pdc_mac PDC_ALIGNMENT;
	register struct ie_softc *sc = (struct ie_softc *)self;
	register struct gsc_attach_args *ga = aux;
	register u_int32_t a;
	register int i;

	if (ga->ga_type.iodc_sv_model == HPPA_FIO_GLAN)
		sc->sc_flags |= IEGSC_GECKO;

	if ((i = pdc_call((iodcio_t)pdc, 0, PDC_LAN_STATION_ID,
			  PDC_LAN_STATION_ID_READ, &pdc_mac, ga->ga_hpa)) < 0){
		pdc_mac.addr[0] = ((u_int8_t *)ASP_PROM)[0];
		pdc_mac.addr[1] = ((u_int8_t *)ASP_PROM)[1];
		pdc_mac.addr[2] = ((u_int8_t *)ASP_PROM)[2];
		pdc_mac.addr[3] = ((u_int8_t *)ASP_PROM)[3];
		pdc_mac.addr[4] = ((u_int8_t *)ASP_PROM)[4];
		pdc_mac.addr[5] = ((u_int8_t *)ASP_PROM)[5];
	}

	sc->bt = ga->ga_iot;
	if (bus_space_map(sc->bt, ga->ga_hpa, IOMOD_HPASIZE,
			  0, (bus_space_handle_t *)&sc->sc_reg))
		panic("ie_gsc_attach: couldn't map I/O ports");

	sc->hwreset = ie_gsc_reset;
	sc->chan_attn = ie_gsc_attend;
	sc->hwinit = ie_gsc_run;
	sc->intrhook = ie_gsc_intrhook;
	sc->memcopyout = ie_gsc_memcopyout;
	sc->memcopyin = ie_gsc_memcopyin;
	sc->ie_bus_read16 = ie_gsc_read16;
	sc->ie_bus_write16 = ie_gsc_write16;
	sc->ie_bus_write24 = ie_gsc_write24;

	sc->sc_msize = IE_SIZE;
	if (!(sc->bh = (bus_space_handle_t)
	      kmem_malloc(kmem_map, sc->sc_msize, 0))) {
		printf (": cannot allocate %d bytes for IO\n", IE_SIZE);
		return;
	}

	bzero((void *)sc->bh, sc->sc_msize);
	sc->sc_maddr = (void *)kvtop((void *)sc->bh);

	printf (" irq %d: mem %p size %x\n%s: ", sc->sc_dev.dv_cfdata->cf_irq,
		sc->sc_maddr, sc->sc_msize, sc->sc_dev.dv_xname);

	sc->iscp = IE_ISCP;
	sc->scb = IE_SCB;
	sc->scp = IE_SCP;
	sc->buf_area = IE_BUF;
	sc->buf_area_sz = IE_EBUF - IE_BUF;

	a = ((u_int32_t)sc->sc_maddr + IE_SCP) | IE_PORT_TEST;
	*(int32_t *)(IE_SCP_TEST(sc->scp)) = -1;
	if (sc->sc_flags & IEGSC_GECKO) {
		register volatile struct ie_gsc_regs *r = sc->sc_reg;
		r->ie_port = a;
		DELAY(1000);
		r->ie_port = a >> 16;
		DELAY(1000);
	} else {
		register volatile struct ie_gsc_regs *r = sc->sc_reg;
		r->ie_port = a >> 16;
		DELAY(1000);
		r->ie_port = a;
		DELAY(1000);
	}
	for (i = 900; i-- && *(int32_t *)(IE_SCP_TEST(sc->scp)); DELAY(100))
		bus_space_barrier(sc->bt, sc->bh, IE_SCP, 8,
				  BUS_SPACE_BARRIER_READ);

#ifdef I82586_DEBUG
	printf ("test %x:%x ", ((int32_t *)(sc->bh + IE_SCP))[0],
		((int32_t *)(sc->bh + IE_SCP))[1]);
#endif

	ie_gsc_write16(sc, IE_ISCP_BUSY(sc->iscp), 1);
	ie_gsc_write16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
	ie_gsc_write24(sc, IE_ISCP_BASE(sc->iscp), (u_long)sc->sc_maddr);
	bus_space_barrier(sc->bt, sc->bh, sc->iscp, IE_ISCP_SZ,
			  BUS_SPACE_BARRIER_READ);
	ie_gsc_write16(sc, IE_SCP_BUS_USE(sc->scp), 0x68);
	ie_gsc_write24(sc, IE_SCP_ISCP(sc->scp),
		       (u_long)sc->sc_maddr + sc->iscp);
	bus_space_barrier(sc->bt, sc->bh, sc->scp, IE_SCP_SZ,
			  BUS_SPACE_BARRIER_READ);

	/* inform i825[89]6 about new SCP address,
	   maddr must be at least 16-byte aligned */
	a = ((u_int32_t)sc->sc_maddr + IE_SCP) | IE_PORT_SCP;
	if (sc->sc_flags & IEGSC_GECKO) {
		register volatile struct ie_gsc_regs *r = sc->sc_reg;
		r->ie_port = a;
		DELAY(1000);
		r->ie_port = a >> 16;
		DELAY(1000);
	} else {
		register volatile struct ie_gsc_regs *r = sc->sc_reg;
		r->ie_port = a >> 16;
		DELAY(1000);
		r->ie_port = a;
		DELAY(1000);
	}
	ie_gsc_attend(sc);

	for (i = 900; i-- &&
		     ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp)); DELAY(100))
		bus_space_barrier(sc->bt, sc->bh, IE_ISCP_BUSY(sc->iscp), 2,
				  BUS_SPACE_BARRIER_READ);

#ifdef I82586_DEBUG
	if (i < 0) {
		printf("timeout for PORT command (%x)%s\n",
		       ie_gsc_read16(sc, IE_ISCP_BUSY(sc->iscp)),
		       (sc->sc_flags & IEGSC_GECKO)? " on gecko":"");
		return;
	}

	sc->sc_debug = IED_ALL;
#endif

	i82586_attach(sc, ga->ga_name, pdc_mac.addr,
		      ie_media, IE_NMEDIA, ie_media[0]);

	gsc_intr_establish((struct gsc_softc *)parent,
			   sc->sc_dev.dv_cfdata->cf_irq,
			   IPL_NET, i82586_intr, sc, sc->sc_dev.dv_xname);
}