Deleted Added
full compact
if_le_cbus.c (166901) if_le_cbus.c (183337)
1/*-
2 * Copyright (c) 1994-2000
3 * Paul Richards. All rights reserved.
4 *
5 * PC-98 port by Chiharu Shibata & FreeBSD(98) porting team.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * from: FreeBSD: src/sys/dev/lnc/if_lnc_cbus.c,v 1.12 2005/11/12 19:14:21
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1994-2000
3 * Paul Richards. All rights reserved.
4 *
5 * PC-98 port by Chiharu Shibata & FreeBSD(98) porting team.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * from: FreeBSD: src/sys/dev/lnc/if_lnc_cbus.c,v 1.12 2005/11/12 19:14:21
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/dev/le/if_le_cbus.c 166901 2007-02-23 12:19:07Z piso $");
36__FBSDID("$FreeBSD: head/sys/dev/le/if_le_cbus.c 183337 2008-09-24 21:26:46Z marius $");
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bus.h>
41#include <sys/endian.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/module.h>

--- 20 unchanged lines hidden (view full) ---

65#define CNET98S_RDP 0x10
66#define CNET98S_RAP 0x12
67#define CNET98S_RESET 0x14
68#define CNET98S_BDP 0x16
69
70struct le_cbus_softc {
71 struct am7990_softc sc_am7990; /* glue to MI code */
72
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bus.h>
41#include <sys/endian.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/module.h>

--- 20 unchanged lines hidden (view full) ---

65#define CNET98S_RDP 0x10
66#define CNET98S_RAP 0x12
67#define CNET98S_RESET 0x14
68#define CNET98S_BDP 0x16
69
70struct le_cbus_softc {
71 struct am7990_softc sc_am7990; /* glue to MI code */
72
73 int sc_rrid;
74 struct resource *sc_rres;
73 struct resource *sc_rres;
75 bus_space_tag_t sc_regt;
76 bus_space_handle_t sc_regh;
77
74
78 int sc_irid;
79 struct resource *sc_ires;
80 void *sc_ih;
81
82 bus_dma_tag_t sc_pdmat;
83 bus_dma_tag_t sc_dmat;
84 bus_dmamap_t sc_dmam;
85};
86

--- 36 unchanged lines hidden (view full) ---

123static void le_cbus_hwreset(struct lance_softc *);
124static bus_dmamap_callback_t le_cbus_dma_callback;
125
126static void
127le_cbus_wrbcr(struct lance_softc *sc, uint16_t port, uint16_t val)
128{
129 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
130
75 struct resource *sc_ires;
76 void *sc_ih;
77
78 bus_dma_tag_t sc_pdmat;
79 bus_dma_tag_t sc_dmat;
80 bus_dmamap_t sc_dmam;
81};
82

--- 36 unchanged lines hidden (view full) ---

119static void le_cbus_hwreset(struct lance_softc *);
120static bus_dmamap_callback_t le_cbus_dma_callback;
121
122static void
123le_cbus_wrbcr(struct lance_softc *sc, uint16_t port, uint16_t val)
124{
125 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
126
131 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, port);
132 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, 2,
133 BUS_SPACE_BARRIER_WRITE);
134 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_BDP, val);
127 bus_write_2(lesc->sc_rres, CNET98S_RAP, port);
128 bus_barrier(lesc->sc_rres, CNET98S_RAP, 2, BUS_SPACE_BARRIER_WRITE);
129 bus_write_2(lesc->sc_rres, CNET98S_BDP, val);
135}
136
137#ifdef LEDEBUG
138static uint16_t
139le_cbus_rdbcr(struct lance_softc *sc, uint16_t port)
140{
141 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
142
130}
131
132#ifdef LEDEBUG
133static uint16_t
134le_cbus_rdbcr(struct lance_softc *sc, uint16_t port)
135{
136 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
137
143 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, port);
144 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, 2,
145 BUS_SPACE_BARRIER_WRITE);
146 return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, CNET98S_BDP));
138 bus_write_2(lesc->sc_rres, CNET98S_RAP, port);
139 bus_barrier(lesc->sc_rres, CNET98S_RAP, 2, BUS_SPACE_BARRIER_WRITE);
140 return (bus_read_2(lesc->sc_rres, CNET98S_BDP));
147}
148#endif
149
150static void
151le_cbus_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
152{
153 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
154
141}
142#endif
143
144static void
145le_cbus_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
146{
147 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
148
155 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, port);
156 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, 2,
157 BUS_SPACE_BARRIER_WRITE);
158 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RDP, val);
149 bus_write_2(lesc->sc_rres, CNET98S_RAP, port);
150 bus_barrier(lesc->sc_rres, CNET98S_RAP, 2, BUS_SPACE_BARRIER_WRITE);
151 bus_write_2(lesc->sc_rres, CNET98S_RDP, val);
159}
160
161static uint16_t
162le_cbus_rdcsr(struct lance_softc *sc, uint16_t port)
163{
164 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
165
152}
153
154static uint16_t
155le_cbus_rdcsr(struct lance_softc *sc, uint16_t port)
156{
157 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
158
166 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, port);
167 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, CNET98S_RAP, 2,
168 BUS_SPACE_BARRIER_WRITE);
169 return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RDP));
159 bus_write_2(lesc->sc_rres, CNET98S_RAP, port);
160 bus_barrier(lesc->sc_rres, CNET98S_RAP, 2, BUS_SPACE_BARRIER_WRITE);
161 return (bus_read_2(lesc->sc_rres, CNET98S_RDP));
170}
171
172static void
173le_cbus_hwreset(struct lance_softc *sc)
174{
175 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
176
177 /*
178 * NB: These are Contec C-NET(98)S only.
179 */
180
181 /* Reset the chip. */
162}
163
164static void
165le_cbus_hwreset(struct lance_softc *sc)
166{
167 struct le_cbus_softc *lesc = (struct le_cbus_softc *)sc;
168
169 /*
170 * NB: These are Contec C-NET(98)S only.
171 */
172
173 /* Reset the chip. */
182 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RESET,
183 bus_space_read_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RESET));
174 bus_write_2(lesc->sc_rres, CNET98S_RESET,
175 bus_read_2(lesc->sc_rres, CNET98S_RESET));
184 DELAY(500);
185
186 /* ISA bus configuration */
187 /* ISACSR0 - set Master Mode Read Active time to 300ns. */
176 DELAY(500);
177
178 /* ISA bus configuration */
179 /* ISACSR0 - set Master Mode Read Active time to 300ns. */
188 le_cbus_wrbcr(sc, LE_BCR0, 0x0006);
180 le_cbus_wrbcr(sc, LE_BCR0, 0x0006);
189 /* ISACSR1 - set Master Mode Write Active time to 300ns. */
181 /* ISACSR1 - set Master Mode Write Active time to 300ns. */
190 le_cbus_wrbcr(sc, LE_BCR1, 0x0006);
191#ifdef LEDEBUG
182 le_cbus_wrbcr(sc, LE_BCR1, 0x0006);
183#ifdef LEDEBUG
192 device_printf(dev, "ISACSR2=0x%x\n", le_cbus_rdbcr(sc, LE_BCR2));
193#endif
194 /* ISACSR5 - LED1 */
195 le_cbus_wrbcr(sc, LE_BCR5, LE_B4_PSE | LE_B4_XMTE);
196 /* ISACSR6 - LED2 */
197 le_cbus_wrbcr(sc, LE_BCR6, LE_B4_PSE | LE_B4_RCVE);
198 /* ISACSR7 - LED3 */
199 le_cbus_wrbcr(sc, LE_BCR7, LE_B4_PSE | LE_B4_COLE);

--- 10 unchanged lines hidden (view full) ---

210 sc->sc_addr = segs[0].ds_addr;
211}
212
213static int
214le_cbus_probe(device_t dev)
215{
216 struct le_cbus_softc *lesc;
217 struct lance_softc *sc;
184 device_printf(dev, "ISACSR2=0x%x\n", le_cbus_rdbcr(sc, LE_BCR2));
185#endif
186 /* ISACSR5 - LED1 */
187 le_cbus_wrbcr(sc, LE_BCR5, LE_B4_PSE | LE_B4_XMTE);
188 /* ISACSR6 - LED2 */
189 le_cbus_wrbcr(sc, LE_BCR6, LE_B4_PSE | LE_B4_RCVE);
190 /* ISACSR7 - LED3 */
191 le_cbus_wrbcr(sc, LE_BCR7, LE_B4_PSE | LE_B4_COLE);

--- 10 unchanged lines hidden (view full) ---

202 sc->sc_addr = segs[0].ds_addr;
203}
204
205static int
206le_cbus_probe(device_t dev)
207{
208 struct le_cbus_softc *lesc;
209 struct lance_softc *sc;
218 int error;
210 int error, i;
219
220 /*
221 * Skip PnP devices as some wedge when trying to probe them as
222 * C-NET(98)S.
223 */
224 if (isa_get_vendorid(dev))
225 return (ENXIO);
226
227 lesc = device_get_softc(dev);
228 sc = &lesc->sc_am7990.lsc;
229
211
212 /*
213 * Skip PnP devices as some wedge when trying to probe them as
214 * C-NET(98)S.
215 */
216 if (isa_get_vendorid(dev))
217 return (ENXIO);
218
219 lesc = device_get_softc(dev);
220 sc = &lesc->sc_am7990.lsc;
221
230 lesc->sc_rrid = 0;
231 lesc->sc_rres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &lesc->sc_rrid,
222 i = 0;
223 lesc->sc_rres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &i,
232 le_ioaddr_cnet98s, CNET98S_IOSIZE, RF_ACTIVE);
233 if (lesc->sc_rres == NULL)
234 return (ENXIO);
235 isa_load_resourcev(lesc->sc_rres, le_ioaddr_cnet98s, CNET98S_IOSIZE);
224 le_ioaddr_cnet98s, CNET98S_IOSIZE, RF_ACTIVE);
225 if (lesc->sc_rres == NULL)
226 return (ENXIO);
227 isa_load_resourcev(lesc->sc_rres, le_ioaddr_cnet98s, CNET98S_IOSIZE);
236 lesc->sc_regt = rman_get_bustag(lesc->sc_rres);
237 lesc->sc_regh = rman_get_bushandle(lesc->sc_rres);
238
239 /* Reset the chip. */
228
229 /* Reset the chip. */
240 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RESET,
241 bus_space_read_2(lesc->sc_regt, lesc->sc_regh, CNET98S_RESET));
230 bus_write_2(lesc->sc_rres, CNET98S_RESET,
231 bus_read_2(lesc->sc_rres, CNET98S_RESET));
242 DELAY(500);
243
244 /* Stop the chip and put it in a known state. */
245 le_cbus_wrcsr(sc, LE_CSR0, LE_C0_STOP);
246 DELAY(100);
247 if (le_cbus_rdcsr(sc, LE_CSR0) != LE_C0_STOP) {
248 error = ENXIO;
249 goto fail;
250 }
251 le_cbus_wrcsr(sc, LE_CSR3, 0);
252 device_set_desc(dev, "C-NET(98)S");
253 error = BUS_PROBE_DEFAULT;
254
255 fail:
232 DELAY(500);
233
234 /* Stop the chip and put it in a known state. */
235 le_cbus_wrcsr(sc, LE_CSR0, LE_C0_STOP);
236 DELAY(100);
237 if (le_cbus_rdcsr(sc, LE_CSR0) != LE_C0_STOP) {
238 error = ENXIO;
239 goto fail;
240 }
241 le_cbus_wrcsr(sc, LE_CSR3, 0);
242 device_set_desc(dev, "C-NET(98)S");
243 error = BUS_PROBE_DEFAULT;
244
245 fail:
256 bus_release_resource(dev, SYS_RES_IOPORT, lesc->sc_rrid, lesc->sc_rres);
246 bus_release_resource(dev, SYS_RES_IOPORT,
247 rman_get_rid(lesc->sc_rres), lesc->sc_rres);
257 return (error);
258}
259
260static int
261le_cbus_attach(device_t dev)
262{
263 struct le_cbus_softc *lesc;
264 struct lance_softc *sc;
265 int error, i;
266
267 lesc = device_get_softc(dev);
268 sc = &lesc->sc_am7990.lsc;
269
270 LE_LOCK_INIT(sc, device_get_nameunit(dev));
271
248 return (error);
249}
250
251static int
252le_cbus_attach(device_t dev)
253{
254 struct le_cbus_softc *lesc;
255 struct lance_softc *sc;
256 int error, i;
257
258 lesc = device_get_softc(dev);
259 sc = &lesc->sc_am7990.lsc;
260
261 LE_LOCK_INIT(sc, device_get_nameunit(dev));
262
272 lesc->sc_rrid = 0;
273 lesc->sc_rres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &lesc->sc_rrid,
263 i = 0;
264 lesc->sc_rres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &i,
274 le_ioaddr_cnet98s, CNET98S_IOSIZE, RF_ACTIVE);
275 if (lesc->sc_rres == NULL) {
276 device_printf(dev, "cannot allocate registers\n");
277 error = ENXIO;
278 goto fail_mtx;
279 }
280 isa_load_resourcev(lesc->sc_rres, le_ioaddr_cnet98s, CNET98S_IOSIZE);
265 le_ioaddr_cnet98s, CNET98S_IOSIZE, RF_ACTIVE);
266 if (lesc->sc_rres == NULL) {
267 device_printf(dev, "cannot allocate registers\n");
268 error = ENXIO;
269 goto fail_mtx;
270 }
271 isa_load_resourcev(lesc->sc_rres, le_ioaddr_cnet98s, CNET98S_IOSIZE);
281 lesc->sc_regt = rman_get_bustag(lesc->sc_rres);
282 lesc->sc_regh = rman_get_bushandle(lesc->sc_rres);
283
272
284 lesc->sc_irid = 0;
273 i = 0;
285 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
274 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
286 &lesc->sc_irid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
275 &i, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
287 device_printf(dev, "cannot allocate interrupt\n");
288 error = ENXIO;
289 goto fail_rres;
290 }
291
292 error = bus_dma_tag_create(
293 bus_get_dma_tag(dev), /* parent */
294 1, 0, /* alignment, boundary */

--- 39 unchanged lines hidden (view full) ---

334 device_printf(dev, "cannot allocate DMA buffer memory\n");
335 goto fail_dtag;
336 }
337
338 sc->sc_addr = 0;
339 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem,
340 sc->sc_memsize, le_cbus_dma_callback, sc, 0);
341 if (error != 0 || sc->sc_addr == 0) {
276 device_printf(dev, "cannot allocate interrupt\n");
277 error = ENXIO;
278 goto fail_rres;
279 }
280
281 error = bus_dma_tag_create(
282 bus_get_dma_tag(dev), /* parent */
283 1, 0, /* alignment, boundary */

--- 39 unchanged lines hidden (view full) ---

323 device_printf(dev, "cannot allocate DMA buffer memory\n");
324 goto fail_dtag;
325 }
326
327 sc->sc_addr = 0;
328 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem,
329 sc->sc_memsize, le_cbus_dma_callback, sc, 0);
330 if (error != 0 || sc->sc_addr == 0) {
342 device_printf(dev, "cannot load DMA buffer map\n");
331 device_printf(dev, "cannot load DMA buffer map\n");
343 goto fail_dmem;
344 }
345
346 sc->sc_flags = 0;
347 sc->sc_conf3 = 0;
348
349 /*
350 * Extract the physical MAC address from the ROM.
351 */
352 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
332 goto fail_dmem;
333 }
334
335 sc->sc_flags = 0;
336 sc->sc_conf3 = 0;
337
338 /*
339 * Extract the physical MAC address from the ROM.
340 */
341 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
353 sc->sc_enaddr[i] = bus_space_read_1(lesc->sc_regt,
354 lesc->sc_regh, i * 2);
342 sc->sc_enaddr[i] = bus_read_1(lesc->sc_rres, i * 2);
355
356 sc->sc_copytodesc = lance_copytobuf_contig;
357 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
358 sc->sc_copytobuf = lance_copytobuf_contig;
359 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
360 sc->sc_zerobuf = lance_zerobuf_contig;
361
362 sc->sc_rdcsr = le_cbus_rdcsr;

--- 28 unchanged lines hidden (view full) ---

391 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
392 fail_dmem:
393 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
394 fail_dtag:
395 bus_dma_tag_destroy(lesc->sc_dmat);
396 fail_pdtag:
397 bus_dma_tag_destroy(lesc->sc_pdmat);
398 fail_ires:
343
344 sc->sc_copytodesc = lance_copytobuf_contig;
345 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
346 sc->sc_copytobuf = lance_copytobuf_contig;
347 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
348 sc->sc_zerobuf = lance_zerobuf_contig;
349
350 sc->sc_rdcsr = le_cbus_rdcsr;

--- 28 unchanged lines hidden (view full) ---

379 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
380 fail_dmem:
381 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
382 fail_dtag:
383 bus_dma_tag_destroy(lesc->sc_dmat);
384 fail_pdtag:
385 bus_dma_tag_destroy(lesc->sc_pdmat);
386 fail_ires:
399 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires);
387 bus_release_resource(dev, SYS_RES_IRQ,
388 rman_get_rid(lesc->sc_ires), lesc->sc_ires);
400 fail_rres:
389 fail_rres:
401 bus_release_resource(dev, SYS_RES_IOPORT, lesc->sc_rrid, lesc->sc_rres);
390 bus_release_resource(dev, SYS_RES_IOPORT,
391 rman_get_rid(lesc->sc_rres), lesc->sc_rres);
402 fail_mtx:
403 LE_LOCK_DESTROY(sc);
404 return (error);
405}
406
407static int
408le_cbus_detach(device_t dev)
409{

--- 4 unchanged lines hidden (view full) ---

414 sc = &lesc->sc_am7990.lsc;
415
416 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih);
417 am7990_detach(&lesc->sc_am7990);
418 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
419 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
420 bus_dma_tag_destroy(lesc->sc_dmat);
421 bus_dma_tag_destroy(lesc->sc_pdmat);
392 fail_mtx:
393 LE_LOCK_DESTROY(sc);
394 return (error);
395}
396
397static int
398le_cbus_detach(device_t dev)
399{

--- 4 unchanged lines hidden (view full) ---

404 sc = &lesc->sc_am7990.lsc;
405
406 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih);
407 am7990_detach(&lesc->sc_am7990);
408 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
409 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
410 bus_dma_tag_destroy(lesc->sc_dmat);
411 bus_dma_tag_destroy(lesc->sc_pdmat);
422 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires);
423 bus_release_resource(dev, SYS_RES_IOPORT, lesc->sc_rrid, lesc->sc_rres);
412 bus_release_resource(dev, SYS_RES_IRQ,
413 rman_get_rid(lesc->sc_ires), lesc->sc_ires);
414 bus_release_resource(dev, SYS_RES_IOPORT,
415 rman_get_rid(lesc->sc_rres), lesc->sc_rres);
424 LE_LOCK_DESTROY(sc);
425
426 return (0);
427}
428
429static int
430le_cbus_suspend(device_t dev)
431{

--- 20 unchanged lines hidden ---
416 LE_LOCK_DESTROY(sc);
417
418 return (0);
419}
420
421static int
422le_cbus_suspend(device_t dev)
423{

--- 20 unchanged lines hidden ---