if_vx_pci.c revision 32350
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 */
30
31#include "pci.h"
32#if NPCI > 0
33
34#include "vx.h"
35#if NVX > 0
36#include "opt_inet.h"
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/kernel.h>
41#include <sys/socket.h>
42
43#include <net/ethernet.h>
44#include <net/if.h>
45#include <net/if_arp.h>
46
47#ifdef INET
48#include <netinet/in.h>
49#include <netinet/if_ether.h>
50#endif
51
52
53#ifdef NS
54#include <netns/ns.h>
55#include <netns/ns_if.h>
56#endif
57
58#include <pci/pcivar.h>
59
60#include <dev/vx/if_vxreg.h>
61
62static void vx_pci_shutdown(int, void *);
63static char *vx_pci_probe(pcici_t, pcidi_t);
64static void vx_pci_attach(pcici_t, int unit);
65
66static void
67vx_pci_shutdown(
68	int howto,
69	void *sc)
70{
71   vxstop(sc);
72   vxfree(sc);
73}
74
75static char*
76vx_pci_probe(
77	pcici_t config_id,
78	pcidi_t device_id)
79{
80   if(device_id == 0x590010b7ul)
81      return "3COM 3C590 Etherlink III PCI";
82   if(device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
83	device_id == 0x595210b7ul)
84      return "3COM 3C595 Fast Etherlink III PCI";
85   if(device_id == 0x900010b7ul || device_id == 0x900110b7ul)
86      return "3COM 3C900 Etherlink XL PCI";
87   if(device_id == 0x905010b7ul || device_id == 0x905110b7ul)
88      return "3COM 3C905 Fast Etherlink XL PCI";
89   return NULL;
90}
91
92static void
93vx_pci_attach(
94	pcici_t config_id,
95	int unit)
96{
97    struct vx_softc *sc;
98
99    if (unit >= NVX) {
100       printf("vx%d: not configured; kernel is built for only %d device%s.\n",
101          unit, NVX, NVX == 1 ? "" : "s");
102       return;
103    }
104
105    sc = vxalloc(unit);
106
107    sc->vx_io_addr = pci_conf_read(config_id, 0x10) & 0xffffffe0;
108
109    if (vxattach(sc) == 0) {
110	return;
111    }
112
113    /* defect check for 3C590 */
114    if ((pci_conf_read(config_id, 0) >> 16) == 0x5900) {
115	GO_WINDOW(0);
116	if (vxbusyeeprom(sc))
117	    return;
118	outw(BASE + VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD | EEPROM_SOFT_INFO_2);
119	if (vxbusyeeprom(sc))
120	    return;
121	if (!(inw(BASE + VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) {
122	    printf("Warning! Defective early revision adapter!\n");
123	}
124    }
125
126    /*
127     * Add shutdown hook so that DMA is disabled prior to reboot. Not
128     * doing do could allow DMA to corrupt kernel memory during the
129     * reboot before the driver initializes.
130     */
131    at_shutdown(vx_pci_shutdown, sc, SHUTDOWN_POST_SYNC);
132
133    pci_map_int(config_id, vxintr, (void *) sc, &net_imask);
134}
135
136static struct pci_device vxdevice = {
137    "vx",
138    vx_pci_probe,
139    vx_pci_attach,
140    &vx_count,
141    NULL
142};
143
144DATA_SET (pcidevice_set, vxdevice);
145
146#endif	/* NVX */
147#endif	/* NPCI */
148