Subversion Repositories HelenOS

Rev

Rev 4723 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4723 Rev 4756
1
/*
1
/*
2
 * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2
 * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
 *
3
 *
4
 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4
 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
5
 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6
 * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
6
 * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7
 * * Any deviations from these conditions require written permission from the copyright holder in advance
7
 * * Any deviations from these conditions require written permission from the copyright holder in advance
8
 *
8
 *
9
 *
9
 *
10
 * Disclaimer
10
 * Disclaimer
11
 *
11
 *
12
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
12
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
13
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
13
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
 *
22
 *
23
 * Changes:
23
 * Changes:
24
 *  2009 Lukas Mejdrech ported to HelenOS
24
 *  2009 ported to HelenOS, Lukas Mejdrech
25
 */
25
 */
26
 
26
 
27
/** @addtogroup ne2k
27
/** @addtogroup ne2k
28
 *  @{
28
 *  @{
29
 */
29
 */
30
 
30
 
31
/** @file
31
/** @file
32
 *  \todo
32
 *  NE1000 and NE2000 network interface initialization and probe functions implementation.
33
 */
33
 */
34
 
34
 
35
#include <stdio.h>
35
#include <stdio.h>
36
#include <unistd.h>
36
#include <unistd.h>
37
 
37
 
38
#include "dp8390_port.h"
38
#include "dp8390_port.h"
39
 
39
 
40
/*
40
/*
41
ne2000.c
41
ne2000.c
42
 
42
 
43
Driver for the ne2000 ethernet cards. This file contains only the ne2000
43
Driver for the ne2000 ethernet cards. This file contains only the ne2000
44
specific code, the rest is in dp8390.c
44
specific code, the rest is in dp8390.c
45
 
45
 
46
Created:    March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
46
Created:    March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
47
*/
47
*/
48
 
48
 
49
//#include "../drivers.h"
49
//#include "../drivers.h"
50
 
50
 
51
//#include <net/gen/ether.h>
51
//#include <net/gen/ether.h>
52
//#include <net/gen/eth_io.h>
52
//#include <net/gen/eth_io.h>
53
//#if __minix_vmd
53
//#if __minix_vmd
54
//#include "config.h"
54
//#include "config.h"
55
//#endif
55
//#endif
56
 
56
 
57
#include "local.h"
57
#include "local.h"
58
#include "dp8390.h"
58
#include "dp8390.h"
59
#include "ne2000.h"
59
#include "ne2000.h"
60
 
60
 
61
#if ENABLE_NE2000
61
#if ENABLE_NE2000
62
 
62
 
-
 
63
/** Number of bytes to transfer.
-
 
64
 */
63
#define N 100
65
#define N 100
64
 
66
 
65
//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
67
//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
66
 
68
 
-
 
69
/** Sleeps for the defined millicesonds.
-
 
70
 *  @param[in] millis The number of milliseconds to sleep.
-
 
71
 */
-
 
72
#define milli_delay( millis )   usleep(( millis ) * 1000 )
-
 
73
 
-
 
74
/** Type definition of the testing function.
-
 
75
 */
67
_PROTOTYPE( typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)  );
76
_PROTOTYPE( typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)  );
68
 
77
 
-
 
78
/** First data pattern.
-
 
79
 */
69
u8_t    pat0[]= { 0x00, 0x00, 0x00, 0x00 };
80
u8_t    pat0[]= { 0x00, 0x00, 0x00, 0x00 };
-
 
81
 
-
 
82
/** Second data pattern.
-
 
83
 */
70
u8_t    pat1[]= { 0xFF, 0xFF, 0xFF, 0xFF };
84
u8_t    pat1[]= { 0xFF, 0xFF, 0xFF, 0xFF };
-
 
85
 
-
 
86
/** Third data pattern.
-
 
87
 */
71
u8_t    pat2[]= { 0xA5, 0x5A, 0x69, 0x96 };
88
u8_t    pat2[]= { 0xA5, 0x5A, 0x69, 0x96 };
-
 
89
 
-
 
