xref: /minix/minix/drivers/net/dp8390/3c503.c (revision 35b65c5a)
1 /*
2  *	3c503.c		A shared memory driver for Etherlink II board.
3  *
4  *	Created:	Dec. 20, 1996 by G. Falzoni <falzoni@marina.scn.de>
5  *
6  *	Inspired by the TNET package by M. Ostrowski, the driver for Linux
7  *	by D. Becker, the Crynwr 3c503 packet driver, and the Amoeba driver.
8  *
9  *	It works in shared memory mode and should be used with the
10  *	device driver for NS 8390 based cards of Minix.  Programmed
11  *	I/O could be used as well but would result in poor performance.
12  */
13 
14 #include <minix/drivers.h>
15 #include <minix/netdriver.h>
16 
17 #include "local.h"
18 #include "dp8390.h"
19 #include "3c503.h"
20 
21 #if ENABLE_3C503
22 
23 extern u32_t system_hz;
24 
25 #define MILLIS_TO_TICKS(m)  (((m)*system_hz/1000)+1)
26 
27 static void el2_init(dpeth_t *dep);
28 static void el2_stop(dpeth_t *dep);
29 
30 /*===========================================================================*
31  *				el2_init				     *
32  *===========================================================================*/
33 static void el2_init(dep)
34 dpeth_t * dep;
35 {
36   /* Initalize hardware and data structures. */
37   int ix, irq;
38   int sendq_nr;
39   int cntr;
40 
41   /* Map the address PROM to lower I/O address range */
42   cntr = inb_el2(dep, EL2_CNTR);
43   outb_el2(dep, EL2_CNTR, cntr | ECNTR_SAPROM);
44 
45   /* Read station address from PROM */
46   for (ix = EL2_EA0; ix <= EL2_EA5; ix += 1)
47 	dep->de_address.na_addr[ix] = inb_el2(dep, ix);
48 
49   /* Map the 8390 back to lower I/O address range */
50   outb_el2(dep, EL2_CNTR, cntr);
51 
52   /* Enable memory, but turn off interrupts until we are ready */
53   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
54 
55   dep->de_data_port = dep->de_dp8390_port = dep->de_base_port;
56   dep->de_prog_IO = 0;		/* Programmed I/O not yet available */
57 
58   /* Check width of data bus:
59    * 1. Write 0 to WTS bit.  The board will drive it to 1 if it is a
60    *    16-bit card.
61    * 2. Select page 2
62    * 3. See if it is a 16-bit card
63    * 4. Select page 0
64    */
65   outb_el2(dep, DP_CR, CR_PS_P0|CR_DM_ABORT|CR_STP);
66   outb_el2(dep, DP_DCR, 0);
67   outb_el2(dep, DP_CR, CR_PS_P2|CR_DM_ABORT|CR_STP);
68   dep->de_16bit = (inb_el2(dep, DP_DCR) & DCR_WTS) != 0;
69   outb_el2(dep, DP_CR, CR_PS_P0|CR_DM_ABORT|CR_STP);
70 
71   /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
72   sendq_nr = (dep->de_ramsize - dep->de_offset_page) / 0x2000;
73   if (sendq_nr < 1)
74 	sendq_nr = 1;
75   else if (sendq_nr > SENDQ_NR)
76 	sendq_nr = SENDQ_NR;
77 
78   dep->de_sendq_nr = sendq_nr;
79   for (ix = 0; ix < sendq_nr; ix++)
80 	dep->de_sendq[ix].sq_sendpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
81 
82   dep->de_startpage = (ix * SENDQ_PAGES) + EL2_SM_START_PG;
83   dep->de_stoppage = EL2_SM_STOP_PG;
84 
85   outb_el2(dep, EL2_STARTPG, dep->de_startpage);
86   outb_el2(dep, EL2_STOPPG, dep->de_stoppage);
87 
88   /* Point the vector pointer registers somewhere ?harmless?. */
89   outb_el2(dep, EL2_VP2, 0xFF);	/* Point at the ROM restart location    */
90   outb_el2(dep, EL2_VP1, 0xFF);	/* 0xFFFF:0000  (from original sources) */
91   outb_el2(dep, EL2_VP0, 0x00);	/*           - What for protected mode? */
92 
93   /* Set interrupt level for 3c503 */
94   irq = (dep->de_irq &= ~DEI_DEFAULT);	/* Strip the default flag. */
95   if (irq == 9) irq = 2;
96   if (irq < 2 || irq > 5) panic("bad 3c503 irq configuration: %d", irq);
97   outb_el2(dep, EL2_IDCFG, (0x04 << irq));
98 
99   outb_el2(dep, EL2_DRQCNT, 0x08);	/* Set burst size to 8 */
100   outb_el2(dep, EL2_DMAAH, EL2_SM_START_PG);	/* Put start of TX  */
101   outb_el2(dep, EL2_DMAAL, 0x00);	/* buffer in the GA DMA reg */
102 
103   outb_el2(dep, EL2_CFGR, ECFGR_NORM);	/* Enable shared memory */
104 
105   if (!debug) {
106 	printf("%s: 3c503 at %X:%d:%lX\n",
107 		netdriver_name(), dep->de_base_port, dep->de_irq,
108 		dep->de_linmem + dep->de_offset_page);
109   } else {
110 	printf("%s: 3Com Etherlink II %sat I/O address 0x%X, "
111 			"memory address 0x%lX, irq %d\n",
112 		netdriver_name(), dep->de_16bit ? "(16-bit) " : "",
113 		dep->de_base_port,
114 		dep->de_linmem + dep->de_offset_page,
115 		dep->de_irq);
116   }
117 }
118 
119 /*===========================================================================*
120  *				el2_stop				     *
121  *===========================================================================*/
122 static void el2_stop(dep)
123 dpeth_t * dep;
124 {
125   /* Stops board by disabling interrupts. */
126 
127 #if DEBUG
128   printf("%s: stopping Etherlink\n", netdriver_name());
129 #endif
130   outb_el2(dep, EL2_CFGR, ECFGR_IRQOFF);
131   return;
132 }
133 
134 /*===========================================================================*
135  *				el2_probe				     *
136  *===========================================================================*/
137 int el2_probe(dep)
138 dpeth_t * dep;
139 {
140   /* Probe for the presence of an EtherLink II card.  Initialize memory
141    * addressing if card detected.
142    */
143   int iobase, membase;
144   int thin;
145 
146   /* Thin ethernet or AUI? */
147   thin = (dep->de_linmem & 1) ? ECNTR_AUI : ECNTR_THIN;
148 
149   /* Location registers should have 1 bit set */
150   if (!(iobase = inb_el2(dep, EL2_IOBASE))) return 0;
151   if (!((membase = inb_el2(dep, EL2_MEMBASE)) & 0xF0)) return 0;
152   if ((iobase & (iobase - 1)) || (membase & (membase - 1))) return 0;
153 
154   /* Resets board */
155   outb_el2(dep, EL2_CNTR, ECNTR_RESET | thin);
156   micro_delay(1000);
157   outb_el2(dep, EL2_CNTR, thin);
158   micro_delay(5000);
159 
160   /* Map the address PROM to lower I/O address range */
161   outb_el2(dep, EL2_CNTR, ECNTR_SAPROM | thin);
162   if (inb_el2(dep, EL2_EA0) != 0x02 ||	/* Etherlink II Station address */
163       inb_el2(dep, EL2_EA1) != 0x60 ||	/* MUST be 02:60:8c:xx:xx:xx */
164       inb_el2(dep, EL2_EA2) != 0x8C)
165 	return 0;		/* No Etherlink board at this address */
166 
167   /* Map the 8390 back to lower I/O address range */
168   outb_el2(dep, EL2_CNTR, thin);
169 
170   /* Setup shared memory addressing for 3c503 */
171   dep->de_linmem = ((membase & 0xC0) ? EL2_BASE_0D8000 : EL2_BASE_0C8000) +
172 	((membase & 0xA0) ? (EL2_BASE_0CC000 - EL2_BASE_0C8000) : 0x0000);
173   dep->de_offset_page = (EL2_SM_START_PG * DP_PAGESIZE);
174   dep->de_ramsize = (EL2_SM_STOP_PG - EL2_SM_START_PG) * DP_PAGESIZE;
175 
176   /* (Bad kludge, something Philip needs to look into. -- kjb) */
177   dep->de_linmem -= dep->de_offset_page;
178   dep->de_ramsize += dep->de_offset_page;
179 
180   /* Board initialization and stop functions */
181   dep->de_initf = el2_init;
182   dep->de_stopf = el2_stop;
183   return 1;
184 }
185 
186 #endif /* ENABLE_3C503 */
187 
188 /** 3c503.c **/
189 
190 /*
191  * $PchId: 3c503.c,v 1.3 2003/09/10 15:33:04 philip Exp $
192  */
193