2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
18 #ifndef __BFA_FCPIM_H__
19 #define __BFA_FCPIM_H__
24 #include "bfa_defs_svc.h"
28 #define BFA_ITNIM_MIN 32
29 #define BFA_ITNIM_MAX 1024
31 #define BFA_IOIM_MIN 8
32 #define BFA_IOIM_MAX 2000
34 #define BFA_TSKIM_MIN 4
35 #define BFA_TSKIM_MAX 512
36 #define BFA_FCPIM_PATHTOV_DEF (30 * 1000) /* in millisecs */
37 #define BFA_FCPIM_PATHTOV_MAX (90 * 1000) /* in millisecs */
40 #define bfa_itnim_ioprofile_update(__itnim, __index) \
41 (__itnim->ioprofile.iocomps[__index]++)
43 #define BFA_IOIM_RETRY_TAG_OFFSET 11
44 #define BFA_IOIM_RETRY_TAG_MASK 0x07ff /* 2K IOs */
45 #define BFA_IOIM_RETRY_MAX 7
47 /* Buckets are are 512 bytes to 2MB */
49 bfa_ioim_get_index(u32 n
) {
52 return BFA_IOBUCKET_MAX
- 1;
65 return (n
== 0) ? (0) : pos
;
69 * forward declarations
76 typedef void (*bfa_fcpim_profile_t
) (struct bfa_ioim_s
*ioim
);
78 struct bfa_fcpim_mod_s
{
80 struct bfa_itnim_s
*itnim_arr
;
81 struct bfa_ioim_s
*ioim_arr
;
82 struct bfa_ioim_sp_s
*ioim_sp_arr
;
83 struct bfa_tskim_s
*tskim_arr
;
84 struct bfa_dma_s snsbase
;
90 u8 reqq
; /* Request queue to be used */
92 struct list_head itnim_q
; /* queue of active itnim */
93 struct list_head ioim_free_q
; /* free IO resources */
94 struct list_head ioim_resfree_q
; /* IOs waiting for f/w */
95 struct list_head ioim_comp_q
; /* IO global comp Q */
96 struct list_head tskim_free_q
;
97 u32 ios_active
; /* current active IOs */
99 struct bfa_fcpim_del_itn_stats_s del_itn_stats
;
100 bfa_boolean_t ioredirect
;
101 bfa_boolean_t io_profile
;
102 u32 io_profile_start_time
;
103 bfa_fcpim_profile_t profile_comp
;
104 bfa_fcpim_profile_t profile_start
;
108 * BFA IO (initiator mode)
111 struct list_head qe
; /* queue elememt */
112 bfa_sm_t sm
; /* BFA ioim state machine */
113 struct bfa_s
*bfa
; /* BFA module */
114 struct bfa_fcpim_mod_s
*fcpim
; /* parent fcpim module */
115 struct bfa_itnim_s
*itnim
; /* i-t-n nexus for this IO */
116 struct bfad_ioim_s
*dio
; /* driver IO handle */
117 u16 iotag
; /* FWI IO tag */
118 u16 abort_tag
; /* unqiue abort request tag */
119 u16 nsges
; /* number of SG elements */
120 u16 nsgpgs
; /* number of SG pages */
121 struct bfa_sgpg_s
*sgpg
; /* first SG page */
122 struct list_head sgpg_q
; /* allocated SG pages */
123 struct bfa_cb_qe_s hcb_qe
; /* bfa callback qelem */
124 bfa_cb_cbfn_t io_cbfn
; /* IO completion handler */
125 struct bfa_ioim_sp_s
*iosp
; /* slow-path IO handling */
126 u8 reqq
; /* Request queue for I/O */
127 u64 start_time
; /* IO's Profile start val */
131 struct bfa_ioim_sp_s
{
132 struct bfi_msg_s comp_rspmsg
; /* IO comp f/w response */
133 u8
*snsinfo
; /* sense info for this IO */
134 struct bfa_sgpg_wqe_s sgpg_wqe
; /* waitq elem for sgpg */
135 struct bfa_reqq_wait_s reqq_wait
; /* to wait for room in reqq */
136 bfa_boolean_t abort_explicit
; /* aborted by OS */
137 struct bfa_tskim_s
*tskim
; /* Relevant TM cmd */
141 * BFA Task management command (initiator mode)
146 struct bfa_s
*bfa
; /* BFA module */
147 struct bfa_fcpim_mod_s
*fcpim
; /* parent fcpim module */
148 struct bfa_itnim_s
*itnim
; /* i-t-n nexus for this IO */
149 struct bfad_tskim_s
*dtsk
; /* driver task mgmt cmnd */
150 bfa_boolean_t notify
; /* notify itnim on TM comp */
151 lun_t lun
; /* lun if applicable */
152 enum fcp_tm_cmnd tm_cmnd
; /* task management command */
153 u16 tsk_tag
; /* FWI IO tag */
154 u8 tsecs
; /* timeout in seconds */
155 struct bfa_reqq_wait_s reqq_wait
; /* to wait for room in reqq */
156 struct list_head io_q
; /* queue of affected IOs */
157 struct bfa_wc_s wc
; /* waiting counter */
158 struct bfa_cb_qe_s hcb_qe
; /* bfa callback qelem */
159 enum bfi_tskim_status tsk_status
; /* TM status */
164 * BFA i-t-n (initiator mode)
167 struct list_head qe
; /* queue element */
168 bfa_sm_t sm
; /* i-t-n im BFA state machine */
169 struct bfa_s
*bfa
; /* bfa instance */
170 struct bfa_rport_s
*rport
; /* bfa rport */
171 void *ditn
; /* driver i-t-n structure */
172 struct bfi_mhdr_s mhdr
; /* pre-built mhdr */
173 u8 msg_no
; /* itnim/rport firmware handle */
174 u8 reqq
; /* CQ for requests */
175 struct bfa_cb_qe_s hcb_qe
; /* bfa callback qelem */
176 struct list_head pending_q
; /* queue of pending IO requests */
177 struct list_head io_q
; /* queue of active IO requests */
178 struct list_head io_cleanup_q
; /* IO being cleaned up */
179 struct list_head tsk_q
; /* queue of active TM commands */
180 struct list_head delay_comp_q
; /* queue of failed inflight cmds */
181 bfa_boolean_t seq_rec
; /* SQER supported */
182 bfa_boolean_t is_online
; /* itnim is ONLINE for IO */
183 bfa_boolean_t iotov_active
; /* IO TOV timer is active */
184 struct bfa_wc_s wc
; /* waiting counter */
185 struct bfa_timer_s timer
; /* pending IO TOV */
186 struct bfa_reqq_wait_s reqq_wait
; /* to wait for room in reqq */
187 struct bfa_fcpim_mod_s
*fcpim
; /* fcpim module */
188 struct bfa_itnim_iostats_s stats
;
189 struct bfa_itnim_ioprofile_s ioprofile
;
193 #define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
194 #define BFA_FCPIM_MOD(_hal) (&(_hal)->modules.fcpim_mod)
195 #define BFA_IOIM_FROM_TAG(_fcpim, _iotag) \
196 (&fcpim->ioim_arr[(_iotag & BFA_IOIM_RETRY_TAG_MASK)])
197 #define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag) \
198 (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])
200 #define bfa_io_profile_start_time(_bfa) \
201 (_bfa->modules.fcpim_mod.io_profile_start_time)
202 #define bfa_fcpim_get_io_profile(_bfa) \
203 (_bfa->modules.fcpim_mod.io_profile)
205 static inline bfa_boolean_t
206 bfa_ioim_get_iotag(struct bfa_ioim_s
*ioim
)
210 k
>>= BFA_IOIM_RETRY_TAG_OFFSET
; k
++;
212 if (k
> BFA_IOIM_RETRY_MAX
)
214 ioim
->iotag
&= BFA_IOIM_RETRY_TAG_MASK
;
215 ioim
->iotag
|= k
<<BFA_IOIM_RETRY_TAG_OFFSET
;
219 * function prototypes
221 void bfa_ioim_attach(struct bfa_fcpim_mod_s
*fcpim
,
222 struct bfa_meminfo_s
*minfo
);
223 void bfa_ioim_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
);
224 void bfa_ioim_good_comp_isr(struct bfa_s
*bfa
,
225 struct bfi_msg_s
*msg
);
226 void bfa_ioim_cleanup(struct bfa_ioim_s
*ioim
);
227 void bfa_ioim_cleanup_tm(struct bfa_ioim_s
*ioim
,
228 struct bfa_tskim_s
*tskim
);
229 void bfa_ioim_iocdisable(struct bfa_ioim_s
*ioim
);
230 void bfa_ioim_tov(struct bfa_ioim_s
*ioim
);
232 void bfa_tskim_attach(struct bfa_fcpim_mod_s
*fcpim
,
233 struct bfa_meminfo_s
*minfo
);
234 void bfa_tskim_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
);
235 void bfa_tskim_iodone(struct bfa_tskim_s
*tskim
);
236 void bfa_tskim_iocdisable(struct bfa_tskim_s
*tskim
);
237 void bfa_tskim_cleanup(struct bfa_tskim_s
*tskim
);
239 void bfa_itnim_meminfo(struct bfa_iocfc_cfg_s
*cfg
, u32
*km_len
,
241 void bfa_itnim_attach(struct bfa_fcpim_mod_s
*fcpim
,
242 struct bfa_meminfo_s
*minfo
);
243 void bfa_itnim_detach(struct bfa_fcpim_mod_s
*fcpim
);
244 void bfa_itnim_iocdisable(struct bfa_itnim_s
*itnim
);
245 void bfa_itnim_isr(struct bfa_s
*bfa
, struct bfi_msg_s
*msg
);
246 void bfa_itnim_iodone(struct bfa_itnim_s
*itnim
);
247 void bfa_itnim_tskdone(struct bfa_itnim_s
*itnim
);
248 bfa_boolean_t
bfa_itnim_hold_io(struct bfa_itnim_s
*itnim
);
249 void bfa_ioim_profile_comp(struct bfa_ioim_s
*ioim
);
250 void bfa_ioim_profile_start(struct bfa_ioim_s
*ioim
);
254 * bfa fcpim module API functions
256 void bfa_fcpim_path_tov_set(struct bfa_s
*bfa
, u16 path_tov
);
257 u16
bfa_fcpim_path_tov_get(struct bfa_s
*bfa
);
258 void bfa_fcpim_qdepth_set(struct bfa_s
*bfa
, u16 q_depth
);
259 u16
bfa_fcpim_qdepth_get(struct bfa_s
*bfa
);
260 bfa_status_t
bfa_fcpim_get_modstats(struct bfa_s
*bfa
,
261 struct bfa_itnim_iostats_s
*modstats
);
262 bfa_status_t
bfa_fcpim_port_iostats(struct bfa_s
*bfa
,
263 struct bfa_itnim_iostats_s
*stats
, u8 lp_tag
);
264 bfa_status_t
bfa_fcpim_get_del_itn_stats(struct bfa_s
*bfa
,
265 struct bfa_fcpim_del_itn_stats_s
*modstats
);
266 bfa_status_t
bfa_fcpim_port_clear_iostats(struct bfa_s
*bfa
, u8 lp_tag
);
267 void bfa_fcpim_add_stats(struct bfa_itnim_iostats_s
*fcpim_stats
,
268 struct bfa_itnim_iostats_s
*itnim_stats
);
269 bfa_status_t
bfa_fcpim_clr_modstats(struct bfa_s
*bfa
);
270 void bfa_fcpim_set_ioredirect(struct bfa_s
*bfa
,
271 bfa_boolean_t state
);
272 void bfa_fcpim_update_ioredirect(struct bfa_s
*bfa
);
273 bfa_status_t
bfa_fcpim_profile_on(struct bfa_s
*bfa
, u32 time
);
274 bfa_status_t
bfa_fcpim_profile_off(struct bfa_s
*bfa
);
275 #define bfa_fcpim_ioredirect_enabled(__bfa) \
276 (((struct bfa_fcpim_mod_s *)(BFA_FCPIM_MOD(__bfa)))->ioredirect)
278 #define bfa_fcpim_get_next_reqq(__bfa, __qid) \
280 struct bfa_fcpim_mod_s *__fcpim = BFA_FCPIM_MOD(__bfa); \
282 __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1); \
283 *(__qid) = __fcpim->reqq; \
286 #define bfa_iocfc_map_msg_to_qid(__msg, __qid) \
287 *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
289 * bfa itnim API functions
291 struct bfa_itnim_s
*bfa_itnim_create(struct bfa_s
*bfa
,
292 struct bfa_rport_s
*rport
, void *itnim
);
293 void bfa_itnim_delete(struct bfa_itnim_s
*itnim
);
294 void bfa_itnim_online(struct bfa_itnim_s
*itnim
,
295 bfa_boolean_t seq_rec
);
296 void bfa_itnim_offline(struct bfa_itnim_s
*itnim
);
297 void bfa_itnim_clear_stats(struct bfa_itnim_s
*itnim
);
298 bfa_status_t
bfa_itnim_get_ioprofile(struct bfa_itnim_s
*itnim
,
299 struct bfa_itnim_ioprofile_s
*ioprofile
);
300 #define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
303 * BFA completion callback for bfa_itnim_online().
305 * @param[in] itnim FCS or driver itnim instance
309 void bfa_cb_itnim_online(void *itnim
);
312 * BFA completion callback for bfa_itnim_offline().
314 * @param[in] itnim FCS or driver itnim instance
318 void bfa_cb_itnim_offline(void *itnim
);
319 void bfa_cb_itnim_tov_begin(void *itnim
);
320 void bfa_cb_itnim_tov(void *itnim
);
323 * BFA notification to FCS/driver for second level error recovery.
325 * Atleast one I/O request has timedout and target is unresponsive to
326 * repeated abort requests. Second level error recovery should be initiated
327 * by starting implicit logout and recovery procedures.
329 * @param[in] itnim FCS or driver itnim instance
333 void bfa_cb_itnim_sler(void *itnim
);
336 * bfa ioim API functions
338 struct bfa_ioim_s
*bfa_ioim_alloc(struct bfa_s
*bfa
,
339 struct bfad_ioim_s
*dio
,
340 struct bfa_itnim_s
*itnim
,
343 void bfa_ioim_free(struct bfa_ioim_s
*ioim
);
344 void bfa_ioim_start(struct bfa_ioim_s
*ioim
);
345 bfa_status_t
bfa_ioim_abort(struct bfa_ioim_s
*ioim
);
346 void bfa_ioim_delayed_comp(struct bfa_ioim_s
*ioim
,
347 bfa_boolean_t iotov
);
351 * I/O completion notification.
353 * @param[in] dio driver IO structure
354 * @param[in] io_status IO completion status
355 * @param[in] scsi_status SCSI status returned by target
356 * @param[in] sns_len SCSI sense length, 0 if none
357 * @param[in] sns_info SCSI sense data, if any
358 * @param[in] residue Residual length
362 void bfa_cb_ioim_done(void *bfad
, struct bfad_ioim_s
*dio
,
363 enum bfi_ioim_status io_status
,
364 u8 scsi_status
, int sns_len
,
365 u8
*sns_info
, s32 residue
);
368 * I/O good completion notification.
370 * @param[in] dio driver IO structure
374 void bfa_cb_ioim_good_comp(void *bfad
, struct bfad_ioim_s
*dio
);
377 * I/O abort completion notification
379 * @param[in] dio driver IO that was aborted
383 void bfa_cb_ioim_abort(void *bfad
, struct bfad_ioim_s
*dio
);
386 * bfa tskim API functions
388 struct bfa_tskim_s
*bfa_tskim_alloc(struct bfa_s
*bfa
,
389 struct bfad_tskim_s
*dtsk
);
390 void bfa_tskim_free(struct bfa_tskim_s
*tskim
);
391 void bfa_tskim_start(struct bfa_tskim_s
*tskim
,
392 struct bfa_itnim_s
*itnim
, lun_t lun
,
393 enum fcp_tm_cmnd tm
, u8 t_secs
);
394 void bfa_cb_tskim_done(void *bfad
, struct bfad_tskim_s
*dtsk
,
395 enum bfi_tskim_status tsk_status
);
397 #endif /* __BFA_FCPIM_H__ */