Remove redundant settings. These are the same in /etc/defaults/rc.conf.
[dragonfly.git] / sys / dev / netif / ep / if_ep_eisa.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: src/sys/dev/ep/if_ep_eisa.c,v 1.18 2000/01/14 07:14:00 peter Exp $
23  * $DragonFly: src/sys/dev/netif/ep/if_ep_eisa.c,v 1.14 2008/08/17 04:32:33 sephe Exp $
24  */
25
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/module.h>
31 #include <sys/bus.h>
32 #include <sys/rman.h> 
33 #include <sys/interrupt.h>
34
35 #include <net/if.h>
36 #include <net/if_arp.h>
37 #include <net/if_media.h> 
38
39 #include <machine/clock.h>
40
41 #include <bus/eisa/eisaconf.h>
42
43 #include "if_epreg.h"
44 #include "if_epvar.h"
45
46 #define EISA_DEVICE_ID_3COM_3C509_TP    0x506d5090
47 #define EISA_DEVICE_ID_3COM_3C509_BNC   0x506d5091
48 #define EISA_DEVICE_ID_3COM_3C579_TP    0x506d5092
49 #define EISA_DEVICE_ID_3COM_3C579_BNC   0x506d5093
50 #define EISA_DEVICE_ID_3COM_3C509_COMBO 0x506d5094
51 #define EISA_DEVICE_ID_3COM_3C509_TPO   0x506d5095
52
53 #define EP_EISA_SLOT_OFFSET             0x0c80
54 #define EP_EISA_IOSIZE                  0x000a
55
56 #define EISA_IOCONF                     0x0008
57 #define         IRQ_CHANNEL             0xf000
58 #define                 INT_3           0x3000
59 #define                 INT_5           0x5000
60 #define                 INT_7           0x7000
61 #define                 INT_9           0x9000
62 #define                 INT_10          0xa000
63 #define                 INT_11          0xb000
64 #define                 INT_12          0xc000
65 #define                 INT_15          0xf000
66 #define EISA_BPROM_MEDIA_CONF           0x0006
67 #define         TRANS_TYPE              0xc000
68 #define                 TRANS_TP        0x0000
69 #define                 TRANS_AUI       0x4000
70 #define                 TRANS_BNC       0xc000
71
72 static const char *ep_match (eisa_id_t type);
73
74 static const char*
75 ep_match(eisa_id_t type)
76 {
77         switch(type) {
78                 case EISA_DEVICE_ID_3COM_3C509_TP:
79                         return "3Com 3C509-TP Network Adapter";
80                         break;
81                 case EISA_DEVICE_ID_3COM_3C509_BNC:
82                         return "3Com 3C509-BNC Network Adapter";
83                         break;
84                 case EISA_DEVICE_ID_3COM_3C579_TP:
85                         return "3Com 3C579-TP EISA Network Adapter";
86                         break;
87                 case EISA_DEVICE_ID_3COM_3C579_BNC:
88                         return "3Com 3C579-BNC EISA Network Adapter";
89                         break;
90                 case EISA_DEVICE_ID_3COM_3C509_COMBO:
91                         return "3Com 3C509-Combo Network Adapter";
92                         break;
93                 case EISA_DEVICE_ID_3COM_3C509_TPO:
94                         return "3Com 3C509-TPO Network Adapter";
95                         break;
96                 default:
97                         break;
98         }
99         return (NULL);
100 }
101
102 static int
103 ep_eisa_probe(device_t dev)
104 {
105         const char *desc;
106         u_long iobase;
107         u_short conf;
108         u_long port;
109         int irq;
110         int int_trig;
111
112         desc = ep_match(eisa_get_id(dev));
113         if (!desc)
114                 return (ENXIO);
115         device_set_desc(dev, desc);
116
117         port = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
118         iobase = port + EP_EISA_SLOT_OFFSET;
119
120         /* We must be in EISA configuration mode */
121         if ((inw(iobase + EP_W0_ADDRESS_CFG) & 0x1f) != 0x1f)
122             return ENXIO;
123
124         eisa_add_iospace(dev, iobase, EP_EISA_IOSIZE, RESVADDR_NONE);
125         eisa_add_iospace(dev, port, EP_IOSIZE, RESVADDR_NONE);
126
127         conf = inw(iobase + EISA_IOCONF);
128         /* Determine our IRQ */
129         switch (conf & IRQ_CHANNEL) {
130         case INT_3:
131             irq = 3;
132             break;
133         case INT_5:
134             irq = 5;
135             break;
136         case INT_7:
137             irq = 7;
138             break;
139         case INT_9:
140             irq = 9;
141             break;
142         case INT_10:
143             irq = 10;
144             break;
145         case INT_11:
146             irq = 11;
147             break;
148         case INT_12:
149             irq = 12;
150             break;
151         case INT_15:
152             irq = 15;
153             break;
154         default:
155                                 /* Disabled */
156             device_printf(dev, "3COM Network Adapter at "
157                           "slot %d has its IRQ disabled. "
158                           "Probe failed.\n", 
159                           eisa_get_slot(dev));
160             return ENXIO;
161         }
162
163         switch(eisa_get_id(dev)) {
164                 case EISA_DEVICE_ID_3COM_3C579_BNC:
165                 case EISA_DEVICE_ID_3COM_3C579_TP:
166                         int_trig = EISA_TRIGGER_LEVEL;
167                         break;
168                 default:
169                         int_trig = EISA_TRIGGER_EDGE;
170                         break;
171         }
172                         
173         eisa_add_intr(dev, irq, int_trig);
174
175         return 0;
176 }
177
178 static int
179 ep_eisa_attach(device_t dev)
180 {
181         struct ep_softc *       sc = device_get_softc(dev);
182         struct ifnet *          ifp = &sc->arpcom.ac_if;
183         struct resource *       eisa_io = NULL;
184         u_int32_t               eisa_iobase;
185         int                     irq;
186         int                     error = 0;
187         int                     rid;
188
189         rid = 1;
190         eisa_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
191         if (!eisa_io) {
192                 device_printf(dev, "No I/O space?!\n");
193                 error = ENXIO;
194                 goto bad;
195         }
196         eisa_iobase = rman_get_start(eisa_io);
197
198         /* Reset and Enable the card */
199         outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_RESET_ADAPTER);
200         DELAY(1000); /* we must wait at least 1 ms */
201         outb(eisa_iobase + EP_W0_CONFIG_CTRL, W0_P4_CMD_ENABLE_ADAPTER);
202         /* Now the registers are availible through the lower ioport */
203
204         if ((error = ep_alloc(dev))) {
205                 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
206                 goto bad;
207         }
208
209         switch(eisa_get_id(dev)) {
210                 case EISA_DEVICE_ID_3COM_3C579_BNC:
211                 case EISA_DEVICE_ID_3COM_3C579_TP:
212                         sc->stat = F_ACCESS_32_BITS;
213                         break;
214                 default:
215                         break;
216         }
217
218         ep_get_media(sc);
219
220         irq = rman_get_start(sc->irq);
221         if (irq == 9)
222                 irq = 2;
223
224         GO_WINDOW(0);
225         SET_IRQ(BASE, irq);
226
227         if ((error = ep_attach(sc))) {
228                 device_printf(dev, "ep_attach() failed! (%d)\n", error);
229                 goto bad;
230         }
231
232         error = bus_setup_intr(dev, sc->irq, INTR_MPSAFE,
233                                ep_intr, sc, &sc->ep_intrhand, 
234                                ifp->if_serializer);
235         if (error) {
236                 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
237                 goto bad;
238         }
239
240         ifp->if_cpuid = ithread_cpuid(rman_get_start(sc->irq));
241         KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
242
243         return (0);
244
245  bad:
246         if (eisa_io)
247                 bus_release_resource(dev, SYS_RES_IOPORT, 0, eisa_io);
248
249         ep_free(dev);
250         return (error);
251 }
252
253 static device_method_t ep_eisa_methods[] = {
254         /* Device interface */
255         DEVMETHOD(device_probe,         ep_eisa_probe),
256         DEVMETHOD(device_attach,        ep_eisa_attach),
257
258         { 0, 0 }
259 };
260
261 static driver_t ep_eisa_driver = {
262         "ep",
263         ep_eisa_methods,
264         sizeof(struct ep_softc),
265 };
266
267 extern devclass_t ep_devclass;
268
269 DRIVER_MODULE(if_ep, eisa, ep_eisa_driver, ep_devclass, 0, 0);