[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / isdn / hardware / avm / b1pci.c
blob5435a6cfb5e7a3c414626d2220872708d5c60fae
1 /* $Id: b1pci.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
2 *
3 * Module for AVM B1 PCI-card.
4 *
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/delay.h>
17 #include <linux/mm.h>
18 #include <linux/interrupt.h>
19 #include <linux/ioport.h>
20 #include <linux/pci.h>
21 #include <linux/capi.h>
22 #include <asm/io.h>
23 #include <linux/init.h>
24 #include <linux/isdn/capicmd.h>
25 #include <linux/isdn/capiutil.h>
26 #include <linux/isdn/capilli.h>
27 #include "avmcard.h"
29 /* ------------------------------------------------------------- */
31 static char *revision = "$Revision: 1.1.2.2 $";
33 /* ------------------------------------------------------------- */
35 static struct pci_device_id b1pci_pci_tbl[] = {
36 { PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_B1, PCI_ANY_ID, PCI_ANY_ID },
37 { } /* Terminating entry */
40 MODULE_DEVICE_TABLE(pci, b1pci_pci_tbl);
41 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM B1 PCI card");
42 MODULE_AUTHOR("Carsten Paeth");
43 MODULE_LICENSE("GPL");
45 /* ------------------------------------------------------------- */
47 static char *b1pci_procinfo(struct capi_ctr *ctrl)
49 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
51 if (!cinfo)
52 return "";
53 sprintf(cinfo->infobuf, "%s %s 0x%x %d r%d",
54 cinfo->cardname[0] ? cinfo->cardname : "-",
55 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
56 cinfo->card ? cinfo->card->port : 0x0,
57 cinfo->card ? cinfo->card->irq : 0,
58 cinfo->card ? cinfo->card->revision : 0
60 return cinfo->infobuf;
63 /* ------------------------------------------------------------- */
65 static int b1pci_probe(struct capicardparams *p, struct pci_dev *pdev)
67 avmcard *card;
68 avmctrl_info *cinfo;
69 int retval;
71 card = b1_alloc_card(1);
72 if (!card) {
73 printk(KERN_WARNING "b1pci: no memory.\n");
74 retval = -ENOMEM;
75 goto err;
78 cinfo = card->ctrlinfo;
79 sprintf(card->name, "b1pci-%x", p->port);
80 card->port = p->port;
81 card->irq = p->irq;
82 card->cardtype = avm_b1pci;
84 if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
85 printk(KERN_WARNING "b1pci: ports 0x%03x-0x%03x in use.\n",
86 card->port, card->port + AVMB1_PORTLEN);
87 retval = -EBUSY;
88 goto err_free;
90 b1_reset(card->port);
91 retval = b1_detect(card->port, card->cardtype);
92 if (retval) {
93 printk(KERN_NOTICE "b1pci: NO card at 0x%x (%d)\n",
94 card->port, retval);
95 retval = -ENODEV;
96 goto err_release_region;
98 b1_reset(card->port);
99 b1_getrevision(card);
101 retval = request_irq(card->irq, b1_interrupt, SA_SHIRQ, card->name, card);
102 if (retval) {
103 printk(KERN_ERR "b1pci: unable to get IRQ %d.\n", card->irq);
104 retval = -EBUSY;
105 goto err_release_region;
108 cinfo->capi_ctrl.driver_name = "b1pci";
109 cinfo->capi_ctrl.driverdata = cinfo;
110 cinfo->capi_ctrl.register_appl = b1_register_appl;
111 cinfo->capi_ctrl.release_appl = b1_release_appl;
112 cinfo->capi_ctrl.send_message = b1_send_message;
113 cinfo->capi_ctrl.load_firmware = b1_load_firmware;
114 cinfo->capi_ctrl.reset_ctr = b1_reset_ctr;
115 cinfo->capi_ctrl.procinfo = b1pci_procinfo;
116 cinfo->capi_ctrl.ctr_read_proc = b1ctl_read_proc;
117 strcpy(cinfo->capi_ctrl.name, card->name);
118 cinfo->capi_ctrl.owner = THIS_MODULE;
120 retval = attach_capi_ctr(&cinfo->capi_ctrl);
121 if (retval) {
122 printk(KERN_ERR "b1pci: attach controller failed.\n");
123 goto err_free_irq;
126 if (card->revision >= 4) {
127 printk(KERN_INFO "b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, revision %d (no dma)\n",
128 card->port, card->irq, card->revision);
129 } else {
130 printk(KERN_INFO "b1pci: AVM B1 PCI at i/o %#x, irq %d, revision %d\n",
131 card->port, card->irq, card->revision);
134 pci_set_drvdata(pdev, card);
135 return 0;
137 err_free_irq:
138 free_irq(card->irq, card);
139 err_release_region:
140 release_region(card->port, AVMB1_PORTLEN);
141 err_free:
142 b1_free_card(card);
143 err:
144 return retval;
147 static void b1pci_remove(struct pci_dev *pdev)
149 avmcard *card = pci_get_drvdata(pdev);
150 avmctrl_info *cinfo = card->ctrlinfo;
151 unsigned int port = card->port;
153 b1_reset(port);
154 b1_reset(port);
156 detach_capi_ctr(&cinfo->capi_ctrl);
157 free_irq(card->irq, card);
158 release_region(card->port, AVMB1_PORTLEN);
159 b1_free_card(card);
162 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
163 /* ------------------------------------------------------------- */
165 static char *b1pciv4_procinfo(struct capi_ctr *ctrl)
167 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
169 if (!cinfo)
170 return "";
171 sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx r%d",
172 cinfo->cardname[0] ? cinfo->cardname : "-",
173 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
174 cinfo->card ? cinfo->card->port : 0x0,
175 cinfo->card ? cinfo->card->irq : 0,
176 cinfo->card ? cinfo->card->membase : 0,
177 cinfo->card ? cinfo->card->revision : 0
179 return cinfo->infobuf;
182 /* ------------------------------------------------------------- */
184 static int b1pciv4_probe(struct capicardparams *p, struct pci_dev *pdev)
186 avmcard *card;
187 avmctrl_info *cinfo;
188 int retval;
190 card = b1_alloc_card(1);
191 if (!card) {
192 printk(KERN_WARNING "b1pci: no memory.\n");
193 retval = -ENOMEM;
194 goto err;
197 card->dma = avmcard_dma_alloc("b1pci", pdev, 2048+128, 2048+128);
198 if (!card->dma) {
199 printk(KERN_WARNING "b1pci: dma alloc.\n");
200 retval = -ENOMEM;
201 goto err_free;
204 cinfo = card->ctrlinfo;
205 sprintf(card->name, "b1pciv4-%x", p->port);
206 card->port = p->port;
207 card->irq = p->irq;
208 card->membase = p->membase;
209 card->cardtype = avm_b1pci;
211 if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
212 printk(KERN_WARNING "b1pci: ports 0x%03x-0x%03x in use.\n",
213 card->port, card->port + AVMB1_PORTLEN);
214 retval = -EBUSY;
215 goto err_free_dma;
218 card->mbase = ioremap(card->membase, 64);
219 if (!card->mbase) {
220 printk(KERN_NOTICE "b1pci: can't remap memory at 0x%lx\n",
221 card->membase);
222 retval = -ENOMEM;
223 goto err_release_region;
226 b1dma_reset(card);
228 retval = b1pciv4_detect(card);
229 if (retval) {
230 printk(KERN_NOTICE "b1pci: NO card at 0x%x (%d)\n",
231 card->port, retval);
232 retval = -ENODEV;
233 goto err_unmap;
235 b1dma_reset(card);
236 b1_getrevision(card);
238 retval = request_irq(card->irq, b1dma_interrupt, SA_SHIRQ, card->name, card);
239 if (retval) {
240 printk(KERN_ERR "b1pci: unable to get IRQ %d.\n",
241 card->irq);
242 retval = -EBUSY;
243 goto err_unmap;
246 cinfo->capi_ctrl.owner = THIS_MODULE;
247 cinfo->capi_ctrl.driver_name = "b1pciv4";
248 cinfo->capi_ctrl.driverdata = cinfo;
249 cinfo->capi_ctrl.register_appl = b1dma_register_appl;
250 cinfo->capi_ctrl.release_appl = b1dma_release_appl;
251 cinfo->capi_ctrl.send_message = b1dma_send_message;
252 cinfo->capi_ctrl.load_firmware = b1dma_load_firmware;
253 cinfo->capi_ctrl.reset_ctr = b1dma_reset_ctr;
254 cinfo->capi_ctrl.procinfo = b1pciv4_procinfo;
255 cinfo->capi_ctrl.ctr_read_proc = b1dmactl_read_proc;
256 strcpy(cinfo->capi_ctrl.name, card->name);
258 retval = attach_capi_ctr(&cinfo->capi_ctrl);
259 if (retval) {
260 printk(KERN_ERR "b1pci: attach controller failed.\n");
261 goto err_free_irq;
263 card->cardnr = cinfo->capi_ctrl.cnr;
265 printk(KERN_INFO "b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, mem %#lx, revision %d (dma)\n",
266 card->port, card->irq, card->membase, card->revision);
268 pci_set_drvdata(pdev, card);
269 return 0;
271 err_free_irq:
272 free_irq(card->irq, card);
273 err_unmap:
274 iounmap(card->mbase);
275 err_release_region:
276 release_region(card->port, AVMB1_PORTLEN);
277 err_free_dma:
278 avmcard_dma_free(card->dma);
279 err_free:
280 b1_free_card(card);
281 err:
282 return retval;
286 static void b1pciv4_remove(struct pci_dev *pdev)
288 avmcard *card = pci_get_drvdata(pdev);
289 avmctrl_info *cinfo = card->ctrlinfo;
291 b1dma_reset(card);
293 detach_capi_ctr(&cinfo->capi_ctrl);
294 free_irq(card->irq, card);
295 iounmap(card->mbase);
296 release_region(card->port, AVMB1_PORTLEN);
297 avmcard_dma_free(card->dma);
298 b1_free_card(card);
301 #endif /* CONFIG_ISDN_DRV_AVMB1_B1PCIV4 */
303 static int __devinit b1pci_pci_probe(struct pci_dev *pdev,
304 const struct pci_device_id *ent)
306 struct capicardparams param;
307 int retval;
309 if (pci_enable_device(pdev) < 0) {
310 printk(KERN_ERR "b1pci: failed to enable AVM-B1\n");
311 return -ENODEV;
313 param.irq = pdev->irq;
315 if (pci_resource_start(pdev, 2)) { /* B1 PCI V4 */
316 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
317 pci_set_master(pdev);
318 #endif
319 param.membase = pci_resource_start(pdev, 0);
320 param.port = pci_resource_start(pdev, 2);
322 printk(KERN_INFO "b1pci: PCI BIOS reports AVM-B1 V4 at i/o %#x, irq %d, mem %#x\n",
323 param.port, param.irq, param.membase);
324 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
325 retval = b1pciv4_probe(&param, pdev);
326 #else
327 retval = b1pci_probe(&param, pdev);
328 #endif
329 if (retval != 0) {
330 printk(KERN_ERR "b1pci: no AVM-B1 V4 at i/o %#x, irq %d, mem %#x detected\n",
331 param.port, param.irq, param.membase);
333 } else {
334 param.membase = 0;
335 param.port = pci_resource_start(pdev, 1);
337 printk(KERN_INFO "b1pci: PCI BIOS reports AVM-B1 at i/o %#x, irq %d\n",
338 param.port, param.irq);
339 retval = b1pci_probe(&param, pdev);
340 if (retval != 0) {
341 printk(KERN_ERR "b1pci: no AVM-B1 at i/o %#x, irq %d detected\n",
342 param.port, param.irq);
345 return retval;
348 static void __devexit b1pci_pci_remove(struct pci_dev *pdev)
350 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
351 avmcard *card = pci_get_drvdata(pdev);
353 if (card->dma)
354 b1pciv4_remove(pdev);
355 else
356 b1pci_remove(pdev);
357 #else
358 b1pci_remove(pdev);
359 #endif
362 static struct pci_driver b1pci_pci_driver = {
363 .name = "b1pci",
364 .id_table = b1pci_pci_tbl,
365 .probe = b1pci_pci_probe,
366 .remove = __devexit_p(b1pci_pci_remove),
369 static struct capi_driver capi_driver_b1pci = {
370 .name = "b1pci",
371 .revision = "1.0",
373 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
374 static struct capi_driver capi_driver_b1pciv4 = {
375 .name = "b1pciv4",
376 .revision = "1.0",
378 #endif
380 static int __init b1pci_init(void)
382 char *p;
383 char rev[32];
384 int err;
386 if ((p = strchr(revision, ':')) != 0 && p[1]) {
387 strlcpy(rev, p + 2, 32);
388 if ((p = strchr(rev, '$')) != 0 && p > rev)
389 *(p-1) = 0;
390 } else
391 strcpy(rev, "1.0");
394 err = pci_register_driver(&b1pci_pci_driver);
395 if (!err) {
396 strlcpy(capi_driver_b1pci.revision, rev, 32);
397 register_capi_driver(&capi_driver_b1pci);
398 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
399 strlcpy(capi_driver_b1pciv4.revision, rev, 32);
400 register_capi_driver(&capi_driver_b1pciv4);
401 #endif
402 printk(KERN_INFO "b1pci: revision %s\n", rev);
404 return err;
407 static void __exit b1pci_exit(void)
409 unregister_capi_driver(&capi_driver_b1pci);
410 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
411 unregister_capi_driver(&capi_driver_b1pciv4);
412 #endif
413 pci_unregister_driver(&b1pci_pci_driver);
416 module_init(b1pci_init);
417 module_exit(b1pci_exit);