2 * Copyright (c) 2002 Takeshi Shibagaki
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
26 * xe pccard interface driver
28 * $FreeBSD: src/sys/dev/xe/if_xe_pccard.c,v 1.1 2002/02/20 14:23:58 shiba Exp $
29 * $DragonFly: src/sys/dev/netif/xe/if_xe_pccard.c,v 1.1 2005/07/13 17:31:05 joerg Exp $
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/socket.h>
37 #include <sys/module.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <net/ethernet.h>
46 #include <net/if_arp.h>
47 #include <net/if_media.h>
48 #include <net/if_mib.h>
50 #include <bus/pccard/pccardvar.h>
51 #include <bus/pccard/pccarddevs.h>
57 static const struct pccard_product xe_pccard_products[] = {
58 PCMCIA_CARD(ACCTON, EN2226, 0),
59 PCMCIA_CARD(COMPAQ2, CPQ_10_100, 0),
60 PCMCIA_CARD(INTEL, EEPRO100, 0),
61 PCMCIA_CARD(XIRCOM, CE, 0),
62 PCMCIA_CARD(XIRCOM, CE2, 0),
63 PCMCIA_CARD(XIRCOM, CE3, 0),
64 PCMCIA_CARD(XIRCOM, CEM, 0),
65 PCMCIA_CARD(XIRCOM, CEM28, 0),
66 PCMCIA_CARD(XIRCOM, CEM33, 0),
67 PCMCIA_CARD(XIRCOM, CEM56, 0),
68 PCMCIA_CARD(XIRCOM, REM56, 0),
69 PCMCIA_CARD(XIRCOM, CNW_801, 0),
70 PCMCIA_CARD(XIRCOM, CNW_802, 0),
76 const char *vendor_desc;
78 { PCMCIA_VENDOR_XIRCOM, "Xircom" },
79 { PCMCIA_VENDOR_COMPAQ, "Compaq" },
80 { PCMCIA_VENDOR_COMPAQ2, "Compaq" },
81 { PCMCIA_VENDOR_INTEL, "Intel" },
85 #define XE_CARD_TYPE_FLAGS_NO 0x0
86 #define XE_CARD_TYPE_FLAGS_CE2 0x1
87 #define XE_CARD_TYPE_FLAGS_MOHAWK 0x2
88 #define XE_CARD_TYPE_FLAGS_DINGO 0x4
90 #define XE_PROD_UMASK 0x100f
91 #define XE_PROD_MODEM_UMASK 0x1000
92 #define XE_PROD_SINGLE_ID1 0x1
93 #define XE_PROD_SINGLE_ID2 0x2
94 #define XE_PROD_SINGLE_ID3 0x3
95 #define XE_PROD_MULTI_ID1 0x1001
96 #define XE_PROD_MULTI_ID2 0x1002
97 #define XE_PROD_MULTI_ID3 0x1003
98 #define XE_PROD_MULTI_ID4 0x1004
99 #define XE_PROD_MULTI_ID5 0x1005
100 #define XE_PROD_MULTI_ID6 0x1006
101 #define XE_PROD_MULTI_ID7 0x1007
103 struct xe_card_type {
105 const char *card_type_desc;
107 } xe_card_types[] = {
108 { XE_PROD_MULTI_ID1, "CEM", XE_CARD_TYPE_FLAGS_NO },
109 { XE_PROD_MULTI_ID2, "CEM2", XE_CARD_TYPE_FLAGS_CE2 },
110 { XE_PROD_MULTI_ID3, "CEM3", XE_CARD_TYPE_FLAGS_CE2 },
111 { XE_PROD_MULTI_ID4, "CEM33", XE_CARD_TYPE_FLAGS_CE2 },
112 { XE_PROD_MULTI_ID5, "CEM56M", XE_CARD_TYPE_FLAGS_MOHAWK },
113 { XE_PROD_MULTI_ID6, "CEM56", XE_CARD_TYPE_FLAGS_MOHAWK |
114 XE_CARD_TYPE_FLAGS_DINGO },
115 { XE_PROD_MULTI_ID7, "CEM56", XE_CARD_TYPE_FLAGS_MOHAWK |
116 XE_CARD_TYPE_FLAGS_DINGO },
117 { XE_PROD_SINGLE_ID1, "CE", XE_CARD_TYPE_FLAGS_NO },
118 { XE_PROD_SINGLE_ID2, "CE2", XE_CARD_TYPE_FLAGS_CE2 },
119 { XE_PROD_SINGLE_ID3, "CE3", XE_CARD_TYPE_FLAGS_MOHAWK },
123 static struct xe_vendor *xe_vendor_lookup (uint32_t);
124 static struct xe_card_type *xe_card_type_lookup (uint32_t);
126 static int xe_cem56fix (device_t);
127 static int xe_pccard_probe (device_t);
128 static int xe_pccard_match (device_t);
129 static int xe_pccard_attach(device_t);
131 static device_method_t xe_pccard_methods[] = {
132 /* Device interface */
133 DEVMETHOD(device_probe, pccard_compat_probe),
134 DEVMETHOD(device_attach, pccard_compat_attach),
135 DEVMETHOD(device_detach, xe_detach),
138 DEVMETHOD(card_compat_match, xe_pccard_match),
139 DEVMETHOD(card_compat_probe, xe_pccard_probe),
140 DEVMETHOD(card_compat_attach, xe_pccard_attach),
145 static driver_t xe_pccard_driver = {
148 sizeof(struct xe_softc),
151 devclass_t xe_devclass;
152 DRIVER_MODULE(xe, pccard, xe_pccard_driver, xe_devclass, 0, 0);
155 * Fixing for RealPort cards - they need a little furtling to get the
156 * ethernet working. But this codes don't work well in NEWCARD.
159 xe_cem56fix(device_t dev)
161 struct xe_softc *sc = device_get_softc(dev);
163 bus_space_handle_t bsh;
168 device_printf(dev, "Realport port 0x%0lx, size 0x%0lx\n",
169 bus_get_resource_start(dev, SYS_RES_IOPORT, sc->port_rid),
170 bus_get_resource_count(dev, SYS_RES_IOPORT, sc->port_rid));
173 r = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0,
174 ~0, 4 << 10, RF_ACTIVE);
176 device_printf(dev, "Can't map in attribute memory\n");
180 bsh = rman_get_bushandle(r);
181 bst = rman_get_bustag(r);
183 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, rid,
186 bus_space_write_1(bst, bsh, DINGO_ECOR, DINGO_ECOR_IRQ_LEVEL |
187 DINGO_ECOR_INT_ENABLE |
188 DINGO_ECOR_IOB_ENABLE |
189 DINGO_ECOR_ETH_ENABLE);
190 ioport = bus_get_resource_start(dev, SYS_RES_IOPORT, sc->port_rid);
191 bus_space_write_1(bst, bsh, DINGO_EBAR0, ioport & 0xff);
192 bus_space_write_1(bst, bsh, DINGO_EBAR1, (ioport >> 8) & 0xff);
194 bus_space_write_1(bst, bsh, DINGO_DCOR0, DINGO_DCOR0_SF_INT);
195 bus_space_write_1(bst, bsh, DINGO_DCOR1, DINGO_DCOR1_INT_LEVEL |
197 bus_space_write_1(bst, bsh, DINGO_DCOR2, 0x00);
198 bus_space_write_1(bst, bsh, DINGO_DCOR3, 0x00);
199 bus_space_write_1(bst, bsh, DINGO_DCOR4, 0x00);
201 bus_release_resource(dev, SYS_RES_MEMORY, rid, r);
207 static struct xe_vendor *
208 xe_vendor_lookup(uint32_t vendor_id)
212 for (v = xe_vendors; v->vendor_id != 0; ++v) {
213 if(v->vendor_id == vendor_id)
219 static struct xe_card_type *
220 xe_card_type_lookup(uint32_t prod)
222 struct xe_card_type *ct;
224 for (ct = xe_card_types; ct->card_type_desc != NULL; ++ct) {
225 if(ct->prod_type == (prod & XE_PROD_UMASK))
232 * PCMCIA probe routine.
233 * Identify the device. Called from the bus driver when the card is
234 * inserted or otherwise powers up.
237 xe_pccard_probe(device_t dev)
239 struct xe_softc *scp = device_get_softc(dev);
240 uint32_t vendor, product, prod;
243 const char *cis3_str=NULL;
244 struct xe_vendor *vendor_itm;
245 struct xe_card_type *card_itm;
249 * PCCARD_CISTPL_MANFID = 0x20
251 vendor = pccard_get_vendor(dev);
252 vendor_itm = xe_vendor_lookup(vendor);
254 * We always have some vendor here, although
255 * vendor description may be "Unknown".
257 scp->vendor = vendor_itm->vendor_desc;
259 product = pccard_get_product(dev);
260 prodext = pccard_get_prodext(dev);
263 * prod(new) = rev, media, prod(old)
264 * prod(new) = (don't care), (care 0x10 bit), (care 0x0f bit)
266 prod = (product << 8) | prodext;
267 card_itm = xe_card_type_lookup(prod);
268 if (card_itm == NULL)
271 scp->card_type = card_itm->card_type_desc;
272 if (card_itm->prod_type & XE_PROD_MODEM_UMASK)
275 for (i = 1; i != XE_CARD_TYPE_FLAGS_DINGO; i = i << 1) {
276 switch(i & card_itm->flags) {
277 case XE_CARD_TYPE_FLAGS_CE2:
280 case XE_CARD_TYPE_FLAGS_MOHAWK:
283 case XE_CARD_TYPE_FLAGS_DINGO:
290 * PCCARD_CISTPL_VERS_1 = 0x15
292 * Check for certain strange CE2's that look like CE's:
293 * match 3rd version string against "CE2"
295 cis3_str = pccard_get_cis3_str(dev);
296 if (strcmp(scp->card_type, "CE") == 0)
297 if (strcmp(cis3_str, "CE2") ==0)
298 scp->card_type = "CE2";
301 * PCCARD_CISTPL_FUNCE = 0x22
303 ether_addr = pccard_get_ether(dev);
304 bcopy(ether_addr, scp->arpcom.ac_enaddr, ETHER_ADDR_LEN);
306 /* Reject unsupported cards */
307 if (strcmp(scp->card_type, "CE") == 0 ||
308 strcmp(scp->card_type, "CEM") == 0) {
309 device_printf(dev, "Sorry, your %s card is not supported :(\n",
319 xe_pccard_attach(device_t dev)
321 struct xe_softc *scp = device_get_softc(dev);
324 if ((err = xe_activate(dev)) != 0)
327 /* Hack RealPorts into submission */
328 if (scp->dingo && xe_cem56fix(dev) < 0) {
329 device_printf(dev, "Unable to fix your RealPort\n");
333 return xe_attach(dev);
337 xe_pccard_match(device_t dev)
339 const struct pccard_product *pp;
341 if ((pp = pccard_product_lookup(dev, xe_pccard_products,
342 sizeof(xe_pccard_products[0]), NULL)) != NULL) {
343 if (pp->pp_name != NULL)
344 device_set_desc(dev, pp->pp_name);