FreeBSD/Linux Kernel Cross Reference
sys/i386/eisa/3c5x9.c
1 /*
2 * Product specific probe and attach routines for:
3 * 3COM 3C579 and 3C509(in eisa config mode) ethernet controllers
4 *
5 * Copyright (c) 1996 Justin T. Gibbs
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Absolutely no warranty of function or purpose is made by the author
18 * Justin T. Gibbs.
19 * 4. Modifications may be freely made to this file if the above conditions
20 * are met.
21 *
22 * $FreeBSD$
23 */
24
25 #include "eisa.h"
26 #if NEISA > 0
27
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32
33 #include <machine/clock.h>
34
35 #include <net/if.h>
36
37 #include <netinet/in.h>
38 #include <netinet/if_ether.h>
39
40 #include <i386/isa/if_epreg.h>
41 #include <i386/eisa/eisaconf.h>
42
43 #define EISA_DEVICE_ID_3COM_3C509_TP 0x506d5090
44 #define EISA_DEVICE_ID_3COM_3C509_BNC 0x506d5091
45 #define EISA_DEVICE_ID_3COM_3C579_TP 0x506d5092
46 #define EISA_DEVICE_ID_3COM_3C579_BNC 0x506d5093
47 #define EISA_DEVICE_ID_3COM_3C509_COMBO 0x506d5094
48 #define EISA_DEVICE_ID_3COM_3C509_TPO 0x506d5095
49
50 #define EP_EISA_SLOT_OFFSET 0x0c80
51 #define EP_EISA_IOSIZE 0x000a
52
53 #define EISA_IOCONF 0x0008
54 #define IRQ_CHANNEL 0xf000
55 #define INT_3 0x3000
56 #define INT_5 0x5000
57 #define INT_7 0x7000
58 #define INT_9 0x9000
59 #define INT_10 0xa000
60 #define INT_11 0xb000
61 #define INT_12 0xc000
62 #define INT_15 0xf000
63 #define EISA_BPROM_MEDIA_CONF 0x0006
64 #define TRANS_TYPE 0xc000
65 #define TRANS_TP 0x0000
66 #define TRANS_AUI 0x4000
67 #define TRANS_BNC 0xc000
68
69 static int ep_eisa_probe __P((void));
70 static int ep_eisa_attach __P((struct eisa_device *e_dev));
71
72 static struct eisa_driver ep_eisa_driver = {
73 "ep",
74 ep_eisa_probe,
75 ep_eisa_attach,
76 /*shutdown*/NULL,
77 &ep_unit
78 };
79
80 DATA_SET (eisadriver_set, ep_eisa_driver);
81
82 static const char *ep_match __P((eisa_id_t type));
83
84 static const char*
85 ep_match(type)
86 eisa_id_t type;
87 {
88 switch(type) {
89 case EISA_DEVICE_ID_3COM_3C509_TP:
90 return "3Com 3C509-TP Network Adapter";
91 break;
92 case EISA_DEVICE_ID_3COM_3C509_BNC:
93 return "3Com 3C509-BNC Network Adapter";
94 break;
95 case EISA_DEVICE_ID_3COM_3C579_TP:
96 return "3Com 3C579-TP EISA Network Adapter";
97 break;
98 case EISA_DEVICE_ID_3COM_3C579_BNC:
99 return "3Com 3C579-BNC EISA Network Adapter";
100 break;
101 case EISA_DEVICE_ID_3COM_3C509_COMBO:
102 return "3Com 3C509-Combo Network Adapter";
103 break;
104 case EISA_DEVICE_ID_3COM_3C509_TPO:
105 return "3Com 3C509-TPO Network Adapter";
106 break;
107 default:
108 break;
109 }
110 return (NULL);
111 }
112
113 static int
114 ep_eisa_probe(void)
115 {
116 u_long iobase;
117 struct eisa_device *e_dev = NULL;
118 int count;
119
120 count = 0;
121 while ((e_dev = eisa_match_dev(e_dev, ep_match))) {
122 u_short conf;
123 u_long port;
124 int irq;
125
126 port = (e_dev->ioconf.slot * EISA_SLOT_SIZE);
127 iobase = port + EP_EISA_SLOT_OFFSET;
128
129 /* We must be in EISA configuration mode */
130 if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f)
131 continue;
132
133 eisa_add_iospace(e_dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE);
134 eisa_add_iospace(e_dev, port, EP_IOSIZE, RESVADDR_NONE);
135
136 conf = inw(iobase + EISA_IOCONF);
137 /* Determine our IRQ */
138 switch (conf & IRQ_CHANNEL) {
139 case INT_3:
140 irq = 3;
141 break;
142 case INT_5:
143 irq = 5;
144 break;
145 case INT_7:
146 irq = 7;
147 break;
148 case INT_9:
149 irq = 9;
150 break;
151 case INT_10:
152 irq = 10;
153 break;
154 case INT_11:
155 irq = 11;
156 break;
157 case INT_12:
158 irq = 12;
159 break;
160 case INT_15:
161 irq = 15;
162 break;
163 default:
164 /* Disabled */
165 printf("ep: 3COM Network Adapter at "
166 "slot %d has its IRQ disabled. "
167 "Probe failed.\n",
168 e_dev->ioconf.slot);
169 continue;
170 }
171 eisa_add_intr(e_dev, irq);
172 eisa_registerdev(e_dev, &ep_eisa_driver);
173 count++;
174 }
175 return count;
176 }
177
178 static int
179 ep_eisa_attach(e_dev)
180 struct eisa_device *e_dev;
181 {
182 struct ep_softc *sc;
183 struct ep_board *epb;
184 int unit = e_dev->unit;
185 int irq;
186 resvaddr_t *ioport;
187 resvaddr_t *eisa_ioport;
188 u_char level_intr;
189 int i;
190
191 if (TAILQ_FIRST(&e_dev->ioconf.irqs) == NULL)
192 return -1;
193
194 irq = TAILQ_FIRST(&e_dev->ioconf.irqs)->irq_no;
195 /*
196 * The addresses are sorted in increasing order
197 * so we know the port to pass to the core ep
198 * driver comes first.
199 */
200 ioport = e_dev->ioconf.ioaddrs.lh_first;
201
202 if(!ioport)
203 return -1;
204
205 eisa_ioport = ioport->links.le_next;
206
207 if(!eisa_ioport)
208 return -1;
209
210 eisa_reg_start(e_dev);
211 if(eisa_reg_iospace(e_dev, ioport))
212 return -1;
213
214 if(eisa_reg_iospace(e_dev, eisa_ioport))
215 return -1;
216
217 epb = &ep_board[ep_boards];
218
219 epb->epb_addr = ioport->addr;
220 epb->epb_used = 1;
221
222 if(!(sc = ep_alloc(unit, epb)))
223 return -1;
224
225 ep_boards++;
226
227 sc->stat = 0;
228 level_intr = FALSE;
229 switch(e_dev->id) {
230 case EISA_DEVICE_ID_3COM_3C509_TP:
231 sc->ep_connectors = UTP|AUI;
232 break;
233 case EISA_DEVICE_ID_3COM_3C509_BNC:
234 sc->ep_connectors = BNC|AUI;
235 break;
236 case EISA_DEVICE_ID_3COM_3C579_TP:
237 sc->ep_connectors = UTP|AUI;
238 sc->stat = F_ACCESS_32_BITS;
239 level_intr = TRUE;
240 break;
241 case EISA_DEVICE_ID_3COM_3C579_BNC:
242 sc->ep_connectors = BNC|AUI;
243 sc->stat = F_ACCESS_32_BITS;
244 level_intr = TRUE;
245 break;
246 case EISA_DEVICE_ID_3COM_3C509_COMBO:
247 sc->ep_connectors = UTP|BNC|AUI;
248 break;
249 case EISA_DEVICE_ID_3COM_3C509_TPO:
250 sc->ep_connectors = UTP;
251 break;
252 default:
253 break;
254 }
255 /*
256 * Set the eisa config selected media type
257 */
258 sc->ep_connector = inw(eisa_ioport->addr + EISA_BPROM_MEDIA_CONF)
259 >> ACF_CONNECTOR_BITS;
260
261 if(eisa_reg_intr(e_dev, irq, ep_intr, (void *)sc, &net_imask,
262 /*shared ==*/level_intr)) {
263 ep_free(sc);
264 return -1;
265 }
266 eisa_reg_end(e_dev);
267
268 /* Reset and Enable the card */
269 outb(eisa_ioport->addr + EP_W0_CONFIG_CTRL, W0_P4_CMD_RESET_ADAPTER);
270 DELAY(1000); /* we must wait at least 1 ms */
271 outb(eisa_ioport->addr + EP_W0_CONFIG_CTRL, W0_P4_CMD_ENABLE_ADAPTER);
272
273 /* Now the registers are availible through the lower ioport */
274
275 /*
276 * Retrieve our ethernet address
277 */
278 GO_WINDOW(0);
279 for(i = 0; i < 3; i++)
280 sc->epb->eth_addr[i] = get_e(sc, i);
281
282 /* Even we get irq number from board, we should tell him..
283 Otherwise we never get a H/W interrupt anymore...*/
284 if ( irq == 9 )
285 irq = 2;
286 SET_IRQ(eisa_ioport->addr, irq);
287
288 ep_attach(sc);
289
290 if(eisa_enable_intr(e_dev, irq)) {
291 ep_free(sc);
292 eisa_release_intr(e_dev, irq, ep_intr);
293 return -1;
294 }
295
296 return 0;
297 }
298
299 #endif /* NEISA > 0 */
Cache object: 25b2d70fae4e44c443d0c670a7a9cabb
|