Subversion Repositories HelenOS

Rev

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

Rev 4163 Rev 4350
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 ne2k
27
/** @addtogroup ne2k
28
 *  @{
28
 *  @{
29
 */
29
 */
-
 
30
 
-
 
31
/** @file
-
 
32
 *
-
 
33
 */
30
 
34
 
31
#include <stdio.h>
35
#include <stdio.h>
32
#include <unistd.h>
36
#include <unistd.h>
33
 
37
 
34
#include "dp8390_port.h"
38
#include "dp8390_port.h"
35
 
39
 
36
/*
40
/*
37
ne2000.c
41
ne2000.c
38
 
42
 
39
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
40
specific code, the rest is in dp8390.c
44
specific code, the rest is in dp8390.c
41
 
45
 
42
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>
43
*/
47
*/
44
 
48
 
45
//#include "../drivers.h"
49
//#include "../drivers.h"
46
 
50
 
47
//#include <net/gen/ether.h>
51
//#include <net/gen/ether.h>
48
//#include <net/gen/eth_io.h>
52
//#include <net/gen/eth_io.h>
49
//#if __minix_vmd
53
//#if __minix_vmd
50
//#include "config.h"
54
//#include "config.h"
51
//#endif
55
//#endif
52
 
56
 
53
#include "local.h"
57
#include "local.h"
54
#include "dp8390.h"
58
#include "dp8390.h"
55
#include "ne2000.h"
59
#include "ne2000.h"
56
 
60
 
57
#if ENABLE_NE2000
61
#if ENABLE_NE2000
58
 
62
 
59
#define N 100
63
#define N 100
60
 
64
 
61
//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
65
//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
62
 
66
 
63
_PROTOTYPE( typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)  );
67
_PROTOTYPE( typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)  );
64
 
68
 
65
u8_t    pat0[]= { 0x00, 0x00, 0x00, 0x00 };
69
u8_t    pat0[]= { 0x00, 0x00, 0x00, 0x00 };
66
u8_t    pat1[]= { 0xFF, 0xFF, 0xFF, 0xFF };
70
u8_t    pat1[]= { 0xFF, 0xFF, 0xFF, 0xFF };
67
u8_t    pat2[]= { 0xA5, 0x5A, 0x69, 0x96 };
71
u8_t    pat2[]= { 0xA5, 0x5A, 0x69, 0x96 };
68
u8_t    pat3[]= { 0x96, 0x69, 0x5A, 0xA5 };
72
u8_t    pat3[]= { 0x96, 0x69, 0x5A, 0xA5 };
69
 
73
 
70
_PROTOTYPE( static int test_8, (dpeth_t *dep, int pos, u8_t *pat)   );
74
_PROTOTYPE( static int test_8, (dpeth_t *dep, int pos, u8_t *pat)   );
71
_PROTOTYPE( static int test_16, (dpeth_t *dep, int pos, u8_t *pat)  );
75
_PROTOTYPE( static int test_16, (dpeth_t *dep, int pos, u8_t *pat)  );
72
_PROTOTYPE( static void ne_stop, (dpeth_t *dep)             );
76
_PROTOTYPE( static void ne_stop, (dpeth_t *dep)             );
73
//_PROTOTYPE( static void milli_delay, (unsigned long millis)       );
77
//_PROTOTYPE( static void milli_delay, (unsigned long millis)       );
74
 
78
 
75
#define milli_delay( millis )   usleep(( millis ) * 1000 )
79
#define milli_delay( millis )   usleep(( millis ) * 1000 )
76
 
80
 
77
_PROTOTYPE( void ne_init, (struct dpeth *dep)               );
81
_PROTOTYPE( void ne_init, (struct dpeth *dep)               );
78
 
82
 
79
/*===========================================================================*
83
/*===========================================================================*
80
 *              ne_probe                     *
84
 *              ne_probe                     *
81
 *===========================================================================*/
85
 *===========================================================================*/
