2 * Copyright (c) 2000 Mitsuru IWASAKI
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/socket.h>
36 #include <sys/module.h>
39 #include <machine/bus.h>
40 #include <machine/resource.h>
44 #include <net/if_arp.h>
45 #include <net/if_media.h>
47 #include <dev/ex/if_exreg.h>
48 #include <dev/ex/if_exvar.h>
50 #include <dev/pccard/pccardvar.h>
51 #include <dev/pccard/pccard_cis.h>
52 #include "pccarddevs.h"
54 static const struct pccard_product ex_pccard_products[] = {
55 PCMCIA_CARD(OLICOM, OC2220),
56 PCMCIA_CARD(OLICOM, OC2231),
57 PCMCIA_CARD(OLICOM, OC2232),
58 PCMCIA_CARD(INTEL, ETHEREXPPRO),
62 /* Bus Front End Functions */
63 static int ex_pccard_probe(device_t);
64 static int ex_pccard_attach(device_t);
67 ex_pccard_enet_ok(u_char *enaddr)
72 if (enaddr[0] == 0xff)
74 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
80 ex_pccard_silicom_cb(const struct pccard_tuple *tuple, void *arg)
85 if (tuple->code != CISTPL_FUNCE)
87 if (tuple->length != 15)
89 if (pccard_tuple_read_1(tuple, 6) != 6)
91 for (i = 0; i < 6; i++)
92 enaddr[i] = pccard_tuple_read_1(tuple, 7 + i);
97 ex_pccard_get_silicom_mac(device_t dev, u_char *ether_addr)
99 pccard_cis_scan(dev, ex_pccard_silicom_cb, ether_addr);
103 ex_pccard_probe(device_t dev)
105 const struct pccard_product *pp;
107 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
109 if ((pp = pccard_product_lookup(dev, ex_pccard_products,
110 sizeof(ex_pccard_products[0]), NULL)) == NULL)
112 if (pp->pp_name != NULL)
113 device_set_desc(dev, pp->pp_name);
115 * Olicom 22.8k and 33.6k modems need to activate the right
116 * CFE. The odd formula below replicates the sequence of cfes
117 * that have multiple resources:
118 * 9, 11, 13, 15, 0 + 9
119 * 25, 27, 29, 31, 16 + 9
120 * 41, 43, 45, 47, 32 + 9
121 * 57, 59, 61, 63 48 + 9
122 * (entries 8, 24, 40 and 56 are single resoruce cfes)
123 * Fortunately the code that enables and disables the multiple
124 * fuctions of the card won't mess with the lower bit for cards
125 * that aren't stanards conforming MFC cards (which these olicom
128 * Note: These cards still don't get interrupts for reasons
129 * unknown, even when the right cfe is selected. There's likely
130 * something in the CCR that needs to be manually tweaked, but
131 * the COR bits seem to all be used. Bit 0 and 3 are always set
132 * and the other bits select the config to use. Maybe one of those
133 * two bits needs to be cleared, or there's something else in the
134 * CCR that needs tweaking. The pattern of resources suggests
135 * bit 0 turns on the ethernet, however...
137 if (pp->pp_vendor == PCMCIA_VENDOR_OLICOM &&
138 (pp->pp_product == PCMCIA_PRODUCT_OLICOM_OC2231 ||
139 pp->pp_product == PCMCIA_PRODUCT_OLICOM_OC2232)) {
140 if (pccard_select_cfe(dev, 1) == 0)
142 for (i = 0; i < 4; i++) {
143 for (j = 0; j < 4; j++) {
144 printf("Trying %d %d\n", i, j);
145 if (pccard_select_cfe(dev,
146 (i << 4) + (j << 1) + 9) == 0)
150 /* Can't activate the net entries, punt */
154 * All other cards supported by this driver don't need specail
155 * treatment, so just filter based on the type of card. The
156 * special treatment ones are setup to 'fail safe' to a modem so
157 * this check would effectively filter them out as well.
159 error = pccard_get_function(dev, &fcn);
162 if (fcn != PCCARD_FUNCTION_NETWORK)
169 ex_pccard_attach(device_t dev)
171 struct ex_softc * sc = device_get_softc(dev);
173 u_char ether_addr[ETHER_ADDR_LEN];
179 if ((error = ex_alloc_resources(dev)) != 0) {
180 device_printf(dev, "ex_alloc_resources() failed!\n");
185 * Fill in several fields of the softc structure:
186 * - Hardware Ethernet address.
189 sc->irq_no = rman_get_start(sc->irq);
191 /* Try to get the ethernet address from the chip, then the CIS */
192 ex_get_address(sc, ether_addr);
193 if (!ex_pccard_enet_ok(ether_addr))
194 pccard_get_ether(dev, ether_addr);
195 if (!ex_pccard_enet_ok(ether_addr))
196 ex_pccard_get_silicom_mac(dev, ether_addr);
197 if (!ex_pccard_enet_ok(ether_addr)) {
198 device_printf(dev, "No NIC address found.\n");
202 bcopy(ether_addr, sc->enaddr, ETHER_ADDR_LEN);
204 if ((error = ex_attach(dev)) != 0) {
205 device_printf(dev, "ex_attach() failed!\n");
211 ex_release_resources(dev);
214 static device_method_t ex_pccard_methods[] = {
215 /* Device interface */
216 DEVMETHOD(device_probe, ex_pccard_probe),
217 DEVMETHOD(device_attach, ex_pccard_attach),
218 DEVMETHOD(device_detach, ex_detach),
223 static driver_t ex_pccard_driver = {
226 sizeof(struct ex_softc),
229 DRIVER_MODULE(ex, pccard, ex_pccard_driver, ex_devclass, 0, 0);
230 MODULE_DEPEND(ex, pccard, 1, 1, 1);