90
/** Fourth data pattern.
-
 
91
 */
72
u8_t    pat3[]= { 0x96, 0x69, 0x5A, 0xA5 };
92
u8_t    pat3[]= { 0x96, 0x69, 0x5A, 0xA5 };
73
 
93
 
-
 
94
/** Tests 8 bit NE2000 network interface.
74
_PROTOTYPE( static int test_8, (dpeth_t *dep, int pos, u8_t *pat)   );
95
 *  @param[in,out] dep The network interface structure.
75
_PROTOTYPE( static int test_16, (dpeth_t *dep, int pos, u8_t *pat)  );
96
 *  @param[in] pos The starting position.
76
_PROTOTYPE( static void ne_stop, (dpeth_t *dep)             );
97
 *  @param[in] pat The data pattern to be written.
-
 
98
 *  @returns True on success.
-
 
99
 *  @returns FALSE otherwise.
-
 
100
 */
77
//_PROTOTYPE( static void milli_delay, (unsigned long millis)       );
101
static int test_8(dpeth_t *dep, int pos, u8_t *pat);
78
 
102
 
-
 
103
/** Tests 16 bit NE2000 network interface.
-
 
104
 *  @param[in,out] dep The network interface structure.
-
 
105
 *  @param[in] pos The starting position.
-
 
106
 *  @param[in] pat The data pattern to be written.
-
 
107
 *  @returns True on success.
-
 
108
 *  @returns FALSE otherwise.
-
 
109
 */
79
#define milli_delay( millis )   usleep(( millis ) * 1000 )
110
static int test_16(dpeth_t *dep, int pos, u8_t *pat);
80
 
111
 
-
 
112
/** Stops the NE2000 network interface.
-
 
113
 *  @param[in,out] dep The network interface structure.
-
 
114
 */
-
 
115
static void ne_stop(dpeth_t *dep);
-
 
116
//_PROTOTYPE( static void milli_delay, (unsigned long millis)       );
-
 
117
 
-
 
118
/** Initializes the NE2000 network interface.
-
 
119
 *  @param[in,out] dep The network interface structure.
-
 
120
 */
81
_PROTOTYPE( void ne_init, (struct dpeth *dep)               );
121
void ne_init(struct dpeth *dep);
82
 
122
 
83
/*===========================================================================*
123
/*===========================================================================*
84
 *              ne_probe                     *
124
 *              ne_probe                     *
85
 *===========================================================================*/
125
 *===========================================================================*/
86
int ne_probe(dep)
126
int ne_probe(dep)
87
dpeth_t *dep;
127
dpeth_t *dep;
88
{
128
{
89
    int byte;
129
    int byte;
90
    int i;
130
    int i;
91
    int loc1, loc2;
131
    int loc1, loc2;
92
    testf_t f;
132
    testf_t f;
93
 
133
 
94
    dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
134
    dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
95
 
135
 
96
    /* We probe for an ne1000 or an ne2000 by testing whether the
136
    /* We probe for an ne1000 or an ne2000 by testing whether the
97
     * on board is reachable through the dp8390. Note that the
137
     * on board is reachable through the dp8390. Note that the
98
     * ne1000 is an 8bit card and has a memory region distict from
138
     * ne1000 is an 8bit card and has a memory region distict from
99
     * the 16bit ne2000
139
     * the 16bit ne2000
100
     */
140
     */
101
 
141
 
102
    for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
142
    for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
103
    {
143
    {
104
        /* Reset the ethernet card */
144
        /* Reset the ethernet card */
105
        byte= inb_ne(dep, NE_RESET);
145
        byte= inb_ne(dep, NE_RESET);
106
        milli_delay(2);
146
        milli_delay(2);
107
        outb_ne(dep, NE_RESET, byte);
147
        outb_ne(dep, NE_RESET, byte);
108
        milli_delay(2);
148
        milli_delay(2);
109
 
149
 
110
        /* Reset the dp8390 */
150
        /* Reset the dp8390 */
111
        outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
151
        outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
112
        for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
152
        for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
113
            ; /* Do nothing */
153
            ; /* Do nothing */
114
 
154
 
115
        /* Check if the dp8390 is really there */
155
        /* Check if the dp8390 is really there */
116
        if ((inb_reg0(dep, DP_CR) & (CR_STP|CR_DM_ABORT)) !=
156
        if ((inb_reg0(dep, DP_CR) & (CR_STP|CR_DM_ABORT)) !=
117
            (CR_STP|CR_DM_ABORT))
157
            (CR_STP|CR_DM_ABORT))
118
        {
158
        {
119
            return 0;
159
            return 0;
120
        }
160
        }
121
 
161
 
122
        /* Disable the receiver and init TCR and DCR. */
162
        /* Disable the receiver and init TCR and DCR. */
123
        outb_reg0(dep, DP_RCR, RCR_MON);
163
        outb_reg0(dep, DP_RCR, RCR_MON);
124
        outb_reg0(dep, DP_TCR, TCR_NORMAL);
164
        outb_reg0(dep, DP_TCR, TCR_NORMAL);
125
        if (dep->de_16bit)
165
        if (dep->de_16bit)
126
        {
166
        {
127
            outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
167
            outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
128
                DCR_BMS);
168
                DCR_BMS);
129
        }
169
        }
130
        else
170
        else
131
        {
171
        {
132
            outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
172
            outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
133
                DCR_BMS);
173
                DCR_BMS);
134
        }
174
        }
