xref: /netbsd-src/sys/arch/arc/jazz/if_sn_jazzio.c (revision 5b84b3983f71fd20a534cfa5d1556623a8aaa717)
1 /*	$NetBSD: if_sn_jazzio.c,v 1.6 2005/01/22 07:35:34 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 <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.6 2005/01/22 07:35:34 tsutsui Exp $");
46 
47 #include "bpfilter.h"
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/malloc.h>
53 #include <sys/kernel.h>
54 #include <sys/socket.h>
55 #include <sys/ioctl.h>
56 #include <sys/errno.h>
57 #include <sys/device.h>
58 #include <sys/kcore.h>
59 
60 #include <net/if.h>
61 #include <net/if_dl.h>
62 #include <net/if_ether.h>
63 
64 #include <machine/autoconf.h>
65 #include <machine/bus.h>
66 #include <machine/intr.h>
67 
68 #include <dev/ic/dp83932reg.h>
69 #include <dev/ic/dp83932var.h>
70 
71 #include <arc/arc/arcbios.h>
72 #include <arc/jazz/jazziovar.h>
73 
74 int	sonic_jazzio_match(struct device *, struct cfdata *, void *);
75 void	sonic_jazzio_attach(struct device *, struct device *, void *);
76 
77 CFATTACH_DECL(sn_jazzio, sizeof(struct sonic_softc),
78     sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
79 
80 int
81 sonic_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
82 {
83 	struct jazzio_attach_args *ja = aux;
84 
85 	if (strcmp(ja->ja_name, "SONIC") != 0)
86 		return 0;
87 
88 	return 1;
89 }
90 
91 void
92 sonic_jazzio_attach(struct device *parent, struct device *self, void *aux)
93 {
94 	struct sonic_softc *sc = (void *) self;
95 	struct jazzio_attach_args *ja = aux;
96 	int i;
97 	uint8_t enaddr[ETHER_ADDR_LEN];
98 
99 	sc->sc_st = ja->ja_bust;
100 	sc->sc_dmat = ja->ja_dmat;
101 
102 	printf(": SONIC Ethernet\n");
103 
104 	/* Map the device. */
105 	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
106 	    0, &sc->sc_sh) != 0) {
107 		printf("%s: unable to map SONIC registers\n",
108 		    sc->sc_dev.dv_xname);
109 		return;
110 	}
111 
112 	/* We run in 32-bit mode. */
113 	sc->sc_32bit = 1;
114 
115 	/* BMODE is set for little-endian. */
116 	sc->sc_bigendian = 0;
117 
118 	/* Regs are 16-bit, plus 16-bit pad. */
119 	for (i = 0; i < SONIC_NREGS; i++)
120 		sc->sc_regmap[i] = i * 4;
121 
122 	/*
123 	 * Configure DCR:
124 	 *
125 	 *	- Latched bug retry
126 	 *	- Synchronous bus (memory cycle 2 clocks)
127 	 *	- 0 wait states added (WC0,WC1 == 0,0)
128 	 */
129 	sc->sc_dcr = DCR_LBR | DCR_SBUS;
130 	sc->sc_dcr2 = 0;
131 
132 	/* Hook up our interrupt handler. */
133 	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
134 
135 	/* The Ethernet address is from the product ID. */
136 	memcpy(enaddr, arc_product_id, sizeof(enaddr));
137 
138 	/* Finish off the attach. */
139 	sonic_attach(sc, enaddr);
140 }
141