Subversion Repositories HelenOS

Rev

Rev 4243 | Rev 4307 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4243 Rev 4261
1
/*
1
/*
2
 * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2
 * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
 *
3
 *
4
 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4
 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
 * * 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.
5
 * * 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.
6
 * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
6
 * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7
 * * Any deviations from these conditions require written permission from the copyright holder in advance
7
 * * Any deviations from these conditions require written permission from the copyright holder in advance
8
 *
8
 *
9
 *
9
 *
10
 * Disclaimer
10
 * Disclaimer
11
 *
11
 *
12
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
12
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
13
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
13
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
 *
22
 *
23
 * Changes:
23
 * Changes:
24
 *  2009 Lukas Mejdrech ported to HelenOS
24
 *  2009 Lukas Mejdrech ported to HelenOS
25
 */
25
 */
26
 
26
 
27
/** @addtogroup dp8390
27
/** @addtogroup dp8390
28
 *  @{
28
 *  @{
29
 */
29
 */
30
 
30
 
31
#include <assert.h>
31
#include <assert.h>
32
#include <errno.h>
32
#include <errno.h>
33
 
33
 
34
#include "../../include/byteorder.h"
34
#include "../../include/byteorder.h"
35
 
35
 
36
#include "../../structures/packet/packet.h"
36
#include "../../structures/packet/packet.h"
37
#include "../../structures/packet/packet_client.h"
37
#include "../../structures/packet/packet_client.h"
38
 
38
 
39
#include "../netif.h"
39
#include "../netif.h"
40
 
40
 
41
#include "dp8390_drv.h"
41
#include "dp8390_drv.h"
42
#include "dp8390_module.h"
-
 
43
#include "dp8390_port.h"
42
#include "dp8390_port.h"
44
 
43
 
45
/*
44
/*
46
 * dp8390.c
45
 * dp8390.c
47
 *
46
 *
48
 * Created: before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>
47
 * Created: before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>
49
 *
48
 *
50
 * Modified Mar 10 1994 by Philip Homburg
49
 * Modified Mar 10 1994 by Philip Homburg
51
 *  Become a generic dp8390 driver.
50
 *  Become a generic dp8390 driver.
52
 *
51
 *
53
 * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>
52
 * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>
54
 *  Added support for 3c503 boards.
53
 *  Added support for 3c503 boards.
55
 */
54
 */
56
 
55
 
57
#include "local.h"
56
#include "local.h"
58
#include "dp8390.h"
57
#include "dp8390.h"
59
 
58
 
60
int queue_packet( dpeth_t * dep, packet_t packet );
59
int queue_packet( dpeth_t * dep, packet_t packet );
61
static void outsb( port_t port, void * buf, size_t size );
60
static void outsb( port_t port, void * buf, size_t size );
62
static void outsw( port_t port, void * buf, size_t size );
61
static void outsw( port_t port, void * buf, size_t size );
63
 
62
 
64
//static u16_t eth_ign_proto;
63
//static u16_t eth_ign_proto;
65
//static char *progname;
64
//static char *progname;
66
 
65
 
67
/* Configuration */
66
/* Configuration */
68
/*typedef struct dp_conf
67
/*typedef struct dp_conf
69
{
68
{
70
    port_t dpc_port;
69
    port_t dpc_port;
71
    int dpc_irq;
70
    int dpc_irq;
72
    phys_bytes dpc_mem;
71
    phys_bytes dpc_mem;
73
    char *dpc_envvar;
72
    char *dpc_envvar;
74
} dp_conf_t;
73
} dp_conf_t;
75
*/
74
*/
76
//dp_conf_t dp_conf[]=  /* Card addresses */
75
//dp_conf_t dp_conf[]=  /* Card addresses */
77
//{
76
//{
78
    /* I/O port, IRQ,  Buffer address,  Env. var. */
77
    /* I/O port, IRQ,  Buffer address,  Env. var. */
79
/*  {  0x280,     3,    0xD0000,        "DPETH0"    },
78
/*  {  0x280,     3,    0xD0000,        "DPETH0"    },
80
    {  0x300,     5,    0xC8000,        "DPETH1"    },
79
    {  0x300,     5,    0xC8000,        "DPETH1"    },
81
    {  0x380,    10,    0xD8000,        "DPETH2"    },
80
    {  0x380,    10,    0xD8000,        "DPETH2"    },
82
};
81
};
83
*/
82
*/
84
/* Test if dp_conf has exactly DE_PORT_NR entries.  If not then you will see
83
/* Test if dp_conf has exactly DE_PORT_NR entries.  If not then you will see
85
 * the error: "array size is negative".
84
 * the error: "array size is negative".
86
 */
85
 */
87
//extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1];
86
//extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1];
88
 
87
 
89
/* Card inits configured out? */
88
/* Card inits configured out? */
90
#if !ENABLE_WDETH
89
#if !ENABLE_WDETH
91
#define wdeth_probe(dep)    (0)
90
#define wdeth_probe(dep)    (0)
92
#endif
91
#endif
93
#if !ENABLE_NE2000
92
#if !ENABLE_NE2000
94
#define ne_probe(dep)       (0)
93
#define ne_probe(dep)       (0)
95
#endif
94
#endif
96
#if !ENABLE_3C503
95
#if !ENABLE_3C503
97
#define el2_probe(dep)      (0)
96
#define el2_probe(dep)      (0)
98
#endif
97
#endif
99
 
98
 
100
/* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA
99
/* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA
101
 * on writes to the CR register. Additional CR_STAs do not appear to hurt
100
 * on writes to the CR register. Additional CR_STAs do not appear to hurt
102
 * genuine dp8390s
101
 * genuine dp8390s
103
 */
102
 */
104
#define CR_EXTRA    CR_STA
103
#define CR_EXTRA    CR_STA
105
 
104
 
106
//#if ENABLE_PCI
105
//#if ENABLE_PCI
107
//_PROTOTYPE( static void pci_conf, (void)              );
106
//_PROTOTYPE( static void pci_conf, (void)              );
108
//#endif
107
//#endif
109
//_PROTOTYPE( static void do_vwrite, (message *mp, int from_int,
108
//_PROTOTYPE( static void do_vwrite, (message *mp, int from_int,
110
//                          int vectored)   );
109
//                          int vectored)   );
111
//_PROTOTYPE( static void do_vwrite_s, (message *mp, int from_int)  );
110
//_PROTOTYPE( static void do_vwrite_s, (message *mp, int from_int)  );
112
//_PROTOTYPE( static void do_vread, (message *mp, int vectored)     );
111
//_PROTOTYPE( static void do_vread, (message *mp, int vectored)     );
113
//_PROTOTYPE( static void do_vread_s, (message *mp)         );
112
//_PROTOTYPE( static void do_vread_s, (message *mp)         );
114
//_PROTOTYPE( static void do_init, (message *mp)                );
113
//_PROTOTYPE( static void do_init, (message *mp)                );
115
//_PROTOTYPE( static void do_int, (dpeth_t *dep)                );
114
//_PROTOTYPE( static void do_int, (dpeth_t *dep)                );
116
//_PROTOTYPE( static void do_getstat, (message *mp)         );
115
//_PROTOTYPE( static void do_getstat, (message *mp)         );
117
//_PROTOTYPE( static void do_getstat_s, (message *mp)           );
116
//_PROTOTYPE( static void do_getstat_s, (message *mp)           );
118
//_PROTOTYPE( static void do_getname, (message *mp)         );
117
//_PROTOTYPE( static void do_getname, (message *mp)         );
119
//_PROTOTYPE( static void do_stop, (message *mp)                );
118
//_PROTOTYPE( static void do_stop, (message *mp)                );
120
_PROTOTYPE( static void dp_init, (dpeth_t *dep)             );
119
_PROTOTYPE( static void dp_init, (dpeth_t *dep)             );
121
//_PROTOTYPE( static void dp_confaddr, (dpeth_t *dep)           );
120
//_PROTOTYPE( static void dp_confaddr, (dpeth_t *dep)           );
122
_PROTOTYPE( static void dp_reinit, (dpeth_t *dep)           );
121
_PROTOTYPE( static void dp_reinit, (dpeth_t *dep)           );
123
_PROTOTYPE( static void dp_reset, (dpeth_t *dep)            );
122
_PROTOTYPE( static void dp_reset, (dpeth_t *dep)            );
124
//_PROTOTYPE( static void dp_check_ints, (dpeth_t *dep)         );
123
//_PROTOTYPE( static void dp_check_ints, (dpeth_t *dep)         );
125
_PROTOTYPE( static void dp_recv, (dpeth_t *dep)             );
124
_PROTOTYPE( static void dp_recv, (dpeth_t *dep)             );
126
_PROTOTYPE( static void dp_send, (dpeth_t *dep)             );
125
_PROTOTYPE( static void dp_send, (dpeth_t *dep)             );
127
//_PROTOTYPE( static void dp8390_stop, (void)               );
126
//_PROTOTYPE( static void dp8390_stop, (void)               );
128
_PROTOTYPE( static void dp_getblock, (dpeth_t *dep, int page,
127
_PROTOTYPE( static void dp_getblock, (dpeth_t *dep, int page,
129
                size_t offset, size_t size, void *dst)  );
128
                size_t offset, size_t size, void *dst)  );
130
_PROTOTYPE( static void dp_pio8_getblock, (dpeth_t *dep, int page,
129
_PROTOTYPE( static void dp_pio8_getblock, (dpeth_t *dep, int page,
131
                size_t offset, size_t size, void *dst)  );
130
                size_t offset, size_t size, void *dst)  );
132
_PROTOTYPE( static void dp_pio16_getblock, (dpeth_t *dep, int page,
131
_PROTOTYPE( static void dp_pio16_getblock, (dpeth_t *dep, int page,
133
                size_t offset, size_t size, void *dst)  );
132
                size_t offset, size_t size, void *dst)  );
134
_PROTOTYPE( static int dp_pkt2user, (dpeth_t *dep, int page,
133
_PROTOTYPE( static int dp_pkt2user, (dpeth_t *dep, int page,
135
                            int length) );
134
                            int length) );
136
//_PROTOTYPE( static int dp_pkt2user_s, (dpeth_t *dep, int page,
135
//_PROTOTYPE( static int dp_pkt2user_s, (dpeth_t *dep, int page,
137
//                          int length) );
136
//                          int length) );
138
_PROTOTYPE( static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp,
137
_PROTOTYPE( static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp,
139
        vir_bytes offset, int nic_addr, vir_bytes count)    );
138
        vir_bytes offset, int nic_addr, vir_bytes count)    );
140
//_PROTOTYPE( static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp, 
139
//_PROTOTYPE( static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp, 
141
//      vir_bytes offset, int nic_addr, vir_bytes count)    );
140
//      vir_bytes offset, int nic_addr, vir_bytes count)    );
142
_PROTOTYPE( static void dp_pio8_user2nic, (dpeth_t *dep,
141
_PROTOTYPE( static void dp_pio8_user2nic, (dpeth_t *dep,
143
                iovec_dat_t *iovp, vir_bytes offset,
142
                iovec_dat_t *iovp, vir_bytes offset,
144
                int nic_addr, vir_bytes count)      );
143
                int nic_addr, vir_bytes count)      );
145
//_PROTOTYPE( static void dp_pio8_user2nic_s, (dpeth_t *dep,
144
//_PROTOTYPE( static void dp_pio8_user2nic_s, (dpeth_t *dep,
146
//              iovec_dat_s_t *iovp, vir_bytes offset,
145
//              iovec_dat_s_t *iovp, vir_bytes offset,
147
//              int nic_addr, vir_bytes count)      );
146
//              int nic_addr, vir_bytes count)      );
148
_PROTOTYPE( static void dp_pio16_user2nic, (dpeth_t *dep,
147
_PROTOTYPE( static void dp_pio16_user2nic, (dpeth_t *dep,
149
                iovec_dat_t *iovp, vir_bytes offset,
148
                iovec_dat_t *iovp, vir_bytes offset,
150
                int nic_addr, vir_bytes count)      );
149
                int nic_addr, vir_bytes count)      );
