1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef __CSIO_SCSI_H__
36#define __CSIO_SCSI_H__
37
38#include <linux/spinlock_types.h>
39#include <linux/completion.h>
40#include <scsi/scsi.h>
41#include <scsi/scsi_cmnd.h>
42#include <scsi/scsi_device.h>
43#include <scsi/scsi_host.h>
44#include <scsi/scsi_eh.h>
45#include <scsi/scsi_tcq.h>
46#include <scsi/fc/fc_fcp.h>
47
48#include "csio_defs.h"
49#include "csio_wr.h"
50
51extern struct scsi_host_template csio_fcoe_shost_template;
52extern struct scsi_host_template csio_fcoe_shost_vport_template;
53
54extern int csio_scsi_eqsize;
55extern int csio_scsi_iqlen;
56extern int csio_scsi_ioreqs;
57extern uint32_t csio_max_scan_tmo;
58extern uint32_t csio_delta_scan_tmo;
59extern int csio_lun_qdepth;
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79#define CSIO_SCSI_MAX_SGE 35
80#define CSIO_SCSI_ABRT_TMO_MS 60000
81#define CSIO_SCSI_LUNRST_TMO_MS 60000
82#define CSIO_SCSI_TM_POLL_MS 2000
83
84
85#define CSIO_SCSI_IQ_WRSZ 128
86#define CSIO_SCSI_IQSIZE (csio_scsi_iqlen * CSIO_SCSI_IQ_WRSZ)
87
88#define CSIO_MAX_SNS_LEN 128
89#define CSIO_SCSI_RSP_LEN (FCP_RESP_WITH_EXT + 4 + CSIO_MAX_SNS_LEN)
90
91
92#define csio_scsi_cmnd(req) ((req)->scratch1)
93
94struct csio_scsi_stats {
95 uint64_t n_tot_success;
96 uint32_t n_rn_nr_error;
97
98
99 uint32_t n_hw_nr_error;
100
101
102 uint32_t n_dmamap_error;
103 uint32_t n_unsupp_sge_error;
104
105
106 uint32_t n_no_req_error;
107 uint32_t n_busy_error;
108 uint32_t n_hosterror;
109 uint32_t n_rsperror;
110 uint32_t n_autosense;
111 uint32_t n_ovflerror;
112 uint32_t n_unflerror;
113 uint32_t n_rdev_nr_error;
114
115
116 uint32_t n_rdev_lost_error;
117 uint32_t n_rdev_logo_error;
118 uint32_t n_link_down_error;
119 uint32_t n_no_xchg_error;
120 uint32_t n_unknown_error;
121 uint32_t n_aborted;
122 uint32_t n_abrt_timedout;
123 uint32_t n_abrt_fail;
124 uint32_t n_abrt_dups;
125 uint32_t n_abrt_race_comp;
126
127
128 uint32_t n_abrt_busy_error;
129
130
131 uint32_t n_closed;
132 uint32_t n_cls_busy_error;
133
134
135 uint32_t n_active;
136 uint32_t n_tm_active;
137 uint32_t n_wcbfn;
138
139
140 uint32_t n_free_ioreq;
141 uint32_t n_free_ddp;
142 uint32_t n_unaligned;
143 uint32_t n_inval_cplop;
144 uint32_t n_inval_scsiop;
145};
146
147struct csio_scsim {
148 struct csio_hw *hw;
149 uint8_t max_sge;
150 uint8_t proto_cmd_len;
151
152
153 uint16_t proto_rsp_len;
154
155
156 spinlock_t freelist_lock;
157 struct list_head active_q;
158 struct list_head ioreq_freelist;
159 struct list_head ddp_freelist;
160 struct csio_scsi_stats stats;
161};
162
163
164enum csio_scsi_ev {
165 CSIO_SCSIE_START_IO = 1,
166 CSIO_SCSIE_START_TM,
167 CSIO_SCSIE_COMPLETED,
168 CSIO_SCSIE_ABORT,
169 CSIO_SCSIE_ABORTED,
170 CSIO_SCSIE_CLOSE,
171 CSIO_SCSIE_CLOSED,
172 CSIO_SCSIE_DRVCLEANUP,
173
174
175};
176
177enum csio_scsi_lev {
178 CSIO_LEV_ALL = 1,
179 CSIO_LEV_LNODE,
180 CSIO_LEV_RNODE,
181 CSIO_LEV_LUN,
182};
183
184struct csio_scsi_level_data {
185 enum csio_scsi_lev level;
186 struct csio_rnode *rnode;
187 struct csio_lnode *lnode;
188 uint64_t oslun;
189};
190
191static inline struct csio_ioreq *
192csio_get_scsi_ioreq(struct csio_scsim *scm)
193{
194 struct csio_sm *req;
195
196 if (likely(!list_empty(&scm->ioreq_freelist))) {
197 req = list_first_entry(&scm->ioreq_freelist,
198 struct csio_sm, sm_list);
199 list_del_init(&req->sm_list);
200 CSIO_DEC_STATS(scm, n_free_ioreq);
201 return (struct csio_ioreq *)req;
202 } else
203 return NULL;
204}
205
206static inline void
207csio_put_scsi_ioreq(struct csio_scsim *scm, struct csio_ioreq *ioreq)
208{
209 list_add_tail(&ioreq->sm.sm_list, &scm->ioreq_freelist);
210 CSIO_INC_STATS(scm, n_free_ioreq);
211}
212
213static inline void
214csio_put_scsi_ioreq_list(struct csio_scsim *scm, struct list_head *reqlist,
215 int n)
216{
217 list_splice_init(reqlist, &scm->ioreq_freelist);
218 scm->stats.n_free_ioreq += n;
219}
220
221static inline struct csio_dma_buf *
222csio_get_scsi_ddp(struct csio_scsim *scm)
223{
224 struct csio_dma_buf *ddp;
225
226 if (likely(!list_empty(&scm->ddp_freelist))) {
227 ddp = list_first_entry(&scm->ddp_freelist,
228 struct csio_dma_buf, list);
229 list_del_init(&ddp->list);
230 CSIO_DEC_STATS(scm, n_free_ddp);
231 return ddp;
232 } else
233 return NULL;
234}
235
236static inline void
237csio_put_scsi_ddp(struct csio_scsim *scm, struct csio_dma_buf *ddp)
238{
239 list_add_tail(&ddp->list, &scm->ddp_freelist);
240 CSIO_INC_STATS(scm, n_free_ddp);
241}
242
243static inline void
244csio_put_scsi_ddp_list(struct csio_scsim *scm, struct list_head *reqlist,
245 int n)
246{
247 list_splice_tail_init(reqlist, &scm->ddp_freelist);
248 scm->stats.n_free_ddp += n;
249}
250
251static inline void
252csio_scsi_completed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
253{
254 csio_post_event(&ioreq->sm, CSIO_SCSIE_COMPLETED);
255 if (csio_list_deleted(&ioreq->sm.sm_list))
256 list_add_tail(&ioreq->sm.sm_list, cbfn_q);
257}
258
259static inline void
260csio_scsi_aborted(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
261{
262 csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORTED);
263 list_add_tail(&ioreq->sm.sm_list, cbfn_q);
264}
265
266static inline void
267csio_scsi_closed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
268{
269 csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSED);
270 list_add_tail(&ioreq->sm.sm_list, cbfn_q);
271}
272
273static inline void
274csio_scsi_drvcleanup(struct csio_ioreq *ioreq)
275{
276 csio_post_event(&ioreq->sm, CSIO_SCSIE_DRVCLEANUP);
277}
278
279
280
281
282
283
284
285static inline int
286csio_scsi_start_io(struct csio_ioreq *ioreq)
287{
288 csio_post_event(&ioreq->sm, CSIO_SCSIE_START_IO);
289 return ioreq->drv_status;
290}
291
292
293
294
295
296
297
298static inline int
299csio_scsi_start_tm(struct csio_ioreq *ioreq)
300{
301 csio_post_event(&ioreq->sm, CSIO_SCSIE_START_TM);
302 return ioreq->drv_status;
303}
304
305
306
307
308
309
310
311static inline int
312csio_scsi_abort(struct csio_ioreq *ioreq)
313{
314 csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORT);
315 return ioreq->drv_status;
316}
317
318
319
320
321
322
323
324static inline int
325csio_scsi_close(struct csio_ioreq *ioreq)
326{
327 csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSE);
328 return ioreq->drv_status;
329}
330
331void csio_scsi_cleanup_io_q(struct csio_scsim *, struct list_head *);
332int csio_scsim_cleanup_io(struct csio_scsim *, bool abort);
333int csio_scsim_cleanup_io_lnode(struct csio_scsim *,
334 struct csio_lnode *);
335struct csio_ioreq *csio_scsi_cmpl_handler(struct csio_hw *, void *, uint32_t,
336 struct csio_fl_dma_buf *,
337 void *, uint8_t **);
338int csio_scsi_qconfig(struct csio_hw *);
339int csio_scsim_init(struct csio_scsim *, struct csio_hw *);
340void csio_scsim_exit(struct csio_scsim *);
341
342#endif
343