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