1 /* ISDN4BSD code */
2 /*-
3 * Copyright (c) 2002 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Martin Husemann <martin@netbsd.org>.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: isic_isa.c,v 1.17 2002/10/20 10:50:01 martin Exp $");
40
41 #include <sys/param.h>
42 #include <sys/errno.h>
43 #include <sys/syslog.h>
44 #include <sys/device.h>
45 #include <sys/socket.h>
46 #include <net/if.h>
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
49
50 #include <sys/timeout.h>
51
52 #include <machine/cpu.h>
53 #include <machine/intr.h>
54 #include <machine/bus.h>
55
56 #include <dev/isa/isavar.h>
57
58 #ifdef __FreeBSD__
59 #include <machine/i4b_ioctl.h>
60 #else
61 #include <netisdn/i4b_ioctl.h>
62 #endif
63
64 #include <netisdn/i4b_debug.h>
65 #include <netisdn/i4b_ioctl.h>
66 #include <netisdn/i4b_trace.h>
67
68 #include <netisdn/i4b_l2.h>
69 #include <netisdn/i4b_l1l2.h>
70 #include <dev/ic/isic_l1.h>
71 #include <dev/ic/ipac.h>
72 #include <dev/ic/isac.h>
73 #include <dev/ic/hscx.h>
74
75 #include <netisdn/i4b_mbuf.h>
76 #include <netisdn/i4b_global.h>
77
78 extern const struct isdn_layer1_isdnif_driver isic_std_driver;
79
80 #if defined(__OpenBSD__)
81 #define __BROKEN_INDIRECT_CONFIG
82 #endif
83
84 /* local functions */
85 #ifdef __BROKEN_INDIRECT_CONFIG
86 static int isic_isa_probe __P((struct device *, void *, void *));
87 #else
88 static int isic_isa_probe __P((struct device *, struct cfdata *, void *));
89 #endif
90
91 static void isic_isa_attach __P((struct device *, struct device *, void *));
92 static int setup_io_map __P((int flags, bus_space_tag_t iot,
93 bus_space_tag_t memt, bus_size_t iobase, bus_size_t maddr,
94 int *num_mappings, struct isic_io_map *maps, int *iosize,
95 int *msize));
96 static void args_unmap __P((int *num_mappings, struct isic_io_map *maps));
97
98 CFATTACH_DECL(isic_isa, sizeof(struct isic_softc),
99 isic_isa_probe, isic_isa_attach, NULL, NULL);
100
101 #define ISIC_FMT "%s: "
102 #define ISIC_PARM sc->sc_dev.dv_xname
103 #define TERMFMT "\n"
104
105 /*
106 * Probe card
107 */
108 static int
109 #ifdef __BROKEN_INDIRECT_CONFIG
isic_isa_probe(parent,match,aux)110 isic_isa_probe(parent, match, aux)
111 #else
112 isic_isa_probe(parent, cf, aux)
113 #endif
114 struct device *parent;
115 #ifdef __BROKEN_INDIRECT_CONFIG
116 void *match;
117 #else
118 struct cfdata *cf;
119 #endif
120 void *aux;
121 {
122 #ifdef __BROKEN_INDIRECT_CONFIG
123 struct cfdata *cf = ((struct device*)match)->dv_cfdata;
124 #endif
125 struct isa_attach_args *ia = aux;
126 bus_space_tag_t memt = ia->ia_memt, iot = ia->ia_iot;
127 int flags = cf->cf_flags;
128 struct isic_attach_args args;
129 int ret = 0, iobase, iosize, maddr, msize;
130
131 #if 0
132 printf("isic%d: enter isic_isa_probe\n", cf->cf_unit);
133 #endif
134
135 if (ia->ipa_nio < 1)
136 return (0);
137 if (ia->ipa_nmem < 1)
138 return (0);
139 if (ia->ipa_nirq < 1)
140 return (0);
141
142 /* check irq */
143 #define ISACF_IRQ_DEFAULT IRQUNK
144 if (ia->ipa_irq[0].num == ISACF_IRQ_DEFAULT) {
145 printf("isic%d: config error: no IRQ specified\n", cf->cf_unit);
146 return 0;
147 }
148
149 iobase = ia->ipa_io[0].base;
150 iosize = ia->ipa_io[0].length;
151
152 maddr = ia->ipa_mem[0].base;
153 msize = ia->ipa_mem[0].length;
154
155 /* setup MI attach args */
156 memset(&args, 0, sizeof(args));
157 args.ia_flags = flags;
158
159 /* if card type specified setup io map for that card */
160 switch(flags)
161 {
162 case FLAG_TELES_S0_8:
163 case FLAG_TELES_S0_16:
164 case FLAG_TELES_S0_163:
165 case FLAG_AVM_A1:
166 case FLAG_USR_ISDN_TA_INT:
167 case FLAG_ITK_IX1:
168 if (setup_io_map(flags, iot, memt, iobase, maddr,
169 &args.ia_num_mappings, &args.ia_maps[0],
170 &iosize, &msize)) {
171 ret = 0;
172 goto done;
173 }
174 break;
175
176 default:
177 /* no io map now, will figure card type later */
178 break;
179 }
180
181 /* probe card */
182 switch(flags)
183 {
184 #ifdef ISICISA_DYNALINK
185 #ifdef __bsdi__
186 case FLAG_DYNALINK:
187 ret = isic_probe_Dyn(&args);
188 break;
189 #endif
190 #endif
191
192 #ifdef ISICISA_TEL_S0_8
193 case FLAG_TELES_S0_8:
194 ret = isic_probe_s08(&args);
195 break;
196 #endif
197
198 #ifdef ISICISA_TEL_S0_16
199 case FLAG_TELES_S0_16:
200 ret = isic_probe_s016(&args);
201 break;
202 #endif
203
204 #ifdef ISICISA_TEL_S0_16_3
205 case FLAG_TELES_S0_163:
206 ret = isic_probe_s0163(&args);
207 break;
208 #endif
209
210 #ifdef ISICISA_AVM_A1
211 case FLAG_AVM_A1:
212 ret = isic_probe_avma1(&args);
213 break;
214 #endif
215
216 #ifdef ISICISA_USR_STI
217 case FLAG_USR_ISDN_TA_INT:
218 ret = isic_probe_usrtai(&args);
219 break;
220 #endif
221
222 #ifdef ISICISA_ITKIX1
223 case FLAG_ITK_IX1:
224 ret = isic_probe_itkix1(&args);
225 break;
226 #endif
227
228 default:
229 /* No card type given, try to figure ... */
230 #define ISACF_PORT_DEFAULT IOBASEUNK
231 if (iobase == ISACF_PORT_DEFAULT) {
232 ret = 0;
233 #ifdef ISICISA_TEL_S0_8
234 /* only Teles S0/8 will work without IO */
235 args.ia_flags = FLAG_TELES_S0_8;
236 if (setup_io_map(args.ia_flags, iot, memt,
237 iobase, maddr, &args.ia_num_mappings,
238 &args.ia_maps[0], &iosize, &msize) == 0)
239 {
240 ret = isic_probe_s08(&args);
241 }
242 #endif /* ISICISA_TEL_S0_8 */
243 #define ISACF_IOMEM_DEFAULT MADDRUNK
244 } else if (maddr == ISACF_IOMEM_DEFAULT) {
245 ret = 0;
246 #ifdef ISICISA_TEL_S0_16_3
247 /* no shared memory, only a 16.3 based card,
248 AVM A1, the usr sportster or an ITK would work */
249 args.ia_flags = FLAG_TELES_S0_163;
250 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
251 &args.ia_num_mappings, &args.ia_maps[0],
252 &iosize, &msize) == 0)
253 {
254 ret = isic_probe_s0163(&args);
255 if (ret)
256 break;
257 }
258 #endif /* ISICISA_TEL_S0_16_3 */
259 #ifdef ISICISA_AVM_A1
260 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
261 args.ia_flags = FLAG_AVM_A1;
262 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
263 &args.ia_num_mappings, &args.ia_maps[0],
264 &iosize, &msize) == 0)
265 {
266 ret = isic_probe_avma1(&args);
267 if (ret)
268 break;
269 }
270 #endif /* ISICISA_AVM_A1 */
271 #ifdef ISICISA_USR_STI
272 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
273 args.ia_flags = FLAG_USR_ISDN_TA_INT;
274 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
275 &args.ia_num_mappings, &args.ia_maps[0],
276 &iosize, &msize) == 0)
277 {
278 ret = isic_probe_usrtai(&args);
279 if (ret)
280 break;
281 }
282 #endif /* ISICISA_USR_STI */
283
284 #ifdef ISICISA_ITKIX1
285 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
286 args.ia_flags = FLAG_ITK_IX1;
287 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
288 &args.ia_num_mappings, &args.ia_maps[0],
289 &iosize, &msize) == 0)
290 {
291 ret = isic_probe_itkix1(&args);
292 if (ret)
293 break;
294 }
295 #endif /* ISICISA_ITKIX1 */
296
297 } else {
298 #ifdef ISICISA_TEL_S0_16_3
299 /* could be anything */
300 args.ia_flags = FLAG_TELES_S0_163;
301 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
302 &args.ia_num_mappings, &args.ia_maps[0],
303 &iosize, &msize) == 0)
304 {
305 ret = isic_probe_s0163(&args);
306 if (ret)
307 break;
308 }
309 #endif /* ISICISA_TEL_S0_16_3 */
310 #ifdef ISICISA_TEL_S0_16
311 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
312 args.ia_flags = FLAG_TELES_S0_16;
313 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
314 &args.ia_num_mappings, &args.ia_maps[0],
315 &iosize, &msize) == 0)
316 {
317 ret = isic_probe_s016(&args);
318 if (ret)
319 break;
320 }
321 #endif /* ISICISA_TEL_S0_16 */
322 #ifdef ISICISA_AVM_A1
323 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
324 args.ia_flags = FLAG_AVM_A1;
325 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
326 &args.ia_num_mappings, &args.ia_maps[0],
327 &iosize, &msize) == 0)
328 {
329 ret = isic_probe_avma1(&args);
330 if (ret)
331 break;
332 }
333 #endif /* ISICISA_AVM_A1 */
334 #ifdef ISICISA_TEL_S0_8
335 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
336 args.ia_flags = FLAG_TELES_S0_8;
337 if (setup_io_map(args.ia_flags, iot, memt, iobase, maddr,
338 &args.ia_num_mappings, &args.ia_maps[0],
339 &iosize, &msize) == 0)
340 {
341 ret = isic_probe_s08(&args);
342 }
343 #endif /* ISICISA_TEL_S0_8 */
344 }
345 break;
346 }
347
348 done:
349 /* unmap resources */
350 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
351
352 #if 0
353 printf("isic%d: exit isic_isa_probe, return = %d\n", cf->cf_unit, ret);
354 #endif
355
356 if (ret) {
357 if (iosize != 0) {
358 ia->ipa_nio = 1;
359 ia->ipa_io[0].base = iobase;
360 ia->ipa_io[0].length = iosize;
361 } else
362 ia->ipa_nio = 0;
363 if (msize != 0) {
364 ia->ipa_nmem = 1;
365 ia->ipa_mem[0].base = maddr;
366 ia->ipa_mem[0].length = msize;
367 } else
368 ia->ipa_nmem = 0;
369 ia->ipa_nirq = 1;
370
371 ia->ipa_ndrq = 0;
372 }
373
374 return ret;
375 }
376
377 static int
isicattach(int flags,struct isic_softc * sc)378 isicattach(int flags, struct isic_softc *sc)
379 {
380 int ret = 0;
381 char *drvid;
382
383 #ifdef __FreeBSD__
384
385 struct isic_softc *sc = &l1_sc[dev->id_unit];
386 #define PARM dev
387 #define PARM2 dev, iobase2
388 #define FLAGS dev->id_flags
389
390 #elif defined(__bsdi__)
391
392 struct isic_softc *sc = (struct isic_softc *)self;
393 #define PARM parent, self, ia
394 #define PARM2 parent, self, ia
395 #define FLAGS sc->sc_flags
396
397 #else
398
399 #define PARM sc
400 #define PARM2 sc
401 #define FLAGS flags
402
403 #endif /* __FreeBSD__ */
404
405 static char *ISACversion[] = {
406 "2085 Version A1/A2 or 2086/2186 Version 1.1",
407 "2085 Version B1",
408 "2085 Version B2",
409 "2085 Version V2.3 (B3)",
410 "Unknown Version"
411 };
412
413 static char *HSCXversion[] = {
414 "82525 Version A1",
415 "Unknown (0x01)",
416 "82525 Version A2",
417 "Unknown (0x03)",
418 "82525 Version A3",
419 "82525 or 21525 Version 2.1",
420 "Unknown Version"
421 };
422
423 /* card dependent setup */
424 switch(FLAGS)
425 {
426 #ifdef ISICISA_DYNALINK
427 #if defined(__bsdi__) || defined(__FreeBSD__)
428 case FLAG_DYNALINK:
429 ret = isic_attach_Dyn(PARM2);
430 break;
431 #endif
432 #endif
433
434 #ifdef ISICISA_TEL_S0_8
435 case FLAG_TELES_S0_8:
436 ret = isic_attach_s08(PARM);
437 break;
438 #endif
439
440 #ifdef ISICISA_TEL_S0_16
441 case FLAG_TELES_S0_16:
442 ret = isic_attach_s016(PARM);
443 break;
444 #endif
445
446 #ifdef ISICISA_TEL_S0_16_3
447 case FLAG_TELES_S0_163:
448 ret = isic_attach_s0163(PARM);
449 break;
450 #endif
451
452 #ifdef ISICISA_AVM_A1
453 case FLAG_AVM_A1:
454 ret = isic_attach_avma1(PARM);
455 break;
456 #endif
457
458 #ifdef ISICISA_USR_STI
459 case FLAG_USR_ISDN_TA_INT:
460 ret = isic_attach_usrtai(PARM);
461 break;
462 #endif
463
464 #ifdef ISICISA_ITKIX1
465 case FLAG_ITK_IX1:
466 ret = isic_attach_itkix1(PARM);
467 break;
468 #endif
469
470 #ifdef ISICISA_ELSA_PCC16
471 case FLAG_ELSA_PCC16:
472 ret = isic_attach_Eqs1pi(dev, 0);
473 break;
474 #endif
475
476 #ifdef amiga
477 case FLAG_BLMASTER:
478 ret = 1; /* full detection was done in caller */
479 break;
480 #endif
481
482 /* ======================================================================
483 * Only P&P cards follow below!!!
484 */
485
486 #ifdef __FreeBSD__ /* we've already splitted all non-ISA stuff
487 out of this ISA specific part for the other
488 OS */
489
490 #ifdef AVM_A1_PCMCIA
491 case FLAG_AVM_A1_PCMCIA:
492 ret = isic_attach_fritzpcmcia(PARM);
493 break;
494 #endif
495
496 #ifdef TEL_S0_16_3_P
497 case FLAG_TELES_S0_163_PnP:
498 ret = isic_attach_s0163P(PARM2);
499 break;
500 #endif
501
502 #ifdef CRTX_S0_P
503 case FLAG_CREATIX_S0_PnP:
504 ret = isic_attach_Cs0P(PARM2);
505 break;
506 #endif
507
508 #ifdef DRN_NGO
509 case FLAG_DRN_NGO:
510 ret = isic_attach_drnngo(PARM2);
511 break;
512 #endif
513
514 #ifdef SEDLBAUER
515 case FLAG_SWS:
516 ret = isic_attach_sws(PARM);
517 break;
518 #endif
519
520 #ifdef ELSA_QS1ISA
521 case FLAG_ELSA_QS1P_ISA:
522 ret = isic_attach_Eqs1pi(PARM2);
523 break;
524 #endif
525
526 #ifdef AVM_PNP
527 case FLAG_AVM_PNP:
528 ret = isic_attach_avm_pnp(PARM2);
529 ret = 0;
530 break;
531 #endif
532
533 #ifdef SIEMENS_ISURF2
534 case FLAG_SIEMENS_ISURF2:
535 ret = isic_attach_siemens_isurf(PARM2);
536 break;
537 #endif
538
539 #ifdef ASUSCOM_IPAC
540 case FLAG_ASUSCOM_IPAC:
541 ret = isic_attach_asi(PARM2);
542 break;
543 #endif
544
545 #endif /* __FreeBSD__ / P&P specific part */
546
547 default:
548 break;
549 }
550
551 if(ret == 0)
552 return(0);
553
554 if(sc->sc_ipac)
555 {
556 sc->sc_ipac_version = IPAC_READ(IPAC_ID);
557
558 switch(sc->sc_ipac_version)
559 {
560 case IPAC_V11:
561 case IPAC_V12:
562 break;
563
564 default:
565 printf("%s: Error, IPAC version %d unknown!\n",
566 sc->sc_dev.dv_xname, ret);
567 return(0);
568 break;
569 }
570 }
571 else
572 {
573 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
574
575 switch(sc->sc_isac_version)
576 {
577 case ISAC_VA:
578 case ISAC_VB1:
579 case ISAC_VB2:
580 case ISAC_VB3:
581 break;
582
583 default:
584 printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
585 ISIC_PARM, sc->sc_isac_version);
586 return(0);
587 break;
588 }
589
590 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
591
592 switch(sc->sc_hscx_version)
593 {
594 case HSCX_VA1:
595 case HSCX_VA2:
596 case HSCX_VA3:
597 case HSCX_V21:
598 break;
599
600 default:
601 printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
602 ISIC_PARM, sc->sc_hscx_version);
603 return(0);
604 break;
605 }
606 }
607
608 sc->sc_intr_valid = ISIC_INTR_DISABLED;
609
610 /* HSCX setup */
611
612 isic_bchannel_setup(sc, HSCX_CH_A, BPROT_NONE, 0);
613
614 isic_bchannel_setup(sc, HSCX_CH_B, BPROT_NONE, 0);
615
616 /* setup linktab */
617
618 isic_init_linktab(sc);
619
620 /* set trace level */
621
622 sc->sc_trace = TRACE_OFF;
623
624 sc->sc_state = ISAC_IDLE;
625
626 sc->sc_ibuf = NULL;
627 sc->sc_ib = NULL;
628 sc->sc_ilen = 0;
629
630 sc->sc_obuf = NULL;
631 sc->sc_op = NULL;
632 sc->sc_ol = 0;
633 sc->sc_freeflag = 0;
634
635 sc->sc_obuf2 = NULL;
636 sc->sc_freeflag2 = 0;
637
638 /* announce manufacturer and card type */
639
640 switch(FLAGS)
641 {
642 case FLAG_TELES_S0_8:
643 drvid = "Teles S0/8 or Niccy 1008";
644 break;
645
646 case FLAG_TELES_S0_16:
647 drvid = "Teles S0/16, Creatix ISDN S0-16 or Niccy 1016";
648 break;
649
650 case FLAG_TELES_S0_163:
651 drvid = "Teles S0/16.3";
652 break;
653
654 case FLAG_AVM_A1:
655 drvid = "AVM A1 or AVM Fritz!Card";
656 break;
657
658 case FLAG_AVM_A1_PCMCIA:
659 drvid = "AVM PCMCIA Fritz!Card";
660 break;
661
662 case FLAG_TELES_S0_163_PnP:
663 drvid = "Teles S0/PnP";
664 break;
665
666 case FLAG_CREATIX_S0_PnP:
667 drvid = "Creatix ISDN S0-16 P&P";
668 break;
669
670 case FLAG_USR_ISDN_TA_INT:
671 drvid = "USRobotics Sportster ISDN TA intern";
672 break;
673
674 case FLAG_DRN_NGO:
675 drvid = "Dr. Neuhaus NICCY Go@";
676 break;
677
678 case FLAG_DYNALINK:
679 drvid = "Dynalink IS64PH";
680 break;
681
682 case FLAG_SWS:
683 drvid = "Sedlbauer WinSpeed";
684 break;
685
686 case FLAG_BLMASTER:
687 /* board announcement was done by caller */
688 drvid = (char *)0;
689 break;
690
691 case FLAG_ELSA_QS1P_ISA:
692 drvid = "ELSA QuickStep 1000pro (ISA)";
693 break;
694
695 case FLAG_ITK_IX1:
696 drvid = "ITK ix1 micro";
697 break;
698
699 case FLAG_ELSA_PCC16:
700 drvid = "ELSA PCC-16";
701 break;
702
703 case FLAG_ASUSCOM_IPAC:
704 drvid = "Asuscom ISDNlink 128K PnP";
705 break;
706
707 case FLAG_SIEMENS_ISURF2:
708 drvid = "Siemens I-Surf 2.0";
709 break;
710
711 default:
712 drvid = "ERROR, unknown flag used";
713 break;
714 }
715 #ifndef __FreeBSD__
716 printf("\n");
717 #endif
718 if (drvid)
719 printf(ISIC_FMT "%s\n", ISIC_PARM, drvid);
720
721 /* announce chip versions */
722
723 if(sc->sc_ipac)
724 {
725 if(sc->sc_ipac_version == IPAC_V11)
726 printf(ISIC_FMT "IPAC PSB2115 Version 1.1\n", ISIC_PARM);
727 else
728 printf(ISIC_FMT "IPAC PSB2115 Version 1.2\n", ISIC_PARM);
729 }
730 else
731 {
732 if(sc->sc_isac_version >= ISAC_UNKN)
733 {
734 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
735 ISIC_PARM,
736 sc->sc_isac_version);
737 sc->sc_isac_version = ISAC_UNKN;
738 }
739 else
740 {
741 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
742 ISIC_PARM,
743 ISACversion[sc->sc_isac_version],
744 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
745 }
746
747 #ifdef __FreeBSD__
748 printf("(Addr=0x%lx)\n", (u_long)ISAC_BASE);
749 #endif
750
751 if(sc->sc_hscx_version >= HSCX_UNKN)
752 {
753 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
754 ISIC_PARM,
755 sc->sc_hscx_version);
756 sc->sc_hscx_version = HSCX_UNKN;
757 }
758 else
759 {
760 printf(ISIC_FMT "HSCX %s" TERMFMT,
761 ISIC_PARM,
762 HSCXversion[sc->sc_hscx_version]);
763 }
764
765 #ifdef __FreeBSD__
766 printf("(AddrA=0x%lx, AddrB=0x%lx)\n", (u_long)HSCX_A_BASE, (u_long)HSCX_B_BASE);
767
768 #endif /* __FreeBSD__ */
769 }
770
771 #ifdef __FreeBSD__
772 next_isic_unit++;
773
774 #if defined(__FreeBSD_version) && __FreeBSD_version >= 300003
775
776 /* set the interrupt handler - no need to change isa_device.h */
777 dev->id_intr = (inthand2_t *)isicintr;
778
779 #endif
780
781 #endif /* __FreeBSD__ */
782
783 /* init higher protocol layers */
784 isic_attach_bri(sc, drvid, &isic_std_driver);
785
786 return(1);
787 #undef PARM
788 #undef FLAGS
789 }
790
791 /*
792 * Attach the card
793 */
794 static void
isic_isa_attach(parent,self,aux)795 isic_isa_attach(parent, self, aux)
796 struct device *parent, *self;
797 void *aux;
798 {
799 struct isic_softc *sc = (void *)self;
800 struct isa_attach_args *ia = aux;
801 int flags = sc->sc_dev.dv_cfdata->cf_flags;
802 int ret = 0, iobase, iosize, maddr, msize;
803 struct isic_attach_args args;
804
805 if (ia->ipa_nio > 0) {
806 iobase = ia->ipa_io[0].base;
807 iosize = ia->ipa_io[0].length;
808 } else {
809 iobase = ISACF_PORT_DEFAULT;
810 iosize = 0;
811 }
812 if (ia->ipa_nmem > 0) {
813 maddr = ia->ipa_mem[0].base;
814 msize = ia->ipa_mem[0].length;
815 } else {
816 maddr = ISACF_IOMEM_DEFAULT;
817 msize = 0;
818 }
819
820 /* Setup parameters */
821 sc->sc_irq = ia->ipa_irq[0].num;
822 sc->sc_maddr = maddr;
823 sc->sc_num_mappings = 0;
824 sc->sc_maps = NULL;
825 switch(flags)
826 {
827 case FLAG_TELES_S0_8:
828 case FLAG_TELES_S0_16:
829 case FLAG_TELES_S0_163:
830 case FLAG_AVM_A1:
831 case FLAG_USR_ISDN_TA_INT:
832 setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
833 &(sc->sc_num_mappings), NULL, NULL, NULL);
834 MALLOC_MAPS(sc);
835 setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
836 &(sc->sc_num_mappings), &(sc->sc_maps[0]), NULL, NULL);
837 break;
838
839 default:
840 /* No card type given, try to figure ... */
841
842 /* setup MI attach args */
843 memset(&args, 0, sizeof(args));
844 args.ia_flags = flags;
845
846 /* Probe cards */
847 if (iobase == ISACF_PORT_DEFAULT) {
848 ret = 0;
849 #ifdef ISICISA_TEL_S0_8
850 /* only Teles S0/8 will work without IO */
851 args.ia_flags = FLAG_TELES_S0_8;
852 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
853 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
854 ret = isic_probe_s08(&args);
855 if (ret)
856 goto found;
857 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
858 #endif /* ISICISA_TEL_S0_8 */
859 } else if (maddr == ISACF_IOMEM_DEFAULT) {
860 /* no shared memory, only a 16.3 based card,
861 AVM A1, the usr sportster or an ITK would work */
862 ret = 0;
863 #ifdef ISICISA_TEL_S0_16_3
864 args.ia_flags = FLAG_TELES_S0_163;
865 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
866 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
867 ret = isic_probe_s0163(&args);
868 if (ret)
869 goto found;
870 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
871 #endif /* ISICISA_TEL_S0_16_3 */
872 #ifdef ISICISA_AVM_A1
873 args.ia_flags = FLAG_AVM_A1;
874 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
875 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
876 ret = isic_probe_avma1(&args);
877 if (ret)
878 goto found;
879 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
880 #endif /* ISICISA_AVM_A1 */
881 #ifdef ISICISA_USR_STI
882 args.ia_flags = FLAG_USR_ISDN_TA_INT;
883 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
884 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
885 ret = isic_probe_usrtai(&args);
886 if (ret)
887 goto found;
888 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
889 #endif /* ISICISA_USR_STI */
890 #ifdef ISICISA_ITKIX1
891 args.ia_flags = FLAG_ITK_IX1;
892 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
893 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
894 ret = isic_probe_itkix1(&args);
895 if (ret)
896 goto found;
897 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
898 #endif /* ISICISA_ITKIX1 */
899 } else {
900 /* could be anything */
901 ret = 0;
902 #ifdef ISICISA_TEL_S0_16_3
903 args.ia_flags = FLAG_TELES_S0_163;
904 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
905 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
906 ret = isic_probe_s0163(&args);
907 if (ret)
908 goto found;
909 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
910 #endif /* ISICISA_TEL_S0_16_3 */
911 #ifdef ISICISA_TEL_S0_16
912 args.ia_flags = FLAG_TELES_S0_16;
913 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
914 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
915 ret = isic_probe_s016(&args);
916 if (ret)
917 goto found;
918 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
919 #endif /* ISICISA_TEL_S0_16 */
920 #ifdef ISICISA_AVM_A1
921 args.ia_flags = FLAG_AVM_A1;
922 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
923 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
924 ret = isic_probe_avma1(&args);
925 if (ret)
926 goto found;
927 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
928 #endif /* ISICISA_AVM_A1 */
929 #ifdef ISICISA_TEL_S0_8
930 args.ia_flags = FLAG_TELES_S0_8;
931 setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
932 &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL);
933 ret = isic_probe_s08(&args);
934 if (ret)
935 goto found;
936 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
937 #endif /* ISICISA_TEL_S0_8 */
938 }
939 break;
940
941 found:
942 flags = args.ia_flags;
943 sc->sc_num_mappings = args.ia_num_mappings;
944 args_unmap(&args.ia_num_mappings, &args.ia_maps[0]);
945 if (ret) {
946 MALLOC_MAPS(sc);
947 setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr,
948 &(sc->sc_num_mappings), &(sc->sc_maps[0]), NULL, NULL);
949 } else {
950 printf(": could not determine card type - not configured!\n");
951 return;
952 }
953 break;
954 }
955
956 #if defined(__OpenBSD__)
957 isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
958 IPL_NET, isicintr, sc, sc->sc_dev.dv_xname);
959
960 /* MI initialization of card */
961 isicattach(flags, sc);
962
963 #else
964
965 /* MI initialization of card */
966 isicattach(flags, sc);
967
968 /*
969 * Try to get a level-triggered interrupt first. If that doesn't
970 * work (like on NetBSD/Atari, try to establish an edge triggered
971 * interrupt.
972 */
973 if (isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_LEVEL,
974 IPL_NET, isicintr, sc) == NULL) {
975 if(isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE,
976 IPL_NET, isicintr, sc) == NULL) {
977 args_unmap(&(sc->sc_num_mappings), &(sc->sc_maps[0]));
978 free((sc)->sc_maps, M_DEVBUF);
979 }
980 else {
981 /*
982 * XXX: This is a hack that probably needs to be
983 * solved by setting an interrupt type in the sc
984 * structure. I don't feel familiar enough with the
985 * code to do this currently. Feel free to contact
986 * me about it (leo@netbsd.org).
987 */
988 isicintr(sc);
989 }
990 }
991 #endif
992 }
993
994 /*
995 * Setup card specific io mapping. Return 0 on success,
996 * any other value on config error.
997 * Be prepared to get NULL as maps array.
998 * Make sure to keep *num_mappings in sync with the real
999 * mappings already setup when returning!
1000 */
1001 static int
setup_io_map(flags,iot,memt,iobase,maddr,num_mappings,maps,iosize,msize)1002 setup_io_map(flags, iot, memt, iobase, maddr, num_mappings, maps, iosize, msize)
1003 int flags, *num_mappings, *iosize, *msize;
1004 bus_size_t iobase, maddr;
1005 bus_space_tag_t iot, memt;
1006 struct isic_io_map *maps;
1007 {
1008 /* nothing mapped yet */
1009 *num_mappings = 0;
1010
1011 /* which resources do we need? */
1012 switch(flags)
1013 {
1014 case FLAG_TELES_S0_8:
1015 if (maddr == ISACF_IOMEM_DEFAULT) {
1016 printf("isic: config error: no shared memory specified for Teles S0/8!\n");
1017 return 1;
1018 }
1019 if (iosize) *iosize = 0; /* no i/o ports */
1020 if (msize) *msize = 0x1000; /* shared memory size */
1021
1022 /* this card uses a single memory mapping */
1023 if (maps == NULL) {
1024 *num_mappings = 1;
1025 return 0;
1026 }
1027 *num_mappings = 0;
1028 maps[0].t = memt;
1029 maps[0].offset = 0;
1030 maps[0].size = 0x1000;
1031 if (bus_space_map(maps[0].t, maddr,
1032 maps[0].size, 0, &maps[0].h)) {
1033 return 1;
1034 }
1035 (*num_mappings)++;
1036 break;
1037
1038 case FLAG_TELES_S0_16:
1039 if (iobase == ISACF_PORT_DEFAULT) {
1040 printf("isic: config error: no i/o address specified for Teles S0/16!\n");
1041 return 1;
1042 }
1043 if (maddr == ISACF_IOMEM_DEFAULT) {
1044 printf("isic: config error: no shared memory specified for Teles S0/16!\n");
1045 return 1;
1046 }
1047 if (iosize) *iosize = 8; /* i/o ports */
1048 if (msize) *msize = 0x1000; /* shared memory size */
1049
1050 /* one io and one memory mapping */
1051 if (maps == NULL) {
1052 *num_mappings = 2;
1053 return 0;
1054 }
1055 *num_mappings = 0;
1056 maps[0].t = iot;
1057 maps[0].offset = 0;
1058 maps[0].size = 8;
1059 if (bus_space_map(maps[0].t, iobase,
1060 maps[0].size, 0, &maps[0].h)) {
1061 return 1;
1062 }
1063 (*num_mappings)++;
1064 maps[1].t = memt;
1065 maps[1].offset = 0;
1066 maps[1].size = 0x1000;
1067 if (bus_space_map(maps[1].t, maddr,
1068 maps[1].size, 0, &maps[1].h)) {
1069 return 1;
1070 }
1071 (*num_mappings)++;
1072 break;
1073
1074 case FLAG_TELES_S0_163:
1075 if (iobase == ISACF_PORT_DEFAULT) {
1076 printf("isic: config error: no i/o address specified for Teles S0/16!\n");
1077 return 1;
1078 }
1079 if (iosize) *iosize = 8; /* only some i/o ports shown */
1080 if (msize) *msize = 0; /* no shared memory */
1081
1082 /* Four io mappings: config, isac, 2 * hscx */
1083 if (maps == NULL) {
1084 *num_mappings = 4;
1085 return 0;
1086 }
1087 *num_mappings = 0;
1088 maps[0].t = iot;
1089 maps[0].offset = 0;
1090 maps[0].size = 8;
1091 if (bus_space_map(maps[0].t, iobase,
1092 maps[0].size, 0, &maps[0].h)) {
1093 return 1;
1094 }
1095 (*num_mappings)++;
1096 maps[1].t = iot;
1097 maps[1].offset = 0;
1098 maps[1].size = 0x40; /* XXX - ??? */
1099 if ((iobase - 0xd80 + 0x980) < 0 || (iobase - 0xd80 + 0x980) > 0x0ffff)
1100 return 1;
1101 if (bus_space_map(maps[1].t, iobase - 0xd80 + 0x980,
1102 maps[1].size, 0, &maps[1].h)) {
1103 return 1;
1104 }
1105 (*num_mappings)++;
1106 maps[2].t = iot;
1107 maps[2].offset = 0;
1108 maps[2].size = 0x40; /* XXX - ??? */
1109 if ((iobase - 0xd80 + 0x180) < 0 || (iobase - 0xd80 + 0x180) > 0x0ffff)
1110 return 1;
1111 if (bus_space_map(maps[2].t, iobase - 0xd80 + 0x180,
1112 maps[2].size, 0, &maps[2].h)) {
1113 return 1;
1114 }
1115 (*num_mappings)++;
1116 maps[3].t = iot;
1117 maps[3].offset = 0;
1118 maps[3].size = 0x40; /* XXX - ??? */
1119 if ((iobase - 0xd80 + 0x580) < 0 || (iobase - 0xd80 + 0x580) > 0x0ffff)
1120 return 1;
1121 if (bus_space_map(maps[3].t, iobase - 0xd80 + 0x580,
1122 maps[3].size, 0, &maps[3].h)) {
1123 return 1;
1124 }
1125 (*num_mappings)++;
1126 break;
1127
1128 case FLAG_AVM_A1:
1129 if (iobase == ISACF_PORT_DEFAULT) {
1130 printf("isic: config error: no i/o address specified for AVM A1/Fritz! card!\n");
1131 return 1;
1132 }
1133 if (iosize) *iosize = 8; /* only some i/o ports shown */
1134 if (msize) *msize = 0; /* no shared memory */
1135
1136 /* Seven io mappings: config, isac, 2 * hscx,
1137 isac-fifo, 2 * hscx-fifo */
1138 if (maps == NULL) {
1139 *num_mappings = 7;
1140 return 0;
1141 }
1142 *num_mappings = 0;
1143 maps[0].t = iot; /* config */
1144 maps[0].offset = 0;
1145 maps[0].size = 8;
1146 if ((iobase + 0x1800) < 0 || (iobase + 0x1800) > 0x0ffff)
1147 return 1;
1148 if (bus_space_map(maps[0].t, iobase + 0x1800, maps[0].size, 0, &maps[0].h))
1149 return 1;
1150 (*num_mappings)++;
1151 maps[1].t = iot; /* isac */
1152 maps[1].offset = 0;
1153 maps[1].size = 0x80; /* XXX - ??? */
1154 if ((iobase + 0x1400 - 0x20) < 0 || (iobase + 0x1400 - 0x20) > 0x0ffff)
1155 return 1;
1156 if (bus_space_map(maps[1].t, iobase + 0x1400 - 0x20, maps[1].size, 0, &maps[1].h))
1157 return 1;
1158 (*num_mappings)++;
1159 maps[2].t = iot; /* hscx 0 */
1160 maps[2].offset = 0;
1161 maps[2].size = 0x40; /* XXX - ??? */
1162 if ((iobase + 0x400 - 0x20) < 0 || (iobase + 0x400 - 0x20) > 0x0ffff)
1163 return 1;
1164 if (bus_space_map(maps[2].t, iobase + 0x400 - 0x20, maps[2].size, 0, &maps[2].h))
1165 return 1;
1166 (*num_mappings)++;
1167 maps[3].t = iot; /* hscx 1 */
1168 maps[3].offset = 0;
1169 maps[3].size = 0x40; /* XXX - ??? */
1170 if ((iobase + 0xc00 - 0x20) < 0 || (iobase + 0xc00 - 0x20) > 0x0ffff)
1171 return 1;
1172 if (bus_space_map(maps[3].t, iobase + 0xc00 - 0x20, maps[3].size, 0, &maps[3].h))
1173 return 1;
1174 (*num_mappings)++;
1175 maps[4].t = iot; /* isac-fifo */
1176 maps[4].offset = 0;
1177 maps[4].size = 1;
1178 if ((iobase + 0x1400 - 0x20 -0x3e0) < 0 || (iobase + 0x1400 - 0x20 -0x3e0) > 0x0ffff)
1179 return 1;
1180 if (bus_space_map(maps[4].t, iobase + 0x1400 - 0x20 -0x3e0, maps[4].size, 0, &maps[4].h))
1181 return 1;
1182 (*num_mappings)++;
1183 maps[5].t = iot; /* hscx 0 fifo */
1184 maps[5].offset = 0;
1185 maps[5].size = 1;
1186 if ((iobase + 0x400 - 0x20 -0x3e0) < 0 || (iobase + 0x400 - 0x20 -0x3e0) > 0x0ffff)
1187 return 1;
1188 if (bus_space_map(maps[5].t, iobase + 0x400 - 0x20 -0x3e0, maps[5].size, 0, &maps[5].h))
1189 return 1;
1190 (*num_mappings)++;
1191 maps[6].t = iot; /* hscx 1 fifo */
1192 maps[6].offset = 0;
1193 maps[6].size = 1;
1194 if ((iobase + 0xc00 - 0x20 -0x3e0) < 0 || (iobase + 0xc00 - 0x20 -0x3e0) > 0x0ffff)
1195 return 1;
1196 if (bus_space_map(maps[6].t, iobase + 0xc00 - 0x20 -0x3e0, maps[6].size, 0, &maps[6].h))
1197 return 1;
1198 (*num_mappings)++;
1199 break;
1200
1201 case FLAG_USR_ISDN_TA_INT:
1202 if (iobase == ISACF_PORT_DEFAULT) {
1203 printf("isic: config error: no I/O base specified for USR Sportster TA intern!\n");
1204 return 1;
1205 }
1206 if (iosize) *iosize = 8; /* scattered ports, only some shown */
1207 if (msize) *msize = 0; /* no shared memory */
1208
1209 /* 49 io mappings: 1 config and 48x8 registers */
1210 if (maps == NULL) {
1211 *num_mappings = 49;
1212 return 0;
1213 }
1214 *num_mappings = 0;
1215 {
1216 int i, num;
1217 bus_size_t base;
1218
1219 /* config at offset 0x8000 */
1220 base = iobase + 0x8000;
1221 maps[0].size = 1;
1222 maps[0].t = iot;
1223 maps[0].offset = 0;
1224 if (base < 0 || base > 0x0ffff)
1225 return 1;
1226 if (bus_space_map(iot, base, 1, 0, &maps[0].h)) {
1227 return 1;
1228 }
1229 *num_mappings = num = 1;
1230
1231 /* HSCX A at offset 0 */
1232 base = iobase;
1233 for (i = 0; i < 16; i++) {
1234 maps[num].size = 8;
1235 maps[num].offset = 0;
1236 maps[num].t = iot;
1237 if (base+i*1024 < 0 || base+i*1024+8 > 0x0ffff)
1238 return 1;
1239 if (bus_space_map(iot, base+i*1024, 8, 0, &maps[num].h)) {
1240 return 1;
1241 }
1242 *num_mappings = ++num;
1243 }
1244 /* HSCX B at offset 0x4000 */
1245 base = iobase + 0x4000;
1246 for (i = 0; i < 16; i++) {
1247 maps[num].size = 8;
1248 maps[num].offset = 0;
1249 maps[num].t = iot;
1250 if (base+i*1024 < 0 || base+i*1024+8 > 0x0ffff)
1251 return 1;
1252 if (bus_space_map(iot, base+i*1024, 8, 0, &maps[num].h)) {
1253 return 1;
1254 }
1255 *num_mappings = ++num;
1256 }
1257 /* ISAC at offset 0xc000 */
1258 base = iobase + 0xc000;
1259 for (i = 0; i < 16; i++) {
1260 maps[num].size = 8;
1261 maps[num].offset = 0;
1262 maps[num].t = iot;
1263 if (base+i*1024 < 0 || base+i*1024+8 > 0x0ffff)
1264 return 1;
1265 if (bus_space_map(iot, base+i*1024, 8, 0, &maps[num].h)) {
1266 return 1;
1267 }
1268 *num_mappings = ++num;
1269 }
1270 }
1271 break;
1272
1273 case FLAG_ITK_IX1:
1274 if (iobase == ISACF_PORT_DEFAULT) {
1275 printf("isic: config error: no I/O base specified for ITK ix1 micro!\n");
1276 return 1;
1277 }
1278 if (iosize) *iosize = 4;
1279 if (msize) *msize = 0;
1280 if (maps == NULL) {
1281 *num_mappings = 1;
1282 return 0;
1283 }
1284 *num_mappings = 0;
1285 maps[0].size = 4;
1286 maps[0].t = iot;
1287 maps[0].offset = 0;
1288 if (bus_space_map(iot, iobase, 4, 0, &maps[0].h)) {
1289 return 1;
1290 }
1291 *num_mappings = 1;
1292 break;
1293
1294 default:
1295 printf("isic: config error: flags do not specify any known card!\n");
1296 return 1;
1297 break;
1298 }
1299
1300 return 0;
1301 }
1302
1303 static void
args_unmap(num_mappings,maps)1304 args_unmap(num_mappings, maps)
1305 int *num_mappings;
1306 struct isic_io_map *maps;
1307 {
1308 int i, n;
1309 for (i = 0, n = *num_mappings; i < n; i++)
1310 if (maps[i].size)
1311 bus_space_unmap(maps[i].t, maps[i].h, maps[i].size);
1312 *num_mappings = 0;
1313 }
1314