Received: by 10.213.65.68 with SMTP id h4csp18621imn; Mon, 19 Mar 2018 18:05:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELtlFV7ECZJ12hhChZx7MRl05NsX24LAn1USJJETBqiO7Z7I4EaDnqu3YGWA/jSDWyB4SYxU X-Received: by 2002:a17:902:209:: with SMTP id 9-v6mr14190234plc.403.1521507912005; Mon, 19 Mar 2018 18:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521507911; cv=none; d=google.com; s=arc-20160816; b=w+EvYgLd6LzlwBDQ4BJ9+G7mzJvwP7WBSrGT6/CoB3MllIB+U8jRTox6I/s4QkQ8ln yAktKnnySdPEZx+Jj+gnXFmw/ZOcdnvTvNUidrw08z0Q8eqOfD0/HeZdhestjDl45gyX Efss9+MVPPmwJ0xOY1kottXHn9xIcKZ2psLk3ggl4sSqzxqg5L7ui01aBoEVDEpfQuVy JBFgAiKRZn8RnQVNoShWB2zKB7ZDUb1HI2Dr4vehqPAZp46HoEQDyFoHprlV5BcE6YMc mKGPnyKIp0eyLR8r7uMyoZjqri4XaWSfoV3cJ7uepHoDwqMn6XCn4NQlgHl3yL++Z6YO pezw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SKMd14MjhA49cVXTTbt6CSzvUKjaIzHDMDCNESkHIbU=; b=yruljKQUZeA2UfnHQ2NB8LYVO8PKFpQcBZbuQGaQ+LeQ51yNkWcOTtGuer7Ojj9C+Q 87THjRYpKzgICxIKVbjB2QUZG60bB56OlLFQMyvnqlgfdwdHDwrGfpqSJ2N+2CFsh7H3 difa5wxXzq/ugaGAUcUijjTr7Wrbg8+vAU5v3GxwYJBbhDbc4JNSVkpmypZmFV/eDDhi Sq69FQH9qTz9wTjo/l6mgQTq8GZjipMRVi0alJtuloG+ZsEUHWlyijWkntge2tErny64 0WM4VMnJMDr1+Iz2moVUoqkhL2T+W4AGv6XSiNRuNpaIF2st1gFL/lt79NxCoA3lMRfv 8muw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10-v6si495919plt.533.2018.03.19.18.04.56; Mon, 19 Mar 2018 18:05:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970515AbeCSSiS (ORCPT + 99 others); Mon, 19 Mar 2018 14:38:18 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de ([131.188.11.21]:43864 "EHLO mx-rz-2.rrze.uni-erlangen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970494AbeCSSiK (ORCPT ); Mon, 19 Mar 2018 14:38:10 -0400 Received: from mx-rz-2.rrze.uni-erlangen.de (mx-rz-2.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx-rz-2.rrze.uni-erlangen.de (Postfix) with ESMTPS id 404lDw3dyvzPkDb; Mon, 19 Mar 2018 19:38:08 +0100 (CET) Authentication-Results: mx-rz-2.rrze.uni-erlangen.de; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Quarantine-ID: X-Virus-Scanned: amavisd-new at boeck2.rrze.uni-erlangen.de (RRZE) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2003:d5:3db:1800:60b5:55d8:d757:229 Received: from fau.de (p200300D503DB180060B555D8D7570229.dip0.t-ipconnect.de [IPv6:2003:d5:3db:1800:60b5:55d8:d757:229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: U2FsdGVkX188rpASASDvw5XbHvO+i4JA3yBRN0+3NdE=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 404lDs0zSTzPkHW; Mon, 19 Mar 2018 19:38:05 +0100 (CET) From: Jonas Rabenstein To: Jonas Rabenstein , Scott Bauer , Jonathan Derrick , Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH v2 09/11] block: sed-opal: unify retrieval of table columns Date: Mon, 19 Mar 2018 19:36:51 +0100 Message-Id: <0cb968f26381001513c188a13cbc92b76a305712.1521482296.git.jonas.rabenstein@studium.uni-erlangen.de> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of having multiple places defining the same argument list to get a specific column of a sed-opal table, provide a generic version and call it from those functions. Signed-off-by: Jonas Rabenstein diff --git a/block/opal_proto.h b/block/opal_proto.h index e20be8258854..b6e352cfe982 100644 --- a/block/opal_proto.h +++ b/block/opal_proto.h @@ -170,6 +170,8 @@ enum opal_token { OPAL_READLOCKED = 0x07, OPAL_WRITELOCKED = 0x08, OPAL_ACTIVEKEY = 0x0A, + /* lockingsp table */ + OPAL_LIFECYCLE = 0x06, /* locking info table */ OPAL_MAXRANGES = 0x04, /* mbr control */ diff --git a/block/sed-opal.c b/block/sed-opal.c index 4549fa164e98..5b7b23cb95a4 100644 --- a/block/sed-opal.c +++ b/block/sed-opal.c @@ -1076,6 +1076,37 @@ static int finalize_and_send(struct opal_dev *dev, cont_fn cont) return opal_send_recv(dev, cont); } +/* + * request @column from table @table on device @dev. On success, the column + * data will be available in dev->resp->tok[4] + */ +static int generic_get_column(struct opal_dev *dev, const u8 *table, + u64 column) +{ + int err; + + err = start_opal_cmd(dev, table, opalmethod[OPAL_GET]); + + add_token_u8(&err, dev, OPAL_STARTLIST); + + add_token_u8(&err, dev, OPAL_STARTNAME); + add_token_u8(&err, dev, OPAL_STARTCOLUMN); + add_token_u64(&err, dev, column); + add_token_u8(&err, dev, OPAL_ENDNAME); + + add_token_u8(&err, dev, OPAL_STARTNAME); + add_token_u8(&err, dev, OPAL_ENDCOLUMN); + add_token_u64(&err, dev, column); + add_token_u8(&err, dev, OPAL_ENDNAME); + + add_token_u8(&err, dev, OPAL_ENDLIST); + + if (err) + return err; + + return finalize_and_send(dev, parse_and_check_status); +} + static int gen_key(struct opal_dev *dev, void *data) { u8 uid[OPAL_UID_LENGTH]; @@ -1130,23 +1161,11 @@ static int get_active_key(struct opal_dev *dev, void *data) if (err) return err; - err = start_opal_cmd(dev, uid, opalmethod[OPAL_GET]); - add_token_u8(&err, dev, OPAL_STARTLIST); - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 3); /* startCloumn */ - add_token_u8(&err, dev, 10); /* ActiveKey */ - add_token_u8(&err, dev, OPAL_ENDNAME); - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 4); /* endColumn */ - add_token_u8(&err, dev, 10); /* ActiveKey */ - add_token_u8(&err, dev, OPAL_ENDNAME); - add_token_u8(&err, dev, OPAL_ENDLIST); - if (err) { - pr_debug("Error building get active key command\n"); + err = generic_get_column(dev, uid, OPAL_ACTIVEKEY); + if (err) return err; - } - return finalize_and_send(dev, get_active_key_cont); + return get_active_key_cont(dev); } static int generic_lr_enable_disable(struct opal_dev *dev, @@ -1801,14 +1820,16 @@ static int activate_lsp(struct opal_dev *dev, void *data) return finalize_and_send(dev, parse_and_check_status); } -static int get_lsp_lifecycle_cont(struct opal_dev *dev) +/* Determine if we're in the Manufactured Inactive or Active state */ +static int get_lsp_lifecycle(struct opal_dev *dev, void *data) { u8 lc_status; - int error = 0; + int err; - error = parse_and_check_status(dev); - if (error) - return error; + err = generic_get_column(dev, opaluid[OPAL_LOCKINGSP_UID], + OPAL_LIFECYCLE); + if (err) + return err; lc_status = response_get_u64(&dev->parsed, 4); /* 0x08 is Manufacured Inactive */ @@ -1821,49 +1842,19 @@ static int get_lsp_lifecycle_cont(struct opal_dev *dev) return 0; } -/* Determine if we're in the Manufactured Inactive or Active state */ -static int get_lsp_lifecycle(struct opal_dev *dev, void *data) -{ - int err; - - err = start_opal_cmd(dev, opaluid[OPAL_LOCKINGSP_UID], - opalmethod[OPAL_GET]); - - add_token_u8(&err, dev, OPAL_STARTLIST); - - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 3); /* Start Column */ - add_token_u8(&err, dev, 6); /* Lifecycle Column */ - add_token_u8(&err, dev, OPAL_ENDNAME); - - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 4); /* End Column */ - add_token_u8(&err, dev, 6); /* Lifecycle Column */ - add_token_u8(&err, dev, OPAL_ENDNAME); - - add_token_u8(&err, dev, OPAL_ENDLIST); - - if (err) { - pr_debug("Error Building GET Lifecycle Status command\n"); - return err; - } - - return finalize_and_send(dev, get_lsp_lifecycle_cont); -} - -static int get_msid_cpin_pin_cont(struct opal_dev *dev) +static int get_msid_cpin_pin(struct opal_dev *dev, void *data) { const char *msid_pin; size_t strlen; - int error = 0; + int err; - error = parse_and_check_status(dev); - if (error) - return error; + err = generic_get_column(dev, opaluid[OPAL_C_PIN_MSID], OPAL_PIN); + if (err) + return err; strlen = response_get_string(&dev->parsed, 4, &msid_pin); if (!msid_pin) { - pr_debug("%s: Couldn't extract PIN from response\n", __func__); + pr_debug("Couldn't extract MSID_CPIN from response\n"); return OPAL_INVAL_PARAM; } @@ -1876,33 +1867,6 @@ static int get_msid_cpin_pin_cont(struct opal_dev *dev) return 0; } -static int get_msid_cpin_pin(struct opal_dev *dev, void *data) -{ - int err; - - err = start_opal_cmd(dev, opaluid[OPAL_C_PIN_MSID], - opalmethod[OPAL_GET]); - - add_token_u8(&err, dev, OPAL_STARTLIST); - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 3); /* Start Column */ - add_token_u8(&err, dev, 3); /* PIN */ - add_token_u8(&err, dev, OPAL_ENDNAME); - - add_token_u8(&err, dev, OPAL_STARTNAME); - add_token_u8(&err, dev, 4); /* End Column */ - add_token_u8(&err, dev, 3); /* Lifecycle Column */ - add_token_u8(&err, dev, OPAL_ENDNAME); - add_token_u8(&err, dev, OPAL_ENDLIST); - - if (err) { - pr_debug("Error building Get MSID CPIN PIN command.\n"); - return err; - } - - return finalize_and_send(dev, get_msid_cpin_pin_cont); -} - static int end_opal_session(struct opal_dev *dev, void *data) { int err = 0; -- 2.16.1