151
//_PROTOTYPE( static void dp_pio16_user2nic_s, (dpeth_t *dep,
150
//_PROTOTYPE( static void dp_pio16_user2nic_s, (dpeth_t *dep,
152
//              iovec_dat_s_t *iovp, vir_bytes offset,
151
//              iovec_dat_s_t *iovp, vir_bytes offset,
153
//              int nic_addr, vir_bytes count)      );
152
//              int nic_addr, vir_bytes count)      );
154
_PROTOTYPE( static void dp_nic2user, (dpeth_t *dep, int nic_addr,
153
_PROTOTYPE( static void dp_nic2user, (dpeth_t *dep, int nic_addr,
155
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
154
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
156
//_PROTOTYPE( static void dp_nic2user_s, (dpeth_t *dep, int nic_addr, 
155
//_PROTOTYPE( static void dp_nic2user_s, (dpeth_t *dep, int nic_addr, 
157
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
156
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
158
_PROTOTYPE( static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr,
157
_PROTOTYPE( static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr,
159
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
158
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
160
//_PROTOTYPE( static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr, 
159
//_PROTOTYPE( static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr, 
161
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
160
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
162
_PROTOTYPE( static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr,
161
_PROTOTYPE( static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr,
163
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
162
        iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)   );
164
//_PROTOTYPE( static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr, 
163
//_PROTOTYPE( static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr, 
165
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
164
//      iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count) );
166
_PROTOTYPE( static void dp_next_iovec, (iovec_dat_t *iovp)      );
165
_PROTOTYPE( static void dp_next_iovec, (iovec_dat_t *iovp)      );
167
//_PROTOTYPE( static void dp_next_iovec_s, (iovec_dat_s_t *iovp)        );
166
//_PROTOTYPE( static void dp_next_iovec_s, (iovec_dat_s_t *iovp)        );
168
_PROTOTYPE( static void conf_hw, (dpeth_t *dep)             );
167
_PROTOTYPE( static void conf_hw, (dpeth_t *dep)             );
169
//_PROTOTYPE( static void update_conf, (dpeth_t *dep, dp_conf_t *dcp)   );
168
//_PROTOTYPE( static void update_conf, (dpeth_t *dep, dp_conf_t *dcp)   );
170
_PROTOTYPE( static void map_hw_buffer, (dpeth_t *dep)           );
169
_PROTOTYPE( static void map_hw_buffer, (dpeth_t *dep)           );
171
//_PROTOTYPE( static int calc_iovec_size, (iovec_dat_t *iovp)       );
170
//_PROTOTYPE( static int calc_iovec_size, (iovec_dat_t *iovp)       );
172
//_PROTOTYPE( static int calc_iovec_size_s, (iovec_dat_s_t *iovp)       );
171
//_PROTOTYPE( static int calc_iovec_size_s, (iovec_dat_s_t *iovp)       );
173
_PROTOTYPE( static void reply, (dpeth_t *dep, int err, int may_block)   );
172
_PROTOTYPE( static void reply, (dpeth_t *dep, int err, int may_block)   );
174
//_PROTOTYPE( static void mess_reply, (message *req, message *reply)    );
173
//_PROTOTYPE( static void mess_reply, (message *req, message *reply)    );
175
_PROTOTYPE( static void get_userdata, (int user_proc,
174
_PROTOTYPE( static void get_userdata, (int user_proc,
176
        vir_bytes user_addr, vir_bytes count, void *loc_addr)   );
175
        vir_bytes user_addr, vir_bytes count, void *loc_addr)   );
177
//_PROTOTYPE( static void get_userdata_s, (int user_proc,
176
//_PROTOTYPE( static void get_userdata_s, (int user_proc,
178
//      cp_grant_id_t grant, vir_bytes offset, vir_bytes count,
177
//      cp_grant_id_t grant, vir_bytes offset, vir_bytes count,
179
//      void *loc_addr) );
178
//      void *loc_addr) );
180
//_PROTOTYPE( static void put_userdata, (int user_proc,
179
//_PROTOTYPE( static void put_userdata, (int user_proc,
181
//      vir_bytes user_addr, vir_bytes count, void *loc_addr)   );
180
//      vir_bytes user_addr, vir_bytes count, void *loc_addr)   );
182
//_PROTOTYPE( static void put_userdata_s, (int user_proc,
181
//_PROTOTYPE( static void put_userdata_s, (int user_proc,
183
//      cp_grant_id_t grant, size_t count, void *loc_addr)  );
182
//      cp_grant_id_t grant, size_t count, void *loc_addr)  );
184
_PROTOTYPE( static void insb, (port_t port, void *buf, size_t size)             );
183
_PROTOTYPE( static void insb, (port_t port, void *buf, size_t size)             );
185
_PROTOTYPE( static void insw, (port_t port, void *buf, size_t size)             );
184
_PROTOTYPE( static void insw, (port_t port, void *buf, size_t size)             );
186
//_PROTOTYPE( static void do_vir_insb, (port_t port, int proc,
185
//_PROTOTYPE( static void do_vir_insb, (port_t port, int proc,
187
//                  vir_bytes buf, size_t size) );
186
//                  vir_bytes buf, size_t size) );
188
//_PROTOTYPE( static void do_vir_insw, (port_t port, int proc,
187
//_PROTOTYPE( static void do_vir_insw, (port_t port, int proc,
189
//                  vir_bytes buf, size_t size) );
188
//                  vir_bytes buf, size_t size) );
190
//_PROTOTYPE( static void do_vir_outsb, (port_t port, int proc,
189
//_PROTOTYPE( static void do_vir_outsb, (port_t port, int proc,
191
//                  vir_bytes buf, size_t size) );
190
//                  vir_bytes buf, size_t size) );
192
//_PROTOTYPE( static void do_vir_outsw, (port_t port, int proc,
191
//_PROTOTYPE( static void do_vir_outsw, (port_t port, int proc,
193
//                  vir_bytes buf, size_t size) );
192
//                  vir_bytes buf, size_t size) );
194
 
193
 
195
int do_probe( dpeth_t * dep ){
194
int do_probe( dpeth_t * dep ){
196
    /* This is the default, try to (re)locate the device. */
195
    /* This is the default, try to (re)locate the device. */
197
    conf_hw(dep);
196
    conf_hw(dep);
198
    if (dep->de_mode == DEM_DISABLED)
197
    if (dep->de_mode == DEM_DISABLED)
199
    {
198
    {
200
        /* Probe failed, or the device is configured off. */
199
        /* Probe failed, or the device is configured off. */
201
        return EXDEV;//ENXIO;
200
        return EXDEV;//ENXIO;
202
    }
201
    }
203
    if (dep->de_mode == DEM_ENABLED)
202
    if (dep->de_mode == DEM_ENABLED)
204
        dp_init(dep);
203
        dp_init(dep);
205
    return EOK;
204
    return EOK;
206
}
205
}
207
 
206
 
208
/*===========================================================================*
207
/*===========================================================================*
209
 *              do_init                      *
208
 *              do_init                      *
210
 *===========================================================================*/
209
 *===========================================================================*/
211
int do_init( dpeth_t * dep, int mode ){
210
int do_init( dpeth_t * dep, int mode ){
212
    if (dep->de_mode == DEM_DISABLED)
211
    if (dep->de_mode == DEM_DISABLED)
213
    {
212
    {
214
        // might call do_probe()
213
        // might call do_probe()
215
        return EXDEV;
214
        return EXDEV;
216
    }
215
    }
217
 
216
 
218
    if (dep->de_mode == DEM_SINK)
217
    if (dep->de_mode == DEM_SINK)
219
    {
218
    {
220
//      strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
219
//      strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
221
//      dep->de_address.ea_addr[5] = port;
220
//      dep->de_address.ea_addr[5] = port;
222
//      dp_confaddr(dep);
221
//      dp_confaddr(dep);
223
        //TODO ether address?
222
        //TODO ether address?
224
//      reply_mess.m_type = DL_CONF_REPLY;
223
//      reply_mess.m_type = DL_CONF_REPLY;
225
//      reply_mess.m3_i1 = mp->DL_PORT;
224
//      reply_mess.m3_i1 = mp->DL_PORT;
226
//      reply_mess.m3_i2 = DE_PORT_NR;
225
//      reply_mess.m3_i2 = DE_PORT_NR;
227
//      *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
226
//      *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
228
//      mess_reply(mp, &reply_mess);
227
//      mess_reply(mp, &reply_mess);
229
//      return;
228
//      return;
230
        return EOK;
229
        return EOK;
231
    }
230
    }
232
    //TODO assert?
231
    //TODO assert?
233
    assert(dep->de_mode == DEM_ENABLED);
232
    assert(dep->de_mode == DEM_ENABLED);
234
    assert(dep->de_flags & DEF_ENABLED);
233
    assert(dep->de_flags & DEF_ENABLED);
235
 
234
 
236
    dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
235
    dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
237
 
236
 
238
    if (mode & DL_PROMISC_REQ)
237
    if (mode & DL_PROMISC_REQ)
239
        dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
238
        dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
240
    if (mode & DL_MULTI_REQ)
239
    if (mode & DL_MULTI_REQ)
241
        dep->de_flags |= DEF_MULTI;
240
        dep->de_flags |= DEF_MULTI;
242
    if (mode & DL_BROAD_REQ)
241
    if (mode & DL_BROAD_REQ)
243
        dep->de_flags |= DEF_BROAD;
242
        dep->de_flags |= DEF_BROAD;
244
 
243
 
245
//  dep->de_client = mp->m_source;
244
//  dep->de_client = mp->m_source;
246
    dp_reinit(dep);
245
    dp_reinit(dep);
247
 
246
 
248
    //TODO ether address?
247
    //TODO ether address?
249
//  reply_mess.m_type = DL_CONF_REPLY;
248
//  reply_mess.m_type = DL_CONF_REPLY;
250
//  reply_mess.m3_i1 = mp->DL_PORT;
249
//  reply_mess.m3_i1 = mp->DL_PORT;
251
//  reply_mess.m3_i2 = DE_PORT_NR;
250
//  reply_mess.m3_i2 = DE_PORT_NR;
252
//  *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
251
//  *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
253
 
252
 
254
//  mess_reply(mp, &reply_mess);
253
//  mess_reply(mp, &reply_mess);
255
    return EOK;
254
    return EOK;
256
}
255
}
257
 
256
 
258
/*===========================================================================*
257
/*===========================================================================*
259
 *              do_stop                      *
258
 *              do_stop                      *
260
 *===========================================================================*/
259
 *===========================================================================*/
261
void do_stop( dpeth_t * dep ){
260
void do_stop( dpeth_t * dep ){
262
    if(( dep->de_mode != DEM_SINK ) && ( dep->de_mode == DEM_ENABLED ) && ( dep->de_flags & DEF_ENABLED )){
261
    if(( dep->de_mode != DEM_SINK ) && ( dep->de_mode == DEM_ENABLED ) && ( dep->de_flags & DEF_ENABLED )){
263
        outb_reg0( dep, DP_CR, CR_STP | CR_DM_ABORT );
262
        outb_reg0( dep, DP_CR, CR_STP | CR_DM_ABORT );
264
        ( dep->de_stopf )( dep );
263
        ( dep->de_stopf )( dep );
265
 
264
 
266
        dep->de_flags = DEF_EMPTY;
265
        dep->de_flags = DEF_EMPTY;
267
    }
266
    }
268
}
267
}
269
 
268
 
270
int queue_packet( dpeth_t * dep, packet_t packet ){
269
int queue_packet( dpeth_t * dep, packet_t packet ){
271
    packet_t    tmp;
270
    packet_t    tmp;
272
 
271
 
273
    if( dep->packet_count > 1 ){
272
    if( dep->packet_count > 1 ){
274
        if( ! pq_add( pq_previous( dep->packet_queue ), packet, 0, 0 )){
273
        if( ! pq_add( pq_previous( dep->packet_queue ), packet, 0, 0 )){
275
            return EINVAL;
274
            return EINVAL;
276
        }
275
        }
277
    }else{
276
    }else{
278
        tmp = pq_add( dep->packet_queue, packet, 0, 0 );
277
        tmp = pq_add( dep->packet_queue, packet, 0, 0 );
279
        if( ! tmp ) return EINVAL;
278
        if( ! tmp ) return EINVAL;
280
        dep->packet_queue = tmp;
279
        dep->packet_queue = tmp;
281
    }
280
    }
282
    ++ dep->packet_count;
281
    ++ dep->packet_count;
283
    return EBUSY;
282
    return EBUSY;
284
}
283
}
285
 
284
 
286
/*===========================================================================*
285
/*===========================================================================*
287
 *          based on    do_vwrite                    *
286
 *          based on    do_vwrite                    *
288
 *===========================================================================*/
287
 *===========================================================================*/
289
int do_pwrite( dpeth_t * dep, packet_t packet, int from_int )
288
int do_pwrite( dpeth_t * dep, packet_t packet, int from_int )
290
{
289
{
291
//  int port, count, size;
290
//  int port, count, size;
292
    int size;
291
    int size;
293
    int sendq_head;
292
    int sendq_head;
294
/*  dpeth_t *dep;
293
/*  dpeth_t *dep;
295
 
294
 
296
    port = mp->DL_PORT;
295
    port = mp->DL_PORT;
297
    count = mp->DL_COUNT;
296
    count = mp->DL_COUNT;
298
    if (port < 0 || port >= DE_PORT_NR)
297
    if (port < 0 || port >= DE_PORT_NR)
299
        panic("", "dp8390: illegal port", port);
298
        panic("", "dp8390: illegal port", port);
300
    dep= &de_table[port];
299
    dep= &de_table[port];
301
    dep->de_client= mp->DL_PROC;
300
    dep->de_client= mp->DL_PROC;
302
*/
301
*/
303
    if (dep->de_mode == DEM_SINK)
302
    if (dep->de_mode == DEM_SINK)
304
    {
303
    {
305
        assert(!from_int);
304
        assert(!from_int);
306
        dep->de_flags |= DEF_PACK_SEND;
305
        dep->de_flags |= DEF_PACK_SEND;
307
        reply(dep, OK, FALSE);
306
        reply(dep, OK, FALSE);
308
//      return;
307
//      return;
309
        return EOK;
308
        return EOK;
310
    }
309
    }
311
    assert(dep->de_mode == DEM_ENABLED);
310
    assert(dep->de_mode == DEM_ENABLED);
312
    assert(dep->de_flags & DEF_ENABLED);
311
    assert(dep->de_flags & DEF_ENABLED);
313
    if (dep->de_flags & DEF_SEND_AVAIL){
312
    if (dep->de_flags & DEF_SEND_AVAIL){
314
//      panic("", "dp8390: send already in progress", NO_NUM);
313
//      panic("", "dp8390: send already in progress", NO_NUM);
315
        return queue_packet( dep, packet );
314
        return queue_packet( dep, packet );
316
    }
315
    }
317
 
316
 
318
    sendq_head= dep->de_sendq_head;
317
    sendq_head= dep->de_sendq_head;
319
    if (dep->de_sendq[sendq_head].sq_filled)
318
    if (dep->de_sendq[sendq_head].sq_filled)
320
    {
319
    {
321
        if (from_int)
320
        if (from_int)
322
            panic("", "dp8390: should not be sending\n", NO_NUM);
321
            panic("", "dp8390: should not be sending\n", NO_NUM);
323
//      dep->de_sendmsg= *mp;
322
//      dep->de_sendmsg= *mp;
324
        dep->de_flags |= DEF_SEND_AVAIL;
323
        dep->de_flags |= DEF_SEND_AVAIL;
325
        reply(dep, OK, FALSE);
324
        reply(dep, OK, FALSE);
326
//      return;
325
//      return;
327
        return queue_packet( dep, packet );
326
        return queue_packet( dep, packet );
328
    }
327
    }
329
    assert(!(dep->de_flags & DEF_PACK_SEND));
328
    assert(!(dep->de_flags & DEF_PACK_SEND));
330
 
329
 
331
/*  if (vectored)
330
/*  if (vectored)
332
    {
331
    {
333
        get_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR,
332
        get_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR,
334
            (count > IOVEC_NR ? IOVEC_NR : count) *
333
            (count > IOVEC_NR ? IOVEC_NR : count) *
335
            sizeof(iovec_t), dep->de_write_iovec.iod_iovec);
334
            sizeof(iovec_t), dep->de_write_iovec.iod_iovec);
336
        dep->de_write_iovec.iod_iovec_s = count;
335
        dep->de_write_iovec.iod_iovec_s = count;
337
        dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
336
        dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
338
        dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR;
337
        dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR;
339
 
338
 
340
        dep->de_tmp_iovec = dep->de_write_iovec;
339
        dep->de_tmp_iovec = dep->de_write_iovec;
341
        size = calc_iovec_size(&dep->de_tmp_iovec);
340
        size = calc_iovec_size(&dep->de_tmp_iovec);
342
    }
341
    }
343
    else
342
    else
344
    {  
343
    {  
345
        dep->de_write_iovec.iod_iovec[0].iov_addr =
344
        dep->de_write_iovec.iod_iovec[0].iov_addr =
346
            (vir_bytes) mp->DL_ADDR;
345
            (vir_bytes) mp->DL_ADDR;
347
        dep->de_write_iovec.iod_iovec[0].iov_size =
346
        dep->de_write_iovec.iod_iovec[0].iov_size =
348
            mp->DL_COUNT;
347
            mp->DL_COUNT;
349
        dep->de_write_iovec.iod_iovec_s = 1;
348
        dep->de_write_iovec.iod_iovec_s = 1;
350
        dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
349
        dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
351
        dep->de_write_iovec.iod_iovec_addr = 0;
350
        dep->de_write_iovec.iod_iovec_addr = 0;
352
        size= mp->DL_COUNT;
351
        size= mp->DL_COUNT;
353
    }
352
    }
354
*/
353
*/
355
    size = packet_get_data_length( packet );
354
    size = packet_get_data_length( packet );
356
    dep->de_write_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_get_data( packet );
355
    dep->de_write_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_get_data( packet );
357
    dep->de_write_iovec.iod_iovec[0].iov_size = size;
356
    dep->de_write_iovec.iod_iovec[0].iov_size = size;
358
    dep->de_write_iovec.iod_iovec_s = 1;
357
    dep->de_write_iovec.iod_iovec_s = 1;
359
    dep->de_write_iovec.iod_iovec_addr = NULL;
358
    dep->de_write_iovec.iod_iovec_addr = NULL;
360
 
359
 
361
    if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED)
360
    if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED)
362
    {
361
    {
363
        panic("", "dp8390: invalid packet size", size);
362
        panic("", "dp8390: invalid packet size", size);
364
        return EINVAL;
363
        return EINVAL;
365
    }
364
    }
366
    (dep->de_user2nicf)(dep, &dep->de_write_iovec, 0,
365
    (dep->de_user2nicf)(dep, &dep->de_write_iovec, 0,
367
        dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE,
366
        dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE,
368
        size);
367
        size);
369
    dep->de_sendq[sendq_head].sq_filled= TRUE;
368
    dep->de_sendq[sendq_head].sq_filled= TRUE;
370
    if (dep->de_sendq_tail == sendq_head)
369
    if (dep->de_sendq_tail == sendq_head)
371
    {
370
    {
372
        outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage);
371
        outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage);
373
        outb_reg0(dep, DP_TBCR1, size >> 8);
372
        outb_reg0(dep, DP_TBCR1, size >> 8);
374
        outb_reg0(dep, DP_TBCR0, size & 0xff);
373
        outb_reg0(dep, DP_TBCR0, size & 0xff);
375
        outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */
374
        outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */
376
    }
375
    }
377
    else
376
    else
378
        dep->de_sendq[sendq_head].sq_size= size;
377
        dep->de_sendq[sendq_head].sq_size= size;
379
   
378
   
380
    if (++sendq_head == dep->de_sendq_nr)
379
    if (++sendq_head == dep->de_sendq_nr)
381
        sendq_head= 0;
380
        sendq_head= 0;
382
    assert(sendq_head < SENDQ_NR);
381
    assert(sendq_head < SENDQ_NR);
383
    dep->de_sendq_head= sendq_head;
382
    dep->de_sendq_head= sendq_head;
384
 
383
 
385
    dep->de_flags |= DEF_PACK_SEND;
384
    dep->de_flags |= DEF_PACK_SEND;
386
 
385
 
387
    /* If the interrupt handler called, don't send a reply. The reply
386
    /* If the interrupt handler called, don't send a reply. The reply
388
     * will be sent after all interrupts are handled.
387
     * will be sent after all interrupts are handled.
389
     */
388
     */
390
    if (from_int)
389
    if (from_int)
391
        return EOK;
390
        return EOK;
392
    reply(dep, OK, FALSE);
391
    reply(dep, OK, FALSE);
393
 
392
 
394
    assert(dep->de_mode == DEM_ENABLED);
393
    assert(dep->de_mode == DEM_ENABLED);
395
    assert(dep->de_flags & DEF_ENABLED);
394
    assert(dep->de_flags & DEF_ENABLED);
396
    return EOK;
395
    return EOK;
397
}
396
}
398
 
397
 
399
/*===========================================================================*
398
/*===========================================================================*
400
 *              dp_init                      *
399
 *              dp_init                      *
401
 *===========================================================================*/
400
 *===========================================================================*/
402
void dp_init(dep)
401
void dp_init(dep)
403
dpeth_t *dep;
402
dpeth_t *dep;
404
{
403
{
405
    int dp_rcr_reg;
404
    int dp_rcr_reg;
406
    int i;//, r;
405
    int i;//, r;
407
 
406
 
408
    /* General initialization */
407
    /* General initialization */
409
    dep->de_flags = DEF_EMPTY;
408
    dep->de_flags = DEF_EMPTY;
410
    (*dep->de_initf)(dep);
409
    (*dep->de_initf)(dep);
411
 
410
 
412
//  dp_confaddr(dep);
411
//  dp_confaddr(dep);
413
 
412
 
414
    if (debug)
413
    if (debug)
415
    {
414
    {
416
        printf("%s: Ethernet address ", dep->de_name);
415
        printf("%s: Ethernet address ", dep->de_name);
417
        for (i= 0; i < 6; i++)
416
        for (i= 0; i < 6; i++)
418
            printf("%x%c", dep->de_address.ea_addr[i],
417
            printf("%x%c", dep->de_address.ea_addr[i],
419
                            i < 5 ? ':' : '\n');
418
                            i < 5 ? ':' : '\n');
420
    }
419
    }
421
 
420
 
422
    /* Map buffer */
421
    /* Map buffer */
423
    map_hw_buffer(dep);
422
    map_hw_buffer(dep);
424
 
423
 
425
    /* Initialization of the dp8390 following the mandatory procedure
424
    /* Initialization of the dp8390 following the mandatory procedure
426
     * in reference manual ("DP8390D/NS32490D NIC Network Interface
425
     * in reference manual ("DP8390D/NS32490D NIC Network Interface
427
     * Controller", National Semiconductor, July 1995, Page 29).
426
     * Controller", National Semiconductor, July 1995, Page 29).
428
     */
427
     */
429
    /* Step 1: */
428
    /* Step 1: */
430
    outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
429
    outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
431
    /* Step 2: */
430
    /* Step 2: */
432
    if (dep->de_16bit)
431
    if (dep->de_16bit)
433
        outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
432
        outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
434
    else
433
    else
435
        outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
434
        outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
436
    /* Step 3: */
435
    /* Step 3: */
437
    outb_reg0(dep, DP_RBCR0, 0);
436
    outb_reg0(dep, DP_RBCR0, 0);
438
    outb_reg0(dep, DP_RBCR1, 0);
437
    outb_reg0(dep, DP_RBCR1, 0);
439
    /* Step 4: */
438
    /* Step 4: */
440
    dp_rcr_reg = 0;
439
    dp_rcr_reg = 0;
441
    if (dep->de_flags & DEF_PROMISC)
440
    if (dep->de_flags & DEF_PROMISC)
442
        dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
441
        dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
443
    if (dep->de_flags & DEF_BROAD)
442
    if (dep->de_flags & DEF_BROAD)
444
        dp_rcr_reg |= RCR_AB;
443
        dp_rcr_reg |= RCR_AB;
445
    if (dep->de_flags & DEF_MULTI)
444
    if (dep->de_flags & DEF_MULTI)
446
        dp_rcr_reg |= RCR_AM;
445
        dp_rcr_reg |= RCR_AM;
447
    outb_reg0(dep, DP_RCR, dp_rcr_reg);
446
    outb_reg0(dep, DP_RCR, dp_rcr_reg);
448
    /* Step 5: */
447
    /* Step 5: */
449
    outb_reg0(dep, DP_TCR, TCR_INTERNAL);
448
    outb_reg0(dep, DP_TCR, TCR_INTERNAL);
450
    /* Step 6: */
449
    /* Step 6: */
451
    outb_reg0(dep, DP_BNRY, dep->de_startpage);
450
    outb_reg0(dep, DP_BNRY, dep->de_startpage);
452
    outb_reg0(dep, DP_PSTART, dep->de_startpage);
451
    outb_reg0(dep, DP_PSTART, dep->de_startpage);
453
    outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
452
    outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
454
    /* Step 7: */
453
    /* Step 7: */
455
    outb_reg0(dep, DP_ISR, 0xFF);
454
    outb_reg0(dep, DP_ISR, 0xFF);
456
    /* Step 8: */
455
    /* Step 8: */
457
    outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
456
    outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
458
        IMR_OVWE | IMR_CNTE);
457
        IMR_OVWE | IMR_CNTE);
459
    /* Step 9: */
458
    /* Step 9: */
460
    outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
459
    outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
461
 
460
 
462
    outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
461
    outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
463
    outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
462
    outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
464
    outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]);
