set version to 1.3.0
[dpdk.git] / lib / librte_pmd_e1000 / e1000 / e1000_vf.c
index 8b81e4b..4d8f58b 100644 (file)
@@ -1,56 +1,55 @@
-/******************************************************************************
-
-  Copyright (c) 2001-2011, Intel Corporation 
-  All rights reserved.
-  
-  Redistribution and use in source and binary forms, with or without 
-  modification, are permitted provided that the following conditions are met:
-  
-   1. Redistributions of source code must retain the above copyright notice, 
-      this list of conditions and the following disclaimer.
-  
-   2. Redistributions in binary form must reproduce the above copyright 
-      notice, this list of conditions and the following disclaimer in the 
-      documentation and/or other materials provided with the distribution.
-  
-   3. Neither the name of the Intel Corporation nor the names of its 
-      contributors may be used to endorse or promote products derived from 
-      this software without specific prior written permission.
-  
-  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
-  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
-  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
-  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
-  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
-  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
-  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
-  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-  POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-/*$FreeBSD$*/
+/*******************************************************************************
+
+Copyright (c) 2001-2012, Intel Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of the Intel Corporation nor the names of its
+    contributors may be used to endorse or promote products derived from
+    this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+***************************************************************************/
 
 
 #include "e1000_api.h"
 
 
-static s32       e1000_init_phy_params_vf(struct e1000_hw *hw);
-static s32       e1000_init_nvm_params_vf(struct e1000_hw *hw);
-static void      e1000_release_vf(struct e1000_hw *hw);
-static s32       e1000_acquire_vf(struct e1000_hw *hw);
-static s32       e1000_setup_link_vf(struct e1000_hw *hw);
-static s32       e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
-static s32       e1000_init_mac_params_vf(struct e1000_hw *hw);
-static s32       e1000_check_for_link_vf(struct e1000_hw *hw);
-static s32       e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
-                                              u16 *duplex);
-static s32       e1000_init_hw_vf(struct e1000_hw *hw);
-static s32       e1000_reset_hw_vf(struct e1000_hw *hw);
-static void      e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
-static void      e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
-static s32       e1000_read_mac_addr_vf(struct e1000_hw *);
+STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
+STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
+STATIC void e1000_release_vf(struct e1000_hw *hw);
+STATIC s32 e1000_acquire_vf(struct e1000_hw *hw);
+STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw);
+STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
+STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
+STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw);
+STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
+                                    u16 *duplex);
+STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw);
+STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw);
+STATIC void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
+STATIC void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
+STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *);
 
 /**
  *  e1000_init_phy_params_vf - Inits PHY params
@@ -58,7 +57,7 @@ static s32       e1000_read_mac_addr_vf(struct e1000_hw *);
  *
  *  Doesn't do much - there's no PHY available to the VF.
  **/
-static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
+STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
 {
        DEBUGFUNC("e1000_init_phy_params_vf");
        hw->phy.type = e1000_phy_vf;
@@ -74,7 +73,7 @@ static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
  *
  *  Doesn't do much - there's no NVM available to the VF.
  **/
-static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
+STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
 {
        DEBUGFUNC("e1000_init_nvm_params_vf");
        hw->nvm.type = e1000_nvm_none;
@@ -88,7 +87,7 @@ static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
  *  e1000_init_mac_params_vf - Inits MAC params
  *  @hw: pointer to the HW structure
  **/
-static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
+STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
 {
        struct e1000_mac_info *mac = &hw->mac;
 
@@ -103,11 +102,11 @@ static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
        hw->phy.media_type = e1000_media_type_unknown;
 
        /* No ASF features for the VF driver */
-       mac->asf_firmware_present = FALSE;
+       mac->asf_firmware_present = false;
        /* ARC subsystem not supported */
-       mac->arc_subsystem_valid = FALSE;
+       mac->arc_subsystem_valid = false;
        /* Disable adaptive IFS mode so the generic funcs don't do anything */
-       mac->adaptive_ifs = FALSE;
+       mac->adaptive_ifs = false;
        /* VF's have no MTA Registers - PF feature only */
        mac->mta_reg_count = 128;
        /* VF's have no access to RAR entries  */
@@ -159,7 +158,7 @@ void e1000_init_function_pointers_vf(struct e1000_hw *hw)
  *  In addition, the MAC registers to access PHY/NVM don't exist so we don't
  *  even want any SW to attempt to use them.
  **/
-static s32 e1000_acquire_vf(struct e1000_hw *hw)
+STATIC s32 e1000_acquire_vf(struct e1000_hw *hw)
 {
        return -E1000_ERR_PHY;
 }
@@ -172,7 +171,7 @@ static s32 e1000_acquire_vf(struct e1000_hw *hw)
  *  In addition, the MAC registers to access PHY/NVM don't exist so we don't
  *  even want any SW to attempt to use them.
  **/
-static void e1000_release_vf(struct e1000_hw *hw)
+STATIC void e1000_release_vf(struct e1000_hw *hw)
 {
        return;
 }
@@ -183,7 +182,7 @@ static void e1000_release_vf(struct e1000_hw *hw)
  *
  *  Virtual functions cannot change link.
  **/
-static s32 e1000_setup_link_vf(struct e1000_hw *hw)
+STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw)
 {
        DEBUGFUNC("e1000_setup_link_vf");
 
@@ -196,7 +195,7 @@ static s32 e1000_setup_link_vf(struct e1000_hw *hw)
  *
  *  Virtual functions are not really on their own bus.
  **/
-static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
+STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
 {
        struct e1000_bus_info *bus = &hw->bus;
 
@@ -218,8 +217,8 @@ static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
  *  Since we cannot read the PHY and get accurate link info, we must rely upon
  *  the status register's data which is often stale and inaccurate.
  **/
-static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
-                                     u16 *duplex)
+STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
+                                    u16 *duplex)
 {
        s32 status;
 
@@ -255,7 +254,7 @@ static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
  *  VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
  *  This is all the reset we can perform on a VF.
  **/
-static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
+STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw)
 {
        struct e1000_mbx_info *mbx = &hw->mbx;
        u32 timeout = E1000_VF_INIT_TIMEOUT;
@@ -288,7 +287,7 @@ static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
                ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
                if (!ret_val) {
                        if (msgbuf[0] == (E1000_VF_RESET |
-                                               E1000_VT_MSGTYPE_ACK))
+                           E1000_VT_MSGTYPE_ACK))
                                memcpy(hw->mac.perm_addr, addr, 6);
                        else
                                ret_val = -E1000_ERR_MAC_INIT;
@@ -304,7 +303,7 @@ static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
  *
  *  Not much to do here except clear the PF Reset indication if there is one.
  **/
-static s32 e1000_init_hw_vf(struct e1000_hw *hw)
+STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw)
 {
        DEBUGFUNC("e1000_init_hw_vf");
 
@@ -320,7 +319,7 @@ static s32 e1000_init_hw_vf(struct e1000_hw *hw)
  *  @addr: pointer to the receive address
  *  @index receive address array register
  **/
-static void e1000_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index)
+STATIC void e1000_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index)
 {
        struct e1000_mbx_info *mbx = &hw->mbx;
        u32 msgbuf[3];
@@ -351,7 +350,7 @@ static void e1000_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index)
  *  Generates a multicast address hash value which is used to determine
  *  the multicast filter table array address and new table value.
  **/
-static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
+STATIC u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
 {
        u32 hash_value, hash_mask;
        u8 bit_shift = 0;
@@ -369,11 +368,22 @@ static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
                bit_shift++;
 
        hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
-                                 (((u16) mc_addr[5]) << bit_shift)));
+                                 (((u16) mc_addr[5]) << bit_shift)));
 
        return hash_value;
 }
 
+static void e1000_write_msg_read_ack(struct e1000_hw *hw,
+                                    u32 *msg, u16 size)
+{
+       struct e1000_mbx_info *mbx = &hw->mbx;
+       u32 retmsg[E1000_VFMAILBOX_SIZE];
+       s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
+
+       if (!retval)
+               mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
+}
+
 /**
  *  e1000_update_mc_addr_list_vf - Update Multicast addresses
  *  @hw: pointer to the HW structure
@@ -384,9 +394,8 @@ static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
  *  The caller must have a packed mc_addr_list of multicast addresses.
  **/
 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
-                                  u8 *mc_addr_list, u32 mc_addr_count)
+                                 u8 *mc_addr_list, u32 mc_addr_count)
 {
-       struct e1000_mbx_info *mbx = &hw->mbx;
        u32 msgbuf[E1000_VFMAILBOX_SIZE];
        u16 *hash_list = (u16 *)&msgbuf[1];
        u32 hash_value;
@@ -420,18 +429,17 @@ void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
                mc_addr_list += ETH_ADDR_LEN;
        }
 
-       mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE, 0);
+       e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
 }
 
 /**
  *  e1000_vfta_set_vf - Set/Unset vlan filter table address
  *  @hw: pointer to the HW structure
  *  @vid: determines the vfta register and bit to set/unset
- *  @set: if TRUE then set bit, else clear bit
+ *  @set: if true then set bit, else clear bit
  **/
 void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
 {
-       struct e1000_mbx_info *mbx = &hw->mbx;
        u32 msgbuf[2];
 
        msgbuf[0] = E1000_VF_SET_VLAN;
@@ -440,7 +448,7 @@ void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
        if (set)
                msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
 
-       mbx->ops.write_posted(hw, msgbuf, 2, 0);
+       e1000_write_msg_read_ack(hw, msgbuf, 2);
 }
 
 /** e1000_rlpml_set_vf - Set the maximum receive packet length
@@ -449,13 +457,12 @@ void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
  **/
 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
 {
-       struct e1000_mbx_info *mbx = &hw->mbx;
        u32 msgbuf[2];
 
        msgbuf[0] = E1000_VF_SET_LPE;
        msgbuf[1] = max_size;
 
-       mbx->ops.write_posted(hw, msgbuf, 2, 0);
+       e1000_write_msg_read_ack(hw, msgbuf, 2);
 }
 
 /**
@@ -499,7 +506,7 @@ s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
  *  e1000_read_mac_addr_vf - Read device MAC address
  *  @hw: pointer to the HW structure
  **/
-static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
+STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
 {
        int i;
 
@@ -517,7 +524,7 @@ static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
  *  if it is then it reports the link state to the hardware, otherwise
  *  it reports link down and returns an error.
  **/
-static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
+STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw)
 {
        struct e1000_mbx_info *mbx = &hw->mbx;
        struct e1000_mac_info *mac = &hw->mac;
@@ -534,7 +541,7 @@ static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
 
        /* If we were hit with a reset or timeout drop the link */
        if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
-               mac->get_link_status = TRUE;
+               mac->get_link_status = true;
 
        if (!mac->get_link_status)
                goto out;
@@ -566,7 +573,7 @@ static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
 
        /* if we passed all the tests above then the link is up and we no
         * longer need to check for link */
-       mac->get_link_status = FALSE;
+       mac->get_link_status = false;
 
 out:
        return ret_val;