1 /* $OpenBSD: if_an_pcmcia.c,v 1.28 2024/05/26 08:46:28 jsg Exp $ */
2
3 /*
4 * Copyright (c) 1999 Michael Shalayeff
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 OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32
33 #include <net/if.h>
34 #include <net/if_media.h>
35
36 #include <netinet/in.h>
37 #include <netinet/if_ether.h>
38
39 #include <net80211/ieee80211_var.h>
40 #include <net80211/ieee80211_radiotap.h>
41
42 #include <dev/pcmcia/pcmciareg.h>
43 #include <dev/pcmcia/pcmciavar.h>
44 #include <dev/pcmcia/pcmciadevs.h>
45
46 #include <dev/ic/anreg.h>
47 #include <dev/ic/anvar.h>
48
49 int an_pcmcia_match(struct device *, void *, void *);
50 void an_pcmcia_attach(struct device *, struct device *, void *);
51 int an_pcmcia_detach(struct device *, int);
52 int an_pcmcia_activate(struct device *, int);
53
54 struct an_pcmcia_softc {
55 struct an_softc sc_an;
56
57 struct pcmcia_io_handle sc_pcioh;
58 int sc_io_window;
59 struct pcmcia_function *sc_pf;
60
61 int sc_state;
62 #define AN_PCMCIA_ATTACHED 3
63 };
64
65 const struct cfattach an_pcmcia_ca = {
66 sizeof(struct an_pcmcia_softc), an_pcmcia_match, an_pcmcia_attach,
67 an_pcmcia_detach, an_pcmcia_activate
68 };
69
70 int
an_pcmcia_match(struct device * parent,void * match,void * aux)71 an_pcmcia_match(struct device *parent, void *match, void *aux)
72 {
73 struct pcmcia_attach_args *pa = aux;
74
75 if (pa->pf->function != PCMCIA_FUNCTION_NETWORK)
76 return 0;
77
78 switch (pa->manufacturer) {
79 case PCMCIA_VENDOR_AIRONET:
80 switch (pa->product) {
81 case PCMCIA_PRODUCT_AIRONET_PC4500:
82 case PCMCIA_PRODUCT_AIRONET_PC4800:
83 case PCMCIA_PRODUCT_AIRONET_350:
84 return 1;
85 }
86 }
87
88 return 0;
89 }
90
91 void
an_pcmcia_attach(struct device * parent,struct device * self,void * aux)92 an_pcmcia_attach(struct device *parent, struct device *self, void *aux)
93 {
94 struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)self;
95 struct an_softc *sc = (struct an_softc *)self;
96 struct pcmcia_attach_args *pa = aux;
97 struct pcmcia_config_entry *cfe;
98 const char *intrstr;
99 int error;
100
101 psc->sc_pf = pa->pf;
102 cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);
103
104 pcmcia_function_init(pa->pf, cfe);
105 if (pcmcia_function_enable(pa->pf)) {
106 printf(": function enable failed\n");
107 return;
108 }
109
110 if (pcmcia_io_alloc(pa->pf, 0, AN_IOSIZ, AN_IOSIZ, &psc->sc_pcioh)) {
111 printf(": can't alloc i/o space\n");
112 pcmcia_function_disable(pa->pf);
113 return;
114 }
115
116 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0, AN_IOSIZ,
117 &psc->sc_pcioh, &psc->sc_io_window)) {
118 printf(": can't map i/o space\n");
119 pcmcia_io_free(pa->pf, &psc->sc_pcioh);
120 pcmcia_function_disable(pa->pf);
121 return;
122 }
123
124 sc->sc_iot = psc->sc_pcioh.iot;
125 sc->sc_ioh = psc->sc_pcioh.ioh;
126 sc->sc_enabled = 1;
127
128 sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, an_intr, sc,
129 sc->sc_dev.dv_xname);
130 intrstr = pcmcia_intr_string(psc->sc_pf, sc->sc_ih);
131 if (*intrstr)
132 printf(", %s", intrstr);
133 printf("\n");
134
135 error = an_attach(sc);
136 if (error) {
137 printf("%s: failed to attach controller\n",
138 self->dv_xname);
139 return;
140 }
141
142 sc->sc_enabled = 0;
143 psc->sc_state = AN_PCMCIA_ATTACHED;
144 }
145
146 int
an_pcmcia_detach(struct device * dev,int flags)147 an_pcmcia_detach(struct device *dev, int flags)
148 {
149 struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)dev;
150 int error;
151
152 if (psc->sc_state != AN_PCMCIA_ATTACHED)
153 return (0);
154
155 error = an_detach(&psc->sc_an);
156 if (error)
157 return (error);
158
159 pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
160 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
161
162 return 0;
163 }
164
165 int
an_pcmcia_activate(struct device * dev,int act)166 an_pcmcia_activate(struct device *dev, int act)
167 {
168 struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)dev;
169 struct an_softc *sc = &psc->sc_an;
170 struct ieee80211com *ic = &sc->sc_ic;
171 struct ifnet *ifp = &ic->ic_if;
172
173 switch (act) {
174 case DVACT_DEACTIVATE:
175 ifp->if_timer = 0;
176 if (ifp->if_flags & IFF_RUNNING)
177 an_stop(ifp, 1);
178 if (sc->sc_ih)
179 pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
180 sc->sc_ih = NULL;
181 pcmcia_function_disable(psc->sc_pf);
182 break;
183 }
184 return (0);
185 }
186