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