[SCSI] bfa: Brocade-1860 Fabric Adapter vHBA support.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / bfa / bfa_fcpim.h
CommitLineData
a36c61f9
KG
1/*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18#ifndef __BFA_FCPIM_H__
19#define __BFA_FCPIM_H__
20
21#include "bfa.h"
22#include "bfa_svc.h"
23#include "bfi_ms.h"
24#include "bfa_defs_svc.h"
25#include "bfa_cs.h"
26
e2187d7f
KG
27/* FCP module related definitions */
28#define BFA_IO_MAX 2000
29#define BFA_FWTIO_MAX 0
30
31struct bfa_fcp_mod_s;
32struct bfa_iotag_s {
33 struct list_head qe; /* queue element */
34 u16 tag; /* FW IO tag */
35};
36
37struct bfa_itn_s {
38 bfa_isr_func_t isr;
39};
40
41void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
43void bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m);
44void bfa_iotag_attach(struct bfa_fcp_mod_s *fcp, struct bfa_meminfo_s *minfo);
3fd45980 45void bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw);
e2187d7f
KG
46
47#define BFA_FCP_MOD(_hal) (&(_hal)->modules.fcp_mod)
48#define BFA_IOTAG_FROM_TAG(_fcp, _tag) \
49 (&(_fcp)->iotag_arr[(_tag & BFA_IOIM_IOTAG_MASK)])
50#define BFA_ITN_FROM_TAG(_fcp, _tag) \
51 ((_fcp)->itn_arr + ((_tag) & ((_fcp)->num_itns - 1)))
52#define BFA_SNSINFO_FROM_TAG(_fcp, _tag) \
53 (((u8 *)(_fcp)->snsbase.kva) + (_tag * BFI_IOIM_SNSLEN))
a36c61f9
KG
54
55#define BFA_ITNIM_MIN 32
56#define BFA_ITNIM_MAX 1024
57
58#define BFA_IOIM_MIN 8
59#define BFA_IOIM_MAX 2000
60
61#define BFA_TSKIM_MIN 4
62#define BFA_TSKIM_MAX 512
63#define BFA_FCPIM_PATHTOV_DEF (30 * 1000) /* in millisecs */
64#define BFA_FCPIM_PATHTOV_MAX (90 * 1000) /* in millisecs */
65
66
67#define bfa_itnim_ioprofile_update(__itnim, __index) \
68 (__itnim->ioprofile.iocomps[__index]++)
69
70#define BFA_IOIM_RETRY_TAG_OFFSET 11
15821f05 71#define BFA_IOIM_IOTAG_MASK 0x07ff /* 2K IOs */
a36c61f9
KG
72#define BFA_IOIM_RETRY_MAX 7
73
74/* Buckets are are 512 bytes to 2MB */
75static inline u32
76bfa_ioim_get_index(u32 n) {
77 int pos = 0;
78 if (n >= (1UL)<<22)
79 return BFA_IOBUCKET_MAX - 1;
80 n >>= 8;
81 if (n >= (1UL)<<16)
82 n >>= 16; pos += 16;
83 if (n >= 1 << 8)
84 n >>= 8; pos += 8;
85 if (n >= 1 << 4)
86 n >>= 4; pos += 4;
87 if (n >= 1 << 2)
88 n >>= 2; pos += 2;
89 if (n >= 1 << 1)
90 pos += 1;
91
92 return (n == 0) ? (0) : pos;
93}
94
95/*
96 * forward declarations
97 */
98struct bfa_ioim_s;
99struct bfa_tskim_s;
100struct bfad_ioim_s;
101struct bfad_tskim_s;
102
103typedef void (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim);
104
e2187d7f 105struct bfa_fcpim_s {
a36c61f9 106 struct bfa_s *bfa;
e2187d7f 107 struct bfa_fcp_mod_s *fcp;
a36c61f9
KG
108 struct bfa_itnim_s *itnim_arr;
109 struct bfa_ioim_s *ioim_arr;
110 struct bfa_ioim_sp_s *ioim_sp_arr;
111 struct bfa_tskim_s *tskim_arr;
a36c61f9 112 int num_itnims;
a36c61f9
KG
113 int num_tskim_reqs;
114 u32 path_tov;
115 u16 q_depth;
116 u8 reqq; /* Request queue to be used */
117 u8 rsvd;
118 struct list_head itnim_q; /* queue of active itnim */
a36c61f9
KG
119 struct list_head ioim_resfree_q; /* IOs waiting for f/w */
120 struct list_head ioim_comp_q; /* IO global comp Q */
121 struct list_head tskim_free_q;
3fd45980 122 struct list_head tskim_unused_q; /* Unused tskim Q */
da99dcc9
MZ
123 u32 ios_active; /* current active IOs */
124 u32 delay_comp;
a36c61f9
KG
125 struct bfa_fcpim_del_itn_stats_s del_itn_stats;
126 bfa_boolean_t ioredirect;
127 bfa_boolean_t io_profile;
da99dcc9 128 u32 io_profile_start_time;
a36c61f9
KG
129 bfa_fcpim_profile_t profile_comp;
130 bfa_fcpim_profile_t profile_start;
131};
132
e2187d7f
KG
133struct bfa_fcp_mod_s {
134 struct bfa_s *bfa;
135 struct list_head iotag_ioim_free_q; /* free IO resources */
136 struct list_head iotag_tio_free_q; /* free IO resources */
3fd45980 137 struct list_head iotag_unused_q; /* unused IO resources*/
e2187d7f
KG
138 struct bfa_iotag_s *iotag_arr;
139 struct bfa_itn_s *itn_arr;
140 int num_ioim_reqs;
141 int num_fwtio_reqs;
142 int num_itns;
143 struct bfa_dma_s snsbase;
144 struct bfa_fcpim_s fcpim;
145};
146
acdc79a6 147/*
a36c61f9
KG
148 * BFA IO (initiator mode)
149 */
150struct bfa_ioim_s {
151 struct list_head qe; /* queue elememt */
152 bfa_sm_t sm; /* BFA ioim state machine */
153 struct bfa_s *bfa; /* BFA module */
e2187d7f 154 struct bfa_fcpim_s *fcpim; /* parent fcpim module */
a36c61f9
KG
155 struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */
156 struct bfad_ioim_s *dio; /* driver IO handle */
da99dcc9
MZ
157 u16 iotag; /* FWI IO tag */
158 u16 abort_tag; /* unqiue abort request tag */
159 u16 nsges; /* number of SG elements */
160 u16 nsgpgs; /* number of SG pages */
a36c61f9
KG
161 struct bfa_sgpg_s *sgpg; /* first SG page */
162 struct list_head sgpg_q; /* allocated SG pages */
163 struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
164 bfa_cb_cbfn_t io_cbfn; /* IO completion handler */
da99dcc9
MZ
165 struct bfa_ioim_sp_s *iosp; /* slow-path IO handling */
166 u8 reqq; /* Request queue for I/O */
167 u64 start_time; /* IO's Profile start val */
a36c61f9
KG
168};
169
a36c61f9
KG
170struct bfa_ioim_sp_s {
171 struct bfi_msg_s comp_rspmsg; /* IO comp f/w response */
da99dcc9
MZ
172 struct bfa_sgpg_wqe_s sgpg_wqe; /* waitq elem for sgpg */
173 struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
a36c61f9
KG
174 bfa_boolean_t abort_explicit; /* aborted by OS */
175 struct bfa_tskim_s *tskim; /* Relevant TM cmd */
176};
177
acdc79a6 178/*
a36c61f9
KG
179 * BFA Task management command (initiator mode)
180 */
181struct bfa_tskim_s {
182 struct list_head qe;
183 bfa_sm_t sm;
da99dcc9 184 struct bfa_s *bfa; /* BFA module */
e2187d7f 185 struct bfa_fcpim_s *fcpim; /* parent fcpim module */
a36c61f9 186 struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */
f314878a 187 struct bfad_tskim_s *dtsk; /* driver task mgmt cmnd */
da99dcc9 188 bfa_boolean_t notify; /* notify itnim on TM comp */
f314878a 189 struct scsi_lun lun; /* lun if applicable */
da99dcc9
MZ
190 enum fcp_tm_cmnd tm_cmnd; /* task management command */
191 u16 tsk_tag; /* FWI IO tag */
192 u8 tsecs; /* timeout in seconds */
a36c61f9
KG
193 struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
194 struct list_head io_q; /* queue of affected IOs */
da99dcc9 195 struct bfa_wc_s wc; /* waiting counter */
a36c61f9
KG
196 struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
197 enum bfi_tskim_status tsk_status; /* TM status */
198};
199
acdc79a6 200/*
a36c61f9
KG
201 * BFA i-t-n (initiator mode)
202 */
203struct bfa_itnim_s {
da99dcc9
MZ
204 struct list_head qe; /* queue element */
205 bfa_sm_t sm; /* i-t-n im BFA state machine */
206 struct bfa_s *bfa; /* bfa instance */
207 struct bfa_rport_s *rport; /* bfa rport */
208 void *ditn; /* driver i-t-n structure */
a36c61f9 209 struct bfi_mhdr_s mhdr; /* pre-built mhdr */
da99dcc9
MZ
210 u8 msg_no; /* itnim/rport firmware handle */
211 u8 reqq; /* CQ for requests */
a36c61f9
KG
212 struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
213 struct list_head pending_q; /* queue of pending IO requests */
214 struct list_head io_q; /* queue of active IO requests */
215 struct list_head io_cleanup_q; /* IO being cleaned up */
216 struct list_head tsk_q; /* queue of active TM commands */
217 struct list_head delay_comp_q; /* queue of failed inflight cmds */
218 bfa_boolean_t seq_rec; /* SQER supported */
219 bfa_boolean_t is_online; /* itnim is ONLINE for IO */
220 bfa_boolean_t iotov_active; /* IO TOV timer is active */
da99dcc9
MZ
221 struct bfa_wc_s wc; /* waiting counter */
222 struct bfa_timer_s timer; /* pending IO TOV */
a36c61f9 223 struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
e2187d7f 224 struct bfa_fcpim_s *fcpim; /* fcpim module */
a36c61f9
KG
225 struct bfa_itnim_iostats_s stats;
226 struct bfa_itnim_ioprofile_s ioprofile;
227};
228
a36c61f9 229#define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
e2187d7f 230#define BFA_FCPIM(_hal) (&(_hal)->modules.fcp_mod.fcpim)
15821f05 231#define BFA_IOIM_TAG_2_ID(_iotag) ((_iotag) & BFA_IOIM_IOTAG_MASK)
a36c61f9 232#define BFA_IOIM_FROM_TAG(_fcpim, _iotag) \
15821f05 233 (&fcpim->ioim_arr[(_iotag & BFA_IOIM_IOTAG_MASK)])
a36c61f9
KG
234#define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag) \
235 (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])
236
237#define bfa_io_profile_start_time(_bfa) \
e2187d7f 238 ((_bfa)->modules.fcp_mod.fcpim.io_profile_start_time)
a36c61f9 239#define bfa_fcpim_get_io_profile(_bfa) \
e2187d7f 240 ((_bfa)->modules.fcp_mod.fcpim.io_profile)
15821f05
KG
241#define bfa_ioim_update_iotag(__ioim) do { \
242 uint16_t k = (__ioim)->iotag >> BFA_IOIM_RETRY_TAG_OFFSET; \
243 k++; (__ioim)->iotag &= BFA_IOIM_IOTAG_MASK; \
244 (__ioim)->iotag |= k << BFA_IOIM_RETRY_TAG_OFFSET; \
245} while (0)
a36c61f9
KG
246
247static inline bfa_boolean_t
15821f05 248bfa_ioim_maxretry_reached(struct bfa_ioim_s *ioim)
a36c61f9 249{
15821f05
KG
250 uint16_t k = ioim->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;
251 if (k < BFA_IOIM_RETRY_MAX)
a36c61f9 252 return BFA_FALSE;
a36c61f9
KG
253 return BFA_TRUE;
254}
15821f05 255
a36c61f9
KG
256/*
257 * function prototypes
258 */
e2187d7f 259void bfa_ioim_attach(struct bfa_fcpim_s *fcpim,
a36c61f9 260 struct bfa_meminfo_s *minfo);
a36c61f9
KG
261void bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
262void bfa_ioim_good_comp_isr(struct bfa_s *bfa,
263 struct bfi_msg_s *msg);
264void bfa_ioim_cleanup(struct bfa_ioim_s *ioim);
265void bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim,
266 struct bfa_tskim_s *tskim);
267void bfa_ioim_iocdisable(struct bfa_ioim_s *ioim);
268void bfa_ioim_tov(struct bfa_ioim_s *ioim);
269
e2187d7f 270void bfa_tskim_attach(struct bfa_fcpim_s *fcpim,
a36c61f9 271 struct bfa_meminfo_s *minfo);
a36c61f9
KG
272void bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
273void bfa_tskim_iodone(struct bfa_tskim_s *tskim);
274void bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
275void bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
3fd45980 276void bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
a36c61f9
KG
277
278void bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
279 u32 *dm_len);
e2187d7f 280void bfa_itnim_attach(struct bfa_fcpim_s *fcpim,
a36c61f9 281 struct bfa_meminfo_s *minfo);
a36c61f9
KG
282void bfa_itnim_iocdisable(struct bfa_itnim_s *itnim);
283void bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
284void bfa_itnim_iodone(struct bfa_itnim_s *itnim);
285void bfa_itnim_tskdone(struct bfa_itnim_s *itnim);
286bfa_boolean_t bfa_itnim_hold_io(struct bfa_itnim_s *itnim);
a36c61f9
KG
287
288/*
289 * bfa fcpim module API functions
290 */
da99dcc9 291void bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov);
a36c61f9 292u16 bfa_fcpim_path_tov_get(struct bfa_s *bfa);
a36c61f9 293u16 bfa_fcpim_qdepth_get(struct bfa_s *bfa);
da99dcc9 294
a36c61f9 295#define bfa_fcpim_ioredirect_enabled(__bfa) \
e2187d7f 296 (((struct bfa_fcpim_s *)(BFA_FCPIM(__bfa)))->ioredirect)
a36c61f9
KG
297
298#define bfa_fcpim_get_next_reqq(__bfa, __qid) \
299{ \
e2187d7f 300 struct bfa_fcpim_s *__fcpim = BFA_FCPIM(__bfa); \
a36c61f9
KG
301 __fcpim->reqq++; \
302 __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1); \
303 *(__qid) = __fcpim->reqq; \
304}
305
306#define bfa_iocfc_map_msg_to_qid(__msg, __qid) \
307 *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
308/*
309 * bfa itnim API functions
310 */
311struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa,
da99dcc9
MZ
312 struct bfa_rport_s *rport, void *itnim);
313void bfa_itnim_delete(struct bfa_itnim_s *itnim);
314void bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec);
315void bfa_itnim_offline(struct bfa_itnim_s *itnim);
316void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim);
317bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
318 struct bfa_itnim_ioprofile_s *ioprofile);
319
a36c61f9
KG
320#define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
321
acdc79a6 322/*
da99dcc9 323 * BFA completion callback for bfa_itnim_online().
a36c61f9
KG
324 */
325void bfa_cb_itnim_online(void *itnim);
326
acdc79a6 327/*
da99dcc9 328 * BFA completion callback for bfa_itnim_offline().
a36c61f9
KG
329 */
330void bfa_cb_itnim_offline(void *itnim);
331void bfa_cb_itnim_tov_begin(void *itnim);
332void bfa_cb_itnim_tov(void *itnim);
333
acdc79a6 334/*
da99dcc9 335 * BFA notification to FCS/driver for second level error recovery.
a36c61f9
KG
336 * Atleast one I/O request has timedout and target is unresponsive to
337 * repeated abort requests. Second level error recovery should be initiated
338 * by starting implicit logout and recovery procedures.
a36c61f9
KG
339 */
340void bfa_cb_itnim_sler(void *itnim);
341
342/*
343 * bfa ioim API functions
344 */
345struct bfa_ioim_s *bfa_ioim_alloc(struct bfa_s *bfa,
346 struct bfad_ioim_s *dio,
347 struct bfa_itnim_s *itnim,
348 u16 nsgles);
349
350void bfa_ioim_free(struct bfa_ioim_s *ioim);
351void bfa_ioim_start(struct bfa_ioim_s *ioim);
352bfa_status_t bfa_ioim_abort(struct bfa_ioim_s *ioim);
353void bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
354 bfa_boolean_t iotov);
acdc79a6 355/*
da99dcc9 356 * I/O completion notification.
a36c61f9
KG
357 *
358 * @param[in] dio driver IO structure
359 * @param[in] io_status IO completion status
360 * @param[in] scsi_status SCSI status returned by target
361 * @param[in] sns_len SCSI sense length, 0 if none
362 * @param[in] sns_info SCSI sense data, if any
363 * @param[in] residue Residual length
364 *
365 * @return None
366 */
da99dcc9
MZ
367void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
368 enum bfi_ioim_status io_status,
369 u8 scsi_status, int sns_len,
370 u8 *sns_info, s32 residue);
a36c61f9 371
acdc79a6 372/*
da99dcc9 373 * I/O good completion notification.
a36c61f9 374 */
da99dcc9 375void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
a36c61f9 376
acdc79a6 377/*
da99dcc9 378 * I/O abort completion notification
a36c61f9 379 */
da99dcc9 380void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio);
a36c61f9
KG
381
382/*
383 * bfa tskim API functions
384 */
da99dcc9
MZ
385struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa,
386 struct bfad_tskim_s *dtsk);
387void bfa_tskim_free(struct bfa_tskim_s *tskim);
388void bfa_tskim_start(struct bfa_tskim_s *tskim,
389 struct bfa_itnim_s *itnim, struct scsi_lun lun,
390 enum fcp_tm_cmnd tm, u8 t_secs);
391void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
392 enum bfi_tskim_status tsk_status);
a36c61f9
KG
393
394#endif /* __BFA_FCPIM_H__ */