82
int ne_probe(dep)
86
int ne_probe(dep)
83
dpeth_t *dep;
87
dpeth_t *dep;
84
{
88
{
85
    int byte;
89
    int byte;
86
    int i;
90
    int i;
87
    int loc1, loc2;
91
    int loc1, loc2;
88
    testf_t f;
92
    testf_t f;
89
 
93
 
90
    dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
94
    dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
91
 
95
 
92
    /* We probe for an ne1000 or an ne2000 by testing whether the
96
    /* We probe for an ne1000 or an ne2000 by testing whether the
93
     * on board is reachable through the dp8390. Note that the
97
     * on board is reachable through the dp8390. Note that the
94
     * ne1000 is an 8bit card and has a memory region distict from
98
     * ne1000 is an 8bit card and has a memory region distict from
95
     * the 16bit ne2000
99
     * the 16bit ne2000
96
     */
100
     */
97
 
101
 
98
    for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
102
    for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
99
    {
103
    {
100
        /* Reset the ethernet card */
104
        /* Reset the ethernet card */
101
        byte= inb_ne(dep, NE_RESET);
105
        byte= inb_ne(dep, NE_RESET);
102
        milli_delay(2);
106
        milli_delay(2);
103
        outb_ne(dep, NE_RESET, byte);
107
        outb_ne(dep, NE_RESET, byte);
104
        milli_delay(2);
108
        milli_delay(2);
105
 
109
 
106
        /* Reset the dp8390 */
110
        /* Reset the dp8390 */
107
        outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
111
        outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
108
        for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
112
        for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
109
            ; /* Do nothing */
113
            ; /* Do nothing */
110
 
114
 
111
        /* Check if the dp8390 is really there */
115
        /* Check if the dp8390 is really there */
112
        if ((inb_reg0(dep, DP_CR) & (CR_STP|CR_DM_ABORT)) !=
116
        if ((inb_reg0(dep, DP_CR) & (CR_STP|CR_DM_ABORT)) !=
113
            (CR_STP|CR_DM_ABORT))
117
            (CR_STP|CR_DM_ABORT))
114
        {
118
        {
115
            return 0;
119
            return 0;
116
        }
120
        }
117
 
121
 
118
        /* Disable the receiver and init TCR and DCR. */
122
        /* Disable the receiver and init TCR and DCR. */
119
        outb_reg0(dep, DP_RCR, RCR_MON);
123
        outb_reg0(dep, DP_RCR, RCR_MON);
120
        outb_reg0(dep, DP_TCR, TCR_NORMAL);
124
        outb_reg0(dep, DP_TCR, TCR_NORMAL);
121
        if (dep->de_16bit)
125
        if (dep->de_16bit)
122
        {
126
        {
123
            outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
127
            outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
124
                DCR_BMS);
128
                DCR_BMS);
125
        }
129
        }
126
        else
130
        else
127
        {
131
        {
128
            outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
132
            outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
129
                DCR_BMS);
133
                DCR_BMS);
130
        }
134
        }
131
 
135
 
132
        if (dep->de_16bit)
136
        if (dep->de_16bit)
133
        {
137
        {
134
            loc1= NE2000_START;
138
            loc1= NE2000_START;
135
            loc2= NE2000_START + NE2000_SIZE - 4;
139
            loc2= NE2000_START + NE2000_SIZE - 4;
136
            f= test_16;
140
            f= test_16;
137
        }
141
        }
138
        else
142
        else
139
        {
143
        {
140
            loc1= NE1000_START;
144
            loc1= NE1000_START;
141
            loc2= NE1000_START + NE1000_SIZE - 4;
145
            loc2= NE1000_START + NE1000_SIZE - 4;
142
            f= test_8;
146
            f= test_8;
143
        }
147
        }
144
        if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
148
        if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
145
            f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
149
            f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
146
            f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
150
            f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
147
            f(dep, loc2, pat2) && f(dep, loc2, pat3))
151
            f(dep, loc2, pat2) && f(dep, loc2, pat3))
148
        {
152
        {
149
            /* We don't need a memory segment */
153
            /* We don't need a memory segment */
150
            dep->de_linmem= 0;
154
            dep->de_linmem= 0;
151
            if (!dep->de_pci)
155
            if (!dep->de_pci)
152
                dep->de_initf= ne_init;
156
                dep->de_initf= ne_init;
153
            dep->de_stopf= ne_stop;
157
            dep->de_stopf= ne_stop;
154
            dep->de_prog_IO= 1;
158
            dep->de_prog_IO= 1;
155
            return 1;
159
            return 1;
156
        }
160
        }
157
    }
161
    }
158
    return 0;
162
    return 0;
159
}
163
}
160
 
164
 
