Deleted Added
full compact
if_le_pci.c (166901) if_le_pci.c (183337)
1/* $NetBSD: if_le_pci.c,v 1.43 2005/12/11 12:22:49 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 and by Jason R. Thorpe of the Numerical Aerospace

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

67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
72 */
73
74#include <sys/cdefs.h>
1/* $NetBSD: if_le_pci.c,v 1.43 2005/12/11 12:22:49 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 and by Jason R. Thorpe of the Numerical Aerospace

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

67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
72 */
73
74#include <sys/cdefs.h>
75__FBSDID("$FreeBSD: head/sys/dev/le/if_le_pci.c 166901 2007-02-23 12:19:07Z piso $");
75__FBSDID("$FreeBSD: head/sys/dev/le/if_le_pci.c 183337 2008-09-24 21:26:46Z marius $");
76
77#include <sys/param.h>
78#include <sys/systm.h>
79#include <sys/bus.h>
80#include <sys/endian.h>
81#include <sys/kernel.h>
82#include <sys/lock.h>
83#include <sys/module.h>

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

106#define PCNET_MEMSIZE (32*1024)
107#define PCNET_PCI_RDP 0x10
108#define PCNET_PCI_RAP 0x12
109#define PCNET_PCI_BDP 0x16
110
111struct le_pci_softc {
112 struct am79900_softc sc_am79900; /* glue to MI code */
113
76
77#include <sys/param.h>
78#include <sys/systm.h>
79#include <sys/bus.h>
80#include <sys/endian.h>
81#include <sys/kernel.h>
82#include <sys/lock.h>
83#include <sys/module.h>

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

106#define PCNET_MEMSIZE (32*1024)
107#define PCNET_PCI_RDP 0x10
108#define PCNET_PCI_RAP 0x12
109#define PCNET_PCI_BDP 0x16
110
111struct le_pci_softc {
112 struct am79900_softc sc_am79900; /* glue to MI code */
113
114 int sc_rrid;
115 struct resource *sc_rres;
114 struct resource *sc_rres;
116 bus_space_tag_t sc_regt;
117 bus_space_handle_t sc_regh;
118
115
119 int sc_irid;
120 struct resource *sc_ires;
121 void *sc_ih;
122
123 bus_dma_tag_t sc_pdmat;
124 bus_dma_tag_t sc_dmat;
125 bus_dmamap_t sc_dmam;
126};
127

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

169static void le_pci_hwreset(struct lance_softc *);
170static bus_dmamap_callback_t le_pci_dma_callback;
171
172static void
173le_pci_wrbcr(struct lance_softc *sc, uint16_t port, uint16_t val)
174{
175 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
176
116 struct resource *sc_ires;
117 void *sc_ih;
118
119 bus_dma_tag_t sc_pdmat;
120 bus_dma_tag_t sc_dmat;
121 bus_dmamap_t sc_dmam;
122};
123

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

165static void le_pci_hwreset(struct lance_softc *);
166static bus_dmamap_callback_t le_pci_dma_callback;
167
168static void
169le_pci_wrbcr(struct lance_softc *sc, uint16_t port, uint16_t val)
170{
171 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
172
177 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port);
178 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2,
179 BUS_SPACE_BARRIER_WRITE);
180 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_BDP, val);
173 bus_write_2(lesc->sc_rres, PCNET_PCI_RAP, port);
174 bus_barrier(lesc->sc_rres, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE);
175 bus_write_2(lesc->sc_rres, PCNET_PCI_BDP, val);
181}
182
183static uint16_t
184le_pci_rdbcr(struct lance_softc *sc, uint16_t port)
185{
186 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
187
176}
177
178static uint16_t
179le_pci_rdbcr(struct lance_softc *sc, uint16_t port)
180{
181 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
182
188 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port);
189 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2,
190 BUS_SPACE_BARRIER_WRITE);
191 return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_BDP));
183 bus_write_2(lesc->sc_rres, PCNET_PCI_RAP, port);
184 bus_barrier(lesc->sc_rres, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE);
185 return (bus_read_2(lesc->sc_rres, PCNET_PCI_BDP));
192}
193
194static void
195le_pci_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
196{
197 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
198
186}
187
188static void
189le_pci_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
190{
191 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
192
199 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port);
200 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2,
201 BUS_SPACE_BARRIER_WRITE);
202 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP, val);
193 bus_write_2(lesc->sc_rres, PCNET_PCI_RAP, port);
194 bus_barrier(lesc->sc_rres, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE);
195 bus_write_2(lesc->sc_rres, PCNET_PCI_RDP, val);
203}
204
205static uint16_t
206le_pci_rdcsr(struct lance_softc *sc, uint16_t port)
207{
208 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
209
196}
197
198static uint16_t
199le_pci_rdcsr(struct lance_softc *sc, uint16_t port)
200{
201 struct le_pci_softc *lesc = (struct le_pci_softc *)sc;
202
210 bus_space_write_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, port);
211 bus_space_barrier(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RAP, 2,
212 BUS_SPACE_BARRIER_WRITE);
213 return (bus_space_read_2(lesc->sc_regt, lesc->sc_regh, PCNET_PCI_RDP));
203 bus_write_2(lesc->sc_rres, PCNET_PCI_RAP, port);
204 bus_barrier(lesc->sc_rres, PCNET_PCI_RAP, 2, BUS_SPACE_BARRIER_WRITE);
205 return (bus_read_2(lesc->sc_rres, PCNET_PCI_RDP));
214}
215
216static int
217le_pci_mediachange(struct lance_softc *sc)
218{
219 struct ifmedia *ifm = &sc->sc_media;
220 uint16_t reg;
221

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

317 lesc = device_get_softc(dev);
318 sc = &lesc->sc_am79900.lsc;
319
320 LE_LOCK_INIT(sc, device_get_nameunit(dev));
321
322 pci_enable_busmaster(dev);
323 pci_enable_io(dev, PCIM_CMD_PORTEN);
324
206}
207
208static int
209le_pci_mediachange(struct lance_softc *sc)
210{
211 struct ifmedia *ifm = &sc->sc_media;
212 uint16_t reg;
213

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

309 lesc = device_get_softc(dev);
310 sc = &lesc->sc_am79900.lsc;
311
312 LE_LOCK_INIT(sc, device_get_nameunit(dev));
313
314 pci_enable_busmaster(dev);
315 pci_enable_io(dev, PCIM_CMD_PORTEN);
316
325 lesc->sc_rrid = PCIR_BAR(0);
317 i = PCIR_BAR(0);
326 lesc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
318 lesc->sc_rres = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
327 &lesc->sc_rrid, RF_ACTIVE);
319 &i, RF_ACTIVE);
328 if (lesc->sc_rres == NULL) {
329 device_printf(dev, "cannot allocate registers\n");
330 error = ENXIO;
331 goto fail_mtx;
332 }
320 if (lesc->sc_rres == NULL) {
321 device_printf(dev, "cannot allocate registers\n");
322 error = ENXIO;
323 goto fail_mtx;
324 }
333 lesc->sc_regt = rman_get_bustag(lesc->sc_rres);
334 lesc->sc_regh = rman_get_bushandle(lesc->sc_rres);
335
325
336 lesc->sc_irid = 0;
326 i = 0;
337 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
327 if ((lesc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
338 &lesc->sc_irid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
328 &i, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
339 device_printf(dev, "cannot allocate interrupt\n");
340 error = ENXIO;
341 goto fail_rres;
342 }
343
344 error = bus_dma_tag_create(
345 bus_get_dma_tag(dev), /* parent */
346 1, 0, /* alignment, boundary */

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

387 device_printf(dev, "cannot allocate DMA buffer memory\n");
388 goto fail_dtag;
389 }
390
391 sc->sc_addr = 0;
392 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem,
393 sc->sc_memsize, le_pci_dma_callback, sc, 0);
394 if (error != 0 || sc->sc_addr == 0) {
329 device_printf(dev, "cannot allocate interrupt\n");
330 error = ENXIO;
331 goto fail_rres;
332 }
333
334 error = bus_dma_tag_create(
335 bus_get_dma_tag(dev), /* parent */
336 1, 0, /* alignment, boundary */

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

377 device_printf(dev, "cannot allocate DMA buffer memory\n");
378 goto fail_dtag;
379 }
380
381 sc->sc_addr = 0;
382 error = bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmam, sc->sc_mem,
383 sc->sc_memsize, le_pci_dma_callback, sc, 0);
384 if (error != 0 || sc->sc_addr == 0) {
395 device_printf(dev, "cannot load DMA buffer map\n");
385 device_printf(dev, "cannot load DMA buffer map\n");
396 goto fail_dmem;
397 }
398
399 sc->sc_flags = LE_BSWAP;
400 sc->sc_conf3 = 0;
401
402 sc->sc_mediastatus = NULL;
403 switch (pci_get_device(dev)) {

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

412 sc->sc_supmedia = le_pci_supmedia;
413 sc->sc_nsupmedia = sizeof(le_pci_supmedia) / sizeof(int);
414 sc->sc_defaultmedia = le_pci_supmedia[0];
415 }
416
417 /*
418 * Extract the physical MAC address from the ROM.
419 */
386 goto fail_dmem;
387 }
388
389 sc->sc_flags = LE_BSWAP;
390 sc->sc_conf3 = 0;
391
392 sc->sc_mediastatus = NULL;
393 switch (pci_get_device(dev)) {

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

402 sc->sc_supmedia = le_pci_supmedia;
403 sc->sc_nsupmedia = sizeof(le_pci_supmedia) / sizeof(int);
404 sc->sc_defaultmedia = le_pci_supmedia[0];
405 }
406
407 /*
408 * Extract the physical MAC address from the ROM.
409 */
420 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
421 sc->sc_enaddr[i] =
422 bus_space_read_1(lesc->sc_regt, lesc->sc_regh, i);
410 bus_read_region_1(lesc->sc_rres, 0, sc->sc_enaddr,
411 sizeof(sc->sc_enaddr));
423
424 sc->sc_copytodesc = lance_copytobuf_contig;
425 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
426 sc->sc_copytobuf = lance_copytobuf_contig;
427 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
428 sc->sc_zerobuf = lance_zerobuf_contig;
429
430 sc->sc_rdcsr = le_pci_rdcsr;

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

