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
|
/* $NetBSD: if_ate_mca.c,v 1.21 2008/04/28 20:23:53 martin Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* 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.
*/
/*
* Driver for ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ate_mca.c,v 1.21 2008/04/28 20:23:53 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <sys/bus.h>
#include <sys/intr.h>
#include <dev/ic/mb86960reg.h>
#include <dev/ic/mb86960var.h>
#include <dev/mca/mcavar.h>
#include <dev/mca/mcadevs.h>
int ate_mca_match(device_t, cfdata_t, void *);
void ate_mca_attach(device_t, device_t, void *);
static void ate_mca_detect(bus_space_tag_t, bus_space_handle_t,
uint8_t enaddr[ETHER_ADDR_LEN]);
#define ATE_NPORTS 0x20
struct ate_softc {
struct mb86960_softc sc_mb86960; /* real "mb86960" softc */
/* MCA-specific goo. */
void *sc_ih; /* interrupt cookie */
};
CFATTACH_DECL_NEW(ate_mca, sizeof(struct ate_softc),
ate_mca_match, ate_mca_attach, NULL, NULL);
static const struct ate_mca_product {
uint32_t at_prodid; /* MCA product ID */
const char *at_name; /* device name */
int at_type; /* device type */
} ate_mca_products[] = {
{ MCA_PRODUCT_AT1720T, "ATI AT1720T", FE_TYPE_AT1700T },
{ MCA_PRODUCT_AT1720BT, "ATI AT1720BT", FE_TYPE_AT1700BT },
{ MCA_PRODUCT_AT1720AT, "ATI AT1720AT", FE_TYPE_AT1700AT },
{ MCA_PRODUCT_AT1720FT, "ATI AT1720FT", FE_TYPE_AT1700FT },
{ 0, NULL, 0 },
};
static const struct ate_mca_product *ate_mca_lookup(uint32_t);
static const struct ate_mca_product *
ate_mca_lookup(uint32_t id)
{
const struct ate_mca_product *atp;
for (atp = ate_mca_products; atp->at_name != NULL; atp++)
if (id == atp->at_prodid)
return atp;
return NULL;
}
int
ate_mca_match(device_t parent, cfdata_t cf, void *aux)
{
struct mca_attach_args *ma = aux;
if (ate_mca_lookup(ma->ma_id) != NULL)
return 1;
return 0;
}
/* see POS diagrams below for explanation of these arrays' contents */
static const int ats_iobase[] = {
0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
};
static const int ats_irq[] = {
3, 4, 5, 9, 10, 11, 12, 15
};
void
ate_mca_attach(device_t parent, device_t self, void *aux)
{
struct ate_softc *isc = device_private(self);
struct mb86960_softc *sc = &isc->sc_mb86960;
struct mca_attach_args *ma = aux;
bus_space_tag_t iot = ma->ma_iot;
bus_space_handle_t ioh;
uint8_t myea[ETHER_ADDR_LEN];
int pos3, pos4;
int iobase, irq;
const struct ate_mca_product *atp;
sc->sc_dev = self;
pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
/*
* POS register 2: (adf pos0)
* 7 6 5 4 3 2 1 0
* \__ enable: 0=adapter disabled, 1=adapter enabled
*
* POS register 3: (adf pos1)
*
* 7 6 5 4 3 2 1 0
* \_/ \___/ \___/
* \ \ \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
* \ \ 001=0x2400 101=0x3400 010=0x4400 110=0x5400
* \ \ 011=0x6400 111=0x7400
* \ \_____ Boot ROM Memory Address
* \
* \_________ Lower 2 bit of Interrupt Request Number
*
* POS register 4: (adf pos2)
*
* 7 6 5 4 3 2 1 0
* \ \_______ Twisted Pair Type: 0=100 ohm, Unshielded
* \ 1=150 ohm, Shielded
* \____________ Higher 1 bit of Interrupt Request Number:
* 000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
*/
atp = ate_mca_lookup(ma->ma_id);
#ifdef DIAGNOSTIC
if (atp == NULL) {
aprint_normal("\n");
aprint_error_dev(sc->sc_dev, "where did the card go?\n");
return;
}
#endif
iobase = ats_iobase[pos3 & 0x7];
irq = ats_irq[((pos4 & 0x40) >> 4) | ((pos3 & 0xc0) >> 6)];
aprint_normal(" slot %d irq %d: %s\n",
ma->ma_slot + 1, irq, atp->at_name);
/* Map i/o space. */
if (bus_space_map(iot, iobase, ATE_NPORTS, 0, &ioh)) {
aprint_error_dev(sc->sc_dev, "can't map i/o space\n");
return;
}
sc->sc_bst = iot;
sc->sc_bsh = ioh;
/* Get ethernet address. */
ate_mca_detect(iot, ioh, myea);
/* This interface is always enabled. */
sc->sc_stat |= FE_STAT_ENABLED;
/*
* Do generic MB86960 attach.
*/
mb86960_attach(sc, myea);
mb86960_config(sc, NULL, 0, 0);
/* Establish the interrupt handler. */
isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
mb86960_intr, sc);
if (isc->sc_ih == NULL) {
aprint_error_dev(sc->sc_dev,
"couldn't establish interrupt handler\n");
return;
}
}
/*
* Very simplified ate_detect() from dev/isa/if_ate.c, only
* to determine ethernet address.
*/
static void
ate_mca_detect(bus_space_tag_t iot, bus_space_handle_t ioh,
uint8_t enaddr[ETHER_ADDR_LEN])
{
uint8_t eeprom[FE_EEPROM_SIZE];
/* Get our station address from EEPROM. */
mb86965_read_eeprom(iot, ioh, eeprom);
memcpy(enaddr, eeprom + FE_ATI_EEP_ADDR, ETHER_ADDR_LEN);
}
|