/* 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 - QUERY REQUEST UPIU structure.97* @opcode: query function to perform B-098* @idn: descriptor or attribute identification number B-199* @index: Index that further identifies which data to access B-2100* @selector: Index that further identifies which data to access B-3101* @reserved_osf: spec reserved field B-4,5102* @length: number of descriptor bytes to read or write B-6,7103* @value: if @opcode == UPIU_QUERY_OPCODE_WRITE_ATTR, the value to be written B-6,7104* @reserved: reserved for future use DW-6,7105*/106struct utp_upiu_query {107__u8 opcode;108__u8 idn;109__u8 index;110__u8 selector;111__be16 reserved_osf;112__be16 length;113__be32 value;114__be32 reserved[2];115};116117/**118* struct utp_upiu_query_v4_0 - upiu request buffer structure for119* query request >= UFS 4.0 spec.120* @opcode: command to perform B-0121* @idn: a value that indicates the particular type of data B-1122* @index: Index to further identify data B-2123* @selector: Index to further identify data B-3124* @osf3: spec field B-4125* @osf4: spec field B-5126* @osf5: spec field B 6,7127* @osf6: spec field DW 8,9128* @osf7: spec field DW 10,11129*/130struct utp_upiu_query_v4_0 {131__u8 opcode;132__u8 idn;133__u8 index;134__u8 selector;135__u8 osf3;136__u8 osf4;137__be16 osf5;138__be32 osf6;139__be32 osf7;140/* private: */141__be32 reserved;142};143144/**145* struct utp_upiu_cmd - Command UPIU structure146* @exp_data_transfer_len: Data Transfer Length DW-3147* @cdb: Command Descriptor Block CDB DW-4 to DW-7148*/149struct utp_upiu_cmd {150__be32 exp_data_transfer_len;151__u8 cdb[UFS_CDB_SIZE];152};153154/**155* struct utp_upiu_req - general upiu request structure156* @header:UPIU header structure DW-0 to DW-2157* @sc: fields structure for scsi command DW-3 to DW-7158* @qr: fields structure for query request DW-3 to DW-7159* @uc: use utp_upiu_query to host the 4 dwords of uic command160*/161struct utp_upiu_req {162struct utp_upiu_header header;163union {164struct utp_upiu_cmd sc;165struct utp_upiu_query qr;166struct utp_upiu_query uc;167};168};169170struct ufs_arpmb_meta {171__be16 req_resp_type;172__u8 nonce[16];173__be32 write_counter;174__be16 addr_lun;175__be16 block_count;176__be16 result;177} __attribute__((__packed__));178179struct ufs_ehs {180__u8 length;181__u8 ehs_type;182__be16 ehssub_type;183struct ufs_arpmb_meta meta;184__u8 mac_key[32];185} __attribute__((__packed__));186187/* request (CDB) structure of the sg_io_v4 */188struct ufs_bsg_request {189__u32 msgcode;190struct utp_upiu_req upiu_req;191};192193/* response (request sense data) structure of the sg_io_v4 */194struct ufs_bsg_reply {195/*196* The completion result. Result exists in two forms:197* if negative, it is an -Exxx system errno value. There will198* be no further reply information supplied.199* else, it's the 4-byte scsi error result, with driver, host,200* msg and status fields. The per-msgcode reply structure201* will contain valid data.202*/203int result;204205/* If there was reply_payload, how much was received? */206__u32 reply_payload_rcv_len;207208struct utp_upiu_req upiu_rsp;209};210211struct ufs_rpmb_request {212struct ufs_bsg_request bsg_request;213struct ufs_ehs ehs_req;214};215216struct ufs_rpmb_reply {217struct ufs_bsg_reply bsg_reply;218struct ufs_ehs ehs_rsp;219};220#endif /* UFS_BSG_H */221222223