if_ed_pci.c revision 52247
115813Sse/*
215813Sse *
315813Sse * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
415813Sse * All rights reserved.
515813Sse *
615813Sse * Redistribution and use in source and binary forms, with or without
715813Sse * modification, are permitted provided that the following conditions
815813Sse * are met:
915813Sse * 1. Redistributions of source code must retain the above copyright
1015813Sse *    notice immediately at the beginning of the file, without modification,
1115813Sse *    this list of conditions, and the following disclaimer.
1215813Sse * 2. Redistributions in binary form must reproduce the above copyright
1315813Sse *    notice, this list of conditions and the following disclaimer in the
1415813Sse *    documentation and/or other materials provided with the distribution.
1515813Sse * 3. Absolutely no warranty of function or purpose is made by the author
1615813Sse *    Stefan Esser.
1715813Sse * 4. Modifications may be freely made to this file if the above conditions
1815813Sse *    are met.
1915813Sse *
2050477Speter * $FreeBSD: head/sys/dev/ed/if_ed_pci.c 52247 1999-10-15 03:12:48Z mdodd $
2115813Sse */
2215813Sse
2351442Speter#include "card.h"
2451442Speter#if NCARD == 0
2551442Speter
2615813Sse#include <sys/param.h>
2715813Sse#include <sys/systm.h>
2850852Speter#include <sys/socket.h>
2915813Sse#include <sys/kernel.h>
3052247Smdodd
3150852Speter#include <sys/module.h>
3250852Speter#include <sys/bus.h>
3352247Smdodd
3450852Speter#include <machine/bus.h>
3552247Smdodd#include <sys/rman.h>
3652247Smdodd#include <machine/resource.h>
3750852Speter
3850852Speter#include <net/if.h>
3950852Speter#include <net/if_arp.h>
4050852Speter#include <net/if_mib.h>
4115813Sse
4252247Smdodd#include <pci/pcireg.h>
4352247Smdodd#include <pci/pcivar.h>
4452247Smdodd
4551442Speter#include <dev/ed/if_edvar.h>
4650852Speter
4724995Sdavidnstatic struct _pcsid
4824995Sdavidn{
4950852Speter	u_int32_t	type;
5050852Speter	const char	*desc;
5124995Sdavidn} pci_ids[] =
5224995Sdavidn{
5324995Sdavidn	{ 0x802910ec,	"NE2000 PCI Ethernet (RealTek 8029)"	},
5428210Sdanny	{ 0x50004a14,	"NE2000 PCI Ethernet (NetVin 5000)"	},
5524995Sdavidn	{ 0x09401050,	"NE2000 PCI Ethernet (ProLAN)"		},
5624995Sdavidn	{ 0x140111f6,	"NE2000 PCI Ethernet (Compex)"		},
5724995Sdavidn	{ 0x30008e2e,	"NE2000 PCI Ethernet (KTI)"		},
5831347Smsmith	{ 0x19808c4a,	"NE2000 PCI Ethernet (Winbond W89C940)" },
5933893Sse	{ 0x0e3410bd,	"NE2000 PCI Ethernet (Surecom NE-34)"	},
6034645Sdanny	{ 0x09261106,	"NE2000 PCI Ethernet (VIA VT86C926)"	},
6124995Sdavidn	{ 0x00000000,	NULL					}
6224995Sdavidn};
6315813Sse
6452247Smdoddstatic int	ed_pci_probe	__P((device_t));
6552247Smdoddstatic int	ed_pci_attach	__P((device_t));
6616289Salex
6750852Speterstatic int
6850852Spetered_pci_probe (device_t dev)
6915813Sse{
7050852Speter	u_int32_t	type = pci_get_devid(dev);
7124995Sdavidn	struct _pcsid	*ep =pci_ids;
7224995Sdavidn
7324995Sdavidn	while (ep->type && ep->type != type)
7424995Sdavidn		++ep;
7550852Speter	if (ep->desc) {
7650852Speter		device_set_desc(dev, ep->desc);
7750852Speter		return 0;
7850852Speter	} else {
7950852Speter		return ENXIO;
8050852Speter	}
8115813Sse}
8215813Sse
8350852Speterstatic int
8450852Spetered_pci_attach(device_t dev)
8515813Sse{
8652247Smdodd        struct ed_softc *sc = device_get_softc(dev);
8752247Smdodd        int flags = 0;
8852247Smdodd        int error;
8952247Smdodd
9052247Smdodd        error = ed_probe_Novell_generic(dev, PCIR_MAPS, flags);
9152247Smdodd        if (error)
9252247Smdodd                return (error);
9352247Smdodd
9452247Smdodd        error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
9552247Smdodd        if (error) {
9652247Smdodd                ed_release_resources(dev);
9752247Smdodd                return (error);
9852247Smdodd        }
9952247Smdodd
10052247Smdodd        error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
10152247Smdodd                               edintr, sc, &sc->irq_handle);
10252247Smdodd        if (error) {
10352247Smdodd                ed_release_resources(dev);
10452247Smdodd                return (error);
10552247Smdodd        }
10652247Smdodd
10752247Smdodd	error = ed_attach(sc, device_get_unit(dev), flags);
10852247Smdodd
10952247Smdodd	return (error);
11050852Speter}
11115813Sse
11250852Speterstatic device_method_t ed_pci_methods[] = {
11350852Speter	/* Device interface */
11450852Speter	DEVMETHOD(device_probe,		ed_pci_probe),
11550852Speter	DEVMETHOD(device_attach,	ed_pci_attach),
11615813Sse
11750852Speter	{ 0, 0 }
11850852Speter};
11915813Sse
12050852Speterstatic driver_t ed_pci_driver = {
12150852Speter	"ed",
12250852Speter	ed_pci_methods,
12350852Speter	sizeof(struct ed_softc),
12450852Speter};
12515813Sse
12650852Speterstatic devclass_t ed_devclass;
12750852Speter
12850852SpeterDRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
12951442Speter#endif
130