463
    outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]);
465
    outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]);
464
    outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]);
466
    outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
465
    outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
467
    outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
466
    outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
468
 
467
 
469
    outb_reg1(dep, DP_MAR0, 0xff);
468
    outb_reg1(dep, DP_MAR0, 0xff);
470
    outb_reg1(dep, DP_MAR1, 0xff);
469
    outb_reg1(dep, DP_MAR1, 0xff);
471
    outb_reg1(dep, DP_MAR2, 0xff);
470
    outb_reg1(dep, DP_MAR2, 0xff);
472
    outb_reg1(dep, DP_MAR3, 0xff);
471
    outb_reg1(dep, DP_MAR3, 0xff);
473
    outb_reg1(dep, DP_MAR4, 0xff);
472
    outb_reg1(dep, DP_MAR4, 0xff);
474
    outb_reg1(dep, DP_MAR5, 0xff);
473
    outb_reg1(dep, DP_MAR5, 0xff);
475
    outb_reg1(dep, DP_MAR6, 0xff);
474
    outb_reg1(dep, DP_MAR6, 0xff);
476
    outb_reg1(dep, DP_MAR7, 0xff);
475
    outb_reg1(dep, DP_MAR7, 0xff);
477
 
476
 
478
    outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
477
    outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
479
    /* Step 10: */
478
    /* Step 10: */
480
    outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
479
    outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
481
    /* Step 11: */
480
    /* Step 11: */
482
    outb_reg0(dep, DP_TCR, TCR_NORMAL);
481
    outb_reg0(dep, DP_TCR, TCR_NORMAL);
483
 
482
 
484
    inb_reg0(dep, DP_CNTR0);        /* reset counters by reading */
483
    inb_reg0(dep, DP_CNTR0);        /* reset counters by reading */
485
    inb_reg0(dep, DP_CNTR1);
484
    inb_reg0(dep, DP_CNTR1);
486
    inb_reg0(dep, DP_CNTR2);
485
    inb_reg0(dep, DP_CNTR2);
487
 
486
 
488
    /* Finish the initialization. */
487
    /* Finish the initialization. */
489
    dep->de_flags |= DEF_ENABLED;
488
    dep->de_flags |= DEF_ENABLED;
490
    for (i= 0; i<dep->de_sendq_nr; i++)
489
    for (i= 0; i<dep->de_sendq_nr; i++)
491
        dep->de_sendq[i].sq_filled= 0;
490
        dep->de_sendq[i].sq_filled= 0;
492
    dep->de_sendq_head= 0;
491
    dep->de_sendq_head= 0;
493
    dep->de_sendq_tail= 0;
492
    dep->de_sendq_tail= 0;
494
    if (!dep->de_prog_IO)
493
    if (!dep->de_prog_IO)
495
    {
494
    {
496
        dep->de_user2nicf= dp_user2nic;
495
        dep->de_user2nicf= dp_user2nic;
497
//      dep->de_user2nicf_s= dp_user2nic_s;
496
//      dep->de_user2nicf_s= dp_user2nic_s;
498
        dep->de_nic2userf= dp_nic2user;
497
        dep->de_nic2userf= dp_nic2user;
499
//      dep->de_nic2userf_s= dp_nic2user_s;
498
//      dep->de_nic2userf_s= dp_nic2user_s;
500
        dep->de_getblockf= dp_getblock;
499
        dep->de_getblockf= dp_getblock;
501
    }
500
    }
502
    else if (dep->de_16bit)
501
    else if (dep->de_16bit)
503
    {
502
    {
504
        dep->de_user2nicf= dp_pio16_user2nic;
503
        dep->de_user2nicf= dp_pio16_user2nic;
505
//      dep->de_user2nicf_s= dp_pio16_user2nic_s;
504
//      dep->de_user2nicf_s= dp_pio16_user2nic_s;
506
        dep->de_nic2userf= dp_pio16_nic2user;
505
        dep->de_nic2userf= dp_pio16_nic2user;
507
//      dep->de_nic2userf_s= dp_pio16_nic2user_s;
506
//      dep->de_nic2userf_s= dp_pio16_nic2user_s;
508
        dep->de_getblockf= dp_pio16_getblock;
507
        dep->de_getblockf= dp_pio16_getblock;
509
    }
508
    }
510
    else
509
    else