161
/*===========================================================================*
165
/*===========================================================================*
162
 *              ne_init                      *
166
 *              ne_init                      *
163
 *===========================================================================*/
167
 *===========================================================================*/
164
void ne_init(dep)
168
void ne_init(dep)
165
dpeth_t *dep;
169
dpeth_t *dep;
166
{
170
{
167
    int i;
171
    int i;
168
    int word, sendq_nr;
172
    int word, sendq_nr;
169
 
173
 
170
    /* Setup a transfer to get the ethernet address. */
174
    /* Setup a transfer to get the ethernet address. */
171
    if (dep->de_16bit)
175
    if (dep->de_16bit)
172
        outb_reg0(dep, DP_RBCR0, 6*2);
176
        outb_reg0(dep, DP_RBCR0, 6*2);
173
    else
177
    else
174
        outb_reg0(dep, DP_RBCR0, 6);
178
        outb_reg0(dep, DP_RBCR0, 6);
175
    outb_reg0(dep, DP_RBCR1, 0);
179
    outb_reg0(dep, DP_RBCR1, 0);
176
    outb_reg0(dep, DP_RSAR0, 0);
180
    outb_reg0(dep, DP_RSAR0, 0);
177
    outb_reg0(dep, DP_RSAR1, 0);
181
    outb_reg0(dep, DP_RSAR1, 0);
178
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
182
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
179
 
183
 
180
    for (i= 0; i<6; i++)
184
    for (i= 0; i<6; i++)
181
    {
185
    {
182
        if (dep->de_16bit)
186
        if (dep->de_16bit)
183
        {
187
        {
184
            word= inw_ne(dep, NE_DATA);
188
            word= inw_ne(dep, NE_DATA);
185
            dep->de_address.ea_addr[i]= word;
189
            dep->de_address.ea_addr[i]= word;
186
        }
190
        }
187
        else
191
        else
188
        {
192
        {
189
            dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
193
            dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
190
        }
194
        }
191
    }
195
    }
192
    dep->de_data_port= dep->de_base_port + NE_DATA;
196
    dep->de_data_port= dep->de_base_port + NE_DATA;
193
    if (dep->de_16bit)
197
    if (dep->de_16bit)
194
    {
198
    {
195
        dep->de_ramsize= NE2000_SIZE;
199
        dep->de_ramsize= NE2000_SIZE;
196
        dep->de_offset_page= NE2000_START / DP_PAGESIZE;
200
        dep->de_offset_page= NE2000_START / DP_PAGESIZE;
197
    }
201
    }
198
    else
202
    else
199
    {
203
    {
200
        dep->de_ramsize= NE1000_SIZE;
204
        dep->de_ramsize= NE1000_SIZE;
201
        dep->de_offset_page= NE1000_START / DP_PAGESIZE;
205
        dep->de_offset_page= NE1000_START / DP_PAGESIZE;
202
    }
206
    }
203
 
207
 
204
    /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
208
    /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
205
    sendq_nr= dep->de_ramsize / 0x2000;
209
    sendq_nr= dep->de_ramsize / 0x2000;
206
    if (sendq_nr < 1)
210
    if (sendq_nr < 1)
207
        sendq_nr= 1;
211
        sendq_nr= 1;
208
    else if (sendq_nr > SENDQ_NR)
212
    else if (sendq_nr > SENDQ_NR)
209
        sendq_nr= SENDQ_NR;
213
        sendq_nr= SENDQ_NR;
210
    dep->de_sendq_nr= sendq_nr;
214
    dep->de_sendq_nr= sendq_nr;
211
    for (i= 0; i<sendq_nr; i++)
215
    for (i= 0; i<sendq_nr; i++)
212
    {
216
    {
213
        dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
217
        dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
214
            i*SENDQ_PAGES; 
218
            i*SENDQ_PAGES; 
215
    }
219
    }
216
 
220
 
217
    dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
221
    dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
218
    dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
222
    dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
219
 
223
 
220
    /* Can't override the default IRQ. */
224
    /* Can't override the default IRQ. */
221
    dep->de_irq &= ~DEI_DEFAULT;
225
    dep->de_irq &= ~DEI_DEFAULT;
222
 
226
 
223
    if (!debug)
227
    if (!debug)
224
    {
228
    {
225
        printf("%s: NE%d000 at %X:%d\n",
229
        printf("%s: NE%d000 at %X:%d\n",
226
            dep->de_name, dep->de_16bit ? 2 : 1,
230
            dep->de_name, dep->de_16bit ? 2 : 1,
227
            dep->de_base_port, dep->de_irq);
231
            dep->de_base_port, dep->de_irq);
228
    }
232
    }
229
    else
233
    else
230
    {
234
    {
231
        printf("%s: Novell NE%d000 ethernet card at I/O address "
235
        printf("%s: Novell NE%d000 ethernet card at I/O address "
232
            "0x%X, memory size 0x%X, irq %d\n",
236
            "0x%X, memory size 0x%X, irq %d\n",
233
            dep->de_name, dep->de_16bit ? 2 : 1,
237
            dep->de_name, dep->de_16bit ? 2 : 1,
234
            dep->de_base_port, dep->de_ramsize, dep->de_irq);
238
            dep->de_base_port, dep->de_ramsize, dep->de_irq);
235
    }
239
    }
236
}
240
}
237
 
