qed*: Add support for ndo_set_vf_trust
authorMintz, Yuval <Yuval.Mintz@cavium.com>
Sun, 1 Jan 2017 11:57:08 +0000 (13:57 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 2 Jan 2017 02:02:14 +0000 (21:02 -0500)
Trusted VFs would be allowed to receive promiscuous and
multicast promiscuous data.

Signed-off-by: Yuval Mintz <Yuval.Mintz@cavium.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qed/qed_sriov.c
drivers/net/ethernet/qlogic/qed/qed_sriov.h
drivers/net/ethernet/qlogic/qede/qede_filter.c
drivers/net/ethernet/qlogic/qede/qede_main.c
include/linux/qed/qed_iov_if.h

index b22baf5e5daf861ecaf164f1df607e975d7cdc4e..b1213643bbfdd95a21c0b9624c396fe832d1facb 100644 (file)
@@ -1225,6 +1225,9 @@ static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
 
        /* Clear the VF mac */
        memset(vf_info->mac, 0, ETH_ALEN);
+
+       vf_info->rx_accept_mode = 0;
+       vf_info->tx_accept_mode = 0;
 }
 
 static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
@@ -2433,6 +2436,39 @@ qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
        *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
 }
 
+static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
+                                   u8 vfid,
+                                   struct qed_sp_vport_update_params *params,
+                                   u16 *tlvs)
+{
+       u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
+       struct qed_filter_accept_flags *flags = &params->accept_flags;
+       struct qed_public_vf_info *vf_info;
+
+       /* Untrusted VFs can't even be trusted to know that fact.
+        * Simply indicate everything is configured fine, and trace
+        * configuration 'behind their back'.
+        */
+       if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
+               return 0;
+
+       vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
+
+       if (flags->update_rx_mode_config) {
+               vf_info->rx_accept_mode = flags->rx_accept_filter;
+               if (!vf_info->is_trusted_configured)
+                       flags->rx_accept_filter &= ~mask;
+       }
+
+       if (flags->update_tx_mode_config) {
+               vf_info->tx_accept_mode = flags->tx_accept_filter;
+               if (!vf_info->is_trusted_configured)
+                       flags->tx_accept_filter &= ~mask;
+       }
+
+       return 0;
+}
+
 static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
                                        struct qed_ptt *p_ptt,
                                        struct qed_vf_info *vf)
@@ -2487,6 +2523,13 @@ static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
        qed_iov_vp_update_rss_param(p_hwfn, vf, &params, p_rss_params,
                                    mbx, &tlvs_mask, &tlvs_accepted);
 
+       if (qed_iov_pre_update_vport(p_hwfn, vf->relative_vf_id,
+                                    &params, &tlvs_accepted)) {
+               tlvs_accepted = 0;
+               status = PFVF_STATUS_NOT_SUPPORTED;
+               goto out;
+       }
+
        if (!tlvs_accepted) {
                if (tlvs_mask)
                        DP_VERBOSE(p_hwfn, QED_MSG_IOV,
@@ -3936,6 +3979,32 @@ static int qed_set_vf_rate(struct qed_dev *cdev,
        return 0;
 }
 
+static int qed_set_vf_trust(struct qed_dev *cdev, int vfid, bool trust)
+{
+       int i;
+
+       for_each_hwfn(cdev, i) {
+               struct qed_hwfn *hwfn = &cdev->hwfns[i];
+               struct qed_public_vf_info *vf;
+
+               if (!qed_iov_pf_sanity_check(hwfn, vfid)) {
+                       DP_NOTICE(hwfn,
+                                 "SR-IOV sanity check failed, can't set trust\n");
+                       return -EINVAL;
+               }
+
+               vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
+
+               if (vf->is_trusted_request == trust)
+                       return 0;
+               vf->is_trusted_request = trust;
+
+               qed_schedule_iov(hwfn, QED_IOV_WQ_TRUST_FLAG);
+       }
+
+       return 0;
+}
+
 static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
 {
        u64 events[QED_VF_ARRAY_LENGTH];
@@ -4040,6 +4109,61 @@ static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
        qed_ptt_release(hwfn, ptt);
 }
 
+static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
+{
+       struct qed_sp_vport_update_params params;
+       struct qed_filter_accept_flags *flags;
+       struct qed_public_vf_info *vf_info;
+       struct qed_vf_info *vf;
+       u8 mask;
+       int i;
+
+       mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
+       flags = &params.accept_flags;
+
+       qed_for_each_vf(hwfn, i) {
+               /* Need to make sure current requested configuration didn't
+                * flip so that we'll end up configuring something that's not
+                * needed.
+                */
+               vf_info = qed_iov_get_public_vf_info(hwfn, i, true);
+               if (vf_info->is_trusted_configured ==
+                   vf_info->is_trusted_request)
+                       continue;
+               vf_info->is_trusted_configured = vf_info->is_trusted_request;
+
+               /* Validate that the VF has a configured vport */
+               vf = qed_iov_get_vf_info(hwfn, i, true);
+               if (!vf->vport_instance)
+                       continue;
+
+               memset(&params, 0, sizeof(params));
+               params.opaque_fid = vf->opaque_fid;
+               params.vport_id = vf->vport_id;
+
+               if (vf_info->rx_accept_mode & mask) {
+                       flags->update_rx_mode_config = 1;
+                       flags->rx_accept_filter = vf_info->rx_accept_mode;
+               }
+
+               if (vf_info->tx_accept_mode & mask) {
+                       flags->update_tx_mode_config = 1;
+                       flags->tx_accept_filter = vf_info->tx_accept_mode;
+               }
+
+               /* Remove if needed; Otherwise this would set the mask */
+               if (!vf_info->is_trusted_configured) {
+                       flags->rx_accept_filter &= ~mask;
+                       flags->tx_accept_filter &= ~mask;
+               }
+
+               if (flags->update_rx_mode_config ||
+                   flags->update_tx_mode_config)
+                       qed_sp_vport_update(hwfn, &params,
+                                           QED_SPQ_MODE_EBLOCK, NULL);
+       }
+}
+
 static void qed_iov_pf_task(struct work_struct *work)
 
 {
@@ -4075,6 +4199,9 @@ static void qed_iov_pf_task(struct work_struct *work)
        if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
                               &hwfn->iov_task_flags))
                qed_handle_bulletin_post(hwfn);
+
+       if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG, &hwfn->iov_task_flags))
+               qed_iov_handle_trust_change(hwfn);
 }
 
 void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
