162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef __SNIC_FWINT_H
562306a36Sopenharmony_ci#define __SNIC_FWINT_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define SNIC_CDB_LEN	32	/* SCSI CDB size 32, can be used for 16 bytes */
862306a36Sopenharmony_ci#define LUN_ADDR_LEN	8
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * Command entry type
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_cienum snic_io_type {
1462306a36Sopenharmony_ci	/*
1562306a36Sopenharmony_ci	 * Initiator request types
1662306a36Sopenharmony_ci	 */
1762306a36Sopenharmony_ci	SNIC_REQ_REPORT_TGTS = 0x2,	/* Report Targets */
1862306a36Sopenharmony_ci	SNIC_REQ_ICMND,			/* Initiator command for SCSI IO */
1962306a36Sopenharmony_ci	SNIC_REQ_ITMF,			/* Initiator command for Task Mgmt */
2062306a36Sopenharmony_ci	SNIC_REQ_HBA_RESET,		/* SNIC Reset */
2162306a36Sopenharmony_ci	SNIC_REQ_EXCH_VER,		/* Exchange Version Information */
2262306a36Sopenharmony_ci	SNIC_REQ_TGT_INFO,		/* Backend/Target Information */
2362306a36Sopenharmony_ci	SNIC_REQ_BOOT_LUNS,
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	/*
2662306a36Sopenharmony_ci	 * Response type
2762306a36Sopenharmony_ci	 */
2862306a36Sopenharmony_ci	SNIC_RSP_REPORT_TGTS_CMPL = 0x12,/* Report Targets Completion */
2962306a36Sopenharmony_ci	SNIC_RSP_ICMND_CMPL,		/* SCSI IO Completion */
3062306a36Sopenharmony_ci	SNIC_RSP_ITMF_CMPL,		/* Task Management Completion */
3162306a36Sopenharmony_ci	SNIC_RSP_HBA_RESET_CMPL,	/* SNIC Reset Completion */
3262306a36Sopenharmony_ci	SNIC_RSP_EXCH_VER_CMPL,		/* Exchange Version Completion*/
3362306a36Sopenharmony_ci	SNIC_RSP_BOOT_LUNS_CMPL,
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	/*
3662306a36Sopenharmony_ci	 * Misc Request types
3762306a36Sopenharmony_ci	 */
3862306a36Sopenharmony_ci	SNIC_MSG_ACK = 0x80,		/* Ack: snic_notify_msg */
3962306a36Sopenharmony_ci	SNIC_MSG_ASYNC_EVNOTIFY,	/* Asynchronous Event Notification */
4062306a36Sopenharmony_ci}; /* end of enum snic_io_type */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * Header status codes from firmware
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_cienum snic_io_status {
4762306a36Sopenharmony_ci	SNIC_STAT_IO_SUCCESS = 0,	/* request was successful */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	/*
5062306a36Sopenharmony_ci	 * If a request to the fw is rejected, the original request header
5162306a36Sopenharmony_ci	 * will be returned with the status set to one of the following:
5262306a36Sopenharmony_ci	 */
5362306a36Sopenharmony_ci	SNIC_STAT_INVALID_HDR,	/* header contains invalid data */
5462306a36Sopenharmony_ci	SNIC_STAT_OUT_OF_RES,	/* out of resources to complete request */
5562306a36Sopenharmony_ci	SNIC_STAT_INVALID_PARM,	/* some parameter in request is not valid */
5662306a36Sopenharmony_ci	SNIC_STAT_REQ_NOT_SUP,	/* req type is not supported */
5762306a36Sopenharmony_ci	SNIC_STAT_IO_NOT_FOUND,	/* requested IO was not found */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/*
6062306a36Sopenharmony_ci	 * Once a request is processed, the fw will usually return
6162306a36Sopenharmony_ci	 * a cmpl message type. In cases where errors occurred,
6262306a36Sopenharmony_ci	 * the header status would be filled in with one of the following:
6362306a36Sopenharmony_ci	 */
6462306a36Sopenharmony_ci	SNIC_STAT_ABORTED,		/* req was aborted */
6562306a36Sopenharmony_ci	SNIC_STAT_TIMEOUT,		/* req was timed out */
6662306a36Sopenharmony_ci	SNIC_STAT_SGL_INVALID,		/* req was aborted due to sgl error */
6762306a36Sopenharmony_ci	SNIC_STAT_DATA_CNT_MISMATCH,	/*recv/sent more/less data than expec */
6862306a36Sopenharmony_ci	SNIC_STAT_FW_ERR,		/* req was terminated due to fw error */
6962306a36Sopenharmony_ci	SNIC_STAT_ITMF_REJECT,		/* itmf req was rejected by target */
7062306a36Sopenharmony_ci	SNIC_STAT_ITMF_FAIL,		/* itmf req was failed */
7162306a36Sopenharmony_ci	SNIC_STAT_ITMF_INCORRECT_LUN,	/* itmf req has incorrect LUN id*/
7262306a36Sopenharmony_ci	SNIC_STAT_CMND_REJECT,		/* req was invalid and rejected */
7362306a36Sopenharmony_ci	SNIC_STAT_DEV_OFFLINE,		/* req sent to offline device */
7462306a36Sopenharmony_ci	SNIC_STAT_NO_BOOTLUN,
7562306a36Sopenharmony_ci	SNIC_STAT_SCSI_ERR,		/* SCSI error returned by Target. */
7662306a36Sopenharmony_ci	SNIC_STAT_NOT_READY,		/* sNIC Subsystem is not ready */
7762306a36Sopenharmony_ci	SNIC_STAT_FATAL_ERROR,		/* sNIC is in unrecoverable state */
7862306a36Sopenharmony_ci}; /* end of enum snic_io_status */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/*
8162306a36Sopenharmony_ci * snic_io_hdr : host <--> firmware
8262306a36Sopenharmony_ci *
8362306a36Sopenharmony_ci * for any other message that will be queued to firmware should
8462306a36Sopenharmony_ci *  have the following request header
8562306a36Sopenharmony_ci */
8662306a36Sopenharmony_cistruct snic_io_hdr {
8762306a36Sopenharmony_ci	__le32	hid;
8862306a36Sopenharmony_ci	__le32	cmnd_id;	/* tag here */
8962306a36Sopenharmony_ci	ulong	init_ctx;	/* initiator context */
9062306a36Sopenharmony_ci	u8	type;		/* request/response type */
9162306a36Sopenharmony_ci	u8	status;		/* header status entry */
9262306a36Sopenharmony_ci	u8	protocol;	/* Protocol specific, may needed for RoCE*/
9362306a36Sopenharmony_ci	u8	flags;
9462306a36Sopenharmony_ci	__le16	sg_cnt;
9562306a36Sopenharmony_ci	u16	resvd;
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* auxillary funciton for encoding the snic_io_hdr */
9962306a36Sopenharmony_cistatic inline void
10062306a36Sopenharmony_cisnic_io_hdr_enc(struct snic_io_hdr *hdr, u8 typ, u8 status, u32 id, u32 hid,
10162306a36Sopenharmony_ci		u16 sg_cnt, ulong ctx)
10262306a36Sopenharmony_ci{
10362306a36Sopenharmony_ci	hdr->type = typ;
10462306a36Sopenharmony_ci	hdr->status = status;
10562306a36Sopenharmony_ci	hdr->protocol = 0;
10662306a36Sopenharmony_ci	hdr->hid = cpu_to_le32(hid);
10762306a36Sopenharmony_ci	hdr->cmnd_id = cpu_to_le32(id);
10862306a36Sopenharmony_ci	hdr->sg_cnt = cpu_to_le16(sg_cnt);
10962306a36Sopenharmony_ci	hdr->init_ctx = ctx;
11062306a36Sopenharmony_ci	hdr->flags = 0;
11162306a36Sopenharmony_ci}
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* auxillary funciton for decoding the snic_io_hdr */
11462306a36Sopenharmony_cistatic inline void
11562306a36Sopenharmony_cisnic_io_hdr_dec(struct snic_io_hdr *hdr, u8 *typ, u8 *stat, u32 *cmnd_id,
11662306a36Sopenharmony_ci		u32 *hid, ulong *ctx)
11762306a36Sopenharmony_ci{
11862306a36Sopenharmony_ci	*typ = hdr->type;
11962306a36Sopenharmony_ci	*stat = hdr->status;
12062306a36Sopenharmony_ci	*hid = le32_to_cpu(hdr->hid);
12162306a36Sopenharmony_ci	*cmnd_id = le32_to_cpu(hdr->cmnd_id);
12262306a36Sopenharmony_ci	*ctx = hdr->init_ctx;
12362306a36Sopenharmony_ci}
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/*
12662306a36Sopenharmony_ci * snic_host_info: host -> firmware
12762306a36Sopenharmony_ci *
12862306a36Sopenharmony_ci * Used for sending host information to firmware, and request fw version
12962306a36Sopenharmony_ci */
13062306a36Sopenharmony_cistruct snic_exch_ver_req {
13162306a36Sopenharmony_ci	__le32	drvr_ver;	/* for debugging, when fw dump captured */
13262306a36Sopenharmony_ci	__le32	os_type;	/* for OS specific features */
13362306a36Sopenharmony_ci};
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/*
13662306a36Sopenharmony_ci * os_type flags
13762306a36Sopenharmony_ci * Bit 0-7 : OS information
13862306a36Sopenharmony_ci * Bit 8-31: Feature/Capability Information
13962306a36Sopenharmony_ci */
14062306a36Sopenharmony_ci#define SNIC_OS_LINUX	0x1
14162306a36Sopenharmony_ci#define SNIC_OS_WIN	0x2
14262306a36Sopenharmony_ci#define SNIC_OS_ESX	0x3
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/*
14562306a36Sopenharmony_ci * HBA Capabilities
14662306a36Sopenharmony_ci * Bit 1: Reserved.
14762306a36Sopenharmony_ci * Bit 2: Dynamic Discovery of LUNs.
14862306a36Sopenharmony_ci * Bit 3: Async event notifications on tgt online/offline events.
14962306a36Sopenharmony_ci * Bit 4: IO timeout support in FW.
15062306a36Sopenharmony_ci * Bit 5-31: Reserved.
15162306a36Sopenharmony_ci */
15262306a36Sopenharmony_ci#define SNIC_HBA_CAP_DDL	0x02	/* Supports Dynamic Discovery of LUNs */
15362306a36Sopenharmony_ci#define SNIC_HBA_CAP_AEN	0x04	/* Supports Async Event Noitifcation */
15462306a36Sopenharmony_ci#define SNIC_HBA_CAP_TMO	0x08	/* Supports IO timeout in FW */
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci/*
15762306a36Sopenharmony_ci * snic_exch_ver_rsp : firmware -> host
15862306a36Sopenharmony_ci *
15962306a36Sopenharmony_ci * Used by firmware to send response to version request
16062306a36Sopenharmony_ci */
16162306a36Sopenharmony_cistruct snic_exch_ver_rsp {
16262306a36Sopenharmony_ci	__le32	version;
16362306a36Sopenharmony_ci	__le32	hid;
16462306a36Sopenharmony_ci	__le32	max_concur_ios;		/* max concurrent ios */
16562306a36Sopenharmony_ci	__le32	max_sgs_per_cmd;	/* max sgls per IO */
16662306a36Sopenharmony_ci	__le32	max_io_sz;		/* max io size supported */
16762306a36Sopenharmony_ci	__le32	hba_cap;		/* hba capabilities */
16862306a36Sopenharmony_ci	__le32	max_tgts;		/* max tgts supported */
16962306a36Sopenharmony_ci	__le16	io_timeout;		/* FW extended timeout */
17062306a36Sopenharmony_ci	u16	rsvd;
17162306a36Sopenharmony_ci};
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci/*
17562306a36Sopenharmony_ci * snic_report_tgts : host -> firmware request
17662306a36Sopenharmony_ci *
17762306a36Sopenharmony_ci * Used by the host to request list of targets
17862306a36Sopenharmony_ci */
17962306a36Sopenharmony_cistruct snic_report_tgts {
18062306a36Sopenharmony_ci	__le16	sg_cnt;
18162306a36Sopenharmony_ci	__le16	flags;		/* specific flags from fw */
18262306a36Sopenharmony_ci	u8	_resvd[4];
18362306a36Sopenharmony_ci	__le64	sg_addr;	/* Points to SGL */
18462306a36Sopenharmony_ci	__le64	sense_addr;
18562306a36Sopenharmony_ci};
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_cienum snic_type {
18862306a36Sopenharmony_ci	SNIC_NONE = 0x0,
18962306a36Sopenharmony_ci	SNIC_DAS,
19062306a36Sopenharmony_ci	SNIC_SAN,
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci/* Report Target Response */
19562306a36Sopenharmony_cienum snic_tgt_type {
19662306a36Sopenharmony_ci	SNIC_TGT_NONE = 0x0,
19762306a36Sopenharmony_ci	SNIC_TGT_DAS,	/* DAS Target */
19862306a36Sopenharmony_ci	SNIC_TGT_SAN,	/* SAN Target */
19962306a36Sopenharmony_ci};
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci/* target id format */
20262306a36Sopenharmony_cistruct snic_tgt_id {
20362306a36Sopenharmony_ci	__le32	tgt_id;		/* target id */
20462306a36Sopenharmony_ci	__le16	tgt_type;	/* tgt type */
20562306a36Sopenharmony_ci	__le16	vnic_id;	/* corresponding vnic id */
20662306a36Sopenharmony_ci};
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci/*
20962306a36Sopenharmony_ci * snic_report_tgts_cmpl : firmware -> host response
21062306a36Sopenharmony_ci *
21162306a36Sopenharmony_ci * Used by firmware to send response to Report Targets request
21262306a36Sopenharmony_ci */
21362306a36Sopenharmony_cistruct snic_report_tgts_cmpl {
21462306a36Sopenharmony_ci	__le32	tgt_cnt;	/* Number of Targets accessible */
21562306a36Sopenharmony_ci	u32	_resvd;
21662306a36Sopenharmony_ci};
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci/*
21962306a36Sopenharmony_ci * Command flags
22062306a36Sopenharmony_ci *
22162306a36Sopenharmony_ci * Bit 0: Read flags
22262306a36Sopenharmony_ci * Bit 1: Write flag
22362306a36Sopenharmony_ci * Bit 2: ESGL - sg/esg array contains extended sg
22462306a36Sopenharmony_ci *	  ESGE - is a host buffer contains sg elements
22562306a36Sopenharmony_ci * Bit 3-4: Task Attributes
22662306a36Sopenharmony_ci *		00b - simple
22762306a36Sopenharmony_ci *		01b - head of queue
22862306a36Sopenharmony_ci *		10b - ordered
22962306a36Sopenharmony_ci * Bit 5-7: Priority - future use
23062306a36Sopenharmony_ci * Bit 8-15: Reserved
23162306a36Sopenharmony_ci */
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci#define SNIC_ICMND_WR		0x01	/* write command */
23462306a36Sopenharmony_ci#define SNIC_ICMND_RD		0x02	/* read command */
23562306a36Sopenharmony_ci#define SNIC_ICMND_ESGL		0x04	/* SGE/ESGE array contains valid data*/
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci/*
23862306a36Sopenharmony_ci * Priority/Task Attribute settings
23962306a36Sopenharmony_ci */
24062306a36Sopenharmony_ci#define SNIC_ICMND_TSK_SHIFT		2	/* task attr starts at bit 2 */
24162306a36Sopenharmony_ci#define SNIC_ICMND_TSK_MASK(x)		((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff))
24262306a36Sopenharmony_ci#define SNIC_ICMND_TSK_SIMPLE		0	/* simple task attr */
24362306a36Sopenharmony_ci#define SNIC_ICMND_TSK_HEAD_OF_QUEUE	1	/* head of qeuue task attr */
24462306a36Sopenharmony_ci#define SNIC_ICMND_TSK_ORDERED		2	/* ordered task attr */
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci#define SNIC_ICMND_PRI_SHIFT		5	/* prio val starts at bit 5 */
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci/*
24962306a36Sopenharmony_ci * snic_icmnd : host-> firmware request
25062306a36Sopenharmony_ci *
25162306a36Sopenharmony_ci * used for sending out an initiator SCSI 16/32-byte command
25262306a36Sopenharmony_ci */
25362306a36Sopenharmony_cistruct snic_icmnd {
25462306a36Sopenharmony_ci	__le16	sg_cnt;		/* Number of SG Elements */
25562306a36Sopenharmony_ci	__le16	flags;		/* flags */
25662306a36Sopenharmony_ci	__le32	sense_len;	/* Sense buffer length */
25762306a36Sopenharmony_ci	__le64	tgt_id;		/* Destination Target ID */
25862306a36Sopenharmony_ci	__le64	lun_id;		/* Destination LUN ID */
25962306a36Sopenharmony_ci	u8	cdb_len;
26062306a36Sopenharmony_ci	u8	_resvd;
26162306a36Sopenharmony_ci	__le16	time_out;	/* ms time for Res allocations fw to handle io*/
26262306a36Sopenharmony_ci	__le32	data_len;	/* Total number of bytes to be transferred */
26362306a36Sopenharmony_ci	u8	cdb[SNIC_CDB_LEN];
26462306a36Sopenharmony_ci	__le64	sg_addr;	/* Points to SG List */
26562306a36Sopenharmony_ci	__le64	sense_addr;	/* Sense buffer address */
26662306a36Sopenharmony_ci};
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci/* Response flags */
27062306a36Sopenharmony_ci/* Bit 0: Under run
27162306a36Sopenharmony_ci * Bit 1: Over Run
27262306a36Sopenharmony_ci * Bit 2-7: Reserved
27362306a36Sopenharmony_ci */
27462306a36Sopenharmony_ci#define SNIC_ICMND_CMPL_UNDR_RUN	0x01	/* resid under and valid */
27562306a36Sopenharmony_ci#define SNIC_ICMND_CMPL_OVER_RUN	0x02	/* resid over and valid */
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci/*
27862306a36Sopenharmony_ci * snic_icmnd_cmpl: firmware -> host response
27962306a36Sopenharmony_ci *
28062306a36Sopenharmony_ci * Used for sending the host a response to an icmnd (initiator command)
28162306a36Sopenharmony_ci */
28262306a36Sopenharmony_cistruct snic_icmnd_cmpl {
28362306a36Sopenharmony_ci	u8	scsi_status;	/* value as per SAM */
28462306a36Sopenharmony_ci	u8	flags;
28562306a36Sopenharmony_ci	__le16	sense_len;	/* Sense Length */
28662306a36Sopenharmony_ci	__le32	resid;		/* Residue : # bytes under or over run */
28762306a36Sopenharmony_ci};
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci/*
29062306a36Sopenharmony_ci * snic_itmf: host->firmware request
29162306a36Sopenharmony_ci *
29262306a36Sopenharmony_ci * used for requesting the firmware to abort a request and/or send out
29362306a36Sopenharmony_ci * a task management function
29462306a36Sopenharmony_ci *
29562306a36Sopenharmony_ci * the req_id field is valid in case of abort task and clear task
29662306a36Sopenharmony_ci */
29762306a36Sopenharmony_cistruct snic_itmf {
29862306a36Sopenharmony_ci	u8	tm_type;	/* SCSI Task Management request */
29962306a36Sopenharmony_ci	u8	resvd;
30062306a36Sopenharmony_ci	__le16	flags;		/* flags */
30162306a36Sopenharmony_ci	__le32	req_id;		/* Command id of snic req to be aborted */
30262306a36Sopenharmony_ci	__le64	tgt_id;		/* Target ID */
30362306a36Sopenharmony_ci	__le64	lun_id;		/* Destination LUN ID */
30462306a36Sopenharmony_ci	__le16	timeout;	/* in sec */
30562306a36Sopenharmony_ci};
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci/*
30862306a36Sopenharmony_ci * Task Management Request
30962306a36Sopenharmony_ci */
31062306a36Sopenharmony_cienum snic_itmf_tm_type {
31162306a36Sopenharmony_ci	SNIC_ITMF_ABTS_TASK = 0x01,	/* Abort Task */
31262306a36Sopenharmony_ci	SNIC_ITMF_ABTS_TASK_SET,	/* Abort Task Set */
31362306a36Sopenharmony_ci	SNIC_ITMF_CLR_TASK,		/* Clear Task */
31462306a36Sopenharmony_ci	SNIC_ITMF_CLR_TASKSET,		/* Clear Task Set */
31562306a36Sopenharmony_ci	SNIC_ITMF_LUN_RESET,		/* Lun Reset */
31662306a36Sopenharmony_ci	SNIC_ITMF_ABTS_TASK_TERM,	/* Supported for SAN Targets */
31762306a36Sopenharmony_ci};
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci/*
32062306a36Sopenharmony_ci * snic_itmf_cmpl: firmware -> host resposne
32162306a36Sopenharmony_ci *
32262306a36Sopenharmony_ci * used for sending the host a response for a itmf request
32362306a36Sopenharmony_ci */
32462306a36Sopenharmony_cistruct snic_itmf_cmpl {
32562306a36Sopenharmony_ci	__le32	nterminated;	/* # IOs terminated as a result of tmf */
32662306a36Sopenharmony_ci	u8	flags;		/* flags */
32762306a36Sopenharmony_ci	u8	_resvd[3];
32862306a36Sopenharmony_ci};
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci/*
33162306a36Sopenharmony_ci * itmfl_cmpl flags
33262306a36Sopenharmony_ci * Bit 0 : 1 - Num terminated field valid
33362306a36Sopenharmony_ci * Bit 1 - 7 : Reserved
33462306a36Sopenharmony_ci */
33562306a36Sopenharmony_ci#define SNIC_NUM_TERM_VALID	0x01	/* Number of IOs terminated */
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci/*
33862306a36Sopenharmony_ci * snic_hba_reset: host -> firmware request
33962306a36Sopenharmony_ci *
34062306a36Sopenharmony_ci * used for requesting firmware to reset snic
34162306a36Sopenharmony_ci */
34262306a36Sopenharmony_cistruct snic_hba_reset {
34362306a36Sopenharmony_ci	__le16	flags;		/* flags */
34462306a36Sopenharmony_ci	u8	_resvd[6];
34562306a36Sopenharmony_ci};
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci/*
34862306a36Sopenharmony_ci * snic_hba_reset_cmpl: firmware -> host response
34962306a36Sopenharmony_ci *
35062306a36Sopenharmony_ci * Used by firmware to respond to the host's hba reset request
35162306a36Sopenharmony_ci */
35262306a36Sopenharmony_cistruct snic_hba_reset_cmpl {
35362306a36Sopenharmony_ci	u8	flags;		/* flags : more info needs to be added*/
35462306a36Sopenharmony_ci	u8	_resvd[7];
35562306a36Sopenharmony_ci};
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci/*
35862306a36Sopenharmony_ci * snic_notify_msg: firmware -> host response
35962306a36Sopenharmony_ci *
36062306a36Sopenharmony_ci * Used by firmware to notify host of the last work queue entry received
36162306a36Sopenharmony_ci */
36262306a36Sopenharmony_cistruct snic_notify_msg {
36362306a36Sopenharmony_ci	__le32	wqe_num;	/* wq entry number */
36462306a36Sopenharmony_ci	u8	flags;		/* flags, macros */
36562306a36Sopenharmony_ci	u8	_resvd[4];
36662306a36Sopenharmony_ci};
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci#define SNIC_EVDATA_LEN		24	/* in bytes */
37062306a36Sopenharmony_ci/* snic_async_evnotify: firmware -> host notification
37162306a36Sopenharmony_ci *
37262306a36Sopenharmony_ci * Used by firmware to notify the host about configuration/state changes
37362306a36Sopenharmony_ci */
37462306a36Sopenharmony_cistruct snic_async_evnotify {
37562306a36Sopenharmony_ci	u8	FLS_EVENT_DESC;
37662306a36Sopenharmony_ci	u8	vnic;			/* vnic id */
37762306a36Sopenharmony_ci	u8	_resvd[2];
37862306a36Sopenharmony_ci	__le32	ev_id;			/* Event ID */
37962306a36Sopenharmony_ci	u8	ev_data[SNIC_EVDATA_LEN]; /* Event Data */
38062306a36Sopenharmony_ci	u8	_resvd2[4];
38162306a36Sopenharmony_ci};
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci/* async event flags */
38462306a36Sopenharmony_cienum snic_ev_type {
38562306a36Sopenharmony_ci	SNIC_EV_TGT_OFFLINE = 0x01, /* Target Offline, PL contains TGT ID */
38662306a36Sopenharmony_ci	SNIC_EV_TGT_ONLINE,	/* Target Online, PL contains TGT ID */
38762306a36Sopenharmony_ci	SNIC_EV_LUN_OFFLINE,	/* LUN Offline, PL contains LUN ID */
38862306a36Sopenharmony_ci	SNIC_EV_LUN_ONLINE,	/* LUN Online, PL contains LUN ID */
38962306a36Sopenharmony_ci	SNIC_EV_CONF_CHG,	/* Dev Config/Attr Change Event */
39062306a36Sopenharmony_ci	SNIC_EV_TGT_ADDED,	/* Target Added */
39162306a36Sopenharmony_ci	SNIC_EV_TGT_DELTD,	/* Target Del'd, PL contains TGT ID */
39262306a36Sopenharmony_ci	SNIC_EV_LUN_ADDED,	/* LUN Added */
39362306a36Sopenharmony_ci	SNIC_EV_LUN_DELTD,	/* LUN Del'd, PL cont. TGT & LUN ID */
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci	SNIC_EV_DISC_CMPL = 0x10, /* Discovery Completed Event */
39662306a36Sopenharmony_ci};
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ci#define SNIC_HOST_REQ_LEN	128	/*Exp length of host req, wq desc sz*/
40062306a36Sopenharmony_ci/* Payload 88 bytes = 128 - 24 - 16 */
40162306a36Sopenharmony_ci#define SNIC_HOST_REQ_PAYLOAD	((int)(SNIC_HOST_REQ_LEN -		\
40262306a36Sopenharmony_ci					sizeof(struct snic_io_hdr) -	\
40362306a36Sopenharmony_ci					(2 * sizeof(u64)) - sizeof(ulong)))
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci/*
40662306a36Sopenharmony_ci * snic_host_req: host -> firmware request
40762306a36Sopenharmony_ci *
40862306a36Sopenharmony_ci * Basic structure for all snic requests that are sent from the host to
40962306a36Sopenharmony_ci * firmware. They are 128 bytes in size.
41062306a36Sopenharmony_ci */
41162306a36Sopenharmony_cistruct snic_host_req {
41262306a36Sopenharmony_ci	u64	ctrl_data[2];	/*16 bytes - Control Data */
41362306a36Sopenharmony_ci	struct snic_io_hdr hdr;
41462306a36Sopenharmony_ci	union {
41562306a36Sopenharmony_ci		/*
41662306a36Sopenharmony_ci		 * Entry specific space, last byte contains color
41762306a36Sopenharmony_ci		 */
41862306a36Sopenharmony_ci		u8	buf[SNIC_HOST_REQ_PAYLOAD];
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci		/*
42162306a36Sopenharmony_ci		 * Exchange firmware version
42262306a36Sopenharmony_ci		 */
42362306a36Sopenharmony_ci		struct snic_exch_ver_req	exch_ver;
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ci		/* report targets */
42662306a36Sopenharmony_ci		struct snic_report_tgts		rpt_tgts;
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci		/* io request */
42962306a36Sopenharmony_ci		struct snic_icmnd		icmnd;
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci		/* task management request */
43262306a36Sopenharmony_ci		struct snic_itmf		itmf;
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci		/* hba reset */
43562306a36Sopenharmony_ci		struct snic_hba_reset		reset;
43662306a36Sopenharmony_ci	} u;
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci	ulong req_pa;
43962306a36Sopenharmony_ci}; /* end of snic_host_req structure */
44062306a36Sopenharmony_ci
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci#define SNIC_FW_REQ_LEN		64 /* Expected length of fw req */
44362306a36Sopenharmony_cistruct snic_fw_req {
44462306a36Sopenharmony_ci	struct snic_io_hdr hdr;
44562306a36Sopenharmony_ci	union {
44662306a36Sopenharmony_ci		/*
44762306a36Sopenharmony_ci		 * Entry specific space, last byte contains color
44862306a36Sopenharmony_ci		 */
44962306a36Sopenharmony_ci		u8	buf[SNIC_FW_REQ_LEN - sizeof(struct snic_io_hdr)];
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci		/* Exchange Version Response */
45262306a36Sopenharmony_ci		struct snic_exch_ver_rsp	exch_ver_cmpl;
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci		/* Report Targets Response */
45562306a36Sopenharmony_ci		struct snic_report_tgts_cmpl	rpt_tgts_cmpl;
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci		/* scsi response */
45862306a36Sopenharmony_ci		struct snic_icmnd_cmpl		icmnd_cmpl;
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci		/* task management response */
46162306a36Sopenharmony_ci		struct snic_itmf_cmpl		itmf_cmpl;
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci		/* hba reset response */
46462306a36Sopenharmony_ci		struct snic_hba_reset_cmpl	reset_cmpl;
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci		/* notify message */
46762306a36Sopenharmony_ci		struct snic_notify_msg		ack;
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci		/* async notification event */
47062306a36Sopenharmony_ci		struct snic_async_evnotify	async_ev;
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci	} u;
47362306a36Sopenharmony_ci}; /* end of snic_fw_req structure */
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci/*
47662306a36Sopenharmony_ci * Auxillary macro to verify specific snic req/cmpl structures
47762306a36Sopenharmony_ci * to ensure that it will be aligned to 64 bit, and not using
47862306a36Sopenharmony_ci * color bit field
47962306a36Sopenharmony_ci */
48062306a36Sopenharmony_ci#define VERIFY_REQ_SZ(x)
48162306a36Sopenharmony_ci#define VERIFY_CMPL_SZ(x)
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci/*
48462306a36Sopenharmony_ci * Access routines to encode and decode the color bit, which is the most
48562306a36Sopenharmony_ci * significant bit of the structure.
48662306a36Sopenharmony_ci */
48762306a36Sopenharmony_cistatic inline void
48862306a36Sopenharmony_cisnic_color_enc(struct snic_fw_req *req, u8 color)
48962306a36Sopenharmony_ci{
49062306a36Sopenharmony_ci	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
49162306a36Sopenharmony_ci
49262306a36Sopenharmony_ci	if (color)
49362306a36Sopenharmony_ci		*c |= 0x80;
49462306a36Sopenharmony_ci	else
49562306a36Sopenharmony_ci		*c &= ~0x80;
49662306a36Sopenharmony_ci}
49762306a36Sopenharmony_ci
49862306a36Sopenharmony_cistatic inline void
49962306a36Sopenharmony_cisnic_color_dec(struct snic_fw_req *req, u8 *color)
50062306a36Sopenharmony_ci{
50162306a36Sopenharmony_ci	u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
50262306a36Sopenharmony_ci
50362306a36Sopenharmony_ci	*color = *c >> 7;
50462306a36Sopenharmony_ci
50562306a36Sopenharmony_ci	/* Make sure color bit is read from desc *before* other fields
50662306a36Sopenharmony_ci	 * are read from desc. Hardware guarantees color bit is last
50762306a36Sopenharmony_ci	 * bit (byte) written. Adding the rmb() prevents the compiler
50862306a36Sopenharmony_ci	 * and/or CPU from reordering the reads which would potentially
50962306a36Sopenharmony_ci	 * result in reading stale values.
51062306a36Sopenharmony_ci	 */
51162306a36Sopenharmony_ci	rmb();
51262306a36Sopenharmony_ci}
51362306a36Sopenharmony_ci#endif /* end of __SNIC_FWINT_H */
514