iPXE
igbvf_vf.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003   Intel(R) 82576 Virtual Function Linux driver
00004   Copyright(c) 1999 - 2008 Intel Corporation.
00005 
00006   This program is free software; you can redistribute it and/or modify it
00007   under the terms and conditions of the GNU General Public License,
00008   version 2, as published by the Free Software Foundation.
00009 
00010   This program is distributed in the hope it will be useful, but WITHOUT
00011   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013   more details.
00014 
00015   You should have received a copy of the GNU General Public License along with
00016   this program; if not, write to the Free Software Foundation, Inc.,
00017   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019   The full GNU General Public License is included in this distribution in
00020   the file called "COPYING".
00021 
00022   Contact Information:
00023   Linux NICS <linux.nics@intel.com>
00024   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
00025   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
00026 
00027 *******************************************************************************/
00028 
00029 FILE_LICENCE ( GPL2_ONLY );
00030 
00031 #include "igbvf_vf.h"
00032 
00033 
00034 static s32       igbvf_init_mac_params_vf(struct e1000_hw *hw);
00035 static s32       igbvf_check_for_link_vf(struct e1000_hw *hw);
00036 static s32       igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
00037                                               u16 *duplex);
00038 static s32       igbvf_init_hw_vf(struct e1000_hw *hw);
00039 static s32       igbvf_reset_hw_vf(struct e1000_hw *hw);
00040 static void      igbvf_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
00041 static void      igbvf_rar_set_vf(struct e1000_hw *, u8 *, u32);
00042 static s32       igbvf_read_mac_addr_vf(struct e1000_hw *);
00043 
00044 /**
00045  *  igbvf_init_mac_params_vf - Inits MAC params
00046  *  @hw: pointer to the HW structure
00047  **/
00048 static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw)
00049 {
00050         struct e1000_mac_info *mac = &hw->mac;
00051 
00052         DEBUGFUNC("igbvf_init_mac_params_vf");
00053 
00054         /* VF's have no MTA Registers - PF feature only */
00055         mac->mta_reg_count = 128;
00056         /* VF's have no access to RAR entries  */
00057         mac->rar_entry_count = 1;
00058 
00059         /* Function pointers */
00060         /* reset */
00061         mac->ops.reset_hw = igbvf_reset_hw_vf;
00062         /* hw initialization */
00063         mac->ops.init_hw = igbvf_init_hw_vf;
00064         /* check for link */
00065         mac->ops.check_for_link = igbvf_check_for_link_vf;
00066         /* link info */
00067         mac->ops.get_link_up_info = igbvf_get_link_up_info_vf;
00068         /* multicast address update */
00069         mac->ops.update_mc_addr_list = igbvf_update_mc_addr_list_vf;
00070         /* set mac address */
00071         mac->ops.rar_set = igbvf_rar_set_vf;
00072         /* read mac address */
00073         mac->ops.read_mac_addr = igbvf_read_mac_addr_vf;
00074 
00075 
00076         return E1000_SUCCESS;
00077 }
00078 
00079 /**
00080  *  igbvf_init_function_pointers_vf - Inits function pointers
00081  *  @hw: pointer to the HW structure
00082  **/
00083 void igbvf_init_function_pointers_vf(struct e1000_hw *hw)
00084 {
00085         DEBUGFUNC("igbvf_init_function_pointers_vf");
00086 
00087         hw->mac.ops.init_params = igbvf_init_mac_params_vf;
00088         hw->mbx.ops.init_params = igbvf_init_mbx_params_vf;
00089 }
00090 
00091 /**
00092  *  igbvf_get_link_up_info_vf - Gets link info.
00093  *  @hw: pointer to the HW structure
00094  *  @speed: pointer to 16 bit value to store link speed.
00095  *  @duplex: pointer to 16 bit value to store duplex.
00096  *
00097  *  Since we cannot read the PHY and get accurate link info, we must rely upon
00098  *  the status register's data which is often stale and inaccurate.
00099  **/
00100 static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
00101                                      u16 *duplex)
00102 {
00103         s32 status;
00104 
00105         DEBUGFUNC("igbvf_get_link_up_info_vf");
00106 
00107         status = E1000_READ_REG(hw, E1000_STATUS);
00108         if (status & E1000_STATUS_SPEED_1000) {
00109                 *speed = SPEED_1000;
00110                 DEBUGOUT("1000 Mbs, ");
00111         } else if (status & E1000_STATUS_SPEED_100) {
00112                 *speed = SPEED_100;
00113                 DEBUGOUT("100 Mbs, ");
00114         } else {
00115                 *speed = SPEED_10;
00116                 DEBUGOUT("10 Mbs, ");
00117         }
00118 
00119         if (status & E1000_STATUS_FD) {
00120                 *duplex = FULL_DUPLEX;
00121                 DEBUGOUT("Full Duplex\n");
00122         } else {
00123                 *duplex = HALF_DUPLEX;
00124                 DEBUGOUT("Half Duplex\n");
00125         }
00126 
00127         return E1000_SUCCESS;
00128 }
00129 
00130 /**
00131  *  igbvf_reset_hw_vf - Resets the HW
00132  *  @hw: pointer to the HW structure
00133  *
00134  *  VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
00135  *  This is all the reset we can perform on a VF.
00136  **/
00137 static s32 igbvf_reset_hw_vf(struct e1000_hw *hw)
00138 {
00139         struct e1000_mbx_info *mbx = &hw->mbx;
00140         u32 timeout = E1000_VF_INIT_TIMEOUT;
00141         s32 ret_val = -E1000_ERR_MAC_INIT;
00142         u32 ctrl, msgbuf[3];
00143         u8 *addr = (u8 *)(&msgbuf[1]);
00144 
00145         DEBUGFUNC("igbvf_reset_hw_vf");
00146 
00147         DEBUGOUT("Issuing a function level reset to MAC\n");
00148         ctrl = E1000_READ_REG(hw, E1000_CTRL);
00149         E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
00150 
00151         /* we cannot reset while the RSTI / RSTD bits are asserted */
00152         while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
00153                 timeout--;
00154                 usec_delay(5);
00155         }
00156 
00157         if (timeout) {
00158                 /* mailbox timeout can now become active */
00159                 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
00160 
00161                 msgbuf[0] = E1000_VF_RESET;
00162                 mbx->ops.write_posted(hw, msgbuf, 1, 0);
00163 
00164                 msec_delay(10);
00165 
00166                 /* set our "perm_addr" based on info provided by PF */
00167                 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
00168                 if (!ret_val) {
00169                         if (msgbuf[0] == (E1000_VF_RESET |
00170                                                 E1000_VT_MSGTYPE_ACK))
00171                                 memcpy(hw->mac.perm_addr, addr, 6);
00172                         else
00173                                 ret_val = -E1000_ERR_MAC_INIT;
00174                 }
00175         }
00176 
00177         return ret_val;
00178 }
00179 
00180 /**
00181  *  igbvf_init_hw_vf - Inits the HW
00182  *  @hw: pointer to the HW structure
00183  *
00184  *  Not much to do here except clear the PF Reset indication if there is one.
00185  **/
00186 static s32 igbvf_init_hw_vf(struct e1000_hw *hw)
00187 {
00188         DEBUGFUNC("igbvf_init_hw_vf");
00189 
00190         /* attempt to set and restore our mac address */
00191         igbvf_rar_set_vf(hw, hw->mac.addr, 0);
00192 
00193         return E1000_SUCCESS;
00194 }
00195 
00196 /**
00197  *  igbvf_rar_set_vf - set device MAC address
00198  *  @hw: pointer to the HW structure
00199  *  @addr: pointer to the receive address
00200  *  @index receive address array register
00201  **/
00202 static void igbvf_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index __unused)
00203 {
00204         struct e1000_mbx_info *mbx = &hw->mbx;
00205         u32 msgbuf[3];
00206         u8 *msg_addr = (u8 *)(&msgbuf[1]);
00207         s32 ret_val;
00208 
00209         memset(msgbuf, 0, 12);
00210         msgbuf[0] = E1000_VF_SET_MAC_ADDR;
00211         memcpy(msg_addr, addr, 6);
00212         ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
00213 
00214         if (!ret_val)
00215                 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
00216 
00217         msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
00218 
00219         /* if nacked the address was rejected, use "perm_addr" */
00220         if (!ret_val &&
00221             (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
00222                 igbvf_read_mac_addr_vf(hw);
00223 }
00224 
00225 /**
00226  *  igbvf_hash_mc_addr_vf - Generate a multicast hash value
00227  *  @hw: pointer to the HW structure
00228  *  @mc_addr: pointer to a multicast address
00229  *
00230  *  Generates a multicast address hash value which is used to determine
00231  *  the multicast filter table array address and new table value.  See
00232  *  igbvf_mta_set_generic()
00233  **/
00234 static u32 igbvf_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
00235 {
00236         u32 hash_value, hash_mask;
00237         u8 bit_shift = 0;
00238 
00239         DEBUGFUNC("igbvf_hash_mc_addr_generic");
00240 
00241         /* Register count multiplied by bits per register */
00242         hash_mask = (hw->mac.mta_reg_count * 32) - 1;
00243 
00244         /*
00245          * The bit_shift is the number of left-shifts
00246          * where 0xFF would still fall within the hash mask.
00247          */
00248         while (hash_mask >> bit_shift != 0xFF)
00249                 bit_shift++;
00250 
00251         hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
00252                                   (((u16) mc_addr[5]) << bit_shift)));
00253 
00254         return hash_value;
00255 }
00256 
00257 /**
00258  *  igbvf_update_mc_addr_list_vf - Update Multicast addresses
00259  *  @hw: pointer to the HW structure
00260  *  @mc_addr_list: array of multicast addresses to program
00261  *  @mc_addr_count: number of multicast addresses to program
00262  *
00263  *  Updates the Multicast Table Array.
00264  *  The caller must have a packed mc_addr_list of multicast addresses.
00265  **/
00266 void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw,
00267                                   u8 *mc_addr_list, u32 mc_addr_count)
00268 {
00269         struct e1000_mbx_info *mbx = &hw->mbx;
00270         u32 msgbuf[E1000_VFMAILBOX_SIZE];
00271         u16 *hash_list = (u16 *)&msgbuf[1];
00272         u32 hash_value;
00273         u32 i;
00274 
00275         DEBUGFUNC("igbvf_update_mc_addr_list_vf");
00276 
00277         /* Each entry in the list uses 1 16 bit word.  We have 30
00278          * 16 bit words available in our HW msg buffer (minus 1 for the
00279          * msg type).  That's 30 hash values if we pack 'em right.  If
00280          * there are more than 30 MC addresses to add then punt the
00281          * extras for now and then add code to handle more than 30 later.
00282          * It would be unusual for a server to request that many multi-cast
00283          * addresses except for in large enterprise network environments.
00284          */
00285 
00286         DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
00287 
00288         msgbuf[0] = E1000_VF_SET_MULTICAST;
00289 
00290         if (mc_addr_count > 30) {
00291                 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
00292                 mc_addr_count = 30;
00293         }
00294 
00295         msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
00296 
00297         for (i = 0; i < mc_addr_count; i++) {
00298                 hash_value = igbvf_hash_mc_addr_vf(hw, mc_addr_list);
00299                 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
00300                 hash_list[i] = hash_value & 0x0FFF;
00301                 mc_addr_list += ETH_ADDR_LEN;
00302         }
00303 
00304         mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE, 0);
00305 }
00306 
00307 /**
00308  *  igbvf_vfta_set_vf - Set/Unset vlan filter table address
00309  *  @hw: pointer to the HW structure
00310  *  @vid: determines the vfta register and bit to set/unset
00311  *  @set: if true then set bit, else clear bit
00312  **/
00313 void igbvf_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
00314 {
00315         struct e1000_mbx_info *mbx = &hw->mbx;
00316         u32 msgbuf[2];
00317 
00318         msgbuf[0] = E1000_VF_SET_VLAN;
00319         msgbuf[1] = vid;
00320         /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
00321         if (set)
00322                 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
00323 
00324         mbx->ops.write_posted(hw, msgbuf, 2, 0);
00325 }
00326 
00327 /** igbvf_rlpml_set_vf - Set the maximum receive packet length
00328  *  @hw: pointer to the HW structure
00329  *  @max_size: value to assign to max frame size
00330  **/
00331 void igbvf_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
00332 {
00333         struct e1000_mbx_info *mbx = &hw->mbx;
00334         u32 msgbuf[2];
00335 
00336         msgbuf[0] = E1000_VF_SET_LPE;
00337         msgbuf[1] = max_size;
00338 
00339         mbx->ops.write_posted(hw, msgbuf, 2, 0);
00340 }
00341 
00342 /**
00343  *  igbvf_promisc_set_vf - Set flags for Unicast or Multicast promisc
00344  *  @hw: pointer to the HW structure
00345  *  @uni: boolean indicating unicast promisc status
00346  *  @multi: boolean indicating multicast promisc status
00347  **/
00348 s32 igbvf_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
00349 {
00350         struct e1000_mbx_info *mbx = &hw->mbx;
00351         u32 msgbuf = E1000_VF_SET_PROMISC;
00352         s32 ret_val;
00353 
00354         switch (type) {
00355         case e1000_promisc_multicast:
00356                 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
00357                 break;
00358         case e1000_promisc_enabled:
00359                 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
00360                 /* Fall through */
00361         case e1000_promisc_unicast:
00362                 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
00363         case e1000_promisc_disabled:
00364                 break;
00365         default:
00366                 return -E1000_ERR_MAC_INIT;
00367         }
00368 
00369          ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
00370 
00371         if (!ret_val)
00372                 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
00373 
00374         if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
00375                 ret_val = -E1000_ERR_MAC_INIT;
00376 
00377         return ret_val;
00378 }
00379 
00380 /**
00381  *  igbvf_read_mac_addr_vf - Read device MAC address
00382  *  @hw: pointer to the HW structure
00383  **/
00384 static s32 igbvf_read_mac_addr_vf(struct e1000_hw *hw)
00385 {
00386         int i;
00387 
00388         for (i = 0; i < ETH_ADDR_LEN; i++)
00389                 hw->mac.addr[i] = hw->mac.perm_addr[i];
00390 
00391         return E1000_SUCCESS;
00392 }
00393 
00394 /**
00395  *  igbvf_check_for_link_vf - Check for link for a virtual interface
00396  *  @hw: pointer to the HW structure
00397  *
00398  *  Checks to see if the underlying PF is still talking to the VF and
00399  *  if it is then it reports the link state to the hardware, otherwise
00400  *  it reports link down and returns an error.
00401  **/
00402 static s32 igbvf_check_for_link_vf(struct e1000_hw *hw)
00403 {
00404         struct e1000_mbx_info *mbx = &hw->mbx;
00405         struct e1000_mac_info *mac = &hw->mac;
00406         s32 ret_val = E1000_SUCCESS;
00407         u32 in_msg = 0;
00408 
00409         DEBUGFUNC("igbvf_check_for_link_vf");
00410 
00411         /*
00412          * We only want to run this if there has been a rst asserted.
00413          * in this case that could mean a link change, device reset,
00414          * or a virtual function reset
00415          */
00416 
00417         /* If we were hit with a reset drop the link */
00418         if (!mbx->ops.check_for_rst(hw, 0))
00419                 mac->get_link_status = true;
00420 
00421         if (!mac->get_link_status)
00422                 goto out;
00423 
00424         /* if link status is down no point in checking to see if pf is up */
00425         if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
00426                 goto out;
00427 
00428         /* if the read failed it could just be a mailbox collision, best wait
00429          * until we are called again and don't report an error */
00430         if (mbx->ops.read(hw, &in_msg, 1, 0))
00431                 goto out;
00432 
00433         /* if incoming message isn't clear to send we are waiting on response */
00434         if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
00435                 /* message is not CTS and is NACK we have lost CTS status */
00436                 if (in_msg & E1000_VT_MSGTYPE_NACK)
00437                         ret_val = -E1000_ERR_MAC_INIT;
00438                 goto out;
00439         }
00440 
00441         /* at this point we know the PF is talking to us, check and see if
00442          * we are still accepting timeout or if we had a timeout failure.
00443          * if we failed then we will need to reinit */
00444         if (!mbx->timeout) {
00445                 ret_val = -E1000_ERR_MAC_INIT;
00446                 goto out;
00447         }
00448 
00449         /* if we passed all the tests above then the link is up and we no
00450          * longer need to check for link */
00451         mac->get_link_status = false;
00452 
00453 out:
00454         return ret_val;
00455 }
00456