1 1.2 rin /* $NetBSD: igc_base.c,v 1.2 2023/10/04 07:35:27 rin Exp $ */ 2 1.1 rin /* $OpenBSD: igc_base.c,v 1.1 2021/10/31 14:52:57 patrick Exp $ */ 3 1.1 rin /*- 4 1.1 rin * Copyright 2021 Intel Corp 5 1.1 rin * Copyright 2021 Rubicon Communications, LLC (Netgate) 6 1.1 rin * SPDX-License-Identifier: BSD-3-Clause 7 1.1 rin */ 8 1.1 rin 9 1.2 rin #include <sys/cdefs.h> 10 1.2 rin __KERNEL_RCSID(0, "$NetBSD: igc_base.c,v 1.2 2023/10/04 07:35:27 rin Exp $"); 11 1.2 rin 12 1.2 rin #include <dev/pci/igc/igc_hw.h> 13 1.2 rin #include <dev/pci/igc/igc_i225.h> 14 1.2 rin #include <dev/pci/igc/if_igc.h> 15 1.2 rin #include <dev/pci/igc/igc_mac.h> 16 1.2 rin #include <dev/pci/igc/igc_base.h> 17 1.1 rin 18 1.1 rin /** 19 1.1 rin * igc_acquire_phy_base - Acquire rights to access PHY 20 1.1 rin * @hw: pointer to the HW structure 21 1.1 rin * 22 1.1 rin * Acquire access rights to the correct PHY. 23 1.1 rin **/ 24 1.1 rin int 25 1.1 rin igc_acquire_phy_base(struct igc_hw *hw) 26 1.1 rin { 27 1.1 rin uint16_t mask = IGC_SWFW_PHY0_SM; 28 1.1 rin 29 1.1 rin DEBUGFUNC("igc_acquire_phy_base"); 30 1.1 rin 31 1.1 rin if (hw->bus.func == IGC_FUNC_1) 32 1.1 rin mask = IGC_SWFW_PHY1_SM; 33 1.1 rin 34 1.1 rin return hw->mac.ops.acquire_swfw_sync(hw, mask); 35 1.1 rin } 36 1.1 rin 37 1.1 rin /** 38 1.1 rin * igc_release_phy_base - Release rights to access PHY 39 1.1 rin * @hw: pointer to the HW structure 40 1.1 rin * 41 1.1 rin * A wrapper to release access rights to the correct PHY. 42 1.1 rin **/ 43 1.1 rin void 44 1.1 rin igc_release_phy_base(struct igc_hw *hw) 45 1.1 rin { 46 1.1 rin uint16_t mask = IGC_SWFW_PHY0_SM; 47 1.1 rin 48 1.1 rin DEBUGFUNC("igc_release_phy_base"); 49 1.1 rin 50 1.1 rin if (hw->bus.func == IGC_FUNC_1) 51 1.1 rin mask = IGC_SWFW_PHY1_SM; 52 1.1 rin 53 1.1 rin hw->mac.ops.release_swfw_sync(hw, mask); 54 1.1 rin } 55 1.1 rin 56 1.1 rin /** 57 1.1 rin * igc_init_hw_base - Initialize hardware 58 1.1 rin * @hw: pointer to the HW structure 59 1.1 rin * 60 1.1 rin * This inits the hardware readying it for operation. 61 1.1 rin **/ 62 1.1 rin int 63 1.1 rin igc_init_hw_base(struct igc_hw *hw) 64 1.1 rin { 65 1.1 rin struct igc_mac_info *mac = &hw->mac; 66 1.1 rin uint16_t i, rar_count = mac->rar_entry_count; 67 1.1 rin int ret_val; 68 1.1 rin 69 1.1 rin DEBUGFUNC("igc_init_hw_base"); 70 1.1 rin 71 1.1 rin /* Setup the receive address */ 72 1.1 rin igc_init_rx_addrs_generic(hw, rar_count); 73 1.1 rin 74 1.1 rin /* Zero out the Multicast HASH table */ 75 1.1 rin DEBUGOUT("Zeroing the MTA\n"); 76 1.1 rin for (i = 0; i < mac->mta_reg_count; i++) 77 1.1 rin IGC_WRITE_REG_ARRAY(hw, IGC_MTA, i, 0); 78 1.1 rin 79 1.1 rin /* Zero out the Unicast HASH table */ 80 1.1 rin DEBUGOUT("Zeroing the UTA\n"); 81 1.1 rin for (i = 0; i < mac->uta_reg_count; i++) 82 1.1 rin IGC_WRITE_REG_ARRAY(hw, IGC_UTA, i, 0); 83 1.1 rin 84 1.1 rin /* Setup link and flow control */ 85 1.1 rin ret_val = mac->ops.setup_link(hw); 86 1.1 rin /* 87 1.1 rin * Clear all of the statistics registers (clear on read). It is 88 1.1 rin * important that we do this after we have tried to establish link 89 1.1 rin * because the symbol error count will increment wildly if there 90 1.1 rin * is no link. 91 1.1 rin */ 92 1.1 rin igc_clear_hw_cntrs_base_generic(hw); 93 1.1 rin 94 1.1 rin return ret_val; 95 1.1 rin } 96 1.1 rin 97 1.1 rin /** 98 1.1 rin * igc_power_down_phy_copper_base - Remove link during PHY power down 99 1.1 rin * @hw: pointer to the HW structure 100 1.1 rin * 101 1.1 rin * In the case of a PHY power down to save power, or to turn off link during a 102 1.1 rin * driver unload, or wake on lan is not enabled, remove the link. 103 1.1 rin **/ 104 1.1 rin void 105 1.1 rin igc_power_down_phy_copper_base(struct igc_hw *hw) 106 1.1 rin { 107 1.1 rin struct igc_phy_info *phy = &hw->phy; 108 1.1 rin 109 1.1 rin if (!(phy->ops.check_reset_block)) 110 1.1 rin return; 111 1.1 rin 112 1.1 rin /* If the management interface is not enabled, then power down */ 113 1.1 rin if (phy->ops.check_reset_block(hw)) 114 1.1 rin igc_power_down_phy_copper(hw); 115 1.1 rin 116 1.1 rin return; 117 1.1 rin } 118