1 /* $NetBSD: if_fxp_cardbus.c,v 1.39 2009/05/12 14:17:31 cegger Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * CardBus front-end for the Intel i82557 family of Ethernet chips.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_fxp_cardbus.c,v 1.39 2009/05/12 14:17:31 cegger Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/malloc.h>
47 #include <sys/kernel.h>
48 #include <sys/socket.h>
49 #include <sys/ioctl.h>
50 #include <sys/errno.h>
51 #include <sys/device.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_ether.h>
62 #include <machine/endian.h>
69 #include <netinet/in.h>
70 #include <netinet/if_inarp.h>
77 #include <dev/mii/miivar.h>
79 #include <dev/ic/i82557reg.h>
80 #include <dev/ic/i82557var.h>
82 #include <dev/pci/pcivar.h>
83 #include <dev/pci/pcireg.h>
84 #include <dev/pci/pcidevs.h>
86 #include <dev/cardbus/cardbusvar.h>
87 #include <dev/pci/pcidevs.h>
89 static int fxp_cardbus_match(device_t
, cfdata_t
, void *);
90 static void fxp_cardbus_attach(device_t
, device_t
, void *);
91 static int fxp_cardbus_detach(device_t
, int);
92 static void fxp_cardbus_setup(struct fxp_softc
*);
93 static int fxp_cardbus_enable(struct fxp_softc
*);
94 static void fxp_cardbus_disable(struct fxp_softc
*);
96 struct fxp_cardbus_softc
{
104 CFATTACH_DECL_NEW(fxp_cardbus
, sizeof(struct fxp_cardbus_softc
),
105 fxp_cardbus_match
, fxp_cardbus_attach
, fxp_cardbus_detach
, fxp_activate
);
108 #define DPRINTF(X) printf X
114 fxp_cardbus_match(device_t parent
, cfdata_t match
,
117 struct cardbus_attach_args
*ca
= aux
;
119 if (CARDBUS_VENDOR(ca
->ca_id
) == PCI_VENDOR_INTEL
&&
120 CARDBUS_PRODUCT(ca
->ca_id
) == PCI_PRODUCT_INTEL_82557
)
127 fxp_cardbus_attach(device_t parent
, device_t self
,
130 struct fxp_cardbus_softc
*csc
= device_private(self
);
131 struct fxp_softc
*sc
= &csc
->sc
;
132 struct cardbus_attach_args
*ca
= aux
;
133 bus_space_tag_t iot
, memt
;
134 bus_space_handle_t ioh
, memh
;
143 * Map control/status registers.
145 if (Cardbus_mapreg_map(csc
->ct
, CARDBUS_BASE1_REG
,
146 PCI_MAPREG_TYPE_IO
, 0, &iot
, &ioh
, &adr
, &size
) == 0) {
147 csc
->base1_reg
= adr
| 1;
151 } else if (Cardbus_mapreg_map(csc
->ct
, CARDBUS_BASE0_REG
,
152 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
,
153 0, &memt
, &memh
, &adr
, &size
) == 0) {
154 csc
->base0_reg
= adr
;
159 panic("%s: failed to allocate mem and io space", __func__
);
161 if (ca
->ca_cis
.cis1_info
[0] && ca
->ca_cis
.cis1_info
[1])
162 printf(": %s %s\n", ca
->ca_cis
.cis1_info
[0],
163 ca
->ca_cis
.cis1_info
[1]);
167 sc
->sc_rev
= CARDBUS_REVISION(ca
->ca_class
);
168 if (sc
->sc_rev
>= FXP_REV_82558_A4
)
169 sc
->sc_flags
|= FXPF_FC
|FXPF_EXT_TXCB
;
170 if (sc
->sc_rev
>= FXP_REV_82559_A0
)
171 sc
->sc_flags
|= FXPF_82559_RXCSUM
;
172 if (sc
->sc_rev
>= FXP_REV_82550
) {
173 sc
->sc_flags
&= ~FXPF_82559_RXCSUM
;
174 sc
->sc_flags
|= FXPF_EXT_RFA
;
177 sc
->sc_dmat
= ca
->ca_dmat
;
178 sc
->sc_enable
= fxp_cardbus_enable
;
179 sc
->sc_disable
= fxp_cardbus_disable
;
186 if (pmf_device_register(self
, NULL
, NULL
))
187 pmf_class_network_register(self
, &sc
->sc_ethercom
.ec_if
);
189 aprint_error_dev(self
, "couldn't establish power handler\n");
193 fxp_cardbus_setup(struct fxp_softc
* sc
)
195 struct fxp_cardbus_softc
*csc
= (struct fxp_cardbus_softc
*)sc
;
196 struct cardbus_softc
*psc
= device_private(device_parent(sc
->sc_dev
));
197 cardbus_chipset_tag_t cc
= psc
->sc_cc
;
198 cardbus_function_tag_t cf
= psc
->sc_cf
;
201 cardbustag_t tag
= cardbus_make_tag(cc
, cf
, csc
->ct
->ct_bus
,
204 command
= Cardbus_conf_read(csc
->ct
, tag
, CARDBUS_COMMAND_STATUS_REG
);
205 if (csc
->base0_reg
) {
206 Cardbus_conf_write(csc
->ct
, tag
,
207 CARDBUS_BASE0_REG
, csc
->base0_reg
);
208 (cf
->cardbus_ctrl
) (cc
, CARDBUS_MEM_ENABLE
);
209 command
|= CARDBUS_COMMAND_MEM_ENABLE
|
210 CARDBUS_COMMAND_MASTER_ENABLE
;
211 } else if (csc
->base1_reg
) {
212 Cardbus_conf_write(csc
->ct
, tag
,
213 CARDBUS_BASE1_REG
, csc
->base1_reg
);
214 (cf
->cardbus_ctrl
) (cc
, CARDBUS_IO_ENABLE
);
215 command
|= (CARDBUS_COMMAND_IO_ENABLE
|
216 CARDBUS_COMMAND_MASTER_ENABLE
);
219 (cf
->cardbus_ctrl
) (cc
, CARDBUS_BM_ENABLE
);
221 /* enable the card */
222 Cardbus_conf_write(csc
->ct
, tag
, CARDBUS_COMMAND_STATUS_REG
, command
);
226 fxp_cardbus_enable(struct fxp_softc
* sc
)
228 struct fxp_cardbus_softc
*csc
= (struct fxp_cardbus_softc
*)sc
;
229 struct cardbus_softc
*psc
= device_private(device_parent(sc
->sc_dev
));
230 cardbus_chipset_tag_t cc
= psc
->sc_cc
;
231 cardbus_function_tag_t cf
= psc
->sc_cf
;
233 Cardbus_function_enable(csc
->ct
);
235 fxp_cardbus_setup(sc
);
237 /* Map and establish the interrupt. */
239 sc
->sc_ih
= cardbus_intr_establish(cc
, cf
, psc
->sc_intrline
, IPL_NET
,
241 if (NULL
== sc
->sc_ih
) {
242 aprint_error_dev(sc
->sc_dev
, "couldn't establish interrupt\n");
250 fxp_cardbus_disable(struct fxp_softc
* sc
)
252 struct fxp_cardbus_softc
*csc
= (struct fxp_cardbus_softc
*)sc
;
253 struct cardbus_softc
*psc
= device_private(device_parent(sc
->sc_dev
));
254 cardbus_chipset_tag_t cc
= psc
->sc_cc
;
255 cardbus_function_tag_t cf
= psc
->sc_cf
;
257 /* Remove interrupt handler. */
258 cardbus_intr_disestablish(cc
, cf
, sc
->sc_ih
);
260 Cardbus_function_disable(csc
->ct
);
264 fxp_cardbus_detach(device_t self
, int flags
)
266 struct fxp_cardbus_softc
*csc
= device_private(self
);
267 struct fxp_softc
*sc
= &csc
->sc
;
268 struct cardbus_devfunc
*ct
= csc
->ct
;
273 panic("%s: data structure lacks", device_xname(self
));
279 * Unhook the interrupt handler.
281 cardbus_intr_disestablish(ct
->ct_cc
, ct
->ct_cf
, sc
->sc_ih
);
284 * release bus space and close window
287 reg
= CARDBUS_BASE0_REG
;
289 reg
= CARDBUS_BASE1_REG
;
290 Cardbus_mapreg_unmap(ct
, reg
, sc
->sc_st
, sc
->sc_sh
, csc
->size
);