From owner-svn-src-head@freebsd.org Thu Mar 31 16:44:34 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 19AE6AE4432; Thu, 31 Mar 2016 16:44:34 +0000 (UTC) (envelope-from zbb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C395116D3; Thu, 31 Mar 2016 16:44:33 +0000 (UTC) (envelope-from zbb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2VGiW6F063880; Thu, 31 Mar 2016 16:44:32 GMT (envelope-from zbb@FreeBSD.org) Received: (from zbb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2VGiWum063879; Thu, 31 Mar 2016 16:44:32 GMT (envelope-from zbb@FreeBSD.org) Message-Id: <201603311644.u2VGiWum063879@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: zbb set sender to zbb@FreeBSD.org using -f From: Zbigniew Bodek Date: Thu, 31 Mar 2016 16:44:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297457 - head/sys/dev/vnic X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2016 16:44:34 -0000 Author: zbb Date: Thu Mar 31 16:44:32 2016 New Revision: 297457 URL: https://svnweb.freebsd.org/changeset/base/297457 Log: Fix number of the enabled VFs in VNIC nic->num_vf_en is set based on the number of the enabled LMACs. This number should not be overwritten later by any routine. Instead it should fail PCI_IOV_ADD_VF() so that available VFs with the corresponding LMACs will attach whereas other, disabled VFs will fail with the proper error code. Error signaling (due to improper number of VFs requested) is also moved from PCI_IOV_INIT() to PCI_IOV_ADD_VF(). This will be reworked when multiple queue sets are enabled but for now this is the correct behavior of the driver. Obtained from: Semihalf Sponsored by: Cavium Modified: head/sys/dev/vnic/nic_main.c Modified: head/sys/dev/vnic/nic_main.c ============================================================================== --- head/sys/dev/vnic/nic_main.c Thu Mar 31 16:09:59 2016 (r297456) +++ head/sys/dev/vnic/nic_main.c Thu Mar 31 16:44:32 2016 (r297457) @@ -269,18 +269,9 @@ nicpf_iov_init(device_t dev, uint16_t nu nic = device_get_softc(dev); - nic->num_vf_en = 0; if (num_vfs == 0) return (ENXIO); - if (num_vfs > MAX_NUM_VFS_SUPPORTED) - return (EINVAL); - /* - * Just set variables here. - * The number of VFs will be written to configuration - * space later in PCI_ADD_VF(). - */ - nic->num_vf_en = num_vfs; nic->flags |= NIC_SRIOV_ENABLED; return (0); @@ -306,6 +297,9 @@ nicpf_iov_add_vf(device_t dev, uint16_t if ((nic->flags & NIC_SRIOV_ENABLED) == 0) return (ENXIO); + if (vfnum > (nic->num_vf_en - 1)) + return (EINVAL); + if (nvlist_exists_binary(params, "mac-addr") != 0) { mac = nvlist_get_binary(params, "mac-addr", &size); bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vfnum]); @@ -1094,11 +1088,8 @@ static int nic_sriov_init(device_t dev, } /* Fix-up the number of enabled VFs */ total_vf_cnt = pci_read_config(dev, iov_pos + PCIR_SRIOV_TOTAL_VFS, 2); - if (total_vf_cnt < nic->num_vf_en) - nic->num_vf_en = total_vf_cnt; - if (total_vf_cnt == 0) - return (0); + return (ENXIO); /* Attach SR-IOV */ pf_schema = pci_iov_schema_alloc_node(); @@ -1116,7 +1107,6 @@ static int nic_sriov_init(device_t dev, device_printf(dev, "Failed to initialize SR-IOV (error=%d)\n", err); - nic->num_vf_en = 0; return (err); } #endif