511
    {
510
    {
512
        dep->de_user2nicf= dp_pio8_user2nic;
511
        dep->de_user2nicf= dp_pio8_user2nic;
513
//      dep->de_user2nicf_s= dp_pio8_user2nic_s;
512
//      dep->de_user2nicf_s= dp_pio8_user2nic_s;
514
        dep->de_nic2userf= dp_pio8_nic2user;
513
        dep->de_nic2userf= dp_pio8_nic2user;
515
//      dep->de_nic2userf_s= dp_pio8_nic2user_s;
514
//      dep->de_nic2userf_s= dp_pio8_nic2user_s;
516
        dep->de_getblockf= dp_pio8_getblock;
515
        dep->de_getblockf= dp_pio8_getblock;
517
    }
516
    }
518
 
517
 
519
    /* Set the interrupt handler and policy. Do not automatically
518
    /* Set the interrupt handler and policy. Do not automatically
520
     * reenable interrupts. Return the IRQ line number on interrupts.
519
     * reenable interrupts. Return the IRQ line number on interrupts.
521
     */
520
     */
522
/*  dep->de_hook = dep->de_irq;
521
/*  dep->de_hook = dep->de_irq;
523
    r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
522
    r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
524
    if (r != OK)
523
    if (r != OK)
525
        panic("DP8390", "sys_irqsetpolicy failed", r);
524
        panic("DP8390", "sys_irqsetpolicy failed", r);
526
 
525
 
527
    r= sys_irqenable(&dep->de_hook);
526
    r= sys_irqenable(&dep->de_hook);
528
    if (r != OK)
527
    if (r != OK)
529
    {
528
    {
530
        panic("DP8390", "unable enable interrupts", r);
529
        panic("DP8390", "unable enable interrupts", r);
531
    }
530
    }
532
*/
531
*/
533
}
532
}
534
 
533
 
535
/*===========================================================================*
534
/*===========================================================================*
536
 *              dp_reinit                    *
535
 *              dp_reinit                    *
537
 *===========================================================================*/
536
 *===========================================================================*/
538
static void dp_reinit(dep)
537
static void dp_reinit(dep)
539
dpeth_t *dep;
538
dpeth_t *dep;
540
{
539
{
541
    int dp_rcr_reg;
540
    int dp_rcr_reg;
542
 
541
 
543
    outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
542
    outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
544
 
543
 
545
    dp_rcr_reg = 0;
544
    dp_rcr_reg = 0;
546
    if (dep->de_flags & DEF_PROMISC)
545
    if (dep->de_flags & DEF_PROMISC)
547
        dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
546
        dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
548
    if (dep->de_flags & DEF_BROAD)
547
    if (dep->de_flags & DEF_BROAD)
549
        dp_rcr_reg |= RCR_AB;
548
        dp_rcr_reg |= RCR_AB;
550
    if (dep->de_flags & DEF_MULTI)
549
    if (dep->de_flags & DEF_MULTI)
551
        dp_rcr_reg |= RCR_AM;
550
        dp_rcr_reg |= RCR_AM;
552
    outb_reg0(dep, DP_RCR, dp_rcr_reg);
551
    outb_reg0(dep, DP_RCR, dp_rcr_reg);
553
}
552
}
554
 
553
 
555
/*===========================================================================*
554
/*===========================================================================*
556
 *              dp_reset                     *
555
 *              dp_reset                     *
557
 *===========================================================================*/
556
 *===========================================================================*/
558
static void dp_reset(dep)
557
static void dp_reset(dep)
559
dpeth_t *dep;
558
dpeth_t *dep;
560
{
559
{
561
    int i;
560
    int i;
562
 
561
 
563
    /* Stop chip */
562
    /* Stop chip */
564
    outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
563
    outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
565
    outb_reg0(dep, DP_RBCR0, 0);
564
    outb_reg0(dep, DP_RBCR0, 0);
566
    outb_reg0(dep, DP_RBCR1, 0);
565
    outb_reg0(dep, DP_RBCR1, 0);
567
    for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
566
    for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
568
        ; /* Do nothing */
567
        ; /* Do nothing */
569
    outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST);
568
    outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST);
570
    outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT);
569
    outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT);
571
    outb_reg0(dep, DP_TCR, TCR_NORMAL);
570
    outb_reg0(dep, DP_TCR, TCR_NORMAL);
572
 
571
 
573
    /* Acknowledge the ISR_RDC (remote dma) interrupt. */
572
    /* Acknowledge the ISR_RDC (remote dma) interrupt. */
574
    for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RDC) == 0); i++)
573
    for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RDC) == 0); i++)
575
        ; /* Do nothing */
574
        ; /* Do nothing */
576
    outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) & ~ISR_RDC);
575
    outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) & ~ISR_RDC);
577
 
576
 
578
    /* Reset the transmit ring. If we were transmitting a packet, we
577
    /* Reset the transmit ring. If we were transmitting a packet, we
579
     * pretend that the packet is processed. Higher layers will
578
     * pretend that the packet is processed. Higher layers will
580
     * retransmit if the packet wasn't actually sent.
579
     * retransmit if the packet wasn't actually sent.
581
     */
580
     */
582
    dep->de_sendq_head= dep->de_sendq_tail= 0;
581
    dep->de_sendq_head= dep->de_sendq_tail= 0;
583
    for (i= 0; i<dep->de_sendq_nr; i++)
582
    for (i= 0; i<dep->de_sendq_nr; i++)
584
        dep->de_sendq[i].sq_filled= 0;
583
        dep->de_sendq[i].sq_filled= 0;
585
    dp_send(dep);
584
    dp_send(dep);
586
    dep->de_flags &= ~DEF_STOPPED;
585
    dep->de_flags &= ~DEF_STOPPED;
587
}
586
}
588
 
587
 
589
/*===========================================================================*
588
/*===========================================================================*
590
 *              dp_check_ints                    *
589
 *              dp_check_ints                    *
591
 *===========================================================================*/
590
 *===========================================================================*/
592
void dp_check_ints(dep)
591
void dp_check_ints(dep)
593
dpeth_t *dep;
592
dpeth_t *dep;
594
{
593
{
595
    int isr, tsr;
594
    int isr, tsr;
596
    int size, sendq_tail;
595
    int size, sendq_tail;
597
 
596
 
598
    if (!(dep->de_flags & DEF_ENABLED))
597
    if (!(dep->de_flags & DEF_ENABLED))
599
        panic("", "dp8390: got premature interrupt", NO_NUM);
598
        panic("", "dp8390: got premature interrupt", NO_NUM);
600
 
599
 
601
    for(;;)
600
    for(;;)
602
    {
601
    {
603
        isr = inb_reg0(dep, DP_ISR);
602
        isr = inb_reg0(dep, DP_ISR);
604
        if (!isr)
603
        if (!isr)
605
            break;
604
            break;
606
        outb_reg0(dep, DP_ISR, isr);
605
        outb_reg0(dep, DP_ISR, isr);
607
        if (isr & (ISR_PTX|ISR_TXE))
606
        if (isr & (ISR_PTX|ISR_TXE))
608
        {
607
        {
609
            if (isr & ISR_TXE)
608
            if (isr & ISR_TXE)
610
            {
609
            {
611
#if DEBUG
610
#if DEBUG
612
 { printf("%s: got send Error\n", dep->de_name); }
611
 { printf("%s: got send Error\n", dep->de_name); }
613
#endif
612
#endif
614
                dep->de_stat.ets_sendErr++;
613
                dep->de_stat.ets_sendErr++;
615
            }
614
            }
616
            else
615
            else
617
            {
616
            {
618
                tsr = inb_reg0(dep, DP_TSR);
617
                tsr = inb_reg0(dep, DP_TSR);
619
 
618
 
620
                if (tsr & TSR_PTX) dep->de_stat.ets_packetT++;
619
                if (tsr & TSR_PTX) dep->de_stat.ets_packetT++;
621
#if 0   /* Reserved in later manuals, should be ignored */
620
#if 0   /* Reserved in later manuals, should be ignored */
622
                if (!(tsr & TSR_DFR))
621
                if (!(tsr & TSR_DFR))
623
                {
622
                {
624
                    /* In most (all?) implementations of
623
                    /* In most (all?) implementations of
625
                     * the dp8390, this bit is set
624
                     * the dp8390, this bit is set
626
                     * when the packet is not deferred
625
                     * when the packet is not deferred
627
                     */
626
                     */
628
                    dep->de_stat.ets_transDef++;
627
                    dep->de_stat.ets_transDef++;
629
                }
628
                }
630
#endif
629
#endif
631
                if (tsr & TSR_COL) dep->de_stat.ets_collision++;
630
                if (tsr & TSR_COL) dep->de_stat.ets_collision++;
632
                if (tsr & TSR_ABT) dep->de_stat.ets_transAb++;
631
                if (tsr & TSR_ABT) dep->de_stat.ets_transAb++;
633
                if (tsr & TSR_CRS) dep->de_stat.ets_carrSense++;
632
                if (tsr & TSR_CRS) dep->de_stat.ets_carrSense++;
634
                if (tsr & TSR_FU
633
                if (tsr & TSR_FU
635
                    && ++dep->de_stat.ets_fifoUnder <= 10)
634
                    && ++dep->de_stat.ets_fifoUnder <= 10)
636
                {
635
                {
637
                    printf("%s: fifo underrun\n",
636
                    printf("%s: fifo underrun\n",
638
                        dep->de_name);
637
                        dep->de_name);
639
                }
638
                }
640
                if (tsr & TSR_CDH
639
                if (tsr & TSR_CDH
641
                    && ++dep->de_stat.ets_CDheartbeat <= 10)
640
                    && ++dep->de_stat.ets_CDheartbeat <= 10)
642
                {
641
                {
643
                    printf("%s: CD heart beat failure\n",
642
                    printf("%s: CD heart beat failure\n",
644
                        dep->de_name);
643
                        dep->de_name);
645
                }
644
                }
646
                if (tsr & TSR_OWC) dep->de_stat.ets_OWC++;
645
                if (tsr & TSR_OWC) dep->de_stat.ets_OWC++;
647
            }
646
            }
648
            sendq_tail= dep->de_sendq_tail;
647
            sendq_tail= dep->de_sendq_tail;
649
 
648
 
650
            if (!(dep->de_sendq[sendq_tail].sq_filled))
649
            if (!(dep->de_sendq[sendq_tail].sq_filled))
651
            {
650
            {
652
                /* Software bug? */
651
                /* Software bug? */
653
                assert(!debug);
652
                assert(!debug);
654
 
653
 
655
                /* Or hardware bug? */
654
                /* Or hardware bug? */
656
                printf(
655
                printf(
657
                "%s: transmit interrupt, but not sending\n",
656
                "%s: transmit interrupt, but not sending\n",
658
                    dep->de_name);
657
                    dep->de_name);
659
                continue;
658
                continue;
660
            }
659
            }
661
            dep->de_sendq[sendq_tail].sq_filled= 0;
660
            dep->de_sendq[sendq_tail].sq_filled= 0;
662
            if (++sendq_tail == dep->de_sendq_nr)
661
            if (++sendq_tail == dep->de_sendq_nr)
663
                sendq_tail= 0;
662
                sendq_tail= 0;
664
            dep->de_sendq_tail= sendq_tail;
663
            dep->de_sendq_tail= sendq_tail;
665
            if (dep->de_sendq[sendq_tail].sq_filled)
664
            if (dep->de_sendq[sendq_tail].sq_filled)
666
            {
665
            {
667
                size= dep->de_sendq[sendq_tail].sq_size;
666
                size= dep->de_sendq[sendq_tail].sq_size;
668
                outb_reg0(dep, DP_TPSR,
667
                outb_reg0(dep, DP_TPSR,
669
                    dep->de_sendq[sendq_tail].sq_sendpage);
668
                    dep->de_sendq[sendq_tail].sq_sendpage);
670
                outb_reg0(dep, DP_TBCR1, size >> 8);
669
                outb_reg0(dep, DP_TBCR1, size >> 8);
671
                outb_reg0(dep, DP_TBCR0, size & 0xff);
670
                outb_reg0(dep, DP_TBCR0, size & 0xff);
672
                outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
671
                outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
673
            }
672
            }
674
            if (dep->de_flags & DEF_SEND_AVAIL)
673
            if (dep->de_flags & DEF_SEND_AVAIL)
675
                dp_send(dep);
674
                dp_send(dep);
676
        }
675
        }
677
 
676
 
678
        if (isr & ISR_PRX)
677
        if (isr & ISR_PRX)
679
        {
678
        {
680
            /* Only call dp_recv if there is a read request */
679
            /* Only call dp_recv if there is a read request */
681
            if (dep->de_flags & DEF_READING)
680
            if (dep->de_flags & DEF_READING)
682
                dp_recv(dep);
681
                dp_recv(dep);
683
        }
682
        }
684
       
683
       
685
        if (isr & ISR_RXE) dep->de_stat.ets_recvErr++;
684
        if (isr & ISR_RXE) dep->de_stat.ets_recvErr++;
686
        if (isr & ISR_CNT)
685
        if (isr & ISR_CNT)
687
        {
686
        {
688
            dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
687
            dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
689
            dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
688
            dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
690
            dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
689
            dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
691
        }
690
        }
692
        if (isr & ISR_OVW)
691
        if (isr & ISR_OVW)
693
        {
692
        {
694
            dep->de_stat.ets_OVW++;
693
            dep->de_stat.ets_OVW++;
695
#if 0
694
#if 0
696
            { printW(); printf(
695
            { printW(); printf(
697
                "%s: got overwrite warning\n", dep->de_name); }
696
                "%s: got overwrite warning\n", dep->de_name); }
698
#endif
697
#endif
699
            if (dep->de_flags & DEF_READING)
698
            if (dep->de_flags & DEF_READING)
700
            {
699
            {
701
                printf(
700
                printf(
702
"dp_check_ints: strange: overwrite warning and pending read request\n");
701
"dp_check_ints: strange: overwrite warning and pending read request\n");
703
                dp_recv(dep);
702
                dp_recv(dep);
704
            }
703
            }
705
        }
704
        }
706
        if (isr & ISR_RDC)
705
        if (isr & ISR_RDC)
707
        {
706
        {
708
            /* Nothing to do */
707
            /* Nothing to do */
709
        }
708
        }
710
        if (isr & ISR_RST)
709
        if (isr & ISR_RST)
711
        {
710
        {
712
            /* this means we got an interrupt but the ethernet
711
            /* this means we got an interrupt but the ethernet
713
             * chip is shutdown. We set the flag DEF_STOPPED,
712
             * chip is shutdown. We set the flag DEF_STOPPED,
714
             * and continue processing arrived packets. When the
713
             * and continue processing arrived packets. When the
715
             * receive buffer is empty, we reset the dp8390.
714
             * receive buffer is empty, we reset the dp8390.
716
             */
715
             */
717
#if 0
716
#if 0
718
             { printW(); printf(
717
             { printW(); printf(
719
                "%s: NIC stopped\n", dep->de_name); }
718
                "%s: NIC stopped\n", dep->de_name); }
720
#endif
719
#endif
721
            dep->de_flags |= DEF_STOPPED;
720
            dep->de_flags |= DEF_STOPPED;
722
            break;
721
            break;
723
        }
722
        }
724
    }
723
    }
725
    if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) ==
724
    if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) ==
