2001-11-13 10:56:39 +03:00
|
|
|
/* $NetBSD: if_le_isapnp.c,v 1.20 2001/11/13 07:56:40 lukem Exp $ */
|
1997-06-07 03:43:45 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1997-04-01 00:22:19 +04:00
|
|
|
|
|
|
|
/*
|
1997-04-01 00:36:38 +04:00
|
|
|
* Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org> and
|
1998-04-18 14:35:48 +04:00
|
|
|
* Matthias Drochner. All rights reserved.
|
1997-04-01 00:22:19 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Jonathan Stone.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:56:39 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_le_isapnp.c,v 1.20 2001/11/13 07:56:40 lukem Exp $");
|
|
|
|
|
1997-04-01 00:22:19 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
2000-11-14 21:42:55 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1997-04-01 00:22:19 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
|
|
|
|
|
|
|
#include <dev/isapnp/isapnpreg.h>
|
|
|
|
#include <dev/isapnp/isapnpvar.h>
|
1998-07-23 23:30:44 +04:00
|
|
|
#include <dev/isapnp/isapnpdevs.h>
|
1997-04-01 00:22:19 +04:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1997-04-01 00:22:19 +04:00
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
|
|
|
#include <dev/isapnp/if_levar.h>
|
|
|
|
|
|
|
|
int le_isapnp_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
void le_isapnp_attach __P((struct device *, struct device *, void *));
|
|
|
|
|
1997-04-09 06:10:48 +04:00
|
|
|
struct cfattach le_isapnp_ca = {
|
1997-04-01 00:22:19 +04:00
|
|
|
sizeof(struct le_softc), le_isapnp_match, le_isapnp_attach
|
|
|
|
};
|
|
|
|
|
1997-04-01 00:36:38 +04:00
|
|
|
int le_isapnp_intredge __P((void *));
|
1998-07-21 21:36:01 +04:00
|
|
|
static void le_isapnp_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
|
|
|
|
static u_int16_t le_isapnp_rdcsr __P((struct lance_softc *, u_int16_t));
|
1997-04-01 00:22:19 +04:00
|
|
|
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
#define LE_ISAPNP_MEMSIZE 16384
|
1997-04-01 00:22:19 +04:00
|
|
|
|
1997-04-01 00:36:38 +04:00
|
|
|
static void
|
1997-04-01 00:22:19 +04:00
|
|
|
le_isapnp_wrcsr(sc, port, val)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1997-04-01 00:22:19 +04:00
|
|
|
u_int16_t port, val;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
bus_space_tag_t iot = lesc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = lesc->sc_ioh;
|
|
|
|
|
|
|
|
bus_space_write_2(iot, ioh, lesc->sc_rap, port);
|
|
|
|
bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
|
|
|
|
}
|
|
|
|
|
1997-04-01 00:36:38 +04:00
|
|
|
static u_int16_t
|
1997-04-01 00:22:19 +04:00
|
|
|
le_isapnp_rdcsr(sc, port)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1997-04-01 00:22:19 +04:00
|
|
|
u_int16_t port;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
bus_space_tag_t iot = lesc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = lesc->sc_ioh;
|
|
|
|
u_int16_t val;
|
|
|
|
|
|
|
|
bus_space_write_2(iot, ioh, lesc->sc_rap, port);
|
|
|
|
val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
le_isapnp_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
1999-03-22 13:00:09 +03:00
|
|
|
int pri, variant;
|
1999-03-22 12:44:12 +03:00
|
|
|
|
1999-03-22 13:00:09 +03:00
|
|
|
pri = isapnp_devmatch(aux, &isapnp_le_devinfo, &variant);
|
|
|
|
if (pri && variant > 0)
|
|
|
|
pri = 0;
|
|
|
|
return (pri);
|
1997-04-01 00:22:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
le_isapnp_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (void *)self;
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc = &lesc->sc_am7990.lsc;
|
1997-04-01 00:22:19 +04:00
|
|
|
struct isapnp_attach_args *ipa = aux;
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1997-06-07 03:43:45 +04:00
|
|
|
bus_dma_tag_t dmat;
|
|
|
|
bus_dma_segment_t seg;
|
1998-06-25 23:18:05 +04:00
|
|
|
int i, rseg, error;
|
1997-04-01 00:22:19 +04:00
|
|
|
|
1997-12-17 04:31:59 +03:00
|
|
|
if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
|
|
|
|
printf("%s: error in region allocation\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-04-01 00:22:19 +04:00
|
|
|
lesc->sc_iot = iot = ipa->ipa_iot;
|
|
|
|
lesc->sc_ioh = ioh = ipa->ipa_io[0].h;
|
1997-06-07 03:43:45 +04:00
|
|
|
lesc->sc_dmat = dmat = ipa->ipa_dmat;
|
1997-04-01 00:22:19 +04:00
|
|
|
|
|
|
|
lesc->sc_rap = PCNET_RAP;
|
|
|
|
lesc->sc_rdp = PCNET_RDP;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the physical MAC address from the ROM.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sizeof(sc->sc_enaddr); i++)
|
|
|
|
sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, PCNET_SAPROM+i);
|
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
/*
|
|
|
|
* Allocate a DMA area for the card.
|
|
|
|
*/
|
2000-11-14 21:42:55 +03:00
|
|
|
if (bus_dmamem_alloc(dmat, LE_ISAPNP_MEMSIZE, PAGE_SIZE, 0, &seg, 1,
|
1997-06-07 03:43:45 +04:00
|
|
|
&rseg, BUS_DMA_NOWAIT)) {
|
1997-04-01 00:22:19 +04:00
|
|
|
printf("%s: couldn't allocate memory for card\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
1997-06-07 03:43:45 +04:00
|
|
|
if (bus_dmamem_map(dmat, &seg, rseg, LE_ISAPNP_MEMSIZE,
|
1998-02-04 03:38:50 +03:00
|
|
|
(caddr_t *)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
|
1997-06-07 03:43:45 +04:00
|
|
|
printf("%s: couldn't map memory for card\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and load the DMA map for the DMA area.
|
|
|
|
*/
|
|
|
|
if (bus_dmamap_create(dmat, LE_ISAPNP_MEMSIZE, 1,
|
|
|
|
LE_ISAPNP_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
|
|
|
|
printf("%s: couldn't create DMA map\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
bus_dmamem_free(dmat, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bus_dmamap_load(dmat, lesc->sc_dmam,
|
|
|
|
sc->sc_mem, LE_ISAPNP_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
|
|
|
|
printf("%s: coundn't load DMA map\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
bus_dmamem_free(dmat, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
1997-04-01 00:22:19 +04:00
|
|
|
|
|
|
|
sc->sc_conf3 = 0;
|
1997-06-07 03:43:45 +04:00
|
|
|
sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
|
|
|
|
sc->sc_memsize = LE_ISAPNP_MEMSIZE;
|
1997-04-01 00:22:19 +04:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
sc->sc_copytodesc = lance_copytobuf_contig;
|
|
|
|
sc->sc_copyfromdesc = lance_copyfrombuf_contig;
|
|
|
|
sc->sc_copytobuf = lance_copytobuf_contig;
|
|
|
|
sc->sc_copyfrombuf = lance_copyfrombuf_contig;
|
|
|
|
sc->sc_zerobuf = lance_zerobuf_contig;
|
1997-04-01 00:22:19 +04:00
|
|
|
|
|
|
|
sc->sc_rdcsr = le_isapnp_rdcsr;
|
|
|
|
sc->sc_wrcsr = le_isapnp_wrcsr;
|
|
|
|
sc->sc_hwinit = NULL;
|
|
|
|
|
1998-06-25 23:18:05 +04:00
|
|
|
if (ipa->ipa_ndrq > 0) {
|
|
|
|
if ((error = isa_dmacascade(ipa->ipa_ic,
|
|
|
|
ipa->ipa_drq[0].num)) != 0) {
|
|
|
|
printf("%s: unable to cascade DRQ, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1997-04-01 00:36:38 +04:00
|
|
|
|
1997-04-01 00:22:19 +04:00
|
|
|
lesc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
|
1997-10-29 00:27:55 +03:00
|
|
|
ipa->ipa_irq[0].type, IPL_NET, le_isapnp_intredge, sc);
|
1998-06-25 23:18:05 +04:00
|
|
|
|
|
|
|
printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
|
|
|
|
ipa->ipa_devclass);
|
1998-07-21 21:36:01 +04:00
|
|
|
am7990_config(&lesc->sc_am7990);
|
1997-04-01 00:22:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
le_isapnp_intredge(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (am7990_intr(arg) == 0)
|
|
|
|
return (0);
|
|
|
|
for (;;)
|
|
|
|
if (am7990_intr(arg) == 0)
|
|
|
|
return (1);
|
|
|
|
}
|