xref: /netbsd-src/sys/dev/dec/if_le_dec.c (revision 50e68e123bf74d17378f7bcc0bb6ac0616d03635)
1*50e68e12Sflxd /*	$NetBSD: if_le_dec.c,v 1.21 2017/06/22 16:46:53 flxd Exp $	*/
2aad01611Sagc 
3aad01611Sagc /*-
4aad01611Sagc  * Copyright (c) 1992, 1993
5aad01611Sagc  *	The Regents of the University of California.  All rights reserved.
6aad01611Sagc  *
7aad01611Sagc  * This code is derived from software contributed to Berkeley by
8aad01611Sagc  * Ralph Campbell and Rick Macklem.
9aad01611Sagc  *
10aad01611Sagc  * Redistribution and use in source and binary forms, with or without
11aad01611Sagc  * modification, are permitted provided that the following conditions
12aad01611Sagc  * are met:
13aad01611Sagc  * 1. Redistributions of source code must retain the above copyright
14aad01611Sagc  *    notice, this list of conditions and the following disclaimer.
15aad01611Sagc  * 2. Redistributions in binary form must reproduce the above copyright
16aad01611Sagc  *    notice, this list of conditions and the following disclaimer in the
17aad01611Sagc  *    documentation and/or other materials provided with the distribution.
18aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
19aad01611Sagc  *    may be used to endorse or promote products derived from this software
20aad01611Sagc  *    without specific prior written permission.
21aad01611Sagc  *
22aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32aad01611Sagc  * SUCH DAMAGE.
33aad01611Sagc  *
34aad01611Sagc  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
35aad01611Sagc  */
3613e808bbSthorpej 
3713e808bbSthorpej /*-
38064c4e51Sjonathan  * Copyright (c) 1997 Jonathan Stone. All rights reserved.
3913e808bbSthorpej  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
4013e808bbSthorpej  *
4113e808bbSthorpej  * This code is derived from software contributed to Berkeley by
4213e808bbSthorpej  * Ralph Campbell and Rick Macklem.
4313e808bbSthorpej  *
4413e808bbSthorpej  * Redistribution and use in source and binary forms, with or without
4513e808bbSthorpej  * modification, are permitted provided that the following conditions
4613e808bbSthorpej  * are met:
4713e808bbSthorpej  * 1. Redistributions of source code must retain the above copyright
4813e808bbSthorpej  *    notice, this list of conditions and the following disclaimer.
4913e808bbSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
5013e808bbSthorpej  *    notice, this list of conditions and the following disclaimer in the
5113e808bbSthorpej  *    documentation and/or other materials provided with the distribution.
5213e808bbSthorpej  * 3. All advertising materials mentioning features or use of this software
5313e808bbSthorpej  *    must display the following acknowledgement:
5413e808bbSthorpej  *	This product includes software developed by the University of
5513e808bbSthorpej  *	California, Berkeley and its contributors.
5613e808bbSthorpej  * 4. Neither the name of the University nor the names of its contributors
5713e808bbSthorpej  *    may be used to endorse or promote products derived from this software
5813e808bbSthorpej  *    without specific prior written permission.
5913e808bbSthorpej  *
6013e808bbSthorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
6113e808bbSthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6213e808bbSthorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6313e808bbSthorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
6413e808bbSthorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6513e808bbSthorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6613e808bbSthorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6713e808bbSthorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6813e808bbSthorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6913e808bbSthorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7013e808bbSthorpej  * SUCH DAMAGE.
7113e808bbSthorpej  *
7213e808bbSthorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
7313e808bbSthorpej  */
7413e808bbSthorpej 
75dca6ccc8Slukem #include <sys/cdefs.h>
76*50e68e12Sflxd __KERNEL_RCSID(0, "$NetBSD: if_le_dec.c,v 1.21 2017/06/22 16:46:53 flxd Exp $");
77dca6ccc8Slukem 
783751946bSjonathan #include "opt_inet.h"
7913e808bbSthorpej 
8013e808bbSthorpej #include <sys/param.h>
8113e808bbSthorpej #include <sys/systm.h>
8213e808bbSthorpej #include <sys/mbuf.h>
8313e808bbSthorpej #include <sys/syslog.h>
8413e808bbSthorpej #include <sys/socket.h>
8513e808bbSthorpej #include <sys/device.h>
8613e808bbSthorpej 
8713e808bbSthorpej #include <net/if.h>
8807b064e0Sis #include <net/if_ether.h>
891d987a16Sthorpej #include <net/if_media.h>
9013e808bbSthorpej 
9113e808bbSthorpej #ifdef INET
9213e808bbSthorpej #include <netinet/in.h>
9307b064e0Sis #include <netinet/if_inarp.h>
9413e808bbSthorpej #endif
9513e808bbSthorpej 
9649bb9d82Sdrochner #include <dev/ic/lancereg.h>
9749bb9d82Sdrochner #include <dev/ic/lancevar.h>
9813e808bbSthorpej #include <dev/ic/am7990reg.h>
9913e808bbSthorpej #include <dev/ic/am7990var.h>
10013e808bbSthorpej 
10113e808bbSthorpej #include <dev/tc/if_levar.h>
10213e808bbSthorpej #include <dev/tc/tcvar.h>
10313e808bbSthorpej 
104a2a38285Sad #include <sys/bus.h>
1050bf6ea43Smhitch 
10613e808bbSthorpej /* access LANCE registers */
107d9941582Stsutsui void le_dec_writereg(volatile uint16_t *regptr, uint16_t val);
10813e808bbSthorpej #define	LERDWR(cntl, src, dst)	{ (dst) = (src); tc_mb(); }
10913e808bbSthorpej #define	LEWREG(src, dst)	le_dec_writereg(&(dst), (src))
11013e808bbSthorpej 
111c13e3a66Smrg #if defined(_KERNEL_OPT)
11249bb9d82Sdrochner #include "opt_ddb.h"
11349bb9d82Sdrochner #endif
11449bb9d82Sdrochner 
11549bb9d82Sdrochner #ifdef DDB
11649bb9d82Sdrochner #define	integrate
11749bb9d82Sdrochner #define hide
11849bb9d82Sdrochner #else
11993124077Sperry #define	integrate	static inline
12049bb9d82Sdrochner #define hide		static
12149bb9d82Sdrochner #endif
12249bb9d82Sdrochner 
123d9941582Stsutsui hide void le_dec_wrcsr(struct lance_softc *, uint16_t, uint16_t);
124d9941582Stsutsui hide uint16_t le_dec_rdcsr(struct lance_softc *, uint16_t);
12513e808bbSthorpej 
12613e808bbSthorpej void
dec_le_common_attach(struct am7990_softc * sc,uint8_t * eap)127d9941582Stsutsui dec_le_common_attach(struct am7990_softc *sc, uint8_t *eap)
12813e808bbSthorpej {
12913e808bbSthorpej 	int i;
13013e808bbSthorpej 
13149bb9d82Sdrochner 	sc->lsc.sc_rdcsr = le_dec_rdcsr;
13249bb9d82Sdrochner 	sc->lsc.sc_wrcsr = le_dec_wrcsr;
13349bb9d82Sdrochner 	sc->lsc.sc_hwinit = NULL;
13413e808bbSthorpej 
13549bb9d82Sdrochner 	sc->lsc.sc_conf3 = 0;
13649bb9d82Sdrochner 	sc->lsc.sc_addr = 0;
13749bb9d82Sdrochner 	sc->lsc.sc_memsize = 65536;
13813e808bbSthorpej 
13913e808bbSthorpej 	/*
14013e808bbSthorpej 	 * Get the ethernet address out of rom
14113e808bbSthorpej 	 */
14249bb9d82Sdrochner 	for (i = 0; i < sizeof(sc->lsc.sc_enaddr); i++) {
14349bb9d82Sdrochner 		sc->lsc.sc_enaddr[i] = *eap;
14413e808bbSthorpej 		eap += 4;
14513e808bbSthorpej 	}
14613e808bbSthorpej 
14713e808bbSthorpej 	am7990_config(sc);
14813e808bbSthorpej }
14913e808bbSthorpej 
15013e808bbSthorpej hide void
le_dec_wrcsr(struct lance_softc * sc,uint16_t port,uint16_t val)151d9941582Stsutsui le_dec_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
15213e808bbSthorpej {
15313e808bbSthorpej 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
15413e808bbSthorpej 
15513e808bbSthorpej 	LEWREG(port, ler1->ler1_rap);
15613e808bbSthorpej 	LERDWR(port, val, ler1->ler1_rdp);
15713e808bbSthorpej }
15813e808bbSthorpej 
159d9941582Stsutsui hide uint16_t
le_dec_rdcsr(struct lance_softc * sc,uint16_t port)160d9941582Stsutsui le_dec_rdcsr(struct lance_softc *sc, uint16_t port)
16113e808bbSthorpej {
16213e808bbSthorpej 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
163d9941582Stsutsui 	uint16_t val;
16413e808bbSthorpej 
16513e808bbSthorpej 	LEWREG(port, ler1->ler1_rap);
16613e808bbSthorpej 	LERDWR(0, ler1->ler1_rdp, val);
16713e808bbSthorpej 	return (val);
16813e808bbSthorpej }
16913e808bbSthorpej 
17013e808bbSthorpej /*
17113e808bbSthorpej  * Write a lance register port, reading it back to ensure success. This seems
17213e808bbSthorpej  * to be necessary during initialization, since the chip appears to be a bit
17313e808bbSthorpej  * pokey sometimes.
17413e808bbSthorpej  */
17513e808bbSthorpej void
le_dec_writereg(volatile uint16_t * regptr,uint16_t val)176d9941582Stsutsui le_dec_writereg(volatile uint16_t *regptr, uint16_t val)
17713e808bbSthorpej {
178d9941582Stsutsui 	int i = 0;
17913e808bbSthorpej 
18013e808bbSthorpej 	while (*regptr != val) {
18113e808bbSthorpej 		*regptr = val;
18213e808bbSthorpej 		tc_mb();
18313e808bbSthorpej 		if (++i > 10000) {
18486373f8cSchristos 			printf("le: Reg did not settle (to x%x): x%x\n", val,
18513e808bbSthorpej 			    *regptr);
18613e808bbSthorpej 			return;
18713e808bbSthorpej 		}
18813e808bbSthorpej 		DELAY(100);
18913e808bbSthorpej 	}
19013e808bbSthorpej }
19113e808bbSthorpej 
19213e808bbSthorpej /*
19313e808bbSthorpej  * Routines for accessing the transmit and receive buffers are provided
19413e808bbSthorpej  * by am7990.c, because of the LE_NEED_BUF_* macros defined above.
19513e808bbSthorpej  * Unfortunately, CPU addressing of these buffers is done in one of
19613e808bbSthorpej  * 3 ways:
197*50e68e12Sflxd  * - contiguous (for the 3max and TURBOchannel option card)
19813e808bbSthorpej  * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
199064c4e51Sjonathan  *   spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
20013e808bbSthorpej  * - gap16, which means 16bytes interspersed with 16byte spaces
20113e808bbSthorpej  *   for buffers which must begin on a 32byte boundary (for 3min, maxine,
20213e808bbSthorpej  *   and alpha)
20313e808bbSthorpej  * The buffer offset is the logical byte offset, assuming contiguous storage.
20413e808bbSthorpej  */
205