if_le_ledma.c (166901) | if_le_ledma.c (182876) |
---|---|
1/* $NetBSD: if_le_ledma.c,v 1.26 2005/12/11 12:23:44 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace --- 24 unchanged lines hidden (view full) --- 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40#include <sys/cdefs.h> | 1/* $NetBSD: if_le_ledma.c,v 1.26 2005/12/11 12:23:44 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace --- 24 unchanged lines hidden (view full) --- 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40#include <sys/cdefs.h> |
41__FBSDID("$FreeBSD: head/sys/dev/le/if_le_ledma.c 166901 2007-02-23 12:19:07Z piso $"); | 41__FBSDID("$FreeBSD: head/sys/dev/le/if_le_ledma.c 182876 2008-09-08 20:20:44Z marius $"); |
42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/bus.h> 46#include <sys/endian.h> 47#include <sys/kernel.h> 48#include <sys/lock.h> 49#include <sys/module.h> --- 23 unchanged lines hidden (view full) --- 73#define LEDMA_BOUNDARY (16*1024*1024) /* must not cross 16MB boundary */ 74#define LEDMA_MEMSIZE (16*1024) /* LANCE memory size */ 75#define LEREG1_RDP 0 /* Register Data Port */ 76#define LEREG1_RAP 2 /* Register Address Port */ 77 78struct le_dma_softc { 79 struct am7990_softc sc_am7990; /* glue to MI code */ 80 | 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/bus.h> 46#include <sys/endian.h> 47#include <sys/kernel.h> 48#include <sys/lock.h> 49#include <sys/module.h> --- 23 unchanged lines hidden (view full) --- 73#define LEDMA_BOUNDARY (16*1024*1024) /* must not cross 16MB boundary */ 74#define LEDMA_MEMSIZE (16*1024) /* LANCE memory size */ 75#define LEREG1_RDP 0 /* Register Data Port */ 76#define LEREG1_RAP 2 /* Register Address Port */ 77 78struct le_dma_softc { 79 struct am7990_softc sc_am7990; /* glue to MI code */ 80 |
81 int sc_rrid; | |
82 struct resource *sc_rres; | 81 struct resource *sc_rres; |
83 bus_space_tag_t sc_regt; 84 bus_space_handle_t sc_regh; | |
85 | 82 |
86 int sc_irid; | |
87 struct resource *sc_ires; 88 void *sc_ih; 89 90 bus_dma_tag_t sc_dmat; 91 bus_dmamap_t sc_dmam; 92 bus_addr_t sc_laddr; /* LANCE DMA address */ 93 94 struct lsi64854_softc *sc_dma; /* pointer to DMA engine */ --- 15 unchanged lines hidden (view full) --- 110 DEVMETHOD(device_suspend, le_dma_suspend), 111 DEVMETHOD(device_resume, le_dma_resume), 112 113 { 0, 0 } 114}; 115 116DEFINE_CLASS_0(le, le_dma_driver, le_dma_methods, sizeof(struct le_dma_softc)); 117DRIVER_MODULE(le, dma, le_dma_driver, le_devclass, 0, 0); | 83 struct resource *sc_ires; 84 void *sc_ih; 85 86 bus_dma_tag_t sc_dmat; 87 bus_dmamap_t sc_dmam; 88 bus_addr_t sc_laddr; /* LANCE DMA address */ 89 90 struct lsi64854_softc *sc_dma; /* pointer to DMA engine */ --- 15 unchanged lines hidden (view full) --- 106 DEVMETHOD(device_suspend, le_dma_suspend), 107 DEVMETHOD(device_resume, le_dma_resume), 108 109 { 0, 0 } 110}; 111 112DEFINE_CLASS_0(le, le_dma_driver, le_dma_methods, sizeof(struct le_dma_softc)); 113DRIVER_MODULE(le, dma, le_dma_driver, le_devclass, 0, 0); |
114MODULE_DEPEND(le, dma, 1, 1, 1); |
|
118MODULE_DEPEND(le, ether, 1, 1, 1); 119 120/* 121 * Media types supported 122 */ 123static const int le_dma_supmedia[] = { 124 IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0), 125 IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0), --- 11 unchanged lines hidden (view full) --- 137static void le_dma_nocarrier(struct lance_softc *); 138static bus_dmamap_callback_t le_dma_dma_callback; 139 140static void 141le_dma_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 142{ 143 struct le_dma_softc *lesc = (struct le_dma_softc *)sc; 144 | 115MODULE_DEPEND(le, ether, 1, 1, 1); 116 117/* 118 * Media types supported 119 */ 120static const int le_dma_supmedia[] = { 121 IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0), 122 IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0), --- 11 unchanged lines hidden (view full) --- 134static void le_dma_nocarrier(struct lance_softc *); 135static bus_dmamap_callback_t le_dma_dma_callback; 136 137static void 138le_dma_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val) 139{ 140 struct le_dma_softc *lesc = (struct le_dma_softc *)sc; 141 |
145 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, LEREG1_RAP, port); 146 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, LEREG1_RAP, 2, 147 BUS_SPACE_BARRIER_WRITE); 148 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, LEREG1_RDP, val); | 142 bus_write_2(lesc->sc_rres, LEREG1_RAP, port); 143 bus_barrier(lesc->sc_rres, LEREG1_RAP, 2, BUS_SPACE_BARRIER_WRITE); 144 bus_write_2(lesc->sc_rres, LEREG1_RDP, val); |
149} 150 151static uint16_t 152le_dma_rdcsr(struct lance_softc *sc, uint16_t port) 153{ 154 struct le_dma_softc *lesc = (struct le_dma_softc *)sc; 155 | 145} 146 147static uint16_t 148le_dma_rdcsr(struct lance_softc *sc, uint16_t port) 149{ 150 struct le_dma_softc *lesc = (struct le_dma_softc *)sc; 151 |
156 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, LEREG1_RAP, port); 157 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, LEREG1_RAP, 2, 158 BUS_SPACE_BARRIER_WRITE); 159 return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, LEREG1_RDP)); | 152 bus_write_2(lesc->sc_rres, LEREG1_RAP, port); 153 bus_barrier(lesc->sc_rres, LEREG1_RAP, 2, BUS_SPACE_BARRIER_WRITE); 154 return (bus_read_2(lesc->sc_rres, LEREG1_RDP)); |
160} 161 162static void 163le_dma_setutp(struct lance_softc *sc) 164{ 165 struct lsi64854_softc *dma = ((struct le_dma_softc *)sc)->sc_dma; 166 167 L64854_SCSR(dma, L64854_GCSR(dma) | E_TP_AUI); --- 65 unchanged lines hidden (view full) --- 233 /* 234 * Reset DMA channel. 235 */ 236 csr = L64854_GCSR(dma); 237 aui_bit = csr & E_TP_AUI; 238 DMA_RESET(dma); 239 240 /* Write bits 24-31 of Lance address. */ | 155} 156 157static void 158le_dma_setutp(struct lance_softc *sc) 159{ 160 struct lsi64854_softc *dma = ((struct le_dma_softc *)sc)->sc_dma; 161 162 L64854_SCSR(dma, L64854_GCSR(dma) | E_TP_AUI); --- 65 unchanged lines hidden (view full) --- 228 /* 229 * Reset DMA channel. 230 */ 231 csr = L64854_GCSR(dma); 232 aui_bit = csr & E_TP_AUI; 233 DMA_RESET(dma); 234 235 /* Write bits 24-31 of Lance address. */ |
241 bus_space_write_4(dma->sc_regt, dma->sc_regh, L64854_REG_ENBAR, | 236 bus_write_4(dma->sc_res, L64854_REG_ENBAR, |
242 lesc->sc_laddr & 0xff000000); 243 244 DMA_ENINTR(dma); 245 246 /* 247 * Disable E-cache invalidates on chip writes. 248 * Retain previous cable selection bit. 249 */ --- 64 unchanged lines hidden (view full) --- 314} 315 316static int 317le_dma_attach(device_t dev) 318{ 319 struct le_dma_softc *lesc; 320 struct lsi64854_softc *dma; 321 struct lance_softc *sc; | 237 lesc->sc_laddr & 0xff000000); 238 239 DMA_ENINTR(dma); 240 241 /* 242 * Disable E-cache invalidates on chip writes. 243 * Retain previous cable selection bit. 244 */ --- 64 unchanged lines hidden (view full) --- 309} 310 311static int 312le_dma_attach(device_t dev) 313{ 314 struct le_dma_softc *lesc; 315 struct lsi64854_softc *dma; 316 struct lance_softc *sc; |
322 int error; | 317 int error, i; |
323 324 lesc = device_get_softc(dev); 325 sc = &lesc->sc_am7990.lsc; 326 327 LE_LOCK_INIT(sc, device_get_nameunit(dev)); 328 329 /* 330 * Establish link to `ledma' device. 331 * XXX hackery. 332 */ 333 dma = (struct lsi64854_softc *)device_get_softc(device_get_parent(dev)); 334 lesc->sc_dma = dma; 335 lesc->sc_dma->sc_client = lesc; 336 | 318 319 lesc = device_get_softc(dev); 320 sc = &lesc->sc_am7990.lsc; 321 322 LE_LOCK_INIT(sc, device_get_nameunit(dev)); 323 324 /* 325 * Establish link to `ledma' device. 326 * XXX hackery. 327 */ 328 dma = (struct lsi64854_softc *)device_get_softc(device_get_parent(dev)); 329 lesc->sc_dma = dma; 330 lesc->sc_dma->sc_client = lesc; 331 |
337 lesc->sc_rrid = 0; | 332 i = 0; |
338 lesc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | 333 lesc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, |
339 &lesc->sc_rrid, RF_ACTIVE); | 334 &i, RF_ACTIVE); |
340 if (lesc->sc_rres == NULL) { 341 device_printf(dev, "cannot allocate registers\n"); 342 error = ENXIO; 343 goto fail_mtx; 344 } | 335 if (lesc->sc_rres == NULL) { 336 device_printf(dev, "cannot allocate registers\n"); 337 error = ENXIO; 338 goto fail_mtx; 339 } |
345 lesc->sc_regt = rman_get_bustag(lesc->sc_rres); 346 lesc->sc_regh = rman_get_bushandle(lesc->sc_rres); | |
347 | 340 |
348 lesc->sc_irid = 0; | 341 i = 0; |
349 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, | 342 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, |
350 &lesc->sc_irid, RF_SHAREABLE | RF_ACTIVE)) == NULL) { | 343 &i, RF_SHAREABLE | RF_ACTIVE)) == NULL) { |
351 device_printf(dev, "cannot allocate interrupt\n"); 352 error = ENXIO; 353 goto fail_rres; 354 } 355 | 344 device_printf(dev, "cannot allocate interrupt\n"); 345 error = ENXIO; 346 goto fail_rres; 347 } 348 |
349 /* Attach the DMA engine. */ 350 error = lsi64854_attach(dma); 351 if (error != 0) { 352 device_printf(dev, "lsi64854_attach failed\n"); 353 goto fail_ires; 354 } 355 |
|
356 sc->sc_memsize = LEDMA_MEMSIZE; 357 error = bus_dma_tag_create( 358 dma->sc_parent_dmat, /* parent */ 359 LEDMA_ALIGNMENT, /* alignment */ 360 LEDMA_BOUNDARY, /* boundary */ 361 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 362 BUS_SPACE_MAXADDR, /* highaddr */ 363 NULL, NULL, /* filter, filterarg */ 364 sc->sc_memsize, /* maxsize */ 365 1, /* nsegments */ 366 sc->sc_memsize, /* maxsegsize */ 367 0, /* flags */ 368 NULL, NULL, /* lockfunc, lockarg */ 369 &lesc->sc_dmat); 370 if (error != 0) { 371 device_printf(dev, "cannot allocate buffer DMA tag\n"); | 356 sc->sc_memsize = LEDMA_MEMSIZE; 357 error = bus_dma_tag_create( 358 dma->sc_parent_dmat, /* parent */ 359 LEDMA_ALIGNMENT, /* alignment */ 360 LEDMA_BOUNDARY, /* boundary */ 361 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 362 BUS_SPACE_MAXADDR, /* highaddr */ 363 NULL, NULL, /* filter, filterarg */ 364 sc->sc_memsize, /* maxsize */ 365 1, /* nsegments */ 366 sc->sc_memsize, /* maxsegsize */ 367 0, /* flags */ 368 NULL, NULL, /* lockfunc, lockarg */ 369 &lesc->sc_dmat); 370 if (error != 0) { 371 device_printf(dev, "cannot allocate buffer DMA tag\n"); |
372 goto fail_ires; | 372 goto fail_lsi; |
373 } 374 375 error = bus_dmamem_alloc(lesc->sc_dmat, (void **)&sc->sc_mem, 376 BUS_DMA_WAITOK | BUS_DMA_COHERENT, &lesc->sc_dmam); 377 if (error != 0) { 378 device_printf(dev, "cannot allocate DMA buffer memory\n"); 379 goto fail_dtag; 380 } 381 382 lesc->sc_laddr = 0; 383 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem, 384 sc->sc_memsize, le_dma_dma_callback, lesc, 0); 385 if (error != 0 || lesc->sc_laddr == 0) { | 373 } 374 375 error = bus_dmamem_alloc(lesc->sc_dmat, (void **)&sc->sc_mem, 376 BUS_DMA_WAITOK | BUS_DMA_COHERENT, &lesc->sc_dmam); 377 if (error != 0) { 378 device_printf(dev, "cannot allocate DMA buffer memory\n"); 379 goto fail_dtag; 380 } 381 382 lesc->sc_laddr = 0; 383 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem, 384 sc->sc_memsize, le_dma_dma_callback, lesc, 0); 385 if (error != 0 || lesc->sc_laddr == 0) { |
386 device_printf(dev, "cannot load DMA buffer map\n"); | 386 device_printf(dev, "cannot load DMA buffer map\n"); |
387 goto fail_dmem; 388 } 389 390 sc->sc_addr = lesc->sc_laddr & 0xffffff; 391 sc->sc_flags = 0; 392 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON; 393 394 sc->sc_mediachange = le_dma_supmediachange; --- 35 unchanged lines hidden (view full) --- 430 fail_am7990: 431 am7990_detach(&lesc->sc_am7990); 432 fail_dmap: 433 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam); 434 fail_dmem: 435 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam); 436 fail_dtag: 437 bus_dma_tag_destroy(lesc->sc_dmat); | 387 goto fail_dmem; 388 } 389 390 sc->sc_addr = lesc->sc_laddr & 0xffffff; 391 sc->sc_flags = 0; 392 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON; 393 394 sc->sc_mediachange = le_dma_supmediachange; --- 35 unchanged lines hidden (view full) --- 430 fail_am7990: 431 am7990_detach(&lesc->sc_am7990); 432 fail_dmap: 433 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam); 434 fail_dmem: 435 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam); 436 fail_dtag: 437 bus_dma_tag_destroy(lesc->sc_dmat); |
438 fail_lsi: 439 lsi64854_detach(dma); |
|
438 fail_ires: | 440 fail_ires: |
439 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires); | 441 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(lesc->sc_ires), 442 lesc->sc_ires); |
440 fail_rres: | 443 fail_rres: |
441 bus_release_resource(dev, SYS_RES_MEMORY, lesc->sc_rrid, lesc->sc_rres); | 444 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lesc->sc_rres), 445 lesc->sc_rres); |
442 fail_mtx: 443 LE_LOCK_DESTROY(sc); 444 return (error); 445} 446 447static int 448le_dma_detach(device_t dev) 449{ 450 struct le_dma_softc *lesc; 451 struct lance_softc *sc; | 446 fail_mtx: 447 LE_LOCK_DESTROY(sc); 448 return (error); 449} 450 451static int 452le_dma_detach(device_t dev) 453{ 454 struct le_dma_softc *lesc; 455 struct lance_softc *sc; |
456 int error; |
|
452 453 lesc = device_get_softc(dev); 454 sc = &lesc->sc_am7990.lsc; 455 456 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih); 457 am7990_detach(&lesc->sc_am7990); 458 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam); 459 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam); 460 bus_dma_tag_destroy(lesc->sc_dmat); | 457 458 lesc = device_get_softc(dev); 459 sc = &lesc->sc_am7990.lsc; 460 461 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih); 462 am7990_detach(&lesc->sc_am7990); 463 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam); 464 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam); 465 bus_dma_tag_destroy(lesc->sc_dmat); |
461 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires); 462 bus_release_resource(dev, SYS_RES_MEMORY, lesc->sc_rrid, lesc->sc_rres); | 466 error = lsi64854_detach(lesc->sc_dma); 467 if (error != 0) 468 return (error); 469 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(lesc->sc_ires), 470 lesc->sc_ires); 471 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lesc->sc_rres), 472 lesc->sc_rres); |
463 LE_LOCK_DESTROY(sc); 464 465 return (0); 466} 467 468static int 469le_dma_suspend(device_t dev) 470{ --- 20 unchanged lines hidden --- | 473 LE_LOCK_DESTROY(sc); 474 475 return (0); 476} 477 478static int 479le_dma_suspend(device_t dev) 480{ --- 20 unchanged lines hidden --- |