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