📄 e1000_main.c
字号:
atomic_set(&adapter->tx_fifo_stall, 0); } } else if (adapter->max_frame_size > ETH_FRAME_LEN + ETHERNET_FCS_SIZE) { /* adjust PBA for jumbo frames */ E1000_WRITE_REG(&adapter->hw, E1000_PBA, pba); /* To maintain wire speed transmits, the Tx FIFO should be * large enough to accommodate two full transmit packets, * rounded up to the next 1KB and expressed in KB. Likewise, * the Rx FIFO should be large enough to accommodate at least * one full receive packet and is similarly rounded up and * expressed in KB. */ pba = E1000_READ_REG(&adapter->hw, E1000_PBA); /* upper 16 bits has Tx packet buffer allocation size in KB */ tx_space = pba >> 16; /* lower 16 bits has Rx packet buffer allocation size in KB */ pba &= 0xffff; /* the tx fifo also stores 16 bytes of information about the tx * but don't include ethernet FCS because hardware appends it */ min_tx_space = (adapter->max_frame_size + sizeof(struct e1000_tx_desc) - ETHERNET_FCS_SIZE) * 2; min_tx_space = ALIGN(min_tx_space, 1024); min_tx_space >>= 10; /* software strips receive CRC, so leave room for it */ min_rx_space = adapter->max_frame_size; min_rx_space = ALIGN(min_rx_space, 1024); min_rx_space >>= 10; /* If current Tx allocation is less than the min Tx FIFO size, * and the min Tx FIFO size is less than the current Rx FIFO * allocation, take space away from current Rx allocation */ if (tx_space < min_tx_space && ((min_tx_space - tx_space) < pba)) { pba = pba - (min_tx_space - tx_space); /* PCI/PCIx hardware has PBA alignment constraints */ switch (mac->type) { case e1000_82545 ... e1000_82546_rev_3: pba &= ~(E1000_PBA_8K - 1); break; default: break; } /* if short on rx space, rx wins and must trump tx * adjustment or use Early Receive if available */ if (pba < min_rx_space) { switch (mac->type) { case e1000_82573: case e1000_ich9lan: /* ERT enabled in e1000_configure_rx */ break; default: pba = min_rx_space; break; } } } } E1000_WRITE_REG(&adapter->hw, E1000_PBA, pba); /* flow control settings */ /* The high water mark must be low enough to fit one full frame * (or the size used for early receive) above it in the Rx FIFO. * Set it to the lower of: * - 90% of the Rx FIFO size, and * - the full Rx FIFO size minus the early receive size (for parts * with ERT support assuming ERT set to E1000_ERT_2048), or * - the full Rx FIFO size minus one full frame */ hwm = min(((pba << 10) * 9 / 10), ((mac->type == e1000_82573 || mac->type == e1000_ich9lan) ? (u16)((pba << 10) - (E1000_ERT_2048 << 3)) : ((pba << 10) - adapter->max_frame_size))); fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */ fc->low_water = fc->high_water - 8; if (mac->type == e1000_80003es2lan) fc->pause_time = 0xFFFF; else fc->pause_time = E1000_FC_PAUSE_TIME; fc->send_xon = 1; fc->type = fc->original_type; /* Allow time for pending master requests to run */ e1000_reset_hw(&adapter->hw); /* For 82573 and ICHx if AMT is enabled, let the firmware know * that the network interface is in control */ if (((adapter->hw.mac.type == e1000_82573) || (adapter->hw.mac.type == e1000_ich8lan) || (adapter->hw.mac.type == e1000_ich9lan)) && e1000_check_mng_mode(&adapter->hw)) e1000_get_hw_control(adapter); if (mac->type >= e1000_82544) E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0); if (e1000_init_hw(&adapter->hw)) DPRINTK(PROBE, ERR, "Hardware Error\n");#ifdef NETIF_F_HW_VLAN_TX e1000_update_mng_vlan(adapter);#endif /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ if (mac->type >= e1000_82544 && mac->type <= e1000_82547_rev_2 && mac->autoneg == 1 && adapter->hw.phy.autoneg_advertised == ADVERTISE_1000_FULL) { u32 ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL); /* clear phy power management bit if we are in gig only mode, * which if enabled will attempt negotiation to 100Mb, which * can cause a loss of link at power off or driver unload */ ctrl &= ~E1000_CTRL_SWDPIN3; E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl); }#if defined(CONFIG_PPC64) || defined(CONFIG_PPC)#define E1000_GCR_DISABLE_TIMEOUT_MECHANISM 0x80000000 if (adapter->hw.mac.type == e1000_82571) { /* work around pSeries hardware by disabling timeouts */ u32 gcr = E1000_READ_REG(&adapter->hw, E1000_GCR); gcr |= E1000_GCR_DISABLE_TIMEOUT_MECHANISM; E1000_WRITE_REG(&adapter->hw, E1000_GCR, gcr); }#endif /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ E1000_WRITE_REG(&adapter->hw, E1000_VET, ETHERNET_IEEE_VLAN_TYPE); e1000_reset_adaptive(&adapter->hw); e1000_get_phy_info(&adapter->hw); if (!adapter->flags.smart_power_down && (mac->type == e1000_82571 || mac->type == e1000_82572)) { u16 phy_data = 0; /* speed up time to link by disabling smart power down, ignore * the return value of this function because there is nothing * different we would do if it failed */ e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); phy_data &= ~IGP02E1000_PM_SPD; e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, phy_data); } e1000_release_manageability(adapter);}/** * e1000_probe - Device Initialization Routine * @pdev: PCI device information struct * @ent: entry in e1000_pci_tbl * * Returns 0 on success, negative on failure * * e1000_probe initializes an adapter identified by a pci_dev structure. * The OS initialization, configuring of the adapter private structure, * and a hardware reset occur. **/static int __devinit e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent){ struct net_device *netdev; struct e1000_adapter *adapter; unsigned long mmio_start, mmio_len; unsigned long flash_start, flash_len; static int cards_found = 0; static int global_quad_port_a = 0; /* global ksp3 port a indication */ int i, err, pci_using_dac; u16 eeprom_data = 0; u16 eeprom_apme_mask = E1000_EEPROM_APME; if ((err = pci_enable_device(pdev))) return err; if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) && !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) { pci_using_dac = 1; } else { if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) && (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) { E1000_ERR("No usable DMA configuration, aborting\n"); goto err_dma; } pci_using_dac = 0; } if ((err = pci_request_regions(pdev, e1000_driver_name))) goto err_pci_reg; pci_set_master(pdev); err = -ENOMEM;#ifdef CONFIG_E1000_MQ netdev = alloc_etherdev(sizeof(struct e1000_adapter) + (sizeof(struct net_device_subqueue) * E1000_MAX_TX_QUEUES));#else netdev = alloc_etherdev(sizeof(struct e1000_adapter));#endif if (!netdev) goto err_alloc_etherdev; SET_MODULE_OWNER(netdev); SET_NETDEV_DEV(netdev, &pdev->dev); pci_set_drvdata(pdev, netdev); adapter = netdev_priv(netdev); adapter->netdev = netdev; adapter->pdev = pdev; adapter->hw.back = adapter; adapter->msg_enable = (1 << debug) - 1; mmio_start = pci_resource_start(pdev, BAR_0); mmio_len = pci_resource_len(pdev, BAR_0); err = -EIO; adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); if (!adapter->hw.hw_addr) goto err_ioremap; for (i = BAR_1; i <= BAR_5; i++) { if (pci_resource_len(pdev, i) == 0) continue; if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { adapter->hw.io_base = pci_resource_start(pdev, i); break; } } netdev->open = &e1000_open; netdev->stop = &e1000_close; netdev->hard_start_xmit = &e1000_xmit_frame;#ifdef CONFIG_E1000_MQ netdev->hard_start_subqueue_xmit = &e1000_subqueue_xmit_frame;#endif netdev->get_stats = &e1000_get_stats; netdev->set_multicast_list = &e1000_set_multi; netdev->set_mac_address = &e1000_set_mac; netdev->change_mtu = &e1000_change_mtu; netdev->do_ioctl = &e1000_ioctl; e1000_set_ethtool_ops(netdev);#ifdef HAVE_TX_TIMEOUT netdev->tx_timeout = &e1000_tx_timeout; netdev->watchdog_timeo = 5 * HZ;#endif#ifdef CONFIG_E1000_NAPI netdev->poll = &e1000_clean; netdev->weight = 64;#endif#ifdef NETIF_F_HW_VLAN_TX netdev->vlan_rx_register = e1000_vlan_rx_register; netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;#endif#ifdef CONFIG_NET_POLL_CONTROLLER netdev->poll_controller = e1000_netpoll;#endif strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); netdev->mem_start = mmio_start; netdev->mem_end = mmio_start + mmio_len; netdev->base_addr = adapter->hw.io_base; adapter->bd_number = cards_found; /* setup the private structure */ if ((err = e1000_sw_init(adapter))) goto err_sw_init; err = -EIO; /* Flash BAR mapping must happen after e1000_sw_init * because it depends on mac.type */ if (((adapter->hw.mac.type == e1000_ich8lan) || (adapter->hw.mac.type == e1000_ich9lan)) && (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { flash_start = pci_resource_start(pdev, 1); flash_len = pci_resource_len(pdev, 1); adapter->hw.flash_address = ioremap(flash_start, flash_len); if (!adapter->hw.flash_address) goto err_flashmap; } if ((err = e1000_init_mac_params(&adapter->hw))) goto err_hw_init; if ((err = e1000_init_nvm_params(&adapter->hw))) goto err_hw_init; if ((err = e1000_init_phy_params(&adapter->hw))) goto err_hw_init; e1000_get_bus_info(&adapter->hw); e1000_init_script_state_82541(&adapter->hw, TRUE); e1000_set_tbi_compatibility_82543(&adapter->hw, TRUE); adapter->hw.phy.autoneg_wait_to_complete = FALSE; adapter->hw.mac.adaptive_ifs = TRUE; /* Copper options */ if (adapter->hw.phy.media_type == e1000_media_type_copper) { adapter->hw.phy.mdix = AUTO_ALL_MODES; adapter->hw.phy.disable_polarity_correction = FALSE; adapter->hw.phy.ms_type = E1000_MASTER_SLAVE; } if (e1000_check_reset_block(&adapter->hw)) DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");#ifdef MAX_SKB_FRAGS if (adapter->hw.mac.type >= e1000_82543) {#ifdef NETIF_F_HW_VLAN_TX netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; if ((adapter->hw.mac.type == e1000_ich8lan) || (adapter->hw.mac.type == e1000_ich9lan)) netdev->features &= ~NETIF_F_HW_VLAN_FILTER;#else netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM;#endif }#ifdef NETIF_F_TSO if ((adapter->hw.mac.type >= e1000_82544) && (adapter->hw.mac.type != e1000_82547)) { adapter->flags.has_tso = 1; netdev->features |= NETIF_F_TSO; }#ifdef NETIF_F_TSO6 if (adapter->hw.mac.type > e1000_82547_rev_2) { adapter->flags.has_tso6 = 1; netdev->features |= NETIF_F_TSO6; }#endif#endif if (pci_using_dac) netdev->features |= NETIF_F_HIGHDMA;#endif#ifdef NETIF_F_LLTX netdev->features |= NETIF_F_LLTX;#endif /* Hardware features, flags and workarounds */ if (adapter->hw.mac.type >= e1000_82571) { adapter->flags.int_assert_auto_mask = 1;#ifdef CONFIG_PCI_MSI adapter->flags.has_msi = 1;#endif adapter->flags.has_manc2h = 1; } if (adapter->hw.mac.type >= e1000_82540) { adapter->flags.has_smbus = 1; adapter->flags.has_intr_moderation = 1; } if (adapter->hw.mac.type == e1000_82543) adapter->flags.bad_tx_carrier_stats_fd = 1; /* In rare occasions, ESB2 systems would end up started without * the RX unit being turned on. */ if (adapter->hw.mac.type == e1000_80003es2lan) adapter->flags.rx_needs_restart = 1; adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); /* before reading the NVM, reset the controller to * put the device in a known good starting state */ e1000_reset_hw(&adapter->hw); /* make sure the NVM is good */ if (e1000_validate_nvm_checksum(&adapter->hw) < 0) { DPRINTK(PROBE, ERR, "The NVM Checksum Is Not Valid\n"); err = -EIO; goto err_eeprom; } /* copy the MAC address out of the NVM */ if (e1000_read_mac_addr(&adapter->hw)) DPRINTK(PROBE, ERR, "NVM Read Error\n"); memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);#ifdef ETHTOOL_GPERMADDR memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); if (!is_valid_ether_addr(netdev->perm_addr)) {#else if (!is_valid_ether_addr(netdev->dev_addr)) {#endif DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); err = -EIO; goto err_eeprom; } init_timer(&adapter->tx_fifo_stall_timer); adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; init_timer(&adapter->watchdog_timer); adapter->watchdog_timer.function = &e1000_watchdog; adapter->watchdog_timer.data = (unsigned long) adapter; init_timer(&adapter->phy_info_timer); adapter->phy_info_timer.function = &e1000_update_phy_info; adapter->phy_info_timer.data = (unsigned long) adapter; INIT_WORK(&adapter->reset_task, e1000_reset_task); INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task); e1000_check_options(adapter);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -