1/*
2 * rpmb.h
3 *
4 * rpmb base data and structs defination
5 *
6 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#ifndef __RPMB_H__
18#define __RPMB_H__
19
20#include <linux/kconfig.h>
21#include <uapi/linux/bsg.h>
22
23#define MAX_CDB_CMD_LENGTH 16
24#define UFS_IOC_MAX_RPMB_CMD 3
25#define STORAGE_IOC_MAX_RPMB_CMD 3
26#define MAX_IOC_RPMB_BYTES (4 * 1024)
27
28enum rpmb_op_type {
29	RPMB_OP_RD = 0,
30	RPMB_OP_WR_DATA = 1,
31	RPMB_OP_WR_CNT = 2
32};
33
34enum func_id {
35	RPMB_FUNC_ID_RESERVED,
36	RPMB_FUNC_ID_SE,
37	RPMB_FUNC_ID_SECURE_OS,
38	RPMB_FUNC_ID_MAX,
39};
40
41enum rpmb_version {
42	RPMB_VER_INVALID = 0,
43	RPMB_VER_UFS_21 = 21,
44	RPMB_VER_UFS_30 = 30,
45	RPMB_VER_MAX = 999
46};
47
48struct storage_blk_ioc_data {
49	unsigned char *buf;
50	u64 buf_bytes;
51	u32 blocks;
52};
53
54struct ufs_blk_ioc_data {
55	struct sg_io_v4 siv;
56	unsigned char *buf;
57	u64 buf_bytes;
58};
59
60struct storage_blk_ioc_rpmb_data {
61	struct storage_blk_ioc_data data[STORAGE_IOC_MAX_RPMB_CMD];
62};
63
64struct ufs_blk_ioc_rpmb_data {
65	struct ufs_blk_ioc_data data[UFS_IOC_MAX_RPMB_CMD];
66	u8 sdb_command[UFS_IOC_MAX_RPMB_CMD][MAX_CDB_CMD_LENGTH];
67};
68
69extern struct mutex rpmb_counter_lock;
70
71extern int vendor_rpmb_ioctl_cmd(
72	enum func_id id,
73	enum rpmb_op_type operation,
74	struct storage_blk_ioc_rpmb_data *storage_data);
75
76#endif /* __RPMB_H__ */