726
                        (DEF_READING|DEF_STOPPED))
725
                        (DEF_READING|DEF_STOPPED))
727
    {
726
    {
728
        /* The chip is stopped, and all arrived packets are
727
        /* The chip is stopped, and all arrived packets are
729
         * delivered.
728
         * delivered.
730
         */
729
         */
731
        dp_reset(dep);
730
        dp_reset(dep);
732
    }
731
    }
733
}
732
}
734
 
733
 
735
/*===========================================================================*
734
/*===========================================================================*
736
 *              dp_recv                      *
735
 *              dp_recv                      *
737
 *===========================================================================*/
736
 *===========================================================================*/
738
static void dp_recv(dep)
737
static void dp_recv(dep)
739
dpeth_t *dep;
738
dpeth_t *dep;
740
{
739
{
741
    dp_rcvhdr_t header;
740
    dp_rcvhdr_t header;
742
    unsigned pageno, curr, next;
741
    unsigned pageno, curr, next;
743
    vir_bytes length;
742
    vir_bytes length;
744
    int packet_processed, r;
743
    int packet_processed, r;
745
    u16_t eth_type;
744
    u16_t eth_type;
746
 
745
 
747
    packet_processed = FALSE;
746
    packet_processed = FALSE;
748
    pageno = inb_reg0(dep, DP_BNRY) + 1;
747
    pageno = inb_reg0(dep, DP_BNRY) + 1;
749
    if (pageno == dep->de_stoppage) pageno = dep->de_startpage;
748
    if (pageno == dep->de_stoppage) pageno = dep->de_startpage;
750
 
749
 
751
    do
750
    do
752
    {
751
    {
753
        outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA);
752
        outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA);
754
        curr = inb_reg1(dep, DP_CURR);
753
        curr = inb_reg1(dep, DP_CURR);
755
        outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
754
        outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
756
 
755
 
757
        if (curr == pageno) break;
756
        if (curr == pageno) break;
758
 
757
 
759
        (dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header),
758
        (dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header),
760
            &header);
759
            &header);
761
        (dep->de_getblockf)(dep, pageno, sizeof(header) +
760
        (dep->de_getblockf)(dep, pageno, sizeof(header) +
762
            2*sizeof(ether_addr_t), sizeof(eth_type), &eth_type);
761
            2*sizeof(ether_addr_t), sizeof(eth_type), &eth_type);
763
 
762
 
764
        length = (header.dr_rbcl | (header.dr_rbch << 8)) -
763
        length = (header.dr_rbcl | (header.dr_rbch << 8)) -
765
            sizeof(dp_rcvhdr_t);
764
            sizeof(dp_rcvhdr_t);
766
        next = header.dr_next;
765
        next = header.dr_next;
767
        if (length < ETH_MIN_PACK_SIZE ||
766
        if (length < ETH_MIN_PACK_SIZE ||
768
            length > ETH_MAX_PACK_SIZE_TAGGED)
767
            length > ETH_MAX_PACK_SIZE_TAGGED)
769
        {
768
        {
770
            printf("%s: packet with strange length arrived: %d\n",
769
            printf("%s: packet with strange length arrived: %d\n",
771
                dep->de_name, (int) length);
770
                dep->de_name, (int) length);
772
            next= curr;
771
            next= curr;
773
        }
772
        }
774
        else if (next < dep->de_startpage || next >= dep->de_stoppage)
773
        else if (next < dep->de_startpage || next >= dep->de_stoppage)
775
        {
774
        {
776
            printf("%s: strange next page\n", dep->de_name);
775
            printf("%s: strange next page\n", dep->de_name);
777
            next= curr;
776
            next= curr;
778
        }
777
        }
779
/*      else if (eth_type == eth_ign_proto)
778
/*      else if (eth_type == eth_ign_proto)
780
        {
779
        {
781
*/          /* Hack: ignore packets of a given protocol, useful
780
*/          /* Hack: ignore packets of a given protocol, useful
782
             * if you share a net with 80 computers sending
781
             * if you share a net with 80 computers sending
783
             * Amoeba FLIP broadcasts.  (Protocol 0x8146.)
782
             * Amoeba FLIP broadcasts.  (Protocol 0x8146.)
784
             */
783
             */
785
/*          static int first= 1;
784
/*          static int first= 1;
786
            if (first)
785
            if (first)
787
            {
786
            {
788
                first= 0;
787
                first= 0;
789
                printf("%s: dropping proto 0x%04x packets\n",
788
                printf("%s: dropping proto 0x%04x packets\n",
790
                    dep->de_name,
789
                    dep->de_name,
791
                    ntohs(eth_ign_proto));
790
                    ntohs(eth_ign_proto));
792
            }
791
            }
793
            dep->de_stat.ets_packetR++;
792
            dep->de_stat.ets_packetR++;
794
        }
793
        }
795
*/      else if (header.dr_status & RSR_FO)
794
*/      else if (header.dr_status & RSR_FO)
796
        {
795
        {
797
            /* This is very serious, so we issue a warning and
796
            /* This is very serious, so we issue a warning and
798
             * reset the buffers */
797
             * reset the buffers */
799
            printf("%s: fifo overrun, resetting receive buffer\n",
798
            printf("%s: fifo overrun, resetting receive buffer\n",
800
                dep->de_name);
799
                dep->de_name);
801
            dep->de_stat.ets_fifoOver++;
800
            dep->de_stat.ets_fifoOver++;
802
            next = curr;
801
            next = curr;
803
        }
802
        }
804
        else if ((header.dr_status & RSR_PRX) &&
803
        else if ((header.dr_status & RSR_PRX) &&
805
                       (dep->de_flags & DEF_ENABLED))
804
                       (dep->de_flags & DEF_ENABLED))
806
        {
805
        {
807
//          if (dep->de_safecopy_read)
806
//          if (dep->de_safecopy_read)
808
//              r = dp_pkt2user_s(dep, pageno, length);
807
//              r = dp_pkt2user_s(dep, pageno, length);
809
//          else
808
//          else
810
                r = dp_pkt2user(dep, pageno, length);
809
                r = dp_pkt2user(dep, pageno, length);
811
            if (r != OK)
810
            if (r != OK)
812
                return;
811
                return;
813
 
812
 
814
            packet_processed = TRUE;
813
            packet_processed = TRUE;
815
            dep->de_stat.ets_packetR++;
814
            dep->de_stat.ets_packetR++;
816
        }
815
        }
817
        if (next == dep->de_startpage)
816
        if (next == dep->de_startpage)
818
            outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1);
817
            outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1);
819
        else
818
        else
820
            outb_reg0(dep, DP_BNRY, next - 1);
819
            outb_reg0(dep, DP_BNRY, next - 1);
821
 
820
 
822
        pageno = next;
821
        pageno = next;
823
    }
822
    }
824
    while (!packet_processed);
823
    while (!packet_processed);
825
}
824
}
826
 
825
 
827
/*===========================================================================*
826
/*===========================================================================*
828
 *              dp_send                      *
827
 *              dp_send                      *
829
 *===========================================================================*/
828
 *===========================================================================*/
830
static void dp_send(dep)
829
static void dp_send(dep)
831
dpeth_t *dep;
830
dpeth_t *dep;
832
{
831
{
833
    packet_t packet;
832
    packet_t packet;
834
 
833
 
835
    if (!(dep->de_flags & DEF_SEND_AVAIL))
834
    if (!(dep->de_flags & DEF_SEND_AVAIL))
836
        return;
835
        return;
837
 
836
 
838
    dep->de_flags &= ~DEF_SEND_AVAIL;
837
    dep->de_flags &= ~DEF_SEND_AVAIL;
839
    while( dep->packet_queue ){
838
    while( dep->packet_queue ){
840
        packet = dep->packet_queue;
839
        packet = dep->packet_queue;
841
        dep->packet_queue = pq_detach( packet );
840
        dep->packet_queue = pq_detach( packet );
842
        do_pwrite( dep, packet, TRUE );
841
        do_pwrite( dep, packet, TRUE );
843
        netif_pq_release( packet_get_id( packet ));
842
        netif_pq_release( packet_get_id( packet ));
844
        -- dep->packet_count;
843
        -- dep->packet_count;
845
    }
844
    }
846
/*  switch(dep->de_sendmsg.m_type)
845
/*  switch(dep->de_sendmsg.m_type)
847
    {
846
    {
848
    case DL_WRITE:  do_vwrite(&dep->de_sendmsg, TRUE, FALSE);   break;
847
    case DL_WRITE:  do_vwrite(&dep->de_sendmsg, TRUE, FALSE);   break;
849
    case DL_WRITEV: do_vwrite(&dep->de_sendmsg, TRUE, TRUE);    break;
848
    case DL_WRITEV: do_vwrite(&dep->de_sendmsg, TRUE, TRUE);    break;
850
    case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, TRUE);  break;
849
    case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, TRUE);  break;
851
    default:
850
    default:
852
        panic("", "dp8390: wrong type", dep->de_sendmsg.m_type);
851
        panic("", "dp8390: wrong type", dep->de_sendmsg.m_type);
853
        break;
852
        break;
854
    }
853
    }
855
*/
854
*/
856
}
855
}
857
 
856
 
858
/*===========================================================================*
857
/*===========================================================================*
859
 *              dp_getblock                  *
858
 *              dp_getblock                  *
860
 *===========================================================================*/
859
 *===========================================================================*/
861
static void dp_getblock(dep, page, offset, size, dst)
860
static void dp_getblock(dep, page, offset, size, dst)
862
dpeth_t *dep;
861
dpeth_t *dep;
863
int page;
862
int page;
864
size_t offset;
863
size_t offset;
865
size_t size;
864
size_t size;
866
void *dst;
865
void *dst;
867
{
866
{
868
//  int r;
867
//  int r;
869
 
868
 
870
    offset = page * DP_PAGESIZE + offset;
869
    offset = page * DP_PAGESIZE + offset;
871
 
870
 
872
    memcpy(dst, dep->de_locmem + offset, size);
871
    memcpy(dst, dep->de_locmem + offset, size);
873
}
872
}
874
 
873
 
875
/*===========================================================================*
874
/*===========================================================================*
876
 *              dp_pio8_getblock                 *
875
 *              dp_pio8_getblock                 *
877
 *===========================================================================*/
876
 *===========================================================================*/
878
static void dp_pio8_getblock(dep, page, offset, size, dst)
877
static void dp_pio8_getblock(dep, page, offset, size, dst)
879
dpeth_t *dep;
878
dpeth_t *dep;
880
int page;
879
int page;
881
size_t offset;
880
size_t offset;
882
size_t size;
881
size_t size;
883
void *dst;
882
void *dst;
884
{
883
{
885
    offset = page * DP_PAGESIZE + offset;
884
    offset = page * DP_PAGESIZE + offset;
886
    outb_reg0(dep, DP_RBCR0, size & 0xFF);
885
    outb_reg0(dep, DP_RBCR0, size & 0xFF);
887
    outb_reg0(dep, DP_RBCR1, size >> 8);
886
    outb_reg0(dep, DP_RBCR1, size >> 8);
888
    outb_reg0(dep, DP_RSAR0, offset & 0xFF);
887
    outb_reg0(dep, DP_RSAR0, offset & 0xFF);
889
    outb_reg0(dep, DP_RSAR1, offset >> 8);
888
    outb_reg0(dep, DP_RSAR1, offset >> 8);
890
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
889
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
891
 
890
 
892
    insb(dep->de_data_port, dst, size);
891
    insb(dep->de_data_port, dst, size);
893
}
892
}
894
 
893
 
895
/*===========================================================================*
894
/*===========================================================================*
896
 *              dp_pio16_getblock                *
895
 *              dp_pio16_getblock                *
897
 *===========================================================================*/
896
 *===========================================================================*/
898
static void dp_pio16_getblock(dep, page, offset, size, dst)
897
static void dp_pio16_getblock(dep, page, offset, size, dst)
899
dpeth_t *dep;
898
dpeth_t *dep;
900
int page;
899
int page;
901
size_t offset;
900
size_t offset;
902
size_t size;
901
size_t size;
903
void *dst;
902
void *dst;
904
{
903
{
905
    offset = page * DP_PAGESIZE + offset;
904
    offset = page * DP_PAGESIZE + offset;
906
    outb_reg0(dep, DP_RBCR0, size & 0xFF);
905
    outb_reg0(dep, DP_RBCR0, size & 0xFF);
907
    outb_reg0(dep, DP_RBCR1, size >> 8);
906
    outb_reg0(dep, DP_RBCR1, size >> 8);
908
    outb_reg0(dep, DP_RSAR0, offset & 0xFF);
907
    outb_reg0(dep, DP_RSAR0, offset & 0xFF);
909
    outb_reg0(dep, DP_RSAR1, offset >> 8);
908
    outb_reg0(dep, DP_RSAR1, offset >> 8);
910
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
909
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
911
 
910
 
912
    assert (!(size & 1));
911
    assert (!(size & 1));
913
    insw(dep->de_data_port, dst, size);
912
    insw(dep->de_data_port, dst, size);
914
}
913
}
915
 
