Deleted Added
sdiff udiff text old ( 113506 ) new ( 119419 )
full compact
1/*
2 * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
10 * 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 *
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
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/snc/if_snc_pccard.c 113506 2003-04-15 06:37:30Z mdodd $
28 */
29
30/*
31 * National Semiconductor DP8393X SONIC Driver
32 *
33 * This is the PC-Card attachment on FreeBSD
34 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> and
35 * Hiroshi Yamashita <bluemoon@msj.biglobe.ne.jp>
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/socket.h>
41#include <sys/kernel.h>
42
43#include <sys/module.h>
44#include <sys/bus.h>
45#include <machine/bus.h>
46
47#include <net/if.h>
48#include <net/if_arp.h>
49#include <net/if_media.h>
50
51
52#include <dev/snc/dp83932var.h>
53#include <dev/snc/if_sncvar.h>
54#include <dev/snc/if_sncreg.h>
55
56/*
57 * PC-Card (PCMCIA) specific code.
58 */
59static int snc_pccard_probe(device_t);
60static int snc_pccard_attach(device_t);
61static int snc_pccard_detach(device_t);
62
63
64static device_method_t snc_pccard_methods[] = {
65 /* Device interface */
66 DEVMETHOD(device_probe, snc_pccard_probe),
67 DEVMETHOD(device_attach, snc_pccard_attach),
68 DEVMETHOD(device_detach, snc_pccard_detach),
69
70 { 0, 0 }
71};
72
73static driver_t snc_pccard_driver = {
74 "snc",
75 snc_pccard_methods,
76 sizeof(struct snc_softc)
77};
78
79DRIVER_MODULE(snc, pccard, snc_pccard_driver, snc_devclass, 0, 0);
80MODULE_DEPEND(snc, ether, 1, 1, 1);
81MODULE_DEPEND(snc, pccard, 1, 1, 1);
82
83/*
84 * snc_pccard_detach - unload the driver and clear the table.
85 * XXX TODO:
86 * This is usually called when the card is ejected, but
87 * can be caused by a modunload of a controller driver.
88 * The idea is to reset the driver's view of the device
89 * and ensure that any driver entry points such as
90 * read and write do not hang.
91 */
92static int
93snc_pccard_detach(device_t dev)
94{
95 struct snc_softc *sc = device_get_softc(dev);
96 struct ifnet *ifp = &sc->sc_if;
97
98 if (sc->gone) {
99 device_printf(dev, "already unloaded\n");
100 return (0);
101 }
102 sncshutdown(sc);
103 ifp->if_flags &= ~IFF_RUNNING;
104 if_detach(ifp);
105 sc->gone = 1;
106 bus_teardown_intr(dev, sc->irq, sc->irq_handle);
107 snc_release_resources(dev);
108 return (0);
109}
110
111/*
112 * Probe framework for pccards. Replicates the standard framework,
113 * minus the pccard driver registration and ignores the ether address
114 * supplied (from the CIS), relying on the probe to find it instead.
115 */
116static int
117snc_pccard_probe(device_t dev)
118{
119 int error;
120
121 error = snc_alloc_port(dev, 0);
122 error = max(error, snc_alloc_memory(dev, 0));
123 error = max(error, snc_alloc_irq(dev, 0, 0));
124
125 if (!error && !snc_probe(dev, SNEC_TYPE_PNP))
126 error = ENOENT;
127
128 snc_release_resources(dev);
129 return (error);
130}
131
132static int
133snc_pccard_attach(device_t dev)
134{
135 struct snc_softc *sc = device_get_softc(dev);
136 int error;
137
138 bzero(sc, sizeof(struct snc_softc));
139
140 snc_alloc_port(dev, 0);
141 snc_alloc_memory(dev, 0);
142 snc_alloc_irq(dev, 0, 0);
143
144 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
145 sncintr, sc, &sc->irq_handle);
146 if (error) {
147 printf("snc_isa_attach: bus_setup_intr() failed\n");
148 snc_release_resources(dev);
149 return (error);
150 }
151
152 /* This interface is always enabled. */
153 sc->sc_enabled = 1;
154
155 /* pccard_get_ether(dev, ether_addr); */
156
157 return snc_attach(dev);
158}