kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / dev / netif / vx / if_vx_pci.c
1 /*
2  * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/dev/vx/if_vx_pci.c,v 1.20 2000/01/29 14:50:32 peter Exp $
30  * $DragonFly: src/sys/dev/netif/vx/if_vx_pci.c,v 1.3 2003/08/07 21:17:06 dillon Exp $
31  */
32
33 #include "use_vx.h"
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/eventhandler.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
40
41 #include <net/if.h>
42 #include <net/if_arp.h>
43
44 #include <bus/pci/pcivar.h>
45
46 #include "if_vxreg.h"
47
48 static void vx_pci_shutdown(void *, int);
49 static const char *vx_pci_probe(pcici_t, pcidi_t);
50 static void vx_pci_attach(pcici_t, int unit);
51
52 static void
53 vx_pci_shutdown(
54         void *sc,
55         int howto)
56 {
57    vxstop(sc); 
58    vxfree(sc);
59 }
60
61 static const char*
62 vx_pci_probe(
63         pcici_t config_id,
64         pcidi_t device_id)
65 {
66    if(device_id == 0x590010b7ul)
67       return "3COM 3C590 Etherlink III PCI";
68    if(device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
69         device_id == 0x595210b7ul)
70       return "3COM 3C595 Fast Etherlink III PCI";
71         /*
72          * The (Fast) Etherlink XL adapters are now supported by
73          * the xl driver, which uses bus master DMA and is much
74          * faster. (And which also supports the 3c905B.
75          */
76 #ifdef VORTEX_ETHERLINK_XL
77    if(device_id == 0x900010b7ul || device_id == 0x900110b7ul)
78       return "3COM 3C900 Etherlink XL PCI";
79    if(device_id == 0x905010b7ul || device_id == 0x905110b7ul)
80       return "3COM 3C905 Fast Etherlink XL PCI";
81 #endif
82    return NULL;
83 }
84
85 static void
86 vx_pci_attach(
87         pcici_t config_id,
88         int unit)
89 {
90     struct vx_softc *sc;
91
92     if (unit >= NVX) {
93        printf("vx%d: not configured; kernel is built for only %d device%s.\n",
94           unit, NVX, NVX == 1 ? "" : "s"); 
95        return;
96     }
97
98     if ((sc = vxalloc(unit)) == NULL) {
99         return;
100     }
101
102     sc->vx_io_addr = pci_conf_read(config_id, 0x10) & 0xffffffe0;
103
104     if (vxattach(sc) == 0) {
105         return;
106     }
107
108     /* defect check for 3C590 */
109     if ((pci_conf_read(config_id, 0) >> 16) == 0x5900) {
110         GO_WINDOW(0);
111         if (vxbusyeeprom(sc))
112             return;
113         outw(BASE + VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD | EEPROM_SOFT_INFO_2);
114         if (vxbusyeeprom(sc))
115             return;
116         if (!(inw(BASE + VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) {
117             printf("Warning! Defective early revision adapter!\n");
118         }
119     }
120
121     /*
122      * Add shutdown hook so that DMA is disabled prior to reboot. Not
123      * doing do could allow DMA to corrupt kernel memory during the
124      * reboot before the driver initializes.
125      */
126     EVENTHANDLER_REGISTER(shutdown_post_sync, vx_pci_shutdown, sc,
127                           SHUTDOWN_PRI_DEFAULT);
128
129     pci_map_int(config_id, vxintr, (void *) sc, &net_imask);
130 }
131
132 static struct pci_device vxdevice = {
133     "vx",
134     vx_pci_probe,
135     vx_pci_attach,
136     &vx_count,
137     NULL
138 };
139
140 COMPAT_PCI_DRIVER (vx, vxdevice);