Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/include/uapi/scsi/scsi_bsg_ufs.h
51475 views
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 <asm/byteorder.h>
12
#include <linux/types.h>
13
/*
14
* This file intended to be included by both kernel and user space
15
*/
16
17
#define UFS_CDB_SIZE 16
18
/* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
19
#define UIC_CMD_SIZE (sizeof(__u32) * 4)
20
21
enum ufs_bsg_msg_code {
22
UPIU_TRANSACTION_UIC_CMD = 0x1F,
23
UPIU_TRANSACTION_ARPMB_CMD,
24
};
25
26
/* UFS RPMB Request Message Types */
27
enum ufs_rpmb_op_type {
28
UFS_RPMB_WRITE_KEY = 0x01,
29
UFS_RPMB_READ_CNT = 0x02,
30
UFS_RPMB_WRITE = 0x03,
31
UFS_RPMB_READ = 0x04,
32
UFS_RPMB_READ_RESP = 0x05,
33
UFS_RPMB_SEC_CONF_WRITE = 0x06,
34
UFS_RPMB_SEC_CONF_READ = 0x07,
35
UFS_RPMB_PURGE_ENABLE = 0x08,
36
UFS_RPMB_PURGE_STATUS_READ = 0x09,
37
};
38
39
/**
40
* struct utp_upiu_header - UPIU header structure
41
* @dword_0: UPIU header DW-0
42
* @dword_1: UPIU header DW-1
43
* @dword_2: UPIU header DW-2
44
*
45
* @transaction_code: Type of request or response. See also enum
46
* upiu_request_transaction and enum upiu_response_transaction.
47
* @flags: UPIU flags. The meaning of individual flags depends on the
48
* transaction code.
49
* @lun: Logical unit number.
50
* @task_tag: Task tag.
51
* @iid: Initiator ID.
52
* @command_set_type: 0 for SCSI command set; 1 for UFS specific.
53
* @tm_function: Task management function in case of a task management request
54
* UPIU.
55
* @query_function: Query function in case of a query request UPIU.
56
* @response: 0 for success; 1 for failure.
57
* @status: SCSI status if this is the header of a response to a SCSI command.
58
* @ehs_length: EHS length in units of 32 bytes.
59
* @device_information:
60
* @data_segment_length: data segment length.
61
*/
62
struct utp_upiu_header {
63
union {
64
struct {
65
__be32 dword_0;
66
__be32 dword_1;
67
__be32 dword_2;
68
};
69
struct {
70
__u8 transaction_code;
71
__u8 flags;
72
__u8 lun;
73
__u8 task_tag;
74
#if defined(__BIG_ENDIAN)
75
__u8 iid: 4;
76
__u8 command_set_type: 4;
77
#elif defined(__LITTLE_ENDIAN)
78
__u8 command_set_type: 4;
79
__u8 iid: 4;
80
#else
81
#error
82
#endif
83
union {
84
__u8 tm_function;
85
__u8 query_function;
86
} __attribute__((packed));
87
__u8 response;
88
__u8 status;
89
__u8 ehs_length;
90
__u8 device_information;
91
__be16 data_segment_length;
92
};
93
};
94
};
95
96
/**
97
* struct utp_upiu_query - QUERY REQUEST UPIU structure.
98
* @opcode: query function to perform B-0
99
* @idn: descriptor or attribute identification number B-1
100
* @index: Index that further identifies which data to access B-2
101
* @selector: Index that further identifies which data to access B-3
102
* @reserved_osf: spec reserved field B-4,5
103
* @length: number of descriptor bytes to read or write B-6,7
104
* @value: if @opcode == UPIU_QUERY_OPCODE_WRITE_ATTR, the value to be written B-6,7
105
* @reserved: reserved for future use DW-6,7
106
*/
107
struct utp_upiu_query {
108
__u8 opcode;
109
__u8 idn;
110
__u8 index;
111
__u8 selector;
112
__be16 reserved_osf;
113
__be16 length;
114
__be32 value;
115
__be32 reserved[2];
116
};
117
118
/**
119
* struct utp_upiu_query_v4_0 - upiu request buffer structure for
120
* query request >= UFS 4.0 spec.
121
* @opcode: command to perform B-0
122
* @idn: a value that indicates the particular type of data B-1
123
* @index: Index to further identify data B-2
124
* @selector: Index to further identify data B-3
125
* @osf3: spec field B-4
126
* @osf4: spec field B-5
127
* @osf5: spec field B 6,7
128
* @osf6: spec field DW 8,9
129
* @osf7: spec field DW 10,11
130
*/
131
struct utp_upiu_query_v4_0 {
132
__u8 opcode;
133
__u8 idn;
134
__u8 index;
135
__u8 selector;
136
__u8 osf3;
137
__u8 osf4;
138
__be16 osf5;
139
__be32 osf6;
140
__be32 osf7;
141
/* private: */
142
__be32 reserved;
143
};
144
145
/**
146
* struct utp_upiu_cmd - Command UPIU structure
147
* @exp_data_transfer_len: Data Transfer Length DW-3
148
* @cdb: Command Descriptor Block CDB DW-4 to DW-7
149
*/
150
struct utp_upiu_cmd {
151
__be32 exp_data_transfer_len;
152
__u8 cdb[UFS_CDB_SIZE];
153
};
154
155
/**
156
* struct utp_upiu_req - general upiu request structure
157
* @header:UPIU header structure DW-0 to DW-2
158
* @sc: fields structure for scsi command DW-3 to DW-7
159
* @qr: fields structure for query request DW-3 to DW-7
160
* @uc: use utp_upiu_query to host the 4 dwords of uic command
161
*/
162
struct utp_upiu_req {
163
struct utp_upiu_header header;
164
union {
165
struct utp_upiu_cmd sc;
166
struct utp_upiu_query qr;
167
struct utp_upiu_query uc;
168
};
169
};
170
171
struct ufs_arpmb_meta {
172
__be16 req_resp_type;
173
__u8 nonce[16];
174
__be32 write_counter;
175
__be16 addr_lun;
176
__be16 block_count;
177
__be16 result;
178
} __attribute__((__packed__));
179
180
struct ufs_ehs {
181
__u8 length;
182
__u8 ehs_type;
183
__be16 ehssub_type;
184
struct ufs_arpmb_meta meta;
185
__u8 mac_key[32];
186
} __attribute__((__packed__));
187
188
/* request (CDB) structure of the sg_io_v4 */
189
struct ufs_bsg_request {
190
__u32 msgcode;
191
struct utp_upiu_req upiu_req;
192
};
193
194
/* response (request sense data) structure of the sg_io_v4 */
195
struct ufs_bsg_reply {
196
/*
197
* The completion result. Result exists in two forms:
198
* if negative, it is an -Exxx system errno value. There will
199
* be no further reply information supplied.
200
* else, it's the 4-byte scsi error result, with driver, host,
201
* msg and status fields. The per-msgcode reply structure
202
* will contain valid data.
203
*/
204
int result;
205
206
/* If there was reply_payload, how much was received? */
207
__u32 reply_payload_rcv_len;
208
209
struct utp_upiu_req upiu_rsp;
210
};
211
212
struct ufs_rpmb_request {
213
struct ufs_bsg_request bsg_request;
214
struct ufs_ehs ehs_req;
215
};
216
217
struct ufs_rpmb_reply {
218
struct ufs_bsg_reply bsg_reply;
219
struct ufs_ehs ehs_rsp;
220
};
221
#endif /* UFS_BSG_H */
222
223