pccard_cis_quirks.c revision 65483
165483Simp/*	$NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
252506Simp/* $FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 65483 2000-09-05 18:25:49Z imp $ */
352506Simp
452506Simp#define	PCCARDDEBUG
552506Simp
652506Simp/*
752506Simp * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
852506Simp *
952506Simp * Redistribution and use in source and binary forms, with or without
1052506Simp * modification, are permitted provided that the following conditions
1152506Simp * are met:
1252506Simp * 1. Redistributions of source code must retain the above copyright
1352506Simp *    notice, this list of conditions and the following disclaimer.
1452506Simp * 2. Redistributions in binary form must reproduce the above copyright
1552506Simp *    notice, this list of conditions and the following disclaimer in the
1652506Simp *    documentation and/or other materials provided with the distribution.
1752506Simp * 3. All advertising materials mentioning features or use of this software
1852506Simp *    must display the following acknowledgement:
1952506Simp *	This product includes software developed by Marc Horowitz.
2052506Simp * 4. The name of the author may not be used to endorse or promote products
2152506Simp *    derived from this software without specific prior written permission.
2252506Simp *
2352506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2452506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2552506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2652506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2752506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2852506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2952506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3052506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3152506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3252506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3352506Simp */
3452506Simp
3552506Simp#include <sys/param.h>
3652506Simp#include <sys/systm.h>
3752506Simp#include <sys/malloc.h>
3852506Simp#include <sys/module.h>
3952506Simp#include <sys/kernel.h>
4052506Simp#include <sys/queue.h>
4152506Simp#include <sys/types.h>
4252506Simp
4352506Simp#include <sys/bus.h>
4452506Simp#include <machine/bus.h>
4552506Simp#include <sys/rman.h>
4652506Simp#include <machine/resource.h>
4752506Simp
4852506Simp#include <dev/pccard/pccarddevs.h>
4952506Simp#include <dev/pccard/pccardreg.h>
5052506Simp#include <dev/pccard/pccardvar.h>
5152506Simp
5252506Simp/* There are cards out there whose CIS flat-out lies.  This file
5352506Simp   contains struct pccard_function chains for those devices. */
5452506Simp
5552506Simp/* these structures are just static templates which are then copied
5652506Simp   into "live" allocated structures */
5752506Simp
5852506Simpstruct pccard_function pccard_3cxem556_func0 = {
5952506Simp	0,			/* function number */
6052506Simp	PCCARD_FUNCTION_NETWORK,
6152506Simp	0x07,			/* last cfe number */
6252506Simp	0x800,			/* ccr_base */
6352506Simp	0x63,			/* ccr_mask */
6452506Simp};
6552506Simp
6652506Simpstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
6752506Simp	0x07,			/* cfe number */
6852506Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
6952506Simp	PCCARD_IFTYPE_IO,
7052506Simp	1,			/* num_iospace */
7152506Simp	4,			/* iomask */
7252506Simp	{ { 0x0010, 0 } },	/* iospace */
7352506Simp	0xffff,			/* irqmask */
7452506Simp	0,			/* num_memspace */
7552506Simp	{ },			/* memspace */
7652506Simp	0,			/* maxtwins */
7752506Simp};
7852506Simp
7952506Simpstatic struct pccard_function pccard_3cxem556_func1 = {
8052506Simp	1,			/* function number */
8152506Simp	PCCARD_FUNCTION_SERIAL,
8252506Simp	0x27,			/* last cfe number */
8352506Simp	0x900,			/* ccr_base */
8452506Simp	0x63,			/* ccr_mask */
8552506Simp};
8652506Simp
8752506Simpstatic struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
8852506Simp	0x27,			/* cfe number */
8952506Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
9052506Simp	PCCARD_IFTYPE_IO,
9152506Simp	1,			/* num_iospace */
9252506Simp	3,			/* iomask */
9352506Simp	{ { 0x0008, 0 } },	/* iospace */
9452506Simp	0xffff,			/* irqmask */
9552506Simp	0,			/* num_memspace */
9652506Simp	{ },			/* memspace */
9752506Simp	0,			/* maxtwins */
9852506Simp};
9952506Simp
10053813Simpstatic struct pccard_function pccard_3ccfem556bi_func0 = {
10153813Simp	0,			/* function number */
10253813Simp	PCCARD_FUNCTION_NETWORK,
10353813Simp	0x07,			/* last cfe number */
10453813Simp	0x1000,			/* ccr_base */
10553813Simp	0x267,			/* ccr_mask */
10653813Simp};
10753813Simp
10853813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
10953813Simp	0x07,			/* cfe number */
11053813Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
11153813Simp	PCCARD_IFTYPE_IO,
11253813Simp	1,			/* num_iospace */
11353813Simp	5,			/* iomask */
11453813Simp	{ { 0x0020, 0 } },	/* iospace */
11553813Simp	0xffff,			/* irqmask */
11653813Simp	0,			/* num_memspace */
11753813Simp	{ },			/* memspace */
11853813Simp	0,			/* maxtwins */
11953813Simp};
12053813Simp
12153813Simpstatic struct pccard_function pccard_3ccfem556bi_func1 = {
12253813Simp	1,			/* function number */
12353813Simp	PCCARD_FUNCTION_SERIAL,
12453813Simp	0x27,			/* last cfe number */
12553813Simp	0x1100,			/* ccr_base */
12653813Simp	0x277,			/* ccr_mask */
12753813Simp};
12853813Simp
12953813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
13053813Simp	0x27,			/* cfe number */
13153813Simp	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
13253813Simp	PCCARD_IFTYPE_IO,
13353813Simp	1,			/* num_iospace */
13453813Simp	3,			/* iomask */
13553813Simp	{ { 0x0008, 0 } },	/* iospace */
13653813Simp	0xffff,			/* irqmask */
13753813Simp	0,			/* num_memspace */
13853813Simp	{ },			/* memspace */
13953813Simp	0,			/* maxtwins */
14053813Simp};
14153813Simp
14252506Simpstatic struct pccard_function pccard_sveclancard_func0 = {
14352506Simp	0,			/* function number */
14452506Simp	PCCARD_FUNCTION_NETWORK,
14552506Simp	0x1,			/* last cfe number */
14652506Simp	0x100,			/* ccr_base */
14752506Simp	0x1,			/* ccr_mask */
14852506Simp};
14952506Simp
15052506Simpstatic struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
15152506Simp	0x1,			/* cfe number */
15252506Simp	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
15352506Simp	PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
15452506Simp	PCCARD_IFTYPE_IO,
15552506Simp	1,			/* num_iospace */
15652506Simp	5,			/* iomask */
15752506Simp	{ { 0x20, 0x300 } },	/* iospace */
15852506Simp	0xdeb8,			/* irqmask */
15952506Simp	0,			/* num_memspace */
16052506Simp	{ },			/* memspace */
16152506Simp	0,			/* maxtwins */
16252506Simp};
16352506Simp
16465483Simpstatic struct pccard_function pccard_ndc_nd5100_func0 = {
16565483Simp	0,			/* function number */
16665483Simp	PCCARD_FUNCTION_NETWORK,
16765483Simp	0x23,			/* last cfe number */
16865483Simp	0x3f8,			/* ccr_base */
16965483Simp	0x3,			/* ccr_mask */
17065483Simp};
17165483Simp
17265483Simpstatic struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
17365483Simp	0x20,			/* cfe number */
17465483Simp	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
17565483Simp	PCCARD_IFTYPE_IO,
17665483Simp	1,			/* num_iospace */
17765483Simp	5,			/* iomask */
17865483Simp	{ { 0x20, 0x300 } },	/* iospace */
17965483Simp	0xdeb8,			/* irqmask */
18065483Simp	0,			/* num_memspace */
18165483Simp	{ },			/* memspace */
18265483Simp	0,			/* maxtwins */
18365483Simp};
18465483Simp
18552506Simpstatic struct pccard_cis_quirk pccard_cis_quirks[] = {
18652506Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID,
18752506Simp	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
18852506Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID,
18952506Simp	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
19053813Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556INT, PCCARD_CIS_INVALID,
19153813Simp	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
19253813Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556INT, PCCARD_CIS_INVALID,
19353813Simp	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
19453813Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CCFEM556BI,
19553813Simp	  PCCARD_CIS_INVALID,
19653813Simp	  &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
19753813Simp	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CCFEM556BI,
19853813Simp	  PCCARD_CIS_INVALID,
19953813Simp	  &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
20052506Simp	{ PCCARD_VENDOR_INVALID, PCCARD_PRODUCT_INVALID, PCCARD_CIS_SVEC_LANCARD,
20152506Simp	  &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
20265483Simp	{ PCCARD_VENDOR_INVALID, PCCARD_PRODUCT_INVALID, PCCARD_CIS_NDC_ND5100_E,
20365483Simp	  &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
20452506Simp};
20552506Simp
20652506Simpstatic int n_pccard_cis_quirks =
20752506Simp	sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
20852506Simp
20952506Simpvoid pccard_check_cis_quirks(device_t dev)
21052506Simp{
21164850Simp	struct pccard_softc *sc = PCCARD_SOFTC(dev);
21252506Simp	int wiped = 0;
21352506Simp	int i, j;
21452506Simp	struct pccard_function *pf, *pf_next, *pf_last;
21552506Simp	struct pccard_config_entry *cfe, *cfe_next;
21652506Simp
21752506Simp	pf = NULL;
21852506Simp	pf_last = NULL;
21952506Simp
22052506Simp	for (i=0; i<n_pccard_cis_quirks; i++) {
22152506Simp		if ((sc->card.manufacturer == pccard_cis_quirks[i].manufacturer) &&
22252506Simp			(sc->card.product == pccard_cis_quirks[i].product) &&
22352506Simp			(((sc->card.manufacturer != PCCARD_VENDOR_INVALID) &&
22452506Simp			  (sc->card.product != PCCARD_PRODUCT_INVALID)) ||
22552506Simp			 ((sc->card.manufacturer == PCCARD_VENDOR_INVALID) &&
22652506Simp			  (sc->card.product == PCCARD_PRODUCT_INVALID) &&
22752506Simp			  sc->card.cis1_info[0] &&
22852506Simp			  (strcmp(sc->card.cis1_info[0],
22952506Simp					  pccard_cis_quirks[i].cis1_info[0]) == 0) &&
23052506Simp			  sc->card.cis1_info[1] &&
23152506Simp			  (strcmp(sc->card.cis1_info[1],
23252506Simp					  pccard_cis_quirks[i].cis1_info[1]) == 0)))) {
23352506Simp			if (!wiped) {
23452506Simp				if (pccard_verbose) {
23552506Simp					device_printf(dev, "using CIS quirks for ");
23652506Simp					for (j = 0; j < 4; j++) {
23752506Simp						if (sc->card.cis1_info[j] == NULL)
23852506Simp							break;
23952506Simp						if (j)
24052506Simp							printf(", ");
24152506Simp						printf("%s", sc->card.cis1_info[j]);
24252506Simp					}
24352506Simp					printf("\n");
24452506Simp				}
24552506Simp
24652506Simp				for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
24752506Simp				     pf = pf_next) {
24852506Simp					for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
24952506Simp					     cfe = cfe_next) {
25052506Simp						cfe_next = STAILQ_NEXT(cfe, cfe_list);
25152506Simp						free(cfe, M_DEVBUF);
25252506Simp					}
25352506Simp					pf_next = STAILQ_NEXT(pf, pf_list);
25452506Simp					free(pf, M_DEVBUF);
25552506Simp				}
25652506Simp
25752506Simp				STAILQ_INIT(&sc->card.pf_head);
25852506Simp				wiped = 1;
25952506Simp			}
26052506Simp
26152506Simp			if (pf_last == pccard_cis_quirks[i].pf) {
26252506Simp				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
26352506Simp				*cfe = *pccard_cis_quirks[i].cfe;
26452506Simp
26552506Simp				STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
26652506Simp			} else {
26752506Simp				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
26852506Simp				*pf = *pccard_cis_quirks[i].pf;
26952506Simp				STAILQ_INIT(&pf->cfe_head);
27052506Simp
27152506Simp				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
27252506Simp				*cfe = *pccard_cis_quirks[i].cfe;
27352506Simp
27452506Simp				STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
27552506Simp				STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
27652506Simp
27752506Simp				pf_last = pccard_cis_quirks[i].pf;
27852506Simp			}
27952506Simp		}
28052506Simp	}
28152506Simp}
282