]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/layer1/pci_isic.c
This commit was generated by cvs2svn to compensate for changes in r56385,
[FreeBSD/FreeBSD.git] / sys / i4b / layer1 / pci_isic.c
1 /*
2  *   Copyright (c) 1998,1999 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  *      pci_isic.c - pcmcia bus frontend for i4b_isic driver
34  *      -------------------------------------------------------
35  *
36  * $FreeBSD$ 
37  *
38  *      last edit-date: [Wed Mar 10 07:22:08 1999]
39  *
40  *      -mh     original implementation
41  *      -mh     added support for Fritz! PCI card
42  *
43  *---------------------------------------------------------------------------*/
44
45 #include <sys/types.h>
46 #include <sys/param.h>
47 #include <sys/errno.h>
48 #include <sys/syslog.h>
49 #include <sys/device.h>
50 #include <sys/socket.h>
51 #include <net/if.h>
52 #include <sys/systm.h>
53 #include <sys/malloc.h>
54
55 #include <machine/cpu.h>
56 #include <machine/intr.h>
57 #include <machine/bus.h>
58
59
60 #include <machine/bus.h>
61 #include <machine/intr.h>
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64 #include <dev/pci/pcidevs.h>
65
66 #ifdef __FreeBSD__
67 #include <machine/i4b_ioctl.h>
68 #else
69 #include <i4b/i4b_ioctl.h>
70 #endif
71
72 #include <i4b/layer1/i4b_l1.h>
73 #include <i4b/layer1/i4b_ipac.h>
74 #include <i4b/layer1/i4b_isac.h>
75 #include <i4b/layer1/i4b_hscx.h>
76 #include <i4b/layer1/pci_isic.h>
77 #include <i4b/include/i4b_global.h>
78 #include <i4b/include/i4b_l1l2.h>
79
80 static int pci_isic_match __P((struct device *, struct cfdata *, void *));
81 static void pci_isic_attach __P((struct device *, struct device *, void *));
82 static const struct isic_pci_product * find_matching_card __P((struct pci_attach_args *pa));
83
84 static void isic_pciattach __P((struct pci_isic_softc *psc, struct pci_attach_args *pa));
85
86 struct cfattach pci_isic_ca = {
87         sizeof(struct pci_isic_softc), pci_isic_match, pci_isic_attach
88 };
89
90
91 static const struct isic_pci_product {
92         pci_vendor_id_t npp_vendor;
93         pci_product_id_t npp_product;
94         int cardtype;
95         const char * name;
96         void (*attach)(struct pci_isic_softc *psc, struct pci_attach_args *pa);
97         void (*pciattach)(struct pci_isic_softc *psc, struct pci_attach_args *pa);
98 } isic_pci_products[] = {
99
100 #ifdef ELSA_QS1PCI
101 #ifndef PCI_PRODUCT_ELSA_QS1PCI
102 #define PCI_PRODUCT_ELSA_QS1PCI 0x1000  /* added to pcidevs in 1.3K, earlier versions missing it */
103 #endif
104         { PCI_VENDOR_ELSA, PCI_PRODUCT_ELSA_QS1PCI,
105           CARD_TYPEP_ELSAQS1PCI,
106           "ELSA QuickStep 1000pro/PCI",
107           isic_attach_Eqs1pp,   /* card specific initialization */
108           isic_pciattach        /* generic setup for ISAC/HSCX or IPAC boards */
109          },
110 #endif
111
112 #ifdef AVM_A1_PCI
113 #ifndef PCI_VENDOR_AVM
114 #define PCI_VENDOR_AVM  0x1244  /* earlier versions missing this */
115 #define PCI_PRODUCT_AVM_FRITZ_CARD 0x0a00
116 #endif
117         { PCI_VENDOR_AVM, PCI_PRODUCT_AVM_FRITZ_CARD,
118           CARD_TYPEP_AVMA1PCI,
119           "Fritz!Card",
120           isic_attach_fritzPci,
121           NULL                          /* card rolls its own setup */
122          },
123 #endif
124
125         { 0, 0, 0, NULL, NULL },
126 };
127
128 static const struct isic_pci_product * find_matching_card(pa)
129         struct pci_attach_args *pa;
130 {
131         const struct isic_pci_product * pp = NULL;
132
133         for (pp = isic_pci_products; pp->npp_vendor; pp++) 
134                 if (PCI_VENDOR(pa->pa_id) == pp->npp_vendor &&
135                     PCI_PRODUCT(pa->pa_id) == pp->npp_product)
136                         return pp;
137
138         return NULL;
139 }
140
141 /*
142  * Match card
143  */
144 static int
145 pci_isic_match(parent, match, aux)
146         struct device *parent;
147         struct cfdata *match;
148         void *aux;
149 {
150         struct pci_attach_args *pa = aux;
151
152         if (!find_matching_card(pa))
153                 return 0;
154
155         return 1;
156 }
157
158 /*
159  * Attach the card
160  */
161 static void
162 pci_isic_attach(parent, self, aux)
163         struct device *parent, *self;
164         void *aux;
165 {
166         struct pci_isic_softc *psc = (void*) self;
167         struct isic_softc *sc = &psc->sc_isic;
168         struct pci_attach_args *pa = aux;
169         const struct isic_pci_product * prod;
170
171         /* Redo probe */
172         prod = find_matching_card(pa);
173         if (prod == NULL) return; /* oops - not found?!? */
174
175         sc->sc_unit = sc->sc_dev.dv_unit;
176         printf(": %s\n", prod->name);
177
178         /* card initilization and sc setup */
179         prod->attach(psc, pa);
180
181         /* generic setup, if needed for this card */
182         if (prod->pciattach) prod->pciattach(psc, pa);
183 }
184
185 /*---------------------------------------------------------------------------*
186  *      isic - pci device driver attach routine
187  *---------------------------------------------------------------------------*/
188 static void
189 isic_pciattach(psc, pa)
190         struct pci_isic_softc *psc;
191         struct pci_attach_args *pa;
192 {
193         struct isic_softc *sc = &psc->sc_isic;
194         pci_chipset_tag_t pc = pa->pa_pc;
195         pci_intr_handle_t ih;
196         const char *intrstr;
197
198         static char *ISACversion[] = {
199                 "2085 Version A1/A2 or 2086/2186 Version 1.1",
200                 "2085 Version B1",
201                 "2085 Version B2",
202                 "2085 Version V2.3 (B3)",
203                 "Unknown Version"
204         };
205
206         static char *HSCXversion[] = {
207                 "82525 Version A1",
208                 "Unknown (0x01)",
209                 "82525 Version A2",
210                 "Unknown (0x03)",
211                 "82525 Version A3",
212                 "82525 or 21525 Version 2.1",
213                 "Unknown Version"
214         };
215
216         isic_sc[sc->sc_unit] = sc;      /* XXX - hack! */
217
218         sc->sc_isac_version = 0;
219         sc->sc_hscx_version = 0;
220         
221         if(sc->sc_ipac)
222         {
223                 u_int ret = IPAC_READ(IPAC_ID);
224
225                 switch(ret)
226                 {
227                         case 0x01:
228                                 printf("%s: IPAC PSB2115 Version 1.1\n", sc->sc_dev.dv_xname);
229                                 break;
230         
231                         default:
232                                 printf("%s: Error, IPAC version %d unknown!\n",
233                                         sc->sc_dev.dv_xname, ret);
234                                 return;
235                 }
236         }
237         else
238         {
239                 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
240         
241                 switch(sc->sc_isac_version)
242                 {
243                         case ISAC_VA:
244                         case ISAC_VB1:
245                         case ISAC_VB2:
246                         case ISAC_VB3:
247                                 printf("%s: ISAC %s (IOM-%c)\n",
248                                         sc->sc_dev.dv_xname,
249                                         ISACversion[sc->sc_isac_version],
250                                         sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
251                                 break;
252         
253                         default:
254                                 printf("%s: Error, ISAC version %d unknown!\n",
255                                         sc->sc_dev.dv_xname, sc->sc_isac_version);
256                                 return;
257                 }
258         
259                 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
260         
261                 switch(sc->sc_hscx_version)
262                 {
263                         case HSCX_VA1:
264                         case HSCX_VA2:
265                         case HSCX_VA3:
266                         case HSCX_V21:
267                                 printf("%s: HSCX %s\n",
268                                         sc->sc_dev.dv_xname,
269                                         HSCXversion[sc->sc_hscx_version]);
270                                 break;
271                                 
272                         default:
273                                 printf("%s: Error, HSCX version %d unknown!\n",
274                                         sc->sc_dev.dv_xname, sc->sc_hscx_version);
275                                 return;
276                 }
277         }
278         
279         /* ISAC setup */
280         
281         isic_isac_init(sc);
282
283         /* HSCX setup */
284
285         isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
286         
287         isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
288
289         /* setup linktab */
290
291         isic_init_linktab(sc);
292
293         /* set trace level */
294
295         sc->sc_trace = TRACE_OFF;
296
297         sc->sc_state = ISAC_IDLE;
298
299         sc->sc_ibuf = NULL;
300         sc->sc_ib = NULL;
301         sc->sc_ilen = 0;
302
303         sc->sc_obuf = NULL;
304         sc->sc_op = NULL;
305         sc->sc_ol = 0;
306         sc->sc_freeflag = 0;
307
308         sc->sc_obuf2 = NULL;
309         sc->sc_freeflag2 = 0;
310
311 #if defined(__FreeBSD__) && __FreeBSD__ >=3
312         callout_handle_init(&sc->sc_T3_callout);
313         callout_handle_init(&sc->sc_T4_callout);        
314 #endif
315         
316         /* init higher protocol layers */
317         
318         MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);
319         
320
321         /* Map and establish the interrupt. */
322         if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
323             pa->pa_intrline, &ih)) {
324                 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
325                 return;
326         }
327         intrstr = pci_intr_string(pc, ih);
328         psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, isicintr, sc);
329         if (psc->sc_ih == NULL) {
330                 printf("%s: couldn't establish interrupt",
331                     sc->sc_dev.dv_xname);
332                 if (intrstr != NULL)
333                         printf(" at %s", intrstr);
334                 printf("\n");
335                 return;
336         }
337         printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
338 }
339