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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/*
** File: dp.c Version 1.01, Oct. 17, 2007
** Original: eth.c Version 1.00, Jan. 14, 1997
**
** Author: Giovanni Falzoni <gfalzoni@inwind.it>
**
** This file contains the ethernet device driver main task.
** It has to be integrated with the board specific drivers.
** It is a rewriting of Minix 2.0.0 ethernet driver (dp8390.c)
** to remove bord specific code. It should operate (I hope)
** with any board driver.
*/
#include <minix/drivers.h>
#include <minix/netdriver.h>
#include <minix/endpoint.h>
#include <sys/mman.h>
#include <assert.h>
#include "dp.h"
/*
** Local data
*/
static dpeth_t de_state;
typedef struct dp_conf { /* Configuration description structure */
port_t dpc_port;
int dpc_irq;
phys_bytes dpc_mem;
} dp_conf_t;
/* Device default configuration */
#define DP_CONF_NR 3
static dp_conf_t dp_conf[DP_CONF_NR] = {
/* I/O port, IRQ, Buff addr, Env. var */
{ 0x300, 5, 0xC8000, },
{ 0x280, 10, 0xCC000, },
{ 0x000, 0, 0x00000, },
};
static int do_init(unsigned int instance, netdriver_addr_t *addr,
uint32_t *caps, unsigned int *ticks);
static void do_stop(void);
static void do_set_mode(unsigned int mode, const netdriver_addr_t *mcast_list,
unsigned int mcast_count);
static int do_send(struct netdriver_data *data, size_t size);
static ssize_t do_recv(struct netdriver_data *data, size_t max);
static void do_intr(unsigned int mask);
static void do_tick(void);
static void do_other(const message *m_ptr, int ipc_status);
static const struct netdriver dp_table = {
.ndr_name = "dpe",
.ndr_init = do_init,
.ndr_stop = do_stop,
.ndr_set_mode = do_set_mode,
.ndr_recv = do_recv,
.ndr_send = do_send,
.ndr_intr = do_intr,
.ndr_tick = do_tick,
.ndr_other = do_other
};
/*
** Name: update_conf
** Function: Gets the default settings from 'dp_conf' table and
** modifies them from the environment.
*/
static void update_conf(dpeth_t * dep, const dp_conf_t * dcp,
unsigned int instance)
{
static char dpc_fmt[] = "x:d:x";
char ec_key[16];
long val;
strlcpy(ec_key, "DPETH0", sizeof(ec_key));
ec_key[5] += instance;
val = dcp->dpc_port; /* Get I/O port address */
env_parse(ec_key, dpc_fmt, 0, &val, 0x000L, 0x3FFL);
dep->de_base_port = val;
val = dcp->dpc_irq | DEI_DEFAULT; /* Get Interrupt line (IRQ) */
env_parse(ec_key, dpc_fmt, 1, &val, 0L, (long) NR_IRQ_VECTORS - 1);
dep->de_irq = val;
val = dcp->dpc_mem; /* Get shared memory address */
env_parse(ec_key, dpc_fmt, 2, &val, 0L, LONG_MAX);
dep->de_linmem = val;
}
/*
** Name: do_dump
** Function: Displays statistics on screen (SFx key from console)
*/
static void do_dump(void)
{
dpeth_t *dep;
dep = &de_state;
printf("\n\n");
printf("%s statistics:\t\t", netdriver_name());
/* Network interface status */
printf("Status: 0x%04x\n\n", dep->de_flags);
(*dep->de_dumpstatsf)(dep);
/* Transmitted/received bytes */
printf("Tx bytes:%10ld\t", dep->bytes_Tx);
printf("Rx bytes:%10ld\n", dep->bytes_Rx);
}
/*
** Name: do_first_init
** Function: Init action to setup task
*/
static void do_first_init(dpeth_t *dep, const dp_conf_t *dcp)
{
dep->de_linmem = 0xFFFF0000; /* FIXME: this overrides update_conf, why? */
/* Device specific initialization */
(*dep->de_initf)(dep);
/* Map memory if requested */
if (dep->de_linmem != 0) {
assert(dep->de_ramsize > 0);
dep->de_locmem =
vm_map_phys(SELF, (void *)dep->de_linmem, dep->de_ramsize);
if (dep->de_locmem == MAP_FAILED)
panic("unable to map memory");
}
/* Set the interrupt handler policy. Request interrupts not to be reenabled
* automatically. Return the IRQ line number when an interrupt occurs.
*/
dep->de_hook = dep->de_irq;
if (sys_irqsetpolicy(dep->de_irq, 0 /*IRQ_REENABLE*/, &dep->de_hook) != OK)
panic("unable to set IRQ policy");
sys_irqenable(&dep->de_hook);
}
/*
** Name: do_init
** Function: Checks for hardware presence.
** Initialize hardware and data structures.
** Return status and ethernet address.
*/
static int do_init(unsigned int instance, netdriver_addr_t *addr,
uint32_t *caps, unsigned int *ticks)
{
dpeth_t *dep;
dp_conf_t *dcp;
int confnr, fkeys, sfkeys;
dep = &de_state;
/* Pick a default configuration for this instance. */
confnr = MIN(instance, DP_CONF_NR-1);
dcp = &dp_conf[confnr];
update_conf(dep, dcp, instance);
if (!el1_probe(dep) && /* Probe for 3c501 */
!wdeth_probe(dep) && /* Probe for WD80x3 */
!ne_probe(dep) && /* Probe for NEx000 */
!el2_probe(dep) && /* Probe for 3c503 */
!el3_probe(dep)) { /* Probe for 3c509 */
printf("%s: warning no ethernet card found at 0x%04X\n",
netdriver_name(), dep->de_base_port);
return ENXIO;
}
do_first_init(dep, dcp);
/* Request function key for debug dumps */
fkeys = sfkeys = 0; bit_set(sfkeys, 7);
if (fkey_map(&fkeys, &sfkeys) != OK)
printf("%s: couldn't bind Shift+F7 key (%d)\n",
netdriver_name(), errno);
memcpy(addr, dep->de_address.na_addr, sizeof(*addr));
*caps = NDEV_CAP_MCAST | NDEV_CAP_BCAST; /* ..is this even accurate? */
*ticks = sys_hz(); /* update statistics once a second */
return OK;
}
/*
** Name: de_set_mode
** Function: Sets packet receipt mode.
*/
static void do_set_mode(unsigned int mode,
const netdriver_addr_t * mcast_list __unused,
unsigned int mcast_count __unused)
{
dpeth_t *dep;
dep = &de_state;
dep->de_flags &= NOT(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
if (mode & NDEV_MODE_PROMISC)
dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
if (mode & (NDEV_MODE_MCAST_LIST | NDEV_MODE_MCAST_ALL))
dep->de_flags |= DEF_MULTI;
if (mode & NDEV_MODE_BCAST)
dep->de_flags |= DEF_BROAD;
(*dep->de_flagsf)(dep);
}
/*
** Name: do_send
** Function: Send a packet, if possible.
*/
static int do_send(struct netdriver_data *data, size_t size)
{
dpeth_t *dep;
dep = &de_state;
return (*dep->de_sendf)(dep, data, size);
}
/*
** Name: do_recv
** Function: Receive a packet, if possible.
*/
static ssize_t do_recv(struct netdriver_data *data, size_t max)
{
dpeth_t *dep;
dep = &de_state;
return (*dep->de_recvf)(dep, data, max);
}
/*
** Name: do_stop
** Function: Stops network interface.
*/
static void do_stop(void)
{
dpeth_t *dep;
dep = &de_state;
/* Stop device */
(dep->de_stopf)(dep);
}
/*
** Name: do_intr
** Function; Handles interrupts.
*/
static void do_intr(unsigned int __unused mask)
{
dpeth_t *dep;
dep = &de_state;
/* If device is enabled and interrupt pending */
(*dep->de_interruptf)(dep);
sys_irqenable(&dep->de_hook);
}
/*
** Name: do_tick
** Function: perform regular processing.
*/
static void do_tick(void)
{
dpeth_t *dep;
dep = &de_state;
if (dep->de_getstatsf != NULL)
(*dep->de_getstatsf)(dep);
}
/*
** Name: do_other
** Function: Processes miscellaneous messages.
*/
static void do_other(const message *m_ptr, int ipc_status)
{
if (is_ipc_notify(ipc_status) && m_ptr->m_source == TTY_PROC_NR)
do_dump();
}
/*
** Name: main
** Function: Main entry for dp task
*/
int main(int argc, char **argv)
{
env_setargs(argc, argv);
netdriver_task(&dp_table);
return 0;
}
|