From patchwork Fri Mar 17 03:33:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sukadev Bhattiprolu X-Patchwork-Id: 740130 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkrfv0DM9z9rxl for ; Fri, 17 Mar 2017 14:39:03 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vkrft6Y37zDqs4 for ; Fri, 17 Mar 2017 14:39:02 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vkrYl1zppzDqbX for ; Fri, 17 Mar 2017 14:34:35 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by bilbo.ozlabs.org (Postfix) with ESMTP id 3vkrYl1FNfz8xX3 for ; Fri, 17 Mar 2017 14:34:35 +1100 (AEDT) Received: by ozlabs.org (Postfix) id 3vkrYl0bBBz9s3w; Fri, 17 Mar 2017 14:34:35 +1100 (AEDT) Delivered-To: linuxppc-dev@ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkrYk4SQKz9s2Q for ; Fri, 17 Mar 2017 14:34:34 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3TXZj077609 for ; Thu, 16 Mar 2017 23:34:29 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 297xku5svd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:34:29 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 23:34:28 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 23:34:25 -0400 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3YF1p43646994; Fri, 17 Mar 2017 03:34:15 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C774B12403F; Thu, 16 Mar 2017 23:34:11 -0400 (EDT) Received: from suka-w540.usor.ibm.com (unknown [9.70.94.25]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP id E7214124044; Thu, 16 Mar 2017 23:34:10 -0400 (EDT) From: Sukadev Bhattiprolu To: Michael Ellerman Subject: [PATCH v3 03/10] VAS: Define vas_init() and vas_exit() Date: Thu, 16 Mar 2017 20:33:55 -0700 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489721642-5657-1-git-send-email-sukadev@linux.vnet.ibm.com> References: <1489721642-5657-1-git-send-email-sukadev@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0048-0000-0000-0000012FD4CA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834936; UDB=6.00410084; IPR=6.00612591; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014685; XFM=3.00000013; UTC=2017-03-17 03:34:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0049-0000-0000-00003FC297FA Message-Id: <1489721642-5657-4-git-send-email-sukadev@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170028 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stewart@linux.vnet.ibm.com, linuxppc-dev@ozlabs.org, apopple@au1.ibm.com, oohall@gmail.com, michael.neuling@au1.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Implement vas_init() and vas_exit() functions for a new VAS module. This VAS module is essentially a library for other device drivers and kernel users of the NX coprocessors like NX-842 and NX-GZIP. Signed-off-by: Sukadev Bhattiprolu --- Changelog[v3]: - Zero vas_instances memory on allocation - [Haren Myneni] Fix description in Kconfig Changelog[v2]: - Get HVWC, UWC and window address parameters from device tree. --- MAINTAINERS | 8 ++- arch/powerpc/include/asm/reg.h | 1 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/vas/Kconfig | 21 ++++++ drivers/misc/vas/Makefile | 3 + drivers/misc/vas/vas-internal.h | 3 + drivers/misc/vas/vas-window.c | 19 +++++ drivers/misc/vas/vas.c | 155 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/vas/Kconfig create mode 100644 drivers/misc/vas/Makefile create mode 100644 drivers/misc/vas/vas-window.c create mode 100644 drivers/misc/vas/vas.c diff --git a/MAINTAINERS b/MAINTAINERS index 2a910c9..4037252 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3673,8 +3673,6 @@ F: arch/powerpc/platforms/powernv/pci-cxl.c F: drivers/misc/cxl/ F: include/misc/cxl* F: include/uapi/misc/cxl.h -F: Documentation/powerpc/cxl.txt -F: Documentation/ABI/testing/sysfs-class-cxl CXLFLASH (IBM Coherent Accelerator Processor Interface CAPI Flash) SCSI DRIVER M: Manoj N. Kumar @@ -3686,6 +3684,12 @@ F: drivers/scsi/cxlflash/ F: include/uapi/scsi/cxlflash_ioctls.h F: Documentation/powerpc/cxlflash.txt +VAS (IBM Virtual Accelerator Switch) DRIVER +M: Sukadev Bhattiprolu +L: linuxppc-dev@lists.ozlabs.org +S: Supported +F: drivers/misc/vas/ + STMMAC ETHERNET DRIVER M: Giuseppe Cavallaro M: Alexandre Torgue diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h index fc879fd..7a45ff7 100644 --- a/arch/powerpc/include/asm/reg.h +++ b/arch/powerpc/include/asm/reg.h @@ -1225,6 +1225,7 @@ #define PVR_POWER8E 0x004B #define PVR_POWER8NVL 0x004C #define PVR_POWER8 0x004D +#define PVR_POWER9 0x004E #define PVR_BE 0x0070 #define PVR_PA6T 0x0090 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index c290990..97d652e 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -783,4 +783,5 @@ source "drivers/misc/mic/Kconfig" source "drivers/misc/genwqe/Kconfig" source "drivers/misc/echo/Kconfig" source "drivers/misc/cxl/Kconfig" +source "drivers/misc/vas/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 7a3ea89..5201ffd 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_GENWQE) += genwqe/ obj-$(CONFIG_ECHO) += echo/ obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o obj-$(CONFIG_CXL_BASE) += cxl/ +obj-$(CONFIG_VAS) += vas/ obj-$(CONFIG_PANEL) += panel.o lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o diff --git a/drivers/misc/vas/Kconfig b/drivers/misc/vas/Kconfig new file mode 100644 index 0000000..43cedda --- /dev/null +++ b/drivers/misc/vas/Kconfig @@ -0,0 +1,21 @@ +# +# IBM Virtual Accelarator Switchboard (VAS) compatible devices +#depends on PPC_POWERNV && PCI_MSI && EEH +# + +config VAS + tristate "Support for IBM Virtual Accelerator Switchboard (VAS)" + depends on PPC_POWERNV + default n + help + Select this option to enable driver support for IBM Virtual + Accelerator Switchboard (VAS). + + VAS allows accelerators in co processors like NX-842 to be + directly available to a user process. This driver enables + userspace programs to access these accelerators via device + nodes like /dev/crypto/nx-gzip. + + VAS adapters are found in POWER9 based systems. + + If unsure, say N. diff --git a/drivers/misc/vas/Makefile b/drivers/misc/vas/Makefile new file mode 100644 index 0000000..7dd7139 --- /dev/null +++ b/drivers/misc/vas/Makefile @@ -0,0 +1,3 @@ +ccflags-y := $(call cc-disable-warning, unused-const-variable) +ccflags-$(CONFIG_PPC_WERROR) += -Werror +obj-$(CONFIG_VAS) += vas.o vas-window.o diff --git a/drivers/misc/vas/vas-internal.h b/drivers/misc/vas/vas-internal.h index ce48f14..15b62e0 100644 --- a/drivers/misc/vas/vas-internal.h +++ b/drivers/misc/vas/vas-internal.h @@ -389,4 +389,7 @@ struct vas_winctx { enum vas_notify_after_count notify_after_count; }; +extern int vas_initialized; +extern int vas_window_reset(struct vas_instance *vinst, int winid); +extern struct vas_instance *find_vas_instance(int vasid); #endif diff --git a/drivers/misc/vas/vas-window.c b/drivers/misc/vas/vas-window.c new file mode 100644 index 0000000..468f3bf --- /dev/null +++ b/drivers/misc/vas/vas-window.c @@ -0,0 +1,19 @@ +/* + * Copyright 2016 IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include +#include +#include +#include "vas-internal.h" + +/* stub for now */ +int vas_window_reset(struct vas_instance *vinst, int winid) +{ + return 0; +} diff --git a/drivers/misc/vas/vas.c b/drivers/misc/vas/vas.c new file mode 100644 index 0000000..75e55f9 --- /dev/null +++ b/drivers/misc/vas/vas.c @@ -0,0 +1,155 @@ +/* + * Copyright 2016 IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "vas-internal.h" + +int vas_initialized; +int vas_num_instances; +struct vas_instance *vas_instances; + +static void init_vas_chip(struct vas_instance *vinst) +{ + int i; + + for (i = 0; i < VAS_MAX_WINDOWS_PER_CHIP; i++) + vas_window_reset(vinst, i); +} + +static int init_vas_instance(struct device_node *dn, + struct vas_instance *vinst) +{ + int rc; + const __be32 *p; + + ida_init(&vinst->ida); + mutex_init(&vinst->mutex); + + p = of_get_property(dn, "vas-id", NULL); + if (!p) { + pr_err("VAS: NULL vas-id? %p\n", p); + return -ENODEV; + } + + vinst->vas_id = of_read_number(p, 1); + + rc = of_property_read_u64(dn, "hvwc-bar-start", &vinst->hvwc_bar_start); + if (rc) + return rc; + + rc = of_property_read_u64(dn, "hvwc-bar-size", &vinst->hvwc_bar_len); + if (rc) + return rc; + + rc = of_property_read_u64(dn, "uwc-bar-start", &vinst->uwc_bar_start); + if (rc) + return rc; + + rc = of_property_read_u64(dn, "uwc-bar-size", &vinst->uwc_bar_len); + if (rc) + return rc; + + rc = of_property_read_u64(dn, "window-base", &vinst->win_base_addr); + if (rc) + return rc; + + rc = of_property_read_u64(dn, "window-shift", &vinst->win_id_shift); + if (rc) + return rc; + + init_vas_chip(vinst); + + return 0; +} + +/* + * Although this is read/used multiple times, it is written to only + * during initialization. + */ +struct vas_instance *find_vas_instance(int vasid) +{ + int i; + struct vas_instance *vinst; + + for (i = 0; i < vas_num_instances; i++) { + vinst = &vas_instances[i]; + if (vinst->vas_id == vasid) + return vinst; + } + pr_err("VAS instance for vas-id %d not found\n", vasid); + WARN_ON_ONCE(1); + return NULL; +} + + +int vas_init(void) +{ + int rc; + struct device_node *dn; + struct vas_instance *vinst; + + if (!pvr_version_is(PVR_POWER9)) + return -ENODEV; + + vas_num_instances = 0; + for_each_node_by_name(dn, "vas") + vas_num_instances++; + + if (!vas_num_instances) + return -ENODEV; + + vas_instances = kcalloc(vas_num_instances, sizeof(*vinst), GFP_KERNEL); + if (!vas_instances) + return -ENOMEM; + + vinst = &vas_instances[0]; + for_each_node_by_name(dn, "vas") { + rc = init_vas_instance(dn, vinst); + if (rc) { + pr_err("Error %d initializing VAS instance %ld\n", rc, + (vinst-&vas_instances[0])); + goto cleanup; + } + vinst++; + } + + rc = -ENODEV; + if (vinst == &vas_instances[0]) { + /* Should not happen as we saw some above. */ + pr_err("VAS: Did not find any VAS DT nodes now!\n"); + goto cleanup; + } + + pr_devel("VAS: Initialized %d instances\n", vas_num_instances); + vas_initialized = 1; + + return 0; + +cleanup: + kfree(vas_instances); + return rc; +} + +void vas_exit(void) +{ + vas_initialized = 0; + kfree(vas_instances); +} + +module_init(vas_init); +module_exit(vas_exit); +MODULE_DESCRIPTION("IBM Virtual Accelerator Switchboard"); +MODULE_AUTHOR("Sukadev Bhattiprolu "); +MODULE_LICENSE("GPL");