if_ed_pci.c revision 150136
1/*- 2 * Copyright (c) 1996 Stefan Esser <se@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Absolutely no warranty of function or purpose is made by the author 15 * Stefan Esser. 16 * 4. Modifications may be freely made to this file if the above conditions 17 * are met. 18 */ 19 20#include <sys/cdefs.h> 21__FBSDID("$FreeBSD: head/sys/dev/ed/if_ed_pci.c 150136 2005-09-14 19:03:14Z ru $"); 22 23#include <sys/param.h> 24#include <sys/systm.h> 25#include <sys/socket.h> 26#include <sys/kernel.h> 27 28#include <sys/module.h> 29#include <sys/bus.h> 30 31#include <machine/bus.h> 32#include <sys/rman.h> 33#include <machine/resource.h> 34 35#include <net/if.h> 36#include <net/if_arp.h> 37#include <net/if_media.h> 38#include <net/if_mib.h> 39 40#include <dev/pci/pcireg.h> 41#include <dev/pci/pcivar.h> 42 43#include <dev/ed/if_edvar.h> 44 45static struct _pcsid 46{ 47 uint32_t type; 48 const char *desc; 49} pci_ids[] = 50{ 51 { 0x802910ec, "RealTek 8029" }, 52 { 0x50004a14, "NetVin 5000" }, 53 { 0x09401050, "ProLAN" }, 54 { 0x140111f6, "Compex" }, 55 { 0x30008e2e, "KTI" }, 56 { 0x19808c4a, "Winbond W89C940" }, 57 { 0x0e3410bd, "Surecom NE-34" }, 58 { 0x09261106, "VIA VT86C926" }, 59 { 0x00000000, NULL } 60}; 61 62static int ed_pci_probe(device_t); 63static int ed_pci_attach(device_t); 64 65static int 66ed_pci_probe(device_t dev) 67{ 68 uint32_t type = pci_get_devid(dev); 69 struct _pcsid *ep =pci_ids; 70 71 while (ep->type && ep->type != type) 72 ++ep; 73 if (ep->desc == NULL) 74 return (ENXIO); 75 device_set_desc(dev, ep->desc); 76 return (BUS_PROBE_DEFAULT); 77} 78 79static int 80ed_pci_attach(device_t dev) 81{ 82 struct ed_softc *sc = device_get_softc(dev); 83 int flags = 0; 84 int error; 85 86 error = ed_probe_Novell(dev, PCIR_BAR(0), flags); 87 if (error) { 88 ed_release_resources(dev); 89 return (error); 90 } 91 ed_Novell_read_mac(sc); 92 93 error = ed_alloc_irq(dev, 0, RF_SHAREABLE); 94 if (error) { 95 ed_release_resources(dev); 96 return (error); 97 } 98 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE, 99 edintr, sc, &sc->irq_handle); 100 if (error) { 101 ed_release_resources(dev); 102 return (error); 103 } 104 105 error = ed_attach(dev); 106 if (error) 107 ed_release_resources(dev); 108 return (error); 109} 110 111static device_method_t ed_pci_methods[] = { 112 /* Device interface */ 113 DEVMETHOD(device_probe, ed_pci_probe), 114 DEVMETHOD(device_attach, ed_pci_attach), 115 DEVMETHOD(device_detach, ed_detach), 116 117 { 0, 0 } 118}; 119 120static driver_t ed_pci_driver = { 121 "ed", 122 ed_pci_methods, 123 sizeof(struct ed_softc), 124}; 125 126DRIVER_MODULE(ed, pci, ed_pci_driver, ed_devclass, 0, 0); 127MODULE_DEPEND(ed, pci, 1, 1, 1); 128MODULE_DEPEND(ed, ether, 1, 1, 1); 129