241
 
238
/*===========================================================================*
242
/*===========================================================================*
239
 *              test_8                       *
243
 *              test_8                       *
240
 *===========================================================================*/
244
 *===========================================================================*/
241
static int test_8(dep, pos, pat)
245
static int test_8(dep, pos, pat)
242
dpeth_t *dep;
246
dpeth_t *dep;
243
int pos;
247
int pos;
244
u8_t *pat;
248
u8_t *pat;
245
{
249
{
246
    u8_t buf[4];
250
    u8_t buf[4];
247
    int i;
251
    int i;
248
    int r;
252
    int r;
249
 
253
 
250
    outb_reg0(dep, DP_ISR, 0xFF);
254
    outb_reg0(dep, DP_ISR, 0xFF);
251
 
255
 
252
    /* Setup a transfer to put the pattern. */
256
    /* Setup a transfer to put the pattern. */
253
    outb_reg0(dep, DP_RBCR0, 4);
257
    outb_reg0(dep, DP_RBCR0, 4);
254
    outb_reg0(dep, DP_RBCR1, 0);
258
    outb_reg0(dep, DP_RBCR1, 0);
255
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
259
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
256
    outb_reg0(dep, DP_RSAR1, pos >> 8);
260
    outb_reg0(dep, DP_RSAR1, pos >> 8);
257
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
261
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
258
 
262
 
259
    for (i= 0; i<4; i++)
263
    for (i= 0; i<4; i++)
260
        outb_ne(dep, NE_DATA, pat[i]);
264
        outb_ne(dep, NE_DATA, pat[i]);
261
 
265
 
262
    for (i= 0; i<N; i++)
266
    for (i= 0; i<N; i++)
263
    {
267
    {
264
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
268
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
265
            break;
269
            break;
266
    }
270
    }
267
    if (i == N)
271
    if (i == N)
268
    {
272
    {
269
        if (debug)
273
        if (debug)
270
        {
274
        {
271
            printf("%s: NE1000 remote DMA test failed\n",
275
            printf("%s: NE1000 remote DMA test failed\n",
272
                dep->de_name);
276
                dep->de_name);
273
        }
277
        }
274
        return 0;
278
        return 0;
275
    }
279
    }
276
 
280
 
277
    outb_reg0(dep, DP_RBCR0, 4);
281
    outb_reg0(dep, DP_RBCR0, 4);
278
    outb_reg0(dep, DP_RBCR1, 0);
282
    outb_reg0(dep, DP_RBCR1, 0);
279
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
283
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
280
    outb_reg0(dep, DP_RSAR1, pos >> 8);
284
    outb_reg0(dep, DP_RSAR1, pos >> 8);
281
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
285
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
282
 
286
 
283
    for (i= 0; i<4; i++)
287
    for (i= 0; i<4; i++)
284
        buf[i]= inb_ne(dep, NE_DATA);
288
        buf[i]= inb_ne(dep, NE_DATA);
285
 
289
 
286
    r= (memcmp(buf, pat, 4) == 0);
290
    r= (memcmp(buf, pat, 4) == 0);
287
    return r;
291
    return r;
288
}
292
}
289
 
293
 
290
/*===========================================================================*
294
/*===========================================================================*
291
 *              test_16                      *
295
 *              test_16                      *
292
 *===========================================================================*/
296
 *===========================================================================*/
