linux/block/sed-opal.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright © 2016 Intel Corporation
 *
 * Authors:
 *    Scott  Bauer      <[email protected]>
 *    Rafael Antognolli <[email protected]>
 */

#define pr_fmt(fmt)

#include <linux/delay.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/blkdev.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <uapi/linux/sed-opal.h>
#include <linux/sed-opal.h>
#include <linux/sed-opal-key.h>
#include <linux/string.h>
#include <linux/kdev_t.h>
#include <linux/key.h>
#include <linux/key-type.h>
#include <keys/user-type.h>

#include "opal_proto.h"

#define IO_BUFFER_LENGTH
#define MAX_TOKS

/* Number of bytes needed by cmd_finalize. */
#define CMD_FINALIZE_BYTES_NEEDED

static struct key *sed_opal_keyring;

struct opal_step {};
cont_fn;

enum opal_atom_width {};

/*
 * On the parsed response, we don't store again the toks that are already
 * stored in the response buffer. Instead, for each token, we just store a
 * pointer to the position in the buffer where the token starts, and the size
 * of the token in bytes.
 */
struct opal_resp_tok {};

/*
 * From the response header it's not possible to know how many tokens there are
 * on the payload. So we hardcode that the maximum will be MAX_TOKS, and later
 * if we start dealing with messages that have more than that, we can increase
 * this number. This is done to avoid having to make two passes through the
 * response, the first one counting how many tokens we have and the second one
 * actually storing the positions.
 */
struct parsed_resp {};

struct opal_dev {};


static const u8 opaluid[][OPAL_UID_LENGTH] =;

/*
 * TCG Storage SSC Methods.
 * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
 * Section: 6.3 Assigned UIDs
 */
static const u8 opalmethod[][OPAL_METHOD_LENGTH] =;

static int end_opal_session_error(struct opal_dev *dev);
static int opal_discovery0_step(struct opal_dev *dev);

struct opal_suspend_data {};

/*
 * Derived from:
 * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
 * Section: 5.1.5 Method Status Codes
 */
static const char * const opal_errors[] =;

static const char *opal_error_to_human(int error)
{}

static void print_buffer(const u8 *ptr, u32 length)
{}

/*
 * Allocate/update a SED Opal key and add it to the SED Opal keyring.
 */
static int update_sed_opal_key(const char *desc, u_char *key_data, int keylen)
{}

/*
 * Read a SED Opal key from the SED Opal keyring.
 */
static int read_sed_opal_key(const char *key_name, u_char *buffer, int buflen)
{}

static int opal_get_key(struct opal_dev *dev, struct opal_key *key)
{}

static bool check_tper(const void *data)
{}

static bool check_lcksuppt(const void *data)
{}

static bool check_lckenabled(const void *data)
{}

static bool check_locked(const void *data)
{}

static bool check_mbrenabled(const void *data)
{}

static bool check_mbrdone(const void *data)
{}

static bool check_sum(const void *data)
{}

static u16 get_comid_v100(const void *data)
{}

static u16 get_comid_v200(const void *data)
{}

static int opal_send_cmd(struct opal_dev *dev)
{}

static int opal_recv_cmd(struct opal_dev *dev)
{}

static int opal_recv_check(struct opal_dev *dev)
{}

static int opal_send_recv(struct opal_dev *dev, cont_fn *cont)
{}

static void check_geometry(struct opal_dev *dev, const void *data)
{}

static int execute_step(struct opal_dev *dev,
			const struct opal_step *step, size_t stepIndex)
{}

static int execute_steps(struct opal_dev *dev,
			 const struct opal_step *steps, size_t n_steps)
{}

static int opal_discovery0_end(struct opal_dev *dev, void *data)
{}

static int opal_discovery0(struct opal_dev *dev, void *data)
{}

static int opal_discovery0_step(struct opal_dev *dev)
{}

static size_t remaining_size(struct opal_dev *cmd)
{}

static bool can_add(int *err, struct opal_dev *cmd, size_t len)
{}

static void add_token_u8(int *err, struct opal_dev *cmd, u8 tok)
{}

static void add_short_atom_header(struct opal_dev *cmd, bool bytestring,
				  bool has_sign, int len)
{}

static void add_medium_atom_header(struct opal_dev *cmd, bool bytestring,
				   bool has_sign, int len)
{}

static void add_token_u64(int *err, struct opal_dev *cmd, u64 number)
{}

static u8 *add_bytestring_header(int *err, struct opal_dev *cmd, size_t len)
{}

static void add_token_bytestring(int *err, struct opal_dev *cmd,
				 const u8 *bytestring, size_t len)
{}

static int build_locking_range(u8 *buffer, size_t length, u8 lr)
{}