914
 
916
/*===========================================================================*
915
/*===========================================================================*
917
 *              dp_pkt2user                  *
916
 *              dp_pkt2user                  *
918
 *===========================================================================*/
917
 *===========================================================================*/
919
static int dp_pkt2user(dep, page, length)
918
static int dp_pkt2user(dep, page, length)
920
dpeth_t *dep;
919
dpeth_t *dep;
921
int page, length;
920
int page, length;
922
{
921
{
923
    int last, count;
922
    int last, count;
924
    packet_t    packet;
923
    packet_t    packet;
-
 
924
    packet_t    queue;
925
 
925
 
926
    if (!(dep->de_flags & DEF_READING))
926
    if (!(dep->de_flags & DEF_READING))
927
        return EGENERIC;
927
        return EGENERIC;
928
 
928
 
929
    packet = netif_packet_get_1( length );
929
    packet = netif_packet_get_1( length );
930
    if( ! packet ) return ENOMEM;
930
    if( ! packet ) return ENOMEM;
931
    dep->de_read_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_suffix( packet, length );
931
    dep->de_read_iovec.iod_iovec[0].iov_addr = ( vir_bytes ) packet_suffix( packet, length );
932
    dep->de_read_iovec.iod_iovec[0].iov_size = length;
932
    dep->de_read_iovec.iod_iovec[0].iov_size = length;
933
    dep->de_read_iovec.iod_iovec_s = 1;
933
    dep->de_read_iovec.iod_iovec_s = 1;
934
    dep->de_read_iovec.iod_iovec_addr = NULL;
934
    dep->de_read_iovec.iod_iovec_addr = NULL;
935
 
935
 
936
    last = page + (length - 1) / DP_PAGESIZE;
936
    last = page + (length - 1) / DP_PAGESIZE;
937
    if (last >= dep->de_stoppage)
937
    if (last >= dep->de_stoppage)
938
    {
938
    {
939
        count = (dep->de_stoppage - page) * DP_PAGESIZE -
939
        count = (dep->de_stoppage - page) * DP_PAGESIZE -
940
            sizeof(dp_rcvhdr_t);
940
            sizeof(dp_rcvhdr_t);
941
 
941
 
942
        /* Save read_iovec since we need it twice. */
942
        /* Save read_iovec since we need it twice. */
943
        dep->de_tmp_iovec = dep->de_read_iovec;
943
        dep->de_tmp_iovec = dep->de_read_iovec;
944
        (dep->de_nic2userf)(dep, page * DP_PAGESIZE +
944
        (dep->de_nic2userf)(dep, page * DP_PAGESIZE +
945
            sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count);
945
            sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count);
946
        (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE,
946
        (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE,
947
                &dep->de_read_iovec, count, length - count);
947
                &dep->de_read_iovec, count, length - count);
948
    }
948
    }
949
    else
949
    else
950
    {
950
    {
951
        (dep->de_nic2userf)(dep, page * DP_PAGESIZE +
951
        (dep->de_nic2userf)(dep, page * DP_PAGESIZE +
952
            sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length);
952
            sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length);
953
    }
953
    }
954
 
954
 
955
    dep->de_read_s = length;
955
    dep->de_read_s = length;
956
    dep->de_flags |= DEF_PACK_RECV;
956
    dep->de_flags |= DEF_PACK_RECV;
957
    dep->de_flags &= ~DEF_READING;
957
    dep->de_flags &= ~DEF_READING;
958
 
958
 
959
    if( netif_send_packet( dep, packet ) != EOK ){
959
    queue = pq_add( dep->received_queue, packet, 0, 0 );
-
 
960
    if( queue ){
-
 
961
        dep->received_queue = queue;
-
 
962
    }else{
960
        netif_pq_release( packet_get_id( packet ));
963
        netif_pq_release( packet_get_id( packet ));
961
    }
964
    }
962
    return OK;
965
    return OK;
963
}
966
}
964
 
967
 
965
/*===========================================================================*
968
/*===========================================================================*
966
 *              dp_user2nic                  *
969
 *              dp_user2nic                  *
967
 *===========================================================================*/
970
 *===========================================================================*/
968
static void dp_user2nic(dep, iovp, offset, nic_addr, count)
971
static void dp_user2nic(dep, iovp, offset, nic_addr, count)
969
dpeth_t *dep;
972
dpeth_t *dep;
970
iovec_dat_t *iovp;
973
iovec_dat_t *iovp;
971
vir_bytes offset;
974
vir_bytes offset;
972
int nic_addr;
975
int nic_addr;
973
vir_bytes count;
976
vir_bytes count;
974
{
977
{
975
    vir_bytes vir_hw;//, vir_user;
978
    vir_bytes vir_hw;//, vir_user;
976
    int bytes, i, r;
979
    int bytes, i, r;
977
 
980
 
978
    vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
981
    vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
979
 
982
 
980
    i= 0;
983
    i= 0;
981
    while (count > 0)
984
    while (count > 0)
982
    {
985
    {
983
        if (i >= IOVEC_NR)
986
        if (i >= IOVEC_NR)
984
        {
987
        {
985
            dp_next_iovec(iovp);
988
            dp_next_iovec(iovp);
986
            i= 0;
989
            i= 0;
987
            continue;
990
            continue;
988
        }
991
        }
989
        assert(i < iovp->iod_iovec_s);
992
        assert(i < iovp->iod_iovec_s);
990
        if (offset >= iovp->iod_iovec[i].iov_size)
993
        if (offset >= iovp->iod_iovec[i].iov_size)
991
        {
994
        {
992
            offset -= iovp->iod_iovec[i].iov_size;
995
            offset -= iovp->iod_iovec[i].iov_size;
993
            i++;
996
            i++;
994
            continue;
997
            continue;
995
        }
998
        }
996
        bytes = iovp->iod_iovec[i].iov_size - offset;
999
        bytes = iovp->iod_iovec[i].iov_size - offset;
997
        if (bytes > count)
1000
        if (bytes > count)
998
            bytes = count;
1001
            bytes = count;
999
 
1002
 
1000
        r= sys_vircopy(iovp->iod_proc_nr, D,
1003
        r= sys_vircopy(iovp->iod_proc_nr, D,
1001
            iovp->iod_iovec[i].iov_addr + offset,
1004
            iovp->iod_iovec[i].iov_addr + offset,
1002
            SELF, D, vir_hw, bytes);
1005
            SELF, D, vir_hw, bytes);
1003
        if (r != OK)
1006
        if (r != OK)
1004
            panic("DP8390", "dp_user2nic: sys_vircopy failed", r);
1007
            panic("DP8390", "dp_user2nic: sys_vircopy failed", r);
1005
 
1008
 
1006
        count -= bytes;
1009
        count -= bytes;
1007
        vir_hw += bytes;
1010
        vir_hw += bytes;
1008
        offset += bytes;
1011
        offset += bytes;
1009
    }
1012
    }
1010
    assert(count == 0);
1013
    assert(count == 0);
1011
}
1014
}
1012
 
1015
 
1013
/*===========================================================================*
1016
/*===========================================================================*
1014
 *              dp_pio8_user2nic                 *
1017
 *              dp_pio8_user2nic                 *
1015
 *===========================================================================*/
1018
 *===========================================================================*/
1016
static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count)
1019
static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count)
1017
dpeth_t *dep;
1020
dpeth_t *dep;
1018
iovec_dat_t *iovp;
1021
iovec_dat_t *iovp;
1019
vir_bytes offset;
1022
vir_bytes offset;
1020
int nic_addr;
1023
int nic_addr;
1021
vir_bytes count;
1024
vir_bytes count;
1022
{
1025
{
1023
//  phys_bytes phys_user;
1026
//  phys_bytes phys_user;
1024
    int bytes, i;
1027
    int bytes, i;
1025
 
1028
 
1026
    outb_reg0(dep, DP_ISR, ISR_RDC);
1029
    outb_reg0(dep, DP_ISR, ISR_RDC);
1027
 
1030
 
1028
    outb_reg0(dep, DP_RBCR0, count & 0xFF);
1031
    outb_reg0(dep, DP_RBCR0, count & 0xFF);
1029
    outb_reg0(dep, DP_RBCR1, count >> 8);
1032
    outb_reg0(dep, DP_RBCR1, count >> 8);
1030
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1033
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1031
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1034
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1032
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
1035
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
1033
 
1036
 
1034
    i= 0;
1037
    i= 0;
1035
    while (count > 0)
1038
    while (count > 0)
1036
    {
1039
    {
1037
        if (i >= IOVEC_NR)
1040
        if (i >= IOVEC_NR)
1038
        {
1041
        {
1039
            dp_next_iovec(iovp);
1042
            dp_next_iovec(iovp);
1040
            i= 0;
1043
            i= 0;
1041
            continue;
1044
            continue;
1042
        }
1045
        }
1043
        assert(i < iovp->iod_iovec_s);
1046
        assert(i < iovp->iod_iovec_s);
1044
        if (offset >= iovp->iod_iovec[i].iov_size)
1047
        if (offset >= iovp->iod_iovec[i].iov_size)
1045
        {
1048
        {
1046
            offset -= iovp->iod_iovec[i].iov_size;
1049
            offset -= iovp->iod_iovec[i].iov_size;
1047
            i++;
1050
            i++;
1048
            continue;
1051
            continue;
1049
        }
1052
        }
1050
        bytes = iovp->iod_iovec[i].iov_size - offset;
1053
        bytes = iovp->iod_iovec[i].iov_size - offset;
1051
        if (bytes > count)
1054
        if (bytes > count)
1052
            bytes = count;
1055
            bytes = count;
1053
 
1056
 
1054
        do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr,
1057
        do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr,
1055
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1058
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1056
        count -= bytes;
1059
        count -= bytes;
1057
        offset += bytes;
1060
        offset += bytes;
1058
    }
1061
    }
1059
    assert(count == 0);
1062
    assert(count == 0);
1060
 
1063
 
1061
    for (i= 0; i<100; i++)
1064
    for (i= 0; i<100; i++)
1062
    {
1065
    {
1063
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
1066
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
1064
            break;
1067
            break;
1065
    }
1068
    }
1066
    if (i == 100)
1069
    if (i == 100)
1067
    {
1070
    {
1068
        panic("", "dp8390: remote dma failed to complete", NO_NUM);
1071
        panic("", "dp8390: remote dma failed to complete", NO_NUM);
1069
    }
1072
    }
1070
}
1073
}
1071
 
1074
 
1072
/*===========================================================================*
1075
/*===========================================================================*
1073
 *              dp_pio16_user2nic                *
1076
 *              dp_pio16_user2nic                *
1074
 *===========================================================================*/
1077
 *===========================================================================*/
