From owner-svn-src-stable-12@freebsd.org Wed Apr 1 19:55:52 2020 Return-Path: Delivered-To: svn-src-stable-12@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 C328927FD0D; Wed, 1 Apr 2020 19:55:52 +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 48sxlD1g4Pz41SW; Wed, 1 Apr 2020 19:55:52 +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 DE4242F14; Wed, 1 Apr 2020 19:37:23 +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 031JbN1x033479; Wed, 1 Apr 2020 19:37:23 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 031JbNsP033478; Wed, 1 Apr 2020 19:37:23 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202004011937.031JbNsP033478@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:37:23 +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: r359531 - 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: 359531 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-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 19:55:53 -0000 Author: kib Date: Wed Apr 1 19:37:23 2020 New Revision: 359531 URL: https://svnweb.freebsd.org/changeset/base/359531 Log: MFC r359098: mlx5: Basic PCIe side of SR-IOV support. 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:22:09 2020 (r359530) +++ stable/12/sys/dev/mlx5/mlx5_core/mlx5_main.c Wed Apr 1 19:37:23 2020 (r359531) @@ -45,6 +45,11 @@ #include #include "mlx5_core.h" #include "fs_core.h" +#ifdef PCI_IOV +#include +#include +#include +#endif static const char mlx5_version[] = "Mellanox Core driver " DRIVER_VERSION " (" DRIVER_RELDATE ")"; @@ -512,12 +517,13 @@ static int set_hca_ctrl(struct mlx5_core_dev *dev) return err; } -static int mlx5_core_enable_hca(struct mlx5_core_dev *dev) +static int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id) { u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {0}; u32 in[MLX5_ST_SZ_DW(enable_hca_in)] = {0}; MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA); + MLX5_SET(enable_hca_in, in, function_id, func_id); return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out)); } @@ -852,8 +858,11 @@ mlx5_firmware_update(struct mlx5_core_dev *dev) static int mlx5_pci_init(struct mlx5_core_dev *dev, struct mlx5_priv *priv) { struct pci_dev *pdev = dev->pdev; - int err = 0; + device_t bsddev; + int err; + pdev = dev->pdev; + bsddev = pdev->dev.bsddev; pci_set_drvdata(dev->pdev, dev); strncpy(priv->name, dev_name(&pdev->dev), MLX5_MAX_NAME_LEN); priv->name[MLX5_MAX_NAME_LEN - 1] = 0; @@ -904,6 +913,10 @@ err_dbg: static void mlx5_pci_close(struct mlx5_core_dev *dev, struct mlx5_priv *priv) { +#ifdef PCI_IOV + if (MLX5_CAP_GEN(dev, eswitch_flow_table)) + pci_iov_detach(dev->pdev->dev.bsddev); +#endif iounmap(dev->iseg); release_bar(dev->pdev); mlx5_pci_disable_device(dev); @@ -1034,7 +1047,7 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, st goto err_cmd_cleanup; } - err = mlx5_core_enable_hca(dev); + err = mlx5_core_enable_hca(dev, 0); if (err) { mlx5_core_err(dev, "enable hca failed\n"); goto err_cmd_cleanup; @@ -1294,6 +1307,9 @@ static int init_one(struct pci_dev *pdev, struct mlx5_core_dev *dev; struct mlx5_priv *priv; device_t bsddev = pdev->dev.bsddev; +#ifdef PCI_IOV + nvlist_t *pf_schema, *vf_schema; +#endif int i,err; struct sysctl_oid *pme_sysctl_node; struct sysctl_oid *pme_err_sysctl_node; @@ -1577,6 +1593,19 @@ static int init_one(struct pci_dev *pdev, mlx5_firmware_update(dev); +#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, + "Failed to initialize SR-IOV support, error %d\n", + err); + } + } +#endif + pci_save_state(bsddev); return 0; @@ -1722,6 +1751,54 @@ static const struct pci_error_handlers mlx5_err_handle .resume = mlx5_pci_resume }; +#ifdef PCI_IOV +static int +mlx5_iov_init(device_t dev, uint16_t num_vfs, const nvlist_t *pf_config) +{ + struct pci_dev *pdev; + struct mlx5_core_dev *core_dev; + struct mlx5_priv *priv; + + pdev = device_get_softc(dev); + core_dev = pci_get_drvdata(pdev); + priv = &core_dev->priv; + + return (0); +} + +static void +mlx5_iov_uninit(device_t dev) +{ + struct pci_dev *pdev; + struct mlx5_core_dev *core_dev; + struct mlx5_priv *priv; + + pdev = device_get_softc(dev); + core_dev = pci_get_drvdata(pdev); + priv = &core_dev->priv; +} + +static int +mlx5_iov_add_vf(device_t dev, uint16_t vfnum, const nvlist_t *vf_config) +{ + struct pci_dev *pdev; + struct mlx5_core_dev *core_dev; + struct mlx5_priv *priv; + int error; + + pdev = device_get_softc(dev); + core_dev = pci_get_drvdata(pdev); + priv = &core_dev->priv; + + 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); + } + return (error); +} +#endif + static int mlx5_try_fast_unload(struct mlx5_core_dev *dev) { bool fast_teardown, force_teardown; @@ -1856,7 +1933,12 @@ struct pci_driver mlx5_core_driver = { .shutdown = shutdown_one, .probe = init_one, .remove = remove_one, - .err_handler = &mlx5_err_handler + .err_handler = &mlx5_err_handler, +#ifdef PCI_IOV + .bsd_iov_init = mlx5_iov_init, + .bsd_iov_uninit = mlx5_iov_uninit, + .bsd_iov_add_vf = mlx5_iov_add_vf, +#endif }; static int __init init(void)