block: sed-opal: Implement IOC_OPAL_REVERT_LSP
authorGreg Joyce <gjoyce@linux.vnet.ibm.com>
Fri, 21 Jul 2023 21:15:33 +0000 (16:15 -0500)
committerJens Axboe <axboe@kernel.dk>
Tue, 22 Aug 2023 17:10:26 +0000 (11:10 -0600)
This is used in conjunction with IOC_OPAL_REVERT_TPR to return a drive to
Original Factory State without erasing the data. If IOC_OPAL_REVERT_LSP
is called with opal_revert_lsp.options bit OPAL_PRESERVE set prior
to calling IOC_OPAL_REVERT_TPR, the drive global locking range will not
be erased.

Signed-off-by: Greg Joyce <gjoyce@linux.vnet.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jonathan Derrick <jonathan.derrick@linux.dev>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20230721211534.3437070-3-gjoyce@linux.vnet.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/opal_proto.h
block/sed-opal.c
include/linux/sed-opal.h
include/uapi/linux/sed-opal.h

index a4e56845dd8267e70adf2844898373812f7b07ee..dec7ce3a3edb7027b971232269846390e3baa834 100644 (file)
@@ -225,6 +225,10 @@ enum opal_parameter {
        OPAL_SUM_SET_LIST = 0x060000,
 };
 
+enum opal_revertlsp {
+       OPAL_KEEP_GLOBAL_RANGE_KEY = 0x060000,
+};
+
 /* Packets derived from:
  * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
  * Secion: 3.2.3 ComPackets, Packets & Subpackets
index 67c6c4f2b4b0f027edc2224e1c0f1e3c37047b3c..e2aed7f4ebdf6872666c210e7447f9b6d899eec7 100644 (file)
@@ -1769,6 +1769,26 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
        return finalize_and_send(dev, parse_and_check_status);
 }
 
+static int revert_lsp(struct opal_dev *dev, void *data)
+{
+       struct opal_revert_lsp *rev = data;
+       int err;
+
+       err = cmd_start(dev, opaluid[OPAL_THISSP_UID],
+                       opalmethod[OPAL_REVERTSP]);
+       add_token_u8(&err, dev, OPAL_STARTNAME);
+       add_token_u64(&err, dev, OPAL_KEEP_GLOBAL_RANGE_KEY);
+       add_token_u8(&err, dev, (rev->options & OPAL_PRESERVE) ?
+                       OPAL_TRUE : OPAL_FALSE);
+       add_token_u8(&err, dev, OPAL_ENDNAME);
+       if (err) {
+               pr_debug("Error building REVERT SP command.\n");
+               return err;
+       }
+
+       return finalize_and_send(dev, parse_and_check_status);
+}
+
 static int erase_locking_range(struct opal_dev *dev, void *data)
 {
        struct opal_session_info *session = data;
@@ -2463,6 +2483,23 @@ static int opal_get_discv(struct opal_dev *dev, struct opal_discovery *discv)
        return discv->size; /* modified to actual length of data */
 }
 
+static int opal_revertlsp(struct opal_dev *dev, struct opal_revert_lsp *rev)
+{
+       /* controller will terminate session */
+       const struct opal_step steps[] = {
+               { start_admin1LSP_opal_session, &rev->key },
+               { revert_lsp, rev }
+       };
+       int ret;
+
+       mutex_lock(&dev->dev_lock);
+       setup_opal_dev(dev);
+       ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
+       mutex_unlock(&dev->dev_lock);
+
+       return ret;
+}
+
 static int opal_erase_locking_range(struct opal_dev *dev,
                                    struct opal_session_info *opal_session)
 {
@@ -3084,6 +3121,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
        case IOC_OPAL_GET_GEOMETRY:
                ret = opal_get_geometry(dev, arg);
                break;
+       case IOC_OPAL_REVERT_LSP:
+               ret = opal_revertlsp(dev, p);
+               break;
        case IOC_OPAL_DISCOVERY:
                ret = opal_get_discv(dev, p);
                break;
index ef65f589fbebbce044acda1ab7a01f30c83692b3..2f189546e133838a6af1fd57fc1082ef96622b35 100644 (file)
@@ -48,6 +48,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
        case IOC_OPAL_GET_LR_STATUS:
        case IOC_OPAL_GET_GEOMETRY:
        case IOC_OPAL_DISCOVERY:
+       case IOC_OPAL_REVERT_LSP:
                return true;
        }
        return false;
index 7f5732c5bdc50308c76a59af17e06bf8799dbb9f..4e10675751b48461296b1a2b4822065940eced43 100644 (file)
@@ -56,6 +56,10 @@ struct opal_key {
        __u8 key[OPAL_KEY_MAX];
 };
 
+enum opal_revert_lsp_opts {
+       OPAL_PRESERVE = 0x01,
+};
+
 struct opal_lr_act {
        struct opal_key key;
        __u32 sum;
@@ -178,6 +182,12 @@ struct opal_discovery {
        __u64 size;
 };
 
+struct opal_revert_lsp {
+       struct opal_key key;
+       __u32 options;
+       __u32 __pad;
+};
+
 #define IOC_OPAL_SAVE              _IOW('p', 220, struct opal_lock_unlock)
 #define IOC_OPAL_LOCK_UNLOCK       _IOW('p', 221, struct opal_lock_unlock)
 #define IOC_OPAL_TAKE_OWNERSHIP            _IOW('p', 222, struct opal_key)
@@ -198,5 +208,6 @@ struct opal_discovery {
 #define IOC_OPAL_GET_LR_STATUS      _IOW('p', 237, struct opal_lr_status)
 #define IOC_OPAL_GET_GEOMETRY       _IOR('p', 238, struct opal_geometry)
 #define IOC_OPAL_DISCOVERY          _IOW('p', 239, struct opal_discovery)
+#define IOC_OPAL_REVERT_LSP         _IOW('p', 240, struct opal_revert_lsp)
 
 #endif /* _UAPI_SED_OPAL_H */