| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_le_ledma.c,v 1.30 2008/04/28 20:23:57 martin Exp $ */ | | 1 | /* $NetBSD: if_le_ledma.c,v 1.30.10.1 2009/06/19 21:25:21 snj Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace | | 8 | * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace |
9 | * Simulation Facility, NASA Ames Research Center; Paul Kranenburg. | | 9 | * Simulation Facility, NASA Ames Research Center; Paul Kranenburg. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: if_le_ledma.c,v 1.30 2008/04/28 20:23:57 martin Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: if_le_ledma.c,v 1.30.10.1 2009/06/19 21:25:21 snj Exp $"); |
35 | | | 35 | |
36 | #include "opt_inet.h" | | 36 | #include "opt_inet.h" |
37 | #include "bpfilter.h" | | 37 | #include "bpfilter.h" |
38 | | | 38 | |
39 | #include <sys/param.h> | | 39 | #include <sys/param.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/mbuf.h> | | 41 | #include <sys/mbuf.h> |
42 | #include <sys/syslog.h> | | 42 | #include <sys/syslog.h> |
43 | #include <sys/socket.h> | | 43 | #include <sys/socket.h> |
44 | #include <sys/device.h> | | 44 | #include <sys/device.h> |
45 | #include <sys/malloc.h> | | 45 | #include <sys/malloc.h> |
46 | | | 46 | |
47 | #include <net/if.h> | | 47 | #include <net/if.h> |
| @@ -73,26 +73,28 @@ __KERNEL_RCSID(0, "$NetBSD: if_le_ledma. | | | @@ -73,26 +73,28 @@ __KERNEL_RCSID(0, "$NetBSD: if_le_ledma. |
73 | * LANCE registers. | | 73 | * LANCE registers. |
74 | */ | | 74 | */ |
75 | #define LEREG1_RDP 0 /* Register Data port */ | | 75 | #define LEREG1_RDP 0 /* Register Data port */ |
76 | #define LEREG1_RAP 2 /* Register Address port */ | | 76 | #define LEREG1_RAP 2 /* Register Address port */ |
77 | | | 77 | |
78 | struct le_softc { | | 78 | struct le_softc { |
79 | struct am7990_softc sc_am7990; /* glue to MI code */ | | 79 | struct am7990_softc sc_am7990; /* glue to MI code */ |
80 | struct sbusdev sc_sd; /* sbus device */ | | 80 | struct sbusdev sc_sd; /* sbus device */ |
81 | bus_space_tag_t sc_bustag; | | 81 | bus_space_tag_t sc_bustag; |
82 | bus_dmamap_t sc_dmamap; | | 82 | bus_dmamap_t sc_dmamap; |
83 | bus_space_handle_t sc_reg; /* LANCE registers */ | | 83 | bus_space_handle_t sc_reg; /* LANCE registers */ |
84 | struct lsi64854_softc *sc_dma; /* pointer to my dma */ | | 84 | struct lsi64854_softc *sc_dma; /* pointer to my dma */ |
85 | u_int sc_laddr; /* LANCE DMA address */ | | 85 | u_int sc_laddr; /* LANCE DMA address */ |
| | | 86 | u_int sc_lostcount; |
| | | 87 | #define LE_LOSTTHRESH 5 /* lost carrior count to switch media */ |
86 | }; | | 88 | }; |
87 | | | 89 | |
88 | #define MEMSIZE (16*1024) /* LANCE memory size */ | | 90 | #define MEMSIZE (16*1024) /* LANCE memory size */ |
89 | #define LEDMA_BOUNDARY (16*1024*1024) /* must not cross 16MB boundary */ | | 91 | #define LEDMA_BOUNDARY (16*1024*1024) /* must not cross 16MB boundary */ |
90 | | | 92 | |
91 | int lematch_ledma(device_t, cfdata_t, void *); | | 93 | int lematch_ledma(device_t, cfdata_t, void *); |
92 | void leattach_ledma(device_t, device_t, void *); | | 94 | void leattach_ledma(device_t, device_t, void *); |
93 | | | 95 | |
94 | /* | | 96 | /* |
95 | * Media types supported by the Sun4m. | | 97 | * Media types supported by the Sun4m. |
96 | */ | | 98 | */ |
97 | static int lemedia[] = { | | 99 | static int lemedia[] = { |
98 | IFM_ETHER|IFM_10_T, | | 100 | IFM_ETHER|IFM_10_T, |
| @@ -267,26 +269,32 @@ lehwinit(struct lance_softc *sc) | | | @@ -267,26 +269,32 @@ lehwinit(struct lance_softc *sc) |
267 | break; | | 269 | break; |
268 | | | 270 | |
269 | case IFM_10_5: | | 271 | case IFM_10_5: |
270 | lesetaui(sc); | | 272 | lesetaui(sc); |
271 | break; | | 273 | break; |
272 | } | | 274 | } |
273 | } | | 275 | } |
274 | | | 276 | |
275 | static void | | 277 | static void |
276 | lenocarrier(struct lance_softc *sc) | | 278 | lenocarrier(struct lance_softc *sc) |
277 | { | | 279 | { |
278 | struct le_softc *lesc = (struct le_softc *)sc; | | 280 | struct le_softc *lesc = (struct le_softc *)sc; |
279 | | | 281 | |
| | | 282 | /* it may take a while for modern switches to set 10baseT media */ |
| | | 283 | if (lesc->sc_lostcount++ < LE_LOSTTHRESH) |
| | | 284 | return; |
| | | 285 | |
| | | 286 | lesc->sc_lostcount = 0; |
| | | 287 | |
280 | /* | | 288 | /* |
281 | * Check if the user has requested a certain cable type, and | | 289 | * Check if the user has requested a certain cable type, and |
282 | * if so, honor that request. | | 290 | * if so, honor that request. |
283 | */ | | 291 | */ |
284 | printf("%s: lost carrier on ", device_xname(sc->sc_dev)); | | 292 | printf("%s: lost carrier on ", device_xname(sc->sc_dev)); |
285 | | | 293 | |
286 | if (L64854_GCSR(lesc->sc_dma) & E_TP_AUI) { | | 294 | if (L64854_GCSR(lesc->sc_dma) & E_TP_AUI) { |
287 | printf("UTP port"); | | 295 | printf("UTP port"); |
288 | switch (IFM_SUBTYPE(sc->sc_media.ifm_media)) { | | 296 | switch (IFM_SUBTYPE(sc->sc_media.ifm_media)) { |
289 | case IFM_10_5: | | 297 | case IFM_10_5: |
290 | case IFM_AUTO: | | 298 | case IFM_AUTO: |
291 | printf(", switching to AUI port"); | | 299 | printf(", switching to AUI port"); |
292 | lesetaui(sc); | | 300 | lesetaui(sc); |
| @@ -369,27 +377,27 @@ leattach_ledma(device_t parent, device_t | | | @@ -369,27 +377,27 @@ leattach_ledma(device_t parent, device_t |
369 | | | 377 | |
370 | /* Load DMA buffer */ | | 378 | /* Load DMA buffer */ |
371 | if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap, sc->sc_mem, | | 379 | if ((error = bus_dmamap_load(dmatag, lesc->sc_dmamap, sc->sc_mem, |
372 | MEMSIZE, NULL, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) { | | 380 | MEMSIZE, NULL, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) { |
373 | aprint_error(": DMA buffer map load error %d\n", error); | | 381 | aprint_error(": DMA buffer map load error %d\n", error); |
374 | bus_dmamem_free(dmatag, &seg, rseg); | | 382 | bus_dmamem_free(dmatag, &seg, rseg); |
375 | bus_dmamem_unmap(dmatag, sc->sc_mem, MEMSIZE); | | 383 | bus_dmamem_unmap(dmatag, sc->sc_mem, MEMSIZE); |
376 | return; | | 384 | return; |
377 | } | | 385 | } |
378 | | | 386 | |
379 | lesc->sc_laddr = lesc->sc_dmamap->dm_segs[0].ds_addr; | | 387 | lesc->sc_laddr = lesc->sc_dmamap->dm_segs[0].ds_addr; |
380 | sc->sc_addr = lesc->sc_laddr & 0xffffff; | | 388 | sc->sc_addr = lesc->sc_laddr & 0xffffff; |
381 | sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON; | | 389 | sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON; |
382 | | | 390 | lesc->sc_lostcount = 0; |
383 | | | 391 | |
384 | /* Assume SBus is grandparent */ | | 392 | /* Assume SBus is grandparent */ |
385 | lesc->sc_sd.sd_reset = (void *)lance_reset; | | 393 | lesc->sc_sd.sd_reset = (void *)lance_reset; |
386 | sbus_establish(&lesc->sc_sd, parent); | | 394 | sbus_establish(&lesc->sc_sd, parent); |
387 | | | 395 | |
388 | sc->sc_mediachange = lemediachange; | | 396 | sc->sc_mediachange = lemediachange; |
389 | sc->sc_mediastatus = lemediastatus; | | 397 | sc->sc_mediastatus = lemediastatus; |
390 | sc->sc_supmedia = lemedia; | | 398 | sc->sc_supmedia = lemedia; |
391 | sc->sc_nsupmedia = NLEMEDIA; | | 399 | sc->sc_nsupmedia = NLEMEDIA; |
392 | sc->sc_defaultmedia = IFM_ETHER|IFM_AUTO; | | 400 | sc->sc_defaultmedia = IFM_ETHER|IFM_AUTO; |
393 | | | 401 | |
394 | prom_getether(sa->sa_node, sc->sc_enaddr); | | 402 | prom_getether(sa->sa_node, sc->sc_enaddr); |
395 | | | 403 | |