if_vx_pci.c revision 46813
183Sattila/*
283Sattila * Copyright (C) 1996 Naoki Hamada <nao@tom-yam.or.jp>
383Sattila * All rights reserved.
4877Sattila *
583Sattila * Redistribution and use in source and binary forms, with or without
683Sattila * modification, are permitted provided that the following conditions
783Sattila * are met:
8877Sattila * 1. Redistributions of source code must retain the above copyright
983Sattila *    notice, this list of conditions and the following disclaimer.
1083Sattila * 2. Redistributions in binary form must reproduce the above copyright
1183Sattila *    notice, this list of conditions and the following disclaimer in the
1283Sattila *    documentation and/or other materials provided with the distribution.
1383Sattila * 3. Neither the name of the author nor the names of any co-contributors
14877Sattila *    may be used to endorse or promote products derived from this software
1583Sattila *    without specific prior written permission.
1683Sattila *
1783Sattila * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18877Sattila * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1983Sattila * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2083Sattila * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2183Sattila * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2283Sattila * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2383Sattila * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2483Sattila * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2583Sattila * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2683Sattila * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2783Sattila * SUCH DAMAGE.
2883Sattila *
2983Sattila */
3083Sattila
3183Sattila#include "pci.h"
3283Sattila#if NPCI > 0
3383Sattila
3483Sattila#include "vx.h"
3583Sattila#if NVX > 0
3683Sattila
3783Sattila#include <sys/param.h>
3883Sattila#include <sys/systm.h>
3983Sattila#include <sys/kernel.h>
4083Sattila#include <sys/socket.h>
4183Sattila
4283Sattila#include <net/if.h>
4383Sattila#include <net/if_arp.h>
4483Sattila
4583Sattila#include <pci/pcivar.h>
4683Sattila
4783Sattila#include <dev/vx/if_vxreg.h>
4883Sattila
4983Sattilastatic void vx_pci_shutdown(int, void *);
5083Sattilastatic const char *vx_pci_probe(pcici_t, pcidi_t);
5183Sattilastatic void vx_pci_attach(pcici_t, int unit);
5283Sattila
5383Sattilastatic void
5483Sattilavx_pci_shutdown(
5583Sattila	int howto,
5683Sattila	void *sc)
5783Sattila{
5883Sattila   vxstop(sc);
5983Sattila   vxfree(sc);
60}
61
62static const char*
63vx_pci_probe(
64	pcici_t config_id,
65	pcidi_t device_id)
66{
67   if(device_id == 0x590010b7ul)
68      return "3COM 3C590 Etherlink III PCI";
69   if(device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
70	device_id == 0x595210b7ul)
71      return "3COM 3C595 Fast Etherlink III PCI";
72	/*
73	 * The (Fast) Etherlink XL adapters are now supported by
74	 * the xl driver, which uses bus master DMA and is much
75	 * faster. (And which also supports the 3c905B.
76	 */
77#ifdef VORTEX_ETHERLINK_XL
78   if(device_id == 0x900010b7ul || device_id == 0x900110b7ul)
79      return "3COM 3C900 Etherlink XL PCI";
80   if(device_id == 0x905010b7ul || device_id == 0x905110b7ul)
81      return "3COM 3C905 Fast Etherlink XL PCI";
82#endif
83   return NULL;
84}
85
86static void
87vx_pci_attach(
88	pcici_t config_id,
89	int unit)
90{
91    struct vx_softc *sc;
92
93    if (unit >= NVX) {
94       printf("vx%d: not configured; kernel is built for only %d device%s.\n",
95          unit, NVX, NVX == 1 ? "" : "s");
96       return;
97    }
98
99    if ((sc = vxalloc(unit)) == NULL) {
100	return;
101    }
102
103    sc->vx_io_addr = pci_conf_read(config_id, 0x10) & 0xffffffe0;
104
105    if (vxattach(sc) == 0) {
106	return;
107    }
108
109    /* defect check for 3C590 */
110    if ((pci_conf_read(config_id, 0) >> 16) == 0x5900) {
111	GO_WINDOW(0);
112	if (vxbusyeeprom(sc))
113	    return;
114	outw(BASE + VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD | EEPROM_SOFT_INFO_2);
115	if (vxbusyeeprom(sc))
116	    return;
117	if (!(inw(BASE + VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY)) {
118	    printf("Warning! Defective early revision adapter!\n");
119	}
120    }
121
122    /*
123     * Add shutdown hook so that DMA is disabled prior to reboot. Not
124     * doing do could allow DMA to corrupt kernel memory during the
125     * reboot before the driver initializes.
126     */
127    at_shutdown(vx_pci_shutdown, sc, SHUTDOWN_POST_SYNC);
128
129    pci_map_int(config_id, vxintr, (void *) sc, &net_imask);
130}
131
132static struct pci_device vxdevice = {
133    "vx",
134    vx_pci_probe,
135    vx_pci_attach,
136    &vx_count,
137    NULL
138};
139
140COMPAT_PCI_DRIVER (vx, vxdevice);
141
142#endif	/* NVX */
143#endif	/* NPCI */
144