This source file includes following definitions.
- fxp_cardbus_match
- fxp_cardbus_attach
- fxp_cardbus_setup
- fxp_detach
- fxp_cardbus_detach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 #include "bpfilter.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/mbuf.h>
49 #include <sys/socket.h>
50 #include <sys/ioctl.h>
51 #include <sys/errno.h>
52 #include <sys/malloc.h>
53 #include <sys/kernel.h>
54 #include <sys/timeout.h>
55 #include <sys/device.h>
56
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_types.h>
60 #include <net/if_media.h>
61
62 #include <machine/endian.h>
63
64 #if NBPFILTER > 0
65 #include <net/bpf.h>
66 #endif
67
68 #ifdef INET
69 #include <netinet/in.h>
70 #include <netinet/in_systm.h>
71 #include <netinet/in_var.h>
72 #include <netinet/ip.h>
73 #include <netinet/if_ether.h>
74 #endif
75
76 #include <machine/bus.h>
77 #include <machine/intr.h>
78
79 #include <dev/mii/miivar.h>
80
81 #include <dev/ic/fxpreg.h>
82 #include <dev/ic/fxpvar.h>
83
84 #include <dev/pci/pcivar.h>
85 #include <dev/pci/pcireg.h>
86 #include <dev/pci/pcidevs.h>
87
88 #include <dev/cardbus/cardbusvar.h>
89
90 int fxp_cardbus_match(struct device *, void *, void *);
91 void fxp_cardbus_attach(struct device *, struct device *, void *);
92 int fxp_cardbus_detach(struct device *, int);
93 void fxp_cardbus_setup(struct fxp_softc *);
94
95 struct fxp_cardbus_softc {
96 struct fxp_softc sc;
97 cardbus_devfunc_t ct;
98 cardbustag_t ct_tag;
99 pcireg_t base0_reg;
100 pcireg_t base1_reg;
101 bus_size_t size;
102 };
103
104 struct cfattach fxp_cardbus_ca = {
105 sizeof(struct fxp_cardbus_softc), fxp_cardbus_match, fxp_cardbus_attach,
106 fxp_cardbus_detach
107 };
108
109 const struct cardbus_matchid fxp_cardbus_devices[] = {
110 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_8255x },
111 };
112
113 #ifdef CBB_DEBUG
114 #define DPRINTF(X) printf X
115 #else
116 #define DPRINTF(X)
117 #endif
118
119 int
120 fxp_cardbus_match(struct device *parent, void *match, void *aux)
121 {
122 return (cardbus_matchbyid((struct cardbus_attach_args *)aux,
123 fxp_cardbus_devices,
124 sizeof(fxp_cardbus_devices)/sizeof(fxp_cardbus_devices[0])));
125 }
126
127 void
128 fxp_cardbus_attach(struct device *parent, struct device *self, void *aux)
129 {
130 char intrstr[16];
131 struct fxp_softc *sc = (struct fxp_softc *) self;
132 struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc *) self;
133 struct cardbus_attach_args *ca = aux;
134 struct cardbus_softc *psc =
135 (struct cardbus_softc *)sc->sc_dev.dv_parent;
136 cardbus_chipset_tag_t cc = psc->sc_cc;
137 cardbus_function_tag_t cf = psc->sc_cf;
138 bus_space_tag_t iot, memt;
139 bus_space_handle_t ioh, memh;
140
141 bus_addr_t adr;
142 bus_size_t size;
143
144 csc->ct = ca->ca_ct;
145
146
147
148
149 if (Cardbus_mapreg_map(csc->ct, CARDBUS_BASE1_REG,
150 PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, &adr, &size) == 0) {
151 csc->base1_reg = adr | 1;
152 sc->sc_st = iot;
153 sc->sc_sh = ioh;
154 csc->size = size;
155 } else if (Cardbus_mapreg_map(csc->ct, CARDBUS_BASE0_REG,
156 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
157 0, &memt, &memh, &adr, &size) == 0) {
158 csc->base0_reg = adr;
159 sc->sc_st = memt;
160 sc->sc_sh = memh;
161 csc->size = size;
162 } else
163 panic("%s: failed to allocate mem and io space", __func__);
164
165 if (ca->ca_cis.cis1_info[0] && ca->ca_cis.cis1_info[1])
166 printf(": %s %s", ca->ca_cis.cis1_info[0],
167 ca->ca_cis.cis1_info[1]);
168 else
169 printf("\n");
170
171 sc->sc_dmat = ca->ca_dmat;
172 #if 0
173 sc->sc_enable = fxp_cardbus_enable;
174 sc->sc_disable = fxp_cardbus_disable;
175 sc->sc_enabled = 0;
176 #endif
177
178 Cardbus_function_enable(csc->ct);
179
180 fxp_cardbus_setup(sc);
181
182
183 sc->sc_ih = cardbus_intr_establish(cc, cf, psc->sc_intrline, IPL_NET,
184 fxp_intr, sc, sc->sc_dev.dv_xname);
185 if (NULL == sc->sc_ih) {
186 printf(": couldn't establish interrupt");
187 printf("at %d\n", ca->ca_intrline);
188 return;
189 }
190 snprintf(intrstr, sizeof(intrstr), "irq %d", ca->ca_intrline);
191
192 sc->sc_revision = PCI_REVISION(ca->ca_class);
193
194 fxp_attach(sc, intrstr);
195 }
196
197 void
198 fxp_cardbus_setup(struct fxp_softc *sc)
199 {
200 struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc *) sc;
201 struct cardbus_softc *psc =
202 (struct cardbus_softc *) sc->sc_dev.dv_parent;
203 cardbus_chipset_tag_t cc = psc->sc_cc;
204 cardbus_function_tag_t cf = psc->sc_cf;
205 pcireg_t command;
206
207 csc->ct_tag = cardbus_make_tag(cc, cf, csc->ct->ct_bus,
208 csc->ct->ct_dev, csc->ct->ct_func);
209
210 command = cardbus_conf_read(cc, cf, csc->ct_tag, CARDBUS_COMMAND_STATUS_REG);
211 if (csc->base0_reg) {
212 cardbus_conf_write(cc, cf, csc->ct_tag, CARDBUS_BASE0_REG, csc->base0_reg);
213 (cf->cardbus_ctrl) (cc, CARDBUS_MEM_ENABLE);
214 command |= CARDBUS_COMMAND_MEM_ENABLE |
215 CARDBUS_COMMAND_MASTER_ENABLE;
216 } else if (csc->base1_reg) {
217 cardbus_conf_write(cc, cf, csc->ct_tag, CARDBUS_BASE1_REG, csc->base1_reg);
218 (cf->cardbus_ctrl) (cc, CARDBUS_IO_ENABLE);
219 command |= (CARDBUS_COMMAND_IO_ENABLE |
220 CARDBUS_COMMAND_MASTER_ENABLE);
221 }
222
223 (cf->cardbus_ctrl) (cc, CARDBUS_BM_ENABLE);
224
225
226 cardbus_conf_write(cc, cf, csc->ct_tag, CARDBUS_COMMAND_STATUS_REG, command);
227 }
228
229 int fxp_detach(struct fxp_softc *);
230
231 int
232 fxp_detach(struct fxp_softc *sc)
233 {
234 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
235
236
237 timeout_del(&sc->stats_update_to);
238
239
240 if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL)
241 mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
242
243
244 ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
245
246 ether_ifdetach(ifp);
247 if_detach(ifp);
248
249 if (sc->sc_sdhook != NULL)
250 shutdownhook_disestablish(sc->sc_sdhook);
251 if (sc->sc_powerhook != NULL)
252 powerhook_disestablish(sc->sc_powerhook);
253
254 return (0);
255 }
256
257 int
258 fxp_cardbus_detach(struct device *self, int flags)
259 {
260 struct fxp_softc *sc = (struct fxp_softc *) self;
261 struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc *) self;
262 struct cardbus_devfunc *ct = csc->ct;
263 int rv, reg;
264
265 #ifdef DIAGNOSTIC
266 if (ct == NULL)
267 panic("%s: data structure lacks", sc->sc_dev.dv_xname);
268 #endif
269
270 rv = fxp_detach(sc);
271 if (rv == 0) {
272
273
274
275 cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
276
277
278
279
280 if (csc->base0_reg)
281 reg = CARDBUS_BASE0_REG;
282 else
283 reg = CARDBUS_BASE1_REG;
284 Cardbus_mapreg_unmap(ct, reg, sc->sc_st, sc->sc_sh, csc->size);
285 }
286 return (rv);
287 }