From patchwork Wed Mar 4 06:26:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 446236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 11CC814016A for ; Thu, 5 Mar 2015 00:32:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=neutral reason="verification failed; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=ZpxEHtkf; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id E507F1A0290 for ; Thu, 5 Mar 2015 00:32:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=neutral reason="verification failed; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=ZpxEHtkf; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pa0-x231.google.com (mail-pa0-x231.google.com [IPv6:2607:f8b0:400e:c03::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 002F11A01BA for ; Thu, 5 Mar 2015 00:32:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass reason="1024-bit key; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=ZpxEHtkf; dkim-adsp=pass; dkim-atps=neutral Received: by pabrd3 with SMTP id rd3so9599721pab.5 for ; Wed, 04 Mar 2015 05:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=Zac545d+qtmJvEJSCGJHRal5EhTevmrDQT2UcF3yphA=; b=ZpxEHtkfjdkCdfrS4J1iWI+quF1Ee/IVXC8zuuHbQoK+W2nOIxhBW1uGTAeEnCN1pJ QmRvQizpHDi/IFV+F5DX7+uM1znILhGpS+1nwOMviTrWLbGYMAe4qNy8ED5aDjvjBLKN zd/p4xYHodqiviQXccI4EqE96Ra1KW+66MyoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Zac545d+qtmJvEJSCGJHRal5EhTevmrDQT2UcF3yphA=; b=XnCn1rJbs+s33vXtSD30ZHV9hGNa38PinFnLrG9WbBg5RgkUomfa5ln3XvPfoxliho SfDG4FJZfhVV4gNT0Cm/0os9Lxc7Y1Ngq/GL6NDA9RA1/L875UpZN1eyauImIhVj0Isa tAOtCpHPWe2g9fsvvEjlhxvd/TRokK+j1R8RJVSnybv1TGmtuIl9MsmVlhx+h/h7uR/7 LTCb1QWPVmDLIh3jdvNM9BwVrYFIyt18iWy/U17rvwxFo+WrOMA59yPaR21LG6hCyI1h 3WI7Pbwg2r576HhhPvg8SyQbtGfkDsAQb6jWCG9EQiwUFaCf0WVyYHl47eKCvr/+yzds tYmw== X-Gm-Message-State: ALoCoQltDK9hbd/G+wO2TB4zNFKSJl/WhBg9cA3p//RW1Lp9eZo9AqgdKhYgEpIcMu6s1fDRiCoS X-Received: by 10.68.117.133 with SMTP id ke5mr6915422pbb.162.1425475951139; Wed, 04 Mar 2015 05:32:31 -0800 (PST) Received: from icarus.jms.id.au ([118.211.5.168]) by mx.google.com with ESMTPSA id iy2sm4123431pbb.22.2015.03.04.05.32.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 05:32:29 -0800 (PST) Received: by icarus.jms.id.au (Postfix, from userid 1000) id 220781013B9; Wed, 4 Mar 2015 16:56:16 +1030 (ACDT) From: Joel Stanley To: skiboot@lists.ozlabs.org Date: Wed, 4 Mar 2015 16:56:13 +1030 Message-Id: <1425450374-6855-2-git-send-email-joel@jms.id.au> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425450374-6855-1-git-send-email-joel@jms.id.au> References: <1425450374-6855-1-git-send-email-joel@jms.id.au> Subject: [Skiboot] [PATCH 2/3] external/opal-prd: Allow partial ops with PNOR API X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The PNOR operations will now return the number of bytes successfully written, which may be less than the number of bytes requested, similar to read(2) and write(2). The hostboot interface is updated with this information. The signature does not change. Signed-off-by: Joel Stanley --- external/opal-prd/hostboot-interface.h | 4 ++-- external/opal-prd/pnor.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/external/opal-prd/hostboot-interface.h b/external/opal-prd/hostboot-interface.h index 1088178..a518f50 100644 --- a/external/opal-prd/hostboot-interface.h +++ b/external/opal-prd/hostboot-interface.h @@ -170,7 +170,7 @@ struct host_interfaces { * @param[in] i_offset: offset within the partition * @param[out] o_data: pointer to the data read * @param[in] i_sizeBytes: size of data to read - * @retval rc - non-zero on error + * @retval rc - number of bytes read, or non-zero on error * @platform OpenPOWER */ int (*pnor_read) ( uint32_t i_proc, const char* i_partitionName, @@ -183,7 +183,7 @@ struct host_interfaces { * @param[in] i_offset: offset withing the partition * @param[in] i_data: pointer to the data to write * @param[in] i_sizeBytes: size of data to write - * @retval rc - non-zero on error + * @retval rc - number of bytes written, or non-zero on error * @platform OpenPOWER */ int (*pnor_write) ( uint32_t i_proc, const char* i_partitionName, diff --git a/external/opal-prd/pnor.c b/external/opal-prd/pnor.c index e5609fe..e40d292 100644 --- a/external/opal-prd/pnor.c +++ b/external/opal-prd/pnor.c @@ -240,11 +240,16 @@ out: return rc; } +/* Similar to read(2), this performs partial operations where the number of + * bytes read/written may be less than size. + * + * Returns number of bytes written, or a negative value on failure. */ int pnor_operation(struct pnor *pnor, const char *name, uint64_t offset, - void *data, size_t size, enum pnor_op op) + void *data, size_t requested_size, enum pnor_op op) { int rc, fd; uint32_t pstart, psize, idx; + int size; if (!pnor->ffsh) { warnx("PNOR: ffs not initialised"); @@ -263,9 +268,23 @@ int pnor_operation(struct pnor *pnor, const char *name, uint64_t offset, return -ENOENT; } - if (size > psize || offset > psize || size + offset > psize) { - warnx("PNOR: offset (%ld) or size (%ld) out of bounds (%d)", - offset, size, psize); + if (offset > psize) { + warnx("PNOR: offset (%ld) out of bounds (%d)", offset, psize); + return -ERANGE; + } + + /* Large requests are trimmed */ + if (requested_size > psize) + size = psize; + else + size = requested_size; + + if (size + offset > psize) + size = psize - offset; + + if (size < 0) { + warnx("PNOR: size (%zd) and offset (%ld) out of bounds (%d)", + requested_size, offset, psize); return -ERANGE; } @@ -297,11 +316,8 @@ int pnor_operation(struct pnor *pnor, const char *name, uint64_t offset, if (rc < 0) warn("PNOR: MTD operation failed"); else if (rc != size) - warnx("PNOR: mtd operation returned %d, expected %zd", + warnx("PNOR: mtd operation returned %d, expected %d", rc, size); - else - rc = 0; - out: close(fd);