pccard_cis_quirks.c revision 129781
165483Simp/*	$NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
252506Simp
3119418Sobrien#include <sys/cdefs.h>
4119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 129781 2004-05-27 15:21:51Z imp $");
5119418Sobrien
652506Simp#define	PCCARDDEBUG
752506Simp
852506Simp/*
952506Simp * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
1052506Simp *
1152506Simp * Redistribution and use in source and binary forms, with or without
1252506Simp * modification, are permitted provided that the following conditions
1352506Simp * are met:
1452506Simp * 1. Redistributions of source code must retain the above copyright
1552506Simp *    notice, this list of conditions and the following disclaimer.
1652506Simp * 2. Redistributions in binary form must reproduce the above copyright
1752506Simp *    notice, this list of conditions and the following disclaimer in the
1852506Simp *    documentation and/or other materials provided with the distribution.
1952506Simp * 3. All advertising materials mentioning features or use of this software
2052506Simp *    must display the following acknowledgement:
2152506Simp *	This product includes software developed by Marc Horowitz.
2252506Simp * 4. The name of the author may not be used to endorse or promote products
2352506Simp *    derived from this software without specific prior written permission.
2452506Simp *
2552506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2652506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2752506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2852506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2952506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3052506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3152506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3252506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3352506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3452506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3552506Simp */
3652506Simp
3752506Simp#include <sys/param.h>
38129762Simp#include <sys/bus.h>
39129781Simp#include <sys/malloc.h>
4052506Simp#include <sys/systm.h>
4152506Simp
4252506Simp#include <machine/bus.h>
4352506Simp
44129762Simp#include <dev/pccard/pccard_cis.h>
45129762Simp#include <dev/pccard/pccardvar.h>
46129781Simp
47129740Simp#include "pccarddevs.h"
4852506Simp
4952506Simp/* There are cards out there whose CIS flat-out lies.  This file
5052506Simp   contains struct pccard_function chains for those devices. */
5152506Simp
5252506Simp/* these structures are just static templates which are then copied
5352506Simp   into "live" allocated structures */
5452506Simp
5552506Simpstruct pccard_function pccard_3cxem556_func0 = {
5652506Simp	0,			/* function number */
5752506Simp	PCCARD_FUNCTION_NETWORK,
5852506Simp	0x07,			/* last cfe number */
5952506Simp	0x800,			/* ccr_base */
6052506Simp	0x63,			/* ccr_mask */
6152506Simp};
6252506Simp
6352506Simpstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
6452506Simp	0x07,			/* cfe number */
6552506Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
6652506Simp	PCCARD_IFTYPE_IO,
6752506Simp	1,			/* num_iospace */
6852506Simp	4,			/* iomask */
6952506Simp	{ { 0x0010, 0 } },	/* iospace */
7052506Simp	0xffff,			/* irqmask */
7152506Simp	0,			/* num_memspace */
7252506Simp	{ },			/* memspace */
7352506Simp	0,			/* maxtwins */
7452506Simp};
7552506Simp
7652506Simpstatic struct pccard_function pccard_3cxem556_func1 = {
7752506Simp	1,			/* function number */
7852506Simp	PCCARD_FUNCTION_SERIAL,
7952506Simp	0x27,			/* last cfe number */
8052506Simp	0x900,			/* ccr_base */
8152506Simp	0x63,			/* ccr_mask */
8252506Simp};
8352506Simp
8452506Simpstatic struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
8552506Simp	0x27,			/* cfe number */
8652506Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
8752506Simp	PCCARD_IFTYPE_IO,
8852506Simp	1,			/* num_iospace */
8952506Simp	3,			/* iomask */
9052506Simp	{ { 0x0008, 0 } },	/* iospace */
9152506Simp	0xffff,			/* irqmask */
9252506Simp	0,			/* num_memspace */
9352506Simp	{ },			/* memspace */
9452506Simp	0,			/* maxtwins */
9552506Simp};
9652506Simp
9753813Simpstatic struct pccard_function pccard_3ccfem556bi_func0 = {
9853813Simp	0,			/* function number */
9953813Simp	PCCARD_FUNCTION_NETWORK,
10053813Simp	0x07,			/* last cfe number */
10153813Simp	0x1000,			/* ccr_base */
10253813Simp	0x267,			/* ccr_mask */
10353813Simp};
10453813Simp
10553813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
10653813Simp	0x07,			/* cfe number */
10753813Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
10853813Simp	PCCARD_IFTYPE_IO,
10953813Simp	1,			/* num_iospace */
11053813Simp	5,			/* iomask */
11153813Simp	{ { 0x0020, 0 } },	/* iospace */
11253813Simp	0xffff,			/* irqmask */
11353813Simp	0,			/* num_memspace */
11453813Simp	{ },			/* memspace */
11553813Simp	0,			/* maxtwins */
11653813Simp};
11753813Simp
11853813Simpstatic struct pccard_function pccard_3ccfem556bi_func1 = {
11953813Simp	1,			/* function number */
12053813Simp	PCCARD_FUNCTION_SERIAL,
12153813Simp	0x27,			/* last cfe number */
12253813Simp	0x1100,			/* ccr_base */
12353813Simp	0x277,			/* ccr_mask */
12453813Simp};
12553813Simp
12653813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
12753813Simp	0x27,			/* cfe number */
12853813Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
12953813Simp	PCCARD_IFTYPE_IO,
13053813Simp	1,			/* num_iospace */
13153813Simp	3,			/* iomask */
13253813Simp	{ { 0x0008, 0 } },	/* iospace */
13353813Simp	0xffff,			/* irqmask */
13453813Simp	0,			/* num_memspace */
13553813Simp	{ },			/* memspace */
13653813Simp	0,			/* maxtwins */
13753813Simp};
13853813Simp
13952506Simpstatic struct pccard_function pccard_sveclancard_func0 = {
14052506Simp	0,			/* function number */
14152506Simp	PCCARD_FUNCTION_NETWORK,
14252506Simp	0x1,			/* last cfe number */
14352506Simp	0x100,			/* ccr_base */
14452506Simp	0x1,			/* ccr_mask */
14552506Simp};
14652506Simp
14752506Simpstatic struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
14852506Simp	0x1,			/* cfe number */
14952506Simp	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
15052506Simp	PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
15152506Simp	PCCARD_IFTYPE_IO,
15252506Simp	1,			/* num_iospace */
15352506Simp	5,			/* iomask */
15452506Simp	{ { 0x20, 0x300 } },	/* iospace */
15552506Simp	0xdeb8,			/* irqmask */
15652506Simp	0,			/* num_memspace */
15752506Simp	{ },			/* memspace */
15852506Simp	0,			/* maxtwins */
15952506Simp};
16052506Simp
16165483Simpstatic struct pccard_function pccard_ndc_nd5100_func0 = {
16265483Simp	0,			/* function number */
16365483Simp	PCCARD_FUNCTION_NETWORK,
16465483Simp	0x23,			/* last cfe number */
16565483Simp	0x3f8,			/* ccr_base */
16665483Simp	0x3,			/* ccr_mask */
16765483Simp};
16865483Simp
16965483Simpstatic struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
17065483Simp	0x20,			/* cfe number */
17165483Simp	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
17265483Simp	PCCARD_IFTYPE_IO,
17365483Simp	1,			/* num_iospace */
17465483Simp	5,			/* iomask */
17565483Simp	{ { 0x20, 0x300 } },	/* iospace */
17665483Simp	0xdeb8,			/* irqmask */
17765483Simp	0,			/* num_memspace */
17865483Simp	{ },			/* memspace */
17965483Simp	0,			/* maxtwins */
18065483Simp};
18165483Simp
18252506Simpstatic struct pccard_cis_quirk pccard_cis_quirks[] = {
18386272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
18452506Simp	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
18586272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
18652506Simp	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
18786272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
18853813Simp	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
18986272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
19053813Simp	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
19186272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
19286272Simp	  PCMCIA_CIS_INVALID,
19353813Simp	  &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
19486272Simp	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
19586272Simp	  PCMCIA_CIS_INVALID,
19653813Simp	  &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
19786272Simp	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
19852506Simp	  &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
19986272Simp	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
20065483Simp	  &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
20152506Simp};
20252506Simp
20352506Simpstatic int n_pccard_cis_quirks =
20452506Simp	sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
20552506Simp
206120849Simpstatic int
207120849Simppccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
208120849Simp{
209120849Simp	if ((sc->card.manufacturer == q->manufacturer) &&
210120849Simp		(sc->card.product == q->product) &&
211120849Simp		(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
212120849Simp		  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
213120849Simp		 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
214120849Simp		  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
215120849Simp		  sc->card.cis1_info[0] &&
216120849Simp		  (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
217120849Simp		  sc->card.cis1_info[1] &&
218120849Simp		  (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
219120849Simp		return (1);
220120849Simp	return (0);
221120849Simp}
222120849Simp
22352506Simpvoid pccard_check_cis_quirks(device_t dev)
22452506Simp{
22564850Simp	struct pccard_softc *sc = PCCARD_SOFTC(dev);
22652506Simp	int wiped = 0;
22752506Simp	int i, j;
22852506Simp	struct pccard_function *pf, *pf_next, *pf_last;
22952506Simp	struct pccard_config_entry *cfe, *cfe_next;
230120849Simp	struct pccard_cis_quirk *q;
23152506Simp
23252506Simp	pf = NULL;
23352506Simp	pf_last = NULL;
23452506Simp
23552506Simp	for (i=0; i<n_pccard_cis_quirks; i++) {
236120849Simp		q = &pccard_cis_quirks[i];
237120849Simp		if (!pccard_cis_quirk_match(sc, q))
238120849Simp			continue;
239120849Simp		if (!wiped) {
240120849Simp			if (bootverbose) {
241120849Simp				device_printf(dev, "using CIS quirks for ");
242120849Simp				for (j = 0; j < 4; j++) {
243120849Simp					if (sc->card.cis1_info[j] == NULL)
244120849Simp						break;
245120849Simp					if (j)
246120849Simp						printf(", ");
247120849Simp					printf("%s", sc->card.cis1_info[j]);
24852506Simp				}
249120849Simp				printf("\n");
250120849Simp			}
25152506Simp
252120849Simp			for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
253120849Simp			     pf = pf_next) {
254120849Simp				for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
255120849Simp				     cfe = cfe_next) {
256120849Simp					cfe_next = STAILQ_NEXT(cfe, cfe_list);
257120849Simp					free(cfe, M_DEVBUF);
25852506Simp				}
259120849Simp				pf_next = STAILQ_NEXT(pf, pf_list);
260120849Simp				free(pf, M_DEVBUF);
26152506Simp			}
26252506Simp
263120849Simp			STAILQ_INIT(&sc->card.pf_head);
264120849Simp			wiped = 1;
265120849Simp		}
26652506Simp
267120849Simp		if (pf_last == q->pf) {
268120849Simp			cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
269120849Simp			*cfe = *q->cfe;
270120849Simp			STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
271120849Simp		} else {
272120849Simp			pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
273120849Simp			*pf = *q->pf;
274120849Simp			STAILQ_INIT(&pf->cfe_head);
275120849Simp			cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
276120849Simp			*cfe = *q->cfe;
277120849Simp			STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
278120849Simp			STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
279120849Simp			pf_last = q->pf;
28052506Simp		}
28152506Simp	}
28252506Simp}
283