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