if_sn_jazzio.c revision 1.4
1/*	$NetBSD: if_sn_jazzio.c,v 1.4 2002/12/28 16:25:39 tsutsui 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
74CFATTACH_DECL(sn_jazzio, sizeof(struct sonic_softc),
75    sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
76
77int
78sonic_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
79{
80	struct jazzio_attach_args *ja = aux;
81
82	if (strcmp(ja->ja_name, "SONIC") != 0)
83		return (0);
84
85	return (1);
86}
87
88void
89sonic_jazzio_attach(struct device *parent, struct device *self, void *aux)
90{
91	struct sonic_softc *sc = (void *) self;
92	struct jazzio_attach_args *ja = aux;
93	int i;
94	uint8_t enaddr[ETHER_ADDR_LEN];
95
96	sc->sc_st = ja->ja_bust;
97	sc->sc_dmat = ja->ja_dmat;
98
99	printf(": SONIC Ethernet\n");
100
101	/* Map the device. */
102	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
103	    0, &sc->sc_sh) != 0) {
104		printf("%s: unable to map SONIC registers\n",
105		    sc->sc_dev.dv_xname);
106		return;
107	}
108
109	/* We run in 32-bit mode. */
110	sc->sc_32bit = 1;
111
112	/* BMODE is set for little-endian. */
113	sc->sc_bigendian = 0;
114
115	/* Regs are 16-bit, plus 16-bit pad. */
116	for (i = 0; i < SONIC_NREGS; i++)
117		sc->sc_regmap[i] = i * 4;
118
119	/*
120	 * Configure DCR:
121	 *
122	 *	- Latched bug retry
123	 *	- Synchronous bus (memory cycle 2 clocks)
124	 *	- 0 wait states added (WC0,WC1 == 0,0)
125	 */
126	sc->sc_dcr = DCR_LBR | DCR_SBUS;
127	sc->sc_dcr2 = 0;
128
129	/* Hook up our interrupt handler. */
130	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
131
132	/* The Ethernet address is from the product ID. */
133	memcpy(enaddr, arc_product_id, sizeof(enaddr));
134
135	/* Finish off the attach. */
136	sonic_attach(sc, enaddr);
137}
138