2 * Copyright (c) 1998,1999 Martin Husemann. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
31 *---------------------------------------------------------------------------
33 * pci_isic.c - pcmcia bus frontend for i4b_isic driver
34 * -------------------------------------------------------
38 * last edit-date: [Wed Mar 10 07:22:08 1999]
40 * -mh original implementation
41 * -mh added support for Fritz! PCI card
43 *---------------------------------------------------------------------------*/
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>
52 #include <sys/systm.h>
53 #include <sys/malloc.h>
55 #include <machine/cpu.h>
56 #include <machine/intr.h>
57 #include <machine/bus.h>
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>
67 #include <machine/i4b_ioctl.h>
69 #include <i4b/i4b_ioctl.h>
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>
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));
84 static void isic_pciattach __P((struct pci_isic_softc *psc, struct pci_attach_args *pa));
86 struct cfattach pci_isic_ca = {
87 sizeof(struct pci_isic_softc), pci_isic_match, pci_isic_attach
91 static const struct isic_pci_product {
92 pci_vendor_id_t npp_vendor;
93 pci_product_id_t npp_product;
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[] = {
101 #ifndef PCI_PRODUCT_ELSA_QS1PCI
102 #define PCI_PRODUCT_ELSA_QS1PCI 0x1000 /* added to pcidevs in 1.3K, earlier versions missing it */
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 */
113 #ifndef PCI_VENDOR_AVM
114 #define PCI_VENDOR_AVM 0x1244 /* earlier versions missing this */
115 #define PCI_PRODUCT_AVM_FRITZ_CARD 0x0a00
117 { PCI_VENDOR_AVM, PCI_PRODUCT_AVM_FRITZ_CARD,
120 isic_attach_fritzPci,
121 NULL /* card rolls its own setup */
125 { 0, 0, 0, NULL, NULL },
128 static const struct isic_pci_product * find_matching_card(pa)
129 struct pci_attach_args *pa;
131 const struct isic_pci_product * pp = NULL;
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)
145 pci_isic_match(parent, match, aux)
146 struct device *parent;
147 struct cfdata *match;
150 struct pci_attach_args *pa = aux;
152 if (!find_matching_card(pa))
162 pci_isic_attach(parent, self, aux)
163 struct device *parent, *self;
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;
172 prod = find_matching_card(pa);
173 if (prod == NULL) return; /* oops - not found?!? */
175 sc->sc_unit = sc->sc_dev.dv_unit;
176 printf(": %s\n", prod->name);
178 /* card initilization and sc setup */
179 prod->attach(psc, pa);
181 /* generic setup, if needed for this card */
182 if (prod->pciattach) prod->pciattach(psc, pa);
185 /*---------------------------------------------------------------------------*
186 * isic - pci device driver attach routine
187 *---------------------------------------------------------------------------*/
189 isic_pciattach(psc, pa)
190 struct pci_isic_softc *psc;
191 struct pci_attach_args *pa;
193 struct isic_softc *sc = &psc->sc_isic;
194 pci_chipset_tag_t pc = pa->pa_pc;
195 pci_intr_handle_t ih;
198 static char *ISACversion[] = {
199 "2085 Version A1/A2 or 2086/2186 Version 1.1",
202 "2085 Version V2.3 (B3)",
206 static char *HSCXversion[] = {
212 "82525 or 21525 Version 2.1",
216 isic_sc[sc->sc_unit] = sc; /* XXX - hack! */
218 sc->sc_isac_version = 0;
219 sc->sc_hscx_version = 0;
223 u_int ret = IPAC_READ(IPAC_ID);
228 printf("%s: IPAC PSB2115 Version 1.1\n", sc->sc_dev.dv_xname);
232 printf("%s: Error, IPAC version %d unknown!\n",
233 sc->sc_dev.dv_xname, ret);
239 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
241 switch(sc->sc_isac_version)
247 printf("%s: ISAC %s (IOM-%c)\n",
249 ISACversion[sc->sc_isac_version],
250 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
254 printf("%s: Error, ISAC version %d unknown!\n",
255 sc->sc_dev.dv_xname, sc->sc_isac_version);
259 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
261 switch(sc->sc_hscx_version)
267 printf("%s: HSCX %s\n",
269 HSCXversion[sc->sc_hscx_version]);
273 printf("%s: Error, HSCX version %d unknown!\n",
274 sc->sc_dev.dv_xname, sc->sc_hscx_version);
285 isic_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
287 isic_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
291 isic_init_linktab(sc);
293 /* set trace level */
295 sc->sc_trace = TRACE_OFF;
297 sc->sc_state = ISAC_IDLE;
309 sc->sc_freeflag2 = 0;
311 #if defined(__FreeBSD__) && __FreeBSD__ >=3
312 callout_handle_init(&sc->sc_T3_callout);
313 callout_handle_init(&sc->sc_T4_callout);
316 /* init higher protocol layers */
318 MPH_Status_Ind(sc->sc_unit, STI_ATTACH, sc->sc_cardtyp);
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);
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);
333 printf(" at %s", intrstr);
337 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);