135
 
175
 
136
        if (dep->de_16bit)
176
        if (dep->de_16bit)
137
        {
177
        {
138
            loc1= NE2000_START;
178
            loc1= NE2000_START;
139
            loc2= NE2000_START + NE2000_SIZE - 4;
179
            loc2= NE2000_START + NE2000_SIZE - 4;
140
            f= test_16;
180
            f= test_16;
141
        }
181
        }
142
        else
182
        else
143
        {
183
        {
144
            loc1= NE1000_START;
184
            loc1= NE1000_START;
145
            loc2= NE1000_START + NE1000_SIZE - 4;
185
            loc2= NE1000_START + NE1000_SIZE - 4;
146
            f= test_8;
186
            f= test_8;
147
        }
187
        }
148
        if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
188
        if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
149
            f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
189
            f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
150
            f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
190
            f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
151
            f(dep, loc2, pat2) && f(dep, loc2, pat3))
191
            f(dep, loc2, pat2) && f(dep, loc2, pat3))
152
        {
192
        {
153
            /* We don't need a memory segment */
193
            /* We don't need a memory segment */
154
            dep->de_linmem= 0;
194
            dep->de_linmem= 0;
155
            if (!dep->de_pci)
195
            if (!dep->de_pci)
156
                dep->de_initf= ne_init;
196
                dep->de_initf= ne_init;
157
            dep->de_stopf= ne_stop;
197
            dep->de_stopf= ne_stop;
158
            dep->de_prog_IO= 1;
198
            dep->de_prog_IO= 1;
159
            return 1;
199
            return 1;
160
        }
200
        }
161
    }
201
    }
162
    return 0;
202
    return 0;
163
}
203
}
164
 
204
 
165
/*===========================================================================*
205
/*===========================================================================*
166
 *              ne_init                      *
206
 *              ne_init                      *
167
 *===========================================================================*/
207
 *===========================================================================*/
