if_snc_pccard.c revision 147318
1139749Simp/*- 266550Snyan * Copyright (c) 1995, David Greenman 366550Snyan * All rights reserved. 466550Snyan * 566550Snyan * Redistribution and use in source and binary forms, with or without 666550Snyan * modification, are permitted provided that the following conditions 766550Snyan * are met: 866550Snyan * 1. Redistributions of source code must retain the above copyright 966550Snyan * notice unmodified, this list of conditions, and the following 1066550Snyan * disclaimer. 1166550Snyan * 2. Redistributions in binary form must reproduce the above copyright 1266550Snyan * notice, this list of conditions and the following disclaimer in the 1366550Snyan * documentation and/or other materials provided with the distribution. 1466550Snyan * 1566550Snyan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666550Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766550Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866550Snyan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966550Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066550Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166550Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266550Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366550Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466550Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566550Snyan * SUCH DAMAGE. 2666550Snyan * 2766550Snyan */ 2866550Snyan 29119419Sobrien#include <sys/cdefs.h> 30119419Sobrien__FBSDID("$FreeBSD: head/sys/dev/snc/if_snc_pccard.c 147318 2005-06-12 16:21:44Z brooks $"); 31119419Sobrien 3266550Snyan/* 3366550Snyan * National Semiconductor DP8393X SONIC Driver 3466550Snyan * 3566550Snyan * This is the PC-Card attachment on FreeBSD 3666550Snyan * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> and 3766550Snyan * Hiroshi Yamashita <bluemoon@msj.biglobe.ne.jp> 3866550Snyan */ 3966550Snyan 4066550Snyan#include <sys/param.h> 4166550Snyan#include <sys/systm.h> 4266550Snyan#include <sys/socket.h> 4366550Snyan#include <sys/kernel.h> 4466550Snyan 4566550Snyan#include <sys/module.h> 4666550Snyan#include <sys/bus.h> 4766550Snyan#include <machine/bus.h> 4866550Snyan 4966550Snyan#include <net/if.h> 5066550Snyan#include <net/if_arp.h> 5166550Snyan#include <net/if_media.h> 5266550Snyan 5366550Snyan 5466550Snyan#include <dev/snc/dp83932var.h> 5566550Snyan#include <dev/snc/if_sncvar.h> 5666550Snyan#include <dev/snc/if_sncreg.h> 5766550Snyan 5866550Snyan/* 5966550Snyan * PC-Card (PCMCIA) specific code. 6066550Snyan */ 6166550Snyanstatic int snc_pccard_probe(device_t); 6266550Snyanstatic int snc_pccard_attach(device_t); 6366550Snyanstatic int snc_pccard_detach(device_t); 6466550Snyan 6566550Snyan 6666550Snyanstatic device_method_t snc_pccard_methods[] = { 6766550Snyan /* Device interface */ 6866550Snyan DEVMETHOD(device_probe, snc_pccard_probe), 6966550Snyan DEVMETHOD(device_attach, snc_pccard_attach), 7066550Snyan DEVMETHOD(device_detach, snc_pccard_detach), 7166550Snyan 7266550Snyan { 0, 0 } 7366550Snyan}; 7466550Snyan 7566550Snyanstatic driver_t snc_pccard_driver = { 7666550Snyan "snc", 7766550Snyan snc_pccard_methods, 7866550Snyan sizeof(struct snc_softc) 7966550Snyan}; 8066550Snyan 81113506SmdoddDRIVER_MODULE(snc, pccard, snc_pccard_driver, snc_devclass, 0, 0); 82113506SmdoddMODULE_DEPEND(snc, ether, 1, 1, 1); 8366550Snyan 8466550Snyan/* 85140529Simp * snc_pccard_detach - detach this instance from the device. 8666550Snyan */ 8766550Snyanstatic int 8866550Snyansnc_pccard_detach(device_t dev) 8966550Snyan{ 9066550Snyan struct snc_softc *sc = device_get_softc(dev); 91147318Sbrooks struct ifnet *ifp = sc->sc_ifp; 9266550Snyan 9366550Snyan if (sc->gone) { 9466550Snyan device_printf(dev, "already unloaded\n"); 9566550Snyan return (0); 9666550Snyan } 9766550Snyan sncshutdown(sc); 9866550Snyan ifp->if_flags &= ~IFF_RUNNING; 9966550Snyan if_detach(ifp); 10066550Snyan sc->gone = 1; 10166550Snyan bus_teardown_intr(dev, sc->irq, sc->irq_handle); 10266550Snyan snc_release_resources(dev); 10366550Snyan return (0); 10466550Snyan} 10566550Snyan 10666550Snyan/* 107140529Simp * Probe the pccard. 10866550Snyan */ 10966550Snyanstatic int 11066550Snyansnc_pccard_probe(device_t dev) 11166550Snyan{ 11266550Snyan int error; 11366550Snyan 11466550Snyan error = snc_alloc_port(dev, 0); 11566550Snyan error = max(error, snc_alloc_memory(dev, 0)); 11666550Snyan error = max(error, snc_alloc_irq(dev, 0, 0)); 11766550Snyan 11866550Snyan if (!error && !snc_probe(dev, SNEC_TYPE_PNP)) 11966550Snyan error = ENOENT; 12066550Snyan 12166550Snyan snc_release_resources(dev); 12266550Snyan return (error); 12366550Snyan} 12466550Snyan 12566550Snyanstatic int 12666550Snyansnc_pccard_attach(device_t dev) 12766550Snyan{ 12866550Snyan struct snc_softc *sc = device_get_softc(dev); 12966550Snyan int error; 13066550Snyan 13166550Snyan bzero(sc, sizeof(struct snc_softc)); 13266550Snyan 13366550Snyan snc_alloc_port(dev, 0); 13466550Snyan snc_alloc_memory(dev, 0); 13566550Snyan snc_alloc_irq(dev, 0, 0); 13666550Snyan 13766550Snyan error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, 13866550Snyan sncintr, sc, &sc->irq_handle); 13966550Snyan if (error) { 14066550Snyan printf("snc_isa_attach: bus_setup_intr() failed\n"); 14166550Snyan snc_release_resources(dev); 14266550Snyan return (error); 14366550Snyan } 14466550Snyan 14566550Snyan /* This interface is always enabled. */ 14666550Snyan sc->sc_enabled = 1; 14766550Snyan 14866550Snyan /* pccard_get_ether(dev, ether_addr); */ 14966550Snyan 15066550Snyan return snc_attach(dev); 15166550Snyan} 152