static int build_locking_user(u8 *buffer, size_t length, u8 lr)
{}

static void set_comid(struct opal_dev *cmd, u16 comid)
{}

static int cmd_finalize(struct opal_dev *cmd, u32 hsn, u32 tsn)
{}

static const struct opal_resp_tok *response_get_token(
				const struct parsed_resp *resp,
				int n)
{}

static ssize_t response_parse_tiny(struct opal_resp_tok *tok,
				   const u8 *pos)
{}

static ssize_t response_parse_short(struct opal_resp_tok *tok,
				    const u8 *pos)
{}

static ssize_t response_parse_medium(struct opal_resp_tok *tok,
				     const u8 *pos)
{}

static ssize_t response_parse_long(struct opal_resp_tok *tok,
				   const u8 *pos)
{}

static ssize_t response_parse_token(struct opal_resp_tok *tok,
				    const u8 *pos)
{}

static int response_parse(const u8 *buf, size_t length,
			  struct parsed_resp *resp)
{}

static size_t response_get_string(const struct parsed_resp *resp, int n,
				  const char **store)
{}

static u64 response_get_u64(const struct parsed_resp *resp, int n)
{}

static bool response_token_matches(const struct opal_resp_tok *token, u8 match)
{}

static u8 response_status(const struct parsed_resp *resp)
{}

/* Parses and checks for errors */
static int parse_and_check_status(struct opal_dev *dev)
{}

static void clear_opal_cmd(struct opal_dev *dev)
{}

static int cmd_start(struct opal_dev *dev, const u8 *uid, const u8 *method)
{}

static int start_opal_session_cont(struct opal_dev *dev)
{}

static void add_suspend_info(struct opal_dev *dev,
			     struct opal_suspend_data *sus)
{}

static int end_session_cont(struct opal_dev *dev)
{}

static int finalize_and_send(struct opal_dev *dev, cont_fn cont)
{}

static int generic_get_columns(struct opal_dev *dev, const u8 *table,
			       u64 start_column, u64 end_column)
{}

/*
 * 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)
{}

/*
 * see TCG SAS 5.3.2.3 for a description of the available columns
 *
 * the result is provided in dev->resp->tok[4]
 */
static int generic_get_table_info(struct opal_dev *dev, const u8 *table_uid,
				  u64 column)
{}

static int gen_key(struct opal_dev *dev, void *data)
{}

static int get_active_key_cont(struct opal_dev *dev)
{}

static int get_active_key(struct opal_dev *dev, void *data)
{}

static int generic_table_write_data(struct opal_dev *dev, const u64 data,
				    u64 offset, u64 size, const u8 *uid)
{}

static int generic_lr_enable_disable(struct opal_dev *dev,
				     u8 *uid, bool rle, bool wle,
				     bool rl, bool wl)
{}

static inline int enable_global_lr(struct opal_dev *dev, u8 *uid,
				   struct opal_user_lr_setup *setup)
{}

static int setup_locking_range(struct opal_dev *dev, void *data)
{}

static int response_get_column(const struct parsed_resp *resp,
			       int *iter,
			       u8 column,
			       u64 *value)
{}

static int locking_range_status(struct opal_dev *dev, void *data)
{}

static int start_generic_opal_session(struct opal_dev *dev,
				      enum opal_uid auth,
				      enum opal_uid sp_type,
				      const char *key,
				      u8 key_len)
{}

static int start_anybodyASP_opal_session(struct opal_dev *dev, void *data)
{}

static int start_SIDASP_opal_session(struct opal_dev *dev, void *data)
{}

static int start_admin1LSP_opal_session(struct opal_dev *dev, void *data)
{}

static int start_PSID_opal_session(struct opal_dev *dev, void *data)
{}

static int start_auth_opal_session(struct opal_dev *dev, void *data)
{}

static int revert_tper(struct opal_dev *dev, void *data)
{}

static int internal_activate_user(struct opal_dev *dev, void *data)
{}

static int revert_lsp(struct opal_dev *dev, void *data)
{}

static int erase_locking_range(struct opal_dev *dev, void *data)
{}

static int set_mbr_done(struct opal_dev *dev, void *data)
{}

static int set_mbr_enable_disable(struct opal_dev *dev, void *data)
{}

static int write_shadow_mbr(struct opal_dev *dev, void *data)
{}

static int generic_pw_cmd(u8 *key, size_t key_len, u8 *cpin_uid,
			  struct opal_dev *dev)
{}

static int set_new_pw(struct opal_dev *dev, void *data)
{}

static int set_sid_cpin_pin(struct opal_dev *dev, void *data)
{}

static void add_authority_object_ref(int *err,
				     struct opal_dev *dev,
				     const u8 *uid,
				     size_t uid_len)
{}

