xref: /netbsd-src/sys/arch/arc/jazz/if_sn_jazzio.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: if_sn_jazzio.c,v 1.13 2011/07/01 19:25:41 dyoung 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Microsoft JAZZ front-end for for the National Semiconductor DP83932
34  * Systems-Oriented Network Interface Controller (SONIC).
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: if_sn_jazzio.c,v 1.13 2011/07/01 19:25:41 dyoung Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/mbuf.h>
43 #include <sys/malloc.h>
44 #include <sys/kernel.h>
45 #include <sys/socket.h>
46 #include <sys/ioctl.h>
47 #include <sys/errno.h>
48 #include <sys/device.h>
49 #include <sys/kcore.h>
50 
51 #include <net/if.h>
52 #include <net/if_dl.h>
53 #include <net/if_ether.h>
54 
55 #include <machine/autoconf.h>
56 #include <sys/bus.h>
57 #include <machine/intr.h>
58 
59 #include <dev/ic/dp83932reg.h>
60 #include <dev/ic/dp83932var.h>
61 
62 #include <arc/arc/arcbios.h>
63 #include <arc/jazz/jazziovar.h>
64 
65 int	sonic_jazzio_match(device_t, cfdata_t, void *);
66 void	sonic_jazzio_attach(device_t, device_t, void *);
67 
68 CFATTACH_DECL_NEW(sn_jazzio, sizeof(struct sonic_softc),
69     sonic_jazzio_match, sonic_jazzio_attach, NULL, NULL);
70 
71 int
72 sonic_jazzio_match(device_t parent, cfdata_t cf, void *aux)
73 {
74 	struct jazzio_attach_args *ja = aux;
75 
76 	if (strcmp(ja->ja_name, "SONIC") != 0)
77 		return 0;
78 
79 	return 1;
80 }
81 
82 void
83 sonic_jazzio_attach(device_t parent, device_t self, void *aux)
84 {
85 	struct sonic_softc *sc = device_private(self);
86 	struct jazzio_attach_args *ja = aux;
87 	int i;
88 	uint8_t enaddr[ETHER_ADDR_LEN];
89 
90 	sc->sc_dev = self;
91 	sc->sc_st = ja->ja_bust;
92 	sc->sc_dmat = ja->ja_dmat;
93 
94 	aprint_normal(": SONIC Ethernet\n");
95 
96 	/* Map the device. */
97 	if (bus_space_map(sc->sc_st, ja->ja_addr, SONIC_NREGS * 4,
98 	    0, &sc->sc_sh) != 0) {
99 		aprint_error_dev(sc->sc_dev, "unable to map SONIC registers\n");
100 		return;
101 	}
102 
103 	/* We run in 32-bit mode. */
104 	sc->sc_32bit = 1;
105 
106 	/* BMODE is set for little-endian. */
107 	sc->sc_bigendian = 0;
108 
109 	/* Regs are 16-bit, plus 16-bit pad. */
110 	for (i = 0; i < SONIC_NREGS; i++)
111 		sc->sc_regmap[i] = i * 4;
112 
113 	/*
114 	 * Configure DCR:
115 	 *
116 	 *	- Latched bug retry
117 	 *	- Synchronous bus (memory cycle 2 clocks)
118 	 *	- 0 wait states added (WC0,WC1 == 0,0)
119 	 *	- 4 byte Rx DMA threshold (RFT0,RFT1 == 0,0)
120 	 *	- 28 byte Tx DMA threshold (TFT0,TFT1 == 1,1)
121 	 *	  XXX There was a comment
122 	 *	  	"XXX RFT & TFT according to MIPS manual"
123 	 *	      in old MD sys/arch/arc/dev/if_sn.c in Attic.
124 	 */
125 	sc->sc_dcr = DCR_LBR | DCR_SBUS | DCR_TFT0 | DCR_TFT1;
126 	sc->sc_dcr2 = 0;
127 
128 	/* Hook up our interrupt handler. */
129 	jazzio_intr_establish(ja->ja_intr, sonic_intr, sc);
130 
131 	/* The Ethernet address is from the product ID. */
132 	memcpy(enaddr, arc_product_id, sizeof(enaddr));
133 
134 	/* Finish off the attach. */
135 	sonic_attach(sc, enaddr);
136 }
137