if_sn_jazzio.c revision 1.1
1/*	$NetBSD: if_sn_jazzio.c,v 1.1 2001/07/05 14:42:35 thorpej Exp $	*/
2
3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * Microsoft JAZZ front-end for for the National Semiconductor DP83932
41 * Systems-Oriented Network Interface Controller (SONIC).
42 */
43
44#include "bpfilter.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/mbuf.h>
49#include <sys/malloc.h>
50#include <sys/kernel.h>
51#include <sys/socket.h>
52#include <sys/ioctl.h>
53#include <sys/errno.h>
54#include <sys/device.h>
55#include <sys/kcore.h>
56
57#include <net/if.h>
58#include <net/if_dl.h>
59#include <net/if_ether.h>
60
61#include <machine/autoconf.h>
62#include <machine/bus.h>
63#include <machine/intr.h>
64
65#include <dev/ic/dp83932reg.h>
66#include <dev/ic/dp83932var.h>
67
68#include <arc/arc/arcbios.h>
69#include <arc/jazz/jazziovar.h>
70
71int	sonic_jazzio_match(struct device *, struct cfdata *, void *);
72void	sonic_jazzio_attach(struct device *, struct device *, void *);
73
74struct cfattach sn_jazzio_ca = {
75	sizeof(struct sonic_softc), sonic_jazzio_match,
76	    sonic_jazzio_attach,
77};
78
79int
80sonic_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
81{
82	struct jazzio_attach_args *ja = aux;
83
84	if (strcmp(ja->ja_name, "sonic") != 0)
85		return (0);
86
87	return (1);
88}
89
90void
91sonic_jazzio_attach(struct device *parent, struct device *self, void *aux)
92{
93	struct sonic_softc *sc = (void *) self;
94	struct jazzio_attach_args *ja = aux;
95	int i;
96	uint8_t enaddr[ETHER_ADDR_LEN];
97
98	sc->sc_st = ja->ja_bust;
99	sc->sc_dmat = ja->ja_dmat;
100
101	printf(": SONIC Ethernet\n");
102
103	/* Map the device. */
104	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
105	    0, &sc->sc_sh) != 0) {
106		printf("%s: unable to map SONIC registers\n",
107		    sc->sc_dev.dv_xname);
108		return;
109	}
110
111	/* We run in 32-bit mode. */
112	sc->sc_32bit = 1;
113
114	/* BMODE is set for little-endian. */
115	sc->sc_bigendian = 0;
116
117	/* Regs are 16-bit, plus 16-bit pad. */
118	for (i = 0; i < SONIC_NREGS; i++)
119		sc->sc_regmap[i] = i * 4;
120
121	/*
122	 * Configure DCR:
123	 *
124	 *	- Latched bug retry
125	 *	- Synchronous bus (memory cycle 2 clocks)
126	 *	- 0 wait states added (WC0,WC1 == 0,0)
127	 */
128	sc->sc_dcr = DCR_LBR | DCR_SBUS;
129	sc->sc_dcr2 = 0;
130
131	/* Hook up our interrupt handler. */
132	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
133
134	/* The Ethernet address is from the product ID. */
135	memcpy(enaddr, arc_product_id, sizeof(enaddr));
136
137	/* Finish off the attach. */
138	sonic_attach(sc, enaddr);
139}
140