293
static int test_16(dep, pos, pat)
297
static int test_16(dep, pos, pat)
294
dpeth_t *dep;
298
dpeth_t *dep;
295
int pos;
299
int pos;
296
u8_t *pat;
300
u8_t *pat;
297
{
301
{
298
    u8_t buf[4];
302
    u8_t buf[4];
299
    int i;
303
    int i;
300
    int r;
304
    int r;
301
 
305
 
302
    outb_reg0(dep, DP_ISR, 0xFF);
306
    outb_reg0(dep, DP_ISR, 0xFF);
303
 
307
 
304
    /* Setup a transfer to put the pattern. */
308
    /* Setup a transfer to put the pattern. */
305
    outb_reg0(dep, DP_RBCR0, 4);
309
    outb_reg0(dep, DP_RBCR0, 4);
306
    outb_reg0(dep, DP_RBCR1, 0);
310
    outb_reg0(dep, DP_RBCR1, 0);
307
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
311
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
308
    outb_reg0(dep, DP_RSAR1, pos >> 8);
312
    outb_reg0(dep, DP_RSAR1, pos >> 8);
309
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
313
    outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
310
 
314
 
311
    for (i= 0; i<4; i += 2)
315
    for (i= 0; i<4; i += 2)
312
    {
316
    {
313
        outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
317
        outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
314
    }
318
    }
315
 
319
 
316
    for (i= 0; i<N; i++)
320
    for (i= 0; i<N; i++)
317
    {
321
    {
318
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
322
        if (inb_reg0(dep, DP_ISR) & ISR_RDC)
319
            break;
323
            break;
320
    }
324
    }
321
    if (i == N)
325
    if (i == N)
322
    {
326
    {
323
        if (debug)
327
        if (debug)
324
        {
328
        {
325
            printf("%s: NE2000 remote DMA test failed\n",
329
            printf("%s: NE2000 remote DMA test failed\n",
326
                dep->de_name);
330
                dep->de_name);
327
        }
331
        }
328
        return 0;
332
        return 0;
329
    }
333
    }
330
 
334
 
331
    outb_reg0(dep, DP_RBCR0, 4);
335
    outb_reg0(dep, DP_RBCR0, 4);
332
    outb_reg0(dep, DP_RBCR1, 0);
336
    outb_reg0(dep, DP_RBCR1, 0);
333
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
337
    outb_reg0(dep, DP_RSAR0, pos & 0xFF);
334
    outb_reg0(dep, DP_RSAR1, pos >> 8);
338
    outb_reg0(dep, DP_RSAR1, pos >> 8);
335
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
339
    outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
336
 
340
 
337
    for (i= 0; i<4; i += 2)
341
    for (i= 0; i<4; i += 2)
338
    {
342
    {
339
        *(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
343
        *(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
340
    }
344
    }
341
 
345
 
342
    r= (memcmp(buf, pat, 4) == 0);
346
    r= (memcmp(buf, pat, 4) == 0);
343
    return r;
347
    return r;
344
}
348
}
345
 
349
 
346
/*===========================================================================*
350
/*===========================================================================*
347
 *              ne_stop                      *
351
 *              ne_stop                      *
348
 *===========================================================================*/
352
 *===========================================================================*/
349
static void ne_stop(dep)
353
static void ne_stop(dep)
350
dpeth_t *dep;
354
dpeth_t *dep;
351
{
355
{
352
    int byte;
356
    int byte;
353
 
357
 
354
    /* Reset the ethernet card */
358
    /* Reset the ethernet card */
355
    byte= inb_ne(dep, NE_RESET);
359
    byte= inb_ne(dep, NE_RESET);
356
    milli_delay(2);
360
    milli_delay(2);
357
    outb_ne(dep, NE_RESET, byte);
361
    outb_ne(dep, NE_RESET, byte);
358
}
362
}
359
/*
363
/*
360
static void milli_delay(unsigned long millis)
364
static void milli_delay(unsigned long millis)
361
{
365
{
362
    tickdelay(MILLIS_TO_TICKS(millis));
366
    tickdelay(MILLIS_TO_TICKS(millis));
363
}
367
}
364
*/
368
*/
365
#endif /* ENABLE_NE2000 */
369
#endif /* ENABLE_NE2000 */
366
 
370
 
367
/*
371
/*
368
 * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
372
 * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
369
 */
373
 */
370
 
374
 
371
/** @}
375
/** @}
372
 */
376
 */
373
 
377