168
void ne_init(dep)
208
void ne_init(dep)
169
dpeth_t *dep;
209
dpeth_t *dep;
170
{
210
{
171
    int i;
211
    int i;
172
    int word, sendq_nr;
212
    int word, sendq_nr;
173
 
213
 
174
    /* Setup a transfer to get the ethernet address. */
214
    /* Setup a transfer to get the ethernet address. */
175
    if (dep->de_16bit)
215
    if (dep->de_16bit)
176
        outb_reg0(dep, DP_RBCR0, 6*2);
216
        outb_reg0(dep, DP_RBCR0, 6*2);
177
    else
217
    else
178
        outb_reg0(dep, DP_RBCR0, 6);
218
        outb_reg0(dep, DP_RBCR0, 6);
179
    outb_reg0(dep, DP_RBCR1, 0);
219
    outb_reg0(dep, DP_RBCR1, 0);
180
    outb_reg0(dep, DP_RSAR0, 0);
220
    outb_reg0(dep, DP_RSAR0, 0);
181
    outb_reg0(dep, DP_RSAR1, 0);
221
    outb_reg0(dep, DP_RSAR1, 0);
182
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
222
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
183
 
223
 
184
    for (i= 0; i<6; i++)
224
    for (i= 0; i<6; i++)
185
    {
225
    {
186
        if (dep->de_16bit)
226
        if (dep->de_16bit)
187
        {
227
        {
188
            word= inw_ne(dep, NE_DATA);
228
            word= inw_ne(dep, NE_DATA);
189
            dep->de_address.ea_addr[i]= word;
229
            dep->de_address.ea_addr[i]= word;
190
        }
230
        }
191
        else
231
        else
192
        {
232
        {
193
            dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
233
            dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
194
        }
234
        }
195
    }
235
    }
196
    dep->de_data_port= dep->de_base_port + NE_DATA;
236
    dep->de_data_port= dep->de_base_port + NE_DATA;
197
    if (dep->de_16bit)
237
    if (dep->de_16bit)
198
    {
238
    {
199
        dep->de_ramsize= NE2000_SIZE;
239
        dep->de_ramsize= NE2000_SIZE;
200
        dep->de_offset_page= NE2000_START / DP_PAGESIZE;
240
        dep->de_offset_page= NE2000_START / DP_PAGESIZE;
201
    }
241
    }
202
    else
242
    else
203
    {
243
    {
204
        dep->de_ramsize= NE1000_SIZE;
244
        dep->de_ramsize= NE1000_SIZE;
205
        dep->de_offset_page= NE1000_START / DP_PAGESIZE;
245
        dep->de_offset_page= NE1000_START / DP_PAGESIZE;
206
    }
246
    }
207
 
247
 
208
    /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
248
    /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
209
    sendq_nr= dep->de_ramsize / 0x2000;
249
    sendq_nr= dep->de_ramsize / 0x2000;
210
    if (sendq_nr < 1)
250
    if (sendq_nr < 1)
211
        sendq_nr= 1;
251
        sendq_nr= 1;
212
    else if (sendq_nr > SENDQ_NR)
252
    else if (sendq_nr > SENDQ_NR)
213
        sendq_nr= SENDQ_NR;
253
        sendq_nr= SENDQ_NR;
214
    dep->de_sendq_nr= sendq_nr;
254
    dep->de_sendq_nr= sendq_nr;
215
    for (i= 0; i<sendq_nr; i++)
255
    for (i= 0; i<sendq_nr; i++)
216
    {
256
    {
217
        dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
257
        dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
218
            i*SENDQ_PAGES; 
258
            i*SENDQ_PAGES; 
219
    }
259
    }
220
 
260
 
221
    dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
261
    dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
222
    dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
262
    dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
223
 
263
 
224
    /* Can't override the default IRQ. */
264
    /* Can't override the default IRQ. */
225
    dep->de_irq &= ~DEI_DEFAULT;
265
    dep->de_irq &= ~DEI_DEFAULT;
226
 
266
 
227
    if (!debug)
267
    if (!debug)
228
    {
268
    {
229
        printf("%s: NE%d000 at %X:%d\n",
269
        printf("%s: NE%d000 at %X:%d\n",
230
            dep->de_name, dep->de_16bit ? 2 : 1,
270
            dep->de_name, dep->de_16bit ? 2 : 1,
231
            dep->de_base_port, dep->de_irq);
271
            dep->de_base_port, dep->de_irq);
232
    }
272
    }
233
    else
273
    else
234
    {
274
    {
235
        printf("%s: Novell NE%d000 ethernet card at I/O address "
275
        printf("%s: Novell NE%d000 ethernet card at I/O address "
236
            "0x%X, memory size 0x%X, irq %d\n",
276
            "0x%X, memory size 0x%X, irq %d\n",
237
            dep->de_name, dep->de_16bit ? 2 : 1,
277
            dep->de_name, dep->de_16bit ? 2 : 1,
238
            dep->de_base_port, dep->de_ramsize, dep->de_irq);
278
            dep->de_base_port, dep->de_ramsize, dep->de_irq);
239
    }
279
    }
240
}
280
}
241
 