1075
static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count)
1078
static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count)
1076
dpeth_t *dep;
1079
dpeth_t *dep;
1077
iovec_dat_t *iovp;
1080
iovec_dat_t *iovp;
1078
vir_bytes offset;
1081
vir_bytes offset;
1079
int nic_addr;
1082
int nic_addr;
1080
vir_bytes count;
1083
vir_bytes count;
1081
{
1084
{
1082
    vir_bytes vir_user;
1085
    vir_bytes vir_user;
1083
    vir_bytes ecount;
1086
    vir_bytes ecount;
1084
    int i, r, bytes, user_proc;
1087
    int i, r, bytes, user_proc;
1085
    u8_t two_bytes[2];
1088
    u8_t two_bytes[2];
1086
    int odd_byte;
1089
    int odd_byte;
1087
 
1090
 
1088
    ecount= (count+1) & ~1;
1091
    ecount= (count+1) & ~1;
1089
    odd_byte= 0;
1092
    odd_byte= 0;
1090
 
1093
 
1091
    outb_reg0(dep, DP_ISR, ISR_RDC);
1094
    outb_reg0(dep, DP_ISR, ISR_RDC);
1092
    outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
1095
    outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
1093
    outb_reg0(dep, DP_RBCR1, ecount >> 8);
1096
    outb_reg0(dep, DP_RBCR1, ecount >> 8);
1094
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1097
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1095
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1098
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1096
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
1099
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
1097
 
1100
 
1098
    i= 0;
1101
    i= 0;
1099
    while (count > 0)
1102
    while (count > 0)
1100
    {
1103
    {
1101
        if (i >= IOVEC_NR)
1104
        if (i >= IOVEC_NR)
1102
        {
1105
        {
1103
            dp_next_iovec(iovp);
1106
            dp_next_iovec(iovp);
1104
            i= 0;
1107
            i= 0;
1105
            continue;
1108
            continue;
1106
        }
1109
        }
1107
        assert(i < iovp->iod_iovec_s);
1110
        assert(i < iovp->iod_iovec_s);
1108
        if (offset >= iovp->iod_iovec[i].iov_size)
1111
        if (offset >= iovp->iod_iovec[i].iov_size)
1109
        {
1112
        {
1110
            offset -= iovp->iod_iovec[i].iov_size;
1113
            offset -= iovp->iod_iovec[i].iov_size;
1111
            i++;
1114
            i++;
1112
            continue;
1115
            continue;
1113
        }
1116
        }
1114
        bytes = iovp->iod_iovec[i].iov_size - offset;
1117
        bytes = iovp->iod_iovec[i].iov_size - offset;
1115
        if (bytes > count)
1118
        if (bytes > count)
1116
            bytes = count;
1119
            bytes = count;
1117
 
1120
 
1118
        user_proc= iovp->iod_proc_nr;
1121
        user_proc= iovp->iod_proc_nr;
1119
        vir_user= iovp->iod_iovec[i].iov_addr + offset;
1122
        vir_user= iovp->iod_iovec[i].iov_addr + offset;
1120
        if (odd_byte)
1123
        if (odd_byte)
1121
        {
1124
        {
1122
            r= sys_vircopy(user_proc, D, vir_user,
1125
            r= sys_vircopy(user_proc, D, vir_user,
1123
                SELF, D, (vir_bytes)&two_bytes[1], 1);
1126
                SELF, D, (vir_bytes)&two_bytes[1], 1);
1124
            if (r != OK)
1127
            if (r != OK)
1125
            {
1128
            {
1126
                panic("DP8390",
1129
                panic("DP8390",
1127
                    "dp_pio16_user2nic: sys_vircopy failed",
1130
                    "dp_pio16_user2nic: sys_vircopy failed",
1128
                    r);
1131
                    r);
1129
            }
1132
            }
1130
            outw(dep->de_data_port, *(u16_t *)two_bytes);
1133
            outw(dep->de_data_port, *(u16_t *)two_bytes);
1131
            count--;
1134
            count--;
1132
            offset++;
1135
            offset++;
1133
            bytes--;
1136
            bytes--;
1134
            vir_user++;
1137
            vir_user++;
1135
            odd_byte= 0;
1138
            odd_byte= 0;
1136
            if (!bytes)
1139
            if (!bytes)
1137
                continue;
1140
                continue;
1138
        }
1141
        }
1139
        ecount= bytes & ~1;
1142
        ecount= bytes & ~1;
1140
        if (ecount != 0)
1143
        if (ecount != 0)
1141
        {
1144
        {
1142
            do_vir_outsw(dep->de_data_port, user_proc, vir_user,
1145
            do_vir_outsw(dep->de_data_port, user_proc, vir_user,
1143
                ecount);
1146
                ecount);
1144
            count -= ecount;
1147
            count -= ecount;
1145
            offset += ecount;
1148
            offset += ecount;
1146
            bytes -= ecount;
1149
            bytes -= ecount;
1147
            vir_user += ecount;
1150
            vir_user += ecount;
1148
        }
1151
        }
1149
        if (bytes)
1152
        if (bytes)
1150
        {
1153
        {
1151
            assert(bytes == 1);
1154
            assert(bytes == 1);
1152
            r= sys_vircopy(user_proc, D, vir_user,
1155
            r= sys_vircopy(user_proc, D, vir_user,
1153
                SELF, D, (vir_bytes)&two_bytes[0], 1);
1156
                SELF, D, (vir_bytes)&two_bytes[0], 1);
1154
            if (r != OK)
1157
            if (r != OK)
1155
            {
1158
            {
1156
                panic("DP8390",
1159
                panic("DP8390",
1157
                    "dp_pio16_user2nic: sys_vircopy failed",
1160
                    "dp_pio16_user2nic: sys_vircopy failed",
1158
                    r);
1161
                    r);
1159
            }
1162
            }
1160
            count--;
1163
            count--;
1161
            offset++;
1164
            offset++;
1162
            bytes--;
1165
            bytes--;
1163
            vir_user++;
1166
            vir_user++;
1164
            odd_byte= 1;
1167
            odd_byte= 1;
1165
        }
1168
        }
1166
    }
1169
    }
1167
    assert(count == 0);
1170
    assert(count == 0);
1168
 
1171
 
1169
    if (odd_byte)
1172
    if (odd_byte)
1170
        outw(dep->de_data_port, *(u16_t *)two_bytes);
1173
        outw(dep->de_data_port, *(u16_t *)two_bytes);
1171
 
1174
 
1172
    for (i= 0; i<100; i++)
1175
    for (i= 0; i<100; i++)
1173
    {
1176
    {
1174
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
1177
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
1175
            break;
1178
            break;
1176
    }
1179
    }
1177
    if (i == 100)
1180
    if (i == 100)
1178
    {
1181
    {
1179
        panic("", "dp8390: remote dma failed to complete", NO_NUM);
1182
        panic("", "dp8390: remote dma failed to complete", NO_NUM);
1180
    }
1183
    }
1181
}
1184
}
1182
 
1185
 
1183
/*===========================================================================*
1186
/*===========================================================================*
1184
 *              dp_nic2user                  *
1187
 *              dp_nic2user                  *
1185
 *===========================================================================*/
1188
 *===========================================================================*/
1186
static void dp_nic2user(dep, nic_addr, iovp, offset, count)
1189
static void dp_nic2user(dep, nic_addr, iovp, offset, count)
1187
dpeth_t *dep;
1190
dpeth_t *dep;
1188
int nic_addr;
1191
int nic_addr;
1189
iovec_dat_t *iovp;
1192
iovec_dat_t *iovp;
1190
vir_bytes offset;
1193
vir_bytes offset;
1191
vir_bytes count;
1194
vir_bytes count;
1192
{
1195
{
1193
    vir_bytes vir_hw;//, vir_user;
1196
    vir_bytes vir_hw;//, vir_user;
1194
    int bytes, i, r;
1197
    int bytes, i, r;
1195
 
1198
 
1196
    vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
1199
    vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
1197
 
1200
 
1198
    i= 0;
1201
    i= 0;
1199
    while (count > 0)
1202
    while (count > 0)
1200
    {
1203
    {
1201
        if (i >= IOVEC_NR)
1204
        if (i >= IOVEC_NR)
1202
        {
1205
        {
1203
            dp_next_iovec(iovp);
1206
            dp_next_iovec(iovp);
1204
            i= 0;
1207
            i= 0;
1205
            continue;
1208
            continue;
1206
        }
1209
        }
1207
        assert(i < iovp->iod_iovec_s);
1210
        assert(i < iovp->iod_iovec_s);
1208
        if (offset >= iovp->iod_iovec[i].iov_size)
1211
        if (offset >= iovp->iod_iovec[i].iov_size)
1209
        {
1212
        {
1210
            offset -= iovp->iod_iovec[i].iov_size;
1213
            offset -= iovp->iod_iovec[i].iov_size;
1211
            i++;
1214
            i++;
1212
            continue;
1215
            continue;
1213
        }
1216
        }
1214
        bytes = iovp->iod_iovec[i].iov_size - offset;
1217
        bytes = iovp->iod_iovec[i].iov_size - offset;
1215
        if (bytes > count)
1218
        if (bytes > count)
1216
            bytes = count;
1219
            bytes = count;
1217
 
1220
 
1218
        r= sys_vircopy(SELF, D, vir_hw,
1221
        r= sys_vircopy(SELF, D, vir_hw,
1219
            iovp->iod_proc_nr, D,
1222
            iovp->iod_proc_nr, D,
1220
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1223
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1221
        if (r != OK)
1224
        if (r != OK)
1222
            panic("DP8390", "dp_nic2user: sys_vircopy failed", r);
1225
            panic("DP8390", "dp_nic2user: sys_vircopy failed", r);
1223
 
1226
 
1224
        count -= bytes;
1227
        count -= bytes;
1225
        vir_hw += bytes;
1228
        vir_hw += bytes;
1226
        offset += bytes;
1229
        offset += bytes;
1227
    }
1230
    }
1228
    assert(count == 0);
1231
    assert(count == 0);
1229
}
1232
}
1230
 
1233
 
1231
/*===========================================================================*
1234
/*===========================================================================*
1232
 *              dp_pio8_nic2user                 *
1235
 *              dp_pio8_nic2user                 *
1233
 *===========================================================================*/
1236
 *===========================================================================*/
1234
static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count)
1237
static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count)
1235
dpeth_t *dep;
1238
dpeth_t *dep;
1236
int nic_addr;
1239
int nic_addr;
1237
iovec_dat_t *iovp;
1240
iovec_dat_t *iovp;
1238
vir_bytes offset;
1241
vir_bytes offset;
1239
vir_bytes count;
1242
vir_bytes count;
1240
{
1243
{
1241
//  phys_bytes phys_user;
1244
//  phys_bytes phys_user;
1242
    int bytes, i;
1245
    int bytes, i;
1243
 
1246
 
1244
    outb_reg0(dep, DP_RBCR0, count & 0xFF);
1247
    outb_reg0(dep, DP_RBCR0, count & 0xFF);
1245
    outb_reg0(dep, DP_RBCR1, count >> 8);
1248
    outb_reg0(dep, DP_RBCR1, count >> 8);
1246
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1249
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1247
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1250
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1248
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
1251
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
1249
 
1252
 
1250
    i= 0;
1253
    i= 0;
1251
    while (count > 0)
1254
    while (count > 0)
1252
    {
1255
    {
1253
        if (i >= IOVEC_NR)
1256
        if (i >= IOVEC_NR)
1254
        {
1257
        {
1255
            dp_next_iovec(iovp);
1258
            dp_next_iovec(iovp);
1256
            i= 0;
1259
            i= 0;
1257
            continue;
1260
            continue;
1258
        }
1261
        }
1259
        assert(i < iovp->iod_iovec_s);
1262
        assert(i < iovp->iod_iovec_s);
1260
        if (offset >= iovp->iod_iovec[i].iov_size)
1263
        if (offset >= iovp->iod_iovec[i].iov_size)
1261
        {
1264
        {
1262
            offset -= iovp->iod_iovec[i].iov_size;
1265
            offset -= iovp->iod_iovec[i].iov_size;
1263
            i++;
1266
            i++;
1264
            continue;
1267
            continue;
1265
        }
1268
        }
1266
        bytes = iovp->iod_iovec[i].iov_size - offset;
1269
        bytes = iovp->iod_iovec[i].iov_size - offset;
1267
        if (bytes > count)
1270
        if (bytes > count)
1268
            bytes = count;
1271
            bytes = count;
1269
 
1272
 
1270
        do_vir_insb(dep->de_data_port, iovp->iod_proc_nr,
1273
        do_vir_insb(dep->de_data_port, iovp->iod_proc_nr,
1271
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1274
            iovp->iod_iovec[i].iov_addr + offset, bytes);
1272
        count -= bytes;
1275
        count -= bytes;
1273
        offset += bytes;
1276
        offset += bytes;
1274
    }
1277
    }
1275
    assert(count == 0);
1278
    assert(count == 0);
1276
}
1279
}
1277
 
1280
 
1278
/*===========================================================================*
1281
/*===========================================================================*
1279
 *              dp_pio16_nic2user                *
1282
 *              dp_pio16_nic2user                *
1280
 *===========================================================================*/
1283
 *===========================================================================*/
1281
static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count)
1284
static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count)
1282
dpeth_t *dep;
1285
dpeth_t *dep;
1283
int nic_addr;
1286
int nic_addr;
1284
iovec_dat_t *iovp;
1287
iovec_dat_t *iovp;
1285
vir_bytes offset;
1288
vir_bytes offset;
1286
vir_bytes count;
1289
vir_bytes count;
1287
{
1290
{
1288
    vir_bytes vir_user;
1291
    vir_bytes vir_user;
1289
    vir_bytes ecount;
1292
    vir_bytes ecount;
1290
    int i, r, bytes, user_proc;
1293
    int i, r, bytes, user_proc;
1291
    u8_t two_bytes[2];
1294
    u8_t two_bytes[2];
1292
    int odd_byte;
1295
    int odd_byte;
1293
 
1296
 
1294
    ecount= (count+1) & ~1;
1297
    ecount= (count+1) & ~1;
1295
    odd_byte= 0;
1298
    odd_byte= 0;
1296
 
1299
 
1297
    outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
1300
    outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
1298
    outb_reg0(dep, DP_RBCR1, ecount >> 8);
1301
    outb_reg0(dep, DP_RBCR1, ecount >> 8);
1299
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1302
    outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
1300
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1303
    outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
1301
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
1304
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
1302
 
1305
 
1303
    i= 0;
1306
    i= 0;
1304
    while (count > 0)
1307
    while (count > 0)
1305
    {
1308
    {
1306
        if (i >= IOVEC_NR)
1309
        if (i >= IOVEC_NR)
1307
        {
1310
        {
1308
            dp_next_iovec(iovp);
1311
            dp_next_iovec(iovp);
1309
            i= 0;
1312
            i= 0;
1310
            continue;
1313
            continue;
1311
        }
1314
        }
1312
        assert(i < iovp->iod_iovec_s);
1315
        assert(i < iovp->iod_iovec_s);
1313
        if (offset >= iovp->iod_iovec[i].iov_size)
1316
        if (offset >= iovp->iod_iovec[i].iov_size)
1314
        {
1317
        {
1315
            offset -= iovp->iod_iovec[i].iov_size;
1318
            offset -= iovp->iod_iovec[i].iov_size;
1316
            i++;
1319
            i++;
1317
            continue;
1320
            continue;
1318
        }
1321
        }
1319
        bytes = iovp->iod_iovec[i].iov_size - offset;
1322
        bytes = iovp->iod_iovec[i].iov_size - offset;
1320
        if (bytes > count)
1323
        if (bytes > count)
1321
            bytes = count;
1324
            bytes = count;
1322
 
1325
 
1323
        user_proc= iovp->iod_proc_nr;
1326
        user_proc= iovp->iod_proc_nr;
1324
        vir_user= iovp->iod_iovec[i].iov_addr + offset;
1327
        vir_user= iovp->iod_iovec[i].iov_addr + offset;
1325
        if (odd_byte)
1328
        if (odd_byte)
1326
        {
1329
        {
1327
            r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1],
1330
            r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1],
1328
                user_proc, D, vir_user,  1);
1331
                user_proc, D, vir_user,  1);
1329
            if (r != OK)
1332
            if (r != OK)
1330
            {
1333
            {
1331
                panic("DP8390",
1334
                panic("DP8390",
1332
                    "dp_pio16_nic2user: sys_vircopy failed",
1335
                    "dp_pio16_nic2user: sys_vircopy failed",
1333
                    r);
1336
                    r);
1334
            }
1337
            }
1335
            count--;
1338
            count--;
1336
            offset++;
1339
            offset++;
1337
            bytes--;
1340
            bytes--;
1338
            vir_user++;
1341
            vir_user++;
1339
            odd_byte= 0;
1342
            odd_byte= 0;
1340
            if (!bytes)
1343
            if (!bytes)
1341
                continue;
1344
                continue;
1342
        }
1345
        }
1343
        ecount= bytes & ~1;
1346
        ecount= bytes & ~1;
1344
        if (ecount != 0)
1347
        if (ecount != 0)