static void add_boolean_object_ref(int *err,
				   struct opal_dev *dev,
				   u8 boolean_op)
{}

static int set_lr_boolean_ace(struct opal_dev *dev,
			      unsigned int opal_uid,
			      u8 lr,
			      const u8 *users,
			      size_t users_len)
{}

static int add_user_to_lr(struct opal_dev *dev, void *data)
{}

static int add_user_to_lr_ace(struct opal_dev *dev, void *data)
{}

static int lock_unlock_locking_range(struct opal_dev *dev, void *data)
{}


static int lock_unlock_locking_range_sum(struct opal_dev *dev, void *data)
{}

static int activate_lsp(struct opal_dev *dev, void *data)
{}

/* Determine if we're in the Manufactured Inactive or Active state */
static int get_lsp_lifecycle(struct opal_dev *dev, void *data)
{}

static int get_msid_cpin_pin(struct opal_dev *dev, void *data)
{}

static int write_table_data(struct opal_dev *dev, void *data)
{}

static int read_table_data_cont(struct opal_dev *dev)
{}

/*
 * IO_BUFFER_LENGTH = 2048
 * sizeof(header) = 56
 * No. of Token Bytes in the Response = 11
 * MAX size of data that can be carried in response buffer
 * at a time is : 2048 - (56 + 11) = 1981 = 0x7BD.
 */
#define OPAL_MAX_READ_TABLE

static int read_table_data(struct opal_dev *dev, void *data)
{}

static int end_opal_session(struct opal_dev *dev, void *data)
{}

static int end_opal_session_error(struct opal_dev *dev)
{}

static inline void setup_opal_dev(struct opal_dev *dev)
{}

static int check_opal_support(struct opal_dev *dev)
{}

static void clean_opal_dev(struct opal_dev *dev)
{}

void free_opal_dev(struct opal_dev *dev)
{}
EXPORT_SYMBOL();

struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv)
{}
EXPORT_SYMBOL();

static int opal_secure_erase_locking_range(struct opal_dev *dev,
					   struct opal_session_info *opal_session)
{}

static int opal_get_discv(struct opal_dev *dev, struct opal_discovery *discv)
{}

static int opal_revertlsp(struct opal_dev *dev, struct opal_revert_lsp *rev)
{}

static int opal_erase_locking_range(struct opal_dev *dev,
				    struct opal_session_info *opal_session)
{}

static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
					  struct opal_mbr_data *opal_mbr)
{}

static int opal_set_mbr_done(struct opal_dev *dev,
			     struct opal_mbr_done *mbr_done)
{}

static int opal_write_shadow_mbr(struct opal_dev *dev,
				 struct opal_shadow_mbr *info)
{}

static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
{}

static int opal_add_user_to_lr(struct opal_dev *dev,
			       struct opal_lock_unlock *lk_unlk)
{}

static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal, bool psid)
{}

static int __opal_lock_unlock(struct opal_dev *dev,
			      struct opal_lock_unlock *lk_unlk)
{}

static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
{}

static void opal_lock_check_for_saved_key(struct opal_dev *dev,
			    struct opal_lock_unlock *lk_unlk)
{}

static int opal_lock_unlock(struct opal_dev *dev,
			    struct opal_lock_unlock *lk_unlk)
{}

static int opal_take_ownership(struct opal_dev *dev, struct opal_key *opal)
{}

static int opal_activate_lsp(struct opal_dev *dev,
			     struct opal_lr_act *opal_lr_act)
{}

static int opal_setup_locking_range(struct opal_dev *dev,
				    struct opal_user_lr_setup *opal_lrs)
{}

static int opal_locking_range_status(struct opal_dev *dev,
			  struct opal_lr_status *opal_lrst,
			  void __user *data)
{}

static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
{}

static int opal_activate_user(struct opal_dev *dev,
			      struct opal_session_info *opal_session)
{}

bool opal_unlock_from_suspend(struct opal_dev *dev)
{}
EXPORT_SYMBOL();

static int opal_read_table(struct opal_dev *dev,
			   struct opal_read_write_table *rw_tbl)
{}

static int opal_write_table(struct opal_dev *dev,
			    struct opal_read_write_table *rw_tbl)
{}

static int opal_generic_read_write_table(struct opal_dev *dev,
					 struct opal_read_write_table *rw_tbl)
{}

static int opal_get_status(struct opal_dev *dev, void __user *data)
{}

static int opal_get_geometry(struct opal_dev *dev, void __user *data)
{}

int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
{}
EXPORT_SYMBOL_GPL();

static int __init sed_opal_init(void)
{}
late_initcall(sed_opal_init);