xref: /minix3/minix/drivers/net/dpeth/3c503.c (revision f7df02e7476731c31f12548e38bcadbaf0233f6a)
1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc **  File:	3c503.c		Dec. 20, 1996
3433d6423SLionel Sambuc **
4433d6423SLionel Sambuc **  Author:	Giovanni Falzoni <gfalzoni@inwind.it>
5433d6423SLionel Sambuc **
6433d6423SLionel Sambuc **  Driver for the Etherlink II boards.  Works in shared memory mode.
7433d6423SLionel Sambuc **  Programmed I/O could be used as well but would result in poor
8433d6423SLionel Sambuc **  performances. This file contains only the board specific code,
9433d6423SLionel Sambuc **  the rest is in 8390.c        Code specific for ISA bus only
10433d6423SLionel Sambuc */
11433d6423SLionel Sambuc 
12433d6423SLionel Sambuc #include <minix/drivers.h>
1391c4db25SDavid van Moolenbroek #include <minix/netdriver.h>
14433d6423SLionel Sambuc #include "dp.h"
15433d6423SLionel Sambuc 
16433d6423SLionel Sambuc #if (ENABLE_3C503 == 1)
17433d6423SLionel Sambuc 
18433d6423SLionel Sambuc #include "8390.h"
19433d6423SLionel Sambuc #include "3c503.h"
20433d6423SLionel Sambuc 
21433d6423SLionel Sambuc /*
2291c4db25SDavid van Moolenbroek **  Name:	el2_init
23433d6423SLionel Sambuc **  Function:	Initalize hardware and data structures.
24433d6423SLionel Sambuc */
el2_init(dpeth_t * dep)25433d6423SLionel Sambuc static void el2_init(dpeth_t * dep)
26433d6423SLionel Sambuc {
27*f7df02e7SDavid van Moolenbroek   unsigned int ix, irq;
28*f7df02e7SDavid van Moolenbroek   unsigned int sendq_nr;
29433d6423SLionel Sambuc   int cntr;
30433d6423SLionel Sambuc 
31433d6423SLionel Sambuc   /* Map the address PROM to lower I/O address range */
32433d6423SLionel Sambuc   cntr = inb_el2(dep, EL2_CNTR);
33433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, cntr | ECNTR_SAPROM);
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc   /* Read station address from PROM */
36433d6423SLionel Sambuc   for (ix = EL2_EA0; ix <= EL2_EA5; ix += 1)
37*f7df02e7SDavid van Moolenbroek 	dep->de_address.na_addr[ix] = inb_el2(dep, ix);
38433d6423SLionel Sambuc 
39433d6423SLionel Sambuc   /* Map the 8390 back to lower I/O address range */
40433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, cntr);
41433d6423SLionel Sambuc 
42433d6423SLionel Sambuc   /* Enable memory, but turn off interrupts until we are ready */
43433d6423SLionel Sambuc   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
44433d6423SLionel Sambuc 
45433d6423SLionel Sambuc   dep->de_data_port = dep->de_dp8390_port = dep->de_base_port;
46433d6423SLionel Sambuc   dep->de_prog_IO = FALSE;	/* Programmed I/O not yet available */
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc   /* Check width of data bus */
49433d6423SLionel Sambuc   outb_el2(dep, DP_CR, CR_PS_P0 | CR_NO_DMA | CR_STP);
50433d6423SLionel Sambuc   outb_el2(dep, DP_DCR, 0);
51433d6423SLionel Sambuc   outb_el2(dep, DP_CR, CR_PS_P2 | CR_NO_DMA | CR_STP);
52433d6423SLionel Sambuc   dep->de_16bit = (inb_el2(dep, DP_DCR) & DCR_WTS) != 0;
53433d6423SLionel Sambuc   outb_el2(dep, DP_CR, CR_PS_P0 | CR_NO_DMA | CR_STP);
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc   /* Allocate one send buffer (1.5kb) per 8kb of on board memory. */
56433d6423SLionel Sambuc   /* Only 8kb of 3c503/16 boards are used to avoid specific routines */
57433d6423SLionel Sambuc   sendq_nr = dep->de_ramsize / 0x2000;
58433d6423SLionel Sambuc   if (sendq_nr < 1)
59433d6423SLionel Sambuc 	sendq_nr = 1;
60433d6423SLionel Sambuc   else if (sendq_nr > SENDQ_NR)
61433d6423SLionel Sambuc 	sendq_nr = SENDQ_NR;
62433d6423SLionel Sambuc 
63433d6423SLionel Sambuc   dep->de_sendq_nr = sendq_nr;
64433d6423SLionel Sambuc   for (ix = 0; ix < sendq_nr; ix++)
65433d6423SLionel Sambuc 	dep->de_sendq[ix].sq_sendpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
66433d6423SLionel Sambuc 
67433d6423SLionel Sambuc   dep->de_startpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
68433d6423SLionel Sambuc   dep->de_stoppage = EL2_SM_STOP_PG;
69433d6423SLionel Sambuc 
70433d6423SLionel Sambuc   outb_el2(dep, EL2_STARTPG, dep->de_startpage);
71433d6423SLionel Sambuc   outb_el2(dep, EL2_STOPPG, dep->de_stoppage);
72433d6423SLionel Sambuc 
73433d6423SLionel Sambuc   /* Point the vector pointer registers somewhere ?harmless?. */
74433d6423SLionel Sambuc   outb_el2(dep, EL2_VP2, 0xFF);	/* Point at the ROM restart location    */
75433d6423SLionel Sambuc   outb_el2(dep, EL2_VP1, 0xFF);	/* 0xFFFF:0000  (from original sources) */
76433d6423SLionel Sambuc   outb_el2(dep, EL2_VP0, 0x00);	/* - What for protected mode? */
77433d6423SLionel Sambuc 
78433d6423SLionel Sambuc   /* Set interrupt level for 3c503 */
79433d6423SLionel Sambuc   irq = (dep->de_irq &= ~DEI_DEFAULT);	/* Strip the default flag. */
80433d6423SLionel Sambuc   if (irq == 9) irq = 2;
81433d6423SLionel Sambuc   if (irq < 2 || irq > 5) panic("bad 3c503 irq configuration: %d", irq);
82433d6423SLionel Sambuc   outb_el2(dep, EL2_IDCFG, (0x04 << irq));
83433d6423SLionel Sambuc 
84433d6423SLionel Sambuc   outb_el2(dep, EL2_DRQCNT, 0x08);	/* Set burst size to 8 */
85433d6423SLionel Sambuc   outb_el2(dep, EL2_DMAAH, EL2_SM_START_PG);	/* Put start of TX  */
86433d6423SLionel Sambuc   outb_el2(dep, EL2_DMAAL, 0x00);	/* buffer in the GA DMA reg */
87433d6423SLionel Sambuc 
88433d6423SLionel Sambuc   outb_el2(dep, EL2_CFGR, ECFGR_NORM);	/* Enable shared memory */
89433d6423SLionel Sambuc 
90433d6423SLionel Sambuc   ns_init(dep);			/* Initialize DP controller */
91433d6423SLionel Sambuc 
92433d6423SLionel Sambuc   printf("%s: Etherlink II%s (%s) at %X:%d:%05lX - ",
93*f7df02e7SDavid van Moolenbroek 	 netdriver_name(), dep->de_16bit ? "/16" : "", "3c503",
94433d6423SLionel Sambuc 	 dep->de_base_port, dep->de_irq,
95433d6423SLionel Sambuc          dep->de_linmem + dep->de_offset_page);
96433d6423SLionel Sambuc   for (ix = 0; ix < SA_ADDR_LEN; ix += 1)
97*f7df02e7SDavid van Moolenbroek 	printf("%02X%c", dep->de_address.na_addr[ix],
98433d6423SLionel Sambuc 	       ix < SA_ADDR_LEN - 1 ? ':' : '\n');
99433d6423SLionel Sambuc }
100433d6423SLionel Sambuc 
101433d6423SLionel Sambuc /*
10291c4db25SDavid van Moolenbroek **  Name:	el2_stop
103433d6423SLionel Sambuc **  Function:	Stops board by disabling interrupts.
104433d6423SLionel Sambuc */
el2_stop(dpeth_t * dep)105433d6423SLionel Sambuc static void el2_stop(dpeth_t * dep)
106433d6423SLionel Sambuc {
107433d6423SLionel Sambuc 
108433d6423SLionel Sambuc   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
109433d6423SLionel Sambuc   sys_irqdisable(&dep->de_hook);	/* disable interrupts */
110433d6423SLionel Sambuc }
111433d6423SLionel Sambuc 
112433d6423SLionel Sambuc /*
11391c4db25SDavid van Moolenbroek **  Name:	el2_probe
114433d6423SLionel Sambuc **  Function:	Probe for the presence of an EtherLink II card.
115433d6423SLionel Sambuc **  		Initialize memory addressing if card detected.
116433d6423SLionel Sambuc */
el2_probe(dpeth_t * dep)117433d6423SLionel Sambuc int el2_probe(dpeth_t * dep)
118433d6423SLionel Sambuc {
119433d6423SLionel Sambuc   int iobase, membase;
120433d6423SLionel Sambuc   int thin;
121433d6423SLionel Sambuc 
122433d6423SLionel Sambuc   /* Thin ethernet or AUI? */
123433d6423SLionel Sambuc   thin = (dep->de_linmem & 1) ? ECNTR_AUI : ECNTR_THIN;
124433d6423SLionel Sambuc 
125433d6423SLionel Sambuc   /* Location registers should have 1 bit set */
126433d6423SLionel Sambuc   if (!(iobase = inb_el2(dep, EL2_IOBASE))) return FALSE;
127433d6423SLionel Sambuc   if (!((membase = inb_el2(dep, EL2_MEMBASE)) & 0xF0)) return FALSE;
128433d6423SLionel Sambuc   if ((iobase & (iobase - 1)) || (membase & (membase - 1))) return FALSE;
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc   /* Resets board */
131433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, ECNTR_RESET | thin);
13291c4db25SDavid van Moolenbroek   micro_delay(1000);
133433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, thin);
13491c4db25SDavid van Moolenbroek   micro_delay(5000);
135433d6423SLionel Sambuc 
136433d6423SLionel Sambuc   /* Map the address PROM to lower I/O address range */
137433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, ECNTR_SAPROM | thin);
138433d6423SLionel Sambuc   if (inb_el2(dep, EL2_EA0) != 0x02 ||	/* Etherlink II Station address */
139433d6423SLionel Sambuc       inb_el2(dep, EL2_EA1) != 0x60 ||	/* MUST be 02:60:8c:xx:xx:xx */
140433d6423SLionel Sambuc       inb_el2(dep, EL2_EA2) != 0x8C)
141433d6423SLionel Sambuc 	return FALSE;		/* No Etherlink board at this address */
142433d6423SLionel Sambuc 
143433d6423SLionel Sambuc   /* Map the 8390 back to lower I/O address range */
144433d6423SLionel Sambuc   outb_el2(dep, EL2_CNTR, thin);
145433d6423SLionel Sambuc 
146433d6423SLionel Sambuc   /* Setup shared memory addressing for 3c503 */
147433d6423SLionel Sambuc   dep->de_linmem = ((membase & 0xC0) ? EL2_BASE_0D8000 : EL2_BASE_0C8000) +
148433d6423SLionel Sambuc 	((membase & 0xA0) ? (EL2_BASE_0CC000 - EL2_BASE_0C8000) : 0x0000);
149433d6423SLionel Sambuc 
150433d6423SLionel Sambuc   /* Shared memory starts at 0x2000 (8kb window) */
151433d6423SLionel Sambuc   dep->de_offset_page = (EL2_SM_START_PG * DP_PAGESIZE);
152433d6423SLionel Sambuc   dep->de_linmem -= dep->de_offset_page;
153433d6423SLionel Sambuc   dep->de_ramsize = (EL2_SM_STOP_PG - EL2_SM_START_PG) * DP_PAGESIZE;
154433d6423SLionel Sambuc 
155433d6423SLionel Sambuc   /* Board initialization and stop functions */
156433d6423SLionel Sambuc   dep->de_initf = el2_init;
157433d6423SLionel Sambuc   dep->de_stopf = el2_stop;
158433d6423SLionel Sambuc   return TRUE;
159433d6423SLionel Sambuc }
160433d6423SLionel Sambuc #endif				/* ENABLE_3C503 */
161433d6423SLionel Sambuc 
162433d6423SLionel Sambuc /** 3c503.c **/
163