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