Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.15.74.1
      1 /*	$NetBSD: if_le.c,v 1.15.74.1 2008/06/02 13:22:28 mjf Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Adam Glass and Gordon W. Ross.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.15.74.1 2008/06/02 13:22:28 mjf Exp $");
     38 
     39 #include "opt_inet.h"
     40 #include "bpfilter.h"
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/mbuf.h>
     45 #include <sys/socket.h>
     46 #include <sys/device.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_ether.h>
     50 #include <net/if_media.h>
     51 
     52 #ifdef INET
     53 #include <netinet/in.h>
     54 #include <netinet/if_inarp.h>
     55 #endif
     56 
     57 #include <machine/cpu.h>
     58 
     59 #include <news68k/dev/hbvar.h>
     60 
     61 #include <dev/ic/lancereg.h>
     62 #include <dev/ic/lancevar.h>
     63 #include <dev/ic/am7990reg.h>
     64 #include <dev/ic/am7990var.h>
     65 
     66 #include "ioconf.h"
     67 
     68 /*
     69  * LANCE registers.
     70  * The real stuff is in dev/ic/am7990reg.h
     71  */
     72 struct lereg1 {
     73 	volatile uint16_t	ler1_rdp;	/* data port */
     74 	volatile uint16_t	ler1_rap;	/* register select port */
     75 };
     76 
     77 /*
     78  * Ethernet software status per interface.
     79  * The real stuff is in dev/ic/am7990var.h
     80  */
     81 struct	le_softc {
     82 	struct	am7990_softc sc_am7990;	/* glue to MI code */
     83 
     84 	struct	lereg1 *sc_r1;		/* LANCE registers */
     85 };
     86 
     87 static int  le_match(device_t, cfdata_t, void *);
     88 static void le_attach(device_t, device_t, void *);
     89 
     90 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
     91     le_match, le_attach, NULL, NULL);
     92 
     93 extern const uint8_t *idrom_addr;
     94 extern uint32_t lance_mem_phys;
     95 
     96 #if defined(_KERNEL_OPT)
     97 #include "opt_ddb.h"
     98 #endif
     99 
    100 #ifdef DDB
    101 #define	integrate
    102 #define hide
    103 #else
    104 #define	integrate	static inline
    105 #define hide		static
    106 #endif
    107 
    108 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
    109 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
    110 int leintr(int);
    111 
    112 hide void
    113 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    114 {
    115 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    116 
    117 	ler1->ler1_rap = port;
    118 	ler1->ler1_rdp = val;
    119 }
    120 
    121 hide uint16_t
    122 lerdcsr(struct lance_softc *sc, uint16_t port)
    123 {
    124 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    125 	uint16_t val;
    126 
    127 	ler1->ler1_rap = port;
    128 	val = ler1->ler1_rdp;
    129 	return val;
    130 }
    131 
    132 int
    133 le_match(device_t parent, cfdata_t cf, void *aux)
    134 {
    135 	struct hb_attach_args *ha = aux;
    136 	int addr;
    137 
    138 	if (strcmp(ha->ha_name, "le"))
    139 		return 0;
    140 
    141 	addr = IIOV(ha->ha_address);
    142 
    143 	if (badaddr((void *)addr, 1))
    144 		return 0;
    145 
    146 	return 1;
    147 }
    148 
    149 void
    150 le_attach(device_t parent, device_t self, void *aux)
    151 {
    152 	struct le_softc *lesc = device_private(self);
    153 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    154 	struct hb_attach_args *ha = aux;
    155 	const uint8_t *p;
    156 
    157 	sc->sc_dev = self;
    158 	lesc->sc_r1 = (void *)IIOV(ha->ha_address);
    159 
    160 	if (ISIIOPA(ha->ha_address)) {
    161 		sc->sc_mem = (u_char *)IIOV(lance_mem_phys);
    162 		p = idrom_addr + 0x10;
    163 	} else {
    164 		sc->sc_mem = lesc->sc_r1 - 0x10000;
    165 		p = (const uint8_t *)(lesc->sc_r1 + 0x8010);
    166 	}
    167 
    168 	sc->sc_memsize = 0x4000;	/* 16K */
    169 	sc->sc_addr = lance_mem_phys & 0x00ffffff;
    170 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
    171 
    172 	sc->sc_enaddr[0] = (*p++ << 4);
    173 	sc->sc_enaddr[0] |= *p++ & 0x0f;
    174 	sc->sc_enaddr[1] = (*p++ << 4);
    175 	sc->sc_enaddr[1] |= *p++ & 0x0f;
    176 	sc->sc_enaddr[2] = (*p++ << 4);
    177 	sc->sc_enaddr[2] |= *p++ & 0x0f;
    178 	sc->sc_enaddr[3] = (*p++ << 4);
    179 	sc->sc_enaddr[3] |= *p++ & 0x0f;
    180 	sc->sc_enaddr[4] = (*p++ << 4);
    181 	sc->sc_enaddr[4] |= *p++ & 0x0f;
    182 	sc->sc_enaddr[5] = (*p++ << 4);
    183 	sc->sc_enaddr[5] |= *p++ & 0x0f;
    184 
    185 	sc->sc_copytodesc = lance_copytobuf_contig;
    186 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    187 	sc->sc_copytobuf = lance_copytobuf_contig;
    188 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    189 	sc->sc_zerobuf = lance_zerobuf_contig;
    190 
    191 	sc->sc_rdcsr = lerdcsr;
    192 	sc->sc_wrcsr = lewrcsr;
    193 	sc->sc_hwinit = NULL;
    194 
    195 	am7990_config(&lesc->sc_am7990);
    196 }
    197 
    198 int
    199 leintr(int unit)
    200 {
    201 	struct am7990_softc *sc;
    202 
    203 	if (unit >= le_cd.cd_ndevs)	/* XXX */
    204 		return 0;
    205 
    206 	sc = device_lookup_private(&le_cd, unit);
    207 	return am7990_intr(sc);
    208 }
    209