/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */1/*2* UFS Transport SGIO v4 BSG Message Support3*4* Copyright (C) 2011-2013 Samsung India Software Operations5* Copyright (C) 2018 Western Digital Corporation6*/7#ifndef SCSI_BSG_UFS_H8#define SCSI_BSG_UFS_H910#include <asm/byteorder.h>11#include <linux/types.h>12/*13* This file intended to be included by both kernel and user space14*/1516#define UFS_CDB_SIZE 1617/* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */18#define UIC_CMD_SIZE (sizeof(__u32) * 4)1920enum ufs_bsg_msg_code {21UPIU_TRANSACTION_UIC_CMD = 0x1F,22UPIU_TRANSACTION_ARPMB_CMD,23};2425/* UFS RPMB Request Message Types */26enum ufs_rpmb_op_type {27UFS_RPMB_WRITE_KEY = 0x01,28UFS_RPMB_READ_CNT = 0x02,29UFS_RPMB_WRITE = 0x03,30UFS_RPMB_READ = 0x04,31UFS_RPMB_READ_RESP = 0x05,32UFS_RPMB_SEC_CONF_WRITE = 0x06,33UFS_RPMB_SEC_CONF_READ = 0x07,34UFS_RPMB_PURGE_ENABLE = 0x08,35UFS_RPMB_PURGE_STATUS_READ = 0x09,36};3738/**39* struct utp_upiu_header - UPIU header structure40* @dword_0: UPIU header DW-041* @dword_1: UPIU header DW-142* @dword_2: UPIU header DW-243*44* @transaction_code: Type of request or response. See also enum45* upiu_request_transaction and enum upiu_response_transaction.46* @flags: UPIU flags. The meaning of individual flags depends on the47* transaction code.48* @lun: Logical unit number.49* @task_tag: Task tag.50* @iid: Initiator ID.51* @command_set_type: 0 for SCSI command set; 1 for UFS specific.52* @tm_function: Task management function in case of a task management request53* UPIU.54* @query_function: Query function in case of a query request UPIU.55* @response: 0 for success; 1 for failure.56* @status: SCSI status if this is the header of a response to a SCSI command.57* @ehs_length: EHS length in units of 32 bytes.58* @device_information:59* @data_segment_length: data segment length.60*/61struct utp_upiu_header {62union {63struct {64__be32 dword_0;65__be32 dword_1;66__be32 dword_2;67};68struct {69__u8 transaction_code;70__u8 flags;71__u8 lun;72__u8 task_tag;73#if defined(__BIG_ENDIAN)74__u8 iid: 4;75__u8 command_set_type: 4;76#elif defined(__LITTLE_ENDIAN)77__u8 command_set_type: 4;78__u8 iid: 4;79#else80#error81#endif82union {83__u8 tm_function;84__u8 query_function;85} __attribute__((packed));86__u8 response;87__u8 status;88__u8 ehs_length;89__u8 device_information;90__be16 data_segment_length;91};92};93};9495/**96* struct utp_upiu_query - upiu request buffer structure for97* query request.98* @opcode: command to perform B-099* @idn: a value that indicates the particular type of data B-1100* @index: Index to further identify data B-2101* @selector: Index to further identify data B-3102* @reserved_osf: spec reserved field B-4,5103* @length: number of descriptor bytes to read/write B-6,7104* @value: Attribute value to be written DW-5105* @reserved: spec reserved DW-6,7106*/107struct 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};117118/**119* struct utp_upiu_query_v4_0 - upiu request buffer structure for120* query request >= UFS 4.0 spec.121* @opcode: command to perform B-0122* @idn: a value that indicates the particular type of data B-1123* @index: Index to further identify data B-2124* @selector: Index to further identify data B-3125* @osf3: spec field B-4126* @osf4: spec field B-5127* @osf5: spec field B 6,7128* @osf6: spec field DW 8,9129* @osf7: spec field DW 10,11130*/131struct 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};144145/**146* struct utp_upiu_cmd - Command UPIU structure147* @exp_data_transfer_len: Data Transfer Length DW-3148* @cdb: Command Descriptor Block CDB DW-4 to DW-7149*/150struct utp_upiu_cmd {151__be32 exp_data_transfer_len;152__u8 cdb[UFS_CDB_SIZE];153};154155/**156* struct utp_upiu_req - general upiu request structure157* @header:UPIU header structure DW-0 to DW-2158* @sc: fields structure for scsi command DW-3 to DW-7159* @qr: fields structure for query request DW-3 to DW-7160* @uc: use utp_upiu_query to host the 4 dwords of uic command161*/162struct utp_upiu_req {163struct utp_upiu_header header;164union {165struct utp_upiu_cmd sc;166struct utp_upiu_query qr;167struct utp_upiu_query uc;168};169};170171struct 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__));179180struct ufs_ehs {181__u8 length;182__u8 ehs_type;183__be16 ehssub_type;184struct ufs_arpmb_meta meta;185__u8 mac_key[32];186} __attribute__((__packed__));187188/* request (CDB) structure of the sg_io_v4 */189struct ufs_bsg_request {190__u32 msgcode;191struct utp_upiu_req upiu_req;192};193194/* response (request sense data) structure of the sg_io_v4 */195struct ufs_bsg_reply {196/*197* The completion result. Result exists in two forms:198* if negative, it is an -Exxx system errno value. There will199* 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 structure202* will contain valid data.203*/204int result;205206/* If there was reply_payload, how much was received? */207__u32 reply_payload_rcv_len;208209struct utp_upiu_req upiu_rsp;210};211212struct ufs_rpmb_request {213struct ufs_bsg_request bsg_request;214struct ufs_ehs ehs_req;215};216217struct ufs_rpmb_reply {218struct ufs_bsg_reply bsg_reply;219struct ufs_ehs ehs_rsp;220};221#endif /* UFS_BSG_H */222223224