1345
        {
1348
        {
1346
            do_vir_insw(dep->de_data_port, user_proc, vir_user,
1349
            do_vir_insw(dep->de_data_port, user_proc, vir_user,
1347
                ecount);
1350
                ecount);
1348
            count -= ecount;
1351
            count -= ecount;
1349
            offset += ecount;
1352
            offset += ecount;
1350
            bytes -= ecount;
1353
            bytes -= ecount;
1351
            vir_user += ecount;
1354
            vir_user += ecount;
1352
        }
1355
        }
1353
        if (bytes)
1356
        if (bytes)
1354
        {
1357
        {
1355
            assert(bytes == 1);
1358
            assert(bytes == 1);
1356
            *(u16_t *)two_bytes= inw(dep->de_data_port);
1359
            *(u16_t *)two_bytes= inw(dep->de_data_port);
1357
            r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0],
1360
            r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0],
1358
                user_proc, D, vir_user,  1);
1361
                user_proc, D, vir_user,  1);
1359
            if (r != OK)
1362
            if (r != OK)
1360
            {
1363
            {
1361
                panic("DP8390",
1364
                panic("DP8390",
1362
                    "dp_pio16_nic2user: sys_vircopy failed",
1365
                    "dp_pio16_nic2user: sys_vircopy failed",
1363
                    r);
1366
                    r);
1364
            }
1367
            }
1365
            count--;
1368
            count--;
1366
            offset++;
1369
            offset++;
1367
            bytes--;
1370
            bytes--;
1368
            vir_user++;
1371
            vir_user++;
1369
            odd_byte= 1;
1372
            odd_byte= 1;
1370
        }
1373
        }
1371
    }
1374
    }
1372
    assert(count == 0);
1375
    assert(count == 0);
1373
}
1376
}
1374
 
1377
 
1375
/*===========================================================================*
1378
/*===========================================================================*
1376
 *              dp_next_iovec                    *
1379
 *              dp_next_iovec                    *
1377
 *===========================================================================*/
1380
 *===========================================================================*/
1378
static void dp_next_iovec(iovp)
1381
static void dp_next_iovec(iovp)
1379
iovec_dat_t *iovp;
1382
iovec_dat_t *iovp;
1380
{
1383
{
1381
    assert(iovp->iod_iovec_s > IOVEC_NR);
1384
    assert(iovp->iod_iovec_s > IOVEC_NR);
1382
 
1385
 
1383
    iovp->iod_iovec_s -= IOVEC_NR;
1386
    iovp->iod_iovec_s -= IOVEC_NR;
1384
 
1387
 
1385
    iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t);
1388
    iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t);
1386
 
1389
 
1387
    get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr,
1390
    get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr,
1388
        (iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
1391
        (iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
1389
        sizeof(iovec_t), iovp->iod_iovec);
1392
        sizeof(iovec_t), iovp->iod_iovec);
1390
}
1393
}
1391
 
1394
 
1392
/*===========================================================================*
1395
/*===========================================================================*
1393
 *              conf_hw                      *
1396
 *              conf_hw                      *
1394
 *===========================================================================*/
1397
 *===========================================================================*/
1395
static void conf_hw(dep)
1398
static void conf_hw(dep)
1396
dpeth_t *dep;
1399
dpeth_t *dep;
1397
{
1400
{
1398
//  static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0    /* ,... */ };
1401
//  static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0    /* ,... */ };
1399
 
1402
 
1400
//  int ifnr;
1403
//  int ifnr;
1401
//  dp_conf_t *dcp;
1404
//  dp_conf_t *dcp;
1402
 
1405
 
1403
//  dep->de_mode= DEM_DISABLED; /* Superfluous */
1406
//  dep->de_mode= DEM_DISABLED; /* Superfluous */
1404
//  ifnr= dep-de_table;
1407
//  ifnr= dep-de_table;
1405
 
1408
 
1406
//  dcp= &dp_conf[ifnr];
1409
//  dcp= &dp_conf[ifnr];
1407
//  update_conf(dep, dcp);
1410
//  update_conf(dep, dcp);
1408
//  if (dep->de_mode != DEM_ENABLED)
1411
//  if (dep->de_mode != DEM_ENABLED)
1409
//      return;
1412
//      return;
1410
    if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep))
1413
    if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep))
1411
    {
1414
    {
1412
        printf("%s: No ethernet card found at 0x%x\n",
1415
        printf("%s: No ethernet card found at 0x%x\n",
1413
            dep->de_name, dep->de_base_port);
1416
            dep->de_name, dep->de_base_port);
1414
        dep->de_mode= DEM_DISABLED;
1417
        dep->de_mode= DEM_DISABLED;
1415
        return;
1418
        return;
1416
    }
1419
    }
1417
 
1420
 
1418
/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
1421
/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
1419
 
1422
 
1420
    dep->de_mode = DEM_ENABLED;
1423
    dep->de_mode = DEM_ENABLED;
1421
 
1424
 
1422
    dep->de_flags = DEF_EMPTY;
1425
    dep->de_flags = DEF_EMPTY;
1423
//  dep->de_stat = empty_stat;
1426
//  dep->de_stat = empty_stat;
1424
}
1427
}
1425
 
1428
 
1426
/*===========================================================================*
1429
/*===========================================================================*
1427
 *              map_hw_buffer                    *
1430
 *              map_hw_buffer                    *
1428
 *===========================================================================*/
1431
 *===========================================================================*/
1429
static void map_hw_buffer(dep)
1432
static void map_hw_buffer(dep)
1430
dpeth_t *dep;
1433
dpeth_t *dep;
1431
{
1434
{
1432
//  int r;
1435
//  int r;
1433
//  size_t o, size;
1436
//  size_t o, size;
1434
//  char *buf, *abuf;
1437
//  char *buf, *abuf;
1435
 
1438
 
1436
    if (dep->de_prog_IO)
1439
    if (dep->de_prog_IO)
1437
    {
1440
    {
1438
#if 0
1441
#if 0
1439
        if(debug){
1442
        if(debug){
1440
            printf(
1443
            printf(
1441
            "map_hw_buffer: programmed I/O, no need to map buffer\n");
1444
            "map_hw_buffer: programmed I/O, no need to map buffer\n");
1442
        }
1445
        }
1443
#endif
1446
#endif
1444
        dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */
1447
        dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */
1445
        return;
1448
        return;
1446
    }else{
1449
    }else{
1447
        printf( "map_hw_buffer: no buffer!" );
1450
        printf( "map_hw_buffer: no buffer!" );
1448
    }
1451
    }
1449
 
1452
 
1450
//  size = dep->de_ramsize + PAGE_SIZE; /* Add PAGE_SIZE for
1453
//  size = dep->de_ramsize + PAGE_SIZE; /* Add PAGE_SIZE for
1451
//                       * alignment
1454
//                       * alignment
1452
//                       */
1455
//                       */
1453
//  buf= malloc(size);
1456
//  buf= malloc(size);
1454
//  if (buf == NULL)
1457
//  if (buf == NULL)
1455
//      panic(__FILE__, "map_hw_buffer: cannot malloc size", size);
1458
//      panic(__FILE__, "map_hw_buffer: cannot malloc size", size);
1456
//  o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE);
1459
//  o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE);
1457
//  abuf= buf + o;
1460
//  abuf= buf + o;
1458
//  printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf);
1461
//  printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf);
1459
 
1462
 
1460
//  r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf,
1463
//  r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf,
1461
//          dep->de_ramsize, (phys_bytes)dep->de_linmem);
1464
//          dep->de_ramsize, (phys_bytes)dep->de_linmem);
1462
//  if (r != OK)
1465
//  if (r != OK)
1463
//      panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r);
1466
//      panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r);
1464
//  dep->de_locmem = abuf;
1467
//  dep->de_locmem = abuf;
1465
}
1468
}
1466
 
1469
 
1467
/*===========================================================================*
1470
/*===========================================================================*
1468
 *              reply                        *
1471
 *              reply                        *
1469
 *===========================================================================*/
1472
 *===========================================================================*/
1470
static void reply(dep, err, may_block)
1473
static void reply(dep, err, may_block)
1471
dpeth_t *dep;
1474
dpeth_t *dep;
1472
int err;
1475
int err;
1473
int may_block;
1476
int may_block;
1474
{
1477
{
1475
/*  message reply;
1478
/*  message reply;
1476
    int status;
1479
    int status;
1477
    int r;
1480
    int r;
1478
 
1481
 
1479
    status = 0;
1482
    status = 0;
1480
    if (dep->de_flags & DEF_PACK_SEND)
1483
    if (dep->de_flags & DEF_PACK_SEND)
1481
        status |= DL_PACK_SEND;
1484
        status |= DL_PACK_SEND;
1482
    if (dep->de_flags & DEF_PACK_RECV)
1485
    if (dep->de_flags & DEF_PACK_RECV)
1483
        status |= DL_PACK_RECV;
1486
        status |= DL_PACK_RECV;
1484
 
1487
 
1485
    reply.m_type = DL_TASK_REPLY;
1488
    reply.m_type = DL_TASK_REPLY;
1486
    reply.DL_PORT = dep - de_table;
1489
    reply.DL_PORT = dep - de_table;
1487
    reply.DL_PROC = dep->de_client;
1490
    reply.DL_PROC = dep->de_client;
1488
    reply.DL_STAT = status | ((u32_t) err << 16);
1491
    reply.DL_STAT = status | ((u32_t) err << 16);
1489
    reply.DL_COUNT = dep->de_read_s;
1492
    reply.DL_COUNT = dep->de_read_s;
1490
    reply.DL_CLCK = 0;  *//* Don't know */
1493
    reply.DL_CLCK = 0;  *//* Don't know */
1491
/*  r= send(dep->de_client, &reply);
1494
/*  r= send(dep->de_client, &reply);
1492
 
1495
 
1493
    if (r == ELOCKED && may_block)
1496
    if (r == ELOCKED && may_block)
1494
    {
1497
    {
1495
#if 0
1498
#if 0
1496
        printf("send locked\n");
1499
        printf("send locked\n");
1497
#endif
1500
#endif
1498
        return;
1501
        return;
1499
    }
1502
    }
1500
 
1503
 
1501
    if (r < 0)
1504
    if (r < 0)
1502
        panic("", "dp8390: send failed:", r);
1505
        panic("", "dp8390: send failed:", r);
1503
   
1506
   
1504
    dep->de_read_s = 0;
1507
    dep->de_read_s = 0;
1505
*/  dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV);
1508
*/  dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV);
1506
}
1509
}
1507
 
1510
 
1508
/*===========================================================================*
1511
/*===========================================================================*
1509
 *              get_userdata                     *
1512
 *              get_userdata                     *
1510
 *===========================================================================*/
1513
 *===========================================================================*/
1511
static void get_userdata(user_proc, user_addr, count, loc_addr)
1514
static void get_userdata(user_proc, user_addr, count, loc_addr)
1512
int user_proc;
1515
int user_proc;
1513
vir_bytes user_addr;
1516
vir_bytes user_addr;
1514
vir_bytes count;
1517
vir_bytes count;
1515
void *loc_addr;
1518
void *loc_addr;
1516
{
1519
{
1517
    int r;
1520
    int r;
1518
 
1521
 
1519
    r= sys_vircopy(user_proc, D, user_addr,
1522
    r= sys_vircopy(user_proc, D, user_addr,
1520
        SELF, D, (vir_bytes)loc_addr, count);
1523
        SELF, D, (vir_bytes)loc_addr, count);
1521
    if (r != OK)
1524
    if (r != OK)
1522
        panic("DP8390", "get_userdata: sys_vircopy failed", r);
1525
        panic("DP8390", "get_userdata: sys_vircopy failed", r);
1523
}
1526
}
1524
 
1527
 
1525
static void insb(port_t port, void *buf, size_t size)
1528
static void insb(port_t port, void *buf, size_t size)
1526
{
1529
{
1527
    size_t i;
1530
    size_t i;
1528
 
1531
 
1529
    for( i = 0; i < size; ++ i ){
1532
    for( i = 0; i < size; ++ i ){
1530
        *(( uint8_t * )( buf + i )) = inb( port );
1533
        *(( uint8_t * )( buf + i )) = inb( port );
1531
    }
1534
    }
1532
}
1535
}
1533
 
1536
 
1534
static void insw(port_t port, void *buf, size_t size)
1537
static void insw(port_t port, void *buf, size_t size)
1535
{
1538
{
1536
    size_t i;
1539
    size_t i;
1537
 
1540
 
1538
    for( i = 0; i < size; i += 2 ){
1541
    for( i = 0; i < size; i += 2 ){
1539
        *(( uint16_t * )( buf + i )) = inw( port );
1542
        *(( uint16_t * )( buf + i )) = inw( port );
1540
    }
1543
    }
1541
}
1544
}
1542
 
1545
 
1543
static void outsb(port_t port, void *buf, size_t size)
1546
static void outsb(port_t port, void *buf, size_t size)
1544
{
1547
{
1545
    size_t i;
1548
    size_t i;
1546
 
1549
 
1547
    for( i = 0; i < size; ++ i ){
1550
    for( i = 0; i < size; ++ i ){
1548
        outb( port, *(( uint8_t * )( buf + i )));
1551
        outb( port, *(( uint8_t * )( buf + i )));
1549
    }
1552
    }
1550
}
1553
}
1551
 
1554
 
1552
static void outsw(port_t port, void *buf, size_t size)
1555
static void outsw(port_t port, void *buf, size_t size)
1553
{
1556
{
1554
    size_t i;
1557
    size_t i;
1555
 
1558
 
1556
    for( i = 0; i < size; i += 2 ){
1559
    for( i = 0; i < size; i += 2 ){
1557
        outw( port, *(( uint16_t * )( buf + i )));
1560
        outw( port, *(( uint16_t * )( buf + i )));
1558
    }
1561
    }
1559
}
1562
}
1560
 
1563
 
1561
/*
1564
/*
1562
 * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $
1565
 * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $
1563
 */
1566
 */
1564
 
1567
 
1565
/** @}
1568
/** @}
1566
 */
1569
 */
1567
 
1570