if_ne_xsh.c revision 1.4.10.2 1 1.4.10.2 tls /* $NetBSD: if_ne_xsh.c,v 1.4.10.2 2014/08/20 00:02:43 tls Exp $ */
2 1.4.10.2 tls
3 1.4.10.2 tls /*-
4 1.4.10.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.4.10.2 tls * All rights reserved.
6 1.4.10.2 tls *
7 1.4.10.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.4.10.2 tls * by Radoslaw Kujawa.
9 1.4.10.2 tls *
10 1.4.10.2 tls * Redistribution and use in source and binary forms, with or without
11 1.4.10.2 tls * modification, are permitted provided that the following conditions
12 1.4.10.2 tls * are met:
13 1.4.10.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.4.10.2 tls * notice, this list of conditions and the following disclaimer.
15 1.4.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.10.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.4.10.2 tls * documentation and/or other materials provided with the distribution.
18 1.4.10.2 tls *
19 1.4.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4.10.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4.10.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4.10.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4.10.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4.10.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4.10.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4.10.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4.10.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4.10.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4.10.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.4.10.2 tls */
31 1.4.10.2 tls
32 1.4.10.2 tls #include <sys/cdefs.h>
33 1.4.10.2 tls
34 1.4.10.2 tls /*
35 1.4.10.2 tls * X-Surf 100 driver, ne(4) attachment.
36 1.4.10.2 tls */
37 1.4.10.2 tls
38 1.4.10.2 tls #include <sys/param.h>
39 1.4.10.2 tls #include <sys/device.h>
40 1.4.10.2 tls #include <sys/malloc.h>
41 1.4.10.2 tls #include <sys/mbuf.h>
42 1.4.10.2 tls #include <sys/socket.h>
43 1.4.10.2 tls #include <sys/syslog.h>
44 1.4.10.2 tls #include <sys/systm.h>
45 1.4.10.2 tls #include <sys/bus.h>
46 1.4.10.2 tls
47 1.4.10.2 tls #include <machine/cpu.h>
48 1.4.10.2 tls
49 1.4.10.2 tls #include <net/if.h>
50 1.4.10.2 tls #include <net/if_media.h>
51 1.4.10.2 tls #include <net/if_ether.h>
52 1.4.10.2 tls
53 1.4.10.2 tls #include <dev/ic/dp8390reg.h>
54 1.4.10.2 tls #include <dev/ic/dp8390var.h>
55 1.4.10.2 tls
56 1.4.10.2 tls #include <dev/ic/ne2000reg.h>
57 1.4.10.2 tls #include <dev/ic/ne2000var.h>
58 1.4.10.2 tls
59 1.4.10.2 tls #include <dev/ic/ax88190var.h>
60 1.4.10.2 tls
61 1.4.10.2 tls #include <amiga/amiga/device.h>
62 1.4.10.2 tls #include <amiga/amiga/isr.h>
63 1.4.10.2 tls
64 1.4.10.2 tls #include <amiga/dev/xshvar.h>
65 1.4.10.2 tls #include <amiga/dev/zbusvar.h>
66 1.4.10.2 tls
67 1.4.10.2 tls /* #define NE_XSH_DEBUG 1 */
68 1.4.10.2 tls
69 1.4.10.2 tls int ne_xsh_match(device_t, cfdata_t , void *);
70 1.4.10.2 tls void ne_xsh_attach(device_t, device_t, void *);
71 1.4.10.2 tls #ifdef NE_XSH_DEBUG
72 1.4.10.2 tls void ne_xsh_debug_mapping(bus_space_tag_t, bus_space_handle_t,
73 1.4.10.2 tls bus_space_handle_t);
74 1.4.10.2 tls #endif /* NE_XSH_DEBUG */
75 1.4.10.2 tls
76 1.4.10.2 tls struct ne_xsh_softc {
77 1.4.10.2 tls struct ne2000_softc sc_ne2000;
78 1.4.10.2 tls struct bus_space_tag sc_bst;
79 1.4.10.2 tls struct isr sc_isr;
80 1.4.10.2 tls };
81 1.4.10.2 tls
82 1.4.10.2 tls CFATTACH_DECL_NEW(ne_xsh, sizeof(struct ne_xsh_softc),
83 1.4.10.2 tls ne_xsh_match, ne_xsh_attach, NULL, NULL);
84 1.4.10.2 tls
85 1.4.10.2 tls int
86 1.4.10.2 tls ne_xsh_match(device_t parent, cfdata_t cf, void *aux)
87 1.4.10.2 tls {
88 1.4.10.2 tls struct xshbus_attach_args *xap = aux;
89 1.4.10.2 tls
90 1.4.10.2 tls if (strcmp(xap->xaa_name, "ne_xsh") != 0)
91 1.4.10.2 tls return 0;
92 1.4.10.2 tls
93 1.4.10.2 tls return 1;
94 1.4.10.2 tls }
95 1.4.10.2 tls
96 1.4.10.2 tls void
97 1.4.10.2 tls ne_xsh_attach(device_t parent, device_t self, void *aux)
98 1.4.10.2 tls {
99 1.4.10.2 tls struct ne_xsh_softc *zsc = device_private(self);
100 1.4.10.2 tls struct ne2000_softc *nsc = &zsc->sc_ne2000;
101 1.4.10.2 tls struct dp8390_softc *dsc = &nsc->sc_dp8390;
102 1.4.10.2 tls
103 1.4.10.2 tls struct xshbus_attach_args *xap = aux;
104 1.4.10.2 tls
105 1.4.10.2 tls bus_space_tag_t xsht;
106 1.4.10.2 tls bus_space_handle_t nich;
107 1.4.10.2 tls bus_space_handle_t asich;
108 1.4.10.2 tls
109 1.4.10.2 tls dsc->sc_dev = self;
110 1.4.10.2 tls
111 1.4.10.2 tls zsc->sc_bst.base = xap->xaa_base;
112 1.4.10.2 tls zsc->sc_bst.absm = &amiga_bus_stride_4;
113 1.4.10.2 tls
114 1.4.10.2 tls aprint_normal("\n");
115 1.4.10.2 tls
116 1.4.10.2 tls xsht = &zsc->sc_bst;
117 1.4.10.2 tls
118 1.4.10.2 tls /* Map the NIC and ASIC spaces. */
119 1.4.10.2 tls if (bus_space_map(xsht, NE2000_NIC_OFFSET, NE2000_NPORTS, 0, &nich)) {
120 1.4.10.2 tls aprint_error_dev(self, "can't map nic i/o space\n");
121 1.4.10.2 tls return;
122 1.4.10.2 tls }
123 1.4.10.2 tls if (bus_space_subregion(xsht, nich, NE2000_ASIC_OFFSET,
124 1.4.10.2 tls NE2000_ASIC_NPORTS, &asich)) {
125 1.4.10.2 tls aprint_error_dev(self, "can't map asic i/o space\n");
126 1.4.10.2 tls return;
127 1.4.10.2 tls }
128 1.4.10.2 tls
129 1.4.10.2 tls #ifdef NE_XSH_DEBUG
130 1.4.10.2 tls ne_xsh_debug_mapping(xsht, nich, asich);
131 1.4.10.2 tls #endif /* NE_XSH_DEBUG */
132 1.4.10.2 tls
133 1.4.10.2 tls dsc->sc_regt = xsht;
134 1.4.10.2 tls dsc->sc_regh = nich;
135 1.4.10.2 tls
136 1.4.10.2 tls nsc->sc_asict = xsht;
137 1.4.10.2 tls nsc->sc_asich = asich;
138 1.4.10.2 tls
139 1.4.10.2 tls /* This interface is always enabled. */
140 1.4.10.2 tls dsc->sc_enabled = 1;
141 1.4.10.2 tls
142 1.4.10.2 tls nsc->sc_type = NE2000_TYPE_AX88796;
143 1.4.10.2 tls
144 1.4.10.2 tls dsc->sc_mediachange = ax88190_mediachange;
145 1.4.10.2 tls dsc->sc_mediastatus = ax88190_mediastatus;
146 1.4.10.2 tls dsc->init_card = ax88190_init_card;
147 1.4.10.2 tls dsc->stop_card = ax88190_stop_card;
148 1.4.10.2 tls dsc->sc_media_init = ax88190_media_init;
149 1.4.10.2 tls dsc->sc_media_fini = ax88190_media_fini;
150 1.4.10.2 tls
151 1.4.10.2 tls /*
152 1.4.10.2 tls * Do generic NE2000 attach. This will read the station address
153 1.4.10.2 tls * from the EEPROM.
154 1.4.10.2 tls */
155 1.4.10.2 tls ne2000_attach(nsc, NULL);
156 1.4.10.2 tls
157 1.4.10.2 tls zsc->sc_isr.isr_intr = dp8390_intr;
158 1.4.10.2 tls zsc->sc_isr.isr_arg = dsc;
159 1.4.10.2 tls zsc->sc_isr.isr_ipl = 2;
160 1.4.10.2 tls add_isr(&zsc->sc_isr);
161 1.4.10.2 tls }
162 1.4.10.2 tls
163 1.4.10.2 tls #ifdef NE_XSH_DEBUG
164 1.4.10.2 tls void
165 1.4.10.2 tls ne_xsh_debug_mapping(bus_space_tag_t xsht, bus_space_handle_t nich,
166 1.4.10.2 tls bus_space_handle_t asich)
167 1.4.10.2 tls {
168 1.4.10.2 tls bus_addr_t va;
169 1.4.10.2 tls int i;
170 1.4.10.2 tls
171 1.4.10.2 tls aprint_normal("xsh: NIC mapping: ");
172 1.4.10.2 tls for(va = nich, i = 0; i < NE2000_NIC_NPORTS; i++) {
173 1.4.10.2 tls aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
174 1.4.10.2 tls }
175 1.4.10.2 tls aprint_normal("\n");
176 1.4.10.2 tls
177 1.4.10.2 tls aprint_normal("xsh: ASIC mapping: ");
178 1.4.10.2 tls for(va = asich, i = 0; i < NE2000_ASIC_NPORTS; i++) {
179 1.4.10.2 tls aprint_normal("%x:%x ", i, kvtop((void*) (va+i)));
180 1.4.10.2 tls }
181 1.4.10.2 tls aprint_normal("\n");
182 1.4.10.2 tls }
183 1.4.10.2 tls #endif /* NE_XSH_DEBUG */
184