fm10k/base: fix VF multicast
authorWang Xiao W <xiao.w.wang@intel.com>
Thu, 10 Sep 2015 04:38:27 +0000 (12:38 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 7 Oct 2015 11:25:07 +0000 (13:25 +0200)
The VF will send a message to request multicast addresses with the
default vid. In the current code, if the PF has statically assigned a
VLAN to a VF, then the VF will not get the multicast addresses. Fix up
all of the various vlan messages to use identical checks (since each
check was different). Also use set as a variable, so that it simplifies
our check for whether vlan matches the pf_vid.

The new logic will allow set of a vlan if it is zero, automatically
converting to the default vid. Otherwise it will allow setting the PF
vid, or any VLAN if PF has not statically assigned a VLAN. This is
consistent behavior, and allows VF to request either 0 or the
default_vid without silently failing. Note that we need the check for
zero since VFs might not get the default VID message in time to actually
request non-zero VLANs.

Create a function, fm10k_iov_select_vid which implements the logic for
selecting a default vid. This helps us remove duplicate code and
streamlines location of this logic so that we don't make similar bugs in
the future.

Signed-off-by: Wang Xiao W <xiao.w.wang@intel.com>
drivers/net/fm10k/base/fm10k_pf.c

index 29ef6a9..9ed47a9 100644 (file)
@@ -1218,6 +1218,24 @@ s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
        return hw->iov.ops.assign_int_moderator(hw, vf_idx);
 }
 
+/**
+ * fm10k_iov_select_vid - Select correct default vid
+ * @hw: Pointer to hardware structure
+ * @vid: vid to correct
+ *
+ * Will report an error if vid is out of range. For vid = 0, it will return
+ * either the pf_vid or sw_vid depending on which one is set.
+ */
+STATIC s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid)
+{
+       if (!vid)
+               return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
+       else if (vf_info->pf_vid && vid != vf_info->pf_vid)
+               return FM10K_ERR_PARAM;
+       else
+               return vid;
+}
+
 /**
  *  fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
  *  @hw: Pointer to hardware structure
@@ -1235,6 +1253,7 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
        int err = FM10K_SUCCESS;
        u8 mac[ETH_ALEN];
        u32 *result;
+       bool set;
        u16 vlan;
        u32 vid;
 
@@ -1252,19 +1271,21 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
                if (err)
                        return err;
 
-               /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-               if (!vid || (vid == FM10K_VLAN_CLEAR)) {
-                       if (vf_info->pf_vid)
-                               vid |= vf_info->pf_vid;
-                       else
-                               vid |= vf_info->sw_vid;
-               } else if (vid != vf_info->pf_vid) {
+               /* verify upper 16 bits are zero */
+               if (vid >> 16)
                        return FM10K_ERR_PARAM;
-               }
+
+               set = !(vid & FM10K_VLAN_CLEAR);
+               vid &= ~FM10K_VLAN_CLEAR;
+
+               err = fm10k_iov_select_vid(vf_info, (u16)vid);
+               if (err < 0)
+                       return err;
+               else
+                       vid = err;
 
                /* update VSI info for VF in regards to VLAN table */
-               err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi,
-                                             !(vid & FM10K_VLAN_CLEAR));
+               err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
        }
 
        if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
@@ -1280,19 +1301,18 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
                    memcmp(mac, vf_info->mac, ETH_ALEN))
                        return FM10K_ERR_PARAM;
 
-               /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-               if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
-                       if (vf_info->pf_vid)
-                               vlan |= vf_info->pf_vid;
-                       else
-                               vlan |= vf_info->sw_vid;
-               } else if (vf_info->pf_vid) {
-                       return FM10K_ERR_PARAM;
-               }
+               set = !(vlan & FM10K_VLAN_CLEAR);
+               vlan &= ~FM10K_VLAN_CLEAR;
+
+               err = fm10k_iov_select_vid(vf_info, vlan);
+               if (err < 0)
+                       return err;
+               else
+                       vlan = (u16)err;
 
                /* notify switch of request for new unicast address */
-               err = hw->mac.ops.update_uc_addr(hw, vf_info->glort, mac, vlan,
-                                                !(vlan & FM10K_VLAN_CLEAR), 0);
+               err = hw->mac.ops.update_uc_addr(hw, vf_info->glort,
+                                                mac, vlan, set, 0);
        }
 
        if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
@@ -1307,19 +1327,18 @@ s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
                if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
                        return FM10K_ERR_PARAM;
 
-               /* if VLAN ID is 0, set the default VLAN ID instead of 0 */
-               if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
-                       if (vf_info->pf_vid)
-                               vlan |= vf_info->pf_vid;
-                       else
-                               vlan |= vf_info->sw_vid;
-               } else if (vf_info->pf_vid) {
-                       return FM10K_ERR_PARAM;
-               }
+               set = !(vlan & FM10K_VLAN_CLEAR);
+               vlan &= ~FM10K_VLAN_CLEAR;
+
+               err = fm10k_iov_select_vid(vf_info, vlan);
+               if (err < 0)
+                       return err;
+               else
+                       vlan = (u16)err;
 
                /* notify switch of request for new multicast address */
-               err = hw->mac.ops.update_mc_addr(hw, vf_info->glort, mac, vlan,
-                                                !(vlan & FM10K_VLAN_CLEAR));
+               err = hw->mac.ops.update_mc_addr(hw, vf_info->glort,
+                                                mac, vlan, set);
        }
 
        return err;