Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.34.2.1
      1  1.34.2.1      yamt /*	$NetBSD: if_le.c,v 1.34.2.1 2008/05/18 12:32:29 yamt Exp $	*/
      2      1.18   mycroft 
      3      1.18   mycroft /*-
      4      1.18   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.18   mycroft  * All rights reserved.
      6      1.18   mycroft  *
      7      1.18   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8      1.18   mycroft  * by Charles M. Hannum.
      9      1.18   mycroft  *
     10      1.18   mycroft  * Redistribution and use in source and binary forms, with or without
     11      1.18   mycroft  * modification, are permitted provided that the following conditions
     12      1.18   mycroft  * are met:
     13      1.18   mycroft  * 1. Redistributions of source code must retain the above copyright
     14      1.18   mycroft  *    notice, this list of conditions and the following disclaimer.
     15      1.18   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.18   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17      1.18   mycroft  *    documentation and/or other materials provided with the distribution.
     18      1.18   mycroft  *
     19      1.18   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.18   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.18   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.18   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.18   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.18   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.18   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.18   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.18   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.18   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.18   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30      1.18   mycroft  */
     31       1.1     chuck 
     32       1.1     chuck /*-
     33       1.2   mycroft  * Copyright (c) 1992, 1993
     34       1.1     chuck  *	The Regents of the University of California.  All rights reserved.
     35       1.1     chuck  *
     36       1.2   mycroft  * This code is derived from software contributed to Berkeley by
     37       1.2   mycroft  * Ralph Campbell and Rick Macklem.
     38       1.2   mycroft  *
     39       1.1     chuck  * Redistribution and use in source and binary forms, with or without
     40       1.1     chuck  * modification, are permitted provided that the following conditions
     41       1.1     chuck  * are met:
     42       1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     43       1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     44       1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     45       1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     46       1.1     chuck  *    documentation and/or other materials provided with the distribution.
     47      1.30       agc  * 3. Neither the name of the University nor the names of its contributors
     48       1.1     chuck  *    may be used to endorse or promote products derived from this software
     49       1.1     chuck  *    without specific prior written permission.
     50       1.1     chuck  *
     51       1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     52       1.1     chuck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53       1.1     chuck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54       1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     55       1.1     chuck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56       1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57       1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58       1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59       1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60       1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61       1.1     chuck  * SUCH DAMAGE.
     62       1.1     chuck  *
     63       1.2   mycroft  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     64       1.1     chuck  */
     65      1.29     lukem 
     66      1.29     lukem #include <sys/cdefs.h>
     67  1.34.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.34.2.1 2008/05/18 12:32:29 yamt Exp $");
     68       1.1     chuck 
     69      1.16  jonathan #include "opt_inet.h"
     70       1.1     chuck #include "bpfilter.h"
     71       1.1     chuck 
     72       1.1     chuck #include <sys/param.h>
     73       1.1     chuck #include <sys/systm.h>
     74       1.1     chuck #include <sys/mbuf.h>
     75       1.2   mycroft #include <sys/syslog.h>
     76       1.1     chuck #include <sys/socket.h>
     77       1.2   mycroft #include <sys/device.h>
     78       1.1     chuck 
     79      1.28   thorpej #include <uvm/uvm_extern.h>
     80      1.28   thorpej 
     81       1.1     chuck #include <net/if.h>
     82      1.12        is #include <net/if_ether.h>
     83      1.13   thorpej #include <net/if_media.h>
     84       1.1     chuck 
     85       1.1     chuck #ifdef INET
     86       1.1     chuck #include <netinet/in.h>
     87      1.12        is #include <netinet/if_inarp.h>
     88       1.1     chuck #endif
     89       1.1     chuck 
     90      1.10     chuck #include <machine/autoconf.h>
     91       1.1     chuck #include <machine/cpu.h>
     92      1.21       scw #include <machine/bus.h>
     93       1.1     chuck 
     94       1.2   mycroft #include <mvme68k/dev/pccreg.h>
     95       1.7     chuck #include <mvme68k/dev/pccvar.h>
     96       1.7     chuck 
     97      1.17  drochner #include <dev/ic/lancereg.h>
     98      1.17  drochner #include <dev/ic/lancevar.h>
     99       1.2   mycroft #include <dev/ic/am7990reg.h>
    100       1.2   mycroft #include <dev/ic/am7990var.h>
    101       1.2   mycroft 
    102       1.8   thorpej #include <mvme68k/dev/if_lereg.h>
    103       1.8   thorpej #include <mvme68k/dev/if_levar.h>
    104       1.2   mycroft 
    105      1.33   tsutsui #include "ioconf.h"
    106      1.20       scw 
    107      1.34   tsutsui int le_pcc_match(device_t, cfdata_t, void *);
    108      1.34   tsutsui void le_pcc_attach(device_t, device_t, void *);
    109       1.1     chuck 
    110      1.34   tsutsui CFATTACH_DECL_NEW(le_pcc, sizeof(struct le_softc),
    111      1.27   thorpej     le_pcc_match, le_pcc_attach, NULL, NULL);
    112      1.15   thorpej 
    113      1.24       mrg #if defined(_KERNEL_OPT)
    114      1.17  drochner #include "opt_ddb.h"
    115      1.17  drochner #endif
    116      1.17  drochner 
    117      1.17  drochner #ifdef DDB
    118      1.17  drochner #define hide
    119      1.17  drochner #else
    120      1.21       scw #define hide	static
    121      1.17  drochner #endif
    122      1.17  drochner 
    123      1.33   tsutsui hide void le_pcc_wrcsr(struct lance_softc *, uint16_t, uint16_t);
    124      1.33   tsutsui hide uint16_t le_pcc_rdcsr(struct lance_softc *, uint16_t);
    125       1.1     chuck 
    126       1.8   thorpej hide void
    127      1.33   tsutsui le_pcc_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    128       1.1     chuck {
    129      1.21       scw 	struct le_softc *lsc;
    130       1.1     chuck 
    131      1.33   tsutsui 	lsc = (struct le_softc *)sc;
    132      1.21       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
    133      1.21       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP, val);
    134       1.1     chuck }
    135       1.1     chuck 
    136      1.33   tsutsui hide uint16_t
    137      1.33   tsutsui le_pcc_rdcsr(struct lance_softc *sc, uint16_t port)
    138       1.1     chuck {
    139      1.21       scw 	struct le_softc *lsc;
    140       1.1     chuck 
    141      1.33   tsutsui 	lsc = (struct le_softc *)sc;
    142      1.21       scw 	bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
    143      1.33   tsutsui 	return bus_space_read_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP);
    144       1.1     chuck }
    145       1.1     chuck 
    146      1.21       scw /* ARGSUSED */
    147       1.1     chuck int
    148      1.34   tsutsui le_pcc_match(device_t parent, cfdata_t cf, void *aux)
    149       1.1     chuck {
    150       1.7     chuck 	struct pcc_attach_args *pa = aux;
    151       1.7     chuck 
    152       1.7     chuck 	if (strcmp(pa->pa_name, le_cd.cd_name))
    153      1.33   tsutsui 		return 0;
    154       1.1     chuck 
    155       1.7     chuck 	pa->pa_ipl = cf->pcccf_ipl;
    156      1.33   tsutsui 	return 1;
    157       1.1     chuck }
    158       1.1     chuck 
    159      1.21       scw /* ARGSUSED */
    160       1.1     chuck void
    161      1.34   tsutsui le_pcc_attach(device_t parent, device_t self, void *aux)
    162       1.2   mycroft {
    163      1.21       scw 	struct le_softc *lsc;
    164      1.21       scw 	struct lance_softc *sc;
    165      1.21       scw 	struct pcc_attach_args *pa;
    166      1.21       scw 	bus_dma_segment_t seg;
    167      1.21       scw 	int rseg;
    168      1.21       scw 
    169      1.34   tsutsui 	lsc = device_private(self);
    170      1.21       scw 	sc = &lsc->sc_am7990.lsc;
    171      1.34   tsutsui 	sc->sc_dev = self;
    172      1.21       scw 	pa = aux;
    173       1.1     chuck 
    174       1.7     chuck 	/* Map control registers. */
    175      1.21       scw 	lsc->sc_bust = pa->pa_bust;
    176      1.21       scw 	bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &lsc->sc_bush);
    177       1.1     chuck 
    178      1.21       scw 	/* Get contiguous DMA-able memory for the lance */
    179      1.28   thorpej 	if (bus_dmamem_alloc(pa->pa_dmat, ether_data_buff_size, PAGE_SIZE, 0,
    180      1.21       scw 	    &seg, 1, &rseg,
    181      1.21       scw 	    BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT)) {
    182      1.34   tsutsui 		aprint_error(": Failed to allocate ether buffer\n");
    183      1.21       scw 		return;
    184      1.21       scw 	}
    185      1.21       scw 	if (bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
    186      1.33   tsutsui 	    (void **)&sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
    187      1.34   tsutsui 		aprint_error(": Failed to map ether buffer\n");
    188      1.21       scw 		bus_dmamem_free(pa->pa_dmat, &seg, rseg);
    189      1.21       scw 		return;
    190      1.21       scw 	}
    191      1.21       scw 	sc->sc_addr = seg.ds_addr;
    192      1.21       scw 	sc->sc_memsize = ether_data_buff_size;
    193       1.2   mycroft 	sc->sc_conf3 = LE_C3_BSWP;
    194       1.2   mycroft 
    195      1.23       scw 	memcpy(sc->sc_enaddr, mvme_ea, ETHER_ADDR_LEN);
    196       1.2   mycroft 
    197      1.17  drochner 	sc->sc_copytodesc = lance_copytobuf_contig;
    198      1.17  drochner 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    199      1.17  drochner 	sc->sc_copytobuf = lance_copytobuf_contig;
    200      1.17  drochner 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    201      1.17  drochner 	sc->sc_zerobuf = lance_zerobuf_contig;
    202       1.1     chuck 
    203       1.8   thorpej 	sc->sc_rdcsr = le_pcc_rdcsr;
    204       1.8   thorpej 	sc->sc_wrcsr = le_pcc_wrcsr;
    205       1.8   thorpej 	sc->sc_hwinit = NULL;
    206       1.1     chuck 
    207      1.21       scw 	am7990_config(&lsc->sc_am7990);
    208       1.8   thorpej 
    209      1.25       scw 	evcnt_attach_dynamic(&lsc->sc_evcnt, EVCNT_TYPE_INTR,
    210      1.34   tsutsui 	    pccintr_evcnt(pa->pa_ipl), "ether", device_xname(self));
    211      1.25       scw 
    212      1.25       scw 	pccintr_establish(PCCV_LE, am7990_intr, pa->pa_ipl, sc, &lsc->sc_evcnt);
    213      1.21       scw 
    214      1.21       scw 	pcc_reg_write(sys_pcc, PCCREG_LANCE_INTR_CTRL,
    215      1.21       scw 	    pa->pa_ipl | PCC_IENABLE);
    216       1.1     chuck }
    217