Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.5
      1 /* $NetBSD: if_le.c,v 1.5 2008/04/04 12:25:06 tsutsui Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Ralph Campbell and Rick Macklem.
      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  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     35  */
     36 
     37 /*-
     38  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
     39  *
     40  * This code is derived from software contributed to Berkeley by
     41  * Ralph Campbell and Rick Macklem.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     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>			/* RCS ID & Copyright macro defns */
     75 
     76 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.5 2008/04/04 12:25:06 tsutsui Exp $");
     77 
     78 #include "opt_inet.h"
     79 #include "bpfilter.h"
     80 
     81 #include <sys/param.h>
     82 #include <sys/systm.h>
     83 #include <sys/mbuf.h>
     84 #include <sys/socket.h>
     85 #include <sys/device.h>
     86 
     87 #include <net/if.h>
     88 #include <net/if_ether.h>
     89 #include <net/if_media.h>
     90 
     91 #ifdef INET
     92 #include <netinet/in.h>
     93 #include <netinet/if_inarp.h>
     94 #endif
     95 
     96 #include <machine/cpu.h>
     97 #include <machine/autoconf.h>
     98 
     99 #include <luna68k/luna68k/isr.h>
    100 
    101 #include <dev/ic/lancereg.h>
    102 #include <dev/ic/lancevar.h>
    103 #include <dev/ic/am7990reg.h>
    104 #include <dev/ic/am7990var.h>
    105 
    106 #include "ioconf.h"
    107 
    108 /*
    109  * LANCE registers.
    110  */
    111 struct lereg1 {
    112 	volatile uint16_t	ler1_rdp;	/* data port */
    113 	volatile uint16_t	ler1_rap;	/* register select port */
    114 };
    115 
    116 /*
    117  * Ethernet software status per interface.
    118  *
    119  * Each interface is referenced by a network interface structure,
    120  * arpcom.ac_if, which the routing code uses to locate the interface.
    121  * This structure contains the output queue for the interface, its address, ...
    122  */
    123 struct	le_softc {
    124 	struct	am7990_softc sc_am7990;	/* glue to MI code */
    125 
    126 	struct	lereg1 *sc_r1;		/* LANCE registers */
    127 };
    128 
    129 static int  le_match(device_t, cfdata_t, void *);
    130 static void le_attach(device_t, device_t, void *);
    131 
    132 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
    133     le_match, le_attach, NULL, NULL);
    134 
    135 static void lesrcsr(struct lance_softc *, uint16_t, uint16_t);
    136 static uint16_t lerdcsr(struct lance_softc *, uint16_t);
    137 static void myetheraddr(uint8_t *);
    138 
    139 static void
    140 lesrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    141 {
    142 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    143 
    144 	ler1->ler1_rap = port;
    145 	ler1->ler1_rdp = val;
    146 }
    147 
    148 static uint16_t
    149 lerdcsr(struct lance_softc *sc, uint16_t port)
    150 {
    151 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    152 	uint16_t val;
    153 
    154 	ler1->ler1_rap = port;
    155 	val = ler1->ler1_rdp;
    156 	return (val);
    157 }
    158 
    159 static int
    160 le_match(device_t parent, cfdata_t cf, void *aux)
    161 {
    162 	struct mainbus_attach_args *ma = aux;
    163 
    164 	if (strcmp(ma->ma_name, le_cd.cd_name))
    165 		return (0);
    166 
    167 	return (1);
    168 }
    169 
    170 void
    171 le_attach(device_t parent, device_t self, void *aux)
    172 {
    173 	struct le_softc *lesc = device_private(self);
    174 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    175 	struct mainbus_attach_args *ma = aux;
    176 
    177 	sc->sc_dev = self;
    178 
    179 	/* Map control registers. */
    180 	lesc->sc_r1 = (struct lereg1 *)ma->ma_addr;	/* LANCE */
    181 
    182 	sc->sc_mem = (void *)0x71010000;		/* SRAM */
    183 	sc->sc_conf3 = LE_C3_BSWP;
    184 	sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
    185 	sc->sc_memsize = 64 * 1024;			/* 64KB */
    186 
    187 	myetheraddr(sc->sc_enaddr);
    188 
    189 	sc->sc_copytodesc = lance_copytobuf_contig;
    190 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    191 	sc->sc_copytobuf = lance_copytobuf_contig;
    192 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    193 	sc->sc_zerobuf = lance_zerobuf_contig;
    194 
    195 	sc->sc_rdcsr = lerdcsr;
    196 	sc->sc_wrcsr = lesrcsr;
    197 	sc->sc_hwinit = NULL;
    198 
    199 	am7990_config(&lesc->sc_am7990);
    200 
    201 	isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET);
    202 }
    203 
    204 /*
    205  * LUNA-I has 1Mbit CPU ROM, which contains MAC address directly
    206  * readable at 0x4100FFE0 as a sequence of 12 ASCII characters.
    207  *
    208  * LUNA-II has 16Kbit NVSRAM on its ethercard, whose contents are
    209  * accessible 4bit-wise by ctl register operation.  The register is
    210  * mapped at 0xF1000004.
    211  */
    212 void
    213 myetheraddr(uint8_t *ether)
    214 {
    215 	unsigned int i, loc;
    216 	uint8_t *ea;
    217 	volatile struct { uint32_t ctl; } *ds1220;
    218 
    219 	switch (machtype) {
    220 	case LUNA_I:
    221 		ea = (uint8_t *)0x4101FFE0;
    222 		for (i = 0; i < ETHER_ADDR_LEN; i++) {
    223 			int u, l;
    224 
    225 			u = ea[0];
    226 			u = (u < 'A') ? u & 0xf : u - 'A' + 10;
    227 			l = ea[1];
    228 			l = (l < 'A') ? l & 0xf : l - 'A' + 10;
    229 
    230 			ether[i] = l | (u << 4);
    231 			ea += 2;
    232 		}
    233 		break;
    234 	case LUNA_II:
    235 		ds1220 = (void *)0xF1000004;
    236 		loc = 12;
    237 		for (i = 0; i < ETHER_ADDR_LEN; i++) {
    238 			unsigned int u, l, hex;
    239 
    240 			ds1220->ctl = (loc) << 16;
    241 			u = 0xf0 & (ds1220->ctl >> 12);
    242 			ds1220->ctl = (loc + 1) << 16;
    243 			l = 0x0f & (ds1220->ctl >> 16);
    244 			hex = (u < '9') ? l : l + 9;
    245 
    246 			ds1220->ctl = (loc + 2) << 16;
    247 			u = 0xf0 & (ds1220->ctl >> 12);
    248 			ds1220->ctl = (loc + 3) << 16;
    249 			l = 0x0f & (ds1220->ctl >> 16);
    250 
    251 			ether[i] = ((u < '9') ? l : l + 9) | (hex << 4);
    252 			loc += 4;
    253 		}
    254 		break;
    255 	default:
    256 		ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a;
    257 		ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00;
    258 		break;
    259 	}
    260 }
    261