281
 
242
/*===========================================================================*
282
/*===========================================================================*
243
 *              test_8                       *
283
 *              test_8                       *
244
 *===========================================================================*/
284
 *===========================================================================*/
245
static int test_8(dep, pos, pat)
285
static int test_8(dep, pos, pat)
246
dpeth_t *dep;
286
dpeth_t *dep;
247
int pos;
287
int pos;
248
u8_t *pat;
288
u8_t *pat;
249
{
289
{
250
    u8_t buf[4];
290
    u8_t buf[4];
251
    int i;
291
    int i;
252
    int r;
292
    int r;
253
 
293
 
254
    outb_reg0(dep, DP_ISR, 0xFF);
294
    outb_reg0(dep, DP_ISR, 0xFF);
255
 
295
 
256
    /* Setup a transfer to put the pattern. */
296
    /* Setup a transfer to put the pattern. */
257
    outb_reg0(dep, DP_RBCR0, 4);
297
    outb_reg0(dep, DP_RBCR0, 4);
258
    outb_reg0(dep, DP_RBCR1, 0);
298
    outb_reg0(dep, DP_RBCR1, 0);
259
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
299
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
260
    outb_reg0(dep, DP_RSAR1, pos >> 8);
300
    outb_reg0(dep, DP_RSAR1, pos >> 8);
261
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
301
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
262
 
302
 
263
    for (i= 0; i<4; i++)
303
    for (i= 0; i<4; i++)
264
        outb_ne(dep, NE_DATA, pat[i]);
304
        outb_ne(dep, NE_DATA, pat[i]);
265
 
305
 
266
    for (i= 0; i<N; i++)
306
    for (i= 0; i<N; i++)
267
    {
307
    {
268
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
308
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
269
            break;
309
            break;
270
    }
310
    }
271
    if (i == N)
311
    if (i == N)
272
    {
312
    {
273
        if (debug)
313
        if (debug)
274
        {
314
        {
275
            printf("%s: NE1000 remote DMA test failed\n",
315
            printf("%s: NE1000 remote DMA test failed\n",
276
                dep->de_name);
316
                dep->de_name);
277
        }
317
        }
278
        return 0;
318
        return 0;
279
    }
319
    }
280
 
320
 
281
    outb_reg0(dep, DP_RBCR0, 4);
321
    outb_reg0(dep, DP_RBCR0, 4);
282
    outb_reg0(dep, DP_RBCR1, 0);
322
    outb_reg0(dep, DP_RBCR1, 0);
283
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
323
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
284
    outb_reg0(dep, DP_RSAR1, pos >> 8);
324
    outb_reg0(dep, DP_RSAR1, pos >> 8);
285
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
325
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
286
 
326
 
287
    for (i= 0; i<4; i++)
327
    for (i= 0; i<4; i++)
288
        buf[i]= inb_ne(dep, NE_DATA);
328
        buf[i]= inb_ne(dep, NE_DATA);
289
 
329
 
290
    r= (memcmp(buf, pat, 4) == 0);
330
    r= (memcmp(buf, pat, 4) == 0);
291
    return r;
331
    return r;
292
}
332
}
293
 
333
 
294
/*===========================================================================*
334
/*===========================================================================*
295
 *              test_16                      *
335
 *              test_16                      *
296
 *===========================================================================*/
336
 *===========================================================================*/
