Skip to content

Commit 5c82efc

Browse files
Greg Joyceaxboe
authored andcommitted
block: sed-opal: Implement IOC_OPAL_REVERT_LSP
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>
1 parent 9fb1072 commit 5c82efc

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

block/opal_proto.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ enum opal_parameter {
225225
OPAL_SUM_SET_LIST = 0x060000,
226226
};
227227

228+
enum opal_revertlsp {
229+
OPAL_KEEP_GLOBAL_RANGE_KEY = 0x060000,
230+
};
231+
228232
/* Packets derived from:
229233
* TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
230234
* Secion: 3.2.3 ComPackets, Packets & Subpackets

block/sed-opal.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,26 @@ static int internal_activate_user(struct opal_dev *dev, void *data)
17691769
return finalize_and_send(dev, parse_and_check_status);
17701770
}
17711771

1772+
static int revert_lsp(struct opal_dev *dev, void *data)
1773+
{
1774+
struct opal_revert_lsp *rev = data;
1775+
int err;
1776+
1777+
err = cmd_start(dev, opaluid[OPAL_THISSP_UID],
1778+
opalmethod[OPAL_REVERTSP]);
1779+
add_token_u8(&err, dev, OPAL_STARTNAME);
1780+
add_token_u64(&err, dev, OPAL_KEEP_GLOBAL_RANGE_KEY);
1781+
add_token_u8(&err, dev, (rev->options & OPAL_PRESERVE) ?
1782+
OPAL_TRUE : OPAL_FALSE);
1783+
add_token_u8(&err, dev, OPAL_ENDNAME);
1784+
if (err) {
1785+
pr_debug("Error building REVERT SP command.\n");
1786+
return err;
1787+
}
1788+
1789+
return finalize_and_send(dev, parse_and_check_status);
1790+
}
1791+
17721792
static int erase_locking_range(struct opal_dev *dev, void *data)
17731793
{
17741794
struct opal_session_info *session = data;
@@ -2463,6 +2483,23 @@ static int opal_get_discv(struct opal_dev *dev, struct opal_discovery *discv)
24632483
return discv->size; /* modified to actual length of data */
24642484
}
24652485

2486+
static int opal_revertlsp(struct opal_dev *dev, struct opal_revert_lsp *rev)
2487+
{
2488+
/* controller will terminate session */
2489+
const struct opal_step steps[] = {
2490+
{ start_admin1LSP_opal_session, &rev->key },
2491+
{ revert_lsp, rev }
2492+
};
2493+
int ret;
2494+
2495+
mutex_lock(&dev->dev_lock);
2496+
setup_opal_dev(dev);
2497+
ret = execute_steps(dev, steps, ARRAY_SIZE(steps));
2498+
mutex_unlock(&dev->dev_lock);
2499+
2500+
return ret;
2501+
}
2502+
24662503
static int opal_erase_locking_range(struct opal_dev *dev,
24672504
struct opal_session_info *opal_session)
24682505
{
@@ -3084,6 +3121,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
30843121
case IOC_OPAL_GET_GEOMETRY:
30853122
ret = opal_get_geometry(dev, arg);
30863123
break;
3124+
case IOC_OPAL_REVERT_LSP:
3125+
ret = opal_revertlsp(dev, p);
3126+
break;
30873127
case IOC_OPAL_DISCOVERY:
30883128
ret = opal_get_discv(dev, p);
30893129
break;

include/linux/sed-opal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
4848
case IOC_OPAL_GET_LR_STATUS:
4949
case IOC_OPAL_GET_GEOMETRY:
5050
case IOC_OPAL_DISCOVERY:
51+
case IOC_OPAL_REVERT_LSP:
5152
return true;
5253
}
5354
return false;

include/uapi/linux/sed-opal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ struct opal_key {
5656
__u8 key[OPAL_KEY_MAX];
5757
};
5858

59+
enum opal_revert_lsp_opts {
60+
OPAL_PRESERVE = 0x01,
61+
};
62+
5963
struct opal_lr_act {
6064
struct opal_key key;
6165
__u32 sum;
@@ -178,6 +182,12 @@ struct opal_discovery {
178182
__u64 size;
179183
};
180184

185+
struct opal_revert_lsp {
186+
struct opal_key key;
187+
__u32 options;
188+
__u32 __pad;
189+
};
190+
181191
#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock)
182192
#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock)
183193
#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key)
@@ -198,5 +208,6 @@ struct opal_discovery {
198208
#define IOC_OPAL_GET_LR_STATUS _IOW('p', 237, struct opal_lr_status)
199209
#define IOC_OPAL_GET_GEOMETRY _IOR('p', 238, struct opal_geometry)
200210
#define IOC_OPAL_DISCOVERY _IOW('p', 239, struct opal_discovery)
211+
#define IOC_OPAL_REVERT_LSP _IOW('p', 240, struct opal_revert_lsp)
201212

202213
#endif /* _UAPI_SED_OPAL_H */

0 commit comments

Comments
 (0)