1 /* $NetBSD: if_le.c,v 1.52 2010/01/19 22:06:23 pooka 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 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.52 2010/01/19 22:06:23 pooka Exp $");
34
35 #include "opt_inet.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/syslog.h>
41 #include <sys/socket.h>
42 #include <sys/device.h>
43
44 #include <net/if.h>
45 #include <net/if_ether.h>
46 #include <net/if_media.h>
47
48 #ifdef INET
49 #include <netinet/in.h>
50 #include <netinet/if_inarp.h>
51 #endif
52
53 #include <machine/autoconf.h>
54 #include <machine/cpu.h>
55 #include <machine/dvma.h>
56 #include <machine/idprom.h>
57
58 #include <dev/ic/lancereg.h>
59 #include <dev/ic/lancevar.h>
60 #include <dev/ic/am7990reg.h>
61 #include <dev/ic/am7990var.h>
62
63 #define LE_MEMSIZE 0x4000 /* 16K */
64
65 /*
66 * LANCE registers.
67 * The real stuff is in dev/ic/am7990reg.h
68 */
69 struct lereg1 {
70 volatile uint16_t ler1_rdp; /* data port */
71 volatile uint16_t ler1_rap; /* register select port */
72 };
73
74 /*
75 * Ethernet software status per interface.
76 * The real stuff is in dev/ic/am7990var.h
77 */
78 struct le_softc {
79 struct am7990_softc sc_am7990; /* glue to MI code */
80
81 struct lereg1 *sc_r1; /* LANCE registers */
82 };
83
84 static int le_match(device_t, cfdata_t, void *);
85 static void le_attach(device_t, device_t, void *);
86
87 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
88 le_match, le_attach, NULL, NULL);
89
90 #if defined(_KERNEL_OPT)
91 #include "opt_ddb.h"
92 #endif
93
94 #ifdef DDB
95 #define integrate
96 #define hide
97 #else
98 #define integrate static inline
99 #define hide static
100 #endif
101
102 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
103 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
104
105 hide void
lewrcsr(struct lance_softc * sc,uint16_t port,uint16_t val)106 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
107 {
108 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
109
110 ler1->ler1_rap = port;
111 ler1->ler1_rdp = val;
112 }
113
114 hide uint16_t
lerdcsr(struct lance_softc * sc,uint16_t port)115 lerdcsr(struct lance_softc *sc, uint16_t port)
116 {
117 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
118 uint16_t val;
119
120 ler1->ler1_rap = port;
121 val = ler1->ler1_rdp;
122 return (val);
123 }
124
125 int
le_match(device_t parent,cfdata_t cf,void * aux)126 le_match(device_t parent, cfdata_t cf, void *aux)
127 {
128 struct confargs *ca = aux;
129
130 /* Make sure there is something there... */
131 if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
132 return (0);
133
134 /* Default interrupt priority. */
135 if (ca->ca_intpri == -1)
136 ca->ca_intpri = 3;
137
138 return (1);
139 }
140
141 void
le_attach(device_t parent,device_t self,void * aux)142 le_attach(device_t parent, device_t self, void *aux)
143 {
144 struct le_softc *lesc = device_private(self);
145 struct lance_softc *sc = &lesc->sc_am7990.lsc;
146 struct confargs *ca = aux;
147
148 sc->sc_dev = self;
149 lesc->sc_r1 = bus_mapin(ca->ca_bustype,
150 ca->ca_paddr, sizeof(struct lereg1));
151
152 sc->sc_memsize = LE_MEMSIZE;
153 sc->sc_mem = dvma_malloc(sc->sc_memsize);
154 sc->sc_addr = dvma_kvtopa(sc->sc_mem, ca->ca_bustype);
155 #ifdef _SUN3X_
156 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
157 #else
158 sc->sc_conf3 = LE_C3_BSWP;
159 #endif
160
161 idprom_etheraddr(sc->sc_enaddr);
162
163 sc->sc_copytodesc = lance_copytobuf_contig;
164 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
165 sc->sc_copytobuf = lance_copytobuf_contig;
166 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
167 sc->sc_zerobuf = lance_zerobuf_contig;
168
169 sc->sc_rdcsr = lerdcsr;
170 sc->sc_wrcsr = lewrcsr;
171 sc->sc_hwinit = NULL;
172
173 am7990_config(&lesc->sc_am7990);
174
175 /* Install interrupt handler. */
176 isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
177 }
178