xref: /titanic_51/usr/src/uts/common/io/e1000api/e1000_vf.c (revision 42cc51e07cdbcad3b9aca8d9d991fc09b251feb7)
175eba5b6SRobert Mustacchi /******************************************************************************
275eba5b6SRobert Mustacchi 
3*42cc51e0SRobert Mustacchi   Copyright (c) 2001-2015, Intel Corporation
475eba5b6SRobert Mustacchi   All rights reserved.
575eba5b6SRobert Mustacchi 
675eba5b6SRobert Mustacchi   Redistribution and use in source and binary forms, with or without
775eba5b6SRobert Mustacchi   modification, are permitted provided that the following conditions are met:
875eba5b6SRobert Mustacchi 
975eba5b6SRobert Mustacchi    1. Redistributions of source code must retain the above copyright notice,
1075eba5b6SRobert Mustacchi       this list of conditions and the following disclaimer.
1175eba5b6SRobert Mustacchi 
1275eba5b6SRobert Mustacchi    2. Redistributions in binary form must reproduce the above copyright
1375eba5b6SRobert Mustacchi       notice, this list of conditions and the following disclaimer in the
1475eba5b6SRobert Mustacchi       documentation and/or other materials provided with the distribution.
1575eba5b6SRobert Mustacchi 
1675eba5b6SRobert Mustacchi    3. Neither the name of the Intel Corporation nor the names of its
1775eba5b6SRobert Mustacchi       contributors may be used to endorse or promote products derived from
1875eba5b6SRobert Mustacchi       this software without specific prior written permission.
1975eba5b6SRobert Mustacchi 
2075eba5b6SRobert Mustacchi   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2175eba5b6SRobert Mustacchi   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2275eba5b6SRobert Mustacchi   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2375eba5b6SRobert Mustacchi   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2475eba5b6SRobert Mustacchi   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2575eba5b6SRobert Mustacchi   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2675eba5b6SRobert Mustacchi   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2775eba5b6SRobert Mustacchi   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2875eba5b6SRobert Mustacchi   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2975eba5b6SRobert Mustacchi   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3075eba5b6SRobert Mustacchi   POSSIBILITY OF SUCH DAMAGE.
3175eba5b6SRobert Mustacchi 
3275eba5b6SRobert Mustacchi ******************************************************************************/
3375eba5b6SRobert Mustacchi /*$FreeBSD$*/
3475eba5b6SRobert Mustacchi 
3575eba5b6SRobert Mustacchi 
3675eba5b6SRobert Mustacchi #include "e1000_api.h"
3775eba5b6SRobert Mustacchi 
3875eba5b6SRobert Mustacchi 
3975eba5b6SRobert Mustacchi static s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
4075eba5b6SRobert Mustacchi static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
4175eba5b6SRobert Mustacchi static void e1000_release_vf(struct e1000_hw *hw);
4275eba5b6SRobert Mustacchi static s32 e1000_acquire_vf(struct e1000_hw *hw);
4375eba5b6SRobert Mustacchi static s32 e1000_setup_link_vf(struct e1000_hw *hw);
4475eba5b6SRobert Mustacchi static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
4575eba5b6SRobert Mustacchi static s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
4675eba5b6SRobert Mustacchi static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
4775eba5b6SRobert Mustacchi static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
4875eba5b6SRobert Mustacchi 				     u16 *duplex);
4975eba5b6SRobert Mustacchi static s32 e1000_init_hw_vf(struct e1000_hw *hw);
5075eba5b6SRobert Mustacchi static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
5175eba5b6SRobert Mustacchi static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
52c124a83eSRobert Mustacchi static int  e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
5375eba5b6SRobert Mustacchi static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
5475eba5b6SRobert Mustacchi 
5575eba5b6SRobert Mustacchi /**
5675eba5b6SRobert Mustacchi  *  e1000_init_phy_params_vf - Inits PHY params
5775eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
5875eba5b6SRobert Mustacchi  *
5975eba5b6SRobert Mustacchi  *  Doesn't do much - there's no PHY available to the VF.
6075eba5b6SRobert Mustacchi  **/
6175eba5b6SRobert Mustacchi static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
6275eba5b6SRobert Mustacchi {
6375eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_init_phy_params_vf");
6475eba5b6SRobert Mustacchi 	hw->phy.type = e1000_phy_vf;
6575eba5b6SRobert Mustacchi 	hw->phy.ops.acquire = e1000_acquire_vf;
6675eba5b6SRobert Mustacchi 	hw->phy.ops.release = e1000_release_vf;
6775eba5b6SRobert Mustacchi 
6875eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
6975eba5b6SRobert Mustacchi }
7075eba5b6SRobert Mustacchi 
7175eba5b6SRobert Mustacchi /**
7275eba5b6SRobert Mustacchi  *  e1000_init_nvm_params_vf - Inits NVM params
7375eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
7475eba5b6SRobert Mustacchi  *
7575eba5b6SRobert Mustacchi  *  Doesn't do much - there's no NVM available to the VF.
7675eba5b6SRobert Mustacchi  **/
7775eba5b6SRobert Mustacchi static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
7875eba5b6SRobert Mustacchi {
7975eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_init_nvm_params_vf");
8075eba5b6SRobert Mustacchi 	hw->nvm.type = e1000_nvm_none;
8175eba5b6SRobert Mustacchi 	hw->nvm.ops.acquire = e1000_acquire_vf;
8275eba5b6SRobert Mustacchi 	hw->nvm.ops.release = e1000_release_vf;
8375eba5b6SRobert Mustacchi 
8475eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
8575eba5b6SRobert Mustacchi }
8675eba5b6SRobert Mustacchi 
8775eba5b6SRobert Mustacchi /**
8875eba5b6SRobert Mustacchi  *  e1000_init_mac_params_vf - Inits MAC params
8975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
9075eba5b6SRobert Mustacchi  **/
9175eba5b6SRobert Mustacchi static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
9275eba5b6SRobert Mustacchi {
9375eba5b6SRobert Mustacchi 	struct e1000_mac_info *mac = &hw->mac;
9475eba5b6SRobert Mustacchi 
9575eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_init_mac_params_vf");
9675eba5b6SRobert Mustacchi 
9775eba5b6SRobert Mustacchi 	/* Set media type */
9875eba5b6SRobert Mustacchi 	/*
9975eba5b6SRobert Mustacchi 	 * Virtual functions don't care what they're media type is as they
10075eba5b6SRobert Mustacchi 	 * have no direct access to the PHY, or the media.  That is handled
10175eba5b6SRobert Mustacchi 	 * by the physical function driver.
10275eba5b6SRobert Mustacchi 	 */
10375eba5b6SRobert Mustacchi 	hw->phy.media_type = e1000_media_type_unknown;
10475eba5b6SRobert Mustacchi 
10575eba5b6SRobert Mustacchi 	/* No ASF features for the VF driver */
10675eba5b6SRobert Mustacchi 	mac->asf_firmware_present = FALSE;
10775eba5b6SRobert Mustacchi 	/* ARC subsystem not supported */
10875eba5b6SRobert Mustacchi 	mac->arc_subsystem_valid = FALSE;
10975eba5b6SRobert Mustacchi 	/* Disable adaptive IFS mode so the generic funcs don't do anything */
11075eba5b6SRobert Mustacchi 	mac->adaptive_ifs = FALSE;
11175eba5b6SRobert Mustacchi 	/* VF's have no MTA Registers - PF feature only */
11275eba5b6SRobert Mustacchi 	mac->mta_reg_count = 128;
11375eba5b6SRobert Mustacchi 	/* VF's have no access to RAR entries  */
11475eba5b6SRobert Mustacchi 	mac->rar_entry_count = 1;
11575eba5b6SRobert Mustacchi 
11675eba5b6SRobert Mustacchi 	/* Function pointers */
11775eba5b6SRobert Mustacchi 	/* link setup */
11875eba5b6SRobert Mustacchi 	mac->ops.setup_link = e1000_setup_link_vf;
11975eba5b6SRobert Mustacchi 	/* bus type/speed/width */
12075eba5b6SRobert Mustacchi 	mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
12175eba5b6SRobert Mustacchi 	/* reset */
12275eba5b6SRobert Mustacchi 	mac->ops.reset_hw = e1000_reset_hw_vf;
12375eba5b6SRobert Mustacchi 	/* hw initialization */
12475eba5b6SRobert Mustacchi 	mac->ops.init_hw = e1000_init_hw_vf;
12575eba5b6SRobert Mustacchi 	/* check for link */
12675eba5b6SRobert Mustacchi 	mac->ops.check_for_link = e1000_check_for_link_vf;
12775eba5b6SRobert Mustacchi 	/* link info */
12875eba5b6SRobert Mustacchi 	mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
12975eba5b6SRobert Mustacchi 	/* multicast address update */
13075eba5b6SRobert Mustacchi 	mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
13175eba5b6SRobert Mustacchi 	/* set mac address */
13275eba5b6SRobert Mustacchi 	mac->ops.rar_set = e1000_rar_set_vf;
13375eba5b6SRobert Mustacchi 	/* read mac address */
13475eba5b6SRobert Mustacchi 	mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
13575eba5b6SRobert Mustacchi 
13675eba5b6SRobert Mustacchi 
13775eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
13875eba5b6SRobert Mustacchi }
13975eba5b6SRobert Mustacchi 
14075eba5b6SRobert Mustacchi /**
14175eba5b6SRobert Mustacchi  *  e1000_init_function_pointers_vf - Inits function pointers
14275eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
14375eba5b6SRobert Mustacchi  **/
14475eba5b6SRobert Mustacchi void e1000_init_function_pointers_vf(struct e1000_hw *hw)
14575eba5b6SRobert Mustacchi {
14675eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_init_function_pointers_vf");
14775eba5b6SRobert Mustacchi 
14875eba5b6SRobert Mustacchi 	hw->mac.ops.init_params = e1000_init_mac_params_vf;
14975eba5b6SRobert Mustacchi 	hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
15075eba5b6SRobert Mustacchi 	hw->phy.ops.init_params = e1000_init_phy_params_vf;
15175eba5b6SRobert Mustacchi 	hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
15275eba5b6SRobert Mustacchi }
15375eba5b6SRobert Mustacchi 
15475eba5b6SRobert Mustacchi /**
15575eba5b6SRobert Mustacchi  *  e1000_acquire_vf - Acquire rights to access PHY or NVM.
15675eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
15775eba5b6SRobert Mustacchi  *
15875eba5b6SRobert Mustacchi  *  There is no PHY or NVM so we want all attempts to acquire these to fail.
15975eba5b6SRobert Mustacchi  *  In addition, the MAC registers to access PHY/NVM don't exist so we don't
16075eba5b6SRobert Mustacchi  *  even want any SW to attempt to use them.
16175eba5b6SRobert Mustacchi  **/
162c124a83eSRobert Mustacchi static s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
16375eba5b6SRobert Mustacchi {
16475eba5b6SRobert Mustacchi 	return -E1000_ERR_PHY;
16575eba5b6SRobert Mustacchi }
16675eba5b6SRobert Mustacchi 
16775eba5b6SRobert Mustacchi /**
16875eba5b6SRobert Mustacchi  *  e1000_release_vf - Release PHY or NVM
16975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
17075eba5b6SRobert Mustacchi  *
17175eba5b6SRobert Mustacchi  *  There is no PHY or NVM so we want all attempts to acquire these to fail.
17275eba5b6SRobert Mustacchi  *  In addition, the MAC registers to access PHY/NVM don't exist so we don't
17375eba5b6SRobert Mustacchi  *  even want any SW to attempt to use them.
17475eba5b6SRobert Mustacchi  **/
175c124a83eSRobert Mustacchi static void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
17675eba5b6SRobert Mustacchi {
17775eba5b6SRobert Mustacchi 	return;
17875eba5b6SRobert Mustacchi }
17975eba5b6SRobert Mustacchi 
18075eba5b6SRobert Mustacchi /**
18175eba5b6SRobert Mustacchi  *  e1000_setup_link_vf - Sets up link.
18275eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
18375eba5b6SRobert Mustacchi  *
18475eba5b6SRobert Mustacchi  *  Virtual functions cannot change link.
18575eba5b6SRobert Mustacchi  **/
186c124a83eSRobert Mustacchi static s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
18775eba5b6SRobert Mustacchi {
18875eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_setup_link_vf");
18975eba5b6SRobert Mustacchi 
19075eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
19175eba5b6SRobert Mustacchi }
19275eba5b6SRobert Mustacchi 
19375eba5b6SRobert Mustacchi /**
19475eba5b6SRobert Mustacchi  *  e1000_get_bus_info_pcie_vf - Gets the bus info.
19575eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
19675eba5b6SRobert Mustacchi  *
19775eba5b6SRobert Mustacchi  *  Virtual functions are not really on their own bus.
19875eba5b6SRobert Mustacchi  **/
19975eba5b6SRobert Mustacchi static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
20075eba5b6SRobert Mustacchi {
20175eba5b6SRobert Mustacchi 	struct e1000_bus_info *bus = &hw->bus;
20275eba5b6SRobert Mustacchi 
20375eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_get_bus_info_pcie_vf");
20475eba5b6SRobert Mustacchi 
20575eba5b6SRobert Mustacchi 	/* Do not set type PCI-E because we don't want disable master to run */
20675eba5b6SRobert Mustacchi 	bus->type = e1000_bus_type_reserved;
20775eba5b6SRobert Mustacchi 	bus->speed = e1000_bus_speed_2500;
20875eba5b6SRobert Mustacchi 
20975eba5b6SRobert Mustacchi 	return 0;
21075eba5b6SRobert Mustacchi }
21175eba5b6SRobert Mustacchi 
21275eba5b6SRobert Mustacchi /**
21375eba5b6SRobert Mustacchi  *  e1000_get_link_up_info_vf - Gets link info.
21475eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
21575eba5b6SRobert Mustacchi  *  @speed: pointer to 16 bit value to store link speed.
21675eba5b6SRobert Mustacchi  *  @duplex: pointer to 16 bit value to store duplex.
21775eba5b6SRobert Mustacchi  *
21875eba5b6SRobert Mustacchi  *  Since we cannot read the PHY and get accurate link info, we must rely upon
21975eba5b6SRobert Mustacchi  *  the status register's data which is often stale and inaccurate.
22075eba5b6SRobert Mustacchi  **/
22175eba5b6SRobert Mustacchi static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
22275eba5b6SRobert Mustacchi 				     u16 *duplex)
22375eba5b6SRobert Mustacchi {
22475eba5b6SRobert Mustacchi 	s32 status;
22575eba5b6SRobert Mustacchi 
22675eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_get_link_up_info_vf");
22775eba5b6SRobert Mustacchi 
22875eba5b6SRobert Mustacchi 	status = E1000_READ_REG(hw, E1000_STATUS);
22975eba5b6SRobert Mustacchi 	if (status & E1000_STATUS_SPEED_1000) {
23075eba5b6SRobert Mustacchi 		*speed = SPEED_1000;
23175eba5b6SRobert Mustacchi 		DEBUGOUT("1000 Mbs, ");
23275eba5b6SRobert Mustacchi 	} else if (status & E1000_STATUS_SPEED_100) {
23375eba5b6SRobert Mustacchi 		*speed = SPEED_100;
23475eba5b6SRobert Mustacchi 		DEBUGOUT("100 Mbs, ");
23575eba5b6SRobert Mustacchi 	} else {
23675eba5b6SRobert Mustacchi 		*speed = SPEED_10;
23775eba5b6SRobert Mustacchi 		DEBUGOUT("10 Mbs, ");
23875eba5b6SRobert Mustacchi 	}
23975eba5b6SRobert Mustacchi 
24075eba5b6SRobert Mustacchi 	if (status & E1000_STATUS_FD) {
24175eba5b6SRobert Mustacchi 		*duplex = FULL_DUPLEX;
24275eba5b6SRobert Mustacchi 		DEBUGOUT("Full Duplex\n");
24375eba5b6SRobert Mustacchi 	} else {
24475eba5b6SRobert Mustacchi 		*duplex = HALF_DUPLEX;
24575eba5b6SRobert Mustacchi 		DEBUGOUT("Half Duplex\n");
24675eba5b6SRobert Mustacchi 	}
24775eba5b6SRobert Mustacchi 
24875eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
24975eba5b6SRobert Mustacchi }
25075eba5b6SRobert Mustacchi 
25175eba5b6SRobert Mustacchi /**
25275eba5b6SRobert Mustacchi  *  e1000_reset_hw_vf - Resets the HW
25375eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
25475eba5b6SRobert Mustacchi  *
25575eba5b6SRobert Mustacchi  *  VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
25675eba5b6SRobert Mustacchi  *  This is all the reset we can perform on a VF.
25775eba5b6SRobert Mustacchi  **/
25875eba5b6SRobert Mustacchi static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
25975eba5b6SRobert Mustacchi {
26075eba5b6SRobert Mustacchi 	struct e1000_mbx_info *mbx = &hw->mbx;
26175eba5b6SRobert Mustacchi 	u32 timeout = E1000_VF_INIT_TIMEOUT;
26275eba5b6SRobert Mustacchi 	s32 ret_val = -E1000_ERR_MAC_INIT;
26375eba5b6SRobert Mustacchi 	u32 ctrl, msgbuf[3];
26475eba5b6SRobert Mustacchi 	u8 *addr = (u8 *)(&msgbuf[1]);
26575eba5b6SRobert Mustacchi 
26675eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_reset_hw_vf");
26775eba5b6SRobert Mustacchi 
26875eba5b6SRobert Mustacchi 	DEBUGOUT("Issuing a function level reset to MAC\n");
26975eba5b6SRobert Mustacchi 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
27075eba5b6SRobert Mustacchi 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
27175eba5b6SRobert Mustacchi 
27275eba5b6SRobert Mustacchi 	/* we cannot reset while the RSTI / RSTD bits are asserted */
27375eba5b6SRobert Mustacchi 	while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
27475eba5b6SRobert Mustacchi 		timeout--;
27575eba5b6SRobert Mustacchi 		usec_delay(5);
27675eba5b6SRobert Mustacchi 	}
27775eba5b6SRobert Mustacchi 
27875eba5b6SRobert Mustacchi 	if (timeout) {
27975eba5b6SRobert Mustacchi 		/* mailbox timeout can now become active */
28075eba5b6SRobert Mustacchi 		mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
28175eba5b6SRobert Mustacchi 
28275eba5b6SRobert Mustacchi 		msgbuf[0] = E1000_VF_RESET;
28375eba5b6SRobert Mustacchi 		mbx->ops.write_posted(hw, msgbuf, 1, 0);
28475eba5b6SRobert Mustacchi 
28575eba5b6SRobert Mustacchi 		msec_delay(10);
28675eba5b6SRobert Mustacchi 
28775eba5b6SRobert Mustacchi 		/* set our "perm_addr" based on info provided by PF */
28875eba5b6SRobert Mustacchi 		ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
28975eba5b6SRobert Mustacchi 		if (!ret_val) {
29075eba5b6SRobert Mustacchi 			if (msgbuf[0] == (E1000_VF_RESET |
29175eba5b6SRobert Mustacchi 			    E1000_VT_MSGTYPE_ACK))
29275eba5b6SRobert Mustacchi 				memcpy(hw->mac.perm_addr, addr, 6);
29375eba5b6SRobert Mustacchi 			else
29475eba5b6SRobert Mustacchi 				ret_val = -E1000_ERR_MAC_INIT;
29575eba5b6SRobert Mustacchi 		}
29675eba5b6SRobert Mustacchi 	}
29775eba5b6SRobert Mustacchi 
29875eba5b6SRobert Mustacchi 	return ret_val;
29975eba5b6SRobert Mustacchi }
30075eba5b6SRobert Mustacchi 
30175eba5b6SRobert Mustacchi /**
30275eba5b6SRobert Mustacchi  *  e1000_init_hw_vf - Inits the HW
30375eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
30475eba5b6SRobert Mustacchi  *
30575eba5b6SRobert Mustacchi  *  Not much to do here except clear the PF Reset indication if there is one.
30675eba5b6SRobert Mustacchi  **/
30775eba5b6SRobert Mustacchi static s32 e1000_init_hw_vf(struct e1000_hw *hw)
30875eba5b6SRobert Mustacchi {
30975eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_init_hw_vf");
31075eba5b6SRobert Mustacchi 
31175eba5b6SRobert Mustacchi 	/* attempt to set and restore our mac address */
31275eba5b6SRobert Mustacchi 	e1000_rar_set_vf(hw, hw->mac.addr, 0);
31375eba5b6SRobert Mustacchi 
31475eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
31575eba5b6SRobert Mustacchi }
31675eba5b6SRobert Mustacchi 
31775eba5b6SRobert Mustacchi /**
31875eba5b6SRobert Mustacchi  *  e1000_rar_set_vf - set device MAC address
31975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
32075eba5b6SRobert Mustacchi  *  @addr: pointer to the receive address
32175eba5b6SRobert Mustacchi  *  @index receive address array register
32275eba5b6SRobert Mustacchi  **/
323c124a83eSRobert Mustacchi static int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
324c124a83eSRobert Mustacchi 			     u32 E1000_UNUSEDARG index)
32575eba5b6SRobert Mustacchi {
32675eba5b6SRobert Mustacchi 	struct e1000_mbx_info *mbx = &hw->mbx;
32775eba5b6SRobert Mustacchi 	u32 msgbuf[3];
32875eba5b6SRobert Mustacchi 	u8 *msg_addr = (u8 *)(&msgbuf[1]);
32975eba5b6SRobert Mustacchi 	s32 ret_val;
33075eba5b6SRobert Mustacchi 
33175eba5b6SRobert Mustacchi 	memset(msgbuf, 0, 12);
33275eba5b6SRobert Mustacchi 	msgbuf[0] = E1000_VF_SET_MAC_ADDR;
33375eba5b6SRobert Mustacchi 	memcpy(msg_addr, addr, 6);
33475eba5b6SRobert Mustacchi 	ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
33575eba5b6SRobert Mustacchi 
33675eba5b6SRobert Mustacchi 	if (!ret_val)
33775eba5b6SRobert Mustacchi 		ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
33875eba5b6SRobert Mustacchi 
33975eba5b6SRobert Mustacchi 	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
34075eba5b6SRobert Mustacchi 
34175eba5b6SRobert Mustacchi 	/* if nacked the address was rejected, use "perm_addr" */
34275eba5b6SRobert Mustacchi 	if (!ret_val &&
34375eba5b6SRobert Mustacchi 	    (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
34475eba5b6SRobert Mustacchi 		e1000_read_mac_addr_vf(hw);
345c124a83eSRobert Mustacchi 
346c124a83eSRobert Mustacchi 	return E1000_SUCCESS;
34775eba5b6SRobert Mustacchi }
34875eba5b6SRobert Mustacchi 
34975eba5b6SRobert Mustacchi /**
35075eba5b6SRobert Mustacchi  *  e1000_hash_mc_addr_vf - Generate a multicast hash value
35175eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
35275eba5b6SRobert Mustacchi  *  @mc_addr: pointer to a multicast address
35375eba5b6SRobert Mustacchi  *
35475eba5b6SRobert Mustacchi  *  Generates a multicast address hash value which is used to determine
35575eba5b6SRobert Mustacchi  *  the multicast filter table array address and new table value.
35675eba5b6SRobert Mustacchi  **/
35775eba5b6SRobert Mustacchi static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
35875eba5b6SRobert Mustacchi {
35975eba5b6SRobert Mustacchi 	u32 hash_value, hash_mask;
36075eba5b6SRobert Mustacchi 	u8 bit_shift = 0;
36175eba5b6SRobert Mustacchi 
36275eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_hash_mc_addr_generic");
36375eba5b6SRobert Mustacchi 
36475eba5b6SRobert Mustacchi 	/* Register count multiplied by bits per register */
36575eba5b6SRobert Mustacchi 	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
36675eba5b6SRobert Mustacchi 
36775eba5b6SRobert Mustacchi 	/*
36875eba5b6SRobert Mustacchi 	 * The bit_shift is the number of left-shifts
36975eba5b6SRobert Mustacchi 	 * where 0xFF would still fall within the hash mask.
37075eba5b6SRobert Mustacchi 	 */
37175eba5b6SRobert Mustacchi 	while (hash_mask >> bit_shift != 0xFF)
37275eba5b6SRobert Mustacchi 		bit_shift++;
37375eba5b6SRobert Mustacchi 
37475eba5b6SRobert Mustacchi 	hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
37575eba5b6SRobert Mustacchi 				  (((u16) mc_addr[5]) << bit_shift)));
37675eba5b6SRobert Mustacchi 
37775eba5b6SRobert Mustacchi 	return hash_value;
37875eba5b6SRobert Mustacchi }
37975eba5b6SRobert Mustacchi 
38075eba5b6SRobert Mustacchi static void e1000_write_msg_read_ack(struct e1000_hw *hw,
38175eba5b6SRobert Mustacchi 				     u32 *msg, u16 size)
38275eba5b6SRobert Mustacchi {
38375eba5b6SRobert Mustacchi 	struct e1000_mbx_info *mbx = &hw->mbx;
38475eba5b6SRobert Mustacchi 	u32 retmsg[E1000_VFMAILBOX_SIZE];
38575eba5b6SRobert Mustacchi 	s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
38675eba5b6SRobert Mustacchi 
38775eba5b6SRobert Mustacchi 	if (!retval)
38875eba5b6SRobert Mustacchi 		mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
38975eba5b6SRobert Mustacchi }
39075eba5b6SRobert Mustacchi 
39175eba5b6SRobert Mustacchi /**
39275eba5b6SRobert Mustacchi  *  e1000_update_mc_addr_list_vf - Update Multicast addresses
39375eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
39475eba5b6SRobert Mustacchi  *  @mc_addr_list: array of multicast addresses to program
39575eba5b6SRobert Mustacchi  *  @mc_addr_count: number of multicast addresses to program
39675eba5b6SRobert Mustacchi  *
39775eba5b6SRobert Mustacchi  *  Updates the Multicast Table Array.
39875eba5b6SRobert Mustacchi  *  The caller must have a packed mc_addr_list of multicast addresses.
39975eba5b6SRobert Mustacchi  **/
40075eba5b6SRobert Mustacchi void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
40175eba5b6SRobert Mustacchi 				  u8 *mc_addr_list, u32 mc_addr_count)
40275eba5b6SRobert Mustacchi {
40375eba5b6SRobert Mustacchi 	u32 msgbuf[E1000_VFMAILBOX_SIZE];
40475eba5b6SRobert Mustacchi 	u16 *hash_list = (u16 *)&msgbuf[1];
40575eba5b6SRobert Mustacchi 	u32 hash_value;
40675eba5b6SRobert Mustacchi 	u32 i;
40775eba5b6SRobert Mustacchi 
40875eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_update_mc_addr_list_vf");
40975eba5b6SRobert Mustacchi 
41075eba5b6SRobert Mustacchi 	/* Each entry in the list uses 1 16 bit word.  We have 30
41175eba5b6SRobert Mustacchi 	 * 16 bit words available in our HW msg buffer (minus 1 for the
41275eba5b6SRobert Mustacchi 	 * msg type).  That's 30 hash values if we pack 'em right.  If
41375eba5b6SRobert Mustacchi 	 * there are more than 30 MC addresses to add then punt the
41475eba5b6SRobert Mustacchi 	 * extras for now and then add code to handle more than 30 later.
41575eba5b6SRobert Mustacchi 	 * It would be unusual for a server to request that many multi-cast
41675eba5b6SRobert Mustacchi 	 * addresses except for in large enterprise network environments.
41775eba5b6SRobert Mustacchi 	 */
41875eba5b6SRobert Mustacchi 
41975eba5b6SRobert Mustacchi 	DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
42075eba5b6SRobert Mustacchi 
42175eba5b6SRobert Mustacchi 	if (mc_addr_count > 30) {
42275eba5b6SRobert Mustacchi 		msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
42375eba5b6SRobert Mustacchi 		mc_addr_count = 30;
42475eba5b6SRobert Mustacchi 	}
42575eba5b6SRobert Mustacchi 
42675eba5b6SRobert Mustacchi 	msgbuf[0] = E1000_VF_SET_MULTICAST;
42775eba5b6SRobert Mustacchi 	msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
42875eba5b6SRobert Mustacchi 
42975eba5b6SRobert Mustacchi 	for (i = 0; i < mc_addr_count; i++) {
43075eba5b6SRobert Mustacchi 		hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
43175eba5b6SRobert Mustacchi 		DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
43275eba5b6SRobert Mustacchi 		hash_list[i] = hash_value & 0x0FFF;
43375eba5b6SRobert Mustacchi 		mc_addr_list += ETH_ADDR_LEN;
43475eba5b6SRobert Mustacchi 	}
43575eba5b6SRobert Mustacchi 
43675eba5b6SRobert Mustacchi 	e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
43775eba5b6SRobert Mustacchi }
43875eba5b6SRobert Mustacchi 
43975eba5b6SRobert Mustacchi /**
44075eba5b6SRobert Mustacchi  *  e1000_vfta_set_vf - Set/Unset vlan filter table address
44175eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
44275eba5b6SRobert Mustacchi  *  @vid: determines the vfta register and bit to set/unset
44375eba5b6SRobert Mustacchi  *  @set: if TRUE then set bit, else clear bit
44475eba5b6SRobert Mustacchi  **/
44575eba5b6SRobert Mustacchi void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
44675eba5b6SRobert Mustacchi {
44775eba5b6SRobert Mustacchi 	u32 msgbuf[2];
44875eba5b6SRobert Mustacchi 
44975eba5b6SRobert Mustacchi 	msgbuf[0] = E1000_VF_SET_VLAN;
45075eba5b6SRobert Mustacchi 	msgbuf[1] = vid;
45175eba5b6SRobert Mustacchi 	/* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
45275eba5b6SRobert Mustacchi 	if (set)
45375eba5b6SRobert Mustacchi 		msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
45475eba5b6SRobert Mustacchi 
45575eba5b6SRobert Mustacchi 	e1000_write_msg_read_ack(hw, msgbuf, 2);
45675eba5b6SRobert Mustacchi }
45775eba5b6SRobert Mustacchi 
45875eba5b6SRobert Mustacchi /** e1000_rlpml_set_vf - Set the maximum receive packet length
45975eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
46075eba5b6SRobert Mustacchi  *  @max_size: value to assign to max frame size
46175eba5b6SRobert Mustacchi  **/
46275eba5b6SRobert Mustacchi void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
46375eba5b6SRobert Mustacchi {
46475eba5b6SRobert Mustacchi 	u32 msgbuf[2];
46575eba5b6SRobert Mustacchi 
46675eba5b6SRobert Mustacchi 	msgbuf[0] = E1000_VF_SET_LPE;
46775eba5b6SRobert Mustacchi 	msgbuf[1] = max_size;
46875eba5b6SRobert Mustacchi 
46975eba5b6SRobert Mustacchi 	e1000_write_msg_read_ack(hw, msgbuf, 2);
47075eba5b6SRobert Mustacchi }
47175eba5b6SRobert Mustacchi 
47275eba5b6SRobert Mustacchi /**
47375eba5b6SRobert Mustacchi  *  e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
47475eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
47575eba5b6SRobert Mustacchi  *  @uni: boolean indicating unicast promisc status
47675eba5b6SRobert Mustacchi  *  @multi: boolean indicating multicast promisc status
47775eba5b6SRobert Mustacchi  **/
47875eba5b6SRobert Mustacchi s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
47975eba5b6SRobert Mustacchi {
48075eba5b6SRobert Mustacchi 	struct e1000_mbx_info *mbx = &hw->mbx;
48175eba5b6SRobert Mustacchi 	u32 msgbuf = E1000_VF_SET_PROMISC;
48275eba5b6SRobert Mustacchi 	s32 ret_val;
48375eba5b6SRobert Mustacchi 
48475eba5b6SRobert Mustacchi 	switch (type) {
48575eba5b6SRobert Mustacchi 	case e1000_promisc_multicast:
48675eba5b6SRobert Mustacchi 		msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
48775eba5b6SRobert Mustacchi 		break;
48875eba5b6SRobert Mustacchi 	case e1000_promisc_enabled:
48975eba5b6SRobert Mustacchi 		msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
49075eba5b6SRobert Mustacchi 	case e1000_promisc_unicast:
49175eba5b6SRobert Mustacchi 		msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
49275eba5b6SRobert Mustacchi 	case e1000_promisc_disabled:
49375eba5b6SRobert Mustacchi 		break;
49475eba5b6SRobert Mustacchi 	default:
49575eba5b6SRobert Mustacchi 		return -E1000_ERR_MAC_INIT;
49675eba5b6SRobert Mustacchi 	}
49775eba5b6SRobert Mustacchi 
49875eba5b6SRobert Mustacchi 	 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
49975eba5b6SRobert Mustacchi 
50075eba5b6SRobert Mustacchi 	if (!ret_val)
50175eba5b6SRobert Mustacchi 		ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
50275eba5b6SRobert Mustacchi 
50375eba5b6SRobert Mustacchi 	if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
50475eba5b6SRobert Mustacchi 		ret_val = -E1000_ERR_MAC_INIT;
50575eba5b6SRobert Mustacchi 
50675eba5b6SRobert Mustacchi 	return ret_val;
50775eba5b6SRobert Mustacchi }
50875eba5b6SRobert Mustacchi 
50975eba5b6SRobert Mustacchi /**
51075eba5b6SRobert Mustacchi  *  e1000_read_mac_addr_vf - Read device MAC address
51175eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
51275eba5b6SRobert Mustacchi  **/
51375eba5b6SRobert Mustacchi static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
51475eba5b6SRobert Mustacchi {
51575eba5b6SRobert Mustacchi 	int i;
51675eba5b6SRobert Mustacchi 
51775eba5b6SRobert Mustacchi 	for (i = 0; i < ETH_ADDR_LEN; i++)
51875eba5b6SRobert Mustacchi 		hw->mac.addr[i] = hw->mac.perm_addr[i];
51975eba5b6SRobert Mustacchi 
52075eba5b6SRobert Mustacchi 	return E1000_SUCCESS;
52175eba5b6SRobert Mustacchi }
52275eba5b6SRobert Mustacchi 
52375eba5b6SRobert Mustacchi /**
52475eba5b6SRobert Mustacchi  *  e1000_check_for_link_vf - Check for link for a virtual interface
52575eba5b6SRobert Mustacchi  *  @hw: pointer to the HW structure
52675eba5b6SRobert Mustacchi  *
52775eba5b6SRobert Mustacchi  *  Checks to see if the underlying PF is still talking to the VF and
52875eba5b6SRobert Mustacchi  *  if it is then it reports the link state to the hardware, otherwise
52975eba5b6SRobert Mustacchi  *  it reports link down and returns an error.
53075eba5b6SRobert Mustacchi  **/
53175eba5b6SRobert Mustacchi static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
53275eba5b6SRobert Mustacchi {
53375eba5b6SRobert Mustacchi 	struct e1000_mbx_info *mbx = &hw->mbx;
53475eba5b6SRobert Mustacchi 	struct e1000_mac_info *mac = &hw->mac;
53575eba5b6SRobert Mustacchi 	s32 ret_val = E1000_SUCCESS;
53675eba5b6SRobert Mustacchi 	u32 in_msg = 0;
53775eba5b6SRobert Mustacchi 
53875eba5b6SRobert Mustacchi 	DEBUGFUNC("e1000_check_for_link_vf");
53975eba5b6SRobert Mustacchi 
54075eba5b6SRobert Mustacchi 	/*
54175eba5b6SRobert Mustacchi 	 * We only want to run this if there has been a rst asserted.
54275eba5b6SRobert Mustacchi 	 * in this case that could mean a link change, device reset,
54375eba5b6SRobert Mustacchi 	 * or a virtual function reset
54475eba5b6SRobert Mustacchi 	 */
54575eba5b6SRobert Mustacchi 
54675eba5b6SRobert Mustacchi 	/* If we were hit with a reset or timeout drop the link */
54775eba5b6SRobert Mustacchi 	if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
54875eba5b6SRobert Mustacchi 		mac->get_link_status = TRUE;
54975eba5b6SRobert Mustacchi 
55075eba5b6SRobert Mustacchi 	if (!mac->get_link_status)
55175eba5b6SRobert Mustacchi 		goto out;
55275eba5b6SRobert Mustacchi 
55375eba5b6SRobert Mustacchi 	/* if link status is down no point in checking to see if pf is up */
55475eba5b6SRobert Mustacchi 	if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
55575eba5b6SRobert Mustacchi 		goto out;
55675eba5b6SRobert Mustacchi 
55775eba5b6SRobert Mustacchi 	/* if the read failed it could just be a mailbox collision, best wait
55875eba5b6SRobert Mustacchi 	 * until we are called again and don't report an error */
55975eba5b6SRobert Mustacchi 	if (mbx->ops.read(hw, &in_msg, 1, 0))
56075eba5b6SRobert Mustacchi 		goto out;
56175eba5b6SRobert Mustacchi 
56275eba5b6SRobert Mustacchi 	/* if incoming message isn't clear to send we are waiting on response */
56375eba5b6SRobert Mustacchi 	if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
56475eba5b6SRobert Mustacchi 		/* message is not CTS and is NACK we have lost CTS status */
56575eba5b6SRobert Mustacchi 		if (in_msg & E1000_VT_MSGTYPE_NACK)
56675eba5b6SRobert Mustacchi 			ret_val = -E1000_ERR_MAC_INIT;
56775eba5b6SRobert Mustacchi 		goto out;
56875eba5b6SRobert Mustacchi 	}
56975eba5b6SRobert Mustacchi 
57075eba5b6SRobert Mustacchi 	/* at this point we know the PF is talking to us, check and see if
57175eba5b6SRobert Mustacchi 	 * we are still accepting timeout or if we had a timeout failure.
57275eba5b6SRobert Mustacchi 	 * if we failed then we will need to reinit */
57375eba5b6SRobert Mustacchi 	if (!mbx->timeout) {
57475eba5b6SRobert Mustacchi 		ret_val = -E1000_ERR_MAC_INIT;
57575eba5b6SRobert Mustacchi 		goto out;
57675eba5b6SRobert Mustacchi 	}
57775eba5b6SRobert Mustacchi 
57875eba5b6SRobert Mustacchi 	/* if we passed all the tests above then the link is up and we no
57975eba5b6SRobert Mustacchi 	 * longer need to check for link */
58075eba5b6SRobert Mustacchi 	mac->get_link_status = FALSE;
58175eba5b6SRobert Mustacchi 
58275eba5b6SRobert Mustacchi out:
58375eba5b6SRobert Mustacchi 	return ret_val;
58475eba5b6SRobert Mustacchi }
58575eba5b6SRobert Mustacchi 
586