if_ed_pci.c revision 147149
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: head/sys/dev/ed/if_ed_pci.c 147149 2005-06-08 23:15:33Z imp $");
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>
3750852Speter#include <net/if_mib.h>
3815813Sse
39119277Simp#include <dev/pci/pcireg.h>
40119277Simp#include <dev/pci/pcivar.h>
4152247Smdodd
4251442Speter#include <dev/ed/if_edvar.h>
4350852Speter
4424995Sdavidnstatic struct _pcsid
4524995Sdavidn{
46140468Simp	uint32_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
61130657Simpstatic int	ed_pci_probe(device_t);
62130657Simpstatic int	ed_pci_attach(device_t);
6316289Salex
6450852Speterstatic int
65130659Simped_pci_probe(device_t dev)
6615813Sse{
67140468Simp	uint32_t	type = pci_get_devid(dev);
6824995Sdavidn	struct _pcsid	*ep =pci_ids;
6924995Sdavidn
7024995Sdavidn	while (ep->type && ep->type != type)
7124995Sdavidn		++ep;
72143161Simp	if (ep->desc == NULL)
73143161Simp		return (ENXIO);
74143161Simp	device_set_desc(dev, ep->desc);
75143161Simp	return (BUS_PROBE_DEFAULT);
7615813Sse}
7715813Sse
7850852Speterstatic int
7950852Spetered_pci_attach(device_t dev)
8015813Sse{
8164777Snyan        struct	ed_softc *sc = device_get_softc(dev);
8264777Snyan        int	flags = 0;
8364777Snyan        int	error;
8452247Smdodd
85119690Sjhb        error = ed_probe_Novell(dev, PCIR_BAR(0), flags);
86141577Simp        if (error) {
87141577Simp                ed_release_resources(dev);
8852247Smdodd                return (error);
89141577Simp	}
90147149Simp	ed_Novell_read_mac(sc);
9152247Smdodd
9252247Smdodd        error = ed_alloc_irq(dev, 0, RF_SHAREABLE);
9352247Smdodd        if (error) {
9452247Smdodd                ed_release_resources(dev);
9552247Smdodd                return (error);
9652247Smdodd        }
9752247Smdodd
9852247Smdodd        error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
99142254Simp	    edintr, sc, &sc->irq_handle);
10052247Smdodd        if (error) {
10152247Smdodd                ed_release_resources(dev);
10252247Smdodd                return (error);
10352247Smdodd        }
10452247Smdodd
105121816Sbrooks	error = ed_attach(dev);
106141577Simp        if (error)
107141577Simp                ed_release_resources(dev);
10852247Smdodd	return (error);
10950852Speter}
11015813Sse
11150852Speterstatic device_method_t ed_pci_methods[] = {
11250852Speter	/* Device interface */
11350852Speter	DEVMETHOD(device_probe,		ed_pci_probe),
11450852Speter	DEVMETHOD(device_attach,	ed_pci_attach),
115141494Simp	DEVMETHOD(device_attach,	ed_detach),
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
126113506SmdoddDRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0);
127113506SmdoddMODULE_DEPEND(ed, pci, 1, 1, 1);
128113506SmdoddMODULE_DEPEND(ed, ether, 1, 1, 1);
129