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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
/* $OpenBSD: rlnreg.h,v 1.3 2002/03/14 01:26:55 millert Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public Domain.
*
* RangeLAN2 registers
*/
/*
* The RangeLAN2 cards provide four control registers for transferring
* messaged between the host and the card using programmed i/o.
*
* A transfer protocol is followed when sending asynchronous messages to,
* and receiving messages from, the card.
*
* DATA
* 7 6 5 4 3 2 1 0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | data |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*
* STATUS
* 7 6 5 4 3 2 1 0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* |WAKEUP | tx message state |CLRNAK | rx message state |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*
* CONTROL
* 7 6 5 4 3 2 1 0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | | | 16BIT | RESET | | | TXINT | RXINT |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*
* INTSEL
* 7 6 5 4 3 2 1 0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | | | |ENABLE | interrupt line |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*/
/* Register offsets. */
#define RLN_REG_DATA 0
#define RLN_REG_STATUS 2
#define RLN_REG_CONTROL 4
#define RLN_REG_EOI 5
#define RLN_REG_INTSEL 6
#define RLN_NPORTS 8
/*
* A short delay is needed (16ms?) after register writes on some cards.
* XXX This is done by performing an innocent and harmless bus read. (i386)
* This is what Proxim's driver does, anyway.
*/
#define _rln_regacc_delay() \
bus_space_read_1(I386_BUS_SPACE_IO, 0, 0x61)
static void _rln_register_write_1(struct rln_softc *, u_int8_t,
u_int8_t);
static void _rln_register_write_2(struct rln_softc *, u_int8_t,
u_int16_t);
static u_int8_t _rln_register_read_1(struct rln_softc *, u_int8_t);
static u_int16_t _rln_register_read_2(struct rln_softc *, u_int8_t);
static int rln_status_rx_ready(struct rln_softc *);
/* Write to a register. */
static inline void
_rln_register_write_1(sc, regoff, value)
struct rln_softc *sc;
u_int8_t regoff;
u_int8_t value;
{
#ifdef RLNDEBUG_REG
printf(" %c<%02x", "DDS3CEI7"[regoff], value);
#endif
bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, (regoff), (value));
_rln_regacc_delay();
}
static inline void
_rln_register_write_2(sc, regoff, value)
struct rln_softc *sc;
u_int8_t regoff;
u_int16_t value;
{
#ifdef RLNDEBUG_REG
printf(" %c<%04x", "DDS3CEI7"[regoff], value);
#endif
bus_space_write_2((sc)->sc_iot, (sc)->sc_ioh, (regoff), (value));
_rln_regacc_delay();
}
/* Read from a register. */
static inline u_int8_t
_rln_register_read_1(sc, regoff)
struct rln_softc *sc;
u_int8_t regoff;
{
u_int8_t ret;
ret = bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, (regoff));
#ifdef RLNDEBUG_REG
if (ret != (sc)->dbg_oreg[regoff]) {
/* avoid spewing out too much debug info */
printf(" %c>%02x", "DDS3CEI7"[regoff], ret);
(sc)->dbg_oreg[regoff] = ret;
}
#endif
return (ret);
}
static inline u_int16_t
_rln_register_read_2(sc, regoff)
struct rln_softc *sc;
u_int8_t regoff;
{
u_int16_t ret;
ret = bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, (regoff));
#ifdef RLNDEBUG_REG
if (ret != (sc)->dbg_oreg[regoff]) {
printf(" %c>%04x", "DDS3CEI7"[regoff], ret);
(sc)->dbg_oreg[regoff] = ret;
}
#endif
return (ret);
}
/* 8-bit data register access. */
#define rln_data_write_1(sc, value) \
_rln_register_write_1(sc, RLN_REG_DATA, (value))
#define rln_data_read_1(sc) \
_rln_register_read_1(sc, RLN_REG_DATA)
#define rln_data_write_multi_1(sc, buf, len) \
bus_space_write_multi_1((sc)->sc_iot, (sc)->sc_ioh, \
RLN_REG_DATA, (buf), (len))
#define rln_data_read_multi_1(sc, buf, len) \
bus_space_read_multi_1((sc)->sc_iot, (sc)->sc_ioh, \
RLN_REG_DATA, (buf), (len))
/* 16-bit data register access. */
#define rln_data_write_2(sc, value) \
_rln_register_write_2(sc, RLN_REG_DATA, (value))
#define rln_data_read_2(sc) \
_rln_register_read_2(sc, RLN_REG_DATA)
#define rln_data_write_multi_2(sc, buf, len) \
bus_space_write_multi_2((sc)->sc_iot, (sc)->sc_ioh, \
RLN_REG_DATA, (buf), (len))
#define rln_data_read_multi_2(sc, buf, len) \
bus_space_read_multi_2((sc)->sc_iot, (sc)->sc_ioh, \
RLN_REG_DATA, (buf), (len))
/* Status register. */
#define RLN_STATUS_CLRNAK 0x08
#define RLN_STATUS_WAKEUP 0x80
#define RLN_STATUS_TX_IDLE 0x00
#define RLN_STATUS_TX_HILEN_AVAIL 0x01
#define RLN_STATUS_TX_HILEN_ACCEPT 0x02
#define RLN_STATUS_TX_XFR_COMPLETE 0x03
#define RLN_STATUS_TX_XFR 0x04
#define RLN_STATUS_TX_ERROR 0x05
#define RLN_STATUS_TX_LOLEN_AVAIL 0x06
#define RLN_STATUS_TX_LOLEN_ACCEPT 0x07
#define RLN_STATUS_TX_MASK 0x0f
#define RLN_STATUS_RX_IDLE 0x00
#define RLN_STATUS_RX_HILEN_AVAIL 0x10
#define RLN_STATUS_RX_HILEN_ACCEPT 0x20
#define RLN_STATUS_RX_XFR_COMPLETE 0x30
#define RLN_STATUS_RX_XFR 0x40
#define RLN_STATUS_RX_ERROR 0x50
#define RLN_STATUS_RX_LOLEN_AVAIL 0x60
#define RLN_STATUS_RX_LOLEN_ACCEPT 0x70
#define RLN_STATUS_RX_MASK 0x70
#define rln_status_write(sc, value) \
_rln_register_write_1(sc, RLN_REG_STATUS, (value))
#define rln_status_set(sc, bits) \
rln_status_write(sc, (sc)->sc_status |= (bits))
#define rln_status_clear(sc, bits) \
rln_status_write(sc, (sc)->sc_status &= ~(bits))
#define _rln_status_setmask(sc, mask, bits) \
do { \
int _s; \
\
_s = splhigh(); \
(sc)->sc_status = ((sc)->sc_status & (mask)) | (bits); \
rln_status_write(sc, (sc)->sc_status); \
splx(_s); \
} while (0);
#define rln_status_rx_write(sc, state) \
_rln_status_setmask((sc), ~RLN_STATUS_RX_MASK, state)
#define rln_status_tx_write(sc, state) \
_rln_status_setmask((sc), ~RLN_STATUS_TX_MASK, state)
#define rln_status_read(sc) \
_rln_register_read_1(sc, RLN_REG_STATUS)
#define rln_status_rx_read(sc) \
(rln_status_read(sc) & ~RLN_STATUS_TX_MASK)
#define rln_status_tx_read(sc) \
(rln_status_read(sc) & ~RLN_STATUS_RX_MASK)
static inline int
rln_status_rx_ready(sc)
struct rln_softc *sc;
{
u_int8_t status;
status = rln_status_rx_read(sc);
return (status == RLN_STATUS_RX_LOLEN_AVAIL ||
status == RLN_STATUS_RX_HILEN_AVAIL ||
status == RLN_STATUS_RX_ERROR);
}
#define rln_status_tx_int(sc) do { \
int _s = splhigh(); \
\
rln_control_clear(sc, RLN_CONTROL_TXINT); \
rln_control_set(sc, RLN_CONTROL_TXINT); \
splx(_s); \
} while (0)
#define rln_status_rx_int(sc) do { \
int _s = splhigh(); \
\
rln_control_clear(sc, RLN_CONTROL_RXINT); \
rln_control_set(sc, RLN_CONTROL_RXINT); \
splx(_s); \
} while (0)
/* Control register. */
#define RLN_CONTROL_RXINT 0x01
#define RLN_CONTROL_TXINT 0x02
#define RLN_CONTROL_BIT2 0x04
#define RLN_CONTROL_BIT3 0x08
#define RLN_CONTROL_RESET 0x10
#define RLN_CONTROL_16BIT 0x20
#define RLN_CONTROL_MASK 0x3f
#define rln_control_write(sc, value) \
_rln_register_write_1(sc, RLN_REG_CONTROL, \
(sc)->sc_control = (value))
#define rln_control_read(sc) \
_rln_register_read_1(sc, RLN_REG_CONTROL)
#define rln_control_set(sc, bits) \
rln_control_write(sc, (sc)->sc_control | (bits))
#define rln_control_clear(sc, bits) \
rln_control_write(sc, (sc)->sc_control & ~(bits))
#define rln_control_outofstandby(sc) do { \
rln_control_write(sc, (sc)->sc_control | RLN_CONTROL_RESET);\
DELAY(30000); \
rln_control_write(sc, (sc)->sc_control); \
} while (0)
/* Interrupt selection register. */
#define RLN_INTSEL_IRQMASK 0x07
#define RLN_INTSEL_ENABLE 0x10
#define RLN_INTSEL_BIT7 0x80
#define rln_intsel_disable(sc) do { \
int _s; \
\
_s = splhigh(); \
_rln_register_write_1(sc, RLN_REG_INTSEL, \
(sc)->sc_intsel &= ~RLN_INTSEL_ENABLE); \
splx(_s); \
} while (0)
#define rln_intsel_enable(sc) do { \
int _s; \
\
_s = splhigh(); \
_rln_register_write_1(sc, RLN_REG_INTSEL, \
(sc)->sc_intsel |= RLN_INTSEL_ENABLE); \
splx(_s); \
} while (0)
#define rln_intsel_write(sc, value) \
_rln_register_write_1(sc, RLN_REG_INTSEL, \
(sc)->sc_intsel |= (value))
/* End of interrupt signal, used on some newer cards. */
#define rln_eoi(sc) \
(void) _rln_register_read_1(sc, RLN_REG_EOI)
|