2 * Copyright (c) 1995, David Greenman
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/snc/if_snc_pccard.c,v 1.1.2.1 2000/10/21 03:30:03 nyan Exp $
28 * $DragonFly: src/sys/dev/netif/snc/Attic/if_snc_pccard.c,v 1.5 2004/02/13 22:12:34 joerg Exp $
32 * National Semiconductor DP8393X SONIC Driver
34 * This is the PC-Card attachment on FreeBSD
35 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> and
36 * Hiroshi Yamashita <bluemoon@msj.biglobe.ne.jp>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/socket.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
46 #include <machine/bus.h>
48 #include <net/ethernet.h>
50 #include <net/if_arp.h>
51 #include <net/if_media.h>
52 #include <net/if_mib.h>
54 #include <bus/pccard/pccardvar.h>
56 #include "dp83932var.h"
57 #include "dp83932reg.h"
58 #include "if_sncvar.h"
59 #include "if_sncreg.h"
62 * PC-Card (PCMCIA) specific code.
64 static int snc_pccard_probe(device_t);
65 static int snc_pccard_attach(device_t);
66 static int snc_pccard_detach(device_t);
69 static device_method_t snc_pccard_methods[] = {
70 /* Device interface */
71 DEVMETHOD(device_probe, snc_pccard_probe),
72 DEVMETHOD(device_attach, snc_pccard_attach),
73 DEVMETHOD(device_detach, snc_pccard_detach),
78 static driver_t snc_pccard_driver = {
81 sizeof(struct snc_softc)
84 DRIVER_MODULE(if_snc, pccard, snc_pccard_driver, snc_devclass, 0, 0);
87 * snc_pccard_detach - unload the driver and clear the table.
89 * This is usually called when the card is ejected, but
90 * can be caused by a modunload of a controller driver.
91 * The idea is to reset the driver's view of the device
92 * and ensure that any driver entry points such as
93 * read and write do not hang.
96 snc_pccard_detach(device_t dev)
98 struct snc_softc *sc = device_get_softc(dev);
99 struct ifnet *ifp = &sc->sc_if;
102 device_printf(dev, "already unloaded\n");
106 ifp->if_flags &= ~IFF_RUNNING;
109 bus_teardown_intr(dev, sc->irq, sc->irq_handle);
110 snc_release_resources(dev);
115 * Probe framework for pccards. Replicates the standard framework,
116 * minus the pccard driver registration and ignores the ether address
117 * supplied (from the CIS), relying on the probe to find it instead.
120 snc_pccard_probe(device_t dev)
124 error = snc_alloc_port(dev, 0);
125 error = max(error, snc_alloc_memory(dev, 0));
126 error = max(error, snc_alloc_irq(dev, 0, 0));
128 if (!error && !snc_probe(dev, SNEC_TYPE_PNP))
131 snc_release_resources(dev);
136 snc_pccard_attach(device_t dev)
138 struct snc_softc *sc = device_get_softc(dev);
141 bzero(sc, sizeof(struct snc_softc));
143 snc_alloc_port(dev, 0);
144 snc_alloc_memory(dev, 0);
145 snc_alloc_irq(dev, 0, 0);
147 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
148 sncintr, sc, &sc->irq_handle);
150 printf("snc_isa_attach: bus_setup_intr() failed\n");
151 snc_release_resources(dev);
155 /* This interface is always enabled. */
158 /* ether_addr = pccard_get_ether(dev); */
160 return snc_attach(dev);