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_IO_H
198c2ecf20Sopenharmony_ci#define _SNIC_IO_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define SNIC_DFLT_SG_DESC_CNT	32	/* Default descriptors for sgl */
228c2ecf20Sopenharmony_ci#define SNIC_MAX_SG_DESC_CNT	60	/* Max descriptor for sgl */
238c2ecf20Sopenharmony_ci#define SNIC_SG_DESC_ALIGN	16	/* Descriptor address alignment */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* SG descriptor for snic */
268c2ecf20Sopenharmony_cistruct snic_sg_desc {
278c2ecf20Sopenharmony_ci	__le64 addr;
288c2ecf20Sopenharmony_ci	__le32 len;
298c2ecf20Sopenharmony_ci	u32 _resvd;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct snic_dflt_sgl {
338c2ecf20Sopenharmony_ci	struct snic_sg_desc sg_desc[SNIC_DFLT_SG_DESC_CNT];
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct snic_max_sgl {
378c2ecf20Sopenharmony_ci	struct snic_sg_desc sg_desc[SNIC_MAX_SG_DESC_CNT];
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cienum snic_req_cache_type {
418c2ecf20Sopenharmony_ci	SNIC_REQ_CACHE_DFLT_SGL = 0,	/* cache with default size sgl */
428c2ecf20Sopenharmony_ci	SNIC_REQ_CACHE_MAX_SGL,		/* cache with max size sgl */
438c2ecf20Sopenharmony_ci	SNIC_REQ_TM_CACHE,		/* cache for task mgmt reqs contains
448c2ecf20Sopenharmony_ci					   snic_host_req objects only*/
458c2ecf20Sopenharmony_ci	SNIC_REQ_MAX_CACHES		/* number of sgl caches */
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Per IO internal state */
498c2ecf20Sopenharmony_cistruct snic_internal_io_state {
508c2ecf20Sopenharmony_ci	char	*rqi;
518c2ecf20Sopenharmony_ci	u64	flags;
528c2ecf20Sopenharmony_ci	u32	state;
538c2ecf20Sopenharmony_ci	u32	abts_status;	/* Abort completion status */
548c2ecf20Sopenharmony_ci	u32	lr_status;	/* device reset completion status */
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* IO state machine */
588c2ecf20Sopenharmony_cienum snic_ioreq_state {
598c2ecf20Sopenharmony_ci	SNIC_IOREQ_NOT_INITED = 0,
608c2ecf20Sopenharmony_ci	SNIC_IOREQ_PENDING,
618c2ecf20Sopenharmony_ci	SNIC_IOREQ_ABTS_PENDING,
628c2ecf20Sopenharmony_ci	SNIC_IOREQ_ABTS_COMPLETE,
638c2ecf20Sopenharmony_ci	SNIC_IOREQ_LR_PENDING,
648c2ecf20Sopenharmony_ci	SNIC_IOREQ_LR_COMPLETE,
658c2ecf20Sopenharmony_ci	SNIC_IOREQ_COMPLETE,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct snic;
698c2ecf20Sopenharmony_cistruct snic_host_req;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/*
728c2ecf20Sopenharmony_ci * snic_req_info : Contains info about IO, one per scsi command.
738c2ecf20Sopenharmony_ci * Notes: Make sure that the structure is aligned to 16 B
748c2ecf20Sopenharmony_ci * this helps in easy access to snic_req_info from snic_host_req
758c2ecf20Sopenharmony_ci */
768c2ecf20Sopenharmony_cistruct snic_req_info {
778c2ecf20Sopenharmony_ci	struct list_head list;
788c2ecf20Sopenharmony_ci	struct snic_host_req *req;
798c2ecf20Sopenharmony_ci	u64	start_time;		/* start time in jiffies */
808c2ecf20Sopenharmony_ci	u16	rq_pool_type;		/* noticion of request pool type */
818c2ecf20Sopenharmony_ci	u16	req_len;		/* buf len passing to fw (req + sgl)*/
828c2ecf20Sopenharmony_ci	u32	tgt_id;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	u32	tm_tag;
858c2ecf20Sopenharmony_ci	u8	io_cmpl:1;		/* sets to 1 when fw completes IO */
868c2ecf20Sopenharmony_ci	u8	resvd[3];
878c2ecf20Sopenharmony_ci	struct scsi_cmnd *sc;		/* Associated scsi cmd */
888c2ecf20Sopenharmony_ci	struct snic	*snic;		/* Associated snic */
898c2ecf20Sopenharmony_ci	ulong	sge_va;			/* Pointer to Resp Buffer */
908c2ecf20Sopenharmony_ci	u64	snsbuf_va;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	struct snic_host_req *abort_req;
938c2ecf20Sopenharmony_ci	struct completion *abts_done;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	struct snic_host_req *dr_req;
968c2ecf20Sopenharmony_ci	struct completion *dr_done;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define rqi_to_req(rqi)	\
1018c2ecf20Sopenharmony_ci	((struct snic_host_req *) (((struct snic_req_info *)rqi)->req))
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define req_to_rqi(req)	\
1048c2ecf20Sopenharmony_ci	((struct snic_req_info *) (((struct snic_host_req *)req)->hdr.init_ctx))
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define req_to_sgl(req)	\
1078c2ecf20Sopenharmony_ci	((struct snic_sg_desc *) (((struct snic_host_req *)req)+1))
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistruct snic_req_info *
1108c2ecf20Sopenharmony_cisnic_req_init(struct snic *, int sg_cnt);
1118c2ecf20Sopenharmony_civoid snic_req_free(struct snic *, struct snic_req_info *);
1128c2ecf20Sopenharmony_civoid snic_calc_io_process_time(struct snic *, struct snic_req_info *);
1138c2ecf20Sopenharmony_civoid snic_pci_unmap_rsp_buf(struct snic *, struct snic_req_info *);
1148c2ecf20Sopenharmony_cistruct snic_host_req *
1158c2ecf20Sopenharmony_cisnic_abort_req_init(struct snic *, struct snic_req_info *);
1168c2ecf20Sopenharmony_cistruct snic_host_req *
1178c2ecf20Sopenharmony_cisnic_dr_req_init(struct snic *, struct snic_req_info *);
1188c2ecf20Sopenharmony_ci#endif /* _SNIC_IO_H */
119