Home | History | Annotate | Line # | Download | only in dev
      1 /* $NetBSD: if_le.c,v 1.9 2019/06/30 05:04:48 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.9 2019/06/30 05:04:48 tsutsui Exp $");
     77 
     78 #include "opt_inet.h"
     79 
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <sys/mbuf.h>
     83 #include <sys/socket.h>
     84 #include <sys/device.h>
     85 
     86 #include <net/if.h>
     87 #include <net/if_ether.h>
     88 #include <net/if_media.h>
     89 
     90 #ifdef INET
     91 #include <netinet/in.h>
     92 #include <netinet/if_inarp.h>
     93 #endif
     94 
     95 #include <machine/cpu.h>
     96 #include <machine/autoconf.h>
     97 #include <machine/board.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 #define TRI_PORT_RAM_LANCE_OFFSET	0x10000 /* first 64KB is used by XP */
    109 #define TRI_PORT_RAM_LANCE_SIZE		0x10000	/* 64KB */
    110 
    111 /*
    112  * LANCE registers.
    113  */
    114 struct lereg1 {
    115 	volatile uint16_t	ler1_rdp;	/* data port */
    116 	volatile uint16_t	ler1_rap;	/* register select port */
    117 };
    118 
    119 /*
    120  * Ethernet software status per interface.
    121  *
    122  * Each interface is referenced by a network interface structure,
    123  * arpcom.ac_if, which the routing code uses to locate the interface.
    124  * This structure contains the output queue for the interface, its address, ...
    125  */
    126 struct	le_softc {
    127 	struct	am7990_softc sc_am7990;	/* glue to MI code */
    128 
    129 	struct	lereg1 *sc_r1;		/* LANCE registers */
    130 };
    131 
    132 static int  le_match(device_t, cfdata_t, void *);
    133 static void le_attach(device_t, device_t, void *);
    134 
    135 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
    136     le_match, le_attach, NULL, NULL);
    137 
    138 static void lesrcsr(struct lance_softc *, uint16_t, uint16_t);
    139 static uint16_t lerdcsr(struct lance_softc *, uint16_t);
    140 static void myetheraddr(uint8_t *);
    141 
    142 static void
    143 lesrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
    144 {
    145 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    146 
    147 	ler1->ler1_rap = port;
    148 	ler1->ler1_rdp = val;
    149 }
    150 
    151 static uint16_t
    152 lerdcsr(struct lance_softc *sc, uint16_t port)
    153 {
    154 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
    155 	uint16_t val;
    156 
    157 	ler1->ler1_rap = port;
    158 	val = ler1->ler1_rdp;
    159 	return val;
    160 }
    161 
    162 static int
    163 le_match(device_t parent, cfdata_t cf, void *aux)
    164 {
    165 	struct mainbus_attach_args *ma = aux;
    166 
    167 	if (strcmp(ma->ma_name, le_cd.cd_name))
    168 		return 0;
    169 
    170 	return 1;
    171 }
    172 
    173 void
    174 le_attach(device_t parent, device_t self, void *aux)
    175 {
    176 	struct le_softc *lesc = device_private(self);
    177 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    178 	struct mainbus_attach_args *ma = aux;
    179 
    180 	sc->sc_dev = self;
    181 
    182 	/* Map control registers. */
    183 	lesc->sc_r1 = (struct lereg1 *)ma->ma_addr;	/* LANCE */
    184 
    185 	sc->sc_mem = (void *)(TRI_PORT_RAM + TRI_PORT_RAM_LANCE_OFFSET);
    186 	sc->sc_conf3 = LE_C3_BSWP;
    187 	sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
    188 	sc->sc_memsize = TRI_PORT_RAM_LANCE_SIZE;
    189 
    190 	myetheraddr(sc->sc_enaddr);
    191 
    192 	sc->sc_copytodesc = lance_copytobuf_contig;
    193 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
    194 	sc->sc_copytobuf = lance_copytobuf_contig;
    195 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
    196 	sc->sc_zerobuf = lance_zerobuf_contig;
    197 
    198 	sc->sc_rdcsr = lerdcsr;
    199 	sc->sc_wrcsr = lesrcsr;
    200 	sc->sc_hwinit = NULL;
    201 
    202 	am7990_config(&lesc->sc_am7990);
    203 
    204 	isrlink_autovec(am7990_intr, (void *)sc, ma->ma_ilvl, ISRPRI_NET);
    205 }
    206 
    207 /*
    208  * LUNA-I has 1Mbit CPU ROM, which contains MAC address directly
    209  * readable at 0x4100FFE0 as a sequence of 12 ASCII characters.
    210  *
    211  * LUNA-II has 16Kbit NVSRAM on its ethercard, whose contents are
    212  * accessible 4bit-wise by ctl register operation.  The register is
    213  * mapped at 0xF1000004.
    214  */
    215 void
    216 myetheraddr(uint8_t *ether)
    217 {
    218 	unsigned int i, loc;
    219 	uint8_t *ea;
    220 	volatile struct { uint32_t ctl; } *ds1220;
    221 
    222 	switch (machtype) {
    223 	case LUNA_I:
    224 		ea = (uint8_t *)0x4101FFE0;
    225 		for (i = 0; i < ETHER_ADDR_LEN; i++) {
    226 			int u, l;
    227 
    228 			u = ea[0];
    229 			u = (u < 'A') ? u & 0xf : u - 'A' + 10;
    230 			l = ea[1];
    231 			l = (l < 'A') ? l & 0xf : l - 'A' + 10;
    232 
    233 			ether[i] = l | (u << 4);
    234 			ea += 2;
    235 		}
    236 		break;
    237 	case LUNA_II:
    238 		ds1220 = (void *)0xF1000004;
    239 		loc = 12;
    240 		for (i = 0; i < ETHER_ADDR_LEN; i++) {
    241 			unsigned int u, l, hex;
    242 
    243 			ds1220->ctl = (loc) << 16;
    244 			u = 0xf0 & (ds1220->ctl >> 12);
    245 			ds1220->ctl = (loc + 1) << 16;
    246 			l = 0x0f & (ds1220->ctl >> 16);
    247 			hex = (u < '9') ? l : l + 9;
    248 
    249 			ds1220->ctl = (loc + 2) << 16;
    250 			u = 0xf0 & (ds1220->ctl >> 12);
    251 			ds1220->ctl = (loc + 3) << 16;
    252 			l = 0x0f & (ds1220->ctl >> 16);
    253 
    254 			ether[i] = ((u < '9') ? l : l + 9) | (hex << 4);
    255 			loc += 4;
    256 		}
    257 		break;
    258 	default:
    259 		ether[0] = 0x00; ether[1] = 0x00; ether[2] = 0x0a;
    260 		ether[3] = 0xDE; ether[4] = 0xAD; ether[5] = 0x00;
    261 		break;
    262 	}
    263 }
    264