From patchwork Tue Apr 13 08:30:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haren Myneni X-Patchwork-Id: 420300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BC9AC433B4 for ; Tue, 13 Apr 2021 08:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB7CA613CA for ; Tue, 13 Apr 2021 08:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbhDMIal (ORCPT ); Tue, 13 Apr 2021 04:30:41 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:13650 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229963AbhDMIaj (ORCPT ); Tue, 13 Apr 2021 04:30:39 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13D83GIR158150; Tue, 13 Apr 2021 04:30:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=pxeHkQP1kmn1yXzALIc5qkqciwnKnZqng2FUwOgZiXs=; b=g2/+WCm/dUqpUSGdxAl8vSFvm3276P/MWwdP4hvx+9qQttFhTXOdwXARVC2lPPzZtSwm v4DGkefPs5FWoy9RAj4GFoV7ehwNjd84BUUlR8Tm5AoR7VB/zPjgFa7hWjCRMkkZ0dOt EvX5Yup4ZevYbYjPHziZxGz0SR1qyCvL3Ocpr2vYmzjfV3MtxC5jUBeL+SsirXiytwK1 cL5g2UPo31egRpMLFHNJzfs3pVn06HBBWSEWRUKEG3s3pNZKmvtekF86weRqGfkRc4Nn sU/OfY3knxMMsflxPtAePRJ+rCOXIUvLvQN98NcKkudGQgpreF8ecqBUdbYhHi5owcRL gQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0nn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:30:11 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13D8N4sC034347; Tue, 13 Apr 2021 04:30:11 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtnt0nmj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 04:30:11 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13D8S3Bm021314; Tue, 13 Apr 2021 08:30:10 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma04wdc.us.ibm.com with ESMTP id 37u3n9y4kn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 08:30:10 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13D8UAvV32309620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 08:30:10 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB16CAC05B; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2687DAC060; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.232.48]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 08:30:09 +0000 (GMT) Message-ID: <1bb10e6566b6984448489f93b89686c0bb1fbe7f.camel@linux.ibm.com> Subject: [V2 PATCH 15/16] crypto/nx: Get NX capabilities for GZIP coprocessor type From: Haren Myneni To: linuxppc-dev@lists.ozlabs.org, linux-crypto@vger.kernel.org, mpe@ellerman.id.au, herbert@gondor.apana.org.au, npiggin@gmail.com Cc: hbabu@us.ibm.com Date: Tue, 13 Apr 2021 01:30:07 -0700 In-Reply-To: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> References: <68aa9f2860f9acffa41469d3858883c938634722.camel@linux.ibm.com> User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: IlFbmZQbgY6yoe2DirnUgsaknPzmyqEq X-Proofpoint-ORIG-GUID: hGEISsj94auK1NWnhbqUz0LWBOQCevz5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_03:2021-04-13,2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130055 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org phyp provides NX capabilities which gives recommended minimum compression / decompression length and maximum request buffer size in bytes. Changes to get NX overall capabilities which points to the specific features phyp supports. Then retrieve NXGZIP specific capabilities. Signed-off-by: Haren Myneni --- drivers/crypto/nx/nx-common-pseries.c | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/crypto/nx/nx-common-pseries.c b/drivers/crypto/nx/nx-common-pseries.c index 9a40fca8a9e6..49224870d05e 100644 --- a/drivers/crypto/nx/nx-common-pseries.c +++ b/drivers/crypto/nx/nx-common-pseries.c @@ -9,6 +9,7 @@ */ #include +#include #include #include "nx-842.h" @@ -20,6 +21,24 @@ MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); MODULE_ALIAS_CRYPTO("842"); MODULE_ALIAS_CRYPTO("842-nx"); +struct nx_ct_capabs_be { + __be64 descriptor; + __be64 req_max_processed_len; /* Max bytes in one GZIP request */ + __be64 min_compress_len; /* Min compression size in bytes */ + __be64 min_decompress_len; /* Min decompression size in bytes */ +} __packed __aligned(0x1000); + +struct nx_ct_capabs { + char name[VAS_DESCR_LEN + 1]; + u64 descriptor; + u64 req_max_processed_len; /* Max bytes in one GZIP request */ + u64 min_compress_len; /* Min compression in bytes */ + u64 min_decompress_len; /* Min decompression in bytes */ +}; + +u64 capab_feat = 0; +struct nx_ct_capabs nx_ct_capab; + static struct nx842_constraints nx842_pseries_constraints = { .alignment = DDE_BUFFER_ALIGN, .multiple = DDE_BUFFER_LAST_MULT, @@ -1066,6 +1085,66 @@ static void nx842_remove(struct vio_dev *viodev) kfree(old_devdata); } +/* + * Get NX capabilities from pHyp. + * Only NXGZIP capabilities are available right now and these values + * are available through sysfs. + */ +static void __init nxct_get_capabilities(void) +{ + struct vas_all_capabs_be *capabs_be; + struct nx_ct_capabs_be *nxc_be; + int rc; + + capabs_be = kmalloc(sizeof(*capabs_be), GFP_KERNEL); + if (!capabs_be) + return; + /* + * Get NX overall capabilities with feature type=0 + */ + rc = plpar_vas_query_capabilities(H_QUERY_NX_CAPABILITIES, 0, + (u64)virt_to_phys(capabs_be)); + if (rc) + goto out; + + capab_feat = be64_to_cpu(capabs_be->feat_type); + /* + * NX-GZIP feature available + */ + if (capab_feat & VAS_NX_GZIP_FEAT_BIT) { + nxc_be = kmalloc(sizeof(*nxc_be), GFP_KERNEL); + if (!nxc_be) + goto out; + /* + * Get capabilities for NX-GZIP feature + */ + rc = plpar_vas_query_capabilities(H_QUERY_NX_CAPABILITIES, + VAS_NX_GZIP_FEAT, + (u64)virt_to_phys(nxc_be)); + } else { + pr_err("NX-GZIP feature is not available\n"); + rc = -EINVAL; + } + + if (!rc) { + snprintf(nx_ct_capab.name, VAS_DESCR_LEN + 1, "%.8s", + (char *)&nxc_be->descriptor); + nx_ct_capab.descriptor = be64_to_cpu(nxc_be->descriptor); + nx_ct_capab.req_max_processed_len = + be64_to_cpu(nxc_be->req_max_processed_len); + nx_ct_capab.min_compress_len = + be64_to_cpu(nxc_be->min_compress_len); + nx_ct_capab.min_decompress_len = + be64_to_cpu(nxc_be->min_decompress_len); + } else { + capab_feat = 0; + } + + kfree(nxc_be); +out: + kfree(capabs_be); +} + static const struct vio_device_id nx842_vio_driver_ids[] = { {"ibm,compression-v1", "ibm,compression"}, {"", ""}, @@ -1093,6 +1172,10 @@ static int __init nx842_pseries_init(void) return -ENOMEM; RCU_INIT_POINTER(devdata, new_devdata); + /* + * Get NX capabilities from pHyp which is used for NX-GZIP. + */ + nxct_get_capabilities(); ret = vio_register_driver(&nx842_vio_driver); if (ret) {