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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/* $OpenBSD: dl10019.c,v 1.4 2008/06/26 05:42:15 ray Exp $ */
/* $NetBSD$ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_media.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#endif
#include <machine/bus.h>
#include <dev/mii/miivar.h>
#include <dev/mii/mii.h>
#include <dev/mii/mii_bitbang.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/ne2000reg.h>
#include <dev/ic/ne2000var.h>
#include <dev/ic/dl10019reg.h>
#include <dev/ic/dl10019var.h>
int dl10019_mii_readreg(struct device *, int, int);
void dl10019_mii_writereg(struct device *, int, int, int);
void dl10019_mii_statchg(struct device *);
void dl10019_mii_reset(struct dp8390_softc *);
/*
* MII bit-bang glue.
*/
u_int32_t dl10019_mii_bitbang_read(struct device *);
void dl10019_mii_bitbang_write(struct device *, u_int32_t);
const struct mii_bitbang_ops dl10019_mii_bitbang_ops = {
dl10019_mii_bitbang_read,
dl10019_mii_bitbang_write,
{
DL0_GPIO_MII_DATAOUT, /* MII_BIT_MDO */
DL0_GPIO_MII_DATAIN, /* MII_BIT_MDI */
DL0_GPIO_MII_CLK, /* MII_BIT_MDC */
DL0_19_GPIO_MII_DIROUT, /* MII_BIT_DIR_HOST_PHY */
0, /* MII_BIT_DIR_PHY_HOST */
}
};
const struct mii_bitbang_ops dl10022_mii_bitbang_ops = {
dl10019_mii_bitbang_read,
dl10019_mii_bitbang_write,
{
DL0_GPIO_MII_DATAOUT, /* MII_BIT_MDO */
DL0_GPIO_MII_DATAIN, /* MII_BIT_MDI */
DL0_GPIO_MII_CLK, /* MII_BIT_MDC */
DL0_22_GPIO_MII_DIROUT, /* MII_BIT_DIR_HOST_PHY */
0, /* MII_BIT_DIR_PHY_HOST */
}
};
void
dl10019_mii_reset(struct dp8390_softc *sc)
{
struct ne2000_softc *nsc = (void *) sc;
int i;
if (nsc->sc_type != NE2000_TYPE_DL10022)
return;
for (i = 0; i < 2; i++) {
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
0x08);
DELAY(1);
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
0x0c);
DELAY(1);
}
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO, 0x00);
}
void
dl10019_media_init(struct dp8390_softc *sc)
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
sc->sc_mii.mii_ifp = ifp;
sc->sc_mii.mii_readreg = dl10019_mii_readreg;
sc->sc_mii.mii_writereg = dl10019_mii_writereg;
sc->sc_mii.mii_statchg = dl10019_mii_statchg;
ifmedia_init(&sc->sc_mii.mii_media, 0, dp8390_mediachange,
dp8390_mediastatus);
dl10019_mii_reset(sc);
mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, 0);
if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
} else
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
}
void
dl10019_media_fini(struct dp8390_softc *sc)
{
mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
}
int
dl10019_mediachange(struct dp8390_softc *sc)
{
mii_mediachg(&sc->sc_mii);
return (0);
}
void
dl10019_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
{
mii_pollstat(&sc->sc_mii);
ifmr->ifm_status = sc->sc_mii.mii_media_status;
ifmr->ifm_active = sc->sc_mii.mii_media_active;
}
void
dl10019_init_card(struct dp8390_softc *sc)
{
dl10019_mii_reset(sc);
mii_mediachg(&sc->sc_mii);
}
void
dl10019_stop_card(struct dp8390_softc *sc)
{
mii_down(&sc->sc_mii);
}
u_int32_t
dl10019_mii_bitbang_read(struct device *self)
{
struct dp8390_softc *sc = (void *) self;
/* We're already in Page 0. */
return (bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO) &
~DL0_GPIO_PRESERVE);
}
void
dl10019_mii_bitbang_write(struct device *self, u_int32_t val)
{
struct dp8390_softc *sc = (void *) self;
u_int8_t gpio;
/* We're already in Page 0. */
gpio = bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO);
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
(val & ~DL0_GPIO_PRESERVE) | (gpio & DL0_GPIO_PRESERVE));
}
int
dl10019_mii_readreg(struct device *self, int phy, int reg)
{
struct ne2000_softc *nsc = (void *) self;
const struct mii_bitbang_ops *ops;
ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
&dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
return (mii_bitbang_readreg(self, ops, phy, reg));
}
void
dl10019_mii_writereg(struct device *self, int phy, int reg, int val)
{
struct ne2000_softc *nsc = (void *) self;
const struct mii_bitbang_ops *ops;
ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
&dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
mii_bitbang_writereg(self, ops, phy, reg, val);
}
void
dl10019_mii_statchg(struct device *self)
{
struct dp8390_softc *sc = (void *) self;
struct ne2000_softc *nsc = (void *) self;
/*
* Disable collision detection on the DL10022 if
* we are on a full-duplex link.
*/
if (nsc->sc_type == NE2000_TYPE_DL10022) {
u_int8_t diag;
if (sc->sc_mii.mii_media_active & IFM_FDX)
diag = DL0_DIAG_NOCOLLDETECT;
else
diag = 0;
bus_space_write_1(sc->sc_regt, sc->sc_regh,
NEDL_DL0_DIAG, diag);
}
}
|