1119418Sobrien/*-
215813Sse * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
315813Sse * All rights reserved.
415813Sse *
515813Sse * Redistribution and use in source and binary forms, with or without
615813Sse * modification, are permitted provided that the following conditions
715813Sse * are met:
815813Sse * 1. Redistributions of source code must retain the above copyright
915813Sse *    notice immediately at the beginning of the file, without modification,
1015813Sse *    this list of conditions, and the following disclaimer.
1115813Sse * 2. Redistributions in binary form must reproduce the above copyright
1215813Sse *    notice, this list of conditions and the following disclaimer in the
1315813Sse *    documentation and/or other materials provided with the distribution.
1415813Sse * 3. Absolutely no warranty of function or purpose is made by the author
1515813Sse *    Stefan Esser.
1615813Sse * 4. Modifications may be freely made to this file if the above conditions
1715813Sse *    are met.
1815813Sse */
1915813Sse
20119418Sobrien#include <sys/cdefs.h>
21119418Sobrien__FBSDID("$FreeBSD$");
22119418Sobrien
2315813Sse#include <sys/param.h>
2473374Simp#include <sys/systm.h>
2550852Speter#include <sys/socket.h>
2615813Sse#include <sys/kernel.h>
2752247Smdodd
2850852Speter#include <sys/module.h>
2950852Speter#include <sys/bus.h>
3052247Smdodd
3150852Speter#include <machine/bus.h>
3252247Smdodd#include <sys/rman.h>
3352247Smdodd#include <machine/resource.h>
3450852Speter
3550852Speter#include <net/if.h>
3650852Speter#include <net/if_arp.h>
37149558Simp#include <net/if_media.h>
3850852Speter#include <net/if_mib.h>
3915813Sse
40119277Simp#include <dev/pci/pcireg.h>
41119277Simp#include <dev/pci/pcivar.h>
4252247Smdodd
4351442Speter#include <dev/ed/if_edvar.h>
44150957Simp#include <dev/ed/rtl80x9reg.h>
4550852Speter
4624995Sdavidnstatic struct _pcsid
4724995Sdavidn{
48140468Simp	uint32_t	type;
4950852Speter	const char	*desc;
5024995Sdavidn} pci_ids[] =
5124995Sdavidn{
52211792Simp	{ 0x140111f6, "Compex RL2000" },
53211792Simp	{ 0x005812c3, "Holtek HT80232" },
54211792Simp	{ 0x30008e2e, "KTI ET32P2" },
55175007Simp	{ 0x50004a14, "NetVin NV5000SC" },
56150102Simp	{ 0x09401050, "ProLAN" },
57211792Simp	{ ED_RTL8029_PCI_ID, "RealTek 8029" }, /* Needs realtek full duplex */
58211792Simp	{ 0x0e3410bd, "Surecom NE-34" },
59211792Simp	{ 0x09261106, "VIA VT86C926" },
60150102Simp	{ 0x19808c4a, "Winbond W89C940" },
61175007Simp	{ 0x5a5a1050, "Winbond W89C940F" },
62175007Simp#if 0
63211792Simp	/* some Holtek needs special lovin', disabled by default */
64211792Simp	/* The Holtek can report/do full duplex, but that's unimplemented */
65175007Simp	{ 0x559812c3, "Holtek HT80229" },	/* Only 32-bit I/O, Holtek fdx, STOP_PG_60? */
66175007Simp#endif
67150102Simp	{ 0x00000000, NULL }
6824995Sdavidn};
6915813Sse
70130657Simpstatic int	ed_pci_probe(device_t);
71130657Simpstatic int	ed_pci_attach(device_t);
7216289Salex
7350852Speterstatic int
74130659Simped_pci_probe(device_t dev)
7515813Sse{
76140468Simp	uint32_t	type = pci_get_devid(dev);
7724995Sdavidn	struct _pcsid	*ep =pci_ids;
7824995Sdavidn
7924995Sdavidn	while (ep->type && ep->type != type)
8024995Sdavidn		++ep;
81143161Simp	if (ep->desc == NULL)
82143161Simp		return (ENXIO);
83143161Simp	device_set_desc(dev, ep->desc);
84143161Simp	return (BUS_PROBE_DEFAULT);
8515813Sse}
8615813Sse
8750852Speterstatic int
8850852Spetered_pci_attach(device_t dev)
8915813Sse{
90147184Simp	struct	ed_softc *sc = device_get_softc(dev);
91151300Simp	int	error = ENXIO;
9252247Smdodd
93151300Simp	/*
94190794Simp	 * Probe RTL8029 cards, but allow failure and try as a generic
95190794Simp	 * ne-2000.  QEMU 0.9 and earlier use the RTL8029 PCI ID, but
96190794Simp	 * are areally just generic ne-2000 cards.
97151300Simp	 */
98150957Simp	if (pci_get_devid(dev) == ED_RTL8029_PCI_ID)
99211792Simp		error = ed_probe_RTL80x9(dev, PCIR_BAR(0), 0);
100151300Simp	if (error)
101211792Simp		error = ed_probe_Novell(dev, PCIR_BAR(0),
102211792Simp		    ED_FLAGS_FORCE_16BIT_MODE);
103147184Simp	if (error) {
104147184Simp		ed_release_resources(dev);
105147184Simp		return (error);
106141577Simp	}
107147149Simp	ed_Novell_read_mac(sc);
10852247Smdodd
109147184Simp	error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
110147184Simp	if (error) {
111147184Simp		ed_release_resources(dev);
112147184Simp		return (error);
113147184Simp	}
114191234Simp	if (sc->sc_media_ioctl == NULL)
115191234Simp		ed_gen_ifmedia_init(sc);
116191234Simp	error = ed_attach(dev);
117147184Simp	if (error) {
118147184Simp		ed_release_resources(dev);
119147184Simp		return (error);
120147184Simp	}
121191234Simp	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
122191234Simp	    NULL, edintr, sc, &sc->irq_handle);
123147184Simp	if (error)
124147184Simp		ed_release_resources(dev);
12552247Smdodd	return (error);
12650852Speter}
12715813Sse
12850852Speterstatic device_method_t ed_pci_methods[] = {
12950852Speter	/* Device interface */
13050852Speter	DEVMETHOD(device_probe,		ed_pci_probe),
13150852Speter	DEVMETHOD(device_attach,	ed_pci_attach),
132150136Sru	DEVMETHOD(device_detach,	ed_detach),
13315813Sse
13450852Speter	{ 0, 0 }
13550852Speter};
13615813Sse
13750852Speterstatic driver_t ed_pci_driver = {
13850852Speter	"ed",
13950852Speter	ed_pci_methods,
14050852Speter	sizeof(struct ed_softc),
14150852Speter};
14215813Sse
143113506SmdoddDRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
144113506SmdoddMODULE_DEPEND(ed, pci, 1, 1, 1);
145113506SmdoddMODULE_DEPEND(ed, ether, 1, 1, 1);
146292081SimpMODULE_PNP_INFO("W32:vendor/device;D:human", pci, ed, pci_ids, sizeof(pci_ids[0]),
147298307Spfg    nitems(pci_ids) - 1);
148292081Simp
149