xref: /netbsd-src/sys/arch/amiga/dev/if_ne_xsh.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: if_ne_xsh.c,v 1.4 2013/08/13 15:43:25 rkujawa Exp $ */
2 
3 /*-
4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Radoslaw Kujawa.
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 #include <sys/cdefs.h>
33 
34 /*
35  * X-Surf 100 driver, ne(4) attachment.
36  */
37 
38 #include <sys/param.h>
39 #include <sys/device.h>
40 #include <sys/malloc.h>
41 #include <sys/mbuf.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
44 #include <sys/systm.h>
45 #include <sys/bus.h>
46 
47 #include <machine/cpu.h>
48 
49 #include <net/if.h>
50 #include <net/if_media.h>
51 #include <net/if_ether.h>
52 
53 #include <dev/ic/dp8390reg.h>
54 #include <dev/ic/dp8390var.h>
55 
56 #include <dev/ic/ne2000reg.h>
57 #include <dev/ic/ne2000var.h>
58 
59 #include <dev/ic/ax88190var.h>
60 
61 #include <amiga/amiga/device.h>
62 #include <amiga/amiga/isr.h>
63 
64 #include <amiga/dev/xshvar.h>
65 #include <amiga/dev/zbusvar.h>
66 
67 /* #define NE_XSH_DEBUG 1 */
68 
69 int	ne_xsh_match(device_t, cfdata_t , void *);
70 void	ne_xsh_attach(device_t, device_t, void *);
71 #ifdef NE_XSH_DEBUG
72 void	ne_xsh_debug_mapping(bus_space_tag_t, bus_space_handle_t,
73 	    bus_space_handle_t);
74 #endif /* NE_XSH_DEBUG */
75 
76 struct ne_xsh_softc {
77 	struct ne2000_softc	sc_ne2000;
78 	struct bus_space_tag	sc_bst;
79 	struct isr		sc_isr;
80 };
81 
82 CFATTACH_DECL_NEW(ne_xsh, sizeof(struct ne_xsh_softc),
83     ne_xsh_match, ne_xsh_attach, NULL, NULL);
84 
85 int
86 ne_xsh_match(device_t parent, cfdata_t cf, void *aux)
87 {
88 	struct xshbus_attach_args *xap = aux;
89 
90 	if (strcmp(xap->xaa_name, "ne_xsh") != 0)
91 		return 0;
92 
93 	return 1;
94 }
95 
96 void
97 ne_xsh_attach(device_t parent, device_t self, void *aux)
98 {
99 	struct ne_xsh_softc *zsc = device_private(self);
100 	struct ne2000_softc *nsc = &zsc->sc_ne2000;
101 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
102 
103 	struct xshbus_attach_args *xap = aux;
104 
105 	bus_space_tag_t xsht;
106 	bus_space_handle_t nich;
107 	bus_space_handle_t asich;
108 
109 	dsc->sc_dev = self;
110 
111 	zsc->sc_bst.base = xap->xaa_base;
112 	zsc->sc_bst.absm = &amiga_bus_stride_4;
113 
114 	aprint_normal("\n");
115 
116 	xsht = &zsc->sc_bst;
117 
118 	/* Map the NIC and ASIC spaces. */
119 	if (bus_space_map(xsht, NE2000_NIC_OFFSET, NE2000_NPORTS, 0, &nich)) {
120 		aprint_error_dev(self, "can't map nic i/o space\n");
121 		return;
122 	}
123 	if (bus_space_subregion(xsht, nich, NE2000_ASIC_OFFSET,
124 	    NE2000_ASIC_NPORTS, &asich)) {
125 		aprint_error_dev(self, "can't map asic i/o space\n");
126 		return;
127 	}
128 
129 #ifdef NE_XSH_DEBUG
130 	ne_xsh_debug_mapping(xsht, nich, asich);
131 #endif /* NE_XSH_DEBUG */
132 
133 	dsc->sc_regt = xsht;
134 	dsc->sc_regh = nich;
135 
136 	nsc->sc_asict = xsht;
137 	nsc->sc_asich = asich;
138 
139 	/* This interface is always enabled. */
140 	dsc->sc_enabled = 1;
141 
142 	nsc->sc_type = NE2000_TYPE_AX88796;
143 
144 	dsc->sc_mediachange = ax88190_mediachange;
145 	dsc->sc_mediastatus = ax88190_mediastatus;
146 	dsc->init_card = ax88190_init_card;
147 	dsc->stop_card = ax88190_stop_card;
148 	dsc->sc_media_init = ax88190_media_init;
149 	dsc->sc_media_fini = ax88190_media_fini;
150 
151 	/*
152 	 * Do generic NE2000 attach.  This will read the station address
153 	 * from the EEPROM.
154 	 */
155 	ne2000_attach(nsc, NULL);
156 
157 	zsc->sc_isr.isr_intr = dp8390_intr;
158 	zsc->sc_isr.isr_arg = dsc;
159 	zsc->sc_isr.isr_ipl = 2;
160 	add_isr(&zsc->sc_isr);
161 }
162 
163 #ifdef NE_XSH_DEBUG
164 void
165 ne_xsh_debug_mapping(bus_space_tag_t xsht, bus_space_handle_t nich,
166     bus_space_handle_t asich)
167 {
168 	bus_addr_t va;
169 	int i;
170 
171 	aprint_normal("xsh: NIC mapping: ");
172 	for(va = nich, i = 0; i < NE2000_NIC_NPORTS; i++) {
173 		aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
174 	}
175 	aprint_normal("\n");
176 
177 	aprint_normal("xsh: ASIC mapping: ");
178 	for(va = asich, i = 0; i < NE2000_ASIC_NPORTS; i++) {
179 		aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
180 	}
181 	aprint_normal("\n");
182 }
183 #endif /* NE_XSH_DEBUG */
184