1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/* $NetBSD: if_le.c,v 1.7 2008/04/04 12:25:06 tsutsui Exp $ */
/*
* Copyright (c) 1997, 1999
* Matthias Drochner. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.7 2008/04/04 12:25:06 tsutsui Exp $");
#include "opt_inet.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/if_inarp.h>
#endif
#include <machine/cpu.h>
#include <machine/pte.h>
#include <machine/autoconf.h>
#include <dev/ic/lancereg.h>
#include <dev/ic/lancevar.h>
#include <dev/ic/am79900reg.h>
#include <dev/ic/am79900var.h>
#include <cesfic/cesfic/isr.h>
int lematch(device_t, cfdata_t, void *);
void leattach(device_t, device_t, void *);
CFATTACH_DECL_NEW(le, sizeof(struct am79900_softc),
lematch, leattach, NULL, NULL);
int leintr(void *);
void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
uint16_t lerdcsr(struct lance_softc *, uint16_t);
static char *lebase, *lemembase;
void
lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
{
*(volatile int *)(lebase + 4) = port;
*(volatile int *)(lebase + 0) = val;
}
uint16_t
lerdcsr(struct lance_softc *sc, uint16_t port)
{
uint16_t val;
*(volatile int *)(lebase + 4) = port;
val = *(volatile int *)(lebase + 0);
return (val);
}
int
lematch(device_t parent, cfdata_t cf, void *aux)
{
return (1);
}
/*
* Interface exists: make available by filling in network interface
* record. System will initialize the interface when it is ready
* to accept packets.
*/
extern void sic_enable_int(int, int, int, int, int);
static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23};
void
leattach(device_t parent, device_t self, void *aux)
{
struct lance_softc *sc = device_private(self);
int i;
mainbus_map(0x4c000000, 0x10000, 0, (void *)&lemembase);
mainbus_map(0x48000000, 0x1000, 0, (void *)&lebase);
sc->sc_dev = self;
sc->sc_mem = lemembase;
sc->sc_conf3 = LE_C3_BSWP;
sc->sc_addr = 0x4c000000;
sc->sc_memsize = 64 * 1024;
if (cesfic_getetheraddr(sc->sc_enaddr)) {
/* fallback */
for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
sc->sc_enaddr[i] = hwa[i];
}
}
sc->sc_copytodesc = lance_copytobuf_contig;
sc->sc_copyfromdesc = lance_copyfrombuf_contig;
sc->sc_copytobuf = lance_copytobuf_contig;
sc->sc_copyfrombuf = lance_copyfrombuf_contig;
sc->sc_zerobuf = lance_zerobuf_contig;
sc->sc_rdcsr = lerdcsr;
sc->sc_wrcsr = lewrcsr;
sc->sc_hwinit = NULL;
lewrcsr(sc, 4, 0x44);
am79900_config((struct am79900_softc *)sc);
/* Establish the interrupt handler. */
(void) isrlink(leintr, sc, 3, ISRPRI_NET);
sic_enable_int(17, 0, 1, 3, 0);
}
int
leintr(void *arg)
{
struct lance_softc *sc = arg;
uint16_t isr4;
isr4 = lerdcsr(sc, 4);
if (isr4 & 0x08) {
lewrcsr(sc, 4, isr4);
return (1);
}
return (am79900_intr(sc));
}
|