From patchwork Wed May 6 16:51:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Streetman X-Patchwork-Id: 6351321 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 28614BEEE1 for ; Wed, 6 May 2015 16:54:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23C02201CE for ; Wed, 6 May 2015 16:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F103420328 for ; Wed, 6 May 2015 16:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751707AbbEFQyF (ORCPT ); Wed, 6 May 2015 12:54:05 -0400 Received: from mail-ie0-f182.google.com ([209.85.223.182]:36269 "EHLO mail-ie0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752618AbbEFQwx (ORCPT ); Wed, 6 May 2015 12:52:53 -0400 Received: by iecnq11 with SMTP id nq11so18948003iec.3; Wed, 06 May 2015 09:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=m2Zc/9v72PLAWf4RwHKVp4AquZclixpSthWWlEnsFIc=; b=MTPl+JqMa5Ouh0g9bgpCcL7TvF4d/55WBlB0NeBJMMy8eP7n0xMwDC8VGwOZ1wUf4j Z0CBP69V3AFUmeMuWEVUgXL1epC5LdYHaCFVqh1mCWMPZCNVLLv5gygnukaND8xLFQsF OfKnDokZHwpYFGGHj6RgB/gLIagBzJKPybMF0qvJrUOoGXo1/sRVKo182jRPiMHp96Ym VJAnpC9ZioarqFsWLu1Wu+Fr7mjC9klSpcvMEzVACkJEvTG0VnjdpvuESSL2BcS1In9T pND8o1cAePEFtGyPS1AwdJvVxMLdRxvklr+Yf2HF3pnU0MkjRvx1qmGlhX97uShI6taE TE9Q== X-Received: by 10.50.142.2 with SMTP id rs2mr4133543igb.1.1430931172369; Wed, 06 May 2015 09:52:52 -0700 (PDT) Received: from toughbook.com (user-0c8ho8q.cable.mindspring.com. [24.136.225.26]) by mx.google.com with ESMTPSA id m9sm1143291igv.4.2015.05.06.09.52.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 May 2015 09:52:51 -0700 (PDT) From: Dan Streetman To: Herbert Xu , "David S. Miller" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: Dan Streetman , Seth Jennings , Robert Jennings , linux-crypto@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/10] drivers/crypto/nx: add nx842 constraints Date: Wed, 6 May 2015 12:51:03 -0400 Message-Id: <1430931066-4536-8-git-send-email-ddstreet@ieee.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430931066-4536-1-git-send-email-ddstreet@ieee.org> References: <1428428070-17803-1-git-send-email-ddstreet@ieee.org> <1430931066-4536-1-git-send-email-ddstreet@ieee.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add "constraints" for the NX-842 driver. The constraints are used to indicate what the current NX-842 platform driver is capable of. The constraints tell the NX-842 user what alignment, min and max length, and length multiple each provided buffers should conform to. These are required because the 842 hardware requires buffers to meet specific constraints that vary based on platform - for example, the pSeries max length is much lower than the PowerNV max length. Signed-off-by: Dan Streetman --- drivers/crypto/nx/nx-842-pseries.c | 10 ++++++++++ drivers/crypto/nx/nx-842.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/crypto/nx/nx-842.h | 2 ++ include/linux/nx842.h | 9 +++++++++ 4 files changed, 59 insertions(+) diff --git a/drivers/crypto/nx/nx-842-pseries.c b/drivers/crypto/nx/nx-842-pseries.c index 9b83c9e..cb481d8 100644 --- a/drivers/crypto/nx/nx-842-pseries.c +++ b/drivers/crypto/nx/nx-842-pseries.c @@ -40,6 +40,13 @@ MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); /* IO buffer must be 128 byte aligned */ #define IO_BUFFER_ALIGN 128 +static struct nx842_constraints nx842_pseries_constraints = { + .alignment = IO_BUFFER_ALIGN, + .multiple = DDE_BUFFER_LAST_MULT, + .minimum = IO_BUFFER_ALIGN, + .maximum = PAGE_SIZE, /* dynamic, max_sync_size */ +}; + struct nx842_header { int blocks_nr; /* number of compressed blocks */ int offset; /* offset of the first block (from beginning of header) */ @@ -842,6 +849,8 @@ static int nx842_OF_upd_maxsyncop(struct nx842_devdata *devdata, goto out; } + nx842_pseries_constraints.maximum = devdata->max_sync_size; + devdata->max_sync_sg = (unsigned int)min(maxsynccop->comp_sg_limit, maxsynccop->decomp_sg_limit); if (devdata->max_sync_sg < 1) { @@ -1115,6 +1124,7 @@ static struct attribute_group nx842_attribute_group = { static struct nx842_driver nx842_pseries_driver = { .owner = THIS_MODULE, + .constraints = &nx842_pseries_constraints, .compress = nx842_pseries_compress, .decompress = nx842_pseries_decompress, }; diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c index f1f378e..160fe2d 100644 --- a/drivers/crypto/nx/nx-842.c +++ b/drivers/crypto/nx/nx-842.c @@ -86,6 +86,44 @@ static void put_driver(struct nx842_driver *driver) module_put(driver->owner); } +/** + * nx842_constraints + * + * This provides the driver's constraints. Different nx842 implementations + * may have varying requirements. The constraints are: + * @alignment: All buffers should be aligned to this + * @multiple: All buffer lengths should be a multiple of this + * @minimum: Buffer lengths must not be less than this amount + * @maximum: Buffer lengths must not be more than this amount + * + * The constraints apply to all buffers and lengths, both input and output, + * for both compression and decompression, except for the minimum which + * only applies to compression input and decompression output; the + * compressed data can be less than the minimum constraint. It can be + * assumed that compressed data will always adhere to the multiple + * constraint. + * + * The driver may succeed even if these constraints are violated; + * however the driver can return failure or suffer reduced performance + * if any constraint is not met. + */ +int nx842_constraints(struct nx842_constraints *c) +{ + struct nx842_driver *driver = get_driver(); + int ret = 0; + + if (!driver) + return -ENODEV; + + BUG_ON(!c); + memcpy(c, driver->constraints, sizeof(*c)); + + put_driver(driver); + + return ret; +} +EXPORT_SYMBOL_GPL(nx842_constraints); + int nx842_compress(const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int *out_len, void *wrkmem) diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h index 2a5d4e1..c6ceb0f 100644 --- a/drivers/crypto/nx/nx-842.h +++ b/drivers/crypto/nx/nx-842.h @@ -12,6 +12,8 @@ struct nx842_driver { struct module *owner; + struct nx842_constraints *constraints; + int (*compress)(const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int *out_len, void *wrkmem); diff --git a/include/linux/nx842.h b/include/linux/nx842.h index d919c22..aa1a97e9 100644 --- a/include/linux/nx842.h +++ b/include/linux/nx842.h @@ -5,6 +5,15 @@ #define NX842_MEM_COMPRESS __NX842_PSERIES_MEM_COMPRESS +struct nx842_constraints { + int alignment; + int multiple; + int minimum; + int maximum; +}; + +int nx842_constraints(struct nx842_constraints *constraints); + int nx842_compress(const unsigned char *in, unsigned int in_len, unsigned char *out, unsigned int *out_len, void *wrkmem); int nx842_decompress(const unsigned char *in, unsigned int in_len,