@@ -4137,4 +4264,5 @@ const struct qed_iov_hv_ops qed_iov_ops_pass = {
        .set_link_state = &qed_set_vf_link_state,
        .set_spoof = &qed_spoof_configure,
        .set_rate = &qed_set_vf_rate,
+       .set_trust = &qed_set_vf_trust,
 };
index 1738d5bd2e8e504dd6c8d8f3bbb2590887248e36..0a2e3a36d2cf6341d2a8dddc10c1ba2199fca119 100644 (file)
@@ -80,6 +80,14 @@ struct qed_public_vf_info {
 
        /* Currently configured Tx rate in MB/sec. 0 if unconfigured */
        int tx_rate;
+
+       /* Trusted VFs can configure promiscuous mode.
+        * Also store shadow promisc configuration if needed.
+        */
+       bool is_trusted_configured;
+       bool is_trusted_request;
+       u8 rx_accept_mode;
+       u8 tx_accept_mode;
 };
 
 struct qed_iov_vf_init_params {
@@ -245,6 +253,7 @@ enum qed_iov_wq_flag {
        QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
        QED_IOV_WQ_STOP_WQ_FLAG,
        QED_IOV_WQ_FLR_FLAG,
+       QED_IOV_WQ_TRUST_FLAG,
 };
 
 #ifdef CONFIG_QED_SRIOV
index 03e2a81b30c6fd84516290b09c228a33239dc6bc..107c3fda4792c3b7f2fb83168f192b1aef35fc70 100644 (file)
@@ -714,11 +714,13 @@ void qede_config_rx_mode(struct net_device *ndev)
                goto out;
 
        /* Check for promiscuous */
-       if ((ndev->flags & IFF_PROMISC) ||
-           (uc_count > edev->dev_info.num_mac_filters - 1)) {
+       if (ndev->flags & IFF_PROMISC)
                accept_flags = QED_FILTER_RX_MODE_TYPE_PROMISC;
-       } else {
-               /* Add MAC filters according to the unicast secondary macs */
+       else
+               accept_flags = QED_FILTER_RX_MODE_TYPE_REGULAR;
+
+       /* Configure all filters regardless, in case promisc is rejected */
+       if (uc_count < edev->dev_info.num_mac_filters) {
                int i;
 
                temp = uc_macs;
@@ -731,12 +733,14 @@ void qede_config_rx_mode(struct net_device *ndev)
 
                        temp += ETH_ALEN;
                }
-
-               rc = qede_configure_mcast_filtering(ndev, &accept_flags);
-               if (rc)
-                       goto out;
+       } else {
+               accept_flags = QED_FILTER_RX_MODE_TYPE_PROMISC;
        }
 
+       rc = qede_configure_mcast_filtering(ndev, &accept_flags);
+       if (rc)
+               goto out;
+
        /* take care of VLAN mode */
        if (ndev->flags & IFF_PROMISC) {
                qede_config_accept_any_vlan(edev, true);
index 88d47d6f35ac9bf15691625f8caa16937f13e11f..b58509feecd5b7447860c79f5d7472e6e8d46384 100644 (file)
@@ -475,6 +475,16 @@ static int qede_set_vf_link_state(struct net_device *dev, int vfidx,
 
        return edev->ops->iov->set_link_state(edev->cdev, vfidx, link_state);
 }
+
+static int qede_set_vf_trust(struct net_device *dev, int vfidx, bool setting)
+{
+       struct qede_dev *edev = netdev_priv(dev);
+
+       if (!edev->ops)
+               return -EINVAL;
+
+       return edev->ops->iov->set_trust(edev->cdev, vfidx, setting);
+}
 #endif
 
 static const struct net_device_ops qede_netdev_ops = {
@@ -488,6 +498,7 @@ static const struct net_device_ops qede_netdev_ops = {
 #ifdef CONFIG_QED_SRIOV
        .ndo_set_vf_mac = qede_set_vf_mac,
        .ndo_set_vf_vlan = qede_set_vf_vlan,
+       .ndo_set_vf_trust = qede_set_vf_trust,
 #endif
        .ndo_vlan_rx_add_vid = qede_vlan_rx_add_vid,
        .ndo_vlan_rx_kill_vid = qede_vlan_rx_kill_vid,
index b1f979135f9739606d7e2aff981727b659c751de..ac2e6a3199a36c88eca3e8126bab85500e37fd98 100644 (file)
@@ -53,6 +53,8 @@ struct qed_iov_hv_ops {
 
        int (*set_rate) (struct qed_dev *cdev, int vfid,
                         u32 min_rate, u32 max_rate);
+
+       int (*set_trust) (struct qed_dev *cdev, int vfid, bool trust);
 };
 
 #endif