1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc ** File: wd.c
3433d6423SLionel Sambuc **
4433d6423SLionel Sambuc ** Driver for the Ethercard (WD80x3) and derivates
5433d6423SLionel Sambuc ** This file contains only the wd80x3 specific code,
6433d6423SLionel Sambuc ** the rest is in 8390.c
7433d6423SLionel Sambuc **
8433d6423SLionel Sambuc ** Created: March 14, 1994 by Philip Homburg
9433d6423SLionel Sambuc ** PchId:
10433d6423SLionel Sambuc **
11433d6423SLionel Sambuc ** Modified: Jun. 08, 2000 by Giovanni Falzoni <gfalzoni@inwind.it>
12433d6423SLionel Sambuc ** Adaptation to interfacing new main network task.
13433d6423SLionel Sambuc */
14433d6423SLionel Sambuc
15433d6423SLionel Sambuc #include <minix/drivers.h>
1691c4db25SDavid van Moolenbroek #include <minix/netdriver.h>
17433d6423SLionel Sambuc #include "dp.h"
18433d6423SLionel Sambuc
19433d6423SLionel Sambuc #if (ENABLE_WDETH == 1)
20433d6423SLionel Sambuc
21433d6423SLionel Sambuc #include "8390.h"
22433d6423SLionel Sambuc #include "wd.h"
23433d6423SLionel Sambuc
24433d6423SLionel Sambuc #define WET_ETHERNET 0x01 /* Ethernet transceiver */
25433d6423SLionel Sambuc #define WET_STARLAN 0x02 /* Starlan transceiver */
26433d6423SLionel Sambuc #define WET_INTERF_CHIP 0x04 /* has a WD83C583 interface chip */
27433d6423SLionel Sambuc #define WET_BRD_16BIT 0x08 /* 16 bit board */
28433d6423SLionel Sambuc #define WET_SLT_16BIT 0x10 /* 16 bit slot */
29433d6423SLionel Sambuc #define WET_790 0x20 /* '790 chip */
30433d6423SLionel Sambuc
31433d6423SLionel Sambuc static const int we_int_table[8] = {9, 3, 5, 7, 10, 11, 15, 4};
32433d6423SLionel Sambuc static const int we_790int_table[8] = {0, 9, 3, 5, 7, 10, 11, 15};
33433d6423SLionel Sambuc
34433d6423SLionel Sambuc static void we_init(dpeth_t * dep);
35433d6423SLionel Sambuc static void we_stop(dpeth_t * dep);
36433d6423SLionel Sambuc static int we_aliasing(dpeth_t * dep);
37433d6423SLionel Sambuc static int we_interface_chip(dpeth_t * dep);
38433d6423SLionel Sambuc static int we_16bitboard(dpeth_t * dep);
39433d6423SLionel Sambuc static int we_16bitslot(dpeth_t * dep);
40433d6423SLionel Sambuc static int we_ultra(dpeth_t * dep);
41433d6423SLionel Sambuc
42433d6423SLionel Sambuc /*===========================================================================*
43433d6423SLionel Sambuc * wdeth_probe *
44433d6423SLionel Sambuc *===========================================================================*/
wdeth_probe(dpeth_t * dep)4591c4db25SDavid van Moolenbroek int wdeth_probe(dpeth_t *dep)
46433d6423SLionel Sambuc {
47433d6423SLionel Sambuc int sum;
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc if (dep->de_linmem == 0)
50433d6423SLionel Sambuc return FALSE; /* No shared memory, so no WD board */
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc sum = inb_we(dep, EPL_EA0) + inb_we(dep, EPL_EA1) +
53433d6423SLionel Sambuc inb_we(dep, EPL_EA2) + inb_we(dep, EPL_EA3) +
54433d6423SLionel Sambuc inb_we(dep, EPL_EA4) + inb_we(dep, EPL_EA5) +
55433d6423SLionel Sambuc inb_we(dep, EPL_TLB) + inb_we(dep, EPL_CHKSUM);
56433d6423SLionel Sambuc if ((sum & 0xFF) != 0xFF)
57433d6423SLionel Sambuc return FALSE; /* No ethernet board at this address */
58433d6423SLionel Sambuc
59433d6423SLionel Sambuc dep->de_initf = we_init;
60433d6423SLionel Sambuc dep->de_stopf = we_stop;
61433d6423SLionel Sambuc dep->de_prog_IO = 0;
62433d6423SLionel Sambuc return TRUE;
63433d6423SLionel Sambuc }
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc /*===========================================================================*
66433d6423SLionel Sambuc * we_init *
67433d6423SLionel Sambuc *===========================================================================*/
we_init(dpeth_t * dep)6891c4db25SDavid van Moolenbroek static void we_init(dpeth_t *dep)
69433d6423SLionel Sambuc {
70*f7df02e7SDavid van Moolenbroek unsigned int i, int_indx, int_nr;
71433d6423SLionel Sambuc int tlb, rambit, revision;
72433d6423SLionel Sambuc int icr, irr, hwr, b, gcr;
73433d6423SLionel Sambuc int we_type;
74*f7df02e7SDavid van Moolenbroek unsigned int sendq_nr;
75433d6423SLionel Sambuc
76433d6423SLionel Sambuc for (i = 0; i < 6; i += 1) {
77*f7df02e7SDavid van Moolenbroek dep->de_address.na_addr[i] = inb_we(dep, EPL_EA0 + i);
78433d6423SLionel Sambuc }
79433d6423SLionel Sambuc
80433d6423SLionel Sambuc dep->de_dp8390_port = dep->de_base_port + EPL_DP8390;
81433d6423SLionel Sambuc
82433d6423SLionel Sambuc dep->de_16bit = 0;
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc we_type = 0;
85433d6423SLionel Sambuc we_type |= WET_ETHERNET; /* assume ethernet */
86433d6423SLionel Sambuc if (we_ultra(dep)) we_type |= WET_790;
87433d6423SLionel Sambuc if (!we_aliasing(dep)) {
88433d6423SLionel Sambuc if (we_interface_chip(dep)) we_type |= WET_INTERF_CHIP;
89433d6423SLionel Sambuc if (we_16bitboard(dep)) {
90433d6423SLionel Sambuc we_type |= WET_BRD_16BIT;
91433d6423SLionel Sambuc if (we_16bitslot(dep)) we_type |= WET_SLT_16BIT;
92433d6423SLionel Sambuc }
93433d6423SLionel Sambuc }
94433d6423SLionel Sambuc if (we_type & WET_SLT_16BIT) dep->de_16bit = 1;
95433d6423SLionel Sambuc
96433d6423SLionel Sambuc /* Look at the on board ram size. */
97433d6423SLionel Sambuc tlb = inb_we(dep, EPL_TLB);
98433d6423SLionel Sambuc revision = tlb & E_TLB_REV;
99433d6423SLionel Sambuc rambit = tlb & E_TLB_RAM;
100433d6423SLionel Sambuc
101433d6423SLionel Sambuc if (dep->de_ramsize != 0) {
102433d6423SLionel Sambuc /* Size set from boot environment. */
103433d6423SLionel Sambuc } else if (revision < 2) {
104433d6423SLionel Sambuc dep->de_ramsize = 0x2000; /* 8K */
105433d6423SLionel Sambuc if (we_type & WET_BRD_16BIT)
106433d6423SLionel Sambuc dep->de_ramsize = 0x4000; /* 16K */
107433d6423SLionel Sambuc else if ((we_type & WET_INTERF_CHIP) &&
108433d6423SLionel Sambuc inb_we(dep, EPL_ICR) & E_ICR_MEMBIT) {
109433d6423SLionel Sambuc dep->de_ramsize = 0x8000; /* 32K */
110433d6423SLionel Sambuc }
111433d6423SLionel Sambuc } else {
112433d6423SLionel Sambuc if (we_type & WET_BRD_16BIT) {
113433d6423SLionel Sambuc /* 32K or 16K */
114433d6423SLionel Sambuc dep->de_ramsize = rambit ? 0x8000 : 0x4000;
115433d6423SLionel Sambuc } else {
116433d6423SLionel Sambuc /* 32K or 8K */
117433d6423SLionel Sambuc dep->de_ramsize = rambit ? 0x8000 : 0x2000;
118433d6423SLionel Sambuc }
119433d6423SLionel Sambuc }
120433d6423SLionel Sambuc
121433d6423SLionel Sambuc if (we_type & WET_790) {
122433d6423SLionel Sambuc outb_we(dep, EPL_MSR, E_MSR_RESET);
123433d6423SLionel Sambuc if ((we_type & (WET_BRD_16BIT | WET_SLT_16BIT)) ==
124433d6423SLionel Sambuc (WET_BRD_16BIT | WET_SLT_16BIT)) {
125433d6423SLionel Sambuc outb_we(dep, EPL_LAAR, E_LAAR_LAN16E | E_LAAR_MEM16E);
126433d6423SLionel Sambuc }
127433d6423SLionel Sambuc } else if (we_type & WET_BRD_16BIT) {
128433d6423SLionel Sambuc if (we_type & WET_SLT_16BIT) {
129433d6423SLionel Sambuc outb_we(dep, EPL_LAAR, E_LAAR_A19 | E_LAAR_SOFTINT |
130433d6423SLionel Sambuc E_LAAR_LAN16E | E_LAAR_MEM16E);
131433d6423SLionel Sambuc } else {
132433d6423SLionel Sambuc outb_we(dep, EPL_LAAR, E_LAAR_A19 | E_LAAR_SOFTINT |
133433d6423SLionel Sambuc E_LAAR_LAN16E);
134433d6423SLionel Sambuc }
135433d6423SLionel Sambuc }
136433d6423SLionel Sambuc if (we_type & WET_790) {
137433d6423SLionel Sambuc outb_we(dep, EPL_MSR, E_MSR_MENABLE);
138433d6423SLionel Sambuc hwr = inb_we(dep, EPL_790_HWR);
139433d6423SLionel Sambuc outb_we(dep, EPL_790_HWR, hwr | E_790_HWR_SWH);
140433d6423SLionel Sambuc b = inb_we(dep, EPL_790_B);
141433d6423SLionel Sambuc outb_we(dep, EPL_790_B, ((dep->de_linmem >> 13) & 0x0f) |
142433d6423SLionel Sambuc ((dep->de_linmem >> 11) & 0x40) | (b & 0xb0));
143433d6423SLionel Sambuc outb_we(dep, EPL_790_HWR, hwr & ~E_790_HWR_SWH);
144433d6423SLionel Sambuc } else {
145433d6423SLionel Sambuc outb_we(dep, EPL_MSR, E_MSR_RESET);
146433d6423SLionel Sambuc outb_we(dep, EPL_MSR, E_MSR_MENABLE |
147433d6423SLionel Sambuc ((dep->de_linmem >> 13) & E_MSR_MEMADDR));
148433d6423SLionel Sambuc }
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc if ((we_type & WET_INTERF_CHIP) && !(we_type & WET_790)) {
151433d6423SLionel Sambuc icr = inb_we(dep, EPL_ICR);
152433d6423SLionel Sambuc irr = inb_we(dep, EPL_IRR);
153433d6423SLionel Sambuc int_indx = (icr & E_ICR_IR2) | ((irr & (E_IRR_IR0 | E_IRR_IR1)) >> 5);
154433d6423SLionel Sambuc int_nr = we_int_table[int_indx];
155*f7df02e7SDavid van Moolenbroek DEBUG(printf("%s: encoded irq= %d\n", netdriver_name(), int_nr));
156433d6423SLionel Sambuc if (dep->de_irq & DEI_DEFAULT) dep->de_irq = int_nr;
157433d6423SLionel Sambuc outb_we(dep, EPL_IRR, irr | E_IRR_IEN);
158433d6423SLionel Sambuc }
159433d6423SLionel Sambuc if (we_type & WET_790) {
160433d6423SLionel Sambuc hwr = inb_we(dep, EPL_790_HWR);
161433d6423SLionel Sambuc outb_we(dep, EPL_790_HWR, hwr | E_790_HWR_SWH);
162433d6423SLionel Sambuc
163433d6423SLionel Sambuc gcr = inb_we(dep, EPL_790_GCR);
164433d6423SLionel Sambuc
165433d6423SLionel Sambuc outb_we(dep, EPL_790_HWR, hwr & ~E_790_HWR_SWH);
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc int_indx = ((gcr & E_790_GCR_IR2) >> 4) |
168433d6423SLionel Sambuc ((gcr & (E_790_GCR_IR1 | E_790_GCR_IR0)) >> 2);
169433d6423SLionel Sambuc int_nr = we_790int_table[int_indx];
170*f7df02e7SDavid van Moolenbroek DEBUG(printf("%s: encoded irq= %d\n", netdriver_name(), int_nr));
171433d6423SLionel Sambuc if (dep->de_irq & DEI_DEFAULT) dep->de_irq = int_nr;
172433d6423SLionel Sambuc icr = inb_we(dep, EPL_790_ICR);
173433d6423SLionel Sambuc outb_we(dep, EPL_790_ICR, icr | E_790_ICR_EIL);
174433d6423SLionel Sambuc }
175433d6423SLionel Sambuc
176433d6423SLionel Sambuc /* Strip the "default flag." */
177433d6423SLionel Sambuc dep->de_irq &= ~DEI_DEFAULT;
178433d6423SLionel Sambuc
179433d6423SLionel Sambuc dep->de_offset_page = 0; /* Shared memory starts at 0 */
180433d6423SLionel Sambuc /* Allocate one send buffer (1.5KB) per 8KB of on board memory.
181433d6423SLionel Sambuc sendq_nr = dep->de_ramsize / 0x2000;
182433d6423SLionel Sambuc if (sendq_nr < 1)
183433d6423SLionel Sambuc sendq_nr = 1;
184433d6423SLionel Sambuc else if (sendq_nr > SENDQ_NR) */
185433d6423SLionel Sambuc sendq_nr = SENDQ_NR;
186433d6423SLionel Sambuc dep->de_sendq_nr = sendq_nr;
187433d6423SLionel Sambuc for (i = 0; i < sendq_nr; i++) {
188433d6423SLionel Sambuc dep->de_sendq[i].sq_sendpage = i * SENDQ_PAGES;
189433d6423SLionel Sambuc }
190433d6423SLionel Sambuc dep->de_startpage = i * SENDQ_PAGES;
191433d6423SLionel Sambuc dep->de_stoppage = dep->de_ramsize / DP_PAGESIZE;
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc ns_init(dep); /* Initialize DP controller */
194433d6423SLionel Sambuc
195433d6423SLionel Sambuc printf("%s: WD80%d3 (%dkB RAM) at %X:%d:%lX - ",
196*f7df02e7SDavid van Moolenbroek netdriver_name(),
197433d6423SLionel Sambuc we_type & WET_BRD_16BIT ? 1 : 0,
198433d6423SLionel Sambuc dep->de_ramsize / 1024,
199433d6423SLionel Sambuc dep->de_base_port,
200433d6423SLionel Sambuc dep->de_irq,
201433d6423SLionel Sambuc dep->de_linmem);
202433d6423SLionel Sambuc for (i = 0; i < SA_ADDR_LEN; i += 1)
203*f7df02e7SDavid van Moolenbroek printf("%02X%c", dep->de_address.na_addr[i],
204433d6423SLionel Sambuc i < SA_ADDR_LEN - 1 ? ':' : '\n');
205433d6423SLionel Sambuc
206433d6423SLionel Sambuc return;
207433d6423SLionel Sambuc }
208433d6423SLionel Sambuc
209433d6423SLionel Sambuc /*===========================================================================*
210433d6423SLionel Sambuc * we_stop *
211433d6423SLionel Sambuc *===========================================================================*/
we_stop(dpeth_t * dep)21291c4db25SDavid van Moolenbroek static void we_stop(dpeth_t *dep)
213433d6423SLionel Sambuc {
214433d6423SLionel Sambuc
215433d6423SLionel Sambuc if (dep->de_16bit) outb_we(dep, EPL_LAAR, E_LAAR_A19 | E_LAAR_LAN16E);
216433d6423SLionel Sambuc outb_we(dep, EPL_MSR, E_MSR_RESET);
217433d6423SLionel Sambuc outb_we(dep, EPL_MSR, 0);
218433d6423SLionel Sambuc sys_irqdisable(&dep->de_hook);
219433d6423SLionel Sambuc return;
220433d6423SLionel Sambuc }
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc /*===========================================================================*
223433d6423SLionel Sambuc * we_aliasing *
224433d6423SLionel Sambuc *===========================================================================*/
we_aliasing(dpeth_t * dep)22591c4db25SDavid van Moolenbroek static int we_aliasing(dpeth_t *dep)
226433d6423SLionel Sambuc {
227433d6423SLionel Sambuc /* Determine whether wd8003 hardware performs register aliasing. This implies
228433d6423SLionel Sambuc * an old WD8003E board. */
229433d6423SLionel Sambuc
230433d6423SLionel Sambuc if (inb_we(dep, EPL_REG1) != inb_we(dep, EPL_EA1)) return 0;
231433d6423SLionel Sambuc if (inb_we(dep, EPL_REG2) != inb_we(dep, EPL_EA2)) return 0;
232433d6423SLionel Sambuc if (inb_we(dep, EPL_REG3) != inb_we(dep, EPL_EA3)) return 0;
233433d6423SLionel Sambuc if (inb_we(dep, EPL_REG4) != inb_we(dep, EPL_EA4)) return 0;
234433d6423SLionel Sambuc if (inb_we(dep, EPL_REG7) != inb_we(dep, EPL_CHKSUM)) return 0;
235433d6423SLionel Sambuc return 1;
236433d6423SLionel Sambuc }
237433d6423SLionel Sambuc
238433d6423SLionel Sambuc /*===========================================================================*
239433d6423SLionel Sambuc * we_interface_chip *
240433d6423SLionel Sambuc *===========================================================================*/
we_interface_chip(dpeth_t * dep)24191c4db25SDavid van Moolenbroek static int we_interface_chip(dpeth_t *dep)
242433d6423SLionel Sambuc {
243433d6423SLionel Sambuc /* Determine if the board has an interface chip. */
244433d6423SLionel Sambuc
245433d6423SLionel Sambuc outb_we(dep, EPL_GP2, 0x35);
246433d6423SLionel Sambuc if (inb_we(dep, EPL_GP2) != 0x35) return 0;
247433d6423SLionel Sambuc outb_we(dep, EPL_GP2, 0x3A);
248433d6423SLionel Sambuc if (inb_we(dep, EPL_GP2) != 0x3A) return 0;
249433d6423SLionel Sambuc return 1;
250433d6423SLionel Sambuc }
251433d6423SLionel Sambuc
252433d6423SLionel Sambuc /*===========================================================================*
253433d6423SLionel Sambuc * we_16bitboard *
254433d6423SLionel Sambuc *===========================================================================*/
we_16bitboard(dpeth_t * dep)25591c4db25SDavid van Moolenbroek static int we_16bitboard(dpeth_t *dep)
256433d6423SLionel Sambuc {
257433d6423SLionel Sambuc /* Determine whether the board is capable of doing 16 bit memory moves.
258433d6423SLionel Sambuc * If the 16 bit enable bit is unchangable by software we'll assume an
259433d6423SLionel Sambuc * 8 bit board.
260433d6423SLionel Sambuc */
261*f7df02e7SDavid van Moolenbroek unsigned int icr;
262433d6423SLionel Sambuc u8_t tlb;
263433d6423SLionel Sambuc
264433d6423SLionel Sambuc icr = inb_we(dep, EPL_ICR);
265433d6423SLionel Sambuc
266433d6423SLionel Sambuc outb_we(dep, EPL_ICR, icr ^ E_ICR_16BIT);
267433d6423SLionel Sambuc if (inb_we(dep, EPL_ICR) == icr) {
268433d6423SLionel Sambuc tlb = inb_we(dep, EPL_TLB);
269433d6423SLionel Sambuc
270*f7df02e7SDavid van Moolenbroek DEBUG(printf("%s: tlb= 0x%x\n", netdriver_name(), tlb));
271433d6423SLionel Sambuc
272433d6423SLionel Sambuc return tlb == E_TLB_EB || tlb == E_TLB_E ||
273433d6423SLionel Sambuc tlb == E_TLB_SMCE || tlb == E_TLB_SMC8216C;
274433d6423SLionel Sambuc }
275433d6423SLionel Sambuc outb_we(dep, EPL_ICR, icr);
276433d6423SLionel Sambuc return 1;
277433d6423SLionel Sambuc }
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc /*===========================================================================*
280433d6423SLionel Sambuc * we_16bitslot *
281433d6423SLionel Sambuc *===========================================================================*/
we_16bitslot(dpeth_t * dep)28291c4db25SDavid van Moolenbroek static int we_16bitslot(dpeth_t *dep)
283433d6423SLionel Sambuc {
284433d6423SLionel Sambuc /* Determine if the 16 bit board in plugged into a 16 bit slot. */
285433d6423SLionel Sambuc
286433d6423SLionel Sambuc return !!(inb_we(dep, EPL_ICR) & E_ICR_16BIT);
287433d6423SLionel Sambuc }
288433d6423SLionel Sambuc
289433d6423SLionel Sambuc /*===========================================================================*
290433d6423SLionel Sambuc * we_ultra *
291433d6423SLionel Sambuc *===========================================================================*/
we_ultra(dpeth_t * dep)29291c4db25SDavid van Moolenbroek static int we_ultra(dpeth_t *dep)
293433d6423SLionel Sambuc {
294433d6423SLionel Sambuc /* Determine if we has an '790 chip. */
295433d6423SLionel Sambuc u8_t tlb;
296433d6423SLionel Sambuc
297433d6423SLionel Sambuc tlb = inb_we(dep, EPL_TLB);
298433d6423SLionel Sambuc return tlb == E_TLB_SMC8216C;
299433d6423SLionel Sambuc }
300433d6423SLionel Sambuc
301433d6423SLionel Sambuc #endif /* ENABLE_WDETH */
302433d6423SLionel Sambuc
303433d6423SLionel Sambuc /** wd.c **/
304