From owner-svn-src-all@freebsd.org Wed Apr 1 19:42:57 2020 Return-Path: Delivered-To: svn-src-all@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 6BB7827F4B6; Wed, 1 Apr 2020 19:42:57 +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 48sxSJ0SJlz3Qv8; Wed, 1 Apr 2020 19:42:55 +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 C32A53113; Wed, 1 Apr 2020 19:42:50 +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 031Jgo3n039232; Wed, 1 Apr 2020 19:42:50 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 031Jgofw039231; Wed, 1 Apr 2020 19:42:50 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202004011942.031Jgofw039231@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 19:42:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r359535 - stable/12/sys/dev/mlx5/mlx5_core X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/sys/dev/mlx5/mlx5_core X-SVN-Commit-Revision: 359535 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 19:42:57 -0000 Author: kib Date: Wed Apr 1 19:42:50 2020 New Revision: 359535 URL: https://svnweb.freebsd.org/changeset/base/359535 Log: MFC r359103: mlx5: Use eswitch interface to configure VFs steering. Modified: stable/12/sys/dev/mlx5/mlx5_core/mlx5_main.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/mlx5/mlx5_core/mlx5_main.c ============================================================================== --- stable/12/sys/dev/mlx5/mlx5_core/mlx5_main.c Wed Apr 1 19:41:26 2020 (r359534) +++ stable/12/sys/dev/mlx5/mlx5_core/mlx5_main.c Wed Apr 1 19:42:50 2020 (r359535) @@ -39,11 +39,13 @@ #include #include #include +#include #include #include #include #include #include "mlx5_core.h" +#include "eswitch.h" #include "fs_core.h" #ifdef PCI_IOV #include @@ -175,6 +177,10 @@ static struct mlx5_profile profiles[] = { }, }; +#ifdef PCI_IOV +static const char iov_mac_addr_name[] = "mac-addr"; +#endif + static int set_dma_caps(struct pci_dev *pdev) { struct mlx5_core_dev *dev = pci_get_drvdata(pdev); @@ -1235,6 +1241,7 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, mlx5_unregister_device(dev); + mlx5_eswitch_cleanup(dev->priv.eswitch); mlx5_fpga_device_stop(dev); mlx5_mpfs_destroy(dev); mlx5_cleanup_fs(dev); @@ -1595,12 +1602,20 @@ static int init_one(struct pci_dev *pdev, #ifdef PCI_IOV if (MLX5_CAP_GEN(dev, vport_group_manager)) { - pf_schema = pci_iov_schema_alloc_node(); - vf_schema = pci_iov_schema_alloc_node(); - err = pci_iov_attach(bsddev, pf_schema, vf_schema); - if (err != 0) { - device_printf(bsddev, + err = mlx5_eswitch_init(dev); + if (err == 0) { + pf_schema = pci_iov_schema_alloc_node(); + vf_schema = pci_iov_schema_alloc_node(); + pci_iov_schema_add_unicast_mac(vf_schema, + iov_mac_addr_name, 0, NULL); + err = pci_iov_attach(bsddev, pf_schema, vf_schema); + if (err != 0) { + device_printf(bsddev, "Failed to initialize SR-IOV support, error %d\n", + err); + } + } else { + mlx5_core_err(dev, "eswitch init failed, error %d\n", err); } } @@ -1758,12 +1773,14 @@ mlx5_iov_init(device_t dev, uint16_t num_vfs, const nv struct pci_dev *pdev; struct mlx5_core_dev *core_dev; struct mlx5_priv *priv; + int err; pdev = device_get_softc(dev); core_dev = pci_get_drvdata(pdev); priv = &core_dev->priv; - return (0); + err = mlx5_eswitch_enable_sriov(priv->eswitch, num_vfs); + return (-err); } static void @@ -1776,6 +1793,8 @@ mlx5_iov_uninit(device_t dev) pdev = device_get_softc(dev); core_dev = pci_get_drvdata(pdev); priv = &core_dev->priv; + + mlx5_eswitch_disable_sriov(priv->eswitch); } static int @@ -1784,16 +1803,32 @@ mlx5_iov_add_vf(device_t dev, uint16_t vfnum, const nv struct pci_dev *pdev; struct mlx5_core_dev *core_dev; struct mlx5_priv *priv; + const void *mac; + size_t mac_size; int error; pdev = device_get_softc(dev); core_dev = pci_get_drvdata(pdev); priv = &core_dev->priv; + if (nvlist_exists_binary(vf_config, iov_mac_addr_name)) { + mac = nvlist_get_binary(vf_config, iov_mac_addr_name, + &mac_size); + error = -mlx5_eswitch_set_vport_mac(priv->eswitch, + vfnum + 1, __DECONST(u8 *, mac)); + } + + error = -mlx5_eswitch_set_vport_state(priv->eswitch, vfnum + 1, + VPORT_STATE_FOLLOW); + if (error != 0) { + mlx5_core_err(core_dev, + "upping vport for VF %d failed, error %d\n", + vfnum + 1, error); + } error = -mlx5_core_enable_hca(core_dev, vfnum + 1); if (error != 0) { mlx5_core_err(core_dev, "enabling VF %d failed, error %d\n", - vfnum, error); + vfnum + 1, error); } return (error); }