456 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
457 fail_dmem:
458 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
459 fail_dtag:
460 bus_dma_tag_destroy(lesc->sc_dmat);
461 fail_pdtag:
462 bus_dma_tag_destroy(lesc->sc_pdmat);
463 fail_ires:
412
413 sc->sc_copytodesc = lance_copytobuf_contig;
414 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
415 sc->sc_copytobuf = lance_copytobuf_contig;
416 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
417 sc->sc_zerobuf = lance_zerobuf_contig;
418
419 sc->sc_rdcsr = le_pci_rdcsr;

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

445 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
446 fail_dmem:
447 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
448 fail_dtag:
449 bus_dma_tag_destroy(lesc->sc_dmat);
450 fail_pdtag:
451 bus_dma_tag_destroy(lesc->sc_pdmat);
452 fail_ires:
464 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires);
453 bus_release_resource(dev, SYS_RES_IRQ,
454 rman_get_rid(lesc->sc_ires), lesc->sc_ires);
465 fail_rres:
455 fail_rres:
466 bus_release_resource(dev, SYS_RES_IOPORT, lesc->sc_rrid, lesc->sc_rres);
456 bus_release_resource(dev, SYS_RES_IOPORT,
457 rman_get_rid(lesc->sc_rres), lesc->sc_rres);
467 fail_mtx:
468 LE_LOCK_DESTROY(sc);
469 return (error);
470}
471
472static int
473le_pci_detach(device_t dev)
474{

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

479 sc = &lesc->sc_am79900.lsc;
480
481 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih);
482 am79900_detach(&lesc->sc_am79900);
483 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
484 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
485 bus_dma_tag_destroy(lesc->sc_dmat);
486 bus_dma_tag_destroy(lesc->sc_pdmat);
458 fail_mtx:
459 LE_LOCK_DESTROY(sc);
460 return (error);
461}
462
463static int
464le_pci_detach(device_t dev)
465{

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

470 sc = &lesc->sc_am79900.lsc;
471
472 bus_teardown_intr(dev, lesc->sc_ires, lesc->sc_ih);
473 am79900_detach(&lesc->sc_am79900);
474 bus_dmamap_unload(lesc->sc_dmat, lesc->sc_dmam);
475 bus_dmamem_free(lesc->sc_dmat, sc->sc_mem, lesc->sc_dmam);
476 bus_dma_tag_destroy(lesc->sc_dmat);
477 bus_dma_tag_destroy(lesc->sc_pdmat);
487 bus_release_resource(dev, SYS_RES_IRQ, lesc->sc_irid, lesc->sc_ires);
488 bus_release_resource(dev, SYS_RES_IOPORT, lesc->sc_rrid, lesc->sc_rres);
478 bus_release_resource(dev, SYS_RES_IRQ,
479 rman_get_rid(lesc->sc_ires), lesc->sc_ires);
480 bus_release_resource(dev, SYS_RES_IOPORT,
481 rman_get_rid(lesc->sc_rres), lesc->sc_rres);
489 LE_LOCK_DESTROY(sc);
490
491 return (0);
492}
493
494static int
495le_pci_suspend(device_t dev)
496{

--- 20 unchanged lines hidden ---
482 LE_LOCK_DESTROY(sc);
483
484 return (0);
485}
486
487static int
488le_pci_suspend(device_t dev)
489{

--- 20 unchanged lines hidden ---