xref: /openbmc/linux/include/uapi/scsi/scsi_bsg_ufs.h (revision d3402925)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * UFS Transport SGIO v4 BSG Message Support
4  *
5  * Copyright (C) 2011-2013 Samsung India Software Operations
6  * Copyright (C) 2018 Western Digital Corporation
7  */
8 #ifndef SCSI_BSG_UFS_H
9 #define SCSI_BSG_UFS_H
10 
11 #include <linux/types.h>
12 /*
13  * This file intended to be included by both kernel and user space
14  */
15 
16 #define UFS_CDB_SIZE	16
17 /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
18 #define UIC_CMD_SIZE (sizeof(__u32) * 4)
19 
20 enum ufs_bsg_msg_code {
21 	UPIU_TRANSACTION_UIC_CMD = 0x1F,
22 	UPIU_TRANSACTION_ARPMB_CMD,
23 };
24 
25 /* UFS RPMB Request Message Types */
26 enum ufs_rpmb_op_type {
27 	UFS_RPMB_WRITE_KEY		= 0x01,
28 	UFS_RPMB_READ_CNT		= 0x02,
29 	UFS_RPMB_WRITE			= 0x03,
30 	UFS_RPMB_READ			= 0x04,
31 	UFS_RPMB_READ_RESP		= 0x05,
32 	UFS_RPMB_SEC_CONF_WRITE		= 0x06,
33 	UFS_RPMB_SEC_CONF_READ		= 0x07,
34 	UFS_RPMB_PURGE_ENABLE		= 0x08,
35 	UFS_RPMB_PURGE_STATUS_READ	= 0x09,
36 };
37 
38 /**
39  * struct utp_upiu_header - UPIU header structure
40  * @dword_0: UPIU header DW-0
41  * @dword_1: UPIU header DW-1
42  * @dword_2: UPIU header DW-2
43  */
44 struct utp_upiu_header {
45 	__be32 dword_0;
46 	__be32 dword_1;
47 	__be32 dword_2;
48 };
49 
50 /**
51  * struct utp_upiu_query - upiu request buffer structure for
52  * query request.
53  * @opcode: command to perform B-0
54  * @idn: a value that indicates the particular type of data B-1
55  * @index: Index to further identify data B-2
56  * @selector: Index to further identify data B-3
57  * @reserved_osf: spec reserved field B-4,5
58  * @length: number of descriptor bytes to read/write B-6,7
59  * @value: Attribute value to be written DW-5
60  * @reserved: spec reserved DW-6,7
61  */
62 struct utp_upiu_query {
63 	__u8 opcode;
64 	__u8 idn;
65 	__u8 index;
66 	__u8 selector;
67 	__be16 reserved_osf;
68 	__be16 length;
69 	__be32 value;
70 	__be32 reserved[2];
71 };
72 
73 /**
74  * struct utp_upiu_cmd - Command UPIU structure
75  * @data_transfer_len: Data Transfer Length DW-3
76  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
77  */
78 struct utp_upiu_cmd {
79 	__be32 exp_data_transfer_len;
80 	__u8 cdb[UFS_CDB_SIZE];
81 };
82 
83 /**
84  * struct utp_upiu_req - general upiu request structure
85  * @header:UPIU header structure DW-0 to DW-2
86  * @sc: fields structure for scsi command DW-3 to DW-7
87  * @qr: fields structure for query request DW-3 to DW-7
88  * @uc: use utp_upiu_query to host the 4 dwords of uic command
89  */
90 struct utp_upiu_req {
91 	struct utp_upiu_header header;
92 	union {
93 		struct utp_upiu_cmd		sc;
94 		struct utp_upiu_query		qr;
95 		struct utp_upiu_query		uc;
96 	};
97 };
98 
99 struct ufs_arpmb_meta {
100 	__be16	req_resp_type;
101 	__u8	nonce[16];
102 	__be32	write_counter;
103 	__be16	addr_lun;
104 	__be16	block_count;
105 	__be16	result;
106 } __attribute__((__packed__));
107 
108 struct ufs_ehs {
109 	__u8	length;
110 	__u8	ehs_type;
111 	__be16	ehssub_type;
112 	struct ufs_arpmb_meta meta;
113 	__u8	mac_key[32];
114 } __attribute__((__packed__));
115 
116 /* request (CDB) structure of the sg_io_v4 */
117 struct ufs_bsg_request {
118 	__u32 msgcode;
119 	struct utp_upiu_req upiu_req;
120 };
121 
122 /* response (request sense data) structure of the sg_io_v4 */
123 struct ufs_bsg_reply {
124 	/*
125 	 * The completion result. Result exists in two forms:
126 	 * if negative, it is an -Exxx system errno value. There will
127 	 * be no further reply information supplied.
128 	 * else, it's the 4-byte scsi error result, with driver, host,
129 	 * msg and status fields. The per-msgcode reply structure
130 	 * will contain valid data.
131 	 */
132 	int result;
133 
134 	/* If there was reply_payload, how much was received? */
135 	__u32 reply_payload_rcv_len;
136 
137 	struct utp_upiu_req upiu_rsp;
138 };
139 
140 struct ufs_rpmb_request {
141 	struct ufs_bsg_request bsg_request;
142 	struct ufs_ehs ehs_req;
143 };
144 
145 struct ufs_rpmb_reply {
146 	struct ufs_bsg_reply bsg_reply;
147 	struct ufs_ehs ehs_rsp;
148 };
149 #endif /* UFS_BSG_H */
150