xref: /openbmc/linux/drivers/scsi/snic/snic_io.h (revision f1575595)
1 /*
2  * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This program is free software; you may redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15  * SOFTWARE.
16  */
17 
18 #ifndef _SNIC_IO_H
19 #define _SNIC_IO_H
20 
21 #define SNIC_DFLT_SG_DESC_CNT	32	/* Default descriptors for sgl */
22 #define SNIC_MAX_SG_DESC_CNT	60	/* Max descriptor for sgl */
23 #define SNIC_SG_DESC_ALIGN	16	/* Descriptor address alignment */
24 
25 /* SG descriptor for snic */
26 struct snic_sg_desc {
27 	__le64 addr;
28 	__le32 len;
29 	u32 _resvd;
30 };
31 
32 struct snic_dflt_sgl {
33 	struct snic_sg_desc sg_desc[SNIC_DFLT_SG_DESC_CNT];
34 };
35 
36 struct snic_max_sgl {
37 	struct snic_sg_desc sg_desc[SNIC_MAX_SG_DESC_CNT];
38 };
39 
40 enum snic_req_cache_type {
41 	SNIC_REQ_CACHE_DFLT_SGL = 0,	/* cache with default size sgl */
42 	SNIC_REQ_CACHE_MAX_SGL,		/* cache with max size sgl */
43 	SNIC_REQ_TM_CACHE,		/* cache for task mgmt reqs contains
44 					   snic_host_req objects only*/
45 	SNIC_REQ_MAX_CACHES		/* number of sgl caches */
46 };
47 
48 /* Per IO internal state */
49 struct snic_internal_io_state {
50 	char	*rqi;
51 	u64	flags;
52 	u32	state;
53 	u32	abts_status;	/* Abort completion status */
54 	u32	lr_status;	/* device reset completion status */
55 };
56 
57 /* IO state machine */
58 enum snic_ioreq_state {
59 	SNIC_IOREQ_NOT_INITED = 0,
60 	SNIC_IOREQ_PENDING,
61 	SNIC_IOREQ_ABTS_PENDING,
62 	SNIC_IOREQ_ABTS_COMPLETE,
63 	SNIC_IOREQ_LR_PENDING,
64 	SNIC_IOREQ_LR_COMPLETE,
65 	SNIC_IOREQ_COMPLETE,
66 };
67 
68 struct snic;
69 struct snic_host_req;
70 
71 /*
72  * snic_req_info : Contains info about IO, one per scsi command.
73  * Notes: Make sure that the structure is aligned to 16 B
74  * this helps in easy access to snic_req_info from snic_host_req
75  */
76 struct snic_req_info {
77 	struct list_head list;
78 	struct snic_host_req *req;
79 	u64	start_time;		/* start time in jiffies */
80 	u16	rq_pool_type;		/* noticion of request pool type */
81 	u16	req_len;		/* buf len passing to fw (req + sgl)*/
82 	u32	tgt_id;
83 
84 	u32	tm_tag;
85 	u8	io_cmpl:1;		/* sets to 1 when fw completes IO */
86 	u8	resvd[3];
87 	struct scsi_cmnd *sc;		/* Associated scsi cmd */
88 	struct snic	*snic;		/* Associated snic */
89 	ulong	sge_va;			/* Pointer to Resp Buffer */
90 	u64	snsbuf_va;
91 
92 	struct snic_host_req *abort_req;
93 	struct completion *abts_done;
94 
95 	struct snic_host_req *dr_req;
96 	struct completion *dr_done;
97 };
98 
99 
100 #define rqi_to_req(rqi)	\
101 	((struct snic_host_req *) (((struct snic_req_info *)rqi)->req))
102 
103 #define req_to_rqi(req)	\
104 	((struct snic_req_info *) (((struct snic_host_req *)req)->hdr.init_ctx))
105 
106 #define req_to_sgl(req)	\
107 	((struct snic_sg_desc *) (((struct snic_host_req *)req)+1))
108 
109 struct snic_req_info *
110 snic_req_init(struct snic *, int sg_cnt);
111 void snic_req_free(struct snic *, struct snic_req_info *);
112 void snic_calc_io_process_time(struct snic *, struct snic_req_info *);
113 void snic_pci_unmap_rsp_buf(struct snic *, struct snic_req_info *);
114 struct snic_host_req *
115 snic_abort_req_init(struct snic *, struct snic_req_info *);
116 struct snic_host_req *
117 snic_dr_req_init(struct snic *, struct snic_req_info *);
118 #endif /* _SNIC_IO_H */
119