Fix #include.
[dragonfly.git] / sys / dev / netif / snc / if_snc.c
... / ...
CommitLineData
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: src/sys/dev/snc/if_snc.c,v 1.2.2.1 2000/10/21 03:30:03 nyan Exp $
28 * $DragonFly: src/sys/dev/netif/snc/Attic/if_snc.c,v 1.5 2005/02/19 15:47:44 swildner Exp $
29 */
30
31/*
32 * National Semiconductor DP8393X SONIC Driver
33 *
34 * This is the bus independent attachment on FreeBSD 4.x
35 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/sockio.h>
41#include <sys/mbuf.h>
42#include <sys/socket.h>
43#include <sys/syslog.h>
44
45#include <sys/linker_set.h>
46#include <sys/module.h>
47#include <sys/bus.h>
48#include <machine/bus.h>
49#include <sys/rman.h>
50#include <machine/resource.h>
51
52#include <net/ethernet.h>
53#include <net/if.h>
54#include <net/if_arp.h>
55#include <net/if_media.h>
56#include <net/if_dl.h>
57#include <net/if_mib.h>
58
59#include <net/bpf.h>
60#include "opt_bdg.h"
61#ifdef BRIDGE
62#include <net/bridge/bridge.h>
63#endif
64
65#include "dp83932reg.h"
66#include "dp83932var.h"
67#include "dp83932subr.h"
68#include "if_sncreg.h"
69#include "if_sncvar.h"
70
71/* devclass for "snc" */
72devclass_t snc_devclass;
73
74DECLARE_DUMMY_MODULE(if_snc);
75
76/****************************************************************
77 Resource management functions
78 ****************************************************************/
79
80/*
81 * Allocate a port resource with the given resource id.
82 */
83int
84snc_alloc_port(dev, rid)
85 device_t dev;
86 int rid;
87{
88 struct snc_softc *sc = device_get_softc(dev);
89 struct resource *res;
90
91 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
92 0ul, ~0ul, SNEC_NREGS, RF_ACTIVE);
93 if (res) {
94 sc->ioport = res;
95 sc->ioport_rid = rid;
96 sc->sc_iot = rman_get_bustag(res);
97 sc->sc_ioh = rman_get_bushandle(res);
98 return (0);
99 } else {
100 device_printf(dev, "can't assign port\n");
101 return (ENOENT);
102 }
103}
104
105/*
106 * Allocate a memory resource with the given resource id.
107 */
108int
109snc_alloc_memory(dev, rid)
110 device_t dev;
111 int rid;
112{
113 struct snc_softc *sc = device_get_softc(dev);
114 struct resource *res;
115
116 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
117 0ul, ~0ul, SNEC_NMEMS, RF_ACTIVE);
118 if (res) {
119 sc->iomem = res;
120 sc->iomem_rid = rid;
121 sc->sc_memt = rman_get_bustag(res);
122 sc->sc_memh = rman_get_bushandle(res);
123 return (0);
124 } else {
125 device_printf(dev, "can't assign memory\n");
126 return (ENOENT);
127 }
128}
129
130/*
131 * Allocate an irq resource with the given resource id.
132 */
133int
134snc_alloc_irq(dev, rid, flags)
135 device_t dev;
136 int rid;
137 int flags;
138{
139 struct snc_softc *sc = device_get_softc(dev);
140 struct resource *res;
141
142 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
143 0ul, ~0ul, 1, (RF_ACTIVE | flags));
144 if (res) {
145 sc->irq = res;
146 sc->irq_rid = rid;
147 return (0);
148 } else {
149 device_printf(dev, "can't assign irq\n");
150 return (ENOENT);
151 }
152}
153
154/*
155 * Release all resources
156 */
157void
158snc_release_resources(dev)
159 device_t dev;
160{
161 struct snc_softc *sc = device_get_softc(dev);
162
163 if (sc->ioport) {
164 bus_release_resource(dev, SYS_RES_IOPORT,
165 sc->ioport_rid, sc->ioport);
166 sc->ioport = 0;
167 }
168 if (sc->iomem) {
169 bus_release_resource(dev, SYS_RES_MEMORY,
170 sc->iomem_rid, sc->iomem);
171 sc->iomem = 0;
172 }
173 if (sc->irq) {
174 bus_release_resource(dev, SYS_RES_IRQ,
175 sc->irq_rid, sc->irq);
176 sc->irq = 0;
177 }
178}
179
180/****************************************************************
181 Probe routine
182 ****************************************************************/
183
184int
185snc_probe(dev, type)
186 device_t dev;
187 int type;
188{
189 struct snc_softc *sc = device_get_softc(dev);
190
191 return snc_nec16_detectsubr(sc->sc_iot, sc->sc_ioh,
192 sc->sc_memt, sc->sc_memh,
193 rman_get_start(sc->irq),
194 rman_get_start(sc->iomem),
195 type);
196}
197
198/****************************************************************
199 Attach routine
200 ****************************************************************/
201
202int
203snc_attach(dev)
204 device_t dev;
205{
206 struct snc_softc *sc = device_get_softc(dev);
207 u_int8_t myea[ETHER_ADDR_LEN];
208
209 if (snc_nec16_register_irq(sc, rman_get_start(sc->irq)) == 0 ||
210 snc_nec16_register_mem(sc, rman_get_start(sc->iomem)) == 0) {
211 snc_release_resources(dev);
212 return(ENOENT);
213 }
214
215 snc_nec16_get_enaddr(sc->sc_iot, sc->sc_ioh, myea);
216 device_printf(dev, "%s Ethernet\n", snc_nec16_detect_type(myea));
217
218 sc->sc_dev = dev;
219
220 sc->sncr_dcr = DCR_SYNC | DCR_WAIT0 |
221 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT28;
222 sc->sncr_dcr2 = 0; /* XXX */
223 sc->bitmode = 0; /* 16 bit card */
224
225 sc->sc_nic_put = snc_nec16_nic_put;
226 sc->sc_nic_get = snc_nec16_nic_get;
227 sc->sc_writetodesc = snc_nec16_writetodesc;
228 sc->sc_readfromdesc = snc_nec16_readfromdesc;
229 sc->sc_copytobuf = snc_nec16_copytobuf;
230 sc->sc_copyfrombuf = snc_nec16_copyfrombuf;
231 sc->sc_zerobuf = snc_nec16_zerobuf;
232
233 /* sncsetup returns 1 if something fails */
234 if (sncsetup(sc, myea)) {
235 snc_release_resources(dev);
236 return(ENOENT);
237 }
238
239 sncconfig(sc, NULL, 0, 0, myea);
240
241 return 0;
242}
243
244/****************************************************************
245 Shutdown routine
246 ****************************************************************/
247
248void
249snc_shutdown(dev)
250 device_t dev;
251{
252 sncshutdown(device_get_softc(dev));
253}