Subversion Repositories HelenOS

Rev

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

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