if_le_sbdio.c revision 1.1.18.2 1 1.1.18.2 yamt /* $NetBSD: if_le_sbdio.c,v 1.1.18.2 2006/06/21 14:51:20 yamt Exp $ */
2 1.1.18.2 yamt
3 1.1.18.2 yamt /*-
4 1.1.18.2 yamt * Copyright (c) 1996, 2005 The NetBSD Foundation, Inc.
5 1.1.18.2 yamt * All rights reserved.
6 1.1.18.2 yamt *
7 1.1.18.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.18.2 yamt * by Adam Glass and Gordon W. Ross.
9 1.1.18.2 yamt *
10 1.1.18.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.18.2 yamt * modification, are permitted provided that the following conditions
12 1.1.18.2 yamt * are met:
13 1.1.18.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.18.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.18.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.18.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.18.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.18.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.1.18.2 yamt * must display the following acknowledgement:
20 1.1.18.2 yamt * This product includes software developed by the NetBSD
21 1.1.18.2 yamt * Foundation, Inc. and its contributors.
22 1.1.18.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.18.2 yamt * contributors may be used to endorse or promote products derived
24 1.1.18.2 yamt * from this software without specific prior written permission.
25 1.1.18.2 yamt *
26 1.1.18.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.18.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.18.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.18.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.18.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.18.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.18.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.18.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.18.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.18.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.18.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.1.18.2 yamt */
38 1.1.18.2 yamt
39 1.1.18.2 yamt #include <sys/cdefs.h>
40 1.1.18.2 yamt __KERNEL_RCSID(0, "$NetBSD: if_le_sbdio.c,v 1.1.18.2 2006/06/21 14:51:20 yamt Exp $");
41 1.1.18.2 yamt
42 1.1.18.2 yamt #include "opt_inet.h"
43 1.1.18.2 yamt #include "bpfilter.h"
44 1.1.18.2 yamt
45 1.1.18.2 yamt #include <sys/param.h>
46 1.1.18.2 yamt #include <sys/systm.h>
47 1.1.18.2 yamt #include <sys/mbuf.h>
48 1.1.18.2 yamt #include <sys/syslog.h>
49 1.1.18.2 yamt #include <sys/socket.h>
50 1.1.18.2 yamt #include <sys/device.h>
51 1.1.18.2 yamt
52 1.1.18.2 yamt #include <net/if.h>
53 1.1.18.2 yamt #include <net/if_ether.h>
54 1.1.18.2 yamt #include <net/if_media.h>
55 1.1.18.2 yamt
56 1.1.18.2 yamt #ifdef INET
57 1.1.18.2 yamt #include <netinet/in.h>
58 1.1.18.2 yamt #include <netinet/if_inarp.h>
59 1.1.18.2 yamt #endif
60 1.1.18.2 yamt
61 1.1.18.2 yamt #include <machine/bus.h>
62 1.1.18.2 yamt #include <machine/intr.h>
63 1.1.18.2 yamt #include <machine/sbdiovar.h>
64 1.1.18.2 yamt #include <machine/sbdvar.h> /* for ether_addr() */
65 1.1.18.2 yamt
66 1.1.18.2 yamt #include <dev/ic/lancereg.h>
67 1.1.18.2 yamt #include <dev/ic/lancevar.h>
68 1.1.18.2 yamt #include <dev/ic/am7990reg.h>
69 1.1.18.2 yamt #include <dev/ic/am7990var.h>
70 1.1.18.2 yamt
71 1.1.18.2 yamt #define LEREG1_RDP 0 /* offset to lance data register */
72 1.1.18.2 yamt #define LEREG1_RAP 6 /* offset to lance address regsiter */
73 1.1.18.2 yamt #define LE_MEMSIZE (64 * 1024)
74 1.1.18.2 yamt
75 1.1.18.2 yamt struct le_sbdio_softc {
76 1.1.18.2 yamt struct am7990_softc sc_am7990;
77 1.1.18.2 yamt
78 1.1.18.2 yamt bus_space_tag_t sc_bst;
79 1.1.18.2 yamt bus_space_handle_t sc_bsh;
80 1.1.18.2 yamt bus_dma_tag_t sc_dmat;
81 1.1.18.2 yamt bus_dmamap_t sc_dmamap;
82 1.1.18.2 yamt };
83 1.1.18.2 yamt
84 1.1.18.2 yamt int le_sbdio_match(struct device *, struct cfdata *, void *);
85 1.1.18.2 yamt void le_sbdio_attach(struct device *, struct device *, void *);
86 1.1.18.2 yamt static void le_sbdio_wrcsr(struct lance_softc *, uint16_t, uint16_t);
87 1.1.18.2 yamt static uint16_t le_sbdio_rdcsr(struct lance_softc *, uint16_t);
88 1.1.18.2 yamt
89 1.1.18.2 yamt CFATTACH_DECL(le_sbdio, sizeof(struct le_sbdio_softc),
90 1.1.18.2 yamt le_sbdio_match, le_sbdio_attach, NULL, NULL);
91 1.1.18.2 yamt
92 1.1.18.2 yamt int
93 1.1.18.2 yamt le_sbdio_match(struct device *parent, struct cfdata *cf, void *aux)
94 1.1.18.2 yamt {
95 1.1.18.2 yamt struct sbdio_attach_args *sa = aux;
96 1.1.18.2 yamt
97 1.1.18.2 yamt return strcmp(sa->sa_name, "lance") ? 0 : 1;
98 1.1.18.2 yamt }
99 1.1.18.2 yamt
100 1.1.18.2 yamt void
101 1.1.18.2 yamt le_sbdio_attach(struct device *parent, struct device *self, void *aux)
102 1.1.18.2 yamt {
103 1.1.18.2 yamt struct sbdio_attach_args *sa = aux;
104 1.1.18.2 yamt struct le_sbdio_softc *lesc = (void *)self;
105 1.1.18.2 yamt struct lance_softc *sc = &lesc->sc_am7990.lsc;
106 1.1.18.2 yamt bus_dma_segment_t seg;
107 1.1.18.2 yamt int rseg;
108 1.1.18.2 yamt
109 1.1.18.2 yamt lesc->sc_dmat = sa->sa_dmat;
110 1.1.18.2 yamt lesc->sc_bst = sa->sa_bust;
111 1.1.18.2 yamt
112 1.1.18.2 yamt if (bus_space_map(lesc->sc_bst, sa->sa_addr1, 8 /* XXX */,
113 1.1.18.2 yamt BUS_SPACE_MAP_LINEAR, &lesc->sc_bsh) != 0) {
114 1.1.18.2 yamt printf(": cannot map registers\n");
115 1.1.18.2 yamt return;
116 1.1.18.2 yamt }
117 1.1.18.2 yamt
118 1.1.18.2 yamt /* Allocate DMA memory for the chip. */
119 1.1.18.2 yamt if (bus_dmamem_alloc(lesc->sc_dmat, LE_MEMSIZE, 0, 0, &seg, 1, &rseg,
120 1.1.18.2 yamt BUS_DMA_NOWAIT) != 0) {
121 1.1.18.2 yamt printf(": can't allocate DMA memory\n");
122 1.1.18.2 yamt return;
123 1.1.18.2 yamt }
124 1.1.18.2 yamt if (bus_dmamem_map(lesc->sc_dmat, &seg, rseg, LE_MEMSIZE,
125 1.1.18.2 yamt (caddr_t *)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0) {
126 1.1.18.2 yamt printf(": can't map DMA memory\n");
127 1.1.18.2 yamt return;
128 1.1.18.2 yamt }
129 1.1.18.2 yamt if (bus_dmamap_create(lesc->sc_dmat, LE_MEMSIZE, 1, LE_MEMSIZE,
130 1.1.18.2 yamt 0, BUS_DMA_NOWAIT, &lesc->sc_dmamap) != 0) {
131 1.1.18.2 yamt printf(": can't create DMA map\n");
132 1.1.18.2 yamt return;
133 1.1.18.2 yamt }
134 1.1.18.2 yamt if (bus_dmamap_load(lesc->sc_dmat, lesc->sc_dmamap, sc->sc_mem,
135 1.1.18.2 yamt LE_MEMSIZE, NULL, BUS_DMA_NOWAIT) != 0) {
136 1.1.18.2 yamt printf(": can't load DMA map\n");
137 1.1.18.2 yamt return;
138 1.1.18.2 yamt }
139 1.1.18.2 yamt
140 1.1.18.2 yamt sc->sc_memsize = LE_MEMSIZE;
141 1.1.18.2 yamt sc->sc_addr = lesc->sc_dmamap->dm_segs[0].ds_addr;
142 1.1.18.2 yamt sc->sc_conf3 = LE_C3_BSWP | LE_C3_BCON;
143 1.1.18.2 yamt (*platform.ether_addr)(sc->sc_enaddr);
144 1.1.18.2 yamt
145 1.1.18.2 yamt sc->sc_copytodesc = lance_copytobuf_contig;
146 1.1.18.2 yamt sc->sc_copyfromdesc = lance_copyfrombuf_contig;
147 1.1.18.2 yamt sc->sc_copytobuf = lance_copytobuf_contig;
148 1.1.18.2 yamt sc->sc_copyfrombuf = lance_copyfrombuf_contig;
149 1.1.18.2 yamt sc->sc_zerobuf = lance_zerobuf_contig;
150 1.1.18.2 yamt #ifdef LEDEBUG
151 1.1.18.2 yamt sc->sc_debug = 0xff;
152 1.1.18.2 yamt #endif
153 1.1.18.2 yamt sc->sc_rdcsr = le_sbdio_rdcsr;
154 1.1.18.2 yamt sc->sc_wrcsr = le_sbdio_wrcsr;
155 1.1.18.2 yamt
156 1.1.18.2 yamt printf(" at %p irq %d", (void *)sa->sa_addr1, sa->sa_irq);
157 1.1.18.2 yamt
158 1.1.18.2 yamt am7990_config(&lesc->sc_am7990);
159 1.1.18.2 yamt intr_establish(sa->sa_irq, am7990_intr, self);
160 1.1.18.2 yamt }
161 1.1.18.2 yamt
162 1.1.18.2 yamt static void
163 1.1.18.2 yamt le_sbdio_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
164 1.1.18.2 yamt {
165 1.1.18.2 yamt struct le_sbdio_softc *lesc = (void *)sc;
166 1.1.18.2 yamt
167 1.1.18.2 yamt bus_space_write_2(lesc->sc_bst, lesc->sc_bsh, LEREG1_RAP, port);
168 1.1.18.2 yamt bus_space_write_2(lesc->sc_bst, lesc->sc_bsh, LEREG1_RDP, val);
169 1.1.18.2 yamt }
170 1.1.18.2 yamt
171 1.1.18.2 yamt static uint16_t
172 1.1.18.2 yamt le_sbdio_rdcsr(struct lance_softc *sc, uint16_t port)
173 1.1.18.2 yamt {
174 1.1.18.2 yamt struct le_sbdio_softc *lesc = (void *)sc;
175 1.1.18.2 yamt
176 1.1.18.2 yamt bus_space_write_2(lesc->sc_bst, lesc->sc_bsh, LEREG1_RAP, port);
177 1.1.18.2 yamt return bus_space_read_2(lesc->sc_bst, lesc->sc_bsh, LEREG1_RDP);
178 1.1.18.2 yamt }
179