OSDN Git Service

nfp: add SR-IOV trusted VF support
authorPablo Cascón <pablo.cascon@netronome.com>
Sat, 20 Apr 2019 00:20:09 +0000 (17:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 20 Apr 2019 04:00:31 +0000 (21:00 -0700)
By default VFs are not trusted. Add ndo_set_vf_trust support to toggle
a new per-VF bit. Coupled with FW with this capability allows a
trusted VF to change its MAC even after being administratively set by
the PF. Also populate the trusted field on ndo_get_vf_config. Add the
same ndo to the representors.

Signed-off-by: Pablo Cascón <pablo.cascon@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfp_net_common.c
drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
drivers/net/ethernet/netronome/nfp/nfp_net_sriov.c
drivers/net/ethernet/netronome/nfp/nfp_net_sriov.h

index 58657fe..b82b684 100644 (file)
@@ -3590,6 +3590,7 @@ const struct net_device_ops nfp_net_netdev_ops = {
        .ndo_set_vf_mac         = nfp_app_set_vf_mac,
        .ndo_set_vf_vlan        = nfp_app_set_vf_vlan,
        .ndo_set_vf_spoofchk    = nfp_app_set_vf_spoofchk,
+       .ndo_set_vf_trust       = nfp_app_set_vf_trust,
        .ndo_get_vf_config      = nfp_app_get_vf_config,
        .ndo_set_vf_link_state  = nfp_app_set_vf_link_state,
        .ndo_setup_tc           = nfp_port_setup_tc,
index 08e9bfa..036edcc 100644 (file)
@@ -267,6 +267,7 @@ const struct net_device_ops nfp_repr_netdev_ops = {
        .ndo_set_vf_mac         = nfp_app_set_vf_mac,
        .ndo_set_vf_vlan        = nfp_app_set_vf_vlan,
        .ndo_set_vf_spoofchk    = nfp_app_set_vf_spoofchk,
+       .ndo_set_vf_trust       = nfp_app_set_vf_trust,
        .ndo_get_vf_config      = nfp_app_get_vf_config,
        .ndo_set_vf_link_state  = nfp_app_set_vf_link_state,
        .ndo_fix_features       = nfp_repr_fix_features,
index b6ec46e..3fdaaf8 100644 (file)
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-/* Copyright (C) 2017 Netronome Systems, Inc. */
+/* Copyright (C) 2017-2019 Netronome Systems, Inc. */
 
 #include <linux/bitfield.h>
 #include <linux/errno.h>
@@ -146,6 +146,30 @@ int nfp_app_set_vf_spoofchk(struct net_device *netdev, int vf, bool enable)
                                    "spoofchk");
 }
 
+int nfp_app_set_vf_trust(struct net_device *netdev, int vf, bool enable)
+{
+       struct nfp_app *app = nfp_app_from_netdev(netdev);
+       unsigned int vf_offset;
+       u8 vf_ctrl;
+       int err;
+
+       err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_TRUST,
+                                 "trust");
+       if (err)
+               return err;
+
+       /* Write trust control bit to VF entry in VF config symbol */
+       vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ +
+               NFP_NET_VF_CFG_CTRL;
+       vf_ctrl = readb(app->pf->vfcfg_tbl2 + vf_offset);
+       vf_ctrl &= ~NFP_NET_VF_CFG_CTRL_TRUST;
+       vf_ctrl |= FIELD_PREP(NFP_NET_VF_CFG_CTRL_TRUST, enable);
+       writeb(vf_ctrl, app->pf->vfcfg_tbl2 + vf_offset);
+
+       return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_TRUST,
+                                   "trust");
+}
+
 int nfp_app_set_vf_link_state(struct net_device *netdev, int vf,
                              int link_state)
 {
@@ -213,6 +237,7 @@ int nfp_app_get_vf_config(struct net_device *netdev, int vf,
        ivi->qos = FIELD_GET(NFP_NET_VF_CFG_VLAN_QOS, vlan_tci);
 
        ivi->spoofchk = FIELD_GET(NFP_NET_VF_CFG_CTRL_SPOOF, flags);
+       ivi->trusted = FIELD_GET(NFP_NET_VF_CFG_CTRL_TRUST, flags);
        ivi->linkstate = FIELD_GET(NFP_NET_VF_CFG_CTRL_LINK_STATE, flags);
 
        return 0;
index c9f09c5..a3db0cb 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
-/* Copyright (C) 2017 Netronome Systems, Inc. */
+/* Copyright (C) 2017-2019 Netronome Systems, Inc. */
 
 #ifndef _NFP_NET_SRIOV_H_
 #define _NFP_NET_SRIOV_H_
 #define   NFP_NET_VF_CFG_MB_CAP_VLAN                     (0x1 << 1)
 #define   NFP_NET_VF_CFG_MB_CAP_SPOOF                    (0x1 << 2)
 #define   NFP_NET_VF_CFG_MB_CAP_LINK_STATE               (0x1 << 3)
+#define   NFP_NET_VF_CFG_MB_CAP_TRUST                    (0x1 << 4)
 #define NFP_NET_VF_CFG_MB_RET                          0x2
 #define NFP_NET_VF_CFG_MB_UPD                          0x4
 #define   NFP_NET_VF_CFG_MB_UPD_MAC                      (0x1 << 0)
 #define   NFP_NET_VF_CFG_MB_UPD_VLAN                     (0x1 << 1)
 #define   NFP_NET_VF_CFG_MB_UPD_SPOOF                    (0x1 << 2)
 #define   NFP_NET_VF_CFG_MB_UPD_LINK_STATE               (0x1 << 3)
+#define   NFP_NET_VF_CFG_MB_UPD_TRUST                    (0x1 << 4)
 #define NFP_NET_VF_CFG_MB_VF_NUM                       0x7
 
 /* VF config entry
@@ -35,6 +37,7 @@
 #define   NFP_NET_VF_CFG_MAC_HI                                  0x0
 #define   NFP_NET_VF_CFG_MAC_LO                                  0x6
 #define NFP_NET_VF_CFG_CTRL                            0x4
+#define   NFP_NET_VF_CFG_CTRL_TRUST                      0x8
 #define   NFP_NET_VF_CFG_CTRL_SPOOF                      0x4
 #define   NFP_NET_VF_CFG_CTRL_LINK_STATE                 0x3
 #define     NFP_NET_VF_CFG_LS_MODE_AUTO                            0
@@ -48,6 +51,7 @@ int nfp_app_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
 int nfp_app_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos,
                        __be16 vlan_proto);
 int nfp_app_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting);
+int nfp_app_set_vf_trust(struct net_device *netdev, int vf, bool setting);
 int nfp_app_set_vf_link_state(struct net_device *netdev, int vf,
                              int link_state);
 int nfp_app_get_vf_config(struct net_device *netdev, int vf,