source: trunk/minix/drivers/dpeth/ne.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 5.3 KB
Line 
1/*
2** File: ne.c Jun. 08, 2000
3**
4** Driver for the NE*000 ethernet cards and derivates.
5** This file contains only the ne specific code,
6** the rest is in 8390.c Code specific for ISA bus only
7**
8** Created: March 15, 1994 by Philip Homburg <philip@cs.vu.nl>
9** PchId: ne2000.c,v 1.4 1996/01/19 23:30:34 philip Exp
10**
11** Modified: Jun. 08, 2000 by Giovanni Falzoni <gfalzoni@inwind.it>
12** Adapted to interface new main network task.
13**
14** $Id: ne.c,v 1.3 2005/08/05 19:08:43 beng Exp $
15*/
16
17#include "drivers.h"
18#include <net/gen/ether.h>
19#include <net/gen/eth_io.h>
20#include "dp.h"
21
22#if (ENABLE_NE2000 == 1)
23
24#include "8390.h"
25#include "ne.h"
26
27/*
28** Name: void ne_reset(dpeth_t * dep);
29** Function: Resets the board and checks if reset cycle completes
30*/
31static int ne_reset(dpeth_t * dep)
32{
33 int count = 0;
34
35 /* Reset the ethernet card */
36 outb_ne(dep, NE_RESET, inb_ne(dep, NE_RESET));
37 do {
38 if (++count > 10) return FALSE; /* 20 mSecs. timeout */
39 milli_delay(2);
40 } while ((inb_ne(dep, DP_ISR) & ISR_RST) == 0);
41 return TRUE;
42}
43
44/*
45** Name: void ne_close(dpeth_t * dep);
46** Function: Stops the board by resetting it and masking interrupts.
47*/
48static void ne_close(dpeth_t * dep)
49{
50
51 (void)ne_reset(dep);
52 outb_ne(dep, DP_ISR, 0xFF);
53 sys_irqdisable(&dep->de_hook);
54 return;
55}
56
57/*
58** Name: void ne_init(dpeth_t * dep);
59** Function: Initialize the board making it ready to work.
60*/
61static void ne_init(dpeth_t * dep)
62{
63 int ix;
64
65 dep->de_data_port = dep->de_base_port + NE_DATA;
66 if (dep->de_16bit) {
67 dep->de_ramsize = NE2000_SIZE;
68 dep->de_offset_page = NE2000_START / DP_PAGESIZE;
69 } else {
70 dep->de_ramsize = NE1000_SIZE;
71 dep->de_offset_page = NE1000_START / DP_PAGESIZE;
72 }
73
74 /* Allocates two send buffers from onboard RAM */
75 dep->de_sendq_nr = SENDQ_NR;
76 for (ix = 0; ix < SENDQ_NR; ix += 1) {
77 dep->de_sendq[ix].sq_sendpage = dep->de_offset_page + ix * SENDQ_PAGES;
78 }
79
80 /* Remaining onboard RAM allocated for receiving */
81 dep->de_startpage = dep->de_offset_page + ix * SENDQ_PAGES;
82 dep->de_stoppage = dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
83
84 /* Can't override the default IRQ. */
85 dep->de_irq &= NOT(DEI_DEFAULT);
86
87 ns_init(dep); /* Initialize DP controller */
88
89 printf("%s: NE%d000 (%dkB RAM) at %X:%d - ",
90 dep->de_name,
91 dep->de_16bit ? 2 : 1,
92 dep->de_ramsize / 1024,
93 dep->de_base_port, dep->de_irq);
94 for (ix = 0; ix < SA_ADDR_LEN; ix += 1)
95 printf("%02X%c", dep->de_address.ea_addr[ix], ix < SA_ADDR_LEN - 1 ? ':' : '\n');
96 return;
97}
98
99/*
100** Name: int ne_probe(dpeth_t * dep);
101** Function: Probe for the presence of a NE*000 card by testing
102** whether the board is reachable through the dp8390.
103** Note that the NE1000 is an 8bit card and has a memory
104** region distict from the 16bit NE2000.
105*/
106PUBLIC int ne_probe(dpeth_t * dep)
107{
108 int ix, wd, loc1, loc2;
109 char EPROM[32];
110 static const struct {
111 unsigned char offset;
112 unsigned char value;
113 } InitSeq[] =
114 {
115 { /* Selects page 0. */
116 DP_CR, (CR_NO_DMA | CR_PS_P0 | CR_STP),
117 },
118 { /* Set byte-wide access and 8 bytes burst mode. */
119 DP_DCR, (DCR_8BYTES | DCR_BMS),
120 },
121 { /* Clears the count registers. */
122 DP_RBCR0, 0x00, }, { DP_RBCR1, 0x00,
123 },
124 { /* Mask completion irq. */
125 DP_IMR, 0x00, }, { DP_ISR, 0xFF,
126 },
127 { /* Set receiver to monitor */
128 DP_RCR, RCR_MON,
129 },
130 { /* and transmitter to loopback mode. */
131 DP_TCR, TCR_INTERNAL,
132 },
133 { /* Transmit 32 bytes */
134 DP_RBCR0, 32, }, { DP_RBCR1, 0,
135 },
136 { /* DMA starting at 0x0000. */
137 DP_RSAR0, 0x00, }, { DP_RSAR1, 0x00,
138 },
139 { /* Start board (reads) */
140 DP_CR, (CR_PS_P0 | CR_DM_RR | CR_STA),
141 },
142 };
143
144 dep->de_dp8390_port = dep->de_base_port + NE_DP8390;
145
146 if ((loc1 = inb_ne(dep, NE_DP8390)) == 0xFF) return FALSE;
147
148 /* Check if the dp8390 is really there */
149 outb_ne(dep, DP_CR, CR_STP | CR_NO_DMA | CR_PS_P1);
150 loc2 = inb_ne(dep, DP_MAR5); /* Saves one byte of the address */
151 outb_ne(dep, DP_MAR5, 0xFF); /* Write 0xFF to it (same offset as DP_CNTR0) */
152 outb_ne(dep, DP_CR, CR_NO_DMA | CR_PS_P0); /* Back to page 0 */
153 inb_ne(dep, DP_CNTR0); /* Reading counter resets it */
154 if (inb_ne(dep, DP_CNTR0) != 0) {
155 outb_ne(dep, NE_DP8390, loc1); /* Try to restore modified bytes */
156 outb_ne(dep, DP_TCR, loc2);
157 return FALSE;
158 }
159
160 /* Try to reset the board */
161 if (ne_reset(dep) == FALSE) return FALSE;
162
163 /* Checks whether the board is 8/16bits and a real NE*000 or clone */
164 for (ix = 0; ix < sizeof(InitSeq)/sizeof(InitSeq[0]); ix += 1) {
165 outb_ne(dep, InitSeq[ix].offset, InitSeq[ix].value);
166 }
167 for (ix = 0, wd = 1; ix < 32; ix += 2) {
168 EPROM[ix + 0] = inb_ne(dep, NE_DATA);
169 EPROM[ix + 1] = inb_ne(dep, NE_DATA);
170 /* NE2000s and clones read same value for even and odd addresses */
171 if (EPROM[ix + 0] != EPROM[ix + 1]) wd = 0;
172 }
173 if (wd == 1) { /* Normalize EPROM contents for NE2000 */
174 for (ix = 0; ix < 16; ix += 1) EPROM[ix] = EPROM[ix * 2];
175 }
176 /* Real NE*000 and good clones have '0x57' at locations 14 and 15 */
177 if (EPROM[14] != 0x57 || EPROM[15] != 0x57) return FALSE;
178
179 /* Setup the ethernet address. */
180 for (ix = 0; ix < SA_ADDR_LEN; ix += 1) {
181 dep->de_address.ea_addr[ix] = EPROM[ix];
182 }
183 dep->de_16bit = wd;
184 dep->de_linmem = 0; /* Uses Programmed I/O only */
185 dep->de_prog_IO = 1;
186 dep->de_initf = ne_init;
187 dep->de_stopf = ne_close;
188 return TRUE;
189}
190
191#endif /* ENABLE_NE2000 */
192
193/** ne.c **/
Note: See TracBrowser for help on using the repository browser.