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_IO_H
562306a36Sopenharmony_ci#define _SNIC_IO_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define SNIC_DFLT_SG_DESC_CNT	32	/* Default descriptors for sgl */
862306a36Sopenharmony_ci#define SNIC_MAX_SG_DESC_CNT	60	/* Max descriptor for sgl */
962306a36Sopenharmony_ci#define SNIC_SG_DESC_ALIGN	16	/* Descriptor address alignment */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* SG descriptor for snic */
1262306a36Sopenharmony_cistruct snic_sg_desc {
1362306a36Sopenharmony_ci	__le64 addr;
1462306a36Sopenharmony_ci	__le32 len;
1562306a36Sopenharmony_ci	u32 _resvd;
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct snic_dflt_sgl {
1962306a36Sopenharmony_ci	struct snic_sg_desc sg_desc[SNIC_DFLT_SG_DESC_CNT];
2062306a36Sopenharmony_ci};
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct snic_max_sgl {
2362306a36Sopenharmony_ci	struct snic_sg_desc sg_desc[SNIC_MAX_SG_DESC_CNT];
2462306a36Sopenharmony_ci};
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cienum snic_req_cache_type {
2762306a36Sopenharmony_ci	SNIC_REQ_CACHE_DFLT_SGL = 0,	/* cache with default size sgl */
2862306a36Sopenharmony_ci	SNIC_REQ_CACHE_MAX_SGL,		/* cache with max size sgl */
2962306a36Sopenharmony_ci	SNIC_REQ_TM_CACHE,		/* cache for task mgmt reqs contains
3062306a36Sopenharmony_ci					   snic_host_req objects only*/
3162306a36Sopenharmony_ci	SNIC_REQ_MAX_CACHES		/* number of sgl caches */
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Per IO internal state */
3562306a36Sopenharmony_cistruct snic_internal_io_state {
3662306a36Sopenharmony_ci	char	*rqi;
3762306a36Sopenharmony_ci	u64	flags;
3862306a36Sopenharmony_ci	u32	state;
3962306a36Sopenharmony_ci	u32	abts_status;	/* Abort completion status */
4062306a36Sopenharmony_ci	u32	lr_status;	/* device reset completion status */
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* IO state machine */
4462306a36Sopenharmony_cienum snic_ioreq_state {
4562306a36Sopenharmony_ci	SNIC_IOREQ_NOT_INITED = 0,
4662306a36Sopenharmony_ci	SNIC_IOREQ_PENDING,
4762306a36Sopenharmony_ci	SNIC_IOREQ_ABTS_PENDING,
4862306a36Sopenharmony_ci	SNIC_IOREQ_ABTS_COMPLETE,
4962306a36Sopenharmony_ci	SNIC_IOREQ_LR_PENDING,
5062306a36Sopenharmony_ci	SNIC_IOREQ_LR_COMPLETE,
5162306a36Sopenharmony_ci	SNIC_IOREQ_COMPLETE,
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct snic;
5562306a36Sopenharmony_cistruct snic_host_req;
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/*
5862306a36Sopenharmony_ci * snic_req_info : Contains info about IO, one per scsi command.
5962306a36Sopenharmony_ci * Notes: Make sure that the structure is aligned to 16 B
6062306a36Sopenharmony_ci * this helps in easy access to snic_req_info from snic_host_req
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_cistruct snic_req_info {
6362306a36Sopenharmony_ci	struct list_head list;
6462306a36Sopenharmony_ci	struct snic_host_req *req;
6562306a36Sopenharmony_ci	u64	start_time;		/* start time in jiffies */
6662306a36Sopenharmony_ci	u16	rq_pool_type;		/* noticion of request pool type */
6762306a36Sopenharmony_ci	u16	req_len;		/* buf len passing to fw (req + sgl)*/
6862306a36Sopenharmony_ci	u32	tgt_id;
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci	u32	tm_tag;
7162306a36Sopenharmony_ci	u8	io_cmpl:1;		/* sets to 1 when fw completes IO */
7262306a36Sopenharmony_ci	u8	resvd[3];
7362306a36Sopenharmony_ci	struct scsi_cmnd *sc;		/* Associated scsi cmd */
7462306a36Sopenharmony_ci	struct snic	*snic;		/* Associated snic */
7562306a36Sopenharmony_ci	ulong	sge_va;			/* Pointer to Resp Buffer */
7662306a36Sopenharmony_ci	u64	snsbuf_va;
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci	struct snic_host_req *abort_req;
7962306a36Sopenharmony_ci	struct completion *abts_done;
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	struct snic_host_req *dr_req;
8262306a36Sopenharmony_ci	struct completion *dr_done;
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define rqi_to_req(rqi)	\
8762306a36Sopenharmony_ci	((struct snic_host_req *) (((struct snic_req_info *)rqi)->req))
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define req_to_rqi(req)	\
9062306a36Sopenharmony_ci	((struct snic_req_info *) (((struct snic_host_req *)req)->hdr.init_ctx))
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define req_to_sgl(req)	\
9362306a36Sopenharmony_ci	((struct snic_sg_desc *) (((struct snic_host_req *)req)+1))
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistruct snic_req_info *
9662306a36Sopenharmony_cisnic_req_init(struct snic *, int sg_cnt);
9762306a36Sopenharmony_civoid snic_req_free(struct snic *, struct snic_req_info *);
9862306a36Sopenharmony_civoid snic_calc_io_process_time(struct snic *, struct snic_req_info *);
9962306a36Sopenharmony_civoid snic_pci_unmap_rsp_buf(struct snic *, struct snic_req_info *);
10062306a36Sopenharmony_cistruct snic_host_req *
10162306a36Sopenharmony_cisnic_abort_req_init(struct snic *, struct snic_req_info *);
10262306a36Sopenharmony_cistruct snic_host_req *
10362306a36Sopenharmony_cisnic_dr_req_init(struct snic *, struct snic_req_info *);
10462306a36Sopenharmony_ci#endif /* _SNIC_IO_H */
105