📄 sdladrv.c
字号:
return 0; _OUTB(port, 0x04); /* set bit 2 */ for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if (_INB(port) != 0xFC) /* verify */ return 0; /* Reset adapter */ _OUTB(port, 0); return 1;}/*============================================================================ * Detect s503 adapter. * Following tests are used to verify adapter presence: * 1. All registers other than status (BASE) should read 0xFF. * 2. After writing 0 to control register (BASE), status register (BASE) * should read 11110000b. * 3. After writing 00000100b (set bit 2) to control register (BASE), * status register should read 11110010b. * Return 1 if detected o.k. or 0 if failed. * Note: This test is destructive! Adapter will be left in shutdown * state after the test. */static int detect_s503 (int port){ int i, j; if (!get_option_index(s503_port_options, port)) return 0; for (j = 1; j < SDLA_MAXIORANGE; ++j) { if (_INB(port + j) != 0xFF) return 0; for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ } _OUTB(port, 0); /* reset control reg.*/ for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if (_INB(port) != 0xF0) /* read status */ return 0; _OUTB(port, 0x04); /* set bit 2 */ for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if (_INB(port) != 0xF2) /* verify */ return 0; /* Reset adapter */ _OUTB(port, 0); return 1;}/*============================================================================ * Detect s507 adapter. * Following tests are used to detect s507 adapter: * 1. All ports should read the same value. * 2. After writing 0x00 to control register, status register should read * ?011000?b. * 3. After writing 0x01 to control register, status register should read * ?011001?b. * Return 1 if detected o.k. or 0 if failed. * Note: This test is destructive! Adapter will be left in shutdown * state after the test. */static int detect_s507 (int port){ int tmp, i, j; if (!get_option_index(s508_port_options, port)) return 0; tmp = _INB(port); for (j = 1; j < S507_IORANGE; ++j) { if (_INB(port + j) != tmp) return 0; for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ } _OUTB(port, 0x00); for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if ((_INB(port) & 0x7E) != 0x30) return 0; _OUTB(port, 0x01); for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if ((_INB(port) & 0x7E) != 0x32) return 0; /* Reset adapter */ _OUTB(port, 0x00); return 1;}/*============================================================================ * Detect s508 adapter. * Following tests are used to detect s508 adapter: * 1. After writing 0x00 to control register, status register should read * ??000000b. * 2. After writing 0x10 to control register, status register should read * ??010000b * Return 1 if detected o.k. or 0 if failed. * Note: This test is destructive! Adapter will be left in shutdown * state after the test. */static int detect_s508 (int port){ int i; if (!get_option_index(s508_port_options, port)) return 0; _OUTB(port, 0x00); for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if ((_INB(port + 1) & 0x3F) != 0x00) return 0; _OUTB(port, 0x10); for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if ((_INB(port + 1) & 0x3F) != 0x10) return 0; /* Reset adapter */ _OUTB(port, 0x00); return 1;}/*============================================================================ * Detect s514 PCI adapter. * Return 1 if detected o.k. or 0 if failed. * Note: This test is destructive! Adapter will be left in shutdown * state after the test. */static int detect_s514 (sdlahw_t* hw){ unsigned char CPU_no, slot_no, auto_slot_cfg; int number_S514_cards = 0; u32 S514_mem_base_addr = 0; u32 ut_u32;#if defined(LINUX_2_1) || defined(LINUX_2_4) struct pci_dev *pci_dev;#else u8 ut_u8;#endif#ifdef CONFIG_PCI#if defined(LINUX_2_1) || defined(LINUX_2_4) if(!pci_present())#else if(!pcibios_present())#endif { printk(KERN_INFO "%s: PCI BIOS not present!\n", modname); return 0; }#else printk(KERN_INFO "%s: Linux not compiled for PCI usage!\n", modname); return 0;#endif /* The 'setup()' procedure in 'sdlamain.c' passes the CPU number and the slot number defined in 'router.conf' via the 'port' definition. */ CPU_no = hw->S514_cpu_no[0]; slot_no = hw->S514_slot_no; auto_slot_cfg = hw->auto_pci_cfg; if (auto_slot_cfg){ printk(KERN_INFO "%s: srch... S514 card, CPU %c, Slot=Auto\n", modname, CPU_no); }else{ printk(KERN_INFO "%s: srch... S514 card, CPU %c, Slot #%d\n", modname, CPU_no, slot_no); } /* check to see that CPU A or B has been selected in 'router.conf' */ switch(CPU_no) { case S514_CPU_A: case S514_CPU_B: break; default: printk(KERN_INFO "%s: S514 CPU definition invalid.\n", modname); printk(KERN_INFO "Must be 'A' or 'B'\n"); return 0; } number_S514_cards = find_s514_adapter(hw, 0); if(!number_S514_cards) return 0; /* we are using a single S514 adapter with a slot of 0 so re-read the */ /* location of this adapter */ if((number_S514_cards == 1) && auto_slot_cfg) { number_S514_cards = find_s514_adapter(hw, 1); if(!number_S514_cards) { printk(KERN_INFO "%s: Error finding PCI card\n", modname); return 0; } } #if defined(LINUX_2_4) pci_dev = hw->pci_dev; /* read the physical memory base address */ S514_mem_base_addr = (CPU_no == S514_CPU_A) ? (pci_dev->resource[1].start) : (pci_dev->resource[2].start); #elif defined (LINUX_2_1) pci_dev = hw->pci_dev; /* read the physical memory base address */ S514_mem_base_addr = (CPU_no == S514_CPU_A) ? (pci_dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK) : (pci_dev->base_address[2] & PCI_BASE_ADDRESS_MEM_MASK); #else pcibios_read_config_dword(hw->pci_bus, hw->pci_dev_func, (CPU_no == S514_CPU_A) ? PCI_MEM_BASE0_DWORD : PCI_MEM_BASE1_DWORD, &S514_mem_base_addr); #endif printk(KERN_INFO "%s: S514 PCI memory at 0x%X\n", modname, S514_mem_base_addr); if(!S514_mem_base_addr) { if(CPU_no == S514_CPU_B) printk(KERN_INFO "%s: CPU #B not present on the card\n", modname); else printk(KERN_INFO "%s: No PCI memory allocated to card\n", modname); return 0; } /* enable the PCI memory */#if defined(LINUX_2_1) || defined(LINUX_2_4) pci_read_config_dword(pci_dev, (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD, &ut_u32); pci_write_config_dword(pci_dev, (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD, (ut_u32 | PCI_MEMORY_ENABLE));#else pcibios_read_config_dword(hw->pci_bus, hw->pci_dev_func, (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD, &ut_u32); pcibios_write_config_dword(hw->pci_bus, hw->pci_dev_func, (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD, (ut_u32 | PCI_MEMORY_ENABLE));#endif /* check the IRQ allocated and enable IRQ usage */#if defined(LINUX_2_1) || defined(LINUX_2_4) if(!(hw->irq = pci_dev->irq)) { printk(KERN_INFO "%s: IRQ not allocated to S514 adapter\n", modname); return 0; } /* BUG FIX : Mar 6 2000 * On a initial loading of the card, we must check * and clear PCI interrupt bits, due to a reset * problem on some other boards. i.e. An interrupt * might be pending, even after system bootup, * in which case, when starting wanrouter the machine * would crash. */ if (init_pci_slot(hw)) return 0; pci_read_config_dword(pci_dev, PCI_INT_CONFIG, &ut_u32); ut_u32 |= (CPU_no == S514_CPU_A) ? PCI_ENABLE_IRQ_CPU_A : PCI_ENABLE_IRQ_CPU_B; pci_write_config_dword(pci_dev, PCI_INT_CONFIG, ut_u32);#else /* the INTPIN must not be 0 - if it is, then the S514 adapter is not */ /* configured for IRQ usage */ pcibios_read_config_byte(hw->pci_bus, hw->pci_dev_func, PCI_INT_PIN_BYTE, &ut_u8); if(!ut_u8) { printk(KERN_INFO "%s: invalid setting for INTPIN on S514 card\n", modname); printk(KERN_INFO "Please contact your Sangoma representative\n"); return 0; } pcibios_read_config_byte(hw->pci_bus, hw->pci_dev_func, PCI_INT_LINE_BYTE, (unsigned char *)&hw->irq); if(hw->irq == PCI_IRQ_NOT_ALLOCATED) { printk(KERN_INFO "%s: IRQ not allocated to S514 adapter\n", modname); return 0; } pcibios_read_config_dword(hw->pci_bus, hw->pci_dev_func, PCI_INT_CONFIG, &ut_u32); ut_u32 |= (CPU_no == S514_CPU_A) ? PCI_ENABLE_IRQ_CPU_A : PCI_ENABLE_IRQ_CPU_B; pcibios_write_config_dword(hw->pci_bus, hw->pci_dev_func, PCI_INT_CONFIG, ut_u32);#endif printk(KERN_INFO "%s: IRQ %d allocated to the S514 card\n", modname, hw->irq); /* map the physical PCI memory to virtual memory */ (void *)hw->dpmbase = ioremap((unsigned long)S514_mem_base_addr, (unsigned long)MAX_SIZEOF_S514_MEMORY); /* map the physical control register memory to virtual memory */ (void *)hw->vector = ioremap( (unsigned long)(S514_mem_base_addr + S514_CTRL_REG_BYTE), (unsigned long)16); if(!hw->dpmbase || !hw->vector) { printk(KERN_INFO "%s: PCI virtual memory allocation failed\n", modname); return 0; } /* halt the adapter */ writeb (S514_CPU_HALT, hw->vector); return 1;}/*============================================================================ * Find the S514 PCI adapter in the PCI bus. * Return the number of S514 adapters found (0 if no adapter found). */static int find_s514_adapter(sdlahw_t* hw, char find_first_S514_card){ unsigned char slot_no; int number_S514_cards = 0; char S514_found_in_slot = 0; u16 PCI_subsys_vendor;#if defined(LINUX_2_1) || defined(LINUX_2_4) struct pci_dev *pci_dev = NULL;#else int pci_index;#endif slot_no = hw->S514_slot_no; #if defined(LINUX_2_1) || defined(LINUX_2_4) while ((pci_dev = pci_find_device(V3_VENDOR_ID, V3_DEVICE_ID, pci_dev)) != NULL) { pci_read_config_word(pci_dev, PCI_SUBSYS_VENDOR_WORD, &PCI_subsys_vendor); if(PCI_subsys_vendor != SANGOMA_SUBSYS_VENDOR) continue; hw->pci_dev = pci_dev; if(find_first_S514_card) return(1); number_S514_cards ++; printk(KERN_INFO "%s: S514 card found, slot #%d (devfn 0x%X)\n", modname, ((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK), pci_dev->devfn); if (hw->auto_pci_cfg){ hw->S514_slot_no = ((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK); slot_no = hw->S514_slot_no; }else if (((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK) == slot_no){ S514_found_in_slot = 1; break; } }#else //LINUX VERSION 2.0.X for (pci_index = 0; pci_index < MAX_S514_CARDS; pci_index ++) { if (pcibios_find_device(V3_VENDOR_ID, V3_DEVICE_ID, pci_index, &hw->pci_bus, &hw->pci_dev_func)!=PCIBIOS_SUCCESSFUL) { break; } pcibios_read_config_word(hw->pci_bus, hw->pci_dev_func, PCI_SUBSYS_VENDOR_WORD, &PCI_subsys_vendor); if (PCI_subsys_vendor != SANGOMA_SUBSYS_VENDOR) continue; if (find_first_S514_card) return(1); number_S514_cards ++; printk(KERN_INFO "%s: S514 card found, bus #%d, slot #%d\n", modname, hw->pci_bus, ((hw->pci_dev_func >> 3) & PCI_DEV_SLOT_MASK)); if (hw->auto_pci_cfg){ hw->S514_slot_no = ((hw->pci_dev_func >> 3) & PCI_DEV_SLOT_MASK) slot_no = hw->S514_slot_no; }else if (((hw->pci_dev_func >> 3) & PCI_DEV_SLOT_MASK) == slot_no) { S514_found_in_slot = 1; break; } }#endif /* if no S514 adapter has been found, then exit */ if (!number_S514_cards) { printk(KERN_INFO "%s: Error, no S514 adapters found\n", modname); return 0; } /* if more than one S514 card has been found, then the user must have */ /* defined a slot number so that the correct adapter is used */ else if ((number_S514_cards > 1) && hw->auto_pci_cfg) { printk(KERN_INFO "%s: Error, PCI Slot autodetect Failed! \n" "%s: More than one S514 adapter found.\n" "%s: Disable the Autodetect feature and supply\n" "%s: the PCISLOT numbers for each card.\n", modname,modname,modname,modname); return 0; } /* if the user has specified a slot number and the S514 adapter has */ /* not been found in that slot, then exit */ else if (!hw->auto_pci_cfg && !S514_found_in_slot) { printk(KERN_INFO "%s: Error, S514 card not found in specified slot #%d\n", modname, slot_no); return 0; } return (number_S514_cards);}/******* Miscellaneous ******************************************************//*============================================================================ * Calibrate SDLA memory access delay. * Count number of idle loops made within 1 second and then calculate the * number of loops that should be made to achive desired delay. */static int calibrate_delay (int mks){ unsigned int delay; unsigned long stop; for (delay = 0, stop = SYSTEM_TICK + HZ; SYSTEM_TICK < stop; ++delay); return (delay/(1000000L/mks) + 1);}/*============================================================================ * Get option's index into the options list. * Return option's index (1 .. N) or zero if option is invalid. */static int get_option_index (unsigned* optlist, unsigned optval){ int i; f
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -