📄 e1000_main.c
字号:
free_irq(adapter->pdev->irq, netdev);#ifdef CONFIG_PCI_MSI if (adapter->flags.msi_enabled) { pci_disable_msi(adapter->pdev); adapter->flags.msi_enabled = 0; }#endif}/** * e1000_irq_disable - Mask off interrupt generation on the NIC * @adapter: board private structure **/static void e1000_irq_disable(struct e1000_adapter *adapter){ atomic_inc(&adapter->irq_sem); E1000_WRITE_REG(&adapter->hw, E1000_IMC, ~0); E1000_WRITE_FLUSH(&adapter->hw); synchronize_irq(adapter->pdev->irq);}/** * e1000_irq_enable - Enable default interrupt generation settings * @adapter: board private structure **/static void e1000_irq_enable(struct e1000_adapter *adapter){ if (likely(atomic_dec_and_test(&adapter->irq_sem))) { E1000_WRITE_REG(&adapter->hw, E1000_IMS, IMS_ENABLE_MASK); E1000_WRITE_FLUSH(&adapter->hw); }}#ifdef NETIF_F_HW_VLAN_TXstatic void e1000_update_mng_vlan(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; u16 vid = adapter->hw.mng_cookie.vlan_id; u16 old_vid = adapter->mng_vlan_id; if (adapter->vlgrp) { if (!vlan_group_get_device(adapter->vlgrp, vid)) { if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { e1000_vlan_rx_add_vid(netdev, vid); adapter->mng_vlan_id = vid; } else { adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; } if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid) && !vlan_group_get_device(adapter->vlgrp, old_vid)) e1000_vlan_rx_kill_vid(netdev, old_vid); } else { adapter->mng_vlan_id = vid; } }}#endif/** * e1000_release_hw_control - release control of the h/w to f/w * @adapter: address of board private structure * * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that the * driver is no longer loaded. For AMT version (only with 82573) i * of the f/w this means that the network i/f is closed. * **/static void e1000_release_hw_control(struct e1000_adapter *adapter){ u32 ctrl_ext; u32 swsm; /* Let firmware taken over control of h/w */ switch (adapter->hw.mac.type) { case e1000_82573: swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM); E1000_WRITE_REG(&adapter->hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD); break; case e1000_82571: case e1000_82572: case e1000_80003es2lan: case e1000_ich8lan: case e1000_ich9lan: ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); break; default: break; }}/** * e1000_get_hw_control - get control of the h/w from f/w * @adapter: address of board private structure * * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. * For ASF and Pass Through versions of f/w this means that * the driver is loaded. For AMT version (only with 82573) * of the f/w this means that the network i/f is open. * **/static void e1000_get_hw_control(struct e1000_adapter *adapter){ u32 ctrl_ext; u32 swsm; /* Let firmware know the driver has taken over */ switch (adapter->hw.mac.type) { case e1000_82573: swsm = E1000_READ_REG(&adapter->hw, E1000_SWSM); E1000_WRITE_REG(&adapter->hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD); break; case e1000_82571: case e1000_82572: case e1000_80003es2lan: case e1000_ich8lan: case e1000_ich9lan: ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT); E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); break; default: break; }}static void e1000_init_manageability(struct e1000_adapter *adapter){ if (adapter->en_mng_pt) { u32 manc = E1000_READ_REG(&adapter->hw, E1000_MANC); /* disable hardware interception of ARP */ manc &= ~(E1000_MANC_ARP_EN); /* enable receiving management packets to the host */ /* this will probably generate destination unreachable messages * from the host OS, but the packets will be handled on SMBUS */ if (adapter->flags.has_manc2h) { u32 manc2h = E1000_READ_REG(&adapter->hw, E1000_MANC2H); manc |= E1000_MANC_EN_MNG2HOST;#define E1000_MNG2HOST_PORT_623 (1 << 5)#define E1000_MNG2HOST_PORT_664 (1 << 6) manc2h |= E1000_MNG2HOST_PORT_623; manc2h |= E1000_MNG2HOST_PORT_664; E1000_WRITE_REG(&adapter->hw, E1000_MANC2H, manc2h); } E1000_WRITE_REG(&adapter->hw, E1000_MANC, manc); }}static void e1000_release_manageability(struct e1000_adapter *adapter){ if (adapter->en_mng_pt) { u32 manc = E1000_READ_REG(&adapter->hw, E1000_MANC); /* re-enable hardware interception of ARP */ manc |= E1000_MANC_ARP_EN; if (adapter->flags.has_manc2h) manc &= ~E1000_MANC_EN_MNG2HOST; /* don't explicitly have to mess with MANC2H since * MANC has an enable disable that gates MANC2H */ /* XXX stop the hardware watchdog ? */ E1000_WRITE_REG(&adapter->hw, E1000_MANC, manc); }}/** * e1000_configure - configure the hardware for RX and TX * @adapter: private board structure **/static void e1000_configure(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; int i; e1000_set_multi(netdev);#ifdef NETIF_F_HW_VLAN_TX e1000_restore_vlan(adapter);#endif e1000_init_manageability(adapter); e1000_configure_tx(adapter); e1000_setup_rctl(adapter); e1000_configure_rx(adapter); /* call E1000_DESC_UNUSED which always leaves * at least 1 descriptor unused to make sure * next_to_use != next_to_clean */ for (i = 0; i < adapter->num_rx_queues; i++) { struct e1000_rx_ring *ring = &adapter->rx_ring[i]; adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); }#ifdef CONFIG_E1000_MQ e1000_setup_queue_mapping(adapter);#endif adapter->tx_queue_len = netdev->tx_queue_len;}int e1000_up(struct e1000_adapter *adapter){ /* hardware has been reset, we need to reload some things */ e1000_configure(adapter); clear_bit(__E1000_DOWN, &adapter->state);#ifdef CONFIG_E1000_NAPI netif_poll_enable(adapter->netdev);#endif e1000_irq_enable(adapter); /* fire a link change interrupt to start the watchdog */ E1000_WRITE_REG(&adapter->hw, E1000_ICS, E1000_ICS_LSC); return 0;}/** * e1000_power_up_phy - restore link in case the phy was powered down * @adapter: address of board private structure * * The phy may be powered down to save power and turn off link when the * driver is unloaded and wake on lan is not enabled (among others) * *** this routine MUST be followed by a call to e1000_reset *** * **/void e1000_power_up_phy(struct e1000_adapter *adapter){ u16 mii_reg = 0; /* Just clear the power down bit to wake the phy back up */ if (adapter->hw.phy.media_type == e1000_media_type_copper) { /* according to the manual, the phy will retain its * settings across a power-down/up cycle */ e1000_read_phy_reg(&adapter->hw, PHY_CONTROL, &mii_reg); mii_reg &= ~MII_CR_POWER_DOWN; e1000_write_phy_reg(&adapter->hw, PHY_CONTROL, mii_reg); } e1000_setup_link(&adapter->hw);}static void e1000_power_down_phy(struct e1000_adapter *adapter){ /* Power down the PHY so no link is implied when interface is down * * The PHY cannot be powered down if any of the following is TRUE * * (a) WoL is enabled * (b) AMT is active * (c) SoL/IDER session is active */ if (!adapter->wol && adapter->hw.mac.type >= e1000_82540 && adapter->hw.phy.media_type == e1000_media_type_copper) { u16 mii_reg = 0; switch (adapter->hw.mac.type) { case e1000_82540: case e1000_82545: case e1000_82545_rev_3: case e1000_82546: case e1000_82546_rev_3: case e1000_82541: case e1000_82541_rev_2: case e1000_82547: case e1000_82547_rev_2: if (E1000_READ_REG(&adapter->hw, E1000_MANC) & E1000_MANC_SMBUS_EN) goto out; break; case e1000_82571: case e1000_82572: case e1000_82573: case e1000_80003es2lan: case e1000_ich8lan: case e1000_ich9lan: if (e1000_check_mng_mode(&adapter->hw) || e1000_check_reset_block(&adapter->hw)) goto out; break; default: goto out; } e1000_read_phy_reg(&adapter->hw, PHY_CONTROL, &mii_reg); mii_reg |= MII_CR_POWER_DOWN; e1000_write_phy_reg(&adapter->hw, PHY_CONTROL, mii_reg); mdelay(1); }out: return;}void e1000_down(struct e1000_adapter *adapter){ struct net_device *netdev = adapter->netdev; u32 tctl, rctl; /* signal that we're down so the interrupt handler does not * reschedule our watchdog timer */ set_bit(__E1000_DOWN, &adapter->state); /* disable receives in the hardware */ rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL); E1000_WRITE_REG(&adapter->hw, E1000_RCTL, rctl & ~E1000_RCTL_EN); /* flush and sleep below */#ifdef NETIF_F_LLTX netif_stop_queue(netdev);#else netif_tx_disable(netdev);#endif /* disable transmits in the hardware */ tctl = E1000_READ_REG(&adapter->hw, E1000_TCTL); tctl &= ~E1000_TCTL_EN; E1000_WRITE_REG(&adapter->hw, E1000_TCTL, tctl); /* flush both disables and wait for them to finish */ E1000_WRITE_FLUSH(&adapter->hw); msleep(10);#ifdef CONFIG_E1000_NAPI netif_poll_disable(netdev);#endif e1000_irq_disable(adapter); del_timer_sync(&adapter->tx_fifo_stall_timer); del_timer_sync(&adapter->watchdog_timer); del_timer_sync(&adapter->phy_info_timer); netdev->tx_queue_len = adapter->tx_queue_len; netif_carrier_off(netdev); adapter->link_speed = 0; adapter->link_duplex = 0; e1000_reset(adapter); e1000_clean_all_tx_rings(adapter); e1000_clean_all_rx_rings(adapter);}void e1000_reinit_locked(struct e1000_adapter *adapter){ WARN_ON(in_interrupt()); while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) msleep(1); e1000_down(adapter); e1000_up(adapter); clear_bit(__E1000_RESETTING, &adapter->state);}void e1000_reset(struct e1000_adapter *adapter){ struct e1000_mac_info *mac = &adapter->hw.mac; struct e1000_fc_info *fc = &adapter->hw.fc; u32 pba = 0, tx_space, min_tx_space, min_rx_space; boolean_t legacy_pba_adjust = FALSE; u16 hwm; /* Repartition Pba for greater than 9k mtu * To take effect CTRL.RST is required. */ switch (mac->type) { case e1000_82542: case e1000_82543: case e1000_82544: case e1000_82540: case e1000_82541: case e1000_82541_rev_2: legacy_pba_adjust = TRUE; pba = E1000_PBA_48K; break; case e1000_82545: case e1000_82545_rev_3: case e1000_82546: case e1000_82546_rev_3: pba = E1000_PBA_48K; break; case e1000_82547: case e1000_82547_rev_2: legacy_pba_adjust = TRUE; pba = E1000_PBA_30K; break; case e1000_82571: case e1000_82572: case e1000_80003es2lan: pba = E1000_PBA_38K; break; case e1000_82573: pba = E1000_PBA_20K; break; case e1000_ich8lan: pba = E1000_PBA_8K; break; case e1000_ich9lan:#define E1000_PBA_10K 0x000A pba = E1000_PBA_10K; break; case e1000_undefined: case e1000_num_macs: break; } if (legacy_pba_adjust == TRUE) { if (adapter->max_frame_size > E1000_RXBUFFER_8192) pba -= 8; /* allocate more FIFO for Tx */ if (mac->type == e1000_82547) { adapter->tx_fifo_head = 0; adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; adapter->tx_fifo_size = (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -