xref: /OK3568_Linux_fs/kernel/include/uapi/scsi/scsi_bsg_ufs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * UFS Transport SGIO v4 BSG Message Support
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2011-2013 Samsung India Software Operations
6*4882a593Smuzhiyun  * Copyright (C) 2018 Western Digital Corporation
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef SCSI_BSG_UFS_H
9*4882a593Smuzhiyun #define SCSI_BSG_UFS_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/types.h>
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun  * This file intended to be included by both kernel and user space
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define UFS_CDB_SIZE	16
17*4882a593Smuzhiyun #define UPIU_TRANSACTION_UIC_CMD 0x1F
18*4882a593Smuzhiyun /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
19*4882a593Smuzhiyun #define UIC_CMD_SIZE (sizeof(__u32) * 4)
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /**
22*4882a593Smuzhiyun  * struct utp_upiu_header - UPIU header structure
23*4882a593Smuzhiyun  * @dword_0: UPIU header DW-0
24*4882a593Smuzhiyun  * @dword_1: UPIU header DW-1
25*4882a593Smuzhiyun  * @dword_2: UPIU header DW-2
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun struct utp_upiu_header {
28*4882a593Smuzhiyun 	__be32 dword_0;
29*4882a593Smuzhiyun 	__be32 dword_1;
30*4882a593Smuzhiyun 	__be32 dword_2;
31*4882a593Smuzhiyun };
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /**
34*4882a593Smuzhiyun  * struct utp_upiu_query - upiu request buffer structure for
35*4882a593Smuzhiyun  * query request.
36*4882a593Smuzhiyun  * @opcode: command to perform B-0
37*4882a593Smuzhiyun  * @idn: a value that indicates the particular type of data B-1
38*4882a593Smuzhiyun  * @index: Index to further identify data B-2
39*4882a593Smuzhiyun  * @selector: Index to further identify data B-3
40*4882a593Smuzhiyun  * @reserved_osf: spec reserved field B-4,5
41*4882a593Smuzhiyun  * @length: number of descriptor bytes to read/write B-6,7
42*4882a593Smuzhiyun  * @value: Attribute value to be written DW-5
43*4882a593Smuzhiyun  * @reserved: spec reserved DW-6,7
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun struct utp_upiu_query {
46*4882a593Smuzhiyun 	__u8 opcode;
47*4882a593Smuzhiyun 	__u8 idn;
48*4882a593Smuzhiyun 	__u8 index;
49*4882a593Smuzhiyun 	__u8 selector;
50*4882a593Smuzhiyun 	__be16 reserved_osf;
51*4882a593Smuzhiyun 	__be16 length;
52*4882a593Smuzhiyun 	__be32 value;
53*4882a593Smuzhiyun 	__be32 reserved[2];
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /**
57*4882a593Smuzhiyun  * struct utp_upiu_cmd - Command UPIU structure
58*4882a593Smuzhiyun  * @data_transfer_len: Data Transfer Length DW-3
59*4882a593Smuzhiyun  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun struct utp_upiu_cmd {
62*4882a593Smuzhiyun 	__be32 exp_data_transfer_len;
63*4882a593Smuzhiyun 	__u8 cdb[UFS_CDB_SIZE];
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /**
67*4882a593Smuzhiyun  * struct utp_upiu_req - general upiu request structure
68*4882a593Smuzhiyun  * @header:UPIU header structure DW-0 to DW-2
69*4882a593Smuzhiyun  * @sc: fields structure for scsi command DW-3 to DW-7
70*4882a593Smuzhiyun  * @qr: fields structure for query request DW-3 to DW-7
71*4882a593Smuzhiyun  * @uc: use utp_upiu_query to host the 4 dwords of uic command
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun struct utp_upiu_req {
74*4882a593Smuzhiyun 	struct utp_upiu_header header;
75*4882a593Smuzhiyun 	union {
76*4882a593Smuzhiyun 		struct utp_upiu_cmd		sc;
77*4882a593Smuzhiyun 		struct utp_upiu_query		qr;
78*4882a593Smuzhiyun 		struct utp_upiu_query		uc;
79*4882a593Smuzhiyun 	};
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /* request (CDB) structure of the sg_io_v4 */
83*4882a593Smuzhiyun struct ufs_bsg_request {
84*4882a593Smuzhiyun 	__u32 msgcode;
85*4882a593Smuzhiyun 	struct utp_upiu_req upiu_req;
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /* response (request sense data) structure of the sg_io_v4 */
89*4882a593Smuzhiyun struct ufs_bsg_reply {
90*4882a593Smuzhiyun 	/*
91*4882a593Smuzhiyun 	 * The completion result. Result exists in two forms:
92*4882a593Smuzhiyun 	 * if negative, it is an -Exxx system errno value. There will
93*4882a593Smuzhiyun 	 * be no further reply information supplied.
94*4882a593Smuzhiyun 	 * else, it's the 4-byte scsi error result, with driver, host,
95*4882a593Smuzhiyun 	 * msg and status fields. The per-msgcode reply structure
96*4882a593Smuzhiyun 	 * will contain valid data.
97*4882a593Smuzhiyun 	 */
98*4882a593Smuzhiyun 	__u32 result;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun 	/* If there was reply_payload, how much was received? */
101*4882a593Smuzhiyun 	__u32 reply_payload_rcv_len;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	struct utp_upiu_req upiu_rsp;
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun #endif /* UFS_BSG_H */
106