1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1999 M. Warner Losh <[email protected]>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/lock.h>
35 #include <sys/kernel.h>
36 #include <sys/mutex.h>
37 #include <sys/socket.h>
38
39 #include <sys/module.h>
40 #include <sys/bus.h>
41
42 #include <machine/bus.h>
43 #include <machine/resource.h>
44
45 #include <net/ethernet.h>
46 #include <net/if.h>
47 #include <net/if_media.h>
48
49 #include <dev/cs/if_csvar.h>
50 #include <dev/cs/if_csreg.h>
51 #include <dev/pccard/pccardvar.h>
52 #include <dev/pccard/pccard_cis.h>
53
54 #include "card_if.h"
55 #include "pccarddevs.h"
56
57 static const struct pccard_product cs_pccard_products[] = {
58 PCMCIA_CARD(IBM, ETHERJET),
59 { NULL }
60 };
61
62 static int
cs_pccard_probe(device_t dev)63 cs_pccard_probe(device_t dev)
64 {
65 const struct pccard_product *pp;
66 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
67
68 /* Make sure we're a network function */
69 pccard_get_function(dev, &fcn);
70 if (fcn != PCCARD_FUNCTION_NETWORK)
71 return (ENXIO);
72
73 if ((pp = pccard_product_lookup(dev, cs_pccard_products,
74 sizeof(cs_pccard_products[0]), NULL)) != NULL) {
75 if (pp->pp_name != NULL)
76 device_set_desc(dev, pp->pp_name);
77 return 0;
78 }
79 return EIO;
80 }
81
82 static int
cs_pccard_attach(device_t dev)83 cs_pccard_attach(device_t dev)
84 {
85 struct cs_softc *sc = device_get_softc(dev);
86 int error;
87
88 sc->flags |= CS_NO_IRQ;
89 error = cs_cs89x0_probe(dev);
90 if (error != 0)
91 return (error);
92 error = cs_alloc_irq(dev, sc->irq_rid);
93 if (error != 0)
94 goto bad;
95
96 return (cs_attach(dev));
97 bad:
98 cs_release_resources(dev);
99 return (error);
100 }
101
102 static device_method_t cs_pccard_methods[] = {
103 /* Device interface */
104 DEVMETHOD(device_probe, cs_pccard_probe),
105 DEVMETHOD(device_attach, cs_pccard_attach),
106 DEVMETHOD(device_detach, cs_detach),
107
108 { 0, 0 }
109 };
110
111 static driver_t cs_pccard_driver = {
112 "cs",
113 cs_pccard_methods,
114 sizeof(struct cs_softc),
115 };
116
117 extern devclass_t cs_devclass;
118
119 DRIVER_MODULE(cs, pccard, cs_pccard_driver, cs_devclass, 0, 0);
120 MODULE_DEPEND(cs, ether, 1, 1, 1);
121 PCCARD_PNP_INFO(cs_pccard_products);
122