if_ed_pci.c revision 73374
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 73374 2001-03-03 08:31:37Z imp $
2115813Sse */
2215813Sse
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>
3750852Speter#include <net/if_mib.h>
3815813Sse
3952247Smdodd#include <pci/pcireg.h>
4052247Smdodd#include <pci/pcivar.h>
4152247Smdodd
4251442Speter#include <dev/ed/if_edvar.h>
4350852Speter
4424995Sdavidnstatic struct _pcsid
4524995Sdavidn{
4650852Speter	u_int32_t	type;
4750852Speter	const char	*desc;
4824995Sdavidn} pci_ids[] =
4924995Sdavidn{
5024995Sdavidn	{ 0x802910ec,	"NE2000 PCI Ethernet (RealTek 8029)"	},
5128210Sdanny	{ 0x50004a14,	"NE2000 PCI Ethernet (NetVin 5000)"	},
5224995Sdavidn	{ 0x09401050,	"NE2000 PCI Ethernet (ProLAN)"		},
5324995Sdavidn	{ 0x140111f6,	"NE2000 PCI Ethernet (Compex)"		},
5424995Sdavidn	{ 0x30008e2e,	"NE2000 PCI Ethernet (KTI)"		},
5531347Smsmith	{ 0x19808c4a,	"NE2000 PCI Ethernet (Winbond W89C940)" },
5633893Sse	{ 0x0e3410bd,	"NE2000 PCI Ethernet (Surecom NE-34)"	},
5734645Sdanny	{ 0x09261106,	"NE2000 PCI Ethernet (VIA VT86C926)"	},
5824995Sdavidn	{ 0x00000000,	NULL					}
5924995Sdavidn};
6015813Sse
6152247Smdoddstatic int	ed_pci_probe	__P((device_t));
6252247Smdoddstatic int	ed_pci_attach	__P((device_t));
6316289Salex
6450852Speterstatic int
6550852Spetered_pci_probe (device_t dev)
6615813Sse{
6750852Speter	u_int32_t	type = pci_get_devid(dev);
6824995Sdavidn	struct _pcsid	*ep =pci_ids;
6924995Sdavidn
7024995Sdavidn	while (ep->type && ep->type != type)
7124995Sdavidn		++ep;
7250852Speter	if (ep->desc) {
7350852Speter		device_set_desc(dev, ep->desc);
7450852Speter		return 0;
7550852Speter	} else {
7650852Speter		return ENXIO;
7750852Speter	}
7815813Sse}
7915813Sse
8050852Speterstatic int
8150852Spetered_pci_attach(device_t dev)
8215813Sse{
8364777Snyan        struct	ed_softc *sc = device_get_softc(dev);
8464777Snyan        int	flags = 0;
8564777Snyan        int	error;
8652247Smdodd
8764777Snyan        error = ed_probe_Novell(dev, PCIR_MAPS, flags);
8852247Smdodd        if (error)
8952247Smdodd                return (error);
9052247Smdodd
9152247Smdodd        error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
9252247Smdodd        if (error) {
9352247Smdodd                ed_release_resources(dev);
9452247Smdodd                return (error);
9552247Smdodd        }
9652247Smdodd
9752247Smdodd        error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
9852247Smdodd                               edintr, sc, &sc->irq_handle);
9952247Smdodd        if (error) {
10052247Smdodd                ed_release_resources(dev);
10152247Smdodd                return (error);
10252247Smdodd        }
10352247Smdodd
10452247Smdodd	error = ed_attach(sc, device_get_unit(dev), flags);
10552247Smdodd
10652247Smdodd	return (error);
10750852Speter}
10815813Sse
10950852Speterstatic device_method_t ed_pci_methods[] = {
11050852Speter	/* Device interface */
11150852Speter	DEVMETHOD(device_probe,		ed_pci_probe),
11250852Speter	DEVMETHOD(device_attach,	ed_pci_attach),
11315813Sse
11450852Speter	{ 0, 0 }
11550852Speter};
11615813Sse
11750852Speterstatic driver_t ed_pci_driver = {
11850852Speter	"ed",
11950852Speter	ed_pci_methods,
12050852Speter	sizeof(struct ed_softc),
12150852Speter};
12215813Sse
12367172SmsmithDRIVER_MODULE(if_ed, pci, ed_pci_driver, ed_devclass, 0, 0);
124