xref: /spdk/include/spdk/opal.h (revision da6841e4509a8eec7972dfe154ea9f13d09d9be1)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2019 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef SPDK_OPAL_H
7 #define SPDK_OPAL_H
8 
9 #include "spdk/stdinc.h"
10 #include "spdk/nvme.h"
11 #include "spdk/log.h"
12 #include "spdk/endian.h"
13 #include "spdk/string.h"
14 #include "spdk/opal_spec.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 struct spdk_opal_d0_features_info {
21 	struct spdk_opal_d0_tper_feat tper;
22 	struct spdk_opal_d0_locking_feat locking;
23 	struct spdk_opal_d0_single_user_mode_feat single_user;
24 	struct spdk_opal_d0_geo_feat geo;
25 	struct spdk_opal_d0_datastore_feat datastore;
26 	struct spdk_opal_d0_v100_feat v100;
27 	struct spdk_opal_d0_v200_feat v200;
28 };
29 
30 enum spdk_opal_lock_state {
31 	OPAL_READONLY	= 0x01,
32 	OPAL_RWLOCK		= 0x02,
33 	OPAL_READWRITE	= 0x04,
34 };
35 
36 enum spdk_opal_user {
37 	OPAL_ADMIN1 = 0x0,
38 	OPAL_USER1 = 0x01,
39 	OPAL_USER2 = 0x02,
40 	OPAL_USER3 = 0x03,
41 	OPAL_USER4 = 0x04,
42 	OPAL_USER5 = 0x05,
43 	OPAL_USER6 = 0x06,
44 	OPAL_USER7 = 0x07,
45 	OPAL_USER8 = 0x08,
46 	OPAL_USER9 = 0x09,
47 };
48 
49 enum spdk_opal_locking_range {
50 	OPAL_LOCKING_RANGE_GLOBAL = 0x0,
51 	OPAL_LOCKING_RANGE_1,
52 	OPAL_LOCKING_RANGE_2,
53 	OPAL_LOCKING_RANGE_3,
54 	OPAL_LOCKING_RANGE_4,
55 	OPAL_LOCKING_RANGE_5,
56 	OPAL_LOCKING_RANGE_6,
57 	OPAL_LOCKING_RANGE_7,
58 	OPAL_LOCKING_RANGE_8,
59 	OPAL_LOCKING_RANGE_9,
60 	OPAL_LOCKING_RANGE_10,
61 };
62 
63 struct spdk_opal_locking_range_info {
64 	uint8_t locking_range_id;
65 	uint8_t _padding[7];
66 	uint64_t range_start;
67 	uint64_t range_length;
68 	bool read_lock_enabled;
69 	bool write_lock_enabled;
70 	bool read_locked;
71 	bool write_locked;
72 };
73 
74 struct spdk_opal_dev;
75 
76 struct spdk_opal_dev *spdk_opal_dev_construct(struct spdk_nvme_ctrlr *ctrlr);
77 void spdk_opal_dev_destruct(struct spdk_opal_dev *dev);
78 
79 struct spdk_opal_d0_features_info *spdk_opal_get_d0_features_info(struct spdk_opal_dev *dev);
80 
81 int spdk_opal_cmd_take_ownership(struct spdk_opal_dev *dev, char *new_passwd);
82 
83 /**
84  * synchronous function: send and then receive.
85  *
86  * Wait until response is received.
87  */
88 int spdk_opal_cmd_revert_tper(struct spdk_opal_dev *dev, const char *passwd);
89 
90 int spdk_opal_cmd_activate_locking_sp(struct spdk_opal_dev *dev, const char *passwd);
91 int spdk_opal_cmd_lock_unlock(struct spdk_opal_dev *dev, enum spdk_opal_user user,
92 			      enum spdk_opal_lock_state flag, enum spdk_opal_locking_range locking_range,
93 			      const char *passwd);
94 int spdk_opal_cmd_setup_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user user,
95 				      enum spdk_opal_locking_range locking_range_id, uint64_t range_start,
96 				      uint64_t range_length, const char *passwd);
97 
98 int spdk_opal_cmd_get_max_ranges(struct spdk_opal_dev *dev, const char *passwd);
99 int spdk_opal_cmd_get_locking_range_info(struct spdk_opal_dev *dev, const char *passwd,
100 		enum spdk_opal_user user_id,
101 		enum spdk_opal_locking_range locking_range_id);
102 int spdk_opal_cmd_enable_user(struct spdk_opal_dev *dev, enum spdk_opal_user user_id,
103 			      const char *passwd);
104 int spdk_opal_cmd_add_user_to_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user user_id,
105 		enum spdk_opal_locking_range locking_range_id,
106 		enum spdk_opal_lock_state lock_flag, const char *passwd);
107 int spdk_opal_cmd_set_new_passwd(struct spdk_opal_dev *dev, enum spdk_opal_user user_id,
108 				 const char *new_passwd, const char *old_passwd, bool new_user);
109 
110 int spdk_opal_cmd_erase_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user user_id,
111 				      enum spdk_opal_locking_range locking_range_id, const char *password);
112 
113 int spdk_opal_cmd_secure_erase_locking_range(struct spdk_opal_dev *dev, enum spdk_opal_user user_id,
114 		enum spdk_opal_locking_range locking_range_id, const char *password);
115 
116 struct spdk_opal_locking_range_info *spdk_opal_get_locking_range_info(struct spdk_opal_dev *dev,
117 		enum spdk_opal_locking_range id);
118 void spdk_opal_free_locking_range_info(struct spdk_opal_dev *dev, enum spdk_opal_locking_range id);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
125