Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / news68k / dev / if_le.c
blob7b01206f43e67f129a39be46215be4f2512e1431
1 /* $NetBSD: if_le.c,v 1.16 2008/04/04 12:25:06 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
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.
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.
33 * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.16 2008/04/04 12:25:06 tsutsui Exp $");
39 #include "opt_inet.h"
40 #include "bpfilter.h"
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>
48 #include <net/if.h>
49 #include <net/if_ether.h>
50 #include <net/if_media.h>
52 #ifdef INET
53 #include <netinet/in.h>
54 #include <netinet/if_inarp.h>
55 #endif
57 #include <machine/cpu.h>
59 #include <news68k/dev/hbvar.h>
61 #include <dev/ic/lancereg.h>
62 #include <dev/ic/lancevar.h>
63 #include <dev/ic/am7990reg.h>
64 #include <dev/ic/am7990var.h>
66 #include "ioconf.h"
69 * LANCE registers.
70 * The real stuff is in dev/ic/am7990reg.h
72 struct lereg1 {
73 volatile uint16_t ler1_rdp; /* data port */
74 volatile uint16_t ler1_rap; /* register select port */
78 * Ethernet software status per interface.
79 * The real stuff is in dev/ic/am7990var.h
81 struct le_softc {
82 struct am7990_softc sc_am7990; /* glue to MI code */
84 struct lereg1 *sc_r1; /* LANCE registers */
87 static int le_match(device_t, cfdata_t, void *);
88 static void le_attach(device_t, device_t, void *);
90 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
91 le_match, le_attach, NULL, NULL);
93 extern const uint8_t *idrom_addr;
94 extern uint32_t lance_mem_phys;
96 #if defined(_KERNEL_OPT)
97 #include "opt_ddb.h"
98 #endif
100 #ifdef DDB
101 #define integrate
102 #define hide
103 #else
104 #define integrate static inline
105 #define hide static
106 #endif
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);
112 hide void
113 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
115 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
117 ler1->ler1_rap = port;
118 ler1->ler1_rdp = val;
121 hide uint16_t
122 lerdcsr(struct lance_softc *sc, uint16_t port)
124 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
125 uint16_t val;
127 ler1->ler1_rap = port;
128 val = ler1->ler1_rdp;
129 return val;
133 le_match(device_t parent, cfdata_t cf, void *aux)
135 struct hb_attach_args *ha = aux;
136 int addr;
138 if (strcmp(ha->ha_name, "le"))
139 return 0;
141 addr = IIOV(ha->ha_address);
143 if (badaddr((void *)addr, 1))
144 return 0;
146 return 1;
149 void
150 le_attach(device_t parent, device_t self, void *aux)
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;
157 sc->sc_dev = self;
158 lesc->sc_r1 = (void *)IIOV(ha->ha_address);
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);
168 sc->sc_memsize = 0x4000; /* 16K */
169 sc->sc_addr = lance_mem_phys & 0x00ffffff;
170 sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
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;
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;
191 sc->sc_rdcsr = lerdcsr;
192 sc->sc_wrcsr = lewrcsr;
193 sc->sc_hwinit = NULL;
195 am7990_config(&lesc->sc_am7990);
199 leintr(int unit)
201 struct am7990_softc *sc;
203 if (unit >= le_cd.cd_ndevs) /* XXX */
204 return 0;
206 sc = device_lookup_private(&le_cd, unit);
207 return am7990_intr(sc);