Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / isic_pci.c
blob504f5a143687095f265aae23fb2339afe963b521
1 /* $NetBSD: isic_pci.c,v 1.36 2009/11/26 15:17:10 njoly Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
12 * are met:
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>
40 #include <net/if.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <sys/callout.h>
45 #include <sys/cpu.h>
46 #include <sys/intr.h>
47 #include <sys/bus.h>
50 #include <sys/bus.h>
51 #include <sys/intr.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;
85 int cardtype;
86 const char * name;
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)
107 return pp;
109 return NULL;
113 * Match card
115 static int
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))
121 return 0;
123 return 1;
127 * Attach the card
129 static void
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;
137 /* Redo probe */
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))
148 return;
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 *---------------------------------------------------------------------------*/
157 static void
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;
163 const char *intrstr;
165 static const char *ISACversion[] = {
166 "2085 Version A1/A2 or 2086/2186 Version 1.1",
167 "2085 Version B1",
168 "2085 Version B2",
169 "2085 Version V2.3 (B3)",
170 "Unknown Version"
173 static const char *HSCXversion[] = {
174 "82525 Version A1",
175 "Unknown (0x01)",
176 "82525 Version A2",
177 "Unknown (0x03)",
178 "82525 Version A3",
179 "82525 or 21525 Version 2.1",
180 "Unknown Version"
183 sc->sc_isac_version = 0;
184 sc->sc_hscx_version = 0;
186 if(sc->sc_ipac)
188 u_int ret = IPAC_READ(IPAC_ID);
190 switch(ret)
192 case 0x01:
193 printf("%s: IPAC PSB2115 Version 1.1\n", device_xname(&sc->sc_dev));
194 break;
196 case 0x02:
197 printf("%s: IPAC PSB2115 Version 1.2\n", device_xname(&sc->sc_dev));
198 break;
200 default:
201 printf("%s: Error, IPAC version %d unknown!\n",
202 device_xname(&sc->sc_dev), ret);
203 return;
206 else
208 sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03;
210 switch(sc->sc_isac_version)
212 case ISAC_VA:
213 case ISAC_VB1:
214 case ISAC_VB2:
215 case ISAC_VB3:
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');
220 break;
222 default:
223 printf("%s: Error, ISAC version %d unknown!\n",
224 device_xname(&sc->sc_dev), sc->sc_isac_version);
225 return;
228 sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf;
230 switch(sc->sc_hscx_version)
232 case HSCX_VA1:
233 case HSCX_VA2:
234 case HSCX_VA3:
235 case HSCX_V21:
236 printf("%s: HSCX %s\n",
237 device_xname(&sc->sc_dev),
238 HSCXversion[sc->sc_hscx_version]);
239 break;
241 default:
242 printf("%s: Error, HSCX version %d unknown!\n",
243 device_xname(&sc->sc_dev), sc->sc_hscx_version);
244 return;
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");
251 return;
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");
257 if (intrstr != NULL)
258 aprint_error(" at %s", intrstr);
259 aprint_error("\n");
260 return;
262 psc->sc_pc = pc;
263 aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n", intrstr);
265 sc->sc_intr_valid = ISIC_INTR_DISABLED;
267 /* HSCX setup */
269 isic_bchannel_setup(sc, HSCX_CH_A, BPROT_NONE, 0);
271 isic_bchannel_setup(sc, HSCX_CH_B, BPROT_NONE, 0);
273 /* setup linktab */
275 isic_init_linktab(sc);
277 /* set trace level */
279 sc->sc_trace = TRACE_OFF;
281 sc->sc_state = ISAC_IDLE;
283 sc->sc_ibuf = NULL;
284 sc->sc_ib = NULL;
285 sc->sc_ilen = 0;
287 sc->sc_obuf = NULL;
288 sc->sc_op = NULL;
289 sc->sc_ol = 0;
290 sc->sc_freeflag = 0;
292 sc->sc_obuf2 = NULL;
293 sc->sc_freeflag2 = 0;
295 /* init higher protocol layers */
296 isic_attach_bri(sc, cardname, &isic_std_driver);
300 static int
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);
309 return (0);
312 static int
313 isic_pci_activate(device_t self, enum devact act)
315 struct pci_isic_softc *psc = device_private(self);
317 switch (act) {
318 case DVACT_DEACTIVATE:
319 psc->sc_isic.sc_intr_valid = ISIC_INTR_DYING;
320 isic_detach_bri(&psc->sc_isic);
321 return 0;
322 default:
323 return EOPNOTSUPP;