]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer1/pcmcia_isic.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / sys / i4b / layer1 / pcmcia_isic.c
1 /*
2  *   Copyright (c) 1998 Martin Husemann. All rights reserved.
3  *
4  *   Redistribution and use in source and binary forms, with or without
5  *   modification, are permitted provided that the following conditions
6  *   are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright
9  *      notice, this list of conditions and the following disclaimer.
10  *   2. Redistributions in binary form must reproduce the above copyright
11  *      notice, this list of conditions and the following disclaimer in the
12  *      documentation and/or other materials provided with the distribution.
13  *   3. Neither the name of the author nor the names of any co-contributors
14  *      may be used to endorse or promote products derived from this software
15  *      without specific prior written permission.
16  *   4. Altered versions must be plainly marked as such, and must not be
17  *      misrepresented as being the original software and/or documentation.
18  *   
19  *   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  *   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  *   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  *   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  *   SUCH DAMAGE.
30  *
31  *---------------------------------------------------------------------------
32  *
33  *      pcmcia_isic.c - pcmcia bus frontend for i4b_isic driver
34  *      -------------------------------------------------------
35  *
36  * $FreeBSD$ 
37  *
38  *      last edit-date: [Tue Apr 20 14:09:16 1999]
39  *
40  *      -mh     original implementation
41  *
42  *---------------------------------------------------------------------------*/
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/errno.h>
47 #include <sys/syslog.h>
48 #include <sys/device.h>
49 #include <sys/socket.h>
50 #include <net/if.h>
51 #include <sys/systm.h>
52 #include <sys/malloc.h>
53
54 #include <machine/cpu.h>
55 #include <machine/intr.h>
56 #include <machine/bus.h>
57
58 #include <dev/pcmcia/pcmciareg.h>
59 #include <dev/pcmcia/pcmciavar.h>
60 #include <dev/pcmcia/pcmciadevs.h>
61
62 #ifdef __FreeBSD__
63 #include <machine/i4b_ioctl.h>
64 #include <machine/i4b_trace.h>
65 #else
66 #include <i4b/i4b_ioctl.h>
67 #include <i4b/i4b_trace.h>
68 #endif
69
70 #include <i4b/layer1/i4b_l1.h>
71 #include <i4b/layer1/i4b_ipac.h>
72 #include <i4b/layer1/i4b_isac.h>
73 #include <i4b/layer1/i4b_hscx.h>
74
75 #include <i4b/include/i4b_l1l2.h>
76 #include <i4b/include/i4b_global.h>
77
78 #include <i4b/layer1/pcmcia_isic.h>
79
80 static int pcmcia_isic_match __P((struct device *, struct cfdata *, void *));
81 static void pcmcia_isic_attach __P((struct device *, struct device *, void *));
82 static const struct isic_pcmcia_card_entry * find_matching_card __P((struct pcmcia_attach_args *pa));
83 static int pcmcia_isicattach __P((struct isic_softc *sc));
84
85 struct cfattach pcmcia_isic_ca = {
86         sizeof(struct pcmcia_isic_softc), pcmcia_isic_match, pcmcia_isic_attach
87 };
88
89 struct isic_pcmcia_card_entry {
90         int32_t vendor;         /* vendor ID */
91         int32_t product;        /* product ID */
92         char *cis1_info[4];     /* CIS info to match */
93         char *name;             /* name of controller */
94         int function;           /* expected PCMCIA function type */
95         int card_type;          /* card type found */
96         isic_pcmcia_attach_func attach; /* card initialization */
97 };
98
99 static const struct isic_pcmcia_card_entry card_list[] = {
100
101 #ifdef AVM_A1_PCMCIA
102     {   PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
103         { "AVM", "ISDN A", NULL, NULL },
104         "AVM Fritz!Card", PCMCIA_FUNCTION_NETWORK,
105         CARD_TYPEP_PCFRITZ, isic_attach_fritzpcmcia },
106 #endif
107
108 #ifdef ELSA_ISDNMC
109     {   PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
110         { "ELSA GmbH, Aachen", "MicroLink ISDN/MC ", NULL, NULL },
111         "ELSA MicroLink ISDN/MC", PCMCIA_FUNCTION_NETWORK,
112         CARD_TYPEP_ELSAMLIMC, isic_attach_elsaisdnmc },
113     {   PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
114         { "ELSA AG, Aachen", "MicroLink ISDN/MC ", NULL, NULL },
115         "ELSA MicroLink ISDN/MC", PCMCIA_FUNCTION_NETWORK,
116         CARD_TYPEP_ELSAMLIMC, isic_attach_elsaisdnmc },
117 #endif
118
119 #ifdef ELSA_MCALL
120     {   0x105, 0x410a,
121         { "ELSA", "MicroLink MC all", NULL, NULL },
122         "ELSA MicroLink MCall", PCMCIA_FUNCTION_NETWORK,
123         CARD_TYPEP_ELSAMLMCALL, isic_attach_elsamcall },
124 #endif
125
126 };
127 #define NUM_MATCH_ENTRIES       (sizeof(card_list)/sizeof(card_list[0]))
128
129 static const struct isic_pcmcia_card_entry *
130 find_matching_card(pa)
131         struct pcmcia_attach_args *pa;
132 {
133         int i, j;
134
135         for (i = 0; i < NUM_MATCH_ENTRIES; i++) {
136                 if (card_list[i].vendor != PCMCIA_VENDOR_INVALID && pa->card->manufacturer != card_list[i].vendor)
137                         continue;
138                 if (card_list[i].product != PCMCIA_PRODUCT_INVALID && pa->card->product != card_list[i].product)
139                                 continue;
140                 if (pa->pf->function != card_list[i].function)
141                         continue;
142                 for (j = 0; j < 4; j++) {
143                         if (card_list[i].cis1_info[j] == NULL)
144                                 continue;       /* wildcard */
145                         if (pa->card->cis1_info[j] == NULL)
146                                 break;          /* not available */
147                         if (strcmp(pa->card->cis1_info[j], card_list[i].cis1_info[j]) != 0)
148                                 break;          /* mismatch */
149                 }
150                 if (j >= 4)
151                         break;
152         }
153         if (i >= NUM_MATCH_ENTRIES)
154                 return NULL;
155
156         return &card_list[i];
157 }
158
159 /*
160  * Match card
161  */
162 static int
163 pcmcia_isic_match(parent, match, aux)
164         struct device *parent;
165         struct cfdata *match;
166         void *aux;
167 {
168         struct pcmcia_attach_args *pa = aux;
169
170         if (!find_matching_card(pa))
171                 return 0;
172
173         return 1;
174 }
175
176 /*
177  * Attach the card
178  */
179 static void
180 pcmcia_isic_attach(parent, self, aux)
181         struct device *parent, *self;
182         void *aux;
183 {
184         struct pcmcia_isic_softc *psc = (void*) self;
185         struct isic_softc *sc = &psc->sc_isic;
186         struct pcmcia_attach_args *pa = aux;
187         struct pcmcia_config_entry *cfe;
188         const struct isic_pcmcia_card_entry * cde;
189
190         /* Which card is it? */
191         cde = find_matching_card(pa);
192         if (cde == NULL) return; /* oops - not found?!? */
193
194         psc->sc_pf = pa->pf;
195         cfe = pa->pf->cfe_head.sqh_first;
196
197         /* Enable the card */
198         pcmcia_function_init(pa->pf, cfe);
199         pcmcia_function_enable(pa->pf);
200
201         if (!cde->attach(psc, cfe, pa))
202                 return;         /* Ooops ? */
203
204         sc->sc_unit = sc->sc_dev.dv_unit;
205
206         /* Announce card name */
207         printf(": %s\n", cde->name);
208
209         /* MI initilization */
210         pcmcia_isicattach(sc);
211
212         /* setup interrupt */
213         psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, isicintr, sc);
214 }
215
216 /*---------------------------------------------------------------------------*
217  *      card independend attach for pcmicia cards
218  *---------------------------------------------------------------------------*/
219
220 /* parameter and format for message producing e.g. "isic0: " */
221
222 #ifdef __FreeBSD__
223 #define ISIC_FMT        "isic%d: "
224 #define ISIC_PARM       dev->id_unit
225 #define TERMFMT " "
226 #else
227 #define ISIC_FMT        "%s: "
228 #define ISIC_PARM       sc->sc_dev.dv_xname
229 #define TERMFMT "\n"
230 #endif
231
232 int
233 pcmcia_isicattach(struct isic_softc *sc)
234 {
235         static char *ISACversion[] = {
236                 "2085 Version A1/A2 or 2086/2186 Version 1.1",
237                 "2085 Version B1",
238                 "2085 Version B2",
239                 "2085 Version V2.3 (B3)",
240                 "Unknown Version"
241         };
242
243         static char *HSCXversion[] = {
244                 "82525 Version A1",
245                 "Unknown (0x01)",
246                 "82525 Version A2",
247                 "Unknown (0x03)",
248                 "82525 Version A3",
249                 "82525 or 21525 Version 2.1",
250                 "Unknown Version"
251         };
252
253         isic_sc[sc->sc_unit] = sc;              
254         sc->sc_isac_version = 0;
255         sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
256
257         switch(sc->sc_isac_version)
258         {
259                 case ISAC_VA:
260                 case ISAC_VB1:
261                 case ISAC_VB2:
262                 case ISAC_VB3:
263                         break;
264
265                 default:
266                         printf(ISIC_FMT "Error, ISAC version %d unknown!\n",
267                                 ISIC_PARM, sc->sc_isac_version);
268                         return(0);
269                         break;
270         }
271
272         sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
273
274         switch(sc->sc_hscx_version)
275         {
276                 case HSCX_VA1:
277                 case HSCX_VA2:
278                 case HSCX_VA3:
279                 case HSCX_V21:
280                         break;
281                         
282                 default:
283                         printf(ISIC_FMT "Error, HSCX version %d unknown!\n",
284                                 ISIC_PARM, sc->sc_hscx_version);
285                         return(0);
286                         break;
287         };
288
289         /* ISAC setup */
290         
291         isic_isac_init(sc);
292
293         /* HSCX setup */
294
295         isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
296         
297         isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
298
299         /* setup linktab */
300
301         isic_init_linktab(sc);
302
303         /* set trace level */
304
305         sc->sc_trace = TRACE_OFF;
306
307         sc->sc_state = ISAC_IDLE;
308
309         sc->sc_ibuf = NULL;
310         sc->sc_ib = NULL;
311         sc->sc_ilen = 0;
312
313         sc->sc_obuf = NULL;
314         sc->sc_op = NULL;
315         sc->sc_ol = 0;
316         sc->sc_freeflag = 0;
317
318         sc->sc_obuf2 = NULL;
319         sc->sc_freeflag2 = 0;
320
321         /* init higher protocol layers */
322         
323         MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);        
324
325         /* announce chip versions */
326         
327         if(sc->sc_isac_version >= ISAC_UNKN)
328         {
329                 printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT,
330                                 ISIC_PARM,
331                                 sc->sc_isac_version);
332                 sc->sc_isac_version = ISAC_UNKN;
333         }
334         else
335         {
336                 printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT,
337                                 ISIC_PARM,
338                                 ISACversion[sc->sc_isac_version],
339                                 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
340         }
341
342         if(sc->sc_hscx_version >= HSCX_UNKN)
343         {
344                 printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT,
345                                 ISIC_PARM,
346                                 sc->sc_hscx_version);
347                 sc->sc_hscx_version = HSCX_UNKN;
348         }
349         else
350         {
351                 printf(ISIC_FMT "HSCX %s" TERMFMT,
352                                 ISIC_PARM,
353                                 HSCXversion[sc->sc_hscx_version]);
354         }
355
356         return(1);
357 }
358