Home | History | Annotate | Line # | Download | only in if
if_le_vsbus.c revision 1.23
      1  1.23  tsutsui /*	$NetBSD: if_le_vsbus.c,v 1.23 2008/04/04 12:25:07 tsutsui Exp $	*/
      2   1.1    ragge 
      3   1.1    ragge /*-
      4   1.1    ragge  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1    ragge  * All rights reserved.
      6   1.1    ragge  *
      7   1.1    ragge  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1    ragge  * by Charles M. Hannum.
      9   1.1    ragge  *
     10   1.1    ragge  * Redistribution and use in source and binary forms, with or without
     11   1.1    ragge  * modification, are permitted provided that the following conditions
     12   1.1    ragge  * are met:
     13   1.1    ragge  * 1. Redistributions of source code must retain the above copyright
     14   1.1    ragge  *    notice, this list of conditions and the following disclaimer.
     15   1.1    ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    ragge  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    ragge  *    documentation and/or other materials provided with the distribution.
     18   1.1    ragge  * 3. All advertising materials mentioning features or use of this software
     19   1.1    ragge  *    must display the following acknowledgement:
     20   1.1    ragge  *	  This product includes software developed by the NetBSD
     21   1.1    ragge  *	  Foundation, Inc. and its contributors.
     22   1.1    ragge  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1    ragge  *    contributors may be used to endorse or promote products derived
     24   1.1    ragge  *    from this software without specific prior written permission.
     25   1.1    ragge  *
     26   1.1    ragge  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1    ragge  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    ragge  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    ragge  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1    ragge  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    ragge  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    ragge  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    ragge  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    ragge  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    ragge  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    ragge  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    ragge  */
     38   1.1    ragge 
     39   1.1    ragge /*-
     40   1.1    ragge  * Copyright (c) 1992, 1993
     41   1.1    ragge  *	The Regents of the University of California.  All rights reserved.
     42   1.1    ragge  *
     43   1.1    ragge  * This code is derived from software contributed to Berkeley by
     44   1.1    ragge  * Ralph Campbell and Rick Macklem.
     45   1.1    ragge  *
     46   1.1    ragge  * Redistribution and use in source and binary forms, with or without
     47   1.1    ragge  * modification, are permitted provided that the following conditions
     48   1.1    ragge  * are met:
     49   1.1    ragge  * 1. Redistributions of source code must retain the above copyright
     50   1.1    ragge  *    notice, this list of conditions and the following disclaimer.
     51   1.1    ragge  * 2. Redistributions in binary form must reproduce the above copyright
     52   1.1    ragge  *    notice, this list of conditions and the following disclaimer in the
     53   1.1    ragge  *    documentation and/or other materials provided with the distribution.
     54  1.19      agc  * 3. Neither the name of the University nor the names of its contributors
     55   1.1    ragge  *    may be used to endorse or promote products derived from this software
     56   1.1    ragge  *    without specific prior written permission.
     57   1.1    ragge  *
     58   1.1    ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1    ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1    ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1    ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1    ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1    ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1    ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1    ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1    ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1    ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1    ragge  * SUCH DAMAGE.
     69   1.1    ragge  *
     70   1.1    ragge  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     71   1.1    ragge  */
     72  1.18    lukem 
     73  1.18    lukem #include <sys/cdefs.h>
     74  1.23  tsutsui __KERNEL_RCSID(0, "$NetBSD: if_le_vsbus.c,v 1.23 2008/04/04 12:25:07 tsutsui Exp $");
     75   1.1    ragge 
     76   1.1    ragge #include "opt_inet.h"
     77   1.1    ragge #include "bpfilter.h"
     78   1.1    ragge 
     79   1.1    ragge #include <sys/param.h>
     80   1.1    ragge #include <sys/syslog.h>
     81   1.1    ragge #include <sys/socket.h>
     82   1.1    ragge #include <sys/device.h>
     83   1.1    ragge #include <sys/reboot.h>
     84   1.1    ragge 
     85  1.10      mrg #include <uvm/uvm_extern.h>
     86   1.1    ragge 
     87   1.1    ragge #include <net/if.h>
     88   1.1    ragge #include <net/if_ether.h>
     89   1.1    ragge #include <net/if_media.h>
     90   1.1    ragge 
     91  1.12    lukem #ifdef INET
     92   1.1    ragge #include <netinet/in.h>
     93   1.1    ragge #include <netinet/if_inarp.h>
     94   1.1    ragge #endif
     95   1.1    ragge 
     96   1.1    ragge #include <machine/cpu.h>
     97   1.2    ragge #include <machine/sid.h>
     98   1.3     matt #include <machine/scb.h>
     99   1.1    ragge #include <machine/bus.h>
    100   1.1    ragge #include <machine/vsbus.h>
    101   1.1    ragge 
    102   1.1    ragge #include <dev/ic/lancereg.h>
    103   1.1    ragge #include <dev/ic/lancevar.h>
    104   1.1    ragge #include <dev/ic/am7990reg.h>
    105   1.1    ragge #include <dev/ic/am7990var.h>
    106   1.1    ragge 
    107   1.1    ragge #include "ioconf.h"
    108   1.1    ragge 
    109   1.1    ragge struct le_softc {
    110   1.1    ragge 	struct	am7990_softc sc_am7990; /* Must be first */
    111   1.7     matt 	struct	evcnt sc_intrcnt;
    112   1.4     matt 	bus_dmamap_t sc_dm;
    113  1.22     matt 	volatile uint16_t *sc_rap;
    114  1.22     matt 	volatile uint16_t *sc_rdp;
    115   1.1    ragge };
    116   1.1    ragge 
    117  1.22     matt static	int	le_vsbus_match(device_t, cfdata_t, void *);
    118  1.22     matt static	void	le_vsbus_attach(device_t, device_t, void *);
    119  1.22     matt static	void	lewrcsr(struct lance_softc *, uint16_t, uint16_t);
    120  1.22     matt static	uint16_t lerdcsr(struct lance_softc *, uint16_t);
    121   1.1    ragge 
    122  1.23  tsutsui CFATTACH_DECL_NEW(le_vsbus, sizeof(struct le_softc),
    123  1.15  thorpej     le_vsbus_match, le_vsbus_attach, NULL, NULL);
    124   1.1    ragge 
    125  1.22     matt void
    126  1.22     matt lewrcsr(struct lance_softc *ls, uint16_t port, uint16_t val)
    127   1.1    ragge {
    128  1.22     matt 	struct le_softc * const sc = (void *)ls;
    129   1.1    ragge 
    130   1.1    ragge 	*sc->sc_rap = port;
    131   1.1    ragge 	*sc->sc_rdp = val;
    132   1.1    ragge }
    133   1.1    ragge 
    134  1.22     matt uint16_t
    135  1.22     matt lerdcsr(struct lance_softc *ls, uint16_t port)
    136   1.1    ragge {
    137  1.22     matt 	struct le_softc * const sc = (void *)ls;
    138   1.1    ragge 
    139   1.1    ragge 	*sc->sc_rap = port;
    140   1.1    ragge 	return *sc->sc_rdp;
    141   1.1    ragge }
    142   1.1    ragge 
    143   1.4     matt static int
    144  1.22     matt le_vsbus_match(device_t parent, cfdata_t cf, void *aux)
    145   1.1    ragge {
    146  1.22     matt 	struct vsbus_attach_args * const va = aux;
    147  1.22     matt 	volatile uint16_t *rdp, *rap;
    148   1.4     matt 	struct leinit initblock;
    149   1.4     matt 	bus_dmamap_t map;
    150   1.4     matt 	int i;
    151   1.4     matt 	int rv = 0;
    152   1.4     matt 	int error;
    153   1.1    ragge 
    154  1.11    ragge 	if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_53)
    155   1.2    ragge 		return 0;
    156   1.4     matt 
    157   1.4     matt 	error = bus_dmamap_create(va->va_dmat, sizeof(initblock), 1,
    158   1.5    ragge 	    sizeof(initblock), 0, BUS_DMA_NOWAIT, &map);
    159   1.4     matt 	if (error) {
    160   1.4     matt 		return 0;
    161   1.4     matt 	}
    162   1.4     matt 
    163   1.4     matt 	error = bus_dmamap_load(va->va_dmat, map, &initblock,
    164   1.4     matt 	    sizeof(initblock), NULL, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    165   1.4     matt 	if (error) {
    166   1.4     matt 		bus_dmamap_destroy(va->va_dmat, map);
    167   1.4     matt 		return 0;
    168   1.4     matt 	}
    169   1.4     matt 
    170   1.4     matt 	memset(&initblock, 0, sizeof(initblock));
    171   1.4     matt 
    172  1.22     matt 	rdp = (uint16_t *)va->va_addr;
    173   1.1    ragge 	rap = rdp + 2;
    174   1.1    ragge 
    175   1.1    ragge 	/* Make sure the chip is stopped. */
    176   1.1    ragge 	*rap = LE_CSR0;
    177   1.1    ragge 	*rdp = LE_C0_STOP;
    178   1.1    ragge 	DELAY(100);
    179   1.4     matt 	*rap = LE_CSR1;
    180   1.4     matt 	*rdp = map->dm_segs->ds_addr & 0xffff;
    181   1.4     matt 	*rap = LE_CSR2;
    182   1.4     matt 	*rdp = (map->dm_segs->ds_addr >> 16) & 0xffff;
    183   1.4     matt 	*rap = LE_CSR0;
    184   1.1    ragge 	*rdp = LE_C0_INIT|LE_C0_INEA;
    185   1.1    ragge 
    186   1.1    ragge 	/* Wait for initialization to finish. */
    187   1.4     matt 	for (i = 100; i >= 0; i--) {
    188   1.4     matt 		DELAY(1000);
    189   1.4     matt 		/* Should have interrupted by now */
    190   1.4     matt 		if (*rdp & LE_C0_IDON)
    191   1.4     matt 			rv = 1;
    192   1.4     matt 	}
    193   1.4     matt 	*rap = LE_CSR0;
    194   1.4     matt 	*rdp = LE_C0_STOP;
    195   1.1    ragge 
    196   1.4     matt 	bus_dmamap_unload(va->va_dmat, map);
    197   1.4     matt 	bus_dmamap_destroy(va->va_dmat, map);
    198   1.4     matt 	return rv;
    199   1.1    ragge }
    200   1.1    ragge 
    201   1.4     matt static void
    202  1.22     matt le_vsbus_attach(device_t parent, device_t self, void *aux)
    203   1.1    ragge {
    204  1.22     matt 	struct vsbus_attach_args * const va = aux;
    205  1.22     matt 	struct le_softc * const sc = device_private(self);
    206   1.1    ragge 	bus_dma_segment_t seg;
    207   1.1    ragge 	int *lance_addr;
    208   1.1    ragge 	int i, err, rseg;
    209   1.1    ragge 
    210  1.23  tsutsui 	sc->sc_am7990.lsc.sc_dev = self;
    211  1.22     matt 	sc->sc_rdp = (uint16_t *) vax_map_physmem(NI_BASE, 1);
    212   1.1    ragge 	sc->sc_rap = sc->sc_rdp + 2;
    213   1.1    ragge 
    214   1.1    ragge 	/*
    215   1.1    ragge 	 * MD functions.
    216   1.1    ragge 	 */
    217   1.1    ragge 	sc->sc_am7990.lsc.sc_rdcsr = lerdcsr;
    218   1.1    ragge 	sc->sc_am7990.lsc.sc_wrcsr = lewrcsr;
    219   1.1    ragge 	sc->sc_am7990.lsc.sc_nocarrier = NULL;
    220   1.1    ragge 
    221   1.7     matt 	scb_vecalloc(va->va_cvec, (void (*)(void *)) am7990_intr, sc,
    222   1.7     matt 		SCB_ISTACK, &sc->sc_intrcnt);
    223   1.8     matt 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    224  1.22     matt 		device_xname(self), "intr");
    225   1.7     matt 
    226  1.23  tsutsui 	/*
    227  1.23  tsutsui 	 * Allocate a (DMA-safe) block for all descriptors and buffers.
    228  1.23  tsutsui 	 */
    229   1.1    ragge 
    230   1.1    ragge #define ALLOCSIZ (64 * 1024)
    231  1.23  tsutsui 	err = bus_dmamem_alloc(va->va_dmat, ALLOCSIZ, PAGE_SIZE, 0,
    232  1.23  tsutsui 	    &seg, 1, &rseg, BUS_DMA_NOWAIT);
    233  1.23  tsutsui 	if (err) {
    234  1.23  tsutsui 		aprint_error(": unable to alloc buffer block: err %d\n", err);
    235  1.23  tsutsui 		return;
    236  1.23  tsutsui 	}
    237  1.23  tsutsui 	err = bus_dmamem_map(va->va_dmat, &seg, rseg, ALLOCSIZ,
    238  1.23  tsutsui 	    (void **)&sc->sc_am7990.lsc.sc_mem,
    239   1.1    ragge 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    240  1.23  tsutsui 	if (err) {
    241  1.23  tsutsui 		aprint_error(": unable to map buffer block: err %d\n", err);
    242  1.23  tsutsui 		bus_dmamem_free(va->va_dmat, &seg, rseg);
    243  1.23  tsutsui 		return;
    244  1.23  tsutsui 	}
    245  1.23  tsutsui 	bus_dmamap_create(va->va_dmat, ALLOCSIZ, rseg, ALLOCSIZ,
    246   1.4     matt 	    0, BUS_DMA_NOWAIT, &sc->sc_dm);
    247  1.23  tsutsui 	if (err) {
    248  1.23  tsutsui 		aprint_error(": unable to create DMA map: err %d\n", err);
    249  1.23  tsutsui 		bus_dmamem_free(va->va_dmat, &seg, rseg);
    250  1.23  tsutsui 		return;
    251  1.23  tsutsui 	}
    252   1.4     matt 	err = bus_dmamap_load(va->va_dmat, sc->sc_dm, sc->sc_am7990.lsc.sc_mem,
    253   1.4     matt 	    ALLOCSIZ, NULL, BUS_DMA_NOWAIT);
    254  1.23  tsutsui 	if (err) {
    255  1.23  tsutsui 		aprint_error(": unable to load DMA map: err %d\n", err);
    256  1.23  tsutsui 		bus_dmamap_destroy(va->va_dmat, sc->sc_dm);
    257  1.23  tsutsui 		bus_dmamem_free(va->va_dmat, &seg, rseg);
    258  1.23  tsutsui 		return;
    259  1.23  tsutsui 	}
    260  1.22     matt 	aprint_normal(" buf 0x%lx-0x%lx", sc->sc_dm->dm_segs->ds_addr,
    261   1.4     matt 	    sc->sc_dm->dm_segs->ds_addr + sc->sc_dm->dm_segs->ds_len - 1);
    262   1.4     matt 	sc->sc_am7990.lsc.sc_addr = sc->sc_dm->dm_segs->ds_addr & 0xffffff;
    263   1.4     matt 	sc->sc_am7990.lsc.sc_memsize = sc->sc_dm->dm_segs->ds_len;
    264   1.1    ragge 
    265   1.1    ragge 	sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_contig;
    266   1.1    ragge 	sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_contig;
    267   1.1    ragge 	sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_contig;
    268   1.1    ragge 	sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_contig;
    269   1.1    ragge 	sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_contig;
    270   1.1    ragge 
    271   1.4     matt #ifdef LEDEBUG
    272   1.4     matt 	sc->sc_am7990.lsc.sc_debug = 1;
    273   1.4     matt #endif
    274   1.1    ragge 	/*
    275   1.1    ragge 	 * Get the ethernet address out of rom
    276   1.1    ragge 	 */
    277   1.1    ragge 	lance_addr = (int *)vax_map_physmem(NI_ADDR, 1);
    278  1.23  tsutsui 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    279   1.1    ragge 		sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)lance_addr[i];
    280   1.1    ragge 	vax_unmap_physmem((vaddr_t)lance_addr, 1);
    281   1.1    ragge 
    282  1.22     matt 	bcopy(device_xname(self), sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname,
    283   1.1    ragge 	    IFNAMSIZ);
    284  1.22     matt 
    285   1.4     matt 	/* Prettier printout */
    286  1.22     matt 	aprint_normal("\n%s", device_xname(self));
    287   1.4     matt 
    288   1.1    ragge 	am7990_config(&sc->sc_am7990);
    289   1.1    ragge }
    290