From patchwork Mon Aug 22 22:43:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Samudrala, Sridhar" X-Patchwork-Id: 661667 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sJ9K95vY9z9s8x for ; Tue, 23 Aug 2016 09:49:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 6043E895D4; Mon, 22 Aug 2016 23:49:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cqp+VAP-RDsM; Mon, 22 Aug 2016 23:49:29 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 01CFF8A14D; Mon, 22 Aug 2016 23:49:25 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 696CA1C2BE5 for ; Mon, 22 Aug 2016 23:49:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 6126D31428 for ; Mon, 22 Aug 2016 23:49:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xiRwht3W11LM for ; Mon, 22 Aug 2016 23:49:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by silver.osuosl.org (Postfix) with ESMTPS id 04F5B31429 for ; Mon, 22 Aug 2016 23:49:20 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP; 22 Aug 2016 16:49:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,562,1464678000"; d="scan'208";a="159588715" Received: from unknown (HELO sri-mi-02.jf.intel.com) ([10.166.31.66]) by fmsmga004.fm.intel.com with ESMTP; 22 Aug 2016 16:49:19 -0700 From: Sridhar Samudrala To: intel-wired-lan@lists.osuosl.org, anjali.singhai@intel.com, john.r.fastabend@intel.com, amritha.nambiar@intel.com, alexander.h.duyck@intel.com Date: Tue, 23 Aug 2016 00:43:09 +0200 Message-Id: <1471905790-4222-3-git-send-email-sridhar.samudrala@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1471905790-4222-1-git-send-email-sridhar.samudrala@intel.com> References: <1471905790-4222-1-git-send-email-sridhar.samudrala@intel.com> Subject: [Intel-wired-lan] [dev-queue PATCH v3 2/3] i40e: Enable VF specific ethtool statistics via VF Port representor netdevs. X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" Sample script that shows ethtool stats on VF representor netdev PF: enp5s0f0, VF0: enp5s2 VF_REP0: enp5s0f0-vf0 # echo 2 > /sys/class/net/enp5s0f0/device/sriov_numvfs # ip link set enp5s2 up # ethtool -S enp5s0f0-vf0 NIC statistics: tx_bytes: 0 tx_unicast: 0 tx_multicast: 0 tx_broadcast: 0 tx_discards: 0 tx_errors: 0 rx_bytes: 140 rx_unicast: 0 rx_multicast: 2 rx_broadcast: 0 rx_discards: 0 rx_unknown_protocol: 0 Signed-off-by: Sridhar Samudrala Tested-by: Andrew Bowers --- drivers/net/ethernet/intel/i40e/i40e.h | 1 + drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 72 ++++++++++++++++++++++ drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 1 + 3 files changed, 74 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h index 19103a6..13b1f75 100644 --- a/drivers/net/ethernet/intel/i40e/i40e.h +++ b/drivers/net/ethernet/intel/i40e/i40e.h @@ -866,4 +866,5 @@ i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf); i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf); i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf); void i40e_print_link_message(struct i40e_vsi *vsi, bool isup); +void i40e_set_vf_netdev_ethtool_ops(struct net_device *netdev); #endif /* _I40E_H_ */ diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index 1835186..e2d3168 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -3116,3 +3116,75 @@ void i40e_set_ethtool_ops(struct net_device *netdev) { netdev->ethtool_ops = &i40e_ethtool_ops; } + +/* As the VF Port representor(VFPR) represents the switch port corresponding + * to a VF, the tx_ and rx_ strings are swapped to indicate that the frames + * transmitted from VF are received on VFPR and the frames received on VF are + * transmitted from VFPR. + */ +static const char i40e_vf_netdev_ethtool_sset[][ETH_GSTRING_LEN] = { + "tx_bytes", + "tx_unicast", + "tx_multicast", + "tx_broadcast", + "tx_discards", + "tx_errors", + "rx_bytes", + "rx_unicast", + "rx_multicast", + "rx_broadcast", + "rx_discards", + "rx_unknown_protocol", +}; + +#define I40E_VF_NETDEV_ETHTOOL_STAT_COUNT \ + ARRAY_SIZE(i40e_vf_netdev_ethtool_sset) + +static void i40e_vf_netdev_ethtool_get_strings(struct net_device *dev, + u32 stringset, + u8 *ethtool_strings) +{ + switch (stringset) { + case ETH_SS_STATS: + memcpy(ethtool_strings, &i40e_vf_netdev_ethtool_sset, + sizeof(i40e_vf_netdev_ethtool_sset)); + break; + } +} + +static int i40e_vf_netdev_ethtool_get_sset_count(struct net_device *dev, + int stringset) +{ + switch (stringset) { + case ETH_SS_STATS: + return I40E_VF_NETDEV_ETHTOOL_STAT_COUNT; + default: + return -EOPNOTSUPP; + } +} + +static void i40e_vf_netdev_ethtool_get_stats(struct net_device *dev, + struct ethtool_stats *target_ethtool_stats, + u64 *target_stat_values) +{ + struct i40e_vf_netdev_priv *priv = netdev_priv(dev); + struct i40e_vf *vf = priv->vf; + struct i40e_pf *pf = vf->pf; + struct i40e_vsi *vsi; + + vsi = pf->vsi[vf->lan_vsi_idx]; + i40e_update_stats(vsi); + memcpy(target_stat_values, &vsi->eth_stats, + I40E_VF_NETDEV_ETHTOOL_STAT_COUNT * 8); +} + +static const struct ethtool_ops i40e_vf_netdev_ethtool_ops = { + .get_strings = i40e_vf_netdev_ethtool_get_strings, + .get_ethtool_stats = i40e_vf_netdev_ethtool_get_stats, + .get_sset_count = i40e_vf_netdev_ethtool_get_sset_count, +}; + +void i40e_set_vf_netdev_ethtool_ops(struct net_device *netdev) +{ + netdev->ethtool_ops = &i40e_vf_netdev_ethtool_ops; +} diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index 6167e56..b5a716e 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -1049,6 +1049,7 @@ int i40e_alloc_vf_netdev(struct i40e_vf *vf, u16 vf_num) priv->vf = &(pf->vf[vf_num]); netdev->netdev_ops = &i40e_vf_netdev_ops; + i40e_set_vf_netdev_ethtool_ops(netdev); netif_carrier_off(netdev); netif_tx_disable(netdev);