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