297
static int test_16(dep, pos, pat)
337
static int test_16(dep, pos, pat)
298
dpeth_t *dep;
338
dpeth_t *dep;
299
int pos;
339
int pos;
300
u8_t *pat;
340
u8_t *pat;
301
{
341
{
302
    u8_t buf[4];
342
    u8_t buf[4];
303
    int i;
343
    int i;
304
    int r;
344
    int r;
305
 
345
 
306
    outb_reg0(dep, DP_ISR, 0xFF);
346
    outb_reg0(dep, DP_ISR, 0xFF);
307
 
347
 
308
    /* Setup a transfer to put the pattern. */
348
    /* Setup a transfer to put the pattern. */
309
    outb_reg0(dep, DP_RBCR0, 4);
349
    outb_reg0(dep, DP_RBCR0, 4);
310
    outb_reg0(dep, DP_RBCR1, 0);
350
    outb_reg0(dep, DP_RBCR1, 0);
311
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
351
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
312
    outb_reg0(dep, DP_RSAR1, pos >> 8);
352
    outb_reg0(dep, DP_RSAR1, pos >> 8);
313
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
353
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
314
 
354
 
315
    for (i= 0; i<4; i += 2)
355
    for (i= 0; i<4; i += 2)
316
    {
356
    {
317
        outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
357
        outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
318
    }
358
    }
319
 
359
 
320
    for (i= 0; i<N; i++)
360
    for (i= 0; i<N; i++)
321
    {
361
    {
322
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
362
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
323
            break;
363
            break;
324
    }
364
    }
325
    if (i == N)
365
    if (i == N)
326
    {
366
    {
327
        if (debug)
367
        if (debug)
328
        {
368
        {
329
            printf("%s: NE2000 remote DMA test failed\n",
369
            printf("%s: NE2000 remote DMA test failed\n",
330
                dep->de_name);
370
                dep->de_name);
331
        }
371
        }
332
        return 0;
372
        return 0;
333
    }
373
    }
334
 
374
 
335
    outb_reg0(dep, DP_RBCR0, 4);
375
    outb_reg0(dep, DP_RBCR0, 4);
336
    outb_reg0(dep, DP_RBCR1, 0);
376
    outb_reg0(dep, DP_RBCR1, 0);
337
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
377
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
338
    outb_reg0(dep, DP_RSAR1, pos >> 8);
378
    outb_reg0(dep, DP_RSAR1, pos >> 8);
339
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
379
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
340
 
380
 
341
    for (i= 0; i<4; i += 2)
381
    for (i= 0; i<4; i += 2)
342
    {
382
    {
343
        *(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
383
        *(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
344
    }
384
    }
345
 
385
 
346
    r= (memcmp(buf, pat, 4) == 0);
386
    r= (memcmp(buf, pat, 4) == 0);
347
    return r;
387
    return r;
348
}
388
}
349
 
389
 
350
/*===========================================================================*
390
/*===========================================================================*
351
 *              ne_stop                      *
391
 *              ne_stop                      *
352
 *===========================================================================*/
392
 *===========================================================================*/
353
static void ne_stop(dep)
393
static void ne_stop(dep)
354
dpeth_t *dep;
394
dpeth_t *dep;
355
{
395
{
356
    int byte;
396
    int byte;
357
 
397
 
358
    /* Reset the ethernet card */
398
    /* Reset the ethernet card */
359
    byte= inb_ne(dep, NE_RESET);
399
    byte= inb_ne(dep, NE_RESET);
360
    milli_delay(2);
400
    milli_delay(2);
361
    outb_ne(dep, NE_RESET, byte);
401
    outb_ne(dep, NE_RESET, byte);
362
}
402
}
363
/*
403
/*
364
static void milli_delay(unsigned long millis)
404
static void milli_delay(unsigned long millis)
365
{
405
{
366
    tickdelay(MILLIS_TO_TICKS(millis));
406
    tickdelay(MILLIS_TO_TICKS(millis));
367
}
407
}
368
*/
408
*/
369
#endif /* ENABLE_NE2000 */
409
#endif /* ENABLE_NE2000 */
370
 
410
 
371
/*
411
/*
372
 * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
412
 * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
373
 */
413
 */
374
 
414
 
375
/** @}
415
/** @}
376
 */
416
 */
377
 
417