18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2005 Cisco Systems.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci * $Id$
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef SCSI_SRP_H
368c2ecf20Sopenharmony_ci#define SCSI_SRP_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Structures and constants for the SCSI RDMA Protocol (SRP) as
408c2ecf20Sopenharmony_ci * defined by the INCITS T10 committee.  This file was written using
418c2ecf20Sopenharmony_ci * draft Revision 16a of the SRP standard.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#include <linux/types.h>
458c2ecf20Sopenharmony_ci#include <scsi/scsi.h>
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cienum {
488c2ecf20Sopenharmony_ci	SRP_LOGIN_REQ	= 0x00,
498c2ecf20Sopenharmony_ci	SRP_TSK_MGMT	= 0x01,
508c2ecf20Sopenharmony_ci	SRP_CMD		= 0x02,
518c2ecf20Sopenharmony_ci	SRP_I_LOGOUT	= 0x03,
528c2ecf20Sopenharmony_ci	SRP_LOGIN_RSP	= 0xc0,
538c2ecf20Sopenharmony_ci	SRP_RSP		= 0xc1,
548c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ	= 0xc2,
558c2ecf20Sopenharmony_ci	SRP_T_LOGOUT	= 0x80,
568c2ecf20Sopenharmony_ci	SRP_CRED_REQ	= 0x81,
578c2ecf20Sopenharmony_ci	SRP_AER_REQ	= 0x82,
588c2ecf20Sopenharmony_ci	SRP_CRED_RSP	= 0x41,
598c2ecf20Sopenharmony_ci	SRP_AER_RSP	= 0x42
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cienum {
638c2ecf20Sopenharmony_ci	SRP_BUF_FORMAT_DIRECT	= 1 << 1,
648c2ecf20Sopenharmony_ci	SRP_BUF_FORMAT_INDIRECT	= 1 << 2
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cienum {
688c2ecf20Sopenharmony_ci	SRP_NO_DATA_DESC	= 0,
698c2ecf20Sopenharmony_ci	SRP_DATA_DESC_DIRECT	= 1,
708c2ecf20Sopenharmony_ci	SRP_DATA_DESC_INDIRECT	= 2,
718c2ecf20Sopenharmony_ci	SRP_DATA_DESC_IMM	= 3,	/* new in SRP2 */
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cienum {
758c2ecf20Sopenharmony_ci	SRP_TSK_ABORT_TASK	= 0x01,
768c2ecf20Sopenharmony_ci	SRP_TSK_ABORT_TASK_SET	= 0x02,
778c2ecf20Sopenharmony_ci	SRP_TSK_CLEAR_TASK_SET	= 0x04,
788c2ecf20Sopenharmony_ci	SRP_TSK_LUN_RESET	= 0x08,
798c2ecf20Sopenharmony_ci	SRP_TSK_CLEAR_ACA	= 0x40
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cienum srp_login_rej_reason {
838c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL		= 0x00010000,
848c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES		= 0x00010001,
858c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_REQ_IT_IU_LENGTH_TOO_LARGE	= 0x00010002,
868c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_UNABLE_ASSOCIATE_CHANNEL		= 0x00010003,
878c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT	= 0x00010004,
888c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_MULTI_CHANNEL_UNSUPPORTED		= 0x00010005,
898c2ecf20Sopenharmony_ci	SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED		= 0x00010006
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cienum {
938c2ecf20Sopenharmony_ci	SRP_REV10_IB_IO_CLASS	= 0xff00,
948c2ecf20Sopenharmony_ci	SRP_REV16A_IB_IO_CLASS	= 0x0100
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistruct srp_direct_buf {
988c2ecf20Sopenharmony_ci	__be64	va;
998c2ecf20Sopenharmony_ci	__be32	key;
1008c2ecf20Sopenharmony_ci	__be32  len;
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*
1048c2ecf20Sopenharmony_ci * We need the packed attribute because the SRP spec puts the list of
1058c2ecf20Sopenharmony_ci * descriptors at an offset of 20, which is not aligned to the size of
1068c2ecf20Sopenharmony_ci * struct srp_direct_buf.  The whole structure must be packed to avoid
1078c2ecf20Sopenharmony_ci * having the 20-byte structure padded to 24 bytes on 64-bit architectures.
1088c2ecf20Sopenharmony_ci */
1098c2ecf20Sopenharmony_cistruct srp_indirect_buf {
1108c2ecf20Sopenharmony_ci	struct srp_direct_buf	table_desc;
1118c2ecf20Sopenharmony_ci	__be32			len;
1128c2ecf20Sopenharmony_ci	struct srp_direct_buf	desc_list[];
1138c2ecf20Sopenharmony_ci} __attribute__((packed));
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* Immediate data buffer descriptor as defined in SRP2. */
1168c2ecf20Sopenharmony_cistruct srp_imm_buf {
1178c2ecf20Sopenharmony_ci	__be32	len;
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* srp_login_req.flags */
1218c2ecf20Sopenharmony_cienum {
1228c2ecf20Sopenharmony_ci	SRP_MULTICHAN_SINGLE = 0,
1238c2ecf20Sopenharmony_ci	SRP_MULTICHAN_MULTI  = 1,
1248c2ecf20Sopenharmony_ci	SRP_IMMED_REQUESTED  = 0x80,	/* new in SRP2 */
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistruct srp_login_req {
1288c2ecf20Sopenharmony_ci	u8	opcode;
1298c2ecf20Sopenharmony_ci	u8	reserved1[7];
1308c2ecf20Sopenharmony_ci	u64	tag;
1318c2ecf20Sopenharmony_ci	__be32	req_it_iu_len;
1328c2ecf20Sopenharmony_ci	u8	reserved2[4];
1338c2ecf20Sopenharmony_ci	__be16	req_buf_fmt;
1348c2ecf20Sopenharmony_ci	u8	req_flags;
1358c2ecf20Sopenharmony_ci	u8	reserved3[1];
1368c2ecf20Sopenharmony_ci	__be16	imm_data_offset;	/* new in SRP2 */
1378c2ecf20Sopenharmony_ci	u8	reserved4[2];
1388c2ecf20Sopenharmony_ci	u8	initiator_port_id[16];
1398c2ecf20Sopenharmony_ci	u8	target_port_id[16];
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/**
1438c2ecf20Sopenharmony_ci * struct srp_login_req_rdma - RDMA/CM login parameters.
1448c2ecf20Sopenharmony_ci *
1458c2ecf20Sopenharmony_ci * RDMA/CM over InfiniBand can only carry 92 - 36 = 56 bytes of private
1468c2ecf20Sopenharmony_ci * data. The %srp_login_req_rdma structure contains the same information as
1478c2ecf20Sopenharmony_ci * %srp_login_req but with the reserved data removed.
1488c2ecf20Sopenharmony_ci */
1498c2ecf20Sopenharmony_cistruct srp_login_req_rdma {
1508c2ecf20Sopenharmony_ci	u64	tag;
1518c2ecf20Sopenharmony_ci	__be16	req_buf_fmt;
1528c2ecf20Sopenharmony_ci	u8	req_flags;
1538c2ecf20Sopenharmony_ci	u8	opcode;
1548c2ecf20Sopenharmony_ci	__be32	req_it_iu_len;
1558c2ecf20Sopenharmony_ci	u8	initiator_port_id[16];
1568c2ecf20Sopenharmony_ci	u8	target_port_id[16];
1578c2ecf20Sopenharmony_ci	__be16	imm_data_offset;
1588c2ecf20Sopenharmony_ci	u8	reserved[6];
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* srp_login_rsp.rsp_flags */
1628c2ecf20Sopenharmony_cienum {
1638c2ecf20Sopenharmony_ci	SRP_LOGIN_RSP_MULTICHAN_NO_CHAN	   = 0x0,
1648c2ecf20Sopenharmony_ci	SRP_LOGIN_RSP_MULTICHAN_TERMINATED = 0x1,
1658c2ecf20Sopenharmony_ci	SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2,
1668c2ecf20Sopenharmony_ci	SRP_LOGIN_RSP_IMMED_SUPP	   = 0x80, /* new in SRP2 */
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/*
1708c2ecf20Sopenharmony_ci * The SRP spec defines the size of the LOGIN_RSP structure to be 52
1718c2ecf20Sopenharmony_ci * bytes, so it needs to be packed to avoid having it padded to 56
1728c2ecf20Sopenharmony_ci * bytes on 64-bit architectures.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_cistruct srp_login_rsp {
1758c2ecf20Sopenharmony_ci	u8	opcode;
1768c2ecf20Sopenharmony_ci	u8	reserved1[3];
1778c2ecf20Sopenharmony_ci	__be32	req_lim_delta;
1788c2ecf20Sopenharmony_ci	u64	tag;
1798c2ecf20Sopenharmony_ci	__be32	max_it_iu_len;
1808c2ecf20Sopenharmony_ci	__be32	max_ti_iu_len;
1818c2ecf20Sopenharmony_ci	__be16	buf_fmt;
1828c2ecf20Sopenharmony_ci	u8	rsp_flags;
1838c2ecf20Sopenharmony_ci	u8	reserved2[25];
1848c2ecf20Sopenharmony_ci} __attribute__((packed));
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct srp_login_rej {
1878c2ecf20Sopenharmony_ci	u8	opcode;
1888c2ecf20Sopenharmony_ci	u8	reserved1[3];
1898c2ecf20Sopenharmony_ci	__be32	reason;
1908c2ecf20Sopenharmony_ci	u64	tag;
1918c2ecf20Sopenharmony_ci	u8	reserved2[8];
1928c2ecf20Sopenharmony_ci	__be16	buf_fmt;
1938c2ecf20Sopenharmony_ci	u8	reserved3[6];
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct srp_i_logout {
1978c2ecf20Sopenharmony_ci	u8	opcode;
1988c2ecf20Sopenharmony_ci	u8	reserved[7];
1998c2ecf20Sopenharmony_ci	u64	tag;
2008c2ecf20Sopenharmony_ci};
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistruct srp_t_logout {
2038c2ecf20Sopenharmony_ci	u8	opcode;
2048c2ecf20Sopenharmony_ci	u8	sol_not;
2058c2ecf20Sopenharmony_ci	u8	reserved[2];
2068c2ecf20Sopenharmony_ci	__be32	reason;
2078c2ecf20Sopenharmony_ci	u64	tag;
2088c2ecf20Sopenharmony_ci};
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci/*
2118c2ecf20Sopenharmony_ci * We need the packed attribute because the SRP spec only aligns the
2128c2ecf20Sopenharmony_ci * 8-byte LUN field to 4 bytes.
2138c2ecf20Sopenharmony_ci */
2148c2ecf20Sopenharmony_cistruct srp_tsk_mgmt {
2158c2ecf20Sopenharmony_ci	u8	opcode;
2168c2ecf20Sopenharmony_ci	u8	sol_not;
2178c2ecf20Sopenharmony_ci	u8	reserved1[6];
2188c2ecf20Sopenharmony_ci	u64	tag;
2198c2ecf20Sopenharmony_ci	u8	reserved2[4];
2208c2ecf20Sopenharmony_ci	struct scsi_lun	lun;
2218c2ecf20Sopenharmony_ci	u8	reserved3[2];
2228c2ecf20Sopenharmony_ci	u8	tsk_mgmt_func;
2238c2ecf20Sopenharmony_ci	u8	reserved4;
2248c2ecf20Sopenharmony_ci	u64	task_tag;
2258c2ecf20Sopenharmony_ci	u8	reserved5[8];
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/*
2298c2ecf20Sopenharmony_ci * We need the packed attribute because the SRP spec only aligns the
2308c2ecf20Sopenharmony_ci * 8-byte LUN field to 4 bytes.
2318c2ecf20Sopenharmony_ci */
2328c2ecf20Sopenharmony_cistruct srp_cmd {
2338c2ecf20Sopenharmony_ci	u8	opcode;
2348c2ecf20Sopenharmony_ci	u8	sol_not;
2358c2ecf20Sopenharmony_ci	u8	reserved1[3];
2368c2ecf20Sopenharmony_ci	u8	buf_fmt;
2378c2ecf20Sopenharmony_ci	u8	data_out_desc_cnt;
2388c2ecf20Sopenharmony_ci	u8	data_in_desc_cnt;
2398c2ecf20Sopenharmony_ci	u64	tag;
2408c2ecf20Sopenharmony_ci	u8	reserved2[4];
2418c2ecf20Sopenharmony_ci	struct scsi_lun	lun;
2428c2ecf20Sopenharmony_ci	u8	reserved3;
2438c2ecf20Sopenharmony_ci	u8	task_attr;
2448c2ecf20Sopenharmony_ci	u8	reserved4;
2458c2ecf20Sopenharmony_ci	u8	add_cdb_len;
2468c2ecf20Sopenharmony_ci	u8	cdb[16];
2478c2ecf20Sopenharmony_ci	u8	add_data[];
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cienum {
2518c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_RSPVALID = 1 << 0,
2528c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_SNSVALID = 1 << 1,
2538c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_DOOVER   = 1 << 2,
2548c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_DOUNDER  = 1 << 3,
2558c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_DIOVER   = 1 << 4,
2568c2ecf20Sopenharmony_ci	SRP_RSP_FLAG_DIUNDER  = 1 << 5
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/*
2608c2ecf20Sopenharmony_ci * The SRP spec defines the size of the RSP structure to be 36 bytes,
2618c2ecf20Sopenharmony_ci * so it needs to be packed to avoid having it padded to 40 bytes on
2628c2ecf20Sopenharmony_ci * 64-bit architectures.
2638c2ecf20Sopenharmony_ci */
2648c2ecf20Sopenharmony_cistruct srp_rsp {
2658c2ecf20Sopenharmony_ci	u8	opcode;
2668c2ecf20Sopenharmony_ci	u8	sol_not;
2678c2ecf20Sopenharmony_ci	u8	reserved1[2];
2688c2ecf20Sopenharmony_ci	__be32	req_lim_delta;
2698c2ecf20Sopenharmony_ci	u64	tag;
2708c2ecf20Sopenharmony_ci	u8	reserved2[2];
2718c2ecf20Sopenharmony_ci	u8	flags;
2728c2ecf20Sopenharmony_ci	u8	status;
2738c2ecf20Sopenharmony_ci	__be32	data_out_res_cnt;
2748c2ecf20Sopenharmony_ci	__be32	data_in_res_cnt;
2758c2ecf20Sopenharmony_ci	__be32	sense_data_len;
2768c2ecf20Sopenharmony_ci	__be32	resp_data_len;
2778c2ecf20Sopenharmony_ci	u8	data[];
2788c2ecf20Sopenharmony_ci} __attribute__((packed));
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistruct srp_cred_req {
2818c2ecf20Sopenharmony_ci	u8	opcode;
2828c2ecf20Sopenharmony_ci	u8	sol_not;
2838c2ecf20Sopenharmony_ci	u8	reserved[2];
2848c2ecf20Sopenharmony_ci	__be32	req_lim_delta;
2858c2ecf20Sopenharmony_ci	u64	tag;
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistruct srp_cred_rsp {
2898c2ecf20Sopenharmony_ci	u8	opcode;
2908c2ecf20Sopenharmony_ci	u8	reserved[7];
2918c2ecf20Sopenharmony_ci	u64	tag;
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/*
2958c2ecf20Sopenharmony_ci * The SRP spec defines the fixed portion of the AER_REQ structure to be
2968c2ecf20Sopenharmony_ci * 36 bytes, so it needs to be packed to avoid having it padded to 40 bytes
2978c2ecf20Sopenharmony_ci * on 64-bit architectures.
2988c2ecf20Sopenharmony_ci */
2998c2ecf20Sopenharmony_cistruct srp_aer_req {
3008c2ecf20Sopenharmony_ci	u8	opcode;
3018c2ecf20Sopenharmony_ci	u8	sol_not;
3028c2ecf20Sopenharmony_ci	u8	reserved[2];
3038c2ecf20Sopenharmony_ci	__be32	req_lim_delta;
3048c2ecf20Sopenharmony_ci	u64	tag;
3058c2ecf20Sopenharmony_ci	u32	reserved2;
3068c2ecf20Sopenharmony_ci	struct scsi_lun	lun;
3078c2ecf20Sopenharmony_ci	__be32	sense_data_len;
3088c2ecf20Sopenharmony_ci	u32	reserved3;
3098c2ecf20Sopenharmony_ci	u8	sense_data[];
3108c2ecf20Sopenharmony_ci} __attribute__((packed));
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistruct srp_aer_rsp {
3138c2ecf20Sopenharmony_ci	u8	opcode;
3148c2ecf20Sopenharmony_ci	u8	reserved[7];
3158c2ecf20Sopenharmony_ci	u64	tag;
3168c2ecf20Sopenharmony_ci};
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci#endif /* SCSI_SRP_H */
319