pcmcia_cis.c revision 1.34
1/*	$NetBSD: pcmcia_cis.c,v 1.34 2004/08/07 01:52:42 mycroft Exp $	*/
2
3/*
4 * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: pcmcia_cis.c,v 1.34 2004/08/07 01:52:42 mycroft Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/device.h>
38#include <sys/malloc.h>
39
40#include <dev/pcmcia/pcmciareg.h>
41#include <dev/pcmcia/pcmciachip.h>
42#include <dev/pcmcia/pcmciavar.h>
43
44#ifdef PCMCIACISDEBUG
45int	pcmciacis_debug = 0;
46#define	DPRINTF(arg) if (pcmciacis_debug) printf arg
47#else
48#define	DPRINTF(arg)
49#endif
50
51#define	PCMCIA_CIS_SIZE		1024
52
53struct cis_state {
54	int	count;
55	int	gotmfc;
56	struct pcmcia_config_entry temp_cfe;
57	struct pcmcia_config_entry *default_cfe;
58	struct pcmcia_card *card;
59	struct pcmcia_function *pf;
60};
61
62int	pcmcia_parse_cis_tuple __P((struct pcmcia_tuple *, void *));
63static int decode_funce __P((struct pcmcia_tuple *, struct pcmcia_function *));
64static void create_pf __P((struct cis_state *));
65
66
67static void
68create_pf(struct cis_state *state)
69{
70	state->pf = malloc(sizeof(*state->pf), M_DEVBUF, M_NOWAIT|M_ZERO);
71	state->pf->number = state->count++;
72	state->pf->last_config_index = -1;
73	SIMPLEQ_INIT(&state->pf->cfe_head);
74	SIMPLEQ_INSERT_TAIL(&state->card->pf_head, state->pf, pf_list);
75}
76
77void
78pcmcia_free_pf(struct pcmcia_function_head *pfhead)
79{
80	struct pcmcia_function *pf, *opf = NULL;
81	struct pcmcia_config_entry *cfe, *ocfe = NULL;
82
83	SIMPLEQ_FOREACH(pf, pfhead, pf_list) {
84		SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
85			if (ocfe)
86				free(ocfe, M_DEVBUF);
87			ocfe = cfe;
88		}
89		if (ocfe) {
90			free(ocfe, M_DEVBUF);
91			ocfe = NULL;
92		}
93		if (opf)
94			free(opf, M_DEVBUF);
95		opf = pf;
96	}
97	if (opf)
98		free(opf, M_DEVBUF);
99
100	SIMPLEQ_INIT(pfhead);
101}
102
103void
104pcmcia_read_cis(sc)
105	struct pcmcia_softc *sc;
106{
107	struct cis_state state;
108
109	memset(&state, 0, sizeof state);
110
111	state.card = &sc->card;
112
113	state.card->error = 0;
114	state.card->cis1_major = -1;
115	state.card->cis1_minor = -1;
116	state.card->cis1_info[0] = NULL;
117	state.card->cis1_info[1] = NULL;
118	state.card->cis1_info[2] = NULL;
119	state.card->cis1_info[3] = NULL;
120	state.card->manufacturer = PCMCIA_VENDOR_INVALID;
121	state.card->product = PCMCIA_PRODUCT_INVALID;
122	SIMPLEQ_INIT(&state.card->pf_head);
123
124	state.pf = NULL;
125
126	if (pcmcia_scan_cis((struct device *)sc, pcmcia_parse_cis_tuple,
127	    &state) == -1)
128		state.card->error++;
129}
130
131int
132pcmcia_scan_cis(dev, fct, arg)
133	struct device *dev;
134	int (*fct) __P((struct pcmcia_tuple *, void *));
135	void *arg;
136{
137	struct pcmcia_softc *sc = (struct pcmcia_softc *) dev;
138	pcmcia_chipset_tag_t pct;
139	pcmcia_chipset_handle_t pch;
140	int window;
141	struct pcmcia_mem_handle pcmh;
142	struct pcmcia_tuple tuple;
143	int longlink_present;
144	int longlink_common;
145	u_long longlink_addr;
146	int mfc_count;
147	int mfc_index;
148	struct {
149		int	common;
150		u_long	addr;
151	} mfc[256 / 5];
152	int ret;
153
154	ret = 0;
155
156	pct = sc->pct;
157	pch = sc->pch;
158
159	/* allocate some memory */
160
161	if (pcmcia_chip_mem_alloc(pct, pch, PCMCIA_CIS_SIZE, &pcmh)) {
162#ifdef DIAGNOSTIC
163		printf("%s: can't alloc memory to read attributes\n",
164		    sc->dev.dv_xname);
165#endif
166		return -1;
167	}
168	/* initialize state for the primary tuple chain */
169	if (pcmcia_chip_mem_map(pct, pch, PCMCIA_MEM_ATTR, 0,
170	    PCMCIA_CIS_SIZE, &pcmh, &tuple.ptr, &window)) {
171		pcmcia_chip_mem_free(pct, pch, &pcmh);
172#ifdef DIAGNOSTIC
173		printf("%s: can't map memory to read attributes\n",
174		    sc->dev.dv_xname);
175#endif
176		return -1;
177	}
178	tuple.memt = pcmh.memt;
179	tuple.memh = pcmh.memh;
180
181	DPRINTF(("cis mem map %x\n", (unsigned int) tuple.memh));
182
183	tuple.mult = 2;
184
185	longlink_present = 1;
186	longlink_common = 1;
187	longlink_addr = 0;
188
189	mfc_count = 0;
190	mfc_index = 0;
191
192	DPRINTF(("%s: CIS tuple chain:\n", sc->dev.dv_xname));
193
194	while (1) {
195		DELAY(1000);
196
197		while (1) {
198			/*
199			 * Perform boundary check for insane cards.
200			 * If CIS is too long, simulate CIS end.
201			 * (This check may not be sufficient for
202			 * malicious cards.)
203			 */
204			if (tuple.mult * tuple.ptr >= PCMCIA_CIS_SIZE - 1
205			    - 32 /* ad hoc value */ ) {
206				DPRINTF(("CISTPL_END (too long CIS)\n"));
207				tuple.code = PCMCIA_CISTPL_END;
208				goto cis_end;
209			}
210
211			/* get the tuple code */
212
213			tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr);
214
215			/* two special-case tuples */
216
217			if (tuple.code == PCMCIA_CISTPL_NULL) {
218				DPRINTF((" 00\nCISTPL_NONE\n"));
219				tuple.ptr++;
220				continue;
221			} else if (tuple.code == PCMCIA_CISTPL_END) {
222				DPRINTF((" ff\nCISTPL_END\n"));
223			cis_end:
224				/* Call the function for the END tuple, since
225				   the CIS semantics depend on it */
226				if ((*fct) (&tuple, arg)) {
227					pcmcia_chip_mem_unmap(pct, pch,
228							      window);
229					ret = 1;
230					goto done;
231				}
232				tuple.ptr++;
233				break;
234			}
235
236			/* now all the normal tuples */
237
238			tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1);
239#ifdef PCMCIACISDEBUG
240			/* print the tuple */
241			{
242				int i;
243
244				DPRINTF((" %02x %02x", tuple.code,
245				    tuple.length));
246
247				for (i = 0; i < tuple.length; i++) {
248					DPRINTF((" %02x",
249					    pcmcia_tuple_read_1(&tuple, i)));
250					if ((i % 16) == 13)
251						DPRINTF(("\n"));
252				}
253				if ((i % 16) != 14)
254					DPRINTF(("\n"));
255			}
256#endif
257			switch (tuple.code) {
258			case PCMCIA_CISTPL_LONGLINK_A:
259			case PCMCIA_CISTPL_LONGLINK_C:
260				if (tuple.length < 4) {
261					DPRINTF(("CISTPL_LONGLINK_%s too "
262					    "short %d\n",
263					    longlink_common ? "C" : "A",
264					    tuple.length));
265					break;
266				}
267				longlink_present = 1;
268				longlink_common = (tuple.code ==
269				    PCMCIA_CISTPL_LONGLINK_C) ? 1 : 0;
270				longlink_addr = pcmcia_tuple_read_4(&tuple, 0);
271				DPRINTF(("CISTPL_LONGLINK_%s %lx\n",
272				    longlink_common ? "C" : "A",
273				    longlink_addr));
274				break;
275			case PCMCIA_CISTPL_NO_LINK:
276				longlink_present = 0;
277				DPRINTF(("CISTPL_NO_LINK\n"));
278				break;
279			case PCMCIA_CISTPL_CHECKSUM:
280				if (tuple.length < 5) {
281					DPRINTF(("CISTPL_CHECKSUM too "
282					    "short %d\n", tuple.length));
283					break;
284				} {
285					int16_t offset;
286					u_long addr, length;
287					u_int cksum, sum;
288					int i;
289
290					*((u_int16_t *) & offset) =
291					    pcmcia_tuple_read_2(&tuple, 0);
292					length = pcmcia_tuple_read_2(&tuple, 2);
293					cksum = pcmcia_tuple_read_1(&tuple, 4);
294
295					addr = tuple.ptr + offset;
296
297					DPRINTF(("CISTPL_CHECKSUM addr=%lx "
298					    "len=%lx cksum=%x",
299					    addr, length, cksum));
300
301					/*
302					 * XXX do more work to deal with
303					 * distant regions
304					 */
305					if ((addr >= PCMCIA_CIS_SIZE) ||
306					    ((addr + length) < 0) ||
307					    ((addr + length) >=
308					      PCMCIA_CIS_SIZE)) {
309						DPRINTF((" skipped, "
310						    "too distant\n"));
311						break;
312					}
313					sum = 0;
314					for (i = 0; i < length; i++)
315						sum +=
316						    bus_space_read_1(tuple.memt,
317						    tuple.memh,
318						    addr + tuple.mult * i);
319					if (cksum != (sum & 0xff)) {
320						DPRINTF((" failed sum=%x\n",
321						    sum));
322						printf("%s: CIS checksum "
323						    "failed\n",
324						    sc->dev.dv_xname);
325#if 0
326						/*
327						 * XXX Some working cards have
328						 * XXX bad checksums!!
329						 */
330						ret = -1;
331#endif
332					} else {
333						DPRINTF((" ok\n"));
334					}
335				}
336				break;
337			case PCMCIA_CISTPL_LONGLINK_MFC:
338				if (tuple.length < 1) {
339					DPRINTF(("CISTPL_LONGLINK_MFC too "
340					    "short %d\n", tuple.length));
341					break;
342				}
343				if (((tuple.length - 1) % 5) != 0) {
344					DPRINTF(("CISTPL_LONGLINK_MFC bogus "
345					    "length %d\n", tuple.length));
346					break;
347				}
348				/*
349				 * this is kind of ad hoc, as I don't have
350				 * any real documentation
351				 */
352				{
353					int i, tmp_count;
354
355					/*
356					 * put count into tmp var so that
357					 * if we have to bail (because it's
358					 * a bogus count) it won't be
359					 * remembered for later use.
360					 */
361					tmp_count =
362					    pcmcia_tuple_read_1(&tuple, 0);
363					DPRINTF(("CISTPL_LONGLINK_MFC %d",
364					    tmp_count));
365
366					/*
367					 * make _sure_ it's the right size;
368					 * if too short, it may be a weird
369					 * (unknown/undefined) format
370					 */
371					if (tuple.length != (tmp_count*5 + 1)) {
372						DPRINTF((" bogus length %d\n",
373						    tuple.length));
374						break;
375					}
376
377#ifdef PCMCIACISDEBUG	/* maybe enable all the time? */
378					/*
379					 * sanity check for a programming
380					 * error which is difficult to find
381					 * when debugging.
382					 */
383					if (tmp_count >
384					    howmany(sizeof mfc, sizeof mfc[0]))
385						panic("CISTPL_LONGLINK_MFC mfc "
386						    "count would blow stack");
387#endif
388
389					mfc_count = tmp_count;
390					for (i = 0; i < mfc_count; i++) {
391						mfc[i].common =
392						    (pcmcia_tuple_read_1(&tuple,
393						    1 + 5 * i) ==
394						    PCMCIA_MFC_MEM_COMMON) ?
395						    1 : 0;
396						mfc[i].addr =
397						    pcmcia_tuple_read_4(&tuple,
398						    1 + 5 * i + 1);
399						DPRINTF((" %s:%lx",
400						    mfc[i].common ? "common" :
401						    "attr", mfc[i].addr));
402					}
403					DPRINTF(("\n"));
404				}
405				/*
406				 * for LONGLINK_MFC, fall through to the
407				 * function.  This tuple has structural and
408				 * semantic content.
409				 */
410			default:
411				{
412					if ((*fct) (&tuple, arg)) {
413						pcmcia_chip_mem_unmap(pct,
414						    pch, window);
415						ret = 1;
416						goto done;
417					}
418				}
419				break;
420			}	/* switch */
421			/* skip to the next tuple */
422			tuple.ptr += 2 + tuple.length;
423		}
424
425		/*
426		 * the chain is done.  Clean up and move onto the next one,
427		 * if any.  The loop is here in the case that there is an MFC
428		 * card with no longlink (which defaults to existing, == 0).
429		 * In general, this means that if one pointer fails, it will
430		 * try the next one, instead of just bailing.
431		 */
432
433		while (1) {
434			pcmcia_chip_mem_unmap(pct, pch, window);
435
436			if (longlink_present) {
437				/*
438				 * if the longlink is to attribute memory,
439				 * then it is unindexed.  That is, if the
440				 * link value is 0x100, then the actual
441				 * memory address is 0x200.  This means that
442				 * we need to multiply by 2 before calling
443				 * mem_map, and then divide the resulting ptr
444				 * by 2 after.
445				 */
446
447				if (!longlink_common)
448					longlink_addr *= 2;
449
450				pcmcia_chip_mem_map(pct, pch, longlink_common ?
451				    (PCMCIA_WIDTH_MEM8 | PCMCIA_MEM_COMMON) :
452				    PCMCIA_MEM_ATTR,
453				    longlink_addr, PCMCIA_CIS_SIZE,
454				    &pcmh, &tuple.ptr, &window);
455
456				if (!longlink_common)
457					tuple.ptr /= 2;
458
459				DPRINTF(("cis mem map %x\n",
460				    (unsigned int) tuple.memh));
461
462				tuple.mult = longlink_common ? 1 : 2;
463				longlink_present = 0;
464				longlink_common = 1;
465				longlink_addr = 0;
466			} else if (mfc_count && (mfc_index < mfc_count)) {
467				if (!mfc[mfc_index].common)
468					mfc[mfc_index].addr *= 2;
469
470				pcmcia_chip_mem_map(pct, pch,
471				    mfc[mfc_index].common ?
472				    (PCMCIA_WIDTH_MEM8 | PCMCIA_MEM_COMMON) :
473				    PCMCIA_MEM_ATTR,
474				    mfc[mfc_index].addr, PCMCIA_CIS_SIZE,
475				    &pcmh, &tuple.ptr, &window);
476
477				if (!mfc[mfc_index].common)
478					tuple.ptr /= 2;
479
480				DPRINTF(("cis mem map %x\n",
481				    (unsigned int) tuple.memh));
482
483				/* set parse state, and point at the next one */
484
485				tuple.mult = mfc[mfc_index].common ? 1 : 2;
486
487				mfc_index++;
488			} else {
489				goto done;
490			}
491
492			/* make sure that the link is valid */
493			tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr);
494			if (tuple.code != PCMCIA_CISTPL_LINKTARGET) {
495				DPRINTF(("CISTPL_LINKTARGET expected, "
496				    "code %02x observed\n", tuple.code));
497				continue;
498			}
499			tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1);
500			if (tuple.length < 3) {
501				DPRINTF(("CISTPL_LINKTARGET too short %d\n",
502				    tuple.length));
503				continue;
504			}
505			if ((pcmcia_tuple_read_1(&tuple, 0) != 'C') ||
506			    (pcmcia_tuple_read_1(&tuple, 1) != 'I') ||
507			    (pcmcia_tuple_read_1(&tuple, 2) != 'S')) {
508				DPRINTF(("CISTPL_LINKTARGET magic "
509				    "%02x%02x%02x incorrect\n",
510				    pcmcia_tuple_read_1(&tuple, 0),
511				    pcmcia_tuple_read_1(&tuple, 1),
512				    pcmcia_tuple_read_1(&tuple, 2)));
513				continue;
514			}
515			tuple.ptr += 2 + tuple.length;
516
517			break;
518		}
519	}
520
521	pcmcia_chip_mem_unmap(pct, pch, window);
522
523done:
524	/* Last, free the allocated memory block */
525	pcmcia_chip_mem_free(pct, pch, &pcmh);
526
527	return (ret);
528}
529
530/* XXX this is incredibly verbose.  Not sure what trt is */
531
532void
533pcmcia_print_cis(sc)
534	struct pcmcia_softc *sc;
535{
536	struct pcmcia_card *card = &sc->card;
537	struct pcmcia_function *pf;
538	struct pcmcia_config_entry *cfe;
539	int i;
540
541	printf("%s: CIS version ", sc->dev.dv_xname);
542	if (card->cis1_major == 4) {
543		if (card->cis1_minor == 0)
544			printf("PCMCIA 1.0\n");
545		else if (card->cis1_minor == 1)
546			printf("PCMCIA 2.0 or 2.1\n");
547	} else if (card->cis1_major >= 5)
548		printf("PC Card Standard %d.%d\n", card->cis1_major, card->cis1_minor);
549	else
550		printf("unknown (major=%d, minor=%d)\n",
551		    card->cis1_major, card->cis1_minor);
552
553	printf("%s: CIS info: ", sc->dev.dv_xname);
554	for (i = 0; i < 4; i++) {
555		if (card->cis1_info[i] == NULL)
556			break;
557		if (i)
558			printf(", ");
559		printf("%s", card->cis1_info[i]);
560	}
561	printf("\n");
562
563	printf("%s: Manufacturer code 0x%x, product 0x%x\n",
564	       sc->dev.dv_xname, card->manufacturer, card->product);
565
566	SIMPLEQ_FOREACH(pf, &card->pf_head, pf_list) {
567		printf("%s: function %d: ", sc->dev.dv_xname, pf->number);
568
569		switch (pf->function) {
570		case PCMCIA_FUNCTION_UNSPEC:
571			printf("unspecified");
572			break;
573		case PCMCIA_FUNCTION_MULTIFUNCTION:
574			printf("multi-function");
575			break;
576		case PCMCIA_FUNCTION_MEMORY:
577			printf("memory");
578			break;
579		case PCMCIA_FUNCTION_SERIAL:
580			printf("serial port");
581			break;
582		case PCMCIA_FUNCTION_PARALLEL:
583			printf("parallel port");
584			break;
585		case PCMCIA_FUNCTION_DISK:
586			printf("fixed disk");
587			switch (pf->pf_funce_disk_interface) {
588			case PCMCIA_TPLFE_DDI_PCCARD_ATA:
589				printf("(ata)");
590				break;
591			default:
592				break;
593			}
594			break;
595		case PCMCIA_FUNCTION_VIDEO:
596			printf("video adapter");
597			break;
598		case PCMCIA_FUNCTION_NETWORK:
599			printf("network adapter");
600			break;
601		case PCMCIA_FUNCTION_AIMS:
602			printf("auto incrementing mass storage");
603			break;
604		case PCMCIA_FUNCTION_SCSI:
605			printf("SCSI bridge");
606			break;
607		case PCMCIA_FUNCTION_SECURITY:
608			printf("Security services");
609			break;
610		case PCMCIA_FUNCTION_INSTRUMENT:
611			printf("Instrument");
612			break;
613		default:
614			printf("unknown (%d)", pf->function);
615			break;
616		}
617
618		printf(", ccr addr %lx mask %lx\n", pf->ccr_base, pf->ccr_mask);
619
620		SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
621			printf("%s: function %d, config table entry %d: ",
622			    sc->dev.dv_xname, pf->number, cfe->number);
623
624			switch (cfe->iftype) {
625			case PCMCIA_IFTYPE_MEMORY:
626				printf("memory card");
627				break;
628			case PCMCIA_IFTYPE_IO:
629				printf("I/O card");
630				break;
631			default:
632				printf("card type unknown");
633				break;
634			}
635
636			printf("; irq mask %x", cfe->irqmask);
637
638			if (cfe->num_iospace) {
639				printf("; iomask %lx, iospace", cfe->iomask);
640
641				for (i = 0; i < cfe->num_iospace; i++) {
642					printf(" %lx", cfe->iospace[i].start);
643					if (cfe->iospace[i].length)
644						printf("-%lx",
645						    cfe->iospace[i].start +
646						    cfe->iospace[i].length - 1);
647				}
648			}
649			if (cfe->num_memspace) {
650				printf("; memspace");
651
652				for (i = 0; i < cfe->num_memspace; i++) {
653					printf(" %lx",
654					    cfe->memspace[i].cardaddr);
655					if (cfe->memspace[i].length)
656						printf("-%lx",
657						    cfe->memspace[i].cardaddr +
658						    cfe->memspace[i].length - 1);
659					if (cfe->memspace[i].hostaddr)
660						printf("@%lx",
661						    cfe->memspace[i].hostaddr);
662				}
663			}
664			if (cfe->maxtwins)
665				printf("; maxtwins %d", cfe->maxtwins);
666
667			printf(";");
668
669			if (cfe->flags & PCMCIA_CFE_MWAIT_REQUIRED)
670				printf(" mwait_required");
671			if (cfe->flags & PCMCIA_CFE_RDYBSY_ACTIVE)
672				printf(" rdybsy_active");
673			if (cfe->flags & PCMCIA_CFE_WP_ACTIVE)
674				printf(" wp_active");
675			if (cfe->flags & PCMCIA_CFE_BVD_ACTIVE)
676				printf(" bvd_active");
677			if (cfe->flags & PCMCIA_CFE_IO8)
678				printf(" io8");
679			if (cfe->flags & PCMCIA_CFE_IO16)
680				printf(" io16");
681			if (cfe->flags & PCMCIA_CFE_IRQSHARE)
682				printf(" irqshare");
683			if (cfe->flags & PCMCIA_CFE_IRQPULSE)
684				printf(" irqpulse");
685			if (cfe->flags & PCMCIA_CFE_IRQLEVEL)
686				printf(" irqlevel");
687			if (cfe->flags & PCMCIA_CFE_POWERDOWN)
688				printf(" powerdown");
689			if (cfe->flags & PCMCIA_CFE_READONLY)
690				printf(" readonly");
691			if (cfe->flags & PCMCIA_CFE_AUDIO)
692				printf(" audio");
693
694			printf("\n");
695		}
696	}
697
698	if (card->error)
699		printf("%s: %d errors found while parsing CIS\n",
700		    sc->dev.dv_xname, card->error);
701}
702
703int
704pcmcia_parse_cis_tuple(tuple, arg)
705	struct pcmcia_tuple *tuple;
706	void *arg;
707{
708	/* most of these are educated guesses */
709	static struct pcmcia_config_entry init_cfe = {
710		-1, PCMCIA_CFE_RDYBSY_ACTIVE | PCMCIA_CFE_WP_ACTIVE |
711		PCMCIA_CFE_BVD_ACTIVE, PCMCIA_IFTYPE_MEMORY,
712	};
713
714	struct cis_state *state = arg;
715
716	switch (tuple->code) {
717	case PCMCIA_CISTPL_END:
718		/* if we've seen a LONGLINK_MFC, and this is the first
719		 * END after it, reset the function list.
720		 *
721		 * XXX This might also be the right place to start a
722		 * new function, but that assumes that a function
723		 * definition never crosses any longlink, and I'm not
724		 * sure about that.  This is probably safe for MFC
725		 * cards, but what we have now isn't broken, so I'd
726		 * rather not change it.
727		 */
728		if (state->gotmfc == 1) {
729			state->gotmfc = 2;
730			state->count = 0;
731			state->pf = NULL;
732
733			pcmcia_free_pf(&state->card->pf_head);
734		}
735		break;
736	case PCMCIA_CISTPL_LONGLINK_MFC:
737		/*
738		 * this tuple's structure was dealt with in scan_cis.  here,
739		 * record the fact that the MFC tuple was seen, so that
740		 * functions declared before the MFC link can be cleaned
741		 * up.
742		 */
743		if (state->gotmfc == 0) {
744			state->gotmfc = 1;
745		} else {
746			DPRINTF(("got LONGLINK_MFC again!"));
747		}
748		break;
749#ifdef PCMCIACISDEBUG
750	case PCMCIA_CISTPL_DEVICE:
751	case PCMCIA_CISTPL_DEVICE_A:
752		{
753			u_int reg, dtype, dspeed;
754
755			reg = pcmcia_tuple_read_1(tuple, 0);
756			dtype = reg & PCMCIA_DTYPE_MASK;
757			dspeed = reg & PCMCIA_DSPEED_MASK;
758
759			DPRINTF(("CISTPL_DEVICE%s type=",
760			(tuple->code == PCMCIA_CISTPL_DEVICE) ? "" : "_A"));
761			switch (dtype) {
762			case PCMCIA_DTYPE_NULL:
763				DPRINTF(("null"));
764				break;
765			case PCMCIA_DTYPE_ROM:
766				DPRINTF(("rom"));
767				break;
768			case PCMCIA_DTYPE_OTPROM:
769				DPRINTF(("otprom"));
770				break;
771			case PCMCIA_DTYPE_EPROM:
772				DPRINTF(("eprom"));
773				break;
774			case PCMCIA_DTYPE_EEPROM:
775				DPRINTF(("eeprom"));
776				break;
777			case PCMCIA_DTYPE_FLASH:
778				DPRINTF(("flash"));
779				break;
780			case PCMCIA_DTYPE_SRAM:
781				DPRINTF(("sram"));
782				break;
783			case PCMCIA_DTYPE_DRAM:
784				DPRINTF(("dram"));
785				break;
786			case PCMCIA_DTYPE_FUNCSPEC:
787				DPRINTF(("funcspec"));
788				break;
789			case PCMCIA_DTYPE_EXTEND:
790				DPRINTF(("extend"));
791				break;
792			default:
793				DPRINTF(("reserved"));
794				break;
795			}
796			DPRINTF((" speed="));
797			switch (dspeed) {
798			case PCMCIA_DSPEED_NULL:
799				DPRINTF(("null"));
800				break;
801			case PCMCIA_DSPEED_250NS:
802				DPRINTF(("250ns"));
803				break;
804			case PCMCIA_DSPEED_200NS:
805				DPRINTF(("200ns"));
806				break;
807			case PCMCIA_DSPEED_150NS:
808				DPRINTF(("150ns"));
809				break;
810			case PCMCIA_DSPEED_100NS:
811				DPRINTF(("100ns"));
812				break;
813			case PCMCIA_DSPEED_EXT:
814				DPRINTF(("ext"));
815				break;
816			default:
817				DPRINTF(("reserved"));
818				break;
819			}
820		}
821		DPRINTF(("\n"));
822		break;
823#endif
824	case PCMCIA_CISTPL_VERS_1:
825		if (tuple->length < 6) {
826			DPRINTF(("CISTPL_VERS_1 too short %d\n",
827			    tuple->length));
828			break;
829		} {
830			int start, i, ch, count;
831
832			state->card->cis1_major = pcmcia_tuple_read_1(tuple, 0);
833			state->card->cis1_minor = pcmcia_tuple_read_1(tuple, 1);
834
835			for (count = 0, start = 0, i = 0;
836			    (count < 4) && ((i + 4) < 256); i++) {
837				ch = pcmcia_tuple_read_1(tuple, 2 + i);
838				if (ch == 0xff) {
839					if (i > start) {
840						state->card->cis1_info_buf[i] = 0;
841						state->card->cis1_info[count] =
842						    state->card->cis1_info_buf + start;
843					}
844					break;
845				}
846				state->card->cis1_info_buf[i] = ch;
847				if (ch == 0) {
848					state->card->cis1_info[count] =
849					    state->card->cis1_info_buf + start;
850					start = i + 1;
851					count++;
852				}
853			}
854			DPRINTF(("CISTPL_VERS_1\n"));
855		}
856		break;
857	case PCMCIA_CISTPL_MANFID:
858		if (tuple->length < 4) {
859			DPRINTF(("CISTPL_MANFID too short %d\n",
860			    tuple->length));
861			break;
862		}
863		state->card->manufacturer = pcmcia_tuple_read_2(tuple, 0);
864		state->card->product = pcmcia_tuple_read_2(tuple, 2);
865		DPRINTF(("CISTPL_MANFID\n"));
866		break;
867	case PCMCIA_CISTPL_FUNCID:
868		if (tuple->length < 1) {
869			DPRINTF(("CISTPL_FUNCID too short %d\n",
870			    tuple->length));
871			break;
872		}
873		if (state->pf) {
874			if (state->pf->function == PCMCIA_FUNCTION_UNSPEC) {
875				/*
876				 * This looks like a opportunistic function
877				 * created by a CONFIG tuple.  Just keep it.
878				 */
879			} else {
880				/*
881				 * A function is being defined, end it.
882				 */
883				state->pf = NULL;
884			}
885		}
886		if (state->pf == NULL)
887			create_pf(state);
888		state->pf->function = pcmcia_tuple_read_1(tuple, 0);
889
890		DPRINTF(("CISTPL_FUNCID\n"));
891		break;
892	case PCMCIA_CISTPL_FUNCE:
893		if (state->pf == NULL || state->pf->function <= 0) {
894			DPRINTF(("CISTPL_FUNCE is not followed by "
895			    "valid CISTPL_FUNCID\n"));
896			break;
897		}
898		if (tuple->length >= 2) {
899			decode_funce(tuple, state->pf);
900		}
901		break;
902	case PCMCIA_CISTPL_CONFIG:
903		if (tuple->length < 3) {
904			DPRINTF(("CISTPL_CONFIG too short %d\n",
905			    tuple->length));
906			break;
907		} {
908			u_int reg, rasz, rmsz, rfsz;
909			int i;
910
911			reg = pcmcia_tuple_read_1(tuple, 0);
912			rasz = 1 + ((reg & PCMCIA_TPCC_RASZ_MASK) >>
913			    PCMCIA_TPCC_RASZ_SHIFT);
914			rmsz = 1 + ((reg & PCMCIA_TPCC_RMSZ_MASK) >>
915			    PCMCIA_TPCC_RMSZ_SHIFT);
916			rfsz = ((reg & PCMCIA_TPCC_RFSZ_MASK) >>
917			    PCMCIA_TPCC_RFSZ_SHIFT);
918
919			if (tuple->length < (rasz + rmsz + rfsz)) {
920				DPRINTF(("CISTPL_CONFIG (%d,%d,%d) too "
921				    "short %d\n", rasz, rmsz, rfsz,
922				    tuple->length));
923				break;
924			}
925			if (state->pf == NULL) {
926				create_pf(state);
927				state->pf->function = PCMCIA_FUNCTION_UNSPEC;
928			}
929			state->pf->last_config_index =
930			    pcmcia_tuple_read_1(tuple, 1);
931
932			state->pf->ccr_base = 0;
933			for (i = 0; i < rasz; i++)
934				state->pf->ccr_base |=
935				    ((pcmcia_tuple_read_1(tuple, 2 + i)) <<
936				    (i * 8));
937
938			state->pf->ccr_mask = 0;
939			for (i = 0; i < rmsz; i++)
940				state->pf->ccr_mask |=
941				    ((pcmcia_tuple_read_1(tuple,
942				    2 + rasz + i)) << (i * 8));
943
944			/* skip the reserved area and subtuples */
945
946			/* reset the default cfe for each cfe list */
947			state->temp_cfe = init_cfe;
948			state->default_cfe = &state->temp_cfe;
949		}
950		DPRINTF(("CISTPL_CONFIG\n"));
951		break;
952	case PCMCIA_CISTPL_CFTABLE_ENTRY:
953		{
954			int idx, i, j;
955			u_int reg, reg2;
956			u_int intface, def, num;
957			u_int power, timing, iospace, irq, memspace, misc;
958			struct pcmcia_config_entry *cfe;
959
960			idx = 0;
961
962			reg = pcmcia_tuple_read_1(tuple, idx);
963			idx++;
964			intface = reg & PCMCIA_TPCE_INDX_INTFACE;
965			def = reg & PCMCIA_TPCE_INDX_DEFAULT;
966			num = reg & PCMCIA_TPCE_INDX_NUM_MASK;
967
968			/*
969			 * this is a little messy.  Some cards have only a
970			 * cfentry with the default bit set.  So, as we go
971			 * through the list, we add new indexes to the queue,
972			 * and keep a pointer to the last one with the
973			 * default bit set.  if we see a record with the same
974			 * index, as the default, we stash the default and
975			 * replace the queue entry. otherwise, we just add
976			 * new entries to the queue, pointing the default ptr
977			 * at them if the default bit is set.  if we get to
978			 * the end with the default pointer pointing at a
979			 * record which hasn't had a matching index, that's
980			 * ok; it just becomes a cfentry like any other.
981			 */
982
983			/*
984			 * if the index in the cis differs from the default
985			 * cis, create new entry in the queue and start it
986			 * with the current default
987			 */
988			if (state->default_cfe == NULL) {
989				DPRINTF(("CISTPL_CFTABLE_ENTRY with no "
990				    "default\n"));
991				break;
992			}
993			if (num != state->default_cfe->number) {
994				cfe = (struct pcmcia_config_entry *)
995				    malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
996
997				*cfe = *state->default_cfe;
998
999				SIMPLEQ_INSERT_TAIL(&state->pf->cfe_head,
1000				    cfe, cfe_list);
1001
1002				cfe->number = num;
1003
1004				/*
1005				 * if the default bit is set in the cis, then
1006				 * point the new default at whatever is being
1007				 * filled in
1008				 */
1009				if (def)
1010					state->default_cfe = cfe;
1011			} else {
1012				/*
1013				 * the cis index matches the default index,
1014				 * fill in the default cfentry.  It is
1015				 * assumed that the cfdefault index is in the
1016				 * queue.  For it to be otherwise, the cis
1017				 * index would have to be -1 (initial
1018				 * condition) which is not possible, or there
1019				 * would have to be a preceding cis entry
1020				 * which had the same cis index and had the
1021				 * default bit unset. Neither condition
1022				 * should happen.  If it does, this cfentry
1023				 * is lost (written into temp space), which
1024				 * is an acceptable failure mode.
1025				 */
1026
1027				cfe = state->default_cfe;
1028
1029				/*
1030				 * if the cis entry does not have the default
1031				 * bit set, copy the default out of the way
1032				 * first.
1033				 */
1034				if (!def) {
1035					state->temp_cfe = *state->default_cfe;
1036					state->default_cfe = &state->temp_cfe;
1037				}
1038			}
1039
1040			if (intface) {
1041				reg = pcmcia_tuple_read_1(tuple, idx);
1042				idx++;
1043				cfe->flags &= ~(PCMCIA_CFE_MWAIT_REQUIRED
1044				    | PCMCIA_CFE_RDYBSY_ACTIVE
1045				    | PCMCIA_CFE_WP_ACTIVE
1046				    | PCMCIA_CFE_BVD_ACTIVE);
1047				if (reg & PCMCIA_TPCE_IF_MWAIT)
1048					cfe->flags |= PCMCIA_CFE_MWAIT_REQUIRED;
1049				if (reg & PCMCIA_TPCE_IF_RDYBSY)
1050					cfe->flags |= PCMCIA_CFE_RDYBSY_ACTIVE;
1051				if (reg & PCMCIA_TPCE_IF_WP)
1052					cfe->flags |= PCMCIA_CFE_WP_ACTIVE;
1053				if (reg & PCMCIA_TPCE_IF_BVD)
1054					cfe->flags |= PCMCIA_CFE_BVD_ACTIVE;
1055				cfe->iftype = reg & PCMCIA_TPCE_IF_IFTYPE;
1056			}
1057			reg = pcmcia_tuple_read_1(tuple, idx);
1058			idx++;
1059
1060			power = reg & PCMCIA_TPCE_FS_POWER_MASK;
1061			timing = reg & PCMCIA_TPCE_FS_TIMING;
1062			iospace = reg & PCMCIA_TPCE_FS_IOSPACE;
1063			irq = reg & PCMCIA_TPCE_FS_IRQ;
1064			memspace = reg & PCMCIA_TPCE_FS_MEMSPACE_MASK;
1065			misc = reg & PCMCIA_TPCE_FS_MISC;
1066
1067			if (power) {
1068				/* skip over power, don't save */
1069				/* for each parameter selection byte */
1070				for (i = 0; i < power; i++) {
1071					reg = pcmcia_tuple_read_1(tuple, idx);
1072					idx++;
1073					/* for each bit */
1074					for (j = 0; j < 7; j++) {
1075						/* if the bit is set */
1076						if ((reg >> j) & 0x01) {
1077							/* skip over bytes */
1078							do {
1079								reg2 = pcmcia_tuple_read_1(tuple, idx);
1080								idx++;
1081								/*
1082								 * until
1083								 * non-
1084								 * extension
1085								 * byte
1086								 */
1087							} while (reg2 & 0x80);
1088						}
1089					}
1090				}
1091			}
1092			if (timing) {
1093				/* skip over timing, don't save */
1094				reg = pcmcia_tuple_read_1(tuple, idx);
1095				idx++;
1096
1097				if ((reg & PCMCIA_TPCE_TD_RESERVED_MASK) !=
1098				    PCMCIA_TPCE_TD_RESERVED_MASK)
1099					idx++;
1100				if ((reg & PCMCIA_TPCE_TD_RDYBSY_MASK) !=
1101				    PCMCIA_TPCE_TD_RDYBSY_MASK)
1102					idx++;
1103				if ((reg & PCMCIA_TPCE_TD_WAIT_MASK) !=
1104				    PCMCIA_TPCE_TD_WAIT_MASK)
1105					idx++;
1106			}
1107			if (iospace) {
1108				if (tuple->length <= idx) {
1109					DPRINTF(("ran out of space before TCPE_IO\n"));
1110					goto abort_cfe;
1111				}
1112
1113				reg = pcmcia_tuple_read_1(tuple, idx);
1114				idx++;
1115
1116				cfe->flags &=
1117				    ~(PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16);
1118				if (reg & PCMCIA_TPCE_IO_BUSWIDTH_8BIT)
1119					cfe->flags |= PCMCIA_CFE_IO8;
1120				if (reg & PCMCIA_TPCE_IO_BUSWIDTH_16BIT)
1121					cfe->flags |= PCMCIA_CFE_IO16;
1122				cfe->iomask =
1123				    reg & PCMCIA_TPCE_IO_IOADDRLINES_MASK;
1124
1125				if (reg & PCMCIA_TPCE_IO_HASRANGE) {
1126					reg = pcmcia_tuple_read_1(tuple, idx);
1127					idx++;
1128
1129					cfe->num_iospace = 1 + (reg &
1130					    PCMCIA_TPCE_IO_RANGE_COUNT);
1131
1132					if (cfe->num_iospace >
1133					    (sizeof(cfe->iospace) /
1134					     sizeof(cfe->iospace[0]))) {
1135						DPRINTF(("too many io "
1136						    "spaces %d",
1137						    cfe->num_iospace));
1138						state->card->error++;
1139						break;
1140					}
1141					for (i = 0; i < cfe->num_iospace; i++) {
1142						switch (reg & PCMCIA_TPCE_IO_RANGE_ADDRSIZE_MASK) {
1143						case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_ONE:
1144							cfe->iospace[i].start =
1145								pcmcia_tuple_read_1(tuple, idx);
1146							idx++;
1147							break;
1148						case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_TWO:
1149							cfe->iospace[i].start =
1150								pcmcia_tuple_read_2(tuple, idx);
1151							idx += 2;
1152							break;
1153						case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_FOUR:
1154							cfe->iospace[i].start =
1155								pcmcia_tuple_read_4(tuple, idx);
1156							idx += 4;
1157							break;
1158						}
1159						switch (reg &
1160							PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_MASK) {
1161						case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_ONE:
1162							cfe->iospace[i].length =
1163								pcmcia_tuple_read_1(tuple, idx);
1164							idx++;
1165							break;
1166						case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_TWO:
1167							cfe->iospace[i].length =
1168								pcmcia_tuple_read_2(tuple, idx);
1169							idx += 2;
1170							break;
1171						case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_FOUR:
1172							cfe->iospace[i].length =
1173								pcmcia_tuple_read_4(tuple, idx);
1174							idx += 4;
1175							break;
1176						}
1177						cfe->iospace[i].length++;
1178					}
1179				} else {
1180					cfe->num_iospace = 1;
1181					cfe->iospace[0].start = 0;
1182					cfe->iospace[0].length =
1183					    (1 << cfe->iomask);
1184				}
1185			}
1186			if (irq) {
1187				if (tuple->length <= idx) {
1188					DPRINTF(("ran out of space before TCPE_IR\n"));
1189					goto abort_cfe;
1190				}
1191
1192				reg = pcmcia_tuple_read_1(tuple, idx);
1193				idx++;
1194
1195				cfe->flags &= ~(PCMCIA_CFE_IRQSHARE
1196				    | PCMCIA_CFE_IRQPULSE
1197				    | PCMCIA_CFE_IRQLEVEL);
1198				if (reg & PCMCIA_TPCE_IR_SHARE)
1199					cfe->flags |= PCMCIA_CFE_IRQSHARE;
1200				if (reg & PCMCIA_TPCE_IR_PULSE)
1201					cfe->flags |= PCMCIA_CFE_IRQPULSE;
1202				if (reg & PCMCIA_TPCE_IR_LEVEL)
1203					cfe->flags |= PCMCIA_CFE_IRQLEVEL;
1204
1205				if (reg & PCMCIA_TPCE_IR_HASMASK) {
1206					/*
1207					 * it's legal to ignore the
1208					 * special-interrupt bits, so I will
1209					 */
1210
1211					cfe->irqmask =
1212					    pcmcia_tuple_read_2(tuple, idx);
1213					idx += 2;
1214				} else {
1215					cfe->irqmask =
1216					    (1 << (reg & PCMCIA_TPCE_IR_IRQ));
1217				}
1218			}
1219			if (memspace) {
1220				if (tuple->length <= idx) {
1221					DPRINTF(("ran out of space before TCPE_MS\n"));
1222					goto abort_cfe;
1223				}
1224
1225				if (memspace == PCMCIA_TPCE_FS_MEMSPACE_NONE) {
1226					cfe->num_memspace = 0;
1227				} else if (memspace == PCMCIA_TPCE_FS_MEMSPACE_LENGTH) {
1228					cfe->num_memspace = 1;
1229					cfe->memspace[0].length = 256 *
1230					    pcmcia_tuple_read_2(tuple, idx);
1231					idx += 2;
1232					cfe->memspace[0].cardaddr = 0;
1233					cfe->memspace[0].hostaddr = 0;
1234				} else if (memspace ==
1235				    PCMCIA_TPCE_FS_MEMSPACE_LENGTHADDR) {
1236					cfe->num_memspace = 1;
1237					cfe->memspace[0].length = 256 *
1238					    pcmcia_tuple_read_2(tuple, idx);
1239					idx += 2;
1240					cfe->memspace[0].cardaddr = 256 *
1241					    pcmcia_tuple_read_2(tuple, idx);
1242					idx += 2;
1243					cfe->memspace[0].hostaddr = cfe->memspace[0].cardaddr;
1244				} else {
1245					int lengthsize;
1246					int cardaddrsize;
1247					int hostaddrsize;
1248
1249					reg = pcmcia_tuple_read_1(tuple, idx);
1250					idx++;
1251
1252					cfe->num_memspace = (reg &
1253					    PCMCIA_TPCE_MS_COUNT) + 1;
1254
1255					if (cfe->num_memspace >
1256					    (sizeof(cfe->memspace) /
1257					     sizeof(cfe->memspace[0]))) {
1258						DPRINTF(("too many mem "
1259						    "spaces %d",
1260						    cfe->num_memspace));
1261						state->card->error++;
1262						break;
1263					}
1264					lengthsize =
1265						((reg & PCMCIA_TPCE_MS_LENGTH_SIZE_MASK) >>
1266						 PCMCIA_TPCE_MS_LENGTH_SIZE_SHIFT);
1267					cardaddrsize =
1268						((reg & PCMCIA_TPCE_MS_CARDADDR_SIZE_MASK) >>
1269						 PCMCIA_TPCE_MS_CARDADDR_SIZE_SHIFT);
1270					hostaddrsize =
1271						(reg & PCMCIA_TPCE_MS_HOSTADDR) ? cardaddrsize : 0;
1272
1273					if (lengthsize == 0) {
1274						DPRINTF(("cfe memspace "
1275						    "lengthsize == 0"));
1276						state->card->error++;
1277					}
1278					for (i = 0; i < cfe->num_memspace; i++) {
1279						if (lengthsize) {
1280							cfe->memspace[i].length =
1281								256 * pcmcia_tuple_read_n(tuple, lengthsize,
1282								       idx);
1283							idx += lengthsize;
1284						} else {
1285							cfe->memspace[i].length = 0;
1286						}
1287						if (cfe->memspace[i].length == 0) {
1288							DPRINTF(("cfe->memspace[%d].length == 0",
1289								 i));
1290							state->card->error++;
1291						}
1292						if (cardaddrsize) {
1293							cfe->memspace[i].cardaddr =
1294								256 * pcmcia_tuple_read_n(tuple, cardaddrsize,
1295								       idx);
1296							idx += cardaddrsize;
1297						} else {
1298							cfe->memspace[i].cardaddr = 0;
1299						}
1300						if (hostaddrsize) {
1301							cfe->memspace[i].hostaddr =
1302								256 * pcmcia_tuple_read_n(tuple, hostaddrsize,
1303								       idx);
1304							idx += hostaddrsize;
1305						} else {
1306							cfe->memspace[i].hostaddr = 0;
1307						}
1308					}
1309				}
1310			}
1311			if (misc) {
1312				if (tuple->length <= idx) {
1313					DPRINTF(("ran out of space before TCPE_MI\n"));
1314					goto abort_cfe;
1315				}
1316
1317				reg = pcmcia_tuple_read_1(tuple, idx);
1318				idx++;
1319
1320				cfe->flags &= ~(PCMCIA_CFE_POWERDOWN
1321				    | PCMCIA_CFE_READONLY
1322				    | PCMCIA_CFE_AUDIO);
1323				if (reg & PCMCIA_TPCE_MI_PWRDOWN)
1324					cfe->flags |= PCMCIA_CFE_POWERDOWN;
1325				if (reg & PCMCIA_TPCE_MI_READONLY)
1326					cfe->flags |= PCMCIA_CFE_READONLY;
1327				if (reg & PCMCIA_TPCE_MI_AUDIO)
1328					cfe->flags |= PCMCIA_CFE_AUDIO;
1329				cfe->maxtwins = reg & PCMCIA_TPCE_MI_MAXTWINS;
1330
1331				while (reg & PCMCIA_TPCE_MI_EXT) {
1332					reg = pcmcia_tuple_read_1(tuple, idx);
1333					idx++;
1334				}
1335			}
1336			/* skip all the subtuples */
1337		}
1338
1339	abort_cfe:
1340		DPRINTF(("CISTPL_CFTABLE_ENTRY\n"));
1341		break;
1342	default:
1343		DPRINTF(("unhandled CISTPL %x\n", tuple->code));
1344		break;
1345	}
1346
1347	return (0);
1348}
1349
1350
1351
1352static int
1353decode_funce(tuple, pf)
1354	struct pcmcia_tuple *tuple;
1355	struct pcmcia_function *pf;
1356{
1357	int type = pcmcia_tuple_read_1(tuple, 0);
1358
1359	switch (pf->function) {
1360	case PCMCIA_FUNCTION_DISK:
1361		if (type == PCMCIA_TPLFE_TYPE_DISK_DEVICE_INTERFACE) {
1362			pf->pf_funce_disk_interface
1363			    = pcmcia_tuple_read_1(tuple, 1);
1364		}
1365		break;
1366	case PCMCIA_FUNCTION_NETWORK:
1367		if (type == PCMCIA_TPLFE_TYPE_LAN_NID) {
1368			int i;
1369			int len = pcmcia_tuple_read_1(tuple, 1);
1370			if (tuple->length < 2 + len || len > 8) {
1371				/* tuple length not enough or nid too long */
1372				break;
1373			}
1374			for (i = 0; i < len; ++i) {
1375				pf->pf_funce_lan_nid[i]
1376				    = pcmcia_tuple_read_1(tuple, 2 + i);
1377			}
1378			pf->pf_funce_lan_nidlen = len;
1379		}
1380		break;
1381	default:
1382		break;
1383	}
1384
1385	return 0;
1386}
1387