Merge git://git.infradead.org/hdrinstall-2.6
[deliverable/linux.git] / drivers / isdn / hardware / eicon / divasmain.c
1 /* $Id: divasmain.c,v 1.55.4.6 2005/02/09 19:28:20 armin Exp $
2 *
3 * Low level driver for Eicon DIVA Server ISDN cards.
4 *
5 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
6 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 */
11
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <asm/uaccess.h>
17 #include <asm/io.h>
18 #include <linux/ioport.h>
19 #include <linux/workqueue.h>
20 #include <linux/pci.h>
21 #include <linux/smp_lock.h>
22 #include <linux/interrupt.h>
23 #include <linux/list.h>
24 #include <linux/poll.h>
25 #include <linux/kmod.h>
26
27 #include "platform.h"
28 #undef ID_MASK
29 #undef N_DATA
30 #include "pc.h"
31 #include "di_defs.h"
32 #include "divasync.h"
33 #include "diva.h"
34 #include "di.h"
35 #include "io.h"
36 #include "xdi_msg.h"
37 #include "xdi_adapter.h"
38 #include "xdi_vers.h"
39 #include "diva_dma.h"
40 #include "diva_pci.h"
41
42 static char *main_revision = "$Revision: 1.55.4.6 $";
43
44 static int major;
45
46 static int dbgmask;
47
48 MODULE_DESCRIPTION("Kernel driver for Eicon DIVA Server cards");
49 MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
50 MODULE_LICENSE("GPL");
51
52 module_param(dbgmask, int, 0);
53 MODULE_PARM_DESC(dbgmask, "initial debug mask");
54
55 static char *DRIVERNAME =
56 "Eicon DIVA Server driver (http://www.melware.net)";
57 static char *DRIVERLNAME = "divas";
58 static char *DEVNAME = "Divas";
59 char *DRIVERRELEASE_DIVAS = "2.0";
60
61 extern irqreturn_t diva_os_irq_wrapper(int irq, void *context,
62 struct pt_regs *regs);
63 extern int create_divas_proc(void);
64 extern void remove_divas_proc(void);
65 extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf);
66 extern int divasfunc_init(int dbgmask);
67 extern void divasfunc_exit(void);
68
69 typedef struct _diva_os_thread_dpc {
70 struct tasklet_struct divas_task;
71 diva_os_soft_isr_t *psoft_isr;
72 } diva_os_thread_dpc_t;
73
74 /* --------------------------------------------------------------------------
75 PCI driver interface section
76 -------------------------------------------------------------------------- */
77 /*
78 vendor, device Vendor and device ID to match (or PCI_ANY_ID)
79 subvendor, Subsystem vendor and device ID to match (or PCI_ANY_ID)
80 subdevice
81 class, Device class to match. The class_mask tells which bits
82 class_mask of the class are honored during the comparison.
83 driver_data Data private to the driver.
84 */
85
86 #if !defined(PCI_DEVICE_ID_EICON_MAESTRAP_2)
87 #define PCI_DEVICE_ID_EICON_MAESTRAP_2 0xE015
88 #endif
89
90 #if !defined(PCI_DEVICE_ID_EICON_4BRI_VOIP)
91 #define PCI_DEVICE_ID_EICON_4BRI_VOIP 0xE016
92 #endif
93
94 #if !defined(PCI_DEVICE_ID_EICON_4BRI_2_VOIP)
95 #define PCI_DEVICE_ID_EICON_4BRI_2_VOIP 0xE017
96 #endif
97
98 #if !defined(PCI_DEVICE_ID_EICON_BRI2M_2)
99 #define PCI_DEVICE_ID_EICON_BRI2M_2 0xE018
100 #endif
101
102 #if !defined(PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP)
103 #define PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP 0xE019
104 #endif
105
106 #if !defined(PCI_DEVICE_ID_EICON_2F)
107 #define PCI_DEVICE_ID_EICON_2F 0xE01A
108 #endif
109
110 #if !defined(PCI_DEVICE_ID_EICON_BRI2M_2_VOIP)
111 #define PCI_DEVICE_ID_EICON_BRI2M_2_VOIP 0xE01B
112 #endif
113
114 /*
115 This table should be sorted by PCI device ID
116 */
117 static struct pci_device_id divas_pci_tbl[] = {
118 /* Diva Server BRI-2M PCI 0xE010 */
119 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRA,
120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_MAESTRA_PCI},
121 /* Diva Server 4BRI-8M PCI 0xE012 */
122 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAQ,
123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_Q_8M_PCI},
124 /* Diva Server 4BRI-8M 2.0 PCI 0xE013 */
125 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAQ_U,
126 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_Q_8M_V2_PCI},
127 /* Diva Server PRI-30M PCI 0xE014 */
128 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP,
129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_P_30M_PCI},
130 /* Diva Server PRI 2.0 adapter 0xE015 */
131 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP_2,
132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_P_30M_V2_PCI},
133 /* Diva Server Voice 4BRI-8M PCI 0xE016 */
134 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_4BRI_VOIP,
135 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_Q_8M_PCI},
136 /* Diva Server Voice 4BRI-8M 2.0 PCI 0xE017 */
137 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_4BRI_2_VOIP,
138 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_Q_8M_V2_PCI},
139 /* Diva Server BRI-2M 2.0 PCI 0xE018 */
140 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_BRI2M_2,
141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_B_2M_V2_PCI},
142 /* Diva Server Voice PRI 2.0 PCI 0xE019 */
143 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_MAESTRAP_2_VOIP,
144 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
145 CARDTYPE_DIVASRV_VOICE_P_30M_V2_PCI},
146 /* Diva Server 2FX 0xE01A */
147 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_2F,
148 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_B_2F_PCI},
149 /* Diva Server Voice BRI-2M 2.0 PCI 0xE01B */
150 {PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_BRI2M_2_VOIP,
151 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CARDTYPE_DIVASRV_VOICE_B_2M_V2_PCI},
152 {0,} /* 0 terminated list. */
153 };
154 MODULE_DEVICE_TABLE(pci, divas_pci_tbl);
155
156 static int divas_init_one(struct pci_dev *pdev,
157 const struct pci_device_id *ent);
158 static void __devexit divas_remove_one(struct pci_dev *pdev);
159
160 static struct pci_driver diva_pci_driver = {
161 .name = "divas",
162 .probe = divas_init_one,
163 .remove = __devexit_p(divas_remove_one),
164 .id_table = divas_pci_tbl,
165 };
166
167 /*********************************************************
168 ** little helper functions
169 *********************************************************/
170 static char *getrev(const char *revision)
171 {
172 char *rev;
173 char *p;
174 if ((p = strchr(revision, ':'))) {
175 rev = p + 2;
176 p = strchr(rev, '$');
177 *--p = 0;
178 } else
179 rev = "1.0";
180 return rev;
181 }
182
183 void diva_log_info(unsigned char *format, ...)
184 {
185 va_list args;
186 unsigned char line[160];
187
188 va_start(args, format);
189 vsprintf(line, format, args);
190 va_end(args);
191
192 printk(KERN_INFO "%s: %s\n", DRIVERLNAME, line);
193 }
194
195 void divas_get_version(char *p)
196 {
197 char tmprev[32];
198
199 strcpy(tmprev, main_revision);
200 sprintf(p, "%s: %s(%s) %s(%s) major=%d\n", DRIVERLNAME, DRIVERRELEASE_DIVAS,
201 getrev(tmprev), diva_xdi_common_code_build, DIVA_BUILD, major);
202 }
203
204 /* --------------------------------------------------------------------------
205 PCI Bus services
206 -------------------------------------------------------------------------- */
207 byte diva_os_get_pci_bus(void *pci_dev_handle)
208 {
209 struct pci_dev *pdev = (struct pci_dev *) pci_dev_handle;
210 return ((byte) pdev->bus->number);
211 }
212
213 byte diva_os_get_pci_func(void *pci_dev_handle)
214 {
215 struct pci_dev *pdev = (struct pci_dev *) pci_dev_handle;
216 return ((byte) pdev->devfn);
217 }
218
219 unsigned long divasa_get_pci_irq(unsigned char bus, unsigned char func,
220 void *pci_dev_handle)
221 {
222 unsigned char irq = 0;
223 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
224
225 irq = dev->irq;
226
227 return ((unsigned long) irq);
228 }
229
230 unsigned long divasa_get_pci_bar(unsigned char bus, unsigned char func,
231 int bar, void *pci_dev_handle)
232 {
233 unsigned long ret = 0;
234 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
235
236 if (bar < 6) {
237 ret = dev->resource[bar].start;
238 }
239
240 DBG_TRC(("GOT BAR[%d]=%08x", bar, ret));
241
242 {
243 unsigned long type = (ret & 0x00000001);
244 if (type & PCI_BASE_ADDRESS_SPACE_IO) {
245 DBG_TRC((" I/O"));
246 ret &= PCI_BASE_ADDRESS_IO_MASK;
247 } else {
248 DBG_TRC((" memory"));
249 ret &= PCI_BASE_ADDRESS_MEM_MASK;
250 }
251 DBG_TRC((" final=%08x", ret));
252 }
253
254 return (ret);
255 }
256
257 void PCIwrite(byte bus, byte func, int offset, void *data, int length,
258 void *pci_dev_handle)
259 {
260 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
261
262 switch (length) {
263 case 1: /* byte */
264 pci_write_config_byte(dev, offset,
265 *(unsigned char *) data);
266 break;
267 case 2: /* word */
268 pci_write_config_word(dev, offset,
269 *(unsigned short *) data);
270 break;
271 case 4: /* dword */
272 pci_write_config_dword(dev, offset,
273 *(unsigned int *) data);
274 break;
275
276 default: /* buffer */
277 if (!(length % 4) && !(length & 0x03)) { /* Copy as dword */
278 dword *p = (dword *) data;
279 length /= 4;
280
281 while (length--) {
282 pci_write_config_dword(dev, offset,
283 *(unsigned int *)
284 p++);
285 }
286 } else { /* copy as byte stream */
287 byte *p = (byte *) data;
288
289 while (length--) {
290 pci_write_config_byte(dev, offset,
291 *(unsigned char *)
292 p++);
293 }
294 }
295 }
296 }
297
298 void PCIread(byte bus, byte func, int offset, void *data, int length,
299 void *pci_dev_handle)
300 {
301 struct pci_dev *dev = (struct pci_dev *) pci_dev_handle;
302
303 switch (length) {
304 case 1: /* byte */
305 pci_read_config_byte(dev, offset, (unsigned char *) data);
306 break;
307 case 2: /* word */
308 pci_read_config_word(dev, offset, (unsigned short *) data);
309 break;
310 case 4: /* dword */
311 pci_read_config_dword(dev, offset, (unsigned int *) data);
312 break;
313
314 default: /* buffer */
315 if (!(length % 4) && !(length & 0x03)) { /* Copy as dword */
316 dword *p = (dword *) data;
317 length /= 4;
318
319 while (length--) {
320 pci_read_config_dword(dev, offset,
321 (unsigned int *)
322 p++);
323 }
324 } else { /* copy as byte stream */
325 byte *p = (byte *) data;
326
327 while (length--) {
328 pci_read_config_byte(dev, offset,
329 (unsigned char *)
330 p++);
331 }
332 }
333 }
334 }
335
336 /*
337 Init map with DMA pages. It is not problem if some allocations fail -
338 the channels that will not get one DMA page will use standard PIO
339 interface
340 */
341 static void *diva_pci_alloc_consistent(struct pci_dev *hwdev,
342 size_t size,
343 dma_addr_t * dma_handle,
344 void **addr_handle)
345 {
346 void *addr = pci_alloc_consistent(hwdev, size, dma_handle);
347
348 *addr_handle = addr;
349
350 return (addr);
351 }
352
353 void diva_init_dma_map(void *hdev,
354 struct _diva_dma_map_entry **ppmap, int nentries)
355 {
356 struct pci_dev *pdev = (struct pci_dev *) hdev;
357 struct _diva_dma_map_entry *pmap =
358 diva_alloc_dma_map(hdev, nentries);
359
360 if (pmap) {
361 int i;
362 dma_addr_t dma_handle;
363 void *cpu_addr;
364 void *addr_handle;
365
366 for (i = 0; i < nentries; i++) {
367 if (!(cpu_addr = diva_pci_alloc_consistent(pdev,
368 PAGE_SIZE,
369 &dma_handle,
370 &addr_handle)))
371 {
372 break;
373 }
374 diva_init_dma_map_entry(pmap, i, cpu_addr,
375 (dword) dma_handle,
376 addr_handle);
377 DBG_TRC(("dma map alloc [%d]=(%08lx:%08x:%08lx)",
378 i, (unsigned long) cpu_addr,
379 (dword) dma_handle,
380 (unsigned long) addr_handle))}
381 }
382
383 *ppmap = pmap;
384 }
385
386 /*
387 Free all contained in the map entries and memory used by the map
388 Should be always called after adapter removal from DIDD array
389 */
390 void diva_free_dma_map(void *hdev, struct _diva_dma_map_entry *pmap)
391 {
392 struct pci_dev *pdev = (struct pci_dev *) hdev;
393 int i;
394 dword phys_addr;
395 void *cpu_addr;
396 dma_addr_t dma_handle;
397 void *addr_handle;
398
399 for (i = 0; (pmap != 0); i++) {
400 diva_get_dma_map_entry(pmap, i, &cpu_addr, &phys_addr);
401 if (!cpu_addr) {
402 break;
403 }
404 addr_handle = diva_get_entry_handle(pmap, i);
405 dma_handle = (dma_addr_t) phys_addr;
406 pci_free_consistent(pdev, PAGE_SIZE, addr_handle,
407 dma_handle);
408 DBG_TRC(("dma map free [%d]=(%08lx:%08x:%08lx)", i,
409 (unsigned long) cpu_addr, (dword) dma_handle,
410 (unsigned long) addr_handle))
411 }
412
413 diva_free_dma_mapping(pmap);
414 }
415
416
417 /*********************************************************
418 ** I/O port utilities
419 *********************************************************/
420
421 int
422 diva_os_register_io_port(void *adapter, int on, unsigned long port,
423 unsigned long length, const char *name, int id)
424 {
425 if (on) {
426 if (!request_region(port, length, name)) {
427 DBG_ERR(("A: I/O: can't register port=%08x", port))
428 return (-1);
429 }
430 } else {
431 release_region(port, length);
432 }
433 return (0);
434 }
435
436 void __iomem *divasa_remap_pci_bar(diva_os_xdi_adapter_t *a, int id, unsigned long bar, unsigned long area_length)
437 {
438 void __iomem *ret = ioremap(bar, area_length);
439 DBG_TRC(("remap(%08x)->%p", bar, ret));
440 return (ret);
441 }
442
443 void divasa_unmap_pci_bar(void __iomem *bar)
444 {
445 if (bar) {
446 iounmap(bar);
447 }
448 }
449
450 /*********************************************************
451 ** I/O port access
452 *********************************************************/
453 byte __inline__ inpp(void __iomem *addr)
454 {
455 return (inb((unsigned long) addr));
456 }
457
458 word __inline__ inppw(void __iomem *addr)
459 {
460 return (inw((unsigned long) addr));
461 }
462
463 void __inline__ inppw_buffer(void __iomem *addr, void *P, int length)
464 {
465 insw((unsigned long) addr, (word *) P, length >> 1);
466 }
467
468 void __inline__ outppw_buffer(void __iomem *addr, void *P, int length)
469 {
470 outsw((unsigned long) addr, (word *) P, length >> 1);
471 }
472
473 void __inline__ outppw(void __iomem *addr, word w)
474 {
475 outw(w, (unsigned long) addr);
476 }
477
478 void __inline__ outpp(void __iomem *addr, word p)
479 {
480 outb(p, (unsigned long) addr);
481 }
482
483 /* --------------------------------------------------------------------------
484 IRQ request / remove
485 -------------------------------------------------------------------------- */
486 int diva_os_register_irq(void *context, byte irq, const char *name)
487 {
488 int result = request_irq(irq, diva_os_irq_wrapper,
489 IRQF_DISABLED | IRQF_SHARED, name, context);
490 return (result);
491 }
492
493 void diva_os_remove_irq(void *context, byte irq)
494 {
495 free_irq(irq, context);
496 }
497
498 /* --------------------------------------------------------------------------
499 DPC framework implementation
500 -------------------------------------------------------------------------- */
501 static void diva_os_dpc_proc(unsigned long context)
502 {
503 diva_os_thread_dpc_t *psoft_isr = (diva_os_thread_dpc_t *) context;
504 diva_os_soft_isr_t *pisr = psoft_isr->psoft_isr;
505
506 (*(pisr->callback)) (pisr, pisr->callback_context);
507 }
508
509 int diva_os_initialize_soft_isr(diva_os_soft_isr_t * psoft_isr,
510 diva_os_soft_isr_callback_t callback,
511 void *callback_context)
512 {
513 diva_os_thread_dpc_t *pdpc;
514
515 pdpc = (diva_os_thread_dpc_t *) diva_os_malloc(0, sizeof(*pdpc));
516 if (!(psoft_isr->object = pdpc)) {
517 return (-1);
518 }
519 memset(pdpc, 0x00, sizeof(*pdpc));
520 psoft_isr->callback = callback;
521 psoft_isr->callback_context = callback_context;
522 pdpc->psoft_isr = psoft_isr;
523 tasklet_init(&pdpc->divas_task, diva_os_dpc_proc, (unsigned long)pdpc);
524
525 return (0);
526 }
527
528 int diva_os_schedule_soft_isr(diva_os_soft_isr_t * psoft_isr)
529 {
530 if (psoft_isr && psoft_isr->object) {
531 diva_os_thread_dpc_t *pdpc =
532 (diva_os_thread_dpc_t *) psoft_isr->object;
533
534 tasklet_schedule(&pdpc->divas_task);
535 }
536
537 return (1);
538 }
539
540 int diva_os_cancel_soft_isr(diva_os_soft_isr_t * psoft_isr)
541 {
542 return (0);
543 }
544
545 void diva_os_remove_soft_isr(diva_os_soft_isr_t * psoft_isr)
546 {
547 if (psoft_isr && psoft_isr->object) {
548 diva_os_thread_dpc_t *pdpc =
549 (diva_os_thread_dpc_t *) psoft_isr->object;
550 void *mem;
551
552 tasklet_kill(&pdpc->divas_task);
553 flush_scheduled_work();
554 mem = psoft_isr->object;
555 psoft_isr->object = NULL;
556 diva_os_free(0, mem);
557 }
558 }
559
560 /*
561 * kernel/user space copy functions
562 */
563 static int
564 xdi_copy_to_user(void *os_handle, void __user *dst, const void *src, int length)
565 {
566 if (copy_to_user(dst, src, length)) {
567 return (-EFAULT);
568 }
569 return (length);
570 }
571
572 static int
573 xdi_copy_from_user(void *os_handle, void *dst, const void __user *src, int length)
574 {
575 if (copy_from_user(dst, src, length)) {
576 return (-EFAULT);
577 }
578 return (length);
579 }
580
581 /*
582 * device node operations
583 */
584 static int divas_open(struct inode *inode, struct file *file)
585 {
586 return (0);
587 }
588
589 static int divas_release(struct inode *inode, struct file *file)
590 {
591 if (file->private_data) {
592 diva_xdi_close_adapter(file->private_data, file);
593 }
594 return (0);
595 }
596
597 static ssize_t divas_write(struct file *file, const char __user *buf,
598 size_t count, loff_t * ppos)
599 {
600 int ret = -EINVAL;
601
602 if (!file->private_data) {
603 file->private_data = diva_xdi_open_adapter(file, buf,
604 count,
605 xdi_copy_from_user);
606 }
607 if (!file->private_data) {
608 return (-ENODEV);
609 }
610
611 ret = diva_xdi_write(file->private_data, file,
612 buf, count, xdi_copy_from_user);
613 switch (ret) {
614 case -1: /* Message should be removed from rx mailbox first */
615 ret = -EBUSY;
616 break;
617 case -2: /* invalid adapter was specified in this call */
618 ret = -ENOMEM;
619 break;
620 case -3:
621 ret = -ENXIO;
622 break;
623 }
624 DBG_TRC(("write: ret %d", ret));
625 return (ret);
626 }
627
628 static ssize_t divas_read(struct file *file, char __user *buf,
629 size_t count, loff_t * ppos)
630 {
631 int ret = -EINVAL;
632
633 if (!file->private_data) {
634 file->private_data = diva_xdi_open_adapter(file, buf,
635 count,
636 xdi_copy_from_user);
637 }
638 if (!file->private_data) {
639 return (-ENODEV);
640 }
641
642 ret = diva_xdi_read(file->private_data, file,
643 buf, count, xdi_copy_to_user);
644 switch (ret) {
645 case -1: /* RX mailbox is empty */
646 ret = -EAGAIN;
647 break;
648 case -2: /* no memory, mailbox was cleared, last command is failed */
649 ret = -ENOMEM;
650 break;
651 case -3: /* can't copy to user, retry */
652 ret = -EFAULT;
653 break;
654 }
655 DBG_TRC(("read: ret %d", ret));
656 return (ret);
657 }
658
659 static unsigned int divas_poll(struct file *file, poll_table * wait)
660 {
661 if (!file->private_data) {
662 return (POLLERR);
663 }
664 return (POLLIN | POLLRDNORM);
665 }
666
667 static struct file_operations divas_fops = {
668 .owner = THIS_MODULE,
669 .llseek = no_llseek,
670 .read = divas_read,
671 .write = divas_write,
672 .poll = divas_poll,
673 .open = divas_open,
674 .release = divas_release
675 };
676
677 static void divas_unregister_chrdev(void)
678 {
679 unregister_chrdev(major, DEVNAME);
680 }
681
682 static int DIVA_INIT_FUNCTION divas_register_chrdev(void)
683 {
684 if ((major = register_chrdev(0, DEVNAME, &divas_fops)) < 0)
685 {
686 printk(KERN_ERR "%s: failed to create /dev entry.\n",
687 DRIVERLNAME);
688 return (0);
689 }
690
691 return (1);
692 }
693
694 /* --------------------------------------------------------------------------
695 PCI driver section
696 -------------------------------------------------------------------------- */
697 static int __devinit divas_init_one(struct pci_dev *pdev,
698 const struct pci_device_id *ent)
699 {
700 void *pdiva = NULL;
701 u8 pci_latency;
702 u8 new_latency = 32;
703
704 DBG_TRC(("%s bus: %08x fn: %08x insertion.\n",
705 CardProperties[ent->driver_data].Name,
706 pdev->bus->number, pdev->devfn))
707 printk(KERN_INFO "%s: %s bus: %08x fn: %08x insertion.\n",
708 DRIVERLNAME, CardProperties[ent->driver_data].Name,
709 pdev->bus->number, pdev->devfn);
710
711 if (pci_enable_device(pdev)) {
712 DBG_TRC(("%s: %s bus: %08x fn: %08x device init failed.\n",
713 DRIVERLNAME,
714 CardProperties[ent->driver_data].Name,
715 pdev->bus->number,
716 pdev->devfn))
717 printk(KERN_ERR
718 "%s: %s bus: %08x fn: %08x device init failed.\n",
719 DRIVERLNAME,
720 CardProperties[ent->driver_data].
721 Name, pdev->bus->number,
722 pdev->devfn);
723 return (-EIO);
724 }
725
726 pci_set_master(pdev);
727
728 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
729 if (!pci_latency) {
730 DBG_TRC(("%s: bus: %08x fn: %08x fix latency.\n",
731 DRIVERLNAME, pdev->bus->number, pdev->devfn))
732 printk(KERN_INFO
733 "%s: bus: %08x fn: %08x fix latency.\n",
734 DRIVERLNAME, pdev->bus->number, pdev->devfn);
735 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
736 }
737
738 if (!(pdiva = diva_driver_add_card(pdev, ent->driver_data))) {
739 DBG_TRC(("%s: %s bus: %08x fn: %08x card init failed.\n",
740 DRIVERLNAME,
741 CardProperties[ent->driver_data].Name,
742 pdev->bus->number,
743 pdev->devfn))
744 printk(KERN_ERR
745 "%s: %s bus: %08x fn: %08x card init failed.\n",
746 DRIVERLNAME,
747 CardProperties[ent->driver_data].
748 Name, pdev->bus->number,
749 pdev->devfn);
750 return (-EIO);
751 }
752
753 pci_set_drvdata(pdev, pdiva);
754
755 return (0);
756 }
757
758 static void __devexit divas_remove_one(struct pci_dev *pdev)
759 {
760 void *pdiva = pci_get_drvdata(pdev);
761
762 DBG_TRC(("bus: %08x fn: %08x removal.\n",
763 pdev->bus->number, pdev->devfn))
764 printk(KERN_INFO "%s: bus: %08x fn: %08x removal.\n",
765 DRIVERLNAME, pdev->bus->number, pdev->devfn);
766
767 if (pdiva) {
768 diva_driver_remove_card(pdiva);
769 }
770
771 }
772
773 /* --------------------------------------------------------------------------
774 Driver Load / Startup
775 -------------------------------------------------------------------------- */
776 static int DIVA_INIT_FUNCTION divas_init(void)
777 {
778 char tmprev[50];
779 int ret = 0;
780
781 printk(KERN_INFO "%s\n", DRIVERNAME);
782 printk(KERN_INFO "%s: Rel:%s Rev:", DRIVERLNAME, DRIVERRELEASE_DIVAS);
783 strcpy(tmprev, main_revision);
784 printk("%s Build: %s(%s)\n", getrev(tmprev),
785 diva_xdi_common_code_build, DIVA_BUILD);
786 printk(KERN_INFO "%s: support for: ", DRIVERLNAME);
787 #ifdef CONFIG_ISDN_DIVAS_BRIPCI
788 printk("BRI/PCI ");
789 #endif
790 #ifdef CONFIG_ISDN_DIVAS_PRIPCI
791 printk("PRI/PCI ");
792 #endif
793 printk("adapters\n");
794
795 if (!divasfunc_init(dbgmask)) {
796 printk(KERN_ERR "%s: failed to connect to DIDD.\n",
797 DRIVERLNAME);
798 ret = -EIO;
799 goto out;
800 }
801
802 if (!divas_register_chrdev()) {
803 #ifdef MODULE
804 divasfunc_exit();
805 #endif
806 ret = -EIO;
807 goto out;
808 }
809
810 if (!create_divas_proc()) {
811 #ifdef MODULE
812 remove_divas_proc();
813 divas_unregister_chrdev();
814 divasfunc_exit();
815 #endif
816 printk(KERN_ERR "%s: failed to create proc entry.\n",
817 DRIVERLNAME);
818 ret = -EIO;
819 goto out;
820 }
821
822 if ((ret = pci_register_driver(&diva_pci_driver))) {
823 #ifdef MODULE
824 remove_divas_proc();
825 divas_unregister_chrdev();
826 divasfunc_exit();
827 #endif
828 printk(KERN_ERR "%s: failed to init pci driver.\n",
829 DRIVERLNAME);
830 goto out;
831 }
832 printk(KERN_INFO "%s: started with major %d\n", DRIVERLNAME, major);
833
834 out:
835 return (ret);
836 }
837
838 /* --------------------------------------------------------------------------
839 Driver Unload
840 -------------------------------------------------------------------------- */
841 static void DIVA_EXIT_FUNCTION divas_exit(void)
842 {
843 pci_unregister_driver(&diva_pci_driver);
844 remove_divas_proc();
845 divas_unregister_chrdev();
846 divasfunc_exit();
847
848 printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);
849 }
850
851 module_init(divas_init);
852 module_exit(divas_exit);
This page took 0.049517 seconds and 6 git commands to generate.