From owner-svn-src-stable@freebsd.org Wed Apr 1 23:05:45 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8F05C2A6672; Wed, 1 Apr 2020 23:05:45 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48t1yH6v5dz4GqR; Wed, 1 Apr 2020 23:05:43 +0000 (UTC) (envelope-from kib@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 55E735B8A; Wed, 1 Apr 2020 22:49:00 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 031Mn0jg050928; Wed, 1 Apr 2020 22:49:00 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 031MmxLK050922; Wed, 1 Apr 2020 22:48:59 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202004012248.031MmxLK050922@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 1 Apr 2020 22:48:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r359545 - stable/11/sys/dev/mlx5/mlx5_core X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/dev/mlx5/mlx5_core X-SVN-Commit-Revision: 359545 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 23:05:45 -0000 Author: kib Date: Wed Apr 1 22:48:59 2020 New Revision: 359545 URL: https://svnweb.freebsd.org/changeset/base/359545 Log: MFC r359104: mlx5: Read number of VF ports from the SR-IOV cap. Modified: stable/11/sys/dev/mlx5/mlx5_core/eswitch.h stable/11/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c stable/11/sys/dev/mlx5/mlx5_core/mlx5_main.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/mlx5/mlx5_core/eswitch.h ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_core/eswitch.h Wed Apr 1 22:48:06 2020 (r359544) +++ stable/11/sys/dev/mlx5/mlx5_core/eswitch.h Wed Apr 1 22:48:59 2020 (r359545) @@ -152,7 +152,7 @@ struct mlx5_esw_vport_info { }; /* E-Switch API */ -int mlx5_eswitch_init(struct mlx5_core_dev *dev); +int mlx5_eswitch_init(struct mlx5_core_dev *dev, int total_vports); void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw); void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe); int mlx5_eswitch_enable_sriov(struct mlx5_eswitch *esw, int nvfs); Modified: stable/11/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c Wed Apr 1 22:48:06 2020 (r359544) +++ stable/11/sys/dev/mlx5/mlx5_core/mlx5_eswitch.c Wed Apr 1 22:48:59 2020 (r359545) @@ -1081,10 +1081,9 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *e esw_enable_vport(esw, 0, UC_ADDR_CHANGE); } -int mlx5_eswitch_init(struct mlx5_core_dev *dev) +int mlx5_eswitch_init(struct mlx5_core_dev *dev, int total_vports) { int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table); - int total_vports = 1; struct mlx5_eswitch *esw; int vport_num; int err; Modified: stable/11/sys/dev/mlx5/mlx5_core/mlx5_main.c ============================================================================== --- stable/11/sys/dev/mlx5/mlx5_core/mlx5_main.c Wed Apr 1 22:48:06 2020 (r359544) +++ stable/11/sys/dev/mlx5/mlx5_core/mlx5_main.c Wed Apr 1 22:48:59 2020 (r359545) @@ -1298,6 +1298,7 @@ static int init_one(struct pci_dev *pdev, device_t bsddev = pdev->dev.bsddev; #ifdef PCI_IOV nvlist_t *pf_schema, *vf_schema; + int num_vfs, sriov_pos; #endif int i,err; struct sysctl_oid *pme_sysctl_node; @@ -1584,7 +1585,14 @@ static int init_one(struct pci_dev *pdev, #ifdef PCI_IOV if (MLX5_CAP_GEN(dev, vport_group_manager)) { - err = mlx5_eswitch_init(dev); + if (pci_find_extcap(bsddev, PCIZ_SRIOV, &sriov_pos) == 0) { + num_vfs = pci_read_config(bsddev, sriov_pos + + PCIR_SRIOV_TOTAL_VFS, 2); + } else { + mlx5_core_err(dev, "cannot find SR-IOV PCIe cap\n"); + num_vfs = 0; + } + err = mlx5_eswitch_init(dev, 1 + num_vfs); if (err == 0) { pf_schema = pci_iov_schema_alloc_node(); vf_schema = pci_iov_schema_alloc_node(); @@ -1761,6 +1769,10 @@ mlx5_iov_init(device_t dev, uint16_t num_vfs, const nv core_dev = pci_get_drvdata(pdev); priv = &core_dev->priv; + if (priv->eswitch == NULL) + return (ENXIO); + if (priv->eswitch->total_vports < num_vfs + 1) + num_vfs = priv->eswitch->total_vports - 1; err = mlx5_eswitch_enable_sriov(priv->eswitch, num_vfs); return (-err); } @@ -1792,6 +1804,9 @@ mlx5_iov_add_vf(device_t dev, uint16_t vfnum, const nv pdev = device_get_softc(dev); core_dev = pci_get_drvdata(pdev); priv = &core_dev->priv; + + if (vfnum + 1 >= priv->eswitch->total_vports) + return (ENXIO); if (nvlist_exists_binary(vf_config, iov_mac_addr_name)) { mac = nvlist_get_binary(vf_config, iov_mac_addr_name,