18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef __SNIC_FWINT_H
198c2ecf20Sopenharmony_ci#define __SNIC_FWINT_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define SNIC_CDB_LEN	32	/* SCSI CDB size 32, can be used for 16 bytes */
228c2ecf20Sopenharmony_ci#define LUN_ADDR_LEN	8
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * Command entry type
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_cienum snic_io_type {
288c2ecf20Sopenharmony_ci	/*
298c2ecf20Sopenharmony_ci	 * Initiator request types
308c2ecf20Sopenharmony_ci	 */
318c2ecf20Sopenharmony_ci	SNIC_REQ_REPORT_TGTS = 0x2,	/* Report Targets */
328c2ecf20Sopenharmony_ci	SNIC_REQ_ICMND,			/* Initiator command for SCSI IO */
338c2ecf20Sopenharmony_ci	SNIC_REQ_ITMF,			/* Initiator command for Task Mgmt */
348c2ecf20Sopenharmony_ci	SNIC_REQ_HBA_RESET,		/* SNIC Reset */
358c2ecf20Sopenharmony_ci	SNIC_REQ_EXCH_VER,		/* Exchange Version Information */
368c2ecf20Sopenharmony_ci	SNIC_REQ_TGT_INFO,		/* Backend/Target Information */
378c2ecf20Sopenharmony_ci	SNIC_REQ_BOOT_LUNS,
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	/*
408c2ecf20Sopenharmony_ci	 * Response type
418c2ecf20Sopenharmony_ci	 */
428c2ecf20Sopenharmony_ci	SNIC_RSP_REPORT_TGTS_CMPL = 0x12,/* Report Targets Completion */
438c2ecf20Sopenharmony_ci	SNIC_RSP_ICMND_CMPL,		/* SCSI IO Completion */
448c2ecf20Sopenharmony_ci	SNIC_RSP_ITMF_CMPL,		/* Task Management Completion */
458c2ecf20Sopenharmony_ci	SNIC_RSP_HBA_RESET_CMPL,	/* SNIC Reset Completion */
468c2ecf20Sopenharmony_ci	SNIC_RSP_EXCH_VER_CMPL,		/* Exchange Version Completion*/
478c2ecf20Sopenharmony_ci	SNIC_RSP_BOOT_LUNS_CMPL,
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/*
508c2ecf20Sopenharmony_ci	 * Misc Request types
518c2ecf20Sopenharmony_ci	 */
528c2ecf20Sopenharmony_ci	SNIC_MSG_ACK = 0x80,		/* Ack: snic_notify_msg */
538c2ecf20Sopenharmony_ci	SNIC_MSG_ASYNC_EVNOTIFY,	/* Asynchronous Event Notification */
548c2ecf20Sopenharmony_ci}; /* end of enum snic_io_type */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * Header status codes from firmware
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cienum snic_io_status {
618c2ecf20Sopenharmony_ci	SNIC_STAT_IO_SUCCESS = 0,	/* request was successful */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	/*
648c2ecf20Sopenharmony_ci	 * If a request to the fw is rejected, the original request header
658c2ecf20Sopenharmony_ci	 * will be returned with the status set to one of the following:
668c2ecf20Sopenharmony_ci	 */
678c2ecf20Sopenharmony_ci	SNIC_STAT_INVALID_HDR,	/* header contains invalid data */
688c2ecf20Sopenharmony_ci	SNIC_STAT_OUT_OF_RES,	/* out of resources to complete request */
698c2ecf20Sopenharmony_ci	SNIC_STAT_INVALID_PARM,	/* some parameter in request is not valid */
708c2ecf20Sopenharmony_ci	SNIC_STAT_REQ_NOT_SUP,	/* req type is not supported */
718c2ecf20Sopenharmony_ci	SNIC_STAT_IO_NOT_FOUND,	/* requested IO was not found */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	/*
748c2ecf20Sopenharmony_ci	 * Once a request is processed, the fw will usually return
758c2ecf20Sopenharmony_ci	 * a cmpl message type. In cases where errors occurred,
768c2ecf20Sopenharmony_ci	 * the header status would be filled in with one of the following:
778c2ecf20Sopenharmony_ci	 */
788c2ecf20Sopenharmony_ci	SNIC_STAT_ABORTED,		/* req was aborted */
798c2ecf20Sopenharmony_ci	SNIC_STAT_TIMEOUT,		/* req was timed out */
808c2ecf20Sopenharmony_ci	SNIC_STAT_SGL_INVALID,		/* req was aborted due to sgl error */
818c2ecf20Sopenharmony_ci	SNIC_STAT_DATA_CNT_MISMATCH,	/*recv/sent more/less data than expec */
828c2ecf20Sopenharmony_ci	SNIC_STAT_FW_ERR,		/* req was terminated due to fw error */
838c2ecf20Sopenharmony_ci	SNIC_STAT_ITMF_REJECT,		/* itmf req was rejected by target */
848c2ecf20Sopenharmony_ci	SNIC_STAT_ITMF_FAIL,		/* itmf req was failed */
858c2ecf20Sopenharmony_ci	SNIC_STAT_ITMF_INCORRECT_LUN,	/* itmf req has incorrect LUN id*/
868c2ecf20Sopenharmony_ci	SNIC_STAT_CMND_REJECT,		/* req was invalid and rejected */
878c2ecf20Sopenharmony_ci	SNIC_STAT_DEV_OFFLINE,		/* req sent to offline device */
888c2ecf20Sopenharmony_ci	SNIC_STAT_NO_BOOTLUN,
898c2ecf20Sopenharmony_ci	SNIC_STAT_SCSI_ERR,		/* SCSI error returned by Target. */
908c2ecf20Sopenharmony_ci	SNIC_STAT_NOT_READY,		/* sNIC Subsystem is not ready */
918c2ecf20Sopenharmony_ci	SNIC_STAT_FATAL_ERROR,		/* sNIC is in unrecoverable state */
928c2ecf20Sopenharmony_ci}; /* end of enum snic_io_status */
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * snic_io_hdr : host <--> firmware
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci * for any other message that will be queued to firmware should
988c2ecf20Sopenharmony_ci *  have the following request header
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_cistruct snic_io_hdr {
1018c2ecf20Sopenharmony_ci	__le32	hid;
1028c2ecf20Sopenharmony_ci	__le32	cmnd_id;	/* tag here */
1038c2ecf20Sopenharmony_ci	ulong	init_ctx;	/* initiator context */
1048c2ecf20Sopenharmony_ci	u8	type;		/* request/response type */
1058c2ecf20Sopenharmony_ci	u8	status;		/* header status entry */
1068c2ecf20Sopenharmony_ci	u8	protocol;	/* Protocol specific, may needed for RoCE*/
1078c2ecf20Sopenharmony_ci	u8	flags;
1088c2ecf20Sopenharmony_ci	__le16	sg_cnt;
1098c2ecf20Sopenharmony_ci	u16	resvd;
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* auxillary funciton for encoding the snic_io_hdr */
1138c2ecf20Sopenharmony_cistatic inline void
1148c2ecf20Sopenharmony_cisnic_io_hdr_enc(struct snic_io_hdr *hdr, u8 typ, u8 status, u32 id, u32 hid,
1158c2ecf20Sopenharmony_ci		u16 sg_cnt, ulong ctx)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	hdr->type = typ;
1188c2ecf20Sopenharmony_ci	hdr->status = status;
1198c2ecf20Sopenharmony_ci	hdr->protocol = 0;
1208c2ecf20Sopenharmony_ci	hdr->hid = cpu_to_le32(hid);
1218c2ecf20Sopenharmony_ci	hdr->cmnd_id = cpu_to_le32(id);
1228c2ecf20Sopenharmony_ci	hdr->sg_cnt = cpu_to_le16(sg_cnt);
1238c2ecf20Sopenharmony_ci	hdr->init_ctx = ctx;
1248c2ecf20Sopenharmony_ci	hdr->flags = 0;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* auxillary funciton for decoding the snic_io_hdr */
1288c2ecf20Sopenharmony_cistatic inline void
1298c2ecf20Sopenharmony_cisnic_io_hdr_dec(struct snic_io_hdr *hdr, u8 *typ, u8 *stat, u32 *cmnd_id,
1308c2ecf20Sopenharmony_ci		u32 *hid, ulong *ctx)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	*typ = hdr->type;
1338c2ecf20Sopenharmony_ci	*stat = hdr->status;
1348c2ecf20Sopenharmony_ci	*hid = le32_to_cpu(hdr->hid);
1358c2ecf20Sopenharmony_ci	*cmnd_id = le32_to_cpu(hdr->cmnd_id);
1368c2ecf20Sopenharmony_ci	*ctx = hdr->init_ctx;
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/*
1408c2ecf20Sopenharmony_ci * snic_host_info: host -> firmware
1418c2ecf20Sopenharmony_ci *
1428c2ecf20Sopenharmony_ci * Used for sending host information to firmware, and request fw version
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_cistruct snic_exch_ver_req {
1458c2ecf20Sopenharmony_ci	__le32	drvr_ver;	/* for debugging, when fw dump captured */
1468c2ecf20Sopenharmony_ci	__le32	os_type;	/* for OS specific features */
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/*
1508c2ecf20Sopenharmony_ci * os_type flags
1518c2ecf20Sopenharmony_ci * Bit 0-7 : OS information
1528c2ecf20Sopenharmony_ci * Bit 8-31: Feature/Capability Information
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_ci#define SNIC_OS_LINUX	0x1
1558c2ecf20Sopenharmony_ci#define SNIC_OS_WIN	0x2
1568c2ecf20Sopenharmony_ci#define SNIC_OS_ESX	0x3
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/*
1598c2ecf20Sopenharmony_ci * HBA Capabilities
1608c2ecf20Sopenharmony_ci * Bit 1: Reserved.
1618c2ecf20Sopenharmony_ci * Bit 2: Dynamic Discovery of LUNs.
1628c2ecf20Sopenharmony_ci * Bit 3: Async event notifications on on tgt online/offline events.
1638c2ecf20Sopenharmony_ci * Bit 4: IO timeout support in FW.
1648c2ecf20Sopenharmony_ci * Bit 5-31: Reserved.
1658c2ecf20Sopenharmony_ci */
1668c2ecf20Sopenharmony_ci#define SNIC_HBA_CAP_DDL	0x02	/* Supports Dynamic Discovery of LUNs */
1678c2ecf20Sopenharmony_ci#define SNIC_HBA_CAP_AEN	0x04	/* Supports Async Event Noitifcation */
1688c2ecf20Sopenharmony_ci#define SNIC_HBA_CAP_TMO	0x08	/* Supports IO timeout in FW */
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/*
1718c2ecf20Sopenharmony_ci * snic_exch_ver_rsp : firmware -> host
1728c2ecf20Sopenharmony_ci *
1738c2ecf20Sopenharmony_ci * Used by firmware to send response to version request
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_cistruct snic_exch_ver_rsp {
1768c2ecf20Sopenharmony_ci	__le32	version;
1778c2ecf20Sopenharmony_ci	__le32	hid;
1788c2ecf20Sopenharmony_ci	__le32	max_concur_ios;		/* max concurrent ios */
1798c2ecf20Sopenharmony_ci	__le32	max_sgs_per_cmd;	/* max sgls per IO */
1808c2ecf20Sopenharmony_ci	__le32	max_io_sz;		/* max io size supported */
1818c2ecf20Sopenharmony_ci	__le32	hba_cap;		/* hba capabilities */
1828c2ecf20Sopenharmony_ci	__le32	max_tgts;		/* max tgts supported */
1838c2ecf20Sopenharmony_ci	__le16	io_timeout;		/* FW extended timeout */
1848c2ecf20Sopenharmony_ci	u16	rsvd;
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/*
1898c2ecf20Sopenharmony_ci * snic_report_tgts : host -> firmware request
1908c2ecf20Sopenharmony_ci *
1918c2ecf20Sopenharmony_ci * Used by the host to request list of targets
1928c2ecf20Sopenharmony_ci */
1938c2ecf20Sopenharmony_cistruct snic_report_tgts {
1948c2ecf20Sopenharmony_ci	__le16	sg_cnt;
1958c2ecf20Sopenharmony_ci	__le16	flags;		/* specific flags from fw */
1968c2ecf20Sopenharmony_ci	u8	_resvd[4];
1978c2ecf20Sopenharmony_ci	__le64	sg_addr;	/* Points to SGL */
1988c2ecf20Sopenharmony_ci	__le64	sense_addr;
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cienum snic_type {
2028c2ecf20Sopenharmony_ci	SNIC_NONE = 0x0,
2038c2ecf20Sopenharmony_ci	SNIC_DAS,
2048c2ecf20Sopenharmony_ci	SNIC_SAN,
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* Report Target Response */
2098c2ecf20Sopenharmony_cienum snic_tgt_type {
2108c2ecf20Sopenharmony_ci	SNIC_TGT_NONE = 0x0,
2118c2ecf20Sopenharmony_ci	SNIC_TGT_DAS,	/* DAS Target */
2128c2ecf20Sopenharmony_ci	SNIC_TGT_SAN,	/* SAN Target */
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* target id format */
2168c2ecf20Sopenharmony_cistruct snic_tgt_id {
2178c2ecf20Sopenharmony_ci	__le32	tgt_id;		/* target id */
2188c2ecf20Sopenharmony_ci	__le16	tgt_type;	/* tgt type */
2198c2ecf20Sopenharmony_ci	__le16	vnic_id;	/* corresponding vnic id */
2208c2ecf20Sopenharmony_ci};
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/*
2238c2ecf20Sopenharmony_ci * snic_report_tgts_cmpl : firmware -> host response
2248c2ecf20Sopenharmony_ci *
2258c2ecf20Sopenharmony_ci * Used by firmware to send response to Report Targets request
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_cistruct snic_report_tgts_cmpl {
2288c2ecf20Sopenharmony_ci	__le32	tgt_cnt;	/* Number of Targets accessible */
2298c2ecf20Sopenharmony_ci	u32	_resvd;
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/*
2338c2ecf20Sopenharmony_ci * Command flags
2348c2ecf20Sopenharmony_ci *
2358c2ecf20Sopenharmony_ci * Bit 0: Read flags
2368c2ecf20Sopenharmony_ci * Bit 1: Write flag
2378c2ecf20Sopenharmony_ci * Bit 2: ESGL - sg/esg array contains extended sg
2388c2ecf20Sopenharmony_ci *	  ESGE - is a host buffer contains sg elements
2398c2ecf20Sopenharmony_ci * Bit 3-4: Task Attributes
2408c2ecf20Sopenharmony_ci *		00b - simple
2418c2ecf20Sopenharmony_ci *		01b - head of queue
2428c2ecf20Sopenharmony_ci *		10b - ordered
2438c2ecf20Sopenharmony_ci * Bit 5-7: Priority - future use
2448c2ecf20Sopenharmony_ci * Bit 8-15: Reserved
2458c2ecf20Sopenharmony_ci */
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci#define SNIC_ICMND_WR		0x01	/* write command */
2488c2ecf20Sopenharmony_ci#define SNIC_ICMND_RD		0x02	/* read command */
2498c2ecf20Sopenharmony_ci#define SNIC_ICMND_ESGL		0x04	/* SGE/ESGE array contains valid data*/
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/*
2528c2ecf20Sopenharmony_ci * Priority/Task Attribute settings
2538c2ecf20Sopenharmony_ci */
2548c2ecf20Sopenharmony_ci#define SNIC_ICMND_TSK_SHIFT		2	/* task attr starts at bit 2 */
2558c2ecf20Sopenharmony_ci#define SNIC_ICMND_TSK_MASK(x)		((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff))
2568c2ecf20Sopenharmony_ci#define SNIC_ICMND_TSK_SIMPLE		0	/* simple task attr */
2578c2ecf20Sopenharmony_ci#define SNIC_ICMND_TSK_HEAD_OF_QUEUE	1	/* head of qeuue task attr */
2588c2ecf20Sopenharmony_ci#define SNIC_ICMND_TSK_ORDERED		2	/* ordered task attr */
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci#define SNIC_ICMND_PRI_SHIFT		5	/* prio val starts at bit 5 */
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/*
2638c2ecf20Sopenharmony_ci * snic_icmnd : host-> firmware request
2648c2ecf20Sopenharmony_ci *
2658c2ecf20Sopenharmony_ci * used for sending out an initiator SCSI 16/32-byte command
2668c2ecf20Sopenharmony_ci */
2678c2ecf20Sopenharmony_cistruct snic_icmnd {
2688c2ecf20Sopenharmony_ci	__le16	sg_cnt;		/* Number of SG Elements */
2698c2ecf20Sopenharmony_ci	__le16	flags;		/* flags */
2708c2ecf20Sopenharmony_ci	__le32	sense_len;	/* Sense buffer length */
2718c2ecf20Sopenharmony_ci	__le64	tgt_id;		/* Destination Target ID */
2728c2ecf20Sopenharmony_ci	__le64	lun_id;		/* Destination LUN ID */
2738c2ecf20Sopenharmony_ci	u8	cdb_len;
2748c2ecf20Sopenharmony_ci	u8	_resvd;
2758c2ecf20Sopenharmony_ci	__le16	time_out;	/* ms time for Res allocations fw to handle io*/
2768c2ecf20Sopenharmony_ci	__le32	data_len;	/* Total number of bytes to be transferred */
2778c2ecf20Sopenharmony_ci	u8	cdb[SNIC_CDB_LEN];
2788c2ecf20Sopenharmony_ci	__le64	sg_addr;	/* Points to SG List */
2798c2ecf20Sopenharmony_ci	__le64	sense_addr;	/* Sense buffer address */
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/* Response flags */
2848c2ecf20Sopenharmony_ci/* Bit 0: Under run
2858c2ecf20Sopenharmony_ci * Bit 1: Over Run
2868c2ecf20Sopenharmony_ci * Bit 2-7: Reserved
2878c2ecf20Sopenharmony_ci */
2888c2ecf20Sopenharmony_ci#define SNIC_ICMND_CMPL_UNDR_RUN	0x01	/* resid under and valid */
2898c2ecf20Sopenharmony_ci#define SNIC_ICMND_CMPL_OVER_RUN	0x02	/* resid over and valid */
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/*
2928c2ecf20Sopenharmony_ci * snic_icmnd_cmpl: firmware -> host response
2938c2ecf20Sopenharmony_ci *
2948c2ecf20Sopenharmony_ci * Used for sending the host a response to an icmnd (initiator command)
2958c2ecf20Sopenharmony_ci */
2968c2ecf20Sopenharmony_cistruct snic_icmnd_cmpl {
2978c2ecf20Sopenharmony_ci	u8	scsi_status;	/* value as per SAM */
2988c2ecf20Sopenharmony_ci	u8	flags;
2998c2ecf20Sopenharmony_ci	__le16	sense_len;	/* Sense Length */
3008c2ecf20Sopenharmony_ci	__le32	resid;		/* Residue : # bytes under or over run */
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/*
3048c2ecf20Sopenharmony_ci * snic_itmf: host->firmware request
3058c2ecf20Sopenharmony_ci *
3068c2ecf20Sopenharmony_ci * used for requesting the firmware to abort a request and/or send out
3078c2ecf20Sopenharmony_ci * a task management function
3088c2ecf20Sopenharmony_ci *
3098c2ecf20Sopenharmony_ci * the req_id field is valid in case of abort task and clear task
3108c2ecf20Sopenharmony_ci */
3118c2ecf20Sopenharmony_cistruct snic_itmf {
3128c2ecf20Sopenharmony_ci	u8	tm_type;	/* SCSI Task Management request */
3138c2ecf20Sopenharmony_ci	u8	resvd;
3148c2ecf20Sopenharmony_ci	__le16	flags;		/* flags */
3158c2ecf20Sopenharmony_ci	__le32	req_id;		/* Command id of snic req to be aborted */
3168c2ecf20Sopenharmony_ci	__le64	tgt_id;		/* Target ID */
3178c2ecf20Sopenharmony_ci	__le64	lun_id;		/* Destination LUN ID */
3188c2ecf20Sopenharmony_ci	__le16	timeout;	/* in sec */
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/*
3228c2ecf20Sopenharmony_ci * Task Management Request
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cienum snic_itmf_tm_type {
3258c2ecf20Sopenharmony_ci	SNIC_ITMF_ABTS_TASK = 0x01,	/* Abort Task */
3268c2ecf20Sopenharmony_ci	SNIC_ITMF_ABTS_TASK_SET,	/* Abort Task Set */
3278c2ecf20Sopenharmony_ci	SNIC_ITMF_CLR_TASK,		/* Clear Task */
3288c2ecf20Sopenharmony_ci	SNIC_ITMF_CLR_TASKSET,		/* Clear Task Set */
3298c2ecf20Sopenharmony_ci	SNIC_ITMF_LUN_RESET,		/* Lun Reset */
3308c2ecf20Sopenharmony_ci	SNIC_ITMF_ABTS_TASK_TERM,	/* Supported for SAN Targets */
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/*
3348c2ecf20Sopenharmony_ci * snic_itmf_cmpl: firmware -> host resposne
3358c2ecf20Sopenharmony_ci *
3368c2ecf20Sopenharmony_ci * used for sending the host a response for a itmf request
3378c2ecf20Sopenharmony_ci */
3388c2ecf20Sopenharmony_cistruct snic_itmf_cmpl {
3398c2ecf20Sopenharmony_ci	__le32	nterminated;	/* # IOs terminated as a result of tmf */
3408c2ecf20Sopenharmony_ci	u8	flags;		/* flags */
3418c2ecf20Sopenharmony_ci	u8	_resvd[3];
3428c2ecf20Sopenharmony_ci};
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/*
3458c2ecf20Sopenharmony_ci * itmfl_cmpl flags
3468c2ecf20Sopenharmony_ci * Bit 0 : 1 - Num terminated field valid
3478c2ecf20Sopenharmony_ci * Bit 1 - 7 : Reserved
3488c2ecf20Sopenharmony_ci */
3498c2ecf20Sopenharmony_ci#define SNIC_NUM_TERM_VALID	0x01	/* Number of IOs terminated */
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/*
3528c2ecf20Sopenharmony_ci * snic_hba_reset: host -> firmware request
3538c2ecf20Sopenharmony_ci *
3548c2ecf20Sopenharmony_ci * used for requesting firmware to reset snic
3558c2ecf20Sopenharmony_ci */
3568c2ecf20Sopenharmony_cistruct snic_hba_reset {
3578c2ecf20Sopenharmony_ci	__le16	flags;		/* flags */
3588c2ecf20Sopenharmony_ci	u8	_resvd[6];
3598c2ecf20Sopenharmony_ci};
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci/*
3628c2ecf20Sopenharmony_ci * snic_hba_reset_cmpl: firmware -> host response
3638c2ecf20Sopenharmony_ci *
3648c2ecf20Sopenharmony_ci * Used by firmware to respond to the host's hba reset request
3658c2ecf20Sopenharmony_ci */
3668c2ecf20Sopenharmony_cistruct snic_hba_reset_cmpl {
3678c2ecf20Sopenharmony_ci	u8	flags;		/* flags : more info needs to be added*/
3688c2ecf20Sopenharmony_ci	u8	_resvd[7];
3698c2ecf20Sopenharmony_ci};
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/*
3728c2ecf20Sopenharmony_ci * snic_notify_msg: firmware -> host response
3738c2ecf20Sopenharmony_ci *
3748c2ecf20Sopenharmony_ci * Used by firmware to notify host of the last work queue entry received
3758c2ecf20Sopenharmony_ci */
3768c2ecf20Sopenharmony_cistruct snic_notify_msg {
3778c2ecf20Sopenharmony_ci	__le32	wqe_num;	/* wq entry number */
3788c2ecf20Sopenharmony_ci	u8	flags;		/* flags, macros */
3798c2ecf20Sopenharmony_ci	u8	_resvd[4];
3808c2ecf20Sopenharmony_ci};
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#define SNIC_EVDATA_LEN		24	/* in bytes */
3848c2ecf20Sopenharmony_ci/* snic_async_evnotify: firmware -> host notification
3858c2ecf20Sopenharmony_ci *
3868c2ecf20Sopenharmony_ci * Used by firmware to notify the host about configuration/state changes
3878c2ecf20Sopenharmony_ci */
3888c2ecf20Sopenharmony_cistruct snic_async_evnotify {
3898c2ecf20Sopenharmony_ci	u8	FLS_EVENT_DESC;
3908c2ecf20Sopenharmony_ci	u8	vnic;			/* vnic id */
3918c2ecf20Sopenharmony_ci	u8	_resvd[2];
3928c2ecf20Sopenharmony_ci	__le32	ev_id;			/* Event ID */
3938c2ecf20Sopenharmony_ci	u8	ev_data[SNIC_EVDATA_LEN]; /* Event Data */
3948c2ecf20Sopenharmony_ci	u8	_resvd2[4];
3958c2ecf20Sopenharmony_ci};
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/* async event flags */
3988c2ecf20Sopenharmony_cienum snic_ev_type {
3998c2ecf20Sopenharmony_ci	SNIC_EV_TGT_OFFLINE = 0x01, /* Target Offline, PL contains TGT ID */
4008c2ecf20Sopenharmony_ci	SNIC_EV_TGT_ONLINE,	/* Target Online, PL contains TGT ID */
4018c2ecf20Sopenharmony_ci	SNIC_EV_LUN_OFFLINE,	/* LUN Offline, PL contains LUN ID */
4028c2ecf20Sopenharmony_ci	SNIC_EV_LUN_ONLINE,	/* LUN Online, PL contains LUN ID */
4038c2ecf20Sopenharmony_ci	SNIC_EV_CONF_CHG,	/* Dev Config/Attr Change Event */
4048c2ecf20Sopenharmony_ci	SNIC_EV_TGT_ADDED,	/* Target Added */
4058c2ecf20Sopenharmony_ci	SNIC_EV_TGT_DELTD,	/* Target Del'd, PL contains TGT ID */
4068c2ecf20Sopenharmony_ci	SNIC_EV_LUN_ADDED,	/* LUN Added */
4078c2ecf20Sopenharmony_ci	SNIC_EV_LUN_DELTD,	/* LUN Del'd, PL cont. TGT & LUN ID */
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	SNIC_EV_DISC_CMPL = 0x10, /* Discovery Completed Event */
4108c2ecf20Sopenharmony_ci};
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci#define SNIC_HOST_REQ_LEN	128	/*Exp length of host req, wq desc sz*/
4148c2ecf20Sopenharmony_ci/* Payload 88 bytes = 128 - 24 - 16 */
4158c2ecf20Sopenharmony_ci#define SNIC_HOST_REQ_PAYLOAD	((int)(SNIC_HOST_REQ_LEN -		\
4168c2ecf20Sopenharmony_ci					sizeof(struct snic_io_hdr) -	\
4178c2ecf20Sopenharmony_ci					(2 * sizeof(u64)) - sizeof(ulong)))
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/*
4208c2ecf20Sopenharmony_ci * snic_host_req: host -> firmware request
4218c2ecf20Sopenharmony_ci *
4228c2ecf20Sopenharmony_ci * Basic structure for all snic requests that are sent from the host to
4238c2ecf20Sopenharmony_ci * firmware. They are 128 bytes in size.
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_cistruct snic_host_req {
4268c2ecf20Sopenharmony_ci	u64	ctrl_data[2];	/*16 bytes - Control Data */
4278c2ecf20Sopenharmony_ci	struct snic_io_hdr hdr;
4288c2ecf20Sopenharmony_ci	union {
4298c2ecf20Sopenharmony_ci		/*
4308c2ecf20Sopenharmony_ci		 * Entry specific space, last byte contains color
4318c2ecf20Sopenharmony_ci		 */
4328c2ecf20Sopenharmony_ci		u8	buf[SNIC_HOST_REQ_PAYLOAD];
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci		/*
4358c2ecf20Sopenharmony_ci		 * Exchange firmware version
4368c2ecf20Sopenharmony_ci		 */
4378c2ecf20Sopenharmony_ci		struct snic_exch_ver_req	exch_ver;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci		/* report targets */
4408c2ecf20Sopenharmony_ci		struct snic_report_tgts		rpt_tgts;
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci		/* io request */
4438c2ecf20Sopenharmony_ci		struct snic_icmnd		icmnd;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci		/* task management request */
4468c2ecf20Sopenharmony_ci		struct snic_itmf		itmf;
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci		/* hba reset */
4498c2ecf20Sopenharmony_ci		struct snic_hba_reset		reset;
4508c2ecf20Sopenharmony_ci	} u;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	ulong req_pa;
4538c2ecf20Sopenharmony_ci}; /* end of snic_host_req structure */
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci#define SNIC_FW_REQ_LEN		64 /* Expected length of fw req */
4578c2ecf20Sopenharmony_cistruct snic_fw_req {
4588c2ecf20Sopenharmony_ci	struct snic_io_hdr hdr;
4598c2ecf20Sopenharmony_ci	union {
4608c2ecf20Sopenharmony_ci		/*
4618c2ecf20Sopenharmony_ci		 * Entry specific space, last byte contains color
4628c2ecf20Sopenharmony_ci		 */
4638c2ecf20Sopenharmony_ci		u8	buf[SNIC_FW_REQ_LEN - sizeof(struct snic_io_hdr)];
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci		/* Exchange Version Response */
4668c2ecf20Sopenharmony_ci		struct snic_exch_ver_rsp	exch_ver_cmpl;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci		/* Report Targets Response */
4698c2ecf20Sopenharmony_ci		struct snic_report_tgts_cmpl	rpt_tgts_cmpl;
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		/* scsi response */
4728c2ecf20Sopenharmony_ci		struct snic_icmnd_cmpl		icmnd_cmpl;
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci		/* task management response */
4758c2ecf20Sopenharmony_ci		struct snic_itmf_cmpl		itmf_cmpl;
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci		/* hba reset response */
4788c2ecf20Sopenharmony_ci		struct snic_hba_reset_cmpl	reset_cmpl;
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci		/* notify message */
4818c2ecf20Sopenharmony_ci		struct snic_notify_msg		ack;
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci		/* async notification event */
4848c2ecf20Sopenharmony_ci		struct snic_async_evnotify	async_ev;
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci	} u;
4878c2ecf20Sopenharmony_ci}; /* end of snic_fw_req structure */
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci/*
4908c2ecf20Sopenharmony_ci * Auxillary macro to verify specific snic req/cmpl structures
4918c2ecf20Sopenharmony_ci * to ensure that it will be aligned to 64 bit, and not using
4928c2ecf20Sopenharmony_ci * color bit field
4938c2ecf20Sopenharmony_ci */
4948c2ecf20Sopenharmony_ci#define VERIFY_REQ_SZ(x)
4958c2ecf20Sopenharmony_ci#define VERIFY_CMPL_SZ(x)
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci/*
4988c2ecf20Sopenharmony_ci * Access routines to encode and decode the color bit, which is the most
4998c2ecf20Sopenharmony_ci * significant bit of the structure.
5008c2ecf20Sopenharmony_ci */
5018c2ecf20Sopenharmony_cistatic inline void
5028c2ecf20Sopenharmony_cisnic_color_enc(struct snic_fw_req *req, u8 color)
5038c2ecf20Sopenharmony_ci{
5048c2ecf20Sopenharmony_ci	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	if (color)
5078c2ecf20Sopenharmony_ci		*c |= 0x80;
5088c2ecf20Sopenharmony_ci	else
5098c2ecf20Sopenharmony_ci		*c &= ~0x80;
5108c2ecf20Sopenharmony_ci}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_cistatic inline void
5138c2ecf20Sopenharmony_cisnic_color_dec(struct snic_fw_req *req, u8 *color)
5148c2ecf20Sopenharmony_ci{
5158c2ecf20Sopenharmony_ci	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	*color = *c >> 7;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	/* Make sure color bit is read from desc *before* other fields
5208c2ecf20Sopenharmony_ci	 * are read from desc. Hardware guarantees color bit is last
5218c2ecf20Sopenharmony_ci	 * bit (byte) written. Adding the rmb() prevents the compiler
5228c2ecf20Sopenharmony_ci	 * and/or CPU from reordering the reads which would potentially
5238c2ecf20Sopenharmony_ci	 * result in reading stale values.
5248c2ecf20Sopenharmony_ci	 */
5258c2ecf20Sopenharmony_ci	rmb();
5268c2ecf20Sopenharmony_ci}
5278c2ecf20Sopenharmony_ci#endif /* end of __SNIC_FWINT_H */
528