Subversion Repositories HelenOS

Rev

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

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