From patchwork Mon Aug 22 22:43:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Samudrala, Sridhar" X-Patchwork-Id: 661665 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 3sJ9K73SzHz9s8x for ; Tue, 23 Aug 2016 09:49:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id BCF498A234; Mon, 22 Aug 2016 23:49:29 +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 AHmBE8r8Ugjk; Mon, 22 Aug 2016 23:49:25 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 8C3E288CDC; Mon, 22 Aug 2016 23:49:24 +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 AA79F1C2BE5 for ; Mon, 22 Aug 2016 23:49:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id A300A31427 for ; Mon, 22 Aug 2016 23:49:21 +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 Z318ToRzBA7q for ; Mon, 22 Aug 2016 23:49:19 +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 E901A3141F for ; Mon, 22 Aug 2016 23:49:19 +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="159588711" 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:08 +0200 Message-Id: <1471905790-4222-2-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 1/3] i40e: Introduce VF port representor/control 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" This patch enables creation of a VF Port representor/Control netdev associated with each VF. These netdevs can be used to control and configure VFs from PFs namespace. They enable exposing VF statistics, configuring link state, mtu, fdb/vlan entries etc. # echo 2 > /sys/class/net/enp5s0f0/device/sriov_numvfs # ip l show 297: enp5s0f0: mtu 1500 qdisc noop portid 6805ca2e7268 state DOWN mode DEFAULT group default qlen 1000 link/ether 68:05:ca:2e:72:68 brd ff:ff:ff:ff:ff:ff vf 0 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust off vf 1 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust off 299: enp5s0f0-vf0: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 300: enp5s0f0-vf1: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff Signed-off-by: Sridhar Samudrala Tested-by: Andrew Bowers --- drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 88 ++++++++++++++++++++++ drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h | 14 ++++ 2 files changed, 102 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index da34235..6167e56 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -1003,6 +1003,90 @@ complete_reset: clear_bit(__I40E_VF_DISABLE, &pf->state); } +static int i40e_vf_netdev_open(struct net_device *dev) +{ + return 0; +} + +static int i40e_vf_netdev_stop(struct net_device *dev) +{ + return 0; +} + +static const struct net_device_ops i40e_vf_netdev_ops = { + .ndo_open = i40e_vf_netdev_open, + .ndo_stop = i40e_vf_netdev_stop, +}; + +/** + * i40e_alloc_vf_netdev + * @vf: pointer to the VF structure + * @vf_num: VF number + * + * Create VF representor/control netdev + **/ +int i40e_alloc_vf_netdev(struct i40e_vf *vf, u16 vf_num) +{ + struct net_device *netdev; + char netdev_name[IFNAMSIZ]; + struct i40e_vf_netdev_priv *priv; + struct i40e_pf *pf = vf->pf; + struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; + int err; + + snprintf(netdev_name, IFNAMSIZ, "%s-vf%d", vsi->netdev->name, vf_num); + netdev = alloc_netdev(sizeof(struct i40e_vf_netdev_priv), netdev_name, + NET_NAME_UNKNOWN, ether_setup); + if (!netdev) { + dev_err(&pf->pdev->dev, "alloc_netdev failed for vf:%d\n", + vf_num); + return -ENOMEM; + } + + pf->vf[vf_num].ctrl_netdev = netdev; + + priv = netdev_priv(netdev); + priv->vf = &(pf->vf[vf_num]); + + netdev->netdev_ops = &i40e_vf_netdev_ops; + + netif_carrier_off(netdev); + netif_tx_disable(netdev); + + err = register_netdev(netdev); + if (err) { + dev_err(&pf->pdev->dev, "register_netdev failed for vf: %s\n", + vf->ctrl_netdev->name); + free_netdev(netdev); + return err; + } + + dev_info(&pf->pdev->dev, "VF representor(%s) created for VF %d\n", + vf->ctrl_netdev->name, vf_num); + + return 0; +} + +/** + * i40e_free_vf_netdev + * @vf: pointer to the VF structure + * + * Free VF representor/control netdev + **/ +void i40e_free_vf_netdev(struct i40e_vf *vf) +{ + struct i40e_pf *pf = vf->pf; + + if (!vf->ctrl_netdev) + return; + + dev_info(&pf->pdev->dev, "Freeing VF representor(%s)\n", + vf->ctrl_netdev->name); + + unregister_netdev(vf->ctrl_netdev); + free_netdev(vf->ctrl_netdev); +} + /** * i40e_free_vfs * @pf: pointer to the PF structure @@ -1045,6 +1129,8 @@ void i40e_free_vfs(struct i40e_pf *pf) i40e_free_vf_res(&pf->vf[i]); /* disable qp mappings */ i40e_disable_vf_mappings(&pf->vf[i]); + + i40e_free_vf_netdev(&pf->vf[i]); } kfree(pf->vf); @@ -1112,6 +1198,8 @@ int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs) /* VF resources get allocated during reset */ i40e_reset_vf(&vfs[i], false); + i40e_alloc_vf_netdev(&vfs[i], i); + } pf->num_alloc_vfs = num_alloc_vfs; diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h index 8751741..1d54b95 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h @@ -72,10 +72,21 @@ enum i40e_vf_capabilities { I40E_VIRTCHNL_VF_CAP_IWARP, }; +/* VF Ctrl netdev private structure */ +struct i40e_vf_netdev_priv { + struct i40e_vf *vf; +}; + /* VF information structure */ struct i40e_vf { struct i40e_pf *pf; + /* VF Port representor netdev that allows control and configuration + * of VFs from the host. Enables returning VF stats, configuring link + * state, mtu, fdb/vlans etc. + */ + struct net_device *ctrl_netdev; + /* VF id in the PF space */ s16 vf_id; /* all VF vsis connect to the same parent */ @@ -142,4 +153,7 @@ int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable); void i40e_vc_notify_link_state(struct i40e_pf *pf); void i40e_vc_notify_reset(struct i40e_pf *pf); +int i40e_alloc_vf_netdev(struct i40e_vf *vf, u16 vf_num); +void i40e_free_vf_netdev(struct i40e_vf *vf); + #endif /* _I40E_VIRTCHNL_PF_H_ */