📄 e100_main.c
字号:
e100_wait_scb(struct e100_private *bdp){ int i; /* loop on the scb for a few times */ for (i = 0; i < 100; i++) { if (!readb(&bdp->scb->scb_cmd_low)) return true; cpu_relax(); } /* it didn't work. do it the slow way using udelay()s */ for (i = 0; i < E100_MAX_SCB_WAIT; i++) { if (!readb(&bdp->scb->scb_cmd_low)) return true; cpu_relax(); udelay(1); } return false;}/** * e100_wait_exec_simple - issue a command * @bdp: atapter's private data struct * @scb_cmd_low: the command that is to be issued * * This general routine will issue a command to the e100 after waiting for * the previous command to finish. * * Returns: * true if the command was issued to the chip successfully * false if the command was not issued to the chip */inline unsigned chare100_wait_exec_simple(struct e100_private *bdp, u8 scb_cmd_low){ if (!e100_wait_scb(bdp)) { printk(KERN_DEBUG "e100: %s: e100_wait_exec_simple: failed\n", bdp->device->name); return false; } e100_exec_cmd(bdp, scb_cmd_low); return true;}voide100_exec_cmplx(struct e100_private *bdp, u32 phys_addr, u8 cmd){ writel(phys_addr, &(bdp->scb->scb_gen_ptr)); readw(&(bdp->scb->scb_status)); /* flushes last write, read-safe */ e100_exec_cmd(bdp, cmd);}unsigned chare100_wait_exec_cmplx(struct e100_private *bdp, u32 phys_addr, u8 cmd){ if (!e100_wait_scb(bdp)) { return false; } e100_exec_cmplx(bdp, phys_addr, cmd); return true;}inline u8e100_wait_cus_idle(struct e100_private *bdp){ int i; /* loop on the scb for a few times */ for (i = 0; i < 100; i++) { if (((readw(&(bdp->scb->scb_status)) & SCB_CUS_MASK) != SCB_CUS_ACTIVE)) { return true; } cpu_relax(); } for (i = 0; i < E100_MAX_CU_IDLE_WAIT; i++) { if (((readw(&(bdp->scb->scb_status)) & SCB_CUS_MASK) != SCB_CUS_ACTIVE)) { return true; } cpu_relax(); udelay(1); } return false;}/** * e100_dis_intr - disable interrupts * @bdp: atapter's private data struct * * This routine disables interrupts at the hardware, by setting * the M (mask) bit in the adapter's CSR SCB command word. */static inline voide100_dis_intr(struct e100_private *bdp){ /* Disable interrupts on our PCI board by setting the mask bit */ writeb(SCB_INT_MASK, &bdp->scb->scb_cmd_hi); readw(&(bdp->scb->scb_status)); /* flushes last write, read-safe */}/** * e100_set_intr_mask - set interrupts * @bdp: atapter's private data struct * * This routine sets interrupts at the hardware, by resetting * the M (mask) bit in the adapter's CSR SCB command word */static inline voide100_set_intr_mask(struct e100_private *bdp){ writeb(bdp->intr_mask, &bdp->scb->scb_cmd_hi); readw(&(bdp->scb->scb_status)); /* flushes last write, read-safe */}static inline voide100_trigger_SWI(struct e100_private *bdp){ /* Trigger interrupt on our PCI board by asserting SWI bit */ writeb(SCB_SOFT_INT, &bdp->scb->scb_cmd_hi); readw(&(bdp->scb->scb_status)); /* flushes last write, read-safe */}static int __devinite100_found1(struct pci_dev *pcid, const struct pci_device_id *ent){ static int first_time = true; struct net_device *dev = NULL; struct e100_private *bdp = NULL; int rc = 0; u16 cal_checksum, read_checksum;#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4) dev = init_etherdev(NULL, sizeof (struct e100_private));#else dev = alloc_etherdev(sizeof (struct e100_private));#endif if (dev == NULL) { printk(KERN_ERR "e100: Not able to alloc etherdev struct\n"); rc = -ENODEV; goto out; } SET_MODULE_OWNER(dev); if (first_time) { first_time = false; printk(KERN_NOTICE "%s - version %s\n", e100_full_driver_name, e100_driver_version); printk(KERN_NOTICE "%s\n", e100_copyright); printk(KERN_NOTICE "\n");#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) INIT_LIST_HEAD(&e100_nic_list);#endif } bdp = dev->priv; bdp->pdev = pcid; bdp->device = dev; pci_set_drvdata(pcid, dev); if ((rc = e100_alloc_space(bdp)) != 0) { goto err_dev; } bdp->flags = 0; bdp->ifs_state = 0; bdp->ifs_value = 0; bdp->scb = 0; init_timer(&bdp->nontx_timer_id); bdp->nontx_timer_id.data = (unsigned long) bdp; bdp->nontx_timer_id.function = (void *) &e100_non_tx_background; INIT_LIST_HEAD(&(bdp->non_tx_cmd_list)); bdp->non_tx_command_state = E100_NON_TX_IDLE; init_timer(&bdp->watchdog_timer); bdp->watchdog_timer.data = (unsigned long) dev; bdp->watchdog_timer.function = (void *) &e100_watchdog; init_timer(&bdp->hwi_timer); bdp->hwi_timer.data = (unsigned long) dev; bdp->hwi_timer.function = (void *) &e100_do_hwi; if ((rc = e100_pci_setup(pcid, bdp)) != 0) { goto err_dealloc; } if (((bdp->pdev->device > 0x1030) && (bdp->pdev->device < 0x103F)) || (bdp->pdev->device == 0x2449) || (bdp->pdev->device == 0x2459) || (bdp->pdev->device == 0x245D)) { bdp->rev_id = D101MA_REV_ID; /* workaround for ICH3 */ bdp->flags |= IS_ICH; } if (bdp->rev_id == 0xff) bdp->rev_id = 1; if ((u8) bdp->rev_id >= D101A4_REV_ID) bdp->flags |= IS_BACHELOR; if ((u8) bdp->rev_id >= D102_REV_ID) { bdp->flags |= USE_IPCB; bdp->rfd_size = 32; } else { bdp->rfd_size = 16; } e100_check_options(e100nics, bdp); if (!e100_init(bdp)) { printk(KERN_ERR "e100: Failed to initialize, instance #%d\n", e100nics); rc = -ENODEV; goto err_pci; } /* Check if checksum is valid */ cal_checksum = e100_eeprom_calculate_chksum(bdp); read_checksum = e100_eeprom_read(bdp, (bdp->eeprom_size - 1)); if (cal_checksum != read_checksum) { printk(KERN_ERR "e100: Corrupted EERPROM on instance #%d\n", e100nics); rc = -ENODEV; goto err_pci; } dev->irq = pcid->irq; dev->open = &e100_open; dev->hard_start_xmit = &e100_xmit_frame; dev->stop = &e100_close; dev->change_mtu = &e100_change_mtu; dev->get_stats = &e100_get_stats; dev->set_multicast_list = &e100_set_multi; dev->set_mac_address = &e100_set_mac; dev->do_ioctl = &e100_ioctl;#ifdef MAX_SKB_FRAGS if (bdp->flags & USE_IPCB) { dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM; }#endif e100nics++;#ifdef SIOCETHTOOL e100_get_speed_duplex_caps(bdp);#endif /*SIOCETHTOOL */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4) if ((rc = register_netdev(dev)) != 0) { goto err_pci; }#endif bdp->device_type = ent->driver_data; printk(KERN_NOTICE "e100: %s: %s\n", bdp->device->name, e100_get_brand_msg(bdp)); e100_print_brd_conf(bdp); bdp->id_string = e100_get_brand_msg(bdp); e100_get_mdix_status(bdp); if (netif_carrier_ok(bdp->device)) bdp->cable_status = "Cable OK"; else { if (bdp->rev_id < D102_REV_ID) bdp->cable_status = "Not supported"; else bdp->cable_status = "Not available"; } if (e100_create_proc_subdir(bdp) < 0) { printk(KERN_ERR "e100: Failed to create proc dir for %s\n", bdp->device->name); } /* Disabling all WOLs as initialization */ bdp->wolsupported = bdp->wolopts = 0; if (bdp->rev_id >= D101A4_REV_ID) { bdp->wolsupported = WAKE_PHY | WAKE_MAGIC; if (bdp->rev_id >= D101MA_REV_ID) bdp->wolsupported |= WAKE_UCAST | WAKE_ARP; bdp->wolopts = WAKE_MAGIC; }#ifdef STB_WA if (bdp->rev_id >= D101MA_REV_ID) { u16 id_reg; id_reg = e100_eeprom_read(bdp, EEPROM_ID_WORD); if (id_reg & (0x02)) { id_reg &= ((u16) (~0x02)); e100_eeprom_write_block(bdp, EEPROM_ID_WORD, &id_reg, 1); printk(KERN_NOTICE "e100: %s Changed the eeprom values\n", dev->name); printk(KERN_NOTICE "e100: for sane operation, " "a reboot is required\n"); } }#endif printk(KERN_NOTICE "\n"); goto out;err_pci: iounmap(bdp->scb); pci_release_regions(pcid); pci_disable_device(pcid);err_dealloc: e100_dealloc_space(bdp);err_dev:#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4) unregister_netdev(dev);#endif pci_set_drvdata(pcid, NULL); kfree(dev);out: return rc;}/** * e100_clear_structs - free resources * @dev: adapter's net_device struct * * Free all device specific structs, unmap i/o address, etc. */static void __devexite100_clear_structs(struct net_device *dev){ struct e100_private *bdp = dev->priv; iounmap(bdp->scb); pci_release_regions(bdp->pdev); pci_disable_device(bdp->pdev); e100_dealloc_space(bdp); pci_set_drvdata(bdp->pdev, NULL); kfree(dev);}static void __devexite100_remove1(struct pci_dev *pcid){ struct net_device *dev; struct e100_private *bdp; if (!(dev = (struct net_device *) pci_get_drvdata(pcid))) return; bdp = dev->priv; unregister_netdev(dev); e100_remove_proc_subdir(bdp); e100_sw_reset(bdp, PORT_SELECTIVE_RESET); if (bdp->non_tx_command_state != E100_NON_TX_IDLE) { del_timer_sync(&bdp->nontx_timer_id); e100_free_nontx_list(bdp); bdp->non_tx_command_state = E100_NON_TX_IDLE; } e100_clear_structs(dev); --e100nics;}MODULE_DEVICE_TABLE(pci, e100_id_table);static struct pci_driver e100_driver = { name: "e100", id_table: e100_id_table, probe: e100_found1, remove: __devexit_p(e100_remove1),#ifdef CONFIG_PM suspend: e100_suspend, resume: e100_resume,#endif};#ifdef E100_IA64_DMA_FIXstatic int non_DMA32_memory_present;#endifstatic int __inite100_init_module(void){ int ret;#ifdef E100_IA64_DMA_FIX struct sysinfo si; si_meminfo(&si); if (si.totalram >= (0x100000000UL) / PAGE_SIZE) { non_DMA32_memory_present = 1; } else { non_DMA32_memory_present = 0; }#endif ret = pci_module_init(&e100_driver); if(ret >= 0) register_reboot_notifier(&e100_notifier); return ret;}static void __exite100_cleanup_module(void){ unregister_reboot_notifier(&e100_notifier); pci_unregister_driver(&e100_driver);}module_init(e100_init_module);module_exit(e100_cleanup_module);/** * e100_check_options - check command line options * @board: board number * @bdp: atapter's private data struct * * This routine does range checking on command-line options */void __devinite100_check_options(int board, struct e100_private *bdp){ if (board >= E100_MAX_NIC) { printk(KERN_NOTICE "e100: No configuration available for board #%d\n", board); printk(KERN_NOTICE "e100: Using defaults for all values\n"); board = E100_MAX_NIC; } e100_set_int_option(&(bdp->params.TxDescriptors), TxDescriptors[board], E100_MIN_TCB, E100_MAX_TCB, E100_DEFAULT_TCB, "TxDescriptor count"); e100_set_int_option(&(bdp->params.RxDescriptors), RxDescriptors[board], E100_MIN_RFD, E100_MAX_RFD, E100_DEFAULT_RFD, "RxDescriptor count"); e100_set_int_option(&(bdp->params.e100_speed_duplex), e100_speed_duplex[board], 0, 4, E100_DEFAULT_SPEED_DUPLEX, "speed/duplex mode"); e100_set_int_option(&(bdp->params.ber), ber[board], 0, ZLOCK_MAX_ERRORS, E100_DEFAULT_BER, "Bit Error Rate count"); e100_set_bool_option(bdp, XsumRX[board], PRM_XSUMRX, E100_DEFAULT_XSUM, "XsumRX value"); /* Default ucode value depended on controller revision */ if (bdp->rev_id >= D101MA_REV_ID) { e100_set_bool_option(bdp, ucode[board], PRM_UCODE, E100_DEFAULT_UCODE, "ucode value"); } else { e100_set_bool_option(bdp, ucode[board], PRM_UCODE, false, "ucode value"); } e100_set_bool_option(bdp, flow_control[board], PRM_FC, E100_DEFAULT_FC, "flow control value"); e100_set_bool_option(bdp, IFS[board], PRM_IFS, E100_DEFAULT_IFS, "IFS value"); e100_set_bool_option(bdp, BundleSmallFr[board], PRM_BUNDLE_SMALL, E100_DEFAULT_BUNDLE_SMALL_FR, "CPU saver bundle small frames value"); e100_set_int_option(&(bdp->params.IntDelay), IntDelay[board], 0x0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -