Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1835352pxv; Fri, 2 Jul 2021 13:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKWeyx++l5TnDEWaa4fymmFFKrUhUn0Wr6ofmJcrSxxvns6jE5Q2uOTyRSPrBwu1aYcYgL X-Received: by 2002:a02:8241:: with SMTP id q1mr1080496jag.134.1625257966095; Fri, 02 Jul 2021 13:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625257966; cv=none; d=google.com; s=arc-20160816; b=PGpE8cLuNPChkf0vPl/8PQUgIaSdX1BVvP9zHW6gY5cal5zWDLXlBfLoEhLoBGSKMU AOfV+hhJZdPphj8J+oadyVunC8KevdNJIb6420GsN88m6+qe5kxsQmdl+XW0nLDv2MDS w8txPDeDoZsT4vihGznQMsqgVlJgrGJpXereuxvKafimmg2tvSIsClUaMdmLHP8MgdHy CkH1cfFXwpiTiExOg3RFHnmprlMxQsF0qHVi+GECJQMws/h9VpPnn/KsFlXIcJnqfQXf 8lJ0q3rFWxbYMjKZBQd1N/3Sj2cDSD5qEh+wASACqJL0s5QEA8b4KZqy0W7YG/gFUWXB rPzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=fmc5dDCDNgUCGurtDUVLQJtKxPKiPIBI/PH7SfH7U+s=; b=JekJaaLkkbRWBy55J9r2S3VuuwnGyccGbiyyczKp7Pbg0j8wZWZoRAeJ6JM2wEvW0l Ar0M8k1+b2uXm1723gw8IqgXW+J8dwBfvpMzRydJCKWEi/oBLrzyMJRM7aOvZyRdVE5v QRzQlIamamfMO9ojlplFl9Wg/iVPRHVAMeqDj1aTwmUiT4wo8AogXXseddkKv+YgQvyv dXET7FpJtfyogO/2serGU5pj3dhDTnYA32Ky3Ew5SJhbowpUwC2AfabMKtypZ4MvdJ/9 VNJhVvs3X8uErZLvSdjtE8MB5b1zpcl/cyE6sJO5M2WgfJJJXXpAfrzABIvZ8Q33A5L+ 3FMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UxvVJPf1; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si4415070jam.120.2021.07.02.13.32.20; Fri, 02 Jul 2021 13:32:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UxvVJPf1; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbhGBUcB (ORCPT + 99 others); Fri, 2 Jul 2021 16:32:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55953 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbhGBUcA (ORCPT ); Fri, 2 Jul 2021 16:32:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625257767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fmc5dDCDNgUCGurtDUVLQJtKxPKiPIBI/PH7SfH7U+s=; b=UxvVJPf12oS0gUgJKi2w2eKEt3eTpdJ9HFzMSWuQxp2o4aht1I7hcnmND1Is6AuO6FsH9F ipuhSaQXROGBK3APhhKQAikYHQDtKo/PyAqYFqEVK+6+EcYY6EUFvc/jUGVrLgL+ddDGYD V7BsFRJtulDoSWRQT0pavGBjW0Cthxg= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-562-ecti3PDZMziNlUrm1qGXYA-1; Fri, 02 Jul 2021 16:29:26 -0400 X-MC-Unique: ecti3PDZMziNlUrm1qGXYA-1 Received: by mail-oo1-f70.google.com with SMTP id q14-20020a4adc4e0000b0290249480f62d9so6201204oov.0 for ; Fri, 02 Jul 2021 13:29:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fmc5dDCDNgUCGurtDUVLQJtKxPKiPIBI/PH7SfH7U+s=; b=dCgwV1W35kV0JbcwejGfTxDoTyozph0iDEEhRomF/iUjpnVlcfOXPYCPm/MYPnnpbf nnuVGTPTvdhqr85qcBkM0toNdypmEZ/XVK0EgLn4QmeVuqo46ETjZuAsOGeTWYJ7ZyrV GPbOC00dPERMSqc1YV8slCUNQJ7oggQy9qURSQXAMrGt+jKuR9A4JH0vzHEBBqw2x/cU 1SEVHlAA0KdXs9H4J6jj6/DEzhLZkjUmFn84I5aQYOaUSDjZNt7jAfyAYityT4zjNH/+ /X7kvhxbbGYChUW0a6tVPIDsFFka6OCnvZzkaTE3Ft9gDly65VUWKrlQWsaTPKWliBv4 0drw== X-Gm-Message-State: AOAM530FkmKpnHp45Nw/pfeatBQFkLq2ucVB4eEekSKVXv9bthBtT4Q0 yeMora8V6hMgg90ycgxsxlbp77x7FrINyHJpPZjGX3uWWO/PqfRDlvcG9y9tTYOaFhMWzA0VtVY lYDzPhuYEzhNd1KmN83s0QFfU X-Received: by 2002:aca:5c83:: with SMTP id q125mr1212831oib.145.1625257765869; Fri, 02 Jul 2021 13:29:25 -0700 (PDT) X-Received: by 2002:aca:5c83:: with SMTP id q125mr1212817oib.145.1625257765667; Fri, 02 Jul 2021 13:29:25 -0700 (PDT) Received: from redhat.com ([198.99.80.109]) by smtp.gmail.com with ESMTPSA id v3sm800954oon.11.2021.07.02.13.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 13:29:25 -0700 (PDT) Date: Fri, 2 Jul 2021 14:29:24 -0600 From: Alex Williamson To: Shameer Kolothum Cc: , , , , , , , , , , Subject: Re: [RFC v2 1/4] hisi-acc-vfio-pci: add new vfio_pci driver for HiSilicon ACC devices Message-ID: <20210702142924.57ad33dc.alex.williamson@redhat.com> In-Reply-To: <20210702095849.1610-2-shameerali.kolothum.thodi@huawei.com> References: <20210702095849.1610-1-shameerali.kolothum.thodi@huawei.com> <20210702095849.1610-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, 2 Jul 2021 10:58:46 +0100 Shameer Kolothum wrote: > Add a vendor-specific vfio_pci driver for HiSilicon ACC devices. > This will be extended in follow-up patches to add support for > vfio live migration feature. > > Signed-off-by: Shameer Kolothum > --- > drivers/vfio/pci/Kconfig | 9 +++ > drivers/vfio/pci/Makefile | 2 + > drivers/vfio/pci/hisi_acc_vfio_pci.c | 100 +++++++++++++++++++++++++++ > 3 files changed, 111 insertions(+) > create mode 100644 drivers/vfio/pci/hisi_acc_vfio_pci.c > > diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig > index 9cdef46dd299..709807c28153 100644 > --- a/drivers/vfio/pci/Kconfig > +++ b/drivers/vfio/pci/Kconfig > @@ -57,3 +57,12 @@ config MLX5_VFIO_PCI > framework. > > If you don't know what to do here, say N. > + > +config HISI_ACC_VFIO_PCI > + tristate "VFIO support for HiSilicon ACC devices" > + depends on ARM64 && VFIO_PCI_CORE > + help > + This provides generic PCI support for HiSilicon devices using the VFIO > + framework. > + > + If you don't know what to do here, say N. > diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile > index a0df9c2a4bd9..d1de3e81921f 100644 > --- a/drivers/vfio/pci/Makefile > +++ b/drivers/vfio/pci/Makefile > @@ -3,6 +3,7 @@ > obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o > obj-$(CONFIG_VFIO_PCI) += vfio-pci.o > obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5-vfio-pci.o > +obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisi-acc-vfio-pci.o > > vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o > vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o > @@ -11,3 +12,4 @@ vfio-pci-y := vfio_pci.o > vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o > > mlx5-vfio-pci-y := mlx5_vfio_pci.o > +hisi-acc-vfio-pci-y := hisi_acc_vfio_pci.o > diff --git a/drivers/vfio/pci/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisi_acc_vfio_pci.c > new file mode 100644 > index 000000000000..a9e173098ab5 > --- /dev/null > +++ b/drivers/vfio/pci/hisi_acc_vfio_pci.c > @@ -0,0 +1,100 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2021, HiSilicon Ltd. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int hisi_acc_vfio_pci_open(struct vfio_device *core_vdev) > +{ > + struct vfio_pci_core_device *vdev = > + container_of(core_vdev, struct vfio_pci_core_device, vdev); > + int ret; > + > + lockdep_assert_held(&core_vdev->reflck->lock); > + > + ret = vfio_pci_core_enable(vdev); > + if (ret) > + return ret; > + > + vfio_pci_core_finish_enable(vdev); > + > + return 0; > +} > + > +static const struct vfio_device_ops hisi_acc_vfio_pci_ops = { > + .name = "hisi-acc-vfio-pci", > + .open = hisi_acc_vfio_pci_open, > + .release = vfio_pci_core_release, > + .ioctl = vfio_pci_core_ioctl, > + .read = vfio_pci_core_read, > + .write = vfio_pci_core_write, > + .mmap = vfio_pci_core_mmap, > + .request = vfio_pci_core_request, > + .match = vfio_pci_core_match, > + .reflck_attach = vfio_pci_core_reflck_attach, > +}; > + > +static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > +{ > + struct vfio_pci_core_device *vdev; > + int ret; > + > + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); > + if (!vdev) > + return -ENOMEM; > + > + ret = vfio_pci_core_register_device(vdev, pdev, &hisi_acc_vfio_pci_ops); > + if (ret) > + goto out_free; > + > + dev_set_drvdata(&pdev->dev, vdev); > + > + return 0; > + > +out_free: > + kfree(vdev); > + return ret; > +} > + > +static void hisi_acc_vfio_pci_remove(struct pci_dev *pdev) > +{ > + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); > + > + vfio_pci_core_unregister_device(vdev); > + kfree(vdev); > +} > + > +static const struct pci_device_id hisi_acc_vfio_pci_table[] = { > + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_HUAWEI, 0xa256) }, /* SEC VF */ > + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_HUAWEI, 0xa259) }, /* HPRE VF */ > + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_HUAWEI, 0xa251) }, /* ZIP VF */ > + { 0, } > +}; > + > +MODULE_DEVICE_TABLE(pci, hisi_acc_vfio_pci_table); > + > +static struct pci_driver hisi_acc_vfio_pci_driver = { > + .name = "hisi-acc-vfio-pci", > + .id_table = hisi_acc_vfio_pci_table, > + .probe = hisi_acc_vfio_pci_probe, > + .remove = hisi_acc_vfio_pci_remove, > +#ifdef CONFIG_PCI_IOV > + .sriov_configure = vfio_pci_core_sriov_configure, > +#endif The device table suggests only VFs are supported by this driver, so it really shouldn't need sriov_configure support, right? Thanks, Alex > + .err_handler = &vfio_pci_core_err_handlers, > +}; > + > +module_pci_driver(hisi_acc_vfio_pci_driver); > + > +MODULE_LICENSE("GPL v2"); > +MODULE_AUTHOR("Liu Longfang "); > +MODULE_AUTHOR("Shameer Kolothum "); > +MODULE_DESCRIPTION("HiSilicon VFIO PCI - Generic VFIO PCI driver for HiSilicon ACC device family");