2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Pccard support for 3C589 by:
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/module.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
50 #include <net/ethernet.h>
52 #include <net/if_arp.h>
53 #include <net/if_media.h>
55 #include <dev/ep/if_epreg.h>
56 #include <dev/ep/if_epvar.h>
58 #include <dev/pccard/pccardvar.h>
59 #include <dev/pccard/pccard_cis.h>
61 #include "pccarddevs.h"
63 struct ep_pccard_product
65 struct pccard_product prod;
69 #define EP_CHIP_589 1 /* Classic 3c5x9 chipset */
70 #define EP_CHIP_574 2 /* Roadrunner */
71 #define EP_CHIP_C1 3 /* 3c1 */
73 static const struct ep_pccard_product ep_pccard_products[] = {
74 { PCMCIA_CARD(3COM, 3C1), EP_CHIP_C1 },
75 { PCMCIA_CARD(3COM, 3C562), EP_CHIP_589 },
76 { PCMCIA_CARD(3COM, 3C589), EP_CHIP_589 },
77 { PCMCIA_CARD(3COM, 3CXEM556), EP_CHIP_589 },
78 { PCMCIA_CARD(3COM, 3CXEM556INT), EP_CHIP_589 },
79 { PCMCIA_CARD(3COM, 3C574), EP_CHIP_574 },
80 { PCMCIA_CARD(3COM, 3CCFEM556BI), EP_CHIP_574 },
84 static const struct ep_pccard_product *
85 ep_pccard_lookup(device_t dev)
87 return ((const struct ep_pccard_product *)pccard_product_lookup(dev,
88 (const struct pccard_product *)ep_pccard_products,
89 sizeof(ep_pccard_products[0]), NULL));
93 ep_pccard_probe(device_t dev)
95 const struct ep_pccard_product *pp;
97 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
99 /* Make sure we're a network function */
100 error = pccard_get_function(dev, &fcn);
103 if (fcn != PCCARD_FUNCTION_NETWORK)
106 /* Check to see if we know about this card */
107 if ((pp = ep_pccard_lookup(dev)) == NULL)
109 if (pp->prod.pp_name != NULL)
110 device_set_desc(dev, pp->prod.pp_name);
116 ep_pccard_mac(const struct pccard_tuple *tuple, void *argp)
118 uint8_t *enaddr = argp;
121 /* Code 0x88 is 3com's special cis node contianing the MAC */
122 if (tuple->code != 0x88)
125 /* Make sure this is a sane node */
126 if (tuple->length < ETHER_ADDR_LEN)
129 /* Copy the MAC ADDR and return success */
130 for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
131 enaddr[i] = pccard_tuple_read_1(tuple, i + 1);
132 enaddr[i + 1] = pccard_tuple_read_1(tuple, i);
138 ep_pccard_attach(device_t dev)
140 struct ep_softc *sc = device_get_softc(dev);
143 const struct ep_pccard_product *pp;
145 if ((pp = ep_pccard_lookup(dev)) == NULL)
146 panic("ep_pccard_attach: can't find product in attach.");
148 if (pp->chipset == EP_CHIP_574) {
149 sc->epb.mii_trans = 1;
152 sc->epb.mii_trans = 0;
155 if ((error = ep_alloc(dev))) {
156 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
160 if (pp->chipset == EP_CHIP_C1)
161 sc->stat |= F_HAS_TX_PLL;
163 /* ROM size = 0, ROM base = 0 */
164 /* For now, ignore AUTO SELECT feature of 3C589B and later. */
165 error = ep_get_e(sc, EEPROM_ADDR_CFG, &result);
166 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000);
169 * Fake IRQ must be 3 for 3C589 and 3C589B. 3C589D and newer
170 * ignore this value. 3C589C is unknown, as are the other
171 * cards supported by this driver, but it appears to never hurt
175 CSR_WRITE_2(sc, EP_W0_PRODUCT_ID, sc->epb.prod_id);
177 if (sc->epb.mii_trans) {
179 * turn on the MII transciever
182 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
184 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040);
185 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
186 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
189 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
194 * The 3C562 (a-c revisions) stores the MAC in the CIS in a
195 * way that's unique to 3com. If we have one of these cards,
196 * scan the CIS for that MAC address, and use it if we find
197 * it. The NetBSD driver says that the ROADRUNNER chips also
198 * do this, which may be true, but none of the cards that I
199 * have include this TUPLE. Always prefer the MAC addr in the
200 * CIS tuple to the one returned by the card, as it appears that
201 * only those cards that need it have this special tuple.
203 if (pccard_cis_scan(dev, ep_pccard_mac, sc->eaddr))
204 sc->stat |= F_ENADDR_SKIP;
205 if ((error = ep_attach(sc))) {
206 device_printf(dev, "ep_attach() failed! (%d)\n", error);
209 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
210 NULL, ep_intr, sc, &sc->ep_intrhand))) {
211 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
220 static device_method_t ep_pccard_methods[] = {
221 /* Device interface */
222 DEVMETHOD(device_probe, ep_pccard_probe),
223 DEVMETHOD(device_attach, ep_pccard_attach),
224 DEVMETHOD(device_detach, ep_detach),
229 static driver_t ep_pccard_driver = {
232 sizeof(struct ep_softc),
235 extern devclass_t ep_devclass;
237 DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0);