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