FreeBSD/Linux Kernel Cross Reference
sys/dev/snc/if_snc.c
1 /*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: releng/5.0/sys/dev/snc/if_snc.c 68054 2000-10-31 08:22:26Z phk $
28 */
29
30 /*
31 * National Semiconductor DP8393X SONIC Driver
32 *
33 * This is the bus independent attachment on FreeBSD 4.x
34 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
35 */
36
37 #include <sys/param.h>
38 #include <sys/socket.h>
39
40 #include <sys/bus.h>
41 #include <machine/bus.h>
42 #include <sys/rman.h>
43 #include <machine/resource.h>
44
45 #include <net/ethernet.h>
46 #include <net/if.h>
47 #include <net/if_arp.h>
48 #include <net/if_media.h>
49
50 #include "opt_bdg.h"
51 #ifdef BRIDGE
52 #include <net/bridge.h>
53 #endif
54
55 #include <dev/snc/dp83932reg.h>
56 #include <dev/snc/dp83932var.h>
57 #include <dev/snc/dp83932subr.h>
58 #include <dev/snc/if_sncreg.h>
59 #include <dev/snc/if_sncvar.h>
60
61 /* devclass for "snc" */
62 devclass_t snc_devclass;
63
64 /****************************************************************
65 Resource management functions
66 ****************************************************************/
67
68 /*
69 * Allocate a port resource with the given resource id.
70 */
71 int
72 snc_alloc_port(dev, rid)
73 device_t dev;
74 int rid;
75 {
76 struct snc_softc *sc = device_get_softc(dev);
77 struct resource *res;
78
79 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
80 0ul, ~0ul, SNEC_NREGS, RF_ACTIVE);
81 if (res) {
82 sc->ioport = res;
83 sc->ioport_rid = rid;
84 sc->sc_iot = rman_get_bustag(res);
85 sc->sc_ioh = rman_get_bushandle(res);
86 return (0);
87 } else {
88 device_printf(dev, "can't assign port\n");
89 return (ENOENT);
90 }
91 }
92
93 /*
94 * Allocate a memory resource with the given resource id.
95 */
96 int
97 snc_alloc_memory(dev, rid)
98 device_t dev;
99 int rid;
100 {
101 struct snc_softc *sc = device_get_softc(dev);
102 struct resource *res;
103
104 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
105 0ul, ~0ul, SNEC_NMEMS, RF_ACTIVE);
106 if (res) {
107 sc->iomem = res;
108 sc->iomem_rid = rid;
109 sc->sc_memt = rman_get_bustag(res);
110 sc->sc_memh = rman_get_bushandle(res);
111 return (0);
112 } else {
113 device_printf(dev, "can't assign memory\n");
114 return (ENOENT);
115 }
116 }
117
118 /*
119 * Allocate an irq resource with the given resource id.
120 */
121 int
122 snc_alloc_irq(dev, rid, flags)
123 device_t dev;
124 int rid;
125 int flags;
126 {
127 struct snc_softc *sc = device_get_softc(dev);
128 struct resource *res;
129
130 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
131 0ul, ~0ul, 1, (RF_ACTIVE | flags));
132 if (res) {
133 sc->irq = res;
134 sc->irq_rid = rid;
135 return (0);
136 } else {
137 device_printf(dev, "can't assign irq\n");
138 return (ENOENT);
139 }
140 }
141
142 /*
143 * Release all resources
144 */
145 void
146 snc_release_resources(dev)
147 device_t dev;
148 {
149 struct snc_softc *sc = device_get_softc(dev);
150
151 if (sc->ioport) {
152 bus_release_resource(dev, SYS_RES_IOPORT,
153 sc->ioport_rid, sc->ioport);
154 sc->ioport = 0;
155 }
156 if (sc->iomem) {
157 bus_release_resource(dev, SYS_RES_MEMORY,
158 sc->iomem_rid, sc->iomem);
159 sc->iomem = 0;
160 }
161 if (sc->irq) {
162 bus_release_resource(dev, SYS_RES_IRQ,
163 sc->irq_rid, sc->irq);
164 sc->irq = 0;
165 }
166 }
167
168 /****************************************************************
169 Probe routine
170 ****************************************************************/
171
172 int
173 snc_probe(dev, type)
174 device_t dev;
175 int type;
176 {
177 struct snc_softc *sc = device_get_softc(dev);
178
179 return snc_nec16_detectsubr(sc->sc_iot, sc->sc_ioh,
180 sc->sc_memt, sc->sc_memh,
181 rman_get_start(sc->irq),
182 rman_get_start(sc->iomem),
183 type);
184 }
185
186 /****************************************************************
187 Attach routine
188 ****************************************************************/
189
190 int
191 snc_attach(dev)
192 device_t dev;
193 {
194 struct snc_softc *sc = device_get_softc(dev);
195 u_int8_t myea[ETHER_ADDR_LEN];
196
197 if (snc_nec16_register_irq(sc, rman_get_start(sc->irq)) == 0 ||
198 snc_nec16_register_mem(sc, rman_get_start(sc->iomem)) == 0) {
199 snc_release_resources(dev);
200 return(ENOENT);
201 }
202
203 snc_nec16_get_enaddr(sc->sc_iot, sc->sc_ioh, myea);
204 device_printf(dev, "%s Ethernet\n", snc_nec16_detect_type(myea));
205
206 sc->sc_dev = dev;
207
208 sc->sncr_dcr = DCR_SYNC | DCR_WAIT0 |
209 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT28;
210 sc->sncr_dcr2 = 0; /* XXX */
211 sc->bitmode = 0; /* 16 bit card */
212
213 sc->sc_nic_put = snc_nec16_nic_put;
214 sc->sc_nic_get = snc_nec16_nic_get;
215 sc->sc_writetodesc = snc_nec16_writetodesc;
216 sc->sc_readfromdesc = snc_nec16_readfromdesc;
217 sc->sc_copytobuf = snc_nec16_copytobuf;
218 sc->sc_copyfrombuf = snc_nec16_copyfrombuf;
219 sc->sc_zerobuf = snc_nec16_zerobuf;
220
221 /* sncsetup returns 1 if something fails */
222 if (sncsetup(sc, myea)) {
223 snc_release_resources(dev);
224 return(ENOENT);
225 }
226
227 sncconfig(sc, NULL, 0, 0, myea);
228
229 return 0;
230 }
231
232 /****************************************************************
233 Shutdown routine
234 ****************************************************************/
235
236 void
237 snc_shutdown(dev)
238 device_t dev;
239 {
240 sncshutdown(device_get_softc(dev));
241 }
Cache object: 0ed14f84a41eea11dc6869d325d36fc9
|