1 /* $NetBSD: isic_pci.c,v 1.36 2009/11/26 15:17:10 njoly Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: isic_pci.c,v 1.36 2009/11/26 15:17:10 njoly Exp $");
35 #include <sys/param.h>
36 #include <sys/errno.h>
37 #include <sys/syslog.h>
38 #include <sys/device.h>
39 #include <sys/socket.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <sys/callout.h>
52 #include <dev/pci/pcireg.h>
53 #include <dev/pci/pcivar.h>
54 #include <dev/pci/pcidevs.h>
56 #include <netisdn/i4b_ioctl.h>
57 #include <netisdn/i4b_global.h>
58 #include <netisdn/i4b_debug.h>
59 #include <netisdn/i4b_trace.h>
60 #include <netisdn/i4b_l2.h>
61 #include <netisdn/i4b_l1l2.h>
63 #include <dev/ic/isic_l1.h>
64 #include <dev/ic/ipac.h>
65 #include <dev/ic/isac.h>
66 #include <dev/ic/hscx.h>
67 #include <dev/pci/isic_pci.h>
69 extern const struct isdn_layer1_isdnif_driver isic_std_driver
;
71 static int isic_pci_match(device_t
, cfdata_t
, void *);
72 static void isic_pci_attach(device_t
, device_t
, void *);
73 static const struct isic_pci_product
* find_matching_card(struct pci_attach_args
*pa
);
75 static void isic_pci_isdn_attach(struct pci_isic_softc
*psc
, struct pci_attach_args
*pa
, const char *cardname
);
76 static int isic_pci_detach(device_t self
, int flags
);
77 static int isic_pci_activate(device_t self
, enum devact act
);
79 CFATTACH_DECL(isic_pci
, sizeof(struct pci_isic_softc
),
80 isic_pci_match
, isic_pci_attach
, isic_pci_detach
, isic_pci_activate
);
82 static const struct isic_pci_product
{
83 pci_vendor_id_t npp_vendor
;
84 pci_product_id_t npp_product
;
87 int (*attach
)(struct pci_isic_softc
*psc
, struct pci_attach_args
*pa
);
88 void (*pciattach
)(struct pci_isic_softc
*psc
, struct pci_attach_args
*pa
, const char *cardname
);
89 } isic_pci_products
[] = {
90 { PCI_VENDOR_ELSA
, PCI_PRODUCT_ELSA_QS1PCI
,
91 CARD_TYPEP_ELSAQS1PCI
,
92 "ELSA QuickStep 1000pro/PCI",
93 isic_attach_Eqs1pp
, /* card specific initialization */
94 isic_pci_isdn_attach
/* generic setup for ISAC/HSCX or IPAC boards */
96 { 0, 0, 0, NULL
, NULL
, NULL
},
99 static const struct isic_pci_product
* find_matching_card(pa
)
100 struct pci_attach_args
*pa
;
102 const struct isic_pci_product
* pp
= NULL
;
104 for (pp
= isic_pci_products
; pp
->npp_vendor
; pp
++)
105 if (PCI_VENDOR(pa
->pa_id
) == pp
->npp_vendor
&&
106 PCI_PRODUCT(pa
->pa_id
) == pp
->npp_product
)
116 isic_pci_match(device_t parent
, cfdata_t match
, void *aux
)
118 struct pci_attach_args
*pa
= aux
;
120 if (!find_matching_card(pa
))
130 isic_pci_attach(device_t parent
, device_t self
, void *aux
)
132 struct pci_isic_softc
*psc
= device_private(self
);
133 struct isic_softc
*sc
= &psc
->sc_isic
;
134 struct pci_attach_args
*pa
= aux
;
135 const struct isic_pci_product
* prod
;
138 prod
= find_matching_card(pa
);
139 if (prod
== NULL
) return; /* oops - not found?!? */
141 printf(": %s\n", prod
->name
);
143 callout_init(&sc
->sc_T3_callout
, 0);
144 callout_init(&sc
->sc_T4_callout
, 0);
146 /* card initilization and sc setup */
147 if (!prod
->attach(psc
, pa
))
150 /* generic setup, if needed for this card */
151 if (prod
->pciattach
) prod
->pciattach(psc
, pa
, prod
->name
);
154 /*---------------------------------------------------------------------------*
155 * isic - pci device driver attach routine
156 *---------------------------------------------------------------------------*/
158 isic_pci_isdn_attach(struct pci_isic_softc
*psc
, struct pci_attach_args
*pa
, const char *cardname
)
160 struct isic_softc
*sc
= &psc
->sc_isic
;
161 pci_chipset_tag_t pc
= pa
->pa_pc
;
162 pci_intr_handle_t ih
;
165 static const char *ISACversion
[] = {
166 "2085 Version A1/A2 or 2086/2186 Version 1.1",
169 "2085 Version V2.3 (B3)",
173 static const char *HSCXversion
[] = {
179 "82525 or 21525 Version 2.1",
183 sc
->sc_isac_version
= 0;
184 sc
->sc_hscx_version
= 0;
188 u_int ret
= IPAC_READ(IPAC_ID
);
193 printf("%s: IPAC PSB2115 Version 1.1\n", device_xname(&sc
->sc_dev
));
197 printf("%s: IPAC PSB2115 Version 1.2\n", device_xname(&sc
->sc_dev
));
201 printf("%s: Error, IPAC version %d unknown!\n",
202 device_xname(&sc
->sc_dev
), ret
);
208 sc
->sc_isac_version
= ((ISAC_READ(I_RBCH
)) >> 5) & 0x03;
210 switch(sc
->sc_isac_version
)
216 printf("%s: ISAC %s (IOM-%c)\n",
217 device_xname(&sc
->sc_dev
),
218 ISACversion
[sc
->sc_isac_version
],
219 sc
->sc_bustyp
== BUS_TYPE_IOM1
? '1' : '2');
223 printf("%s: Error, ISAC version %d unknown!\n",
224 device_xname(&sc
->sc_dev
), sc
->sc_isac_version
);
228 sc
->sc_hscx_version
= HSCX_READ(0, H_VSTR
) & 0xf;
230 switch(sc
->sc_hscx_version
)
236 printf("%s: HSCX %s\n",
237 device_xname(&sc
->sc_dev
),
238 HSCXversion
[sc
->sc_hscx_version
]);
242 printf("%s: Error, HSCX version %d unknown!\n",
243 device_xname(&sc
->sc_dev
), sc
->sc_hscx_version
);
248 /* Map and establish the interrupt. */
249 if (pci_intr_map(pa
, &ih
)) {
250 aprint_error_dev(&sc
->sc_dev
, "couldn't map interrupt\n");
253 intrstr
= pci_intr_string(pc
, ih
);
254 psc
->sc_ih
= pci_intr_establish(pc
, ih
, IPL_NET
, isic_intr_qs1p
, psc
);
255 if (psc
->sc_ih
== NULL
) {
256 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt");
258 aprint_error(" at %s", intrstr
);
263 aprint_normal_dev(&sc
->sc_dev
, "interrupting at %s\n", intrstr
);
265 sc
->sc_intr_valid
= ISIC_INTR_DISABLED
;
269 isic_bchannel_setup(sc
, HSCX_CH_A
, BPROT_NONE
, 0);
271 isic_bchannel_setup(sc
, HSCX_CH_B
, BPROT_NONE
, 0);
275 isic_init_linktab(sc
);
277 /* set trace level */
279 sc
->sc_trace
= TRACE_OFF
;
281 sc
->sc_state
= ISAC_IDLE
;
293 sc
->sc_freeflag2
= 0;
295 /* init higher protocol layers */
296 isic_attach_bri(sc
, cardname
, &isic_std_driver
);
301 isic_pci_detach(device_t self
, int flags
)
303 struct pci_isic_softc
*psc
= device_private(self
);
305 bus_space_unmap(psc
->sc_isic
.sc_maps
[0].t
, psc
->sc_isic
.sc_maps
[0].h
, psc
->sc_size
);
306 bus_space_free(psc
->sc_isic
.sc_maps
[0].t
, psc
->sc_isic
.sc_maps
[0].h
, psc
->sc_size
);
307 pci_intr_disestablish(psc
->sc_pc
, psc
->sc_ih
);
313 isic_pci_activate(device_t self
, enum devact act
)
315 struct pci_isic_softc
*psc
= device_private(self
);
318 case DVACT_DEACTIVATE
:
319 psc
->sc_isic
.sc_intr_valid
= ISIC_INTR_DYING
;
320 isic_detach_bri(&psc
->sc_isic
);